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.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.renderer.ResidueShader;
47 import jalview.renderer.ResidueShaderI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.util.MessageManager;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.StrucConsensusThread;
62 import java.awt.Color;
63 import java.beans.PropertyChangeSupport;
64 import java.util.ArrayDeque;
65 import java.util.ArrayList;
66 import java.util.BitSet;
67 import java.util.Deque;
68 import java.util.HashMap;
69 import java.util.Hashtable;
70 import java.util.List;
74 * base class holding visualization and analysis attributes and common logic for
75 * an active alignment view displayed in the GUI
80 public abstract class AlignmentViewport implements AlignViewportI,
81 CommandListener, VamsasSource
83 final protected ViewportRanges ranges;
85 protected ViewStyleI viewStyle = new ViewStyle();
88 * A viewport that hosts the cDna view of this (protein), or vice versa (if
91 AlignViewportI codingComplement = null;
93 FeaturesDisplayedI featuresDisplayed = null;
95 protected Deque<CommandI> historyList = new ArrayDeque<>();
97 protected Deque<CommandI> redoList = new ArrayDeque<>();
101 * alignment displayed in the viewport. Please use get/setter
103 protected AlignmentI alignment;
105 public AlignmentViewport(AlignmentI al)
108 ranges = new ViewportRanges(al);
113 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
116 public void setFontName(String name)
118 viewStyle.setFontName(name);
123 * @see jalview.api.ViewStyleI#setFontStyle(int)
126 public void setFontStyle(int style)
128 viewStyle.setFontStyle(style);
133 * @see jalview.api.ViewStyleI#setFontSize(int)
136 public void setFontSize(int size)
138 viewStyle.setFontSize(size);
143 * @see jalview.api.ViewStyleI#getFontStyle()
146 public int getFontStyle()
148 return viewStyle.getFontStyle();
153 * @see jalview.api.ViewStyleI#getFontName()
156 public String getFontName()
158 return viewStyle.getFontName();
163 * @see jalview.api.ViewStyleI#getFontSize()
166 public int getFontSize()
168 return viewStyle.getFontSize();
172 * @param upperCasebold
173 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
176 public void setUpperCasebold(boolean upperCasebold)
178 viewStyle.setUpperCasebold(upperCasebold);
183 * @see jalview.api.ViewStyleI#isUpperCasebold()
186 public boolean isUpperCasebold()
188 return viewStyle.isUpperCasebold();
193 * @see jalview.api.ViewStyleI#isSeqNameItalics()
196 public boolean isSeqNameItalics()
198 return viewStyle.isSeqNameItalics();
202 * @param colourByReferenceSeq
203 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
206 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
208 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
213 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
216 public void setColourAppliesToAllGroups(boolean b)
218 viewStyle.setColourAppliesToAllGroups(b);
223 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
226 public boolean getColourAppliesToAllGroups()
228 return viewStyle.getColourAppliesToAllGroups();
233 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
236 public boolean getAbovePIDThreshold()
238 return viewStyle.getAbovePIDThreshold();
243 * @see jalview.api.ViewStyleI#setIncrement(int)
246 public void setIncrement(int inc)
248 viewStyle.setIncrement(inc);
253 * @see jalview.api.ViewStyleI#getIncrement()
256 public int getIncrement()
258 return viewStyle.getIncrement();
263 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
266 public void setConservationSelected(boolean b)
268 viewStyle.setConservationSelected(b);
273 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
276 public void setShowHiddenMarkers(boolean show)
278 viewStyle.setShowHiddenMarkers(show);
283 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
286 public boolean getShowHiddenMarkers()
288 return viewStyle.getShowHiddenMarkers();
293 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
296 public void setScaleRightWrapped(boolean b)
298 viewStyle.setScaleRightWrapped(b);
303 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
306 public void setScaleLeftWrapped(boolean b)
308 viewStyle.setScaleLeftWrapped(b);
313 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
316 public void setScaleAboveWrapped(boolean b)
318 viewStyle.setScaleAboveWrapped(b);
323 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
326 public boolean getScaleLeftWrapped()
328 return viewStyle.getScaleLeftWrapped();
333 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
336 public boolean getScaleAboveWrapped()
338 return viewStyle.getScaleAboveWrapped();
343 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
346 public boolean getScaleRightWrapped()
348 return viewStyle.getScaleRightWrapped();
353 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
356 public void setAbovePIDThreshold(boolean b)
358 viewStyle.setAbovePIDThreshold(b);
363 * @see jalview.api.ViewStyleI#setThreshold(int)
366 public void setThreshold(int thresh)
368 viewStyle.setThreshold(thresh);
373 * @see jalview.api.ViewStyleI#getThreshold()
376 public int getThreshold()
378 return viewStyle.getThreshold();
383 * @see jalview.api.ViewStyleI#getShowJVSuffix()
386 public boolean getShowJVSuffix()
388 return viewStyle.getShowJVSuffix();
393 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
396 public void setShowJVSuffix(boolean b)
398 viewStyle.setShowJVSuffix(b);
403 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
406 public void setWrapAlignment(boolean state)
408 viewStyle.setWrapAlignment(state);
413 * @see jalview.api.ViewStyleI#setShowText(boolean)
416 public void setShowText(boolean state)
418 viewStyle.setShowText(state);
423 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
426 public void setRenderGaps(boolean state)
428 viewStyle.setRenderGaps(state);
433 * @see jalview.api.ViewStyleI#getColourText()
436 public boolean getColourText()
438 return viewStyle.getColourText();
443 * @see jalview.api.ViewStyleI#setColourText(boolean)
446 public void setColourText(boolean state)
448 viewStyle.setColourText(state);
453 * @see jalview.api.ViewStyleI#getWrapAlignment()
456 public boolean getWrapAlignment()
458 return viewStyle.getWrapAlignment();
463 * @see jalview.api.ViewStyleI#getShowText()
466 public boolean getShowText()
468 return viewStyle.getShowText();
473 * @see jalview.api.ViewStyleI#getWrappedWidth()
476 public int getWrappedWidth()
478 return viewStyle.getWrappedWidth();
483 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
486 public void setWrappedWidth(int w)
488 viewStyle.setWrappedWidth(w);
493 * @see jalview.api.ViewStyleI#getCharHeight()
496 public int getCharHeight()
498 return viewStyle.getCharHeight();
503 * @see jalview.api.ViewStyleI#setCharHeight(int)
506 public void setCharHeight(int h)
508 viewStyle.setCharHeight(h);
513 * @see jalview.api.ViewStyleI#getCharWidth()
516 public int getCharWidth()
518 return viewStyle.getCharWidth();
523 * @see jalview.api.ViewStyleI#setCharWidth(int)
526 public void setCharWidth(int w)
528 viewStyle.setCharWidth(w);
533 * @see jalview.api.ViewStyleI#getShowBoxes()
536 public boolean getShowBoxes()
538 return viewStyle.getShowBoxes();
543 * @see jalview.api.ViewStyleI#getShowUnconserved()
546 public boolean getShowUnconserved()
548 return viewStyle.getShowUnconserved();
552 * @param showunconserved
553 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
556 public void setShowUnconserved(boolean showunconserved)
558 viewStyle.setShowUnconserved(showunconserved);
563 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
566 public void setSeqNameItalics(boolean default1)
568 viewStyle.setSeqNameItalics(default1);
574 public AlignmentI getAlignment()
580 public char getGapCharacter()
582 return alignment.getGapCharacter();
585 protected String sequenceSetID;
588 * probably unused indicator that view is of a dataset rather than an
591 protected boolean isDataset = false;
593 public void setDataset(boolean b)
598 public boolean isDataset()
603 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
605 protected ColumnSelection colSel = new ColumnSelection();
607 public boolean autoCalculateConsensus = true;
609 protected boolean autoCalculateStrucConsensus = true;
611 protected boolean ignoreGapsInConsensusCalculation = false;
613 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
615 protected ResidueShaderI residueShading = new ResidueShader();
618 public void setGlobalColourScheme(ColourSchemeI cs)
620 // TODO: logic refactored from AlignFrame changeColour -
621 // TODO: autorecalc stuff should be changed to rely on the worker system
622 // check to see if we should implement a changeColour(cs) method rather than
623 // put the logic in here
624 // - means that caller decides if they want to just modify state and defer
625 // calculation till later or to do all calculations in thread.
629 * only instantiate alignment colouring once, thereafter update it;
630 * this means that any conservation or PID threshold settings
631 * persist when the alignment colour scheme is changed
633 if (residueShading == null)
635 residueShading = new ResidueShader(viewStyle);
637 residueShading.setColourScheme(cs);
639 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
640 // ...problem: groups need these, but do not currently have a ViewStyle
644 if (getConservationSelected())
646 residueShading.setConservation(hconservation);
648 residueShading.alignmentChanged(alignment, hiddenRepSequences);
652 * if 'apply colour to all groups' is selected... do so
653 * (but don't transfer any colour threshold settings to groups)
655 if (getColourAppliesToAllGroups())
657 for (SequenceGroup sg : getAlignment().getGroups())
660 * retain any colour thresholds per group while
661 * changing choice of colour scheme (JAL-2386)
663 sg.setColourScheme(cs);
666 sg.getGroupColourScheme()
667 .alignmentChanged(sg, hiddenRepSequences);
674 public ColourSchemeI getGlobalColourScheme()
676 return residueShading == null ? null : residueShading
681 public ResidueShaderI getResidueShading()
683 return residueShading;
686 protected AlignmentAnnotation consensus;
688 protected AlignmentAnnotation complementConsensus;
690 protected AlignmentAnnotation gapcounts;
692 protected AlignmentAnnotation strucConsensus;
694 protected AlignmentAnnotation conservation;
696 protected AlignmentAnnotation quality;
698 protected AlignmentAnnotation[] groupConsensus;
700 protected AlignmentAnnotation[] groupConservation;
702 protected AlignmentAnnotation hmmConsensus;
705 * results of alignment consensus analysis for visible portion of view
707 protected ProfilesI hconsensus = null;
710 * results of cDNA complement consensus visible portion of view
712 protected Hashtable[] hcomplementConsensus = null;
715 * results of secondary structure base pair consensus for visible portion of
718 protected Hashtable[] hStrucConsensus = null;
720 protected Conservation hconservation = null;
723 public void setConservation(Conservation cons)
725 hconservation = cons;
729 * percentage gaps allowed in a column before all amino acid properties should
730 * be considered unconserved
732 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
735 public int getConsPercGaps()
741 public void setSequenceConsensusHash(ProfilesI hconsensus)
743 this.hconsensus = hconsensus;
747 public void setComplementConsensusHash(Hashtable[] hconsensus)
749 this.hcomplementConsensus = hconsensus;
753 public ProfilesI getSequenceConsensusHash()
759 public Hashtable[] getComplementConsensusHash()
761 return hcomplementConsensus;
765 public Hashtable[] getRnaStructureConsensusHash()
767 return hStrucConsensus;
771 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
773 this.hStrucConsensus = hStrucConsensus;
778 public AlignmentAnnotation getAlignmentQualityAnnot()
784 public AlignmentAnnotation getAlignmentConservationAnnotation()
790 public AlignmentAnnotation getAlignmentConsensusAnnotation()
796 public AlignmentAnnotation getAlignmentGapAnnotation()
802 public AlignmentAnnotation getComplementConsensusAnnotation()
804 return complementConsensus;
808 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
810 return strucConsensus;
813 protected AlignCalcManagerI calculator = new AlignCalcManager();
816 * trigger update of conservation annotation
818 public void updateConservation(final AlignmentViewPanel ap)
820 // see note in mantis : issue number 8585
821 if (alignment.isNucleotide()
822 || (conservation == null && quality == null)
823 || !autoCalculateConsensus)
828 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
830 calculator.registerWorker(new jalview.workers.ConservationThread(
836 * trigger update of consensus annotation
838 public void updateConsensus(final AlignmentViewPanel ap)
840 // see note in mantis : issue number 8585
841 if (consensus == null || !autoCalculateConsensus)
845 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
847 calculator.registerWorker(new ConsensusThread(this, ap));
851 * A separate thread to compute cDNA consensus for a protein alignment
852 * which has mapping to cDNA
854 final AlignmentI al = this.getAlignment();
855 if (!al.isNucleotide() && al.getCodonFrames() != null
856 && !al.getCodonFrames().isEmpty())
859 * fudge - check first for protein-to-nucleotide mappings
860 * (we don't want to do this for protein-to-protein)
862 boolean doConsensus = false;
863 for (AlignedCodonFrame mapping : al.getCodonFrames())
865 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
866 MapList[] mapLists = mapping.getdnaToProt();
867 // mapLists can be empty if project load has not finished resolving seqs
868 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
877 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
880 .registerWorker(new ComplementConsensusThread(this, ap));
886 // --------START Structure Conservation
887 public void updateStrucConsensus(final AlignmentViewPanel ap)
889 if (autoCalculateStrucConsensus && strucConsensus == null
890 && alignment.isNucleotide() && alignment.hasRNAStructure())
892 // secondary structure has been added - so init the consensus line
896 // see note in mantis : issue number 8585
897 if (strucConsensus == null || !autoCalculateStrucConsensus)
901 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
903 calculator.registerWorker(new StrucConsensusThread(this, ap));
907 public boolean isCalcInProgress()
909 return calculator.isWorking();
913 public boolean isCalculationInProgress(
914 AlignmentAnnotation alignmentAnnotation)
916 if (!alignmentAnnotation.autoCalculated)
920 if (calculator.workingInvolvedWith(alignmentAnnotation))
922 // System.err.println("grey out ("+alignmentAnnotation.label+")");
928 public void setAlignment(AlignmentI align)
930 this.alignment = align;
934 * Clean up references when this viewport is closed
937 public void dispose()
940 * defensively null out references to large objects in case
941 * this object is not garbage collected (as if!)
944 complementConsensus = null;
945 strucConsensus = null;
948 groupConsensus = null;
949 groupConservation = null;
951 hcomplementConsensus = null;
952 // colour scheme may hold reference to consensus
953 residueShading = null;
954 // TODO remove listeners from changeSupport?
955 changeSupport = null;
960 public boolean isClosed()
962 // TODO: check that this isClosed is only true after panel is closed, not
963 // before it is fully constructed.
964 return alignment == null;
968 public AlignCalcManagerI getCalcManager()
974 * should conservation rows be shown for groups
976 protected boolean showGroupConservation = false;
979 * should consensus rows be shown for groups
981 protected boolean showGroupConsensus = false;
984 * should consensus profile be rendered by default
986 protected boolean showSequenceLogo = false;
989 * should consensus profile be rendered normalised to row height
991 protected boolean normaliseSequenceLogo = false;
994 * should consensus histograms be rendered by default
996 protected boolean showConsensusHistogram = true;
999 * @return the showConsensusProfile
1002 public boolean isShowSequenceLogo()
1004 return showSequenceLogo;
1008 * @param showSequenceLogo
1011 public void setShowSequenceLogo(boolean showSequenceLogo)
1013 if (showSequenceLogo != this.showSequenceLogo)
1015 // TODO: decouple settings setting from calculation when refactoring
1016 // annotation update method from alignframe to viewport
1017 this.showSequenceLogo = showSequenceLogo;
1018 calculator.updateAnnotationFor(ConsensusThread.class);
1019 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1020 calculator.updateAnnotationFor(StrucConsensusThread.class);
1022 this.showSequenceLogo = showSequenceLogo;
1026 * @param showConsensusHistogram
1027 * the showConsensusHistogram to set
1029 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1031 this.showConsensusHistogram = showConsensusHistogram;
1035 * @return the showGroupConservation
1037 public boolean isShowGroupConservation()
1039 return showGroupConservation;
1043 * @param showGroupConservation
1044 * the showGroupConservation to set
1046 public void setShowGroupConservation(boolean showGroupConservation)
1048 this.showGroupConservation = showGroupConservation;
1052 * @return the showGroupConsensus
1054 public boolean isShowGroupConsensus()
1056 return showGroupConsensus;
1060 * @param showGroupConsensus
1061 * the showGroupConsensus to set
1063 public void setShowGroupConsensus(boolean showGroupConsensus)
1065 this.showGroupConsensus = showGroupConsensus;
1070 * @return flag to indicate if the consensus histogram should be rendered by
1074 public boolean isShowConsensusHistogram()
1076 return this.showConsensusHistogram;
1080 * when set, updateAlignment will always ensure sequences are of equal length
1082 private boolean padGaps = false;
1085 * when set, alignment should be reordered according to a newly opened tree
1087 public boolean sortByTree = false;
1092 * @return null or the currently selected sequence region
1095 public SequenceGroup getSelectionGroup()
1097 return selectionGroup;
1101 * Set the selection group for this window. Also sets the current alignment as
1102 * the context for the group, if it does not already have one.
1105 * - group holding references to sequences in this alignment view
1109 public void setSelectionGroup(SequenceGroup sg)
1111 selectionGroup = sg;
1112 if (sg != null && sg.getContext() == null)
1114 sg.setContext(alignment);
1118 public void setHiddenColumns(HiddenColumns hidden)
1120 this.alignment.setHiddenColumns(hidden);
1124 public ColumnSelection getColumnSelection()
1130 public void setColumnSelection(ColumnSelection colSel)
1132 this.colSel = colSel;
1135 updateHiddenColumns();
1137 isColSelChanged(true);
1145 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1147 return hiddenRepSequences;
1151 public void setHiddenRepSequences(
1152 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1154 this.hiddenRepSequences = hiddenRepSequences;
1158 public boolean hasSelectedColumns()
1160 ColumnSelection columnSelection = getColumnSelection();
1161 return columnSelection != null && columnSelection.hasSelectedColumns();
1165 public boolean hasHiddenColumns()
1167 return colSel != null
1168 && alignment.getHiddenColumns().hasHiddenColumns();
1171 public void updateHiddenColumns()
1173 // this method doesn't really do anything now. But - it could, since a
1174 // column Selection could be in the process of modification
1175 // hasHiddenColumns = colSel.hasHiddenColumns();
1179 public boolean hasHiddenRows()
1181 return alignment.getHiddenSequences().getSize() > 0;
1184 protected SequenceGroup selectionGroup;
1186 public void setSequenceSetId(String newid)
1188 if (sequenceSetID != null)
1191 .println("Warning - overwriting a sequenceSetId for a viewport!");
1193 sequenceSetID = new String(newid);
1197 public String getSequenceSetId()
1199 if (sequenceSetID == null)
1201 sequenceSetID = alignment.hashCode() + "";
1204 return sequenceSetID;
1208 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1211 protected String viewId = null;
1214 public String getViewId()
1218 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1223 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1225 ignoreGapsInConsensusCalculation = b;
1228 updateConsensus(ap);
1229 if (residueShading != null)
1231 residueShading.setThreshold(residueShading.getThreshold(),
1232 ignoreGapsInConsensusCalculation);
1238 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1240 ignoreBelowBackGroundFrequencyCalculation = b;
1243 // updateConsensus(ap);
1244 if (residueShading != null)
1246 residueShading.setThreshold(residueShading.getThreshold(),
1247 ignoreBelowBackGroundFrequencyCalculation);
1253 private long sgrouphash = -1, colselhash = -1;
1256 * checks current SelectionGroup against record of last hash value, and
1260 * update the record of last hash value
1262 * @return true if SelectionGroup changed since last call (when b is true)
1264 public boolean isSelectionGroupChanged(boolean b)
1266 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1267 : selectionGroup.hashCode();
1268 if (hc != -1 && hc != sgrouphash)
1280 * checks current colsel against record of last hash value, and optionally
1284 * update the record of last hash value
1285 * @return true if colsel changed since last call (when b is true)
1287 public boolean isColSelChanged(boolean b)
1289 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1290 if (hc != -1 && hc != colselhash)
1302 public boolean isIgnoreGapsConsensus()
1304 return ignoreGapsInConsensusCalculation;
1307 public boolean isIgnoreBelowBackground()
1309 return ignoreBelowBackGroundFrequencyCalculation;
1312 // property change stuff
1313 // JBPNote Prolly only need this in the applet version.
1314 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1317 protected boolean showConservation = true;
1319 protected boolean showQuality = true;
1321 protected boolean showConsensus = true;
1323 protected boolean showOccupancy = true;
1325 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1327 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1329 protected boolean showAutocalculatedAbove;
1332 * when set, view will scroll to show the highlighted position
1334 private boolean followHighlight = true;
1337 * Property change listener for changes in alignment
1342 public void addPropertyChangeListener(
1343 java.beans.PropertyChangeListener listener)
1345 changeSupport.addPropertyChangeListener(listener);
1354 public void removePropertyChangeListener(
1355 java.beans.PropertyChangeListener listener)
1357 changeSupport.removePropertyChangeListener(listener);
1361 * Property change listener for changes in alignment
1370 public void firePropertyChange(String prop, Object oldvalue,
1373 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1376 // common hide/show column stuff
1378 public void hideSelectedColumns()
1380 if (colSel.isEmpty())
1385 colSel.hideSelectedColumns(alignment);
1386 setSelectionGroup(null);
1387 isColSelChanged(true);
1390 public void hideColumns(int start, int end)
1394 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1398 alignment.getHiddenColumns().hideColumns(start, end);
1400 isColSelChanged(true);
1403 public void showColumn(int col)
1405 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1406 isColSelChanged(true);
1409 public void showAllHiddenColumns()
1411 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1412 isColSelChanged(true);
1415 // common hide/show seq stuff
1416 public void showAllHiddenSeqs()
1418 if (alignment.getHiddenSequences().getSize() > 0)
1420 if (selectionGroup == null)
1422 selectionGroup = new SequenceGroup();
1423 selectionGroup.setEndRes(alignment.getWidth() - 1);
1425 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1426 hiddenRepSequences);
1427 for (SequenceI seq : tmp)
1429 selectionGroup.addSequence(seq, false);
1430 setSequenceAnnotationsVisible(seq, true);
1433 hiddenRepSequences = null;
1435 firePropertyChange("alignment", null, alignment.getSequences());
1436 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1442 public void showSequence(int index)
1444 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1445 index, hiddenRepSequences);
1448 if (selectionGroup == null)
1450 selectionGroup = new SequenceGroup();
1451 selectionGroup.setEndRes(alignment.getWidth() - 1);
1454 for (SequenceI seq : tmp)
1456 selectionGroup.addSequence(seq, false);
1457 setSequenceAnnotationsVisible(seq, true);
1459 firePropertyChange("alignment", null, alignment.getSequences());
1464 public void hideAllSelectedSeqs()
1466 if (selectionGroup == null || selectionGroup.getSize() < 1)
1471 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1475 setSelectionGroup(null);
1478 public void hideSequence(SequenceI[] seq)
1482 for (int i = 0; i < seq.length; i++)
1484 alignment.getHiddenSequences().hideSequence(seq[i]);
1485 setSequenceAnnotationsVisible(seq[i], false);
1487 firePropertyChange("alignment", null, alignment.getSequences());
1492 * Hides the specified sequence, or the sequences it represents
1495 * the sequence to hide, or keep as representative
1496 * @param representGroup
1497 * if true, hide the current selection group except for the
1498 * representative sequence
1500 public void hideSequences(SequenceI sequence, boolean representGroup)
1502 if (selectionGroup == null || selectionGroup.getSize() < 1)
1504 hideSequence(new SequenceI[] { sequence });
1510 hideRepSequences(sequence, selectionGroup);
1511 setSelectionGroup(null);
1515 int gsize = selectionGroup.getSize();
1516 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1517 new SequenceI[gsize]);
1519 hideSequence(hseqs);
1520 setSelectionGroup(null);
1525 * Set visibility for any annotations for the given sequence.
1529 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1532 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1535 for (AlignmentAnnotation ann : anns)
1537 if (ann.sequenceRef == sequenceI)
1539 ann.visible = visible;
1545 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1547 int sSize = sg.getSize();
1553 if (hiddenRepSequences == null)
1555 hiddenRepSequences = new Hashtable<>();
1558 hiddenRepSequences.put(repSequence, sg);
1560 // Hide all sequences except the repSequence
1561 SequenceI[] seqs = new SequenceI[sSize - 1];
1563 for (int i = 0; i < sSize; i++)
1565 if (sg.getSequenceAt(i) != repSequence)
1567 if (index == sSize - 1)
1572 seqs[index++] = sg.getSequenceAt(i);
1575 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1576 sg.setHidereps(true); // note: not done in 2.7applet
1583 * @return null or the current reference sequence
1585 public SequenceI getReferenceSeq()
1587 return alignment.getSeqrep();
1592 * @return true iff seq is the reference for the alignment
1594 public boolean isReferenceSeq(SequenceI seq)
1596 return alignment.getSeqrep() == seq;
1602 * @return true if there are sequences represented by this sequence that are
1605 public boolean isHiddenRepSequence(SequenceI seq)
1607 return (hiddenRepSequences != null && hiddenRepSequences
1614 * @return null or a sequence group containing the sequences that seq
1617 public SequenceGroup getRepresentedSequences(SequenceI seq)
1619 return (SequenceGroup) (hiddenRepSequences == null ? null
1620 : hiddenRepSequences.get(seq));
1624 public int adjustForHiddenSeqs(int alignmentIndex)
1626 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1631 public void invertColumnSelection()
1633 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1637 public SequenceI[] getSelectionAsNewSequence()
1639 SequenceI[] sequences;
1640 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1641 // this was the only caller in the applet for this method
1642 // JBPNote: in applet, this method returned references to the alignment
1643 // sequences, and it did not honour the presence/absence of annotation
1644 // attached to the alignment (probably!)
1645 if (selectionGroup == null || selectionGroup.getSize() == 0)
1647 sequences = alignment.getSequencesArray();
1648 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1649 for (int i = 0; i < sequences.length; i++)
1651 // construct new sequence with subset of visible annotation
1652 sequences[i] = new Sequence(sequences[i], annots);
1657 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1664 public SequenceI[] getSequenceSelection()
1666 SequenceI[] sequences = null;
1667 if (selectionGroup != null)
1669 sequences = selectionGroup.getSequencesInOrder(alignment);
1671 if (sequences == null)
1673 sequences = alignment.getSequencesArray();
1679 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1681 return new CigarArray(alignment, alignment.getHiddenColumns(),
1682 (selectedRegionOnly ? selectionGroup : null));
1686 public jalview.datamodel.AlignmentView getAlignmentView(
1687 boolean selectedOnly)
1689 return getAlignmentView(selectedOnly, false);
1693 public jalview.datamodel.AlignmentView getAlignmentView(
1694 boolean selectedOnly, boolean markGroups)
1696 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1697 selectionGroup, alignment.getHiddenColumns() != null
1698 && alignment.getHiddenColumns().hasHiddenColumns(),
1704 public String[] getViewAsString(boolean selectedRegionOnly)
1706 return getViewAsString(selectedRegionOnly, true);
1710 public String[] getViewAsString(boolean selectedRegionOnly,
1711 boolean exportHiddenSeqs)
1713 String[] selection = null;
1714 SequenceI[] seqs = null;
1716 int start = 0, end = 0;
1717 if (selectedRegionOnly && selectionGroup != null)
1719 iSize = selectionGroup.getSize();
1720 seqs = selectionGroup.getSequencesInOrder(alignment);
1721 start = selectionGroup.getStartRes();
1722 end = selectionGroup.getEndRes() + 1;
1726 if (hasHiddenRows() && exportHiddenSeqs)
1728 AlignmentI fullAlignment = alignment.getHiddenSequences()
1729 .getFullAlignment();
1730 iSize = fullAlignment.getHeight();
1731 seqs = fullAlignment.getSequencesArray();
1732 end = fullAlignment.getWidth();
1736 iSize = alignment.getHeight();
1737 seqs = alignment.getSequencesArray();
1738 end = alignment.getWidth();
1742 selection = new String[iSize];
1743 if (alignment.getHiddenColumns() != null
1744 && alignment.getHiddenColumns().hasHiddenColumns())
1746 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1751 for (i = 0; i < iSize; i++)
1753 selection[i] = seqs[i].getSequenceAsString(start, end);
1761 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1763 ArrayList<int[]> regions = new ArrayList<>();
1769 HiddenColumns hidden = alignment.getHiddenColumns();
1770 if (hidden != null && hidden.hasHiddenColumns())
1774 start = hidden.adjustForHiddenColumns(start);
1777 end = hidden.getHiddenBoundaryRight(start);
1788 regions.add(new int[] { start, end });
1790 if (hidden != null && hidden.hasHiddenColumns())
1792 start = hidden.adjustForHiddenColumns(end);
1793 start = hidden.getHiddenBoundaryLeft(start) + 1;
1795 } while (end < max);
1797 int[][] startEnd = new int[regions.size()][2];
1803 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1804 boolean selectedOnly)
1806 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1807 AlignmentAnnotation[] aa;
1808 if ((aa = alignment.getAlignmentAnnotation()) != null)
1810 for (AlignmentAnnotation annot : aa)
1812 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1813 if (selectedOnly && selectionGroup != null)
1815 alignment.getHiddenColumns().makeVisibleAnnotation(
1816 selectionGroup.getStartRes(),
1817 selectionGroup.getEndRes(), clone);
1821 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1830 public boolean isPadGaps()
1836 public void setPadGaps(boolean padGaps)
1838 this.padGaps = padGaps;
1842 * apply any post-edit constraints and trigger any calculations needed after
1843 * an edit has been performed on the alignment
1848 public void alignmentChanged(AlignmentViewPanel ap)
1852 alignment.padGaps();
1854 if (autoCalculateConsensus)
1856 updateConsensus(ap);
1858 if (hconsensus != null && autoCalculateConsensus)
1860 updateConservation(ap);
1862 if (autoCalculateStrucConsensus)
1864 updateStrucConsensus(ap);
1867 // Reset endRes of groups if beyond alignment width
1868 int alWidth = alignment.getWidth();
1869 List<SequenceGroup> groups = alignment.getGroups();
1872 for (SequenceGroup sg : groups)
1874 if (sg.getEndRes() > alWidth)
1876 sg.setEndRes(alWidth - 1);
1881 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1883 selectionGroup.setEndRes(alWidth - 1);
1886 updateAllColourSchemes();
1887 calculator.restartWorkers();
1888 // alignment.adjustSequenceAnnotations();
1892 * reset scope and do calculations for all applied colourschemes on alignment
1894 void updateAllColourSchemes()
1896 ResidueShaderI rs = residueShading;
1899 rs.alignmentChanged(alignment, hiddenRepSequences);
1901 rs.setConsensus(hconsensus);
1902 if (rs.conservationApplied())
1904 rs.setConservation(Conservation.calculateConservation("All",
1905 alignment.getSequences(), 0, alignment.getWidth(), false,
1906 getConsPercGaps(), false));
1910 for (SequenceGroup sg : alignment.getGroups())
1914 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1916 sg.recalcConservation();
1920 protected void initAutoAnnotation()
1922 // TODO: add menu option action that nulls or creates consensus object
1923 // depending on if the user wants to see the annotation or not in a
1924 // specific alignment
1926 if (hconsensus == null && !isDataset)
1928 if (!alignment.isNucleotide())
1937 consensus = new AlignmentAnnotation("Consensus",
1938 MessageManager.getString("label.consensus_descr"),
1939 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1940 initConsensus(consensus);
1944 initComplementConsensus();
1949 * If this is a protein alignment and there are mappings to cDNA, adds the
1950 * cDNA consensus annotation and returns true, else returns false.
1952 public boolean initComplementConsensus()
1954 if (!alignment.isNucleotide())
1956 final List<AlignedCodonFrame> codonMappings = alignment
1958 if (codonMappings != null && !codonMappings.isEmpty())
1960 boolean doConsensus = false;
1961 for (AlignedCodonFrame mapping : codonMappings)
1963 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1964 MapList[] mapLists = mapping.getdnaToProt();
1965 // mapLists can be empty if project load has not finished resolving
1967 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1975 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1977 .getString("label.complement_consensus_descr"),
1978 new Annotation[1], 0f, 100f,
1979 AlignmentAnnotation.BAR_GRAPH);
1980 initConsensus(complementConsensus);
1988 private void initConsensus(AlignmentAnnotation aa)
1991 aa.autoCalculated = true;
1995 alignment.addAnnotation(aa);
1999 // these should be extracted from the view model - style and settings for
2000 // derived annotation
2001 private void initGapCounts()
2005 gapcounts = new AlignmentAnnotation("Occupancy",
2006 MessageManager.getString("label.occupancy_descr"),
2007 new Annotation[1], 0f,
2008 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
2009 gapcounts.hasText = true;
2010 gapcounts.autoCalculated = true;
2011 gapcounts.scaleColLabel = true;
2012 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2014 alignment.addAnnotation(gapcounts);
2018 private void initConservation()
2020 if (showConservation)
2022 if (conservation == null)
2024 conservation = new AlignmentAnnotation("Conservation",
2025 MessageManager.formatMessage("label.conservation_descr",
2026 getConsPercGaps()), new Annotation[1],
2027 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2028 conservation.hasText = true;
2029 conservation.autoCalculated = true;
2030 alignment.addAnnotation(conservation);
2035 private void initQuality()
2039 if (quality == null)
2041 quality = new AlignmentAnnotation("Quality",
2042 MessageManager.getString("label.quality_descr"),
2043 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2044 quality.hasText = true;
2045 quality.autoCalculated = true;
2046 alignment.addAnnotation(quality);
2051 private void initRNAStructure()
2053 if (alignment.hasRNAStructure() && strucConsensus == null)
2055 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2056 MessageManager.getString("label.strucconsensus_descr"),
2057 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2058 strucConsensus.hasText = true;
2059 strucConsensus.autoCalculated = true;
2063 alignment.addAnnotation(strucConsensus);
2071 * @see jalview.api.AlignViewportI#calcPanelHeight()
2074 public int calcPanelHeight()
2076 // setHeight of panels
2077 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2079 int charHeight = getCharHeight();
2082 BitSet graphgrp = new BitSet();
2083 for (AlignmentAnnotation aa : anns)
2087 System.err.println("Null annotation row: ignoring.");
2094 if (aa.graphGroup > -1)
2096 if (graphgrp.get(aa.graphGroup))
2102 graphgrp.set(aa.graphGroup);
2109 aa.height += charHeight;
2119 aa.height += aa.graphHeight;
2127 height += aa.height;
2139 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2140 boolean preserveNewGroupSettings)
2142 boolean updateCalcs = false;
2143 boolean conv = isShowGroupConservation();
2144 boolean cons = isShowGroupConsensus();
2145 boolean showprf = isShowSequenceLogo();
2146 boolean showConsHist = isShowConsensusHistogram();
2147 boolean normLogo = isNormaliseSequenceLogo();
2150 * TODO reorder the annotation rows according to group/sequence ordering on
2153 boolean sortg = true;
2155 // remove old automatic annotation
2156 // add any new annotation
2158 // intersect alignment annotation with alignment groups
2160 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2161 List<SequenceGroup> oldrfs = new ArrayList<>();
2164 for (int an = 0; an < aan.length; an++)
2166 if (aan[an].autoCalculated && aan[an].groupRef != null)
2168 oldrfs.add(aan[an].groupRef);
2169 alignment.deleteAnnotation(aan[an], false);
2173 if (alignment.getGroups() != null)
2175 for (SequenceGroup sg : alignment.getGroups())
2177 updateCalcs = false;
2178 if (applyGlobalSettings
2179 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2181 // set defaults for this group's conservation/consensus
2182 sg.setshowSequenceLogo(showprf);
2183 sg.setShowConsensusHistogram(showConsHist);
2184 sg.setNormaliseSequenceLogo(normLogo);
2189 alignment.addAnnotation(sg.getConservationRow(), 0);
2194 alignment.addAnnotation(sg.getConsensus(), 0);
2196 // refresh the annotation rows
2199 sg.recalcConservation();
2207 public boolean isDisplayReferenceSeq()
2209 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2213 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2215 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2219 public boolean isColourByReferenceSeq()
2221 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2225 public Color getSequenceColour(SequenceI seq)
2227 Color sqc = sequenceColours.get(seq);
2228 return (sqc == null ? Color.white : sqc);
2232 public void setSequenceColour(SequenceI seq, Color col)
2236 sequenceColours.remove(seq);
2240 sequenceColours.put(seq, col);
2245 public void updateSequenceIdColours()
2247 for (SequenceGroup sg : alignment.getGroups())
2249 if (sg.idColour != null)
2251 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2253 sequenceColours.put(s, sg.idColour);
2260 public void clearSequenceColours()
2262 sequenceColours.clear();
2266 public AlignViewportI getCodingComplement()
2268 return this.codingComplement;
2272 * Set this as the (cDna/protein) complement of the given viewport. Also
2273 * ensures the reverse relationship is set on the given viewport.
2276 public void setCodingComplement(AlignViewportI av)
2280 System.err.println("Ignoring recursive setCodingComplement request");
2284 this.codingComplement = av;
2285 // avoid infinite recursion!
2286 if (av.getCodingComplement() != this)
2288 av.setCodingComplement(this);
2294 public boolean isNucleotide()
2296 return getAlignment() == null ? false : getAlignment().isNucleotide();
2300 public FeaturesDisplayedI getFeaturesDisplayed()
2302 return featuresDisplayed;
2306 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2308 featuresDisplayed = featuresDisplayedI;
2312 public boolean areFeaturesDisplayed()
2314 return featuresDisplayed != null
2315 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2322 * features are displayed if true
2325 public void setShowSequenceFeatures(boolean b)
2327 viewStyle.setShowSequenceFeatures(b);
2331 public boolean isShowSequenceFeatures()
2333 return viewStyle.isShowSequenceFeatures();
2337 public void setShowSequenceFeaturesHeight(boolean selected)
2339 viewStyle.setShowSequenceFeaturesHeight(selected);
2343 public boolean isShowSequenceFeaturesHeight()
2345 return viewStyle.isShowSequenceFeaturesHeight();
2349 public void setShowAnnotation(boolean b)
2351 viewStyle.setShowAnnotation(b);
2355 public boolean isShowAnnotation()
2357 return viewStyle.isShowAnnotation();
2361 public boolean isRightAlignIds()
2363 return viewStyle.isRightAlignIds();
2367 public void setRightAlignIds(boolean rightAlignIds)
2369 viewStyle.setRightAlignIds(rightAlignIds);
2373 public boolean getConservationSelected()
2375 return viewStyle.getConservationSelected();
2379 public void setShowBoxes(boolean state)
2381 viewStyle.setShowBoxes(state);
2386 * @see jalview.api.ViewStyleI#getTextColour()
2389 public Color getTextColour()
2391 return viewStyle.getTextColour();
2396 * @see jalview.api.ViewStyleI#getTextColour2()
2399 public Color getTextColour2()
2401 return viewStyle.getTextColour2();
2406 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2409 public int getThresholdTextColour()
2411 return viewStyle.getThresholdTextColour();
2416 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2419 public boolean isConservationColourSelected()
2421 return viewStyle.isConservationColourSelected();
2426 * @see jalview.api.ViewStyleI#isRenderGaps()
2429 public boolean isRenderGaps()
2431 return viewStyle.isRenderGaps();
2436 * @see jalview.api.ViewStyleI#isShowColourText()
2439 public boolean isShowColourText()
2441 return viewStyle.isShowColourText();
2445 * @param conservationColourSelected
2446 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2449 public void setConservationColourSelected(
2450 boolean conservationColourSelected)
2452 viewStyle.setConservationColourSelected(conservationColourSelected);
2456 * @param showColourText
2457 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2460 public void setShowColourText(boolean showColourText)
2462 viewStyle.setShowColourText(showColourText);
2467 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2470 public void setTextColour(Color textColour)
2472 viewStyle.setTextColour(textColour);
2476 * @param thresholdTextColour
2477 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2480 public void setThresholdTextColour(int thresholdTextColour)
2482 viewStyle.setThresholdTextColour(thresholdTextColour);
2486 * @param textColour2
2487 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2490 public void setTextColour2(Color textColour2)
2492 viewStyle.setTextColour2(textColour2);
2496 public ViewStyleI getViewStyle()
2498 return new ViewStyle(viewStyle);
2502 public void setViewStyle(ViewStyleI settingsForView)
2504 viewStyle = new ViewStyle(settingsForView);
2505 if (residueShading != null)
2507 residueShading.setConservationApplied(settingsForView
2508 .isConservationColourSelected());
2513 public boolean sameStyle(ViewStyleI them)
2515 return viewStyle.sameStyle(them);
2520 * @see jalview.api.ViewStyleI#getIdWidth()
2523 public int getIdWidth()
2525 return viewStyle.getIdWidth();
2530 * @see jalview.api.ViewStyleI#setIdWidth(int)
2533 public void setIdWidth(int i)
2535 viewStyle.setIdWidth(i);
2540 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2543 public boolean isCentreColumnLabels()
2545 return viewStyle.isCentreColumnLabels();
2549 * @param centreColumnLabels
2550 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2553 public void setCentreColumnLabels(boolean centreColumnLabels)
2555 viewStyle.setCentreColumnLabels(centreColumnLabels);
2560 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2563 public void setShowDBRefs(boolean showdbrefs)
2565 viewStyle.setShowDBRefs(showdbrefs);
2570 * @see jalview.api.ViewStyleI#isShowDBRefs()
2573 public boolean isShowDBRefs()
2575 return viewStyle.isShowDBRefs();
2580 * @see jalview.api.ViewStyleI#isShowNPFeats()
2583 public boolean isShowNPFeats()
2585 return viewStyle.isShowNPFeats();
2589 * @param shownpfeats
2590 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2593 public void setShowNPFeats(boolean shownpfeats)
2595 viewStyle.setShowNPFeats(shownpfeats);
2598 public abstract StructureSelectionManager getStructureSelectionManager();
2601 * Add one command to the command history list.
2605 public void addToHistoryList(CommandI command)
2607 if (this.historyList != null)
2609 this.historyList.push(command);
2610 broadcastCommand(command, false);
2614 protected void broadcastCommand(CommandI command, boolean undo)
2616 getStructureSelectionManager().commandPerformed(command, undo,
2621 * Add one command to the command redo list.
2625 public void addToRedoList(CommandI command)
2627 if (this.redoList != null)
2629 this.redoList.push(command);
2631 broadcastCommand(command, true);
2635 * Clear the command redo list.
2637 public void clearRedoList()
2639 if (this.redoList != null)
2641 this.redoList.clear();
2645 public void setHistoryList(Deque<CommandI> list)
2647 this.historyList = list;
2650 public Deque<CommandI> getHistoryList()
2652 return this.historyList;
2655 public void setRedoList(Deque<CommandI> list)
2657 this.redoList = list;
2660 public Deque<CommandI> getRedoList()
2662 return this.redoList;
2666 public VamsasSource getVamsasSource()
2671 public SequenceAnnotationOrder getSortAnnotationsBy()
2673 return sortAnnotationsBy;
2676 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2678 this.sortAnnotationsBy = sortAnnotationsBy;
2681 public boolean isShowAutocalculatedAbove()
2683 return showAutocalculatedAbove;
2686 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2688 this.showAutocalculatedAbove = showAutocalculatedAbove;
2692 public boolean isScaleProteinAsCdna()
2694 return viewStyle.isScaleProteinAsCdna();
2698 public void setScaleProteinAsCdna(boolean b)
2700 viewStyle.setScaleProteinAsCdna(b);
2704 public boolean isProteinFontAsCdna()
2706 return viewStyle.isProteinFontAsCdna();
2710 public void setProteinFontAsCdna(boolean b)
2712 viewStyle.setProteinFontAsCdna(b);
2716 * @return true if view should scroll to show the highlighted region of a
2721 public final boolean isFollowHighlight()
2723 return followHighlight;
2727 public final void setFollowHighlight(boolean b)
2729 this.followHighlight = b;
2733 public ViewportRanges getRanges()
2739 * Helper method to populate the SearchResults with the location in the
2740 * complementary alignment to scroll to, in order to match this one.
2743 * the SearchResults to add to
2744 * @return the offset (below top of visible region) of the matched sequence
2746 protected int findComplementScrollTarget(SearchResultsI sr)
2748 final AlignViewportI complement = getCodingComplement();
2749 if (complement == null || !complement.isFollowHighlight())
2753 boolean iAmProtein = !getAlignment().isNucleotide();
2754 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2756 if (proteinAlignment == null)
2760 final List<AlignedCodonFrame> mappings = proteinAlignment
2764 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2765 * residue in the middle column of the visible region. Scroll the
2766 * complementary alignment to line up the corresponding residue.
2769 SequenceI sequence = null;
2772 * locate 'middle' column (true middle if an odd number visible, left of
2773 * middle if an even number visible)
2775 int middleColumn = ranges.getStartRes()
2776 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2777 final HiddenSequences hiddenSequences = getAlignment()
2778 .getHiddenSequences();
2781 * searching to the bottom of the alignment gives smoother scrolling across
2782 * all gapped visible regions
2784 int lastSeq = alignment.getHeight() - 1;
2785 List<AlignedCodonFrame> seqMappings = null;
2786 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2788 sequence = getAlignment().getSequenceAt(seqNo);
2789 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2793 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2797 seqMappings = MappingUtils
2798 .findMappingsForSequenceAndOthers(sequence, mappings,
2799 getCodingComplement().getAlignment().getSequences());
2800 if (!seqMappings.isEmpty())
2806 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2809 * No ungapped mapped sequence in middle column - do nothing
2813 MappingUtils.addSearchResults(sr, sequence,
2814 sequence.findPosition(middleColumn), seqMappings);
2819 * synthesize a column selection if none exists so it covers the given
2820 * selection group. if wholewidth is false, no column selection is made if the
2821 * selection group covers the whole alignment width.
2826 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2829 if (sg != null && (sgs = sg.getStartRes()) >= 0
2830 && sg.getStartRes() <= (sge = sg.getEndRes())
2831 && !this.hasSelectedColumns())
2833 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2840 colSel = new ColumnSelection();
2842 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2844 colSel.addElement(cspos);
2850 * hold status of current selection group - defined on alignment or not.
2852 private boolean selectionIsDefinedGroup = false;
2855 public boolean isSelectionDefinedGroup()
2857 if (selectionGroup == null)
2861 if (isSelectionGroupChanged(true))
2863 selectionIsDefinedGroup = false;
2864 List<SequenceGroup> gps = alignment.getGroups();
2865 if (gps == null || gps.size() == 0)
2867 selectionIsDefinedGroup = false;
2871 selectionIsDefinedGroup = gps.contains(selectionGroup);
2874 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2878 * null, or currently highlighted results on this view
2880 private SearchResultsI searchResults = null;
2883 public boolean hasSearchResults()
2885 return searchResults != null;
2889 public void setSearchResults(SearchResultsI results)
2891 searchResults = results;
2895 public SearchResultsI getSearchResults()
2897 return searchResults;