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);
1466 // common hide/show column stuff
1468 public void hideSelectedColumns()
1470 if (colSel.isEmpty())
1475 colSel.hideSelectedColumns(alignment);
1476 setSelectionGroup(null);
1477 isColSelChanged(true);
1480 public void hideColumns(int start, int end)
1484 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1488 alignment.getHiddenColumns().hideColumns(start, end);
1490 isColSelChanged(true);
1493 public void showColumn(int col)
1495 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1496 isColSelChanged(true);
1499 public void showAllHiddenColumns()
1501 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1502 isColSelChanged(true);
1505 // common hide/show seq stuff
1506 public void showAllHiddenSeqs()
1508 int startSeq = ranges.getStartSeq();
1509 int endSeq = ranges.getEndSeq();
1511 if (alignment.getHiddenSequences().getSize() > 0)
1513 if (selectionGroup == null)
1515 selectionGroup = new SequenceGroup();
1516 selectionGroup.setEndRes(alignment.getWidth() - 1);
1518 List<SequenceI> tmp = alignment.getHiddenSequences()
1519 .showAll(hiddenRepSequences);
1520 for (SequenceI seq : tmp)
1522 selectionGroup.addSequence(seq, false);
1523 setSequenceAnnotationsVisible(seq, true);
1526 hiddenRepSequences = null;
1528 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1530 firePropertyChange("alignment", null, alignment.getSequences());
1531 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1537 public void showSequence(int index)
1539 int startSeq = ranges.getStartSeq();
1540 int endSeq = ranges.getEndSeq();
1542 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1543 hiddenRepSequences);
1546 if (selectionGroup == null)
1548 selectionGroup = new SequenceGroup();
1549 selectionGroup.setEndRes(alignment.getWidth() - 1);
1552 for (SequenceI seq : tmp)
1554 selectionGroup.addSequence(seq, false);
1555 setSequenceAnnotationsVisible(seq, true);
1558 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1560 firePropertyChange("alignment", null, alignment.getSequences());
1565 public void hideAllSelectedSeqs()
1567 if (selectionGroup == null || selectionGroup.getSize() < 1)
1572 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1576 setSelectionGroup(null);
1579 public void hideSequence(SequenceI[] seq)
1582 * cache offset to first visible sequence
1584 int startSeq = ranges.getStartSeq();
1588 for (int i = 0; i < seq.length; i++)
1590 alignment.getHiddenSequences().hideSequence(seq[i]);
1591 setSequenceAnnotationsVisible(seq[i], false);
1593 ranges.setStartSeq(startSeq);
1594 firePropertyChange("alignment", null, alignment.getSequences());
1599 * Hides the specified sequence, or the sequences it represents
1602 * the sequence to hide, or keep as representative
1603 * @param representGroup
1604 * if true, hide the current selection group except for the
1605 * representative sequence
1607 public void hideSequences(SequenceI sequence, boolean representGroup)
1609 if (selectionGroup == null || selectionGroup.getSize() < 1)
1611 hideSequence(new SequenceI[] { sequence });
1617 hideRepSequences(sequence, selectionGroup);
1618 setSelectionGroup(null);
1622 int gsize = selectionGroup.getSize();
1623 SequenceI[] hseqs = selectionGroup.getSequences()
1624 .toArray(new SequenceI[gsize]);
1626 hideSequence(hseqs);
1627 setSelectionGroup(null);
1632 * Set visibility for any annotations for the given sequence.
1636 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1639 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1642 for (AlignmentAnnotation ann : anns)
1644 if (ann.sequenceRef == sequenceI)
1646 ann.visible = visible;
1652 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1654 int sSize = sg.getSize();
1660 if (hiddenRepSequences == null)
1662 hiddenRepSequences = new Hashtable<>();
1665 hiddenRepSequences.put(repSequence, sg);
1667 // Hide all sequences except the repSequence
1668 SequenceI[] seqs = new SequenceI[sSize - 1];
1670 for (int i = 0; i < sSize; i++)
1672 if (sg.getSequenceAt(i) != repSequence)
1674 if (index == sSize - 1)
1679 seqs[index++] = sg.getSequenceAt(i);
1682 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1683 sg.setHidereps(true); // note: not done in 2.7applet
1690 * @return null or the current reference sequence
1692 public SequenceI getReferenceSeq()
1694 return alignment.getSeqrep();
1699 * @return true iff seq is the reference for the alignment
1701 public boolean isReferenceSeq(SequenceI seq)
1703 return alignment.getSeqrep() == seq;
1709 * @return true if there are sequences represented by this sequence that are
1712 public boolean isHiddenRepSequence(SequenceI seq)
1714 return (hiddenRepSequences != null
1715 && hiddenRepSequences.containsKey(seq));
1721 * @return null or a sequence group containing the sequences that seq
1724 public SequenceGroup getRepresentedSequences(SequenceI seq)
1726 return (SequenceGroup) (hiddenRepSequences == null ? null
1727 : hiddenRepSequences.get(seq));
1731 public int adjustForHiddenSeqs(int alignmentIndex)
1733 return alignment.getHiddenSequences()
1734 .adjustForHiddenSeqs(alignmentIndex);
1738 public void invertColumnSelection()
1740 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1741 isColSelChanged(true);
1745 public SequenceI[] getSelectionAsNewSequence()
1747 SequenceI[] sequences;
1748 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1749 // this was the only caller in the applet for this method
1750 // JBPNote: in applet, this method returned references to the alignment
1751 // sequences, and it did not honour the presence/absence of annotation
1752 // attached to the alignment (probably!)
1753 if (selectionGroup == null || selectionGroup.getSize() == 0)
1755 sequences = alignment.getSequencesArray();
1756 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1757 for (int i = 0; i < sequences.length; i++)
1759 // construct new sequence with subset of visible annotation
1760 sequences[i] = new Sequence(sequences[i], annots);
1765 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1772 public SequenceI[] getSequenceSelection()
1774 SequenceI[] sequences = null;
1775 if (selectionGroup != null)
1777 sequences = selectionGroup.getSequencesInOrder(alignment);
1779 if (sequences == null)
1781 sequences = alignment.getSequencesArray();
1787 public jalview.datamodel.AlignmentView getAlignmentView(
1788 boolean selectedOnly)
1790 return getAlignmentView(selectedOnly, false);
1794 public jalview.datamodel.AlignmentView getAlignmentView(
1795 boolean selectedOnly, boolean markGroups)
1797 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1799 alignment.getHiddenColumns() != null
1800 && alignment.getHiddenColumns().hasHiddenColumns(),
1801 selectedOnly, markGroups);
1805 public String[] getViewAsString(boolean selectedRegionOnly)
1807 return getViewAsString(selectedRegionOnly, true);
1811 public String[] getViewAsString(boolean selectedRegionOnly,
1812 boolean exportHiddenSeqs)
1814 String[] selection = null;
1815 SequenceI[] seqs = null;
1817 int start = 0, end = 0;
1818 if (selectedRegionOnly && selectionGroup != null)
1820 iSize = selectionGroup.getSize();
1821 seqs = selectionGroup.getSequencesInOrder(alignment);
1822 start = selectionGroup.getStartRes();
1823 end = selectionGroup.getEndRes() + 1;
1827 if (hasHiddenRows() && exportHiddenSeqs)
1829 AlignmentI fullAlignment = alignment.getHiddenSequences()
1830 .getFullAlignment();
1831 iSize = fullAlignment.getHeight();
1832 seqs = fullAlignment.getSequencesArray();
1833 end = fullAlignment.getWidth();
1837 iSize = alignment.getHeight();
1838 seqs = alignment.getSequencesArray();
1839 end = alignment.getWidth();
1843 selection = new String[iSize];
1844 if (alignment.getHiddenColumns() != null
1845 && alignment.getHiddenColumns().hasHiddenColumns())
1847 for (i = 0; i < iSize; i++)
1849 Iterator<int[]> blocks = alignment.getHiddenColumns()
1850 .getVisContigsIterator(start, end + 1, false);
1851 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1856 for (i = 0; i < iSize; i++)
1858 selection[i] = seqs[i].getSequenceAsString(start, end);
1866 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1868 ArrayList<int[]> regions = new ArrayList<>();
1874 HiddenColumns hidden = alignment.getHiddenColumns();
1875 if (hidden != null && hidden.hasHiddenColumns())
1879 start = hidden.visibleToAbsoluteColumn(start);
1882 end = hidden.getNextHiddenBoundary(false, start);
1893 regions.add(new int[] { start, end });
1895 if (hidden != null && hidden.hasHiddenColumns())
1897 start = hidden.visibleToAbsoluteColumn(end);
1898 start = hidden.getNextHiddenBoundary(true, start) + 1;
1900 } while (end < max);
1902 // int[][] startEnd = new int[regions.size()][2];
1908 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1909 boolean selectedOnly)
1911 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1912 AlignmentAnnotation[] aa;
1913 if ((aa = alignment.getAlignmentAnnotation()) != null)
1915 for (AlignmentAnnotation annot : aa)
1917 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1918 if (selectedOnly && selectionGroup != null)
1920 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1921 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1925 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1934 public boolean isPadGaps()
1940 public void setPadGaps(boolean padGaps)
1942 this.padGaps = padGaps;
1946 * apply any post-edit constraints and trigger any calculations needed after
1947 * an edit has been performed on the alignment
1952 public void alignmentChanged(AlignmentViewPanel ap)
1956 alignment.padGaps();
1958 if (autoCalculateConsensus)
1960 updateConsensus(ap);
1961 updateSecondaryStructureConsensus(ap);
1963 if (hconsensus != null && autoCalculateConsensus)
1965 updateConservation(ap);
1967 if (autoCalculateStrucConsensus)
1969 updateStrucConsensus(ap);
1972 // Reset endRes of groups if beyond alignment width
1973 int alWidth = alignment.getWidth();
1974 List<SequenceGroup> groups = alignment.getGroups();
1977 for (SequenceGroup sg : groups)
1979 if (sg.getEndRes() > alWidth)
1981 sg.setEndRes(alWidth - 1);
1986 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1988 selectionGroup.setEndRes(alWidth - 1);
1991 updateAllColourSchemes();
1992 calculator.restartWorkers();
1993 // alignment.adjustSequenceAnnotations();
1997 * reset scope and do calculations for all applied colourschemes on alignment
1999 void updateAllColourSchemes()
2001 ResidueShaderI rs = residueShading;
2004 rs.alignmentChanged(alignment, hiddenRepSequences);
2006 rs.setConsensus(hconsensus);
2007 if (rs.conservationApplied())
2009 rs.setConservation(Conservation.calculateConservation("All",
2010 alignment.getSequences(), 0, alignment.getWidth(), false,
2011 getConsPercGaps(), false));
2015 for (SequenceGroup sg : alignment.getGroups())
2019 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2021 sg.recalcConservation();
2025 protected void initAutoAnnotation()
2027 // TODO: add menu option action that nulls or creates consensus object
2028 // depending on if the user wants to see the annotation or not in a
2029 // specific alignment
2031 if (hconsensus == null && !isDataset)
2033 if (!alignment.isNucleotide())
2042 consensus = new AlignmentAnnotation("Consensus",
2043 MessageManager.getString("label.consensus_descr"),
2044 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2046 secondaryStructureConsensus = new AlignmentAnnotation(MessageManager.getString("label.ssconsensus_label"),
2047 MessageManager.getString("label.ssconsensus_descr"),
2048 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2050 initConsensus(consensus);
2051 initSSConsensus(secondaryStructureConsensus);
2053 initComplementConsensus();
2059 * If this is a protein alignment and there are mappings to cDNA, adds the
2060 * cDNA consensus annotation and returns true, else returns false.
2062 public boolean initComplementConsensus()
2064 if (!alignment.isNucleotide())
2066 final List<AlignedCodonFrame> codonMappings = alignment
2068 if (codonMappings != null && !codonMappings.isEmpty())
2070 boolean doConsensus = false;
2071 for (AlignedCodonFrame mapping : codonMappings)
2073 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2074 MapList[] mapLists = mapping.getdnaToProt();
2075 // mapLists can be empty if project load has not finished resolving
2077 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2085 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2087 .getString("label.complement_consensus_descr"),
2088 new Annotation[1], 0f, 100f,
2089 AlignmentAnnotation.BAR_GRAPH);
2090 initConsensus(complementConsensus);
2098 private void initConsensus(AlignmentAnnotation aa)
2101 aa.autoCalculated = true;
2105 alignment.addAnnotation(aa);
2109 private void initSSConsensus(AlignmentAnnotation aa)
2112 aa.autoCalculated = true;
2114 if (showSSConsensus)
2116 alignment.addAnnotation(aa);
2120 // these should be extracted from the view model - style and settings for
2121 // derived annotation
2122 private void initGapCounts()
2126 gapcounts = new AlignmentAnnotation("Occupancy",
2127 MessageManager.getString("label.occupancy_descr"),
2128 new Annotation[1], 0f, alignment.getHeight(),
2129 AlignmentAnnotation.BAR_GRAPH);
2130 gapcounts.hasText = true;
2131 gapcounts.autoCalculated = true;
2132 gapcounts.scaleColLabel = true;
2133 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2135 alignment.addAnnotation(gapcounts);
2139 private void initConservation()
2141 if (showConservation)
2143 if (conservation == null)
2145 conservation = new AlignmentAnnotation("Conservation",
2146 MessageManager.formatMessage("label.conservation_descr",
2148 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2149 conservation.hasText = true;
2150 conservation.autoCalculated = true;
2151 alignment.addAnnotation(conservation);
2156 private void initQuality()
2160 if (quality == null)
2162 quality = new AlignmentAnnotation("Quality",
2163 MessageManager.getString("label.quality_descr"),
2164 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2165 quality.hasText = true;
2166 quality.autoCalculated = true;
2167 alignment.addAnnotation(quality);
2172 private void initRNAStructure()
2174 if (alignment.hasRNAStructure() && strucConsensus == null)
2176 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2177 MessageManager.getString("label.strucconsensus_descr"),
2178 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2179 strucConsensus.hasText = true;
2180 strucConsensus.autoCalculated = true;
2184 alignment.addAnnotation(strucConsensus);
2192 * @see jalview.api.AlignViewportI#calcPanelHeight()
2195 public int calcPanelHeight()
2197 // setHeight of panels
2198 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2200 int charHeight = getCharHeight();
2203 BitSet graphgrp = new BitSet();
2204 for (AlignmentAnnotation aa : anns)
2208 jalview.bin.Console.errPrintln("Null annotation row: ignoring.");
2215 if (aa.graphGroup > -1)
2217 if (graphgrp.get(aa.graphGroup))
2223 graphgrp.set(aa.graphGroup);
2230 aa.height += charHeight;
2240 aa.height += aa.graphHeight + 20;
2248 height += aa.height;
2260 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2261 boolean preserveNewGroupSettings)
2263 boolean updateCalcs = false;
2264 boolean conv = isShowGroupConservation();
2265 boolean cons = isShowGroupConsensus();
2266 boolean showprf = isShowSequenceLogo();
2267 boolean showSSprf = isShowSequenceSSLogo();
2268 boolean showConsHist = isShowConsensusHistogram();
2269 boolean showSSConsHist = isShowSSConsensusHistogram();
2270 boolean normLogo = isNormaliseSequenceLogo();
2273 * TODO reorder the annotation rows according to group/sequence ordering on
2276 // boolean sortg = true;
2278 // remove old automatic annotation
2279 // add any new annotation
2281 // intersect alignment annotation with alignment groups
2283 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2284 List<SequenceGroup> oldrfs = new ArrayList<>();
2287 for (int an = 0; an < aan.length; an++)
2289 if (aan[an].autoCalculated && aan[an].groupRef != null)
2291 oldrfs.add(aan[an].groupRef);
2292 alignment.deleteAnnotation(aan[an], false);
2296 if (alignment.getGroups() != null)
2298 for (SequenceGroup sg : alignment.getGroups())
2300 updateCalcs = false;
2301 if (applyGlobalSettings
2302 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2304 // set defaults for this group's conservation/consensus
2305 sg.setshowSequenceLogo(showprf);
2306 sg.setshowSequenceSSLogo(showSSprf);
2307 sg.setShowConsensusHistogram(showConsHist);
2308 sg.setShowSSConsensusHistogram(showSSConsHist);
2309 sg.setNormaliseSequenceLogo(normLogo);
2314 alignment.addAnnotation(sg.getConservationRow(), 0);
2319 alignment.addAnnotation(sg.getConsensus(), 0);
2320 alignment.addAnnotation(sg.getSSConsensus(), 0);
2322 // refresh the annotation rows
2325 sg.recalcConservation();
2333 public boolean isDisplayReferenceSeq()
2335 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2339 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2341 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2345 public boolean isColourByReferenceSeq()
2347 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2351 public Color getSequenceColour(SequenceI seq)
2353 Color sqc = sequenceColours.get(seq);
2354 return (sqc == null ? Color.white : sqc);
2358 public void setSequenceColour(SequenceI seq, Color col)
2362 sequenceColours.remove(seq);
2366 sequenceColours.put(seq, col);
2371 public void updateSequenceIdColours()
2373 for (SequenceGroup sg : alignment.getGroups())
2375 if (sg.idColour != null)
2377 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2379 sequenceColours.put(s, sg.idColour);
2386 public void clearSequenceColours()
2388 sequenceColours.clear();
2392 public AlignViewportI getCodingComplement()
2394 return this.codingComplement;
2398 * Set this as the (cDna/protein) complement of the given viewport. Also
2399 * ensures the reverse relationship is set on the given viewport.
2402 public void setCodingComplement(AlignViewportI av)
2407 .errPrintln("Ignoring recursive setCodingComplement request");
2411 this.codingComplement = av;
2412 // avoid infinite recursion!
2413 if (av.getCodingComplement() != this)
2415 av.setCodingComplement(this);
2421 public boolean isNucleotide()
2423 return getAlignment() == null ? false : getAlignment().isNucleotide();
2427 public FeaturesDisplayedI getFeaturesDisplayed()
2429 return featuresDisplayed;
2433 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2435 featuresDisplayed = featuresDisplayedI;
2439 public boolean areFeaturesDisplayed()
2441 return featuresDisplayed != null
2442 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2449 * features are displayed if true
2452 public void setShowSequenceFeatures(boolean b)
2454 viewStyle.setShowSequenceFeatures(b);
2458 public boolean isShowSequenceFeatures()
2460 return viewStyle.isShowSequenceFeatures();
2464 public void setShowSequenceFeaturesHeight(boolean selected)
2466 viewStyle.setShowSequenceFeaturesHeight(selected);
2470 public boolean isShowSequenceFeaturesHeight()
2472 return viewStyle.isShowSequenceFeaturesHeight();
2476 public void setShowAnnotation(boolean b)
2478 viewStyle.setShowAnnotation(b);
2482 public boolean isShowAnnotation()
2484 return viewStyle.isShowAnnotation();
2488 public boolean isRightAlignIds()
2490 return viewStyle.isRightAlignIds();
2494 public void setRightAlignIds(boolean rightAlignIds)
2496 viewStyle.setRightAlignIds(rightAlignIds);
2500 public boolean getConservationSelected()
2502 return viewStyle.getConservationSelected();
2506 public void setShowBoxes(boolean state)
2508 viewStyle.setShowBoxes(state);
2513 * @see jalview.api.ViewStyleI#getTextColour()
2516 public Color getTextColour()
2518 return viewStyle.getTextColour();
2523 * @see jalview.api.ViewStyleI#getTextColour2()
2526 public Color getTextColour2()
2528 return viewStyle.getTextColour2();
2533 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2536 public int getThresholdTextColour()
2538 return viewStyle.getThresholdTextColour();
2543 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2546 public boolean isConservationColourSelected()
2548 return viewStyle.isConservationColourSelected();
2553 * @see jalview.api.ViewStyleI#isRenderGaps()
2556 public boolean isRenderGaps()
2558 return viewStyle.isRenderGaps();
2563 * @see jalview.api.ViewStyleI#isShowColourText()
2566 public boolean isShowColourText()
2568 return viewStyle.isShowColourText();
2572 * @param conservationColourSelected
2573 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2576 public void setConservationColourSelected(
2577 boolean conservationColourSelected)
2579 viewStyle.setConservationColourSelected(conservationColourSelected);
2583 * @param showColourText
2584 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2587 public void setShowColourText(boolean showColourText)
2589 viewStyle.setShowColourText(showColourText);
2594 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2597 public void setTextColour(Color textColour)
2599 viewStyle.setTextColour(textColour);
2603 * @param thresholdTextColour
2604 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2607 public void setThresholdTextColour(int thresholdTextColour)
2609 viewStyle.setThresholdTextColour(thresholdTextColour);
2613 * @param textColour2
2614 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2617 public void setTextColour2(Color textColour2)
2619 viewStyle.setTextColour2(textColour2);
2623 public ViewStyleI getViewStyle()
2625 return new ViewStyle(viewStyle);
2629 public void setViewStyle(ViewStyleI settingsForView)
2631 viewStyle = new ViewStyle(settingsForView);
2632 if (residueShading != null)
2634 residueShading.setConservationApplied(
2635 settingsForView.isConservationColourSelected());
2640 public boolean sameStyle(ViewStyleI them)
2642 return viewStyle.sameStyle(them);
2647 * @see jalview.api.ViewStyleI#getIdWidth()
2650 public int getIdWidth()
2652 return viewStyle.getIdWidth();
2657 * @see jalview.api.ViewStyleI#setIdWidth(int)
2660 public void setIdWidth(int i)
2662 viewStyle.setIdWidth(i);
2667 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2670 public boolean isCentreColumnLabels()
2672 return viewStyle.isCentreColumnLabels();
2676 * @param centreColumnLabels
2677 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2680 public void setCentreColumnLabels(boolean centreColumnLabels)
2682 viewStyle.setCentreColumnLabels(centreColumnLabels);
2687 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2690 public void setShowDBRefs(boolean showdbrefs)
2692 viewStyle.setShowDBRefs(showdbrefs);
2697 * @see jalview.api.ViewStyleI#isShowDBRefs()
2700 public boolean isShowDBRefs()
2702 return viewStyle.isShowDBRefs();
2707 * @see jalview.api.ViewStyleI#isShowNPFeats()
2710 public boolean isShowNPFeats()
2712 return viewStyle.isShowNPFeats();
2716 * @param shownpfeats
2717 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2720 public void setShowNPFeats(boolean shownpfeats)
2722 viewStyle.setShowNPFeats(shownpfeats);
2725 public abstract StructureSelectionManager getStructureSelectionManager();
2728 * Add one command to the command history list.
2732 public void addToHistoryList(CommandI command)
2734 if (this.historyList != null)
2736 this.historyList.push(command);
2737 broadcastCommand(command, false);
2738 setSavedUpToDate(false);
2739 Jalview2XML.setStateSavedUpToDate(false);
2743 protected void broadcastCommand(CommandI command, boolean undo)
2745 getStructureSelectionManager().commandPerformed(command, undo,
2750 * Add one command to the command redo list.
2754 public void addToRedoList(CommandI command)
2756 if (this.redoList != null)
2758 this.redoList.push(command);
2760 broadcastCommand(command, true);
2764 * Clear the command redo list.
2766 public void clearRedoList()
2768 if (this.redoList != null)
2770 this.redoList.clear();
2774 public void setHistoryList(Deque<CommandI> list)
2776 this.historyList = list;
2779 public Deque<CommandI> getHistoryList()
2781 return this.historyList;
2784 public void setRedoList(Deque<CommandI> list)
2786 this.redoList = list;
2789 public Deque<CommandI> getRedoList()
2791 return this.redoList;
2795 public VamsasSource getVamsasSource()
2800 public SequenceAnnotationOrder getSortAnnotationsBy()
2802 return sortAnnotationsBy;
2805 public void setSortAnnotationsBy(
2806 SequenceAnnotationOrder sortAnnotationsBy)
2808 this.sortAnnotationsBy = sortAnnotationsBy;
2811 public boolean isShowAutocalculatedAbove()
2813 return showAutocalculatedAbove;
2816 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2818 this.showAutocalculatedAbove = showAutocalculatedAbove;
2822 public boolean isScaleProteinAsCdna()
2824 return viewStyle.isScaleProteinAsCdna();
2828 public void setScaleProteinAsCdna(boolean b)
2830 viewStyle.setScaleProteinAsCdna(b);
2834 public boolean isProteinFontAsCdna()
2836 return viewStyle.isProteinFontAsCdna();
2840 public void setProteinFontAsCdna(boolean b)
2842 viewStyle.setProteinFontAsCdna(b);
2846 public void setShowComplementFeatures(boolean b)
2848 viewStyle.setShowComplementFeatures(b);
2852 public boolean isShowComplementFeatures()
2854 return viewStyle.isShowComplementFeatures();
2858 public void setShowComplementFeaturesOnTop(boolean b)
2860 viewStyle.setShowComplementFeaturesOnTop(b);
2864 public boolean isShowComplementFeaturesOnTop()
2866 return viewStyle.isShowComplementFeaturesOnTop();
2870 * @return true if view should scroll to show the highlighted region of a
2875 public final boolean isFollowHighlight()
2877 return followHighlight;
2881 public final void setFollowHighlight(boolean b)
2883 this.followHighlight = b;
2887 public ViewportRanges getRanges()
2893 * Helper method to populate the SearchResults with the location in the
2894 * complementary alignment to scroll to, in order to match this one.
2897 * the SearchResults to add to
2898 * @return the offset (below top of visible region) of the matched sequence
2900 protected int findComplementScrollTarget(SearchResultsI sr)
2902 final AlignViewportI complement = getCodingComplement();
2903 if (complement == null || !complement.isFollowHighlight())
2907 boolean iAmProtein = !getAlignment().isNucleotide();
2908 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2909 : complement.getAlignment();
2910 if (proteinAlignment == null)
2914 final List<AlignedCodonFrame> mappings = proteinAlignment
2918 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2919 * residue in the middle column of the visible region. Scroll the
2920 * complementary alignment to line up the corresponding residue.
2923 SequenceI sequence = null;
2926 * locate 'middle' column (true middle if an odd number visible, left of
2927 * middle if an even number visible)
2929 int middleColumn = ranges.getStartRes()
2930 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2931 final HiddenSequences hiddenSequences = getAlignment()
2932 .getHiddenSequences();
2935 * searching to the bottom of the alignment gives smoother scrolling across
2936 * all gapped visible regions
2938 int lastSeq = alignment.getHeight() - 1;
2939 List<AlignedCodonFrame> seqMappings = null;
2940 for (int seqNo = ranges
2941 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2943 sequence = getAlignment().getSequenceAt(seqNo);
2944 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2948 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2952 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2954 getCodingComplement().getAlignment().getSequences());
2955 if (!seqMappings.isEmpty())
2961 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2964 * No ungapped mapped sequence in middle column - do nothing
2968 MappingUtils.addSearchResults(sr, sequence,
2969 sequence.findPosition(middleColumn), seqMappings);
2974 * synthesize a column selection if none exists so it covers the given
2975 * selection group. if wholewidth is false, no column selection is made if the
2976 * selection group covers the whole alignment width.
2981 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2984 if (sg != null && (sgs = sg.getStartRes()) >= 0
2985 && sg.getStartRes() <= (sge = sg.getEndRes())
2986 && !this.hasSelectedColumns())
2988 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2995 colSel = new ColumnSelection();
2997 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2999 colSel.addElement(cspos);
3005 * hold status of current selection group - defined on alignment or not.
3007 private boolean selectionIsDefinedGroup = false;
3010 public boolean isSelectionDefinedGroup()
3012 if (selectionGroup == null)
3016 if (isSelectionGroupChanged(true))
3018 selectionIsDefinedGroup = false;
3019 List<SequenceGroup> gps = alignment.getGroups();
3020 if (gps == null || gps.size() == 0)
3022 selectionIsDefinedGroup = false;
3026 selectionIsDefinedGroup = gps.contains(selectionGroup);
3029 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3033 * null, or currently highlighted results on this view
3035 private SearchResultsI searchResults = null;
3037 protected TreeModel currentTree = null;
3040 public boolean hasSearchResults()
3042 return searchResults != null;
3046 public void setSearchResults(SearchResultsI results)
3048 searchResults = results;
3052 public SearchResultsI getSearchResults()
3054 return searchResults;
3058 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
3060 return alignment.getContactListFor(_aa, column);
3064 public ContactMatrixI getContactMatrix(
3065 AlignmentAnnotation alignmentAnnotation)
3067 return alignment.getContactMatrixFor(alignmentAnnotation);
3071 * get the consensus sequence as displayed under the PID consensus annotation
3074 * @return consensus sequence as a new sequence object
3076 public SequenceI getConsensusSeq()
3078 if (consensus == null)
3080 updateConsensus(null);
3082 if (consensus == null)
3086 StringBuffer seqs = new StringBuffer();
3087 for (int i = 0; i < consensus.annotations.length; i++)
3089 Annotation annotation = consensus.annotations[i];
3090 if (annotation != null)
3092 String description = annotation.description;
3093 if (description != null && description.startsWith("["))
3095 // consensus is a tie - just pick the first one
3096 seqs.append(description.charAt(1));
3100 seqs.append(annotation.displayCharacter);
3105 SequenceI sq = new Sequence("Consensus", seqs.toString());
3106 sq.setDescription("Percentage Identity Consensus "
3107 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3111 public SequenceI getSSConsensusSeq()
3113 if (secondaryStructureConsensus == null)
3115 updateSecondaryStructureConsensus(null);
3117 if (secondaryStructureConsensus == null)
3121 StringBuffer seqs = new StringBuffer();
3122 for (int i = 0; i < secondaryStructureConsensus.annotations.length; i++)
3124 Annotation annotation = secondaryStructureConsensus.annotations[i];
3125 if (annotation != null)
3127 String description = annotation.description;
3128 if (description != null && description.startsWith("["))
3130 // consensus is a tie - just pick the first one
3131 seqs.append(description.charAt(1));
3135 seqs.append(annotation.displayCharacter);
3140 SequenceI sq = new Sequence("Sec Str Consensus", seqs.toString());
3141 sq.setDescription("Percentage Identity Sec Str Consensus "
3142 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3147 public void setCurrentTree(TreeModel tree)
3153 public TreeModel getCurrentTree()
3159 public AlignmentExportData getAlignExportData(
3160 AlignExportSettingsI options)
3162 AlignmentI alignmentToExport = null;
3163 String[] omitHidden = null;
3164 alignmentToExport = null;
3166 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3168 omitHidden = getViewAsString(false,
3169 options.isExportHiddenSequences());
3172 int[] alignmentStartEnd = new int[2];
3173 if (hasHiddenRows() && options.isExportHiddenSequences())
3175 alignmentToExport = getAlignment().getHiddenSequences()
3176 .getFullAlignment();
3180 alignmentToExport = getAlignment();
3182 alignmentStartEnd = getAlignment().getHiddenColumns()
3183 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3184 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3185 omitHidden, alignmentStartEnd);
3190 * flag set to indicate if structure views might be out of sync with sequences
3194 private boolean needToUpdateStructureViews = false;
3197 public boolean isUpdateStructures()
3199 return needToUpdateStructureViews;
3203 public void setUpdateStructures(boolean update)
3205 needToUpdateStructureViews = update;
3209 public boolean needToUpdateStructureViews()
3211 boolean update = needToUpdateStructureViews;
3212 needToUpdateStructureViews = false;
3217 public void addSequenceGroup(SequenceGroup sequenceGroup)
3219 alignment.addGroup(sequenceGroup);
3221 Color col = sequenceGroup.idColour;
3224 col = col.brighter();
3226 for (SequenceI sq : sequenceGroup.getSequences())
3228 setSequenceColour(sq, col);
3232 if (codingComplement != null)
3234 SequenceGroup mappedGroup = MappingUtils
3235 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3236 if (mappedGroup.getSequences().size() > 0)
3238 codingComplement.getAlignment().addGroup(mappedGroup);
3242 for (SequenceI seq : mappedGroup.getSequences())
3244 codingComplement.setSequenceColour(seq, col);
3248 // propagate the structure view update flag according to our own setting
3249 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3254 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3258 if (selectedRegionOnly && selectionGroup != null)
3260 start = selectionGroup.getStartRes();
3261 end = selectionGroup.getEndRes() + 1;
3265 end = alignment.getWidth();
3267 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3271 public void setSavedUpToDate(boolean s)
3273 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3276 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3279 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3281 QuitHandler.setMessage(m);
3284 public boolean savedUpToDate()
3286 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3288 return savedUpToDate;