X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fviewmodel%2FAlignmentViewport.java;h=7cea5a325f06815796aec184406d62307cf1a038;hb=e7b6c76c3b028aeeef7770c99c87d895c1b46172;hp=07cb689a891a5e84af44cb865e68cf6b95df4a7d;hpb=a73dfac0f8c2280f13651bcd804cd7bb2420e8d5;p=jalview.git diff --git a/src/jalview/viewmodel/AlignmentViewport.java b/src/jalview/viewmodel/AlignmentViewport.java index 07cb689..7cea5a3 100644 --- a/src/jalview/viewmodel/AlignmentViewport.java +++ b/src/jalview/viewmodel/AlignmentViewport.java @@ -49,6 +49,7 @@ import jalview.structure.CommandListener; import jalview.structure.StructureSelectionManager; import jalview.structure.VamsasSource; import jalview.util.Comparison; +import jalview.util.MapList; import jalview.util.MappingUtils; import jalview.viewmodel.styles.ViewStyle; import jalview.workers.AlignCalcManager; @@ -848,7 +849,9 @@ public abstract class AlignmentViewport implements AlignViewportI, */ AlignedCodonFrame mapping = al.getCodonFrames().iterator().next(); // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame? - if (mapping.getdnaToProt()[0].getFromRatio() == 3) + MapList[] mapLists = mapping.getdnaToProt(); + // mapLists can be empty if project load has not finished resolving seqs + if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3) { if (calculator .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null) @@ -1075,6 +1078,7 @@ public abstract class AlignmentViewport implements AlignViewportI, { updateHiddenColumns(); } + isColSelChanged(true); } /** @@ -1203,8 +1207,7 @@ public abstract class AlignmentViewport implements AlignViewportI, */ public boolean isColSelChanged(boolean b) { - int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel - .hashCode(); + int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode(); if (hc != -1 && hc != colselhash) { if (b) @@ -1305,7 +1308,7 @@ public abstract class AlignmentViewport implements AlignViewportI, colSel.hideSelectedColumns(); setSelectionGroup(null); - + isColSelChanged(true); } public void hideColumns(int start, int end) @@ -1318,17 +1321,19 @@ public abstract class AlignmentViewport implements AlignViewportI, { colSel.hideColumns(start, end); } + isColSelChanged(true); } public void showColumn(int col) { colSel.revealHiddenColumns(col); - + isColSelChanged(true); } public void showAllHiddenColumns() { colSel.revealAllHiddenColumns(); + isColSelChanged(true); } // common hide/show seq stuff @@ -1460,13 +1465,42 @@ public abstract class AlignmentViewport implements AlignViewportI, } + /** + * + * @return null or the current reference sequence + */ + public SequenceI getReferenceSeq() + { + return alignment.getSeqrep(); + } + + /** + * @param seq + * @return true iff seq is the reference for the alignment + */ + public boolean isReferenceSeq(SequenceI seq) + { + return alignment.getSeqrep() == seq; + } + + /** + * + * @param seq + * @return true if there are sequences represented by this sequence that are + * currently hidden + */ public boolean isHiddenRepSequence(SequenceI seq) { - return alignment.getSeqrep() == seq - || (hiddenRepSequences != null && hiddenRepSequences + return (hiddenRepSequences != null && hiddenRepSequences .containsKey(seq)); } + /** + * + * @param seq + * @return null or a sequence group containing the sequences that seq + * represents + */ public SequenceGroup getRepresentedSequences(SequenceI seq) { return (SequenceGroup) (hiddenRepSequences == null ? null @@ -1554,6 +1588,13 @@ public abstract class AlignmentViewport implements AlignViewportI, @Override public String[] getViewAsString(boolean selectedRegionOnly) { + return getViewAsString(selectedRegionOnly, true); + } + + @Override + public String[] getViewAsString(boolean selectedRegionOnly, + boolean isExportHiddenSeqs) + { String[] selection = null; SequenceI[] seqs = null; int i, iSize; @@ -1567,7 +1608,7 @@ public abstract class AlignmentViewport implements AlignViewportI, } else { - if (hasHiddenRows()) + if (hasHiddenRows() && isExportHiddenSeqs) { iSize = alignment.getHiddenSequences().getFullAlignment() .getHeight(); @@ -1797,7 +1838,9 @@ public abstract class AlignmentViewport implements AlignViewportI, // fudge: check mappings are not protein-to-protein // TODO: nicer AlignedCodonFrame mapping = codonMappings.iterator().next(); - if (mapping.getdnaToProt()[0].getFromRatio() == 3) + MapList[] mapLists = mapping.getdnaToProt(); + // mapLists can be empty if project load has not finished resolving seqs + if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3) { complementConsensus = new AlignmentAnnotation("cDNA Consensus", "PID for cDNA", new Annotation[1], 0f, 100f, @@ -2650,4 +2693,39 @@ public abstract class AlignmentViewport implements AlignViewportI, sequence.findPosition(middleColumn), mappings); return seqOffset; } + + /** + * synthesize a column selection if none exists so it covers the given + * selection group. if wholewidth is false, no column selection is made if the + * selection group covers the whole alignment width. + * + * @param sg + * @param wholewidth + */ + public void expandColSelection(SequenceGroup sg, boolean wholewidth) + { + int sgs, sge; + if (sg != null + && (sgs = sg.getStartRes()) >= 0 + && sg.getStartRes() <= (sge = sg.getEndRes()) + && (colSel == null || colSel.getSelected() == null || colSel + .getSelected().size() == 0)) + { + if (!wholewidth && alignment.getWidth() == (1 + sge - sgs)) + { + // do nothing + return; + } + if (colSel == null) + { + colSel = new ColumnSelection(); + } + for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++) + { + colSel.addElement(cspos); + } + } + } + + }