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.AlignmentComparisonThread;
78 import jalview.workers.ComplementConsensusThread;
79 import jalview.workers.ConsensusThread;
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 complementConsensus;
704 protected AlignmentAnnotation gapcounts;
706 protected AlignmentAnnotation strucConsensus;
708 protected AlignmentAnnotation conservation;
710 protected AlignmentAnnotation quality;
712 protected AlignmentAnnotation[] groupConsensus;
714 protected AlignmentAnnotation[] groupConservation;
717 * results of alignment consensus analysis for visible portion of view
719 protected ProfilesI hconsensus = null;
722 * results of cDNA complement consensus visible portion of view
724 protected Hashtable<String, Object>[] hcomplementConsensus = null;
727 * results of secondary structure base pair consensus for visible portion of
730 protected Hashtable<String, Object>[] hStrucConsensus = null;
732 protected Conservation hconservation = null;
735 public void setConservation(Conservation cons)
737 hconservation = cons;
741 * percentage gaps allowed in a column before all amino acid properties should
742 * be considered unconserved
744 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
747 public int getConsPercGaps()
753 public void setSequenceConsensusHash(ProfilesI hconsensus)
755 this.hconsensus = hconsensus;
759 public void setComplementConsensusHash(
760 Hashtable<String, Object>[] hconsensus)
762 this.hcomplementConsensus = hconsensus;
766 public ProfilesI getSequenceConsensusHash()
772 public Hashtable<String, Object>[] getComplementConsensusHash()
774 return hcomplementConsensus;
778 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
780 return hStrucConsensus;
784 public void setRnaStructureConsensusHash(
785 Hashtable<String, Object>[] hStrucConsensus)
787 this.hStrucConsensus = hStrucConsensus;
792 public AlignmentAnnotation getAlignmentQualityAnnot()
798 public AlignmentAnnotation getAlignmentConservationAnnotation()
804 public AlignmentAnnotation getAlignmentConsensusAnnotation()
810 public AlignmentAnnotation getAlignmentGapAnnotation()
816 public AlignmentAnnotation getComplementConsensusAnnotation()
818 return complementConsensus;
822 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
824 return strucConsensus;
827 protected AlignCalcManagerI calculator = new AlignCalcManager();
830 * trigger update of conservation annotation
832 public void updateConservation(final AlignmentViewPanel ap)
834 // see note in mantis : issue number 8585
835 if (alignment.isNucleotide()
836 || (conservation == null && quality == null)
837 || !autoCalculateConsensus)
841 if (calculator.getRegisteredWorkersOfClass(
842 jalview.workers.ConservationThread.class) == null)
844 calculator.registerWorker(
845 new jalview.workers.ConservationThread(this, ap));
850 * trigger update of consensus annotation
852 public void updateConsensus(final AlignmentViewPanel ap)
854 // see note in mantis : issue number 8585
855 if (consensus == null || !autoCalculateConsensus)
860 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
862 calculator.registerWorker(new ConsensusThread(this, ap));
866 * A separate thread to compute cDNA consensus for a protein alignment
867 * which has mapping to cDNA
869 final AlignmentI al = this.getAlignment();
870 if (!al.isNucleotide() && al.getCodonFrames() != null
871 && !al.getCodonFrames().isEmpty())
874 * fudge - check first for protein-to-nucleotide mappings
875 * (we don't want to do this for protein-to-protein)
877 boolean doConsensus = false;
878 for (AlignedCodonFrame mapping : al.getCodonFrames())
880 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
881 MapList[] mapLists = mapping.getdnaToProt();
882 // mapLists can be empty if project load has not finished resolving seqs
883 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
891 if (calculator.getRegisteredWorkersOfClass(
892 ComplementConsensusThread.class) == null)
895 .registerWorker(new ComplementConsensusThread(this, ap));
899 if (getCodingComplement() != null)
901 if (getCodingComplement().isNucleotide() == isNucleotide())
903 if (calculator.getRegisteredWorkersOfClass(
904 AlignmentComparisonThread.class) == null)
907 .registerWorker(new AlignmentComparisonThread(this, ap));
913 // --------START Structure Conservation
914 public void updateStrucConsensus(final AlignmentViewPanel ap)
916 if (autoCalculateStrucConsensus && strucConsensus == null
917 && alignment.isNucleotide() && alignment.hasRNAStructure())
919 // secondary structure has been added - so init the consensus line
923 // see note in mantis : issue number 8585
924 if (strucConsensus == null || !autoCalculateStrucConsensus)
928 if (calculator.getRegisteredWorkersOfClass(
929 StrucConsensusThread.class) == null)
931 calculator.registerWorker(new StrucConsensusThread(this, ap));
935 public boolean isCalcInProgress()
937 return calculator.isWorking();
941 public boolean isCalculationInProgress(
942 AlignmentAnnotation alignmentAnnotation)
944 if (!alignmentAnnotation.autoCalculated)
948 if (calculator.workingInvolvedWith(alignmentAnnotation))
950 // jalview.bin.Console.errPrintln("grey out
951 // ("+alignmentAnnotation.label+")");
957 public void setAlignment(AlignmentI align)
959 this.alignment = align;
963 * Clean up references when this viewport is closed
966 public void dispose()
969 * defensively null out references to large objects in case
970 * this object is not garbage collected (as if!)
973 complementConsensus = null;
974 strucConsensus = null;
977 groupConsensus = null;
978 groupConservation = null;
980 hconservation = null;
981 hcomplementConsensus = null;
984 residueShading = null; // may hold a reference to Consensus
985 changeSupport = null;
988 selectionGroup = null;
994 public boolean isClosed()
996 // TODO: check that this isClosed is only true after panel is closed, not
997 // before it is fully constructed.
998 return alignment == null;
1002 public AlignCalcManagerI getCalcManager()
1008 * should conservation rows be shown for groups
1010 protected boolean showGroupConservation = false;
1013 * should consensus rows be shown for groups
1015 protected boolean showGroupConsensus = false;
1018 * should consensus profile be rendered by default
1020 protected boolean showSequenceLogo = false;
1023 * should consensus profile be rendered normalised to row height
1025 protected boolean normaliseSequenceLogo = false;
1028 * should consensus histograms be rendered by default
1030 protected boolean showConsensusHistogram = true;
1033 * @return the showConsensusProfile
1036 public boolean isShowSequenceLogo()
1038 return showSequenceLogo;
1042 * @param showSequenceLogo
1045 public void setShowSequenceLogo(boolean showSequenceLogo)
1047 if (showSequenceLogo != this.showSequenceLogo)
1049 // TODO: decouple settings setting from calculation when refactoring
1050 // annotation update method from alignframe to viewport
1051 this.showSequenceLogo = showSequenceLogo;
1052 calculator.updateAnnotationFor(ConsensusThread.class);
1053 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1054 calculator.updateAnnotationFor(StrucConsensusThread.class);
1056 this.showSequenceLogo = showSequenceLogo;
1060 * @param showConsensusHistogram
1061 * the showConsensusHistogram to set
1063 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1065 this.showConsensusHistogram = showConsensusHistogram;
1069 * @return the showGroupConservation
1071 public boolean isShowGroupConservation()
1073 return showGroupConservation;
1077 * @param showGroupConservation
1078 * the showGroupConservation to set
1080 public void setShowGroupConservation(boolean showGroupConservation)
1082 this.showGroupConservation = showGroupConservation;
1086 * @return the showGroupConsensus
1088 public boolean isShowGroupConsensus()
1090 return showGroupConsensus;
1094 * @param showGroupConsensus
1095 * the showGroupConsensus to set
1097 public void setShowGroupConsensus(boolean showGroupConsensus)
1099 this.showGroupConsensus = showGroupConsensus;
1104 * @return flag to indicate if the consensus histogram should be rendered by
1108 public boolean isShowConsensusHistogram()
1110 return this.showConsensusHistogram;
1114 * when set, updateAlignment will always ensure sequences are of equal length
1116 private boolean padGaps = false;
1119 * when set, alignment should be reordered according to a newly opened tree
1121 public boolean sortByTree = false;
1126 * @return null or the currently selected sequence region
1129 public SequenceGroup getSelectionGroup()
1131 return selectionGroup;
1135 * Set the selection group for this window. Also sets the current alignment as
1136 * the context for the group, if it does not already have one.
1139 * - group holding references to sequences in this alignment view
1143 public void setSelectionGroup(SequenceGroup sg)
1145 selectionGroup = sg;
1146 if (sg != null && sg.getContext() == null)
1148 sg.setContext(alignment);
1152 public void setHiddenColumns(HiddenColumns hidden)
1154 this.alignment.setHiddenColumns(hidden);
1158 public ColumnSelection getColumnSelection()
1164 public void setColumnSelection(ColumnSelection colSel)
1166 this.colSel = colSel;
1169 updateHiddenColumns();
1171 isColSelChanged(true);
1179 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1181 return hiddenRepSequences;
1185 public void setHiddenRepSequences(
1186 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1188 this.hiddenRepSequences = hiddenRepSequences;
1192 public boolean hasSelectedColumns()
1194 ColumnSelection columnSelection = getColumnSelection();
1195 return columnSelection != null && columnSelection.hasSelectedColumns();
1199 public boolean hasHiddenColumns()
1201 return alignment.getHiddenColumns() != null
1202 && alignment.getHiddenColumns().hasHiddenColumns();
1205 public void updateHiddenColumns()
1207 // this method doesn't really do anything now. But - it could, since a
1208 // column Selection could be in the process of modification
1209 // hasHiddenColumns = colSel.hasHiddenColumns();
1213 public boolean hasHiddenRows()
1215 return alignment.getHiddenSequences().getSize() > 0;
1218 protected SequenceGroup selectionGroup;
1220 public void setSequenceSetId(String newid)
1222 if (sequenceSetID != null)
1224 jalview.bin.Console.errPrintln(
1225 "Warning - overwriting a sequenceSetId for a viewport!");
1227 sequenceSetID = new String(newid);
1231 public String getSequenceSetId()
1233 if (sequenceSetID == null)
1235 sequenceSetID = alignment.hashCode() + "";
1238 return sequenceSetID;
1242 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1245 protected String viewId = null;
1248 public String getViewId()
1252 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1257 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1259 ignoreGapsInConsensusCalculation = b;
1262 updateConsensus(ap);
1263 if (residueShading != null)
1265 residueShading.setThreshold(residueShading.getThreshold(),
1266 ignoreGapsInConsensusCalculation);
1272 private long sgrouphash = -1, colselhash = -1;
1275 * checks current SelectionGroup against record of last hash value, and
1279 * update the record of last hash value
1281 * @return true if SelectionGroup changed since last call (when b is true)
1283 public boolean isSelectionGroupChanged(boolean b)
1285 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1286 : selectionGroup.hashCode();
1287 if (hc != -1 && hc != sgrouphash)
1299 * checks current colsel against record of last hash value, and optionally
1303 * update the record of last hash value
1304 * @return true if colsel changed since last call (when b is true)
1306 public boolean isColSelChanged(boolean b)
1308 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1309 if (hc != -1 && hc != colselhash)
1321 public boolean isIgnoreGapsConsensus()
1323 return ignoreGapsInConsensusCalculation;
1326 // property change stuff
1327 // JBPNote Prolly only need this in the applet version.
1328 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1331 protected boolean showConservation = true;
1333 protected boolean showQuality = true;
1335 protected boolean showConsensus = true;
1337 protected boolean showOccupancy = true;
1339 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1341 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1343 protected boolean showAutocalculatedAbove;
1346 * when set, view will scroll to show the highlighted position
1348 private boolean followHighlight = true;
1351 * Property change listener for changes in alignment
1356 public void addPropertyChangeListener(
1357 java.beans.PropertyChangeListener listener)
1359 changeSupport.addPropertyChangeListener(listener);
1368 public void removePropertyChangeListener(
1369 java.beans.PropertyChangeListener listener)
1371 if (changeSupport != null)
1373 changeSupport.removePropertyChangeListener(listener);
1378 * Property change listener for changes in alignment
1387 public void firePropertyChange(String prop, Object oldvalue,
1390 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1393 // common hide/show column stuff
1395 public void hideSelectedColumns()
1397 if (colSel.isEmpty())
1402 colSel.hideSelectedColumns(alignment);
1403 setSelectionGroup(null);
1404 isColSelChanged(true);
1407 public void hideColumns(int start, int end)
1411 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1415 alignment.getHiddenColumns().hideColumns(start, end);
1417 isColSelChanged(true);
1420 public void showColumn(int col)
1422 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1423 isColSelChanged(true);
1426 public void showAllHiddenColumns()
1428 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1429 isColSelChanged(true);
1432 // common hide/show seq stuff
1433 public void showAllHiddenSeqs()
1435 int startSeq = ranges.getStartSeq();
1436 int endSeq = ranges.getEndSeq();
1438 if (alignment.getHiddenSequences().getSize() > 0)
1440 if (selectionGroup == null)
1442 selectionGroup = new SequenceGroup();
1443 selectionGroup.setEndRes(alignment.getWidth() - 1);
1445 List<SequenceI> tmp = alignment.getHiddenSequences()
1446 .showAll(hiddenRepSequences);
1447 for (SequenceI seq : tmp)
1449 selectionGroup.addSequence(seq, false);
1450 setSequenceAnnotationsVisible(seq, true);
1453 hiddenRepSequences = null;
1455 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1457 firePropertyChange("alignment", null, alignment.getSequences());
1458 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1464 public void showSequence(int index)
1466 int startSeq = ranges.getStartSeq();
1467 int endSeq = ranges.getEndSeq();
1469 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1470 hiddenRepSequences);
1473 if (selectionGroup == null)
1475 selectionGroup = new SequenceGroup();
1476 selectionGroup.setEndRes(alignment.getWidth() - 1);
1479 for (SequenceI seq : tmp)
1481 selectionGroup.addSequence(seq, false);
1482 setSequenceAnnotationsVisible(seq, true);
1485 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1487 firePropertyChange("alignment", null, alignment.getSequences());
1492 public void hideAllSelectedSeqs()
1494 if (selectionGroup == null || selectionGroup.getSize() < 1)
1499 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1503 setSelectionGroup(null);
1506 public void hideSequence(SequenceI[] seq)
1509 * cache offset to first visible sequence
1511 int startSeq = ranges.getStartSeq();
1515 for (int i = 0; i < seq.length; i++)
1517 alignment.getHiddenSequences().hideSequence(seq[i]);
1518 setSequenceAnnotationsVisible(seq[i], false);
1520 ranges.setStartSeq(startSeq);
1521 firePropertyChange("alignment", null, alignment.getSequences());
1526 * Hides the specified sequence, or the sequences it represents
1529 * the sequence to hide, or keep as representative
1530 * @param representGroup
1531 * if true, hide the current selection group except for the
1532 * representative sequence
1534 public void hideSequences(SequenceI sequence, boolean representGroup)
1536 if (selectionGroup == null || selectionGroup.getSize() < 1)
1538 hideSequence(new SequenceI[] { sequence });
1544 hideRepSequences(sequence, selectionGroup);
1545 setSelectionGroup(null);
1549 int gsize = selectionGroup.getSize();
1550 SequenceI[] hseqs = selectionGroup.getSequences()
1551 .toArray(new SequenceI[gsize]);
1553 hideSequence(hseqs);
1554 setSelectionGroup(null);
1559 * Set visibility for any annotations for the given sequence.
1563 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1566 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1569 for (AlignmentAnnotation ann : anns)
1571 if (ann.sequenceRef == sequenceI)
1573 ann.visible = visible;
1579 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1581 int sSize = sg.getSize();
1587 if (hiddenRepSequences == null)
1589 hiddenRepSequences = new Hashtable<>();
1592 hiddenRepSequences.put(repSequence, sg);
1594 // Hide all sequences except the repSequence
1595 SequenceI[] seqs = new SequenceI[sSize - 1];
1597 for (int i = 0; i < sSize; i++)
1599 if (sg.getSequenceAt(i) != repSequence)
1601 if (index == sSize - 1)
1606 seqs[index++] = sg.getSequenceAt(i);
1609 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1610 sg.setHidereps(true); // note: not done in 2.7applet
1617 * @return null or the current reference sequence
1619 public SequenceI getReferenceSeq()
1621 return alignment.getSeqrep();
1626 * @return true iff seq is the reference for the alignment
1628 public boolean isReferenceSeq(SequenceI seq)
1630 return alignment.getSeqrep() == seq;
1636 * @return true if there are sequences represented by this sequence that are
1639 public boolean isHiddenRepSequence(SequenceI seq)
1641 return (hiddenRepSequences != null
1642 && hiddenRepSequences.containsKey(seq));
1648 * @return null or a sequence group containing the sequences that seq
1651 public SequenceGroup getRepresentedSequences(SequenceI seq)
1653 return (SequenceGroup) (hiddenRepSequences == null ? null
1654 : hiddenRepSequences.get(seq));
1658 public int adjustForHiddenSeqs(int alignmentIndex)
1660 return alignment.getHiddenSequences()
1661 .adjustForHiddenSeqs(alignmentIndex);
1665 public void invertColumnSelection()
1667 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1668 isColSelChanged(true);
1672 public SequenceI[] getSelectionAsNewSequence()
1674 SequenceI[] sequences;
1675 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1676 // this was the only caller in the applet for this method
1677 // JBPNote: in applet, this method returned references to the alignment
1678 // sequences, and it did not honour the presence/absence of annotation
1679 // attached to the alignment (probably!)
1680 if (selectionGroup == null || selectionGroup.getSize() == 0)
1682 sequences = alignment.getSequencesArray();
1683 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1684 for (int i = 0; i < sequences.length; i++)
1686 // construct new sequence with subset of visible annotation
1687 sequences[i] = new Sequence(sequences[i], annots);
1692 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1699 public SequenceI[] getSequenceSelection()
1701 SequenceI[] sequences = null;
1702 if (selectionGroup != null)
1704 sequences = selectionGroup.getSequencesInOrder(alignment);
1706 if (sequences == null)
1708 sequences = alignment.getSequencesArray();
1714 public jalview.datamodel.AlignmentView getAlignmentView(
1715 boolean selectedOnly)
1717 return getAlignmentView(selectedOnly, false);
1721 public jalview.datamodel.AlignmentView getAlignmentView(
1722 boolean selectedOnly, boolean markGroups)
1724 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1726 alignment.getHiddenColumns() != null
1727 && alignment.getHiddenColumns().hasHiddenColumns(),
1728 selectedOnly, markGroups);
1732 public String[] getViewAsString(boolean selectedRegionOnly)
1734 return getViewAsString(selectedRegionOnly, true);
1738 public String[] getViewAsString(boolean selectedRegionOnly,
1739 boolean exportHiddenSeqs)
1741 String[] selection = null;
1742 SequenceI[] seqs = null;
1744 int start = 0, end = 0;
1745 if (selectedRegionOnly && selectionGroup != null)
1747 iSize = selectionGroup.getSize();
1748 seqs = selectionGroup.getSequencesInOrder(alignment);
1749 start = selectionGroup.getStartRes();
1750 end = selectionGroup.getEndRes() + 1;
1754 if (hasHiddenRows() && exportHiddenSeqs)
1756 AlignmentI fullAlignment = alignment.getHiddenSequences()
1757 .getFullAlignment();
1758 iSize = fullAlignment.getHeight();
1759 seqs = fullAlignment.getSequencesArray();
1760 end = fullAlignment.getWidth();
1764 iSize = alignment.getHeight();
1765 seqs = alignment.getSequencesArray();
1766 end = alignment.getWidth();
1770 selection = new String[iSize];
1771 if (alignment.getHiddenColumns() != null
1772 && alignment.getHiddenColumns().hasHiddenColumns())
1774 for (i = 0; i < iSize; i++)
1776 Iterator<int[]> blocks = alignment.getHiddenColumns()
1777 .getVisContigsIterator(start, end + 1, false);
1778 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1783 for (i = 0; i < iSize; i++)
1785 selection[i] = seqs[i].getSequenceAsString(start, end);
1793 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1795 ArrayList<int[]> regions = new ArrayList<>();
1801 HiddenColumns hidden = alignment.getHiddenColumns();
1802 if (hidden != null && hidden.hasHiddenColumns())
1806 start = hidden.visibleToAbsoluteColumn(start);
1809 end = hidden.getNextHiddenBoundary(false, start);
1820 regions.add(new int[] { start, end });
1822 if (hidden != null && hidden.hasHiddenColumns())
1824 start = hidden.visibleToAbsoluteColumn(end);
1825 start = hidden.getNextHiddenBoundary(true, start) + 1;
1827 } while (end < max);
1829 // int[][] startEnd = new int[regions.size()][2];
1835 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1836 boolean selectedOnly)
1838 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1839 AlignmentAnnotation[] aa;
1840 if ((aa = alignment.getAlignmentAnnotation()) != null)
1842 for (AlignmentAnnotation annot : aa)
1844 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1845 if (selectedOnly && selectionGroup != null)
1847 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1848 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1852 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1861 public boolean isPadGaps()
1867 public void setPadGaps(boolean padGaps)
1869 this.padGaps = padGaps;
1873 * apply any post-edit constraints and trigger any calculations needed after
1874 * an edit has been performed on the alignment
1879 public void alignmentChanged(AlignmentViewPanel ap)
1883 alignment.padGaps();
1885 if (autoCalculateConsensus)
1887 updateConsensus(ap);
1889 if (hconsensus != null && autoCalculateConsensus)
1891 updateConservation(ap);
1893 if (autoCalculateStrucConsensus)
1895 updateStrucConsensus(ap);
1898 // Reset endRes of groups if beyond alignment width
1899 int alWidth = alignment.getWidth();
1900 List<SequenceGroup> groups = alignment.getGroups();
1903 for (SequenceGroup sg : groups)
1905 if (sg.getEndRes() > alWidth)
1907 sg.setEndRes(alWidth - 1);
1912 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1914 selectionGroup.setEndRes(alWidth - 1);
1917 updateAllColourSchemes();
1918 calculator.restartWorkers();
1919 // alignment.adjustSequenceAnnotations();
1923 * reset scope and do calculations for all applied colourschemes on alignment
1925 void updateAllColourSchemes()
1927 ResidueShaderI rs = residueShading;
1930 rs.alignmentChanged(alignment, hiddenRepSequences);
1932 rs.setConsensus(hconsensus);
1933 if (rs.conservationApplied())
1935 rs.setConservation(Conservation.calculateConservation("All",
1936 alignment.getSequences(), 0, alignment.getWidth(), false,
1937 getConsPercGaps(), false));
1941 for (SequenceGroup sg : alignment.getGroups())
1945 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1947 sg.recalcConservation();
1951 protected void initAutoAnnotation()
1953 // TODO: add menu option action that nulls or creates consensus object
1954 // depending on if the user wants to see the annotation or not in a
1955 // specific alignment
1957 if (hconsensus == null && !isDataset)
1959 if (!alignment.isNucleotide())
1968 consensus = new AlignmentAnnotation("Consensus",
1969 MessageManager.getString("label.consensus_descr"),
1970 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1971 initConsensus(consensus);
1974 initComplementConsensus();
1979 * If this is a protein alignment and there are mappings to cDNA, adds the
1980 * cDNA consensus annotation and returns true, else returns false.
1982 public boolean initComplementConsensus()
1984 if (!alignment.isNucleotide())
1986 final List<AlignedCodonFrame> codonMappings = alignment
1988 if (codonMappings != null && !codonMappings.isEmpty())
1990 boolean doConsensus = false;
1991 for (AlignedCodonFrame mapping : codonMappings)
1993 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1994 MapList[] mapLists = mapping.getdnaToProt();
1995 // mapLists can be empty if project load has not finished resolving
1997 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2005 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2007 .getString("label.complement_consensus_descr"),
2008 new Annotation[1], 0f, 100f,
2009 AlignmentAnnotation.BAR_GRAPH);
2010 initConsensus(complementConsensus);
2018 private void initConsensus(AlignmentAnnotation aa)
2021 aa.autoCalculated = true;
2025 alignment.addAnnotation(aa);
2029 // these should be extracted from the view model - style and settings for
2030 // derived annotation
2031 private void initGapCounts()
2035 gapcounts = new AlignmentAnnotation("Occupancy",
2036 MessageManager.getString("label.occupancy_descr"),
2037 new Annotation[1], 0f, alignment.getHeight(),
2038 AlignmentAnnotation.BAR_GRAPH);
2039 gapcounts.hasText = true;
2040 gapcounts.autoCalculated = true;
2041 gapcounts.scaleColLabel = true;
2042 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2044 alignment.addAnnotation(gapcounts);
2048 private void initConservation()
2050 if (showConservation)
2052 if (conservation == null)
2054 conservation = new AlignmentAnnotation("Conservation",
2055 MessageManager.formatMessage("label.conservation_descr",
2057 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2058 conservation.hasText = true;
2059 conservation.autoCalculated = true;
2060 alignment.addAnnotation(conservation);
2065 private void initQuality()
2069 if (quality == null)
2071 quality = new AlignmentAnnotation("Quality",
2072 MessageManager.getString("label.quality_descr"),
2073 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2074 quality.hasText = true;
2075 quality.autoCalculated = true;
2076 alignment.addAnnotation(quality);
2081 private void initRNAStructure()
2083 if (alignment.hasRNAStructure() && strucConsensus == null)
2085 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2086 MessageManager.getString("label.strucconsensus_descr"),
2087 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2088 strucConsensus.hasText = true;
2089 strucConsensus.autoCalculated = true;
2093 alignment.addAnnotation(strucConsensus);
2101 * @see jalview.api.AlignViewportI#calcPanelHeight()
2104 public int calcPanelHeight()
2106 // setHeight of panels
2107 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2109 int charHeight = getCharHeight();
2112 BitSet graphgrp = new BitSet();
2113 for (AlignmentAnnotation aa : anns)
2117 jalview.bin.Console.errPrintln("Null annotation row: ignoring.");
2124 if (aa.graphGroup > -1)
2126 if (graphgrp.get(aa.graphGroup))
2132 graphgrp.set(aa.graphGroup);
2139 aa.height += charHeight;
2149 aa.height += aa.graphHeight + 20;
2157 height += aa.height;
2169 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2170 boolean preserveNewGroupSettings)
2172 boolean updateCalcs = false;
2173 boolean conv = isShowGroupConservation();
2174 boolean cons = isShowGroupConsensus();
2175 boolean showprf = isShowSequenceLogo();
2176 boolean showConsHist = isShowConsensusHistogram();
2177 boolean normLogo = isNormaliseSequenceLogo();
2180 * TODO reorder the annotation rows according to group/sequence ordering on
2183 // boolean sortg = true;
2185 // remove old automatic annotation
2186 // add any new annotation
2188 // intersect alignment annotation with alignment groups
2190 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2191 List<SequenceGroup> oldrfs = new ArrayList<>();
2194 for (int an = 0; an < aan.length; an++)
2196 if (aan[an].autoCalculated && aan[an].groupRef != null)
2198 oldrfs.add(aan[an].groupRef);
2199 alignment.deleteAnnotation(aan[an], false);
2203 if (alignment.getGroups() != null)
2205 for (SequenceGroup sg : alignment.getGroups())
2207 updateCalcs = false;
2208 if (applyGlobalSettings
2209 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2211 // set defaults for this group's conservation/consensus
2212 sg.setshowSequenceLogo(showprf);
2213 sg.setShowConsensusHistogram(showConsHist);
2214 sg.setNormaliseSequenceLogo(normLogo);
2219 alignment.addAnnotation(sg.getConservationRow(), 0);
2224 alignment.addAnnotation(sg.getConsensus(), 0);
2226 // refresh the annotation rows
2229 sg.recalcConservation();
2237 public boolean isDisplayReferenceSeq()
2239 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2243 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2245 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2249 public boolean isColourByReferenceSeq()
2251 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2255 public Color getSequenceColour(SequenceI seq)
2257 Color sqc = sequenceColours.get(seq);
2258 return (sqc == null ? Color.white : sqc);
2262 public void setSequenceColour(SequenceI seq, Color col)
2266 sequenceColours.remove(seq);
2270 sequenceColours.put(seq, col);
2275 public void updateSequenceIdColours()
2277 for (SequenceGroup sg : alignment.getGroups())
2279 if (sg.idColour != null)
2281 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2283 sequenceColours.put(s, sg.idColour);
2290 public void clearSequenceColours()
2292 sequenceColours.clear();
2296 public AlignViewportI getCodingComplement()
2298 return this.codingComplement;
2302 * Set this as the (cDna/protein) complement of the given viewport. Also
2303 * ensures the reverse relationship is set on the given viewport.
2306 public void setCodingComplement(AlignViewportI av)
2311 .errPrintln("Ignoring recursive setCodingComplement request");
2315 this.codingComplement = av;
2316 // avoid infinite recursion!
2317 if (av.getCodingComplement() != this)
2319 av.setCodingComplement(this);
2325 public boolean is3di()
2327 return getAlignment() == null ? false
2328 : !isNucleotide() && getGlobalColourScheme() != null
2329 && "3Di-gecos".equalsIgnoreCase(
2330 getGlobalColourScheme().getSchemeName());
2333 public boolean isNucleotide()
2335 return getAlignment() == null ? false : getAlignment().isNucleotide();
2339 public FeaturesDisplayedI getFeaturesDisplayed()
2341 return featuresDisplayed;
2345 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2347 featuresDisplayed = featuresDisplayedI;
2351 public boolean areFeaturesDisplayed()
2353 return featuresDisplayed != null
2354 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2361 * features are displayed if true
2364 public void setShowSequenceFeatures(boolean b)
2366 viewStyle.setShowSequenceFeatures(b);
2370 public boolean isShowSequenceFeatures()
2372 return viewStyle.isShowSequenceFeatures();
2376 public void setShowSequenceFeaturesHeight(boolean selected)
2378 viewStyle.setShowSequenceFeaturesHeight(selected);
2382 public boolean isShowSequenceFeaturesHeight()
2384 return viewStyle.isShowSequenceFeaturesHeight();
2388 public void setShowAnnotation(boolean b)
2390 viewStyle.setShowAnnotation(b);
2394 public boolean isShowAnnotation()
2396 return viewStyle.isShowAnnotation();
2400 public boolean isRightAlignIds()
2402 return viewStyle.isRightAlignIds();
2406 public void setRightAlignIds(boolean rightAlignIds)
2408 viewStyle.setRightAlignIds(rightAlignIds);
2412 public boolean getConservationSelected()
2414 return viewStyle.getConservationSelected();
2418 public void setShowBoxes(boolean state)
2420 viewStyle.setShowBoxes(state);
2425 * @see jalview.api.ViewStyleI#getTextColour()
2428 public Color getTextColour()
2430 return viewStyle.getTextColour();
2435 * @see jalview.api.ViewStyleI#getTextColour2()
2438 public Color getTextColour2()
2440 return viewStyle.getTextColour2();
2445 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2448 public int getThresholdTextColour()
2450 return viewStyle.getThresholdTextColour();
2455 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2458 public boolean isConservationColourSelected()
2460 return viewStyle.isConservationColourSelected();
2465 * @see jalview.api.ViewStyleI#isRenderGaps()
2468 public boolean isRenderGaps()
2470 return viewStyle.isRenderGaps();
2475 * @see jalview.api.ViewStyleI#isShowColourText()
2478 public boolean isShowColourText()
2480 return viewStyle.isShowColourText();
2484 * @param conservationColourSelected
2485 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2488 public void setConservationColourSelected(
2489 boolean conservationColourSelected)
2491 viewStyle.setConservationColourSelected(conservationColourSelected);
2495 * @param showColourText
2496 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2499 public void setShowColourText(boolean showColourText)
2501 viewStyle.setShowColourText(showColourText);
2506 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2509 public void setTextColour(Color textColour)
2511 viewStyle.setTextColour(textColour);
2515 * @param thresholdTextColour
2516 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2519 public void setThresholdTextColour(int thresholdTextColour)
2521 viewStyle.setThresholdTextColour(thresholdTextColour);
2525 * @param textColour2
2526 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2529 public void setTextColour2(Color textColour2)
2531 viewStyle.setTextColour2(textColour2);
2535 public ViewStyleI getViewStyle()
2537 return new ViewStyle(viewStyle);
2541 public void setViewStyle(ViewStyleI settingsForView)
2543 viewStyle = new ViewStyle(settingsForView);
2544 if (residueShading != null)
2546 residueShading.setConservationApplied(
2547 settingsForView.isConservationColourSelected());
2552 public boolean sameStyle(ViewStyleI them)
2554 return viewStyle.sameStyle(them);
2559 * @see jalview.api.ViewStyleI#getIdWidth()
2562 public int getIdWidth()
2564 return viewStyle.getIdWidth();
2569 * @see jalview.api.ViewStyleI#setIdWidth(int)
2572 public void setIdWidth(int i)
2574 viewStyle.setIdWidth(i);
2579 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2582 public boolean isCentreColumnLabels()
2584 return viewStyle.isCentreColumnLabels();
2588 * @param centreColumnLabels
2589 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2592 public void setCentreColumnLabels(boolean centreColumnLabels)
2594 viewStyle.setCentreColumnLabels(centreColumnLabels);
2599 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2602 public void setShowDBRefs(boolean showdbrefs)
2604 viewStyle.setShowDBRefs(showdbrefs);
2609 * @see jalview.api.ViewStyleI#isShowDBRefs()
2612 public boolean isShowDBRefs()
2614 return viewStyle.isShowDBRefs();
2619 * @see jalview.api.ViewStyleI#isShowNPFeats()
2622 public boolean isShowNPFeats()
2624 return viewStyle.isShowNPFeats();
2628 * @param shownpfeats
2629 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2632 public void setShowNPFeats(boolean shownpfeats)
2634 viewStyle.setShowNPFeats(shownpfeats);
2637 public abstract StructureSelectionManager getStructureSelectionManager();
2640 * Add one command to the command history list.
2644 public void addToHistoryList(CommandI command)
2646 if (this.historyList != null)
2648 this.historyList.push(command);
2649 broadcastCommand(command, false);
2650 setSavedUpToDate(false);
2651 Jalview2XML.setStateSavedUpToDate(false);
2655 protected void broadcastCommand(CommandI command, boolean undo)
2657 getStructureSelectionManager().commandPerformed(command, undo,
2662 * Add one command to the command redo list.
2666 public void addToRedoList(CommandI command)
2668 if (this.redoList != null)
2670 this.redoList.push(command);
2672 broadcastCommand(command, true);
2676 * Clear the command redo list.
2678 public void clearRedoList()
2680 if (this.redoList != null)
2682 this.redoList.clear();
2686 public void setHistoryList(Deque<CommandI> list)
2688 this.historyList = list;
2691 public Deque<CommandI> getHistoryList()
2693 return this.historyList;
2696 public void setRedoList(Deque<CommandI> list)
2698 this.redoList = list;
2701 public Deque<CommandI> getRedoList()
2703 return this.redoList;
2707 public VamsasSource getVamsasSource()
2712 public SequenceAnnotationOrder getSortAnnotationsBy()
2714 return sortAnnotationsBy;
2717 public void setSortAnnotationsBy(
2718 SequenceAnnotationOrder sortAnnotationsBy)
2720 this.sortAnnotationsBy = sortAnnotationsBy;
2723 public boolean isShowAutocalculatedAbove()
2725 return showAutocalculatedAbove;
2728 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2730 this.showAutocalculatedAbove = showAutocalculatedAbove;
2734 public boolean isScaleProteinAsCdna()
2736 return viewStyle.isScaleProteinAsCdna();
2740 public void setScaleProteinAsCdna(boolean b)
2742 viewStyle.setScaleProteinAsCdna(b);
2746 public boolean isProteinFontAsCdna()
2748 return viewStyle.isProteinFontAsCdna();
2752 public void setProteinFontAsCdna(boolean b)
2754 viewStyle.setProteinFontAsCdna(b);
2758 public void setShowComplementFeatures(boolean b)
2760 viewStyle.setShowComplementFeatures(b);
2764 public boolean isShowComplementFeatures()
2766 return viewStyle.isShowComplementFeatures();
2770 public void setShowComplementFeaturesOnTop(boolean b)
2772 viewStyle.setShowComplementFeaturesOnTop(b);
2776 public boolean isShowComplementFeaturesOnTop()
2778 return viewStyle.isShowComplementFeaturesOnTop();
2782 * @return true if view should scroll to show the highlighted region of a
2787 public final boolean isFollowHighlight()
2789 return followHighlight;
2793 public final void setFollowHighlight(boolean b)
2795 this.followHighlight = b;
2799 public ViewportRanges getRanges()
2805 * Helper method to populate the SearchResults with the location in the
2806 * complementary alignment to scroll to, in order to match this one.
2809 * the SearchResults to add to
2810 * @return the offset (below top of visible region) of the matched sequence
2812 protected int findComplementScrollTarget(SearchResultsI sr)
2814 final AlignViewportI complement = getCodingComplement();
2815 if (complement == null || !complement.isFollowHighlight())
2819 boolean iAmProtein = !getAlignment().isNucleotide();
2820 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2821 : complement.getAlignment();
2822 if (proteinAlignment == null)
2826 final List<AlignedCodonFrame> mappings = proteinAlignment
2830 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2831 * residue in the middle column of the visible region. Scroll the
2832 * complementary alignment to line up the corresponding residue.
2835 SequenceI sequence = null;
2838 * locate 'middle' column (true middle if an odd number visible, left of
2839 * middle if an even number visible)
2841 int middleColumn = ranges.getStartRes()
2842 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2843 final HiddenSequences hiddenSequences = getAlignment()
2844 .getHiddenSequences();
2847 * searching to the bottom of the alignment gives smoother scrolling across
2848 * all gapped visible regions
2850 int lastSeq = alignment.getHeight() - 1;
2851 List<AlignedCodonFrame> seqMappings = null;
2852 for (int seqNo = ranges
2853 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2855 sequence = getAlignment().getSequenceAt(seqNo);
2856 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2860 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2864 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2866 getCodingComplement().getAlignment().getSequences());
2867 if (!seqMappings.isEmpty())
2873 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2876 * No ungapped mapped sequence in middle column - do nothing
2880 MappingUtils.addSearchResults(sr, sequence,
2881 sequence.findPosition(middleColumn), seqMappings);
2886 * synthesize a column selection if none exists so it covers the given
2887 * selection group. if wholewidth is false, no column selection is made if the
2888 * selection group covers the whole alignment width.
2893 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2896 if (sg != null && (sgs = sg.getStartRes()) >= 0
2897 && sg.getStartRes() <= (sge = sg.getEndRes())
2898 && !this.hasSelectedColumns())
2900 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2907 colSel = new ColumnSelection();
2909 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2911 colSel.addElement(cspos);
2917 * hold status of current selection group - defined on alignment or not.
2919 private boolean selectionIsDefinedGroup = false;
2922 public boolean isSelectionDefinedGroup()
2924 if (selectionGroup == null)
2928 if (isSelectionGroupChanged(true))
2930 selectionIsDefinedGroup = false;
2931 List<SequenceGroup> gps = alignment.getGroups();
2932 if (gps == null || gps.size() == 0)
2934 selectionIsDefinedGroup = false;
2938 selectionIsDefinedGroup = gps.contains(selectionGroup);
2941 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2945 * null, or currently highlighted results on this view
2947 private SearchResultsI searchResults = null;
2949 protected TreeModel currentTree = null;
2952 public boolean hasSearchResults()
2954 return searchResults != null;
2958 public void setSearchResults(SearchResultsI results)
2960 searchResults = results;
2964 public SearchResultsI getSearchResults()
2966 return searchResults;
2970 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
2972 return alignment.getContactListFor(_aa, column);
2976 public ContactMatrixI getContactMatrix(
2977 AlignmentAnnotation alignmentAnnotation)
2979 return alignment.getContactMatrixFor(alignmentAnnotation);
2983 * get the consensus sequence as displayed under the PID consensus annotation
2986 * @return consensus sequence as a new sequence object
2988 public SequenceI getConsensusSeq()
2990 if (consensus == null)
2992 updateConsensus(null);
2994 if (consensus == null)
2998 StringBuffer seqs = new StringBuffer();
2999 for (int i = 0; i < consensus.annotations.length; i++)
3001 Annotation annotation = consensus.annotations[i];
3002 if (annotation != null)
3004 String description = annotation.description;
3005 if (description != null && description.startsWith("["))
3007 // consensus is a tie - just pick the first one
3008 seqs.append(description.charAt(1));
3012 seqs.append(annotation.displayCharacter);
3017 SequenceI sq = new Sequence("Consensus", seqs.toString());
3018 sq.setDescription("Percentage Identity Consensus "
3019 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3024 public void setCurrentTree(TreeModel tree)
3030 public TreeModel getCurrentTree()
3036 public AlignmentExportData getAlignExportData(
3037 AlignExportSettingsI options)
3039 AlignmentI alignmentToExport = null;
3040 String[] omitHidden = null;
3041 alignmentToExport = null;
3043 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3045 omitHidden = getViewAsString(false,
3046 options.isExportHiddenSequences());
3049 int[] alignmentStartEnd = new int[2];
3050 if (hasHiddenRows() && options.isExportHiddenSequences())
3052 alignmentToExport = getAlignment().getHiddenSequences()
3053 .getFullAlignment();
3057 alignmentToExport = getAlignment();
3059 alignmentStartEnd = getAlignment().getHiddenColumns()
3060 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3061 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3062 omitHidden, alignmentStartEnd);
3067 * flag set to indicate if structure views might be out of sync with sequences
3071 private boolean needToUpdateStructureViews = false;
3074 public boolean isUpdateStructures()
3076 return needToUpdateStructureViews;
3080 public void setUpdateStructures(boolean update)
3082 needToUpdateStructureViews = update;
3086 public boolean needToUpdateStructureViews()
3088 boolean update = needToUpdateStructureViews;
3089 needToUpdateStructureViews = false;
3094 public void addSequenceGroup(SequenceGroup sequenceGroup)
3096 alignment.addGroup(sequenceGroup);
3098 Color col = sequenceGroup.idColour;
3101 col = col.brighter();
3103 for (SequenceI sq : sequenceGroup.getSequences())
3105 setSequenceColour(sq, col);
3109 if (codingComplement != null)
3111 SequenceGroup mappedGroup = MappingUtils
3112 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3113 if (mappedGroup.getSequences().size() > 0)
3115 codingComplement.getAlignment().addGroup(mappedGroup);
3119 for (SequenceI seq : mappedGroup.getSequences())
3121 codingComplement.setSequenceColour(seq, col);
3125 // propagate the structure view update flag according to our own setting
3126 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3131 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3135 if (selectedRegionOnly && selectionGroup != null)
3137 start = selectionGroup.getStartRes();
3138 end = selectionGroup.getEndRes() + 1;
3142 end = alignment.getWidth();
3144 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3148 public void setSavedUpToDate(boolean s)
3150 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3153 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3156 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3158 QuitHandler.setMessage(m);
3161 public boolean savedUpToDate()
3163 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3165 return savedUpToDate;