1 package jalview.datamodel;
\r
3 import jalview.util.MapList;
\r
6 * Stores mapping between the columns of a protein alignment and a DNA alignment
\r
7 * and a list of individual codon to amino acid mappings between sequences.
\r
10 public class AlignedCodonFrame
\r
13 * array of nucleotide positions for aligned codons at column of aligned proteins.
\r
15 public int[][] codons = null;
\r
17 * width of protein sequence alignement
\r
18 * implicit assertion that codons.length >= aaWidth
\r
20 public int aaWidth=0;
\r
22 * initialise codon frame with a nominal alignment width
\r
25 public AlignedCodonFrame(int aWidth)
\r
27 codons = new int[aWidth][];
\r
28 for (int res = 0; res < aWidth; res++)
\r
33 * ensure that codons array is at least as wide as aslen residues
\r
35 * @return (possibly newly expanded) codon array
\r
37 public int[][] checkCodonFrameWidth(int aslen)
\r
39 if (codons.length <= aslen + 1)
\r
41 // probably never have to do this ?
\r
42 int[][] c = new int[codons.length + 10][];
\r
43 for (int i = 0; i < codons.length; i++)
\r
53 * @return width of aligned translated amino acid residues
\r
55 public int getaaWidth()
\r
60 * increase aaWidth by one and insert a new aligned codon position space at aspos.
\r
63 public void insertAAGap(int aspos, char gapCharacter)
\r
65 // this aa appears before the aligned codons at aspos - so shift them in each pair of mapped sequences
\r
67 for (int sq=0;aaSeqs!=null && sq<aaSeqs.length; sq++) {
\r
68 aaSeqs[sq].insertCharAt(aspos, gapCharacter);
\r
71 checkCodonFrameWidth(aspos);
\r
75 System.arraycopy(codons, aspos, codons, aspos+1, aaWidth-aspos);
\r
76 codons[aspos]=null; // clear so new codon position can be marked.
\r
80 public void setAaWidth(int aapos)
\r
85 * tied array of na Sequence objects.
\r
87 SequenceI[] dnaSeqs=null;
\r
89 * tied array of protein sequence Objects
\r
91 SequenceI[] aaSeqs=null;
\r
93 * tied array of MapLists where eac maps from the corresponding dnaSeqs element to corresponding aaSeqs element
\r
95 MapList[] dnaToProt=null;
\r
97 public void addMap(SequenceI dnaseq, SequenceI aaseq, MapList map)
\r
102 nlen = dnaSeqs.length+1;
\r
104 SequenceI[] ndna = new SequenceI[nlen];
\r
105 SequenceI[] naa = new SequenceI[nlen];
\r
106 MapList[] ndtp = new MapList[nlen];
\r
109 System.arraycopy(dnaSeqs,0,ndna, 0, dnaSeqs.length);
\r
110 System.arraycopy(aaSeqs,0,naa, 0, dnaSeqs.length);
\r
111 System.arraycopy(dnaToProt,0,ndtp, 0, dnaSeqs.length);
\r
117 dnaSeqs[nlen] = (dnaseq.getDatasetSequence()==null) ? dnaseq : dnaseq.getDatasetSequence();
\r
118 aaSeqs[nlen] = (aaseq.getDatasetSequence()==null) ? aaseq : aaseq.getDatasetSequence();
\r
119 dnaToProt[nlen] = map;
\r
123 public SequenceI[] getdnaSeqs()
\r
127 public SequenceI[] getAaSeqs()
\r
131 public MapList[] getdnaToProt()
\r
137 * @param sequenceRef
\r
138 * @return null or corresponding aaSeq entry for dnaSeq entry
\r
140 public SequenceI getAaForDnaSeq(SequenceI dnaSeqRef)
\r
146 SequenceI dnads = dnaSeqRef.getDatasetSequence();
\r
147 for (int ds=0;ds<dnaSeqs.length; ds++)
\r
149 if (dnaSeqs[ds]==dnaSeqRef || dnaSeqs[ds]==dnads)
\r
156 * @param sequenceRef
\r
157 * @return null or corresponding aaSeq entry for dnaSeq entry
\r
159 public SequenceI getDnaForAaSeq(SequenceI aaSeqRef)
\r
165 SequenceI aads = aaSeqRef.getDatasetSequence();
\r
166 for (int as=0;as<aaSeqs.length; as++)
\r
168 if (aaSeqs[as]==aaSeqRef || aaSeqs[as]==aads)
\r
169 return dnaSeqs[as];
\r
174 * test to see if codon frame involves seq in any way
\r
175 * @param seq a nucleotide or protein sequence
\r
176 * @return true if a mapping exists to or from this sequence to any translated sequence
\r
178 public boolean involvesSequence(SequenceI seq)
\r
180 return getAaForDnaSeq(seq)!=null || getDnaForAaSeq(seq)!=null;
\r
183 * Add search results for regions in other sequences that translate or are translated from a particular position in seq
\r
185 * @param index position in seq
\r
186 * @param results where highlighted regions go
\r
188 public void markMappedRegion(SequenceI seq, int index, SearchResults results)
\r
191 SequenceI ds = seq.getDatasetSequence();
\r
192 for (int mi = 0; mi<aaSeqs.length; mi++)
\r
194 if (dnaSeqs[mi]==seq || dnaSeqs[mi]==ds)
\r
196 // DEBUG System.err.println("dna pos "+index);
\r
197 codon = dnaToProt[mi].locateInTo(index,index);
\r
200 for (int i=0; i<codon.length; i+=2)
\r
202 results.addResult(aaSeqs[mi], codon[i], codon[i+1]);
\r
206 if (aaSeqs[mi]==seq || aaSeqs[mi]==ds)
\r
208 // DEBUG System.err.println("aa pos "+index);
\r
210 codon = dnaToProt[mi].locateInFrom(index, index);
\r
213 for (int i=0; i<codon.length; i+=2)
\r
215 results.addResult(dnaSeqs[mi], codon[i], codon[i+1]);
\r