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.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfileI;
41 import jalview.datamodel.Profiles;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.renderer.ResidueShader;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.ColourSchemeI;
51 import jalview.structure.CommandListener;
52 import jalview.structure.StructureSelectionManager;
53 import jalview.structure.VamsasSource;
54 import jalview.util.Comparison;
55 import jalview.util.MapList;
56 import jalview.util.MappingUtils;
57 import jalview.util.MessageManager;
58 import jalview.viewmodel.styles.ViewStyle;
59 import jalview.workers.AlignCalcManager;
60 import jalview.workers.ComplementConsensusThread;
61 import jalview.workers.ConsensusThread;
62 import jalview.workers.InformationThread;
63 import jalview.workers.StrucConsensusThread;
65 import java.awt.Color;
66 import java.beans.PropertyChangeSupport;
67 import java.util.ArrayDeque;
68 import java.util.ArrayList;
69 import java.util.BitSet;
70 import java.util.Deque;
71 import java.util.HashMap;
72 import java.util.Hashtable;
73 import java.util.List;
77 * base class holding visualization and analysis attributes and common logic for
78 * an active alignment view displayed in the GUI
83 public abstract class AlignmentViewport
84 implements AlignViewportI, CommandListener, VamsasSource
86 final protected ViewportRanges ranges;
88 protected ViewStyleI viewStyle = new ViewStyle();
91 * A viewport that hosts the cDna view of this (protein), or vice versa (if
94 AlignViewportI codingComplement = null;
96 FeaturesDisplayedI featuresDisplayed = null;
98 protected Deque<CommandI> historyList = new ArrayDeque<>();
100 protected Deque<CommandI> redoList = new ArrayDeque<>();
104 * alignment displayed in the viewport. Please use get/setter
106 protected AlignmentI alignment;
108 public AlignmentViewport(AlignmentI al)
111 ranges = new ViewportRanges(al);
116 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
119 public void setFontName(String name)
121 viewStyle.setFontName(name);
126 * @see jalview.api.ViewStyleI#setFontStyle(int)
129 public void setFontStyle(int style)
131 viewStyle.setFontStyle(style);
136 * @see jalview.api.ViewStyleI#setFontSize(int)
139 public void setFontSize(int size)
141 viewStyle.setFontSize(size);
146 * @see jalview.api.ViewStyleI#getFontStyle()
149 public int getFontStyle()
151 return viewStyle.getFontStyle();
156 * @see jalview.api.ViewStyleI#getFontName()
159 public String getFontName()
161 return viewStyle.getFontName();
166 * @see jalview.api.ViewStyleI#getFontSize()
169 public int getFontSize()
171 return viewStyle.getFontSize();
175 * @param upperCasebold
176 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
179 public void setUpperCasebold(boolean upperCasebold)
181 viewStyle.setUpperCasebold(upperCasebold);
186 * @see jalview.api.ViewStyleI#isUpperCasebold()
189 public boolean isUpperCasebold()
191 return viewStyle.isUpperCasebold();
196 * @see jalview.api.ViewStyleI#isSeqNameItalics()
199 public boolean isSeqNameItalics()
201 return viewStyle.isSeqNameItalics();
205 * @param colourByReferenceSeq
206 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
209 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
211 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
216 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
219 public void setColourAppliesToAllGroups(boolean b)
221 viewStyle.setColourAppliesToAllGroups(b);
226 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
229 public boolean getColourAppliesToAllGroups()
231 return viewStyle.getColourAppliesToAllGroups();
236 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
239 public boolean getAbovePIDThreshold()
241 return viewStyle.getAbovePIDThreshold();
246 * @see jalview.api.ViewStyleI#setIncrement(int)
249 public void setIncrement(int inc)
251 viewStyle.setIncrement(inc);
256 * @see jalview.api.ViewStyleI#getIncrement()
259 public int getIncrement()
261 return viewStyle.getIncrement();
266 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
269 public void setConservationSelected(boolean b)
271 viewStyle.setConservationSelected(b);
276 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
279 public void setShowHiddenMarkers(boolean show)
281 viewStyle.setShowHiddenMarkers(show);
286 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
289 public boolean getShowHiddenMarkers()
291 return viewStyle.getShowHiddenMarkers();
296 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
299 public void setScaleRightWrapped(boolean b)
301 viewStyle.setScaleRightWrapped(b);
306 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
309 public void setScaleLeftWrapped(boolean b)
311 viewStyle.setScaleLeftWrapped(b);
316 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
319 public void setScaleAboveWrapped(boolean b)
321 viewStyle.setScaleAboveWrapped(b);
326 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
329 public boolean getScaleLeftWrapped()
331 return viewStyle.getScaleLeftWrapped();
336 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
339 public boolean getScaleAboveWrapped()
341 return viewStyle.getScaleAboveWrapped();
346 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
349 public boolean getScaleRightWrapped()
351 return viewStyle.getScaleRightWrapped();
356 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
359 public void setAbovePIDThreshold(boolean b)
361 viewStyle.setAbovePIDThreshold(b);
366 * @see jalview.api.ViewStyleI#setThreshold(int)
369 public void setThreshold(int thresh)
371 viewStyle.setThreshold(thresh);
376 * @see jalview.api.ViewStyleI#getThreshold()
379 public int getThreshold()
381 return viewStyle.getThreshold();
386 * @see jalview.api.ViewStyleI#getShowJVSuffix()
389 public boolean getShowJVSuffix()
391 return viewStyle.getShowJVSuffix();
396 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
399 public void setShowJVSuffix(boolean b)
401 viewStyle.setShowJVSuffix(b);
406 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
409 public void setWrapAlignment(boolean state)
411 viewStyle.setWrapAlignment(state);
416 * @see jalview.api.ViewStyleI#setShowText(boolean)
419 public void setShowText(boolean state)
421 viewStyle.setShowText(state);
426 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
429 public void setRenderGaps(boolean state)
431 viewStyle.setRenderGaps(state);
436 * @see jalview.api.ViewStyleI#getColourText()
439 public boolean getColourText()
441 return viewStyle.getColourText();
446 * @see jalview.api.ViewStyleI#setColourText(boolean)
449 public void setColourText(boolean state)
451 viewStyle.setColourText(state);
456 * @see jalview.api.ViewStyleI#getWrapAlignment()
459 public boolean getWrapAlignment()
461 return viewStyle.getWrapAlignment();
466 * @see jalview.api.ViewStyleI#getShowText()
469 public boolean getShowText()
471 return viewStyle.getShowText();
476 * @see jalview.api.ViewStyleI#getWrappedWidth()
479 public int getWrappedWidth()
481 return viewStyle.getWrappedWidth();
486 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
489 public void setWrappedWidth(int w)
491 viewStyle.setWrappedWidth(w);
496 * @see jalview.api.ViewStyleI#getCharHeight()
499 public int getCharHeight()
501 return viewStyle.getCharHeight();
506 * @see jalview.api.ViewStyleI#setCharHeight(int)
509 public void setCharHeight(int h)
511 viewStyle.setCharHeight(h);
516 * @see jalview.api.ViewStyleI#getCharWidth()
519 public int getCharWidth()
521 return viewStyle.getCharWidth();
526 * @see jalview.api.ViewStyleI#setCharWidth(int)
529 public void setCharWidth(int w)
531 viewStyle.setCharWidth(w);
536 * @see jalview.api.ViewStyleI#getShowBoxes()
539 public boolean getShowBoxes()
541 return viewStyle.getShowBoxes();
546 * @see jalview.api.ViewStyleI#getShowUnconserved()
549 public boolean getShowUnconserved()
551 return viewStyle.getShowUnconserved();
555 * @param showunconserved
556 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
559 public void setShowUnconserved(boolean showunconserved)
561 viewStyle.setShowUnconserved(showunconserved);
566 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
569 public void setSeqNameItalics(boolean default1)
571 viewStyle.setSeqNameItalics(default1);
575 public AlignmentI getAlignment()
581 public char getGapCharacter()
583 return alignment.getGapCharacter();
586 protected String sequenceSetID;
589 * probably unused indicator that view is of a dataset rather than an
592 protected boolean isDataset = false;
594 public void setDataset(boolean b)
599 public boolean isDataset()
604 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
606 protected ColumnSelection colSel = new ColumnSelection();
608 public boolean autoCalculateConsensus = true;
610 public boolean autoCalculateInformation = true;
612 protected boolean autoCalculateStrucConsensus = true;
614 protected boolean ignoreGapsInConsensusCalculation = false;
616 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
618 protected ResidueShaderI residueShading = new ResidueShader();
621 public void setGlobalColourScheme(ColourSchemeI cs)
623 // TODO: logic refactored from AlignFrame changeColour -
624 // TODO: autorecalc stuff should be changed to rely on the worker system
625 // check to see if we should implement a changeColour(cs) method rather than
626 // put the logic in here
627 // - means that caller decides if they want to just modify state and defer
628 // calculation till later or to do all calculations in thread.
632 * only instantiate alignment colouring once, thereafter update it;
633 * this means that any conservation or PID threshold settings
634 * persist when the alignment colour scheme is changed
636 if (residueShading == null)
638 residueShading = new ResidueShader(viewStyle);
640 residueShading.setColourScheme(cs);
642 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
643 // ...problem: groups need these, but do not currently have a ViewStyle
647 if (getConservationSelected())
649 residueShading.setConservation(hconservation);
651 residueShading.alignmentChanged(alignment, hiddenRepSequences);
655 * if 'apply colour to all groups' is selected... do so
656 * (but don't transfer any colour threshold settings to groups)
658 if (getColourAppliesToAllGroups())
660 for (SequenceGroup sg : getAlignment().getGroups())
663 * retain any colour thresholds per group while
664 * changing choice of colour scheme (JAL-2386)
666 sg.setColourScheme(cs);
669 sg.getGroupColourScheme().alignmentChanged(sg,
677 public ColourSchemeI getGlobalColourScheme()
679 return residueShading == null ? null : residueShading.getColourScheme();
683 public ResidueShaderI getResidueShading()
685 return residueShading;
688 protected AlignmentAnnotation consensus;
690 protected AlignmentAnnotation complementConsensus;
692 protected AlignmentAnnotation gapcounts;
694 protected AlignmentAnnotation strucConsensus;
696 protected AlignmentAnnotation conservation;
698 protected AlignmentAnnotation quality;
700 protected AlignmentAnnotation[] groupConsensus;
702 protected AlignmentAnnotation[] groupConservation;
704 protected List<AlignmentAnnotation> groupInformation = new ArrayList<>();
706 protected List<AlignmentAnnotation> information = new ArrayList<>();
709 * results of alignment consensus analysis for visible portion of view
711 protected ProfilesI hconsensus = null;
713 protected List<ProfilesI> hinformation = new ArrayList<>();
716 * results of cDNA complement consensus visible portion of view
718 protected Hashtable[] hcomplementConsensus = null;
721 * results of secondary structure base pair consensus for visible portion of
724 protected Hashtable[] hStrucConsensus = null;
726 protected Conservation hconservation = null;
729 public void setConservation(Conservation cons)
731 hconservation = cons;
735 * percentage gaps allowed in a column before all amino acid properties should
736 * be considered unconserved
738 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
741 public int getConsPercGaps()
747 public void setSequenceConsensusHash(ProfilesI hconsensus)
749 this.hconsensus = hconsensus;
753 public void setComplementConsensusHash(Hashtable[] hconsensus)
755 this.hcomplementConsensus = hconsensus;
759 public ProfilesI getSequenceConsensusHash()
765 public void setSequenceInformationHashes(List<ProfilesI> info)
771 public void setSequenceInformationHash(ProfilesI info, int index)
773 hinformation.set(index, info);
777 public List<ProfilesI> getSequenceInformationHashes()
783 public ProfilesI getSequenceInformationHash(int index)
785 return hinformation.get(index);
789 public Hashtable[] getComplementConsensusHash()
791 return hcomplementConsensus;
795 public Hashtable[] getRnaStructureConsensusHash()
797 return hStrucConsensus;
801 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
803 this.hStrucConsensus = hStrucConsensus;
808 public AlignmentAnnotation getAlignmentQualityAnnot()
814 public AlignmentAnnotation getAlignmentConservationAnnotation()
820 public AlignmentAnnotation getAlignmentConsensusAnnotation()
826 public List<AlignmentAnnotation> getInformationAnnotations()
832 public AlignmentAnnotation getInformationAnnotation(int index)
834 return information.get(index);
838 public AlignmentAnnotation getAlignmentGapAnnotation()
844 public AlignmentAnnotation getComplementConsensusAnnotation()
846 return complementConsensus;
850 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
852 return strucConsensus;
855 protected AlignCalcManagerI calculator = new AlignCalcManager();
858 * trigger update of conservation annotation
860 public void updateConservation(final AlignmentViewPanel ap)
862 // see note in mantis : issue number 8585
863 if (alignment.isNucleotide()
864 || (conservation == null && quality == null)
865 || !autoCalculateConsensus)
869 if (calculator.getRegisteredWorkersOfClass(
870 jalview.workers.ConservationThread.class) == null)
872 calculator.registerWorker(
873 new jalview.workers.ConservationThread(this, ap));
878 * trigger update of consensus annotation
880 public void updateConsensus(final AlignmentViewPanel ap)
882 // see note in mantis : issue number 8585
883 if (consensus == null || !autoCalculateConsensus)
888 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
890 calculator.registerWorker(new ConsensusThread(this, ap));
894 * A separate thread to compute cDNA consensus for a protein alignment
895 * which has mapping to cDNA
897 final AlignmentI al = this.getAlignment();
898 if (!al.isNucleotide() && al.getCodonFrames() != null
899 && !al.getCodonFrames().isEmpty())
902 * fudge - check first for protein-to-nucleotide mappings
903 * (we don't want to do this for protein-to-protein)
905 boolean doConsensus = false;
906 for (AlignedCodonFrame mapping : al.getCodonFrames())
908 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
909 MapList[] mapLists = mapping.getdnaToProt();
910 // mapLists can be empty if project load has not finished resolving seqs
911 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
919 if (calculator.getRegisteredWorkersOfClass(
920 ComplementConsensusThread.class) == null)
923 .registerWorker(new ComplementConsensusThread(this, ap));
930 * trigger update of information annotation
933 public void updateInformation(final AlignmentViewPanel ap)
936 .getRegisteredWorkersOfClass(InformationThread.class) == null)
938 calculator.registerWorker(new InformationThread(this, ap));
943 // --------START Structure Conservation
944 public void updateStrucConsensus(final AlignmentViewPanel ap)
946 if (autoCalculateStrucConsensus && strucConsensus == null
947 && alignment.isNucleotide() && alignment.hasRNAStructure())
949 // secondary structure has been added - so init the consensus line
953 // see note in mantis : issue number 8585
954 if (strucConsensus == null || !autoCalculateStrucConsensus)
958 if (calculator.getRegisteredWorkersOfClass(
959 StrucConsensusThread.class) == null)
961 calculator.registerWorker(new StrucConsensusThread(this, ap));
965 public boolean isCalcInProgress()
967 return calculator.isWorking();
971 public boolean isCalculationInProgress(
972 AlignmentAnnotation alignmentAnnotation)
974 if (!alignmentAnnotation.autoCalculated)
978 if (calculator.workingInvolvedWith(alignmentAnnotation))
980 // System.err.println("grey out ("+alignmentAnnotation.label+")");
986 public void setAlignment(AlignmentI align)
988 this.alignment = align;
992 * Clean up references when this viewport is closed
995 public void dispose()
998 * defensively null out references to large objects in case
999 * this object is not garbage collected (as if!)
1002 complementConsensus = null;
1003 strucConsensus = null;
1004 conservation = null;
1006 groupConsensus = null;
1007 groupConservation = null;
1009 hcomplementConsensus = null;
1010 // colour scheme may hold reference to consensus
1011 residueShading = null;
1012 // TODO remove listeners from changeSupport?
1013 changeSupport = null;
1018 public boolean isClosed()
1020 // TODO: check that this isClosed is only true after panel is closed, not
1021 // before it is fully constructed.
1022 return alignment == null;
1026 public AlignCalcManagerI getCalcManager()
1032 * should conservation rows be shown for groups
1034 protected boolean showGroupConservation = false;
1037 * should consensus rows be shown for groups
1039 protected boolean showGroupConsensus = false;
1042 * should consensus profile be rendered by default
1044 protected boolean showSequenceLogo = false;
1047 * should consensus profile be rendered normalised to row height
1049 protected boolean normaliseSequenceLogo = false;
1052 * should consensus histograms be rendered by default
1054 protected boolean showConsensusHistogram = true;
1057 * should hmm profile be rendered by default
1059 protected boolean showHMMSequenceLogo = false;
1062 * should hmm profile be rendered normalised to row height
1064 protected boolean normaliseHMMSequenceLogo = false;
1067 * should information histograms be rendered by default
1069 protected boolean showInformationHistogram = true;
1072 * @return the showConsensusProfile
1075 public boolean isShowSequenceLogo()
1077 return showSequenceLogo;
1081 * @return the showInformationProfile
1084 public boolean isShowHMMSequenceLogo()
1086 return showHMMSequenceLogo;
1090 * @param showSequenceLogo
1093 public void setShowSequenceLogo(boolean showSequenceLogo)
1095 if (showSequenceLogo != this.showSequenceLogo)
1097 // TODO: decouple settings setting from calculation when refactoring
1098 // annotation update method from alignframe to viewport
1099 this.showSequenceLogo = showSequenceLogo;
1100 calculator.updateAnnotationFor(ConsensusThread.class);
1101 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1102 calculator.updateAnnotationFor(StrucConsensusThread.class);
1104 this.showSequenceLogo = showSequenceLogo;
1107 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1109 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1111 this.showHMMSequenceLogo = showHMMSequenceLogo;
1112 calculator.updateAnnotationFor(InformationThread.class);
1114 this.showHMMSequenceLogo = showHMMSequenceLogo;
1118 * @param showConsensusHistogram
1119 * the showConsensusHistogram to set
1121 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1123 this.showConsensusHistogram = showConsensusHistogram;
1127 * @param showInformationHistogram
1128 * the showInformationHistogram to set
1130 public void setShowInformationHistogram(boolean showInformationHistogram)
1132 this.showInformationHistogram = showInformationHistogram;
1136 * @return the showGroupConservation
1138 public boolean isShowGroupConservation()
1140 return showGroupConservation;
1144 * @param showGroupConservation
1145 * the showGroupConservation to set
1147 public void setShowGroupConservation(boolean showGroupConservation)
1149 this.showGroupConservation = showGroupConservation;
1153 * @return the showGroupConsensus
1155 public boolean isShowGroupConsensus()
1157 return showGroupConsensus;
1161 * @param showGroupConsensus
1162 * the showGroupConsensus to set
1164 public void setShowGroupConsensus(boolean showGroupConsensus)
1166 this.showGroupConsensus = showGroupConsensus;
1171 * @return flag to indicate if the consensus histogram should be rendered by
1175 public boolean isShowConsensusHistogram()
1177 return this.showConsensusHistogram;
1182 * @return flag to indicate if the information content histogram should be
1183 * rendered by default
1186 public boolean isShowInformationHistogram()
1188 return this.showInformationHistogram;
1192 * when set, updateAlignment will always ensure sequences are of equal length
1194 private boolean padGaps = false;
1197 * when set, alignment should be reordered according to a newly opened tree
1199 public boolean sortByTree = false;
1204 * @return null or the currently selected sequence region
1207 public SequenceGroup getSelectionGroup()
1209 return selectionGroup;
1213 * Set the selection group for this window. Also sets the current alignment as
1214 * the context for the group, if it does not already have one.
1217 * - group holding references to sequences in this alignment view
1221 public void setSelectionGroup(SequenceGroup sg)
1223 selectionGroup = sg;
1224 if (sg != null && sg.getContext() == null)
1226 sg.setContext(alignment);
1230 public void setHiddenColumns(HiddenColumns hidden)
1232 this.alignment.setHiddenColumns(hidden);
1236 public ColumnSelection getColumnSelection()
1242 public void setColumnSelection(ColumnSelection colSel)
1244 this.colSel = colSel;
1247 updateHiddenColumns();
1249 isColSelChanged(true);
1257 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1259 return hiddenRepSequences;
1263 public void setHiddenRepSequences(
1264 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1266 this.hiddenRepSequences = hiddenRepSequences;
1270 public boolean hasSelectedColumns()
1272 ColumnSelection columnSelection = getColumnSelection();
1273 return columnSelection != null && columnSelection.hasSelectedColumns();
1277 public boolean hasHiddenColumns()
1279 return colSel != null
1280 && alignment.getHiddenColumns().hasHiddenColumns();
1283 public void updateHiddenColumns()
1285 // this method doesn't really do anything now. But - it could, since a
1286 // column Selection could be in the process of modification
1287 // hasHiddenColumns = colSel.hasHiddenColumns();
1291 public boolean hasHiddenRows()
1293 return alignment.getHiddenSequences().getSize() > 0;
1296 protected SequenceGroup selectionGroup;
1298 public void setSequenceSetId(String newid)
1300 if (sequenceSetID != null)
1303 "Warning - overwriting a sequenceSetId for a viewport!");
1305 sequenceSetID = new String(newid);
1309 public String getSequenceSetId()
1311 if (sequenceSetID == null)
1313 sequenceSetID = alignment.hashCode() + "";
1316 return sequenceSetID;
1320 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1323 protected String viewId = null;
1326 public String getViewId()
1330 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1335 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1337 ignoreGapsInConsensusCalculation = b;
1340 updateConsensus(ap);
1341 if (residueShading != null)
1343 residueShading.setThreshold(residueShading.getThreshold(),
1344 ignoreGapsInConsensusCalculation);
1350 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1352 ignoreBelowBackGroundFrequencyCalculation = b;
1355 updateInformation(ap);
1360 private long sgrouphash = -1, colselhash = -1;
1363 * checks current SelectionGroup against record of last hash value, and
1367 * update the record of last hash value
1369 * @return true if SelectionGroup changed since last call (when b is true)
1371 public boolean isSelectionGroupChanged(boolean b)
1373 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1374 : selectionGroup.hashCode();
1375 if (hc != -1 && hc != sgrouphash)
1387 * checks current colsel against record of last hash value, and optionally
1391 * update the record of last hash value
1392 * @return true if colsel changed since last call (when b is true)
1394 public boolean isColSelChanged(boolean b)
1396 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1397 if (hc != -1 && hc != colselhash)
1409 public boolean isIgnoreGapsConsensus()
1411 return ignoreGapsInConsensusCalculation;
1415 public boolean isIgnoreBelowBackground()
1417 return ignoreBelowBackGroundFrequencyCalculation;
1420 // property change stuff
1421 // JBPNote Prolly only need this in the applet version.
1422 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1425 protected boolean showConservation = true;
1427 protected boolean showQuality = true;
1429 protected boolean showConsensus = true;
1431 protected boolean showOccupancy = true;
1433 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1435 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1437 protected boolean showAutocalculatedAbove;
1440 * when set, view will scroll to show the highlighted position
1442 private boolean followHighlight = true;
1445 * Property change listener for changes in alignment
1450 public void addPropertyChangeListener(
1451 java.beans.PropertyChangeListener listener)
1453 changeSupport.addPropertyChangeListener(listener);
1462 public void removePropertyChangeListener(
1463 java.beans.PropertyChangeListener listener)
1465 changeSupport.removePropertyChangeListener(listener);
1469 * Property change listener for changes in alignment
1478 public void firePropertyChange(String prop, Object oldvalue,
1481 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1484 // common hide/show column stuff
1486 public void hideSelectedColumns()
1488 if (colSel.isEmpty())
1493 colSel.hideSelectedColumns(alignment);
1494 setSelectionGroup(null);
1495 isColSelChanged(true);
1498 public void hideColumns(int start, int end)
1502 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1506 alignment.getHiddenColumns().hideColumns(start, end);
1508 isColSelChanged(true);
1511 public void showColumn(int col)
1513 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1514 isColSelChanged(true);
1517 public void showAllHiddenColumns()
1519 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1520 isColSelChanged(true);
1523 // common hide/show seq stuff
1524 public void showAllHiddenSeqs()
1526 if (alignment.getHiddenSequences().getSize() > 0)
1528 if (selectionGroup == null)
1530 selectionGroup = new SequenceGroup();
1531 selectionGroup.setEndRes(alignment.getWidth() - 1);
1533 List<SequenceI> tmp = alignment.getHiddenSequences()
1534 .showAll(hiddenRepSequences);
1535 for (SequenceI seq : tmp)
1537 selectionGroup.addSequence(seq, false);
1538 setSequenceAnnotationsVisible(seq, true);
1541 hiddenRepSequences = null;
1543 firePropertyChange("alignment", null, alignment.getSequences());
1544 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1550 public void showSequence(int index)
1552 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1553 hiddenRepSequences);
1556 if (selectionGroup == null)
1558 selectionGroup = new SequenceGroup();
1559 selectionGroup.setEndRes(alignment.getWidth() - 1);
1562 for (SequenceI seq : tmp)
1564 selectionGroup.addSequence(seq, false);
1565 setSequenceAnnotationsVisible(seq, true);
1567 firePropertyChange("alignment", null, alignment.getSequences());
1572 public void hideAllSelectedSeqs()
1574 if (selectionGroup == null || selectionGroup.getSize() < 1)
1579 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1583 setSelectionGroup(null);
1586 public void hideSequence(SequenceI[] seq)
1590 for (int i = 0; i < seq.length; i++)
1592 alignment.getHiddenSequences().hideSequence(seq[i]);
1593 setSequenceAnnotationsVisible(seq[i], false);
1595 firePropertyChange("alignment", null, alignment.getSequences());
1600 * Hides the specified sequence, or the sequences it represents
1603 * the sequence to hide, or keep as representative
1604 * @param representGroup
1605 * if true, hide the current selection group except for the
1606 * representative sequence
1608 public void hideSequences(SequenceI sequence, boolean representGroup)
1610 if (selectionGroup == null || selectionGroup.getSize() < 1)
1612 hideSequence(new SequenceI[] { sequence });
1618 hideRepSequences(sequence, selectionGroup);
1619 setSelectionGroup(null);
1623 int gsize = selectionGroup.getSize();
1624 SequenceI[] hseqs = selectionGroup.getSequences()
1625 .toArray(new SequenceI[gsize]);
1627 hideSequence(hseqs);
1628 setSelectionGroup(null);
1633 * Set visibility for any annotations for the given sequence.
1637 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1640 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1643 for (AlignmentAnnotation ann : anns)
1645 if (ann.sequenceRef == sequenceI)
1647 ann.visible = visible;
1653 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1655 int sSize = sg.getSize();
1661 if (hiddenRepSequences == null)
1663 hiddenRepSequences = new Hashtable<>();
1666 hiddenRepSequences.put(repSequence, sg);
1668 // Hide all sequences except the repSequence
1669 SequenceI[] seqs = new SequenceI[sSize - 1];
1671 for (int i = 0; i < sSize; i++)
1673 if (sg.getSequenceAt(i) != repSequence)
1675 if (index == sSize - 1)
1680 seqs[index++] = sg.getSequenceAt(i);
1683 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1684 sg.setHidereps(true); // note: not done in 2.7applet
1691 * @return null or the current reference sequence
1693 public SequenceI getReferenceSeq()
1695 return alignment.getSeqrep();
1700 * @return true iff seq is the reference for the alignment
1702 public boolean isReferenceSeq(SequenceI seq)
1704 return alignment.getSeqrep() == seq;
1710 * @return true if there are sequences represented by this sequence that are
1713 public boolean isHiddenRepSequence(SequenceI seq)
1715 return (hiddenRepSequences != null
1716 && hiddenRepSequences.containsKey(seq));
1722 * @return null or a sequence group containing the sequences that seq
1725 public SequenceGroup getRepresentedSequences(SequenceI seq)
1727 return (SequenceGroup) (hiddenRepSequences == null ? null
1728 : hiddenRepSequences.get(seq));
1732 public int adjustForHiddenSeqs(int alignmentIndex)
1734 return alignment.getHiddenSequences()
1735 .adjustForHiddenSeqs(alignmentIndex);
1739 public void invertColumnSelection()
1741 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1745 public SequenceI[] getSelectionAsNewSequence()
1747 SequenceI[] sequences;
1748 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1749 // this was the only caller in the applet for this method
1750 // JBPNote: in applet, this method returned references to the alignment
1751 // sequences, and it did not honour the presence/absence of annotation
1752 // attached to the alignment (probably!)
1753 if (selectionGroup == null || selectionGroup.getSize() == 0)
1755 sequences = alignment.getSequencesArray();
1756 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1757 for (int i = 0; i < sequences.length; i++)
1759 // construct new sequence with subset of visible annotation
1760 sequences[i] = new Sequence(sequences[i], annots);
1765 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1772 public SequenceI[] getSequenceSelection()
1774 SequenceI[] sequences = null;
1775 if (selectionGroup != null)
1777 sequences = selectionGroup.getSequencesInOrder(alignment);
1779 if (sequences == null)
1781 sequences = alignment.getSequencesArray();
1787 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1789 return new CigarArray(alignment, alignment.getHiddenColumns(),
1790 (selectedRegionOnly ? selectionGroup : null));
1794 public jalview.datamodel.AlignmentView getAlignmentView(
1795 boolean selectedOnly)
1797 return getAlignmentView(selectedOnly, false);
1801 public jalview.datamodel.AlignmentView getAlignmentView(
1802 boolean selectedOnly, boolean markGroups)
1804 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1805 selectionGroup, alignment.getHiddenColumns() != null
1806 && alignment.getHiddenColumns().hasHiddenColumns(),
1807 selectedOnly, markGroups);
1811 public String[] getViewAsString(boolean selectedRegionOnly)
1813 return getViewAsString(selectedRegionOnly, true);
1817 public String[] getViewAsString(boolean selectedRegionOnly,
1818 boolean exportHiddenSeqs)
1820 String[] selection = null;
1821 SequenceI[] seqs = null;
1823 int start = 0, end = 0;
1824 if (selectedRegionOnly && selectionGroup != null)
1826 iSize = selectionGroup.getSize();
1827 seqs = selectionGroup.getSequencesInOrder(alignment);
1828 start = selectionGroup.getStartRes();
1829 end = selectionGroup.getEndRes() + 1;
1833 if (hasHiddenRows() && exportHiddenSeqs)
1835 AlignmentI fullAlignment = alignment.getHiddenSequences()
1836 .getFullAlignment();
1837 iSize = fullAlignment.getHeight();
1838 seqs = fullAlignment.getSequencesArray();
1839 end = fullAlignment.getWidth();
1843 iSize = alignment.getHeight();
1844 seqs = alignment.getSequencesArray();
1845 end = alignment.getWidth();
1849 selection = new String[iSize];
1850 if (alignment.getHiddenColumns() != null
1851 && alignment.getHiddenColumns().hasHiddenColumns())
1853 selection = alignment.getHiddenColumns()
1854 .getVisibleSequenceStrings(start, end, seqs);
1858 for (i = 0; i < iSize; i++)
1860 selection[i] = seqs[i].getSequenceAsString(start, end);
1868 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1870 ArrayList<int[]> regions = new ArrayList<>();
1876 HiddenColumns hidden = alignment.getHiddenColumns();
1877 if (hidden != null && hidden.hasHiddenColumns())
1881 start = hidden.adjustForHiddenColumns(start);
1884 end = hidden.getHiddenBoundaryRight(start);
1895 regions.add(new int[] { start, end });
1897 if (hidden != null && hidden.hasHiddenColumns())
1899 start = hidden.adjustForHiddenColumns(end);
1900 start = hidden.getHiddenBoundaryLeft(start) + 1;
1902 } while (end < max);
1904 int[][] startEnd = new int[regions.size()][2];
1910 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1911 boolean selectedOnly)
1913 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1914 AlignmentAnnotation[] aa;
1915 if ((aa = alignment.getAlignmentAnnotation()) != null)
1917 for (AlignmentAnnotation annot : aa)
1919 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1920 if (selectedOnly && selectionGroup != null)
1922 alignment.getHiddenColumns().makeVisibleAnnotation(
1923 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1928 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1937 public boolean isPadGaps()
1943 public void setPadGaps(boolean padGaps)
1945 this.padGaps = padGaps;
1949 * apply any post-edit constraints and trigger any calculations needed after
1950 * an edit has been performed on the alignment
1955 public void alignmentChanged(AlignmentViewPanel ap)
1959 alignment.padGaps();
1961 if (autoCalculateConsensus)
1963 updateConsensus(ap);
1965 if (hconsensus != null && autoCalculateConsensus)
1967 updateConservation(ap);
1969 if (autoCalculateStrucConsensus)
1971 updateStrucConsensus(ap);
1973 updateInformation(ap);
1975 List<SequenceI> hmmSequences;
1976 hmmSequences = alignment.getHMMConsensusSequences(false);
1978 for (SequenceI seq : hmmSequences)
1980 seq.updateHMMMapping();
1983 // Reset endRes of groups if beyond alignment width
1984 int alWidth = alignment.getWidth();
1985 List<SequenceGroup> groups = alignment.getGroups();
1988 for (SequenceGroup sg : groups)
1990 if (sg.getEndRes() > alWidth)
1992 sg.setEndRes(alWidth - 1);
1997 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1999 selectionGroup.setEndRes(alWidth - 1);
2002 updateAllColourSchemes();
2003 calculator.restartWorkers();
2004 // alignment.adjustSequenceAnnotations();
2008 * reset scope and do calculations for all applied colourschemes on alignment
2010 void updateAllColourSchemes()
2012 ResidueShaderI rs = residueShading;
2015 rs.alignmentChanged(alignment, hiddenRepSequences);
2017 rs.setConsensus(hconsensus);
2018 if (rs.conservationApplied())
2020 rs.setConservation(Conservation.calculateConservation("All",
2021 alignment.getSequences(), 0, alignment.getWidth(), false,
2022 getConsPercGaps(), false));
2026 for (SequenceGroup sg : alignment.getGroups())
2030 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2032 sg.recalcConservation();
2036 protected void initAutoAnnotation()
2038 // TODO: add menu option action that nulls or creates consensus object
2039 // depending on if the user wants to see the annotation or not in a
2040 // specific alignment
2042 if (hconsensus == null && !isDataset)
2044 if (!alignment.isNucleotide())
2053 consensus = new AlignmentAnnotation("Consensus",
2054 MessageManager.getString("label.consensus_descr"),
2055 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2056 initConsensus(consensus);
2060 initComplementConsensus();
2065 * If this is a protein alignment and there are mappings to cDNA, adds the
2066 * cDNA consensus annotation and returns true, else returns false.
2068 public boolean initComplementConsensus()
2070 if (!alignment.isNucleotide())
2072 final List<AlignedCodonFrame> codonMappings = alignment
2074 if (codonMappings != null && !codonMappings.isEmpty())
2076 boolean doConsensus = false;
2077 for (AlignedCodonFrame mapping : codonMappings)
2079 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2080 MapList[] mapLists = mapping.getdnaToProt();
2081 // mapLists can be empty if project load has not finished resolving
2083 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2091 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2093 .getString("label.complement_consensus_descr"),
2094 new Annotation[1], 0f, 100f,
2095 AlignmentAnnotation.BAR_GRAPH);
2096 initConsensus(complementConsensus);
2104 private void initConsensus(AlignmentAnnotation aa)
2107 aa.autoCalculated = true;
2111 alignment.addAnnotation(aa);
2116 public void initInformation()
2118 for (SequenceI seq : alignment.getHMMConsensusSequences(false))
2120 if (!seq.hasHMMAnnotation())
2122 AlignmentAnnotation information;
2123 information = new AlignmentAnnotation(seq.getName(),
2124 MessageManager.getString("label.information_description"),
2125 new Annotation[1], 0f, 6.52f,
2126 AlignmentAnnotation.BAR_GRAPH);
2127 information.hasText = true;
2128 information.autoCalculated = true;
2129 information.hasText = true;
2130 information.autoCalculated = false;
2131 information.sequenceRef = seq;
2132 information.setCalcId("HMM annotation");
2133 this.information.add(information);
2134 hinformation.add(new Profiles(new ProfileI[1]));
2135 alignment.addAnnotation(information);
2136 seq.updateHMMMapping();
2137 seq.setHasInfo(true);
2138 seq.addAlignmentAnnotation(information);
2144 // these should be extracted from the view model - style and settings for
2145 // derived annotation
2146 private void initGapCounts()
2150 gapcounts = new AlignmentAnnotation("Occupancy",
2151 MessageManager.getString("label.occupancy_descr"),
2152 new Annotation[1], 0f, alignment.getHeight(),
2153 AlignmentAnnotation.BAR_GRAPH);
2154 gapcounts.hasText = true;
2155 gapcounts.autoCalculated = true;
2156 gapcounts.scaleColLabel = true;
2157 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2159 alignment.addAnnotation(gapcounts);
2163 private void initConservation()
2165 if (showConservation)
2167 if (conservation == null)
2169 conservation = new AlignmentAnnotation("Conservation",
2170 MessageManager.formatMessage("label.conservation_descr",
2172 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2173 conservation.hasText = true;
2174 conservation.autoCalculated = true;
2175 alignment.addAnnotation(conservation);
2180 private void initQuality()
2184 if (quality == null)
2186 quality = new AlignmentAnnotation("Quality",
2187 MessageManager.getString("label.quality_descr"),
2188 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2189 quality.hasText = true;
2190 quality.autoCalculated = true;
2191 alignment.addAnnotation(quality);
2196 private void initRNAStructure()
2198 if (alignment.hasRNAStructure() && strucConsensus == null)
2200 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2201 MessageManager.getString("label.strucconsensus_descr"),
2202 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2203 strucConsensus.hasText = true;
2204 strucConsensus.autoCalculated = true;
2208 alignment.addAnnotation(strucConsensus);
2216 * @see jalview.api.AlignViewportI#calcPanelHeight()
2219 public int calcPanelHeight()
2221 // setHeight of panels
2222 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2224 int charHeight = getCharHeight();
2227 BitSet graphgrp = new BitSet();
2228 for (AlignmentAnnotation aa : anns)
2232 System.err.println("Null annotation row: ignoring.");
2239 if (aa.graphGroup > -1)
2241 if (graphgrp.get(aa.graphGroup))
2247 graphgrp.set(aa.graphGroup);
2254 aa.height += charHeight;
2264 aa.height += aa.graphHeight;
2272 height += aa.height;
2284 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2285 boolean preserveNewGroupSettings)
2287 boolean updateCalcs = false;
2288 boolean conv = isShowGroupConservation();
2289 boolean cons = isShowGroupConsensus();
2290 boolean showprf = isShowSequenceLogo();
2291 boolean showConsHist = isShowConsensusHistogram();
2292 boolean normLogo = isNormaliseSequenceLogo();
2293 boolean showHMMPrf = isShowHMMSequenceLogo();
2294 boolean showInfoHist = isShowInformationHistogram();
2295 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2298 * TODO reorder the annotation rows according to group/sequence ordering on
2301 boolean sortg = true;
2303 // remove old automatic annotation
2304 // add any new annotation
2306 // intersect alignment annotation with alignment groups
2308 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2309 List<SequenceGroup> oldrfs = new ArrayList<>();
2312 for (int an = 0; an < aan.length; an++)
2314 if (aan[an].autoCalculated && aan[an].groupRef != null)
2316 oldrfs.add(aan[an].groupRef);
2317 alignment.deleteAnnotation(aan[an], false);
2321 if (alignment.getGroups() != null)
2323 for (SequenceGroup sg : alignment.getGroups())
2325 updateCalcs = false;
2326 if (applyGlobalSettings
2327 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2329 // set defaults for this group's conservation/consensus
2330 sg.setshowSequenceLogo(showprf);
2331 sg.setShowConsensusHistogram(showConsHist);
2332 sg.setNormaliseSequenceLogo(normLogo);
2333 sg.setshowHMMSequenceLogo(showHMMPrf);
2334 sg.setShowInformationHistogram(showInfoHist);
2335 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2340 alignment.addAnnotation(sg.getConservationRow(), 0);
2345 alignment.addAnnotation(sg.getConsensus(), 0);
2347 // refresh the annotation rows
2350 sg.recalcConservation();
2358 public boolean isDisplayReferenceSeq()
2360 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2364 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2366 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2370 public boolean isColourByReferenceSeq()
2372 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2376 public Color getSequenceColour(SequenceI seq)
2378 Color sqc = sequenceColours.get(seq);
2379 return (sqc == null ? Color.white : sqc);
2383 public void setSequenceColour(SequenceI seq, Color col)
2387 sequenceColours.remove(seq);
2391 sequenceColours.put(seq, col);
2396 public void updateSequenceIdColours()
2398 for (SequenceGroup sg : alignment.getGroups())
2400 if (sg.idColour != null)
2402 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2404 sequenceColours.put(s, sg.idColour);
2411 public void clearSequenceColours()
2413 sequenceColours.clear();
2417 public AlignViewportI getCodingComplement()
2419 return this.codingComplement;
2423 * Set this as the (cDna/protein) complement of the given viewport. Also
2424 * ensures the reverse relationship is set on the given viewport.
2427 public void setCodingComplement(AlignViewportI av)
2431 System.err.println("Ignoring recursive setCodingComplement request");
2435 this.codingComplement = av;
2436 // avoid infinite recursion!
2437 if (av.getCodingComplement() != this)
2439 av.setCodingComplement(this);
2445 public boolean isNucleotide()
2447 return getAlignment() == null ? false : getAlignment().isNucleotide();
2451 public FeaturesDisplayedI getFeaturesDisplayed()
2453 return featuresDisplayed;
2457 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2459 featuresDisplayed = featuresDisplayedI;
2463 public boolean areFeaturesDisplayed()
2465 return featuresDisplayed != null
2466 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2473 * features are displayed if true
2476 public void setShowSequenceFeatures(boolean b)
2478 viewStyle.setShowSequenceFeatures(b);
2482 public boolean isShowSequenceFeatures()
2484 return viewStyle.isShowSequenceFeatures();
2488 public void setShowSequenceFeaturesHeight(boolean selected)
2490 viewStyle.setShowSequenceFeaturesHeight(selected);
2494 public boolean isShowSequenceFeaturesHeight()
2496 return viewStyle.isShowSequenceFeaturesHeight();
2500 public void setShowAnnotation(boolean b)
2502 viewStyle.setShowAnnotation(b);
2506 public boolean isShowAnnotation()
2508 return viewStyle.isShowAnnotation();
2512 public boolean isRightAlignIds()
2514 return viewStyle.isRightAlignIds();
2518 public void setRightAlignIds(boolean rightAlignIds)
2520 viewStyle.setRightAlignIds(rightAlignIds);
2524 public boolean getConservationSelected()
2526 return viewStyle.getConservationSelected();
2530 public void setShowBoxes(boolean state)
2532 viewStyle.setShowBoxes(state);
2537 * @see jalview.api.ViewStyleI#getTextColour()
2540 public Color getTextColour()
2542 return viewStyle.getTextColour();
2547 * @see jalview.api.ViewStyleI#getTextColour2()
2550 public Color getTextColour2()
2552 return viewStyle.getTextColour2();
2557 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2560 public int getThresholdTextColour()
2562 return viewStyle.getThresholdTextColour();
2567 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2570 public boolean isConservationColourSelected()
2572 return viewStyle.isConservationColourSelected();
2577 * @see jalview.api.ViewStyleI#isRenderGaps()
2580 public boolean isRenderGaps()
2582 return viewStyle.isRenderGaps();
2587 * @see jalview.api.ViewStyleI#isShowColourText()
2590 public boolean isShowColourText()
2592 return viewStyle.isShowColourText();
2596 * @param conservationColourSelected
2597 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2600 public void setConservationColourSelected(
2601 boolean conservationColourSelected)
2603 viewStyle.setConservationColourSelected(conservationColourSelected);
2607 * @param showColourText
2608 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2611 public void setShowColourText(boolean showColourText)
2613 viewStyle.setShowColourText(showColourText);
2618 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2621 public void setTextColour(Color textColour)
2623 viewStyle.setTextColour(textColour);
2627 * @param thresholdTextColour
2628 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2631 public void setThresholdTextColour(int thresholdTextColour)
2633 viewStyle.setThresholdTextColour(thresholdTextColour);
2637 * @param textColour2
2638 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2641 public void setTextColour2(Color textColour2)
2643 viewStyle.setTextColour2(textColour2);
2647 public ViewStyleI getViewStyle()
2649 return new ViewStyle(viewStyle);
2653 public void setViewStyle(ViewStyleI settingsForView)
2655 viewStyle = new ViewStyle(settingsForView);
2656 if (residueShading != null)
2658 residueShading.setConservationApplied(
2659 settingsForView.isConservationColourSelected());
2664 public boolean sameStyle(ViewStyleI them)
2666 return viewStyle.sameStyle(them);
2671 * @see jalview.api.ViewStyleI#getIdWidth()
2674 public int getIdWidth()
2676 return viewStyle.getIdWidth();
2681 * @see jalview.api.ViewStyleI#setIdWidth(int)
2684 public void setIdWidth(int i)
2686 viewStyle.setIdWidth(i);
2691 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2694 public boolean isCentreColumnLabels()
2696 return viewStyle.isCentreColumnLabels();
2700 * @param centreColumnLabels
2701 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2704 public void setCentreColumnLabels(boolean centreColumnLabels)
2706 viewStyle.setCentreColumnLabels(centreColumnLabels);
2711 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2714 public void setShowDBRefs(boolean showdbrefs)
2716 viewStyle.setShowDBRefs(showdbrefs);
2721 * @see jalview.api.ViewStyleI#isShowDBRefs()
2724 public boolean isShowDBRefs()
2726 return viewStyle.isShowDBRefs();
2731 * @see jalview.api.ViewStyleI#isShowNPFeats()
2734 public boolean isShowNPFeats()
2736 return viewStyle.isShowNPFeats();
2740 * @param shownpfeats
2741 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2744 public void setShowNPFeats(boolean shownpfeats)
2746 viewStyle.setShowNPFeats(shownpfeats);
2749 public abstract StructureSelectionManager getStructureSelectionManager();
2752 * Add one command to the command history list.
2756 public void addToHistoryList(CommandI command)
2758 if (this.historyList != null)
2760 this.historyList.push(command);
2761 broadcastCommand(command, false);
2765 protected void broadcastCommand(CommandI command, boolean undo)
2767 getStructureSelectionManager().commandPerformed(command, undo,
2772 * Add one command to the command redo list.
2776 public void addToRedoList(CommandI command)
2778 if (this.redoList != null)
2780 this.redoList.push(command);
2782 broadcastCommand(command, true);
2786 * Clear the command redo list.
2788 public void clearRedoList()
2790 if (this.redoList != null)
2792 this.redoList.clear();
2796 public void setHistoryList(Deque<CommandI> list)
2798 this.historyList = list;
2801 public Deque<CommandI> getHistoryList()
2803 return this.historyList;
2806 public void setRedoList(Deque<CommandI> list)
2808 this.redoList = list;
2811 public Deque<CommandI> getRedoList()
2813 return this.redoList;
2817 public VamsasSource getVamsasSource()
2822 public SequenceAnnotationOrder getSortAnnotationsBy()
2824 return sortAnnotationsBy;
2827 public void setSortAnnotationsBy(
2828 SequenceAnnotationOrder sortAnnotationsBy)
2830 this.sortAnnotationsBy = sortAnnotationsBy;
2833 public boolean isShowAutocalculatedAbove()
2835 return showAutocalculatedAbove;
2838 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2840 this.showAutocalculatedAbove = showAutocalculatedAbove;
2844 public boolean isScaleProteinAsCdna()
2846 return viewStyle.isScaleProteinAsCdna();
2850 public void setScaleProteinAsCdna(boolean b)
2852 viewStyle.setScaleProteinAsCdna(b);
2856 public boolean isProteinFontAsCdna()
2858 return viewStyle.isProteinFontAsCdna();
2862 public void setProteinFontAsCdna(boolean b)
2864 viewStyle.setProteinFontAsCdna(b);
2868 * @return true if view should scroll to show the highlighted region of a
2873 public final boolean isFollowHighlight()
2875 return followHighlight;
2879 public final void setFollowHighlight(boolean b)
2881 this.followHighlight = b;
2885 public ViewportRanges getRanges()
2891 * Helper method to populate the SearchResults with the location in the
2892 * complementary alignment to scroll to, in order to match this one.
2895 * the SearchResults to add to
2896 * @return the offset (below top of visible region) of the matched sequence
2898 protected int findComplementScrollTarget(SearchResultsI sr)
2900 final AlignViewportI complement = getCodingComplement();
2901 if (complement == null || !complement.isFollowHighlight())
2905 boolean iAmProtein = !getAlignment().isNucleotide();
2906 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2907 : complement.getAlignment();
2908 if (proteinAlignment == null)
2912 final List<AlignedCodonFrame> mappings = proteinAlignment
2916 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2917 * residue in the middle column of the visible region. Scroll the
2918 * complementary alignment to line up the corresponding residue.
2921 SequenceI sequence = null;
2924 * locate 'middle' column (true middle if an odd number visible, left of
2925 * middle if an even number visible)
2927 int middleColumn = ranges.getStartRes()
2928 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2929 final HiddenSequences hiddenSequences = getAlignment()
2930 .getHiddenSequences();
2933 * searching to the bottom of the alignment gives smoother scrolling across
2934 * all gapped visible regions
2936 int lastSeq = alignment.getHeight() - 1;
2937 List<AlignedCodonFrame> seqMappings = null;
2938 for (int seqNo = ranges
2939 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2941 sequence = getAlignment().getSequenceAt(seqNo);
2942 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2946 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2950 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2952 getCodingComplement().getAlignment().getSequences());
2953 if (!seqMappings.isEmpty())
2959 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2962 * No ungapped mapped sequence in middle column - do nothing
2966 MappingUtils.addSearchResults(sr, sequence,
2967 sequence.findPosition(middleColumn), seqMappings);
2972 * synthesize a column selection if none exists so it covers the given
2973 * selection group. if wholewidth is false, no column selection is made if the
2974 * selection group covers the whole alignment width.
2979 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2982 if (sg != null && (sgs = sg.getStartRes()) >= 0
2983 && sg.getStartRes() <= (sge = sg.getEndRes())
2984 && !this.hasSelectedColumns())
2986 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2993 colSel = new ColumnSelection();
2995 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2997 colSel.addElement(cspos);
3003 * hold status of current selection group - defined on alignment or not.
3005 private boolean selectionIsDefinedGroup = false;
3008 public boolean isSelectionDefinedGroup()
3010 if (selectionGroup == null)
3014 if (isSelectionGroupChanged(true))
3016 selectionIsDefinedGroup = false;
3017 List<SequenceGroup> gps = alignment.getGroups();
3018 if (gps == null || gps.size() == 0)
3020 selectionIsDefinedGroup = false;
3024 selectionIsDefinedGroup = gps.contains(selectionGroup);
3027 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3031 * null, or currently highlighted results on this view
3033 private SearchResultsI searchResults = null;
3036 public boolean hasSearchResults()
3038 return searchResults != null;
3042 public void setSearchResults(SearchResultsI results)
3044 searchResults = results;
3048 public SearchResultsI getSearchResults()
3050 return searchResults;
3054 * Gets the selected hidden Markov model