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 informationContent;
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 getAlignmentInformationAnnotation()
798 return informationContent;
802 public AlignmentAnnotation getAlignmentGapAnnotation()
808 public AlignmentAnnotation getComplementConsensusAnnotation()
810 return complementConsensus;
814 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
816 return strucConsensus;
819 protected AlignCalcManagerI calculator = new AlignCalcManager();
822 * trigger update of conservation annotation
824 public void updateConservation(final AlignmentViewPanel ap)
826 // see note in mantis : issue number 8585
827 if (alignment.isNucleotide()
828 || (conservation == null && quality == null)
829 || !autoCalculateConsensus)
834 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
836 calculator.registerWorker(new jalview.workers.ConservationThread(
842 * trigger update of consensus annotation
844 public void updateConsensus(final AlignmentViewPanel ap)
846 // see note in mantis : issue number 8585
847 if (consensus == null || !autoCalculateConsensus)
851 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
853 calculator.registerWorker(new ConsensusThread(this, ap));
857 * A separate thread to compute cDNA consensus for a protein alignment
858 * which has mapping to cDNA
860 final AlignmentI al = this.getAlignment();
861 if (!al.isNucleotide() && al.getCodonFrames() != null
862 && !al.getCodonFrames().isEmpty())
865 * fudge - check first for protein-to-nucleotide mappings
866 * (we don't want to do this for protein-to-protein)
868 boolean doConsensus = false;
869 for (AlignedCodonFrame mapping : al.getCodonFrames())
871 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
872 MapList[] mapLists = mapping.getdnaToProt();
873 // mapLists can be empty if project load has not finished resolving seqs
874 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
883 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
886 .registerWorker(new ComplementConsensusThread(this, ap));
892 // --------START Structure Conservation
893 public void updateStrucConsensus(final AlignmentViewPanel ap)
895 if (autoCalculateStrucConsensus && strucConsensus == null
896 && alignment.isNucleotide() && alignment.hasRNAStructure())
898 // secondary structure has been added - so init the consensus line
902 // see note in mantis : issue number 8585
903 if (strucConsensus == null || !autoCalculateStrucConsensus)
907 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
909 calculator.registerWorker(new StrucConsensusThread(this, ap));
913 public boolean isCalcInProgress()
915 return calculator.isWorking();
919 public boolean isCalculationInProgress(
920 AlignmentAnnotation alignmentAnnotation)
922 if (!alignmentAnnotation.autoCalculated)
926 if (calculator.workingInvolvedWith(alignmentAnnotation))
928 // System.err.println("grey out ("+alignmentAnnotation.label+")");
934 public void setAlignment(AlignmentI align)
936 this.alignment = align;
940 * Clean up references when this viewport is closed
943 public void dispose()
946 * defensively null out references to large objects in case
947 * this object is not garbage collected (as if!)
950 complementConsensus = null;
951 strucConsensus = null;
954 groupConsensus = null;
955 groupConservation = null;
957 hcomplementConsensus = null;
958 // colour scheme may hold reference to consensus
959 residueShading = null;
960 // TODO remove listeners from changeSupport?
961 changeSupport = null;
966 public boolean isClosed()
968 // TODO: check that this isClosed is only true after panel is closed, not
969 // before it is fully constructed.
970 return alignment == null;
974 public AlignCalcManagerI getCalcManager()
980 * should conservation rows be shown for groups
982 protected boolean showGroupConservation = false;
985 * should consensus rows be shown for groups
987 protected boolean showGroupConsensus = false;
990 * should consensus profile be rendered by default
992 protected boolean showSequenceLogo = false;
995 * should consensus profile be rendered normalised to row height
997 protected boolean normaliseSequenceLogo = false;
1000 * should consensus histograms be rendered by default
1002 protected boolean showConsensusHistogram = true;
1005 * should hmm profile be rendered by default
1007 protected boolean showHMMSequenceLogo = false;
1010 * should hmm profile be rendered normalised to row height
1012 protected boolean normaliseHMMSequenceLogo = false;
1015 * should information histograms be rendered by default
1017 protected boolean showInformationHistogram = true;
1020 * @return the showConsensusProfile
1023 public boolean isShowSequenceLogo()
1025 return showSequenceLogo;
1029 * @return the showInformationProfile
1032 public boolean isShowHMMSequenceLogo()
1034 return showHMMSequenceLogo;
1038 * @param showSequenceLogo
1041 public void setShowSequenceLogo(boolean showSequenceLogo)
1043 if (showSequenceLogo != this.showSequenceLogo)
1045 // TODO: decouple settings setting from calculation when refactoring
1046 // annotation update method from alignframe to viewport
1047 this.showSequenceLogo = showSequenceLogo;
1048 calculator.updateAnnotationFor(ConsensusThread.class);
1049 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1050 calculator.updateAnnotationFor(StrucConsensusThread.class);
1052 this.showSequenceLogo = showSequenceLogo;
1055 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1057 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1059 this.showHMMSequenceLogo = showHMMSequenceLogo;
1061 this.showHMMSequenceLogo = showHMMSequenceLogo;
1065 * @param showConsensusHistogram
1066 * the showConsensusHistogram to set
1068 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1070 this.showConsensusHistogram = showConsensusHistogram;
1074 * @param showInformationHistogram
1075 * the showInformationHistogram to set
1077 public void setShowInformationHistogram(boolean showInformationHistogram)
1079 this.showInformationHistogram = showInformationHistogram;
1083 * @return the showGroupConservation
1085 public boolean isShowGroupConservation()
1087 return showGroupConservation;
1091 * @param showGroupConservation
1092 * the showGroupConservation to set
1094 public void setShowGroupConservation(boolean showGroupConservation)
1096 this.showGroupConservation = showGroupConservation;
1100 * @return the showGroupConsensus
1102 public boolean isShowGroupConsensus()
1104 return showGroupConsensus;
1108 * @param showGroupConsensus
1109 * the showGroupConsensus to set
1111 public void setShowGroupConsensus(boolean showGroupConsensus)
1113 this.showGroupConsensus = showGroupConsensus;
1118 * @return flag to indicate if the consensus histogram should be rendered by
1122 public boolean isShowConsensusHistogram()
1124 return this.showConsensusHistogram;
1129 * @return flag to indicate if the information content histogram should be
1130 * rendered by default
1133 public boolean isShowInformationHistogram()
1135 return this.showInformationHistogram;
1139 * when set, updateAlignment will always ensure sequences are of equal length
1141 private boolean padGaps = false;
1144 * when set, alignment should be reordered according to a newly opened tree
1146 public boolean sortByTree = false;
1151 * @return null or the currently selected sequence region
1154 public SequenceGroup getSelectionGroup()
1156 return selectionGroup;
1160 * Set the selection group for this window. Also sets the current alignment as
1161 * the context for the group, if it does not already have one.
1164 * - group holding references to sequences in this alignment view
1168 public void setSelectionGroup(SequenceGroup sg)
1170 selectionGroup = sg;
1171 if (sg != null && sg.getContext() == null)
1173 sg.setContext(alignment);
1177 public void setHiddenColumns(HiddenColumns hidden)
1179 this.alignment.setHiddenColumns(hidden);
1183 public ColumnSelection getColumnSelection()
1189 public void setColumnSelection(ColumnSelection colSel)
1191 this.colSel = colSel;
1194 updateHiddenColumns();
1196 isColSelChanged(true);
1204 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1206 return hiddenRepSequences;
1210 public void setHiddenRepSequences(
1211 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1213 this.hiddenRepSequences = hiddenRepSequences;
1217 public boolean hasSelectedColumns()
1219 ColumnSelection columnSelection = getColumnSelection();
1220 return columnSelection != null && columnSelection.hasSelectedColumns();
1224 public boolean hasHiddenColumns()
1226 return colSel != null
1227 && alignment.getHiddenColumns().hasHiddenColumns();
1230 public void updateHiddenColumns()
1232 // this method doesn't really do anything now. But - it could, since a
1233 // column Selection could be in the process of modification
1234 // hasHiddenColumns = colSel.hasHiddenColumns();
1238 public boolean hasHiddenRows()
1240 return alignment.getHiddenSequences().getSize() > 0;
1243 protected SequenceGroup selectionGroup;
1245 public void setSequenceSetId(String newid)
1247 if (sequenceSetID != null)
1250 .println("Warning - overwriting a sequenceSetId for a viewport!");
1252 sequenceSetID = new String(newid);
1256 public String getSequenceSetId()
1258 if (sequenceSetID == null)
1260 sequenceSetID = alignment.hashCode() + "";
1263 return sequenceSetID;
1267 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1270 protected String viewId = null;
1273 public String getViewId()
1277 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1282 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1284 ignoreGapsInConsensusCalculation = b;
1287 updateConsensus(ap);
1288 if (residueShading != null)
1290 residueShading.setThreshold(residueShading.getThreshold(),
1291 ignoreGapsInConsensusCalculation);
1297 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1299 ignoreBelowBackGroundFrequencyCalculation = b;
1302 // updateConsensus(ap);
1303 if (residueShading != null)
1305 residueShading.setThreshold(residueShading.getThreshold(),
1306 ignoreBelowBackGroundFrequencyCalculation);
1312 private long sgrouphash = -1, colselhash = -1;
1315 * checks current SelectionGroup against record of last hash value, and
1319 * update the record of last hash value
1321 * @return true if SelectionGroup changed since last call (when b is true)
1323 public boolean isSelectionGroupChanged(boolean b)
1325 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1326 : selectionGroup.hashCode();
1327 if (hc != -1 && hc != sgrouphash)
1339 * checks current colsel against record of last hash value, and optionally
1343 * update the record of last hash value
1344 * @return true if colsel changed since last call (when b is true)
1346 public boolean isColSelChanged(boolean b)
1348 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1349 if (hc != -1 && hc != colselhash)
1361 public boolean isIgnoreGapsConsensus()
1363 return ignoreGapsInConsensusCalculation;
1367 public boolean isIgnoreBelowBackground()
1369 return ignoreBelowBackGroundFrequencyCalculation;
1372 // property change stuff
1373 // JBPNote Prolly only need this in the applet version.
1374 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1377 protected boolean showConservation = true;
1379 protected boolean showQuality = true;
1381 protected boolean showConsensus = true;
1383 protected boolean showOccupancy = true;
1385 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1387 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1389 protected boolean showAutocalculatedAbove;
1392 * when set, view will scroll to show the highlighted position
1394 private boolean followHighlight = true;
1397 * Property change listener for changes in alignment
1402 public void addPropertyChangeListener(
1403 java.beans.PropertyChangeListener listener)
1405 changeSupport.addPropertyChangeListener(listener);
1414 public void removePropertyChangeListener(
1415 java.beans.PropertyChangeListener listener)
1417 changeSupport.removePropertyChangeListener(listener);
1421 * Property change listener for changes in alignment
1430 public void firePropertyChange(String prop, Object oldvalue,
1433 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1436 // common hide/show column stuff
1438 public void hideSelectedColumns()
1440 if (colSel.isEmpty())
1445 colSel.hideSelectedColumns(alignment);
1446 setSelectionGroup(null);
1447 isColSelChanged(true);
1450 public void hideColumns(int start, int end)
1454 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1458 alignment.getHiddenColumns().hideColumns(start, end);
1460 isColSelChanged(true);
1463 public void showColumn(int col)
1465 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1466 isColSelChanged(true);
1469 public void showAllHiddenColumns()
1471 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1472 isColSelChanged(true);
1475 // common hide/show seq stuff
1476 public void showAllHiddenSeqs()
1478 if (alignment.getHiddenSequences().getSize() > 0)
1480 if (selectionGroup == null)
1482 selectionGroup = new SequenceGroup();
1483 selectionGroup.setEndRes(alignment.getWidth() - 1);
1485 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1486 hiddenRepSequences);
1487 for (SequenceI seq : tmp)
1489 selectionGroup.addSequence(seq, false);
1490 setSequenceAnnotationsVisible(seq, true);
1493 hiddenRepSequences = null;
1495 firePropertyChange("alignment", null, alignment.getSequences());
1496 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1502 public void showSequence(int index)
1504 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1505 index, hiddenRepSequences);
1508 if (selectionGroup == null)
1510 selectionGroup = new SequenceGroup();
1511 selectionGroup.setEndRes(alignment.getWidth() - 1);
1514 for (SequenceI seq : tmp)
1516 selectionGroup.addSequence(seq, false);
1517 setSequenceAnnotationsVisible(seq, true);
1519 firePropertyChange("alignment", null, alignment.getSequences());
1524 public void hideAllSelectedSeqs()
1526 if (selectionGroup == null || selectionGroup.getSize() < 1)
1531 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1535 setSelectionGroup(null);
1538 public void hideSequence(SequenceI[] seq)
1542 for (int i = 0; i < seq.length; i++)
1544 alignment.getHiddenSequences().hideSequence(seq[i]);
1545 setSequenceAnnotationsVisible(seq[i], false);
1547 firePropertyChange("alignment", null, alignment.getSequences());
1552 * Hides the specified sequence, or the sequences it represents
1555 * the sequence to hide, or keep as representative
1556 * @param representGroup
1557 * if true, hide the current selection group except for the
1558 * representative sequence
1560 public void hideSequences(SequenceI sequence, boolean representGroup)
1562 if (selectionGroup == null || selectionGroup.getSize() < 1)
1564 hideSequence(new SequenceI[] { sequence });
1570 hideRepSequences(sequence, selectionGroup);
1571 setSelectionGroup(null);
1575 int gsize = selectionGroup.getSize();
1576 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1577 new SequenceI[gsize]);
1579 hideSequence(hseqs);
1580 setSelectionGroup(null);
1585 * Set visibility for any annotations for the given sequence.
1589 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1592 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1595 for (AlignmentAnnotation ann : anns)
1597 if (ann.sequenceRef == sequenceI)
1599 ann.visible = visible;
1605 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1607 int sSize = sg.getSize();
1613 if (hiddenRepSequences == null)
1615 hiddenRepSequences = new Hashtable<>();
1618 hiddenRepSequences.put(repSequence, sg);
1620 // Hide all sequences except the repSequence
1621 SequenceI[] seqs = new SequenceI[sSize - 1];
1623 for (int i = 0; i < sSize; i++)
1625 if (sg.getSequenceAt(i) != repSequence)
1627 if (index == sSize - 1)
1632 seqs[index++] = sg.getSequenceAt(i);
1635 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1636 sg.setHidereps(true); // note: not done in 2.7applet
1643 * @return null or the current reference sequence
1645 public SequenceI getReferenceSeq()
1647 return alignment.getSeqrep();
1652 * @return true iff seq is the reference for the alignment
1654 public boolean isReferenceSeq(SequenceI seq)
1656 return alignment.getSeqrep() == seq;
1662 * @return true if there are sequences represented by this sequence that are
1665 public boolean isHiddenRepSequence(SequenceI seq)
1667 return (hiddenRepSequences != null && hiddenRepSequences
1674 * @return null or a sequence group containing the sequences that seq
1677 public SequenceGroup getRepresentedSequences(SequenceI seq)
1679 return (SequenceGroup) (hiddenRepSequences == null ? null
1680 : hiddenRepSequences.get(seq));
1684 public int adjustForHiddenSeqs(int alignmentIndex)
1686 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1691 public void invertColumnSelection()
1693 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1697 public SequenceI[] getSelectionAsNewSequence()
1699 SequenceI[] sequences;
1700 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1701 // this was the only caller in the applet for this method
1702 // JBPNote: in applet, this method returned references to the alignment
1703 // sequences, and it did not honour the presence/absence of annotation
1704 // attached to the alignment (probably!)
1705 if (selectionGroup == null || selectionGroup.getSize() == 0)
1707 sequences = alignment.getSequencesArray();
1708 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1709 for (int i = 0; i < sequences.length; i++)
1711 // construct new sequence with subset of visible annotation
1712 sequences[i] = new Sequence(sequences[i], annots);
1717 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1724 public SequenceI[] getSequenceSelection()
1726 SequenceI[] sequences = null;
1727 if (selectionGroup != null)
1729 sequences = selectionGroup.getSequencesInOrder(alignment);
1731 if (sequences == null)
1733 sequences = alignment.getSequencesArray();
1739 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1741 return new CigarArray(alignment, alignment.getHiddenColumns(),
1742 (selectedRegionOnly ? selectionGroup : null));
1746 public jalview.datamodel.AlignmentView getAlignmentView(
1747 boolean selectedOnly)
1749 return getAlignmentView(selectedOnly, false);
1753 public jalview.datamodel.AlignmentView getAlignmentView(
1754 boolean selectedOnly, boolean markGroups)
1756 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1757 selectionGroup, alignment.getHiddenColumns() != null
1758 && alignment.getHiddenColumns().hasHiddenColumns(),
1764 public String[] getViewAsString(boolean selectedRegionOnly)
1766 return getViewAsString(selectedRegionOnly, true);
1770 public String[] getViewAsString(boolean selectedRegionOnly,
1771 boolean exportHiddenSeqs)
1773 String[] selection = null;
1774 SequenceI[] seqs = null;
1776 int start = 0, end = 0;
1777 if (selectedRegionOnly && selectionGroup != null)
1779 iSize = selectionGroup.getSize();
1780 seqs = selectionGroup.getSequencesInOrder(alignment);
1781 start = selectionGroup.getStartRes();
1782 end = selectionGroup.getEndRes() + 1;
1786 if (hasHiddenRows() && exportHiddenSeqs)
1788 AlignmentI fullAlignment = alignment.getHiddenSequences()
1789 .getFullAlignment();
1790 iSize = fullAlignment.getHeight();
1791 seqs = fullAlignment.getSequencesArray();
1792 end = fullAlignment.getWidth();
1796 iSize = alignment.getHeight();
1797 seqs = alignment.getSequencesArray();
1798 end = alignment.getWidth();
1802 selection = new String[iSize];
1803 if (alignment.getHiddenColumns() != null
1804 && alignment.getHiddenColumns().hasHiddenColumns())
1806 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1811 for (i = 0; i < iSize; i++)
1813 selection[i] = seqs[i].getSequenceAsString(start, end);
1821 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1823 ArrayList<int[]> regions = new ArrayList<>();
1829 HiddenColumns hidden = alignment.getHiddenColumns();
1830 if (hidden != null && hidden.hasHiddenColumns())
1834 start = hidden.adjustForHiddenColumns(start);
1837 end = hidden.getHiddenBoundaryRight(start);
1848 regions.add(new int[] { start, end });
1850 if (hidden != null && hidden.hasHiddenColumns())
1852 start = hidden.adjustForHiddenColumns(end);
1853 start = hidden.getHiddenBoundaryLeft(start) + 1;
1855 } while (end < max);
1857 int[][] startEnd = new int[regions.size()][2];
1863 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1864 boolean selectedOnly)
1866 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1867 AlignmentAnnotation[] aa;
1868 if ((aa = alignment.getAlignmentAnnotation()) != null)
1870 for (AlignmentAnnotation annot : aa)
1872 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1873 if (selectedOnly && selectionGroup != null)
1875 alignment.getHiddenColumns().makeVisibleAnnotation(
1876 selectionGroup.getStartRes(),
1877 selectionGroup.getEndRes(), clone);
1881 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1890 public boolean isPadGaps()
1896 public void setPadGaps(boolean padGaps)
1898 this.padGaps = padGaps;
1902 * apply any post-edit constraints and trigger any calculations needed after
1903 * an edit has been performed on the alignment
1908 public void alignmentChanged(AlignmentViewPanel ap)
1912 alignment.padGaps();
1914 if (autoCalculateConsensus)
1916 updateConsensus(ap);
1918 if (hconsensus != null && autoCalculateConsensus)
1920 updateConservation(ap);
1922 if (autoCalculateStrucConsensus)
1924 updateStrucConsensus(ap);
1927 // Reset endRes of groups if beyond alignment width
1928 int alWidth = alignment.getWidth();
1929 List<SequenceGroup> groups = alignment.getGroups();
1932 for (SequenceGroup sg : groups)
1934 if (sg.getEndRes() > alWidth)
1936 sg.setEndRes(alWidth - 1);
1941 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1943 selectionGroup.setEndRes(alWidth - 1);
1946 updateAllColourSchemes();
1947 calculator.restartWorkers();
1948 // alignment.adjustSequenceAnnotations();
1952 * reset scope and do calculations for all applied colourschemes on alignment
1954 void updateAllColourSchemes()
1956 ResidueShaderI rs = residueShading;
1959 rs.alignmentChanged(alignment, hiddenRepSequences);
1961 rs.setConsensus(hconsensus);
1962 if (rs.conservationApplied())
1964 rs.setConservation(Conservation.calculateConservation("All",
1965 alignment.getSequences(), 0, alignment.getWidth(), false,
1966 getConsPercGaps(), false));
1970 for (SequenceGroup sg : alignment.getGroups())
1974 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1976 sg.recalcConservation();
1980 protected void initAutoAnnotation()
1982 // TODO: add menu option action that nulls or creates consensus object
1983 // depending on if the user wants to see the annotation or not in a
1984 // specific alignment
1986 if (hconsensus == null && !isDataset)
1988 if (!alignment.isNucleotide())
1997 consensus = new AlignmentAnnotation("Consensus",
1998 MessageManager.getString("label.consensus_descr"),
1999 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2000 initConsensus(consensus);
2004 initComplementConsensus();
2009 * If this is a protein alignment and there are mappings to cDNA, adds the
2010 * cDNA consensus annotation and returns true, else returns false.
2012 public boolean initComplementConsensus()
2014 if (!alignment.isNucleotide())
2016 final List<AlignedCodonFrame> codonMappings = alignment
2018 if (codonMappings != null && !codonMappings.isEmpty())
2020 boolean doConsensus = false;
2021 for (AlignedCodonFrame mapping : codonMappings)
2023 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2024 MapList[] mapLists = mapping.getdnaToProt();
2025 // mapLists can be empty if project load has not finished resolving
2027 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2035 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2037 .getString("label.complement_consensus_descr"),
2038 new Annotation[1], 0f, 100f,
2039 AlignmentAnnotation.BAR_GRAPH);
2040 initConsensus(complementConsensus);
2048 private void initConsensus(AlignmentAnnotation aa)
2051 aa.autoCalculated = true;
2055 alignment.addAnnotation(aa);
2059 // these should be extracted from the view model - style and settings for
2060 // derived annotation
2061 private void initGapCounts()
2065 gapcounts = new AlignmentAnnotation("Occupancy",
2066 MessageManager.getString("label.occupancy_descr"),
2067 new Annotation[1], 0f,
2068 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
2069 gapcounts.hasText = true;
2070 gapcounts.autoCalculated = true;
2071 gapcounts.scaleColLabel = true;
2072 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2074 alignment.addAnnotation(gapcounts);
2078 private void initConservation()
2080 if (showConservation)
2082 if (conservation == null)
2084 conservation = new AlignmentAnnotation("Conservation",
2085 MessageManager.formatMessage("label.conservation_descr",
2086 getConsPercGaps()), new Annotation[1],
2087 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2088 conservation.hasText = true;
2089 conservation.autoCalculated = true;
2090 alignment.addAnnotation(conservation);
2095 private void initQuality()
2099 if (quality == null)
2101 quality = new AlignmentAnnotation("Quality",
2102 MessageManager.getString("label.quality_descr"),
2103 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2104 quality.hasText = true;
2105 quality.autoCalculated = true;
2106 alignment.addAnnotation(quality);
2111 private void initRNAStructure()
2113 if (alignment.hasRNAStructure() && strucConsensus == null)
2115 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2116 MessageManager.getString("label.strucconsensus_descr"),
2117 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2118 strucConsensus.hasText = true;
2119 strucConsensus.autoCalculated = true;
2123 alignment.addAnnotation(strucConsensus);
2131 * @see jalview.api.AlignViewportI#calcPanelHeight()
2134 public int calcPanelHeight()
2136 // setHeight of panels
2137 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2139 int charHeight = getCharHeight();
2142 BitSet graphgrp = new BitSet();
2143 for (AlignmentAnnotation aa : anns)
2147 System.err.println("Null annotation row: ignoring.");
2154 if (aa.graphGroup > -1)
2156 if (graphgrp.get(aa.graphGroup))
2162 graphgrp.set(aa.graphGroup);
2169 aa.height += charHeight;
2179 aa.height += aa.graphHeight;
2187 height += aa.height;
2199 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2200 boolean preserveNewGroupSettings)
2202 boolean updateCalcs = false;
2203 boolean conv = isShowGroupConservation();
2204 boolean cons = isShowGroupConsensus();
2205 boolean showprf = isShowSequenceLogo();
2206 boolean showConsHist = isShowConsensusHistogram();
2207 boolean normLogo = isNormaliseSequenceLogo();
2210 * TODO reorder the annotation rows according to group/sequence ordering on
2213 boolean sortg = true;
2215 // remove old automatic annotation
2216 // add any new annotation
2218 // intersect alignment annotation with alignment groups
2220 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2221 List<SequenceGroup> oldrfs = new ArrayList<>();
2224 for (int an = 0; an < aan.length; an++)
2226 if (aan[an].autoCalculated && aan[an].groupRef != null)
2228 oldrfs.add(aan[an].groupRef);
2229 alignment.deleteAnnotation(aan[an], false);
2233 if (alignment.getGroups() != null)
2235 for (SequenceGroup sg : alignment.getGroups())
2237 updateCalcs = false;
2238 if (applyGlobalSettings
2239 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2241 // set defaults for this group's conservation/consensus
2242 sg.setshowSequenceLogo(showprf);
2243 sg.setShowConsensusHistogram(showConsHist);
2244 sg.setNormaliseSequenceLogo(normLogo);
2249 alignment.addAnnotation(sg.getConservationRow(), 0);
2254 alignment.addAnnotation(sg.getConsensus(), 0);
2256 // refresh the annotation rows
2259 sg.recalcConservation();
2267 public boolean isDisplayReferenceSeq()
2269 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2273 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2275 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2279 public boolean isColourByReferenceSeq()
2281 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2285 public Color getSequenceColour(SequenceI seq)
2287 Color sqc = sequenceColours.get(seq);
2288 return (sqc == null ? Color.white : sqc);
2292 public void setSequenceColour(SequenceI seq, Color col)
2296 sequenceColours.remove(seq);
2300 sequenceColours.put(seq, col);
2305 public void updateSequenceIdColours()
2307 for (SequenceGroup sg : alignment.getGroups())
2309 if (sg.idColour != null)
2311 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2313 sequenceColours.put(s, sg.idColour);
2320 public void clearSequenceColours()
2322 sequenceColours.clear();
2326 public AlignViewportI getCodingComplement()
2328 return this.codingComplement;
2332 * Set this as the (cDna/protein) complement of the given viewport. Also
2333 * ensures the reverse relationship is set on the given viewport.
2336 public void setCodingComplement(AlignViewportI av)
2340 System.err.println("Ignoring recursive setCodingComplement request");
2344 this.codingComplement = av;
2345 // avoid infinite recursion!
2346 if (av.getCodingComplement() != this)
2348 av.setCodingComplement(this);
2354 public boolean isNucleotide()
2356 return getAlignment() == null ? false : getAlignment().isNucleotide();
2360 public FeaturesDisplayedI getFeaturesDisplayed()
2362 return featuresDisplayed;
2366 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2368 featuresDisplayed = featuresDisplayedI;
2372 public boolean areFeaturesDisplayed()
2374 return featuresDisplayed != null
2375 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2382 * features are displayed if true
2385 public void setShowSequenceFeatures(boolean b)
2387 viewStyle.setShowSequenceFeatures(b);
2391 public boolean isShowSequenceFeatures()
2393 return viewStyle.isShowSequenceFeatures();
2397 public void setShowSequenceFeaturesHeight(boolean selected)
2399 viewStyle.setShowSequenceFeaturesHeight(selected);
2403 public boolean isShowSequenceFeaturesHeight()
2405 return viewStyle.isShowSequenceFeaturesHeight();
2409 public void setShowAnnotation(boolean b)
2411 viewStyle.setShowAnnotation(b);
2415 public boolean isShowAnnotation()
2417 return viewStyle.isShowAnnotation();
2421 public boolean isRightAlignIds()
2423 return viewStyle.isRightAlignIds();
2427 public void setRightAlignIds(boolean rightAlignIds)
2429 viewStyle.setRightAlignIds(rightAlignIds);
2433 public boolean getConservationSelected()
2435 return viewStyle.getConservationSelected();
2439 public void setShowBoxes(boolean state)
2441 viewStyle.setShowBoxes(state);
2446 * @see jalview.api.ViewStyleI#getTextColour()
2449 public Color getTextColour()
2451 return viewStyle.getTextColour();
2456 * @see jalview.api.ViewStyleI#getTextColour2()
2459 public Color getTextColour2()
2461 return viewStyle.getTextColour2();
2466 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2469 public int getThresholdTextColour()
2471 return viewStyle.getThresholdTextColour();
2476 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2479 public boolean isConservationColourSelected()
2481 return viewStyle.isConservationColourSelected();
2486 * @see jalview.api.ViewStyleI#isRenderGaps()
2489 public boolean isRenderGaps()
2491 return viewStyle.isRenderGaps();
2496 * @see jalview.api.ViewStyleI#isShowColourText()
2499 public boolean isShowColourText()
2501 return viewStyle.isShowColourText();
2505 * @param conservationColourSelected
2506 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2509 public void setConservationColourSelected(
2510 boolean conservationColourSelected)
2512 viewStyle.setConservationColourSelected(conservationColourSelected);
2516 * @param showColourText
2517 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2520 public void setShowColourText(boolean showColourText)
2522 viewStyle.setShowColourText(showColourText);
2527 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2530 public void setTextColour(Color textColour)
2532 viewStyle.setTextColour(textColour);
2536 * @param thresholdTextColour
2537 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2540 public void setThresholdTextColour(int thresholdTextColour)
2542 viewStyle.setThresholdTextColour(thresholdTextColour);
2546 * @param textColour2
2547 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2550 public void setTextColour2(Color textColour2)
2552 viewStyle.setTextColour2(textColour2);
2556 public ViewStyleI getViewStyle()
2558 return new ViewStyle(viewStyle);
2562 public void setViewStyle(ViewStyleI settingsForView)
2564 viewStyle = new ViewStyle(settingsForView);
2565 if (residueShading != null)
2567 residueShading.setConservationApplied(settingsForView
2568 .isConservationColourSelected());
2573 public boolean sameStyle(ViewStyleI them)
2575 return viewStyle.sameStyle(them);
2580 * @see jalview.api.ViewStyleI#getIdWidth()
2583 public int getIdWidth()
2585 return viewStyle.getIdWidth();
2590 * @see jalview.api.ViewStyleI#setIdWidth(int)
2593 public void setIdWidth(int i)
2595 viewStyle.setIdWidth(i);
2600 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2603 public boolean isCentreColumnLabels()
2605 return viewStyle.isCentreColumnLabels();
2609 * @param centreColumnLabels
2610 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2613 public void setCentreColumnLabels(boolean centreColumnLabels)
2615 viewStyle.setCentreColumnLabels(centreColumnLabels);
2620 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2623 public void setShowDBRefs(boolean showdbrefs)
2625 viewStyle.setShowDBRefs(showdbrefs);
2630 * @see jalview.api.ViewStyleI#isShowDBRefs()
2633 public boolean isShowDBRefs()
2635 return viewStyle.isShowDBRefs();
2640 * @see jalview.api.ViewStyleI#isShowNPFeats()
2643 public boolean isShowNPFeats()
2645 return viewStyle.isShowNPFeats();
2649 * @param shownpfeats
2650 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2653 public void setShowNPFeats(boolean shownpfeats)
2655 viewStyle.setShowNPFeats(shownpfeats);
2658 public abstract StructureSelectionManager getStructureSelectionManager();
2661 * Add one command to the command history list.
2665 public void addToHistoryList(CommandI command)
2667 if (this.historyList != null)
2669 this.historyList.push(command);
2670 broadcastCommand(command, false);
2674 protected void broadcastCommand(CommandI command, boolean undo)
2676 getStructureSelectionManager().commandPerformed(command, undo,
2681 * Add one command to the command redo list.
2685 public void addToRedoList(CommandI command)
2687 if (this.redoList != null)
2689 this.redoList.push(command);
2691 broadcastCommand(command, true);
2695 * Clear the command redo list.
2697 public void clearRedoList()
2699 if (this.redoList != null)
2701 this.redoList.clear();
2705 public void setHistoryList(Deque<CommandI> list)
2707 this.historyList = list;
2710 public Deque<CommandI> getHistoryList()
2712 return this.historyList;
2715 public void setRedoList(Deque<CommandI> list)
2717 this.redoList = list;
2720 public Deque<CommandI> getRedoList()
2722 return this.redoList;
2726 public VamsasSource getVamsasSource()
2731 public SequenceAnnotationOrder getSortAnnotationsBy()
2733 return sortAnnotationsBy;
2736 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2738 this.sortAnnotationsBy = sortAnnotationsBy;
2741 public boolean isShowAutocalculatedAbove()
2743 return showAutocalculatedAbove;
2746 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2748 this.showAutocalculatedAbove = showAutocalculatedAbove;
2752 public boolean isScaleProteinAsCdna()
2754 return viewStyle.isScaleProteinAsCdna();
2758 public void setScaleProteinAsCdna(boolean b)
2760 viewStyle.setScaleProteinAsCdna(b);
2764 public boolean isProteinFontAsCdna()
2766 return viewStyle.isProteinFontAsCdna();
2770 public void setProteinFontAsCdna(boolean b)
2772 viewStyle.setProteinFontAsCdna(b);
2776 * @return true if view should scroll to show the highlighted region of a
2781 public final boolean isFollowHighlight()
2783 return followHighlight;
2787 public final void setFollowHighlight(boolean b)
2789 this.followHighlight = b;
2793 public ViewportRanges getRanges()
2799 * Helper method to populate the SearchResults with the location in the
2800 * complementary alignment to scroll to, in order to match this one.
2803 * the SearchResults to add to
2804 * @return the offset (below top of visible region) of the matched sequence
2806 protected int findComplementScrollTarget(SearchResultsI sr)
2808 final AlignViewportI complement = getCodingComplement();
2809 if (complement == null || !complement.isFollowHighlight())
2813 boolean iAmProtein = !getAlignment().isNucleotide();
2814 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2816 if (proteinAlignment == null)
2820 final List<AlignedCodonFrame> mappings = proteinAlignment
2824 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2825 * residue in the middle column of the visible region. Scroll the
2826 * complementary alignment to line up the corresponding residue.
2829 SequenceI sequence = null;
2832 * locate 'middle' column (true middle if an odd number visible, left of
2833 * middle if an even number visible)
2835 int middleColumn = ranges.getStartRes()
2836 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2837 final HiddenSequences hiddenSequences = getAlignment()
2838 .getHiddenSequences();
2841 * searching to the bottom of the alignment gives smoother scrolling across
2842 * all gapped visible regions
2844 int lastSeq = alignment.getHeight() - 1;
2845 List<AlignedCodonFrame> seqMappings = null;
2846 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2848 sequence = getAlignment().getSequenceAt(seqNo);
2849 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2853 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2857 seqMappings = MappingUtils
2858 .findMappingsForSequenceAndOthers(sequence, mappings,
2859 getCodingComplement().getAlignment().getSequences());
2860 if (!seqMappings.isEmpty())
2866 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2869 * No ungapped mapped sequence in middle column - do nothing
2873 MappingUtils.addSearchResults(sr, sequence,
2874 sequence.findPosition(middleColumn), seqMappings);
2879 * synthesize a column selection if none exists so it covers the given
2880 * selection group. if wholewidth is false, no column selection is made if the
2881 * selection group covers the whole alignment width.
2886 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2889 if (sg != null && (sgs = sg.getStartRes()) >= 0
2890 && sg.getStartRes() <= (sge = sg.getEndRes())
2891 && !this.hasSelectedColumns())
2893 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2900 colSel = new ColumnSelection();
2902 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2904 colSel.addElement(cspos);
2910 * hold status of current selection group - defined on alignment or not.
2912 private boolean selectionIsDefinedGroup = false;
2915 public boolean isSelectionDefinedGroup()
2917 if (selectionGroup == null)
2921 if (isSelectionGroupChanged(true))
2923 selectionIsDefinedGroup = false;
2924 List<SequenceGroup> gps = alignment.getGroups();
2925 if (gps == null || gps.size() == 0)
2927 selectionIsDefinedGroup = false;
2931 selectionIsDefinedGroup = gps.contains(selectionGroup);
2934 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2938 * null, or currently highlighted results on this view
2940 private SearchResultsI searchResults = null;
2943 public boolean hasSearchResults()
2945 return searchResults != null;
2949 public void setSearchResults(SearchResultsI results)
2951 searchResults = results;
2955 public SearchResultsI getSearchResults()
2957 return searchResults;