Exemplo n.º 1
0
    public void DestroyGene(int i)
    {
        GeneID id = playerScript.genes[i].id;

        foreach (Transform child in geneObjects[i].transform)
        {
            GeneDeathScript geneDeathScript = child.gameObject.GetComponent <GeneDeathScript>();
            if (geneDeathScript != null)
            {
                geneDeathScript.enabled = true;
            }
        }
        foreach (TextMeshPro textMeshPro in geneObjects[i].GetComponentsInChildren <TextMeshPro>())
        {
            Destroy(textMeshPro);
        }
        playerScript.genes.RemoveAt(i);
        geneObjects.RemoveAt(i);
        if (id == GeneID.Junk)
        {
            playerScript.genes.Insert(i, new Gene(GeneID.DamagedJunk));
            AddGene(i);
        }
        popupTextScript.Display(Gene.NAME_LOOKUP[id] + " gene destroyed.");
    }
Exemplo n.º 2
0
 public bool HasGene(GeneID id)
 {
     foreach (Gene gene in genes)
     {
         if (gene.id == id)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 public void SetID(GeneID id)
 {
     this.id       = id;
     nameText.text = Gene.NAME_LOOKUP[id];
     foreach (SpriteRenderer spriteRenderer in spriteObject.GetComponentsInChildren <SpriteRenderer>())
     {
         spriteRenderer.color = Gene.COLOR_LOOKUP[id];
     }
     int[] prices = Gene.PRICE_LOOKUP[id];
     price          = Random.Range(prices[0], prices[1] + 1);
     priceText.text = price.ToString();
 }
Exemplo n.º 4
0
    public int NumGene(GeneID id)
    {
        int ret = 0;

        foreach (Gene gene in genes)
        {
            if (gene.id == id)
            {
                ret++;
            }
        }
        return(ret);
    }
Exemplo n.º 5
0
 public Gene(GeneID id)
 {
     this.id = id;
 }
Exemplo n.º 6
0
 bool GetSpecialButtonDown(GeneID id)
 {
     return(HasGene(id) && Input.GetButtonDown("Special"));
 }
Exemplo n.º 7
0
        /// <summary>
        /// In this method we will take one dictionary to populate GeneId's and mapped read count and another dictionary
        /// to populate GeneID's and their length. Take a list CHRData with data from chr1-250.fa file.
        /// Pass read length value and a string variable which will return the GeneID and their corresponding mappability value.
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="GeneData"></param>
        /// <param name="GeneDataLength"></param>
        /// <param name="CHRData"></param>
        /// <param name="Values"></param>
        /// <param name="readLength"></param>
        public static void MappabilityFunction(string FilePath, Dictionary <string, int> GeneData, Dictionary <string, int> GeneDataLength, List <KeyValuePair <string, string> > CHRData, ref string Values, int readLength)
        {
            //Clear the list as there might be values for previous read length Bowtie file.
            GeneData.Clear();
            //Loop through the Bowtie output (BED format) to get the unique GeneId's and there mapped read count
            foreach (string GeneID in File.ReadAllLines(FilePath))
            {
                string[] BToutDetails    = GeneID.Split('\t');
                string[] GeneNameDetails = BToutDetails[3].Split('.');
                //Build the gene name
                string GeneName = ">" + GeneNameDetails[0] + "." + GeneNameDetails[1] + "." + GeneNameDetails[2] + "." + GeneNameDetails[3] + "." + GeneNameDetails[4];// GeneNameDetails[3];
                //Check if there exists Gene Name in dictionary and add 1 to the value.
                if (GeneData.ContainsKey(GeneName))
                {
                    //Add 1 to existing value for particular GeneID. If Map start and end are in range of Gene ID.
                    if ((Convert.ToInt32(BToutDetails[1]) >= Convert.ToInt32(GeneNameDetails[1])) &&
                        (Convert.ToInt32(BToutDetails[2]) <= Convert.ToInt32(GeneNameDetails[2])))
                    {
                        GeneData[GeneName] = GeneData[GeneName] + 1;
                    }
                }
                else
                {
                    //Add GeneID and 1 as initial value. If Map start and end are in range of Gene ID.
                    if ((Convert.ToInt32(BToutDetails[1]) >= Convert.ToInt32(GeneNameDetails[1])) &&
                        (Convert.ToInt32(BToutDetails[2]) <= Convert.ToInt32(GeneNameDetails[2])))
                    {
                        GeneData.Add(GeneName, 1);
                    }
                }
            }
            //Clear the dictionary before we put some information into it.
            GeneDataLength.Clear();
            //Loop through CHRData which contains information of Chr1-250.fa file and populate the unique GeneID's and their length.
            foreach (KeyValuePair <string, string> GeneLengthData in CHRData)
            {
                string[] GeneAnnotData_Array = GeneLengthData.Key.Split('.');
                string   GeneName            = GeneLengthData.Key;//GeneAnnotData_Array[3];
                int      GeneLength          = 0;
                //If we have duplicate GeneID then we will consider only the last GeneID found and its corresponding length.
                if (GeneDataLength.ContainsKey(GeneName))
                {
                    //Replace new length with the existing Value for particular GeneID which is duplicate.
                    GeneDataLength[GeneName] = Convert.ToInt32(GeneAnnotData_Array[2]) - Convert.ToInt32(GeneAnnotData_Array[1]);
                }
                else
                {
                    //Add GeneID and its length.
                    GeneLength = Convert.ToInt32(GeneAnnotData_Array[2]) - Convert.ToInt32(GeneAnnotData_Array[1]);
                    GeneDataLength.Add(GeneName, GeneLength);
                }
            }
            //Linq query to get data present in disctionary.
            var items = from pair in GeneData
                        select pair;
            //Initialize KeyValuePair List for storing data from GeneData dictionary.
            List <KeyValuePair <string, int> > med1 = new List <KeyValuePair <string, int> >(items);
            //Linq query to get data present in disctionary.
            var items1 = from pair in GeneDataLength
                         select pair;
            //Initialize KeyValuePair List for storing data from GeneDataLength dictionary.
            List <KeyValuePair <string, int> > med2 = new List <KeyValuePair <string, int> >(items1);
            //Set read_Length value.
            int    read_length = readLength;
            double FinalValue  = 0.0;
            bool   present     = false;

            //Loop through the list which contains GeneID and its length values.
            foreach (KeyValuePair <string, int> GeneLengthValue  in med2)
            {
                //Loop through the list which contains GeneID and its mapped reads.
                foreach (KeyValuePair <string, int> GeneDataValue in med1)
                {
                    //Check if GeneID exists or not
                    if (GeneDataValue.Key == GeneLengthValue.Key)//&& GeneLengthValue.Key == "NR_026818")
                    {
                        //Calculate the mappability value in percentile.
                        double totaltiles = 0.0;
                        //if gene length less than or equal to current read length then set total tiles as 1 other wise calculate.
                        if (GeneLengthValue.Value <= read_length)
                        {
                            totaltiles = 1.0;
                        }
                        else
                        {
                            totaltiles = GeneLengthValue.Value - read_length + 1;
                        }
                        FinalValue = ((Convert.ToDouble(GeneDataValue.Value) / totaltiles)) * 100;
                        string vl = Math.Round(FinalValue, 2).ToString();
                        if (vl.IndexOf('.') != -1)
                        {
                            Values += GeneDataValue.Key + "$" + vl + ";";
                        }
                        else
                        {
                            Values += GeneDataValue.Key + "$" + vl + ".0" + ";";
                        }
                        present = true;
                    }
                }
                //Based on flag value above, if GeneID doesnt exists then we will set value as '0.0'
                if (!present)
                {
                    Values += GeneLengthValue.Key + "$" + "0.0;";
                    present = false;
                }
                else
                {
                    present = false;
                }
            }
        }
Exemplo n.º 8
0
    // Start is called before the first frame update
    void Start()
    {
        playerScript = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerScript>();

        // Pick 3 weighted genes.
        GeneID[] ids     = new List <GeneID>(Gene.SHOP_WEIGHT_LOOKUP.Keys).ToArray();
        float[]  weights = new float[ids.Length];
        for (int i = 0; i < ids.Length; i++)
        {
            GeneID id         = ids[i];
            float  baseWeight = Gene.SHOP_WEIGHT_LOOKUP[id];
            // No repeat powers.
            if (id == GeneID.Blink || id == GeneID.Glide)
            {
                weights[i] = playerScript.HasGene(id) ? 0 : baseWeight;
                continue;
            }
            if (id == GeneID.DoubleJump)
            {
                weights[i] = baseWeight / (1 + playerScript.NumGene(GeneID.DoubleJump));
                continue;
            }
            weights[i] = baseWeight;
        }
        float totalWeight = 0;

        foreach (float f in weights)
        {
            totalWeight += f;
        }
        List <GeneID> chosen = new List <GeneID>();

        while (chosen.Count < 4)
        {
            float selector    = Random.value * totalWeight;
            int   targetIndex = 0;
            for (; targetIndex < weights.Length; targetIndex++)
            {
                selector -= weights[targetIndex];
                if (selector < 0)
                {
                    break;
                }
            }
            GeneID id = ids[targetIndex];
            if (chosen.Contains(id))
            {
                continue;
            }
            chosen.Add(id);
        }

        float spacing = 2.5f / chosen.Count;

        for (int i = 0; i < chosen.Count; i++)
        {
            float      xMult    = i - (chosen.Count - 1) / 2;
            GameObject shopGene = Instantiate(shopGenePrefab, transform.parent, false);
            shopGene.transform.localPosition = new Vector3(xMult * spacing, -2);
            ShopGeneScript shopGeneScript = shopGene.GetComponent <ShopGeneScript>();
            shopGeneScript.SetID(chosen[i]);
        }
    }