From: gmungoc Date: Tue, 22 Dec 2015 09:21:22 +0000 (+0000) Subject: JAL-653 realise virtual mappings and align when adding sequences X-Git-Tag: Release_2_10_0~296^2~102 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=49428d3a57e4f4863acbdeb3f77049ed95efd6c3;p=jalview.git JAL-653 realise virtual mappings and align when adding sequences --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 3f9f03f..1134857 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -22,13 +22,14 @@ package jalview.datamodel; import jalview.analysis.AlignmentUtils; import jalview.io.FastaFile; +import jalview.util.Comparison; import jalview.util.MessageManager; import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashSet; import java.util.Hashtable; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -47,8 +48,7 @@ public class Alignment implements AlignmentI protected List sequences; - protected List groups = java.util.Collections - .synchronizedList(new ArrayList()); + protected List groups; protected char gapCharacter = '-'; @@ -60,20 +60,21 @@ public class Alignment implements AlignmentI public boolean hasRNAStructure = false; - /** DOCUMENT ME!! */ public AlignmentAnnotation[] annotations; - HiddenSequences hiddenSequences = new HiddenSequences(this); + HiddenSequences hiddenSequences; public Hashtable alignmentProperties; - private Set codonFrameList = new LinkedHashSet(); + private List codonFrameList; private void initAlignment(SequenceI[] seqs) { - int i = 0; + groups = Collections.synchronizedList(new ArrayList()); + hiddenSequences = new HiddenSequences(this); + codonFrameList = new ArrayList(); - if (jalview.util.Comparison.isNucleotide(seqs)) + if (Comparison.isNucleotide(seqs)) { type = NUCLEOTIDE; } @@ -82,10 +83,9 @@ public class Alignment implements AlignmentI type = PROTEIN; } - sequences = java.util.Collections - .synchronizedList(new ArrayList()); + sequences = Collections.synchronizedList(new ArrayList()); - for (i = 0; i < seqs.length; i++) + for (int i = 0; i < seqs.length; i++) { sequences.add(seqs[i]); } @@ -104,13 +104,12 @@ public class Alignment implements AlignmentI seqs[i] = new Sequence(seqs[i]); } + initAlignment(seqs); + /* - * Share the same dataset sequence mappings (if any). TODO: find a better - * place for these to live (alignment dataset?). + * Share the same dataset sequence mappings (if any). */ this.setCodonFrames(al.getCodonFrames()); - - initAlignment(seqs); } /** @@ -1281,8 +1280,8 @@ public class Alignment implements AlignmentI @Override public void addCodonFrame(AlignedCodonFrame codons) { - Set acfs = getCodonFrames(); - if (codons != null && acfs != null) + List acfs = getCodonFrames(); + if (codons != null && acfs != null && !acfs.contains(codons)) { acfs.add(codons); } @@ -1319,7 +1318,7 @@ public class Alignment implements AlignmentI * @see jalview.datamodel.AlignmentI#setCodonFrames() */ @Override - public void setCodonFrames(Set acfs) + public void setCodonFrames(List acfs) { if (dataset != null) { @@ -1339,7 +1338,7 @@ public class Alignment implements AlignmentI * @see jalview.datamodel.AlignmentI#getCodonFrames() */ @Override - public Set getCodonFrames() + public List getCodonFrames() { return dataset != null ? dataset.getCodonFrames() : codonFrameList; } @@ -1351,7 +1350,7 @@ public class Alignment implements AlignmentI @Override public boolean removeCodonFrame(AlignedCodonFrame codons) { - Set acfs = getCodonFrames(); + List acfs = getCodonFrames(); if (codons == null || acfs == null) { return false; @@ -1770,4 +1769,46 @@ public class Alignment implements AlignmentI } return hasValidSeq; } + + /** + * Update any mappings to 'virtual' sequences to compatible real ones, if + * present in the added sequences. Returns a count of mappings updated. + * + * @param seqs + * @return + */ + @Override + public int realiseMappings(List seqs) + { + int count = 0; + for (SequenceI seq : seqs) + { + for (AlignedCodonFrame mapping : getCodonFrames()) + { + count += mapping.realiseWith(seq); + } + } + return count; + } + + /** + * Returns the first AlignedCodonFrame that has a mapping between the given + * dataset sequences + * + * @param mapFrom + * @param mapTo + * @return + */ + @Override + public AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo) + { + for (AlignedCodonFrame acf : getCodonFrames()) + { + if (acf.getAaForDnaSeq(mapFrom) == mapTo) + { + return acf; + } + } + return null; + } } diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index de79488..396ef2d 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -375,12 +375,12 @@ public interface AlignmentI extends AnnotatedCollectionI * * @return */ - Set getCodonFrames(); + List getCodonFrames(); /** - * Set the codon frame mappings (replacing any existing set). + * Set the codon frame mappings (replacing any existing list). */ - void setCodonFrames(Set acfs); + void setCodonFrames(List acfs); /** * get codon frames involving sequenceI @@ -524,4 +524,23 @@ public interface AlignmentI extends AnnotatedCollectionI * @return */ public boolean hasValidSequence(); + + /** + * Update any mappings to 'virtual' sequences to compatible real ones, if + * present in the added sequences. Returns a count of mappings updated. + * + * @param seqs + * @return + */ + int realiseMappings(List seqs); + + /** + * Returns the first AlignedCodonFrame that has a mapping between the given + * dataset sequences + * + * @param mapFrom + * @param mapTo + * @return + */ + AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo); } diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 9ee88db..06dc4c4 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -72,7 +72,6 @@ import java.awt.Rectangle; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; -import java.util.Set; import java.util.Vector; import javax.swing.JInternalFrame; @@ -461,7 +460,7 @@ public class AlignViewport extends AlignmentViewport implements AlignmentI al = getAlignment(); if (al != null) { - Set mappings = al.getCodonFrames(); + List mappings = al.getCodonFrames(); if (mappings != null) { StructureSelectionManager ssm = StructureSelectionManager @@ -855,7 +854,7 @@ public class AlignViewport extends AlignmentViewport implements * Check if any added sequence could be the object of a mapping or * cross-reference; if so, make the mapping explicit */ - realiseMappings(getAlignment(), toAdd); + getAlignment().realiseMappings(toAdd.getSequences()); /* * If any cDNA/protein mappings exist or can be made between the alignments, @@ -878,60 +877,26 @@ public class AlignViewport extends AlignmentViewport implements // TODO: JAL-407 regardless of above - identical sequences (based on ID and // provenance) should share the same dataset sequence + AlignmentI al = getAlignment(); + String gap = String.valueOf(al.getGapCharacter()); for (int i = 0; i < toAdd.getHeight(); i++) { - getAlignment().addSequence(toAdd.getSequenceAt(i)); - } - - setEndSeq(getAlignment().getHeight()); - firePropertyChange("alignment", null, getAlignment().getSequences()); - } - - /** - * Check if any added sequence could be the object of a mapping or - * cross-reference; if so, make the mapping explicit. Returns the count of - * mappings updated. - * - * @param al - * @param toAdd - */ - protected int realiseMappings(AlignmentI al, AlignmentI toAdd) - { - // TODO this is proof of concept - // we might want to give the user some choice here - int count = 0; - for (SequenceI seq : toAdd.getSequences()) - { - count += realiseMappingsTo(al, seq); - } - return count; - } - - /** - * If the alignment holds any mappings to a virtual (placeholder) sequence - * that matches all or part of the given sequence, then update the mapping to - * point to the sequence. Returns the number of mappings updated. - * - * @param al - * @param seq - * @return - */ - protected int realiseMappingsTo(AlignmentI al, SequenceI seq) - { - int count = 0; - Set mappings = al.getCodonFrames(); - for (AlignedCodonFrame mapping : mappings) - { + SequenceI seq = toAdd.getSequenceAt(i); /* - * TODO could just go straight to realiseWith() here unless we want - * to give the user some choice before going ahead + * experimental! + * - 'align' any mapped sequences as per existing + * e.g. cdna to genome, domain hit to protein sequence + * very experimental! (need a separate menu option for this) + * - only add mapped sequences ('select targets from a dataset') */ - if (mapping.isRealisableWith(seq)) + if (true /*AlignmentUtils.alignSequenceAs(seq, al, gap, true, true)*/) { - count += mapping.realiseWith(seq); + al.addSequence(seq); } } - return count; + + setEndSeq(getAlignment().getHeight()); + firePropertyChange("alignment", null, getAlignment().getSequences()); } /** diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 3f1946e..3d807e2 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -65,7 +65,6 @@ import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.Map; -import java.util.Set; /** * base class holding visualization and analysis attributes and common logic for @@ -95,6 +94,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param name * @see jalview.api.ViewStyleI#setFontName(java.lang.String) */ + @Override public void setFontName(String name) { viewStyle.setFontName(name); @@ -104,6 +104,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param style * @see jalview.api.ViewStyleI#setFontStyle(int) */ + @Override public void setFontStyle(int style) { viewStyle.setFontStyle(style); @@ -113,6 +114,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param size * @see jalview.api.ViewStyleI#setFontSize(int) */ + @Override public void setFontSize(int size) { viewStyle.setFontSize(size); @@ -122,6 +124,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getFontStyle() */ + @Override public int getFontStyle() { return viewStyle.getFontStyle(); @@ -131,6 +134,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getFontName() */ + @Override public String getFontName() { return viewStyle.getFontName(); @@ -140,6 +144,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getFontSize() */ + @Override public int getFontSize() { return viewStyle.getFontSize(); @@ -149,6 +154,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param upperCasebold * @see jalview.api.ViewStyleI#setUpperCasebold(boolean) */ + @Override public void setUpperCasebold(boolean upperCasebold) { viewStyle.setUpperCasebold(upperCasebold); @@ -158,6 +164,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#isUpperCasebold() */ + @Override public boolean isUpperCasebold() { return viewStyle.isUpperCasebold(); @@ -167,6 +174,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#isSeqNameItalics() */ + @Override public boolean isSeqNameItalics() { return viewStyle.isSeqNameItalics(); @@ -176,6 +184,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param colourByReferenceSeq * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean) */ + @Override public void setColourByReferenceSeq(boolean colourByReferenceSeq) { viewStyle.setColourByReferenceSeq(colourByReferenceSeq); @@ -185,6 +194,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param b * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean) */ + @Override public void setColourAppliesToAllGroups(boolean b) { viewStyle.setColourAppliesToAllGroups(b); @@ -194,6 +204,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups() */ + @Override public boolean getColourAppliesToAllGroups() { return viewStyle.getColourAppliesToAllGroups(); @@ -203,6 +214,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getAbovePIDThreshold() */ + @Override public boolean getAbovePIDThreshold() { return viewStyle.getAbovePIDThreshold(); @@ -212,6 +224,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param inc * @see jalview.api.ViewStyleI#setIncrement(int) */ + @Override public void setIncrement(int inc) { viewStyle.setIncrement(inc); @@ -221,6 +234,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getIncrement() */ + @Override public int getIncrement() { return viewStyle.getIncrement(); @@ -230,6 +244,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param b * @see jalview.api.ViewStyleI#setConservationSelected(boolean) */ + @Override public void setConservationSelected(boolean b) { viewStyle.setConservationSelected(b); @@ -239,6 +254,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param show * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean) */ + @Override public void setShowHiddenMarkers(boolean show) { viewStyle.setShowHiddenMarkers(show); @@ -248,6 +264,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getShowHiddenMarkers() */ + @Override public boolean getShowHiddenMarkers() { return viewStyle.getShowHiddenMarkers(); @@ -257,6 +274,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param b * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean) */ + @Override public void setScaleRightWrapped(boolean b) { viewStyle.setScaleRightWrapped(b); @@ -266,6 +284,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param b * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean) */ + @Override public void setScaleLeftWrapped(boolean b) { viewStyle.setScaleLeftWrapped(b); @@ -275,6 +294,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param b * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean) */ + @Override public void setScaleAboveWrapped(boolean b) { viewStyle.setScaleAboveWrapped(b); @@ -284,6 +304,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getScaleLeftWrapped() */ + @Override public boolean getScaleLeftWrapped() { return viewStyle.getScaleLeftWrapped(); @@ -293,6 +314,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getScaleAboveWrapped() */ + @Override public boolean getScaleAboveWrapped() { return viewStyle.getScaleAboveWrapped(); @@ -302,6 +324,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getScaleRightWrapped() */ + @Override public boolean getScaleRightWrapped() { return viewStyle.getScaleRightWrapped(); @@ -311,6 +334,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param b * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean) */ + @Override public void setAbovePIDThreshold(boolean b) { viewStyle.setAbovePIDThreshold(b); @@ -320,6 +344,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param thresh * @see jalview.api.ViewStyleI#setThreshold(int) */ + @Override public void setThreshold(int thresh) { viewStyle.setThreshold(thresh); @@ -329,6 +354,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getThreshold() */ + @Override public int getThreshold() { return viewStyle.getThreshold(); @@ -338,6 +364,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getShowJVSuffix() */ + @Override public boolean getShowJVSuffix() { return viewStyle.getShowJVSuffix(); @@ -347,6 +374,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param b * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean) */ + @Override public void setShowJVSuffix(boolean b) { viewStyle.setShowJVSuffix(b); @@ -356,6 +384,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param state * @see jalview.api.ViewStyleI#setWrapAlignment(boolean) */ + @Override public void setWrapAlignment(boolean state) { viewStyle.setWrapAlignment(state); @@ -365,6 +394,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param state * @see jalview.api.ViewStyleI#setShowText(boolean) */ + @Override public void setShowText(boolean state) { viewStyle.setShowText(state); @@ -374,6 +404,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param state * @see jalview.api.ViewStyleI#setRenderGaps(boolean) */ + @Override public void setRenderGaps(boolean state) { viewStyle.setRenderGaps(state); @@ -383,6 +414,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getColourText() */ + @Override public boolean getColourText() { return viewStyle.getColourText(); @@ -392,6 +424,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param state * @see jalview.api.ViewStyleI#setColourText(boolean) */ + @Override public void setColourText(boolean state) { viewStyle.setColourText(state); @@ -401,6 +434,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getWrapAlignment() */ + @Override public boolean getWrapAlignment() { return viewStyle.getWrapAlignment(); @@ -410,6 +444,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getShowText() */ + @Override public boolean getShowText() { return viewStyle.getShowText(); @@ -419,6 +454,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getWrappedWidth() */ + @Override public int getWrappedWidth() { return viewStyle.getWrappedWidth(); @@ -428,6 +464,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param w * @see jalview.api.ViewStyleI#setWrappedWidth(int) */ + @Override public void setWrappedWidth(int w) { viewStyle.setWrappedWidth(w); @@ -437,6 +474,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getCharHeight() */ + @Override public int getCharHeight() { return viewStyle.getCharHeight(); @@ -446,6 +484,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param h * @see jalview.api.ViewStyleI#setCharHeight(int) */ + @Override public void setCharHeight(int h) { viewStyle.setCharHeight(h); @@ -455,6 +494,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getCharWidth() */ + @Override public int getCharWidth() { return viewStyle.getCharWidth(); @@ -464,6 +504,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param w * @see jalview.api.ViewStyleI#setCharWidth(int) */ + @Override public void setCharWidth(int w) { viewStyle.setCharWidth(w); @@ -473,6 +514,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getShowBoxes() */ + @Override public boolean getShowBoxes() { return viewStyle.getShowBoxes(); @@ -482,6 +524,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getShowUnconserved() */ + @Override public boolean getShowUnconserved() { return viewStyle.getShowUnconserved(); @@ -491,6 +534,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param showunconserved * @see jalview.api.ViewStyleI#setShowUnconserved(boolean) */ + @Override public void setShowUnconserved(boolean showunconserved) { viewStyle.setShowUnconserved(showunconserved); @@ -500,6 +544,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param default1 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean) */ + @Override public void setSeqNameItalics(boolean default1) { viewStyle.setSeqNameItalics(default1); @@ -791,15 +836,26 @@ public abstract class AlignmentViewport implements AlignViewportI, /* * A separate thread to compute cDNA consensus for a protein alignment + * which has mapping to cDNA */ final AlignmentI al = this.getAlignment(); if (!al.isNucleotide() && al.getCodonFrames() != null && !al.getCodonFrames().isEmpty()) { - if (calculator - .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null) + /* + * fudge - check first mapping is protein-to-nucleotide + * (we don't want to do this for protein-to-protein) + */ + AlignedCodonFrame mapping = al.getCodonFrames().iterator().next(); + // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame? + if (mapping.getdnaToProt()[0].getFromRatio() == 3) { - calculator.registerWorker(new ComplementConsensusThread(this, ap)); + if (calculator + .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null) + { + calculator + .registerWorker(new ComplementConsensusThread(this, ap)); + } } } } @@ -1378,7 +1434,7 @@ public abstract class AlignmentViewport implements AlignViewportI, if (hiddenRepSequences == null) { - hiddenRepSequences = new Hashtable(); + hiddenRepSequences = new Hashtable(); } hiddenRepSequences.put(repSequence, sg); @@ -1723,14 +1779,20 @@ public abstract class AlignmentViewport implements AlignViewportI, { if (!alignment.isNucleotide()) { - final Set codonMappings = alignment + final List codonMappings = alignment .getCodonFrames(); if (codonMappings != null && !codonMappings.isEmpty()) { - complementConsensus = new AlignmentAnnotation("cDNA Consensus", - "PID for cDNA", new Annotation[1], 0f, 100f, - AlignmentAnnotation.BAR_GRAPH); - initConsensus(complementConsensus); + // fudge: check mappings are not protein-to-protein + // TODO: nicer + AlignedCodonFrame mapping = codonMappings.iterator().next(); + if (mapping.getdnaToProt()[0].getFromRatio() == 3) + { + complementConsensus = new AlignmentAnnotation("cDNA Consensus", + "PID for cDNA", new Annotation[1], 0f, 100f, + AlignmentAnnotation.BAR_GRAPH); + initConsensus(complementConsensus); + } } } } @@ -2115,6 +2177,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getTextColour() */ + @Override public Color getTextColour() { return viewStyle.getTextColour(); @@ -2124,6 +2187,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getTextColour2() */ + @Override public Color getTextColour2() { return viewStyle.getTextColour2(); @@ -2133,6 +2197,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getThresholdTextColour() */ + @Override public int getThresholdTextColour() { return viewStyle.getThresholdTextColour(); @@ -2142,6 +2207,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#isConservationColourSelected() */ + @Override public boolean isConservationColourSelected() { return viewStyle.isConservationColourSelected(); @@ -2151,6 +2217,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#isRenderGaps() */ + @Override public boolean isRenderGaps() { return viewStyle.isRenderGaps(); @@ -2160,6 +2227,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#isShowColourText() */ + @Override public boolean isShowColourText() { return viewStyle.isShowColourText(); @@ -2169,6 +2237,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param conservationColourSelected * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean) */ + @Override public void setConservationColourSelected( boolean conservationColourSelected) { @@ -2179,6 +2248,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param showColourText * @see jalview.api.ViewStyleI#setShowColourText(boolean) */ + @Override public void setShowColourText(boolean showColourText) { viewStyle.setShowColourText(showColourText); @@ -2188,6 +2258,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param textColour * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color) */ + @Override public void setTextColour(Color textColour) { viewStyle.setTextColour(textColour); @@ -2197,6 +2268,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param thresholdTextColour * @see jalview.api.ViewStyleI#setThresholdTextColour(int) */ + @Override public void setThresholdTextColour(int thresholdTextColour) { viewStyle.setThresholdTextColour(thresholdTextColour); @@ -2206,6 +2278,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param textColour2 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color) */ + @Override public void setTextColour2(Color textColour2) { viewStyle.setTextColour2(textColour2); @@ -2233,6 +2306,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#getIdWidth() */ + @Override public int getIdWidth() { return viewStyle.getIdWidth(); @@ -2242,6 +2316,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param i * @see jalview.api.ViewStyleI#setIdWidth(int) */ + @Override public void setIdWidth(int i) { viewStyle.setIdWidth(i); @@ -2251,6 +2326,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#isCentreColumnLabels() */ + @Override public boolean isCentreColumnLabels() { return viewStyle.isCentreColumnLabels(); @@ -2260,6 +2336,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param centreColumnLabels * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean) */ + @Override public void setCentreColumnLabels(boolean centreColumnLabels) { viewStyle.setCentreColumnLabels(centreColumnLabels); @@ -2269,6 +2346,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param showdbrefs * @see jalview.api.ViewStyleI#setShowDBRefs(boolean) */ + @Override public void setShowDBRefs(boolean showdbrefs) { viewStyle.setShowDBRefs(showdbrefs); @@ -2278,6 +2356,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#isShowDBRefs() */ + @Override public boolean isShowDBRefs() { return viewStyle.isShowDBRefs(); @@ -2287,6 +2366,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @return * @see jalview.api.ViewStyleI#isShowNPFeats() */ + @Override public boolean isShowNPFeats() { return viewStyle.isShowNPFeats(); @@ -2296,6 +2376,7 @@ public abstract class AlignmentViewport implements AlignViewportI, * @param shownpfeats * @see jalview.api.ViewStyleI#setShowNPFeats(boolean) */ + @Override public void setShowNPFeats(boolean shownpfeats) { viewStyle.setShowNPFeats(shownpfeats); @@ -2428,6 +2509,7 @@ public abstract class AlignmentViewport implements AlignViewportI, return startRes; } + @Override public int getEndRes() { return endRes; @@ -2503,7 +2585,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { return 0; } - final Set mappings = proteinAlignment + final List mappings = proteinAlignment .getCodonFrames(); /* diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index ad1d3bf..75c6485 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -32,8 +32,9 @@ import jalview.io.FormatAdapter; import jalview.util.MapList; import java.io.IOException; -import java.util.Collections; +import java.util.Arrays; import java.util.Iterator; +import java.util.List; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -397,7 +398,9 @@ public class AlignmentTest // create sequence and alignment datasets protein.setDataset(null); AlignedCodonFrame acf = new AlignedCodonFrame(); - protein.getDataset().setCodonFrames(Collections.singleton(acf)); + List acfList = Arrays.asList(new AlignedCodonFrame[] + { acf }); + protein.getDataset().setCodonFrames(acfList); AlignmentI copy = new Alignment(protein); /* @@ -468,4 +471,26 @@ public class AlignmentTest // prove the codon frames are indeed on the dataset: assertTrue(ds.getCodonFrames().contains(acf)); } + + @Test(groups = "Functional") + public void testAddCodonFrame() + { + AlignmentI align = new Alignment(new SequenceI[] {}); + AlignedCodonFrame acf = new AlignedCodonFrame(); + align.addCodonFrame(acf); + assertEquals(1, align.getCodonFrames().size()); + assertTrue(align.getCodonFrames().contains(acf)); + // can't add the same object twice: + align.addCodonFrame(acf); + assertEquals(1, align.getCodonFrames().size()); + + // create dataset alignment - mappings move to dataset + ((Alignment) align).createDatasetAlignment(); + assertSame(align.getCodonFrames(), align.getDataset().getCodonFrames()); + assertEquals(1, align.getCodonFrames().size()); + + AlignedCodonFrame acf2 = new AlignedCodonFrame(); + align.addCodonFrame(acf2); + assertTrue(align.getDataset().getCodonFrames().contains(acf)); + } } diff --git a/test/jalview/gui/AlignViewportTest.java b/test/jalview/gui/AlignViewportTest.java index 0a53f10..b39b2bd 100644 --- a/test/jalview/gui/AlignViewportTest.java +++ b/test/jalview/gui/AlignViewportTest.java @@ -37,8 +37,8 @@ import jalview.io.FileLoader; import jalview.io.FormatAdapter; import jalview.structure.StructureSelectionManager; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -136,7 +136,7 @@ public class AlignViewportTest AlignedCodonFrame acf1 = new AlignedCodonFrame(); AlignedCodonFrame acf2 = new AlignedCodonFrame(); - Set mappings = new LinkedHashSet(); + List mappings = new ArrayList(); mappings.add(acf1); mappings.add(acf2); af1.getViewport().getAlignment().setCodonFrames(mappings); @@ -148,18 +148,18 @@ public class AlignViewportTest */ StructureSelectionManager ssm = StructureSelectionManager .getStructureSelectionManager(Desktop.instance); - assertEquals(2, ssm.seqmappings.size()); - assertTrue(ssm.seqmappings.contains(acf1)); - assertTrue(ssm.seqmappings.contains(acf2)); + assertEquals(2, ssm.getSequenceMappings().size()); + assertTrue(ssm.getSequenceMappings().contains(acf1)); + assertTrue(ssm.getSequenceMappings().contains(acf2)); /* * Close the second view. Verify that mappings are not removed as the first * view still holds a reference to them. */ af1.closeMenuItem_actionPerformed(false); - assertEquals(2, ssm.seqmappings.size()); - assertTrue(ssm.seqmappings.contains(acf1)); - assertTrue(ssm.seqmappings.contains(acf2)); + assertEquals(2, ssm.getSequenceMappings().size()); + assertTrue(ssm.getSequenceMappings().contains(acf1)); + assertTrue(ssm.getSequenceMappings().contains(acf2)); } /** @@ -183,11 +183,11 @@ public class AlignViewportTest AlignedCodonFrame acf2 = new AlignedCodonFrame(); AlignedCodonFrame acf3 = new AlignedCodonFrame(); - Set mappings1 = new LinkedHashSet(); + List mappings1 = new ArrayList(); mappings1.add(acf1); af1.getViewport().getAlignment().setCodonFrames(mappings1); - Set mappings2 = new LinkedHashSet(); + List mappings2 = new ArrayList(); mappings2.add(acf2); mappings2.add(acf3); af2.getViewport().getAlignment().setCodonFrames(mappings2); @@ -196,7 +196,7 @@ public class AlignViewportTest * AlignFrame1 has mapping acf1, AlignFrame2 has acf2 and acf3 */ - Set ssmMappings = ssm.seqmappings; + List ssmMappings = ssm.getSequenceMappings(); assertEquals(0, ssmMappings.size()); ssm.registerMapping(acf1); assertEquals(1, ssmMappings.size()); @@ -236,12 +236,12 @@ public class AlignViewportTest AlignedCodonFrame acf2 = new AlignedCodonFrame(); AlignedCodonFrame acf3 = new AlignedCodonFrame(); - Set mappings1 = new LinkedHashSet(); + List mappings1 = new ArrayList(); mappings1.add(acf1); mappings1.add(acf2); af1.getViewport().getAlignment().setCodonFrames(mappings1); - Set mappings2 = new LinkedHashSet(); + List mappings2 = new ArrayList(); mappings2.add(acf2); mappings2.add(acf3); af2.getViewport().getAlignment().setCodonFrames(mappings2); @@ -250,7 +250,7 @@ public class AlignViewportTest * AlignFrame1 has mappings acf1 and acf2, AlignFrame2 has acf2 and acf3 */ - Set ssmMappings = ssm.seqmappings; + List ssmMappings = ssm.getSequenceMappings(); assertEquals(0, ssmMappings.size()); ssm.registerMapping(acf1); assertEquals(1, ssmMappings.size());