From 759d83a940b86333a264437462a2b0c8bc662d97 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Wed, 14 Jan 2015 16:36:34 +0000 Subject: [PATCH] JAL-1619 AlignedCodonFrame in new alignment should references realigned sequences --- src/jalview/datamodel/AlignedCodonFrame.java | 96 +++++++++++++++++--------- src/jalview/ws/AWSThread.java | 9 +-- 2 files changed, 69 insertions(+), 36 deletions(-) diff --git a/src/jalview/datamodel/AlignedCodonFrame.java b/src/jalview/datamodel/AlignedCodonFrame.java index 4016ee5..f65f068 100644 --- a/src/jalview/datamodel/AlignedCodonFrame.java +++ b/src/jalview/datamodel/AlignedCodonFrame.java @@ -22,16 +22,16 @@ package jalview.datamodel; import jalview.util.MapList; -import java.util.Enumeration; -import java.util.Vector; +import java.util.ArrayList; +import java.util.List; /** * Stores mapping between the columns of a protein alignment and a DNA alignment * and a list of individual codon to amino acid mappings between sequences. */ - public class AlignedCodonFrame { + /** * array of nucleotide positions for aligned codons at column of aligned * proteins. @@ -44,6 +44,25 @@ public class AlignedCodonFrame */ public int aaWidth = 0; + /* + * TODO: not an ideal solution - we reference the aligned amino acid sequences + * in order to make insertions on them Better would be dnaAlignment and + * aaAlignment reference.... + */ + private List a_aaSeqs = new ArrayList(); + + /* + * tied array of na Sequence objects. + */ + private SequenceI[] dnaSeqs = null; + + /* + * tied array of Mappings to protein sequence Objects and SequenceI[] + * aaSeqs=null; MapLists where eac maps from the corresponding dnaSeqs element + * to corresponding aaSeqs element + */ + private Mapping[] dnaToProt = null; + /** * initialise codon frame with a nominal alignment width * @@ -64,6 +83,41 @@ public class AlignedCodonFrame } /** + * Construct a 'near copy' of the given AlignedCodonFrame, that references the + * same dataset sequences, but the given protein aligned sequences. + * + * @param acf + * @param alignment + * @throws IllegalStateException + * if the copied mapping references any dataset not in the alignment + */ + public AlignedCodonFrame(AlignedCodonFrame acf, SequenceI[] alignment) + { + this.codons = acf.codons; + this.dnaSeqs = acf.dnaSeqs; + this.dnaToProt = acf.dnaToProt; + + for (SequenceI seq : acf.a_aaSeqs) + { + boolean found = false; + for (SequenceI newseq : alignment) + { + if (seq.getDatasetSequence() == newseq.getDatasetSequence()) + { + this.a_aaSeqs.add(newseq); + found = true; + break; + } + } + if (!found) + { + throw new IllegalStateException("Copying codon mapping for" + + seq.getSequenceAsString()); + } + } + } + + /** * ensure that codons array is at least as wide as aslen residues * * @param aslen @@ -94,13 +148,6 @@ public class AlignedCodonFrame } /** - * TODO: not an ideal solution - we reference the aligned amino acid sequences - * in order to make insertions on them Better would be dnaAlignment and - * aaAlignment reference.... - */ - Vector a_aaSeqs = new Vector(); - - /** * increase aaWidth by one and insert a new aligned codon position space at * aspos. * @@ -111,16 +158,13 @@ public class AlignedCodonFrame // this aa appears before the aligned codons at aspos - so shift them in // each pair of mapped sequences aaWidth++; - if (a_aaSeqs != null) + // we actually have to modify the aligned sequences here, so use the + // a_aaSeqs vector + for (SequenceI seq : a_aaSeqs) { - // we actually have to modify the aligned sequences here, so use the - // a_aaSeqs vector - Enumeration sq = a_aaSeqs.elements(); - while (sq.hasMoreElements()) - { - ((SequenceI) sq.nextElement()).insertCharAt(aspos, gapCharacter); - } + seq.insertCharAt(aspos, gapCharacter); } + checkCodonFrameWidth(aspos); if (aspos < aaWidth) { @@ -137,18 +181,6 @@ public class AlignedCodonFrame } /** - * tied array of na Sequence objects. - */ - SequenceI[] dnaSeqs = null; - - /** - * tied array of Mappings to protein sequence Objects and SequenceI[] - * aaSeqs=null; MapLists where eac maps from the corresponding dnaSeqs element - * to corresponding aaSeqs element - */ - Mapping[] dnaToProt = null; - - /** * add a mapping between the dataset sequences for the associated dna and * protein sequence objects * @@ -181,7 +213,7 @@ public class AlignedCodonFrame // aaseq.transferAnnotation(dnaseq, new Mapping(map.getInverse())); mp.to = (aaseq.getDatasetSequence() == null) ? aaseq : aaseq .getDatasetSequence(); - a_aaSeqs.addElement(aaseq); + a_aaSeqs.add(aaseq); dnaToProt[nlen] = mp; } @@ -261,7 +293,7 @@ public class AlignedCodonFrame { // TODO very fragile - depends on dnaSeqs, dnaToProt, a_aaSeqs moving // in parallel; revise data model to guarantee this - return (SequenceI) a_aaSeqs.elementAt(ds); + return a_aaSeqs.get(ds); } } } diff --git a/src/jalview/ws/AWSThread.java b/src/jalview/ws/AWSThread.java index edb56a9..7f05e90 100644 --- a/src/jalview/ws/AWSThread.java +++ b/src/jalview/ws/AWSThread.java @@ -27,8 +27,8 @@ import jalview.datamodel.AlignmentI; import jalview.datamodel.AlignmentView; import jalview.datamodel.SequenceI; import jalview.gui.AlignFrame; -import jalview.gui.WebserviceInfo; import jalview.gui.FeatureRenderer.FeatureRendererSettings; +import jalview.gui.WebserviceInfo; import jalview.util.MessageManager; public abstract class AWSThread extends Thread @@ -297,10 +297,11 @@ public abstract class AWSThread extends Thread { for (int i = 0; i < codonframe.length; i++) { - if (codonframe[i] != null - && codonframe[i].involvesSequence(alignment[sq])) + AlignedCodonFrame acf = codonframe[i]; + final SequenceI seq = alignment[sq]; + if (acf != null && acf.involvesSequence(seq)) { - al.addCodonFrame(codonframe[i]); + al.addCodonFrame(new AlignedCodonFrame(acf, alignment)); codonframe[i] = null; break; } -- 1.7.10.2