public void BuildTexture() //, ParseDNA parseDNA) { //this.DNA_Model = parseDNA; { Debug.Log("inside build texture"); string[] val = DNA_Model.data[key]; string sequence = val[1]; var texture = new Texture2D(textureX, textureY, TextureFormat.BGRA32, true); GetComponent <Renderer>().material.mainTexture = texture; texture.SetPixel(textureX, textureY, Color.black); // mark the end of this texture. Debug.Log("sequence: " + sequence); for (int i = 0; i < sequence.Length; i++) { Nuc n = Nucleotide.CharToNuc(sequence[i]); texture.SetPixel(i % textureX, i / textureX, Nucleotide.defaultColor[n]); } texture.filterMode = FilterMode.Point; texture.Apply(); }
public virtual Nuc[] RandomDNA(int length) { Nuc[] array = new Nuc[length]; for (int i = 0; i < length; i++) { array[i] = GetRandomNuc(); } return(array); }
//NOTICE: VERY SIMILAR TO GETPEPTIDE. @todo: create a common helper function for these two functions. public int getPeptidePos(string name, int pos, Nuc n, Seq type) { Debug.Log("getPeptidePos"); int index; int offset = 0; FASTAModel m = registerModel(type); //lol if (m.GetType() == typeof(RNAModel)) { offset = (m as RNAModel).exonStartIndices[0]; } else //dna model, uses start index. { offset = (m as DNAModel).indexStart; } string key = name + "," + name + ":" + type.ToString() + "," + Seq.AA.ToString(); if (currentAlignment == null || !currentAlignment.id.Equals(key)) { Consensus alignment; Debug.Log("getPeptidePos, key: " + key); if (alignments.TryGetValue(key, out alignment)) { currentAlignment = alignment; } else //make the alignment object. { if (proteinSeq == null) { registerProteinModel(); } alignment = seqAligner.alignTo3DProtein(name, type, proteinSeq._3DSeq); alignment.id = key; alignments[key] = alignment; //warning, overwrite the old val at the given key! } currentAlignment = alignment; index = alignment.getResNum(pos - offset, n); } else { index = currentAlignment.getResNum(pos - offset, n); if (index == -1) { Debug.Log("incorrect!!"); } } return(index); }
public int getResNum(int pos, Nuc n) { if (nucXaa.Count == 0) { AAConsensusNucList(); } Debug.Log("pos: " + pos); Debug.Log("nucXaa[0]: " + nucXaa[0]); Debug.Log(" nucXaa[0].Length: " + nucXaa[0].Length); string nuc = Char.ToString(nucXaa[0][pos]); if (Nucleotide.NucToStr(n).Equals(nuc)) //matches our data struct, implying correct alignment { return(pos / 3); } else { //something wrong //NOTE: it could be the case that the alignment went like so: // 012 345 678 9 // ATG | GAG | --- | GTA | GGT | //sequence mRNA // M | somehting | L | something | something //sequence according to 3D protein // ^ // therefore getResNum(6, G) now refers to ---, L. instead of G of the original pos 6. // such cases all fall into this branch. string _1stStr = nucXaa[0]; int numDashes = 0; for (int i = 0; i < pos; i++) { if (_1stStr[i].Equals('-')) { numDashes++; } if (i == pos - 1 && numDashes % 3 != 0) //eg : --- | -- - | { numDashes = ((numDashes / 3) + 1) * 3; // ^ } } Debug.Log("numDashes: " + numDashes); nuc = Char.ToString(nucXaa[0][pos + numDashes]); if (Nucleotide.NucToStr(n).Equals(nuc)) { return((pos + numDashes) / 3); } Debug.Log("residue can't be found in Consensus for the given seq position in RNA."); return(-1); } }
public virtual void Mutate(int chromosome, int index, Nuc newNuc) { if (Count() - 1 > chromosome) { return; } var chr = Chromosomes.ElementAt(chromosome); if (chr.Length < index) { return; } chr[index] = newNuc; }
private void button1_Click(object sender, EventArgs e) { if (textBox1.Text.IsEmpty()) { Log("请输入设备IP"); return; } constrant = new Constrant(); constrant.Init(textBox1.Text); nuc = new Nuc(constrant); button1.Enabled = false; groupBox1.Enabled = true; groupBox2.Enabled = true; groupBox3.Enabled = true; groupBox4.Enabled = true; }
//niceName: rattus, mus musculus, etc. //int pos: the position we are interested in //Nuc n : whether it's A|T|C|G //Seq type: DNA or RNA. shouldn't be AA. public string getPeptide(string name, int pos, Nuc n, Seq type) { string result; string key = name + "," + name + ":" + type.ToString() + "," + Seq.AA.ToString(); int index; int offset = 0; FASTAModel m = registerModel(type); //could be either DNA or RNA. if (m.GetType() == typeof(RNAModel)) { offset = (m as RNAModel).exonStartIndices[0]; } else //dna model, uses start index. { offset = (m as DNAModel).indexStart; } Consensus alignment; if (!alignments.TryGetValue(key, out alignment)) //alignment is null, create one. { if (proteinSeq == null) { registerProteinModel(); } Debug.Log("inside getPeptide"); alignment = seqAligner.alignTo3DProtein(name, type, proteinSeq._3DSeq); alignment.id = key; alignments[key] = alignment; } else { // (alignment != null) } index = alignment.getResNum(pos - offset, n); if (index == -1) { return("-"); } result = proteinSeq._3DSeq[index].name; return(result); }
public void BuildCDSTexture(List <string> cds) { Debug.Log("inside build CDS texture"); string sequence1 = cds[0]; string sequence2 = cds[1]; var texture = new Texture2D(textureX, textureY, TextureFormat.BGRA32, true); GetComponent <Renderer>().material.mainTexture = texture; //@todo: get new textureX, textureY values from alignment. texture.SetPixel(textureX, textureY, Color.black); // mark the end of this texture. Debug.Log("sequence2: " + sequence2); if (sequence1.Length != sequence2.Length) { throw new Exception("two sequences from alignment are not the same length."); } for (int i = 0; i < sequence1.Length; i++) { Nuc n1 = Nucleotide.CharToNuc(sequence1[i]); Nuc n2 = Nucleotide.CharToNuc(sequence2[i]); if (n1 == n2) { texture.SetPixel(i % textureX, i / textureX, Nucleotide.litColor[n1]); } else { texture.SetPixel(i % textureX, i / textureX, Nucleotide.dimColor[n1]); } } texture.filterMode = FilterMode.Point; texture.Apply(); }
public static string NucToStr(Nuc n) { //PetType pet = (PetType)Enum.Parse(typeof(PetType), value); // See if the conversion succeeded: if (pet == PetType.Dog) return(n.ToString()); }
public virtual ActionMethod SelectAction(Nuc[] tr) { Nuc f = tr[0]; Nuc s = tr[1]; Nuc t = tr[2]; if (f == Nuc.A) { if (s == Nuc.A) { var r = new ActionMethod(MoveAction); if (t == Nuc.A) { ActionIndex = 1; } else if (t == Nuc.T) { ActionIndex = 2; } else if (t == Nuc.C) { ActionIndex = 3; } else { ActionIndex = 4; } return(r); } else if (s == Nuc.T) { var r = new ActionMethod(MoveAction); if (t == Nuc.A) { ActionIndex = 5; } else if (t == Nuc.T) { ActionIndex = 6; } else if (t == Nuc.C) { ActionIndex = 7; } else { ActionIndex = 8; } return(r); } else if (s == Nuc.C) { var r = new ActionMethod(FightAction); if (t == Nuc.A) { ActionIndex = 1; } else if (t == Nuc.T) { ActionIndex = 2; } else if (t == Nuc.C) { ActionIndex = 3; } else { ActionIndex = 4; } return(r); } else { var r = new ActionMethod(FightAction); if (t == Nuc.A) { ActionIndex = 5; } else if (t == Nuc.T) { ActionIndex = 6; } else if (t == Nuc.C) { ActionIndex = 7; } else { ActionIndex = 8; } return(r); } } else if (f == Nuc.T) { if (s == Nuc.A) { var r = new ActionMethod(WatchAction); if (t == Nuc.A) { ActionIndex = 1; } else if (t == Nuc.T) { ActionIndex = 2; } else if (t == Nuc.C) { ActionIndex = 3; } else { ActionIndex = 4; } return(r); } else if (s == Nuc.T) { var r = new ActionMethod(WatchAction); if (t == Nuc.A) { ActionIndex = 5; } else if (t == Nuc.T) { ActionIndex = 6; } else if (t == Nuc.C) { ActionIndex = 7; } else { ActionIndex = 8; } return(r); } if (s == Nuc.C) { var r = new ActionMethod(ActivateAction); if (t == Nuc.A) { ActionIndex = 1; } else if (t == Nuc.T) { ActionIndex = 2; } else if (t == Nuc.C) { ActionIndex = 3; } else { ActionIndex = 4; } return(r); } else if (s == Nuc.G) { var r = new ActionMethod(ActivateAction); if (t == Nuc.A) { ActionIndex = 5; } else if (t == Nuc.T) { ActionIndex = 6; } else if (t == Nuc.C) { ActionIndex = 7; } else { ActionIndex = 8; } return(r); } } else if (f == Nuc.C) { if (s == Nuc.A) { var r = new ActionMethod(Duplicate); if (t == Nuc.A) { ActionIndex = 1; } else if (t == Nuc.T) { ActionIndex = 2; } else if (t == Nuc.C) { ActionIndex = 3; } else { ActionIndex = 4; } return(r); } else if (s == Nuc.T) { var r = new ActionMethod(Duplicate); if (t == Nuc.A) { ActionIndex = 5; } else if (t == Nuc.T) { ActionIndex = 6; } else if (t == Nuc.C) { ActionIndex = 7; } else { ActionIndex = 8; } return(r); } } ActionIndex = 0; return(new ActionMethod(SleepAction)); }
public virtual int Skip(Nuc[] tr) { if (tr.Length != 3) { return(0); } Nuc f = tr[0]; Nuc s = tr[1]; Nuc t = tr[2]; if (f == Nuc.A) { if (s == Nuc.A) { return(1); } else if (s == Nuc.T) { return(2); } else if (s == Nuc.C) { return(3); } else if (s == Nuc.G) { return(4); } else { return(0); } } else if (f == Nuc.T) { if (s == Nuc.A) { return(5); } else if (s == Nuc.T) { return(6); } else if (s == Nuc.C) { return(7); } else if (s == Nuc.G) { return(8); } else { return(0); } } else if (f == Nuc.C) { if (s == Nuc.A) { return(-1); } else if (s == Nuc.T) { return(-2); } else if (s == Nuc.C) { return(-3); } else if (s == Nuc.G) { return(-4); } else { return(0); } } else if (f == Nuc.G) { if (s == Nuc.A) { return(-5); } else if (s == Nuc.T) { return(-6); } else if (s == Nuc.C) { return(-7); } else if (s == Nuc.G) { return(-8); } else { return(0); } } return(0); }