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.structure.CommandListener;
48 import jalview.structure.StructureSelectionManager;
49 import jalview.structure.VamsasSource;
50 import jalview.util.Comparison;
51 import jalview.util.MapList;
52 import jalview.util.MappingUtils;
53 import jalview.viewmodel.styles.ViewStyle;
54 import jalview.workers.AlignCalcManager;
55 import jalview.workers.ComplementConsensusThread;
56 import jalview.workers.ConsensusThread;
57 import jalview.workers.StrucConsensusThread;
59 import java.awt.Color;
60 import java.beans.PropertyChangeSupport;
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()
811 || (conservation == null && quality == null)
812 || !autoCalculateConsensus)
817 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
819 calculator.registerWorker(new jalview.workers.ConservationThread(
825 * trigger update of consensus annotation
827 public void updateConsensus(final AlignmentViewPanel ap)
829 // see note in mantis : issue number 8585
830 if (consensus == null || !autoCalculateConsensus)
834 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
836 calculator.registerWorker(new ConsensusThread(this, ap));
840 * A separate thread to compute cDNA consensus for a protein alignment
841 * which has mapping to cDNA
843 final AlignmentI al = this.getAlignment();
844 if (!al.isNucleotide() && al.getCodonFrames() != null
845 && !al.getCodonFrames().isEmpty())
848 * fudge - check first for protein-to-nucleotide mappings
849 * (we don't want to do this for protein-to-protein)
851 boolean doConsensus = false;
852 for (AlignedCodonFrame mapping : al.getCodonFrames())
854 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
855 MapList[] mapLists = mapping.getdnaToProt();
856 // mapLists can be empty if project load has not finished resolving seqs
857 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
866 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
869 .registerWorker(new ComplementConsensusThread(this, ap));
875 // --------START Structure Conservation
876 public void updateStrucConsensus(final AlignmentViewPanel ap)
878 if (autoCalculateStrucConsensus && strucConsensus == null
879 && alignment.isNucleotide() && alignment.hasRNAStructure())
881 // secondary structure has been added - so init the consensus line
885 // see note in mantis : issue number 8585
886 if (strucConsensus == null || !autoCalculateStrucConsensus)
890 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
892 calculator.registerWorker(new StrucConsensusThread(this, ap));
896 public boolean isCalcInProgress()
898 return calculator.isWorking();
902 public boolean isCalculationInProgress(
903 AlignmentAnnotation alignmentAnnotation)
905 if (!alignmentAnnotation.autoCalculated)
909 if (calculator.workingInvolvedWith(alignmentAnnotation))
911 // System.err.println("grey out ("+alignmentAnnotation.label+")");
917 public void setAlignment(AlignmentI align)
919 this.alignment = align;
923 * Clean up references when this viewport is closed
926 public void dispose()
929 * defensively null out references to large objects in case
930 * this object is not garbage collected (as if!)
933 complementConsensus = null;
934 strucConsensus = null;
937 groupConsensus = null;
938 groupConservation = null;
940 hcomplementConsensus = null;
941 // TODO removed listeners from changeSupport?
942 changeSupport = null;
947 public boolean isClosed()
949 // TODO: check that this isClosed is only true after panel is closed, not
950 // before it is fully constructed.
951 return alignment == null;
955 public AlignCalcManagerI getCalcManager()
961 * should conservation rows be shown for groups
963 protected boolean showGroupConservation = false;
966 * should consensus rows be shown for groups
968 protected boolean showGroupConsensus = false;
971 * should consensus profile be rendered by default
973 protected boolean showSequenceLogo = false;
976 * should consensus profile be rendered normalised to row height
978 protected boolean normaliseSequenceLogo = false;
981 * should consensus histograms be rendered by default
983 protected boolean showConsensusHistogram = true;
986 * @return the showConsensusProfile
989 public boolean isShowSequenceLogo()
991 return showSequenceLogo;
995 * @param showSequenceLogo
998 public void setShowSequenceLogo(boolean showSequenceLogo)
1000 if (showSequenceLogo != this.showSequenceLogo)
1002 // TODO: decouple settings setting from calculation when refactoring
1003 // annotation update method from alignframe to viewport
1004 this.showSequenceLogo = showSequenceLogo;
1005 calculator.updateAnnotationFor(ConsensusThread.class);
1006 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1007 calculator.updateAnnotationFor(StrucConsensusThread.class);
1009 this.showSequenceLogo = showSequenceLogo;
1013 * @param showConsensusHistogram
1014 * the showConsensusHistogram to set
1016 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1018 this.showConsensusHistogram = showConsensusHistogram;
1022 * @return the showGroupConservation
1024 public boolean isShowGroupConservation()
1026 return showGroupConservation;
1030 * @param showGroupConservation
1031 * the showGroupConservation to set
1033 public void setShowGroupConservation(boolean showGroupConservation)
1035 this.showGroupConservation = showGroupConservation;
1039 * @return the showGroupConsensus
1041 public boolean isShowGroupConsensus()
1043 return showGroupConsensus;
1047 * @param showGroupConsensus
1048 * the showGroupConsensus to set
1050 public void setShowGroupConsensus(boolean showGroupConsensus)
1052 this.showGroupConsensus = showGroupConsensus;
1057 * @return flag to indicate if the consensus histogram should be rendered by
1061 public boolean isShowConsensusHistogram()
1063 return this.showConsensusHistogram;
1067 * when set, updateAlignment will always ensure sequences are of equal length
1069 private boolean padGaps = false;
1072 * when set, alignment should be reordered according to a newly opened tree
1074 public boolean sortByTree = false;
1079 * @return null or the currently selected sequence region
1082 public SequenceGroup getSelectionGroup()
1084 return selectionGroup;
1088 * Set the selection group for this window.
1091 * - group holding references to sequences in this alignment view
1095 public void setSelectionGroup(SequenceGroup sg)
1097 selectionGroup = sg;
1100 public void setHiddenColumns(ColumnSelection colsel)
1102 this.colSel = colsel;
1106 public ColumnSelection getColumnSelection()
1112 public void setColumnSelection(ColumnSelection colSel)
1114 this.colSel = colSel;
1117 updateHiddenColumns();
1119 isColSelChanged(true);
1127 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1129 return hiddenRepSequences;
1133 public void setHiddenRepSequences(
1134 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1136 this.hiddenRepSequences = hiddenRepSequences;
1140 public boolean hasSelectedColumns()
1142 ColumnSelection columnSelection = getColumnSelection();
1143 return columnSelection != null && columnSelection.hasSelectedColumns();
1147 public boolean hasHiddenColumns()
1149 return colSel != null && colSel.hasHiddenColumns();
1152 public void updateHiddenColumns()
1154 // this method doesn't really do anything now. But - it could, since a
1155 // column Selection could be in the process of modification
1156 // hasHiddenColumns = colSel.hasHiddenColumns();
1160 public boolean hasHiddenRows()
1162 return alignment.getHiddenSequences().getSize() > 0;
1165 protected SequenceGroup selectionGroup;
1167 public void setSequenceSetId(String newid)
1169 if (sequenceSetID != null)
1172 .println("Warning - overwriting a sequenceSetId for a viewport!");
1174 sequenceSetID = new String(newid);
1178 public String getSequenceSetId()
1180 if (sequenceSetID == null)
1182 sequenceSetID = alignment.hashCode() + "";
1185 return sequenceSetID;
1189 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1192 protected String viewId = null;
1195 public String getViewId()
1199 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1204 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1206 ignoreGapsInConsensusCalculation = b;
1209 updateConsensus(ap);
1210 if (globalColourScheme != null)
1212 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1213 ignoreGapsInConsensusCalculation);
1219 private long sgrouphash = -1, colselhash = -1;
1222 * checks current SelectionGroup against record of last hash value, and
1226 * update the record of last hash value
1228 * @return true if SelectionGroup changed since last call (when b is true)
1230 public boolean isSelectionGroupChanged(boolean b)
1232 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1233 : selectionGroup.hashCode();
1234 if (hc != -1 && hc != sgrouphash)
1246 * checks current colsel against record of last hash value, and optionally
1250 * update the record of last hash value
1251 * @return true if colsel changed since last call (when b is true)
1253 public boolean isColSelChanged(boolean b)
1255 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1256 if (hc != -1 && hc != colselhash)
1268 public boolean isIgnoreGapsConsensus()
1270 return ignoreGapsInConsensusCalculation;
1273 // property change stuff
1274 // JBPNote Prolly only need this in the applet version.
1275 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1278 protected boolean showConservation = true;
1280 protected boolean showQuality = true;
1282 protected boolean showConsensus = true;
1284 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1286 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1288 protected boolean showAutocalculatedAbove;
1291 * when set, view will scroll to show the highlighted position
1293 private boolean followHighlight = true;
1295 // TODO private with getters and setters?
1296 public int startRes;
1300 public int startSeq;
1305 * Property change listener for changes in alignment
1310 public void addPropertyChangeListener(
1311 java.beans.PropertyChangeListener listener)
1313 changeSupport.addPropertyChangeListener(listener);
1322 public void removePropertyChangeListener(
1323 java.beans.PropertyChangeListener listener)
1325 changeSupport.removePropertyChangeListener(listener);
1329 * Property change listener for changes in alignment
1338 public void firePropertyChange(String prop, Object oldvalue,
1341 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1344 // common hide/show column stuff
1346 public void hideSelectedColumns()
1348 if (colSel.isEmpty())
1353 colSel.hideSelectedColumns();
1354 setSelectionGroup(null);
1355 isColSelChanged(true);
1358 public void hideColumns(int start, int end)
1362 colSel.hideColumns(start);
1366 colSel.hideColumns(start, end);
1368 isColSelChanged(true);
1371 public void showColumn(int col)
1373 colSel.revealHiddenColumns(col);
1374 isColSelChanged(true);
1377 public void showAllHiddenColumns()
1379 colSel.revealAllHiddenColumns();
1380 isColSelChanged(true);
1383 // common hide/show seq stuff
1384 public void showAllHiddenSeqs()
1386 if (alignment.getHiddenSequences().getSize() > 0)
1388 if (selectionGroup == null)
1390 selectionGroup = new SequenceGroup();
1391 selectionGroup.setEndRes(alignment.getWidth() - 1);
1393 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1394 hiddenRepSequences);
1395 for (SequenceI seq : tmp)
1397 selectionGroup.addSequence(seq, false);
1398 setSequenceAnnotationsVisible(seq, true);
1401 hiddenRepSequences = null;
1403 firePropertyChange("alignment", null, alignment.getSequences());
1404 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1410 public void showSequence(int index)
1412 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1413 index, hiddenRepSequences);
1416 if (selectionGroup == null)
1418 selectionGroup = new SequenceGroup();
1419 selectionGroup.setEndRes(alignment.getWidth() - 1);
1422 for (SequenceI seq : tmp)
1424 selectionGroup.addSequence(seq, false);
1425 setSequenceAnnotationsVisible(seq, true);
1427 firePropertyChange("alignment", null, alignment.getSequences());
1432 public void hideAllSelectedSeqs()
1434 if (selectionGroup == null || selectionGroup.getSize() < 1)
1439 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1443 setSelectionGroup(null);
1446 public void hideSequence(SequenceI[] seq)
1450 for (int i = 0; i < seq.length; i++)
1452 alignment.getHiddenSequences().hideSequence(seq[i]);
1453 setSequenceAnnotationsVisible(seq[i], false);
1455 firePropertyChange("alignment", null, alignment.getSequences());
1460 * Hides the specified sequence, or the sequences it represents
1463 * the sequence to hide, or keep as representative
1464 * @param representGroup
1465 * if true, hide the current selection group except for the
1466 * representative sequence
1468 public void hideSequences(SequenceI sequence, boolean representGroup)
1470 if (selectionGroup == null || selectionGroup.getSize() < 1)
1472 hideSequence(new SequenceI[] { sequence });
1478 hideRepSequences(sequence, selectionGroup);
1479 setSelectionGroup(null);
1483 int gsize = selectionGroup.getSize();
1484 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1485 new SequenceI[gsize]);
1487 hideSequence(hseqs);
1488 setSelectionGroup(null);
1493 * Set visibility for any annotations for the given sequence.
1497 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1500 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1503 for (AlignmentAnnotation ann : anns)
1505 if (ann.sequenceRef == sequenceI)
1507 ann.visible = visible;
1513 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1515 int sSize = sg.getSize();
1521 if (hiddenRepSequences == null)
1523 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1526 hiddenRepSequences.put(repSequence, sg);
1528 // Hide all sequences except the repSequence
1529 SequenceI[] seqs = new SequenceI[sSize - 1];
1531 for (int i = 0; i < sSize; i++)
1533 if (sg.getSequenceAt(i) != repSequence)
1535 if (index == sSize - 1)
1540 seqs[index++] = sg.getSequenceAt(i);
1543 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1544 sg.setHidereps(true); // note: not done in 2.7applet
1551 * @return null or the current reference sequence
1553 public SequenceI getReferenceSeq()
1555 return alignment.getSeqrep();
1560 * @return true iff seq is the reference for the alignment
1562 public boolean isReferenceSeq(SequenceI seq)
1564 return alignment.getSeqrep() == seq;
1570 * @return true if there are sequences represented by this sequence that are
1573 public boolean isHiddenRepSequence(SequenceI seq)
1575 return (hiddenRepSequences != null && hiddenRepSequences
1582 * @return null or a sequence group containing the sequences that seq
1585 public SequenceGroup getRepresentedSequences(SequenceI seq)
1587 return (SequenceGroup) (hiddenRepSequences == null ? null
1588 : hiddenRepSequences.get(seq));
1592 public int adjustForHiddenSeqs(int alignmentIndex)
1594 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1599 public void invertColumnSelection()
1601 colSel.invertColumnSelection(0, alignment.getWidth());
1605 public SequenceI[] getSelectionAsNewSequence()
1607 SequenceI[] sequences;
1608 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1609 // this was the only caller in the applet for this method
1610 // JBPNote: in applet, this method returned references to the alignment
1611 // sequences, and it did not honour the presence/absence of annotation
1612 // attached to the alignment (probably!)
1613 if (selectionGroup == null || selectionGroup.getSize() == 0)
1615 sequences = alignment.getSequencesArray();
1616 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1617 for (int i = 0; i < sequences.length; i++)
1619 // construct new sequence with subset of visible annotation
1620 sequences[i] = new Sequence(sequences[i], annots);
1625 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1632 public SequenceI[] getSequenceSelection()
1634 SequenceI[] sequences = null;
1635 if (selectionGroup != null)
1637 sequences = selectionGroup.getSequencesInOrder(alignment);
1639 if (sequences == null)
1641 sequences = alignment.getSequencesArray();
1647 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1649 return new CigarArray(alignment, colSel,
1650 (selectedRegionOnly ? selectionGroup : null));
1654 public jalview.datamodel.AlignmentView getAlignmentView(
1655 boolean selectedOnly)
1657 return getAlignmentView(selectedOnly, false);
1661 public jalview.datamodel.AlignmentView getAlignmentView(
1662 boolean selectedOnly, boolean markGroups)
1664 return new AlignmentView(alignment, colSel, selectionGroup,
1665 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1670 public String[] getViewAsString(boolean selectedRegionOnly)
1672 return getViewAsString(selectedRegionOnly, true);
1676 public String[] getViewAsString(boolean selectedRegionOnly,
1677 boolean exportHiddenSeqs)
1679 String[] selection = null;
1680 SequenceI[] seqs = null;
1682 int start = 0, end = 0;
1683 if (selectedRegionOnly && selectionGroup != null)
1685 iSize = selectionGroup.getSize();
1686 seqs = selectionGroup.getSequencesInOrder(alignment);
1687 start = selectionGroup.getStartRes();
1688 end = selectionGroup.getEndRes() + 1;
1692 if (hasHiddenRows() && exportHiddenSeqs)
1694 AlignmentI fullAlignment = alignment.getHiddenSequences()
1695 .getFullAlignment();
1696 iSize = fullAlignment.getHeight();
1697 seqs = fullAlignment.getSequencesArray();
1698 end = fullAlignment.getWidth();
1702 iSize = alignment.getHeight();
1703 seqs = alignment.getSequencesArray();
1704 end = alignment.getWidth();
1708 selection = new String[iSize];
1709 if (colSel != null && colSel.hasHiddenColumns())
1711 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1715 for (i = 0; i < iSize; i++)
1717 selection[i] = seqs[i].getSequenceAsString(start, end);
1725 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1727 ArrayList<int[]> regions = new ArrayList<int[]>();
1733 if (colSel != null && colSel.hasHiddenColumns())
1737 start = colSel.adjustForHiddenColumns(start);
1740 end = colSel.getHiddenBoundaryRight(start);
1751 regions.add(new int[] { start, end });
1753 if (colSel != null && colSel.hasHiddenColumns())
1755 start = colSel.adjustForHiddenColumns(end);
1756 start = colSel.getHiddenBoundaryLeft(start) + 1;
1758 } while (end < max);
1760 int[][] startEnd = new int[regions.size()][2];
1766 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1767 boolean selectedOnly)
1769 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1770 AlignmentAnnotation[] aa;
1771 if ((aa = alignment.getAlignmentAnnotation()) != null)
1773 for (AlignmentAnnotation annot : aa)
1775 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1776 if (selectedOnly && selectionGroup != null)
1778 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1779 selectionGroup.getEndRes(), clone);
1783 colSel.makeVisibleAnnotation(clone);
1792 public boolean isPadGaps()
1798 public void setPadGaps(boolean padGaps)
1800 this.padGaps = padGaps;
1804 * apply any post-edit constraints and trigger any calculations needed after
1805 * an edit has been performed on the alignment
1810 public void alignmentChanged(AlignmentViewPanel ap)
1814 alignment.padGaps();
1816 if (autoCalculateConsensus)
1818 updateConsensus(ap);
1820 if (hconsensus != null && autoCalculateConsensus)
1822 updateConservation(ap);
1824 if (autoCalculateStrucConsensus)
1826 updateStrucConsensus(ap);
1829 // Reset endRes of groups if beyond alignment width
1830 int alWidth = alignment.getWidth();
1831 List<SequenceGroup> groups = alignment.getGroups();
1834 for (SequenceGroup sg : groups)
1836 if (sg.getEndRes() > alWidth)
1838 sg.setEndRes(alWidth - 1);
1843 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1845 selectionGroup.setEndRes(alWidth - 1);
1848 resetAllColourSchemes();
1849 calculator.restartWorkers();
1850 // alignment.adjustSequenceAnnotations();
1854 * reset scope and do calculations for all applied colourschemes on alignment
1856 void resetAllColourSchemes()
1858 ColourSchemeI cs = globalColourScheme;
1861 cs.alignmentChanged(alignment, hiddenRepSequences);
1863 cs.setConsensus(hconsensus);
1864 if (cs.conservationApplied())
1866 cs.setConservation(Conservation.calculateConservation("All", 3,
1867 alignment.getSequences(), 0, alignment.getWidth(), false,
1868 getConsPercGaps(), false));
1872 for (SequenceGroup sg : alignment.getGroups())
1876 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1878 sg.recalcConservation();
1882 protected void initAutoAnnotation()
1884 // TODO: add menu option action that nulls or creates consensus object
1885 // depending on if the user wants to see the annotation or not in a
1886 // specific alignment
1888 if (hconsensus == null && !isDataset)
1890 if (!alignment.isNucleotide())
1899 consensus = new AlignmentAnnotation("Consensus", "PID",
1900 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1901 initConsensus(consensus);
1903 initComplementConsensus();
1908 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1909 * consensus annotation.
1911 public void initComplementConsensus()
1913 if (!alignment.isNucleotide())
1915 final List<AlignedCodonFrame> codonMappings = alignment
1917 if (codonMappings != null && !codonMappings.isEmpty())
1919 boolean doConsensus = false;
1920 for (AlignedCodonFrame mapping : codonMappings)
1922 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1923 MapList[] mapLists = mapping.getdnaToProt();
1924 // mapLists can be empty if project load has not finished resolving
1926 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1934 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1935 "PID for cDNA", new Annotation[1], 0f, 100f,
1936 AlignmentAnnotation.BAR_GRAPH);
1937 initConsensus(complementConsensus);
1943 private void initConsensus(AlignmentAnnotation aa)
1946 aa.autoCalculated = true;
1950 alignment.addAnnotation(aa);
1954 private void initConservation()
1956 if (showConservation)
1958 if (conservation == null)
1960 conservation = new AlignmentAnnotation("Conservation",
1961 "Conservation of total alignment less than "
1962 + getConsPercGaps() + "% gaps", new Annotation[1],
1963 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1964 conservation.hasText = true;
1965 conservation.autoCalculated = true;
1966 alignment.addAnnotation(conservation);
1971 private void initQuality()
1975 if (quality == null)
1977 quality = new AlignmentAnnotation("Quality",
1978 "Alignment Quality based on Blosum62 scores",
1979 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1980 quality.hasText = true;
1981 quality.autoCalculated = true;
1982 alignment.addAnnotation(quality);
1987 private void initRNAStructure()
1989 if (alignment.hasRNAStructure() && strucConsensus == null)
1991 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1992 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1993 strucConsensus.hasText = true;
1994 strucConsensus.autoCalculated = true;
1998 alignment.addAnnotation(strucConsensus);
2006 * @see jalview.api.AlignViewportI#calcPanelHeight()
2009 public int calcPanelHeight()
2011 // setHeight of panels
2012 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2014 int charHeight = getCharHeight();
2017 BitSet graphgrp = new BitSet();
2018 for (AlignmentAnnotation aa : anns)
2022 System.err.println("Null annotation row: ignoring.");
2029 if (aa.graphGroup > -1)
2031 if (graphgrp.get(aa.graphGroup))
2037 graphgrp.set(aa.graphGroup);
2044 aa.height += charHeight;
2054 aa.height += aa.graphHeight;
2062 height += aa.height;
2074 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2075 boolean preserveNewGroupSettings)
2077 boolean updateCalcs = false;
2078 boolean conv = isShowGroupConservation();
2079 boolean cons = isShowGroupConsensus();
2080 boolean showprf = isShowSequenceLogo();
2081 boolean showConsHist = isShowConsensusHistogram();
2082 boolean normLogo = isNormaliseSequenceLogo();
2085 * TODO reorder the annotation rows according to group/sequence ordering on
2088 boolean sortg = true;
2090 // remove old automatic annotation
2091 // add any new annotation
2093 // intersect alignment annotation with alignment groups
2095 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2096 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2099 for (int an = 0; an < aan.length; an++)
2101 if (aan[an].autoCalculated && aan[an].groupRef != null)
2103 oldrfs.add(aan[an].groupRef);
2104 alignment.deleteAnnotation(aan[an], false);
2108 if (alignment.getGroups() != null)
2110 for (SequenceGroup sg : alignment.getGroups())
2112 updateCalcs = false;
2113 if (applyGlobalSettings
2114 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2116 // set defaults for this group's conservation/consensus
2117 sg.setshowSequenceLogo(showprf);
2118 sg.setShowConsensusHistogram(showConsHist);
2119 sg.setNormaliseSequenceLogo(normLogo);
2124 alignment.addAnnotation(sg.getConservationRow(), 0);
2129 alignment.addAnnotation(sg.getConsensus(), 0);
2131 // refresh the annotation rows
2134 sg.recalcConservation();
2142 public boolean isDisplayReferenceSeq()
2144 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2148 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2150 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2154 public boolean isColourByReferenceSeq()
2156 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2160 public Color getSequenceColour(SequenceI seq)
2162 Color sqc = sequenceColours.get(seq);
2163 return (sqc == null ? Color.white : sqc);
2167 public void setSequenceColour(SequenceI seq, Color col)
2171 sequenceColours.remove(seq);
2175 sequenceColours.put(seq, col);
2180 public void updateSequenceIdColours()
2182 for (SequenceGroup sg : alignment.getGroups())
2184 if (sg.idColour != null)
2186 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2188 sequenceColours.put(s, sg.idColour);
2195 public void clearSequenceColours()
2197 sequenceColours.clear();
2201 public AlignViewportI getCodingComplement()
2203 return this.codingComplement;
2207 * Set this as the (cDna/protein) complement of the given viewport. Also
2208 * ensures the reverse relationship is set on the given viewport.
2211 public void setCodingComplement(AlignViewportI av)
2215 System.err.println("Ignoring recursive setCodingComplement request");
2219 this.codingComplement = av;
2220 // avoid infinite recursion!
2221 if (av.getCodingComplement() != this)
2223 av.setCodingComplement(this);
2229 public boolean isNucleotide()
2231 return getAlignment() == null ? false : getAlignment().isNucleotide();
2235 public FeaturesDisplayedI getFeaturesDisplayed()
2237 return featuresDisplayed;
2241 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2243 featuresDisplayed = featuresDisplayedI;
2247 public boolean areFeaturesDisplayed()
2249 return featuresDisplayed != null
2250 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2257 * features are displayed if true
2260 public void setShowSequenceFeatures(boolean b)
2262 viewStyle.setShowSequenceFeatures(b);
2266 public boolean isShowSequenceFeatures()
2268 return viewStyle.isShowSequenceFeatures();
2272 public void setShowSequenceFeaturesHeight(boolean selected)
2274 viewStyle.setShowSequenceFeaturesHeight(selected);
2278 public boolean isShowSequenceFeaturesHeight()
2280 return viewStyle.isShowSequenceFeaturesHeight();
2284 public void setShowAnnotation(boolean b)
2286 viewStyle.setShowAnnotation(b);
2290 public boolean isShowAnnotation()
2292 return viewStyle.isShowAnnotation();
2296 public boolean isRightAlignIds()
2298 return viewStyle.isRightAlignIds();
2302 public void setRightAlignIds(boolean rightAlignIds)
2304 viewStyle.setRightAlignIds(rightAlignIds);
2308 public boolean getConservationSelected()
2310 return viewStyle.getConservationSelected();
2314 public void setShowBoxes(boolean state)
2316 viewStyle.setShowBoxes(state);
2321 * @see jalview.api.ViewStyleI#getTextColour()
2324 public Color getTextColour()
2326 return viewStyle.getTextColour();
2331 * @see jalview.api.ViewStyleI#getTextColour2()
2334 public Color getTextColour2()
2336 return viewStyle.getTextColour2();
2341 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2344 public int getThresholdTextColour()
2346 return viewStyle.getThresholdTextColour();
2351 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2354 public boolean isConservationColourSelected()
2356 return viewStyle.isConservationColourSelected();
2361 * @see jalview.api.ViewStyleI#isRenderGaps()
2364 public boolean isRenderGaps()
2366 return viewStyle.isRenderGaps();
2371 * @see jalview.api.ViewStyleI#isShowColourText()
2374 public boolean isShowColourText()
2376 return viewStyle.isShowColourText();
2380 * @param conservationColourSelected
2381 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2384 public void setConservationColourSelected(
2385 boolean conservationColourSelected)
2387 viewStyle.setConservationColourSelected(conservationColourSelected);
2391 * @param showColourText
2392 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2395 public void setShowColourText(boolean showColourText)
2397 viewStyle.setShowColourText(showColourText);
2402 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2405 public void setTextColour(Color textColour)
2407 viewStyle.setTextColour(textColour);
2411 * @param thresholdTextColour
2412 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2415 public void setThresholdTextColour(int thresholdTextColour)
2417 viewStyle.setThresholdTextColour(thresholdTextColour);
2421 * @param textColour2
2422 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2425 public void setTextColour2(Color textColour2)
2427 viewStyle.setTextColour2(textColour2);
2431 public ViewStyleI getViewStyle()
2433 return new ViewStyle(viewStyle);
2437 public void setViewStyle(ViewStyleI settingsForView)
2439 viewStyle = new ViewStyle(settingsForView);
2443 public boolean sameStyle(ViewStyleI them)
2445 return viewStyle.sameStyle(them);
2450 * @see jalview.api.ViewStyleI#getIdWidth()
2453 public int getIdWidth()
2455 return viewStyle.getIdWidth();
2460 * @see jalview.api.ViewStyleI#setIdWidth(int)
2463 public void setIdWidth(int i)
2465 viewStyle.setIdWidth(i);
2470 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2473 public boolean isCentreColumnLabels()
2475 return viewStyle.isCentreColumnLabels();
2479 * @param centreColumnLabels
2480 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2483 public void setCentreColumnLabels(boolean centreColumnLabels)
2485 viewStyle.setCentreColumnLabels(centreColumnLabels);
2490 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2493 public void setShowDBRefs(boolean showdbrefs)
2495 viewStyle.setShowDBRefs(showdbrefs);
2500 * @see jalview.api.ViewStyleI#isShowDBRefs()
2503 public boolean isShowDBRefs()
2505 return viewStyle.isShowDBRefs();
2510 * @see jalview.api.ViewStyleI#isShowNPFeats()
2513 public boolean isShowNPFeats()
2515 return viewStyle.isShowNPFeats();
2519 * @param shownpfeats
2520 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2523 public void setShowNPFeats(boolean shownpfeats)
2525 viewStyle.setShowNPFeats(shownpfeats);
2528 public abstract StructureSelectionManager getStructureSelectionManager();
2531 * Add one command to the command history list.
2535 public void addToHistoryList(CommandI command)
2537 if (this.historyList != null)
2539 this.historyList.push(command);
2540 broadcastCommand(command, false);
2544 protected void broadcastCommand(CommandI command, boolean undo)
2546 getStructureSelectionManager().commandPerformed(command, undo,
2551 * Add one command to the command redo list.
2555 public void addToRedoList(CommandI command)
2557 if (this.redoList != null)
2559 this.redoList.push(command);
2561 broadcastCommand(command, true);
2565 * Clear the command redo list.
2567 public void clearRedoList()
2569 if (this.redoList != null)
2571 this.redoList.clear();
2575 public void setHistoryList(Deque<CommandI> list)
2577 this.historyList = list;
2580 public Deque<CommandI> getHistoryList()
2582 return this.historyList;
2585 public void setRedoList(Deque<CommandI> list)
2587 this.redoList = list;
2590 public Deque<CommandI> getRedoList()
2592 return this.redoList;
2596 public VamsasSource getVamsasSource()
2601 public SequenceAnnotationOrder getSortAnnotationsBy()
2603 return sortAnnotationsBy;
2606 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2608 this.sortAnnotationsBy = sortAnnotationsBy;
2611 public boolean isShowAutocalculatedAbove()
2613 return showAutocalculatedAbove;
2616 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2618 this.showAutocalculatedAbove = showAutocalculatedAbove;
2622 public boolean isScaleProteinAsCdna()
2624 return viewStyle.isScaleProteinAsCdna();
2628 public void setScaleProteinAsCdna(boolean b)
2630 viewStyle.setScaleProteinAsCdna(b);
2634 * @return true if view should scroll to show the highlighted region of a
2639 public final boolean isFollowHighlight()
2641 return followHighlight;
2645 public final void setFollowHighlight(boolean b)
2647 this.followHighlight = b;
2650 public int getStartRes()
2656 public int getEndRes()
2661 public int getStartSeq()
2666 public void setStartRes(int res)
2668 this.startRes = res;
2671 public void setStartSeq(int seq)
2673 this.startSeq = seq;
2676 public void setEndRes(int res)
2678 if (res > alignment.getWidth() - 1)
2680 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2681 // (alignment.getWidth()-1));
2682 res = alignment.getWidth() - 1;
2691 public void setEndSeq(int seq)
2693 if (seq > alignment.getHeight())
2695 seq = alignment.getHeight();
2704 public int getEndSeq()
2710 * Helper method to populate the SearchResults with the location in the
2711 * complementary alignment to scroll to, in order to match this one.
2714 * the SearchResults to add to
2715 * @return the offset (below top of visible region) of the matched sequence
2717 protected int findComplementScrollTarget(SearchResults sr)
2719 final AlignViewportI complement = getCodingComplement();
2720 if (complement == null || !complement.isFollowHighlight())
2724 boolean iAmProtein = !getAlignment().isNucleotide();
2725 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2727 if (proteinAlignment == null)
2731 final List<AlignedCodonFrame> mappings = proteinAlignment
2735 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2736 * residue in the middle column of the visible region. Scroll the
2737 * complementary alignment to line up the corresponding residue.
2740 SequenceI sequence = null;
2743 * locate 'middle' column (true middle if an odd number visible, left of
2744 * middle if an even number visible)
2746 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2747 final HiddenSequences hiddenSequences = getAlignment()
2748 .getHiddenSequences();
2751 * searching to the bottom of the alignment gives smoother scrolling across
2752 * all gapped visible regions
2754 int lastSeq = alignment.getHeight() - 1;
2755 List<AlignedCodonFrame> seqMappings = null;
2756 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2758 sequence = getAlignment().getSequenceAt(seqNo);
2759 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2763 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2767 seqMappings = MappingUtils
2768 .findMappingsForSequenceAndOthers(sequence, mappings,
2769 getCodingComplement().getAlignment().getSequences());
2770 if (!seqMappings.isEmpty())
2776 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2779 * No ungapped mapped sequence in middle column - do nothing
2783 MappingUtils.addSearchResults(sr, sequence,
2784 sequence.findPosition(middleColumn), seqMappings);
2789 * synthesize a column selection if none exists so it covers the given
2790 * selection group. if wholewidth is false, no column selection is made if the
2791 * selection group covers the whole alignment width.
2796 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2800 && (sgs = sg.getStartRes()) >= 0
2801 && sg.getStartRes() <= (sge = sg.getEndRes())
2802 && !this.hasSelectedColumns())
2804 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2811 colSel = new ColumnSelection();
2813 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2815 colSel.addElement(cspos);
2821 * hold status of current selection group - defined on alignment or not.
2823 private boolean selectionIsDefinedGroup = false;
2826 public boolean isSelectionDefinedGroup()
2828 if (selectionGroup == null)
2832 if (isSelectionGroupChanged(true))
2834 selectionIsDefinedGroup = false;
2835 List<SequenceGroup> gps = alignment.getGroups();
2836 if (gps == null || gps.size() == 0)
2838 selectionIsDefinedGroup = false;
2842 selectionIsDefinedGroup = gps.contains(selectionGroup);
2845 return selectionGroup.getContext() == alignment
2846 || selectionIsDefinedGroup;