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 hmmShowSequenceLogo = false;
1034 * should hmm profile be rendered normalised to row height
1036 protected boolean hmmNormaliseSequenceLogo = false;
1039 * should information histograms be rendered by default
1041 protected boolean hmmShowHistogram = true;
1044 * @return the showConsensusProfile
1047 public boolean isShowSequenceLogo()
1049 return showSequenceLogo;
1053 * @return the showInformationProfile
1056 public boolean isShowHMMSequenceLogo()
1058 return hmmShowSequenceLogo;
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.hmmShowSequenceLogo)
1083 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1084 // TODO: updateAnnotation if description (tooltip) will show
1085 // profile in place of information content?
1086 // calculator.updateAnnotationFor(InformationThread.class);
1088 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1092 * @param showConsensusHistogram
1093 * the showConsensusHistogram to set
1095 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1097 this.showConsensusHistogram = showConsensusHistogram;
1101 * @param showInformationHistogram
1103 public void setShowInformationHistogram(boolean showInformationHistogram)
1105 this.hmmShowHistogram = showInformationHistogram;
1109 * @return the showGroupConservation
1111 public boolean isShowGroupConservation()
1113 return showGroupConservation;
1117 * @param showGroupConservation
1118 * the showGroupConservation to set
1120 public void setShowGroupConservation(boolean showGroupConservation)
1122 this.showGroupConservation = showGroupConservation;
1126 * @return the showGroupConsensus
1128 public boolean isShowGroupConsensus()
1130 return showGroupConsensus;
1134 * @param showGroupConsensus
1135 * the showGroupConsensus to set
1137 public void setShowGroupConsensus(boolean showGroupConsensus)
1139 this.showGroupConsensus = showGroupConsensus;
1144 * @return flag to indicate if the consensus histogram should be rendered by
1148 public boolean isShowConsensusHistogram()
1150 return this.showConsensusHistogram;
1155 * @return flag to indicate if the information content histogram should be
1156 * rendered by default
1159 public boolean isShowInformationHistogram()
1161 return this.hmmShowHistogram;
1165 * when set, updateAlignment will always ensure sequences are of equal length
1167 private boolean padGaps = false;
1170 * when set, alignment should be reordered according to a newly opened tree
1172 public boolean sortByTree = false;
1177 * @return null or the currently selected sequence region
1180 public SequenceGroup getSelectionGroup()
1182 return selectionGroup;
1186 * Set the selection group for this window. Also sets the current alignment as
1187 * the context for the group, if it does not already have one.
1190 * - group holding references to sequences in this alignment view
1194 public void setSelectionGroup(SequenceGroup sg)
1196 selectionGroup = sg;
1197 if (sg != null && sg.getContext() == null)
1199 sg.setContext(alignment);
1203 public void setHiddenColumns(HiddenColumns hidden)
1205 this.alignment.setHiddenColumns(hidden);
1209 public ColumnSelection getColumnSelection()
1215 public void setColumnSelection(ColumnSelection colSel)
1217 this.colSel = colSel;
1220 updateHiddenColumns();
1222 isColSelChanged(true);
1230 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1232 return hiddenRepSequences;
1236 public void setHiddenRepSequences(
1237 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1239 this.hiddenRepSequences = hiddenRepSequences;
1243 public boolean hasSelectedColumns()
1245 ColumnSelection columnSelection = getColumnSelection();
1246 return columnSelection != null && columnSelection.hasSelectedColumns();
1250 public boolean hasHiddenColumns()
1252 return alignment.getHiddenColumns() != null
1253 && alignment.getHiddenColumns().hasHiddenColumns();
1256 public void updateHiddenColumns()
1258 // this method doesn't really do anything now. But - it could, since a
1259 // column Selection could be in the process of modification
1260 // hasHiddenColumns = colSel.hasHiddenColumns();
1264 public boolean hasHiddenRows()
1266 return alignment.getHiddenSequences().getSize() > 0;
1269 protected SequenceGroup selectionGroup;
1271 public void setSequenceSetId(String newid)
1273 if (sequenceSetID != null)
1276 "Warning - overwriting a sequenceSetId for a viewport!");
1278 sequenceSetID = new String(newid);
1282 public String getSequenceSetId()
1284 if (sequenceSetID == null)
1286 sequenceSetID = alignment.hashCode() + "";
1289 return sequenceSetID;
1293 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1296 protected String viewId = null;
1299 public String getViewId()
1303 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1308 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1310 ignoreGapsInConsensusCalculation = b;
1313 if (residueShading != null)
1315 residueShading.setThreshold(residueShading.getThreshold(),
1316 ignoreGapsInConsensusCalculation);
1321 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1323 ignoreBelowBackGroundFrequencyCalculation = b;
1326 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1328 infoLetterHeight = b;
1331 private long sgrouphash = -1, colselhash = -1;
1334 * checks current SelectionGroup against record of last hash value, and
1338 * update the record of last hash value
1340 * @return true if SelectionGroup changed since last call (when b is true)
1342 public boolean isSelectionGroupChanged(boolean b)
1344 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1345 : selectionGroup.hashCode();
1346 if (hc != -1 && hc != sgrouphash)
1358 * checks current colsel against record of last hash value, and optionally
1362 * update the record of last hash value
1363 * @return true if colsel changed since last call (when b is true)
1365 public boolean isColSelChanged(boolean b)
1367 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1368 if (hc != -1 && hc != colselhash)
1380 public boolean isIgnoreGapsConsensus()
1382 return ignoreGapsInConsensusCalculation;
1386 public boolean isIgnoreBelowBackground()
1388 return ignoreBelowBackGroundFrequencyCalculation;
1392 public boolean isInfoLetterHeight()
1394 return infoLetterHeight;
1397 // property change stuff
1398 // JBPNote Prolly only need this in the applet version.
1399 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1402 protected boolean showConservation = true;
1404 protected boolean showQuality = true;
1406 protected boolean showConsensus = true;
1408 protected boolean showOccupancy = true;
1410 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1412 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1414 protected boolean showAutocalculatedAbove;
1417 * when set, view will scroll to show the highlighted position
1419 private boolean followHighlight = true;
1422 * Property change listener for changes in alignment
1427 public void addPropertyChangeListener(
1428 java.beans.PropertyChangeListener listener)
1430 changeSupport.addPropertyChangeListener(listener);
1439 public void removePropertyChangeListener(
1440 java.beans.PropertyChangeListener listener)
1442 if (changeSupport != null)
1444 changeSupport.removePropertyChangeListener(listener);
1449 * Property change listener for changes in alignment
1458 public void firePropertyChange(String prop, Object oldvalue,
1461 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1464 // common hide/show column stuff
1466 public void hideSelectedColumns()
1468 if (colSel.isEmpty())
1473 colSel.hideSelectedColumns(alignment);
1474 setSelectionGroup(null);
1475 isColSelChanged(true);
1478 public void hideColumns(int start, int end)
1482 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1486 alignment.getHiddenColumns().hideColumns(start, end);
1488 isColSelChanged(true);
1491 public void showColumn(int col)
1493 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1494 isColSelChanged(true);
1497 public void showAllHiddenColumns()
1499 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1500 isColSelChanged(true);
1503 // common hide/show seq stuff
1504 public void showAllHiddenSeqs()
1506 int startSeq = ranges.getStartSeq();
1507 int endSeq = ranges.getEndSeq();
1509 if (alignment.getHiddenSequences().getSize() > 0)
1511 if (selectionGroup == null)
1513 selectionGroup = new SequenceGroup();
1514 selectionGroup.setEndRes(alignment.getWidth() - 1);
1516 List<SequenceI> tmp = alignment.getHiddenSequences()
1517 .showAll(hiddenRepSequences);
1518 for (SequenceI seq : tmp)
1520 selectionGroup.addSequence(seq, false);
1521 setSequenceAnnotationsVisible(seq, true);
1524 hiddenRepSequences = null;
1526 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1528 firePropertyChange("alignment", null, alignment.getSequences());
1529 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1535 public void showSequence(int index)
1537 int startSeq = ranges.getStartSeq();
1538 int endSeq = ranges.getEndSeq();
1540 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1541 hiddenRepSequences);
1544 if (selectionGroup == null)
1546 selectionGroup = new SequenceGroup();
1547 selectionGroup.setEndRes(alignment.getWidth() - 1);
1550 for (SequenceI seq : tmp)
1552 selectionGroup.addSequence(seq, false);
1553 setSequenceAnnotationsVisible(seq, true);
1556 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1558 firePropertyChange("alignment", null, alignment.getSequences());
1563 public void hideAllSelectedSeqs()
1565 if (selectionGroup == null || selectionGroup.getSize() < 1)
1570 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1574 setSelectionGroup(null);
1577 public void hideSequence(SequenceI[] seq)
1580 * cache offset to first visible sequence
1582 int startSeq = ranges.getStartSeq();
1586 for (int i = 0; i < seq.length; i++)
1588 alignment.getHiddenSequences().hideSequence(seq[i]);
1589 setSequenceAnnotationsVisible(seq[i], false);
1591 ranges.setStartSeq(startSeq);
1592 firePropertyChange("alignment", null, alignment.getSequences());
1597 * Hides the specified sequence, or the sequences it represents
1600 * the sequence to hide, or keep as representative
1601 * @param representGroup
1602 * if true, hide the current selection group except for the
1603 * representative sequence
1605 public void hideSequences(SequenceI sequence, boolean representGroup)
1607 if (selectionGroup == null || selectionGroup.getSize() < 1)
1609 hideSequence(new SequenceI[] { sequence });
1615 hideRepSequences(sequence, selectionGroup);
1616 setSelectionGroup(null);
1620 int gsize = selectionGroup.getSize();
1621 SequenceI[] hseqs = selectionGroup.getSequences()
1622 .toArray(new SequenceI[gsize]);
1624 hideSequence(hseqs);
1625 setSelectionGroup(null);
1630 * Set visibility for any annotations for the given sequence.
1634 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1637 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1640 for (AlignmentAnnotation ann : anns)
1642 if (ann.sequenceRef == sequenceI)
1644 ann.visible = visible;
1650 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1652 int sSize = sg.getSize();
1658 if (hiddenRepSequences == null)
1660 hiddenRepSequences = new Hashtable<>();
1663 hiddenRepSequences.put(repSequence, sg);
1665 // Hide all sequences except the repSequence
1666 SequenceI[] seqs = new SequenceI[sSize - 1];
1668 for (int i = 0; i < sSize; i++)
1670 if (sg.getSequenceAt(i) != repSequence)
1672 if (index == sSize - 1)
1677 seqs[index++] = sg.getSequenceAt(i);
1680 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1681 sg.setHidereps(true); // note: not done in 2.7applet
1688 * @return null or the current reference sequence
1690 public SequenceI getReferenceSeq()
1692 return alignment.getSeqrep();
1697 * @return true iff seq is the reference for the alignment
1699 public boolean isReferenceSeq(SequenceI seq)
1701 return alignment.getSeqrep() == seq;
1707 * @return true if there are sequences represented by this sequence that are
1710 public boolean isHiddenRepSequence(SequenceI seq)
1712 return (hiddenRepSequences != null
1713 && hiddenRepSequences.containsKey(seq));
1719 * @return null or a sequence group containing the sequences that seq
1722 public SequenceGroup getRepresentedSequences(SequenceI seq)
1724 return (SequenceGroup) (hiddenRepSequences == null ? null
1725 : hiddenRepSequences.get(seq));
1729 public int adjustForHiddenSeqs(int alignmentIndex)
1731 return alignment.getHiddenSequences()
1732 .adjustForHiddenSeqs(alignmentIndex);
1736 public void invertColumnSelection()
1738 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1742 public SequenceI[] getSelectionAsNewSequence()
1744 SequenceI[] sequences;
1745 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1746 // this was the only caller in the applet for this method
1747 // JBPNote: in applet, this method returned references to the alignment
1748 // sequences, and it did not honour the presence/absence of annotation
1749 // attached to the alignment (probably!)
1750 if (selectionGroup == null || selectionGroup.getSize() == 0)
1752 sequences = alignment.getSequencesArray();
1753 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1754 for (int i = 0; i < sequences.length; i++)
1756 // construct new sequence with subset of visible annotation
1757 sequences[i] = new Sequence(sequences[i], annots);
1762 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1769 public SequenceI[] getSequenceSelection()
1771 SequenceI[] sequences = null;
1772 if (selectionGroup != null)
1774 sequences = selectionGroup.getSequencesInOrder(alignment);
1776 if (sequences == null)
1778 sequences = alignment.getSequencesArray();
1784 public jalview.datamodel.AlignmentView getAlignmentView(
1785 boolean selectedOnly)
1787 return getAlignmentView(selectedOnly, false);
1791 public jalview.datamodel.AlignmentView getAlignmentView(
1792 boolean selectedOnly, boolean markGroups)
1794 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1796 alignment.getHiddenColumns() != null
1797 && alignment.getHiddenColumns().hasHiddenColumns(),
1798 selectedOnly, markGroups);
1802 public String[] getViewAsString(boolean selectedRegionOnly)
1804 return getViewAsString(selectedRegionOnly, true);
1808 public String[] getViewAsString(boolean selectedRegionOnly,
1809 boolean exportHiddenSeqs)
1811 String[] selection = null;
1812 SequenceI[] seqs = null;
1814 int start = 0, end = 0;
1815 if (selectedRegionOnly && selectionGroup != null)
1817 iSize = selectionGroup.getSize();
1818 seqs = selectionGroup.getSequencesInOrder(alignment);
1819 start = selectionGroup.getStartRes();
1820 end = selectionGroup.getEndRes() + 1;
1824 if (hasHiddenRows() && exportHiddenSeqs)
1826 AlignmentI fullAlignment = alignment.getHiddenSequences()
1827 .getFullAlignment();
1828 iSize = fullAlignment.getHeight();
1829 seqs = fullAlignment.getSequencesArray();
1830 end = fullAlignment.getWidth();
1834 iSize = alignment.getHeight();
1835 seqs = alignment.getSequencesArray();
1836 end = alignment.getWidth();
1840 selection = new String[iSize];
1841 if (alignment.getHiddenColumns() != null
1842 && alignment.getHiddenColumns().hasHiddenColumns())
1844 for (i = 0; i < iSize; i++)
1846 Iterator<int[]> blocks = alignment.getHiddenColumns()
1847 .getVisContigsIterator(start, end + 1, false);
1848 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1853 for (i = 0; i < iSize; i++)
1855 selection[i] = seqs[i].getSequenceAsString(start, end);
1863 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1865 ArrayList<int[]> regions = new ArrayList<>();
1871 HiddenColumns hidden = alignment.getHiddenColumns();
1872 if (hidden != null && hidden.hasHiddenColumns())
1876 start = hidden.visibleToAbsoluteColumn(start);
1879 end = hidden.getNextHiddenBoundary(false, start);
1890 regions.add(new int[] { start, end });
1892 if (hidden != null && hidden.hasHiddenColumns())
1894 start = hidden.visibleToAbsoluteColumn(end);
1895 start = hidden.getNextHiddenBoundary(true, start) + 1;
1897 } while (end < max);
1899 int[][] startEnd = new int[regions.size()][2];
1905 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1906 boolean selectedOnly)
1908 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1909 AlignmentAnnotation[] aa;
1910 if ((aa = alignment.getAlignmentAnnotation()) != null)
1912 for (AlignmentAnnotation annot : aa)
1914 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1915 if (selectedOnly && selectionGroup != null)
1917 clone.makeVisibleAnnotation(
1918 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1919 alignment.getHiddenColumns());
1923 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1932 public boolean isPadGaps()
1938 public void setPadGaps(boolean padGaps)
1940 this.padGaps = padGaps;
1944 * apply any post-edit constraints and trigger any calculations needed after
1945 * an edit has been performed on the alignment
1950 public void alignmentChanged(AlignmentViewPanel ap)
1954 alignment.padGaps();
1957 // Reset endRes of groups if beyond alignment width
1958 int alWidth = alignment.getWidth();
1959 List<SequenceGroup> groups = alignment.getGroups();
1962 for (SequenceGroup sg : groups)
1964 if (sg.getEndRes() > alWidth)
1966 sg.setEndRes(alWidth - 1);
1971 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1973 selectionGroup.setEndRes(alWidth - 1);
1976 updateAllColourSchemes();
1977 calculator.restartWorkers();
1981 * reset scope and do calculations for all applied colourschemes on alignment
1983 void updateAllColourSchemes()
1985 ResidueShaderI rs = residueShading;
1988 rs.alignmentChanged(alignment, hiddenRepSequences);
1990 rs.setConsensus(consensusProfiles);
1991 if (rs.conservationApplied())
1993 rs.setConservation(Conservation.calculateConservation("All",
1994 alignment.getSequences(), 0, alignment.getWidth(), false,
1995 getConsPercGaps(), false));
1999 for (SequenceGroup sg : alignment.getGroups())
2003 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2005 sg.recalcConservation();
2009 protected void initAutoAnnotation()
2011 // TODO: add menu option action that nulls or creates consensus object
2012 // depending on if the user wants to see the annotation or not in a
2013 // specific alignment
2015 if (consensusProfiles == null && !isDataset)
2017 if (!alignment.isNucleotide())
2026 consensus = new AlignmentAnnotation("Consensus",
2027 MessageManager.getString("label.consensus_descr"),
2028 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2029 initConsensus(consensus);
2033 initComplementConsensus();
2038 * If this is a protein alignment and there are mappings to cDNA, adds the
2039 * cDNA consensus annotation and returns true, else returns false.
2041 public boolean initComplementConsensus()
2043 if (!alignment.isNucleotide())
2045 final List<AlignedCodonFrame> codonMappings = alignment
2047 if (codonMappings != null && !codonMappings.isEmpty())
2049 boolean doConsensus = false;
2050 for (AlignedCodonFrame mapping : codonMappings)
2052 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2053 MapList[] mapLists = mapping.getdnaToProt();
2054 // mapLists can be empty if project load has not finished resolving
2056 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2064 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2066 .getString("label.complement_consensus_descr"),
2067 new Annotation[1], 0f, 100f,
2068 AlignmentAnnotation.BAR_GRAPH);
2069 initConsensus(complementConsensus);
2077 private void initConsensus(AlignmentAnnotation aa)
2080 aa.autoCalculated = true;
2084 alignment.addAnnotation(aa);
2088 // these should be extracted from the view model - style and settings for
2089 // derived annotation
2090 private void initOccupancy()
2094 occupancy = new AlignmentAnnotation("Occupancy",
2095 MessageManager.getString("label.occupancy_descr"),
2096 new Annotation[1], 0f, alignment.getHeight(),
2097 AlignmentAnnotation.BAR_GRAPH);
2098 occupancy.hasText = true;
2099 occupancy.autoCalculated = true;
2100 occupancy.scaleColLabel = true;
2101 occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
2103 alignment.addAnnotation(occupancy);
2107 private void initConservation()
2109 if (showConservation)
2111 if (conservation == null)
2113 conservation = new AlignmentAnnotation("Conservation",
2114 MessageManager.formatMessage("label.conservation_descr",
2116 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2117 conservation.hasText = true;
2118 conservation.autoCalculated = true;
2119 alignment.addAnnotation(conservation);
2124 private void initQuality()
2128 if (quality == null)
2130 quality = new AlignmentAnnotation("Quality",
2131 MessageManager.getString("label.quality_descr"),
2132 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2133 quality.hasText = true;
2134 quality.autoCalculated = true;
2135 alignment.addAnnotation(quality);
2140 private void initRNAStructure()
2142 if (alignment.hasRNAStructure() && strucConsensus == null)
2144 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2145 MessageManager.getString("label.strucconsensus_descr"),
2146 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2147 strucConsensus.hasText = true;
2148 strucConsensus.autoCalculated = true;
2152 alignment.addAnnotation(strucConsensus);
2160 * @see jalview.api.AlignViewportI#calcPanelHeight()
2163 public int calcPanelHeight()
2165 // setHeight of panels
2166 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2168 int charHeight = getCharHeight();
2171 BitSet graphgrp = new BitSet();
2172 for (AlignmentAnnotation aa : anns)
2176 System.err.println("Null annotation row: ignoring.");
2183 if (aa.graphGroup > -1)
2185 if (graphgrp.get(aa.graphGroup))
2191 graphgrp.set(aa.graphGroup);
2198 aa.height += charHeight;
2208 aa.height += aa.graphHeight;
2216 height += aa.height;
2228 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2229 boolean preserveNewGroupSettings)
2231 boolean updateCalcs = false;
2232 boolean conv = isShowGroupConservation();
2233 boolean cons = isShowGroupConsensus();
2234 boolean showprf = isShowSequenceLogo();
2235 boolean showConsHist = isShowConsensusHistogram();
2236 boolean normLogo = isNormaliseSequenceLogo();
2237 boolean showHMMPrf = isShowHMMSequenceLogo();
2238 boolean showInfoHist = isShowInformationHistogram();
2239 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2242 * TODO reorder the annotation rows according to group/sequence ordering on
2245 boolean sortg = true;
2247 // remove old automatic annotation
2248 // add any new annotation
2250 // intersect alignment annotation with alignment groups
2252 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2253 List<SequenceGroup> oldrfs = new ArrayList<>();
2256 for (int an = 0; an < aan.length; an++)
2258 if (aan[an].autoCalculated && aan[an].groupRef != null)
2260 oldrfs.add(aan[an].groupRef);
2261 alignment.deleteAnnotation(aan[an], false);
2265 if (alignment.getGroups() != null)
2267 for (SequenceGroup sg : alignment.getGroups())
2269 updateCalcs = false;
2270 if (applyGlobalSettings
2271 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2273 // set defaults for this group's conservation/consensus
2274 sg.setshowSequenceLogo(showprf);
2275 sg.setShowConsensusHistogram(showConsHist);
2276 sg.setNormaliseSequenceLogo(normLogo);
2277 sg.setShowHMMSequenceLogo(showHMMPrf);
2278 sg.setShowInformationHistogram(showInfoHist);
2279 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2284 alignment.addAnnotation(sg.getConservationRow(), 0);
2289 alignment.addAnnotation(sg.getConsensus(), 0);
2291 // refresh the annotation rows
2294 sg.recalcConservation();
2302 public boolean isDisplayReferenceSeq()
2304 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2308 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2310 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2314 public boolean isColourByReferenceSeq()
2316 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2320 public Color getSequenceColour(SequenceI seq)
2322 Color sqc = sequenceColours.get(seq);
2323 return (sqc == null ? Color.white : sqc);
2327 public void setSequenceColour(SequenceI seq, Color col)
2331 sequenceColours.remove(seq);
2335 sequenceColours.put(seq, col);
2340 public void updateSequenceIdColours()
2342 for (SequenceGroup sg : alignment.getGroups())
2344 if (sg.idColour != null)
2346 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2348 sequenceColours.put(s, sg.idColour);
2355 public void clearSequenceColours()
2357 sequenceColours.clear();
2361 public AlignViewportI getCodingComplement()
2363 return this.codingComplement;
2367 * Set this as the (cDna/protein) complement of the given viewport. Also
2368 * ensures the reverse relationship is set on the given viewport.
2371 public void setCodingComplement(AlignViewportI av)
2375 System.err.println("Ignoring recursive setCodingComplement request");
2379 this.codingComplement = av;
2380 // avoid infinite recursion!
2381 if (av.getCodingComplement() != this)
2383 av.setCodingComplement(this);
2389 public boolean isNucleotide()
2391 return getAlignment() == null ? false : getAlignment().isNucleotide();
2395 public FeaturesDisplayedI getFeaturesDisplayed()
2397 return featuresDisplayed;
2401 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2403 featuresDisplayed = featuresDisplayedI;
2407 public boolean areFeaturesDisplayed()
2409 return featuresDisplayed != null
2410 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2417 * features are displayed if true
2420 public void setShowSequenceFeatures(boolean b)
2422 viewStyle.setShowSequenceFeatures(b);
2426 public boolean isShowSequenceFeatures()
2428 return viewStyle.isShowSequenceFeatures();
2432 public void setShowSequenceFeaturesHeight(boolean selected)
2434 viewStyle.setShowSequenceFeaturesHeight(selected);
2438 public boolean isShowSequenceFeaturesHeight()
2440 return viewStyle.isShowSequenceFeaturesHeight();
2444 public void setShowAnnotation(boolean b)
2446 viewStyle.setShowAnnotation(b);
2450 public boolean isShowAnnotation()
2452 return viewStyle.isShowAnnotation();
2456 public boolean isRightAlignIds()
2458 return viewStyle.isRightAlignIds();
2462 public void setRightAlignIds(boolean rightAlignIds)
2464 viewStyle.setRightAlignIds(rightAlignIds);
2468 public boolean getConservationSelected()
2470 return viewStyle.getConservationSelected();
2474 public void setShowBoxes(boolean state)
2476 viewStyle.setShowBoxes(state);
2481 * @see jalview.api.ViewStyleI#getTextColour()
2484 public Color getTextColour()
2486 return viewStyle.getTextColour();
2491 * @see jalview.api.ViewStyleI#getTextColour2()
2494 public Color getTextColour2()
2496 return viewStyle.getTextColour2();
2501 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2504 public int getThresholdTextColour()
2506 return viewStyle.getThresholdTextColour();
2511 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2514 public boolean isConservationColourSelected()
2516 return viewStyle.isConservationColourSelected();
2521 * @see jalview.api.ViewStyleI#isRenderGaps()
2524 public boolean isRenderGaps()
2526 return viewStyle.isRenderGaps();
2531 * @see jalview.api.ViewStyleI#isShowColourText()
2534 public boolean isShowColourText()
2536 return viewStyle.isShowColourText();
2540 * @param conservationColourSelected
2541 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2544 public void setConservationColourSelected(
2545 boolean conservationColourSelected)
2547 viewStyle.setConservationColourSelected(conservationColourSelected);
2551 * @param showColourText
2552 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2555 public void setShowColourText(boolean showColourText)
2557 viewStyle.setShowColourText(showColourText);
2562 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2565 public void setTextColour(Color textColour)
2567 viewStyle.setTextColour(textColour);
2571 * @param thresholdTextColour
2572 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2575 public void setThresholdTextColour(int thresholdTextColour)
2577 viewStyle.setThresholdTextColour(thresholdTextColour);
2581 * @param textColour2
2582 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2585 public void setTextColour2(Color textColour2)
2587 viewStyle.setTextColour2(textColour2);
2591 public ViewStyleI getViewStyle()
2593 return new ViewStyle(viewStyle);
2597 public void setViewStyle(ViewStyleI settingsForView)
2599 viewStyle = new ViewStyle(settingsForView);
2600 if (residueShading != null)
2602 residueShading.setConservationApplied(
2603 settingsForView.isConservationColourSelected());
2608 public boolean sameStyle(ViewStyleI them)
2610 return viewStyle.sameStyle(them);
2615 * @see jalview.api.ViewStyleI#getIdWidth()
2618 public int getIdWidth()
2620 return viewStyle.getIdWidth();
2625 * @see jalview.api.ViewStyleI#setIdWidth(int)
2628 public void setIdWidth(int i)
2630 viewStyle.setIdWidth(i);
2635 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2638 public boolean isCentreColumnLabels()
2640 return viewStyle.isCentreColumnLabels();
2644 * @param centreColumnLabels
2645 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2648 public void setCentreColumnLabels(boolean centreColumnLabels)
2650 viewStyle.setCentreColumnLabels(centreColumnLabels);
2655 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2658 public void setShowDBRefs(boolean showdbrefs)
2660 viewStyle.setShowDBRefs(showdbrefs);
2665 * @see jalview.api.ViewStyleI#isShowDBRefs()
2668 public boolean isShowDBRefs()
2670 return viewStyle.isShowDBRefs();
2675 * @see jalview.api.ViewStyleI#isShowNPFeats()
2678 public boolean isShowNPFeats()
2680 return viewStyle.isShowNPFeats();
2684 * @param shownpfeats
2685 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2688 public void setShowNPFeats(boolean shownpfeats)
2690 viewStyle.setShowNPFeats(shownpfeats);
2693 public abstract StructureSelectionManager getStructureSelectionManager();
2696 * Add one command to the command history list.
2700 public void addToHistoryList(CommandI command)
2702 if (this.historyList != null)
2704 this.historyList.push(command);
2705 broadcastCommand(command, false);
2709 protected void broadcastCommand(CommandI command, boolean undo)
2711 getStructureSelectionManager().commandPerformed(command, undo,
2716 * Add one command to the command redo list.
2720 public void addToRedoList(CommandI command)
2722 if (this.redoList != null)
2724 this.redoList.push(command);
2726 broadcastCommand(command, true);
2730 * Clear the command redo list.
2732 public void clearRedoList()
2734 if (this.redoList != null)
2736 this.redoList.clear();
2740 public void setHistoryList(Deque<CommandI> list)
2742 this.historyList = list;
2745 public Deque<CommandI> getHistoryList()
2747 return this.historyList;
2750 public void setRedoList(Deque<CommandI> list)
2752 this.redoList = list;
2755 public Deque<CommandI> getRedoList()
2757 return this.redoList;
2761 public VamsasSource getVamsasSource()
2766 public SequenceAnnotationOrder getSortAnnotationsBy()
2768 return sortAnnotationsBy;
2771 public void setSortAnnotationsBy(
2772 SequenceAnnotationOrder sortAnnotationsBy)
2774 this.sortAnnotationsBy = sortAnnotationsBy;
2777 public boolean isShowAutocalculatedAbove()
2779 return showAutocalculatedAbove;
2782 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2784 this.showAutocalculatedAbove = showAutocalculatedAbove;
2788 public boolean isScaleProteinAsCdna()
2790 return viewStyle.isScaleProteinAsCdna();
2794 public void setScaleProteinAsCdna(boolean b)
2796 viewStyle.setScaleProteinAsCdna(b);
2800 public boolean isProteinFontAsCdna()
2802 return viewStyle.isProteinFontAsCdna();
2806 public void setProteinFontAsCdna(boolean b)
2808 viewStyle.setProteinFontAsCdna(b);
2812 * @return true if view should scroll to show the highlighted region of a
2817 public final boolean isFollowHighlight()
2819 return followHighlight;
2823 public final void setFollowHighlight(boolean b)
2825 this.followHighlight = b;
2829 public ViewportRanges getRanges()
2835 * Helper method to populate the SearchResults with the location in the
2836 * complementary alignment to scroll to, in order to match this one.
2839 * the SearchResults to add to
2840 * @return the offset (below top of visible region) of the matched sequence
2842 protected int findComplementScrollTarget(SearchResultsI sr)
2844 final AlignViewportI complement = getCodingComplement();
2845 if (complement == null || !complement.isFollowHighlight())
2849 boolean iAmProtein = !getAlignment().isNucleotide();
2850 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2851 : complement.getAlignment();
2852 if (proteinAlignment == null)
2856 final List<AlignedCodonFrame> mappings = proteinAlignment
2860 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2861 * residue in the middle column of the visible region. Scroll the
2862 * complementary alignment to line up the corresponding residue.
2865 SequenceI sequence = null;
2868 * locate 'middle' column (true middle if an odd number visible, left of
2869 * middle if an even number visible)
2871 int middleColumn = ranges.getStartRes()
2872 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2873 final HiddenSequences hiddenSequences = getAlignment()
2874 .getHiddenSequences();
2877 * searching to the bottom of the alignment gives smoother scrolling across
2878 * all gapped visible regions
2880 int lastSeq = alignment.getHeight() - 1;
2881 List<AlignedCodonFrame> seqMappings = null;
2882 for (int seqNo = ranges
2883 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2885 sequence = getAlignment().getSequenceAt(seqNo);
2886 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2890 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2894 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2896 getCodingComplement().getAlignment().getSequences());
2897 if (!seqMappings.isEmpty())
2903 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2906 * No ungapped mapped sequence in middle column - do nothing
2910 MappingUtils.addSearchResults(sr, sequence,
2911 sequence.findPosition(middleColumn), seqMappings);
2916 * synthesize a column selection if none exists so it covers the given
2917 * selection group. if wholewidth is false, no column selection is made if the
2918 * selection group covers the whole alignment width.
2923 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2926 if (sg != null && (sgs = sg.getStartRes()) >= 0
2927 && sg.getStartRes() <= (sge = sg.getEndRes())
2928 && !this.hasSelectedColumns())
2930 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2937 colSel = new ColumnSelection();
2939 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2941 colSel.addElement(cspos);
2947 * hold status of current selection group - defined on alignment or not.
2949 private boolean selectionIsDefinedGroup = false;
2952 public boolean isSelectionDefinedGroup()
2954 if (selectionGroup == null)
2958 if (isSelectionGroupChanged(true))
2960 selectionIsDefinedGroup = false;
2961 List<SequenceGroup> gps = alignment.getGroups();
2962 if (gps == null || gps.size() == 0)
2964 selectionIsDefinedGroup = false;
2968 selectionIsDefinedGroup = gps.contains(selectionGroup);
2971 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2975 * null, or currently highlighted results on this view
2977 private SearchResultsI searchResults = null;
2979 protected TreeModel currentTree = null;
2982 public boolean hasSearchResults()
2984 return searchResults != null;
2988 public void setSearchResults(SearchResultsI results)
2990 searchResults = results;
2994 public SearchResultsI getSearchResults()
2996 return searchResults;
3000 * get the consensus sequence as displayed under the PID consensus annotation
3003 * @return consensus sequence as a new sequence object
3005 public SequenceI getConsensusSeq()
3007 if (consensus == null)
3009 updateConsensus(null);
3011 if (consensus == null)
3015 StringBuffer seqs = new StringBuffer();
3016 for (int i = 0; i < consensus.annotations.length; i++)
3018 Annotation annotation = consensus.annotations[i];
3019 if (annotation != null)
3021 String description = annotation.description;
3022 if (description != null && description.startsWith("["))
3024 // consensus is a tie - just pick the first one
3025 seqs.append(description.charAt(1));
3029 seqs.append(annotation.displayCharacter);
3034 SequenceI sq = new Sequence("Consensus", seqs.toString());
3035 sq.setDescription("Percentage Identity Consensus "
3036 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3040 public boolean hasReferenceAnnotation()
3042 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3043 for (AlignmentAnnotation annot : annots)
3045 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3054 public void setCurrentTree(TreeModel tree)
3060 public TreeModel getCurrentTree()
3066 public boolean isNormaliseSequenceLogo()
3068 return normaliseSequenceLogo;
3071 public void setNormaliseSequenceLogo(boolean state)
3073 normaliseSequenceLogo = state;
3077 public boolean isNormaliseHMMSequenceLogo()
3079 return hmmNormaliseSequenceLogo;
3082 public void setNormaliseHMMSequenceLogo(boolean state)
3084 hmmNormaliseSequenceLogo = state;