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 java.awt.Color;
24 import java.beans.PropertyChangeSupport;
25 import java.util.ArrayDeque;
26 import java.util.ArrayList;
27 import java.util.BitSet;
28 import java.util.Deque;
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.List;
35 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
36 import jalview.analysis.Conservation;
37 import jalview.analysis.TreeModel;
38 import jalview.api.AlignCalcManagerI;
39 import jalview.api.AlignExportSettingsI;
40 import jalview.api.AlignViewportI;
41 import jalview.api.AlignmentViewPanel;
42 import jalview.api.FeaturesDisplayedI;
43 import jalview.api.ViewStyleI;
44 import jalview.bin.Console;
45 import jalview.commands.CommandI;
46 import jalview.datamodel.AlignedCodonFrame;
47 import jalview.datamodel.AlignmentAnnotation;
48 import jalview.datamodel.AlignmentExportData;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.AlignmentView;
51 import jalview.datamodel.Annotation;
52 import jalview.datamodel.ColumnSelection;
53 import jalview.datamodel.ContactListI;
54 import jalview.datamodel.ContactMatrixI;
55 import jalview.datamodel.HiddenColumns;
56 import jalview.datamodel.HiddenSequences;
57 import jalview.datamodel.ProfilesI;
58 import jalview.datamodel.SearchResultsI;
59 import jalview.datamodel.Sequence;
60 import jalview.datamodel.SequenceCollectionI;
61 import jalview.datamodel.SequenceGroup;
62 import jalview.datamodel.SequenceI;
63 import jalview.gui.QuitHandler;
64 import jalview.project.Jalview2XML;
65 import jalview.renderer.ResidueShader;
66 import jalview.renderer.ResidueShaderI;
67 import jalview.schemes.ColourSchemeI;
68 import jalview.structure.CommandListener;
69 import jalview.structure.StructureSelectionManager;
70 import jalview.structure.VamsasSource;
71 import jalview.util.Comparison;
72 import jalview.util.MapList;
73 import jalview.util.MappingUtils;
74 import jalview.util.MessageManager;
75 import jalview.viewmodel.styles.ViewStyle;
76 import jalview.workers.AlignCalcManager;
77 import jalview.workers.ComplementConsensusThread;
78 import jalview.workers.ConsensusThread;
79 import jalview.workers.SecondaryStructureConsensusThread;
80 import jalview.workers.StrucConsensusThread;
83 * base class holding visualization and analysis attributes and common logic for
84 * an active alignment view displayed in the GUI
89 public abstract class AlignmentViewport
90 implements AlignViewportI, CommandListener, VamsasSource
92 protected ViewportRanges ranges;
94 protected ViewStyleI viewStyle = new ViewStyle();
97 * A viewport that hosts the cDna view of this (protein), or vice versa (if
100 AlignViewportI codingComplement = null;
102 FeaturesDisplayedI featuresDisplayed = null;
104 protected Deque<CommandI> historyList = new ArrayDeque<>();
106 protected Deque<CommandI> redoList = new ArrayDeque<>();
109 * used to determine if quit should be confirmed
111 private boolean savedUpToDate = false;
114 * alignment displayed in the viewport. Please use get/setter
116 protected AlignmentI alignment;
118 public AlignmentViewport(AlignmentI al)
121 ranges = new ViewportRanges(al);
126 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
129 public void setFontName(String name)
131 viewStyle.setFontName(name);
136 * @see jalview.api.ViewStyleI#setFontStyle(int)
139 public void setFontStyle(int style)
141 viewStyle.setFontStyle(style);
146 * @see jalview.api.ViewStyleI#setFontSize(int)
149 public void setFontSize(int size)
151 viewStyle.setFontSize(size);
156 * @see jalview.api.ViewStyleI#getFontStyle()
159 public int getFontStyle()
161 return viewStyle.getFontStyle();
166 * @see jalview.api.ViewStyleI#getFontName()
169 public String getFontName()
171 return viewStyle.getFontName();
176 * @see jalview.api.ViewStyleI#getFontSize()
179 public int getFontSize()
181 return viewStyle.getFontSize();
185 * @param upperCasebold
186 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
189 public void setUpperCasebold(boolean upperCasebold)
191 viewStyle.setUpperCasebold(upperCasebold);
196 * @see jalview.api.ViewStyleI#isUpperCasebold()
199 public boolean isUpperCasebold()
201 return viewStyle.isUpperCasebold();
206 * @see jalview.api.ViewStyleI#isSeqNameItalics()
209 public boolean isSeqNameItalics()
211 return viewStyle.isSeqNameItalics();
215 * @param colourByReferenceSeq
216 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
219 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
221 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
226 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
229 public void setColourAppliesToAllGroups(boolean b)
231 viewStyle.setColourAppliesToAllGroups(b);
236 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
239 public boolean getColourAppliesToAllGroups()
241 return viewStyle.getColourAppliesToAllGroups();
246 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
249 public boolean getAbovePIDThreshold()
251 return viewStyle.getAbovePIDThreshold();
256 * @see jalview.api.ViewStyleI#setIncrement(int)
259 public void setIncrement(int inc)
261 viewStyle.setIncrement(inc);
266 * @see jalview.api.ViewStyleI#getIncrement()
269 public int getIncrement()
271 return viewStyle.getIncrement();
276 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
279 public void setConservationSelected(boolean b)
281 viewStyle.setConservationSelected(b);
286 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
289 public void setShowHiddenMarkers(boolean show)
291 viewStyle.setShowHiddenMarkers(show);
296 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
299 public boolean getShowHiddenMarkers()
301 return viewStyle.getShowHiddenMarkers();
306 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
309 public void setScaleRightWrapped(boolean b)
311 viewStyle.setScaleRightWrapped(b);
316 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
319 public void setScaleLeftWrapped(boolean b)
321 viewStyle.setScaleLeftWrapped(b);
326 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
329 public void setScaleAboveWrapped(boolean b)
331 viewStyle.setScaleAboveWrapped(b);
336 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
339 public boolean getScaleLeftWrapped()
341 return viewStyle.getScaleLeftWrapped();
346 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
349 public boolean getScaleAboveWrapped()
351 return viewStyle.getScaleAboveWrapped();
356 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
359 public boolean getScaleRightWrapped()
361 return viewStyle.getScaleRightWrapped();
366 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
369 public void setAbovePIDThreshold(boolean b)
371 viewStyle.setAbovePIDThreshold(b);
376 * @see jalview.api.ViewStyleI#setThreshold(int)
379 public void setThreshold(int thresh)
381 viewStyle.setThreshold(thresh);
386 * @see jalview.api.ViewStyleI#getThreshold()
389 public int getThreshold()
391 return viewStyle.getThreshold();
396 * @see jalview.api.ViewStyleI#getShowJVSuffix()
399 public boolean getShowJVSuffix()
401 return viewStyle.getShowJVSuffix();
406 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
409 public void setShowJVSuffix(boolean b)
411 viewStyle.setShowJVSuffix(b);
416 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
419 public void setWrapAlignment(boolean state)
421 viewStyle.setWrapAlignment(state);
422 ranges.setWrappedMode(state);
427 * @see jalview.api.ViewStyleI#setShowText(boolean)
430 public void setShowText(boolean state)
432 viewStyle.setShowText(state);
437 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
440 public void setRenderGaps(boolean state)
442 viewStyle.setRenderGaps(state);
447 * @see jalview.api.ViewStyleI#getColourText()
450 public boolean getColourText()
452 return viewStyle.getColourText();
457 * @see jalview.api.ViewStyleI#setColourText(boolean)
460 public void setColourText(boolean state)
462 viewStyle.setColourText(state);
467 * @see jalview.api.ViewStyleI#getWrapAlignment()
470 public boolean getWrapAlignment()
472 return viewStyle.getWrapAlignment();
477 * @see jalview.api.ViewStyleI#getShowText()
480 public boolean getShowText()
482 return viewStyle.getShowText();
487 * @see jalview.api.ViewStyleI#getWrappedWidth()
490 public int getWrappedWidth()
492 return viewStyle.getWrappedWidth();
497 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
500 public void setWrappedWidth(int w)
502 viewStyle.setWrappedWidth(w);
507 * @see jalview.api.ViewStyleI#getCharHeight()
510 public int getCharHeight()
512 return viewStyle.getCharHeight();
517 * @see jalview.api.ViewStyleI#setCharHeight(int)
520 public void setCharHeight(int h)
522 viewStyle.setCharHeight(h);
527 * @see jalview.api.ViewStyleI#getCharWidth()
530 public int getCharWidth()
532 return viewStyle.getCharWidth();
537 * @see jalview.api.ViewStyleI#setCharWidth(int)
540 public void setCharWidth(int w)
542 viewStyle.setCharWidth(w);
547 * @see jalview.api.ViewStyleI#getShowBoxes()
550 public boolean getShowBoxes()
552 return viewStyle.getShowBoxes();
557 * @see jalview.api.ViewStyleI#getShowUnconserved()
560 public boolean getShowUnconserved()
562 return viewStyle.getShowUnconserved();
566 * @param showunconserved
567 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
570 public void setShowUnconserved(boolean showunconserved)
572 viewStyle.setShowUnconserved(showunconserved);
577 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
580 public void setSeqNameItalics(boolean default1)
582 viewStyle.setSeqNameItalics(default1);
586 public AlignmentI getAlignment()
592 public char getGapCharacter()
594 return alignment.getGapCharacter();
597 protected String sequenceSetID;
600 * probably unused indicator that view is of a dataset rather than an
603 protected boolean isDataset = false;
605 public void setDataset(boolean b)
610 public boolean isDataset()
615 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
617 protected ColumnSelection colSel = new ColumnSelection();
619 public boolean autoCalculateConsensus = true;
621 protected boolean autoCalculateStrucConsensus = true;
623 protected boolean ignoreGapsInConsensusCalculation = false;
625 protected ResidueShaderI residueShading = new ResidueShader();
628 public void setGlobalColourScheme(ColourSchemeI cs)
630 // TODO: logic refactored from AlignFrame changeColour -
631 // TODO: autorecalc stuff should be changed to rely on the worker system
632 // check to see if we should implement a changeColour(cs) method rather than
633 // put the logic in here
634 // - means that caller decides if they want to just modify state and defer
635 // calculation till later or to do all calculations in thread.
639 * only instantiate alignment colouring once, thereafter update it;
640 * this means that any conservation or PID threshold settings
641 * persist when the alignment colour scheme is changed
643 if (residueShading == null)
645 residueShading = new ResidueShader(viewStyle);
647 residueShading.setColourScheme(cs);
649 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
650 // ...problem: groups need these, but do not currently have a ViewStyle
654 if (getConservationSelected())
656 residueShading.setConservation(hconservation);
659 * reset conservation flag in case just set to false if
660 * Conservation was null (calculation still in progress)
662 residueShading.setConservationApplied(getConservationSelected());
663 residueShading.alignmentChanged(alignment, hiddenRepSequences);
667 * if 'apply colour to all groups' is selected... do so
668 * (but don't transfer any colour threshold settings to groups)
670 if (getColourAppliesToAllGroups())
672 for (SequenceGroup sg : getAlignment().getGroups())
675 * retain any colour thresholds per group while
676 * changing choice of colour scheme (JAL-2386)
678 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
681 sg.getGroupColourScheme().alignmentChanged(sg,
689 public ColourSchemeI getGlobalColourScheme()
691 return residueShading == null ? null : residueShading.getColourScheme();
695 public ResidueShaderI getResidueShading()
697 return residueShading;
700 protected AlignmentAnnotation consensus;
702 protected AlignmentAnnotation secondaryStructureConsensus;
704 protected AlignmentAnnotation complementConsensus;
706 protected AlignmentAnnotation gapcounts;
708 protected AlignmentAnnotation strucConsensus;
710 protected AlignmentAnnotation conservation;
712 protected AlignmentAnnotation quality;
714 protected AlignmentAnnotation[] groupConsensus;
716 protected AlignmentAnnotation[] groupSSConsensus;
718 protected AlignmentAnnotation[] groupConservation;
721 * results of alignment consensus analysis for visible portion of view
723 protected ProfilesI hconsensus = null;
725 protected ProfilesI hSSConsensus = null;
730 * results of cDNA complement consensus visible portion of view
732 protected Hashtable<String, Object>[] hcomplementConsensus = null;
735 * results of secondary structure base pair consensus for visible portion of
738 protected Hashtable<String, Object>[] hStrucConsensus = null;
740 protected Conservation hconservation = null;
743 public void setConservation(Conservation cons)
745 hconservation = cons;
749 * percentage gaps allowed in a column before all amino acid properties should
750 * be considered unconserved
752 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
755 public int getConsPercGaps()
761 public void setSequenceConsensusHash(ProfilesI hconsensus)
763 this.hconsensus = hconsensus;
767 public void setSequenceSSConsensusHash(ProfilesI hSSConsensus)
769 this.hSSConsensus = hSSConsensus;
773 public void setComplementConsensusHash(
774 Hashtable<String, Object>[] hconsensus)
776 this.hcomplementConsensus = hconsensus;
780 public ProfilesI getSequenceConsensusHash()
786 public ProfilesI getSequenceSSConsensusHash()
792 public Hashtable<String, Object>[] getComplementConsensusHash()
794 return hcomplementConsensus;
798 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
800 return hStrucConsensus;
804 public void setRnaStructureConsensusHash(
805 Hashtable<String, Object>[] hStrucConsensus)
807 this.hStrucConsensus = hStrucConsensus;
812 public AlignmentAnnotation getAlignmentQualityAnnot()
818 public AlignmentAnnotation getAlignmentConservationAnnotation()
824 public AlignmentAnnotation getAlignmentConsensusAnnotation()
831 public AlignmentAnnotation getAlignmentSecondaryStructureConsensusAnnotation()
833 return secondaryStructureConsensus;
838 public AlignmentAnnotation getAlignmentGapAnnotation()
844 public AlignmentAnnotation getComplementConsensusAnnotation()
846 return complementConsensus;
850 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
852 return strucConsensus;
855 protected AlignCalcManagerI calculator = new AlignCalcManager();
858 * trigger update of conservation annotation
860 public void updateConservation(final AlignmentViewPanel ap)
862 // see note in mantis : issue number 8585
863 if (alignment.isNucleotide()
864 || (conservation == null && quality == null)
865 || !autoCalculateConsensus)
869 if (calculator.getRegisteredWorkersOfClass(
870 jalview.workers.ConservationThread.class) == null)
872 calculator.registerWorker(
873 new jalview.workers.ConservationThread(this, ap));
878 * trigger update of consensus annotation
880 public void updateConsensus(final AlignmentViewPanel ap)
882 // see note in mantis : issue number 8585
883 if (consensus == null || !autoCalculateConsensus)
888 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
890 calculator.registerWorker(new ConsensusThread(this, ap));
894 * A separate thread to compute cDNA consensus for a protein alignment
895 * which has mapping to cDNA
897 final AlignmentI al = this.getAlignment();
898 if (!al.isNucleotide() && al.getCodonFrames() != null
899 && !al.getCodonFrames().isEmpty())
902 * fudge - check first for protein-to-nucleotide mappings
903 * (we don't want to do this for protein-to-protein)
905 boolean doConsensus = false;
906 for (AlignedCodonFrame mapping : al.getCodonFrames())
908 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
909 MapList[] mapLists = mapping.getdnaToProt();
910 // mapLists can be empty if project load has not finished resolving seqs
911 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
919 if (calculator.getRegisteredWorkersOfClass(
920 ComplementConsensusThread.class) == null)
923 .registerWorker(new ComplementConsensusThread(this, ap));
933 * trigger update of consensus annotation
935 public void updateSecondaryStructureConsensus(final AlignmentViewPanel ap)
937 // see note in mantis : issue number 8585
938 if (secondaryStructureConsensus == null || !autoCalculateConsensus)
943 .getRegisteredWorkersOfClass(SecondaryStructureConsensusThread.class) == null)
945 calculator.registerWorker(new SecondaryStructureConsensusThread(this, ap));
949 // --------START Structure Conservation
950 public void updateStrucConsensus(final AlignmentViewPanel ap)
952 if (autoCalculateStrucConsensus && strucConsensus == null
953 && alignment.isNucleotide() && alignment.hasRNAStructure())
955 // secondary structure has been added - so init the consensus line
959 // see note in mantis : issue number 8585
960 if (strucConsensus == null || !autoCalculateStrucConsensus)
964 if (calculator.getRegisteredWorkersOfClass(
965 StrucConsensusThread.class) == null)
967 calculator.registerWorker(new StrucConsensusThread(this, ap));
971 public boolean isCalcInProgress()
973 return calculator.isWorking();
977 public boolean isCalculationInProgress(
978 AlignmentAnnotation alignmentAnnotation)
980 if (!alignmentAnnotation.autoCalculated)
984 if (calculator.workingInvolvedWith(alignmentAnnotation))
986 // jalview.bin.Console.errPrintln("grey out
987 // ("+alignmentAnnotation.label+")");
993 public void setAlignment(AlignmentI align)
995 this.alignment = align;
999 * Clean up references when this viewport is closed
1002 public void dispose()
1005 * defensively null out references to large objects in case
1006 * this object is not garbage collected (as if!)
1009 complementConsensus = null;
1010 strucConsensus = null;
1011 secondaryStructureConsensus = null;
1012 conservation = null;
1014 groupConsensus = null;
1015 groupConservation = null;
1017 hconservation = null;
1018 hcomplementConsensus = null;
1021 residueShading = null; // may hold a reference to Consensus
1022 changeSupport = null;
1025 selectionGroup = null;
1031 public boolean isClosed()
1033 // TODO: check that this isClosed is only true after panel is closed, not
1034 // before it is fully constructed.
1035 return alignment == null;
1039 public AlignCalcManagerI getCalcManager()
1045 * should conservation rows be shown for groups
1047 protected boolean showGroupConservation = false;
1050 * should consensus rows be shown for groups
1052 protected boolean showGroupConsensus = false;
1055 * should consensus profile be rendered by default
1057 protected boolean showSequenceLogo = false;
1059 protected boolean showSequenceSSLogo = false;
1062 * should consensus profile be rendered normalised to row height
1064 protected boolean normaliseSequenceLogo = false;
1067 * should consensus histograms be rendered by default
1069 protected boolean showConsensusHistogram = true;
1071 protected boolean showSSConsensusHistogram = true;
1073 public void setShowSSConsensusHistogram(boolean showSSConsensusHistogram)
1075 this.showSSConsensusHistogram = showSSConsensusHistogram;
1079 * @return the showConsensusProfile
1082 public boolean isShowSequenceLogo()
1084 return showSequenceLogo;
1088 public boolean isShowSequenceSSLogo()
1090 return showSequenceSSLogo;
1094 * @param showSequenceLogo
1097 public void setShowSequenceLogo(boolean showSequenceLogo)
1099 if (showSequenceLogo != this.showSequenceLogo)
1101 // TODO: decouple settings setting from calculation when refactoring
1102 // annotation update method from alignframe to viewport
1103 this.showSequenceLogo = showSequenceLogo;
1104 calculator.updateAnnotationFor(ConsensusThread.class);
1105 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1106 calculator.updateAnnotationFor(StrucConsensusThread.class);
1108 this.showSequenceLogo = showSequenceLogo;
1111 public void setShowSequenceSSLogo(boolean showSequenceSSLogo)
1113 if (showSequenceSSLogo != this.showSequenceSSLogo)
1115 // TODO: decouple settings setting from calculation when refactoring
1116 // annotation update method from alignframe to viewport
1117 this.showSequenceSSLogo = showSequenceSSLogo;
1118 calculator.updateAnnotationFor(SecondaryStructureConsensusThread.class);
1120 this.showSequenceSSLogo = showSequenceSSLogo;
1124 * @param showConsensusHistogram
1125 * the showConsensusHistogram to set
1127 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1129 this.showConsensusHistogram = showConsensusHistogram;
1133 * @return the showGroupConservation
1135 public boolean isShowGroupConservation()
1137 return showGroupConservation;
1141 * @param showGroupConservation
1142 * the showGroupConservation to set
1144 public void setShowGroupConservation(boolean showGroupConservation)
1146 this.showGroupConservation = showGroupConservation;
1150 * @return the showGroupConsensus
1152 public boolean isShowGroupConsensus()
1154 return showGroupConsensus;
1158 * @param showGroupConsensus
1159 * the showGroupConsensus to set
1161 public void setShowGroupConsensus(boolean showGroupConsensus)
1163 this.showGroupConsensus = showGroupConsensus;
1168 * @return flag to indicate if the consensus histogram should be rendered by
1172 public boolean isShowConsensusHistogram()
1174 return this.showConsensusHistogram;
1178 public boolean isShowSSConsensusHistogram()
1180 return this.showSSConsensusHistogram;
1184 * when set, updateAlignment will always ensure sequences are of equal length
1186 private boolean padGaps = false;
1189 * when set, alignment should be reordered according to a newly opened tree
1191 public boolean sortByTree = false;
1196 * @return null or the currently selected sequence region
1199 public SequenceGroup getSelectionGroup()
1201 return selectionGroup;
1205 * Set the selection group for this window. Also sets the current alignment as
1206 * the context for the group, if it does not already have one.
1209 * - group holding references to sequences in this alignment view
1213 public void setSelectionGroup(SequenceGroup sg)
1215 selectionGroup = sg;
1216 if (sg != null && sg.getContext() == null)
1218 sg.setContext(alignment);
1222 public void setHiddenColumns(HiddenColumns hidden)
1224 this.alignment.setHiddenColumns(hidden);
1228 public ColumnSelection getColumnSelection()
1234 public void setColumnSelection(ColumnSelection colSel)
1236 this.colSel = colSel;
1239 updateHiddenColumns();
1241 isColSelChanged(true);
1249 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1251 return hiddenRepSequences;
1255 public void setHiddenRepSequences(
1256 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1258 this.hiddenRepSequences = hiddenRepSequences;
1262 public boolean hasSelectedColumns()
1264 ColumnSelection columnSelection = getColumnSelection();
1265 return columnSelection != null && columnSelection.hasSelectedColumns();
1269 public boolean hasHiddenColumns()
1271 return alignment.getHiddenColumns() != null
1272 && alignment.getHiddenColumns().hasHiddenColumns();
1275 public void updateHiddenColumns()
1277 // this method doesn't really do anything now. But - it could, since a
1278 // column Selection could be in the process of modification
1279 // hasHiddenColumns = colSel.hasHiddenColumns();
1283 public boolean hasHiddenRows()
1285 return alignment.getHiddenSequences().getSize() > 0;
1288 protected SequenceGroup selectionGroup;
1290 public void setSequenceSetId(String newid)
1292 if (sequenceSetID != null)
1294 jalview.bin.Console.errPrintln(
1295 "Warning - overwriting a sequenceSetId for a viewport!");
1297 sequenceSetID = new String(newid);
1301 public String getSequenceSetId()
1303 if (sequenceSetID == null)
1305 sequenceSetID = alignment.hashCode() + "";
1308 return sequenceSetID;
1312 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1315 protected String viewId = null;
1318 public String getViewId()
1322 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1327 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1329 ignoreGapsInConsensusCalculation = b;
1332 updateConsensus(ap);
1333 updateSecondaryStructureConsensus(ap);
1334 if (residueShading != null)
1336 residueShading.setThreshold(residueShading.getThreshold(),
1337 ignoreGapsInConsensusCalculation);
1343 private long sgrouphash = -1, colselhash = -1;
1346 * checks current SelectionGroup against record of last hash value, and
1350 * update the record of last hash value
1352 * @return true if SelectionGroup changed since last call (when b is true)
1354 public boolean isSelectionGroupChanged(boolean b)
1356 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1357 : selectionGroup.hashCode();
1358 if (hc != -1 && hc != sgrouphash)
1370 * checks current colsel against record of last hash value, and optionally
1374 * update the record of last hash value
1375 * @return true if colsel changed since last call (when b is true)
1377 public boolean isColSelChanged(boolean b)
1379 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1380 if (hc != -1 && hc != colselhash)
1392 public boolean isIgnoreGapsConsensus()
1394 return ignoreGapsInConsensusCalculation;
1397 // property change stuff
1398 // JBPNote Prolly only need this in the applet version.
1399 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1402 protected boolean showConservation = true;
1404 protected boolean showQuality = true;
1406 protected boolean showConsensus = true;
1408 protected boolean showSSConsensus = false;
1410 protected boolean showOccupancy = true;
1412 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1414 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1416 protected boolean showAutocalculatedAbove;
1419 * when set, view will scroll to show the highlighted position
1421 private boolean followHighlight = true;
1424 * Property change listener for changes in alignment
1429 public void addPropertyChangeListener(
1430 java.beans.PropertyChangeListener listener)
1432 changeSupport.addPropertyChangeListener(listener);
1441 public void removePropertyChangeListener(
1442 java.beans.PropertyChangeListener listener)
1444 if (changeSupport != null)
1446 changeSupport.removePropertyChangeListener(listener);
1451 * Property change listener for changes in alignment
1460 public void firePropertyChange(String prop, Object oldvalue,
1463 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1467 public void notifyAlignmentChanged()
1469 firePropertyChange("alignment", null, alignment);
1472 // common hide/show column stuff
1474 public void hideSelectedColumns()
1476 if (colSel.isEmpty())
1481 colSel.hideSelectedColumns(alignment);
1482 setSelectionGroup(null);
1483 isColSelChanged(true);
1486 public void hideColumns(int start, int end)
1490 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1494 alignment.getHiddenColumns().hideColumns(start, end);
1496 isColSelChanged(true);
1499 public void showColumn(int col)
1501 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1502 isColSelChanged(true);
1505 public void showAllHiddenColumns()
1507 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1508 isColSelChanged(true);
1511 // common hide/show seq stuff
1512 public void showAllHiddenSeqs()
1514 int startSeq = ranges.getStartSeq();
1515 int endSeq = ranges.getEndSeq();
1517 if (alignment.getHiddenSequences().getSize() > 0)
1519 if (selectionGroup == null)
1521 selectionGroup = new SequenceGroup();
1522 selectionGroup.setEndRes(alignment.getWidth() - 1);
1524 List<SequenceI> tmp = alignment.getHiddenSequences()
1525 .showAll(hiddenRepSequences);
1526 for (SequenceI seq : tmp)
1528 selectionGroup.addSequence(seq, false);
1529 setSequenceAnnotationsVisible(seq, true);
1532 hiddenRepSequences = null;
1534 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1536 firePropertyChange("alignment", null, alignment.getSequences());
1537 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1543 public void showSequence(int index)
1545 int startSeq = ranges.getStartSeq();
1546 int endSeq = ranges.getEndSeq();
1548 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1549 hiddenRepSequences);
1552 if (selectionGroup == null)
1554 selectionGroup = new SequenceGroup();
1555 selectionGroup.setEndRes(alignment.getWidth() - 1);
1558 for (SequenceI seq : tmp)
1560 selectionGroup.addSequence(seq, false);
1561 setSequenceAnnotationsVisible(seq, true);
1564 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1566 firePropertyChange("alignment", null, alignment.getSequences());
1571 public void hideAllSelectedSeqs()
1573 if (selectionGroup == null || selectionGroup.getSize() < 1)
1578 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1582 setSelectionGroup(null);
1585 public void hideSequence(SequenceI[] seq)
1588 * cache offset to first visible sequence
1590 int startSeq = ranges.getStartSeq();
1594 for (int i = 0; i < seq.length; i++)
1596 alignment.getHiddenSequences().hideSequence(seq[i]);
1597 setSequenceAnnotationsVisible(seq[i], false);
1599 ranges.setStartSeq(startSeq);
1600 firePropertyChange("alignment", null, alignment.getSequences());
1605 * Hides the specified sequence, or the sequences it represents
1608 * the sequence to hide, or keep as representative
1609 * @param representGroup
1610 * if true, hide the current selection group except for the
1611 * representative sequence
1613 public void hideSequences(SequenceI sequence, boolean representGroup)
1615 if (selectionGroup == null || selectionGroup.getSize() < 1)
1617 hideSequence(new SequenceI[] { sequence });
1623 hideRepSequences(sequence, selectionGroup);
1624 setSelectionGroup(null);
1628 int gsize = selectionGroup.getSize();
1629 SequenceI[] hseqs = selectionGroup.getSequences()
1630 .toArray(new SequenceI[gsize]);
1632 hideSequence(hseqs);
1633 setSelectionGroup(null);
1638 * Set visibility for any annotations for the given sequence.
1642 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1645 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1648 for (AlignmentAnnotation ann : anns)
1650 if (ann.sequenceRef == sequenceI)
1652 ann.visible = visible;
1658 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1660 int sSize = sg.getSize();
1666 if (hiddenRepSequences == null)
1668 hiddenRepSequences = new Hashtable<>();
1671 hiddenRepSequences.put(repSequence, sg);
1673 // Hide all sequences except the repSequence
1674 SequenceI[] seqs = new SequenceI[sSize - 1];
1676 for (int i = 0; i < sSize; i++)
1678 if (sg.getSequenceAt(i) != repSequence)
1680 if (index == sSize - 1)
1685 seqs[index++] = sg.getSequenceAt(i);
1688 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1689 sg.setHidereps(true); // note: not done in 2.7applet
1696 * @return null or the current reference sequence
1698 public SequenceI getReferenceSeq()
1700 return alignment.getSeqrep();
1705 * @return true iff seq is the reference for the alignment
1707 public boolean isReferenceSeq(SequenceI seq)
1709 return alignment.getSeqrep() == seq;
1715 * @return true if there are sequences represented by this sequence that are
1718 public boolean isHiddenRepSequence(SequenceI seq)
1720 return (hiddenRepSequences != null
1721 && hiddenRepSequences.containsKey(seq));
1727 * @return null or a sequence group containing the sequences that seq
1730 public SequenceGroup getRepresentedSequences(SequenceI seq)
1732 return (SequenceGroup) (hiddenRepSequences == null ? null
1733 : hiddenRepSequences.get(seq));
1737 public int adjustForHiddenSeqs(int alignmentIndex)
1739 return alignment.getHiddenSequences()
1740 .adjustForHiddenSeqs(alignmentIndex);
1744 public void invertColumnSelection()
1746 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1747 isColSelChanged(true);
1751 public SequenceI[] getSelectionAsNewSequence()
1753 SequenceI[] sequences;
1754 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1755 // this was the only caller in the applet for this method
1756 // JBPNote: in applet, this method returned references to the alignment
1757 // sequences, and it did not honour the presence/absence of annotation
1758 // attached to the alignment (probably!)
1759 if (selectionGroup == null || selectionGroup.getSize() == 0)
1761 sequences = alignment.getSequencesArray();
1762 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1763 for (int i = 0; i < sequences.length; i++)
1765 // construct new sequence with subset of visible annotation
1766 sequences[i] = new Sequence(sequences[i], annots);
1771 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1778 public SequenceI[] getSequenceSelection()
1780 SequenceI[] sequences = null;
1781 if (selectionGroup != null)
1783 sequences = selectionGroup.getSequencesInOrder(alignment);
1785 if (sequences == null)
1787 sequences = alignment.getSequencesArray();
1793 public jalview.datamodel.AlignmentView getAlignmentView(
1794 boolean selectedOnly)
1796 return getAlignmentView(selectedOnly, false);
1800 public jalview.datamodel.AlignmentView getAlignmentView(
1801 boolean selectedOnly, boolean markGroups)
1803 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1805 alignment.getHiddenColumns() != null
1806 && alignment.getHiddenColumns().hasHiddenColumns(),
1807 selectedOnly, markGroups);
1811 public String[] getViewAsString(boolean selectedRegionOnly)
1813 return getViewAsString(selectedRegionOnly, true);
1817 public String[] getViewAsString(boolean selectedRegionOnly,
1818 boolean exportHiddenSeqs)
1820 String[] selection = null;
1821 SequenceI[] seqs = null;
1823 int start = 0, end = 0;
1824 if (selectedRegionOnly && selectionGroup != null)
1826 iSize = selectionGroup.getSize();
1827 seqs = selectionGroup.getSequencesInOrder(alignment);
1828 start = selectionGroup.getStartRes();
1829 end = selectionGroup.getEndRes() + 1;
1833 if (hasHiddenRows() && exportHiddenSeqs)
1835 AlignmentI fullAlignment = alignment.getHiddenSequences()
1836 .getFullAlignment();
1837 iSize = fullAlignment.getHeight();
1838 seqs = fullAlignment.getSequencesArray();
1839 end = fullAlignment.getWidth();
1843 iSize = alignment.getHeight();
1844 seqs = alignment.getSequencesArray();
1845 end = alignment.getWidth();
1849 selection = new String[iSize];
1850 if (alignment.getHiddenColumns() != null
1851 && alignment.getHiddenColumns().hasHiddenColumns())
1853 for (i = 0; i < iSize; i++)
1855 Iterator<int[]> blocks = alignment.getHiddenColumns()
1856 .getVisContigsIterator(start, end + 1, false);
1857 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1862 for (i = 0; i < iSize; i++)
1864 selection[i] = seqs[i].getSequenceAsString(start, end);
1872 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1874 ArrayList<int[]> regions = new ArrayList<>();
1880 HiddenColumns hidden = alignment.getHiddenColumns();
1881 if (hidden != null && hidden.hasHiddenColumns())
1885 start = hidden.visibleToAbsoluteColumn(start);
1888 end = hidden.getNextHiddenBoundary(false, start);
1899 regions.add(new int[] { start, end });
1901 if (hidden != null && hidden.hasHiddenColumns())
1903 start = hidden.visibleToAbsoluteColumn(end);
1904 start = hidden.getNextHiddenBoundary(true, start) + 1;
1906 } while (end < max);
1908 // int[][] startEnd = new int[regions.size()][2];
1914 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1915 boolean selectedOnly)
1917 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1918 AlignmentAnnotation[] aa;
1919 if ((aa = alignment.getAlignmentAnnotation()) != null)
1921 for (AlignmentAnnotation annot : aa)
1923 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1924 if (selectedOnly && selectionGroup != null)
1926 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1927 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1931 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1940 public boolean isPadGaps()
1946 public void setPadGaps(boolean padGaps)
1948 this.padGaps = padGaps;
1952 * apply any post-edit constraints and trigger any calculations needed after
1953 * an edit has been performed on the alignment
1958 public void alignmentChanged(AlignmentViewPanel ap)
1962 alignment.padGaps();
1964 if (autoCalculateConsensus)
1966 updateConsensus(ap);
1967 updateSecondaryStructureConsensus(ap);
1969 if (hconsensus != null && autoCalculateConsensus)
1971 updateConservation(ap);
1973 if (autoCalculateStrucConsensus)
1975 updateStrucConsensus(ap);
1978 // Reset endRes of groups if beyond alignment width
1979 int alWidth = alignment.getWidth();
1980 List<SequenceGroup> groups = alignment.getGroups();
1983 for (SequenceGroup sg : groups)
1985 if (sg.getEndRes() > alWidth)
1987 sg.setEndRes(alWidth - 1);
1992 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1994 selectionGroup.setEndRes(alWidth - 1);
1997 updateAllColourSchemes();
1998 calculator.restartWorkers();
1999 // alignment.adjustSequenceAnnotations();
2003 * reset scope and do calculations for all applied colourschemes on alignment
2005 void updateAllColourSchemes()
2007 ResidueShaderI rs = residueShading;
2010 rs.alignmentChanged(alignment, hiddenRepSequences);
2012 rs.setConsensus(hconsensus);
2013 if (rs.conservationApplied())
2015 rs.setConservation(Conservation.calculateConservation("All",
2016 alignment.getSequences(), 0, alignment.getWidth(), false,
2017 getConsPercGaps(), false));
2021 for (SequenceGroup sg : alignment.getGroups())
2025 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2027 sg.recalcConservation();
2031 protected void initAutoAnnotation()
2033 // TODO: add menu option action that nulls or creates consensus object
2034 // depending on if the user wants to see the annotation or not in a
2035 // specific alignment
2037 if (hconsensus == null && !isDataset)
2039 if (!alignment.isNucleotide())
2048 consensus = new AlignmentAnnotation("Consensus",
2049 MessageManager.getString("label.consensus_descr"),
2050 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2052 secondaryStructureConsensus = new AlignmentAnnotation(MessageManager.getString("label.ssconsensus_label"),
2053 MessageManager.getString("label.ssconsensus_descr"),
2054 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2056 initConsensus(consensus);
2057 initSSConsensus(secondaryStructureConsensus);
2059 initComplementConsensus();
2065 * If this is a protein alignment and there are mappings to cDNA, adds the
2066 * cDNA consensus annotation and returns true, else returns false.
2068 public boolean initComplementConsensus()
2070 if (!alignment.isNucleotide())
2072 final List<AlignedCodonFrame> codonMappings = alignment
2074 if (codonMappings != null && !codonMappings.isEmpty())
2076 boolean doConsensus = false;
2077 for (AlignedCodonFrame mapping : codonMappings)
2079 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2080 MapList[] mapLists = mapping.getdnaToProt();
2081 // mapLists can be empty if project load has not finished resolving
2083 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2091 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2093 .getString("label.complement_consensus_descr"),
2094 new Annotation[1], 0f, 100f,
2095 AlignmentAnnotation.BAR_GRAPH);
2096 initConsensus(complementConsensus);
2104 private void initConsensus(AlignmentAnnotation aa)
2107 aa.autoCalculated = true;
2111 alignment.addAnnotation(aa);
2115 private void initSSConsensus(AlignmentAnnotation aa)
2118 aa.autoCalculated = true;
2120 if (showSSConsensus)
2122 alignment.addAnnotation(aa);
2126 // these should be extracted from the view model - style and settings for
2127 // derived annotation
2128 private void initGapCounts()
2132 gapcounts = new AlignmentAnnotation("Occupancy",
2133 MessageManager.getString("label.occupancy_descr"),
2134 new Annotation[1], 0f, alignment.getHeight(),
2135 AlignmentAnnotation.BAR_GRAPH);
2136 gapcounts.hasText = true;
2137 gapcounts.autoCalculated = true;
2138 gapcounts.scaleColLabel = true;
2139 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2141 alignment.addAnnotation(gapcounts);
2145 private void initConservation()
2147 if (showConservation)
2149 if (conservation == null)
2151 conservation = new AlignmentAnnotation("Conservation",
2152 MessageManager.formatMessage("label.conservation_descr",
2154 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2155 conservation.hasText = true;
2156 conservation.autoCalculated = true;
2157 alignment.addAnnotation(conservation);
2162 private void initQuality()
2166 if (quality == null)
2168 quality = new AlignmentAnnotation("Quality",
2169 MessageManager.getString("label.quality_descr"),
2170 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2171 quality.hasText = true;
2172 quality.autoCalculated = true;
2173 alignment.addAnnotation(quality);
2178 private void initRNAStructure()
2180 if (alignment.hasRNAStructure() && strucConsensus == null)
2182 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2183 MessageManager.getString("label.strucconsensus_descr"),
2184 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2185 strucConsensus.hasText = true;
2186 strucConsensus.autoCalculated = true;
2190 alignment.addAnnotation(strucConsensus);
2198 * @see jalview.api.AlignViewportI#calcPanelHeight()
2201 public int calcPanelHeight()
2203 // setHeight of panels
2204 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2206 int charHeight = getCharHeight();
2209 BitSet graphgrp = new BitSet();
2210 for (AlignmentAnnotation aa : anns)
2214 jalview.bin.Console.errPrintln("Null annotation row: ignoring.");
2221 if (aa.graphGroup > -1)
2223 if (graphgrp.get(aa.graphGroup))
2229 graphgrp.set(aa.graphGroup);
2236 aa.height += charHeight;
2246 aa.height += aa.graphHeight + 20;
2254 height += aa.height;
2266 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2267 boolean preserveNewGroupSettings)
2269 boolean updateCalcs = false;
2270 boolean conv = isShowGroupConservation();
2271 boolean cons = isShowGroupConsensus();
2272 boolean showprf = isShowSequenceLogo();
2273 boolean showSSprf = isShowSequenceSSLogo();
2274 boolean showConsHist = isShowConsensusHistogram();
2275 boolean showSSConsHist = isShowSSConsensusHistogram();
2276 boolean normLogo = isNormaliseSequenceLogo();
2279 * TODO reorder the annotation rows according to group/sequence ordering on
2282 // boolean sortg = true;
2284 // remove old automatic annotation
2285 // add any new annotation
2287 // intersect alignment annotation with alignment groups
2289 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2290 List<SequenceGroup> oldrfs = new ArrayList<>();
2293 for (int an = 0; an < aan.length; an++)
2295 if (aan[an].autoCalculated && aan[an].groupRef != null)
2297 oldrfs.add(aan[an].groupRef);
2298 alignment.deleteAnnotation(aan[an], false);
2302 if (alignment.getGroups() != null)
2304 for (SequenceGroup sg : alignment.getGroups())
2306 updateCalcs = false;
2307 if (applyGlobalSettings
2308 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2310 // set defaults for this group's conservation/consensus
2311 sg.setshowSequenceLogo(showprf);
2312 sg.setshowSequenceSSLogo(showSSprf);
2313 sg.setShowConsensusHistogram(showConsHist);
2314 sg.setShowSSConsensusHistogram(showSSConsHist);
2315 sg.setNormaliseSequenceLogo(normLogo);
2320 alignment.addAnnotation(sg.getConservationRow(), 0);
2325 alignment.addAnnotation(sg.getConsensus(), 0);
2326 alignment.addAnnotation(sg.getSSConsensus(), 0);
2328 // refresh the annotation rows
2331 sg.recalcConservation();
2339 public boolean isDisplayReferenceSeq()
2341 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2345 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2347 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2351 public boolean isColourByReferenceSeq()
2353 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2357 public Color getSequenceColour(SequenceI seq)
2359 Color sqc = sequenceColours.get(seq);
2360 return (sqc == null ? Color.white : sqc);
2364 public void setSequenceColour(SequenceI seq, Color col)
2368 sequenceColours.remove(seq);
2372 sequenceColours.put(seq, col);
2377 public void updateSequenceIdColours()
2379 for (SequenceGroup sg : alignment.getGroups())
2381 if (sg.idColour != null)
2383 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2385 sequenceColours.put(s, sg.idColour);
2392 public void clearSequenceColours()
2394 sequenceColours.clear();
2398 public AlignViewportI getCodingComplement()
2400 return this.codingComplement;
2404 * Set this as the (cDna/protein) complement of the given viewport. Also
2405 * ensures the reverse relationship is set on the given viewport.
2408 public void setCodingComplement(AlignViewportI av)
2413 .errPrintln("Ignoring recursive setCodingComplement request");
2417 this.codingComplement = av;
2418 // avoid infinite recursion!
2419 if (av.getCodingComplement() != this)
2421 av.setCodingComplement(this);
2427 public boolean isNucleotide()
2429 return getAlignment() == null ? false : getAlignment().isNucleotide();
2433 public FeaturesDisplayedI getFeaturesDisplayed()
2435 return featuresDisplayed;
2439 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2441 featuresDisplayed = featuresDisplayedI;
2445 public boolean areFeaturesDisplayed()
2447 return featuresDisplayed != null
2448 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2455 * features are displayed if true
2458 public void setShowSequenceFeatures(boolean b)
2460 viewStyle.setShowSequenceFeatures(b);
2464 public boolean isShowSequenceFeatures()
2466 return viewStyle.isShowSequenceFeatures();
2470 public void setShowSequenceFeaturesHeight(boolean selected)
2472 viewStyle.setShowSequenceFeaturesHeight(selected);
2476 public boolean isShowSequenceFeaturesHeight()
2478 return viewStyle.isShowSequenceFeaturesHeight();
2482 public void setShowAnnotation(boolean b)
2484 viewStyle.setShowAnnotation(b);
2488 public boolean isShowAnnotation()
2490 return viewStyle.isShowAnnotation();
2494 public boolean isRightAlignIds()
2496 return viewStyle.isRightAlignIds();
2500 public void setRightAlignIds(boolean rightAlignIds)
2502 viewStyle.setRightAlignIds(rightAlignIds);
2506 public boolean getConservationSelected()
2508 return viewStyle.getConservationSelected();
2512 public void setShowBoxes(boolean state)
2514 viewStyle.setShowBoxes(state);
2519 * @see jalview.api.ViewStyleI#getTextColour()
2522 public Color getTextColour()
2524 return viewStyle.getTextColour();
2529 * @see jalview.api.ViewStyleI#getTextColour2()
2532 public Color getTextColour2()
2534 return viewStyle.getTextColour2();
2539 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2542 public int getThresholdTextColour()
2544 return viewStyle.getThresholdTextColour();
2549 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2552 public boolean isConservationColourSelected()
2554 return viewStyle.isConservationColourSelected();
2559 * @see jalview.api.ViewStyleI#isRenderGaps()
2562 public boolean isRenderGaps()
2564 return viewStyle.isRenderGaps();
2569 * @see jalview.api.ViewStyleI#isShowColourText()
2572 public boolean isShowColourText()
2574 return viewStyle.isShowColourText();
2578 * @param conservationColourSelected
2579 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2582 public void setConservationColourSelected(
2583 boolean conservationColourSelected)
2585 viewStyle.setConservationColourSelected(conservationColourSelected);
2589 * @param showColourText
2590 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2593 public void setShowColourText(boolean showColourText)
2595 viewStyle.setShowColourText(showColourText);
2600 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2603 public void setTextColour(Color textColour)
2605 viewStyle.setTextColour(textColour);
2609 * @param thresholdTextColour
2610 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2613 public void setThresholdTextColour(int thresholdTextColour)
2615 viewStyle.setThresholdTextColour(thresholdTextColour);
2619 * @param textColour2
2620 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2623 public void setTextColour2(Color textColour2)
2625 viewStyle.setTextColour2(textColour2);
2629 public ViewStyleI getViewStyle()
2631 return new ViewStyle(viewStyle);
2635 public void setViewStyle(ViewStyleI settingsForView)
2637 viewStyle = new ViewStyle(settingsForView);
2638 if (residueShading != null)
2640 residueShading.setConservationApplied(
2641 settingsForView.isConservationColourSelected());
2646 public boolean sameStyle(ViewStyleI them)
2648 return viewStyle.sameStyle(them);
2653 * @see jalview.api.ViewStyleI#getIdWidth()
2656 public int getIdWidth()
2658 return viewStyle.getIdWidth();
2663 * @see jalview.api.ViewStyleI#setIdWidth(int)
2666 public void setIdWidth(int i)
2668 viewStyle.setIdWidth(i);
2673 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2676 public boolean isCentreColumnLabels()
2678 return viewStyle.isCentreColumnLabels();
2682 * @param centreColumnLabels
2683 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2686 public void setCentreColumnLabels(boolean centreColumnLabels)
2688 viewStyle.setCentreColumnLabels(centreColumnLabels);
2693 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2696 public void setShowDBRefs(boolean showdbrefs)
2698 viewStyle.setShowDBRefs(showdbrefs);
2703 * @see jalview.api.ViewStyleI#isShowDBRefs()
2706 public boolean isShowDBRefs()
2708 return viewStyle.isShowDBRefs();
2713 * @see jalview.api.ViewStyleI#isShowNPFeats()
2716 public boolean isShowNPFeats()
2718 return viewStyle.isShowNPFeats();
2722 * @param shownpfeats
2723 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2726 public void setShowNPFeats(boolean shownpfeats)
2728 viewStyle.setShowNPFeats(shownpfeats);
2731 public abstract StructureSelectionManager getStructureSelectionManager();
2734 * Add one command to the command history list.
2738 public void addToHistoryList(CommandI command)
2740 if (this.historyList != null)
2742 this.historyList.push(command);
2743 broadcastCommand(command, false);
2744 setSavedUpToDate(false);
2745 Jalview2XML.setStateSavedUpToDate(false);
2749 protected void broadcastCommand(CommandI command, boolean undo)
2751 getStructureSelectionManager().commandPerformed(command, undo,
2756 * Add one command to the command redo list.
2760 public void addToRedoList(CommandI command)
2762 if (this.redoList != null)
2764 this.redoList.push(command);
2766 broadcastCommand(command, true);
2770 * Clear the command redo list.
2772 public void clearRedoList()
2774 if (this.redoList != null)
2776 this.redoList.clear();
2780 public void setHistoryList(Deque<CommandI> list)
2782 this.historyList = list;
2785 public Deque<CommandI> getHistoryList()
2787 return this.historyList;
2790 public void setRedoList(Deque<CommandI> list)
2792 this.redoList = list;
2795 public Deque<CommandI> getRedoList()
2797 return this.redoList;
2801 public VamsasSource getVamsasSource()
2806 public SequenceAnnotationOrder getSortAnnotationsBy()
2808 return sortAnnotationsBy;
2811 public void setSortAnnotationsBy(
2812 SequenceAnnotationOrder sortAnnotationsBy)
2814 this.sortAnnotationsBy = sortAnnotationsBy;
2817 public boolean isShowAutocalculatedAbove()
2819 return showAutocalculatedAbove;
2822 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2824 this.showAutocalculatedAbove = showAutocalculatedAbove;
2828 public boolean isScaleProteinAsCdna()
2830 return viewStyle.isScaleProteinAsCdna();
2834 public void setScaleProteinAsCdna(boolean b)
2836 viewStyle.setScaleProteinAsCdna(b);
2840 public boolean isProteinFontAsCdna()
2842 return viewStyle.isProteinFontAsCdna();
2846 public void setProteinFontAsCdna(boolean b)
2848 viewStyle.setProteinFontAsCdna(b);
2852 public void setShowComplementFeatures(boolean b)
2854 viewStyle.setShowComplementFeatures(b);
2858 public boolean isShowComplementFeatures()
2860 return viewStyle.isShowComplementFeatures();
2864 public void setShowComplementFeaturesOnTop(boolean b)
2866 viewStyle.setShowComplementFeaturesOnTop(b);
2870 public boolean isShowComplementFeaturesOnTop()
2872 return viewStyle.isShowComplementFeaturesOnTop();
2876 * @return true if view should scroll to show the highlighted region of a
2881 public final boolean isFollowHighlight()
2883 return followHighlight;
2887 public final void setFollowHighlight(boolean b)
2889 this.followHighlight = b;
2893 public ViewportRanges getRanges()
2899 * Helper method to populate the SearchResults with the location in the
2900 * complementary alignment to scroll to, in order to match this one.
2903 * the SearchResults to add to
2904 * @return the offset (below top of visible region) of the matched sequence
2906 protected int findComplementScrollTarget(SearchResultsI sr)
2908 final AlignViewportI complement = getCodingComplement();
2909 if (complement == null || !complement.isFollowHighlight())
2913 boolean iAmProtein = !getAlignment().isNucleotide();
2914 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2915 : complement.getAlignment();
2916 if (proteinAlignment == null)
2920 final List<AlignedCodonFrame> mappings = proteinAlignment
2924 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2925 * residue in the middle column of the visible region. Scroll the
2926 * complementary alignment to line up the corresponding residue.
2929 SequenceI sequence = null;
2932 * locate 'middle' column (true middle if an odd number visible, left of
2933 * middle if an even number visible)
2935 int middleColumn = ranges.getStartRes()
2936 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2937 final HiddenSequences hiddenSequences = getAlignment()
2938 .getHiddenSequences();
2941 * searching to the bottom of the alignment gives smoother scrolling across
2942 * all gapped visible regions
2944 int lastSeq = alignment.getHeight() - 1;
2945 List<AlignedCodonFrame> seqMappings = null;
2946 for (int seqNo = ranges
2947 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2949 sequence = getAlignment().getSequenceAt(seqNo);
2950 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2954 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2958 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2960 getCodingComplement().getAlignment().getSequences());
2961 if (!seqMappings.isEmpty())
2967 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2970 * No ungapped mapped sequence in middle column - do nothing
2974 MappingUtils.addSearchResults(sr, sequence,
2975 sequence.findPosition(middleColumn), seqMappings);
2980 * synthesize a column selection if none exists so it covers the given
2981 * selection group. if wholewidth is false, no column selection is made if the
2982 * selection group covers the whole alignment width.
2987 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2990 if (sg != null && (sgs = sg.getStartRes()) >= 0
2991 && sg.getStartRes() <= (sge = sg.getEndRes())
2992 && !this.hasSelectedColumns())
2994 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
3001 colSel = new ColumnSelection();
3003 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
3005 colSel.addElement(cspos);
3011 * hold status of current selection group - defined on alignment or not.
3013 private boolean selectionIsDefinedGroup = false;
3016 public boolean isSelectionDefinedGroup()
3018 if (selectionGroup == null)
3022 if (isSelectionGroupChanged(true))
3024 selectionIsDefinedGroup = false;
3025 List<SequenceGroup> gps = alignment.getGroups();
3026 if (gps == null || gps.size() == 0)
3028 selectionIsDefinedGroup = false;
3032 selectionIsDefinedGroup = gps.contains(selectionGroup);
3035 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3039 * null, or currently highlighted results on this view
3041 private SearchResultsI searchResults = null;
3043 protected TreeModel currentTree = null;
3046 public boolean hasSearchResults()
3048 return searchResults != null;
3052 public void setSearchResults(SearchResultsI results)
3054 searchResults = results;
3058 public SearchResultsI getSearchResults()
3060 return searchResults;
3064 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
3066 return alignment.getContactListFor(_aa, column);
3070 public ContactMatrixI getContactMatrix(
3071 AlignmentAnnotation alignmentAnnotation)
3073 return alignment.getContactMatrixFor(alignmentAnnotation);
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 SequenceI getSSConsensusSeq()
3119 if (secondaryStructureConsensus == null)
3121 updateSecondaryStructureConsensus(null);
3123 if (secondaryStructureConsensus == null)
3127 StringBuffer seqs = new StringBuffer();
3128 for (int i = 0; i < secondaryStructureConsensus.annotations.length; i++)
3130 Annotation annotation = secondaryStructureConsensus.annotations[i];
3131 if (annotation != null)
3133 String description = annotation.description;
3134 if (description != null && description.startsWith("["))
3136 // consensus is a tie - just pick the first one
3137 seqs.append(description.charAt(1));
3141 seqs.append(annotation.displayCharacter);
3146 SequenceI sq = new Sequence("Sec Str Consensus", seqs.toString());
3147 sq.setDescription("Percentage Identity Sec Str Consensus "
3148 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3153 public void setCurrentTree(TreeModel tree)
3159 public TreeModel getCurrentTree()
3165 public AlignmentExportData getAlignExportData(
3166 AlignExportSettingsI options)
3168 AlignmentI alignmentToExport = null;
3169 String[] omitHidden = null;
3170 alignmentToExport = null;
3172 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3174 omitHidden = getViewAsString(false,
3175 options.isExportHiddenSequences());
3178 int[] alignmentStartEnd = new int[2];
3179 if (hasHiddenRows() && options.isExportHiddenSequences())
3181 alignmentToExport = getAlignment().getHiddenSequences()
3182 .getFullAlignment();
3186 alignmentToExport = getAlignment();
3188 alignmentStartEnd = getAlignment().getHiddenColumns()
3189 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3190 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3191 omitHidden, alignmentStartEnd);
3196 * flag set to indicate if structure views might be out of sync with sequences
3200 private boolean needToUpdateStructureViews = false;
3203 public boolean isUpdateStructures()
3205 return needToUpdateStructureViews;
3209 public void setUpdateStructures(boolean update)
3211 needToUpdateStructureViews = update;
3215 public boolean needToUpdateStructureViews()
3217 boolean update = needToUpdateStructureViews;
3218 needToUpdateStructureViews = false;
3223 public void addSequenceGroup(SequenceGroup sequenceGroup)
3225 alignment.addGroup(sequenceGroup);
3227 Color col = sequenceGroup.idColour;
3230 col = col.brighter();
3232 for (SequenceI sq : sequenceGroup.getSequences())
3234 setSequenceColour(sq, col);
3238 if (codingComplement != null)
3240 SequenceGroup mappedGroup = MappingUtils
3241 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3242 if (mappedGroup.getSequences().size() > 0)
3244 codingComplement.getAlignment().addGroup(mappedGroup);
3248 for (SequenceI seq : mappedGroup.getSequences())
3250 codingComplement.setSequenceColour(seq, col);
3254 // propagate the structure view update flag according to our own setting
3255 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3260 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3264 if (selectedRegionOnly && selectionGroup != null)
3266 start = selectionGroup.getStartRes();
3267 end = selectionGroup.getEndRes() + 1;
3271 end = alignment.getWidth();
3273 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3277 public void setSavedUpToDate(boolean s)
3279 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3282 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3285 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3287 QuitHandler.setMessage(m);
3290 public boolean savedUpToDate()
3292 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3294 return savedUpToDate;