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.List;
75 * base class holding visualization and analysis attributes and common logic for
76 * an active alignment view displayed in the GUI
81 public abstract class AlignmentViewport
82 implements AlignViewportI, CommandListener, VamsasSource
84 protected ViewportRanges ranges;
86 protected ViewStyleI viewStyle = new ViewStyle();
89 * A viewport that hosts the cDna view of this (protein), or vice versa (if
92 AlignViewportI codingComplement = null;
94 FeaturesDisplayedI featuresDisplayed = null;
96 protected Deque<CommandI> historyList = new ArrayDeque<>();
98 protected Deque<CommandI> redoList = new ArrayDeque<>();
100 protected String sequenceSetID;
103 * probably unused indicator that view is of a dataset rather than an
106 protected boolean isDataset = false;
108 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
110 protected ColumnSelection colSel = new ColumnSelection();
112 public boolean autoCalculateConsensus = true;
114 protected boolean autoCalculateStrucConsensus = true;
116 protected boolean ignoreGapsInConsensusCalculation = false;
118 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
120 protected boolean infoLetterHeight = false;
122 protected ResidueShaderI residueShading = new ResidueShader();
124 protected AlignmentAnnotation consensus;
126 protected AlignmentAnnotation complementConsensus;
128 protected AlignmentAnnotation occupancy;
130 protected AlignmentAnnotation strucConsensus;
132 protected AlignmentAnnotation conservation;
134 protected AlignmentAnnotation quality;
137 * alignment displayed in the viewport
139 private AlignmentI alignment;
142 * results of alignment consensus analysis for visible portion of view
144 protected ProfilesI consensusProfiles;
147 * HMM profile for the alignment
149 protected ProfilesI hmmProfiles;
152 * results of cDNA complement consensus visible portion of view
154 protected Hashtable[] hcomplementConsensus;
157 * results of secondary structure base pair consensus for visible portion of
160 protected Hashtable[] hStrucConsensus;
162 protected Conservation hconservation;
164 public AlignmentViewport(AlignmentI al)
167 ranges = new ViewportRanges(al);
172 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
175 public void setFontName(String name)
177 viewStyle.setFontName(name);
182 * @see jalview.api.ViewStyleI#setFontStyle(int)
185 public void setFontStyle(int style)
187 viewStyle.setFontStyle(style);
192 * @see jalview.api.ViewStyleI#setFontSize(int)
195 public void setFontSize(int size)
197 viewStyle.setFontSize(size);
202 * @see jalview.api.ViewStyleI#getFontStyle()
205 public int getFontStyle()
207 return viewStyle.getFontStyle();
212 * @see jalview.api.ViewStyleI#getFontName()
215 public String getFontName()
217 return viewStyle.getFontName();
222 * @see jalview.api.ViewStyleI#getFontSize()
225 public int getFontSize()
227 return viewStyle.getFontSize();
231 * @param upperCasebold
232 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
235 public void setUpperCasebold(boolean upperCasebold)
237 viewStyle.setUpperCasebold(upperCasebold);
242 * @see jalview.api.ViewStyleI#isUpperCasebold()
245 public boolean isUpperCasebold()
247 return viewStyle.isUpperCasebold();
252 * @see jalview.api.ViewStyleI#isSeqNameItalics()
255 public boolean isSeqNameItalics()
257 return viewStyle.isSeqNameItalics();
261 * @param colourByReferenceSeq
262 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
265 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
267 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
272 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
275 public void setColourAppliesToAllGroups(boolean b)
277 viewStyle.setColourAppliesToAllGroups(b);
282 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
285 public boolean getColourAppliesToAllGroups()
287 return viewStyle.getColourAppliesToAllGroups();
292 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
295 public boolean getAbovePIDThreshold()
297 return viewStyle.getAbovePIDThreshold();
302 * @see jalview.api.ViewStyleI#setIncrement(int)
305 public void setIncrement(int inc)
307 viewStyle.setIncrement(inc);
312 * @see jalview.api.ViewStyleI#getIncrement()
315 public int getIncrement()
317 return viewStyle.getIncrement();
322 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
325 public void setConservationSelected(boolean b)
327 viewStyle.setConservationSelected(b);
332 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
335 public void setShowHiddenMarkers(boolean show)
337 viewStyle.setShowHiddenMarkers(show);
342 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
345 public boolean getShowHiddenMarkers()
347 return viewStyle.getShowHiddenMarkers();
352 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
355 public void setScaleRightWrapped(boolean b)
357 viewStyle.setScaleRightWrapped(b);
362 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
365 public void setScaleLeftWrapped(boolean b)
367 viewStyle.setScaleLeftWrapped(b);
372 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
375 public void setScaleAboveWrapped(boolean b)
377 viewStyle.setScaleAboveWrapped(b);
382 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
385 public boolean getScaleLeftWrapped()
387 return viewStyle.getScaleLeftWrapped();
392 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
395 public boolean getScaleAboveWrapped()
397 return viewStyle.getScaleAboveWrapped();
402 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
405 public boolean getScaleRightWrapped()
407 return viewStyle.getScaleRightWrapped();
412 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
415 public void setAbovePIDThreshold(boolean b)
417 viewStyle.setAbovePIDThreshold(b);
422 * @see jalview.api.ViewStyleI#setThreshold(int)
425 public void setThreshold(int thresh)
427 viewStyle.setThreshold(thresh);
432 * @see jalview.api.ViewStyleI#getThreshold()
435 public int getThreshold()
437 return viewStyle.getThreshold();
442 * @see jalview.api.ViewStyleI#getShowJVSuffix()
445 public boolean getShowJVSuffix()
447 return viewStyle.getShowJVSuffix();
452 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
455 public void setShowJVSuffix(boolean b)
457 viewStyle.setShowJVSuffix(b);
462 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
465 public void setWrapAlignment(boolean state)
467 viewStyle.setWrapAlignment(state);
468 ranges.setWrappedMode(state);
473 * @see jalview.api.ViewStyleI#setShowText(boolean)
476 public void setShowText(boolean state)
478 viewStyle.setShowText(state);
483 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
486 public void setRenderGaps(boolean state)
488 viewStyle.setRenderGaps(state);
493 * @see jalview.api.ViewStyleI#getColourText()
496 public boolean getColourText()
498 return viewStyle.getColourText();
503 * @see jalview.api.ViewStyleI#setColourText(boolean)
506 public void setColourText(boolean state)
508 viewStyle.setColourText(state);
513 * @see jalview.api.ViewStyleI#getWrapAlignment()
516 public boolean getWrapAlignment()
518 return viewStyle.getWrapAlignment();
523 * @see jalview.api.ViewStyleI#getShowText()
526 public boolean getShowText()
528 return viewStyle.getShowText();
533 * @see jalview.api.ViewStyleI#getWrappedWidth()
536 public int getWrappedWidth()
538 return viewStyle.getWrappedWidth();
543 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
546 public void setWrappedWidth(int w)
548 viewStyle.setWrappedWidth(w);
553 * @see jalview.api.ViewStyleI#getCharHeight()
556 public int getCharHeight()
558 return viewStyle.getCharHeight();
563 * @see jalview.api.ViewStyleI#setCharHeight(int)
566 public void setCharHeight(int h)
568 viewStyle.setCharHeight(h);
573 * @see jalview.api.ViewStyleI#getCharWidth()
576 public int getCharWidth()
578 return viewStyle.getCharWidth();
583 * @see jalview.api.ViewStyleI#setCharWidth(int)
586 public void setCharWidth(int w)
588 viewStyle.setCharWidth(w);
593 * @see jalview.api.ViewStyleI#getShowBoxes()
596 public boolean getShowBoxes()
598 return viewStyle.getShowBoxes();
603 * @see jalview.api.ViewStyleI#getShowUnconserved()
606 public boolean getShowUnconserved()
608 return viewStyle.getShowUnconserved();
612 * @param showunconserved
613 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
616 public void setShowUnconserved(boolean showunconserved)
618 viewStyle.setShowUnconserved(showunconserved);
623 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
626 public void setSeqNameItalics(boolean default1)
628 viewStyle.setSeqNameItalics(default1);
632 public AlignmentI getAlignment()
638 public char getGapCharacter()
640 return alignment.getGapCharacter();
643 public void setDataset(boolean b)
648 public boolean isDataset()
654 public void setGlobalColourScheme(ColourSchemeI cs)
656 // TODO: logic refactored from AlignFrame changeColour -
657 // TODO: autorecalc stuff should be changed to rely on the worker system
658 // check to see if we should implement a changeColour(cs) method rather than
659 // put the logic in here
660 // - means that caller decides if they want to just modify state and defer
661 // calculation till later or to do all calculations in thread.
665 * only instantiate alignment colouring once, thereafter update it;
666 * this means that any conservation or PID threshold settings
667 * persist when the alignment colour scheme is changed
669 if (residueShading == null)
671 residueShading = new ResidueShader(viewStyle);
673 residueShading.setColourScheme(cs);
675 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
676 // ...problem: groups need these, but do not currently have a ViewStyle
680 if (getConservationSelected())
682 residueShading.setConservation(hconservation);
685 * reset conservation flag in case just set to false if
686 * Conservation was null (calculation still in progress)
688 residueShading.setConservationApplied(getConservationSelected());
689 residueShading.alignmentChanged(alignment, hiddenRepSequences);
693 * if 'apply colour to all groups' is selected... do so
694 * (but don't transfer any colour threshold settings to groups)
696 if (getColourAppliesToAllGroups())
698 for (SequenceGroup sg : getAlignment().getGroups())
701 * retain any colour thresholds per group while
702 * changing choice of colour scheme (JAL-2386)
704 sg.setColourScheme(cs);
707 sg.getGroupColourScheme().alignmentChanged(sg,
715 public ColourSchemeI getGlobalColourScheme()
717 return residueShading == null ? null : residueShading.getColourScheme();
721 public ResidueShaderI getResidueShading()
723 return residueShading;
726 public void setConservation(Conservation cons)
728 hconservation = cons;
732 * percentage gaps allowed in a column before all amino acid properties should
733 * be considered unconserved
735 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
738 public int getConsPercGaps()
744 public void setConsensusProfiles(ProfilesI hconsensus)
746 this.consensusProfiles = hconsensus;
750 public void setComplementConsensusHash(Hashtable[] hconsensus)
752 this.hcomplementConsensus = hconsensus;
756 public ProfilesI getConsensusProfiles()
758 return consensusProfiles;
762 public void setHmmProfiles(ProfilesI info)
768 public ProfilesI getHmmProfiles()
774 public Hashtable[] getComplementConsensusHash()
776 return hcomplementConsensus;
780 public Hashtable[] getRnaStructureConsensusHash()
782 return hStrucConsensus;
786 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
788 this.hStrucConsensus = hStrucConsensus;
793 public AlignmentAnnotation getAlignmentQualityAnnot()
799 public AlignmentAnnotation getAlignmentConservationAnnotation()
805 public AlignmentAnnotation getAlignmentConsensusAnnotation()
811 public AlignmentAnnotation getOccupancyAnnotation()
817 public AlignmentAnnotation getComplementConsensusAnnotation()
819 return complementConsensus;
823 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
825 return strucConsensus;
828 protected AlignCalcManagerI calculator = new AlignCalcManager();
831 * trigger update of conservation annotation
833 public void updateConservation(final AlignmentViewPanel ap)
835 // see note in mantis : issue number 8585
836 if (alignment.isNucleotide()
837 || (conservation == null && quality == null)
838 || !autoCalculateConsensus)
842 if (calculator.getRegisteredWorkersOfClass(
843 jalview.workers.ConservationThread.class) == null)
845 calculator.registerWorker(
846 new jalview.workers.ConservationThread(this, ap));
851 * trigger update of consensus annotation
853 public void updateConsensus(final AlignmentViewPanel ap)
855 // see note in mantis : issue number 8585
856 if (consensus == null || !autoCalculateConsensus)
861 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
863 calculator.registerWorker(new ConsensusThread(this, ap));
867 * A separate thread to compute cDNA consensus for a protein alignment
868 * which has mapping to cDNA
870 final AlignmentI al = this.getAlignment();
871 if (!al.isNucleotide() && al.getCodonFrames() != null
872 && !al.getCodonFrames().isEmpty())
875 * fudge - check first for protein-to-nucleotide mappings
876 * (we don't want to do this for protein-to-protein)
878 boolean doConsensus = false;
879 for (AlignedCodonFrame mapping : al.getCodonFrames())
881 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
882 MapList[] mapLists = mapping.getdnaToProt();
883 // mapLists can be empty if project load has not finished resolving seqs
884 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
892 if (calculator.getRegisteredWorkersOfClass(
893 ComplementConsensusThread.class) == null)
896 .registerWorker(new ComplementConsensusThread(this, ap));
903 * trigger update of information annotation
906 public void updateInformation(final AlignmentViewPanel ap)
909 .getRegisteredWorkersOfClass(InformationThread.class) == null)
911 calculator.registerWorker(new InformationThread(this, ap));
916 // --------START Structure Conservation
917 public void updateStrucConsensus(final AlignmentViewPanel ap)
919 if (autoCalculateStrucConsensus && strucConsensus == null
920 && alignment.isNucleotide() && alignment.hasRNAStructure())
922 // secondary structure has been added - so init the consensus line
926 // see note in mantis : issue number 8585
927 if (strucConsensus == null || !autoCalculateStrucConsensus)
931 if (calculator.getRegisteredWorkersOfClass(
932 StrucConsensusThread.class) == null)
934 calculator.registerWorker(new StrucConsensusThread(this, ap));
938 public boolean isCalcInProgress()
940 return calculator.isWorking();
944 public boolean isCalculationInProgress(
945 AlignmentAnnotation alignmentAnnotation)
947 if (!alignmentAnnotation.autoCalculated)
951 if (calculator.workingInvolvedWith(alignmentAnnotation))
953 // System.err.println("grey out ("+alignmentAnnotation.label+")");
959 public void setAlignment(AlignmentI align)
961 this.alignment = align;
965 * Clean up references when this viewport is closed
968 public void dispose()
971 * defensively null out references to large objects in case
972 * this object is not garbage collected (as if!)
975 complementConsensus = null;
976 strucConsensus = null;
979 consensusProfiles = null;
980 hconservation = null;
981 hcomplementConsensus = null;
984 residueShading = null; // may hold a reference to Consensus
985 changeSupport = null;
988 selectionGroup = null;
993 public boolean isClosed()
995 // TODO: check that this isClosed is only true after panel is closed, not
996 // before it is fully constructed.
997 return alignment == null;
1001 public AlignCalcManagerI getCalcManager()
1007 * should conservation rows be shown for groups
1009 protected boolean showGroupConservation = false;
1012 * should consensus rows be shown for groups
1014 protected boolean showGroupConsensus = false;
1017 * should consensus profile be rendered by default
1019 protected boolean showSequenceLogo = false;
1022 * should consensus profile be rendered normalised to row height
1024 protected boolean normaliseSequenceLogo = false;
1027 * should consensus histograms be rendered by default
1029 protected boolean showConsensusHistogram = true;
1032 * should hmm profile be rendered by default
1034 protected boolean showHMMSequenceLogo = false;
1037 * should hmm profile be rendered normalised to row height
1039 protected boolean normaliseHMMSequenceLogo = false;
1042 * should information histograms be rendered by default
1044 protected boolean showInformationHistogram = true;
1047 * @return the showConsensusProfile
1050 public boolean isShowSequenceLogo()
1052 return showSequenceLogo;
1056 * @return the showInformationProfile
1059 public boolean isShowHMMSequenceLogo()
1061 return showHMMSequenceLogo;
1065 * @param showSequenceLogo
1068 public void setShowSequenceLogo(boolean showSequenceLogo)
1070 if (showSequenceLogo != this.showSequenceLogo)
1072 // TODO: decouple settings setting from calculation when refactoring
1073 // annotation update method from alignframe to viewport
1074 this.showSequenceLogo = showSequenceLogo;
1075 calculator.updateAnnotationFor(ConsensusThread.class);
1076 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1077 calculator.updateAnnotationFor(StrucConsensusThread.class);
1079 this.showSequenceLogo = showSequenceLogo;
1082 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1084 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1086 this.showHMMSequenceLogo = showHMMSequenceLogo;
1087 calculator.updateAnnotationFor(InformationThread.class);
1089 this.showHMMSequenceLogo = showHMMSequenceLogo;
1093 * @param showConsensusHistogram
1094 * the showConsensusHistogram to set
1096 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1098 this.showConsensusHistogram = showConsensusHistogram;
1102 * @param showInformationHistogram
1103 * the showInformationHistogram to set
1105 public void setShowInformationHistogram(boolean showInformationHistogram)
1107 this.showInformationHistogram = showInformationHistogram;
1111 * @return the showGroupConservation
1113 public boolean isShowGroupConservation()
1115 return showGroupConservation;
1119 * @param showGroupConservation
1120 * the showGroupConservation to set
1122 public void setShowGroupConservation(boolean showGroupConservation)
1124 this.showGroupConservation = showGroupConservation;
1128 * @return the showGroupConsensus
1130 public boolean isShowGroupConsensus()
1132 return showGroupConsensus;
1136 * @param showGroupConsensus
1137 * the showGroupConsensus to set
1139 public void setShowGroupConsensus(boolean showGroupConsensus)
1141 this.showGroupConsensus = showGroupConsensus;
1146 * @return flag to indicate if the consensus histogram should be rendered by
1150 public boolean isShowConsensusHistogram()
1152 return this.showConsensusHistogram;
1157 * @return flag to indicate if the information content histogram should be
1158 * rendered by default
1161 public boolean isShowInformationHistogram()
1163 return this.showInformationHistogram;
1167 * when set, updateAlignment will always ensure sequences are of equal length
1169 private boolean padGaps = false;
1172 * when set, alignment should be reordered according to a newly opened tree
1174 public boolean sortByTree = false;
1179 * @return null or the currently selected sequence region
1182 public SequenceGroup getSelectionGroup()
1184 return selectionGroup;
1188 * Set the selection group for this window. Also sets the current alignment as
1189 * the context for the group, if it does not already have one.
1192 * - group holding references to sequences in this alignment view
1196 public void setSelectionGroup(SequenceGroup sg)
1198 selectionGroup = sg;
1199 if (sg != null && sg.getContext() == null)
1201 sg.setContext(alignment);
1205 public void setHiddenColumns(HiddenColumns hidden)
1207 this.alignment.setHiddenColumns(hidden);
1211 public ColumnSelection getColumnSelection()
1217 public void setColumnSelection(ColumnSelection colSel)
1219 this.colSel = colSel;
1222 updateHiddenColumns();
1224 isColSelChanged(true);
1232 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1234 return hiddenRepSequences;
1238 public void setHiddenRepSequences(
1239 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1241 this.hiddenRepSequences = hiddenRepSequences;
1245 public boolean hasSelectedColumns()
1247 ColumnSelection columnSelection = getColumnSelection();
1248 return columnSelection != null && columnSelection.hasSelectedColumns();
1252 public boolean hasHiddenColumns()
1254 return alignment.getHiddenColumns() != null
1255 && alignment.getHiddenColumns().hasHiddenColumns();
1258 public void updateHiddenColumns()
1260 // this method doesn't really do anything now. But - it could, since a
1261 // column Selection could be in the process of modification
1262 // hasHiddenColumns = colSel.hasHiddenColumns();
1266 public boolean hasHiddenRows()
1268 return alignment.getHiddenSequences().getSize() > 0;
1271 protected SequenceGroup selectionGroup;
1273 public void setSequenceSetId(String newid)
1275 if (sequenceSetID != null)
1278 "Warning - overwriting a sequenceSetId for a viewport!");
1280 sequenceSetID = new String(newid);
1284 public String getSequenceSetId()
1286 if (sequenceSetID == null)
1288 sequenceSetID = alignment.hashCode() + "";
1291 return sequenceSetID;
1295 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1298 protected String viewId = null;
1301 public String getViewId()
1305 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1310 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1312 ignoreGapsInConsensusCalculation = b;
1315 updateConsensus(ap);
1316 if (residueShading != null)
1318 residueShading.setThreshold(residueShading.getThreshold(),
1319 ignoreGapsInConsensusCalculation);
1324 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1326 boolean was = ignoreBelowBackGroundFrequencyCalculation;
1327 ignoreBelowBackGroundFrequencyCalculation = b;
1328 if (ap != null && was != b)
1330 updateInformation(ap);
1334 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1336 boolean was = infoLetterHeight;
1337 infoLetterHeight = b;
1338 if (ap != null && was != b)
1340 updateInformation(ap);
1344 private long sgrouphash = -1, colselhash = -1;
1347 * checks current SelectionGroup against record of last hash value, and
1351 * update the record of last hash value
1353 * @return true if SelectionGroup changed since last call (when b is true)
1355 public boolean isSelectionGroupChanged(boolean b)
1357 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1358 : selectionGroup.hashCode();
1359 if (hc != -1 && hc != sgrouphash)
1371 * checks current colsel against record of last hash value, and optionally
1375 * update the record of last hash value
1376 * @return true if colsel changed since last call (when b is true)
1378 public boolean isColSelChanged(boolean b)
1380 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1381 if (hc != -1 && hc != colselhash)
1393 public boolean isIgnoreGapsConsensus()
1395 return ignoreGapsInConsensusCalculation;
1399 public boolean isIgnoreBelowBackground()
1401 return ignoreBelowBackGroundFrequencyCalculation;
1405 public boolean isInfoLetterHeight()
1407 return infoLetterHeight;
1410 // property change stuff
1411 // JBPNote Prolly only need this in the applet version.
1412 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1415 protected boolean showConservation = true;
1417 protected boolean showQuality = true;
1419 protected boolean showConsensus = true;
1421 protected boolean showOccupancy = true;
1423 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1425 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1427 protected boolean showAutocalculatedAbove;
1430 * when set, view will scroll to show the highlighted position
1432 private boolean followHighlight = true;
1435 * Property change listener for changes in alignment
1440 public void addPropertyChangeListener(
1441 java.beans.PropertyChangeListener listener)
1443 changeSupport.addPropertyChangeListener(listener);
1452 public void removePropertyChangeListener(
1453 java.beans.PropertyChangeListener listener)
1455 if (changeSupport != null)
1457 changeSupport.removePropertyChangeListener(listener);
1462 * Property change listener for changes in alignment
1471 public void firePropertyChange(String prop, Object oldvalue,
1474 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1477 // common hide/show column stuff
1479 public void hideSelectedColumns()
1481 if (colSel.isEmpty())
1486 colSel.hideSelectedColumns(alignment);
1487 setSelectionGroup(null);
1488 isColSelChanged(true);
1491 public void hideColumns(int start, int end)
1495 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1499 alignment.getHiddenColumns().hideColumns(start, end);
1501 isColSelChanged(true);
1504 public void showColumn(int col)
1506 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1507 isColSelChanged(true);
1510 public void showAllHiddenColumns()
1512 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1513 isColSelChanged(true);
1516 // common hide/show seq stuff
1517 public void showAllHiddenSeqs()
1519 int startSeq = ranges.getStartSeq();
1520 int endSeq = ranges.getEndSeq();
1522 if (alignment.getHiddenSequences().getSize() > 0)
1524 if (selectionGroup == null)
1526 selectionGroup = new SequenceGroup();
1527 selectionGroup.setEndRes(alignment.getWidth() - 1);
1529 List<SequenceI> tmp = alignment.getHiddenSequences()
1530 .showAll(hiddenRepSequences);
1531 for (SequenceI seq : tmp)
1533 selectionGroup.addSequence(seq, false);
1534 setSequenceAnnotationsVisible(seq, true);
1537 hiddenRepSequences = null;
1539 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1541 firePropertyChange("alignment", null, alignment.getSequences());
1542 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1548 public void showSequence(int index)
1550 int startSeq = ranges.getStartSeq();
1551 int endSeq = ranges.getEndSeq();
1553 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1554 hiddenRepSequences);
1557 if (selectionGroup == null)
1559 selectionGroup = new SequenceGroup();
1560 selectionGroup.setEndRes(alignment.getWidth() - 1);
1563 for (SequenceI seq : tmp)
1565 selectionGroup.addSequence(seq, false);
1566 setSequenceAnnotationsVisible(seq, true);
1569 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1571 firePropertyChange("alignment", null, alignment.getSequences());
1576 public void hideAllSelectedSeqs()
1578 if (selectionGroup == null || selectionGroup.getSize() < 1)
1583 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1587 setSelectionGroup(null);
1590 public void hideSequence(SequenceI[] seq)
1593 * cache offset to first visible sequence
1595 int startSeq = ranges.getStartSeq();
1599 for (int i = 0; i < seq.length; i++)
1601 alignment.getHiddenSequences().hideSequence(seq[i]);
1602 setSequenceAnnotationsVisible(seq[i], false);
1604 ranges.setStartSeq(startSeq);
1605 firePropertyChange("alignment", null, alignment.getSequences());
1610 * Hides the specified sequence, or the sequences it represents
1613 * the sequence to hide, or keep as representative
1614 * @param representGroup
1615 * if true, hide the current selection group except for the
1616 * representative sequence
1618 public void hideSequences(SequenceI sequence, boolean representGroup)
1620 if (selectionGroup == null || selectionGroup.getSize() < 1)
1622 hideSequence(new SequenceI[] { sequence });
1628 hideRepSequences(sequence, selectionGroup);
1629 setSelectionGroup(null);
1633 int gsize = selectionGroup.getSize();
1634 SequenceI[] hseqs = selectionGroup.getSequences()
1635 .toArray(new SequenceI[gsize]);
1637 hideSequence(hseqs);
1638 setSelectionGroup(null);
1643 * Set visibility for any annotations for the given sequence.
1647 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1650 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1653 for (AlignmentAnnotation ann : anns)
1655 if (ann.sequenceRef == sequenceI)
1657 ann.visible = visible;
1663 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1665 int sSize = sg.getSize();
1671 if (hiddenRepSequences == null)
1673 hiddenRepSequences = new Hashtable<>();
1676 hiddenRepSequences.put(repSequence, sg);
1678 // Hide all sequences except the repSequence
1679 SequenceI[] seqs = new SequenceI[sSize - 1];
1681 for (int i = 0; i < sSize; i++)
1683 if (sg.getSequenceAt(i) != repSequence)
1685 if (index == sSize - 1)
1690 seqs[index++] = sg.getSequenceAt(i);
1693 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1694 sg.setHidereps(true); // note: not done in 2.7applet
1701 * @return null or the current reference sequence
1703 public SequenceI getReferenceSeq()
1705 return alignment.getSeqrep();
1710 * @return true iff seq is the reference for the alignment
1712 public boolean isReferenceSeq(SequenceI seq)
1714 return alignment.getSeqrep() == seq;
1720 * @return true if there are sequences represented by this sequence that are
1723 public boolean isHiddenRepSequence(SequenceI seq)
1725 return (hiddenRepSequences != null
1726 && hiddenRepSequences.containsKey(seq));
1732 * @return null or a sequence group containing the sequences that seq
1735 public SequenceGroup getRepresentedSequences(SequenceI seq)
1737 return (SequenceGroup) (hiddenRepSequences == null ? null
1738 : hiddenRepSequences.get(seq));
1742 public int adjustForHiddenSeqs(int alignmentIndex)
1744 return alignment.getHiddenSequences()
1745 .adjustForHiddenSeqs(alignmentIndex);
1749 public void invertColumnSelection()
1751 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1755 public SequenceI[] getSelectionAsNewSequence()
1757 SequenceI[] sequences;
1758 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1759 // this was the only caller in the applet for this method
1760 // JBPNote: in applet, this method returned references to the alignment
1761 // sequences, and it did not honour the presence/absence of annotation
1762 // attached to the alignment (probably!)
1763 if (selectionGroup == null || selectionGroup.getSize() == 0)
1765 sequences = alignment.getSequencesArray();
1766 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1767 for (int i = 0; i < sequences.length; i++)
1769 // construct new sequence with subset of visible annotation
1770 sequences[i] = new Sequence(sequences[i], annots);
1775 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1782 public SequenceI[] getSequenceSelection()
1784 SequenceI[] sequences = null;
1785 if (selectionGroup != null)
1787 sequences = selectionGroup.getSequencesInOrder(alignment);
1789 if (sequences == null)
1791 sequences = alignment.getSequencesArray();
1797 public jalview.datamodel.AlignmentView getAlignmentView(
1798 boolean selectedOnly)
1800 return getAlignmentView(selectedOnly, false);
1804 public jalview.datamodel.AlignmentView getAlignmentView(
1805 boolean selectedOnly, boolean markGroups)
1807 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1809 alignment.getHiddenColumns() != null
1810 && alignment.getHiddenColumns().hasHiddenColumns(),
1811 selectedOnly, markGroups);
1815 public String[] getViewAsString(boolean selectedRegionOnly)
1817 return getViewAsString(selectedRegionOnly, true);
1821 public String[] getViewAsString(boolean selectedRegionOnly,
1822 boolean exportHiddenSeqs)
1824 String[] selection = null;
1825 SequenceI[] seqs = null;
1827 int start = 0, end = 0;
1828 if (selectedRegionOnly && selectionGroup != null)
1830 iSize = selectionGroup.getSize();
1831 seqs = selectionGroup.getSequencesInOrder(alignment);
1832 start = selectionGroup.getStartRes();
1833 end = selectionGroup.getEndRes() + 1;
1837 if (hasHiddenRows() && exportHiddenSeqs)
1839 AlignmentI fullAlignment = alignment.getHiddenSequences()
1840 .getFullAlignment();
1841 iSize = fullAlignment.getHeight();
1842 seqs = fullAlignment.getSequencesArray();
1843 end = fullAlignment.getWidth();
1847 iSize = alignment.getHeight();
1848 seqs = alignment.getSequencesArray();
1849 end = alignment.getWidth();
1853 selection = new String[iSize];
1854 if (alignment.getHiddenColumns() != null
1855 && alignment.getHiddenColumns().hasHiddenColumns())
1857 selection = alignment.getHiddenColumns()
1858 .getVisibleSequenceStrings(start, end, seqs);
1862 for (i = 0; i < iSize; i++)
1864 selection[i] = seqs[i].getSequenceAsString(start, end);
1872 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1874 ArrayList<int[]> regions = new ArrayList<>();
1880 HiddenColumns hidden = alignment.getHiddenColumns();
1881 if (hidden != null && hidden.hasHiddenColumns())
1885 start = hidden.adjustForHiddenColumns(start);
1888 end = hidden.getHiddenBoundaryRight(start);
1899 regions.add(new int[] { start, end });
1901 if (hidden != null && hidden.hasHiddenColumns())
1903 start = hidden.adjustForHiddenColumns(end);
1904 start = hidden.getHiddenBoundaryLeft(start) + 1;
1906 } while (end < max);
1908 int[][] startEnd = new int[regions.size()][2];
1914 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1915 boolean selectedOnly)
1917 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1918 AlignmentAnnotation[] aa;
1919 if ((aa = alignment.getAlignmentAnnotation()) != null)
1921 for (AlignmentAnnotation annot : aa)
1923 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1924 if (selectedOnly && selectionGroup != null)
1926 alignment.getHiddenColumns().makeVisibleAnnotation(
1927 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1932 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1941 public boolean isPadGaps()
1947 public void setPadGaps(boolean padGaps)
1949 this.padGaps = padGaps;
1953 * apply any post-edit constraints and trigger any calculations needed after
1954 * an edit has been performed on the alignment
1959 public void alignmentChanged(AlignmentViewPanel ap)
1963 alignment.padGaps();
1965 if (autoCalculateConsensus)
1967 updateConsensus(ap);
1969 if (consensusProfiles != null && autoCalculateConsensus)
1971 updateConservation(ap);
1973 if (autoCalculateStrucConsensus)
1975 updateStrucConsensus(ap);
1977 // initInformation();
1978 updateInformation(ap);
1980 // Reset endRes of groups if beyond alignment width
1981 int alWidth = alignment.getWidth();
1982 List<SequenceGroup> groups = alignment.getGroups();
1985 for (SequenceGroup sg : groups)
1987 if (sg.getEndRes() > alWidth)
1989 sg.setEndRes(alWidth - 1);
1994 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1996 selectionGroup.setEndRes(alWidth - 1);
1999 updateAllColourSchemes();
2000 calculator.restartWorkers();
2001 // alignment.adjustSequenceAnnotations();
2005 * reset scope and do calculations for all applied colourschemes on alignment
2007 void updateAllColourSchemes()
2009 ResidueShaderI rs = residueShading;
2012 rs.alignmentChanged(alignment, hiddenRepSequences);
2014 rs.setConsensus(consensusProfiles);
2015 if (rs.conservationApplied())
2017 rs.setConservation(Conservation.calculateConservation("All",
2018 alignment.getSequences(), 0, alignment.getWidth(), false,
2019 getConsPercGaps(), false));
2023 for (SequenceGroup sg : alignment.getGroups())
2027 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2029 sg.recalcConservation();
2033 protected void initAutoAnnotation()
2035 // TODO: add menu option action that nulls or creates consensus object
2036 // depending on if the user wants to see the annotation or not in a
2037 // specific alignment
2039 if (consensusProfiles == null && !isDataset)
2041 if (!alignment.isNucleotide())
2050 consensus = new AlignmentAnnotation("Consensus",
2051 MessageManager.getString("label.consensus_descr"),
2052 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2053 initConsensus(consensus);
2057 initComplementConsensus();
2062 * If this is a protein alignment and there are mappings to cDNA, adds the
2063 * cDNA consensus annotation and returns true, else returns false.
2065 public boolean initComplementConsensus()
2067 if (!alignment.isNucleotide())
2069 final List<AlignedCodonFrame> codonMappings = alignment
2071 if (codonMappings != null && !codonMappings.isEmpty())
2073 boolean doConsensus = false;
2074 for (AlignedCodonFrame mapping : codonMappings)
2076 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2077 MapList[] mapLists = mapping.getdnaToProt();
2078 // mapLists can be empty if project load has not finished resolving
2080 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2088 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2090 .getString("label.complement_consensus_descr"),
2091 new Annotation[1], 0f, 100f,
2092 AlignmentAnnotation.BAR_GRAPH);
2093 initConsensus(complementConsensus);
2101 private void initConsensus(AlignmentAnnotation aa)
2104 aa.autoCalculated = true;
2108 alignment.addAnnotation(aa);
2112 // these should be extracted from the view model - style and settings for
2113 // derived annotation
2114 private void initOccupancy()
2118 occupancy = new AlignmentAnnotation("Occupancy",
2119 MessageManager.getString("label.occupancy_descr"),
2120 new Annotation[1], 0f, alignment.getHeight(),
2121 AlignmentAnnotation.BAR_GRAPH);
2122 occupancy.hasText = true;
2123 occupancy.autoCalculated = true;
2124 occupancy.scaleColLabel = true;
2125 occupancy.graph = AlignmentAnnotation.BAR_GRAPH;
2127 alignment.addAnnotation(occupancy);
2131 private void initConservation()
2133 if (showConservation)
2135 if (conservation == null)
2137 conservation = new AlignmentAnnotation("Conservation",
2138 MessageManager.formatMessage("label.conservation_descr",
2140 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2141 conservation.hasText = true;
2142 conservation.autoCalculated = true;
2143 alignment.addAnnotation(conservation);
2148 private void initQuality()
2152 if (quality == null)
2154 quality = new AlignmentAnnotation("Quality",
2155 MessageManager.getString("label.quality_descr"),
2156 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2157 quality.hasText = true;
2158 quality.autoCalculated = true;
2159 alignment.addAnnotation(quality);
2164 private void initRNAStructure()
2166 if (alignment.hasRNAStructure() && strucConsensus == null)
2168 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2169 MessageManager.getString("label.strucconsensus_descr"),
2170 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2171 strucConsensus.hasText = true;
2172 strucConsensus.autoCalculated = true;
2176 alignment.addAnnotation(strucConsensus);
2184 * @see jalview.api.AlignViewportI#calcPanelHeight()
2187 public int calcPanelHeight()
2189 // setHeight of panels
2190 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2192 int charHeight = getCharHeight();
2195 BitSet graphgrp = new BitSet();
2196 for (AlignmentAnnotation aa : anns)
2200 System.err.println("Null annotation row: ignoring.");
2207 if (aa.graphGroup > -1)
2209 if (graphgrp.get(aa.graphGroup))
2215 graphgrp.set(aa.graphGroup);
2222 aa.height += charHeight;
2232 aa.height += aa.graphHeight;
2240 height += aa.height;
2252 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2253 boolean preserveNewGroupSettings)
2255 boolean updateCalcs = false;
2256 boolean conv = isShowGroupConservation();
2257 boolean cons = isShowGroupConsensus();
2258 boolean showprf = isShowSequenceLogo();
2259 boolean showConsHist = isShowConsensusHistogram();
2260 boolean normLogo = isNormaliseSequenceLogo();
2261 boolean showHMMPrf = isShowHMMSequenceLogo();
2262 boolean showInfoHist = isShowInformationHistogram();
2263 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2266 * TODO reorder the annotation rows according to group/sequence ordering on
2269 boolean sortg = true;
2271 // remove old automatic annotation
2272 // add any new annotation
2274 // intersect alignment annotation with alignment groups
2276 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2277 List<SequenceGroup> oldrfs = new ArrayList<>();
2280 for (int an = 0; an < aan.length; an++)
2282 if (aan[an].autoCalculated && aan[an].groupRef != null)
2284 oldrfs.add(aan[an].groupRef);
2285 alignment.deleteAnnotation(aan[an], false);
2289 if (alignment.getGroups() != null)
2291 for (SequenceGroup sg : alignment.getGroups())
2293 updateCalcs = false;
2294 if (applyGlobalSettings
2295 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2297 // set defaults for this group's conservation/consensus
2298 sg.setshowSequenceLogo(showprf);
2299 sg.setShowConsensusHistogram(showConsHist);
2300 sg.setNormaliseSequenceLogo(normLogo);
2301 sg.setshowHMMSequenceLogo(showHMMPrf);
2302 sg.setShowInformationHistogram(showInfoHist);
2303 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2308 alignment.addAnnotation(sg.getConservationRow(), 0);
2313 alignment.addAnnotation(sg.getConsensus(), 0);
2315 // refresh the annotation rows
2318 sg.recalcConservation();
2326 public boolean isDisplayReferenceSeq()
2328 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2332 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2334 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2338 public boolean isColourByReferenceSeq()
2340 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2344 public Color getSequenceColour(SequenceI seq)
2346 Color sqc = sequenceColours.get(seq);
2347 return (sqc == null ? Color.white : sqc);
2351 public void setSequenceColour(SequenceI seq, Color col)
2355 sequenceColours.remove(seq);
2359 sequenceColours.put(seq, col);
2364 public void updateSequenceIdColours()
2366 for (SequenceGroup sg : alignment.getGroups())
2368 if (sg.idColour != null)
2370 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2372 sequenceColours.put(s, sg.idColour);
2379 public void clearSequenceColours()
2381 sequenceColours.clear();
2385 public AlignViewportI getCodingComplement()
2387 return this.codingComplement;
2391 * Set this as the (cDna/protein) complement of the given viewport. Also
2392 * ensures the reverse relationship is set on the given viewport.
2395 public void setCodingComplement(AlignViewportI av)
2399 System.err.println("Ignoring recursive setCodingComplement request");
2403 this.codingComplement = av;
2404 // avoid infinite recursion!
2405 if (av.getCodingComplement() != this)
2407 av.setCodingComplement(this);
2413 public boolean isNucleotide()
2415 return getAlignment() == null ? false : getAlignment().isNucleotide();
2419 public FeaturesDisplayedI getFeaturesDisplayed()
2421 return featuresDisplayed;
2425 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2427 featuresDisplayed = featuresDisplayedI;
2431 public boolean areFeaturesDisplayed()
2433 return featuresDisplayed != null
2434 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2441 * features are displayed if true
2444 public void setShowSequenceFeatures(boolean b)
2446 viewStyle.setShowSequenceFeatures(b);
2450 public boolean isShowSequenceFeatures()
2452 return viewStyle.isShowSequenceFeatures();
2456 public void setShowSequenceFeaturesHeight(boolean selected)
2458 viewStyle.setShowSequenceFeaturesHeight(selected);
2462 public boolean isShowSequenceFeaturesHeight()
2464 return viewStyle.isShowSequenceFeaturesHeight();
2468 public void setShowAnnotation(boolean b)
2470 viewStyle.setShowAnnotation(b);
2474 public boolean isShowAnnotation()
2476 return viewStyle.isShowAnnotation();
2480 public boolean isRightAlignIds()
2482 return viewStyle.isRightAlignIds();
2486 public void setRightAlignIds(boolean rightAlignIds)
2488 viewStyle.setRightAlignIds(rightAlignIds);
2492 public boolean getConservationSelected()
2494 return viewStyle.getConservationSelected();
2498 public void setShowBoxes(boolean state)
2500 viewStyle.setShowBoxes(state);
2505 * @see jalview.api.ViewStyleI#getTextColour()
2508 public Color getTextColour()
2510 return viewStyle.getTextColour();
2515 * @see jalview.api.ViewStyleI#getTextColour2()
2518 public Color getTextColour2()
2520 return viewStyle.getTextColour2();
2525 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2528 public int getThresholdTextColour()
2530 return viewStyle.getThresholdTextColour();
2535 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2538 public boolean isConservationColourSelected()
2540 return viewStyle.isConservationColourSelected();
2545 * @see jalview.api.ViewStyleI#isRenderGaps()
2548 public boolean isRenderGaps()
2550 return viewStyle.isRenderGaps();
2555 * @see jalview.api.ViewStyleI#isShowColourText()
2558 public boolean isShowColourText()
2560 return viewStyle.isShowColourText();
2564 * @param conservationColourSelected
2565 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2568 public void setConservationColourSelected(
2569 boolean conservationColourSelected)
2571 viewStyle.setConservationColourSelected(conservationColourSelected);
2575 * @param showColourText
2576 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2579 public void setShowColourText(boolean showColourText)
2581 viewStyle.setShowColourText(showColourText);
2586 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2589 public void setTextColour(Color textColour)
2591 viewStyle.setTextColour(textColour);
2595 * @param thresholdTextColour
2596 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2599 public void setThresholdTextColour(int thresholdTextColour)
2601 viewStyle.setThresholdTextColour(thresholdTextColour);
2605 * @param textColour2
2606 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2609 public void setTextColour2(Color textColour2)
2611 viewStyle.setTextColour2(textColour2);
2615 public ViewStyleI getViewStyle()
2617 return new ViewStyle(viewStyle);
2621 public void setViewStyle(ViewStyleI settingsForView)
2623 viewStyle = new ViewStyle(settingsForView);
2624 if (residueShading != null)
2626 residueShading.setConservationApplied(
2627 settingsForView.isConservationColourSelected());
2632 public boolean sameStyle(ViewStyleI them)
2634 return viewStyle.sameStyle(them);
2639 * @see jalview.api.ViewStyleI#getIdWidth()
2642 public int getIdWidth()
2644 return viewStyle.getIdWidth();
2649 * @see jalview.api.ViewStyleI#setIdWidth(int)
2652 public void setIdWidth(int i)
2654 viewStyle.setIdWidth(i);
2659 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2662 public boolean isCentreColumnLabels()
2664 return viewStyle.isCentreColumnLabels();
2668 * @param centreColumnLabels
2669 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2672 public void setCentreColumnLabels(boolean centreColumnLabels)
2674 viewStyle.setCentreColumnLabels(centreColumnLabels);
2679 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2682 public void setShowDBRefs(boolean showdbrefs)
2684 viewStyle.setShowDBRefs(showdbrefs);
2689 * @see jalview.api.ViewStyleI#isShowDBRefs()
2692 public boolean isShowDBRefs()
2694 return viewStyle.isShowDBRefs();
2699 * @see jalview.api.ViewStyleI#isShowNPFeats()
2702 public boolean isShowNPFeats()
2704 return viewStyle.isShowNPFeats();
2708 * @param shownpfeats
2709 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2712 public void setShowNPFeats(boolean shownpfeats)
2714 viewStyle.setShowNPFeats(shownpfeats);
2717 public abstract StructureSelectionManager getStructureSelectionManager();
2720 * Add one command to the command history list.
2724 public void addToHistoryList(CommandI command)
2726 if (this.historyList != null)
2728 this.historyList.push(command);
2729 broadcastCommand(command, false);
2733 protected void broadcastCommand(CommandI command, boolean undo)
2735 getStructureSelectionManager().commandPerformed(command, undo,
2740 * Add one command to the command redo list.
2744 public void addToRedoList(CommandI command)
2746 if (this.redoList != null)
2748 this.redoList.push(command);
2750 broadcastCommand(command, true);
2754 * Clear the command redo list.
2756 public void clearRedoList()
2758 if (this.redoList != null)
2760 this.redoList.clear();
2764 public void setHistoryList(Deque<CommandI> list)
2766 this.historyList = list;
2769 public Deque<CommandI> getHistoryList()
2771 return this.historyList;
2774 public void setRedoList(Deque<CommandI> list)
2776 this.redoList = list;
2779 public Deque<CommandI> getRedoList()
2781 return this.redoList;
2785 public VamsasSource getVamsasSource()
2790 public SequenceAnnotationOrder getSortAnnotationsBy()
2792 return sortAnnotationsBy;
2795 public void setSortAnnotationsBy(
2796 SequenceAnnotationOrder sortAnnotationsBy)
2798 this.sortAnnotationsBy = sortAnnotationsBy;
2801 public boolean isShowAutocalculatedAbove()
2803 return showAutocalculatedAbove;
2806 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2808 this.showAutocalculatedAbove = showAutocalculatedAbove;
2812 public boolean isScaleProteinAsCdna()
2814 return viewStyle.isScaleProteinAsCdna();
2818 public void setScaleProteinAsCdna(boolean b)
2820 viewStyle.setScaleProteinAsCdna(b);
2824 public boolean isProteinFontAsCdna()
2826 return viewStyle.isProteinFontAsCdna();
2830 public void setProteinFontAsCdna(boolean b)
2832 viewStyle.setProteinFontAsCdna(b);
2836 * @return true if view should scroll to show the highlighted region of a
2841 public final boolean isFollowHighlight()
2843 return followHighlight;
2847 public final void setFollowHighlight(boolean b)
2849 this.followHighlight = b;
2853 public ViewportRanges getRanges()
2859 * Helper method to populate the SearchResults with the location in the
2860 * complementary alignment to scroll to, in order to match this one.
2863 * the SearchResults to add to
2864 * @return the offset (below top of visible region) of the matched sequence
2866 protected int findComplementScrollTarget(SearchResultsI sr)
2868 final AlignViewportI complement = getCodingComplement();
2869 if (complement == null || !complement.isFollowHighlight())
2873 boolean iAmProtein = !getAlignment().isNucleotide();
2874 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2875 : complement.getAlignment();
2876 if (proteinAlignment == null)
2880 final List<AlignedCodonFrame> mappings = proteinAlignment
2884 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2885 * residue in the middle column of the visible region. Scroll the
2886 * complementary alignment to line up the corresponding residue.
2889 SequenceI sequence = null;
2892 * locate 'middle' column (true middle if an odd number visible, left of
2893 * middle if an even number visible)
2895 int middleColumn = ranges.getStartRes()
2896 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2897 final HiddenSequences hiddenSequences = getAlignment()
2898 .getHiddenSequences();
2901 * searching to the bottom of the alignment gives smoother scrolling across
2902 * all gapped visible regions
2904 int lastSeq = alignment.getHeight() - 1;
2905 List<AlignedCodonFrame> seqMappings = null;
2906 for (int seqNo = ranges
2907 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2909 sequence = getAlignment().getSequenceAt(seqNo);
2910 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2914 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2918 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2920 getCodingComplement().getAlignment().getSequences());
2921 if (!seqMappings.isEmpty())
2927 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2930 * No ungapped mapped sequence in middle column - do nothing
2934 MappingUtils.addSearchResults(sr, sequence,
2935 sequence.findPosition(middleColumn), seqMappings);
2940 * synthesize a column selection if none exists so it covers the given
2941 * selection group. if wholewidth is false, no column selection is made if the
2942 * selection group covers the whole alignment width.
2947 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2950 if (sg != null && (sgs = sg.getStartRes()) >= 0
2951 && sg.getStartRes() <= (sge = sg.getEndRes())
2952 && !this.hasSelectedColumns())
2954 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2961 colSel = new ColumnSelection();
2963 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2965 colSel.addElement(cspos);
2971 * hold status of current selection group - defined on alignment or not.
2973 private boolean selectionIsDefinedGroup = false;
2976 public boolean isSelectionDefinedGroup()
2978 if (selectionGroup == null)
2982 if (isSelectionGroupChanged(true))
2984 selectionIsDefinedGroup = false;
2985 List<SequenceGroup> gps = alignment.getGroups();
2986 if (gps == null || gps.size() == 0)
2988 selectionIsDefinedGroup = false;
2992 selectionIsDefinedGroup = gps.contains(selectionGroup);
2995 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2999 * null, or currently highlighted results on this view
3001 private SearchResultsI searchResults = null;
3003 protected TreeModel currentTree = null;
3006 public boolean hasSearchResults()
3008 return searchResults != null;
3012 public void setSearchResults(SearchResultsI results)
3014 searchResults = results;
3018 public SearchResultsI getSearchResults()
3020 return searchResults;
3024 * get the consensus sequence as displayed under the PID consensus annotation
3027 * @return consensus sequence as a new sequence object
3029 public SequenceI getConsensusSeq()
3031 if (consensus == null)
3033 updateConsensus(null);
3035 if (consensus == null)
3039 StringBuffer seqs = new StringBuffer();
3040 for (int i = 0; i < consensus.annotations.length; i++)
3042 Annotation annotation = consensus.annotations[i];
3043 if (annotation != null)
3045 String description = annotation.description;
3046 if (description != null && description.startsWith("["))
3048 // consensus is a tie - just pick the first one
3049 seqs.append(description.charAt(1));
3053 seqs.append(annotation.displayCharacter);
3058 SequenceI sq = new Sequence("Consensus", seqs.toString());
3059 sq.setDescription("Percentage Identity Consensus "
3060 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3064 public boolean hasReferenceAnnotation()
3066 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3067 for (AlignmentAnnotation annot : annots)
3069 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3078 public void setCurrentTree(TreeModel tree)
3084 public TreeModel getCurrentTree()