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,
1770 public SequenceI[] getSequenceSelection()
1772 SequenceI[] sequences = null;
1773 if (selectionGroup != null)
1775 sequences = selectionGroup.getSequencesInOrder(alignment);
1777 if (sequences == null)
1779 sequences = alignment.getSequencesArray();
1785 public jalview.datamodel.AlignmentView getAlignmentView(
1786 boolean selectedOnly)
1788 return getAlignmentView(selectedOnly, false);
1792 public jalview.datamodel.AlignmentView getAlignmentView(
1793 boolean selectedOnly, boolean markGroups)
1795 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1797 alignment.getHiddenColumns() != null
1798 && alignment.getHiddenColumns().hasHiddenColumns(),
1799 selectedOnly, markGroups);
1803 public String[] getViewAsString(boolean selectedRegionOnly)
1805 return getViewAsString(selectedRegionOnly, true);
1809 public String[] getViewAsString(boolean selectedRegionOnly,
1810 boolean exportHiddenSeqs)
1812 String[] selection = null;
1813 SequenceI[] seqs = null;
1815 int start = 0, end = 0;
1816 if (selectedRegionOnly && selectionGroup != null)
1818 iSize = selectionGroup.getSize();
1819 seqs = selectionGroup.getSequencesInOrder(alignment);
1820 start = selectionGroup.getStartRes();
1821 end = selectionGroup.getEndRes() + 1;
1825 if (hasHiddenRows() && exportHiddenSeqs)
1827 AlignmentI fullAlignment = alignment.getHiddenSequences()
1828 .getFullAlignment();
1829 iSize = fullAlignment.getHeight();
1830 seqs = fullAlignment.getSequencesArray();
1831 end = fullAlignment.getWidth();
1835 iSize = alignment.getHeight();
1836 seqs = alignment.getSequencesArray();
1837 end = alignment.getWidth();
1841 selection = new String[iSize];
1842 if (alignment.getHiddenColumns() != null
1843 && alignment.getHiddenColumns().hasHiddenColumns())
1845 for (i = 0; i < iSize; i++)
1847 Iterator<int[]> blocks = alignment.getHiddenColumns()
1848 .getVisContigsIterator(start, end + 1, false);
1849 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1854 for (i = 0; i < iSize; i++)
1856 selection[i] = seqs[i].getSequenceAsString(start, end);
1864 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1866 ArrayList<int[]> regions = new ArrayList<>();
1872 HiddenColumns hidden = alignment.getHiddenColumns();
1873 if (hidden != null && hidden.hasHiddenColumns())
1877 start = hidden.visibleToAbsoluteColumn(start);
1880 end = hidden.getNextHiddenBoundary(false, start);
1891 regions.add(new int[] { start, end });
1893 if (hidden != null && hidden.hasHiddenColumns())
1895 start = hidden.visibleToAbsoluteColumn(end);
1896 start = hidden.getNextHiddenBoundary(true, start) + 1;
1898 } while (end < max);
1900 int[][] startEnd = new int[regions.size()][2];
1906 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1907 boolean selectedOnly)
1909 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1910 AlignmentAnnotation[] aa;
1911 if ((aa = alignment.getAlignmentAnnotation()) != null)
1913 for (AlignmentAnnotation annot : aa)
1915 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1916 if (selectedOnly && selectionGroup != null)
1918 clone.makeVisibleAnnotation(
1919 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1920 alignment.getHiddenColumns());
1924 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1933 public boolean isPadGaps()
1939 public void setPadGaps(boolean padGaps)
1941 this.padGaps = padGaps;
1945 * apply any post-edit constraints and trigger any calculations needed after
1946 * an edit has been performed on the alignment
1951 public void alignmentChanged(AlignmentViewPanel ap)
1955 alignment.padGaps();
1958 // Reset endRes of groups if beyond alignment width
1959 int alWidth = alignment.getWidth();
1960 List<SequenceGroup> groups = alignment.getGroups();
1963 for (SequenceGroup sg : groups)
1965 if (sg.getEndRes() > alWidth)
1967 sg.setEndRes(alWidth - 1);
1972 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1974 selectionGroup.setEndRes(alWidth - 1);
1977 updateAllColourSchemes();
1978 calculator.restartWorkers();
1982 * reset scope and do calculations for all applied colourschemes on alignment
1984 void updateAllColourSchemes()
1986 ResidueShaderI rs = residueShading;
1989 rs.alignmentChanged(alignment, hiddenRepSequences);
1991 rs.setConsensus(consensusProfiles);
1992 if (rs.conservationApplied())
1994 rs.setConservation(Conservation.calculateConservation("All",
1995 alignment.getSequences(), 0, alignment.getWidth(), false,
1996 getConsPercGaps(), false));
2000 for (SequenceGroup sg : alignment.getGroups())
2004 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2006 sg.recalcConservation();
2010 protected void initAutoAnnotation()
2012 // TODO: add menu option action that nulls or creates consensus object
2013 // depending on if the user wants to see the annotation or not in a
2014 // specific alignment
2016 if (consensusProfiles == null && !isDataset)
2018 if (!alignment.isNucleotide())
2027 consensus = new AlignmentAnnotation("Consensus",
2028 MessageManager.getString("label.consensus_descr"),
2029 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2030 initConsensus(consensus);
2034 initComplementConsensus();
2039 * If this is a protein alignment and there are mappings to cDNA, adds the
2040 * cDNA consensus annotation and returns true, else returns false.
2042 public boolean initComplementConsensus()
2044 if (!alignment.isNucleotide())
2046 final List<AlignedCodonFrame> codonMappings = alignment
2048 if (codonMappings != null && !codonMappings.isEmpty())
2050 boolean doConsensus = false;
2051 for (AlignedCodonFrame mapping : codonMappings)
2053 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2054 MapList[] mapLists = mapping.getdnaToProt();
2055 // mapLists can be empty if project load has not finished resolving
2057 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2065 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2067 .getString("label.complement_consensus_descr"),
2068 new Annotation[1], 0f, 100f,
2069 AlignmentAnnotation.BAR_GRAPH);
2070 initConsensus(complementConsensus);
2078 private void initConsensus(AlignmentAnnotation aa)
2081 aa.autoCalculated = true;
2085 alignment.addAnnotation(aa);
2089 // these should be extracted from the view model - style and settings for
2090 // derived annotation
2091 private void initOccupancy()
2095 occupancy = new AlignmentAnnotation("Occupancy",
2096 MessageManager.getString("label.occupancy_descr"),
2097 new Annotation[1], 0f, alignment.getHeight(),
2098 AlignmentAnnotation.BAR_GRAPH);
2099 occupancy.hasText = true;
2100 occupancy.autoCalculated = true;
2101 occupancy.scaleColLabel = true;
2102 occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
2104 alignment.addAnnotation(occupancy);
2108 private void initConservation()
2110 if (showConservation)
2112 if (conservation == null)
2114 conservation = new AlignmentAnnotation("Conservation",
2115 MessageManager.formatMessage("label.conservation_descr",
2117 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2118 conservation.hasText = true;
2119 conservation.autoCalculated = true;
2120 alignment.addAnnotation(conservation);
2125 private void initQuality()
2129 if (quality == null)
2131 quality = new AlignmentAnnotation("Quality",
2132 MessageManager.getString("label.quality_descr"),
2133 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2134 quality.hasText = true;
2135 quality.autoCalculated = true;
2136 alignment.addAnnotation(quality);
2141 private void initRNAStructure()
2143 if (alignment.hasRNAStructure() && strucConsensus == null)
2145 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2146 MessageManager.getString("label.strucconsensus_descr"),
2147 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2148 strucConsensus.hasText = true;
2149 strucConsensus.autoCalculated = true;
2153 alignment.addAnnotation(strucConsensus);
2161 * @see jalview.api.AlignViewportI#calcPanelHeight()
2164 public int calcPanelHeight()
2166 // setHeight of panels
2167 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2169 int charHeight = getCharHeight();
2172 BitSet graphgrp = new BitSet();
2173 for (AlignmentAnnotation aa : anns)
2177 System.err.println("Null annotation row: ignoring.");
2184 if (aa.graphGroup > -1)
2186 if (graphgrp.get(aa.graphGroup))
2192 graphgrp.set(aa.graphGroup);
2199 aa.height += charHeight;
2209 aa.height += aa.graphHeight;
2217 height += aa.height;
2229 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2230 boolean preserveNewGroupSettings)
2232 boolean updateCalcs = false;
2233 boolean conv = isShowGroupConservation();
2234 boolean cons = isShowGroupConsensus();
2235 boolean showprf = isShowSequenceLogo();
2236 boolean showConsHist = isShowConsensusHistogram();
2237 boolean normLogo = isNormaliseSequenceLogo();
2238 boolean showHMMPrf = isShowHMMSequenceLogo();
2239 boolean showInfoHist = isShowInformationHistogram();
2240 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2243 * TODO reorder the annotation rows according to group/sequence ordering on
2246 boolean sortg = true;
2248 // remove old automatic annotation
2249 // add any new annotation
2251 // intersect alignment annotation with alignment groups
2253 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2254 List<SequenceGroup> oldrfs = new ArrayList<>();
2257 for (int an = 0; an < aan.length; an++)
2259 if (aan[an].autoCalculated && aan[an].groupRef != null)
2261 oldrfs.add(aan[an].groupRef);
2262 alignment.deleteAnnotation(aan[an], false);
2266 if (alignment.getGroups() != null)
2268 for (SequenceGroup sg : alignment.getGroups())
2270 updateCalcs = false;
2271 if (applyGlobalSettings
2272 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2274 // set defaults for this group's conservation/consensus
2275 sg.setshowSequenceLogo(showprf);
2276 sg.setShowConsensusHistogram(showConsHist);
2277 sg.setNormaliseSequenceLogo(normLogo);
2278 sg.setShowHMMSequenceLogo(showHMMPrf);
2279 sg.setShowInformationHistogram(showInfoHist);
2280 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2285 alignment.addAnnotation(sg.getConservationRow(), 0);
2290 alignment.addAnnotation(sg.getConsensus(), 0);
2292 // refresh the annotation rows
2295 sg.recalcConservation();
2303 public boolean isDisplayReferenceSeq()
2305 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2309 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2311 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2315 public boolean isColourByReferenceSeq()
2317 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2321 public Color getSequenceColour(SequenceI seq)
2323 Color sqc = sequenceColours.get(seq);
2324 return (sqc == null ? Color.white : sqc);
2328 public void setSequenceColour(SequenceI seq, Color col)
2332 sequenceColours.remove(seq);
2336 sequenceColours.put(seq, col);
2341 public void updateSequenceIdColours()
2343 for (SequenceGroup sg : alignment.getGroups())
2345 if (sg.idColour != null)
2347 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2349 sequenceColours.put(s, sg.idColour);
2356 public void clearSequenceColours()
2358 sequenceColours.clear();
2362 public AlignViewportI getCodingComplement()
2364 return this.codingComplement;
2368 * Set this as the (cDna/protein) complement of the given viewport. Also
2369 * ensures the reverse relationship is set on the given viewport.
2372 public void setCodingComplement(AlignViewportI av)
2376 System.err.println("Ignoring recursive setCodingComplement request");
2380 this.codingComplement = av;
2381 // avoid infinite recursion!
2382 if (av.getCodingComplement() != this)
2384 av.setCodingComplement(this);
2390 public boolean isNucleotide()
2392 return getAlignment() == null ? false : getAlignment().isNucleotide();
2396 public FeaturesDisplayedI getFeaturesDisplayed()
2398 return featuresDisplayed;
2402 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2404 featuresDisplayed = featuresDisplayedI;
2408 public boolean areFeaturesDisplayed()
2410 return featuresDisplayed != null
2411 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2418 * features are displayed if true
2421 public void setShowSequenceFeatures(boolean b)
2423 viewStyle.setShowSequenceFeatures(b);
2427 public boolean isShowSequenceFeatures()
2429 return viewStyle.isShowSequenceFeatures();
2433 public void setShowSequenceFeaturesHeight(boolean selected)
2435 viewStyle.setShowSequenceFeaturesHeight(selected);
2439 public boolean isShowSequenceFeaturesHeight()
2441 return viewStyle.isShowSequenceFeaturesHeight();
2445 public void setShowAnnotation(boolean b)
2447 viewStyle.setShowAnnotation(b);
2451 public boolean isShowAnnotation()
2453 return viewStyle.isShowAnnotation();
2457 public boolean isRightAlignIds()
2459 return viewStyle.isRightAlignIds();
2463 public void setRightAlignIds(boolean rightAlignIds)
2465 viewStyle.setRightAlignIds(rightAlignIds);
2469 public boolean getConservationSelected()
2471 return viewStyle.getConservationSelected();
2475 public void setShowBoxes(boolean state)
2477 viewStyle.setShowBoxes(state);
2482 * @see jalview.api.ViewStyleI#getTextColour()
2485 public Color getTextColour()
2487 return viewStyle.getTextColour();
2492 * @see jalview.api.ViewStyleI#getTextColour2()
2495 public Color getTextColour2()
2497 return viewStyle.getTextColour2();
2502 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2505 public int getThresholdTextColour()
2507 return viewStyle.getThresholdTextColour();
2512 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2515 public boolean isConservationColourSelected()
2517 return viewStyle.isConservationColourSelected();
2522 * @see jalview.api.ViewStyleI#isRenderGaps()
2525 public boolean isRenderGaps()
2527 return viewStyle.isRenderGaps();
2532 * @see jalview.api.ViewStyleI#isShowColourText()
2535 public boolean isShowColourText()
2537 return viewStyle.isShowColourText();
2541 * @param conservationColourSelected
2542 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2545 public void setConservationColourSelected(
2546 boolean conservationColourSelected)
2548 viewStyle.setConservationColourSelected(conservationColourSelected);
2552 * @param showColourText
2553 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2556 public void setShowColourText(boolean showColourText)
2558 viewStyle.setShowColourText(showColourText);
2563 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2566 public void setTextColour(Color textColour)
2568 viewStyle.setTextColour(textColour);
2572 * @param thresholdTextColour
2573 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2576 public void setThresholdTextColour(int thresholdTextColour)
2578 viewStyle.setThresholdTextColour(thresholdTextColour);
2582 * @param textColour2
2583 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2586 public void setTextColour2(Color textColour2)
2588 viewStyle.setTextColour2(textColour2);
2592 public ViewStyleI getViewStyle()
2594 return new ViewStyle(viewStyle);
2598 public void setViewStyle(ViewStyleI settingsForView)
2600 viewStyle = new ViewStyle(settingsForView);
2601 if (residueShading != null)
2603 residueShading.setConservationApplied(
2604 settingsForView.isConservationColourSelected());
2609 public boolean sameStyle(ViewStyleI them)
2611 return viewStyle.sameStyle(them);
2616 * @see jalview.api.ViewStyleI#getIdWidth()
2619 public int getIdWidth()
2621 return viewStyle.getIdWidth();
2626 * @see jalview.api.ViewStyleI#setIdWidth(int)
2629 public void setIdWidth(int i)
2631 viewStyle.setIdWidth(i);
2636 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2639 public boolean isCentreColumnLabels()
2641 return viewStyle.isCentreColumnLabels();
2645 * @param centreColumnLabels
2646 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2649 public void setCentreColumnLabels(boolean centreColumnLabels)
2651 viewStyle.setCentreColumnLabels(centreColumnLabels);
2656 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2659 public void setShowDBRefs(boolean showdbrefs)
2661 viewStyle.setShowDBRefs(showdbrefs);
2666 * @see jalview.api.ViewStyleI#isShowDBRefs()
2669 public boolean isShowDBRefs()
2671 return viewStyle.isShowDBRefs();
2676 * @see jalview.api.ViewStyleI#isShowNPFeats()
2679 public boolean isShowNPFeats()
2681 return viewStyle.isShowNPFeats();
2685 * @param shownpfeats
2686 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2689 public void setShowNPFeats(boolean shownpfeats)
2691 viewStyle.setShowNPFeats(shownpfeats);
2694 public abstract StructureSelectionManager getStructureSelectionManager();
2697 * Add one command to the command history list.
2701 public void addToHistoryList(CommandI command)
2703 if (this.historyList != null)
2705 this.historyList.push(command);
2706 broadcastCommand(command, false);
2710 protected void broadcastCommand(CommandI command, boolean undo)
2712 getStructureSelectionManager().commandPerformed(command, undo,
2717 * Add one command to the command redo list.
2721 public void addToRedoList(CommandI command)
2723 if (this.redoList != null)
2725 this.redoList.push(command);
2727 broadcastCommand(command, true);
2731 * Clear the command redo list.
2733 public void clearRedoList()
2735 if (this.redoList != null)
2737 this.redoList.clear();
2741 public void setHistoryList(Deque<CommandI> list)
2743 this.historyList = list;
2746 public Deque<CommandI> getHistoryList()
2748 return this.historyList;
2751 public void setRedoList(Deque<CommandI> list)
2753 this.redoList = list;
2756 public Deque<CommandI> getRedoList()
2758 return this.redoList;
2762 public VamsasSource getVamsasSource()
2767 public SequenceAnnotationOrder getSortAnnotationsBy()
2769 return sortAnnotationsBy;
2772 public void setSortAnnotationsBy(
2773 SequenceAnnotationOrder sortAnnotationsBy)
2775 this.sortAnnotationsBy = sortAnnotationsBy;
2778 public boolean isShowAutocalculatedAbove()
2780 return showAutocalculatedAbove;
2783 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2785 this.showAutocalculatedAbove = showAutocalculatedAbove;
2789 public boolean isScaleProteinAsCdna()
2791 return viewStyle.isScaleProteinAsCdna();
2795 public void setScaleProteinAsCdna(boolean b)
2797 viewStyle.setScaleProteinAsCdna(b);
2801 public boolean isProteinFontAsCdna()
2803 return viewStyle.isProteinFontAsCdna();
2807 public void setProteinFontAsCdna(boolean b)
2809 viewStyle.setProteinFontAsCdna(b);
2813 * @return true if view should scroll to show the highlighted region of a
2818 public final boolean isFollowHighlight()
2820 return followHighlight;
2824 public final void setFollowHighlight(boolean b)
2826 this.followHighlight = b;
2830 public ViewportRanges getRanges()
2836 * Helper method to populate the SearchResults with the location in the
2837 * complementary alignment to scroll to, in order to match this one.
2840 * the SearchResults to add to
2841 * @return the offset (below top of visible region) of the matched sequence
2843 protected int findComplementScrollTarget(SearchResultsI sr)
2845 final AlignViewportI complement = getCodingComplement();
2846 if (complement == null || !complement.isFollowHighlight())
2850 boolean iAmProtein = !getAlignment().isNucleotide();
2851 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2852 : complement.getAlignment();
2853 if (proteinAlignment == null)
2857 final List<AlignedCodonFrame> mappings = proteinAlignment
2861 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2862 * residue in the middle column of the visible region. Scroll the
2863 * complementary alignment to line up the corresponding residue.
2866 SequenceI sequence = null;
2869 * locate 'middle' column (true middle if an odd number visible, left of
2870 * middle if an even number visible)
2872 int middleColumn = ranges.getStartRes()
2873 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2874 final HiddenSequences hiddenSequences = getAlignment()
2875 .getHiddenSequences();
2878 * searching to the bottom of the alignment gives smoother scrolling across
2879 * all gapped visible regions
2881 int lastSeq = alignment.getHeight() - 1;
2882 List<AlignedCodonFrame> seqMappings = null;
2883 for (int seqNo = ranges
2884 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2886 sequence = getAlignment().getSequenceAt(seqNo);
2887 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2891 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2895 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2897 getCodingComplement().getAlignment().getSequences());
2898 if (!seqMappings.isEmpty())
2904 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2907 * No ungapped mapped sequence in middle column - do nothing
2911 MappingUtils.addSearchResults(sr, sequence,
2912 sequence.findPosition(middleColumn), seqMappings);
2917 * synthesize a column selection if none exists so it covers the given
2918 * selection group. if wholewidth is false, no column selection is made if the
2919 * selection group covers the whole alignment width.
2924 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2927 if (sg != null && (sgs = sg.getStartRes()) >= 0
2928 && sg.getStartRes() <= (sge = sg.getEndRes())
2929 && !this.hasSelectedColumns())
2931 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2938 colSel = new ColumnSelection();
2940 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2942 colSel.addElement(cspos);
2948 * hold status of current selection group - defined on alignment or not.
2950 private boolean selectionIsDefinedGroup = false;
2953 public boolean isSelectionDefinedGroup()
2955 if (selectionGroup == null)
2959 if (isSelectionGroupChanged(true))
2961 selectionIsDefinedGroup = false;
2962 List<SequenceGroup> gps = alignment.getGroups();
2963 if (gps == null || gps.size() == 0)
2965 selectionIsDefinedGroup = false;
2969 selectionIsDefinedGroup = gps.contains(selectionGroup);
2972 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2976 * null, or currently highlighted results on this view
2978 private SearchResultsI searchResults = null;
2980 protected TreeModel currentTree = null;
2983 public boolean hasSearchResults()
2985 return searchResults != null;
2989 public void setSearchResults(SearchResultsI results)
2991 searchResults = results;
2995 public SearchResultsI getSearchResults()
2997 return searchResults;
3001 * get the consensus sequence as displayed under the PID consensus annotation
3004 * @return consensus sequence as a new sequence object
3006 public SequenceI getConsensusSeq()
3008 if (consensus == null)
3010 updateConsensus(null);
3012 if (consensus == null)
3016 StringBuffer seqs = new StringBuffer();
3017 for (int i = 0; i < consensus.annotations.length; i++)
3019 Annotation annotation = consensus.annotations[i];
3020 if (annotation != null)
3022 String description = annotation.description;
3023 if (description != null && description.startsWith("["))
3025 // consensus is a tie - just pick the first one
3026 seqs.append(description.charAt(1));
3030 seqs.append(annotation.displayCharacter);
3035 SequenceI sq = new Sequence("Consensus", seqs.toString());
3036 sq.setDescription("Percentage Identity Consensus "
3037 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3041 public boolean hasReferenceAnnotation()
3043 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3044 for (AlignmentAnnotation annot : annots)
3046 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3055 public void setCurrentTree(TreeModel tree)
3061 public TreeModel getCurrentTree()
3067 public boolean isNormaliseSequenceLogo()
3069 return normaliseSequenceLogo;
3072 public void setNormaliseSequenceLogo(boolean state)
3074 normaliseSequenceLogo = state;
3078 public boolean isNormaliseHMMSequenceLogo()
3080 return hmmNormaliseSequenceLogo;
3083 public void setNormaliseHMMSequenceLogo(boolean state)
3085 hmmNormaliseSequenceLogo = state;