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.HiddenMarkovModel;
40 import jalview.datamodel.HiddenSequences;
41 import jalview.datamodel.ProfileI;
42 import jalview.datamodel.Profiles;
43 import jalview.datamodel.ProfilesI;
44 import jalview.datamodel.SearchResultsI;
45 import jalview.datamodel.Sequence;
46 import jalview.datamodel.SequenceCollectionI;
47 import jalview.datamodel.SequenceGroup;
48 import jalview.datamodel.SequenceI;
49 import jalview.renderer.ResidueShader;
50 import jalview.renderer.ResidueShaderI;
51 import jalview.schemes.ColourSchemeI;
52 import jalview.structure.CommandListener;
53 import jalview.structure.StructureSelectionManager;
54 import jalview.structure.VamsasSource;
55 import jalview.util.Comparison;
56 import jalview.util.MapList;
57 import jalview.util.MappingUtils;
58 import jalview.util.MessageManager;
59 import jalview.viewmodel.styles.ViewStyle;
60 import jalview.workers.AlignCalcManager;
61 import jalview.workers.ComplementConsensusThread;
62 import jalview.workers.ConsensusThread;
63 import jalview.workers.InformationThread;
64 import jalview.workers.StrucConsensusThread;
66 import java.awt.Color;
67 import java.beans.PropertyChangeSupport;
68 import java.util.ArrayDeque;
69 import java.util.ArrayList;
70 import java.util.BitSet;
71 import java.util.Deque;
72 import java.util.HashMap;
73 import java.util.Hashtable;
74 import java.util.List;
78 * base class holding visualization and analysis attributes and common logic for
79 * an active alignment view displayed in the GUI
84 public abstract class AlignmentViewport
85 implements AlignViewportI, CommandListener, VamsasSource
87 final protected ViewportRanges ranges;
89 protected ViewStyleI viewStyle = new ViewStyle();
92 * A viewport that hosts the cDna view of this (protein), or vice versa (if
95 AlignViewportI codingComplement = null;
97 FeaturesDisplayedI featuresDisplayed = null;
99 protected Deque<CommandI> historyList = new ArrayDeque<>();
101 protected Deque<CommandI> redoList = new ArrayDeque<>();
103 HiddenMarkovModel selectedHMM;
106 * alignment displayed in the viewport. Please use get/setter
108 protected AlignmentI alignment;
110 public AlignmentViewport(AlignmentI al)
113 ranges = new ViewportRanges(al);
118 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
121 public void setFontName(String name)
123 viewStyle.setFontName(name);
128 * @see jalview.api.ViewStyleI#setFontStyle(int)
131 public void setFontStyle(int style)
133 viewStyle.setFontStyle(style);
138 * @see jalview.api.ViewStyleI#setFontSize(int)
141 public void setFontSize(int size)
143 viewStyle.setFontSize(size);
148 * @see jalview.api.ViewStyleI#getFontStyle()
151 public int getFontStyle()
153 return viewStyle.getFontStyle();
158 * @see jalview.api.ViewStyleI#getFontName()
161 public String getFontName()
163 return viewStyle.getFontName();
168 * @see jalview.api.ViewStyleI#getFontSize()
171 public int getFontSize()
173 return viewStyle.getFontSize();
177 * @param upperCasebold
178 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
181 public void setUpperCasebold(boolean upperCasebold)
183 viewStyle.setUpperCasebold(upperCasebold);
188 * @see jalview.api.ViewStyleI#isUpperCasebold()
191 public boolean isUpperCasebold()
193 return viewStyle.isUpperCasebold();
198 * @see jalview.api.ViewStyleI#isSeqNameItalics()
201 public boolean isSeqNameItalics()
203 return viewStyle.isSeqNameItalics();
207 * @param colourByReferenceSeq
208 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
211 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
213 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
218 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
221 public void setColourAppliesToAllGroups(boolean b)
223 viewStyle.setColourAppliesToAllGroups(b);
228 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
231 public boolean getColourAppliesToAllGroups()
233 return viewStyle.getColourAppliesToAllGroups();
238 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
241 public boolean getAbovePIDThreshold()
243 return viewStyle.getAbovePIDThreshold();
248 * @see jalview.api.ViewStyleI#setIncrement(int)
251 public void setIncrement(int inc)
253 viewStyle.setIncrement(inc);
258 * @see jalview.api.ViewStyleI#getIncrement()
261 public int getIncrement()
263 return viewStyle.getIncrement();
268 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
271 public void setConservationSelected(boolean b)
273 viewStyle.setConservationSelected(b);
278 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
281 public void setShowHiddenMarkers(boolean show)
283 viewStyle.setShowHiddenMarkers(show);
288 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
291 public boolean getShowHiddenMarkers()
293 return viewStyle.getShowHiddenMarkers();
298 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
301 public void setScaleRightWrapped(boolean b)
303 viewStyle.setScaleRightWrapped(b);
308 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
311 public void setScaleLeftWrapped(boolean b)
313 viewStyle.setScaleLeftWrapped(b);
318 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
321 public void setScaleAboveWrapped(boolean b)
323 viewStyle.setScaleAboveWrapped(b);
328 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
331 public boolean getScaleLeftWrapped()
333 return viewStyle.getScaleLeftWrapped();
338 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
341 public boolean getScaleAboveWrapped()
343 return viewStyle.getScaleAboveWrapped();
348 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
351 public boolean getScaleRightWrapped()
353 return viewStyle.getScaleRightWrapped();
358 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
361 public void setAbovePIDThreshold(boolean b)
363 viewStyle.setAbovePIDThreshold(b);
368 * @see jalview.api.ViewStyleI#setThreshold(int)
371 public void setThreshold(int thresh)
373 viewStyle.setThreshold(thresh);
378 * @see jalview.api.ViewStyleI#getThreshold()
381 public int getThreshold()
383 return viewStyle.getThreshold();
388 * @see jalview.api.ViewStyleI#getShowJVSuffix()
391 public boolean getShowJVSuffix()
393 return viewStyle.getShowJVSuffix();
398 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
401 public void setShowJVSuffix(boolean b)
403 viewStyle.setShowJVSuffix(b);
408 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
411 public void setWrapAlignment(boolean state)
413 viewStyle.setWrapAlignment(state);
418 * @see jalview.api.ViewStyleI#setShowText(boolean)
421 public void setShowText(boolean state)
423 viewStyle.setShowText(state);
428 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
431 public void setRenderGaps(boolean state)
433 viewStyle.setRenderGaps(state);
438 * @see jalview.api.ViewStyleI#getColourText()
441 public boolean getColourText()
443 return viewStyle.getColourText();
448 * @see jalview.api.ViewStyleI#setColourText(boolean)
451 public void setColourText(boolean state)
453 viewStyle.setColourText(state);
458 * @see jalview.api.ViewStyleI#getWrapAlignment()
461 public boolean getWrapAlignment()
463 return viewStyle.getWrapAlignment();
468 * @see jalview.api.ViewStyleI#getShowText()
471 public boolean getShowText()
473 return viewStyle.getShowText();
478 * @see jalview.api.ViewStyleI#getWrappedWidth()
481 public int getWrappedWidth()
483 return viewStyle.getWrappedWidth();
488 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
491 public void setWrappedWidth(int w)
493 viewStyle.setWrappedWidth(w);
498 * @see jalview.api.ViewStyleI#getCharHeight()
501 public int getCharHeight()
503 return viewStyle.getCharHeight();
508 * @see jalview.api.ViewStyleI#setCharHeight(int)
511 public void setCharHeight(int h)
513 viewStyle.setCharHeight(h);
518 * @see jalview.api.ViewStyleI#getCharWidth()
521 public int getCharWidth()
523 return viewStyle.getCharWidth();
528 * @see jalview.api.ViewStyleI#setCharWidth(int)
531 public void setCharWidth(int w)
533 viewStyle.setCharWidth(w);
538 * @see jalview.api.ViewStyleI#getShowBoxes()
541 public boolean getShowBoxes()
543 return viewStyle.getShowBoxes();
548 * @see jalview.api.ViewStyleI#getShowUnconserved()
551 public boolean getShowUnconserved()
553 return viewStyle.getShowUnconserved();
557 * @param showunconserved
558 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
561 public void setShowUnconserved(boolean showunconserved)
563 viewStyle.setShowUnconserved(showunconserved);
568 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
571 public void setSeqNameItalics(boolean default1)
573 viewStyle.setSeqNameItalics(default1);
577 public AlignmentI getAlignment()
583 public char getGapCharacter()
585 return alignment.getGapCharacter();
588 protected String sequenceSetID;
591 * probably unused indicator that view is of a dataset rather than an
594 protected boolean isDataset = false;
596 public void setDataset(boolean b)
601 public boolean isDataset()
606 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
608 protected ColumnSelection colSel = new ColumnSelection();
610 public boolean autoCalculateConsensus = true;
612 public boolean autoCalculateInformation = true;
614 protected boolean autoCalculateStrucConsensus = true;
616 protected boolean ignoreGapsInConsensusCalculation = false;
618 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
620 protected ResidueShaderI residueShading = new ResidueShader();
623 public void setGlobalColourScheme(ColourSchemeI cs)
625 // TODO: logic refactored from AlignFrame changeColour -
626 // TODO: autorecalc stuff should be changed to rely on the worker system
627 // check to see if we should implement a changeColour(cs) method rather than
628 // put the logic in here
629 // - means that caller decides if they want to just modify state and defer
630 // calculation till later or to do all calculations in thread.
634 * only instantiate alignment colouring once, thereafter update it;
635 * this means that any conservation or PID threshold settings
636 * persist when the alignment colour scheme is changed
638 if (residueShading == null)
640 residueShading = new ResidueShader(viewStyle);
642 residueShading.setColourScheme(cs);
644 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
645 // ...problem: groups need these, but do not currently have a ViewStyle
649 if (getConservationSelected())
651 residueShading.setConservation(hconservation);
653 residueShading.alignmentChanged(alignment, hiddenRepSequences);
657 * if 'apply colour to all groups' is selected... do so
658 * (but don't transfer any colour threshold settings to groups)
660 if (getColourAppliesToAllGroups())
662 for (SequenceGroup sg : getAlignment().getGroups())
665 * retain any colour thresholds per group while
666 * changing choice of colour scheme (JAL-2386)
668 sg.setColourScheme(cs);
671 sg.getGroupColourScheme().alignmentChanged(sg,
679 public ColourSchemeI getGlobalColourScheme()
681 return residueShading == null ? null : residueShading.getColourScheme();
685 public ResidueShaderI getResidueShading()
687 return residueShading;
690 protected AlignmentAnnotation consensus;
692 protected AlignmentAnnotation complementConsensus;
694 protected AlignmentAnnotation gapcounts;
696 protected AlignmentAnnotation strucConsensus;
698 protected AlignmentAnnotation conservation;
700 protected AlignmentAnnotation quality;
702 protected AlignmentAnnotation[] groupConsensus;
704 protected AlignmentAnnotation[] groupConservation;
706 protected List<AlignmentAnnotation> groupInformation = new ArrayList<>();
708 protected List<AlignmentAnnotation> information = new ArrayList<>();
711 * results of alignment consensus analysis for visible portion of view
713 protected ProfilesI hconsensus = null;
715 protected List<ProfilesI> hinformation = new ArrayList<>();
718 * results of cDNA complement consensus visible portion of view
720 protected Hashtable[] hcomplementConsensus = null;
723 * results of secondary structure base pair consensus for visible portion of
726 protected Hashtable[] hStrucConsensus = null;
728 protected Conservation hconservation = null;
731 public void setConservation(Conservation cons)
733 hconservation = cons;
737 * percentage gaps allowed in a column before all amino acid properties should
738 * be considered unconserved
740 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
743 public int getConsPercGaps()
749 public void setSequenceConsensusHash(ProfilesI hconsensus)
751 this.hconsensus = hconsensus;
755 public void setComplementConsensusHash(Hashtable[] hconsensus)
757 this.hcomplementConsensus = hconsensus;
761 public ProfilesI getSequenceConsensusHash()
767 public void setSequenceInformationHashes(List<ProfilesI> info)
773 public void setSequenceInformationHash(ProfilesI info, int index)
775 hinformation.set(index, info);
779 public List<ProfilesI> getSequenceInformationHashes()
785 public ProfilesI getSequenceInformationHash(int index)
787 return hinformation.get(index);
791 public Hashtable[] getComplementConsensusHash()
793 return hcomplementConsensus;
797 public Hashtable[] getRnaStructureConsensusHash()
799 return hStrucConsensus;
803 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
805 this.hStrucConsensus = hStrucConsensus;
810 public AlignmentAnnotation getAlignmentQualityAnnot()
816 public AlignmentAnnotation getAlignmentConservationAnnotation()
822 public AlignmentAnnotation getAlignmentConsensusAnnotation()
828 public List<AlignmentAnnotation> getInformationAnnotations()
834 public AlignmentAnnotation getInformationAnnotation(int index)
836 return information.get(index);
840 public AlignmentAnnotation getAlignmentGapAnnotation()
846 public AlignmentAnnotation getComplementConsensusAnnotation()
848 return complementConsensus;
852 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
854 return strucConsensus;
857 protected AlignCalcManagerI calculator = new AlignCalcManager();
860 * trigger update of conservation annotation
862 public void updateConservation(final AlignmentViewPanel ap)
864 // see note in mantis : issue number 8585
865 if (alignment.isNucleotide()
866 || (conservation == null && quality == null)
867 || !autoCalculateConsensus)
871 if (calculator.getRegisteredWorkersOfClass(
872 jalview.workers.ConservationThread.class) == null)
874 calculator.registerWorker(
875 new jalview.workers.ConservationThread(this, ap));
880 * trigger update of consensus annotation
882 public void updateConsensus(final AlignmentViewPanel ap)
884 // see note in mantis : issue number 8585
885 if (consensus == null || !autoCalculateConsensus)
890 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
892 calculator.registerWorker(new ConsensusThread(this, ap));
896 * A separate thread to compute cDNA consensus for a protein alignment
897 * which has mapping to cDNA
899 final AlignmentI al = this.getAlignment();
900 if (!al.isNucleotide() && al.getCodonFrames() != null
901 && !al.getCodonFrames().isEmpty())
904 * fudge - check first for protein-to-nucleotide mappings
905 * (we don't want to do this for protein-to-protein)
907 boolean doConsensus = false;
908 for (AlignedCodonFrame mapping : al.getCodonFrames())
910 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
911 MapList[] mapLists = mapping.getdnaToProt();
912 // mapLists can be empty if project load has not finished resolving seqs
913 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
921 if (calculator.getRegisteredWorkersOfClass(
922 ComplementConsensusThread.class) == null)
925 .registerWorker(new ComplementConsensusThread(this, ap));
932 * trigger update of information annotation
935 public void updateInformation(final AlignmentViewPanel ap)
938 .getRegisteredWorkersOfClass(InformationThread.class) == null)
940 calculator.registerWorker(new InformationThread(this, ap));
945 // --------START Structure Conservation
946 public void updateStrucConsensus(final AlignmentViewPanel ap)
948 if (autoCalculateStrucConsensus && strucConsensus == null
949 && alignment.isNucleotide() && alignment.hasRNAStructure())
951 // secondary structure has been added - so init the consensus line
955 // see note in mantis : issue number 8585
956 if (strucConsensus == null || !autoCalculateStrucConsensus)
960 if (calculator.getRegisteredWorkersOfClass(
961 StrucConsensusThread.class) == null)
963 calculator.registerWorker(new StrucConsensusThread(this, ap));
967 public boolean isCalcInProgress()
969 return calculator.isWorking();
973 public boolean isCalculationInProgress(
974 AlignmentAnnotation alignmentAnnotation)
976 if (!alignmentAnnotation.autoCalculated)
980 if (calculator.workingInvolvedWith(alignmentAnnotation))
982 // System.err.println("grey out ("+alignmentAnnotation.label+")");
988 public void setAlignment(AlignmentI align)
990 this.alignment = align;
994 * Clean up references when this viewport is closed
997 public void dispose()
1000 * defensively null out references to large objects in case
1001 * this object is not garbage collected (as if!)
1004 complementConsensus = null;
1005 strucConsensus = null;
1006 conservation = null;
1008 groupConsensus = null;
1009 groupConservation = null;
1011 hcomplementConsensus = null;
1012 // colour scheme may hold reference to consensus
1013 residueShading = null;
1014 // TODO remove listeners from changeSupport?
1015 changeSupport = null;
1020 public boolean isClosed()
1022 // TODO: check that this isClosed is only true after panel is closed, not
1023 // before it is fully constructed.
1024 return alignment == null;
1028 public AlignCalcManagerI getCalcManager()
1034 * should conservation rows be shown for groups
1036 protected boolean showGroupConservation = false;
1039 * should consensus rows be shown for groups
1041 protected boolean showGroupConsensus = false;
1044 * should consensus profile be rendered by default
1046 protected boolean showSequenceLogo = false;
1049 * should consensus profile be rendered normalised to row height
1051 protected boolean normaliseSequenceLogo = false;
1054 * should consensus histograms be rendered by default
1056 protected boolean showConsensusHistogram = true;
1059 * should hmm profile be rendered by default
1061 protected boolean showHMMSequenceLogo = false;
1064 * should hmm profile be rendered normalised to row height
1066 protected boolean normaliseHMMSequenceLogo = false;
1069 * should information histograms be rendered by default
1071 protected boolean showInformationHistogram = true;
1074 * @return the showConsensusProfile
1077 public boolean isShowSequenceLogo()
1079 return showSequenceLogo;
1083 * @return the showInformationProfile
1086 public boolean isShowHMMSequenceLogo()
1088 return showHMMSequenceLogo;
1092 * @param showSequenceLogo
1095 public void setShowSequenceLogo(boolean showSequenceLogo)
1097 if (showSequenceLogo != this.showSequenceLogo)
1099 // TODO: decouple settings setting from calculation when refactoring
1100 // annotation update method from alignframe to viewport
1101 this.showSequenceLogo = showSequenceLogo;
1102 calculator.updateAnnotationFor(ConsensusThread.class);
1103 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1104 calculator.updateAnnotationFor(StrucConsensusThread.class);
1106 this.showSequenceLogo = showSequenceLogo;
1109 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1111 if (showHMMSequenceLogo != this.showHMMSequenceLogo)
1113 this.showHMMSequenceLogo = showHMMSequenceLogo;
1114 calculator.updateAnnotationFor(InformationThread.class);
1116 this.showHMMSequenceLogo = showHMMSequenceLogo;
1120 * @param showConsensusHistogram
1121 * the showConsensusHistogram to set
1123 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1125 this.showConsensusHistogram = showConsensusHistogram;
1129 * @param showInformationHistogram
1130 * the showInformationHistogram to set
1132 public void setShowInformationHistogram(boolean showInformationHistogram)
1134 this.showInformationHistogram = showInformationHistogram;
1138 * @return the showGroupConservation
1140 public boolean isShowGroupConservation()
1142 return showGroupConservation;
1146 * @param showGroupConservation
1147 * the showGroupConservation to set
1149 public void setShowGroupConservation(boolean showGroupConservation)
1151 this.showGroupConservation = showGroupConservation;
1155 * @return the showGroupConsensus
1157 public boolean isShowGroupConsensus()
1159 return showGroupConsensus;
1163 * @param showGroupConsensus
1164 * the showGroupConsensus to set
1166 public void setShowGroupConsensus(boolean showGroupConsensus)
1168 this.showGroupConsensus = showGroupConsensus;
1173 * @return flag to indicate if the consensus histogram should be rendered by
1177 public boolean isShowConsensusHistogram()
1179 return this.showConsensusHistogram;
1184 * @return flag to indicate if the information content histogram should be
1185 * rendered by default
1188 public boolean isShowInformationHistogram()
1190 return this.showInformationHistogram;
1194 * when set, updateAlignment will always ensure sequences are of equal length
1196 private boolean padGaps = false;
1199 * when set, alignment should be reordered according to a newly opened tree
1201 public boolean sortByTree = false;
1206 * @return null or the currently selected sequence region
1209 public SequenceGroup getSelectionGroup()
1211 return selectionGroup;
1215 * Set the selection group for this window. Also sets the current alignment as
1216 * the context for the group, if it does not already have one.
1219 * - group holding references to sequences in this alignment view
1223 public void setSelectionGroup(SequenceGroup sg)
1225 selectionGroup = sg;
1226 if (sg != null && sg.getContext() == null)
1228 sg.setContext(alignment);
1232 public void setHiddenColumns(HiddenColumns hidden)
1234 this.alignment.setHiddenColumns(hidden);
1238 public ColumnSelection getColumnSelection()
1244 public void setColumnSelection(ColumnSelection colSel)
1246 this.colSel = colSel;
1249 updateHiddenColumns();
1251 isColSelChanged(true);
1259 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1261 return hiddenRepSequences;
1265 public void setHiddenRepSequences(
1266 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1268 this.hiddenRepSequences = hiddenRepSequences;
1272 public boolean hasSelectedColumns()
1274 ColumnSelection columnSelection = getColumnSelection();
1275 return columnSelection != null && columnSelection.hasSelectedColumns();
1279 public boolean hasHiddenColumns()
1281 return colSel != null
1282 && alignment.getHiddenColumns().hasHiddenColumns();
1285 public void updateHiddenColumns()
1287 // this method doesn't really do anything now. But - it could, since a
1288 // column Selection could be in the process of modification
1289 // hasHiddenColumns = colSel.hasHiddenColumns();
1293 public boolean hasHiddenRows()
1295 return alignment.getHiddenSequences().getSize() > 0;
1298 protected SequenceGroup selectionGroup;
1300 public void setSequenceSetId(String newid)
1302 if (sequenceSetID != null)
1305 "Warning - overwriting a sequenceSetId for a viewport!");
1307 sequenceSetID = new String(newid);
1311 public String getSequenceSetId()
1313 if (sequenceSetID == null)
1315 sequenceSetID = alignment.hashCode() + "";
1318 return sequenceSetID;
1322 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1325 protected String viewId = null;
1328 public String getViewId()
1332 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1337 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1339 ignoreGapsInConsensusCalculation = b;
1342 updateConsensus(ap);
1343 if (residueShading != null)
1345 residueShading.setThreshold(residueShading.getThreshold(),
1346 ignoreGapsInConsensusCalculation);
1352 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1354 ignoreBelowBackGroundFrequencyCalculation = b;
1357 updateInformation(ap);
1362 private long sgrouphash = -1, colselhash = -1;
1365 * checks current SelectionGroup against record of last hash value, and
1369 * update the record of last hash value
1371 * @return true if SelectionGroup changed since last call (when b is true)
1373 public boolean isSelectionGroupChanged(boolean b)
1375 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1376 : selectionGroup.hashCode();
1377 if (hc != -1 && hc != sgrouphash)
1389 * checks current colsel against record of last hash value, and optionally
1393 * update the record of last hash value
1394 * @return true if colsel changed since last call (when b is true)
1396 public boolean isColSelChanged(boolean b)
1398 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1399 if (hc != -1 && hc != colselhash)
1411 public boolean isIgnoreGapsConsensus()
1413 return ignoreGapsInConsensusCalculation;
1417 public boolean isIgnoreBelowBackground()
1419 return ignoreBelowBackGroundFrequencyCalculation;
1422 // property change stuff
1423 // JBPNote Prolly only need this in the applet version.
1424 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1427 protected boolean showConservation = true;
1429 protected boolean showQuality = true;
1431 protected boolean showConsensus = true;
1433 protected boolean showOccupancy = true;
1435 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1437 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1439 protected boolean showAutocalculatedAbove;
1442 * when set, view will scroll to show the highlighted position
1444 private boolean followHighlight = true;
1447 * Property change listener for changes in alignment
1452 public void addPropertyChangeListener(
1453 java.beans.PropertyChangeListener listener)
1455 changeSupport.addPropertyChangeListener(listener);
1464 public void removePropertyChangeListener(
1465 java.beans.PropertyChangeListener listener)
1467 changeSupport.removePropertyChangeListener(listener);
1471 * Property change listener for changes in alignment
1480 public void firePropertyChange(String prop, Object oldvalue,
1483 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1486 // common hide/show column stuff
1488 public void hideSelectedColumns()
1490 if (colSel.isEmpty())
1495 colSel.hideSelectedColumns(alignment);
1496 setSelectionGroup(null);
1497 isColSelChanged(true);
1500 public void hideColumns(int start, int end)
1504 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1508 alignment.getHiddenColumns().hideColumns(start, end);
1510 isColSelChanged(true);
1513 public void showColumn(int col)
1515 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1516 isColSelChanged(true);
1519 public void showAllHiddenColumns()
1521 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1522 isColSelChanged(true);
1525 // common hide/show seq stuff
1526 public void showAllHiddenSeqs()
1528 if (alignment.getHiddenSequences().getSize() > 0)
1530 if (selectionGroup == null)
1532 selectionGroup = new SequenceGroup();
1533 selectionGroup.setEndRes(alignment.getWidth() - 1);
1535 List<SequenceI> tmp = alignment.getHiddenSequences()
1536 .showAll(hiddenRepSequences);
1537 for (SequenceI seq : tmp)
1539 selectionGroup.addSequence(seq, false);
1540 setSequenceAnnotationsVisible(seq, true);
1543 hiddenRepSequences = null;
1545 firePropertyChange("alignment", null, alignment.getSequences());
1546 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1552 public void showSequence(int index)
1554 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1555 hiddenRepSequences);
1558 if (selectionGroup == null)
1560 selectionGroup = new SequenceGroup();
1561 selectionGroup.setEndRes(alignment.getWidth() - 1);
1564 for (SequenceI seq : tmp)
1566 selectionGroup.addSequence(seq, false);
1567 setSequenceAnnotationsVisible(seq, true);
1569 firePropertyChange("alignment", null, alignment.getSequences());
1574 public void hideAllSelectedSeqs()
1576 if (selectionGroup == null || selectionGroup.getSize() < 1)
1581 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1585 setSelectionGroup(null);
1588 public void hideSequence(SequenceI[] seq)
1592 for (int i = 0; i < seq.length; i++)
1594 alignment.getHiddenSequences().hideSequence(seq[i]);
1595 setSequenceAnnotationsVisible(seq[i], false);
1597 firePropertyChange("alignment", null, alignment.getSequences());
1602 * Hides the specified sequence, or the sequences it represents
1605 * the sequence to hide, or keep as representative
1606 * @param representGroup
1607 * if true, hide the current selection group except for the
1608 * representative sequence
1610 public void hideSequences(SequenceI sequence, boolean representGroup)
1612 if (selectionGroup == null || selectionGroup.getSize() < 1)
1614 hideSequence(new SequenceI[] { sequence });
1620 hideRepSequences(sequence, selectionGroup);
1621 setSelectionGroup(null);
1625 int gsize = selectionGroup.getSize();
1626 SequenceI[] hseqs = selectionGroup.getSequences()
1627 .toArray(new SequenceI[gsize]);
1629 hideSequence(hseqs);
1630 setSelectionGroup(null);
1635 * Set visibility for any annotations for the given sequence.
1639 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1642 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1645 for (AlignmentAnnotation ann : anns)
1647 if (ann.sequenceRef == sequenceI)
1649 ann.visible = visible;
1655 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1657 int sSize = sg.getSize();
1663 if (hiddenRepSequences == null)
1665 hiddenRepSequences = new Hashtable<>();
1668 hiddenRepSequences.put(repSequence, sg);
1670 // Hide all sequences except the repSequence
1671 SequenceI[] seqs = new SequenceI[sSize - 1];
1673 for (int i = 0; i < sSize; i++)
1675 if (sg.getSequenceAt(i) != repSequence)
1677 if (index == sSize - 1)
1682 seqs[index++] = sg.getSequenceAt(i);
1685 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1686 sg.setHidereps(true); // note: not done in 2.7applet
1693 * @return null or the current reference sequence
1695 public SequenceI getReferenceSeq()
1697 return alignment.getSeqrep();
1702 * @return true iff seq is the reference for the alignment
1704 public boolean isReferenceSeq(SequenceI seq)
1706 return alignment.getSeqrep() == seq;
1712 * @return true if there are sequences represented by this sequence that are
1715 public boolean isHiddenRepSequence(SequenceI seq)
1717 return (hiddenRepSequences != null
1718 && hiddenRepSequences.containsKey(seq));
1724 * @return null or a sequence group containing the sequences that seq
1727 public SequenceGroup getRepresentedSequences(SequenceI seq)
1729 return (SequenceGroup) (hiddenRepSequences == null ? null
1730 : hiddenRepSequences.get(seq));
1734 public int adjustForHiddenSeqs(int alignmentIndex)
1736 return alignment.getHiddenSequences()
1737 .adjustForHiddenSeqs(alignmentIndex);
1741 public void invertColumnSelection()
1743 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1747 public SequenceI[] getSelectionAsNewSequence()
1749 SequenceI[] sequences;
1750 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1751 // this was the only caller in the applet for this method
1752 // JBPNote: in applet, this method returned references to the alignment
1753 // sequences, and it did not honour the presence/absence of annotation
1754 // attached to the alignment (probably!)
1755 if (selectionGroup == null || selectionGroup.getSize() == 0)
1757 sequences = alignment.getSequencesArray();
1758 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1759 for (int i = 0; i < sequences.length; i++)
1761 // construct new sequence with subset of visible annotation
1762 sequences[i] = new Sequence(sequences[i], annots);
1767 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1774 public SequenceI[] getSequenceSelection()
1776 SequenceI[] sequences = null;
1777 if (selectionGroup != null)
1779 sequences = selectionGroup.getSequencesInOrder(alignment);
1781 if (sequences == null)
1783 sequences = alignment.getSequencesArray();
1789 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1791 return new CigarArray(alignment, alignment.getHiddenColumns(),
1792 (selectedRegionOnly ? selectionGroup : null));
1796 public jalview.datamodel.AlignmentView getAlignmentView(
1797 boolean selectedOnly)
1799 return getAlignmentView(selectedOnly, false);
1803 public jalview.datamodel.AlignmentView getAlignmentView(
1804 boolean selectedOnly, boolean markGroups)
1806 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1807 selectionGroup, alignment.getHiddenColumns() != null
1808 && alignment.getHiddenColumns().hasHiddenColumns(),
1809 selectedOnly, markGroups);
1813 public String[] getViewAsString(boolean selectedRegionOnly)
1815 return getViewAsString(selectedRegionOnly, true);
1819 public String[] getViewAsString(boolean selectedRegionOnly,
1820 boolean exportHiddenSeqs)
1822 String[] selection = null;
1823 SequenceI[] seqs = null;
1825 int start = 0, end = 0;
1826 if (selectedRegionOnly && selectionGroup != null)
1828 iSize = selectionGroup.getSize();
1829 seqs = selectionGroup.getSequencesInOrder(alignment);
1830 start = selectionGroup.getStartRes();
1831 end = selectionGroup.getEndRes() + 1;
1835 if (hasHiddenRows() && exportHiddenSeqs)
1837 AlignmentI fullAlignment = alignment.getHiddenSequences()
1838 .getFullAlignment();
1839 iSize = fullAlignment.getHeight();
1840 seqs = fullAlignment.getSequencesArray();
1841 end = fullAlignment.getWidth();
1845 iSize = alignment.getHeight();
1846 seqs = alignment.getSequencesArray();
1847 end = alignment.getWidth();
1851 selection = new String[iSize];
1852 if (alignment.getHiddenColumns() != null
1853 && alignment.getHiddenColumns().hasHiddenColumns())
1855 selection = alignment.getHiddenColumns()
1856 .getVisibleSequenceStrings(start, end, seqs);
1860 for (i = 0; i < iSize; i++)
1862 selection[i] = seqs[i].getSequenceAsString(start, end);
1870 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1872 ArrayList<int[]> regions = new ArrayList<>();
1878 HiddenColumns hidden = alignment.getHiddenColumns();
1879 if (hidden != null && hidden.hasHiddenColumns())
1883 start = hidden.adjustForHiddenColumns(start);
1886 end = hidden.getHiddenBoundaryRight(start);
1897 regions.add(new int[] { start, end });
1899 if (hidden != null && hidden.hasHiddenColumns())
1901 start = hidden.adjustForHiddenColumns(end);
1902 start = hidden.getHiddenBoundaryLeft(start) + 1;
1904 } while (end < max);
1906 int[][] startEnd = new int[regions.size()][2];
1912 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1913 boolean selectedOnly)
1915 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1916 AlignmentAnnotation[] aa;
1917 if ((aa = alignment.getAlignmentAnnotation()) != null)
1919 for (AlignmentAnnotation annot : aa)
1921 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1922 if (selectedOnly && selectionGroup != null)
1924 alignment.getHiddenColumns().makeVisibleAnnotation(
1925 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1930 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1939 public boolean isPadGaps()
1945 public void setPadGaps(boolean padGaps)
1947 this.padGaps = padGaps;
1951 * apply any post-edit constraints and trigger any calculations needed after
1952 * an edit has been performed on the alignment
1957 public void alignmentChanged(AlignmentViewPanel ap)
1961 alignment.padGaps();
1963 if (autoCalculateConsensus)
1965 updateConsensus(ap);
1967 if (hconsensus != null && autoCalculateConsensus)
1969 updateConservation(ap);
1971 if (autoCalculateStrucConsensus)
1973 updateStrucConsensus(ap);
1975 updateInformation(ap);
1977 List<SequenceI> hmmSequences;
1978 hmmSequences = alignment.getHMMConsensusSequences(false);
1980 for (SequenceI seq : hmmSequences)
1982 seq.updateHMMMapping();
1985 // Reset endRes of groups if beyond alignment width
1986 int alWidth = alignment.getWidth();
1987 List<SequenceGroup> groups = alignment.getGroups();
1990 for (SequenceGroup sg : groups)
1992 if (sg.getEndRes() > alWidth)
1994 sg.setEndRes(alWidth - 1);
1999 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2001 selectionGroup.setEndRes(alWidth - 1);
2004 updateAllColourSchemes();
2005 calculator.restartWorkers();
2006 // alignment.adjustSequenceAnnotations();
2010 * reset scope and do calculations for all applied colourschemes on alignment
2012 void updateAllColourSchemes()
2014 ResidueShaderI rs = residueShading;
2017 rs.alignmentChanged(alignment, hiddenRepSequences);
2019 rs.setConsensus(hconsensus);
2020 if (rs.conservationApplied())
2022 rs.setConservation(Conservation.calculateConservation("All",
2023 alignment.getSequences(), 0, alignment.getWidth(), false,
2024 getConsPercGaps(), false));
2028 for (SequenceGroup sg : alignment.getGroups())
2032 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2034 sg.recalcConservation();
2038 protected void initAutoAnnotation()
2040 // TODO: add menu option action that nulls or creates consensus object
2041 // depending on if the user wants to see the annotation or not in a
2042 // specific alignment
2044 if (hconsensus == null && !isDataset)
2046 if (!alignment.isNucleotide())
2055 consensus = new AlignmentAnnotation("Consensus",
2056 MessageManager.getString("label.consensus_descr"),
2057 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2058 initConsensus(consensus);
2062 initComplementConsensus();
2067 * If this is a protein alignment and there are mappings to cDNA, adds the
2068 * cDNA consensus annotation and returns true, else returns false.
2070 public boolean initComplementConsensus()
2072 if (!alignment.isNucleotide())
2074 final List<AlignedCodonFrame> codonMappings = alignment
2076 if (codonMappings != null && !codonMappings.isEmpty())
2078 boolean doConsensus = false;
2079 for (AlignedCodonFrame mapping : codonMappings)
2081 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2082 MapList[] mapLists = mapping.getdnaToProt();
2083 // mapLists can be empty if project load has not finished resolving
2085 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2093 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2095 .getString("label.complement_consensus_descr"),
2096 new Annotation[1], 0f, 100f,
2097 AlignmentAnnotation.BAR_GRAPH);
2098 initConsensus(complementConsensus);
2106 private void initConsensus(AlignmentAnnotation aa)
2109 aa.autoCalculated = true;
2113 alignment.addAnnotation(aa);
2118 public void initInformation()
2120 for (SequenceI seq : alignment.getHMMConsensusSequences(false))
2122 if (!seq.hasHMMAnnotation())
2124 AlignmentAnnotation information;
2125 information = new AlignmentAnnotation(seq.getName(),
2126 MessageManager.getString("label.information_description"),
2127 new Annotation[1], 0f, 6.52f,
2128 AlignmentAnnotation.BAR_GRAPH);
2129 information.hasText = true;
2130 information.autoCalculated = true;
2131 information.hasText = true;
2132 information.autoCalculated = false;
2133 information.sequenceRef = seq;
2134 information.setCalcId("HMM annotation");
2135 this.information.add(information);
2136 hinformation.add(new Profiles(new ProfileI[1]));
2137 alignment.addAnnotation(information);
2138 seq.updateHMMMapping();
2139 seq.setHasInfo(true);
2140 seq.addAlignmentAnnotation(information);
2146 // these should be extracted from the view model - style and settings for
2147 // derived annotation
2148 private void initGapCounts()
2152 gapcounts = new AlignmentAnnotation("Occupancy",
2153 MessageManager.getString("label.occupancy_descr"),
2154 new Annotation[1], 0f, alignment.getHeight(),
2155 AlignmentAnnotation.BAR_GRAPH);
2156 gapcounts.hasText = true;
2157 gapcounts.autoCalculated = true;
2158 gapcounts.scaleColLabel = true;
2159 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2161 alignment.addAnnotation(gapcounts);
2165 private void initConservation()
2167 if (showConservation)
2169 if (conservation == null)
2171 conservation = new AlignmentAnnotation("Conservation",
2172 MessageManager.formatMessage("label.conservation_descr",
2174 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2175 conservation.hasText = true;
2176 conservation.autoCalculated = true;
2177 alignment.addAnnotation(conservation);
2182 private void initQuality()
2186 if (quality == null)
2188 quality = new AlignmentAnnotation("Quality",
2189 MessageManager.getString("label.quality_descr"),
2190 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2191 quality.hasText = true;
2192 quality.autoCalculated = true;
2193 alignment.addAnnotation(quality);
2198 private void initRNAStructure()
2200 if (alignment.hasRNAStructure() && strucConsensus == null)
2202 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2203 MessageManager.getString("label.strucconsensus_descr"),
2204 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2205 strucConsensus.hasText = true;
2206 strucConsensus.autoCalculated = true;
2210 alignment.addAnnotation(strucConsensus);
2218 * @see jalview.api.AlignViewportI#calcPanelHeight()
2221 public int calcPanelHeight()
2223 // setHeight of panels
2224 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2226 int charHeight = getCharHeight();
2229 BitSet graphgrp = new BitSet();
2230 for (AlignmentAnnotation aa : anns)
2234 System.err.println("Null annotation row: ignoring.");
2241 if (aa.graphGroup > -1)
2243 if (graphgrp.get(aa.graphGroup))
2249 graphgrp.set(aa.graphGroup);
2256 aa.height += charHeight;
2266 aa.height += aa.graphHeight;
2274 height += aa.height;
2286 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2287 boolean preserveNewGroupSettings)
2289 boolean updateCalcs = false;
2290 boolean conv = isShowGroupConservation();
2291 boolean cons = isShowGroupConsensus();
2292 boolean showprf = isShowSequenceLogo();
2293 boolean showConsHist = isShowConsensusHistogram();
2294 boolean normLogo = isNormaliseSequenceLogo();
2295 boolean showHMMPrf = isShowHMMSequenceLogo();
2296 boolean showInfoHist = isShowInformationHistogram();
2297 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2300 * TODO reorder the annotation rows according to group/sequence ordering on
2303 boolean sortg = true;
2305 // remove old automatic annotation
2306 // add any new annotation
2308 // intersect alignment annotation with alignment groups
2310 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2311 List<SequenceGroup> oldrfs = new ArrayList<>();
2314 for (int an = 0; an < aan.length; an++)
2316 if (aan[an].autoCalculated && aan[an].groupRef != null)
2318 oldrfs.add(aan[an].groupRef);
2319 alignment.deleteAnnotation(aan[an], false);
2323 if (alignment.getGroups() != null)
2325 for (SequenceGroup sg : alignment.getGroups())
2327 updateCalcs = false;
2328 if (applyGlobalSettings
2329 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2331 // set defaults for this group's conservation/consensus
2332 sg.setshowSequenceLogo(showprf);
2333 sg.setShowConsensusHistogram(showConsHist);
2334 sg.setNormaliseSequenceLogo(normLogo);
2335 sg.setshowHMMSequenceLogo(showHMMPrf);
2336 sg.setShowInformationHistogram(showInfoHist);
2337 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2342 alignment.addAnnotation(sg.getConservationRow(), 0);
2347 alignment.addAnnotation(sg.getConsensus(), 0);
2349 // refresh the annotation rows
2352 sg.recalcConservation();
2360 public boolean isDisplayReferenceSeq()
2362 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2366 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2368 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2372 public boolean isColourByReferenceSeq()
2374 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2378 public Color getSequenceColour(SequenceI seq)
2380 Color sqc = sequenceColours.get(seq);
2381 return (sqc == null ? Color.white : sqc);
2385 public void setSequenceColour(SequenceI seq, Color col)
2389 sequenceColours.remove(seq);
2393 sequenceColours.put(seq, col);
2398 public void updateSequenceIdColours()
2400 for (SequenceGroup sg : alignment.getGroups())
2402 if (sg.idColour != null)
2404 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2406 sequenceColours.put(s, sg.idColour);
2413 public void clearSequenceColours()
2415 sequenceColours.clear();
2419 public AlignViewportI getCodingComplement()
2421 return this.codingComplement;
2425 * Set this as the (cDna/protein) complement of the given viewport. Also
2426 * ensures the reverse relationship is set on the given viewport.
2429 public void setCodingComplement(AlignViewportI av)
2433 System.err.println("Ignoring recursive setCodingComplement request");
2437 this.codingComplement = av;
2438 // avoid infinite recursion!
2439 if (av.getCodingComplement() != this)
2441 av.setCodingComplement(this);
2447 public boolean isNucleotide()
2449 return getAlignment() == null ? false : getAlignment().isNucleotide();
2453 public FeaturesDisplayedI getFeaturesDisplayed()
2455 return featuresDisplayed;
2459 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2461 featuresDisplayed = featuresDisplayedI;
2465 public boolean areFeaturesDisplayed()
2467 return featuresDisplayed != null
2468 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2475 * features are displayed if true
2478 public void setShowSequenceFeatures(boolean b)
2480 viewStyle.setShowSequenceFeatures(b);
2484 public boolean isShowSequenceFeatures()
2486 return viewStyle.isShowSequenceFeatures();
2490 public void setShowSequenceFeaturesHeight(boolean selected)
2492 viewStyle.setShowSequenceFeaturesHeight(selected);
2496 public boolean isShowSequenceFeaturesHeight()
2498 return viewStyle.isShowSequenceFeaturesHeight();
2502 public void setShowAnnotation(boolean b)
2504 viewStyle.setShowAnnotation(b);
2508 public boolean isShowAnnotation()
2510 return viewStyle.isShowAnnotation();
2514 public boolean isRightAlignIds()
2516 return viewStyle.isRightAlignIds();
2520 public void setRightAlignIds(boolean rightAlignIds)
2522 viewStyle.setRightAlignIds(rightAlignIds);
2526 public boolean getConservationSelected()
2528 return viewStyle.getConservationSelected();
2532 public void setShowBoxes(boolean state)
2534 viewStyle.setShowBoxes(state);
2539 * @see jalview.api.ViewStyleI#getTextColour()
2542 public Color getTextColour()
2544 return viewStyle.getTextColour();
2549 * @see jalview.api.ViewStyleI#getTextColour2()
2552 public Color getTextColour2()
2554 return viewStyle.getTextColour2();
2559 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2562 public int getThresholdTextColour()
2564 return viewStyle.getThresholdTextColour();
2569 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2572 public boolean isConservationColourSelected()
2574 return viewStyle.isConservationColourSelected();
2579 * @see jalview.api.ViewStyleI#isRenderGaps()
2582 public boolean isRenderGaps()
2584 return viewStyle.isRenderGaps();
2589 * @see jalview.api.ViewStyleI#isShowColourText()
2592 public boolean isShowColourText()
2594 return viewStyle.isShowColourText();
2598 * @param conservationColourSelected
2599 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2602 public void setConservationColourSelected(
2603 boolean conservationColourSelected)
2605 viewStyle.setConservationColourSelected(conservationColourSelected);
2609 * @param showColourText
2610 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2613 public void setShowColourText(boolean showColourText)
2615 viewStyle.setShowColourText(showColourText);
2620 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2623 public void setTextColour(Color textColour)
2625 viewStyle.setTextColour(textColour);
2629 * @param thresholdTextColour
2630 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2633 public void setThresholdTextColour(int thresholdTextColour)
2635 viewStyle.setThresholdTextColour(thresholdTextColour);
2639 * @param textColour2
2640 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2643 public void setTextColour2(Color textColour2)
2645 viewStyle.setTextColour2(textColour2);
2649 public ViewStyleI getViewStyle()
2651 return new ViewStyle(viewStyle);
2655 public void setViewStyle(ViewStyleI settingsForView)
2657 viewStyle = new ViewStyle(settingsForView);
2658 if (residueShading != null)
2660 residueShading.setConservationApplied(
2661 settingsForView.isConservationColourSelected());
2666 public boolean sameStyle(ViewStyleI them)
2668 return viewStyle.sameStyle(them);
2673 * @see jalview.api.ViewStyleI#getIdWidth()
2676 public int getIdWidth()
2678 return viewStyle.getIdWidth();
2683 * @see jalview.api.ViewStyleI#setIdWidth(int)
2686 public void setIdWidth(int i)
2688 viewStyle.setIdWidth(i);
2693 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2696 public boolean isCentreColumnLabels()
2698 return viewStyle.isCentreColumnLabels();
2702 * @param centreColumnLabels
2703 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2706 public void setCentreColumnLabels(boolean centreColumnLabels)
2708 viewStyle.setCentreColumnLabels(centreColumnLabels);
2713 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2716 public void setShowDBRefs(boolean showdbrefs)
2718 viewStyle.setShowDBRefs(showdbrefs);
2723 * @see jalview.api.ViewStyleI#isShowDBRefs()
2726 public boolean isShowDBRefs()
2728 return viewStyle.isShowDBRefs();
2733 * @see jalview.api.ViewStyleI#isShowNPFeats()
2736 public boolean isShowNPFeats()
2738 return viewStyle.isShowNPFeats();
2742 * @param shownpfeats
2743 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2746 public void setShowNPFeats(boolean shownpfeats)
2748 viewStyle.setShowNPFeats(shownpfeats);
2751 public abstract StructureSelectionManager getStructureSelectionManager();
2754 * Add one command to the command history list.
2758 public void addToHistoryList(CommandI command)
2760 if (this.historyList != null)
2762 this.historyList.push(command);
2763 broadcastCommand(command, false);
2767 protected void broadcastCommand(CommandI command, boolean undo)
2769 getStructureSelectionManager().commandPerformed(command, undo,
2774 * Add one command to the command redo list.
2778 public void addToRedoList(CommandI command)
2780 if (this.redoList != null)
2782 this.redoList.push(command);
2784 broadcastCommand(command, true);
2788 * Clear the command redo list.
2790 public void clearRedoList()
2792 if (this.redoList != null)
2794 this.redoList.clear();
2798 public void setHistoryList(Deque<CommandI> list)
2800 this.historyList = list;
2803 public Deque<CommandI> getHistoryList()
2805 return this.historyList;
2808 public void setRedoList(Deque<CommandI> list)
2810 this.redoList = list;
2813 public Deque<CommandI> getRedoList()
2815 return this.redoList;
2819 public VamsasSource getVamsasSource()
2824 public SequenceAnnotationOrder getSortAnnotationsBy()
2826 return sortAnnotationsBy;
2829 public void setSortAnnotationsBy(
2830 SequenceAnnotationOrder sortAnnotationsBy)
2832 this.sortAnnotationsBy = sortAnnotationsBy;
2835 public boolean isShowAutocalculatedAbove()
2837 return showAutocalculatedAbove;
2840 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2842 this.showAutocalculatedAbove = showAutocalculatedAbove;
2846 public boolean isScaleProteinAsCdna()
2848 return viewStyle.isScaleProteinAsCdna();
2852 public void setScaleProteinAsCdna(boolean b)
2854 viewStyle.setScaleProteinAsCdna(b);
2858 public boolean isProteinFontAsCdna()
2860 return viewStyle.isProteinFontAsCdna();
2864 public void setProteinFontAsCdna(boolean b)
2866 viewStyle.setProteinFontAsCdna(b);
2870 * @return true if view should scroll to show the highlighted region of a
2875 public final boolean isFollowHighlight()
2877 return followHighlight;
2881 public final void setFollowHighlight(boolean b)
2883 this.followHighlight = b;
2887 public ViewportRanges getRanges()
2893 * Helper method to populate the SearchResults with the location in the
2894 * complementary alignment to scroll to, in order to match this one.
2897 * the SearchResults to add to
2898 * @return the offset (below top of visible region) of the matched sequence
2900 protected int findComplementScrollTarget(SearchResultsI sr)
2902 final AlignViewportI complement = getCodingComplement();
2903 if (complement == null || !complement.isFollowHighlight())
2907 boolean iAmProtein = !getAlignment().isNucleotide();
2908 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2909 : complement.getAlignment();
2910 if (proteinAlignment == null)
2914 final List<AlignedCodonFrame> mappings = proteinAlignment
2918 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2919 * residue in the middle column of the visible region. Scroll the
2920 * complementary alignment to line up the corresponding residue.
2923 SequenceI sequence = null;
2926 * locate 'middle' column (true middle if an odd number visible, left of
2927 * middle if an even number visible)
2929 int middleColumn = ranges.getStartRes()
2930 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2931 final HiddenSequences hiddenSequences = getAlignment()
2932 .getHiddenSequences();
2935 * searching to the bottom of the alignment gives smoother scrolling across
2936 * all gapped visible regions
2938 int lastSeq = alignment.getHeight() - 1;
2939 List<AlignedCodonFrame> seqMappings = null;
2940 for (int seqNo = ranges
2941 .getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2943 sequence = getAlignment().getSequenceAt(seqNo);
2944 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2948 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2952 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2954 getCodingComplement().getAlignment().getSequences());
2955 if (!seqMappings.isEmpty())
2961 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2964 * No ungapped mapped sequence in middle column - do nothing
2968 MappingUtils.addSearchResults(sr, sequence,
2969 sequence.findPosition(middleColumn), seqMappings);
2974 * synthesize a column selection if none exists so it covers the given
2975 * selection group. if wholewidth is false, no column selection is made if the
2976 * selection group covers the whole alignment width.
2981 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2984 if (sg != null && (sgs = sg.getStartRes()) >= 0
2985 && sg.getStartRes() <= (sge = sg.getEndRes())
2986 && !this.hasSelectedColumns())
2988 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2995 colSel = new ColumnSelection();
2997 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2999 colSel.addElement(cspos);
3005 * hold status of current selection group - defined on alignment or not.
3007 private boolean selectionIsDefinedGroup = false;
3010 public boolean isSelectionDefinedGroup()
3012 if (selectionGroup == null)
3016 if (isSelectionGroupChanged(true))
3018 selectionIsDefinedGroup = false;
3019 List<SequenceGroup> gps = alignment.getGroups();
3020 if (gps == null || gps.size() == 0)
3022 selectionIsDefinedGroup = false;
3026 selectionIsDefinedGroup = gps.contains(selectionGroup);
3029 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3033 * null, or currently highlighted results on this view
3035 private SearchResultsI searchResults = null;
3038 public boolean hasSearchResults()
3040 return searchResults != null;
3044 public void setSearchResults(SearchResultsI results)
3046 searchResults = results;
3050 public SearchResultsI getSearchResults()
3052 return searchResults;
3056 * Gets the selected hidden Markov model
3060 public HiddenMarkovModel getSelectedHMM()
3066 * Sets the selected hidden Markov model
3068 * @param selectedHMM
3070 public void setSelectedHMM(HiddenMarkovModel selectedHMM)
3072 this.selectedHMM = selectedHMM;