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 showOccupancy = true;
1410 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1412 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1414 protected boolean showAutocalculatedAbove;
1417 * when set, view will scroll to show the highlighted position
1419 private boolean followHighlight = true;
1422 * Property change listener for changes in alignment
1427 public void addPropertyChangeListener(
1428 java.beans.PropertyChangeListener listener)
1430 changeSupport.addPropertyChangeListener(listener);
1439 public void removePropertyChangeListener(
1440 java.beans.PropertyChangeListener listener)
1442 if (changeSupport != null)
1444 changeSupport.removePropertyChangeListener(listener);
1449 * Property change listener for changes in alignment
1458 public void firePropertyChange(String prop, Object oldvalue,
1461 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1464 // common hide/show column stuff
1466 public void hideSelectedColumns()
1468 if (colSel.isEmpty())
1473 colSel.hideSelectedColumns(alignment);
1474 setSelectionGroup(null);
1475 isColSelChanged(true);
1478 public void hideColumns(int start, int end)
1482 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1486 alignment.getHiddenColumns().hideColumns(start, end);
1488 isColSelChanged(true);
1491 public void showColumn(int col)
1493 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1494 isColSelChanged(true);
1497 public void showAllHiddenColumns()
1499 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1500 isColSelChanged(true);
1503 // common hide/show seq stuff
1504 public void showAllHiddenSeqs()
1506 int startSeq = ranges.getStartSeq();
1507 int endSeq = ranges.getEndSeq();
1509 if (alignment.getHiddenSequences().getSize() > 0)
1511 if (selectionGroup == null)
1513 selectionGroup = new SequenceGroup();
1514 selectionGroup.setEndRes(alignment.getWidth() - 1);
1516 List<SequenceI> tmp = alignment.getHiddenSequences()
1517 .showAll(hiddenRepSequences);
1518 for (SequenceI seq : tmp)
1520 selectionGroup.addSequence(seq, false);
1521 setSequenceAnnotationsVisible(seq, true);
1524 hiddenRepSequences = null;
1526 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1528 firePropertyChange("alignment", null, alignment.getSequences());
1529 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1535 public void showSequence(int index)
1537 int startSeq = ranges.getStartSeq();
1538 int endSeq = ranges.getEndSeq();
1540 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1541 hiddenRepSequences);
1544 if (selectionGroup == null)
1546 selectionGroup = new SequenceGroup();
1547 selectionGroup.setEndRes(alignment.getWidth() - 1);
1550 for (SequenceI seq : tmp)
1552 selectionGroup.addSequence(seq, false);
1553 setSequenceAnnotationsVisible(seq, true);
1556 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1558 firePropertyChange("alignment", null, alignment.getSequences());
1563 public void hideAllSelectedSeqs()
1565 if (selectionGroup == null || selectionGroup.getSize() < 1)
1570 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1574 setSelectionGroup(null);
1577 public void hideSequence(SequenceI[] seq)
1580 * cache offset to first visible sequence
1582 int startSeq = ranges.getStartSeq();
1586 for (int i = 0; i < seq.length; i++)
1588 alignment.getHiddenSequences().hideSequence(seq[i]);
1589 setSequenceAnnotationsVisible(seq[i], false);
1591 ranges.setStartSeq(startSeq);
1592 firePropertyChange("alignment", null, alignment.getSequences());
1597 * Hides the specified sequence, or the sequences it represents
1600 * the sequence to hide, or keep as representative
1601 * @param representGroup
1602 * if true, hide the current selection group except for the
1603 * representative sequence
1605 public void hideSequences(SequenceI sequence, boolean representGroup)
1607 if (selectionGroup == null || selectionGroup.getSize() < 1)
1609 hideSequence(new SequenceI[] { sequence });
1615 hideRepSequences(sequence, selectionGroup);
1616 setSelectionGroup(null);
1620 int gsize = selectionGroup.getSize();
1621 SequenceI[] hseqs = selectionGroup.getSequences()
1622 .toArray(new SequenceI[gsize]);
1624 hideSequence(hseqs);
1625 setSelectionGroup(null);
1630 * Set visibility for any annotations for the given sequence.
1634 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1637 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1640 for (AlignmentAnnotation ann : anns)
1642 if (ann.sequenceRef == sequenceI)
1644 ann.visible = visible;
1650 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1652 int sSize = sg.getSize();
1658 if (hiddenRepSequences == null)
1660 hiddenRepSequences = new Hashtable<>();
1663 hiddenRepSequences.put(repSequence, sg);
1665 // Hide all sequences except the repSequence
1666 SequenceI[] seqs = new SequenceI[sSize - 1];
1668 for (int i = 0; i < sSize; i++)
1670 if (sg.getSequenceAt(i) != repSequence)
1672 if (index == sSize - 1)
1677 seqs[index++] = sg.getSequenceAt(i);
1680 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1681 sg.setHidereps(true); // note: not done in 2.7applet
1688 * @return null or the current reference sequence
1690 public SequenceI getReferenceSeq()
1692 return alignment.getSeqrep();
1697 * @return true iff seq is the reference for the alignment
1699 public boolean isReferenceSeq(SequenceI seq)
1701 return alignment.getSeqrep() == seq;
1707 * @return true if there are sequences represented by this sequence that are
1710 public boolean isHiddenRepSequence(SequenceI seq)
1712 return (hiddenRepSequences != null
1713 && hiddenRepSequences.containsKey(seq));
1719 * @return null or a sequence group containing the sequences that seq
1722 public SequenceGroup getRepresentedSequences(SequenceI seq)
1724 return (SequenceGroup) (hiddenRepSequences == null ? null
1725 : hiddenRepSequences.get(seq));
1729 public int adjustForHiddenSeqs(int alignmentIndex)
1731 return alignment.getHiddenSequences()
1732 .adjustForHiddenSeqs(alignmentIndex);
1736 public void invertColumnSelection()
1738 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1739 isColSelChanged(true);
1743 public SequenceI[] getSelectionAsNewSequence()
1745 SequenceI[] sequences;
1746 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1747 // this was the only caller in the applet for this method
1748 // JBPNote: in applet, this method returned references to the alignment
1749 // sequences, and it did not honour the presence/absence of annotation
1750 // attached to the alignment (probably!)
1751 if (selectionGroup == null || selectionGroup.getSize() == 0)
1753 sequences = alignment.getSequencesArray();
1754 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1755 for (int i = 0; i < sequences.length; i++)
1757 // construct new sequence with subset of visible annotation
1758 sequences[i] = new Sequence(sequences[i], annots);
1763 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1770 public SequenceI[] getSequenceSelection()
1772 SequenceI[] sequences = null;
1773 if (selectionGroup != null)
1775 sequences = selectionGroup.getSequencesInOrder(alignment);
1777 if (sequences == null)
1779 sequences = alignment.getSequencesArray();
1785 public jalview.datamodel.AlignmentView getAlignmentView(
1786 boolean selectedOnly)
1788 return getAlignmentView(selectedOnly, false);
1792 public jalview.datamodel.AlignmentView getAlignmentView(
1793 boolean selectedOnly, boolean markGroups)
1795 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1797 alignment.getHiddenColumns() != null
1798 && alignment.getHiddenColumns().hasHiddenColumns(),
1799 selectedOnly, markGroups);
1803 public String[] getViewAsString(boolean selectedRegionOnly)
1805 return getViewAsString(selectedRegionOnly, true);
1809 public String[] getViewAsString(boolean selectedRegionOnly,
1810 boolean exportHiddenSeqs)
1812 String[] selection = null;
1813 SequenceI[] seqs = null;
1815 int start = 0, end = 0;
1816 if (selectedRegionOnly && selectionGroup != null)
1818 iSize = selectionGroup.getSize();
1819 seqs = selectionGroup.getSequencesInOrder(alignment);
1820 start = selectionGroup.getStartRes();
1821 end = selectionGroup.getEndRes() + 1;
1825 if (hasHiddenRows() && exportHiddenSeqs)
1827 AlignmentI fullAlignment = alignment.getHiddenSequences()
1828 .getFullAlignment();
1829 iSize = fullAlignment.getHeight();
1830 seqs = fullAlignment.getSequencesArray();
1831 end = fullAlignment.getWidth();
1835 iSize = alignment.getHeight();
1836 seqs = alignment.getSequencesArray();
1837 end = alignment.getWidth();
1841 selection = new String[iSize];
1842 if (alignment.getHiddenColumns() != null
1843 && alignment.getHiddenColumns().hasHiddenColumns())
1845 for (i = 0; i < iSize; i++)
1847 Iterator<int[]> blocks = alignment.getHiddenColumns()
1848 .getVisContigsIterator(start, end + 1, false);
1849 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1854 for (i = 0; i < iSize; i++)
1856 selection[i] = seqs[i].getSequenceAsString(start, end);
1864 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1866 ArrayList<int[]> regions = new ArrayList<>();
1872 HiddenColumns hidden = alignment.getHiddenColumns();
1873 if (hidden != null && hidden.hasHiddenColumns())
1877 start = hidden.visibleToAbsoluteColumn(start);
1880 end = hidden.getNextHiddenBoundary(false, start);
1891 regions.add(new int[] { start, end });
1893 if (hidden != null && hidden.hasHiddenColumns())
1895 start = hidden.visibleToAbsoluteColumn(end);
1896 start = hidden.getNextHiddenBoundary(true, start) + 1;
1898 } while (end < max);
1900 // int[][] startEnd = new int[regions.size()][2];
1906 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1907 boolean selectedOnly)
1909 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1910 AlignmentAnnotation[] aa;
1911 if ((aa = alignment.getAlignmentAnnotation()) != null)
1913 for (AlignmentAnnotation annot : aa)
1915 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1916 if (selectedOnly && selectionGroup != null)
1918 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1919 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1923 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1932 public boolean isPadGaps()
1938 public void setPadGaps(boolean padGaps)
1940 this.padGaps = padGaps;
1944 * apply any post-edit constraints and trigger any calculations needed after
1945 * an edit has been performed on the alignment
1950 public void alignmentChanged(AlignmentViewPanel ap)
1954 alignment.padGaps();
1956 if (autoCalculateConsensus)
1958 updateConsensus(ap);
1959 updateSecondaryStructureConsensus(ap);
1961 if (hconsensus != null && autoCalculateConsensus)
1963 updateConservation(ap);
1965 if (autoCalculateStrucConsensus)
1967 updateStrucConsensus(ap);
1970 // Reset endRes of groups if beyond alignment width
1971 int alWidth = alignment.getWidth();
1972 List<SequenceGroup> groups = alignment.getGroups();
1975 for (SequenceGroup sg : groups)
1977 if (sg.getEndRes() > alWidth)
1979 sg.setEndRes(alWidth - 1);
1984 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1986 selectionGroup.setEndRes(alWidth - 1);
1989 updateAllColourSchemes();
1990 calculator.restartWorkers();
1991 // alignment.adjustSequenceAnnotations();
1995 * reset scope and do calculations for all applied colourschemes on alignment
1997 void updateAllColourSchemes()
1999 ResidueShaderI rs = residueShading;
2002 rs.alignmentChanged(alignment, hiddenRepSequences);
2004 rs.setConsensus(hconsensus);
2005 if (rs.conservationApplied())
2007 rs.setConservation(Conservation.calculateConservation("All",
2008 alignment.getSequences(), 0, alignment.getWidth(), false,
2009 getConsPercGaps(), false));
2013 for (SequenceGroup sg : alignment.getGroups())
2017 sg.cs.alignmentChanged(sg, hiddenRepSequences);
2019 sg.recalcConservation();
2023 protected void initAutoAnnotation()
2025 // TODO: add menu option action that nulls or creates consensus object
2026 // depending on if the user wants to see the annotation or not in a
2027 // specific alignment
2029 if (hconsensus == null && !isDataset)
2031 if (!alignment.isNucleotide())
2040 consensus = new AlignmentAnnotation("Consensus",
2041 MessageManager.getString("label.consensus_descr"),
2042 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2044 secondaryStructureConsensus = new AlignmentAnnotation("SecondaryStructureConsensus",
2045 MessageManager.getString("label.ssconsensus_descr"),
2046 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2048 initConsensus(consensus);
2049 initSSConsensus(secondaryStructureConsensus);
2051 initComplementConsensus();
2057 * If this is a protein alignment and there are mappings to cDNA, adds the
2058 * cDNA consensus annotation and returns true, else returns false.
2060 public boolean initComplementConsensus()
2062 if (!alignment.isNucleotide())
2064 final List<AlignedCodonFrame> codonMappings = alignment
2066 if (codonMappings != null && !codonMappings.isEmpty())
2068 boolean doConsensus = false;
2069 for (AlignedCodonFrame mapping : codonMappings)
2071 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2072 MapList[] mapLists = mapping.getdnaToProt();
2073 // mapLists can be empty if project load has not finished resolving
2075 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2083 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2085 .getString("label.complement_consensus_descr"),
2086 new Annotation[1], 0f, 100f,
2087 AlignmentAnnotation.BAR_GRAPH);
2088 initConsensus(complementConsensus);
2096 private void initConsensus(AlignmentAnnotation aa)
2099 aa.autoCalculated = true;
2103 alignment.addAnnotation(aa);
2107 private void initSSConsensus(AlignmentAnnotation aa)
2110 aa.autoCalculated = true;
2114 alignment.addAnnotation(aa);
2118 // these should be extracted from the view model - style and settings for
2119 // derived annotation
2120 private void initGapCounts()
2124 gapcounts = new AlignmentAnnotation("Occupancy",
2125 MessageManager.getString("label.occupancy_descr"),
2126 new Annotation[1], 0f, alignment.getHeight(),
2127 AlignmentAnnotation.BAR_GRAPH);
2128 gapcounts.hasText = true;
2129 gapcounts.autoCalculated = true;
2130 gapcounts.scaleColLabel = true;
2131 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2133 alignment.addAnnotation(gapcounts);
2137 private void initConservation()
2139 if (showConservation)
2141 if (conservation == null)
2143 conservation = new AlignmentAnnotation("Conservation",
2144 MessageManager.formatMessage("label.conservation_descr",
2146 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2147 conservation.hasText = true;
2148 conservation.autoCalculated = true;
2149 alignment.addAnnotation(conservation);
2154 private void initQuality()
2158 if (quality == null)
2160 quality = new AlignmentAnnotation("Quality",
2161 MessageManager.getString("label.quality_descr"),
2162 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2163 quality.hasText = true;
2164 quality.autoCalculated = true;
2165 alignment.addAnnotation(quality);
2170 private void initRNAStructure()
2172 if (alignment.hasRNAStructure() && strucConsensus == null)
2174 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2175 MessageManager.getString("label.strucconsensus_descr"),
2176 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2177 strucConsensus.hasText = true;
2178 strucConsensus.autoCalculated = true;
2182 alignment.addAnnotation(strucConsensus);
2190 * @see jalview.api.AlignViewportI#calcPanelHeight()
2193 public int calcPanelHeight()
2195 // setHeight of panels
2196 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2198 int charHeight = getCharHeight();
2201 BitSet graphgrp = new BitSet();
2202 for (AlignmentAnnotation aa : anns)
2206 jalview.bin.Console.errPrintln("Null annotation row: ignoring.");
2213 if (aa.graphGroup > -1)
2215 if (graphgrp.get(aa.graphGroup))
2221 graphgrp.set(aa.graphGroup);
2228 aa.height += charHeight;
2238 aa.height += aa.graphHeight + 20;
2246 height += aa.height;
2258 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2259 boolean preserveNewGroupSettings)
2261 boolean updateCalcs = false;
2262 boolean conv = isShowGroupConservation();
2263 boolean cons = isShowGroupConsensus();
2264 boolean showprf = isShowSequenceLogo();
2265 boolean showSSprf = isShowSequenceSSLogo();
2266 boolean showConsHist = isShowConsensusHistogram();
2267 boolean showSSConsHist = isShowSSConsensusHistogram();
2268 boolean normLogo = isNormaliseSequenceLogo();
2271 * TODO reorder the annotation rows according to group/sequence ordering on
2274 // boolean sortg = true;
2276 // remove old automatic annotation
2277 // add any new annotation
2279 // intersect alignment annotation with alignment groups
2281 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2282 List<SequenceGroup> oldrfs = new ArrayList<>();
2285 for (int an = 0; an < aan.length; an++)
2287 if (aan[an].autoCalculated && aan[an].groupRef != null)
2289 oldrfs.add(aan[an].groupRef);
2290 alignment.deleteAnnotation(aan[an], false);
2294 if (alignment.getGroups() != null)
2296 for (SequenceGroup sg : alignment.getGroups())
2298 updateCalcs = false;
2299 if (applyGlobalSettings
2300 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2302 // set defaults for this group's conservation/consensus
2303 sg.setshowSequenceLogo(showprf);
2304 sg.setshowSequenceSSLogo(showSSprf);
2305 sg.setShowConsensusHistogram(showConsHist);
2306 sg.setShowSSConsensusHistogram(showSSConsHist);
2307 sg.setNormaliseSequenceLogo(normLogo);
2312 alignment.addAnnotation(sg.getConservationRow(), 0);
2317 alignment.addAnnotation(sg.getConsensus(), 0);
2318 alignment.addAnnotation(sg.getSSConsensus(), 0);
2320 // refresh the annotation rows
2323 sg.recalcConservation();
2331 public boolean isDisplayReferenceSeq()
2333 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2337 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2339 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2343 public boolean isColourByReferenceSeq()
2345 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2349 public Color getSequenceColour(SequenceI seq)
2351 Color sqc = sequenceColours.get(seq);
2352 return (sqc == null ? Color.white : sqc);
2356 public void setSequenceColour(SequenceI seq, Color col)
2360 sequenceColours.remove(seq);
2364 sequenceColours.put(seq, col);
2369 public void updateSequenceIdColours()
2371 for (SequenceGroup sg : alignment.getGroups())
2373 if (sg.idColour != null)
2375 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2377 sequenceColours.put(s, sg.idColour);
2384 public void clearSequenceColours()
2386 sequenceColours.clear();
2390 public AlignViewportI getCodingComplement()
2392 return this.codingComplement;
2396 * Set this as the (cDna/protein) complement of the given viewport. Also
2397 * ensures the reverse relationship is set on the given viewport.
2400 public void setCodingComplement(AlignViewportI av)
2405 .errPrintln("Ignoring recursive setCodingComplement request");
2409 this.codingComplement = av;
2410 // avoid infinite recursion!
2411 if (av.getCodingComplement() != this)
2413 av.setCodingComplement(this);
2419 public boolean isNucleotide()
2421 return getAlignment() == null ? false : getAlignment().isNucleotide();
2425 public FeaturesDisplayedI getFeaturesDisplayed()
2427 return featuresDisplayed;
2431 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2433 featuresDisplayed = featuresDisplayedI;
2437 public boolean areFeaturesDisplayed()
2439 return featuresDisplayed != null
2440 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2447 * features are displayed if true
2450 public void setShowSequenceFeatures(boolean b)
2452 viewStyle.setShowSequenceFeatures(b);
2456 public boolean isShowSequenceFeatures()
2458 return viewStyle.isShowSequenceFeatures();
2462 public void setShowSequenceFeaturesHeight(boolean selected)
2464 viewStyle.setShowSequenceFeaturesHeight(selected);
2468 public boolean isShowSequenceFeaturesHeight()
2470 return viewStyle.isShowSequenceFeaturesHeight();
2474 public void setShowAnnotation(boolean b)
2476 viewStyle.setShowAnnotation(b);
2480 public boolean isShowAnnotation()
2482 return viewStyle.isShowAnnotation();
2486 public boolean isRightAlignIds()
2488 return viewStyle.isRightAlignIds();
2492 public void setRightAlignIds(boolean rightAlignIds)
2494 viewStyle.setRightAlignIds(rightAlignIds);
2498 public boolean getConservationSelected()
2500 return viewStyle.getConservationSelected();
2504 public void setShowBoxes(boolean state)
2506 viewStyle.setShowBoxes(state);
2511 * @see jalview.api.ViewStyleI#getTextColour()
2514 public Color getTextColour()
2516 return viewStyle.getTextColour();
2521 * @see jalview.api.ViewStyleI#getTextColour2()
2524 public Color getTextColour2()
2526 return viewStyle.getTextColour2();
2531 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2534 public int getThresholdTextColour()
2536 return viewStyle.getThresholdTextColour();
2541 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2544 public boolean isConservationColourSelected()
2546 return viewStyle.isConservationColourSelected();
2551 * @see jalview.api.ViewStyleI#isRenderGaps()
2554 public boolean isRenderGaps()
2556 return viewStyle.isRenderGaps();
2561 * @see jalview.api.ViewStyleI#isShowColourText()
2564 public boolean isShowColourText()
2566 return viewStyle.isShowColourText();
2570 * @param conservationColourSelected
2571 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2574 public void setConservationColourSelected(
2575 boolean conservationColourSelected)
2577 viewStyle.setConservationColourSelected(conservationColourSelected);
2581 * @param showColourText
2582 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2585 public void setShowColourText(boolean showColourText)
2587 viewStyle.setShowColourText(showColourText);
2592 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2595 public void setTextColour(Color textColour)
2597 viewStyle.setTextColour(textColour);
2601 * @param thresholdTextColour
2602 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2605 public void setThresholdTextColour(int thresholdTextColour)
2607 viewStyle.setThresholdTextColour(thresholdTextColour);
2611 * @param textColour2
2612 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2615 public void setTextColour2(Color textColour2)
2617 viewStyle.setTextColour2(textColour2);
2621 public ViewStyleI getViewStyle()
2623 return new ViewStyle(viewStyle);
2627 public void setViewStyle(ViewStyleI settingsForView)
2629 viewStyle = new ViewStyle(settingsForView);
2630 if (residueShading != null)
2632 residueShading.setConservationApplied(
2633 settingsForView.isConservationColourSelected());
2638 public boolean sameStyle(ViewStyleI them)
2640 return viewStyle.sameStyle(them);
2645 * @see jalview.api.ViewStyleI#getIdWidth()
2648 public int getIdWidth()
2650 return viewStyle.getIdWidth();
2655 * @see jalview.api.ViewStyleI#setIdWidth(int)
2658 public void setIdWidth(int i)
2660 viewStyle.setIdWidth(i);
2665 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2668 public boolean isCentreColumnLabels()
2670 return viewStyle.isCentreColumnLabels();
2674 * @param centreColumnLabels
2675 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2678 public void setCentreColumnLabels(boolean centreColumnLabels)
2680 viewStyle.setCentreColumnLabels(centreColumnLabels);
2685 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2688 public void setShowDBRefs(boolean showdbrefs)
2690 viewStyle.setShowDBRefs(showdbrefs);
2695 * @see jalview.api.ViewStyleI#isShowDBRefs()
2698 public boolean isShowDBRefs()
2700 return viewStyle.isShowDBRefs();
2705 * @see jalview.api.ViewStyleI#isShowNPFeats()
2708 public boolean isShowNPFeats()
2710 return viewStyle.isShowNPFeats();
2714 * @param shownpfeats
2715 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2718 public void setShowNPFeats(boolean shownpfeats)
2720 viewStyle.setShowNPFeats(shownpfeats);
2723 public abstract StructureSelectionManager getStructureSelectionManager();
2726 * Add one command to the command history list.
2730 public void addToHistoryList(CommandI command)
2732 if (this.historyList != null)
2734 this.historyList.push(command);
2735 broadcastCommand(command, false);
2736 setSavedUpToDate(false);
2737 Jalview2XML.setStateSavedUpToDate(false);
2741 protected void broadcastCommand(CommandI command, boolean undo)
2743 getStructureSelectionManager().commandPerformed(command, undo,
2748 * Add one command to the command redo list.
2752 public void addToRedoList(CommandI command)
2754 if (this.redoList != null)
2756 this.redoList.push(command);
2758 broadcastCommand(command, true);
2762 * Clear the command redo list.
2764 public void clearRedoList()
2766 if (this.redoList != null)
2768 this.redoList.clear();
2772 public void setHistoryList(Deque<CommandI> list)
2774 this.historyList = list;
2777 public Deque<CommandI> getHistoryList()
2779 return this.historyList;
2782 public void setRedoList(Deque<CommandI> list)
2784 this.redoList = list;
2787 public Deque<CommandI> getRedoList()
2789 return this.redoList;
2793 public VamsasSource getVamsasSource()
2798 public SequenceAnnotationOrder getSortAnnotationsBy()
2800 return sortAnnotationsBy;
2803 public void setSortAnnotationsBy(
2804 SequenceAnnotationOrder sortAnnotationsBy)
2806 this.sortAnnotationsBy = sortAnnotationsBy;
2809 public boolean isShowAutocalculatedAbove()
2811 return showAutocalculatedAbove;
2814 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2816 this.showAutocalculatedAbove = showAutocalculatedAbove;
2820 public boolean isScaleProteinAsCdna()
2822 return viewStyle.isScaleProteinAsCdna();
2826 public void setScaleProteinAsCdna(boolean b)
2828 viewStyle.setScaleProteinAsCdna(b);
2832 public boolean isProteinFontAsCdna()
2834 return viewStyle.isProteinFontAsCdna();
2838 public void setProteinFontAsCdna(boolean b)
2840 viewStyle.setProteinFontAsCdna(b);
2844 public void setShowComplementFeatures(boolean b)
2846 viewStyle.setShowComplementFeatures(b);
2850 public boolean isShowComplementFeatures()
2852 return viewStyle.isShowComplementFeatures();
2856 public void setShowComplementFeaturesOnTop(boolean b)
2858 viewStyle.setShowComplementFeaturesOnTop(b);
2862 public boolean isShowComplementFeaturesOnTop()
2864 return viewStyle.isShowComplementFeaturesOnTop();
2868 * @return true if view should scroll to show the highlighted region of a
2873 public final boolean isFollowHighlight()
2875 return followHighlight;
2879 public final void setFollowHighlight(boolean b)
2881 this.followHighlight = b;
2885 public ViewportRanges getRanges()
2891 * Helper method to populate the SearchResults with the location in the
2892 * complementary alignment to scroll to, in order to match this one.
2895 * the SearchResults to add to
2896 * @return the offset (below top of visible region) of the matched sequence
2898 protected int findComplementScrollTarget(SearchResultsI sr)
2900 final AlignViewportI complement = getCodingComplement();
2901 if (complement == null || !complement.isFollowHighlight())
2905 boolean iAmProtein = !getAlignment().isNucleotide();
2906 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2907 : complement.getAlignment();
2908 if (proteinAlignment == null)
2912 final List<AlignedCodonFrame> mappings = proteinAlignment
2916 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2917 * residue in the middle column of the visible region. Scroll the
2918 * complementary alignment to line up the corresponding residue.
2921 SequenceI sequence = null;
2924 * locate 'middle' column (true middle if an odd number visible, left of
2925 * middle if an even number visible)
2927 int middleColumn = ranges.getStartRes()
2928 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2929 final HiddenSequences hiddenSequences = getAlignment()
2930 .getHiddenSequences();
2933 * searching to the bottom of the alignment gives smoother scrolling across
2934 * all gapped visible regions
2936 int lastSeq = alignment.getHeight() - 1;
2937 List<AlignedCodonFrame> seqMappings = null;
2938 for (int seqNo = ranges
2939 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2941 sequence = getAlignment().getSequenceAt(seqNo);
2942 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2946 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2950 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2952 getCodingComplement().getAlignment().getSequences());
2953 if (!seqMappings.isEmpty())
2959 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2962 * No ungapped mapped sequence in middle column - do nothing
2966 MappingUtils.addSearchResults(sr, sequence,
2967 sequence.findPosition(middleColumn), seqMappings);
2972 * synthesize a column selection if none exists so it covers the given
2973 * selection group. if wholewidth is false, no column selection is made if the
2974 * selection group covers the whole alignment width.
2979 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2982 if (sg != null && (sgs = sg.getStartRes()) >= 0
2983 && sg.getStartRes() <= (sge = sg.getEndRes())
2984 && !this.hasSelectedColumns())
2986 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2993 colSel = new ColumnSelection();
2995 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2997 colSel.addElement(cspos);
3003 * hold status of current selection group - defined on alignment or not.
3005 private boolean selectionIsDefinedGroup = false;
3008 public boolean isSelectionDefinedGroup()
3010 if (selectionGroup == null)
3014 if (isSelectionGroupChanged(true))
3016 selectionIsDefinedGroup = false;
3017 List<SequenceGroup> gps = alignment.getGroups();
3018 if (gps == null || gps.size() == 0)
3020 selectionIsDefinedGroup = false;
3024 selectionIsDefinedGroup = gps.contains(selectionGroup);
3027 return selectionGroup.isDefined() || selectionIsDefinedGroup;
3031 * null, or currently highlighted results on this view
3033 private SearchResultsI searchResults = null;
3035 protected TreeModel currentTree = null;
3038 public boolean hasSearchResults()
3040 return searchResults != null;
3044 public void setSearchResults(SearchResultsI results)
3046 searchResults = results;
3050 public SearchResultsI getSearchResults()
3052 return searchResults;
3056 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
3058 return alignment.getContactListFor(_aa, column);
3062 public ContactMatrixI getContactMatrix(
3063 AlignmentAnnotation alignmentAnnotation)
3065 return alignment.getContactMatrixFor(alignmentAnnotation);
3069 * get the consensus sequence as displayed under the PID consensus annotation
3072 * @return consensus sequence as a new sequence object
3074 public SequenceI getConsensusSeq()
3076 if (consensus == null)
3078 updateConsensus(null);
3080 if (consensus == null)
3084 StringBuffer seqs = new StringBuffer();
3085 for (int i = 0; i < consensus.annotations.length; i++)
3087 Annotation annotation = consensus.annotations[i];
3088 if (annotation != null)
3090 String description = annotation.description;
3091 if (description != null && description.startsWith("["))
3093 // consensus is a tie - just pick the first one
3094 seqs.append(description.charAt(1));
3098 seqs.append(annotation.displayCharacter);
3103 SequenceI sq = new Sequence("Consensus", seqs.toString());
3104 sq.setDescription("Percentage Identity Consensus "
3105 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3109 public SequenceI getSSConsensusSeq()
3111 if (secondaryStructureConsensus == null)
3113 updateSecondaryStructureConsensus(null);
3115 if (secondaryStructureConsensus == null)
3119 StringBuffer seqs = new StringBuffer();
3120 for (int i = 0; i < secondaryStructureConsensus.annotations.length; i++)
3122 Annotation annotation = secondaryStructureConsensus.annotations[i];
3123 if (annotation != null)
3125 String description = annotation.description;
3126 if (description != null && description.startsWith("["))
3128 // consensus is a tie - just pick the first one
3129 seqs.append(description.charAt(1));
3133 seqs.append(annotation.displayCharacter);
3138 SequenceI sq = new Sequence("Sec Str Consensus", seqs.toString());
3139 sq.setDescription("Percentage Identity Sec Str Consensus "
3140 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3145 public void setCurrentTree(TreeModel tree)
3151 public TreeModel getCurrentTree()
3157 public AlignmentExportData getAlignExportData(
3158 AlignExportSettingsI options)
3160 AlignmentI alignmentToExport = null;
3161 String[] omitHidden = null;
3162 alignmentToExport = null;
3164 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3166 omitHidden = getViewAsString(false,
3167 options.isExportHiddenSequences());
3170 int[] alignmentStartEnd = new int[2];
3171 if (hasHiddenRows() && options.isExportHiddenSequences())
3173 alignmentToExport = getAlignment().getHiddenSequences()
3174 .getFullAlignment();
3178 alignmentToExport = getAlignment();
3180 alignmentStartEnd = getAlignment().getHiddenColumns()
3181 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3182 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3183 omitHidden, alignmentStartEnd);
3188 * flag set to indicate if structure views might be out of sync with sequences
3192 private boolean needToUpdateStructureViews = false;
3195 public boolean isUpdateStructures()
3197 return needToUpdateStructureViews;
3201 public void setUpdateStructures(boolean update)
3203 needToUpdateStructureViews = update;
3207 public boolean needToUpdateStructureViews()
3209 boolean update = needToUpdateStructureViews;
3210 needToUpdateStructureViews = false;
3215 public void addSequenceGroup(SequenceGroup sequenceGroup)
3217 alignment.addGroup(sequenceGroup);
3219 Color col = sequenceGroup.idColour;
3222 col = col.brighter();
3224 for (SequenceI sq : sequenceGroup.getSequences())
3226 setSequenceColour(sq, col);
3230 if (codingComplement != null)
3232 SequenceGroup mappedGroup = MappingUtils
3233 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3234 if (mappedGroup.getSequences().size() > 0)
3236 codingComplement.getAlignment().addGroup(mappedGroup);
3240 for (SequenceI seq : mappedGroup.getSequences())
3242 codingComplement.setSequenceColour(seq, col);
3246 // propagate the structure view update flag according to our own setting
3247 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3252 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3256 if (selectedRegionOnly && selectionGroup != null)
3258 start = selectionGroup.getStartRes();
3259 end = selectionGroup.getEndRes() + 1;
3263 end = alignment.getWidth();
3265 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3269 public void setSavedUpToDate(boolean s)
3271 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3274 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3277 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3279 QuitHandler.setMessage(m);
3282 public boolean savedUpToDate()
3284 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3286 return savedUpToDate;