2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignViewportI;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.api.FeaturesDisplayedI;
30 import jalview.api.ViewStyleI;
31 import jalview.commands.CommandI;
32 import jalview.datamodel.AlignedCodonFrame;
33 import jalview.datamodel.AlignmentAnnotation;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentView;
36 import jalview.datamodel.Annotation;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.renderer.ResidueShader;
47 import jalview.renderer.ResidueShaderI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.util.MessageManager;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.InformationThread;
61 import jalview.workers.StrucConsensusThread;
63 import java.awt.Color;
64 import java.beans.PropertyChangeSupport;
65 import java.util.ArrayDeque;
66 import java.util.ArrayList;
67 import java.util.BitSet;
68 import java.util.Deque;
69 import java.util.HashMap;
70 import java.util.Hashtable;
71 import java.util.Iterator;
72 import java.util.List;
76 * base class holding visualization and analysis attributes and common logic for
77 * an active alignment view displayed in the GUI
82 public abstract class AlignmentViewport
83 implements AlignViewportI, CommandListener, VamsasSource
85 protected ViewportRanges ranges;
87 protected ViewStyleI viewStyle = new ViewStyle();
90 * A viewport that hosts the cDna view of this (protein), or vice versa (if
93 AlignViewportI codingComplement = null;
95 FeaturesDisplayedI featuresDisplayed = null;
97 protected Deque<CommandI> historyList = new ArrayDeque<>();
99 protected Deque<CommandI> redoList = new ArrayDeque<>();
102 * alignment displayed in the viewport. Please use get/setter
104 protected AlignmentI alignment;
107 * probably unused indicator that view is of a dataset rather than an
111 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
113 protected ColumnSelection colSel = new ColumnSelection();
115 public boolean autoCalculateConsensus = true;
117 protected boolean autoCalculateStrucConsensus = true;
119 protected boolean ignoreGapsInConsensusCalculation = false;
121 protected boolean ignoreBelowBackGroundFrequencyCalculation = false;
123 protected boolean infoLetterHeight = false;
125 protected ResidueShaderI residueShading = new ResidueShader();
127 protected AlignmentAnnotation consensus;
129 protected AlignmentAnnotation complementConsensus;
131 protected AlignmentAnnotation occupancy;
133 protected AlignmentAnnotation strucConsensus;
135 protected AlignmentAnnotation conservation;
137 protected AlignmentAnnotation quality;
140 * results of alignment consensus analysis for visible portion of view
142 protected ProfilesI consensusProfiles;
145 * HMM profile for the alignment
147 protected ProfilesI hmmProfiles;
150 * results of cDNA complement consensus visible portion of view
152 protected Hashtable[] hcomplementConsensus;
155 * results of secondary structure base pair consensus for visible portion of
158 protected Hashtable[] hStrucConsensus;
160 protected Conservation hconservation;
162 public AlignmentViewport(AlignmentI al)
165 ranges = new ViewportRanges(al);
170 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
173 public void setFontName(String name)
175 viewStyle.setFontName(name);
180 * @see jalview.api.ViewStyleI#setFontStyle(int)
183 public void setFontStyle(int style)
185 viewStyle.setFontStyle(style);
190 * @see jalview.api.ViewStyleI#setFontSize(int)
193 public void setFontSize(int size)
195 viewStyle.setFontSize(size);
200 * @see jalview.api.ViewStyleI#getFontStyle()
203 public int getFontStyle()
205 return viewStyle.getFontStyle();
210 * @see jalview.api.ViewStyleI#getFontName()
213 public String getFontName()
215 return viewStyle.getFontName();
220 * @see jalview.api.ViewStyleI#getFontSize()
223 public int getFontSize()
225 return viewStyle.getFontSize();
229 * @param upperCasebold
230 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
233 public void setUpperCasebold(boolean upperCasebold)
235 viewStyle.setUpperCasebold(upperCasebold);
240 * @see jalview.api.ViewStyleI#isUpperCasebold()
243 public boolean isUpperCasebold()
245 return viewStyle.isUpperCasebold();
250 * @see jalview.api.ViewStyleI#isSeqNameItalics()
253 public boolean isSeqNameItalics()
255 return viewStyle.isSeqNameItalics();
259 * @param colourByReferenceSeq
260 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
263 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
265 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
270 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
273 public void setColourAppliesToAllGroups(boolean b)
275 viewStyle.setColourAppliesToAllGroups(b);
280 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
283 public boolean getColourAppliesToAllGroups()
285 return viewStyle.getColourAppliesToAllGroups();
290 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
293 public boolean getAbovePIDThreshold()
295 return viewStyle.getAbovePIDThreshold();
300 * @see jalview.api.ViewStyleI#setIncrement(int)
303 public void setIncrement(int inc)
305 viewStyle.setIncrement(inc);
310 * @see jalview.api.ViewStyleI#getIncrement()
313 public int getIncrement()
315 return viewStyle.getIncrement();
320 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
323 public void setConservationSelected(boolean b)
325 viewStyle.setConservationSelected(b);
330 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
333 public void setShowHiddenMarkers(boolean show)
335 viewStyle.setShowHiddenMarkers(show);
340 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
343 public boolean getShowHiddenMarkers()
345 return viewStyle.getShowHiddenMarkers();
350 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
353 public void setScaleRightWrapped(boolean b)
355 viewStyle.setScaleRightWrapped(b);
360 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
363 public void setScaleLeftWrapped(boolean b)
365 viewStyle.setScaleLeftWrapped(b);
370 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
373 public void setScaleAboveWrapped(boolean b)
375 viewStyle.setScaleAboveWrapped(b);
380 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
383 public boolean getScaleLeftWrapped()
385 return viewStyle.getScaleLeftWrapped();
390 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
393 public boolean getScaleAboveWrapped()
395 return viewStyle.getScaleAboveWrapped();
400 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
403 public boolean getScaleRightWrapped()
405 return viewStyle.getScaleRightWrapped();
410 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
413 public void setAbovePIDThreshold(boolean b)
415 viewStyle.setAbovePIDThreshold(b);
420 * @see jalview.api.ViewStyleI#setThreshold(int)
423 public void setThreshold(int thresh)
425 viewStyle.setThreshold(thresh);
430 * @see jalview.api.ViewStyleI#getThreshold()
433 public int getThreshold()
435 return viewStyle.getThreshold();
440 * @see jalview.api.ViewStyleI#getShowJVSuffix()
443 public boolean getShowJVSuffix()
445 return viewStyle.getShowJVSuffix();
450 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
453 public void setShowJVSuffix(boolean b)
455 viewStyle.setShowJVSuffix(b);
460 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
463 public void setWrapAlignment(boolean state)
465 viewStyle.setWrapAlignment(state);
466 ranges.setWrappedMode(state);
471 * @see jalview.api.ViewStyleI#setShowText(boolean)
474 public void setShowText(boolean state)
476 viewStyle.setShowText(state);
481 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
484 public void setRenderGaps(boolean state)
486 viewStyle.setRenderGaps(state);
491 * @see jalview.api.ViewStyleI#getColourText()
494 public boolean getColourText()
496 return viewStyle.getColourText();
501 * @see jalview.api.ViewStyleI#setColourText(boolean)
504 public void setColourText(boolean state)
506 viewStyle.setColourText(state);
511 * @see jalview.api.ViewStyleI#getWrapAlignment()
514 public boolean getWrapAlignment()
516 return viewStyle.getWrapAlignment();
521 * @see jalview.api.ViewStyleI#getShowText()
524 public boolean getShowText()
526 return viewStyle.getShowText();
531 * @see jalview.api.ViewStyleI#getWrappedWidth()
534 public int getWrappedWidth()
536 return viewStyle.getWrappedWidth();
541 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
544 public void setWrappedWidth(int w)
546 viewStyle.setWrappedWidth(w);
551 * @see jalview.api.ViewStyleI#getCharHeight()
554 public int getCharHeight()
556 return viewStyle.getCharHeight();
561 * @see jalview.api.ViewStyleI#setCharHeight(int)
564 public void setCharHeight(int h)
566 viewStyle.setCharHeight(h);
571 * @see jalview.api.ViewStyleI#getCharWidth()
574 public int getCharWidth()
576 return viewStyle.getCharWidth();
581 * @see jalview.api.ViewStyleI#setCharWidth(int)
584 public void setCharWidth(int w)
586 viewStyle.setCharWidth(w);
591 * @see jalview.api.ViewStyleI#getShowBoxes()
594 public boolean getShowBoxes()
596 return viewStyle.getShowBoxes();
601 * @see jalview.api.ViewStyleI#getShowUnconserved()
604 public boolean getShowUnconserved()
606 return viewStyle.getShowUnconserved();
610 * @param showunconserved
611 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
614 public void setShowUnconserved(boolean showunconserved)
616 viewStyle.setShowUnconserved(showunconserved);
621 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
624 public void setSeqNameItalics(boolean default1)
626 viewStyle.setSeqNameItalics(default1);
630 public AlignmentI getAlignment()
636 public char getGapCharacter()
638 return alignment.getGapCharacter();
641 protected String sequenceSetID;
644 * probably unused indicator that view is of a dataset rather than an
647 protected boolean isDataset = false;
649 public void setDataset(boolean b)
654 public boolean isDataset()
659 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
661 protected ColumnSelection colSel = new ColumnSelection();
663 public boolean autoCalculateConsensus = true;
665 protected boolean autoCalculateStrucConsensus = true;
667 protected boolean ignoreGapsInConsensusCalculation = false;
669 protected ResidueShaderI residueShading = new ResidueShader();
672 public void setGlobalColourScheme(ColourSchemeI cs)
674 // TODO: logic refactored from AlignFrame changeColour -
675 // TODO: autorecalc stuff should be changed to rely on the worker system
676 // check to see if we should implement a changeColour(cs) method rather than
677 // put the logic in here
678 // - means that caller decides if they want to just modify state and defer
679 // calculation till later or to do all calculations in thread.
683 * only instantiate alignment colouring once, thereafter update it;
684 * this means that any conservation or PID threshold settings
685 * persist when the alignment colour scheme is changed
687 if (residueShading == null)
689 residueShading = new ResidueShader(viewStyle);
691 residueShading.setColourScheme(cs);
693 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
694 // ...problem: groups need these, but do not currently have a ViewStyle
698 if (getConservationSelected())
700 residueShading.setConservation(hconservation);
703 * reset conservation flag in case just set to false if
704 * Conservation was null (calculation still in progress)
706 residueShading.setConservationApplied(getConservationSelected());
707 residueShading.alignmentChanged(alignment, hiddenRepSequences);
711 * if 'apply colour to all groups' is selected... do so
712 * (but don't transfer any colour threshold settings to groups)
714 if (getColourAppliesToAllGroups())
716 for (SequenceGroup sg : getAlignment().getGroups())
719 * retain any colour thresholds per group while
720 * changing choice of colour scheme (JAL-2386)
723 cs == null ? null : cs.getInstance(this, sg));
726 sg.getGroupColourScheme().alignmentChanged(sg,
734 public ColourSchemeI getGlobalColourScheme()
736 return residueShading == null ? null : residueShading.getColourScheme();
740 public ResidueShaderI getResidueShading()
742 return residueShading;
745 protected AlignmentAnnotation consensus;
747 protected AlignmentAnnotation complementConsensus;
749 protected AlignmentAnnotation gapcounts;
751 protected AlignmentAnnotation strucConsensus;
753 protected AlignmentAnnotation conservation;
755 protected AlignmentAnnotation quality;
757 protected AlignmentAnnotation[] groupConsensus;
759 protected AlignmentAnnotation[] groupConservation;
762 * results of alignment consensus analysis for visible portion of view
764 protected ProfilesI hconsensus = null;
767 * results of cDNA complement consensus visible portion of view
769 protected Hashtable[] hcomplementConsensus = null;
772 * results of secondary structure base pair consensus for visible portion of
775 protected Hashtable[] hStrucConsensus = null;
777 protected Conservation hconservation = null;
780 public void setConservation(Conservation cons)
782 hconservation = cons;
786 * percentage gaps allowed in a column before all amino acid properties should
787 * be considered unconserved
789 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
792 public int getConsPercGaps()
798 public void setSequenceConsensusHash(ProfilesI hconsensus)
800 this.hconsensus = hconsensus;
804 public void setComplementConsensusHash(Hashtable[] hconsensus)
806 this.hcomplementConsensus = hconsensus;
810 public ProfilesI getSequenceConsensusHash()
816 public void setHmmProfiles(ProfilesI info)
822 public ProfilesI getHmmProfiles()
828 public Hashtable[] getComplementConsensusHash()
830 return hcomplementConsensus;
834 public Hashtable[] getRnaStructureConsensusHash()
836 return hStrucConsensus;
840 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
842 this.hStrucConsensus = hStrucConsensus;
847 public AlignmentAnnotation getAlignmentQualityAnnot()
853 public AlignmentAnnotation getAlignmentConservationAnnotation()
859 public AlignmentAnnotation getAlignmentConsensusAnnotation()
865 public AlignmentAnnotation getAlignmentGapAnnotation()
871 public AlignmentAnnotation getComplementConsensusAnnotation()
873 return complementConsensus;
877 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
879 return strucConsensus;
882 protected AlignCalcManagerI calculator = new AlignCalcManager();
885 * trigger update of conservation annotation
887 public void updateConservation(final AlignmentViewPanel ap)
889 // see note in mantis : issue number 8585
890 if (alignment.isNucleotide()
891 || (conservation == null && quality == null)
892 || !autoCalculateConsensus)
896 if (calculator.getRegisteredWorkersOfClass(
897 jalview.workers.ConservationThread.class) == null)
899 calculator.registerWorker(
900 new jalview.workers.ConservationThread(this, ap));
905 * trigger update of consensus annotation
907 public void updateConsensus(final AlignmentViewPanel ap)
909 // see note in mantis : issue number 8585
910 if (consensus == null || !autoCalculateConsensus)
915 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
917 calculator.registerWorker(new ConsensusThread(this, ap));
921 * A separate thread to compute cDNA consensus for a protein alignment
922 * which has mapping to cDNA
924 final AlignmentI al = this.getAlignment();
925 if (!al.isNucleotide() && al.getCodonFrames() != null
926 && !al.getCodonFrames().isEmpty())
929 * fudge - check first for protein-to-nucleotide mappings
930 * (we don't want to do this for protein-to-protein)
932 boolean doConsensus = false;
933 for (AlignedCodonFrame mapping : al.getCodonFrames())
935 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
936 MapList[] mapLists = mapping.getdnaToProt();
937 // mapLists can be empty if project load has not finished resolving seqs
938 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
946 if (calculator.getRegisteredWorkersOfClass(
947 ComplementConsensusThread.class) == null)
950 .registerWorker(new ComplementConsensusThread(this, ap));
957 public void initInformationWorker(final AlignmentViewPanel ap)
960 .getRegisteredWorkersOfClass(InformationThread.class) == null)
962 calculator.registerWorker(new InformationThread(this, ap));
966 // --------START Structure Conservation
967 public void updateStrucConsensus(final AlignmentViewPanel ap)
969 if (autoCalculateStrucConsensus && strucConsensus == null
970 && alignment.isNucleotide() && alignment.hasRNAStructure())
972 // secondary structure has been added - so init the consensus line
976 // see note in mantis : issue number 8585
977 if (strucConsensus == null || !autoCalculateStrucConsensus)
981 if (calculator.getRegisteredWorkersOfClass(
982 StrucConsensusThread.class) == null)
984 calculator.registerWorker(new StrucConsensusThread(this, ap));
988 public boolean isCalcInProgress()
990 return calculator.isWorking();
994 public boolean isCalculationInProgress(
995 AlignmentAnnotation alignmentAnnotation)
997 if (!alignmentAnnotation.autoCalculated)
1001 if (calculator.workingInvolvedWith(alignmentAnnotation))
1003 // System.err.println("grey out ("+alignmentAnnotation.label+")");
1009 public void setAlignment(AlignmentI align)
1011 this.alignment = align;
1015 * Clean up references when this viewport is closed
1018 public void dispose()
1021 * defensively null out references to large objects in case
1022 * this object is not garbage collected (as if!)
1025 complementConsensus = null;
1026 strucConsensus = null;
1027 conservation = null;
1029 consensusProfiles = null;
1030 groupConsensus = null;
1031 groupConservation = null;
1033 hconservation = null;
1034 hcomplementConsensus = null;
1037 residueShading = null; // may hold a reference to Consensus
1038 changeSupport = null;
1041 selectionGroup = null;
1046 public boolean isClosed()
1048 // TODO: check that this isClosed is only true after panel is closed, not
1049 // before it is fully constructed.
1050 return alignment == null;
1054 public AlignCalcManagerI getCalcManager()
1060 * should conservation rows be shown for groups
1062 protected boolean showGroupConservation = false;
1065 * should consensus rows be shown for groups
1067 protected boolean showGroupConsensus = false;
1070 * should consensus profile be rendered by default
1072 protected boolean showSequenceLogo = false;
1075 * should consensus profile be rendered normalised to row height
1077 protected boolean normaliseSequenceLogo = false;
1080 * should consensus histograms be rendered by default
1082 protected boolean showConsensusHistogram = true;
1085 * should hmm profile be rendered by default
1087 protected boolean hmmShowSequenceLogo = false;
1090 * should hmm profile be rendered normalised to row height
1092 protected boolean hmmNormaliseSequenceLogo = false;
1095 * should information histograms be rendered by default
1097 protected boolean hmmShowHistogram = true;
1100 * @return the showConsensusProfile
1103 public boolean isShowSequenceLogo()
1105 return showSequenceLogo;
1109 * @return the showInformationProfile
1112 public boolean isShowHMMSequenceLogo()
1114 return hmmShowSequenceLogo;
1118 * @param showSequenceLogo
1121 public void setShowSequenceLogo(boolean showSequenceLogo)
1123 if (showSequenceLogo != this.showSequenceLogo)
1125 // TODO: decouple settings setting from calculation when refactoring
1126 // annotation update method from alignframe to viewport
1127 this.showSequenceLogo = showSequenceLogo;
1128 calculator.updateAnnotationFor(ConsensusThread.class);
1129 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1130 calculator.updateAnnotationFor(StrucConsensusThread.class);
1132 this.showSequenceLogo = showSequenceLogo;
1135 public void setShowHMMSequenceLogo(boolean showHMMSequenceLogo)
1137 if (showHMMSequenceLogo != this.hmmShowSequenceLogo)
1139 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1140 // TODO: updateAnnotation if description (tooltip) will show
1141 // profile in place of information content?
1142 // calculator.updateAnnotationFor(InformationThread.class);
1144 this.hmmShowSequenceLogo = showHMMSequenceLogo;
1148 * @param showConsensusHistogram
1149 * the showConsensusHistogram to set
1151 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1153 this.showConsensusHistogram = showConsensusHistogram;
1157 * @param showInformationHistogram
1159 public void setShowInformationHistogram(boolean showInformationHistogram)
1161 this.hmmShowHistogram = showInformationHistogram;
1165 * @return the showGroupConservation
1167 public boolean isShowGroupConservation()
1169 return showGroupConservation;
1173 * @param showGroupConservation
1174 * the showGroupConservation to set
1176 public void setShowGroupConservation(boolean showGroupConservation)
1178 this.showGroupConservation = showGroupConservation;
1182 * @return the showGroupConsensus
1184 public boolean isShowGroupConsensus()
1186 return showGroupConsensus;
1190 * @param showGroupConsensus
1191 * the showGroupConsensus to set
1193 public void setShowGroupConsensus(boolean showGroupConsensus)
1195 this.showGroupConsensus = showGroupConsensus;
1200 * @return flag to indicate if the consensus histogram should be rendered by
1204 public boolean isShowConsensusHistogram()
1206 return this.showConsensusHistogram;
1211 * @return flag to indicate if the information content histogram should be
1212 * rendered by default
1215 public boolean isShowInformationHistogram()
1217 return this.hmmShowHistogram;
1221 * when set, updateAlignment will always ensure sequences are of equal length
1223 private boolean padGaps = false;
1226 * when set, alignment should be reordered according to a newly opened tree
1228 public boolean sortByTree = false;
1233 * @return null or the currently selected sequence region
1236 public SequenceGroup getSelectionGroup()
1238 return selectionGroup;
1242 * Set the selection group for this window. Also sets the current alignment as
1243 * the context for the group, if it does not already have one.
1246 * - group holding references to sequences in this alignment view
1250 public void setSelectionGroup(SequenceGroup sg)
1252 selectionGroup = sg;
1253 if (sg != null && sg.getContext() == null)
1255 sg.setContext(alignment);
1259 public void setHiddenColumns(HiddenColumns hidden)
1261 this.alignment.setHiddenColumns(hidden);
1265 public ColumnSelection getColumnSelection()
1271 public void setColumnSelection(ColumnSelection colSel)
1273 this.colSel = colSel;
1276 updateHiddenColumns();
1278 isColSelChanged(true);
1286 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1288 return hiddenRepSequences;
1292 public void setHiddenRepSequences(
1293 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1295 this.hiddenRepSequences = hiddenRepSequences;
1299 public boolean hasSelectedColumns()
1301 ColumnSelection columnSelection = getColumnSelection();
1302 return columnSelection != null && columnSelection.hasSelectedColumns();
1306 public boolean hasHiddenColumns()
1308 return alignment.getHiddenColumns() != null
1309 && alignment.getHiddenColumns().hasHiddenColumns();
1312 public void updateHiddenColumns()
1314 // this method doesn't really do anything now. But - it could, since a
1315 // column Selection could be in the process of modification
1316 // hasHiddenColumns = colSel.hasHiddenColumns();
1320 public boolean hasHiddenRows()
1322 return alignment.getHiddenSequences().getSize() > 0;
1325 protected SequenceGroup selectionGroup;
1327 public void setSequenceSetId(String newid)
1329 if (sequenceSetID != null)
1332 "Warning - overwriting a sequenceSetId for a viewport!");
1334 sequenceSetID = new String(newid);
1338 public String getSequenceSetId()
1340 if (sequenceSetID == null)
1342 sequenceSetID = alignment.hashCode() + "";
1345 return sequenceSetID;
1349 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1352 protected String viewId = null;
1355 public String getViewId()
1359 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1364 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1366 ignoreGapsInConsensusCalculation = b;
1369 updateConsensus(ap);
1370 if (residueShading != null)
1372 residueShading.setThreshold(residueShading.getThreshold(),
1373 ignoreGapsInConsensusCalculation);
1378 public void setIgnoreBelowBackground(boolean b, AlignmentViewPanel ap)
1380 ignoreBelowBackGroundFrequencyCalculation = b;
1383 public void setInfoLetterHeight(boolean b, AlignmentViewPanel ap)
1385 infoLetterHeight = b;
1388 private long sgrouphash = -1, colselhash = -1;
1391 * checks current SelectionGroup against record of last hash value, and
1395 * update the record of last hash value
1397 * @return true if SelectionGroup changed since last call (when b is true)
1399 public boolean isSelectionGroupChanged(boolean b)
1401 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1402 : selectionGroup.hashCode();
1403 if (hc != -1 && hc != sgrouphash)
1415 * checks current colsel against record of last hash value, and optionally
1419 * update the record of last hash value
1420 * @return true if colsel changed since last call (when b is true)
1422 public boolean isColSelChanged(boolean b)
1424 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1425 if (hc != -1 && hc != colselhash)
1437 public boolean isIgnoreGapsConsensus()
1439 return ignoreGapsInConsensusCalculation;
1443 public boolean isIgnoreBelowBackground()
1445 return ignoreBelowBackGroundFrequencyCalculation;
1449 public boolean isInfoLetterHeight()
1451 return infoLetterHeight;
1454 // property change stuff
1455 // JBPNote Prolly only need this in the applet version.
1456 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1459 protected boolean showConservation = true;
1461 protected boolean showQuality = true;
1463 protected boolean showConsensus = true;
1465 protected boolean showOccupancy = true;
1467 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1469 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1471 protected boolean showAutocalculatedAbove;
1474 * when set, view will scroll to show the highlighted position
1476 private boolean followHighlight = true;
1479 * Property change listener for changes in alignment
1484 public void addPropertyChangeListener(
1485 java.beans.PropertyChangeListener listener)
1487 changeSupport.addPropertyChangeListener(listener);
1496 public void removePropertyChangeListener(
1497 java.beans.PropertyChangeListener listener)
1499 if (changeSupport != null)
1501 changeSupport.removePropertyChangeListener(listener);
1506 * Property change listener for changes in alignment
1515 public void firePropertyChange(String prop, Object oldvalue,
1518 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1521 // common hide/show column stuff
1523 public void hideSelectedColumns()
1525 if (colSel.isEmpty())
1530 colSel.hideSelectedColumns(alignment);
1531 setSelectionGroup(null);
1532 isColSelChanged(true);
1535 public void hideColumns(int start, int end)
1539 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1543 alignment.getHiddenColumns().hideColumns(start, end);
1545 isColSelChanged(true);
1548 public void showColumn(int col)
1550 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1551 isColSelChanged(true);
1554 public void showAllHiddenColumns()
1556 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1557 isColSelChanged(true);
1560 // common hide/show seq stuff
1561 public void showAllHiddenSeqs()
1563 int startSeq = ranges.getStartSeq();
1564 int endSeq = ranges.getEndSeq();
1566 if (alignment.getHiddenSequences().getSize() > 0)
1568 if (selectionGroup == null)
1570 selectionGroup = new SequenceGroup();
1571 selectionGroup.setEndRes(alignment.getWidth() - 1);
1573 List<SequenceI> tmp = alignment.getHiddenSequences()
1574 .showAll(hiddenRepSequences);
1575 for (SequenceI seq : tmp)
1577 selectionGroup.addSequence(seq, false);
1578 setSequenceAnnotationsVisible(seq, true);
1581 hiddenRepSequences = null;
1583 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1585 firePropertyChange("alignment", null, alignment.getSequences());
1586 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1592 public void showSequence(int index)
1594 int startSeq = ranges.getStartSeq();
1595 int endSeq = ranges.getEndSeq();
1597 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1598 hiddenRepSequences);
1601 if (selectionGroup == null)
1603 selectionGroup = new SequenceGroup();
1604 selectionGroup.setEndRes(alignment.getWidth() - 1);
1607 for (SequenceI seq : tmp)
1609 selectionGroup.addSequence(seq, false);
1610 setSequenceAnnotationsVisible(seq, true);
1613 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1615 firePropertyChange("alignment", null, alignment.getSequences());
1620 public void hideAllSelectedSeqs()
1622 if (selectionGroup == null || selectionGroup.getSize() < 1)
1627 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1631 setSelectionGroup(null);
1634 public void hideSequence(SequenceI[] seq)
1637 * cache offset to first visible sequence
1639 int startSeq = ranges.getStartSeq();
1643 for (int i = 0; i < seq.length; i++)
1645 alignment.getHiddenSequences().hideSequence(seq[i]);
1646 setSequenceAnnotationsVisible(seq[i], false);
1648 ranges.setStartSeq(startSeq);
1649 firePropertyChange("alignment", null, alignment.getSequences());
1654 * Hides the specified sequence, or the sequences it represents
1657 * the sequence to hide, or keep as representative
1658 * @param representGroup
1659 * if true, hide the current selection group except for the
1660 * representative sequence
1662 public void hideSequences(SequenceI sequence, boolean representGroup)
1664 if (selectionGroup == null || selectionGroup.getSize() < 1)
1666 hideSequence(new SequenceI[] { sequence });
1672 hideRepSequences(sequence, selectionGroup);
1673 setSelectionGroup(null);
1677 int gsize = selectionGroup.getSize();
1678 SequenceI[] hseqs = selectionGroup.getSequences()
1679 .toArray(new SequenceI[gsize]);
1681 hideSequence(hseqs);
1682 setSelectionGroup(null);
1687 * Set visibility for any annotations for the given sequence.
1691 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1694 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1697 for (AlignmentAnnotation ann : anns)
1699 if (ann.sequenceRef == sequenceI)
1701 ann.visible = visible;
1707 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1709 int sSize = sg.getSize();
1715 if (hiddenRepSequences == null)
1717 hiddenRepSequences = new Hashtable<>();
1720 hiddenRepSequences.put(repSequence, sg);
1722 // Hide all sequences except the repSequence
1723 SequenceI[] seqs = new SequenceI[sSize - 1];
1725 for (int i = 0; i < sSize; i++)
1727 if (sg.getSequenceAt(i) != repSequence)
1729 if (index == sSize - 1)
1734 seqs[index++] = sg.getSequenceAt(i);
1737 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1738 sg.setHidereps(true); // note: not done in 2.7applet
1745 * @return null or the current reference sequence
1747 public SequenceI getReferenceSeq()
1749 return alignment.getSeqrep();
1754 * @return true iff seq is the reference for the alignment
1756 public boolean isReferenceSeq(SequenceI seq)
1758 return alignment.getSeqrep() == seq;
1764 * @return true if there are sequences represented by this sequence that are
1767 public boolean isHiddenRepSequence(SequenceI seq)
1769 return (hiddenRepSequences != null
1770 && hiddenRepSequences.containsKey(seq));
1776 * @return null or a sequence group containing the sequences that seq
1779 public SequenceGroup getRepresentedSequences(SequenceI seq)
1781 return (SequenceGroup) (hiddenRepSequences == null ? null
1782 : hiddenRepSequences.get(seq));
1786 public int adjustForHiddenSeqs(int alignmentIndex)
1788 return alignment.getHiddenSequences()
1789 .adjustForHiddenSeqs(alignmentIndex);
1793 public void invertColumnSelection()
1795 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1796 isColSelChanged(true);
1800 public SequenceI[] getSelectionAsNewSequence()
1802 SequenceI[] sequences;
1803 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1804 // this was the only caller in the applet for this method
1805 // JBPNote: in applet, this method returned references to the alignment
1806 // sequences, and it did not honour the presence/absence of annotation
1807 // attached to the alignment (probably!)
1808 if (selectionGroup == null || selectionGroup.getSize() == 0)
1810 sequences = alignment.getSequencesArray();
1811 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1812 for (int i = 0; i < sequences.length; i++)
1814 // construct new sequence with subset of visible annotation
1815 sequences[i] = new Sequence(sequences[i], annots);
1820 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1827 public SequenceI[] getSequenceSelection()
1829 SequenceI[] sequences = null;
1830 if (selectionGroup != null)
1832 sequences = selectionGroup.getSequencesInOrder(alignment);
1834 if (sequences == null)
1836 sequences = alignment.getSequencesArray();
1842 public jalview.datamodel.AlignmentView getAlignmentView(
1843 boolean selectedOnly)
1845 return getAlignmentView(selectedOnly, false);
1849 public jalview.datamodel.AlignmentView getAlignmentView(
1850 boolean selectedOnly, boolean markGroups)
1852 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1854 alignment.getHiddenColumns() != null
1855 && alignment.getHiddenColumns().hasHiddenColumns(),
1856 selectedOnly, markGroups);
1860 public String[] getViewAsString(boolean selectedRegionOnly)
1862 return getViewAsString(selectedRegionOnly, true);
1866 public String[] getViewAsString(boolean selectedRegionOnly,
1867 boolean exportHiddenSeqs)
1869 String[] selection = null;
1870 SequenceI[] seqs = null;
1872 int start = 0, end = 0;
1873 if (selectedRegionOnly && selectionGroup != null)
1875 iSize = selectionGroup.getSize();
1876 seqs = selectionGroup.getSequencesInOrder(alignment);
1877 start = selectionGroup.getStartRes();
1878 end = selectionGroup.getEndRes() + 1;
1882 if (hasHiddenRows() && exportHiddenSeqs)
1884 AlignmentI fullAlignment = alignment.getHiddenSequences()
1885 .getFullAlignment();
1886 iSize = fullAlignment.getHeight();
1887 seqs = fullAlignment.getSequencesArray();
1888 end = fullAlignment.getWidth();
1892 iSize = alignment.getHeight();
1893 seqs = alignment.getSequencesArray();
1894 end = alignment.getWidth();
1898 selection = new String[iSize];
1899 if (alignment.getHiddenColumns() != null
1900 && alignment.getHiddenColumns().hasHiddenColumns())
1902 for (i = 0; i < iSize; i++)
1904 Iterator<int[]> blocks = alignment.getHiddenColumns()
1905 .getVisContigsIterator(start, end + 1, false);
1906 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1911 for (i = 0; i < iSize; i++)
1913 selection[i] = seqs[i].getSequenceAsString(start, end);
1921 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1923 ArrayList<int[]> regions = new ArrayList<>();
1929 HiddenColumns hidden = alignment.getHiddenColumns();
1930 if (hidden != null && hidden.hasHiddenColumns())
1934 start = hidden.visibleToAbsoluteColumn(start);
1937 end = hidden.getNextHiddenBoundary(false, start);
1948 regions.add(new int[] { start, end });
1950 if (hidden != null && hidden.hasHiddenColumns())
1952 start = hidden.visibleToAbsoluteColumn(end);
1953 start = hidden.getNextHiddenBoundary(true, start) + 1;
1955 } while (end < max);
1957 int[][] startEnd = new int[regions.size()][2];
1963 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1964 boolean selectedOnly)
1966 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1967 AlignmentAnnotation[] aa;
1968 if ((aa = alignment.getAlignmentAnnotation()) != null)
1970 for (AlignmentAnnotation annot : aa)
1972 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1973 if (selectedOnly && selectionGroup != null)
1975 clone.makeVisibleAnnotation(
1976 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1977 alignment.getHiddenColumns());
1981 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1990 public boolean isPadGaps()
1996 public void setPadGaps(boolean padGaps)
1998 this.padGaps = padGaps;
2002 * apply any post-edit constraints and trigger any calculations needed after
2003 * an edit has been performed on the alignment
2008 public void alignmentChanged(AlignmentViewPanel ap)
2012 alignment.padGaps();
2014 if (autoCalculateConsensus)
2016 updateConsensus(ap);
2018 if (hconsensus != null && autoCalculateConsensus)
2020 updateConservation(ap);
2022 if (autoCalculateStrucConsensus)
2024 updateStrucConsensus(ap);
2027 // Reset endRes of groups if beyond alignment width
2028 int alWidth = alignment.getWidth();
2029 List<SequenceGroup> groups = alignment.getGroups();
2032 for (SequenceGroup sg : groups)
2034 if (sg.getEndRes() > alWidth)
2036 sg.setEndRes(alWidth - 1);
2041 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
2043 selectionGroup.setEndRes(alWidth - 1);
2046 updateAllColourSchemes();
2047 calculator.restartWorkers();
2051 * reset scope and do calculations for all applied colourschemes on alignment
2053 void updateAllColourSchemes()
2055 ResidueShaderI rs = residueShading;
2058 rs.alignmentChanged(alignment, hiddenRepSequences);
2060 rs.setConsensus(hconsensus);
2061 if (rs.conservationApplied())
2063 rs.setConservation(Conservation.calculateConservation("All",
2064 alignment.getSequences(), 0, alignment.getWidth(), false,
2065 getConsPercGaps(), false));
2069 for (SequenceGroup sg : alignment.getGroups())
2073 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2075 sg.recalcConservation();
2079 protected void initAutoAnnotation()
2081 // TODO: add menu option action that nulls or creates consensus object
2082 // depending on if the user wants to see the annotation or not in a
2083 // specific alignment
2085 if (hconsensus == null && !isDataset)
2087 if (!alignment.isNucleotide())
2096 consensus = new AlignmentAnnotation("Consensus",
2097 MessageManager.getString("label.consensus_descr"),
2098 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2099 initConsensus(consensus);
2103 initComplementConsensus();
2108 * If this is a protein alignment and there are mappings to cDNA, adds the
2109 * cDNA consensus annotation and returns true, else returns false.
2111 public boolean initComplementConsensus()
2113 if (!alignment.isNucleotide())
2115 final List<AlignedCodonFrame> codonMappings = alignment
2117 if (codonMappings != null && !codonMappings.isEmpty())
2119 boolean doConsensus = false;
2120 for (AlignedCodonFrame mapping : codonMappings)
2122 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2123 MapList[] mapLists = mapping.getdnaToProt();
2124 // mapLists can be empty if project load has not finished resolving
2126 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2134 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2136 .getString("label.complement_consensus_descr"),
2137 new Annotation[1], 0f, 100f,
2138 AlignmentAnnotation.BAR_GRAPH);
2139 initConsensus(complementConsensus);
2147 private void initConsensus(AlignmentAnnotation aa)
2150 aa.autoCalculated = true;
2154 alignment.addAnnotation(aa);
2158 // these should be extracted from the view model - style and settings for
2159 // derived annotation
2160 private void initGapCounts()
2164 gapcounts = new AlignmentAnnotation("Occupancy",
2165 MessageManager.getString("label.occupancy_descr"),
2166 new Annotation[1], 0f, alignment.getHeight(),
2167 AlignmentAnnotation.BAR_GRAPH);
2168 gapcounts.hasText = true;
2169 gapcounts.autoCalculated = true;
2170 gapcounts.scaleColLabel = true;
2171 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2173 alignment.addAnnotation(gapcounts);
2177 private void initConservation()
2179 if (showConservation)
2181 if (conservation == null)
2183 conservation = new AlignmentAnnotation("Conservation",
2184 MessageManager.formatMessage("label.conservation_descr",
2186 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2187 conservation.hasText = true;
2188 conservation.autoCalculated = true;
2189 alignment.addAnnotation(conservation);
2194 private void initQuality()
2198 if (quality == null)
2200 quality = new AlignmentAnnotation("Quality",
2201 MessageManager.getString("label.quality_descr"),
2202 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2203 quality.hasText = true;
2204 quality.autoCalculated = true;
2205 alignment.addAnnotation(quality);
2210 private void initRNAStructure()
2212 if (alignment.hasRNAStructure() && strucConsensus == null)
2214 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2215 MessageManager.getString("label.strucconsensus_descr"),
2216 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2217 strucConsensus.hasText = true;
2218 strucConsensus.autoCalculated = true;
2222 alignment.addAnnotation(strucConsensus);
2230 * @see jalview.api.AlignViewportI#calcPanelHeight()
2233 public int calcPanelHeight()
2235 // setHeight of panels
2236 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2238 int charHeight = getCharHeight();
2241 BitSet graphgrp = new BitSet();
2242 for (AlignmentAnnotation aa : anns)
2246 System.err.println("Null annotation row: ignoring.");
2253 if (aa.graphGroup > -1)
2255 if (graphgrp.get(aa.graphGroup))
2261 graphgrp.set(aa.graphGroup);
2268 aa.height += charHeight;
2278 aa.height += aa.graphHeight;
2286 height += aa.height;
2298 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2299 boolean preserveNewGroupSettings)
2301 boolean updateCalcs = false;
2302 boolean conv = isShowGroupConservation();
2303 boolean cons = isShowGroupConsensus();
2304 boolean showprf = isShowSequenceLogo();
2305 boolean showConsHist = isShowConsensusHistogram();
2306 boolean normLogo = isNormaliseSequenceLogo();
2307 boolean showHMMPrf = isShowHMMSequenceLogo();
2308 boolean showInfoHist = isShowInformationHistogram();
2309 boolean normHMMLogo = isNormaliseHMMSequenceLogo();
2312 * TODO reorder the annotation rows according to group/sequence ordering on
2315 boolean sortg = true;
2317 // remove old automatic annotation
2318 // add any new annotation
2320 // intersect alignment annotation with alignment groups
2322 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2323 List<SequenceGroup> oldrfs = new ArrayList<>();
2326 for (int an = 0; an < aan.length; an++)
2328 if (aan[an].autoCalculated && aan[an].groupRef != null)
2330 oldrfs.add(aan[an].groupRef);
2331 alignment.deleteAnnotation(aan[an], false);
2335 if (alignment.getGroups() != null)
2337 for (SequenceGroup sg : alignment.getGroups())
2339 updateCalcs = false;
2340 if (applyGlobalSettings
2341 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2343 // set defaults for this group's conservation/consensus
2344 sg.setshowSequenceLogo(showprf);
2345 sg.setShowConsensusHistogram(showConsHist);
2346 sg.setNormaliseSequenceLogo(normLogo);
2347 sg.setShowHMMSequenceLogo(showHMMPrf);
2348 sg.setShowInformationHistogram(showInfoHist);
2349 sg.setNormaliseHMMSequenceLogo(normHMMLogo);
2354 alignment.addAnnotation(sg.getConservationRow(), 0);
2359 alignment.addAnnotation(sg.getConsensus(), 0);
2361 // refresh the annotation rows
2364 sg.recalcConservation();
2372 public boolean isDisplayReferenceSeq()
2374 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2378 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2380 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2384 public boolean isColourByReferenceSeq()
2386 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2390 public Color getSequenceColour(SequenceI seq)
2392 Color sqc = sequenceColours.get(seq);
2393 return (sqc == null ? Color.white : sqc);
2397 public void setSequenceColour(SequenceI seq, Color col)
2401 sequenceColours.remove(seq);
2405 sequenceColours.put(seq, col);
2410 public void updateSequenceIdColours()
2412 for (SequenceGroup sg : alignment.getGroups())
2414 if (sg.idColour != null)
2416 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2418 sequenceColours.put(s, sg.idColour);
2425 public void clearSequenceColours()
2427 sequenceColours.clear();
2431 public AlignViewportI getCodingComplement()
2433 return this.codingComplement;
2437 * Set this as the (cDna/protein) complement of the given viewport. Also
2438 * ensures the reverse relationship is set on the given viewport.
2441 public void setCodingComplement(AlignViewportI av)
2445 System.err.println("Ignoring recursive setCodingComplement request");
2449 this.codingComplement = av;
2450 // avoid infinite recursion!
2451 if (av.getCodingComplement() != this)
2453 av.setCodingComplement(this);
2459 public boolean isNucleotide()
2461 return getAlignment() == null ? false : getAlignment().isNucleotide();
2465 public FeaturesDisplayedI getFeaturesDisplayed()
2467 return featuresDisplayed;
2471 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2473 featuresDisplayed = featuresDisplayedI;
2477 public boolean areFeaturesDisplayed()
2479 return featuresDisplayed != null
2480 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2487 * features are displayed if true
2490 public void setShowSequenceFeatures(boolean b)
2492 viewStyle.setShowSequenceFeatures(b);
2496 public boolean isShowSequenceFeatures()
2498 return viewStyle.isShowSequenceFeatures();
2502 public void setShowSequenceFeaturesHeight(boolean selected)
2504 viewStyle.setShowSequenceFeaturesHeight(selected);
2508 public boolean isShowSequenceFeaturesHeight()
2510 return viewStyle.isShowSequenceFeaturesHeight();
2514 public void setShowAnnotation(boolean b)
2516 viewStyle.setShowAnnotation(b);
2520 public boolean isShowAnnotation()
2522 return viewStyle.isShowAnnotation();
2526 public boolean isRightAlignIds()
2528 return viewStyle.isRightAlignIds();
2532 public void setRightAlignIds(boolean rightAlignIds)
2534 viewStyle.setRightAlignIds(rightAlignIds);
2538 public boolean getConservationSelected()
2540 return viewStyle.getConservationSelected();
2544 public void setShowBoxes(boolean state)
2546 viewStyle.setShowBoxes(state);
2551 * @see jalview.api.ViewStyleI#getTextColour()
2554 public Color getTextColour()
2556 return viewStyle.getTextColour();
2561 * @see jalview.api.ViewStyleI#getTextColour2()
2564 public Color getTextColour2()
2566 return viewStyle.getTextColour2();
2571 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2574 public int getThresholdTextColour()
2576 return viewStyle.getThresholdTextColour();
2581 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2584 public boolean isConservationColourSelected()
2586 return viewStyle.isConservationColourSelected();
2591 * @see jalview.api.ViewStyleI#isRenderGaps()
2594 public boolean isRenderGaps()
2596 return viewStyle.isRenderGaps();
2601 * @see jalview.api.ViewStyleI#isShowColourText()
2604 public boolean isShowColourText()
2606 return viewStyle.isShowColourText();
2610 * @param conservationColourSelected
2611 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2614 public void setConservationColourSelected(
2615 boolean conservationColourSelected)
2617 viewStyle.setConservationColourSelected(conservationColourSelected);
2621 * @param showColourText
2622 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2625 public void setShowColourText(boolean showColourText)
2627 viewStyle.setShowColourText(showColourText);
2632 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2635 public void setTextColour(Color textColour)
2637 viewStyle.setTextColour(textColour);
2641 * @param thresholdTextColour
2642 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2645 public void setThresholdTextColour(int thresholdTextColour)
2647 viewStyle.setThresholdTextColour(thresholdTextColour);
2651 * @param textColour2
2652 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2655 public void setTextColour2(Color textColour2)
2657 viewStyle.setTextColour2(textColour2);
2661 public ViewStyleI getViewStyle()
2663 return new ViewStyle(viewStyle);
2667 public void setViewStyle(ViewStyleI settingsForView)
2669 viewStyle = new ViewStyle(settingsForView);
2670 if (residueShading != null)
2672 residueShading.setConservationApplied(
2673 settingsForView.isConservationColourSelected());
2678 public boolean sameStyle(ViewStyleI them)
2680 return viewStyle.sameStyle(them);
2685 * @see jalview.api.ViewStyleI#getIdWidth()
2688 public int getIdWidth()
2690 return viewStyle.getIdWidth();
2695 * @see jalview.api.ViewStyleI#setIdWidth(int)
2698 public void setIdWidth(int i)
2700 viewStyle.setIdWidth(i);
2705 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2708 public boolean isCentreColumnLabels()
2710 return viewStyle.isCentreColumnLabels();
2714 * @param centreColumnLabels
2715 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2718 public void setCentreColumnLabels(boolean centreColumnLabels)
2720 viewStyle.setCentreColumnLabels(centreColumnLabels);
2725 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2728 public void setShowDBRefs(boolean showdbrefs)
2730 viewStyle.setShowDBRefs(showdbrefs);
2735 * @see jalview.api.ViewStyleI#isShowDBRefs()
2738 public boolean isShowDBRefs()
2740 return viewStyle.isShowDBRefs();
2745 * @see jalview.api.ViewStyleI#isShowNPFeats()
2748 public boolean isShowNPFeats()
2750 return viewStyle.isShowNPFeats();
2754 * @param shownpfeats
2755 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2758 public void setShowNPFeats(boolean shownpfeats)
2760 viewStyle.setShowNPFeats(shownpfeats);
2763 public abstract StructureSelectionManager getStructureSelectionManager();
2766 * Add one command to the command history list.
2770 public void addToHistoryList(CommandI command)
2772 if (this.historyList != null)
2774 this.historyList.push(command);
2775 broadcastCommand(command, false);
2779 protected void broadcastCommand(CommandI command, boolean undo)
2781 getStructureSelectionManager().commandPerformed(command, undo,
2786 * Add one command to the command redo list.
2790 public void addToRedoList(CommandI command)
2792 if (this.redoList != null)
2794 this.redoList.push(command);
2796 broadcastCommand(command, true);
2800 * Clear the command redo list.
2802 public void clearRedoList()
2804 if (this.redoList != null)
2806 this.redoList.clear();
2810 public void setHistoryList(Deque<CommandI> list)
2812 this.historyList = list;
2815 public Deque<CommandI> getHistoryList()
2817 return this.historyList;
2820 public void setRedoList(Deque<CommandI> list)
2822 this.redoList = list;
2825 public Deque<CommandI> getRedoList()
2827 return this.redoList;
2831 public VamsasSource getVamsasSource()
2836 public SequenceAnnotationOrder getSortAnnotationsBy()
2838 return sortAnnotationsBy;
2841 public void setSortAnnotationsBy(
2842 SequenceAnnotationOrder sortAnnotationsBy)
2844 this.sortAnnotationsBy = sortAnnotationsBy;
2847 public boolean isShowAutocalculatedAbove()
2849 return showAutocalculatedAbove;
2852 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2854 this.showAutocalculatedAbove = showAutocalculatedAbove;
2858 public boolean isScaleProteinAsCdna()
2860 return viewStyle.isScaleProteinAsCdna();
2864 public void setScaleProteinAsCdna(boolean b)
2866 viewStyle.setScaleProteinAsCdna(b);
2870 public boolean isProteinFontAsCdna()
2872 return viewStyle.isProteinFontAsCdna();
2876 public void setProteinFontAsCdna(boolean b)
2878 viewStyle.setProteinFontAsCdna(b);
2882 * @return true if view should scroll to show the highlighted region of a
2887 public final boolean isFollowHighlight()
2889 return followHighlight;
2893 public final void setFollowHighlight(boolean b)
2895 this.followHighlight = b;
2899 public ViewportRanges getRanges()
2905 * Helper method to populate the SearchResults with the location in the
2906 * complementary alignment to scroll to, in order to match this one.
2909 * the SearchResults to add to
2910 * @return the offset (below top of visible region) of the matched sequence
2912 protected int findComplementScrollTarget(SearchResultsI sr)
2914 final AlignViewportI complement = getCodingComplement();
2915 if (complement == null || !complement.isFollowHighlight())
2919 boolean iAmProtein = !getAlignment().isNucleotide();
2920 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2921 : complement.getAlignment();
2922 if (proteinAlignment == null)
2926 final List<AlignedCodonFrame> mappings = proteinAlignment
2930 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2931 * residue in the middle column of the visible region. Scroll the
2932 * complementary alignment to line up the corresponding residue.
2935 SequenceI sequence = null;
2938 * locate 'middle' column (true middle if an odd number visible, left of
2939 * middle if an even number visible)
2941 int middleColumn = ranges.getStartRes()
2942 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2943 final HiddenSequences hiddenSequences = getAlignment()
2944 .getHiddenSequences();
2947 * searching to the bottom of the alignment gives smoother scrolling across
2948 * all gapped visible regions
2950 int lastSeq = alignment.getHeight() - 1;
2951 List<AlignedCodonFrame> seqMappings = null;
2952 for (int seqNo = ranges
2953 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2955 sequence = getAlignment().getSequenceAt(seqNo);
2956 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2960 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2964 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2966 getCodingComplement().getAlignment().getSequences());
2967 if (!seqMappings.isEmpty())
2973 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2976 * No ungapped mapped sequence in middle column - do nothing
2980 MappingUtils.addSearchResults(sr, sequence,
2981 sequence.findPosition(middleColumn), seqMappings);
2986 * synthesize a column selection if none exists so it covers the given
2987 * selection group. if wholewidth is false, no column selection is made if the
2988 * selection group covers the whole alignment width.
2993 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2996 if (sg != null && (sgs = sg.getStartRes()) >= 0
2997 && sg.getStartRes() <= (sge = sg.getEndRes())
2998 && !this.hasSelectedColumns())
3000 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3007 colSel = new ColumnSelection();
3009 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3011 colSel.addElement(cspos);
3017 * hold status of current selection group - defined on alignment or not.
3019 private boolean selectionIsDefinedGroup = false;
3022 public boolean isSelectionDefinedGroup()
3024 if (selectionGroup == null)
3028 if (isSelectionGroupChanged(true))
3030 selectionIsDefinedGroup = false;
3031 List<SequenceGroup> gps = alignment.getGroups();
3032 if (gps == null || gps.size() == 0)
3034 selectionIsDefinedGroup = false;
3038 selectionIsDefinedGroup = gps.contains(selectionGroup);
3041 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3045 * null, or currently highlighted results on this view
3047 private SearchResultsI searchResults = null;
3049 protected TreeModel currentTree = null;
3052 public boolean hasSearchResults()
3054 return searchResults != null;
3058 public void setSearchResults(SearchResultsI results)
3060 searchResults = results;
3064 public SearchResultsI getSearchResults()
3066 return searchResults;
3070 * get the consensus sequence as displayed under the PID consensus annotation
3073 * @return consensus sequence as a new sequence object
3075 public SequenceI getConsensusSeq()
3077 if (consensus == null)
3079 updateConsensus(null);
3081 if (consensus == null)
3085 StringBuffer seqs = new StringBuffer();
3086 for (int i = 0; i < consensus.annotations.length; i++)
3088 Annotation annotation = consensus.annotations[i];
3089 if (annotation != null)
3091 String description = annotation.description;
3092 if (description != null && description.startsWith("["))
3094 // consensus is a tie - just pick the first one
3095 seqs.append(description.charAt(1));
3099 seqs.append(annotation.displayCharacter);
3104 SequenceI sq = new Sequence("Consensus", seqs.toString());
3105 sq.setDescription("Percentage Identity Consensus "
3106 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3110 public boolean hasReferenceAnnotation()
3112 AlignmentAnnotation[] annots = this.alignment.getAlignmentAnnotation();
3113 for (AlignmentAnnotation annot : annots)
3115 if ("RF".equals(annot.label) || annot.label.contains("Reference"))
3124 public void setCurrentTree(TreeModel tree)
3130 public TreeModel getCurrentTree()
3136 public boolean isNormaliseSequenceLogo()
3138 return normaliseSequenceLogo;
3141 public void setNormaliseSequenceLogo(boolean state)
3143 normaliseSequenceLogo = state;
3147 public boolean isNormaliseHMMSequenceLogo()
3149 return hmmNormaliseSequenceLogo;
3152 public void setNormaliseHMMSequenceLogo(boolean state)
3154 hmmNormaliseSequenceLogo = state;
3158 * flag set to indicate if structure views might be out of sync with sequences
3162 private boolean needToUpdateStructureViews = false;
3165 public boolean isUpdateStructures()
3167 return needToUpdateStructureViews;
3171 public void setUpdateStructures(boolean update)
3173 needToUpdateStructureViews = update;
3177 public boolean needToUpdateStructureViews()
3179 boolean update = needToUpdateStructureViews;
3180 needToUpdateStructureViews = false;
3185 public void addSequenceGroup(SequenceGroup sequenceGroup)
3187 alignment.addGroup(sequenceGroup);
3189 Color col = sequenceGroup.idColour;
3192 col = col.brighter();
3194 for (SequenceI sq : sequenceGroup.getSequences())
3196 setSequenceColour(sq, col);
3200 if (codingComplement != null)
3202 SequenceGroup mappedGroup = MappingUtils
3203 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3204 if (mappedGroup.getSequences().size() > 0)
3206 codingComplement.getAlignment().addGroup(mappedGroup);
3210 for (SequenceI seq : mappedGroup.getSequences())
3212 codingComplement.setSequenceColour(seq, col);
3216 // propagate the structure view update flag according to our own setting
3217 codingComplement.setUpdateStructures(needToUpdateStructureViews);