/// <summary> /// Convenience method for testing and custom sequences. /// Converts the given string (if valid) into an array of nucleobases. /// </summary> /// <param name="s"></param> /// <returns></returns> public static Nucleobase[] StringSeq(String s) { Nucleobase[] seq = new Nucleobase[s.Length]; int i = 0; foreach (Char c in s) { if (Enum.TryParse(c.ToString(), out Nucleobase b)) { seq[i] = b; } else { throw new ArgumentException("input for quick sequences must only " + "contain characters which are valid elements of that sequence. Invalid" + "character: " + c); } i++; } if (seq.Contains(Nucleobase.U) && seq.Contains(Nucleobase.T)) { throw new ArgumentException("sequence should not contain both Thymine and Uracil"); } return(seq); }
/*public Gene(int type, int num) { * nucleobases = new Nucleobase[num]; * geneType = type; * DeriveBases (); * }*/ // Check for case where a base is already present public void AddBase(int num, Nucleobase b) { if (nucleobases [num] != b) { nucleobases [num] = b; DeriveType(); } }
void OnTriggerEnter2D(Collider2D col) { if (col.tag.Equals("Nucleobase")) { Nucleobase b = col.GetComponent <Nucleobase> (); //print ("Enter: " + gene + " " + slot + " " + b.value); b.QueueSlot(dna, gene, slot); } }
public void Setup(int baseVal) { GameObject nucleobase = GameObject.Instantiate(Resources.Load("bases/nucleobase"), new Vector3(), Quaternion.identity, transform) as GameObject; nucleobase.transform.localPosition = slotCol.offset; //nucleobase.transform.localScale = Vector3.Scale (GeneValues.basePrefab.transform.localScale, nucleobase.transform.lossyScale); nucleobase.transform.localScale = Vector3.Scale(((GameObject)Resources.Load("bases/nucleobase")).transform.localScale, new Vector3(1 / nucleobase.transform.parent.lossyScale.x, 1 / nucleobase.transform.parent.lossyScale.y, 0)); nucleobase.GetComponent <Nucleobase> ().value = baseVal; nb = nucleobase.GetComponent <Nucleobase>(); }
protected List<Nucleobase_View> list; // Serialized for debugging #endregion Fields #region Methods public Nucleobase_View GetNucleobaseOfType(Nucleobase.types type) { foreach (Nucleobase_View nv in availableForPlucking) { if (nv.getNucleobaseType () == type) { availableForPlucking.Remove(nv); return nv; } } return null; }
public void RemoveGene(int gene, int slot) { if (genes [gene].HasBase(slot)) { Nucleobase b = genes [gene].RemoveBase(slot); slots [gene, slot].RemoveBase(); b.transform.parent = looseNucleobases.transform; //print ("Processing Removal"); } ProcessDNA(); }
public Nucleobase RemoveBase(int num) { Nucleobase b = nucleobases [num]; if (b) { nucleobases [num] = null; DeriveType(); } return(b); }
//TODO generalize these two methods public static Nucleobase[] ReverseTranscribe(Nucleobase[] r) { Nucleobase[] d = new Nucleobase[r.Length]; for (int i = 0; i < r.Length; i++) { if (r[i].Equals(Nucleobase.U)) { d[i] = Nucleobase.T; } else { d[i] = r[i]; } } return(d); }
/// <summary> /// transcribes the given dna sequence into rna, replacing /// instances of T with U. Preserves the initial strand /// </summary> /// <param name="d">DNA strand to be transcribed</param> /// <returns>new RNA strand</returns> public static Nucleobase[] Transcribe(Nucleobase[] d) { Nucleobase[] r = new Nucleobase[d.Length]; for (int i = 0; i < d.Length; i++) { if (d[i].Equals(Nucleobase.T)) { r[i] = Nucleobase.U; } else { r[i] = d[i]; } } return(r); }
/// <summary> /// Generates a random sequence of appropriate nucleobases /// based on the given length and specified type /// </summary> /// <param name="len">length of desired sequence</param> /// <param name="t">type of sequence</param> /// <returns>Returns the newly generated sequence</returns> private static Nucleobase[] GenerateSequence(int len, SequenceType t) { if (len < 1) { throw new ArgumentException("Sequence length must be greater than 0"); } /* * base indices: * 0 T * 1 C * 2 G * 3 A * 4 U */ int baseStart; // defines the index of the first base in the set of bases to build the sequence with int baseEnd; // defines the index of the last base " " " Nucleobase[] seq = new Nucleobase[len]; Random randall = new Random(); switch (t) { case SequenceType.DNA: baseStart = 0; baseEnd = 3; break; case SequenceType.RNA: baseStart = 1; baseEnd = 4; break; default: throw new ArgumentException("sequence type must be either DNA or RNA"); } for (int i = 0; i < len; i++) { seq[i] = (Nucleobase)randall.Next(baseStart, baseEnd + 1); } return(seq); }
public void AddToGene(int gene, int slot, Nucleobase b) { // Take care of overlap nucleo bases if (genes [gene].HasBase(slot)) { Nucleobase oldB = genes [gene].RemoveBase(slot); b.transform.parent = looseNucleobases.transform; oldB.transform.position = oldB.startLoc; // Break nucleobase ties to dna oldB.UnqueueSlot(this); //print ("Processing Forced Removal"); } genes [gene].AddBase(slot, b); slots [gene, slot].AddBase(b); b.transform.parent = slots[gene, slot].transform; b.transform.localPosition = slots[gene, slot].GetComponent <Collider2D>().offset; //print ("Processing Addition"); ProcessDNA(); }
void AddNucleobases() { SpriteRenderer nSprite = ((GameObject)Resources.Load("bases/nucleobase")).GetComponent <SpriteRenderer>(); Vector3 nSize = Vector3.Scale(nSprite.sprite.bounds.size, nSprite.transform.localScale); Vector3 nCenter = nSize / 2; nCenter.y = -nCenter.y; Vector3 pos = new Vector3(UI.inventoryBounds.x, UI.inventoryBounds.y + UI.inventoryBounds.w, 0); for (int i = 0; i < looseNucleobaseDefaults.Length; i++) { Nucleobase n = ((GameObject)GameObject.Instantiate(nSprite.gameObject, pos + nCenter, Quaternion.identity, ((GameObject)GameObject.Find("NucleobaseHolder")).transform)).GetComponent <Nucleobase>(); n.value = looseNucleobaseDefaults [i]; pos.x += nSize.x; if (pos.x + nSize.x >= UI.inventoryBounds.x + UI.inventoryBounds.z) { pos.x = UI.inventoryBounds.x; pos.y -= nSize.y; } } }
public void RemoveBase() { nb = null; }
public void AddBase(Nucleobase b) { nb = b; }
public Nucleobase_View SpawnNucleobaseFromType(Nucleobase.types type) { switch (type) { case Nucleobase.types.A: return Instantiate(AdeninePrefab).GetComponent<Nucleobase_View>(); case Nucleobase.types.C: return Instantiate(CytosinePrefab).GetComponent<Nucleobase_View>(); case Nucleobase.types.G: return Instantiate(GuaninePrefab).GetComponent<Nucleobase_View>(); case Nucleobase.types.T: return Instantiate(ThyminePrefab).GetComponent<Nucleobase_View>(); default: throw new System.Exception ("Invalid Nucleobase type!"); } }