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.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignViewportI;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.api.FeaturesDisplayedI;
30 import jalview.api.ViewStyleI;
31 import jalview.commands.CommandI;
32 import jalview.datamodel.AlignedCodonFrame;
33 import jalview.datamodel.AlignmentAnnotation;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentView;
36 import jalview.datamodel.Annotation;
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.InformationThread;
61 import jalview.workers.StrucConsensusThread;
63 import java.awt.Color;
64 import java.beans.PropertyChangeSupport;
65 import java.util.ArrayDeque;
66 import java.util.ArrayList;
67 import java.util.BitSet;
68 import java.util.Deque;
69 import java.util.HashMap;
70 import java.util.Hashtable;
71 import java.util.Iterator;
72 import java.util.List;
76 * base class holding visualization and analysis attributes and common logic for
77 * an active alignment view displayed in the GUI
82 public abstract class AlignmentViewport
83 implements AlignViewportI, CommandListener, VamsasSource
85 protected ViewportRanges ranges;
87 protected ViewStyleI viewStyle = new ViewStyle();
90 * A viewport that hosts the cDna view of this (protein), or vice versa (if
93 AlignViewportI codingComplement = null;
95 FeaturesDisplayedI featuresDisplayed = null;
97 protected Deque<CommandI> historyList = new ArrayDeque<>();
99 protected Deque<CommandI> redoList = new ArrayDeque<>();
101 protected String sequenceSetID;
104 * probably unused indicator that view is of a dataset rather than an
107 protected boolean isDataset = false;
109 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
111 protected ColumnSelection colSel = new ColumnSelection();
113 public boolean autoCalculateConsensus = true;
115 protected boolean autoCalculateStrucConsensus = true;
117 protected boolean ignoreGapsInConsensusCalculation = false;
119 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
121 protected boolean infoLetterHeight = false;
123 protected ResidueShaderI residueShading = new ResidueShader();
125 protected AlignmentAnnotation consensus;
127 protected AlignmentAnnotation complementConsensus;
129 protected AlignmentAnnotation occupancy;
131 protected AlignmentAnnotation strucConsensus;
133 protected AlignmentAnnotation conservation;
135 protected AlignmentAnnotation quality;
138 * alignment displayed in the viewport
140 private AlignmentI alignment;
143 * results of alignment consensus analysis for visible portion of view
145 protected ProfilesI consensusProfiles;
148 * HMM profile for the alignment
150 protected ProfilesI hmmProfiles;
153 * results of cDNA complement consensus visible portion of view
155 protected Hashtable[] hcomplementConsensus;
158 * results of secondary structure base pair consensus for visible portion of
161 protected Hashtable[] hStrucConsensus;
163 protected Conservation hconservation;
165 public AlignmentViewport(AlignmentI al)
168 ranges = new ViewportRanges(al);
173 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
176 public void setFontName(String name)
178 viewStyle.setFontName(name);
183 * @see jalview.api.ViewStyleI#setFontStyle(int)
186 public void setFontStyle(int style)
188 viewStyle.setFontStyle(style);
193 * @see jalview.api.ViewStyleI#setFontSize(int)
196 public void setFontSize(int size)
198 viewStyle.setFontSize(size);
203 * @see jalview.api.ViewStyleI#getFontStyle()
206 public int getFontStyle()
208 return viewStyle.getFontStyle();
213 * @see jalview.api.ViewStyleI#getFontName()
216 public String getFontName()
218 return viewStyle.getFontName();
223 * @see jalview.api.ViewStyleI#getFontSize()
226 public int getFontSize()
228 return viewStyle.getFontSize();
232 * @param upperCasebold
233 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
236 public void setUpperCasebold(boolean upperCasebold)
238 viewStyle.setUpperCasebold(upperCasebold);
243 * @see jalview.api.ViewStyleI#isUpperCasebold()
246 public boolean isUpperCasebold()
248 return viewStyle.isUpperCasebold();
253 * @see jalview.api.ViewStyleI#isSeqNameItalics()
256 public boolean isSeqNameItalics()
258 return viewStyle.isSeqNameItalics();
262 * @param colourByReferenceSeq
263 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
266 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
268 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
273 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
276 public void setColourAppliesToAllGroups(boolean b)
278 viewStyle.setColourAppliesToAllGroups(b);
283 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
286 public boolean getColourAppliesToAllGroups()
288 return viewStyle.getColourAppliesToAllGroups();
293 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
296 public boolean getAbovePIDThreshold()
298 return viewStyle.getAbovePIDThreshold();
303 * @see jalview.api.ViewStyleI#setIncrement(int)
306 public void setIncrement(int inc)
308 viewStyle.setIncrement(inc);
313 * @see jalview.api.ViewStyleI#getIncrement()
316 public int getIncrement()
318 return viewStyle.getIncrement();
323 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
326 public void setConservationSelected(boolean b)
328 viewStyle.setConservationSelected(b);
333 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
336 public void setShowHiddenMarkers(boolean show)
338 viewStyle.setShowHiddenMarkers(show);
343 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
346 public boolean getShowHiddenMarkers()
348 return viewStyle.getShowHiddenMarkers();
353 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
356 public void setScaleRightWrapped(boolean b)
358 viewStyle.setScaleRightWrapped(b);
363 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
366 public void setScaleLeftWrapped(boolean b)
368 viewStyle.setScaleLeftWrapped(b);
373 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
376 public void setScaleAboveWrapped(boolean b)
378 viewStyle.setScaleAboveWrapped(b);
383 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
386 public boolean getScaleLeftWrapped()
388 return viewStyle.getScaleLeftWrapped();
393 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
396 public boolean getScaleAboveWrapped()
398 return viewStyle.getScaleAboveWrapped();
403 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
406 public boolean getScaleRightWrapped()
408 return viewStyle.getScaleRightWrapped();
413 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
416 public void setAbovePIDThreshold(boolean b)
418 viewStyle.setAbovePIDThreshold(b);
423 * @see jalview.api.ViewStyleI#setThreshold(int)
426 public void setThreshold(int thresh)
428 viewStyle.setThreshold(thresh);
433 * @see jalview.api.ViewStyleI#getThreshold()
436 public int getThreshold()
438 return viewStyle.getThreshold();
443 * @see jalview.api.ViewStyleI#getShowJVSuffix()
446 public boolean getShowJVSuffix()
448 return viewStyle.getShowJVSuffix();
453 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
456 public void setShowJVSuffix(boolean b)
458 viewStyle.setShowJVSuffix(b);
463 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
466 public void setWrapAlignment(boolean state)
468 viewStyle.setWrapAlignment(state);
469 ranges.setWrappedMode(state);
474 * @see jalview.api.ViewStyleI#setShowText(boolean)
477 public void setShowText(boolean state)
479 viewStyle.setShowText(state);
484 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
487 public void setRenderGaps(boolean state)
489 viewStyle.setRenderGaps(state);
494 * @see jalview.api.ViewStyleI#getColourText()
497 public boolean getColourText()
499 return viewStyle.getColourText();
504 * @see jalview.api.ViewStyleI#setColourText(boolean)
507 public void setColourText(boolean state)
509 viewStyle.setColourText(state);
514 * @see jalview.api.ViewStyleI#getWrapAlignment()
517 public boolean getWrapAlignment()
519 return viewStyle.getWrapAlignment();
524 * @see jalview.api.ViewStyleI#getShowText()
527 public boolean getShowText()
529 return viewStyle.getShowText();
534 * @see jalview.api.ViewStyleI#getWrappedWidth()
537 public int getWrappedWidth()
539 return viewStyle.getWrappedWidth();
544 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
547 public void setWrappedWidth(int w)
549 viewStyle.setWrappedWidth(w);
554 * @see jalview.api.ViewStyleI#getCharHeight()
557 public int getCharHeight()
559 return viewStyle.getCharHeight();
564 * @see jalview.api.ViewStyleI#setCharHeight(int)
567 public void setCharHeight(int h)
569 viewStyle.setCharHeight(h);
574 * @see jalview.api.ViewStyleI#getCharWidth()
577 public int getCharWidth()
579 return viewStyle.getCharWidth();
584 * @see jalview.api.ViewStyleI#setCharWidth(int)
587 public void setCharWidth(int w)
589 viewStyle.setCharWidth(w);
594 * @see jalview.api.ViewStyleI#getShowBoxes()
597 public boolean getShowBoxes()
599 return viewStyle.getShowBoxes();
604 * @see jalview.api.ViewStyleI#getShowUnconserved()
607 public boolean getShowUnconserved()
609 return viewStyle.getShowUnconserved();
613 * @param showunconserved
614 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
617 public void setShowUnconserved(boolean showunconserved)
619 viewStyle.setShowUnconserved(showunconserved);
624 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
627 public void setSeqNameItalics(boolean default1)
629 viewStyle.setSeqNameItalics(default1);
633 public AlignmentI getAlignment()
639 public char getGapCharacter()
641 return alignment.getGapCharacter();
644 public void setDataset(boolean b)
649 public boolean isDataset()
655 public void setGlobalColourScheme(ColourSchemeI cs)
657 // TODO: logic refactored from AlignFrame changeColour -
658 // TODO: autorecalc stuff should be changed to rely on the worker system
659 // check to see if we should implement a changeColour(cs) method rather than
660 // put the logic in here
661 // - means that caller decides if they want to just modify state and defer
662 // calculation till later or to do all calculations in thread.
666 * only instantiate alignment colouring once, thereafter update it;
667 * this means that any conservation or PID threshold settings
668 * persist when the alignment colour scheme is changed
670 if (residueShading == null)
672 residueShading = new ResidueShader(viewStyle);
674 residueShading.setColourScheme(cs);
676 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
677 // ...problem: groups need these, but do not currently have a ViewStyle
681 if (getConservationSelected())
683 residueShading.setConservation(hconservation);
686 * reset conservation flag in case just set to false if
687 * Conservation was null (calculation still in progress)
689 residueShading.setConservationApplied(getConservationSelected());
690 residueShading.alignmentChanged(alignment, hiddenRepSequences);
694 * if 'apply colour to all groups' is selected... do so
695 * (but don't transfer any colour threshold settings to groups)
697 if (getColourAppliesToAllGroups())
699 for (SequenceGroup sg : getAlignment().getGroups())
702 * retain any colour thresholds per group while
703 * changing choice of colour scheme (JAL-2386)
705 sg.setColourScheme(cs);
708 sg.getGroupColourScheme().alignmentChanged(sg,
716 public ColourSchemeI getGlobalColourScheme()
718 return residueShading == null ? null : residueShading.getColourScheme();
722 public ResidueShaderI getResidueShading()
724 return residueShading;
727 public void setConservation(Conservation cons)
729 hconservation = cons;
733 * percentage gaps allowed in a column before all amino acid properties should
734 * be considered unconserved
736 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
739 public int getConsPercGaps()
745 public void setConsensusProfiles(ProfilesI hconsensus)
747 this.consensusProfiles = hconsensus;
751 public void setComplementConsensusHash(Hashtable[] hconsensus)
753 this.hcomplementConsensus = hconsensus;
757 public ProfilesI getConsensusProfiles()
759 return consensusProfiles;
763 public void setHmmProfiles(ProfilesI info)
769 public ProfilesI getHmmProfiles()
775 public Hashtable[] getComplementConsensusHash()
777 return hcomplementConsensus;
781 public Hashtable[] getRnaStructureConsensusHash()
783 return hStrucConsensus;
787 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
789 this.hStrucConsensus = hStrucConsensus;
794 public AlignmentAnnotation getAlignmentQualityAnnot()
800 public AlignmentAnnotation getAlignmentConservationAnnotation()
806 public AlignmentAnnotation getAlignmentConsensusAnnotation()
812 public AlignmentAnnotation getOccupancyAnnotation()
818 public AlignmentAnnotation getComplementConsensusAnnotation()
820 return complementConsensus;
824 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
826 return strucConsensus;
829 protected AlignCalcManagerI calculator = new AlignCalcManager();
832 * trigger update of conservation annotation
834 public void updateConservation(final AlignmentViewPanel ap)
836 // see note in mantis : issue number 8585
837 if (alignment.isNucleotide()
838 || (conservation == null && quality == null)
839 || !autoCalculateConsensus)
843 if (calculator.getRegisteredWorkersOfClass(
844 jalview.workers.ConservationThread.class) == null)
846 calculator.registerWorker(
847 new jalview.workers.ConservationThread(this, ap));
852 * trigger update of consensus annotation
854 public void updateConsensus(final AlignmentViewPanel ap)
856 // see note in mantis : issue number 8585
857 if (consensus == null || !autoCalculateConsensus)
862 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
864 calculator.registerWorker(new ConsensusThread(this, ap));
868 * A separate thread to compute cDNA consensus for a protein alignment
869 * which has mapping to cDNA
871 final AlignmentI al = this.getAlignment();
872 if (!al.isNucleotide() && al.getCodonFrames() != null
873 && !al.getCodonFrames().isEmpty())
876 * fudge - check first for protein-to-nucleotide mappings
877 * (we don't want to do this for protein-to-protein)
879 boolean doConsensus = false;
880 for (AlignedCodonFrame mapping : al.getCodonFrames())
882 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
883 MapList[] mapLists = mapping.getdnaToProt();
884 // mapLists can be empty if project load has not finished resolving seqs
885 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
893 if (calculator.getRegisteredWorkersOfClass(
894 ComplementConsensusThread.class) == null)
897 .registerWorker(new ComplementConsensusThread(this, ap));
904 public void initInformationWorker(final AlignmentViewPanel ap)
907 .getRegisteredWorkersOfClass(InformationThread.class) == null)
909 calculator.registerWorker(new InformationThread(this, ap));
913 // --------START Structure Conservation
914 public void updateStrucConsensus(final AlignmentViewPanel ap)
916 if (autoCalculateStrucConsensus && strucConsensus == null
917 && alignment.isNucleotide() && alignment.hasRNAStructure())
919 // secondary structure has been added - so init the consensus line
923 // see note in mantis : issue number 8585
924 if (strucConsensus == null || !autoCalculateStrucConsensus)
928 if (calculator.getRegisteredWorkersOfClass(
929 StrucConsensusThread.class) == null)
931 calculator.registerWorker(new StrucConsensusThread(this, ap));
935 public boolean isCalcInProgress()
937 return calculator.isWorking();
941 public boolean isCalculationInProgress(
942 AlignmentAnnotation alignmentAnnotation)
944 if (!alignmentAnnotation.autoCalculated)
948 if (calculator.workingInvolvedWith(alignmentAnnotation))
950 // System.err.println("grey out ("+alignmentAnnotation.label+")");
956 public void setAlignment(AlignmentI align)
958 this.alignment = align;
962 * Clean up references when this viewport is closed
965 public void dispose()
968 * defensively null out references to large objects in case
969 * this object is not garbage collected (as if!)
972 complementConsensus = null;
973 strucConsensus = null;
976 consensusProfiles = null;
977 hconservation = null;
978 hcomplementConsensus = null;
981 residueShading = null; // may hold a reference to Consensus
982 changeSupport = null;
985 selectionGroup = null;
990 public boolean isClosed()
992 // TODO: check that this isClosed is only true after panel is closed, not
993 // before it is fully constructed.
994 return alignment == null;
998 public AlignCalcManagerI getCalcManager()
1004 * should conservation rows be shown for groups
1006 protected boolean showGroupConservation = false;
1009 * should consensus rows be shown for groups
1011 protected boolean showGroupConsensus = false;
1014 * should consensus profile be rendered by default
1016 protected boolean showSequenceLogo = false;
1019 * should consensus profile be rendered normalised to row height
1021 protected boolean normaliseSequenceLogo = false;
1024 * should consensus histograms be rendered by default
1026 protected boolean showConsensusHistogram = true;
1029 * should hmm profile be rendered by default
1031 protected boolean showHMMSequenceLogo = false;
1034 * should hmm profile be rendered normalised to row height
1036 protected boolean normaliseHMMSequenceLogo = false;
1039 * should information histograms be rendered by default
1041 protected boolean showInformationHistogram = true;
1044 * @return the showConsensusProfile
1047 public boolean isShowSequenceLogo()
1049 return showSequenceLogo;
1053 * @return the showInformationProfile
1056 public boolean isShowHMMSequenceLogo()
1058 return showHMMSequenceLogo;
1062 * @param showSequenceLogo
1065 public void setShowSequenceLogo(boolean showSequenceLogo)
1067 if (showSequenceLogo != this.showSequenceLogo)
1069 // TODO: decouple settings setting from calculation when refactoring
1070 // annotation update method from alignframe to viewport
1071 this.showSequenceLogo = showSequenceLogo;
1072 calculator.updateAnnotationFor(ConsensusThread.class);
1073 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1074 calculator.updateAnnotationFor(StrucConsensusThread.class);
1076 this.showSequenceLogo = showSequenceLogo;
1079 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1081 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1083 this.showHMMSequenceLogo = showHMMSequenceLogo;
1084 // TODO: updateAnnotation if description (tooltip) will show
1085 // profile in place of information content?
1086 // calculator.updateAnnotationFor(InformationThread.class);
1088 this.showHMMSequenceLogo = showHMMSequenceLogo;
1092 * @param showConsensusHistogram
1093 * the showConsensusHistogram to set
1095 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1097 this.showConsensusHistogram = showConsensusHistogram;
1101 * @param showInformationHistogram
1102 * the showInformationHistogram to set
1104 public void setShowInformationHistogram(boolean showInformationHistogram)
1106 this.showInformationHistogram = showInformationHistogram;
1110 * @return the showGroupConservation
1112 public boolean isShowGroupConservation()
1114 return showGroupConservation;
1118 * @param showGroupConservation
1119 * the showGroupConservation to set
1121 public void setShowGroupConservation(boolean showGroupConservation)
1123 this.showGroupConservation = showGroupConservation;
1127 * @return the showGroupConsensus
1129 public boolean isShowGroupConsensus()
1131 return showGroupConsensus;
1135 * @param showGroupConsensus
1136 * the showGroupConsensus to set
1138 public void setShowGroupConsensus(boolean showGroupConsensus)
1140 this.showGroupConsensus = showGroupConsensus;
1145 * @return flag to indicate if the consensus histogram should be rendered by
1149 public boolean isShowConsensusHistogram()
1151 return this.showConsensusHistogram;
1156 * @return flag to indicate if the information content histogram should be
1157 * rendered by default
1160 public boolean isShowInformationHistogram()
1162 return this.showInformationHistogram;
1166 * when set, updateAlignment will always ensure sequences are of equal length
1168 private boolean padGaps = false;
1171 * when set, alignment should be reordered according to a newly opened tree
1173 public boolean sortByTree = false;
1178 * @return null or the currently selected sequence region
1181 public SequenceGroup getSelectionGroup()
1183 return selectionGroup;
1187 * Set the selection group for this window. Also sets the current alignment as
1188 * the context for the group, if it does not already have one.
1191 * - group holding references to sequences in this alignment view
1195 public void setSelectionGroup(SequenceGroup sg)
1197 selectionGroup = sg;
1198 if (sg != null && sg.getContext() == null)
1200 sg.setContext(alignment);
1204 public void setHiddenColumns(HiddenColumns hidden)
1206 this.alignment.setHiddenColumns(hidden);
1210 public ColumnSelection getColumnSelection()
1216 public void setColumnSelection(ColumnSelection colSel)
1218 this.colSel = colSel;
1221 updateHiddenColumns();
1223 isColSelChanged(true);
1231 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1233 return hiddenRepSequences;
1237 public void setHiddenRepSequences(
1238 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1240 this.hiddenRepSequences = hiddenRepSequences;
1244 public boolean hasSelectedColumns()
1246 ColumnSelection columnSelection = getColumnSelection();
1247 return columnSelection != null && columnSelection.hasSelectedColumns();
1251 public boolean hasHiddenColumns()
1253 return alignment.getHiddenColumns() != null
1254 && alignment.getHiddenColumns().hasHiddenColumns();
1257 public void updateHiddenColumns()
1259 // this method doesn't really do anything now. But - it could, since a
1260 // column Selection could be in the process of modification
1261 // hasHiddenColumns = colSel.hasHiddenColumns();
1265 public boolean hasHiddenRows()
1267 return alignment.getHiddenSequences().getSize() > 0;
1270 protected SequenceGroup selectionGroup;
1272 public void setSequenceSetId(String newid)
1274 if (sequenceSetID != null)
1277 "Warning - overwriting a sequenceSetId for a viewport!");
1279 sequenceSetID = new String(newid);
1283 public String getSequenceSetId()
1285 if (sequenceSetID == null)
1287 sequenceSetID = alignment.hashCode() + "";
1290 return sequenceSetID;
1294 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1297 protected String viewId = null;
1300 public String getViewId()
1304 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1309 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1311 ignoreGapsInConsensusCalculation = b;
1314 if (residueShading != null)
1316 residueShading.setThreshold(residueShading.getThreshold(),
1317 ignoreGapsInConsensusCalculation);
1322 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1324 ignoreBelowBackGroundFrequencyCalculation = b;
1327 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1329 infoLetterHeight = b;
1332 private long sgrouphash = -1, colselhash = -1;
1335 * checks current SelectionGroup against record of last hash value, and
1339 * update the record of last hash value
1341 * @return true if SelectionGroup changed since last call (when b is true)
1343 public boolean isSelectionGroupChanged(boolean b)
1345 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1346 : selectionGroup.hashCode();
1347 if (hc != -1 && hc != sgrouphash)
1359 * checks current colsel against record of last hash value, and optionally
1363 * update the record of last hash value
1364 * @return true if colsel changed since last call (when b is true)
1366 public boolean isColSelChanged(boolean b)
1368 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1369 if (hc != -1 && hc != colselhash)
1381 public boolean isIgnoreGapsConsensus()
1383 return ignoreGapsInConsensusCalculation;
1387 public boolean isIgnoreBelowBackground()
1389 return ignoreBelowBackGroundFrequencyCalculation;
1393 public boolean isInfoLetterHeight()
1395 return infoLetterHeight;
1398 // property change stuff
1399 // JBPNote Prolly only need this in the applet version.
1400 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1403 protected boolean showConservation = true;
1405 protected boolean showQuality = true;
1407 protected boolean showConsensus = true;
1409 protected boolean showOccupancy = true;
1411 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1413 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1415 protected boolean showAutocalculatedAbove;
1418 * when set, view will scroll to show the highlighted position
1420 private boolean followHighlight = true;
1423 * Property change listener for changes in alignment
1428 public void addPropertyChangeListener(
1429 java.beans.PropertyChangeListener listener)
1431 changeSupport.addPropertyChangeListener(listener);
1440 public void removePropertyChangeListener(
1441 java.beans.PropertyChangeListener listener)
1443 if (changeSupport != null)
1445 changeSupport.removePropertyChangeListener(listener);
1450 * Property change listener for changes in alignment
1459 public void firePropertyChange(String prop, Object oldvalue,
1462 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1465 // common hide/show column stuff
1467 public void hideSelectedColumns()
1469 if (colSel.isEmpty())
1474 colSel.hideSelectedColumns(alignment);
1475 setSelectionGroup(null);
1476 isColSelChanged(true);
1479 public void hideColumns(int start, int end)
1483 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1487 alignment.getHiddenColumns().hideColumns(start, end);
1489 isColSelChanged(true);
1492 public void showColumn(int col)
1494 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1495 isColSelChanged(true);
1498 public void showAllHiddenColumns()
1500 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1501 isColSelChanged(true);
1504 // common hide/show seq stuff
1505 public void showAllHiddenSeqs()
1507 int startSeq = ranges.getStartSeq();
1508 int endSeq = ranges.getEndSeq();
1510 if (alignment.getHiddenSequences().getSize() > 0)
1512 if (selectionGroup == null)
1514 selectionGroup = new SequenceGroup();
1515 selectionGroup.setEndRes(alignment.getWidth() - 1);
1517 List<SequenceI> tmp = alignment.getHiddenSequences()
1518 .showAll(hiddenRepSequences);
1519 for (SequenceI seq : tmp)
1521 selectionGroup.addSequence(seq, false);
1522 setSequenceAnnotationsVisible(seq, true);
1525 hiddenRepSequences = null;
1527 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1529 firePropertyChange("alignment", null, alignment.getSequences());
1530 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1536 public void showSequence(int index)
1538 int startSeq = ranges.getStartSeq();
1539 int endSeq = ranges.getEndSeq();
1541 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1542 hiddenRepSequences);
1545 if (selectionGroup == null)
1547 selectionGroup = new SequenceGroup();
1548 selectionGroup.setEndRes(alignment.getWidth() - 1);
1551 for (SequenceI seq : tmp)
1553 selectionGroup.addSequence(seq, false);
1554 setSequenceAnnotationsVisible(seq, true);
1557 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1559 firePropertyChange("alignment", null, alignment.getSequences());
1564 public void hideAllSelectedSeqs()
1566 if (selectionGroup == null || selectionGroup.getSize() < 1)
1571 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1575 setSelectionGroup(null);
1578 public void hideSequence(SequenceI[] seq)
1581 * cache offset to first visible sequence
1583 int startSeq = ranges.getStartSeq();
1587 for (int i = 0; i < seq.length; i++)
1589 alignment.getHiddenSequences().hideSequence(seq[i]);
1590 setSequenceAnnotationsVisible(seq[i], false);
1592 ranges.setStartSeq(startSeq);
1593 firePropertyChange("alignment", null, alignment.getSequences());
1598 * Hides the specified sequence, or the sequences it represents
1601 * the sequence to hide, or keep as representative
1602 * @param representGroup
1603 * if true, hide the current selection group except for the
1604 * representative sequence
1606 public void hideSequences(SequenceI sequence, boolean representGroup)
1608 if (selectionGroup == null || selectionGroup.getSize() < 1)
1610 hideSequence(new SequenceI[] { sequence });
1616 hideRepSequences(sequence, selectionGroup);
1617 setSelectionGroup(null);
1621 int gsize = selectionGroup.getSize();
1622 SequenceI[] hseqs = selectionGroup.getSequences()
1623 .toArray(new SequenceI[gsize]);
1625 hideSequence(hseqs);
1626 setSelectionGroup(null);
1631 * Set visibility for any annotations for the given sequence.
1635 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1638 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1641 for (AlignmentAnnotation ann : anns)
1643 if (ann.sequenceRef == sequenceI)
1645 ann.visible = visible;
1651 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1653 int sSize = sg.getSize();
1659 if (hiddenRepSequences == null)
1661 hiddenRepSequences = new Hashtable<>();
1664 hiddenRepSequences.put(repSequence, sg);
1666 // Hide all sequences except the repSequence
1667 SequenceI[] seqs = new SequenceI[sSize - 1];
1669 for (int i = 0; i < sSize; i++)
1671 if (sg.getSequenceAt(i) != repSequence)
1673 if (index == sSize - 1)
1678 seqs[index++] = sg.getSequenceAt(i);
1681 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1682 sg.setHidereps(true); // note: not done in 2.7applet
1689 * @return null or the current reference sequence
1691 public SequenceI getReferenceSeq()
1693 return alignment.getSeqrep();
1698 * @return true iff seq is the reference for the alignment
1700 public boolean isReferenceSeq(SequenceI seq)
1702 return alignment.getSeqrep() == seq;
1708 * @return true if there are sequences represented by this sequence that are
1711 public boolean isHiddenRepSequence(SequenceI seq)
1713 return (hiddenRepSequences != null
1714 && hiddenRepSequences.containsKey(seq));
1720 * @return null or a sequence group containing the sequences that seq
1723 public SequenceGroup getRepresentedSequences(SequenceI seq)
1725 return (SequenceGroup) (hiddenRepSequences == null ? null
1726 : hiddenRepSequences.get(seq));
1730 public int adjustForHiddenSeqs(int alignmentIndex)
1732 return alignment.getHiddenSequences()
1733 .adjustForHiddenSeqs(alignmentIndex);
1737 public void invertColumnSelection()
1739 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1743 public SequenceI[] getSelectionAsNewSequence()
1745 SequenceI[] sequences;
1746 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1747 // this was the only caller in the applet for this method
1748 // JBPNote: in applet, this method returned references to the alignment
1749 // sequences, and it did not honour the presence/absence of annotation
1750 // attached to the alignment (probably!)
1751 if (selectionGroup == null || selectionGroup.getSize() == 0)
1753 sequences = alignment.getSequencesArray();
1754 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1755 for (int i = 0; i < sequences.length; i++)
1757 // construct new sequence with subset of visible annotation
1758 sequences[i] = new Sequence(sequences[i], annots);
1763 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1770 public SequenceI[] getSequenceSelection()
1772 SequenceI[] sequences = null;
1773 if (selectionGroup != null)
1775 sequences = selectionGroup.getSequencesInOrder(alignment);
1777 if (sequences == null)
1779 sequences = alignment.getSequencesArray();
1785 public jalview.datamodel.AlignmentView getAlignmentView(
1786 boolean selectedOnly)
1788 return getAlignmentView(selectedOnly, false);
1792 public jalview.datamodel.AlignmentView getAlignmentView(
1793 boolean selectedOnly, boolean markGroups)
1795 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1797 alignment.getHiddenColumns() != null
1798 && alignment.getHiddenColumns().hasHiddenColumns(),
1799 selectedOnly, markGroups);
1803 public String[] getViewAsString(boolean selectedRegionOnly)
1805 return getViewAsString(selectedRegionOnly, true);
1809 public String[] getViewAsString(boolean selectedRegionOnly,
1810 boolean exportHiddenSeqs)
1812 String[] selection = null;
1813 SequenceI[] seqs = null;
1815 int start = 0, end = 0;
1816 if (selectedRegionOnly && selectionGroup != null)
1818 iSize = selectionGroup.getSize();
1819 seqs = selectionGroup.getSequencesInOrder(alignment);
1820 start = selectionGroup.getStartRes();
1821 end = selectionGroup.getEndRes() + 1;
1825 if (hasHiddenRows() && exportHiddenSeqs)
1827 AlignmentI fullAlignment = alignment.getHiddenSequences()
1828 .getFullAlignment();
1829 iSize = fullAlignment.getHeight();
1830 seqs = fullAlignment.getSequencesArray();
1831 end = fullAlignment.getWidth();
1835 iSize = alignment.getHeight();
1836 seqs = alignment.getSequencesArray();
1837 end = alignment.getWidth();
1841 selection = new String[iSize];
1842 if (alignment.getHiddenColumns() != null
1843 && alignment.getHiddenColumns().hasHiddenColumns())
1845 for (i = 0; i < iSize; i++)
1847 Iterator<int[]> blocks = alignment.getHiddenColumns()
1848 .getVisContigsIterator(start, end + 1, false);
1849 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1854 for (i = 0; i < iSize; i++)
1856 selection[i] = seqs[i].getSequenceAsString(start, end);
1864 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1866 ArrayList<int[]> regions = new ArrayList<>();
1872 HiddenColumns hidden = alignment.getHiddenColumns();
1873 if (hidden != null && hidden.hasHiddenColumns())
1877 start = hidden.visibleToAbsoluteColumn(start);
1880 end = hidden.getNextHiddenBoundary(false, start);
1891 regions.add(new int[] { start, end });
1893 if (hidden != null && hidden.hasHiddenColumns())
1895 start = hidden.visibleToAbsoluteColumn(end);
1896 start = hidden.getNextHiddenBoundary(true, start) + 1;
1898 } while (end < max);
1900 int[][] startEnd = new int[regions.size()][2];
1906 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1907 boolean selectedOnly)
1909 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1910 AlignmentAnnotation[] aa;
1911 if ((aa = alignment.getAlignmentAnnotation()) != null)
1913 for (AlignmentAnnotation annot : aa)
1915 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1916 if (selectedOnly && selectionGroup != null)
1918 clone.makeVisibleAnnotation(
1919 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1920 alignment.getHiddenColumns());
1924 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1933 public boolean isPadGaps()
1939 public void setPadGaps(boolean padGaps)
1941 this.padGaps = padGaps;
1945 * apply any post-edit constraints and trigger any calculations needed after
1946 * an edit has been performed on the alignment
1951 public void alignmentChanged(AlignmentViewPanel ap)
1955 alignment.padGaps();
1957 // if (autoCalculateConsensus)
1959 // updateConsensus(ap);
1961 // if (consensusProfiles != null && autoCalculateConsensus)
1963 // updateConservation(ap);
1965 // if (autoCalculateStrucConsensus)
1967 // updateStrucConsensus(ap);
1970 // updateInformation(ap);
1972 // Reset endRes of groups if beyond alignment width
1973 int alWidth = alignment.getWidth();
1974 List<SequenceGroup> groups = alignment.getGroups();
1977 for (SequenceGroup sg : groups)
1979 if (sg.getEndRes() > alWidth)
1981 sg.setEndRes(alWidth - 1);
1986 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1988 selectionGroup.setEndRes(alWidth - 1);
1991 updateAllColourSchemes();
1992 calculator.restartWorkers();
1996 * reset scope and do calculations for all applied colourschemes on alignment
1998 void updateAllColourSchemes()
2000 ResidueShaderI rs = residueShading;
2003 rs.alignmentChanged(alignment, hiddenRepSequences);
2005 rs.setConsensus(consensusProfiles);
2006 if (rs.conservationApplied())
2008 rs.setConservation(Conservation.calculateConservation("All",
2009 alignment.getSequences(), 0, alignment.getWidth(), false,
2010 getConsPercGaps(), false));
2014 for (SequenceGroup sg : alignment.getGroups())
2018 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2020 sg.recalcConservation();
2024 protected void initAutoAnnotation()
2026 // TODO: add menu option action that nulls or creates consensus object
2027 // depending on if the user wants to see the annotation or not in a
2028 // specific alignment
2030 if (consensusProfiles == null && !isDataset)
2032 if (!alignment.isNucleotide())
2041 consensus = new AlignmentAnnotation("Consensus",
2042 MessageManager.getString("label.consensus_descr"),
2043 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2044 initConsensus(consensus);
2048 initComplementConsensus();
2053 * If this is a protein alignment and there are mappings to cDNA, adds the
2054 * cDNA consensus annotation and returns true, else returns false.
2056 public boolean initComplementConsensus()
2058 if (!alignment.isNucleotide())
2060 final List<AlignedCodonFrame> codonMappings = alignment
2062 if (codonMappings != null && !codonMappings.isEmpty())
2064 boolean doConsensus = false;
2065 for (AlignedCodonFrame mapping : codonMappings)
2067 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2068 MapList[] mapLists = mapping.getdnaToProt();
2069 // mapLists can be empty if project load has not finished resolving
2071 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2079 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2081 .getString("label.complement_consensus_descr"),
2082 new Annotation[1], 0f, 100f,
2083 AlignmentAnnotation.BAR_GRAPH);
2084 initConsensus(complementConsensus);
2092 private void initConsensus(AlignmentAnnotation aa)
2095 aa.autoCalculated = true;
2099 alignment.addAnnotation(aa);
2103 // these should be extracted from the view model - style and settings for
2104 // derived annotation
2105 private void initOccupancy()
2109 occupancy = new AlignmentAnnotation("Occupancy",
2110 MessageManager.getString("label.occupancy_descr"),
2111 new Annotation[1], 0f, alignment.getHeight(),
2112 AlignmentAnnotation.BAR_GRAPH);
2113 occupancy.hasText = true;
2114 occupancy.autoCalculated = true;
2115 occupancy.scaleColLabel = true;
2116 occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
2118 alignment.addAnnotation(occupancy);
2122 private void initConservation()
2124 if (showConservation)
2126 if (conservation == null)
2128 conservation = new AlignmentAnnotation("Conservation",
2129 MessageManager.formatMessage("label.conservation_descr",
2131 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2132 conservation.hasText = true;
2133 conservation.autoCalculated = true;
2134 alignment.addAnnotation(conservation);
2139 private void initQuality()
2143 if (quality == null)
2145 quality = new AlignmentAnnotation("Quality",
2146 MessageManager.getString("label.quality_descr"),
2147 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2148 quality.hasText = true;
2149 quality.autoCalculated = true;
2150 alignment.addAnnotation(quality);
2155 private void initRNAStructure()
2157 if (alignment.hasRNAStructure() && strucConsensus == null)
2159 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2160 MessageManager.getString("label.strucconsensus_descr"),
2161 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2162 strucConsensus.hasText = true;
2163 strucConsensus.autoCalculated = true;
2167 alignment.addAnnotation(strucConsensus);
2175 * @see jalview.api.AlignViewportI#calcPanelHeight()
2178 public int calcPanelHeight()
2180 // setHeight of panels
2181 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2183 int charHeight = getCharHeight();
2186 BitSet graphgrp = new BitSet();
2187 for (AlignmentAnnotation aa : anns)
2191 System.err.println("Null annotation row: ignoring.");
2198 if (aa.graphGroup > -1)
2200 if (graphgrp.get(aa.graphGroup))
2206 graphgrp.set(aa.graphGroup);
2213 aa.height += charHeight;
2223 aa.height += aa.graphHeight;
2231 height += aa.height;
2243 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2244 boolean preserveNewGroupSettings)
2246 boolean updateCalcs = false;
2247 boolean conv = isShowGroupConservation();
2248 boolean cons = isShowGroupConsensus();
2249 boolean showprf = isShowSequenceLogo();
2250 boolean showConsHist = isShowConsensusHistogram();
2251 boolean normLogo = isNormaliseSequenceLogo();
2252 boolean showHMMPrf = isShowHMMSequenceLogo();
2253 boolean showInfoHist = isShowInformationHistogram();
2254 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2257 * TODO reorder the annotation rows according to group/sequence ordering on
2260 boolean sortg = true;
2262 // remove old automatic annotation
2263 // add any new annotation
2265 // intersect alignment annotation with alignment groups
2267 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2268 List<SequenceGroup> oldrfs = new ArrayList<>();
2271 for (int an = 0; an < aan.length; an++)
2273 if (aan[an].autoCalculated && aan[an].groupRef != null)
2275 oldrfs.add(aan[an].groupRef);
2276 alignment.deleteAnnotation(aan[an], false);
2280 if (alignment.getGroups() != null)
2282 for (SequenceGroup sg : alignment.getGroups())
2284 updateCalcs = false;
2285 if (applyGlobalSettings
2286 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2288 // set defaults for this group's conservation/consensus
2289 sg.setshowSequenceLogo(showprf);
2290 sg.setShowConsensusHistogram(showConsHist);
2291 sg.setNormaliseSequenceLogo(normLogo);
2292 sg.setshowHMMSequenceLogo(showHMMPrf);
2293 sg.setShowInformationHistogram(showInfoHist);
2294 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2299 alignment.addAnnotation(sg.getConservationRow(), 0);
2304 alignment.addAnnotation(sg.getConsensus(), 0);
2306 // refresh the annotation rows
2309 sg.recalcConservation();
2317 public boolean isDisplayReferenceSeq()
2319 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2323 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2325 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2329 public boolean isColourByReferenceSeq()
2331 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2335 public Color getSequenceColour(SequenceI seq)
2337 Color sqc = sequenceColours.get(seq);
2338 return (sqc == null ? Color.white : sqc);
2342 public void setSequenceColour(SequenceI seq, Color col)
2346 sequenceColours.remove(seq);
2350 sequenceColours.put(seq, col);
2355 public void updateSequenceIdColours()
2357 for (SequenceGroup sg : alignment.getGroups())
2359 if (sg.idColour != null)
2361 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2363 sequenceColours.put(s, sg.idColour);
2370 public void clearSequenceColours()
2372 sequenceColours.clear();
2376 public AlignViewportI getCodingComplement()
2378 return this.codingComplement;
2382 * Set this as the (cDna/protein) complement of the given viewport. Also
2383 * ensures the reverse relationship is set on the given viewport.
2386 public void setCodingComplement(AlignViewportI av)
2390 System.err.println("Ignoring recursive setCodingComplement request");
2394 this.codingComplement = av;
2395 // avoid infinite recursion!
2396 if (av.getCodingComplement() != this)
2398 av.setCodingComplement(this);
2404 public boolean isNucleotide()
2406 return getAlignment() == null ? false : getAlignment().isNucleotide();
2410 public FeaturesDisplayedI getFeaturesDisplayed()
2412 return featuresDisplayed;
2416 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2418 featuresDisplayed = featuresDisplayedI;
2422 public boolean areFeaturesDisplayed()
2424 return featuresDisplayed != null
2425 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2432 * features are displayed if true
2435 public void setShowSequenceFeatures(boolean b)
2437 viewStyle.setShowSequenceFeatures(b);
2441 public boolean isShowSequenceFeatures()
2443 return viewStyle.isShowSequenceFeatures();
2447 public void setShowSequenceFeaturesHeight(boolean selected)
2449 viewStyle.setShowSequenceFeaturesHeight(selected);
2453 public boolean isShowSequenceFeaturesHeight()
2455 return viewStyle.isShowSequenceFeaturesHeight();
2459 public void setShowAnnotation(boolean b)
2461 viewStyle.setShowAnnotation(b);
2465 public boolean isShowAnnotation()
2467 return viewStyle.isShowAnnotation();
2471 public boolean isRightAlignIds()
2473 return viewStyle.isRightAlignIds();
2477 public void setRightAlignIds(boolean rightAlignIds)
2479 viewStyle.setRightAlignIds(rightAlignIds);
2483 public boolean getConservationSelected()
2485 return viewStyle.getConservationSelected();
2489 public void setShowBoxes(boolean state)
2491 viewStyle.setShowBoxes(state);
2496 * @see jalview.api.ViewStyleI#getTextColour()
2499 public Color getTextColour()
2501 return viewStyle.getTextColour();
2506 * @see jalview.api.ViewStyleI#getTextColour2()
2509 public Color getTextColour2()
2511 return viewStyle.getTextColour2();
2516 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2519 public int getThresholdTextColour()
2521 return viewStyle.getThresholdTextColour();
2526 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2529 public boolean isConservationColourSelected()
2531 return viewStyle.isConservationColourSelected();
2536 * @see jalview.api.ViewStyleI#isRenderGaps()
2539 public boolean isRenderGaps()
2541 return viewStyle.isRenderGaps();
2546 * @see jalview.api.ViewStyleI#isShowColourText()
2549 public boolean isShowColourText()
2551 return viewStyle.isShowColourText();
2555 * @param conservationColourSelected
2556 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2559 public void setConservationColourSelected(
2560 boolean conservationColourSelected)
2562 viewStyle.setConservationColourSelected(conservationColourSelected);
2566 * @param showColourText
2567 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2570 public void setShowColourText(boolean showColourText)
2572 viewStyle.setShowColourText(showColourText);
2577 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2580 public void setTextColour(Color textColour)
2582 viewStyle.setTextColour(textColour);
2586 * @param thresholdTextColour
2587 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2590 public void setThresholdTextColour(int thresholdTextColour)
2592 viewStyle.setThresholdTextColour(thresholdTextColour);
2596 * @param textColour2
2597 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2600 public void setTextColour2(Color textColour2)
2602 viewStyle.setTextColour2(textColour2);
2606 public ViewStyleI getViewStyle()
2608 return new ViewStyle(viewStyle);
2612 public void setViewStyle(ViewStyleI settingsForView)
2614 viewStyle = new ViewStyle(settingsForView);
2615 if (residueShading != null)
2617 residueShading.setConservationApplied(
2618 settingsForView.isConservationColourSelected());
2623 public boolean sameStyle(ViewStyleI them)
2625 return viewStyle.sameStyle(them);
2630 * @see jalview.api.ViewStyleI#getIdWidth()
2633 public int getIdWidth()
2635 return viewStyle.getIdWidth();
2640 * @see jalview.api.ViewStyleI#setIdWidth(int)
2643 public void setIdWidth(int i)
2645 viewStyle.setIdWidth(i);
2650 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2653 public boolean isCentreColumnLabels()
2655 return viewStyle.isCentreColumnLabels();
2659 * @param centreColumnLabels
2660 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2663 public void setCentreColumnLabels(boolean centreColumnLabels)
2665 viewStyle.setCentreColumnLabels(centreColumnLabels);
2670 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2673 public void setShowDBRefs(boolean showdbrefs)
2675 viewStyle.setShowDBRefs(showdbrefs);
2680 * @see jalview.api.ViewStyleI#isShowDBRefs()
2683 public boolean isShowDBRefs()
2685 return viewStyle.isShowDBRefs();
2690 * @see jalview.api.ViewStyleI#isShowNPFeats()
2693 public boolean isShowNPFeats()
2695 return viewStyle.isShowNPFeats();
2699 * @param shownpfeats
2700 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2703 public void setShowNPFeats(boolean shownpfeats)
2705 viewStyle.setShowNPFeats(shownpfeats);
2708 public abstract StructureSelectionManager getStructureSelectionManager();
2711 * Add one command to the command history list.
2715 public void addToHistoryList(CommandI command)
2717 if (this.historyList != null)
2719 this.historyList.push(command);
2720 broadcastCommand(command, false);
2724 protected void broadcastCommand(CommandI command, boolean undo)
2726 getStructureSelectionManager().commandPerformed(command, undo,
2731 * Add one command to the command redo list.
2735 public void addToRedoList(CommandI command)
2737 if (this.redoList != null)
2739 this.redoList.push(command);
2741 broadcastCommand(command, true);
2745 * Clear the command redo list.
2747 public void clearRedoList()
2749 if (this.redoList != null)
2751 this.redoList.clear();
2755 public void setHistoryList(Deque<CommandI> list)
2757 this.historyList = list;
2760 public Deque<CommandI> getHistoryList()
2762 return this.historyList;
2765 public void setRedoList(Deque<CommandI> list)
2767 this.redoList = list;
2770 public Deque<CommandI> getRedoList()
2772 return this.redoList;
2776 public VamsasSource getVamsasSource()
2781 public SequenceAnnotationOrder getSortAnnotationsBy()
2783 return sortAnnotationsBy;
2786 public void setSortAnnotationsBy(
2787 SequenceAnnotationOrder sortAnnotationsBy)
2789 this.sortAnnotationsBy = sortAnnotationsBy;
2792 public boolean isShowAutocalculatedAbove()
2794 return showAutocalculatedAbove;
2797 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2799 this.showAutocalculatedAbove = showAutocalculatedAbove;
2803 public boolean isScaleProteinAsCdna()
2805 return viewStyle.isScaleProteinAsCdna();
2809 public void setScaleProteinAsCdna(boolean b)
2811 viewStyle.setScaleProteinAsCdna(b);
2815 public boolean isProteinFontAsCdna()
2817 return viewStyle.isProteinFontAsCdna();
2821 public void setProteinFontAsCdna(boolean b)
2823 viewStyle.setProteinFontAsCdna(b);
2827 * @return true if view should scroll to show the highlighted region of a
2832 public final boolean isFollowHighlight()
2834 return followHighlight;
2838 public final void setFollowHighlight(boolean b)
2840 this.followHighlight = b;
2844 public ViewportRanges getRanges()
2850 * Helper method to populate the SearchResults with the location in the
2851 * complementary alignment to scroll to, in order to match this one.
2854 * the SearchResults to add to
2855 * @return the offset (below top of visible region) of the matched sequence
2857 protected int findComplementScrollTarget(SearchResultsI sr)
2859 final AlignViewportI complement = getCodingComplement();
2860 if (complement == null || !complement.isFollowHighlight())
2864 boolean iAmProtein = !getAlignment().isNucleotide();
2865 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2866 : complement.getAlignment();
2867 if (proteinAlignment == null)
2871 final List<AlignedCodonFrame> mappings = proteinAlignment
2875 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2876 * residue in the middle column of the visible region. Scroll the
2877 * complementary alignment to line up the corresponding residue.
2880 SequenceI sequence = null;
2883 * locate 'middle' column (true middle if an odd number visible, left of
2884 * middle if an even number visible)
2886 int middleColumn = ranges.getStartRes()
2887 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2888 final HiddenSequences hiddenSequences = getAlignment()
2889 .getHiddenSequences();
2892 * searching to the bottom of the alignment gives smoother scrolling across
2893 * all gapped visible regions
2895 int lastSeq = alignment.getHeight() - 1;
2896 List<AlignedCodonFrame> seqMappings = null;
2897 for (int seqNo = ranges
2898 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2900 sequence = getAlignment().getSequenceAt(seqNo);
2901 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2905 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2909 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2911 getCodingComplement().getAlignment().getSequences());
2912 if (!seqMappings.isEmpty())
2918 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2921 * No ungapped mapped sequence in middle column - do nothing
2925 MappingUtils.addSearchResults(sr, sequence,
2926 sequence.findPosition(middleColumn), seqMappings);
2931 * synthesize a column selection if none exists so it covers the given
2932 * selection group. if wholewidth is false, no column selection is made if the
2933 * selection group covers the whole alignment width.
2938 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2941 if (sg != null && (sgs = sg.getStartRes()) >= 0
2942 && sg.getStartRes() <= (sge = sg.getEndRes())
2943 && !this.hasSelectedColumns())
2945 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2952 colSel = new ColumnSelection();
2954 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2956 colSel.addElement(cspos);
2962 * hold status of current selection group - defined on alignment or not.
2964 private boolean selectionIsDefinedGroup = false;
2967 public boolean isSelectionDefinedGroup()
2969 if (selectionGroup == null)
2973 if (isSelectionGroupChanged(true))
2975 selectionIsDefinedGroup = false;
2976 List<SequenceGroup> gps = alignment.getGroups();
2977 if (gps == null || gps.size() == 0)
2979 selectionIsDefinedGroup = false;
2983 selectionIsDefinedGroup = gps.contains(selectionGroup);
2986 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2990 * null, or currently highlighted results on this view
2992 private SearchResultsI searchResults = null;
2994 protected TreeModel currentTree = null;
2997 public boolean hasSearchResults()
2999 return searchResults != null;
3003 public void setSearchResults(SearchResultsI results)
3005 searchResults = results;
3009 public SearchResultsI getSearchResults()
3011 return searchResults;
3015 * get the consensus sequence as displayed under the PID consensus annotation
3018 * @return consensus sequence as a new sequence object
3020 public SequenceI getConsensusSeq()
3022 if (consensus == null)
3024 updateConsensus(null);
3026 if (consensus == null)
3030 StringBuffer seqs = new StringBuffer();
3031 for (int i = 0; i < consensus.annotations.length; i++)
3033 Annotation annotation = consensus.annotations[i];
3034 if (annotation != null)
3036 String description = annotation.description;
3037 if (description != null && description.startsWith("["))
3039 // consensus is a tie - just pick the first one
3040 seqs.append(description.charAt(1));
3044 seqs.append(annotation.displayCharacter);
3049 SequenceI sq = new Sequence("Consensus", seqs.toString());
3050 sq.setDescription("Percentage Identity Consensus "
3051 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3055 public boolean hasReferenceAnnotation()
3057 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3058 for (AlignmentAnnotation annot : annots)
3060 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3069 public void setCurrentTree(TreeModel tree)
3075 public TreeModel getCurrentTree()
3081 public boolean isNormaliseSequenceLogo()
3083 return normaliseSequenceLogo;
3086 public void setNormaliseSequenceLogo(boolean state)
3088 normaliseSequenceLogo = state;
3092 public boolean isNormaliseHMMSequenceLogo()
3094 return normaliseHMMSequenceLogo;
3097 public void setNormaliseHMMSequenceLogo(boolean state)
3099 normaliseHMMSequenceLogo = state;