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 calculator.updateAnnotationFor(InformationThread.class);
1086 this.showHMMSequenceLogo = showHMMSequenceLogo;
1090 * @param showConsensusHistogram
1091 * the showConsensusHistogram to set
1093 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1095 this.showConsensusHistogram = showConsensusHistogram;
1099 * @param showInformationHistogram
1100 * the showInformationHistogram to set
1102 public void setShowInformationHistogram(boolean showInformationHistogram)
1104 this.showInformationHistogram = showInformationHistogram;
1108 * @return the showGroupConservation
1110 public boolean isShowGroupConservation()
1112 return showGroupConservation;
1116 * @param showGroupConservation
1117 * the showGroupConservation to set
1119 public void setShowGroupConservation(boolean showGroupConservation)
1121 this.showGroupConservation = showGroupConservation;
1125 * @return the showGroupConsensus
1127 public boolean isShowGroupConsensus()
1129 return showGroupConsensus;
1133 * @param showGroupConsensus
1134 * the showGroupConsensus to set
1136 public void setShowGroupConsensus(boolean showGroupConsensus)
1138 this.showGroupConsensus = showGroupConsensus;
1143 * @return flag to indicate if the consensus histogram should be rendered by
1147 public boolean isShowConsensusHistogram()
1149 return this.showConsensusHistogram;
1154 * @return flag to indicate if the information content histogram should be
1155 * rendered by default
1158 public boolean isShowInformationHistogram()
1160 return this.showInformationHistogram;
1164 * when set, updateAlignment will always ensure sequences are of equal length
1166 private boolean padGaps = false;
1169 * when set, alignment should be reordered according to a newly opened tree
1171 public boolean sortByTree = false;
1176 * @return null or the currently selected sequence region
1179 public SequenceGroup getSelectionGroup()
1181 return selectionGroup;
1185 * Set the selection group for this window. Also sets the current alignment as
1186 * the context for the group, if it does not already have one.
1189 * - group holding references to sequences in this alignment view
1193 public void setSelectionGroup(SequenceGroup sg)
1195 selectionGroup = sg;
1196 if (sg != null && sg.getContext() == null)
1198 sg.setContext(alignment);
1202 public void setHiddenColumns(HiddenColumns hidden)
1204 this.alignment.setHiddenColumns(hidden);
1208 public ColumnSelection getColumnSelection()
1214 public void setColumnSelection(ColumnSelection colSel)
1216 this.colSel = colSel;
1219 updateHiddenColumns();
1221 isColSelChanged(true);
1229 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1231 return hiddenRepSequences;
1235 public void setHiddenRepSequences(
1236 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1238 this.hiddenRepSequences = hiddenRepSequences;
1242 public boolean hasSelectedColumns()
1244 ColumnSelection columnSelection = getColumnSelection();
1245 return columnSelection != null && columnSelection.hasSelectedColumns();
1249 public boolean hasHiddenColumns()
1251 return alignment.getHiddenColumns() != null
1252 && alignment.getHiddenColumns().hasHiddenColumns();
1255 public void updateHiddenColumns()
1257 // this method doesn't really do anything now. But - it could, since a
1258 // column Selection could be in the process of modification
1259 // hasHiddenColumns = colSel.hasHiddenColumns();
1263 public boolean hasHiddenRows()
1265 return alignment.getHiddenSequences().getSize() > 0;
1268 protected SequenceGroup selectionGroup;
1270 public void setSequenceSetId(String newid)
1272 if (sequenceSetID != null)
1275 "Warning - overwriting a sequenceSetId for a viewport!");
1277 sequenceSetID = new String(newid);
1281 public String getSequenceSetId()
1283 if (sequenceSetID == null)
1285 sequenceSetID = alignment.hashCode() + "";
1288 return sequenceSetID;
1292 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1295 protected String viewId = null;
1298 public String getViewId()
1302 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1307 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1309 ignoreGapsInConsensusCalculation = b;
1312 if (residueShading != null)
1314 residueShading.setThreshold(residueShading.getThreshold(),
1315 ignoreGapsInConsensusCalculation);
1320 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1322 ignoreBelowBackGroundFrequencyCalculation = b;
1325 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1327 infoLetterHeight = b;
1330 private long sgrouphash = -1, colselhash = -1;
1333 * checks current SelectionGroup against record of last hash value, and
1337 * update the record of last hash value
1339 * @return true if SelectionGroup changed since last call (when b is true)
1341 public boolean isSelectionGroupChanged(boolean b)
1343 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1344 : selectionGroup.hashCode();
1345 if (hc != -1 && hc != sgrouphash)
1357 * checks current colsel against record of last hash value, and optionally
1361 * update the record of last hash value
1362 * @return true if colsel changed since last call (when b is true)
1364 public boolean isColSelChanged(boolean b)
1366 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1367 if (hc != -1 && hc != colselhash)
1379 public boolean isIgnoreGapsConsensus()
1381 return ignoreGapsInConsensusCalculation;
1385 public boolean isIgnoreBelowBackground()
1387 return ignoreBelowBackGroundFrequencyCalculation;
1391 public boolean isInfoLetterHeight()
1393 return infoLetterHeight;
1396 // property change stuff
1397 // JBPNote Prolly only need this in the applet version.
1398 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1401 protected boolean showConservation = true;
1403 protected boolean showQuality = true;
1405 protected boolean showConsensus = true;
1407 protected boolean showOccupancy = true;
1409 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1411 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1413 protected boolean showAutocalculatedAbove;
1416 * when set, view will scroll to show the highlighted position
1418 private boolean followHighlight = true;
1421 * Property change listener for changes in alignment
1426 public void addPropertyChangeListener(
1427 java.beans.PropertyChangeListener listener)
1429 changeSupport.addPropertyChangeListener(listener);
1438 public void removePropertyChangeListener(
1439 java.beans.PropertyChangeListener listener)
1441 if (changeSupport != null)
1443 changeSupport.removePropertyChangeListener(listener);
1448 * Property change listener for changes in alignment
1457 public void firePropertyChange(String prop, Object oldvalue,
1460 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1463 // common hide/show column stuff
1465 public void hideSelectedColumns()
1467 if (colSel.isEmpty())
1472 colSel.hideSelectedColumns(alignment);
1473 setSelectionGroup(null);
1474 isColSelChanged(true);
1477 public void hideColumns(int start, int end)
1481 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1485 alignment.getHiddenColumns().hideColumns(start, end);
1487 isColSelChanged(true);
1490 public void showColumn(int col)
1492 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1493 isColSelChanged(true);
1496 public void showAllHiddenColumns()
1498 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1499 isColSelChanged(true);
1502 // common hide/show seq stuff
1503 public void showAllHiddenSeqs()
1505 int startSeq = ranges.getStartSeq();
1506 int endSeq = ranges.getEndSeq();
1508 if (alignment.getHiddenSequences().getSize() > 0)
1510 if (selectionGroup == null)
1512 selectionGroup = new SequenceGroup();
1513 selectionGroup.setEndRes(alignment.getWidth() - 1);
1515 List<SequenceI> tmp = alignment.getHiddenSequences()
1516 .showAll(hiddenRepSequences);
1517 for (SequenceI seq : tmp)
1519 selectionGroup.addSequence(seq, false);
1520 setSequenceAnnotationsVisible(seq, true);
1523 hiddenRepSequences = null;
1525 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1527 firePropertyChange("alignment", null, alignment.getSequences());
1528 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1534 public void showSequence(int index)
1536 int startSeq = ranges.getStartSeq();
1537 int endSeq = ranges.getEndSeq();
1539 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1540 hiddenRepSequences);
1543 if (selectionGroup == null)
1545 selectionGroup = new SequenceGroup();
1546 selectionGroup.setEndRes(alignment.getWidth() - 1);
1549 for (SequenceI seq : tmp)
1551 selectionGroup.addSequence(seq, false);
1552 setSequenceAnnotationsVisible(seq, true);
1555 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1557 firePropertyChange("alignment", null, alignment.getSequences());
1562 public void hideAllSelectedSeqs()
1564 if (selectionGroup == null || selectionGroup.getSize() < 1)
1569 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1573 setSelectionGroup(null);
1576 public void hideSequence(SequenceI[] seq)
1579 * cache offset to first visible sequence
1581 int startSeq = ranges.getStartSeq();
1585 for (int i = 0; i < seq.length; i++)
1587 alignment.getHiddenSequences().hideSequence(seq[i]);
1588 setSequenceAnnotationsVisible(seq[i], false);
1590 ranges.setStartSeq(startSeq);
1591 firePropertyChange("alignment", null, alignment.getSequences());
1596 * Hides the specified sequence, or the sequences it represents
1599 * the sequence to hide, or keep as representative
1600 * @param representGroup
1601 * if true, hide the current selection group except for the
1602 * representative sequence
1604 public void hideSequences(SequenceI sequence, boolean representGroup)
1606 if (selectionGroup == null || selectionGroup.getSize() < 1)
1608 hideSequence(new SequenceI[] { sequence });
1614 hideRepSequences(sequence, selectionGroup);
1615 setSelectionGroup(null);
1619 int gsize = selectionGroup.getSize();
1620 SequenceI[] hseqs = selectionGroup.getSequences()
1621 .toArray(new SequenceI[gsize]);
1623 hideSequence(hseqs);
1624 setSelectionGroup(null);
1629 * Set visibility for any annotations for the given sequence.
1633 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1636 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1639 for (AlignmentAnnotation ann : anns)
1641 if (ann.sequenceRef == sequenceI)
1643 ann.visible = visible;
1649 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1651 int sSize = sg.getSize();
1657 if (hiddenRepSequences == null)
1659 hiddenRepSequences = new Hashtable<>();
1662 hiddenRepSequences.put(repSequence, sg);
1664 // Hide all sequences except the repSequence
1665 SequenceI[] seqs = new SequenceI[sSize - 1];
1667 for (int i = 0; i < sSize; i++)
1669 if (sg.getSequenceAt(i) != repSequence)
1671 if (index == sSize - 1)
1676 seqs[index++] = sg.getSequenceAt(i);
1679 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1680 sg.setHidereps(true); // note: not done in 2.7applet
1687 * @return null or the current reference sequence
1689 public SequenceI getReferenceSeq()
1691 return alignment.getSeqrep();
1696 * @return true iff seq is the reference for the alignment
1698 public boolean isReferenceSeq(SequenceI seq)
1700 return alignment.getSeqrep() == seq;
1706 * @return true if there are sequences represented by this sequence that are
1709 public boolean isHiddenRepSequence(SequenceI seq)
1711 return (hiddenRepSequences != null
1712 && hiddenRepSequences.containsKey(seq));
1718 * @return null or a sequence group containing the sequences that seq
1721 public SequenceGroup getRepresentedSequences(SequenceI seq)
1723 return (SequenceGroup) (hiddenRepSequences == null ? null
1724 : hiddenRepSequences.get(seq));
1728 public int adjustForHiddenSeqs(int alignmentIndex)
1730 return alignment.getHiddenSequences()
1731 .adjustForHiddenSeqs(alignmentIndex);
1735 public void invertColumnSelection()
1737 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1741 public SequenceI[] getSelectionAsNewSequence()
1743 SequenceI[] sequences;
1744 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1745 // this was the only caller in the applet for this method
1746 // JBPNote: in applet, this method returned references to the alignment
1747 // sequences, and it did not honour the presence/absence of annotation
1748 // attached to the alignment (probably!)
1749 if (selectionGroup == null || selectionGroup.getSize() == 0)
1751 sequences = alignment.getSequencesArray();
1752 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1753 for (int i = 0; i < sequences.length; i++)
1755 // construct new sequence with subset of visible annotation
1756 sequences[i] = new Sequence(sequences[i], annots);
1761 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1768 public SequenceI[] getSequenceSelection()
1770 SequenceI[] sequences = null;
1771 if (selectionGroup != null)
1773 sequences = selectionGroup.getSequencesInOrder(alignment);
1775 if (sequences == null)
1777 sequences = alignment.getSequencesArray();
1783 public jalview.datamodel.AlignmentView getAlignmentView(
1784 boolean selectedOnly)
1786 return getAlignmentView(selectedOnly, false);
1790 public jalview.datamodel.AlignmentView getAlignmentView(
1791 boolean selectedOnly, boolean markGroups)
1793 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1795 alignment.getHiddenColumns() != null
1796 && alignment.getHiddenColumns().hasHiddenColumns(),
1797 selectedOnly, markGroups);
1801 public String[] getViewAsString(boolean selectedRegionOnly)
1803 return getViewAsString(selectedRegionOnly, true);
1807 public String[] getViewAsString(boolean selectedRegionOnly,
1808 boolean exportHiddenSeqs)
1810 String[] selection = null;
1811 SequenceI[] seqs = null;
1813 int start = 0, end = 0;
1814 if (selectedRegionOnly && selectionGroup != null)
1816 iSize = selectionGroup.getSize();
1817 seqs = selectionGroup.getSequencesInOrder(alignment);
1818 start = selectionGroup.getStartRes();
1819 end = selectionGroup.getEndRes() + 1;
1823 if (hasHiddenRows() && exportHiddenSeqs)
1825 AlignmentI fullAlignment = alignment.getHiddenSequences()
1826 .getFullAlignment();
1827 iSize = fullAlignment.getHeight();
1828 seqs = fullAlignment.getSequencesArray();
1829 end = fullAlignment.getWidth();
1833 iSize = alignment.getHeight();
1834 seqs = alignment.getSequencesArray();
1835 end = alignment.getWidth();
1839 selection = new String[iSize];
1840 if (alignment.getHiddenColumns() != null
1841 && alignment.getHiddenColumns().hasHiddenColumns())
1843 for (i = 0; i < iSize; i++)
1845 Iterator<int[]> blocks = alignment.getHiddenColumns()
1846 .getVisContigsIterator(start, end + 1, false);
1847 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1852 for (i = 0; i < iSize; i++)
1854 selection[i] = seqs[i].getSequenceAsString(start, end);
1862 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1864 ArrayList<int[]> regions = new ArrayList<>();
1870 HiddenColumns hidden = alignment.getHiddenColumns();
1871 if (hidden != null && hidden.hasHiddenColumns())
1875 start = hidden.visibleToAbsoluteColumn(start);
1878 end = hidden.getNextHiddenBoundary(false, start);
1889 regions.add(new int[] { start, end });
1891 if (hidden != null && hidden.hasHiddenColumns())
1893 start = hidden.visibleToAbsoluteColumn(end);
1894 start = hidden.getNextHiddenBoundary(true, start) + 1;
1896 } while (end < max);
1898 int[][] startEnd = new int[regions.size()][2];
1904 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1905 boolean selectedOnly)
1907 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1908 AlignmentAnnotation[] aa;
1909 if ((aa = alignment.getAlignmentAnnotation()) != null)
1911 for (AlignmentAnnotation annot : aa)
1913 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1914 if (selectedOnly && selectionGroup != null)
1916 clone.makeVisibleAnnotation(
1917 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1918 alignment.getHiddenColumns());
1922 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1931 public boolean isPadGaps()
1937 public void setPadGaps(boolean padGaps)
1939 this.padGaps = padGaps;
1943 * apply any post-edit constraints and trigger any calculations needed after
1944 * an edit has been performed on the alignment
1949 public void alignmentChanged(AlignmentViewPanel ap)
1953 alignment.padGaps();
1955 // if (autoCalculateConsensus)
1957 // updateConsensus(ap);
1959 // if (consensusProfiles != null && autoCalculateConsensus)
1961 // updateConservation(ap);
1963 // if (autoCalculateStrucConsensus)
1965 // updateStrucConsensus(ap);
1968 // updateInformation(ap);
1970 // Reset endRes of groups if beyond alignment width
1971 int alWidth = alignment.getWidth();
1972 List<SequenceGroup> groups = alignment.getGroups();
1975 for (SequenceGroup sg : groups)
1977 if (sg.getEndRes() > alWidth)
1979 sg.setEndRes(alWidth - 1);
1984 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1986 selectionGroup.setEndRes(alWidth - 1);
1989 updateAllColourSchemes();
1990 calculator.restartWorkers();
1994 * reset scope and do calculations for all applied colourschemes on alignment
1996 void updateAllColourSchemes()
1998 ResidueShaderI rs = residueShading;
2001 rs.alignmentChanged(alignment, hiddenRepSequences);
2003 rs.setConsensus(consensusProfiles);
2004 if (rs.conservationApplied())
2006 rs.setConservation(Conservation.calculateConservation("All",
2007 alignment.getSequences(), 0, alignment.getWidth(), false,
2008 getConsPercGaps(), false));
2012 for (SequenceGroup sg : alignment.getGroups())
2016 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2018 sg.recalcConservation();
2022 protected void initAutoAnnotation()
2024 // TODO: add menu option action that nulls or creates consensus object
2025 // depending on if the user wants to see the annotation or not in a
2026 // specific alignment
2028 if (consensusProfiles == null && !isDataset)
2030 if (!alignment.isNucleotide())
2039 consensus = new AlignmentAnnotation("Consensus",
2040 MessageManager.getString("label.consensus_descr"),
2041 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2042 initConsensus(consensus);
2046 initComplementConsensus();
2051 * If this is a protein alignment and there are mappings to cDNA, adds the
2052 * cDNA consensus annotation and returns true, else returns false.
2054 public boolean initComplementConsensus()
2056 if (!alignment.isNucleotide())
2058 final List<AlignedCodonFrame> codonMappings = alignment
2060 if (codonMappings != null && !codonMappings.isEmpty())
2062 boolean doConsensus = false;
2063 for (AlignedCodonFrame mapping : codonMappings)
2065 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2066 MapList[] mapLists = mapping.getdnaToProt();
2067 // mapLists can be empty if project load has not finished resolving
2069 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2077 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2079 .getString("label.complement_consensus_descr"),
2080 new Annotation[1], 0f, 100f,
2081 AlignmentAnnotation.BAR_GRAPH);
2082 initConsensus(complementConsensus);
2090 private void initConsensus(AlignmentAnnotation aa)
2093 aa.autoCalculated = true;
2097 alignment.addAnnotation(aa);
2101 // these should be extracted from the view model - style and settings for
2102 // derived annotation
2103 private void initOccupancy()
2107 occupancy = new AlignmentAnnotation("Occupancy",
2108 MessageManager.getString("label.occupancy_descr"),
2109 new Annotation[1], 0f, alignment.getHeight(),
2110 AlignmentAnnotation.BAR_GRAPH);
2111 occupancy.hasText = true;
2112 occupancy.autoCalculated = true;
2113 occupancy.scaleColLabel = true;
2114 occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
2116 alignment.addAnnotation(occupancy);
2120 private void initConservation()
2122 if (showConservation)
2124 if (conservation == null)
2126 conservation = new AlignmentAnnotation("Conservation",
2127 MessageManager.formatMessage("label.conservation_descr",
2129 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2130 conservation.hasText = true;
2131 conservation.autoCalculated = true;
2132 alignment.addAnnotation(conservation);
2137 private void initQuality()
2141 if (quality == null)
2143 quality = new AlignmentAnnotation("Quality",
2144 MessageManager.getString("label.quality_descr"),
2145 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2146 quality.hasText = true;
2147 quality.autoCalculated = true;
2148 alignment.addAnnotation(quality);
2153 private void initRNAStructure()
2155 if (alignment.hasRNAStructure() && strucConsensus == null)
2157 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2158 MessageManager.getString("label.strucconsensus_descr"),
2159 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2160 strucConsensus.hasText = true;
2161 strucConsensus.autoCalculated = true;
2165 alignment.addAnnotation(strucConsensus);
2173 * @see jalview.api.AlignViewportI#calcPanelHeight()
2176 public int calcPanelHeight()
2178 // setHeight of panels
2179 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2181 int charHeight = getCharHeight();
2184 BitSet graphgrp = new BitSet();
2185 for (AlignmentAnnotation aa : anns)
2189 System.err.println("Null annotation row: ignoring.");
2196 if (aa.graphGroup > -1)
2198 if (graphgrp.get(aa.graphGroup))
2204 graphgrp.set(aa.graphGroup);
2211 aa.height += charHeight;
2221 aa.height += aa.graphHeight;
2229 height += aa.height;
2241 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2242 boolean preserveNewGroupSettings)
2244 boolean updateCalcs = false;
2245 boolean conv = isShowGroupConservation();
2246 boolean cons = isShowGroupConsensus();
2247 boolean showprf = isShowSequenceLogo();
2248 boolean showConsHist = isShowConsensusHistogram();
2249 boolean normLogo = isNormaliseSequenceLogo();
2250 boolean showHMMPrf = isShowHMMSequenceLogo();
2251 boolean showInfoHist = isShowInformationHistogram();
2252 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2255 * TODO reorder the annotation rows according to group/sequence ordering on
2258 boolean sortg = true;
2260 // remove old automatic annotation
2261 // add any new annotation
2263 // intersect alignment annotation with alignment groups
2265 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2266 List<SequenceGroup> oldrfs = new ArrayList<>();
2269 for (int an = 0; an < aan.length; an++)
2271 if (aan[an].autoCalculated && aan[an].groupRef != null)
2273 oldrfs.add(aan[an].groupRef);
2274 alignment.deleteAnnotation(aan[an], false);
2278 if (alignment.getGroups() != null)
2280 for (SequenceGroup sg : alignment.getGroups())
2282 updateCalcs = false;
2283 if (applyGlobalSettings
2284 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2286 // set defaults for this group's conservation/consensus
2287 sg.setshowSequenceLogo(showprf);
2288 sg.setShowConsensusHistogram(showConsHist);
2289 sg.setNormaliseSequenceLogo(normLogo);
2290 sg.setshowHMMSequenceLogo(showHMMPrf);
2291 sg.setShowInformationHistogram(showInfoHist);
2292 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2297 alignment.addAnnotation(sg.getConservationRow(), 0);
2302 alignment.addAnnotation(sg.getConsensus(), 0);
2304 // refresh the annotation rows
2307 sg.recalcConservation();
2315 public boolean isDisplayReferenceSeq()
2317 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2321 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2323 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2327 public boolean isColourByReferenceSeq()
2329 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2333 public Color getSequenceColour(SequenceI seq)
2335 Color sqc = sequenceColours.get(seq);
2336 return (sqc == null ? Color.white : sqc);
2340 public void setSequenceColour(SequenceI seq, Color col)
2344 sequenceColours.remove(seq);
2348 sequenceColours.put(seq, col);
2353 public void updateSequenceIdColours()
2355 for (SequenceGroup sg : alignment.getGroups())
2357 if (sg.idColour != null)
2359 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2361 sequenceColours.put(s, sg.idColour);
2368 public void clearSequenceColours()
2370 sequenceColours.clear();
2374 public AlignViewportI getCodingComplement()
2376 return this.codingComplement;
2380 * Set this as the (cDna/protein) complement of the given viewport. Also
2381 * ensures the reverse relationship is set on the given viewport.
2384 public void setCodingComplement(AlignViewportI av)
2388 System.err.println("Ignoring recursive setCodingComplement request");
2392 this.codingComplement = av;
2393 // avoid infinite recursion!
2394 if (av.getCodingComplement() != this)
2396 av.setCodingComplement(this);
2402 public boolean isNucleotide()
2404 return getAlignment() == null ? false : getAlignment().isNucleotide();
2408 public FeaturesDisplayedI getFeaturesDisplayed()
2410 return featuresDisplayed;
2414 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2416 featuresDisplayed = featuresDisplayedI;
2420 public boolean areFeaturesDisplayed()
2422 return featuresDisplayed != null
2423 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2430 * features are displayed if true
2433 public void setShowSequenceFeatures(boolean b)
2435 viewStyle.setShowSequenceFeatures(b);
2439 public boolean isShowSequenceFeatures()
2441 return viewStyle.isShowSequenceFeatures();
2445 public void setShowSequenceFeaturesHeight(boolean selected)
2447 viewStyle.setShowSequenceFeaturesHeight(selected);
2451 public boolean isShowSequenceFeaturesHeight()
2453 return viewStyle.isShowSequenceFeaturesHeight();
2457 public void setShowAnnotation(boolean b)
2459 viewStyle.setShowAnnotation(b);
2463 public boolean isShowAnnotation()
2465 return viewStyle.isShowAnnotation();
2469 public boolean isRightAlignIds()
2471 return viewStyle.isRightAlignIds();
2475 public void setRightAlignIds(boolean rightAlignIds)
2477 viewStyle.setRightAlignIds(rightAlignIds);
2481 public boolean getConservationSelected()
2483 return viewStyle.getConservationSelected();
2487 public void setShowBoxes(boolean state)
2489 viewStyle.setShowBoxes(state);
2494 * @see jalview.api.ViewStyleI#getTextColour()
2497 public Color getTextColour()
2499 return viewStyle.getTextColour();
2504 * @see jalview.api.ViewStyleI#getTextColour2()
2507 public Color getTextColour2()
2509 return viewStyle.getTextColour2();
2514 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2517 public int getThresholdTextColour()
2519 return viewStyle.getThresholdTextColour();
2524 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2527 public boolean isConservationColourSelected()
2529 return viewStyle.isConservationColourSelected();
2534 * @see jalview.api.ViewStyleI#isRenderGaps()
2537 public boolean isRenderGaps()
2539 return viewStyle.isRenderGaps();
2544 * @see jalview.api.ViewStyleI#isShowColourText()
2547 public boolean isShowColourText()
2549 return viewStyle.isShowColourText();
2553 * @param conservationColourSelected
2554 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2557 public void setConservationColourSelected(
2558 boolean conservationColourSelected)
2560 viewStyle.setConservationColourSelected(conservationColourSelected);
2564 * @param showColourText
2565 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2568 public void setShowColourText(boolean showColourText)
2570 viewStyle.setShowColourText(showColourText);
2575 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2578 public void setTextColour(Color textColour)
2580 viewStyle.setTextColour(textColour);
2584 * @param thresholdTextColour
2585 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2588 public void setThresholdTextColour(int thresholdTextColour)
2590 viewStyle.setThresholdTextColour(thresholdTextColour);
2594 * @param textColour2
2595 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2598 public void setTextColour2(Color textColour2)
2600 viewStyle.setTextColour2(textColour2);
2604 public ViewStyleI getViewStyle()
2606 return new ViewStyle(viewStyle);
2610 public void setViewStyle(ViewStyleI settingsForView)
2612 viewStyle = new ViewStyle(settingsForView);
2613 if (residueShading != null)
2615 residueShading.setConservationApplied(
2616 settingsForView.isConservationColourSelected());
2621 public boolean sameStyle(ViewStyleI them)
2623 return viewStyle.sameStyle(them);
2628 * @see jalview.api.ViewStyleI#getIdWidth()
2631 public int getIdWidth()
2633 return viewStyle.getIdWidth();
2638 * @see jalview.api.ViewStyleI#setIdWidth(int)
2641 public void setIdWidth(int i)
2643 viewStyle.setIdWidth(i);
2648 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2651 public boolean isCentreColumnLabels()
2653 return viewStyle.isCentreColumnLabels();
2657 * @param centreColumnLabels
2658 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2661 public void setCentreColumnLabels(boolean centreColumnLabels)
2663 viewStyle.setCentreColumnLabels(centreColumnLabels);
2668 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2671 public void setShowDBRefs(boolean showdbrefs)
2673 viewStyle.setShowDBRefs(showdbrefs);
2678 * @see jalview.api.ViewStyleI#isShowDBRefs()
2681 public boolean isShowDBRefs()
2683 return viewStyle.isShowDBRefs();
2688 * @see jalview.api.ViewStyleI#isShowNPFeats()
2691 public boolean isShowNPFeats()
2693 return viewStyle.isShowNPFeats();
2697 * @param shownpfeats
2698 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2701 public void setShowNPFeats(boolean shownpfeats)
2703 viewStyle.setShowNPFeats(shownpfeats);
2706 public abstract StructureSelectionManager getStructureSelectionManager();
2709 * Add one command to the command history list.
2713 public void addToHistoryList(CommandI command)
2715 if (this.historyList != null)
2717 this.historyList.push(command);
2718 broadcastCommand(command, false);
2722 protected void broadcastCommand(CommandI command, boolean undo)
2724 getStructureSelectionManager().commandPerformed(command, undo,
2729 * Add one command to the command redo list.
2733 public void addToRedoList(CommandI command)
2735 if (this.redoList != null)
2737 this.redoList.push(command);
2739 broadcastCommand(command, true);
2743 * Clear the command redo list.
2745 public void clearRedoList()
2747 if (this.redoList != null)
2749 this.redoList.clear();
2753 public void setHistoryList(Deque<CommandI> list)
2755 this.historyList = list;
2758 public Deque<CommandI> getHistoryList()
2760 return this.historyList;
2763 public void setRedoList(Deque<CommandI> list)
2765 this.redoList = list;
2768 public Deque<CommandI> getRedoList()
2770 return this.redoList;
2774 public VamsasSource getVamsasSource()
2779 public SequenceAnnotationOrder getSortAnnotationsBy()
2781 return sortAnnotationsBy;
2784 public void setSortAnnotationsBy(
2785 SequenceAnnotationOrder sortAnnotationsBy)
2787 this.sortAnnotationsBy = sortAnnotationsBy;
2790 public boolean isShowAutocalculatedAbove()
2792 return showAutocalculatedAbove;
2795 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2797 this.showAutocalculatedAbove = showAutocalculatedAbove;
2801 public boolean isScaleProteinAsCdna()
2803 return viewStyle.isScaleProteinAsCdna();
2807 public void setScaleProteinAsCdna(boolean b)
2809 viewStyle.setScaleProteinAsCdna(b);
2813 public boolean isProteinFontAsCdna()
2815 return viewStyle.isProteinFontAsCdna();
2819 public void setProteinFontAsCdna(boolean b)
2821 viewStyle.setProteinFontAsCdna(b);
2825 * @return true if view should scroll to show the highlighted region of a
2830 public final boolean isFollowHighlight()
2832 return followHighlight;
2836 public final void setFollowHighlight(boolean b)
2838 this.followHighlight = b;
2842 public ViewportRanges getRanges()
2848 * Helper method to populate the SearchResults with the location in the
2849 * complementary alignment to scroll to, in order to match this one.
2852 * the SearchResults to add to
2853 * @return the offset (below top of visible region) of the matched sequence
2855 protected int findComplementScrollTarget(SearchResultsI sr)
2857 final AlignViewportI complement = getCodingComplement();
2858 if (complement == null || !complement.isFollowHighlight())
2862 boolean iAmProtein = !getAlignment().isNucleotide();
2863 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2864 : complement.getAlignment();
2865 if (proteinAlignment == null)
2869 final List<AlignedCodonFrame> mappings = proteinAlignment
2873 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2874 * residue in the middle column of the visible region. Scroll the
2875 * complementary alignment to line up the corresponding residue.
2878 SequenceI sequence = null;
2881 * locate 'middle' column (true middle if an odd number visible, left of
2882 * middle if an even number visible)
2884 int middleColumn = ranges.getStartRes()
2885 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2886 final HiddenSequences hiddenSequences = getAlignment()
2887 .getHiddenSequences();
2890 * searching to the bottom of the alignment gives smoother scrolling across
2891 * all gapped visible regions
2893 int lastSeq = alignment.getHeight() - 1;
2894 List<AlignedCodonFrame> seqMappings = null;
2895 for (int seqNo = ranges
2896 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2898 sequence = getAlignment().getSequenceAt(seqNo);
2899 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2903 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2907 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2909 getCodingComplement().getAlignment().getSequences());
2910 if (!seqMappings.isEmpty())
2916 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2919 * No ungapped mapped sequence in middle column - do nothing
2923 MappingUtils.addSearchResults(sr, sequence,
2924 sequence.findPosition(middleColumn), seqMappings);
2929 * synthesize a column selection if none exists so it covers the given
2930 * selection group. if wholewidth is false, no column selection is made if the
2931 * selection group covers the whole alignment width.
2936 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2939 if (sg != null && (sgs = sg.getStartRes()) >= 0
2940 && sg.getStartRes() <= (sge = sg.getEndRes())
2941 && !this.hasSelectedColumns())
2943 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2950 colSel = new ColumnSelection();
2952 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2954 colSel.addElement(cspos);
2960 * hold status of current selection group - defined on alignment or not.
2962 private boolean selectionIsDefinedGroup = false;
2965 public boolean isSelectionDefinedGroup()
2967 if (selectionGroup == null)
2971 if (isSelectionGroupChanged(true))
2973 selectionIsDefinedGroup = false;
2974 List<SequenceGroup> gps = alignment.getGroups();
2975 if (gps == null || gps.size() == 0)
2977 selectionIsDefinedGroup = false;
2981 selectionIsDefinedGroup = gps.contains(selectionGroup);
2984 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2988 * null, or currently highlighted results on this view
2990 private SearchResultsI searchResults = null;
2992 protected TreeModel currentTree = null;
2995 public boolean hasSearchResults()
2997 return searchResults != null;
3001 public void setSearchResults(SearchResultsI results)
3003 searchResults = results;
3007 public SearchResultsI getSearchResults()
3009 return searchResults;
3013 * get the consensus sequence as displayed under the PID consensus annotation
3016 * @return consensus sequence as a new sequence object
3018 public SequenceI getConsensusSeq()
3020 if (consensus == null)
3022 updateConsensus(null);
3024 if (consensus == null)
3028 StringBuffer seqs = new StringBuffer();
3029 for (int i = 0; i < consensus.annotations.length; i++)
3031 Annotation annotation = consensus.annotations[i];
3032 if (annotation != null)
3034 String description = annotation.description;
3035 if (description != null && description.startsWith("["))
3037 // consensus is a tie - just pick the first one
3038 seqs.append(description.charAt(1));
3042 seqs.append(annotation.displayCharacter);
3047 SequenceI sq = new Sequence("Consensus", seqs.toString());
3048 sq.setDescription("Percentage Identity Consensus "
3049 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3053 public boolean hasReferenceAnnotation()
3055 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3056 for (AlignmentAnnotation annot : annots)
3058 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3067 public void setCurrentTree(TreeModel tree)
3073 public TreeModel getCurrentTree()