2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignCalcManagerI2;
28 import jalview.api.AlignCalcWorkerI;
29 import jalview.api.AlignExportSettingsI;
30 import jalview.api.AlignViewportI;
31 import jalview.api.AlignmentViewPanel;
32 import jalview.api.FeaturesDisplayedI;
33 import jalview.api.ViewStyleI;
34 import jalview.commands.CommandI;
35 import jalview.datamodel.AlignedCodonFrame;
36 import jalview.datamodel.AlignmentAnnotation;
37 import jalview.datamodel.AlignmentExportData;
38 import jalview.datamodel.AlignmentI;
39 import jalview.datamodel.AlignmentView;
40 import jalview.datamodel.Annotation;
41 import jalview.datamodel.ColumnSelection;
42 import jalview.datamodel.HiddenColumns;
43 import jalview.datamodel.HiddenSequences;
44 import jalview.datamodel.ProfilesI;
45 import jalview.datamodel.SearchResultsI;
46 import jalview.datamodel.Sequence;
47 import jalview.datamodel.SequenceCollectionI;
48 import jalview.datamodel.SequenceGroup;
49 import jalview.datamodel.SequenceI;
50 import jalview.renderer.ResidueShader;
51 import jalview.renderer.ResidueShaderI;
52 import jalview.schemes.ColourSchemeI;
53 import jalview.structure.CommandListener;
54 import jalview.structure.StructureSelectionManager;
55 import jalview.structure.VamsasSource;
56 import jalview.util.Comparison;
57 import jalview.util.MapList;
58 import jalview.util.MappingUtils;
59 import jalview.util.MessageManager;
60 import jalview.viewmodel.styles.ViewStyle;
61 import jalview.workers.AlignCalcManager;
62 import jalview.workers.AlignCalcManager2;
63 import jalview.workers.ComplementConsensusThread;
64 import jalview.workers.ConsensusThread;
65 import jalview.workers.InformationThread;
66 import jalview.workers.StrucConsensusThread;
68 import java.awt.Color;
69 import java.beans.PropertyChangeSupport;
70 import java.util.ArrayDeque;
71 import java.util.ArrayList;
72 import java.util.BitSet;
73 import java.util.Deque;
74 import java.util.HashMap;
75 import java.util.Hashtable;
76 import java.util.Iterator;
77 import java.util.List;
81 * base class holding visualization and analysis attributes and common logic for
82 * an active alignment view displayed in the GUI
87 public abstract class AlignmentViewport
88 implements AlignViewportI, CommandListener, VamsasSource
90 public static final String PROPERTY_ALIGNMENT = "alignment";
91 public static final String PROPERTY_SEQUENCE = "sequence";
93 protected ViewportRanges ranges;
95 protected ViewStyleI viewStyle = new ViewStyle();
98 * A viewport that hosts the cDna view of this (protein), or vice versa (if
101 AlignViewportI codingComplement = null;
103 FeaturesDisplayedI featuresDisplayed = null;
105 protected Deque<CommandI> historyList = new ArrayDeque<>();
107 protected Deque<CommandI> redoList = new ArrayDeque<>();
110 * alignment displayed in the viewport. Please use get/setter
112 protected AlignmentI alignment;
115 * probably unused indicator that view is of a dataset rather than an
119 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
121 protected boolean infoLetterHeight = false;
123 protected AlignmentAnnotation occupancy;
126 * results of alignment consensus analysis for visible portion of view
128 protected ProfilesI consensusProfiles;
131 * HMM profile for the alignment
133 protected ProfilesI hmmProfiles;
135 public AlignmentViewport(AlignmentI al)
138 ranges = new ViewportRanges(al);
143 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
146 public void setFontName(String name)
148 viewStyle.setFontName(name);
153 * @see jalview.api.ViewStyleI#setFontStyle(int)
156 public void setFontStyle(int style)
158 viewStyle.setFontStyle(style);
163 * @see jalview.api.ViewStyleI#setFontSize(int)
166 public void setFontSize(int size)
168 viewStyle.setFontSize(size);
173 * @see jalview.api.ViewStyleI#getFontStyle()
176 public int getFontStyle()
178 return viewStyle.getFontStyle();
183 * @see jalview.api.ViewStyleI#getFontName()
186 public String getFontName()
188 return viewStyle.getFontName();
193 * @see jalview.api.ViewStyleI#getFontSize()
196 public int getFontSize()
198 return viewStyle.getFontSize();
202 * @param upperCasebold
203 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
206 public void setUpperCasebold(boolean upperCasebold)
208 viewStyle.setUpperCasebold(upperCasebold);
213 * @see jalview.api.ViewStyleI#isUpperCasebold()
216 public boolean isUpperCasebold()
218 return viewStyle.isUpperCasebold();
223 * @see jalview.api.ViewStyleI#isSeqNameItalics()
226 public boolean isSeqNameItalics()
228 return viewStyle.isSeqNameItalics();
232 * @param colourByReferenceSeq
233 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
236 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
238 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
243 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
246 public void setColourAppliesToAllGroups(boolean b)
248 viewStyle.setColourAppliesToAllGroups(b);
253 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
256 public boolean getColourAppliesToAllGroups()
258 return viewStyle.getColourAppliesToAllGroups();
263 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
266 public boolean getAbovePIDThreshold()
268 return viewStyle.getAbovePIDThreshold();
273 * @see jalview.api.ViewStyleI#setIncrement(int)
276 public void setIncrement(int inc)
278 viewStyle.setIncrement(inc);
283 * @see jalview.api.ViewStyleI#getIncrement()
286 public int getIncrement()
288 return viewStyle.getIncrement();
293 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
296 public void setConservationSelected(boolean b)
298 viewStyle.setConservationSelected(b);
303 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
306 public void setShowHiddenMarkers(boolean show)
308 viewStyle.setShowHiddenMarkers(show);
313 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
316 public boolean getShowHiddenMarkers()
318 return viewStyle.getShowHiddenMarkers();
323 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
326 public void setScaleRightWrapped(boolean b)
328 viewStyle.setScaleRightWrapped(b);
333 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
336 public void setScaleLeftWrapped(boolean b)
338 viewStyle.setScaleLeftWrapped(b);
343 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
346 public void setScaleAboveWrapped(boolean b)
348 viewStyle.setScaleAboveWrapped(b);
353 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
356 public boolean getScaleLeftWrapped()
358 return viewStyle.getScaleLeftWrapped();
363 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
366 public boolean getScaleAboveWrapped()
368 return viewStyle.getScaleAboveWrapped();
373 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
376 public boolean getScaleRightWrapped()
378 return viewStyle.getScaleRightWrapped();
383 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
386 public void setAbovePIDThreshold(boolean b)
388 viewStyle.setAbovePIDThreshold(b);
393 * @see jalview.api.ViewStyleI#setThreshold(int)
396 public void setThreshold(int thresh)
398 viewStyle.setThreshold(thresh);
403 * @see jalview.api.ViewStyleI#getThreshold()
406 public int getThreshold()
408 return viewStyle.getThreshold();
413 * @see jalview.api.ViewStyleI#getShowJVSuffix()
416 public boolean getShowJVSuffix()
418 return viewStyle.getShowJVSuffix();
423 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
426 public void setShowJVSuffix(boolean b)
428 viewStyle.setShowJVSuffix(b);
433 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
436 public void setWrapAlignment(boolean state)
438 viewStyle.setWrapAlignment(state);
439 ranges.setWrappedMode(state);
444 * @see jalview.api.ViewStyleI#setShowText(boolean)
447 public void setShowText(boolean state)
449 viewStyle.setShowText(state);
454 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
457 public void setRenderGaps(boolean state)
459 viewStyle.setRenderGaps(state);
464 * @see jalview.api.ViewStyleI#getColourText()
467 public boolean getColourText()
469 return viewStyle.getColourText();
474 * @see jalview.api.ViewStyleI#setColourText(boolean)
477 public void setColourText(boolean state)
479 viewStyle.setColourText(state);
484 * @see jalview.api.ViewStyleI#getWrapAlignment()
487 public boolean getWrapAlignment()
489 return viewStyle.getWrapAlignment();
494 * @see jalview.api.ViewStyleI#getShowText()
497 public boolean getShowText()
499 return viewStyle.getShowText();
504 * @see jalview.api.ViewStyleI#getWrappedWidth()
507 public int getWrappedWidth()
509 return viewStyle.getWrappedWidth();
514 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
517 public void setWrappedWidth(int w)
519 viewStyle.setWrappedWidth(w);
524 * @see jalview.api.ViewStyleI#getCharHeight()
527 public int getCharHeight()
529 return viewStyle.getCharHeight();
534 * @see jalview.api.ViewStyleI#setCharHeight(int)
537 public void setCharHeight(int h)
539 viewStyle.setCharHeight(h);
544 * @see jalview.api.ViewStyleI#getCharWidth()
547 public int getCharWidth()
549 return viewStyle.getCharWidth();
554 * @see jalview.api.ViewStyleI#setCharWidth(int)
557 public void setCharWidth(int w)
559 viewStyle.setCharWidth(w);
564 * @see jalview.api.ViewStyleI#getShowBoxes()
567 public boolean getShowBoxes()
569 return viewStyle.getShowBoxes();
574 * @see jalview.api.ViewStyleI#getShowUnconserved()
577 public boolean getShowUnconserved()
579 return viewStyle.getShowUnconserved();
583 * @param showunconserved
584 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
587 public void setShowUnconserved(boolean showunconserved)
589 viewStyle.setShowUnconserved(showunconserved);
594 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
597 public void setSeqNameItalics(boolean default1)
599 viewStyle.setSeqNameItalics(default1);
603 public AlignmentI getAlignment()
609 public char getGapCharacter()
611 return alignment.getGapCharacter();
614 protected String sequenceSetID;
617 * probably unused indicator that view is of a dataset rather than an
620 protected boolean isDataset = false;
622 public void setDataset(boolean b)
627 public boolean isDataset()
632 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
634 protected ColumnSelection colSel = new ColumnSelection();
636 protected boolean autoCalculateConsensusAndConservation = true;
638 public boolean getAutoCalculateConsensusAndConservation()
640 return autoCalculateConsensusAndConservation;
643 public void setAutoCalculateConsensusAndConservation(boolean b)
645 autoCalculateConsensusAndConservation = b;
648 protected boolean autoCalculateStrucConsensus = true;
650 public boolean getAutoCalculateStrucConsensus()
652 return autoCalculateStrucConsensus;
655 public void setAutoCalculateStrucConsensus(boolean b)
657 autoCalculateStrucConsensus = b;
661 protected boolean ignoreGapsInConsensusCalculation = false;
663 protected ResidueShaderI residueShading = new ResidueShader();
666 public void setGlobalColourScheme(ColourSchemeI cs)
668 // TODO: logic refactored from AlignFrame changeColour -
669 // TODO: autorecalc stuff should be changed to rely on the worker system
670 // check to see if we should implement a changeColour(cs) method rather than
671 // put the logic in here
672 // - means that caller decides if they want to just modify state and defer
673 // calculation till later or to do all calculations in thread.
677 * only instantiate alignment colouring once, thereafter update it;
678 * this means that any conservation or PID threshold settings
679 * persist when the alignment colour scheme is changed
681 if (residueShading == null)
683 residueShading = new ResidueShader(viewStyle);
685 residueShading.setColourScheme(cs);
687 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
688 // ...problem: groups need these, but do not currently have a ViewStyle
692 if (getConservationSelected())
694 residueShading.setConservation(hconservation);
697 * reset conservation flag in case just set to false if
698 * Conservation was null (calculation still in progress)
700 residueShading.setConservationApplied(getConservationSelected());
701 residueShading.alignmentChanged(alignment, hiddenRepSequences);
705 * if 'apply colour to all groups' is selected... do so
706 * (but don't transfer any colour threshold settings to groups)
708 if (getColourAppliesToAllGroups())
710 for (SequenceGroup sg : getAlignment().getGroups())
713 * retain any colour thresholds per group while
714 * changing choice of colour scheme (JAL-2386)
717 cs == null ? null : cs.getInstance(this, sg));
720 sg.getGroupColourScheme().alignmentChanged(sg,
728 public ColourSchemeI getGlobalColourScheme()
730 return residueShading == null ? null : residueShading.getColourScheme();
734 public ResidueShaderI getResidueShading()
736 return residueShading;
739 protected AlignmentAnnotation consensus;
741 protected AlignmentAnnotation complementConsensus;
743 protected AlignmentAnnotation gapcounts;
745 protected AlignmentAnnotation strucConsensus;
747 protected AlignmentAnnotation conservation;
749 protected AlignmentAnnotation quality;
751 protected AlignmentAnnotation[] groupConsensus;
753 protected AlignmentAnnotation[] groupConservation;
756 * results of alignment consensus analysis for visible portion of view
758 protected ProfilesI hconsensus = null;
761 * results of cDNA complement consensus visible portion of view
763 protected Hashtable<String, Object>[] hcomplementConsensus = null;
766 * results of secondary structure base pair consensus for visible portion of
769 protected Hashtable<String, Object>[] hStrucConsensus = null;
771 protected Conservation hconservation = null;
774 public void setConservation(Conservation cons)
776 hconservation = cons;
780 * percentage gaps allowed in a column before all amino acid properties should
781 * be considered unconserved
783 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
786 public int getConsPercGaps()
792 public void setSequenceConsensusHash(ProfilesI hconsensus)
794 this.hconsensus = hconsensus;
798 public void setComplementConsensusHash(
799 Hashtable<String, Object>[] hconsensus)
801 this.hcomplementConsensus = hconsensus;
805 public ProfilesI getSequenceConsensusHash()
811 public void setHmmProfiles(ProfilesI info)
817 public ProfilesI getHmmProfiles()
823 public Hashtable<String, Object>[] getComplementConsensusHash()
825 return hcomplementConsensus;
829 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
831 return hStrucConsensus;
835 public void setRnaStructureConsensusHash(
836 Hashtable<String, Object>[] hStrucConsensus)
838 this.hStrucConsensus = hStrucConsensus;
843 public AlignmentAnnotation getAlignmentQualityAnnot()
849 public AlignmentAnnotation getAlignmentConservationAnnotation()
855 public AlignmentAnnotation getAlignmentConsensusAnnotation()
861 public AlignmentAnnotation getAlignmentGapAnnotation()
867 public AlignmentAnnotation getComplementConsensusAnnotation()
869 return complementConsensus;
873 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
875 return strucConsensus;
878 protected AlignCalcManagerI2 calculator = new AlignCalcManager2();
881 * trigger update of conservation annotation
883 public void updateConservation(final AlignmentViewPanel ap)
885 // see note in mantis : issue number 8585
886 if (alignment.isNucleotide()
887 || (conservation == null && quality == null)
888 || !autoCalculateConsensusAndConservation)
892 if (calculator.getWorkersOfClass(
893 jalview.workers.ConservationThread.class).isEmpty())
895 calculator.registerWorker(
896 new jalview.workers.ConservationThread(this, ap));
901 * trigger update of consensus annotation
903 public void updateConsensus(final AlignmentViewPanel ap)
905 // see note in mantis : issue number 8585
906 if (consensus == null || !autoCalculateConsensusAndConservation)
910 if (calculator.getWorkersOfClass(ConsensusThread.class).isEmpty())
912 calculator.registerWorker(new ConsensusThread(this, ap));
916 * A separate thread to compute cDNA consensus for a protein alignment
917 * which has mapping to cDNA
919 final AlignmentI al = this.getAlignment();
920 if (!al.isNucleotide() && al.getCodonFrames() != null
921 && !al.getCodonFrames().isEmpty())
924 * fudge - check first for protein-to-nucleotide mappings
925 * (we don't want to do this for protein-to-protein)
927 boolean doConsensus = false;
928 for (AlignedCodonFrame mapping : al.getCodonFrames())
930 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
931 MapList[] mapLists = mapping.getdnaToProt();
932 // mapLists can be empty if project load has not finished resolving seqs
933 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
941 if (calculator.getWorkersOfClass(ComplementConsensusThread.class).isEmpty())
943 calculator.registerWorker(new ComplementConsensusThread(this, ap));
950 public void initInformationWorker(final AlignmentViewPanel ap)
952 if (calculator.getWorkersOfClass(InformationThread.class).isEmpty())
954 calculator.registerWorker(new InformationThread(this, ap));
958 // --------START Structure Conservation
959 public void updateStrucConsensus(final AlignmentViewPanel ap)
961 if (autoCalculateStrucConsensus && strucConsensus == null
962 && alignment.isNucleotide() && alignment.hasRNAStructure())
964 // secondary structure has been added - so init the consensus line
968 // see note in mantis : issue number 8585
969 if (strucConsensus == null || !autoCalculateStrucConsensus)
973 if (calculator.getWorkersOfClass(StrucConsensusThread.class).isEmpty())
975 calculator.registerWorker(new StrucConsensusThread(this, ap));
979 public boolean isCalcInProgress()
981 return calculator.isWorking();
985 public boolean isCalculationInProgress(
986 AlignmentAnnotation alignmentAnnotation)
988 if (!alignmentAnnotation.autoCalculated)
992 if (calculator.isWorkingWithAnnotation(alignmentAnnotation))
994 // System.err.println("grey out ("+alignmentAnnotation.label+")");
1000 public void setAlignment(AlignmentI align)
1002 this.alignment = align;
1006 * Clean up references when this viewport is closed
1009 public void dispose()
1012 * defensively null out references to large objects in case
1013 * this object is not garbage collected (as if!)
1016 complementConsensus = null;
1017 strucConsensus = null;
1018 conservation = null;
1020 consensusProfiles = null;
1021 groupConsensus = null;
1022 groupConservation = null;
1024 hconservation = null;
1025 hcomplementConsensus = null;
1027 calculator.shutdown();
1029 residueShading = null; // may hold a reference to Consensus
1030 changeSupport = null;
1033 selectionGroup = null;
1038 public boolean isClosed()
1040 // TODO: check that this isClosed is only true after panel is closed, not
1041 // before it is fully constructed.
1042 return alignment == null;
1046 public AlignCalcManagerI2 getCalcManager()
1052 * should conservation rows be shown for groups
1054 protected boolean showGroupConservation = false;
1057 * should consensus rows be shown for groups
1059 protected boolean showGroupConsensus = false;
1062 * should consensus profile be rendered by default
1064 protected boolean showSequenceLogo = false;
1067 * should consensus profile be rendered normalised to row height
1069 protected boolean normaliseSequenceLogo = false;
1072 * should consensus histograms be rendered by default
1074 protected boolean showConsensusHistogram = true;
1077 * should hmm profile be rendered by default
1079 protected boolean hmmShowSequenceLogo = false;
1082 * should hmm profile be rendered normalised to row height
1084 protected boolean hmmNormaliseSequenceLogo = false;
1087 * should information histograms be rendered by default
1089 protected boolean hmmShowHistogram = true;
1092 * @return the showConsensusProfile
1095 public boolean isShowSequenceLogo()
1097 return showSequenceLogo;
1101 * @return the showInformationProfile
1104 public boolean isShowHMMSequenceLogo()
1106 return hmmShowSequenceLogo;
1110 * @param showSequenceLogo
1113 public void setShowSequenceLogo(boolean showSequenceLogo)
1115 if (showSequenceLogo != this.showSequenceLogo)
1117 // TODO: decouple settings setting from calculation when refactoring
1118 // annotation update method from alignframe to viewport
1119 this.showSequenceLogo = showSequenceLogo;
1120 for (AlignCalcWorkerI worker : calculator.getWorkers())
1122 if (worker.getClass().equals(ConsensusThread.class) ||
1123 worker.getClass().equals(ComplementConsensusThread.class) ||
1124 worker.getClass().equals(StrucConsensusThread.class))
1126 worker.updateAnnotation();
1130 this.showSequenceLogo = showSequenceLogo;
1133 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1135 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1137 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1138 // TODO: updateAnnotation if description (tooltip) will show
1139 // profile in place of information content?
1140 // calculator.updateAnnotationFor(InformationThread.class);
1142 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1146 * @param showConsensusHistogram
1147 * the showConsensusHistogram to set
1149 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1151 this.showConsensusHistogram = showConsensusHistogram;
1155 * @param showInformationHistogram
1157 public void setShowInformationHistogram(boolean showInformationHistogram)
1159 this.hmmShowHistogram = showInformationHistogram;
1163 * @return the showGroupConservation
1165 public boolean isShowGroupConservation()
1167 return showGroupConservation;
1171 * @param showGroupConservation
1172 * the showGroupConservation to set
1174 public void setShowGroupConservation(boolean showGroupConservation)
1176 this.showGroupConservation = showGroupConservation;
1180 * @return the showGroupConsensus
1182 public boolean isShowGroupConsensus()
1184 return showGroupConsensus;
1188 * @param showGroupConsensus
1189 * the showGroupConsensus to set
1191 public void setShowGroupConsensus(boolean showGroupConsensus)
1193 this.showGroupConsensus = showGroupConsensus;
1198 * @return flag to indicate if the consensus histogram should be rendered by
1202 public boolean isShowConsensusHistogram()
1204 return this.showConsensusHistogram;
1209 * @return flag to indicate if the information content histogram should be
1210 * rendered by default
1213 public boolean isShowInformationHistogram()
1215 return this.hmmShowHistogram;
1219 * when set, updateAlignment will always ensure sequences are of equal length
1221 private boolean padGaps = false;
1224 * when set, alignment should be reordered according to a newly opened tree
1226 public boolean sortByTree = false;
1231 * @return null or the currently selected sequence region
1234 public SequenceGroup getSelectionGroup()
1236 return selectionGroup;
1240 * Set the selection group for this window. Also sets the current alignment as
1241 * the context for the group, if it does not already have one.
1244 * - group holding references to sequences in this alignment view
1248 public void setSelectionGroup(SequenceGroup sg)
1250 selectionGroup = sg;
1251 if (sg != null && sg.getContext() == null)
1253 sg.setContext(alignment);
1257 public void setHiddenColumns(HiddenColumns hidden)
1259 this.alignment.setHiddenColumns(hidden);
1263 public ColumnSelection getColumnSelection()
1269 public void setColumnSelection(ColumnSelection colSel)
1271 this.colSel = colSel;
1274 updateHiddenColumns();
1276 isColSelChanged(true);
1284 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1286 return hiddenRepSequences;
1290 public void setHiddenRepSequences(
1291 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1293 this.hiddenRepSequences = hiddenRepSequences;
1297 public boolean hasSelectedColumns()
1299 ColumnSelection columnSelection = getColumnSelection();
1300 return columnSelection != null && columnSelection.hasSelectedColumns();
1304 public boolean hasHiddenColumns()
1306 return alignment.getHiddenColumns() != null
1307 && alignment.getHiddenColumns().hasHiddenColumns();
1310 public void updateHiddenColumns()
1312 // this method doesn't really do anything now. But - it could, since a
1313 // column Selection could be in the process of modification
1314 // hasHiddenColumns = colSel.hasHiddenColumns();
1318 public boolean hasHiddenRows()
1320 return alignment.getHiddenSequences().getSize() > 0;
1323 protected SequenceGroup selectionGroup;
1325 public void setSequenceSetId(String newid)
1327 if (sequenceSetID != null)
1330 "Warning - overwriting a sequenceSetId for a viewport!");
1332 sequenceSetID = new String(newid);
1336 public String getSequenceSetId()
1338 if (sequenceSetID == null)
1340 sequenceSetID = alignment.hashCode() + "";
1343 return sequenceSetID;
1347 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1350 protected String viewId = null;
1353 public String getViewId()
1357 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1362 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1364 ignoreGapsInConsensusCalculation = b;
1367 updateConsensus(ap);
1368 if (residueShading != null)
1370 residueShading.setThreshold(residueShading.getThreshold(),
1371 ignoreGapsInConsensusCalculation);
1376 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1378 ignoreBelowBackGroundFrequencyCalculation = b;
1381 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1383 infoLetterHeight = b;
1386 private long sgrouphash = -1, colselhash = -1;
1389 * checks current SelectionGroup against record of last hash value, and
1393 * update the record of last hash value
1395 * @return true if SelectionGroup changed since last call (when b is true)
1397 public boolean isSelectionGroupChanged(boolean b)
1399 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1400 : selectionGroup.hashCode();
1401 if (hc != -1 && hc != sgrouphash)
1413 * checks current colsel against record of last hash value, and optionally
1417 * update the record of last hash value
1418 * @return true if colsel changed since last call (when b is true)
1420 public boolean isColSelChanged(boolean updateHash)
1422 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1423 if (hc != -1 && hc != colselhash)
1436 public boolean isIgnoreGapsConsensus()
1438 return ignoreGapsInConsensusCalculation;
1442 public boolean isIgnoreBelowBackground()
1444 return ignoreBelowBackGroundFrequencyCalculation;
1448 public boolean isInfoLetterHeight()
1450 return infoLetterHeight;
1453 // property change stuff
1454 // JBPNote Prolly only need this in the applet version.
1455 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1458 protected boolean showConservation = true;
1460 protected boolean showQuality = true;
1462 protected boolean showConsensus = true;
1464 protected boolean showOccupancy = true;
1466 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1468 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1470 protected boolean showAutocalculatedAbove;
1473 * when set, view will scroll to show the highlighted position
1475 private boolean followHighlight = true;
1478 * Property change listener for changes in alignment
1483 public void addPropertyChangeListener(
1484 java.beans.PropertyChangeListener listener)
1486 changeSupport.addPropertyChangeListener(listener);
1495 public void removePropertyChangeListener(
1496 java.beans.PropertyChangeListener listener)
1498 if (changeSupport != null)
1500 changeSupport.removePropertyChangeListener(listener);
1504 // common hide/show column stuff
1506 public void hideSelectedColumns()
1508 if (colSel.isEmpty())
1513 colSel.hideSelectedColumns(alignment);
1514 setSelectionGroup(null);
1515 isColSelChanged(true);
1518 public void hideColumns(int start, int end)
1522 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1526 alignment.getHiddenColumns().hideColumns(start, end);
1528 isColSelChanged(true);
1531 public void showColumn(int col)
1533 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1534 isColSelChanged(true);
1537 public void showAllHiddenColumns()
1539 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1540 isColSelChanged(true);
1543 // common hide/show seq stuff
1544 public void showAllHiddenSeqs()
1546 int startSeq = ranges.getStartSeq();
1547 int endSeq = ranges.getEndSeq();
1549 if (alignment.getHiddenSequences().getSize() > 0)
1551 if (selectionGroup == null)
1553 selectionGroup = new SequenceGroup();
1554 selectionGroup.setEndRes(alignment.getWidth() - 1);
1556 List<SequenceI> tmp = alignment.getHiddenSequences()
1557 .showAll(hiddenRepSequences);
1558 for (SequenceI seq : tmp)
1560 selectionGroup.addSequence(seq, false);
1561 setSequenceAnnotationsVisible(seq, true);
1564 hiddenRepSequences = null;
1566 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1568 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1576 public void showSequence(int index)
1578 int startSeq = ranges.getStartSeq();
1579 int endSeq = ranges.getEndSeq();
1581 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1582 hiddenRepSequences);
1585 if (selectionGroup == null)
1587 selectionGroup = new SequenceGroup();
1588 selectionGroup.setEndRes(alignment.getWidth() - 1);
1591 for (SequenceI seq : tmp)
1593 selectionGroup.addSequence(seq, false);
1594 setSequenceAnnotationsVisible(seq, true);
1597 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1603 public void hideAllSelectedSeqs()
1605 if (selectionGroup == null || selectionGroup.getSize() < 1)
1610 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1614 setSelectionGroup(null);
1617 public void hideSequence(SequenceI[] seq)
1620 * cache offset to first visible sequence
1622 int startSeq = ranges.getStartSeq();
1626 for (int i = 0; i < seq.length; i++)
1628 alignment.getHiddenSequences().hideSequence(seq[i]);
1629 setSequenceAnnotationsVisible(seq[i], false);
1631 ranges.setStartSeq(startSeq);
1637 * Hides the specified sequence, or the sequences it represents
1640 * the sequence to hide, or keep as representative
1641 * @param representGroup
1642 * if true, hide the current selection group except for the
1643 * representative sequence
1645 public void hideSequences(SequenceI sequence, boolean representGroup)
1647 if (selectionGroup == null || selectionGroup.getSize() < 1)
1649 hideSequence(new SequenceI[] { sequence });
1655 hideRepSequences(sequence, selectionGroup);
1656 setSelectionGroup(null);
1660 int gsize = selectionGroup.getSize();
1661 SequenceI[] hseqs = selectionGroup.getSequences()
1662 .toArray(new SequenceI[gsize]);
1664 hideSequence(hseqs);
1665 setSelectionGroup(null);
1670 * Set visibility for any annotations for the given sequence.
1674 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1677 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1680 for (AlignmentAnnotation ann : anns)
1682 if (ann.sequenceRef == sequenceI)
1684 ann.visible = visible;
1690 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1692 int sSize = sg.getSize();
1698 if (hiddenRepSequences == null)
1700 hiddenRepSequences = new Hashtable<>();
1703 hiddenRepSequences.put(repSequence, sg);
1705 // Hide all sequences except the repSequence
1706 SequenceI[] seqs = new SequenceI[sSize - 1];
1708 for (int i = 0; i < sSize; i++)
1710 if (sg.getSequenceAt(i) != repSequence)
1712 if (index == sSize - 1)
1717 seqs[index++] = sg.getSequenceAt(i);
1720 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1721 sg.setHidereps(true); // note: not done in 2.7applet
1728 * @return null or the current reference sequence
1730 public SequenceI getReferenceSeq()
1732 return alignment.getSeqrep();
1737 * @return true iff seq is the reference for the alignment
1739 public boolean isReferenceSeq(SequenceI seq)
1741 return alignment.getSeqrep() == seq;
1747 * @return true if there are sequences represented by this sequence that are
1750 public boolean isHiddenRepSequence(SequenceI seq)
1752 return (hiddenRepSequences != null
1753 && hiddenRepSequences.containsKey(seq));
1759 * @return null or a sequence group containing the sequences that seq
1762 public SequenceGroup getRepresentedSequences(SequenceI seq)
1764 return (SequenceGroup) (hiddenRepSequences == null ? null
1765 : hiddenRepSequences.get(seq));
1769 public int adjustForHiddenSeqs(int alignmentIndex)
1771 return alignment.getHiddenSequences()
1772 .adjustForHiddenSeqs(alignmentIndex);
1776 public void invertColumnSelection()
1778 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1779 isColSelChanged(true);
1783 public SequenceI[] getSelectionAsNewSequence()
1785 SequenceI[] sequences;
1786 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1787 // this was the only caller in the applet for this method
1788 // JBPNote: in applet, this method returned references to the alignment
1789 // sequences, and it did not honour the presence/absence of annotation
1790 // attached to the alignment (probably!)
1791 if (selectionGroup == null || selectionGroup.getSize() == 0)
1793 sequences = alignment.getSequencesArray();
1794 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1795 for (int i = 0; i < sequences.length; i++)
1797 // construct new sequence with subset of visible annotation
1798 sequences[i] = new Sequence(sequences[i], annots);
1803 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1810 public SequenceI[] getSequenceSelection()
1812 SequenceI[] sequences = null;
1813 if (selectionGroup != null)
1815 sequences = selectionGroup.getSequencesInOrder(alignment);
1817 if (sequences == null)
1819 sequences = alignment.getSequencesArray();
1825 public jalview.datamodel.AlignmentView getAlignmentView(
1826 boolean selectedOnly)
1828 return getAlignmentView(selectedOnly, false);
1832 public jalview.datamodel.AlignmentView getAlignmentView(
1833 boolean selectedOnly, boolean markGroups)
1835 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1837 alignment.getHiddenColumns() != null
1838 && alignment.getHiddenColumns().hasHiddenColumns(),
1839 selectedOnly, markGroups);
1843 public String[] getViewAsString(boolean selectedRegionOnly)
1845 return getViewAsString(selectedRegionOnly, true);
1849 public String[] getViewAsString(boolean selectedRegionOnly,
1850 boolean exportHiddenSeqs)
1852 String[] selection = null;
1853 SequenceI[] seqs = null;
1855 int start = 0, end = 0;
1856 if (selectedRegionOnly && selectionGroup != null)
1858 iSize = selectionGroup.getSize();
1859 seqs = selectionGroup.getSequencesInOrder(alignment);
1860 start = selectionGroup.getStartRes();
1861 end = selectionGroup.getEndRes() + 1;
1865 if (hasHiddenRows() && exportHiddenSeqs)
1867 AlignmentI fullAlignment = alignment.getHiddenSequences()
1868 .getFullAlignment();
1869 iSize = fullAlignment.getHeight();
1870 seqs = fullAlignment.getSequencesArray();
1871 end = fullAlignment.getWidth();
1875 iSize = alignment.getHeight();
1876 seqs = alignment.getSequencesArray();
1877 end = alignment.getWidth();
1881 selection = new String[iSize];
1882 if (alignment.getHiddenColumns() != null
1883 && alignment.getHiddenColumns().hasHiddenColumns())
1885 for (i = 0; i < iSize; i++)
1887 Iterator<int[]> blocks = alignment.getHiddenColumns()
1888 .getVisContigsIterator(start, end + 1, false);
1889 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1894 for (i = 0; i < iSize; i++)
1896 selection[i] = seqs[i].getSequenceAsString(start, end);
1904 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1906 ArrayList<int[]> regions = new ArrayList<>();
1912 HiddenColumns hidden = alignment.getHiddenColumns();
1913 if (hidden != null && hidden.hasHiddenColumns())
1917 start = hidden.visibleToAbsoluteColumn(start);
1920 end = hidden.getNextHiddenBoundary(false, start);
1931 regions.add(new int[] { start, end });
1933 if (hidden != null && hidden.hasHiddenColumns())
1935 start = hidden.visibleToAbsoluteColumn(end);
1936 start = hidden.getNextHiddenBoundary(true, start) + 1;
1938 } while (end < max);
1940 // int[][] startEnd = new int[regions.size()][2];
1946 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1947 boolean selectedOnly)
1949 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1950 AlignmentAnnotation[] aa;
1951 if ((aa = alignment.getAlignmentAnnotation()) != null)
1953 for (AlignmentAnnotation annot : aa)
1955 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1956 if (selectedOnly && selectionGroup != null)
1958 clone.makeVisibleAnnotation(
1959 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1960 alignment.getHiddenColumns());
1964 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1973 public boolean isPadGaps()
1979 public void setPadGaps(boolean padGaps)
1981 this.padGaps = padGaps;
1985 * apply any post-edit constraints and trigger any calculations needed after
1986 * an edit has been performed on the alignment
1991 public void alignmentChanged(AlignmentViewPanel ap)
1995 alignment.padGaps();
1997 if (autoCalculateConsensusAndConservation)
1999 updateConsensus(ap);
2001 if (hconsensus != null && autoCalculateConsensusAndConservation)
2003 updateConservation(ap);
2005 if (autoCalculateStrucConsensus)
2007 updateStrucConsensus(ap);
2010 // Reset endRes of groups if beyond alignment width
2011 int alWidth = alignment.getWidth();
2012 List<SequenceGroup> groups = alignment.getGroups();
2015 for (SequenceGroup sg : groups)
2017 if (sg.getEndRes() > alWidth)
2019 sg.setEndRes(alWidth - 1);
2024 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2026 selectionGroup.setEndRes(alWidth - 1);
2029 updateAllColourSchemes();
2030 calculator.restartWorkers();
2034 * reset scope and do calculations for all applied colourschemes on alignment
2036 void updateAllColourSchemes()
2038 ResidueShaderI rs = residueShading;
2041 rs.alignmentChanged(alignment, hiddenRepSequences);
2043 rs.setConsensus(hconsensus);
2044 if (rs.conservationApplied())
2046 rs.setConservation(Conservation.calculateConservation("All",
2047 alignment.getSequences(), 0, alignment.getWidth(), false,
2048 getConsPercGaps(), false));
2052 for (SequenceGroup sg : alignment.getGroups())
2056 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2058 sg.recalcConservation();
2062 protected void initAutoAnnotation()
2064 // TODO: add menu option action that nulls or creates consensus object
2065 // depending on if the user wants to see the annotation or not in a
2066 // specific alignment
2068 if (hconsensus == null && !isDataset)
2070 if (!alignment.isNucleotide())
2079 consensus = new AlignmentAnnotation("Consensus",
2080 MessageManager.getString("label.consensus_descr"),
2081 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2082 initConsensus(consensus);
2086 initComplementConsensus();
2091 * If this is a protein alignment and there are mappings to cDNA, adds the
2092 * cDNA consensus annotation and returns true, else returns false.
2094 public boolean initComplementConsensus()
2096 if (!alignment.isNucleotide())
2098 final List<AlignedCodonFrame> codonMappings = alignment
2100 if (codonMappings != null && !codonMappings.isEmpty())
2102 boolean doConsensus = false;
2103 for (AlignedCodonFrame mapping : codonMappings)
2105 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2106 MapList[] mapLists = mapping.getdnaToProt();
2107 // mapLists can be empty if project load has not finished resolving
2109 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2117 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2119 .getString("label.complement_consensus_descr"),
2120 new Annotation[1], 0f, 100f,
2121 AlignmentAnnotation.BAR_GRAPH);
2122 initConsensus(complementConsensus);
2130 private void initConsensus(AlignmentAnnotation aa)
2133 aa.autoCalculated = true;
2137 alignment.addAnnotation(aa);
2141 // these should be extracted from the view model - style and settings for
2142 // derived annotation
2143 private void initGapCounts()
2147 gapcounts = new AlignmentAnnotation("Occupancy",
2148 MessageManager.getString("label.occupancy_descr"),
2149 new Annotation[1], 0f, alignment.getHeight(),
2150 AlignmentAnnotation.BAR_GRAPH);
2151 gapcounts.hasText = true;
2152 gapcounts.autoCalculated = true;
2153 gapcounts.scaleColLabel = true;
2154 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2156 alignment.addAnnotation(gapcounts);
2160 private void initConservation()
2162 if (showConservation)
2164 if (conservation == null)
2166 conservation = new AlignmentAnnotation("Conservation",
2167 MessageManager.formatMessage("label.conservation_descr",
2169 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2170 conservation.hasText = true;
2171 conservation.autoCalculated = true;
2172 alignment.addAnnotation(conservation);
2177 private void initQuality()
2181 if (quality == null)
2183 quality = new AlignmentAnnotation("Quality",
2184 MessageManager.getString("label.quality_descr"),
2185 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2186 quality.hasText = true;
2187 quality.autoCalculated = true;
2188 alignment.addAnnotation(quality);
2193 private void initRNAStructure()
2195 if (alignment.hasRNAStructure() && strucConsensus == null)
2197 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2198 MessageManager.getString("label.strucconsensus_descr"),
2199 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2200 strucConsensus.hasText = true;
2201 strucConsensus.autoCalculated = true;
2205 alignment.addAnnotation(strucConsensus);
2213 * @see jalview.api.AlignViewportI#calcPanelHeight()
2216 public int calcPanelHeight()
2218 // setHeight of panels
2219 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2221 int charHeight = getCharHeight();
2224 BitSet graphgrp = new BitSet();
2225 for (AlignmentAnnotation aa : anns)
2229 System.err.println("Null annotation row: ignoring.");
2236 if (aa.graphGroup > -1)
2238 if (graphgrp.get(aa.graphGroup))
2244 graphgrp.set(aa.graphGroup);
2251 aa.height += charHeight;
2261 aa.height += aa.graphHeight;
2269 height += aa.height;
2281 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2282 boolean preserveNewGroupSettings)
2284 boolean updateCalcs = false;
2285 boolean conv = isShowGroupConservation();
2286 boolean cons = isShowGroupConsensus();
2287 boolean showprf = isShowSequenceLogo();
2288 boolean showConsHist = isShowConsensusHistogram();
2289 boolean normLogo = isNormaliseSequenceLogo();
2290 boolean showHMMPrf = isShowHMMSequenceLogo();
2291 boolean showInfoHist = isShowInformationHistogram();
2292 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2295 * TODO reorder the annotation rows according to group/sequence ordering on
2298 // boolean sortg = true;
2300 // remove old automatic annotation
2301 // add any new annotation
2303 // intersect alignment annotation with alignment groups
2305 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2306 List<SequenceGroup> oldrfs = new ArrayList<>();
2309 for (int an = 0; an < aan.length; an++)
2311 if (aan[an].autoCalculated && aan[an].groupRef != null)
2313 oldrfs.add(aan[an].groupRef);
2314 alignment.deleteAnnotation(aan[an], false);
2318 if (alignment.getGroups() != null)
2320 for (SequenceGroup sg : alignment.getGroups())
2322 updateCalcs = false;
2323 if (applyGlobalSettings
2324 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2326 // set defaults for this group's conservation/consensus
2327 sg.setshowSequenceLogo(showprf);
2328 sg.setShowConsensusHistogram(showConsHist);
2329 sg.setNormaliseSequenceLogo(normLogo);
2330 sg.setShowHMMSequenceLogo(showHMMPrf);
2331 sg.setShowInformationHistogram(showInfoHist);
2332 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2337 alignment.addAnnotation(sg.getConservationRow(), 0);
2342 alignment.addAnnotation(sg.getConsensus(), 0);
2344 // refresh the annotation rows
2347 sg.recalcConservation();
2355 public boolean isDisplayReferenceSeq()
2357 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2361 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2363 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2367 public boolean isColourByReferenceSeq()
2369 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2373 public Color getSequenceColour(SequenceI seq)
2375 Color sqc = sequenceColours.get(seq);
2376 return (sqc == null ? Color.white : sqc);
2380 public void setSequenceColour(SequenceI seq, Color col)
2384 sequenceColours.remove(seq);
2388 sequenceColours.put(seq, col);
2393 public void updateSequenceIdColours()
2395 for (SequenceGroup sg : alignment.getGroups())
2397 if (sg.idColour != null)
2399 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2401 sequenceColours.put(s, sg.idColour);
2408 public void clearSequenceColours()
2410 sequenceColours.clear();
2414 public AlignViewportI getCodingComplement()
2416 return this.codingComplement;
2420 * Set this as the (cDna/protein) complement of the given viewport. Also
2421 * ensures the reverse relationship is set on the given viewport.
2424 public void setCodingComplement(AlignViewportI av)
2428 System.err.println("Ignoring recursive setCodingComplement request");
2432 this.codingComplement = av;
2433 // avoid infinite recursion!
2434 if (av.getCodingComplement() != this)
2436 av.setCodingComplement(this);
2442 public boolean isNucleotide()
2444 return getAlignment() == null ? false : getAlignment().isNucleotide();
2448 public FeaturesDisplayedI getFeaturesDisplayed()
2450 return featuresDisplayed;
2454 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2456 featuresDisplayed = featuresDisplayedI;
2460 public boolean areFeaturesDisplayed()
2462 return featuresDisplayed != null
2463 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2470 * features are displayed if true
2473 public void setShowSequenceFeatures(boolean b)
2475 viewStyle.setShowSequenceFeatures(b);
2479 public boolean isShowSequenceFeatures()
2481 return viewStyle.isShowSequenceFeatures();
2485 public void setShowSequenceFeaturesHeight(boolean selected)
2487 viewStyle.setShowSequenceFeaturesHeight(selected);
2491 public boolean isShowSequenceFeaturesHeight()
2493 return viewStyle.isShowSequenceFeaturesHeight();
2497 public void setShowAnnotation(boolean b)
2499 viewStyle.setShowAnnotation(b);
2503 public boolean isShowAnnotation()
2505 return viewStyle.isShowAnnotation();
2509 public boolean isRightAlignIds()
2511 return viewStyle.isRightAlignIds();
2515 public void setRightAlignIds(boolean rightAlignIds)
2517 viewStyle.setRightAlignIds(rightAlignIds);
2521 public boolean getConservationSelected()
2523 return viewStyle.getConservationSelected();
2527 public void setShowBoxes(boolean state)
2529 viewStyle.setShowBoxes(state);
2534 * @see jalview.api.ViewStyleI#getTextColour()
2537 public Color getTextColour()
2539 return viewStyle.getTextColour();
2544 * @see jalview.api.ViewStyleI#getTextColour2()
2547 public Color getTextColour2()
2549 return viewStyle.getTextColour2();
2554 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2557 public int getThresholdTextColour()
2559 return viewStyle.getThresholdTextColour();
2564 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2567 public boolean isConservationColourSelected()
2569 return viewStyle.isConservationColourSelected();
2574 * @see jalview.api.ViewStyleI#isRenderGaps()
2577 public boolean isRenderGaps()
2579 return viewStyle.isRenderGaps();
2584 * @see jalview.api.ViewStyleI#isShowColourText()
2587 public boolean isShowColourText()
2589 return viewStyle.isShowColourText();
2593 * @param conservationColourSelected
2594 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2597 public void setConservationColourSelected(
2598 boolean conservationColourSelected)
2600 viewStyle.setConservationColourSelected(conservationColourSelected);
2604 * @param showColourText
2605 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2608 public void setShowColourText(boolean showColourText)
2610 viewStyle.setShowColourText(showColourText);
2615 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2618 public void setTextColour(Color textColour)
2620 viewStyle.setTextColour(textColour);
2624 * @param thresholdTextColour
2625 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2628 public void setThresholdTextColour(int thresholdTextColour)
2630 viewStyle.setThresholdTextColour(thresholdTextColour);
2634 * @param textColour2
2635 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2638 public void setTextColour2(Color textColour2)
2640 viewStyle.setTextColour2(textColour2);
2644 public ViewStyleI getViewStyle()
2646 return new ViewStyle(viewStyle);
2650 public void setViewStyle(ViewStyleI settingsForView)
2652 viewStyle = new ViewStyle(settingsForView);
2653 if (residueShading != null)
2655 residueShading.setConservationApplied(
2656 settingsForView.isConservationColourSelected());
2661 public boolean sameStyle(ViewStyleI them)
2663 return viewStyle.sameStyle(them);
2668 * @see jalview.api.ViewStyleI#getIdWidth()
2671 public int getIdWidth()
2673 return viewStyle.getIdWidth();
2678 * @see jalview.api.ViewStyleI#setIdWidth(int)
2681 public void setIdWidth(int i)
2683 viewStyle.setIdWidth(i);
2688 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2691 public boolean isCentreColumnLabels()
2693 return viewStyle.isCentreColumnLabels();
2697 * @param centreColumnLabels
2698 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2701 public void setCentreColumnLabels(boolean centreColumnLabels)
2703 viewStyle.setCentreColumnLabels(centreColumnLabels);
2708 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2711 public void setShowDBRefs(boolean showdbrefs)
2713 viewStyle.setShowDBRefs(showdbrefs);
2718 * @see jalview.api.ViewStyleI#isShowDBRefs()
2721 public boolean isShowDBRefs()
2723 return viewStyle.isShowDBRefs();
2728 * @see jalview.api.ViewStyleI#isShowNPFeats()
2731 public boolean isShowNPFeats()
2733 return viewStyle.isShowNPFeats();
2737 * @param shownpfeats
2738 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2741 public void setShowNPFeats(boolean shownpfeats)
2743 viewStyle.setShowNPFeats(shownpfeats);
2746 public abstract StructureSelectionManager getStructureSelectionManager();
2749 * Add one command to the command history list.
2753 public void addToHistoryList(CommandI command)
2755 if (this.historyList != null)
2757 this.historyList.push(command);
2758 broadcastCommand(command, false);
2762 protected void broadcastCommand(CommandI command, boolean undo)
2764 getStructureSelectionManager().commandPerformed(command, undo,
2769 * Add one command to the command redo list.
2773 public void addToRedoList(CommandI command)
2775 if (this.redoList != null)
2777 this.redoList.push(command);
2779 broadcastCommand(command, true);
2783 * Clear the command redo list.
2785 public void clearRedoList()
2787 if (this.redoList != null)
2789 this.redoList.clear();
2793 public void setHistoryList(Deque<CommandI> list)
2795 this.historyList = list;
2798 public Deque<CommandI> getHistoryList()
2800 return this.historyList;
2803 public void setRedoList(Deque<CommandI> list)
2805 this.redoList = list;
2808 public Deque<CommandI> getRedoList()
2810 return this.redoList;
2814 public VamsasSource getVamsasSource()
2819 public SequenceAnnotationOrder getSortAnnotationsBy()
2821 return sortAnnotationsBy;
2824 public void setSortAnnotationsBy(
2825 SequenceAnnotationOrder sortAnnotationsBy)
2827 this.sortAnnotationsBy = sortAnnotationsBy;
2830 public boolean isShowAutocalculatedAbove()
2832 return showAutocalculatedAbove;
2835 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2837 this.showAutocalculatedAbove = showAutocalculatedAbove;
2841 public boolean isScaleProteinAsCdna()
2843 return viewStyle.isScaleProteinAsCdna();
2847 public void setScaleProteinAsCdna(boolean b)
2849 viewStyle.setScaleProteinAsCdna(b);
2853 public boolean isProteinFontAsCdna()
2855 return viewStyle.isProteinFontAsCdna();
2859 public void setProteinFontAsCdna(boolean b)
2861 viewStyle.setProteinFontAsCdna(b);
2865 public void setShowComplementFeatures(boolean b)
2867 viewStyle.setShowComplementFeatures(b);
2871 public boolean isShowComplementFeatures()
2873 return viewStyle.isShowComplementFeatures();
2877 public void setShowComplementFeaturesOnTop(boolean b)
2879 viewStyle.setShowComplementFeaturesOnTop(b);
2883 public boolean isShowComplementFeaturesOnTop()
2885 return viewStyle.isShowComplementFeaturesOnTop();
2889 * @return true if view should scroll to show the highlighted region of a
2894 public final boolean isFollowHighlight()
2896 return followHighlight;
2900 public final void setFollowHighlight(boolean b)
2902 this.followHighlight = b;
2906 public ViewportRanges getRanges()
2912 * Helper method to populate the SearchResults with the location in the
2913 * complementary alignment to scroll to, in order to match this one.
2916 * the SearchResults to add to
2917 * @return the offset (below top of visible region) of the matched sequence
2919 protected int findComplementScrollTarget(SearchResultsI sr)
2921 final AlignViewportI complement = getCodingComplement();
2922 if (complement == null || !complement.isFollowHighlight())
2926 boolean iAmProtein = !getAlignment().isNucleotide();
2927 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2928 : complement.getAlignment();
2929 if (proteinAlignment == null)
2933 final List<AlignedCodonFrame> mappings = proteinAlignment
2937 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2938 * residue in the middle column of the visible region. Scroll the
2939 * complementary alignment to line up the corresponding residue.
2942 SequenceI sequence = null;
2945 * locate 'middle' column (true middle if an odd number visible, left of
2946 * middle if an even number visible)
2948 int middleColumn = ranges.getStartRes()
2949 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2950 final HiddenSequences hiddenSequences = getAlignment()
2951 .getHiddenSequences();
2954 * searching to the bottom of the alignment gives smoother scrolling across
2955 * all gapped visible regions
2957 int lastSeq = alignment.getHeight() - 1;
2958 List<AlignedCodonFrame> seqMappings = null;
2959 for (int seqNo = ranges
2960 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2962 sequence = getAlignment().getSequenceAt(seqNo);
2963 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2967 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2971 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2973 getCodingComplement().getAlignment().getSequences());
2974 if (!seqMappings.isEmpty())
2980 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2983 * No ungapped mapped sequence in middle column - do nothing
2987 MappingUtils.addSearchResults(sr, sequence,
2988 sequence.findPosition(middleColumn), seqMappings);
2993 * synthesize a column selection if none exists so it covers the given
2994 * selection group. if wholewidth is false, no column selection is made if the
2995 * selection group covers the whole alignment width.
3000 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
3003 if (sg != null && (sgs = sg.getStartRes()) >= 0
3004 && sg.getStartRes() <= (sge = sg.getEndRes())
3005 && !this.hasSelectedColumns())
3007 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3014 colSel = new ColumnSelection();
3016 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3018 colSel.addElement(cspos);
3024 * hold status of current selection group - defined on alignment or not.
3026 private boolean selectionIsDefinedGroup = false;
3029 public boolean isSelectionDefinedGroup()
3031 if (selectionGroup == null)
3035 if (isSelectionGroupChanged(true))
3037 selectionIsDefinedGroup = false;
3038 List<SequenceGroup> gps = alignment.getGroups();
3039 if (gps == null || gps.size() == 0)
3041 selectionIsDefinedGroup = false;
3045 selectionIsDefinedGroup = gps.contains(selectionGroup);
3048 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3052 * null, or currently highlighted results on this view
3054 private SearchResultsI searchResults = null;
3056 protected TreeModel currentTree = null;
3059 public boolean hasSearchResults()
3061 return searchResults != null;
3065 public void setSearchResults(SearchResultsI results)
3067 searchResults = results;
3071 public SearchResultsI getSearchResults()
3073 return searchResults;
3077 * get the consensus sequence as displayed under the PID consensus annotation
3080 * @return consensus sequence as a new sequence object
3082 public SequenceI getConsensusSeq()
3084 if (consensus == null)
3086 updateConsensus(null);
3088 if (consensus == null)
3092 StringBuffer seqs = new StringBuffer();
3093 for (int i = 0; i < consensus.annotations.length; i++)
3095 Annotation annotation = consensus.annotations[i];
3096 if (annotation != null)
3098 String description = annotation.description;
3099 if (description != null && description.startsWith("["))
3101 // consensus is a tie - just pick the first one
3102 seqs.append(description.charAt(1));
3106 seqs.append(annotation.displayCharacter);
3111 SequenceI sq = new Sequence("Consensus", seqs.toString());
3112 sq.setDescription("Percentage Identity Consensus "
3113 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3117 public boolean hasReferenceAnnotation()
3119 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3120 for (AlignmentAnnotation annot : annots)
3122 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3131 public void setCurrentTree(TreeModel tree)
3137 public TreeModel getCurrentTree()
3143 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3145 AlignmentI alignmentToExport = null;
3146 String[] omitHidden = null;
3147 alignmentToExport = null;
3149 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3151 omitHidden = getViewAsString(false,
3152 options.isExportHiddenSequences());
3155 int[] alignmentStartEnd = new int[2];
3156 if (hasHiddenRows() && options.isExportHiddenSequences())
3158 alignmentToExport = getAlignment().getHiddenSequences()
3159 .getFullAlignment();
3163 alignmentToExport = getAlignment();
3165 alignmentStartEnd = getAlignment().getHiddenColumns()
3166 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3167 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3168 omitHidden, alignmentStartEnd);
3173 public boolean isNormaliseSequenceLogo()
3175 return normaliseSequenceLogo;
3178 public void setNormaliseSequenceLogo(boolean state)
3180 normaliseSequenceLogo = state;
3184 public boolean isNormaliseHMMSequenceLogo()
3186 return hmmNormaliseSequenceLogo;
3189 public void setNormaliseHMMSequenceLogo(boolean state)
3191 hmmNormaliseSequenceLogo = state;
3194 * flag set to indicate if structure views might be out of sync with sequences
3198 private boolean needToUpdateStructureViews = false;
3201 public boolean isUpdateStructures()
3203 return needToUpdateStructureViews;
3207 public void setUpdateStructures(boolean update)
3209 needToUpdateStructureViews = update;
3213 public boolean needToUpdateStructureViews()
3215 boolean update = needToUpdateStructureViews;
3216 needToUpdateStructureViews = false;
3221 public void addSequenceGroup(SequenceGroup sequenceGroup)
3223 alignment.addGroup(sequenceGroup);
3225 Color col = sequenceGroup.idColour;
3228 col = col.brighter();
3230 for (SequenceI sq : sequenceGroup.getSequences())
3232 setSequenceColour(sq, col);
3236 if (codingComplement != null)
3238 SequenceGroup mappedGroup = MappingUtils
3239 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3240 if (mappedGroup.getSequences().size() > 0)
3242 codingComplement.getAlignment().addGroup(mappedGroup);
3246 for (SequenceI seq : mappedGroup.getSequences())
3248 codingComplement.setSequenceColour(seq, col);
3252 // propagate the structure view update flag according to our own setting
3253 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3257 * Filters out sequences with an eValue higher than the specified value. The
3258 * filtered sequences are hidden or deleted. Sequences with no eValues are also
3264 public void filterByEvalue(double eValue)
3266 for (SequenceI seq : alignment.getSequencesArray())
3268 if ((seq.getAnnotation("Search Scores") == null
3269 || seq.getAnnotation("Search Scores")[0].getEValue() > eValue)
3270 && seq.getHMM() == null)
3272 hideSequence(new SequenceI[] { seq });
3278 * Filters out sequences with an score lower than the specified value. The
3279 * filtered sequences are hidden or deleted.
3284 public void filterByScore(double score)
3286 for (SequenceI seq : alignment.getSequencesArray())
3288 if ((seq.getAnnotation("Search Scores") == null
3289 || seq.getAnnotation("Search Scores")[0]
3290 .getBitScore() < score)
3291 && seq.getHMM() == null)
3293 hideSequence(new SequenceI[] { seq });
3299 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3301 public void notifyAlignment()
3303 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3307 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3309 public void notifySequence()
3311 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);