2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenSequences;
39 import jalview.datamodel.SearchResults;
40 import jalview.datamodel.Sequence;
41 import jalview.datamodel.SequenceCollectionI;
42 import jalview.datamodel.SequenceGroup;
43 import jalview.datamodel.SequenceI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.ColourSchemeI;
46 import jalview.schemes.PIDColourScheme;
47 import jalview.schemes.ResidueProperties;
48 import jalview.structure.CommandListener;
49 import jalview.structure.StructureSelectionManager;
50 import jalview.structure.VamsasSource;
51 import jalview.util.Comparison;
52 import jalview.util.MapList;
53 import jalview.util.MappingUtils;
54 import jalview.viewmodel.styles.ViewStyle;
55 import jalview.workers.AlignCalcManager;
56 import jalview.workers.ComplementConsensusThread;
57 import jalview.workers.ConsensusThread;
58 import jalview.workers.StrucConsensusThread;
60 import java.awt.Color;
61 import java.util.ArrayDeque;
62 import java.util.ArrayList;
63 import java.util.BitSet;
64 import java.util.Deque;
65 import java.util.HashMap;
66 import java.util.Hashtable;
67 import java.util.List;
71 * base class holding visualization and analysis attributes and common logic for
72 * an active alignment view displayed in the GUI
77 public abstract class AlignmentViewport implements AlignViewportI,
78 CommandListener, VamsasSource
80 protected ViewStyleI viewStyle = new ViewStyle();
83 * A viewport that hosts the cDna view of this (protein), or vice versa (if
86 AlignViewportI codingComplement = null;
88 FeaturesDisplayedI featuresDisplayed = null;
90 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
92 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
96 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
99 public void setFontName(String name)
101 viewStyle.setFontName(name);
106 * @see jalview.api.ViewStyleI#setFontStyle(int)
109 public void setFontStyle(int style)
111 viewStyle.setFontStyle(style);
116 * @see jalview.api.ViewStyleI#setFontSize(int)
119 public void setFontSize(int size)
121 viewStyle.setFontSize(size);
126 * @see jalview.api.ViewStyleI#getFontStyle()
129 public int getFontStyle()
131 return viewStyle.getFontStyle();
136 * @see jalview.api.ViewStyleI#getFontName()
139 public String getFontName()
141 return viewStyle.getFontName();
146 * @see jalview.api.ViewStyleI#getFontSize()
149 public int getFontSize()
151 return viewStyle.getFontSize();
155 * @param upperCasebold
156 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
159 public void setUpperCasebold(boolean upperCasebold)
161 viewStyle.setUpperCasebold(upperCasebold);
166 * @see jalview.api.ViewStyleI#isUpperCasebold()
169 public boolean isUpperCasebold()
171 return viewStyle.isUpperCasebold();
176 * @see jalview.api.ViewStyleI#isSeqNameItalics()
179 public boolean isSeqNameItalics()
181 return viewStyle.isSeqNameItalics();
185 * @param colourByReferenceSeq
186 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
189 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
191 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
196 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
199 public void setColourAppliesToAllGroups(boolean b)
201 viewStyle.setColourAppliesToAllGroups(b);
206 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
209 public boolean getColourAppliesToAllGroups()
211 return viewStyle.getColourAppliesToAllGroups();
216 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
219 public boolean getAbovePIDThreshold()
221 return viewStyle.getAbovePIDThreshold();
226 * @see jalview.api.ViewStyleI#setIncrement(int)
229 public void setIncrement(int inc)
231 viewStyle.setIncrement(inc);
236 * @see jalview.api.ViewStyleI#getIncrement()
239 public int getIncrement()
241 return viewStyle.getIncrement();
246 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
249 public void setConservationSelected(boolean b)
251 viewStyle.setConservationSelected(b);
256 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
259 public void setShowHiddenMarkers(boolean show)
261 viewStyle.setShowHiddenMarkers(show);
266 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
269 public boolean getShowHiddenMarkers()
271 return viewStyle.getShowHiddenMarkers();
276 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
279 public void setScaleRightWrapped(boolean b)
281 viewStyle.setScaleRightWrapped(b);
286 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
289 public void setScaleLeftWrapped(boolean b)
291 viewStyle.setScaleLeftWrapped(b);
296 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
299 public void setScaleAboveWrapped(boolean b)
301 viewStyle.setScaleAboveWrapped(b);
306 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
309 public boolean getScaleLeftWrapped()
311 return viewStyle.getScaleLeftWrapped();
316 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
319 public boolean getScaleAboveWrapped()
321 return viewStyle.getScaleAboveWrapped();
326 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
329 public boolean getScaleRightWrapped()
331 return viewStyle.getScaleRightWrapped();
336 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
339 public void setAbovePIDThreshold(boolean b)
341 viewStyle.setAbovePIDThreshold(b);
346 * @see jalview.api.ViewStyleI#setThreshold(int)
349 public void setThreshold(int thresh)
351 viewStyle.setThreshold(thresh);
356 * @see jalview.api.ViewStyleI#getThreshold()
359 public int getThreshold()
361 return viewStyle.getThreshold();
366 * @see jalview.api.ViewStyleI#getShowJVSuffix()
369 public boolean getShowJVSuffix()
371 return viewStyle.getShowJVSuffix();
376 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
379 public void setShowJVSuffix(boolean b)
381 viewStyle.setShowJVSuffix(b);
386 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
389 public void setWrapAlignment(boolean state)
391 viewStyle.setWrapAlignment(state);
396 * @see jalview.api.ViewStyleI#setShowText(boolean)
399 public void setShowText(boolean state)
401 viewStyle.setShowText(state);
406 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
409 public void setRenderGaps(boolean state)
411 viewStyle.setRenderGaps(state);
416 * @see jalview.api.ViewStyleI#getColourText()
419 public boolean getColourText()
421 return viewStyle.getColourText();
426 * @see jalview.api.ViewStyleI#setColourText(boolean)
429 public void setColourText(boolean state)
431 viewStyle.setColourText(state);
436 * @see jalview.api.ViewStyleI#getWrapAlignment()
439 public boolean getWrapAlignment()
441 return viewStyle.getWrapAlignment();
446 * @see jalview.api.ViewStyleI#getShowText()
449 public boolean getShowText()
451 return viewStyle.getShowText();
456 * @see jalview.api.ViewStyleI#getWrappedWidth()
459 public int getWrappedWidth()
461 return viewStyle.getWrappedWidth();
466 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
469 public void setWrappedWidth(int w)
471 viewStyle.setWrappedWidth(w);
476 * @see jalview.api.ViewStyleI#getCharHeight()
479 public int getCharHeight()
481 return viewStyle.getCharHeight();
486 * @see jalview.api.ViewStyleI#setCharHeight(int)
489 public void setCharHeight(int h)
491 viewStyle.setCharHeight(h);
496 * @see jalview.api.ViewStyleI#getCharWidth()
499 public int getCharWidth()
501 return viewStyle.getCharWidth();
506 * @see jalview.api.ViewStyleI#setCharWidth(int)
509 public void setCharWidth(int w)
511 viewStyle.setCharWidth(w);
516 * @see jalview.api.ViewStyleI#getShowBoxes()
519 public boolean getShowBoxes()
521 return viewStyle.getShowBoxes();
526 * @see jalview.api.ViewStyleI#getShowUnconserved()
529 public boolean getShowUnconserved()
531 return viewStyle.getShowUnconserved();
535 * @param showunconserved
536 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
539 public void setShowUnconserved(boolean showunconserved)
541 viewStyle.setShowUnconserved(showunconserved);
546 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
549 public void setSeqNameItalics(boolean default1)
551 viewStyle.setSeqNameItalics(default1);
555 * alignment displayed in the viewport. Please use get/setter
557 protected AlignmentI alignment;
560 public AlignmentI getAlignment()
566 public char getGapCharacter()
568 return alignment.getGapCharacter();
571 protected String sequenceSetID;
574 * probably unused indicator that view is of a dataset rather than an
577 protected boolean isDataset = false;
579 public void setDataset(boolean b)
584 public boolean isDataset()
589 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
591 protected ColumnSelection colSel = new ColumnSelection();
593 public boolean autoCalculateConsensus = true;
595 protected boolean autoCalculateStrucConsensus = true;
597 protected boolean ignoreGapsInConsensusCalculation = false;
599 protected ColourSchemeI globalColourScheme = null;
602 public void setGlobalColourScheme(ColourSchemeI cs)
604 // TODO: logic refactored from AlignFrame changeColour -
605 // TODO: autorecalc stuff should be changed to rely on the worker system
606 // check to see if we should implement a changeColour(cs) method rather than
607 // put th logic in here
608 // - means that caller decides if they want to just modify state and defer
609 // calculation till later or to do all calculations in thread.
611 globalColourScheme = cs;
612 boolean recalc = false;
615 cs.setConservationApplied(recalc = getConservationSelected());
616 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
617 || cs instanceof Blosum62ColourScheme)
620 cs.setThreshold(viewStyle.getThreshold(),
621 ignoreGapsInConsensusCalculation);
625 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
629 cs.setConsensus(hconsensus);
630 cs.setConservation(hconservation);
632 cs.alignmentChanged(alignment, hiddenRepSequences);
634 if (getColourAppliesToAllGroups())
636 for (SequenceGroup sg : getAlignment().getGroups())
643 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
644 sg.setConsPercGaps(ConsPercGaps);
645 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
646 || cs instanceof Blosum62ColourScheme)
648 sg.cs.setThreshold(viewStyle.getThreshold(),
649 isIgnoreGapsConsensus());
654 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
657 if (getConservationSelected())
659 sg.cs.setConservationApplied(true);
664 sg.cs.setConservation(null);
665 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
669 sg.recalcConservation();
673 sg.cs.alignmentChanged(sg, hiddenRepSequences);
680 public ColourSchemeI getGlobalColourScheme()
682 return globalColourScheme;
685 protected AlignmentAnnotation consensus;
687 protected AlignmentAnnotation complementConsensus;
689 protected AlignmentAnnotation strucConsensus;
691 protected AlignmentAnnotation conservation;
693 protected AlignmentAnnotation quality;
695 protected AlignmentAnnotation[] groupConsensus;
697 protected AlignmentAnnotation[] groupConservation;
700 * results of alignment consensus analysis for visible portion of view
702 protected Hashtable[] hconsensus = null;
705 * results of cDNA complement consensus visible portion of view
707 protected Hashtable[] hcomplementConsensus = null;
710 * results of secondary structure base pair consensus for visible portion of
713 protected Hashtable[] hStrucConsensus = null;
715 protected Conservation hconservation = null;
718 public void setConservation(Conservation cons)
720 hconservation = cons;
724 * percentage gaps allowed in a column before all amino acid properties should
725 * be considered unconserved
727 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
730 public int getConsPercGaps()
736 public void setSequenceConsensusHash(Hashtable[] hconsensus)
738 this.hconsensus = hconsensus;
742 public void setComplementConsensusHash(Hashtable[] hconsensus)
744 this.hcomplementConsensus = hconsensus;
748 public Hashtable[] getSequenceConsensusHash()
754 public Hashtable[] getComplementConsensusHash()
756 return hcomplementConsensus;
760 public Hashtable[] getRnaStructureConsensusHash()
762 return hStrucConsensus;
766 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
768 this.hStrucConsensus = hStrucConsensus;
773 public AlignmentAnnotation getAlignmentQualityAnnot()
779 public AlignmentAnnotation getAlignmentConservationAnnotation()
785 public AlignmentAnnotation getAlignmentConsensusAnnotation()
791 public AlignmentAnnotation getComplementConsensusAnnotation()
793 return complementConsensus;
797 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
799 return strucConsensus;
802 protected AlignCalcManagerI calculator = new AlignCalcManager();
805 * trigger update of conservation annotation
807 public void updateConservation(final AlignmentViewPanel ap)
809 // see note in mantis : issue number 8585
810 if (alignment.isNucleotide() || conservation == null
811 || !autoCalculateConsensus)
816 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
818 calculator.registerWorker(new jalview.workers.ConservationThread(
824 * trigger update of consensus annotation
826 public void updateConsensus(final AlignmentViewPanel ap)
828 // see note in mantis : issue number 8585
829 if (consensus == null || !autoCalculateConsensus)
833 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
835 calculator.registerWorker(new ConsensusThread(this, ap));
839 * A separate thread to compute cDNA consensus for a protein alignment
840 * which has mapping to cDNA
842 final AlignmentI al = this.getAlignment();
843 if (!al.isNucleotide() && al.getCodonFrames() != null
844 && !al.getCodonFrames().isEmpty())
847 * fudge - check first for protein-to-nucleotide mappings
848 * (we don't want to do this for protein-to-protein)
850 boolean doConsensus = false;
851 for (AlignedCodonFrame mapping : al.getCodonFrames())
853 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
854 MapList[] mapLists = mapping.getdnaToProt();
855 // mapLists can be empty if project load has not finished resolving seqs
856 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
865 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
868 .registerWorker(new ComplementConsensusThread(this, ap));
874 // --------START Structure Conservation
875 public void updateStrucConsensus(final AlignmentViewPanel ap)
877 if (autoCalculateStrucConsensus && strucConsensus == null
878 && alignment.isNucleotide() && alignment.hasRNAStructure())
880 // secondary structure has been added - so init the consensus line
884 // see note in mantis : issue number 8585
885 if (strucConsensus == null || !autoCalculateStrucConsensus)
889 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
891 calculator.registerWorker(new StrucConsensusThread(this, ap));
895 public boolean isCalcInProgress()
897 return calculator.isWorking();
901 public boolean isCalculationInProgress(
902 AlignmentAnnotation alignmentAnnotation)
904 if (!alignmentAnnotation.autoCalculated)
908 if (calculator.workingInvolvedWith(alignmentAnnotation))
910 // System.err.println("grey out ("+alignmentAnnotation.label+")");
917 public boolean isClosed()
919 // TODO: check that this isClosed is only true after panel is closed, not
920 // before it is fully constructed.
921 return alignment == null;
925 public AlignCalcManagerI getCalcManager()
931 * should conservation rows be shown for groups
933 protected boolean showGroupConservation = false;
936 * should consensus rows be shown for groups
938 protected boolean showGroupConsensus = false;
941 * should consensus profile be rendered by default
943 protected boolean showSequenceLogo = false;
946 * should consensus profile be rendered normalised to row height
948 protected boolean normaliseSequenceLogo = false;
951 * should consensus histograms be rendered by default
953 protected boolean showConsensusHistogram = true;
956 * @return the showConsensusProfile
959 public boolean isShowSequenceLogo()
961 return showSequenceLogo;
965 * @param showSequenceLogo
968 public void setShowSequenceLogo(boolean showSequenceLogo)
970 if (showSequenceLogo != this.showSequenceLogo)
972 // TODO: decouple settings setting from calculation when refactoring
973 // annotation update method from alignframe to viewport
974 this.showSequenceLogo = showSequenceLogo;
975 calculator.updateAnnotationFor(ConsensusThread.class);
976 calculator.updateAnnotationFor(ComplementConsensusThread.class);
977 calculator.updateAnnotationFor(StrucConsensusThread.class);
979 this.showSequenceLogo = showSequenceLogo;
983 * @param showConsensusHistogram
984 * the showConsensusHistogram to set
986 public void setShowConsensusHistogram(boolean showConsensusHistogram)
988 this.showConsensusHistogram = showConsensusHistogram;
992 * @return the showGroupConservation
994 public boolean isShowGroupConservation()
996 return showGroupConservation;
1000 * @param showGroupConservation
1001 * the showGroupConservation to set
1003 public void setShowGroupConservation(boolean showGroupConservation)
1005 this.showGroupConservation = showGroupConservation;
1009 * @return the showGroupConsensus
1011 public boolean isShowGroupConsensus()
1013 return showGroupConsensus;
1017 * @param showGroupConsensus
1018 * the showGroupConsensus to set
1020 public void setShowGroupConsensus(boolean showGroupConsensus)
1022 this.showGroupConsensus = showGroupConsensus;
1027 * @return flag to indicate if the consensus histogram should be rendered by
1031 public boolean isShowConsensusHistogram()
1033 return this.showConsensusHistogram;
1037 * when set, updateAlignment will always ensure sequences are of equal length
1039 private boolean padGaps = false;
1042 * when set, alignment should be reordered according to a newly opened tree
1044 public boolean sortByTree = false;
1049 * @return null or the currently selected sequence region
1052 public SequenceGroup getSelectionGroup()
1054 return selectionGroup;
1058 * Set the selection group for this window.
1061 * - group holding references to sequences in this alignment view
1065 public void setSelectionGroup(SequenceGroup sg)
1067 selectionGroup = sg;
1070 public void setHiddenColumns(ColumnSelection colsel)
1072 this.colSel = colsel;
1076 public ColumnSelection getColumnSelection()
1082 public void setColumnSelection(ColumnSelection colSel)
1084 this.colSel = colSel;
1087 updateHiddenColumns();
1089 isColSelChanged(true);
1097 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1099 return hiddenRepSequences;
1103 public void setHiddenRepSequences(
1104 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1106 this.hiddenRepSequences = hiddenRepSequences;
1110 public boolean hasSelectedColumns()
1112 ColumnSelection columnSelection = getColumnSelection();
1113 return columnSelection != null && columnSelection.hasSelectedColumns();
1117 public boolean hasHiddenColumns()
1119 return colSel != null && colSel.hasHiddenColumns();
1122 public void updateHiddenColumns()
1124 // this method doesn't really do anything now. But - it could, since a
1125 // column Selection could be in the process of modification
1126 // hasHiddenColumns = colSel.hasHiddenColumns();
1130 public boolean hasHiddenRows()
1132 return alignment.getHiddenSequences().getSize() > 0;
1135 protected SequenceGroup selectionGroup;
1137 public void setSequenceSetId(String newid)
1139 if (sequenceSetID != null)
1142 .println("Warning - overwriting a sequenceSetId for a viewport!");
1144 sequenceSetID = new String(newid);
1148 public String getSequenceSetId()
1150 if (sequenceSetID == null)
1152 sequenceSetID = alignment.hashCode() + "";
1155 return sequenceSetID;
1159 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1162 protected String viewId = null;
1165 public String getViewId()
1169 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1174 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1176 ignoreGapsInConsensusCalculation = b;
1179 updateConsensus(ap);
1180 if (globalColourScheme != null)
1182 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1183 ignoreGapsInConsensusCalculation);
1189 private long sgrouphash = -1, colselhash = -1;
1192 * checks current SelectionGroup against record of last hash value, and
1196 * update the record of last hash value
1198 * @return true if SelectionGroup changed since last call (when b is true)
1200 public boolean isSelectionGroupChanged(boolean b)
1202 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1203 : selectionGroup.hashCode();
1204 if (hc != -1 && hc != sgrouphash)
1216 * checks current colsel against record of last hash value, and optionally
1220 * update the record of last hash value
1221 * @return true if colsel changed since last call (when b is true)
1223 public boolean isColSelChanged(boolean b)
1225 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1226 if (hc != -1 && hc != colselhash)
1238 public boolean isIgnoreGapsConsensus()
1240 return ignoreGapsInConsensusCalculation;
1243 // / property change stuff
1245 // JBPNote Prolly only need this in the applet version.
1246 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1249 protected boolean showConservation = true;
1251 protected boolean showQuality = true;
1253 protected boolean showConsensus = true;
1255 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1257 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1259 protected boolean showAutocalculatedAbove;
1262 * when set, view will scroll to show the highlighted position
1264 private boolean followHighlight = true;
1266 // TODO private with getters and setters?
1267 public int startRes;
1271 public int startSeq;
1276 * Property change listener for changes in alignment
1281 public void addPropertyChangeListener(
1282 java.beans.PropertyChangeListener listener)
1284 changeSupport.addPropertyChangeListener(listener);
1293 public void removePropertyChangeListener(
1294 java.beans.PropertyChangeListener listener)
1296 changeSupport.removePropertyChangeListener(listener);
1300 * Property change listener for changes in alignment
1309 public void firePropertyChange(String prop, Object oldvalue,
1312 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1315 // common hide/show column stuff
1317 public void hideSelectedColumns()
1319 if (colSel.isEmpty())
1324 colSel.hideSelectedColumns();
1325 setSelectionGroup(null);
1326 isColSelChanged(true);
1329 public void hideColumns(int start, int end)
1333 colSel.hideColumns(start);
1337 colSel.hideColumns(start, end);
1339 isColSelChanged(true);
1342 public void showColumn(int col)
1344 colSel.revealHiddenColumns(col);
1345 isColSelChanged(true);
1348 public void showAllHiddenColumns()
1350 colSel.revealAllHiddenColumns();
1351 isColSelChanged(true);
1354 // common hide/show seq stuff
1355 public void showAllHiddenSeqs()
1357 if (alignment.getHiddenSequences().getSize() > 0)
1359 if (selectionGroup == null)
1361 selectionGroup = new SequenceGroup();
1362 selectionGroup.setEndRes(alignment.getWidth() - 1);
1364 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1365 hiddenRepSequences);
1366 for (SequenceI seq : tmp)
1368 selectionGroup.addSequence(seq, false);
1369 setSequenceAnnotationsVisible(seq, true);
1372 hiddenRepSequences = null;
1374 firePropertyChange("alignment", null, alignment.getSequences());
1375 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1381 public void showSequence(int index)
1383 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1384 index, hiddenRepSequences);
1387 if (selectionGroup == null)
1389 selectionGroup = new SequenceGroup();
1390 selectionGroup.setEndRes(alignment.getWidth() - 1);
1393 for (SequenceI seq : tmp)
1395 selectionGroup.addSequence(seq, false);
1396 setSequenceAnnotationsVisible(seq, true);
1398 firePropertyChange("alignment", null, alignment.getSequences());
1403 public void hideAllSelectedSeqs()
1405 if (selectionGroup == null || selectionGroup.getSize() < 1)
1410 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1414 setSelectionGroup(null);
1417 public void hideSequence(SequenceI[] seq)
1421 for (int i = 0; i < seq.length; i++)
1423 alignment.getHiddenSequences().hideSequence(seq[i]);
1424 setSequenceAnnotationsVisible(seq[i], false);
1426 firePropertyChange("alignment", null, alignment.getSequences());
1431 * Hides the specified sequence, or the sequences it represents
1434 * the sequence to hide, or keep as representative
1435 * @param representGroup
1436 * if true, hide the current selection group except for the
1437 * representative sequence
1439 public void hideSequences(SequenceI sequence, boolean representGroup)
1441 if (selectionGroup == null || selectionGroup.getSize() < 1)
1443 hideSequence(new SequenceI[] { sequence });
1449 hideRepSequences(sequence, selectionGroup);
1450 setSelectionGroup(null);
1454 int gsize = selectionGroup.getSize();
1455 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1456 new SequenceI[gsize]);
1458 hideSequence(hseqs);
1459 setSelectionGroup(null);
1464 * Set visibility for any annotations for the given sequence.
1468 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1471 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1474 for (AlignmentAnnotation ann : anns)
1476 if (ann.sequenceRef == sequenceI)
1478 ann.visible = visible;
1484 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1486 int sSize = sg.getSize();
1492 if (hiddenRepSequences == null)
1494 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1497 hiddenRepSequences.put(repSequence, sg);
1499 // Hide all sequences except the repSequence
1500 SequenceI[] seqs = new SequenceI[sSize - 1];
1502 for (int i = 0; i < sSize; i++)
1504 if (sg.getSequenceAt(i) != repSequence)
1506 if (index == sSize - 1)
1511 seqs[index++] = sg.getSequenceAt(i);
1514 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1515 sg.setHidereps(true); // note: not done in 2.7applet
1522 * @return null or the current reference sequence
1524 public SequenceI getReferenceSeq()
1526 return alignment.getSeqrep();
1531 * @return true iff seq is the reference for the alignment
1533 public boolean isReferenceSeq(SequenceI seq)
1535 return alignment.getSeqrep() == seq;
1541 * @return true if there are sequences represented by this sequence that are
1544 public boolean isHiddenRepSequence(SequenceI seq)
1546 return (hiddenRepSequences != null && hiddenRepSequences
1553 * @return null or a sequence group containing the sequences that seq
1556 public SequenceGroup getRepresentedSequences(SequenceI seq)
1558 return (SequenceGroup) (hiddenRepSequences == null ? null
1559 : hiddenRepSequences.get(seq));
1563 public int adjustForHiddenSeqs(int alignmentIndex)
1565 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1570 public void invertColumnSelection()
1572 colSel.invertColumnSelection(0, alignment.getWidth());
1576 public SequenceI[] getSelectionAsNewSequence()
1578 SequenceI[] sequences;
1579 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1580 // this was the only caller in the applet for this method
1581 // JBPNote: in applet, this method returned references to the alignment
1582 // sequences, and it did not honour the presence/absence of annotation
1583 // attached to the alignment (probably!)
1584 if (selectionGroup == null || selectionGroup.getSize() == 0)
1586 sequences = alignment.getSequencesArray();
1587 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1588 for (int i = 0; i < sequences.length; i++)
1590 // construct new sequence with subset of visible annotation
1591 sequences[i] = new Sequence(sequences[i], annots);
1596 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1603 public SequenceI[] getSequenceSelection()
1605 SequenceI[] sequences = null;
1606 if (selectionGroup != null)
1608 sequences = selectionGroup.getSequencesInOrder(alignment);
1610 if (sequences == null)
1612 sequences = alignment.getSequencesArray();
1618 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1620 return new CigarArray(alignment, colSel,
1621 (selectedRegionOnly ? selectionGroup : null));
1625 public jalview.datamodel.AlignmentView getAlignmentView(
1626 boolean selectedOnly)
1628 return getAlignmentView(selectedOnly, false);
1632 public jalview.datamodel.AlignmentView getAlignmentView(
1633 boolean selectedOnly, boolean markGroups)
1635 return new AlignmentView(alignment, colSel, selectionGroup,
1636 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1641 public String[] getViewAsString(boolean selectedRegionOnly)
1643 return getViewAsString(selectedRegionOnly, true);
1647 public String[] getViewAsString(boolean selectedRegionOnly,
1648 boolean exportHiddenSeqs)
1650 String[] selection = null;
1651 SequenceI[] seqs = null;
1653 int start = 0, end = 0;
1654 if (selectedRegionOnly && selectionGroup != null)
1656 iSize = selectionGroup.getSize();
1657 seqs = selectionGroup.getSequencesInOrder(alignment);
1658 start = selectionGroup.getStartRes();
1659 end = selectionGroup.getEndRes() + 1;
1663 if (hasHiddenRows() && exportHiddenSeqs)
1665 AlignmentI fullAlignment = alignment.getHiddenSequences()
1666 .getFullAlignment();
1667 iSize = fullAlignment.getHeight();
1668 seqs = fullAlignment.getSequencesArray();
1669 end = fullAlignment.getWidth();
1673 iSize = alignment.getHeight();
1674 seqs = alignment.getSequencesArray();
1675 end = alignment.getWidth();
1679 selection = new String[iSize];
1680 if (colSel != null && colSel.hasHiddenColumns())
1682 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1686 for (i = 0; i < iSize; i++)
1688 selection[i] = seqs[i].getSequenceAsString(start, end);
1696 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1698 ArrayList<int[]> regions = new ArrayList<int[]>();
1704 if (colSel != null && colSel.hasHiddenColumns())
1708 start = colSel.adjustForHiddenColumns(start);
1711 end = colSel.getHiddenBoundaryRight(start);
1722 regions.add(new int[] { start, end });
1724 if (colSel != null && colSel.hasHiddenColumns())
1726 start = colSel.adjustForHiddenColumns(end);
1727 start = colSel.getHiddenBoundaryLeft(start) + 1;
1729 } while (end < max);
1731 int[][] startEnd = new int[regions.size()][2];
1737 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1738 boolean selectedOnly)
1740 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1741 AlignmentAnnotation[] aa;
1742 if ((aa = alignment.getAlignmentAnnotation()) != null)
1744 for (AlignmentAnnotation annot : aa)
1746 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1747 if (selectedOnly && selectionGroup != null)
1749 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1750 selectionGroup.getEndRes(), clone);
1754 colSel.makeVisibleAnnotation(clone);
1763 public boolean isPadGaps()
1769 public void setPadGaps(boolean padGaps)
1771 this.padGaps = padGaps;
1775 * apply any post-edit constraints and trigger any calculations needed after
1776 * an edit has been performed on the alignment
1781 public void alignmentChanged(AlignmentViewPanel ap)
1785 alignment.padGaps();
1787 if (autoCalculateConsensus)
1789 updateConsensus(ap);
1791 if (hconsensus != null && autoCalculateConsensus)
1793 updateConservation(ap);
1795 if (autoCalculateStrucConsensus)
1797 updateStrucConsensus(ap);
1800 // Reset endRes of groups if beyond alignment width
1801 int alWidth = alignment.getWidth();
1802 List<SequenceGroup> groups = alignment.getGroups();
1805 for (SequenceGroup sg : groups)
1807 if (sg.getEndRes() > alWidth)
1809 sg.setEndRes(alWidth - 1);
1814 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1816 selectionGroup.setEndRes(alWidth - 1);
1819 resetAllColourSchemes();
1820 calculator.restartWorkers();
1821 // alignment.adjustSequenceAnnotations();
1825 * reset scope and do calculations for all applied colourschemes on alignment
1827 void resetAllColourSchemes()
1829 ColourSchemeI cs = globalColourScheme;
1832 cs.alignmentChanged(alignment, hiddenRepSequences);
1834 cs.setConsensus(hconsensus);
1835 if (cs.conservationApplied())
1837 cs.setConservation(Conservation.calculateConservation("All",
1838 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1839 alignment.getWidth(), false, getConsPercGaps(), false));
1843 for (SequenceGroup sg : alignment.getGroups())
1847 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1849 sg.recalcConservation();
1853 protected void initAutoAnnotation()
1855 // TODO: add menu option action that nulls or creates consensus object
1856 // depending on if the user wants to see the annotation or not in a
1857 // specific alignment
1859 if (hconsensus == null && !isDataset)
1861 if (!alignment.isNucleotide())
1870 consensus = new AlignmentAnnotation("Consensus", "PID",
1871 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1872 initConsensus(consensus);
1874 initComplementConsensus();
1879 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1880 * consensus annotation.
1882 public void initComplementConsensus()
1884 if (!alignment.isNucleotide())
1886 final List<AlignedCodonFrame> codonMappings = alignment
1888 if (codonMappings != null && !codonMappings.isEmpty())
1890 boolean doConsensus = false;
1891 for (AlignedCodonFrame mapping : codonMappings)
1893 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1894 MapList[] mapLists = mapping.getdnaToProt();
1895 // mapLists can be empty if project load has not finished resolving
1897 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1905 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1906 "PID for cDNA", new Annotation[1], 0f, 100f,
1907 AlignmentAnnotation.BAR_GRAPH);
1908 initConsensus(complementConsensus);
1914 private void initConsensus(AlignmentAnnotation aa)
1917 aa.autoCalculated = true;
1921 alignment.addAnnotation(aa);
1925 private void initConservation()
1927 if (showConservation)
1929 if (conservation == null)
1931 conservation = new AlignmentAnnotation("Conservation",
1932 "Conservation of total alignment less than "
1933 + getConsPercGaps() + "% gaps", new Annotation[1],
1934 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1935 conservation.hasText = true;
1936 conservation.autoCalculated = true;
1937 alignment.addAnnotation(conservation);
1942 private void initQuality()
1946 if (quality == null)
1948 quality = new AlignmentAnnotation("Quality",
1949 "Alignment Quality based on Blosum62 scores",
1950 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1951 quality.hasText = true;
1952 quality.autoCalculated = true;
1953 alignment.addAnnotation(quality);
1958 private void initRNAStructure()
1960 if (alignment.hasRNAStructure() && strucConsensus == null)
1962 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1963 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1964 strucConsensus.hasText = true;
1965 strucConsensus.autoCalculated = true;
1969 alignment.addAnnotation(strucConsensus);
1977 * @see jalview.api.AlignViewportI#calcPanelHeight()
1980 public int calcPanelHeight()
1982 // setHeight of panels
1983 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
1985 int charHeight = getCharHeight();
1988 BitSet graphgrp = new BitSet();
1989 for (AlignmentAnnotation aa : anns)
1993 System.err.println("Null annotation row: ignoring.");
2000 if (aa.graphGroup > -1)
2002 if (graphgrp.get(aa.graphGroup))
2008 graphgrp.set(aa.graphGroup);
2015 aa.height += charHeight;
2025 aa.height += aa.graphHeight;
2033 height += aa.height;
2045 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2046 boolean preserveNewGroupSettings)
2048 boolean updateCalcs = false;
2049 boolean conv = isShowGroupConservation();
2050 boolean cons = isShowGroupConsensus();
2051 boolean showprf = isShowSequenceLogo();
2052 boolean showConsHist = isShowConsensusHistogram();
2053 boolean normLogo = isNormaliseSequenceLogo();
2056 * TODO reorder the annotation rows according to group/sequence ordering on
2059 boolean sortg = true;
2061 // remove old automatic annotation
2062 // add any new annotation
2064 // intersect alignment annotation with alignment groups
2066 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2067 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2070 for (int an = 0; an < aan.length; an++)
2072 if (aan[an].autoCalculated && aan[an].groupRef != null)
2074 oldrfs.add(aan[an].groupRef);
2075 alignment.deleteAnnotation(aan[an], false);
2079 if (alignment.getGroups() != null)
2081 for (SequenceGroup sg : alignment.getGroups())
2083 updateCalcs = false;
2084 if (applyGlobalSettings
2085 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2087 // set defaults for this group's conservation/consensus
2088 sg.setshowSequenceLogo(showprf);
2089 sg.setShowConsensusHistogram(showConsHist);
2090 sg.setNormaliseSequenceLogo(normLogo);
2095 alignment.addAnnotation(sg.getConservationRow(), 0);
2100 alignment.addAnnotation(sg.getConsensus(), 0);
2102 // refresh the annotation rows
2105 sg.recalcConservation();
2113 public boolean isDisplayReferenceSeq()
2115 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2119 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2121 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2125 public boolean isColourByReferenceSeq()
2127 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2131 public Color getSequenceColour(SequenceI seq)
2133 Color sqc = sequenceColours.get(seq);
2134 return (sqc == null ? Color.white : sqc);
2138 public void setSequenceColour(SequenceI seq, Color col)
2142 sequenceColours.remove(seq);
2146 sequenceColours.put(seq, col);
2151 public void updateSequenceIdColours()
2153 for (SequenceGroup sg : alignment.getGroups())
2155 if (sg.idColour != null)
2157 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2159 sequenceColours.put(s, sg.idColour);
2166 public void clearSequenceColours()
2168 sequenceColours.clear();
2172 public AlignViewportI getCodingComplement()
2174 return this.codingComplement;
2178 * Set this as the (cDna/protein) complement of the given viewport. Also
2179 * ensures the reverse relationship is set on the given viewport.
2182 public void setCodingComplement(AlignViewportI av)
2186 System.err.println("Ignoring recursive setCodingComplement request");
2190 this.codingComplement = av;
2191 // avoid infinite recursion!
2192 if (av.getCodingComplement() != this)
2194 av.setCodingComplement(this);
2200 public boolean isNucleotide()
2202 return getAlignment() == null ? false : getAlignment().isNucleotide();
2206 public FeaturesDisplayedI getFeaturesDisplayed()
2208 return featuresDisplayed;
2212 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2214 featuresDisplayed = featuresDisplayedI;
2218 public boolean areFeaturesDisplayed()
2220 return featuresDisplayed != null
2221 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2228 * features are displayed if true
2231 public void setShowSequenceFeatures(boolean b)
2233 viewStyle.setShowSequenceFeatures(b);
2237 public boolean isShowSequenceFeatures()
2239 return viewStyle.isShowSequenceFeatures();
2243 public void setShowSequenceFeaturesHeight(boolean selected)
2245 viewStyle.setShowSequenceFeaturesHeight(selected);
2249 public boolean isShowSequenceFeaturesHeight()
2251 return viewStyle.isShowSequenceFeaturesHeight();
2255 public void setShowAnnotation(boolean b)
2257 viewStyle.setShowAnnotation(b);
2261 public boolean isShowAnnotation()
2263 return viewStyle.isShowAnnotation();
2267 public boolean isRightAlignIds()
2269 return viewStyle.isRightAlignIds();
2273 public void setRightAlignIds(boolean rightAlignIds)
2275 viewStyle.setRightAlignIds(rightAlignIds);
2279 public boolean getConservationSelected()
2281 return viewStyle.getConservationSelected();
2285 public void setShowBoxes(boolean state)
2287 viewStyle.setShowBoxes(state);
2292 * @see jalview.api.ViewStyleI#getTextColour()
2295 public Color getTextColour()
2297 return viewStyle.getTextColour();
2302 * @see jalview.api.ViewStyleI#getTextColour2()
2305 public Color getTextColour2()
2307 return viewStyle.getTextColour2();
2312 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2315 public int getThresholdTextColour()
2317 return viewStyle.getThresholdTextColour();
2322 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2325 public boolean isConservationColourSelected()
2327 return viewStyle.isConservationColourSelected();
2332 * @see jalview.api.ViewStyleI#isRenderGaps()
2335 public boolean isRenderGaps()
2337 return viewStyle.isRenderGaps();
2342 * @see jalview.api.ViewStyleI#isShowColourText()
2345 public boolean isShowColourText()
2347 return viewStyle.isShowColourText();
2351 * @param conservationColourSelected
2352 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2355 public void setConservationColourSelected(
2356 boolean conservationColourSelected)
2358 viewStyle.setConservationColourSelected(conservationColourSelected);
2362 * @param showColourText
2363 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2366 public void setShowColourText(boolean showColourText)
2368 viewStyle.setShowColourText(showColourText);
2373 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2376 public void setTextColour(Color textColour)
2378 viewStyle.setTextColour(textColour);
2382 * @param thresholdTextColour
2383 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2386 public void setThresholdTextColour(int thresholdTextColour)
2388 viewStyle.setThresholdTextColour(thresholdTextColour);
2392 * @param textColour2
2393 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2396 public void setTextColour2(Color textColour2)
2398 viewStyle.setTextColour2(textColour2);
2402 public ViewStyleI getViewStyle()
2404 return new ViewStyle(viewStyle);
2408 public void setViewStyle(ViewStyleI settingsForView)
2410 viewStyle = new ViewStyle(settingsForView);
2414 public boolean sameStyle(ViewStyleI them)
2416 return viewStyle.sameStyle(them);
2421 * @see jalview.api.ViewStyleI#getIdWidth()
2424 public int getIdWidth()
2426 return viewStyle.getIdWidth();
2431 * @see jalview.api.ViewStyleI#setIdWidth(int)
2434 public void setIdWidth(int i)
2436 viewStyle.setIdWidth(i);
2441 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2444 public boolean isCentreColumnLabels()
2446 return viewStyle.isCentreColumnLabels();
2450 * @param centreColumnLabels
2451 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2454 public void setCentreColumnLabels(boolean centreColumnLabels)
2456 viewStyle.setCentreColumnLabels(centreColumnLabels);
2461 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2464 public void setShowDBRefs(boolean showdbrefs)
2466 viewStyle.setShowDBRefs(showdbrefs);
2471 * @see jalview.api.ViewStyleI#isShowDBRefs()
2474 public boolean isShowDBRefs()
2476 return viewStyle.isShowDBRefs();
2481 * @see jalview.api.ViewStyleI#isShowNPFeats()
2484 public boolean isShowNPFeats()
2486 return viewStyle.isShowNPFeats();
2490 * @param shownpfeats
2491 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2494 public void setShowNPFeats(boolean shownpfeats)
2496 viewStyle.setShowNPFeats(shownpfeats);
2499 public abstract StructureSelectionManager getStructureSelectionManager();
2502 * Add one command to the command history list.
2506 public void addToHistoryList(CommandI command)
2508 if (this.historyList != null)
2510 this.historyList.push(command);
2511 broadcastCommand(command, false);
2515 protected void broadcastCommand(CommandI command, boolean undo)
2517 getStructureSelectionManager().commandPerformed(command, undo,
2522 * Add one command to the command redo list.
2526 public void addToRedoList(CommandI command)
2528 if (this.redoList != null)
2530 this.redoList.push(command);
2532 broadcastCommand(command, true);
2536 * Clear the command redo list.
2538 public void clearRedoList()
2540 if (this.redoList != null)
2542 this.redoList.clear();
2546 public void setHistoryList(Deque<CommandI> list)
2548 this.historyList = list;
2551 public Deque<CommandI> getHistoryList()
2553 return this.historyList;
2556 public void setRedoList(Deque<CommandI> list)
2558 this.redoList = list;
2561 public Deque<CommandI> getRedoList()
2563 return this.redoList;
2567 public VamsasSource getVamsasSource()
2572 public SequenceAnnotationOrder getSortAnnotationsBy()
2574 return sortAnnotationsBy;
2577 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2579 this.sortAnnotationsBy = sortAnnotationsBy;
2582 public boolean isShowAutocalculatedAbove()
2584 return showAutocalculatedAbove;
2587 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2589 this.showAutocalculatedAbove = showAutocalculatedAbove;
2593 public boolean isScaleProteinAsCdna()
2595 return viewStyle.isScaleProteinAsCdna();
2599 public void setScaleProteinAsCdna(boolean b)
2601 viewStyle.setScaleProteinAsCdna(b);
2605 * @return true if view should scroll to show the highlighted region of a
2610 public final boolean isFollowHighlight()
2612 return followHighlight;
2616 public final void setFollowHighlight(boolean b)
2618 this.followHighlight = b;
2621 public int getStartRes()
2627 public int getEndRes()
2632 public int getStartSeq()
2637 public void setStartRes(int res)
2639 this.startRes = res;
2642 public void setStartSeq(int seq)
2644 this.startSeq = seq;
2647 public void setEndRes(int res)
2649 if (res > alignment.getWidth() - 1)
2651 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2652 // (alignment.getWidth()-1));
2653 res = alignment.getWidth() - 1;
2662 public void setEndSeq(int seq)
2664 if (seq > alignment.getHeight())
2666 seq = alignment.getHeight();
2675 public int getEndSeq()
2681 * Helper method to populate the SearchResults with the location in the
2682 * complementary alignment to scroll to, in order to match this one.
2685 * the SearchResults to add to
2686 * @return the offset (below top of visible region) of the matched sequence
2688 protected int findComplementScrollTarget(SearchResults sr)
2690 final AlignViewportI complement = getCodingComplement();
2691 if (complement == null || !complement.isFollowHighlight())
2695 boolean iAmProtein = !getAlignment().isNucleotide();
2696 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2698 if (proteinAlignment == null)
2702 final List<AlignedCodonFrame> mappings = proteinAlignment
2706 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2707 * residue in the middle column of the visible region. Scroll the
2708 * complementary alignment to line up the corresponding residue.
2711 SequenceI sequence = null;
2714 * locate 'middle' column (true middle if an odd number visible, left of
2715 * middle if an even number visible)
2717 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2718 final HiddenSequences hiddenSequences = getAlignment()
2719 .getHiddenSequences();
2722 * searching to the bottom of the alignment gives smoother scrolling across
2723 * all gapped visible regions
2725 int lastSeq = alignment.getHeight() - 1;
2726 List<AlignedCodonFrame> seqMappings = null;
2727 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2729 sequence = getAlignment().getSequenceAt(seqNo);
2730 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2734 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2738 seqMappings = MappingUtils
2739 .findMappingsForSequenceAndOthers(sequence, mappings,
2740 getCodingComplement().getAlignment().getSequences());
2741 if (!seqMappings.isEmpty())
2747 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2750 * No ungapped mapped sequence in middle column - do nothing
2754 MappingUtils.addSearchResults(sr, sequence,
2755 sequence.findPosition(middleColumn), seqMappings);
2760 * synthesize a column selection if none exists so it covers the given
2761 * selection group. if wholewidth is false, no column selection is made if the
2762 * selection group covers the whole alignment width.
2767 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2771 && (sgs = sg.getStartRes()) >= 0
2772 && sg.getStartRes() <= (sge = sg.getEndRes())
2773 && !this.hasSelectedColumns())
2775 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2782 colSel = new ColumnSelection();
2784 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2786 colSel.addElement(cspos);
2792 * hold status of current selection group - defined on alignment or not.
2794 private boolean selectionIsDefinedGroup = false;
2797 public boolean isSelectionDefinedGroup()
2799 if (selectionGroup == null)
2803 if (isSelectionGroupChanged(true))
2805 selectionIsDefinedGroup = false;
2806 List<SequenceGroup> gps = alignment.getGroups();
2807 if (gps == null || gps.size() == 0)
2809 selectionIsDefinedGroup = false;
2813 selectionIsDefinedGroup = gps.contains(selectionGroup);
2816 return selectionGroup.getContext() == alignment
2817 || selectionIsDefinedGroup;