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 * trigger update of information annotation
907 public void updateInformation(final AlignmentViewPanel ap)
910 .getRegisteredWorkersOfClass(InformationThread.class) == null)
912 calculator.registerWorker(new InformationThread(this, ap));
917 // --------START Structure Conservation
918 public void updateStrucConsensus(final AlignmentViewPanel ap)
920 if (autoCalculateStrucConsensus && strucConsensus == null
921 && alignment.isNucleotide() && alignment.hasRNAStructure())
923 // secondary structure has been added - so init the consensus line
927 // see note in mantis : issue number 8585
928 if (strucConsensus == null || !autoCalculateStrucConsensus)
932 if (calculator.getRegisteredWorkersOfClass(
933 StrucConsensusThread.class) == null)
935 calculator.registerWorker(new StrucConsensusThread(this, ap));
939 public boolean isCalcInProgress()
941 return calculator.isWorking();
945 public boolean isCalculationInProgress(
946 AlignmentAnnotation alignmentAnnotation)
948 if (!alignmentAnnotation.autoCalculated)
952 if (calculator.workingInvolvedWith(alignmentAnnotation))
954 // System.err.println("grey out ("+alignmentAnnotation.label+")");
960 public void setAlignment(AlignmentI align)
962 this.alignment = align;
966 * Clean up references when this viewport is closed
969 public void dispose()
972 * defensively null out references to large objects in case
973 * this object is not garbage collected (as if!)
976 complementConsensus = null;
977 strucConsensus = null;
980 consensusProfiles = null;
981 hconservation = null;
982 hcomplementConsensus = null;
985 residueShading = null; // may hold a reference to Consensus
986 changeSupport = null;
989 selectionGroup = null;
994 public boolean isClosed()
996 // TODO: check that this isClosed is only true after panel is closed, not
997 // before it is fully constructed.
998 return alignment == null;
1002 public AlignCalcManagerI getCalcManager()
1008 * should conservation rows be shown for groups
1010 protected boolean showGroupConservation = false;
1013 * should consensus rows be shown for groups
1015 protected boolean showGroupConsensus = false;
1018 * should consensus profile be rendered by default
1020 protected boolean showSequenceLogo = false;
1023 * should consensus profile be rendered normalised to row height
1025 protected boolean normaliseSequenceLogo = false;
1028 * should consensus histograms be rendered by default
1030 protected boolean showConsensusHistogram = true;
1033 * should hmm profile be rendered by default
1035 protected boolean showHMMSequenceLogo = false;
1038 * should hmm profile be rendered normalised to row height
1040 protected boolean normaliseHMMSequenceLogo = false;
1043 * should information histograms be rendered by default
1045 protected boolean showInformationHistogram = true;
1048 * @return the showConsensusProfile
1051 public boolean isShowSequenceLogo()
1053 return showSequenceLogo;
1057 * @return the showInformationProfile
1060 public boolean isShowHMMSequenceLogo()
1062 return showHMMSequenceLogo;
1066 * @param showSequenceLogo
1069 public void setShowSequenceLogo(boolean showSequenceLogo)
1071 if (showSequenceLogo != this.showSequenceLogo)
1073 // TODO: decouple settings setting from calculation when refactoring
1074 // annotation update method from alignframe to viewport
1075 this.showSequenceLogo = showSequenceLogo;
1076 calculator.updateAnnotationFor(ConsensusThread.class);
1077 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1078 calculator.updateAnnotationFor(StrucConsensusThread.class);
1080 this.showSequenceLogo = showSequenceLogo;
1083 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1085 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1087 this.showHMMSequenceLogo = showHMMSequenceLogo;
1088 calculator.updateAnnotationFor(InformationThread.class);
1090 this.showHMMSequenceLogo = showHMMSequenceLogo;
1094 * @param showConsensusHistogram
1095 * the showConsensusHistogram to set
1097 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1099 this.showConsensusHistogram = showConsensusHistogram;
1103 * @param showInformationHistogram
1104 * the showInformationHistogram to set
1106 public void setShowInformationHistogram(boolean showInformationHistogram)
1108 this.showInformationHistogram = showInformationHistogram;
1112 * @return the showGroupConservation
1114 public boolean isShowGroupConservation()
1116 return showGroupConservation;
1120 * @param showGroupConservation
1121 * the showGroupConservation to set
1123 public void setShowGroupConservation(boolean showGroupConservation)
1125 this.showGroupConservation = showGroupConservation;
1129 * @return the showGroupConsensus
1131 public boolean isShowGroupConsensus()
1133 return showGroupConsensus;
1137 * @param showGroupConsensus
1138 * the showGroupConsensus to set
1140 public void setShowGroupConsensus(boolean showGroupConsensus)
1142 this.showGroupConsensus = showGroupConsensus;
1147 * @return flag to indicate if the consensus histogram should be rendered by
1151 public boolean isShowConsensusHistogram()
1153 return this.showConsensusHistogram;
1158 * @return flag to indicate if the information content histogram should be
1159 * rendered by default
1162 public boolean isShowInformationHistogram()
1164 return this.showInformationHistogram;
1168 * when set, updateAlignment will always ensure sequences are of equal length
1170 private boolean padGaps = false;
1173 * when set, alignment should be reordered according to a newly opened tree
1175 public boolean sortByTree = false;
1180 * @return null or the currently selected sequence region
1183 public SequenceGroup getSelectionGroup()
1185 return selectionGroup;
1189 * Set the selection group for this window. Also sets the current alignment as
1190 * the context for the group, if it does not already have one.
1193 * - group holding references to sequences in this alignment view
1197 public void setSelectionGroup(SequenceGroup sg)
1199 selectionGroup = sg;
1200 if (sg != null && sg.getContext() == null)
1202 sg.setContext(alignment);
1206 public void setHiddenColumns(HiddenColumns hidden)
1208 this.alignment.setHiddenColumns(hidden);
1212 public ColumnSelection getColumnSelection()
1218 public void setColumnSelection(ColumnSelection colSel)
1220 this.colSel = colSel;
1223 updateHiddenColumns();
1225 isColSelChanged(true);
1233 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1235 return hiddenRepSequences;
1239 public void setHiddenRepSequences(
1240 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1242 this.hiddenRepSequences = hiddenRepSequences;
1246 public boolean hasSelectedColumns()
1248 ColumnSelection columnSelection = getColumnSelection();
1249 return columnSelection != null && columnSelection.hasSelectedColumns();
1253 public boolean hasHiddenColumns()
1255 return alignment.getHiddenColumns() != null
1256 && alignment.getHiddenColumns().hasHiddenColumns();
1259 public void updateHiddenColumns()
1261 // this method doesn't really do anything now. But - it could, since a
1262 // column Selection could be in the process of modification
1263 // hasHiddenColumns = colSel.hasHiddenColumns();
1267 public boolean hasHiddenRows()
1269 return alignment.getHiddenSequences().getSize() > 0;
1272 protected SequenceGroup selectionGroup;
1274 public void setSequenceSetId(String newid)
1276 if (sequenceSetID != null)
1279 "Warning - overwriting a sequenceSetId for a viewport!");
1281 sequenceSetID = new String(newid);
1285 public String getSequenceSetId()
1287 if (sequenceSetID == null)
1289 sequenceSetID = alignment.hashCode() + "";
1292 return sequenceSetID;
1296 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1299 protected String viewId = null;
1302 public String getViewId()
1306 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1311 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1313 ignoreGapsInConsensusCalculation = b;
1316 updateConsensus(ap);
1317 if (residueShading != null)
1319 residueShading.setThreshold(residueShading.getThreshold(),
1320 ignoreGapsInConsensusCalculation);
1325 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1327 boolean was = ignoreBelowBackGroundFrequencyCalculation;
1328 ignoreBelowBackGroundFrequencyCalculation = b;
1329 if (ap != null && was != b)
1331 updateInformation(ap);
1335 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1337 boolean was = infoLetterHeight;
1338 infoLetterHeight = b;
1339 if (ap != null && was != b)
1341 updateInformation(ap);
1345 private long sgrouphash = -1, colselhash = -1;
1348 * checks current SelectionGroup against record of last hash value, and
1352 * update the record of last hash value
1354 * @return true if SelectionGroup changed since last call (when b is true)
1356 public boolean isSelectionGroupChanged(boolean b)
1358 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1359 : selectionGroup.hashCode();
1360 if (hc != -1 && hc != sgrouphash)
1372 * checks current colsel against record of last hash value, and optionally
1376 * update the record of last hash value
1377 * @return true if colsel changed since last call (when b is true)
1379 public boolean isColSelChanged(boolean b)
1381 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1382 if (hc != -1 && hc != colselhash)
1394 public boolean isIgnoreGapsConsensus()
1396 return ignoreGapsInConsensusCalculation;
1400 public boolean isIgnoreBelowBackground()
1402 return ignoreBelowBackGroundFrequencyCalculation;
1406 public boolean isInfoLetterHeight()
1408 return infoLetterHeight;
1411 // property change stuff
1412 // JBPNote Prolly only need this in the applet version.
1413 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1416 protected boolean showConservation = true;
1418 protected boolean showQuality = true;
1420 protected boolean showConsensus = true;
1422 protected boolean showOccupancy = true;
1424 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1426 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1428 protected boolean showAutocalculatedAbove;
1431 * when set, view will scroll to show the highlighted position
1433 private boolean followHighlight = true;
1436 * Property change listener for changes in alignment
1441 public void addPropertyChangeListener(
1442 java.beans.PropertyChangeListener listener)
1444 changeSupport.addPropertyChangeListener(listener);
1453 public void removePropertyChangeListener(
1454 java.beans.PropertyChangeListener listener)
1456 if (changeSupport != null)
1458 changeSupport.removePropertyChangeListener(listener);
1463 * Property change listener for changes in alignment
1472 public void firePropertyChange(String prop, Object oldvalue,
1475 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1478 // common hide/show column stuff
1480 public void hideSelectedColumns()
1482 if (colSel.isEmpty())
1487 colSel.hideSelectedColumns(alignment);
1488 setSelectionGroup(null);
1489 isColSelChanged(true);
1492 public void hideColumns(int start, int end)
1496 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1500 alignment.getHiddenColumns().hideColumns(start, end);
1502 isColSelChanged(true);
1505 public void showColumn(int col)
1507 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1508 isColSelChanged(true);
1511 public void showAllHiddenColumns()
1513 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1514 isColSelChanged(true);
1517 // common hide/show seq stuff
1518 public void showAllHiddenSeqs()
1520 int startSeq = ranges.getStartSeq();
1521 int endSeq = ranges.getEndSeq();
1523 if (alignment.getHiddenSequences().getSize() > 0)
1525 if (selectionGroup == null)
1527 selectionGroup = new SequenceGroup();
1528 selectionGroup.setEndRes(alignment.getWidth() - 1);
1530 List<SequenceI> tmp = alignment.getHiddenSequences()
1531 .showAll(hiddenRepSequences);
1532 for (SequenceI seq : tmp)
1534 selectionGroup.addSequence(seq, false);
1535 setSequenceAnnotationsVisible(seq, true);
1538 hiddenRepSequences = null;
1540 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1542 firePropertyChange("alignment", null, alignment.getSequences());
1543 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1549 public void showSequence(int index)
1551 int startSeq = ranges.getStartSeq();
1552 int endSeq = ranges.getEndSeq();
1554 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1555 hiddenRepSequences);
1558 if (selectionGroup == null)
1560 selectionGroup = new SequenceGroup();
1561 selectionGroup.setEndRes(alignment.getWidth() - 1);
1564 for (SequenceI seq : tmp)
1566 selectionGroup.addSequence(seq, false);
1567 setSequenceAnnotationsVisible(seq, true);
1570 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1572 firePropertyChange("alignment", null, alignment.getSequences());
1577 public void hideAllSelectedSeqs()
1579 if (selectionGroup == null || selectionGroup.getSize() < 1)
1584 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1588 setSelectionGroup(null);
1591 public void hideSequence(SequenceI[] seq)
1594 * cache offset to first visible sequence
1596 int startSeq = ranges.getStartSeq();
1600 for (int i = 0; i < seq.length; i++)
1602 alignment.getHiddenSequences().hideSequence(seq[i]);
1603 setSequenceAnnotationsVisible(seq[i], false);
1605 ranges.setStartSeq(startSeq);
1606 firePropertyChange("alignment", null, alignment.getSequences());
1611 * Hides the specified sequence, or the sequences it represents
1614 * the sequence to hide, or keep as representative
1615 * @param representGroup
1616 * if true, hide the current selection group except for the
1617 * representative sequence
1619 public void hideSequences(SequenceI sequence, boolean representGroup)
1621 if (selectionGroup == null || selectionGroup.getSize() < 1)
1623 hideSequence(new SequenceI[] { sequence });
1629 hideRepSequences(sequence, selectionGroup);
1630 setSelectionGroup(null);
1634 int gsize = selectionGroup.getSize();
1635 SequenceI[] hseqs = selectionGroup.getSequences()
1636 .toArray(new SequenceI[gsize]);
1638 hideSequence(hseqs);
1639 setSelectionGroup(null);
1644 * Set visibility for any annotations for the given sequence.
1648 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1651 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1654 for (AlignmentAnnotation ann : anns)
1656 if (ann.sequenceRef == sequenceI)
1658 ann.visible = visible;
1664 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1666 int sSize = sg.getSize();
1672 if (hiddenRepSequences == null)
1674 hiddenRepSequences = new Hashtable<>();
1677 hiddenRepSequences.put(repSequence, sg);
1679 // Hide all sequences except the repSequence
1680 SequenceI[] seqs = new SequenceI[sSize - 1];
1682 for (int i = 0; i < sSize; i++)
1684 if (sg.getSequenceAt(i) != repSequence)
1686 if (index == sSize - 1)
1691 seqs[index++] = sg.getSequenceAt(i);
1694 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1695 sg.setHidereps(true); // note: not done in 2.7applet
1702 * @return null or the current reference sequence
1704 public SequenceI getReferenceSeq()
1706 return alignment.getSeqrep();
1711 * @return true iff seq is the reference for the alignment
1713 public boolean isReferenceSeq(SequenceI seq)
1715 return alignment.getSeqrep() == seq;
1721 * @return true if there are sequences represented by this sequence that are
1724 public boolean isHiddenRepSequence(SequenceI seq)
1726 return (hiddenRepSequences != null
1727 && hiddenRepSequences.containsKey(seq));
1733 * @return null or a sequence group containing the sequences that seq
1736 public SequenceGroup getRepresentedSequences(SequenceI seq)
1738 return (SequenceGroup) (hiddenRepSequences == null ? null
1739 : hiddenRepSequences.get(seq));
1743 public int adjustForHiddenSeqs(int alignmentIndex)
1745 return alignment.getHiddenSequences()
1746 .adjustForHiddenSeqs(alignmentIndex);
1750 public void invertColumnSelection()
1752 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1756 public SequenceI[] getSelectionAsNewSequence()
1758 SequenceI[] sequences;
1759 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1760 // this was the only caller in the applet for this method
1761 // JBPNote: in applet, this method returned references to the alignment
1762 // sequences, and it did not honour the presence/absence of annotation
1763 // attached to the alignment (probably!)
1764 if (selectionGroup == null || selectionGroup.getSize() == 0)
1766 sequences = alignment.getSequencesArray();
1767 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1768 for (int i = 0; i < sequences.length; i++)
1770 // construct new sequence with subset of visible annotation
1771 sequences[i] = new Sequence(sequences[i], annots);
1776 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1783 public SequenceI[] getSequenceSelection()
1785 SequenceI[] sequences = null;
1786 if (selectionGroup != null)
1788 sequences = selectionGroup.getSequencesInOrder(alignment);
1790 if (sequences == null)
1792 sequences = alignment.getSequencesArray();
1798 public jalview.datamodel.AlignmentView getAlignmentView(
1799 boolean selectedOnly)
1801 return getAlignmentView(selectedOnly, false);
1805 public jalview.datamodel.AlignmentView getAlignmentView(
1806 boolean selectedOnly, boolean markGroups)
1808 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1810 alignment.getHiddenColumns() != null
1811 && alignment.getHiddenColumns().hasHiddenColumns(),
1812 selectedOnly, markGroups);
1816 public String[] getViewAsString(boolean selectedRegionOnly)
1818 return getViewAsString(selectedRegionOnly, true);
1822 public String[] getViewAsString(boolean selectedRegionOnly,
1823 boolean exportHiddenSeqs)
1825 String[] selection = null;
1826 SequenceI[] seqs = null;
1828 int start = 0, end = 0;
1829 if (selectedRegionOnly && selectionGroup != null)
1831 iSize = selectionGroup.getSize();
1832 seqs = selectionGroup.getSequencesInOrder(alignment);
1833 start = selectionGroup.getStartRes();
1834 end = selectionGroup.getEndRes() + 1;
1838 if (hasHiddenRows() && exportHiddenSeqs)
1840 AlignmentI fullAlignment = alignment.getHiddenSequences()
1841 .getFullAlignment();
1842 iSize = fullAlignment.getHeight();
1843 seqs = fullAlignment.getSequencesArray();
1844 end = fullAlignment.getWidth();
1848 iSize = alignment.getHeight();
1849 seqs = alignment.getSequencesArray();
1850 end = alignment.getWidth();
1854 selection = new String[iSize];
1855 if (alignment.getHiddenColumns() != null
1856 && alignment.getHiddenColumns().hasHiddenColumns())
1858 for (i = 0; i < iSize; i++)
1860 Iterator<int[]> blocks = alignment.getHiddenColumns()
1861 .getVisContigsIterator(start, end + 1, false);
1862 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1867 for (i = 0; i < iSize; i++)
1869 selection[i] = seqs[i].getSequenceAsString(start, end);
1877 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1879 ArrayList<int[]> regions = new ArrayList<>();
1885 HiddenColumns hidden = alignment.getHiddenColumns();
1886 if (hidden != null && hidden.hasHiddenColumns())
1890 start = hidden.visibleToAbsoluteColumn(start);
1893 end = hidden.getNextHiddenBoundary(false, start);
1904 regions.add(new int[] { start, end });
1906 if (hidden != null && hidden.hasHiddenColumns())
1908 start = hidden.visibleToAbsoluteColumn(end);
1909 start = hidden.getNextHiddenBoundary(true, start) + 1;
1911 } while (end < max);
1913 int[][] startEnd = new int[regions.size()][2];
1919 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1920 boolean selectedOnly)
1922 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1923 AlignmentAnnotation[] aa;
1924 if ((aa = alignment.getAlignmentAnnotation()) != null)
1926 for (AlignmentAnnotation annot : aa)
1928 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1929 if (selectedOnly && selectionGroup != null)
1931 clone.makeVisibleAnnotation(
1932 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1933 alignment.getHiddenColumns());
1937 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1946 public boolean isPadGaps()
1952 public void setPadGaps(boolean padGaps)
1954 this.padGaps = padGaps;
1958 * apply any post-edit constraints and trigger any calculations needed after
1959 * an edit has been performed on the alignment
1964 public void alignmentChanged(AlignmentViewPanel ap)
1968 alignment.padGaps();
1970 if (autoCalculateConsensus)
1972 updateConsensus(ap);
1974 if (consensusProfiles != null && autoCalculateConsensus)
1976 updateConservation(ap);
1978 if (autoCalculateStrucConsensus)
1980 updateStrucConsensus(ap);
1982 // initInformation();
1983 updateInformation(ap);
1985 // Reset endRes of groups if beyond alignment width
1986 int alWidth = alignment.getWidth();
1987 List<SequenceGroup> groups = alignment.getGroups();
1990 for (SequenceGroup sg : groups)
1992 if (sg.getEndRes() > alWidth)
1994 sg.setEndRes(alWidth - 1);
1999 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2001 selectionGroup.setEndRes(alWidth - 1);
2004 updateAllColourSchemes();
2005 calculator.restartWorkers();
2006 // alignment.adjustSequenceAnnotations();
2010 * reset scope and do calculations for all applied colourschemes on alignment
2012 void updateAllColourSchemes()
2014 ResidueShaderI rs = residueShading;
2017 rs.alignmentChanged(alignment, hiddenRepSequences);
2019 rs.setConsensus(consensusProfiles);
2020 if (rs.conservationApplied())
2022 rs.setConservation(Conservation.calculateConservation("All",
2023 alignment.getSequences(), 0, alignment.getWidth(), false,
2024 getConsPercGaps(), false));
2028 for (SequenceGroup sg : alignment.getGroups())
2032 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2034 sg.recalcConservation();
2038 protected void initAutoAnnotation()
2040 // TODO: add menu option action that nulls or creates consensus object
2041 // depending on if the user wants to see the annotation or not in a
2042 // specific alignment
2044 if (consensusProfiles == null && !isDataset)
2046 if (!alignment.isNucleotide())
2055 consensus = new AlignmentAnnotation("Consensus",
2056 MessageManager.getString("label.consensus_descr"),
2057 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2058 initConsensus(consensus);
2062 initComplementConsensus();
2067 * If this is a protein alignment and there are mappings to cDNA, adds the
2068 * cDNA consensus annotation and returns true, else returns false.
2070 public boolean initComplementConsensus()
2072 if (!alignment.isNucleotide())
2074 final List<AlignedCodonFrame> codonMappings = alignment
2076 if (codonMappings != null && !codonMappings.isEmpty())
2078 boolean doConsensus = false;
2079 for (AlignedCodonFrame mapping : codonMappings)
2081 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2082 MapList[] mapLists = mapping.getdnaToProt();
2083 // mapLists can be empty if project load has not finished resolving
2085 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2093 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2095 .getString("label.complement_consensus_descr"),
2096 new Annotation[1], 0f, 100f,
2097 AlignmentAnnotation.BAR_GRAPH);
2098 initConsensus(complementConsensus);
2106 private void initConsensus(AlignmentAnnotation aa)
2109 aa.autoCalculated = true;
2113 alignment.addAnnotation(aa);
2117 // these should be extracted from the view model - style and settings for
2118 // derived annotation
2119 private void initOccupancy()
2123 occupancy = new AlignmentAnnotation("Occupancy",
2124 MessageManager.getString("label.occupancy_descr"),
2125 new Annotation[1], 0f, alignment.getHeight(),
2126 AlignmentAnnotation.BAR_GRAPH);
2127 occupancy.hasText = true;
2128 occupancy.autoCalculated = true;
2129 occupancy.scaleColLabel = true;
2130 occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
2132 alignment.addAnnotation(occupancy);
2136 private void initConservation()
2138 if (showConservation)
2140 if (conservation == null)
2142 conservation = new AlignmentAnnotation("Conservation",
2143 MessageManager.formatMessage("label.conservation_descr",
2145 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2146 conservation.hasText = true;
2147 conservation.autoCalculated = true;
2148 alignment.addAnnotation(conservation);
2153 private void initQuality()
2157 if (quality == null)
2159 quality = new AlignmentAnnotation("Quality",
2160 MessageManager.getString("label.quality_descr"),
2161 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2162 quality.hasText = true;
2163 quality.autoCalculated = true;
2164 alignment.addAnnotation(quality);
2169 private void initRNAStructure()
2171 if (alignment.hasRNAStructure() && strucConsensus == null)
2173 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2174 MessageManager.getString("label.strucconsensus_descr"),
2175 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2176 strucConsensus.hasText = true;
2177 strucConsensus.autoCalculated = true;
2181 alignment.addAnnotation(strucConsensus);
2189 * @see jalview.api.AlignViewportI#calcPanelHeight()
2192 public int calcPanelHeight()
2194 // setHeight of panels
2195 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2197 int charHeight = getCharHeight();
2200 BitSet graphgrp = new BitSet();
2201 for (AlignmentAnnotation aa : anns)
2205 System.err.println("Null annotation row: ignoring.");
2212 if (aa.graphGroup > -1)
2214 if (graphgrp.get(aa.graphGroup))
2220 graphgrp.set(aa.graphGroup);
2227 aa.height += charHeight;
2237 aa.height += aa.graphHeight;
2245 height += aa.height;
2257 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2258 boolean preserveNewGroupSettings)
2260 boolean updateCalcs = false;
2261 boolean conv = isShowGroupConservation();
2262 boolean cons = isShowGroupConsensus();
2263 boolean showprf = isShowSequenceLogo();
2264 boolean showConsHist = isShowConsensusHistogram();
2265 boolean normLogo = isNormaliseSequenceLogo();
2266 boolean showHMMPrf = isShowHMMSequenceLogo();
2267 boolean showInfoHist = isShowInformationHistogram();
2268 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2271 * TODO reorder the annotation rows according to group/sequence ordering on
2274 boolean sortg = true;
2276 // remove old automatic annotation
2277 // add any new annotation
2279 // intersect alignment annotation with alignment groups
2281 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2282 List<SequenceGroup> oldrfs = new ArrayList<>();
2285 for (int an = 0; an < aan.length; an++)
2287 if (aan[an].autoCalculated && aan[an].groupRef != null)
2289 oldrfs.add(aan[an].groupRef);
2290 alignment.deleteAnnotation(aan[an], false);
2294 if (alignment.getGroups() != null)
2296 for (SequenceGroup sg : alignment.getGroups())
2298 updateCalcs = false;
2299 if (applyGlobalSettings
2300 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2302 // set defaults for this group's conservation/consensus
2303 sg.setshowSequenceLogo(showprf);
2304 sg.setShowConsensusHistogram(showConsHist);
2305 sg.setNormaliseSequenceLogo(normLogo);
2306 sg.setshowHMMSequenceLogo(showHMMPrf);
2307 sg.setShowInformationHistogram(showInfoHist);
2308 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2313 alignment.addAnnotation(sg.getConservationRow(), 0);
2318 alignment.addAnnotation(sg.getConsensus(), 0);
2320 // refresh the annotation rows
2323 sg.recalcConservation();
2331 public boolean isDisplayReferenceSeq()
2333 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2337 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2339 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2343 public boolean isColourByReferenceSeq()
2345 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2349 public Color getSequenceColour(SequenceI seq)
2351 Color sqc = sequenceColours.get(seq);
2352 return (sqc == null ? Color.white : sqc);
2356 public void setSequenceColour(SequenceI seq, Color col)
2360 sequenceColours.remove(seq);
2364 sequenceColours.put(seq, col);
2369 public void updateSequenceIdColours()
2371 for (SequenceGroup sg : alignment.getGroups())
2373 if (sg.idColour != null)
2375 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2377 sequenceColours.put(s, sg.idColour);
2384 public void clearSequenceColours()
2386 sequenceColours.clear();
2390 public AlignViewportI getCodingComplement()
2392 return this.codingComplement;
2396 * Set this as the (cDna/protein) complement of the given viewport. Also
2397 * ensures the reverse relationship is set on the given viewport.
2400 public void setCodingComplement(AlignViewportI av)
2404 System.err.println("Ignoring recursive setCodingComplement request");
2408 this.codingComplement = av;
2409 // avoid infinite recursion!
2410 if (av.getCodingComplement() != this)
2412 av.setCodingComplement(this);
2418 public boolean isNucleotide()
2420 return getAlignment() == null ? false : getAlignment().isNucleotide();
2424 public FeaturesDisplayedI getFeaturesDisplayed()
2426 return featuresDisplayed;
2430 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2432 featuresDisplayed = featuresDisplayedI;
2436 public boolean areFeaturesDisplayed()
2438 return featuresDisplayed != null
2439 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2446 * features are displayed if true
2449 public void setShowSequenceFeatures(boolean b)
2451 viewStyle.setShowSequenceFeatures(b);
2455 public boolean isShowSequenceFeatures()
2457 return viewStyle.isShowSequenceFeatures();
2461 public void setShowSequenceFeaturesHeight(boolean selected)
2463 viewStyle.setShowSequenceFeaturesHeight(selected);
2467 public boolean isShowSequenceFeaturesHeight()
2469 return viewStyle.isShowSequenceFeaturesHeight();
2473 public void setShowAnnotation(boolean b)
2475 viewStyle.setShowAnnotation(b);
2479 public boolean isShowAnnotation()
2481 return viewStyle.isShowAnnotation();
2485 public boolean isRightAlignIds()
2487 return viewStyle.isRightAlignIds();
2491 public void setRightAlignIds(boolean rightAlignIds)
2493 viewStyle.setRightAlignIds(rightAlignIds);
2497 public boolean getConservationSelected()
2499 return viewStyle.getConservationSelected();
2503 public void setShowBoxes(boolean state)
2505 viewStyle.setShowBoxes(state);
2510 * @see jalview.api.ViewStyleI#getTextColour()
2513 public Color getTextColour()
2515 return viewStyle.getTextColour();
2520 * @see jalview.api.ViewStyleI#getTextColour2()
2523 public Color getTextColour2()
2525 return viewStyle.getTextColour2();
2530 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2533 public int getThresholdTextColour()
2535 return viewStyle.getThresholdTextColour();
2540 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2543 public boolean isConservationColourSelected()
2545 return viewStyle.isConservationColourSelected();
2550 * @see jalview.api.ViewStyleI#isRenderGaps()
2553 public boolean isRenderGaps()
2555 return viewStyle.isRenderGaps();
2560 * @see jalview.api.ViewStyleI#isShowColourText()
2563 public boolean isShowColourText()
2565 return viewStyle.isShowColourText();
2569 * @param conservationColourSelected
2570 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2573 public void setConservationColourSelected(
2574 boolean conservationColourSelected)
2576 viewStyle.setConservationColourSelected(conservationColourSelected);
2580 * @param showColourText
2581 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2584 public void setShowColourText(boolean showColourText)
2586 viewStyle.setShowColourText(showColourText);
2591 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2594 public void setTextColour(Color textColour)
2596 viewStyle.setTextColour(textColour);
2600 * @param thresholdTextColour
2601 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2604 public void setThresholdTextColour(int thresholdTextColour)
2606 viewStyle.setThresholdTextColour(thresholdTextColour);
2610 * @param textColour2
2611 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2614 public void setTextColour2(Color textColour2)
2616 viewStyle.setTextColour2(textColour2);
2620 public ViewStyleI getViewStyle()
2622 return new ViewStyle(viewStyle);
2626 public void setViewStyle(ViewStyleI settingsForView)
2628 viewStyle = new ViewStyle(settingsForView);
2629 if (residueShading != null)
2631 residueShading.setConservationApplied(
2632 settingsForView.isConservationColourSelected());
2637 public boolean sameStyle(ViewStyleI them)
2639 return viewStyle.sameStyle(them);
2644 * @see jalview.api.ViewStyleI#getIdWidth()
2647 public int getIdWidth()
2649 return viewStyle.getIdWidth();
2654 * @see jalview.api.ViewStyleI#setIdWidth(int)
2657 public void setIdWidth(int i)
2659 viewStyle.setIdWidth(i);
2664 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2667 public boolean isCentreColumnLabels()
2669 return viewStyle.isCentreColumnLabels();
2673 * @param centreColumnLabels
2674 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2677 public void setCentreColumnLabels(boolean centreColumnLabels)
2679 viewStyle.setCentreColumnLabels(centreColumnLabels);
2684 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2687 public void setShowDBRefs(boolean showdbrefs)
2689 viewStyle.setShowDBRefs(showdbrefs);
2694 * @see jalview.api.ViewStyleI#isShowDBRefs()
2697 public boolean isShowDBRefs()
2699 return viewStyle.isShowDBRefs();
2704 * @see jalview.api.ViewStyleI#isShowNPFeats()
2707 public boolean isShowNPFeats()
2709 return viewStyle.isShowNPFeats();
2713 * @param shownpfeats
2714 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2717 public void setShowNPFeats(boolean shownpfeats)
2719 viewStyle.setShowNPFeats(shownpfeats);
2722 public abstract StructureSelectionManager getStructureSelectionManager();
2725 * Add one command to the command history list.
2729 public void addToHistoryList(CommandI command)
2731 if (this.historyList != null)
2733 this.historyList.push(command);
2734 broadcastCommand(command, false);
2738 protected void broadcastCommand(CommandI command, boolean undo)
2740 getStructureSelectionManager().commandPerformed(command, undo,
2745 * Add one command to the command redo list.
2749 public void addToRedoList(CommandI command)
2751 if (this.redoList != null)
2753 this.redoList.push(command);
2755 broadcastCommand(command, true);
2759 * Clear the command redo list.
2761 public void clearRedoList()
2763 if (this.redoList != null)
2765 this.redoList.clear();
2769 public void setHistoryList(Deque<CommandI> list)
2771 this.historyList = list;
2774 public Deque<CommandI> getHistoryList()
2776 return this.historyList;
2779 public void setRedoList(Deque<CommandI> list)
2781 this.redoList = list;
2784 public Deque<CommandI> getRedoList()
2786 return this.redoList;
2790 public VamsasSource getVamsasSource()
2795 public SequenceAnnotationOrder getSortAnnotationsBy()
2797 return sortAnnotationsBy;
2800 public void setSortAnnotationsBy(
2801 SequenceAnnotationOrder sortAnnotationsBy)
2803 this.sortAnnotationsBy = sortAnnotationsBy;
2806 public boolean isShowAutocalculatedAbove()
2808 return showAutocalculatedAbove;
2811 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2813 this.showAutocalculatedAbove = showAutocalculatedAbove;
2817 public boolean isScaleProteinAsCdna()
2819 return viewStyle.isScaleProteinAsCdna();
2823 public void setScaleProteinAsCdna(boolean b)
2825 viewStyle.setScaleProteinAsCdna(b);
2829 public boolean isProteinFontAsCdna()
2831 return viewStyle.isProteinFontAsCdna();
2835 public void setProteinFontAsCdna(boolean b)
2837 viewStyle.setProteinFontAsCdna(b);
2841 * @return true if view should scroll to show the highlighted region of a
2846 public final boolean isFollowHighlight()
2848 return followHighlight;
2852 public final void setFollowHighlight(boolean b)
2854 this.followHighlight = b;
2858 public ViewportRanges getRanges()
2864 * Helper method to populate the SearchResults with the location in the
2865 * complementary alignment to scroll to, in order to match this one.
2868 * the SearchResults to add to
2869 * @return the offset (below top of visible region) of the matched sequence
2871 protected int findComplementScrollTarget(SearchResultsI sr)
2873 final AlignViewportI complement = getCodingComplement();
2874 if (complement == null || !complement.isFollowHighlight())
2878 boolean iAmProtein = !getAlignment().isNucleotide();
2879 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2880 : complement.getAlignment();
2881 if (proteinAlignment == null)
2885 final List<AlignedCodonFrame> mappings = proteinAlignment
2889 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2890 * residue in the middle column of the visible region. Scroll the
2891 * complementary alignment to line up the corresponding residue.
2894 SequenceI sequence = null;
2897 * locate 'middle' column (true middle if an odd number visible, left of
2898 * middle if an even number visible)
2900 int middleColumn = ranges.getStartRes()
2901 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2902 final HiddenSequences hiddenSequences = getAlignment()
2903 .getHiddenSequences();
2906 * searching to the bottom of the alignment gives smoother scrolling across
2907 * all gapped visible regions
2909 int lastSeq = alignment.getHeight() - 1;
2910 List<AlignedCodonFrame> seqMappings = null;
2911 for (int seqNo = ranges
2912 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2914 sequence = getAlignment().getSequenceAt(seqNo);
2915 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2919 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2923 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2925 getCodingComplement().getAlignment().getSequences());
2926 if (!seqMappings.isEmpty())
2932 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2935 * No ungapped mapped sequence in middle column - do nothing
2939 MappingUtils.addSearchResults(sr, sequence,
2940 sequence.findPosition(middleColumn), seqMappings);
2945 * synthesize a column selection if none exists so it covers the given
2946 * selection group. if wholewidth is false, no column selection is made if the
2947 * selection group covers the whole alignment width.
2952 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2955 if (sg != null && (sgs = sg.getStartRes()) >= 0
2956 && sg.getStartRes() <= (sge = sg.getEndRes())
2957 && !this.hasSelectedColumns())
2959 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2966 colSel = new ColumnSelection();
2968 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2970 colSel.addElement(cspos);
2976 * hold status of current selection group - defined on alignment or not.
2978 private boolean selectionIsDefinedGroup = false;
2981 public boolean isSelectionDefinedGroup()
2983 if (selectionGroup == null)
2987 if (isSelectionGroupChanged(true))
2989 selectionIsDefinedGroup = false;
2990 List<SequenceGroup> gps = alignment.getGroups();
2991 if (gps == null || gps.size() == 0)
2993 selectionIsDefinedGroup = false;
2997 selectionIsDefinedGroup = gps.contains(selectionGroup);
3000 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3004 * null, or currently highlighted results on this view
3006 private SearchResultsI searchResults = null;
3008 protected TreeModel currentTree = null;
3011 public boolean hasSearchResults()
3013 return searchResults != null;
3017 public void setSearchResults(SearchResultsI results)
3019 searchResults = results;
3023 public SearchResultsI getSearchResults()
3025 return searchResults;
3029 * get the consensus sequence as displayed under the PID consensus annotation
3032 * @return consensus sequence as a new sequence object
3034 public SequenceI getConsensusSeq()
3036 if (consensus == null)
3038 updateConsensus(null);
3040 if (consensus == null)
3044 StringBuffer seqs = new StringBuffer();
3045 for (int i = 0; i < consensus.annotations.length; i++)
3047 Annotation annotation = consensus.annotations[i];
3048 if (annotation != null)
3050 String description = annotation.description;
3051 if (description != null && description.startsWith("["))
3053 // consensus is a tie - just pick the first one
3054 seqs.append(description.charAt(1));
3058 seqs.append(annotation.displayCharacter);
3063 SequenceI sq = new Sequence("Consensus", seqs.toString());
3064 sq.setDescription("Percentage Identity Consensus "
3065 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3069 public boolean hasReferenceAnnotation()
3071 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3072 for (AlignmentAnnotation annot : annots)
3074 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3083 public void setCurrentTree(TreeModel tree)
3089 public TreeModel getCurrentTree()