package jalview.datamodel;\r
\r
+import java.util.Enumeration;\r
+import java.util.Vector;\r
+\r
import jalview.util.MapList;\r
\r
/**\r
*/\r
public AlignedCodonFrame(int aWidth)\r
{\r
+ if (aWidth<=0)\r
+ {\r
+ codons=null;\r
+ return;\r
+ }\r
codons = new int[aWidth][];\r
for (int res = 0; res < aWidth; res++)\r
codons[res] = null;\r
return aaWidth;\r
}\r
/**\r
+ * TODO: not an ideal solution - we reference the aligned amino acid sequences in order to make insertions on them\r
+ * Better would be dnaAlignment and aaAlignment reference....\r
+ */\r
+ Vector a_aaSeqs=new Vector();\r
+ /**\r
* increase aaWidth by one and insert a new aligned codon position space at aspos.\r
* @param aspos\r
*/\r
{ \r
// this aa appears before the aligned codons at aspos - so shift them in each pair of mapped sequences\r
aaWidth++;\r
- for (int sq=0;aaSeqs!=null && sq<aaSeqs.length; sq++) {\r
- aaSeqs[sq].insertCharAt(aspos, gapCharacter);\r
+ if (a_aaSeqs!=null)\r
+ {\r
+ // we actually have to modify the aligned sequences here, so use the a_aaSeqs vector\r
+ Enumeration sq = a_aaSeqs.elements();\r
+ while (sq.hasMoreElements())\r
+ {\r
+ ((SequenceI) sq.nextElement()).insertCharAt(aspos, gapCharacter);\r
+ }\r
}\r
-\r
checkCodonFrameWidth(aspos);\r
if (aspos<aaWidth)\r
{\r
*/\r
SequenceI[] dnaSeqs=null;\r
/**\r
- * tied array of protein sequence Objects\r
+ * tied array of Mappings to protein sequence Objects and \r
+ SequenceI[] aaSeqs=null;\r
+ * MapLists where eac maps from the corresponding dnaSeqs element to corresponding aaSeqs element \r
*/\r
- SequenceI[] aaSeqs=null;\r
+ Mapping[] dnaToProt=null;\r
/**\r
- * tied array of MapLists where eac maps from the corresponding dnaSeqs element to corresponding aaSeqs element \r
+ * add a mapping between the dataset sequences for the associated dna and protein sequence objects\r
+ * @param dnaseq\r
+ * @param aaseq\r
+ * @param map\r
*/\r
- MapList[] dnaToProt=null;\r
- \r
public void addMap(SequenceI dnaseq, SequenceI aaseq, MapList map)\r
{ \r
int nlen=1;\r
nlen = dnaSeqs.length+1;\r
}\r
SequenceI[] ndna = new SequenceI[nlen];\r
- SequenceI[] naa = new SequenceI[nlen];\r
- MapList[] ndtp = new MapList[nlen];\r
+ Mapping[] ndtp = new Mapping[nlen];\r
if (dnaSeqs!=null)\r
{\r
System.arraycopy(dnaSeqs,0,ndna, 0, dnaSeqs.length);\r
- System.arraycopy(aaSeqs,0,naa, 0, dnaSeqs.length);\r
System.arraycopy(dnaToProt,0,ndtp, 0, dnaSeqs.length);\r
}\r
dnaSeqs = ndna;\r
- aaSeqs = naa;\r
dnaToProt = ndtp;\r
nlen--;\r
dnaSeqs[nlen] = (dnaseq.getDatasetSequence()==null) ? dnaseq : dnaseq.getDatasetSequence();\r
- aaSeqs[nlen] = (aaseq.getDatasetSequence()==null) ? aaseq : aaseq.getDatasetSequence();\r
- dnaToProt[nlen] = map;\r
+ Mapping mp = new Mapping(map);\r
+ mp.to = (aaseq.getDatasetSequence()==null) ? aaseq : aaseq.getDatasetSequence();\r
+ a_aaSeqs.addElement(aaseq);\r
+ dnaToProt[nlen] = mp;\r
}\r
\r
\r
}\r
public SequenceI[] getAaSeqs()\r
{\r
- return aaSeqs;\r
+ if (dnaToProt==null)\r
+ return null;\r
+ SequenceI[] sqs = new SequenceI[dnaToProt.length];\r
+ for (int sz=0; sz<dnaToProt.length; sz++)\r
+ {\r
+ sqs[sz] = dnaToProt[sz].to;\r
+ }\r
+ return sqs;\r
}\r
public MapList[] getdnaToProt()\r
{\r
+ if (dnaToProt==null)\r
+ return null;\r
+ MapList[] sqs = new MapList[dnaToProt.length];\r
+ for (int sz=0; sz<dnaToProt.length; sz++)\r
+ {\r
+ sqs[sz] = dnaToProt[sz].map;\r
+ }\r
+ return sqs;\r
+ }\r
+ public Mapping[] getProtMappings()\r
+ {\r
return dnaToProt;\r
}\r
/**\r
for (int ds=0;ds<dnaSeqs.length; ds++)\r
{\r
if (dnaSeqs[ds]==dnaSeqRef || dnaSeqs[ds]==dnads)\r
- return aaSeqs[ds];\r
+ return dnaToProt[ds].to;\r
}\r
return null;\r
}\r
*/\r
public SequenceI getDnaForAaSeq(SequenceI aaSeqRef)\r
{\r
- if (aaSeqs==null)\r
+ if (dnaToProt==null)\r
{\r
return null;\r
}\r
SequenceI aads = aaSeqRef.getDatasetSequence();\r
- for (int as=0;as<aaSeqs.length; as++)\r
+ for (int as=0;as<dnaToProt.length; as++)\r
{\r
- if (aaSeqs[as]==aaSeqRef || aaSeqs[as]==aads)\r
+ if (dnaToProt[as].to==aaSeqRef || dnaToProt[as].to==aads)\r
return dnaSeqs[as];\r
}\r
return null;\r
{\r
int[] codon;\r
SequenceI ds = seq.getDatasetSequence();\r
- for (int mi = 0; mi<aaSeqs.length; mi++)\r
+ for (int mi = 0; mi<dnaToProt.length; mi++)\r
{\r
if (dnaSeqs[mi]==seq || dnaSeqs[mi]==ds)\r
{\r
// DEBUG System.err.println("dna pos "+index);\r
- codon = dnaToProt[mi].locateInTo(index,index);\r
+ codon = dnaToProt[mi].map.locateInTo(index,index);\r
if (codon!=null)\r
{\r
for (int i=0; i<codon.length; i+=2)\r
{\r
- results.addResult(aaSeqs[mi], codon[i], codon[i+1]);\r
+ results.addResult(dnaToProt[mi].to, codon[i], codon[i+1]);\r
}\r
}\r
} else\r
- if (aaSeqs[mi]==seq || aaSeqs[mi]==ds)\r
+ if (dnaToProt[mi].to==seq || dnaToProt[mi].to==ds)\r
{\r
// DEBUG System.err.println("aa pos "+index);\r
{\r
- codon = dnaToProt[mi].locateInFrom(index, index);\r
+ codon = dnaToProt[mi].map.locateInFrom(index, index);\r
if (codon!=null)\r
{\r
for (int i=0; i<codon.length; i+=2)\r