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.commands.CommandI;
45 import jalview.datamodel.AlignedCodonFrame;
46 import jalview.datamodel.AlignmentAnnotation;
47 import jalview.datamodel.AlignmentExportData;
48 import jalview.datamodel.AlignmentI;
49 import jalview.datamodel.AlignmentView;
50 import jalview.datamodel.Annotation;
51 import jalview.datamodel.ColumnSelection;
52 import jalview.datamodel.HiddenColumns;
53 import jalview.datamodel.HiddenSequences;
54 import jalview.datamodel.ProfilesI;
55 import jalview.datamodel.SearchResultsI;
56 import jalview.datamodel.Sequence;
57 import jalview.datamodel.SequenceCollectionI;
58 import jalview.datamodel.SequenceGroup;
59 import jalview.datamodel.SequenceI;
60 import jalview.renderer.ResidueShader;
61 import jalview.renderer.ResidueShaderI;
62 import jalview.schemes.ColourSchemeI;
63 import jalview.structure.CommandListener;
64 import jalview.structure.StructureSelectionManager;
65 import jalview.structure.VamsasSource;
66 import jalview.util.Comparison;
67 import jalview.util.MapList;
68 import jalview.util.MappingUtils;
69 import jalview.util.MessageManager;
70 import jalview.viewmodel.styles.ViewStyle;
71 import jalview.workers.AlignCalcManager;
72 import jalview.workers.ComplementConsensusThread;
73 import jalview.workers.ConsensusThread;
74 import jalview.workers.StrucConsensusThread;
77 * base class holding visualization and analysis attributes and common logic for
78 * an active alignment view displayed in the GUI
83 public abstract class AlignmentViewport
84 implements AlignViewportI, CommandListener, VamsasSource
86 protected ViewportRanges ranges;
88 protected ViewStyleI viewStyle = new ViewStyle();
91 * A viewport that hosts the cDna view of this (protein), or vice versa (if
94 AlignViewportI codingComplement = null;
96 FeaturesDisplayedI featuresDisplayed = null;
98 protected Deque<CommandI> historyList = new ArrayDeque<>();
100 protected Deque<CommandI> redoList = new ArrayDeque<>();
103 * alignment displayed in the viewport. Please use get/setter
105 protected AlignmentI alignment;
107 public AlignmentViewport(AlignmentI al)
110 ranges = new ViewportRanges(al);
115 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
118 public void setFontName(String name)
120 viewStyle.setFontName(name);
125 * @see jalview.api.ViewStyleI#setFontStyle(int)
128 public void setFontStyle(int style)
130 viewStyle.setFontStyle(style);
135 * @see jalview.api.ViewStyleI#setFontSize(int)
138 public void setFontSize(int size)
140 viewStyle.setFontSize(size);
145 * @see jalview.api.ViewStyleI#getFontStyle()
148 public int getFontStyle()
150 return viewStyle.getFontStyle();
155 * @see jalview.api.ViewStyleI#getFontName()
158 public String getFontName()
160 return viewStyle.getFontName();
165 * @see jalview.api.ViewStyleI#getFontSize()
168 public int getFontSize()
170 return viewStyle.getFontSize();
174 * @param upperCasebold
175 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
178 public void setUpperCasebold(boolean upperCasebold)
180 viewStyle.setUpperCasebold(upperCasebold);
185 * @see jalview.api.ViewStyleI#isUpperCasebold()
188 public boolean isUpperCasebold()
190 return viewStyle.isUpperCasebold();
195 * @see jalview.api.ViewStyleI#isSeqNameItalics()
198 public boolean isSeqNameItalics()
200 return viewStyle.isSeqNameItalics();
204 * @param colourByReferenceSeq
205 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
208 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
210 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
215 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
218 public void setColourAppliesToAllGroups(boolean b)
220 viewStyle.setColourAppliesToAllGroups(b);
225 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
228 public boolean getColourAppliesToAllGroups()
230 return viewStyle.getColourAppliesToAllGroups();
235 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
238 public boolean getAbovePIDThreshold()
240 return viewStyle.getAbovePIDThreshold();
245 * @see jalview.api.ViewStyleI#setIncrement(int)
248 public void setIncrement(int inc)
250 viewStyle.setIncrement(inc);
255 * @see jalview.api.ViewStyleI#getIncrement()
258 public int getIncrement()
260 return viewStyle.getIncrement();
265 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
268 public void setConservationSelected(boolean b)
270 viewStyle.setConservationSelected(b);
275 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
278 public void setShowHiddenMarkers(boolean show)
280 viewStyle.setShowHiddenMarkers(show);
285 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
288 public boolean getShowHiddenMarkers()
290 return viewStyle.getShowHiddenMarkers();
295 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
298 public void setScaleRightWrapped(boolean b)
300 viewStyle.setScaleRightWrapped(b);
305 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
308 public void setScaleLeftWrapped(boolean b)
310 viewStyle.setScaleLeftWrapped(b);
315 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
318 public void setScaleAboveWrapped(boolean b)
320 viewStyle.setScaleAboveWrapped(b);
325 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
328 public boolean getScaleLeftWrapped()
330 return viewStyle.getScaleLeftWrapped();
335 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
338 public boolean getScaleAboveWrapped()
340 return viewStyle.getScaleAboveWrapped();
345 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
348 public boolean getScaleRightWrapped()
350 return viewStyle.getScaleRightWrapped();
355 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
358 public void setAbovePIDThreshold(boolean b)
360 viewStyle.setAbovePIDThreshold(b);
365 * @see jalview.api.ViewStyleI#setThreshold(int)
368 public void setThreshold(int thresh)
370 viewStyle.setThreshold(thresh);
375 * @see jalview.api.ViewStyleI#getThreshold()
378 public int getThreshold()
380 return viewStyle.getThreshold();
385 * @see jalview.api.ViewStyleI#getShowJVSuffix()
388 public boolean getShowJVSuffix()
390 return viewStyle.getShowJVSuffix();
395 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
398 public void setShowJVSuffix(boolean b)
400 viewStyle.setShowJVSuffix(b);
405 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
408 public void setWrapAlignment(boolean state)
410 viewStyle.setWrapAlignment(state);
411 ranges.setWrappedMode(state);
416 * @see jalview.api.ViewStyleI#setShowText(boolean)
419 public void setShowText(boolean state)
421 viewStyle.setShowText(state);
426 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
429 public void setRenderGaps(boolean state)
431 viewStyle.setRenderGaps(state);
436 * @see jalview.api.ViewStyleI#getColourText()
439 public boolean getColourText()
441 return viewStyle.getColourText();
446 * @see jalview.api.ViewStyleI#setColourText(boolean)
449 public void setColourText(boolean state)
451 viewStyle.setColourText(state);
456 * @see jalview.api.ViewStyleI#getWrapAlignment()
459 public boolean getWrapAlignment()
461 return viewStyle.getWrapAlignment();
466 * @see jalview.api.ViewStyleI#getShowText()
469 public boolean getShowText()
471 return viewStyle.getShowText();
476 * @see jalview.api.ViewStyleI#getWrappedWidth()
479 public int getWrappedWidth()
481 return viewStyle.getWrappedWidth();
486 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
489 public void setWrappedWidth(int w)
491 viewStyle.setWrappedWidth(w);
496 * @see jalview.api.ViewStyleI#getCharHeight()
499 public int getCharHeight()
501 return viewStyle.getCharHeight();
506 * @see jalview.api.ViewStyleI#setCharHeight(int)
509 public void setCharHeight(int h)
511 viewStyle.setCharHeight(h);
516 * @see jalview.api.ViewStyleI#getCharWidth()
519 public int getCharWidth()
521 return viewStyle.getCharWidth();
526 * @see jalview.api.ViewStyleI#setCharWidth(int)
529 public void setCharWidth(int w)
531 viewStyle.setCharWidth(w);
536 * @see jalview.api.ViewStyleI#getShowBoxes()
539 public boolean getShowBoxes()
541 return viewStyle.getShowBoxes();
546 * @see jalview.api.ViewStyleI#getShowUnconserved()
549 public boolean getShowUnconserved()
551 return viewStyle.getShowUnconserved();
555 * @param showunconserved
556 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
559 public void setShowUnconserved(boolean showunconserved)
561 viewStyle.setShowUnconserved(showunconserved);
566 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
569 public void setSeqNameItalics(boolean default1)
571 viewStyle.setSeqNameItalics(default1);
575 * Set the flag indicating that feature count annotation tracks are to be
578 * @see jalview.api.ViewStyleI#setShowSequenceFeatureCounts(boolean)
581 public void setShowSequenceFeatureCounts(boolean show)
583 viewStyle.setShowSequenceFeatureCounts(show);
587 * @return true if feature count annotation tracks are to be displayed
588 * @see jalview.api.ViewStyleI#isShowSequenceFeatureCounts()
591 public boolean isShowSequenceFeatureCounts()
593 return viewStyle.isShowSequenceFeatureCounts();
597 public AlignmentI getAlignment()
603 public char getGapCharacter()
605 return alignment.getGapCharacter();
608 protected String sequenceSetID;
611 * probably unused indicator that view is of a dataset rather than an
614 protected boolean isDataset = false;
616 public void setDataset(boolean b)
621 public boolean isDataset()
626 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
628 protected ColumnSelection colSel = new ColumnSelection();
630 public boolean autoCalculateConsensus = true;
632 protected boolean autoCalculateStrucConsensus = true;
634 protected boolean ignoreGapsInConsensusCalculation = false;
636 protected ResidueShaderI residueShading = new ResidueShader();
639 public void setGlobalColourScheme(ColourSchemeI cs)
641 // TODO: logic refactored from AlignFrame changeColour -
642 // TODO: autorecalc stuff should be changed to rely on the worker system
643 // check to see if we should implement a changeColour(cs) method rather than
644 // put the logic in here
645 // - means that caller decides if they want to just modify state and defer
646 // calculation till later or to do all calculations in thread.
650 * only instantiate alignment colouring once, thereafter update it;
651 * this means that any conservation or PID threshold settings
652 * persist when the alignment colour scheme is changed
654 if (residueShading == null)
656 residueShading = new ResidueShader(viewStyle);
658 residueShading.setColourScheme(cs);
660 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
661 // ...problem: groups need these, but do not currently have a ViewStyle
665 if (getConservationSelected())
667 residueShading.setConservation(hconservation);
670 * reset conservation flag in case just set to false if
671 * Conservation was null (calculation still in progress)
673 residueShading.setConservationApplied(getConservationSelected());
674 residueShading.alignmentChanged(alignment, hiddenRepSequences);
678 * if 'apply colour to all groups' is selected... do so
679 * (but don't transfer any colour threshold settings to groups)
681 if (getColourAppliesToAllGroups())
683 for (SequenceGroup sg : getAlignment().getGroups())
686 * retain any colour thresholds per group while
687 * changing choice of colour scheme (JAL-2386)
689 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
692 sg.getGroupColourScheme().alignmentChanged(sg,
700 public ColourSchemeI getGlobalColourScheme()
702 return residueShading == null ? null : residueShading.getColourScheme();
706 public ResidueShaderI getResidueShading()
708 return residueShading;
711 protected AlignmentAnnotation consensus;
713 protected AlignmentAnnotation complementConsensus;
715 protected AlignmentAnnotation gapcounts;
717 protected AlignmentAnnotation strucConsensus;
719 protected AlignmentAnnotation conservation;
721 protected AlignmentAnnotation quality;
723 protected AlignmentAnnotation[] groupConsensus;
725 protected AlignmentAnnotation[] groupConservation;
728 * results of alignment consensus analysis for visible portion of view
730 protected ProfilesI hconsensus = null;
733 * results of cDNA complement consensus visible portion of view
735 protected Hashtable<String, Object>[] hcomplementConsensus = null;
738 * results of secondary structure base pair consensus for visible portion of
741 protected Hashtable<String, Object>[] hStrucConsensus = null;
743 protected Conservation hconservation = null;
746 public void setConservation(Conservation cons)
748 hconservation = cons;
752 * percentage gaps allowed in a column before all amino acid properties should
753 * be considered unconserved
755 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
758 public int getConsPercGaps()
764 public void setSequenceConsensusHash(ProfilesI hconsensus)
766 this.hconsensus = hconsensus;
770 public void setComplementConsensusHash(
771 Hashtable<String, Object>[] hconsensus)
773 this.hcomplementConsensus = hconsensus;
777 public ProfilesI getSequenceConsensusHash()
783 public Hashtable<String, Object>[] getComplementConsensusHash()
785 return hcomplementConsensus;
789 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
791 return hStrucConsensus;
795 public void setRnaStructureConsensusHash(
796 Hashtable<String, Object>[] hStrucConsensus)
798 this.hStrucConsensus = hStrucConsensus;
803 public AlignmentAnnotation getAlignmentQualityAnnot()
809 public AlignmentAnnotation getAlignmentConservationAnnotation()
815 public AlignmentAnnotation getAlignmentConsensusAnnotation()
821 public AlignmentAnnotation getAlignmentGapAnnotation()
827 public AlignmentAnnotation getComplementConsensusAnnotation()
829 return complementConsensus;
833 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
835 return strucConsensus;
838 protected AlignCalcManagerI calculator = new AlignCalcManager();
841 * trigger update of conservation annotation
843 public void updateConservation(final AlignmentViewPanel ap)
845 // see note in mantis : issue number 8585
846 if (alignment.isNucleotide()
847 || (conservation == null && quality == null)
848 || !autoCalculateConsensus)
852 if (calculator.getRegisteredWorkersOfClass(
853 jalview.workers.ConservationThread.class) == null)
855 calculator.registerWorker(
856 new jalview.workers.ConservationThread(this, ap));
861 * trigger update of consensus annotation
863 public void updateConsensus(final AlignmentViewPanel ap)
865 // see note in mantis : issue number 8585
866 if (consensus == null || !autoCalculateConsensus)
871 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
873 calculator.registerWorker(new ConsensusThread(this, ap));
877 * A separate thread to compute cDNA consensus for a protein alignment
878 * which has mapping to cDNA
880 final AlignmentI al = this.getAlignment();
881 if (!al.isNucleotide() && al.getCodonFrames() != null
882 && !al.getCodonFrames().isEmpty())
885 * fudge - check first for protein-to-nucleotide mappings
886 * (we don't want to do this for protein-to-protein)
888 boolean doConsensus = false;
889 for (AlignedCodonFrame mapping : al.getCodonFrames())
891 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
892 MapList[] mapLists = mapping.getdnaToProt();
893 // mapLists can be empty if project load has not finished resolving seqs
894 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
902 if (calculator.getRegisteredWorkersOfClass(
903 ComplementConsensusThread.class) == null)
906 .registerWorker(new ComplementConsensusThread(this, ap));
912 // --------START Structure Conservation
913 public void updateStrucConsensus(final AlignmentViewPanel ap)
915 if (autoCalculateStrucConsensus && strucConsensus == null
916 && alignment.isNucleotide() && alignment.hasRNAStructure())
918 // secondary structure has been added - so init the consensus line
922 // see note in mantis : issue number 8585
923 if (strucConsensus == null || !autoCalculateStrucConsensus)
927 if (calculator.getRegisteredWorkersOfClass(
928 StrucConsensusThread.class) == null)
930 calculator.registerWorker(new StrucConsensusThread(this, ap));
934 public boolean isCalcInProgress()
936 return calculator.isWorking();
940 public boolean isCalculationInProgress(
941 AlignmentAnnotation alignmentAnnotation)
943 if (!alignmentAnnotation.autoCalculated)
947 if (calculator.workingInvolvedWith(alignmentAnnotation))
949 // System.err.println("grey out ("+alignmentAnnotation.label+")");
955 public void setAlignment(AlignmentI align)
957 this.alignment = align;
961 * Clean up references when this viewport is closed
964 public void dispose()
967 * defensively null out references to large objects in case
968 * this object is not garbage collected (as if!)
971 complementConsensus = null;
972 strucConsensus = null;
975 groupConsensus = null;
976 groupConservation = null;
978 hconservation = null;
979 hcomplementConsensus = null;
982 residueShading = null; // may hold a reference to Consensus
983 changeSupport = null;
986 selectionGroup = null;
992 public boolean isClosed()
994 // TODO: check that this isClosed is only true after panel is closed, not
995 // before it is fully constructed.
996 return alignment == null;
1000 public AlignCalcManagerI getCalcManager()
1006 * should conservation rows be shown for groups
1008 protected boolean showGroupConservation = false;
1011 * should consensus rows be shown for groups
1013 protected boolean showGroupConsensus = false;
1016 * should consensus profile be rendered by default
1018 protected boolean showSequenceLogo = false;
1021 * should consensus profile be rendered normalised to row height
1023 protected boolean normaliseSequenceLogo = false;
1026 * should consensus histograms be rendered by default
1028 protected boolean showConsensusHistogram = true;
1031 * @return the showConsensusProfile
1034 public boolean isShowSequenceLogo()
1036 return showSequenceLogo;
1040 * @param showSequenceLogo
1043 public void setShowSequenceLogo(boolean showSequenceLogo)
1045 if (showSequenceLogo != this.showSequenceLogo)
1047 // TODO: decouple settings setting from calculation when refactoring
1048 // annotation update method from alignframe to viewport
1049 this.showSequenceLogo = showSequenceLogo;
1050 calculator.updateAnnotationFor(ConsensusThread.class);
1051 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1052 calculator.updateAnnotationFor(StrucConsensusThread.class);
1054 this.showSequenceLogo = showSequenceLogo;
1058 * @param showConsensusHistogram
1059 * the showConsensusHistogram to set
1061 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1063 this.showConsensusHistogram = showConsensusHistogram;
1067 * @return the showGroupConservation
1069 public boolean isShowGroupConservation()
1071 return showGroupConservation;
1075 * @param showGroupConservation
1076 * the showGroupConservation to set
1078 public void setShowGroupConservation(boolean showGroupConservation)
1080 this.showGroupConservation = showGroupConservation;
1084 * @return the showGroupConsensus
1086 public boolean isShowGroupConsensus()
1088 return showGroupConsensus;
1092 * @param showGroupConsensus
1093 * the showGroupConsensus to set
1095 public void setShowGroupConsensus(boolean showGroupConsensus)
1097 this.showGroupConsensus = showGroupConsensus;
1102 * @return flag to indicate if the consensus histogram should be rendered by
1106 public boolean isShowConsensusHistogram()
1108 return this.showConsensusHistogram;
1112 * when set, updateAlignment will always ensure sequences are of equal length
1114 private boolean padGaps = false;
1117 * when set, alignment should be reordered according to a newly opened tree
1119 public boolean sortByTree = false;
1124 * @return null or the currently selected sequence region
1127 public SequenceGroup getSelectionGroup()
1129 return selectionGroup;
1133 * Set the selection group for this window. Also sets the current alignment as
1134 * the context for the group, if it does not already have one.
1137 * - group holding references to sequences in this alignment view
1141 public void setSelectionGroup(SequenceGroup sg)
1143 selectionGroup = sg;
1144 if (sg != null && sg.getContext() == null)
1146 sg.setContext(alignment);
1150 public void setHiddenColumns(HiddenColumns hidden)
1152 this.alignment.setHiddenColumns(hidden);
1156 public ColumnSelection getColumnSelection()
1162 public void setColumnSelection(ColumnSelection colSel)
1164 this.colSel = colSel;
1167 updateHiddenColumns();
1169 isColSelChanged(true);
1177 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1179 return hiddenRepSequences;
1183 public void setHiddenRepSequences(
1184 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1186 this.hiddenRepSequences = hiddenRepSequences;
1190 public boolean hasSelectedColumns()
1192 ColumnSelection columnSelection = getColumnSelection();
1193 return columnSelection != null && columnSelection.hasSelectedColumns();
1197 public boolean hasHiddenColumns()
1199 return alignment.getHiddenColumns() != null
1200 && alignment.getHiddenColumns().hasHiddenColumns();
1203 public void updateHiddenColumns()
1205 // this method doesn't really do anything now. But - it could, since a
1206 // column Selection could be in the process of modification
1207 // hasHiddenColumns = colSel.hasHiddenColumns();
1211 public boolean hasHiddenRows()
1213 return alignment.getHiddenSequences().getSize() > 0;
1216 protected SequenceGroup selectionGroup;
1218 public void setSequenceSetId(String newid)
1220 if (sequenceSetID != null)
1223 "Warning - overwriting a sequenceSetId for a viewport!");
1225 sequenceSetID = new String(newid);
1229 public String getSequenceSetId()
1231 if (sequenceSetID == null)
1233 sequenceSetID = alignment.hashCode() + "";
1236 return sequenceSetID;
1240 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1243 protected String viewId = null;
1246 public String getViewId()
1250 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1255 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1257 ignoreGapsInConsensusCalculation = b;
1260 updateConsensus(ap);
1261 if (residueShading != null)
1263 residueShading.setThreshold(residueShading.getThreshold(),
1264 ignoreGapsInConsensusCalculation);
1270 private long sgrouphash = -1, colselhash = -1;
1273 * checks current SelectionGroup against record of last hash value, and
1277 * update the record of last hash value
1279 * @return true if SelectionGroup changed since last call (when b is true)
1281 public boolean isSelectionGroupChanged(boolean b)
1283 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1284 : selectionGroup.hashCode();
1285 if (hc != -1 && hc != sgrouphash)
1297 * checks current colsel against record of last hash value, and optionally
1301 * update the record of last hash value
1302 * @return true if colsel changed since last call (when b is true)
1304 public boolean isColSelChanged(boolean b)
1306 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1307 if (hc != -1 && hc != colselhash)
1319 public boolean isIgnoreGapsConsensus()
1321 return ignoreGapsInConsensusCalculation;
1324 // property change stuff
1325 // JBPNote Prolly only need this in the applet version.
1326 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1329 protected boolean showConservation = true;
1331 protected boolean showQuality = true;
1333 protected boolean showConsensus = true;
1335 protected boolean showOccupancy = true;
1337 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1339 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1341 protected boolean showAutocalculatedAbove;
1344 * when set, view will scroll to show the highlighted position
1346 private boolean followHighlight = true;
1349 * Property change listener for changes in alignment
1354 public void addPropertyChangeListener(
1355 java.beans.PropertyChangeListener listener)
1357 changeSupport.addPropertyChangeListener(listener);
1366 public void removePropertyChangeListener(
1367 java.beans.PropertyChangeListener listener)
1369 if (changeSupport != null)
1371 changeSupport.removePropertyChangeListener(listener);
1376 * Property change listener for changes in alignment
1385 public void firePropertyChange(String prop, Object oldvalue,
1388 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1391 // common hide/show column stuff
1393 public void hideSelectedColumns()
1395 if (colSel.isEmpty())
1400 colSel.hideSelectedColumns(alignment);
1401 setSelectionGroup(null);
1402 isColSelChanged(true);
1405 public void hideColumns(int start, int end)
1409 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1413 alignment.getHiddenColumns().hideColumns(start, end);
1415 isColSelChanged(true);
1418 public void showColumn(int col)
1420 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1421 isColSelChanged(true);
1424 public void showAllHiddenColumns()
1426 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1427 isColSelChanged(true);
1430 // common hide/show seq stuff
1431 public void showAllHiddenSeqs()
1433 int startSeq = ranges.getStartSeq();
1434 int endSeq = ranges.getEndSeq();
1436 if (alignment.getHiddenSequences().getSize() > 0)
1438 if (selectionGroup == null)
1440 selectionGroup = new SequenceGroup();
1441 selectionGroup.setEndRes(alignment.getWidth() - 1);
1443 List<SequenceI> tmp = alignment.getHiddenSequences()
1444 .showAll(hiddenRepSequences);
1445 for (SequenceI seq : tmp)
1447 selectionGroup.addSequence(seq, false);
1448 setSequenceAnnotationsVisible(seq, true);
1451 hiddenRepSequences = null;
1453 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1455 firePropertyChange("alignment", null, alignment.getSequences());
1456 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1462 public void showSequence(int index)
1464 int startSeq = ranges.getStartSeq();
1465 int endSeq = ranges.getEndSeq();
1467 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1468 hiddenRepSequences);
1471 if (selectionGroup == null)
1473 selectionGroup = new SequenceGroup();
1474 selectionGroup.setEndRes(alignment.getWidth() - 1);
1477 for (SequenceI seq : tmp)
1479 selectionGroup.addSequence(seq, false);
1480 setSequenceAnnotationsVisible(seq, true);
1483 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1485 firePropertyChange("alignment", null, alignment.getSequences());
1490 public void hideAllSelectedSeqs()
1492 if (selectionGroup == null || selectionGroup.getSize() < 1)
1497 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1501 setSelectionGroup(null);
1504 public void hideSequence(SequenceI[] seq)
1507 * cache offset to first visible sequence
1509 int startSeq = ranges.getStartSeq();
1513 for (int i = 0; i < seq.length; i++)
1515 alignment.getHiddenSequences().hideSequence(seq[i]);
1516 setSequenceAnnotationsVisible(seq[i], false);
1518 ranges.setStartSeq(startSeq);
1519 firePropertyChange("alignment", null, alignment.getSequences());
1524 * Hides the specified sequence, or the sequences it represents
1527 * the sequence to hide, or keep as representative
1528 * @param representGroup
1529 * if true, hide the current selection group except for the
1530 * representative sequence
1532 public void hideSequences(SequenceI sequence, boolean representGroup)
1534 if (selectionGroup == null || selectionGroup.getSize() < 1)
1536 hideSequence(new SequenceI[] { sequence });
1542 hideRepSequences(sequence, selectionGroup);
1543 setSelectionGroup(null);
1547 int gsize = selectionGroup.getSize();
1548 SequenceI[] hseqs = selectionGroup.getSequences()
1549 .toArray(new SequenceI[gsize]);
1551 hideSequence(hseqs);
1552 setSelectionGroup(null);
1557 * Set visibility for any annotations for the given sequence.
1561 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1564 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1567 for (AlignmentAnnotation ann : anns)
1569 if (ann.sequenceRef == sequenceI)
1571 ann.visible = visible;
1577 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1579 int sSize = sg.getSize();
1585 if (hiddenRepSequences == null)
1587 hiddenRepSequences = new Hashtable<>();
1590 hiddenRepSequences.put(repSequence, sg);
1592 // Hide all sequences except the repSequence
1593 SequenceI[] seqs = new SequenceI[sSize - 1];
1595 for (int i = 0; i < sSize; i++)
1597 if (sg.getSequenceAt(i) != repSequence)
1599 if (index == sSize - 1)
1604 seqs[index++] = sg.getSequenceAt(i);
1607 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1608 sg.setHidereps(true); // note: not done in 2.7applet
1615 * @return null or the current reference sequence
1617 public SequenceI getReferenceSeq()
1619 return alignment.getSeqrep();
1624 * @return true iff seq is the reference for the alignment
1626 public boolean isReferenceSeq(SequenceI seq)
1628 return alignment.getSeqrep() == seq;
1634 * @return true if there are sequences represented by this sequence that are
1637 public boolean isHiddenRepSequence(SequenceI seq)
1639 return (hiddenRepSequences != null
1640 && hiddenRepSequences.containsKey(seq));
1646 * @return null or a sequence group containing the sequences that seq
1649 public SequenceGroup getRepresentedSequences(SequenceI seq)
1651 return (SequenceGroup) (hiddenRepSequences == null ? null
1652 : hiddenRepSequences.get(seq));
1656 public int adjustForHiddenSeqs(int alignmentIndex)
1658 return alignment.getHiddenSequences()
1659 .adjustForHiddenSeqs(alignmentIndex);
1663 public void invertColumnSelection()
1665 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1666 isColSelChanged(true);
1670 public SequenceI[] getSelectionAsNewSequence()
1672 SequenceI[] sequences;
1673 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1674 // this was the only caller in the applet for this method
1675 // JBPNote: in applet, this method returned references to the alignment
1676 // sequences, and it did not honour the presence/absence of annotation
1677 // attached to the alignment (probably!)
1678 if (selectionGroup == null || selectionGroup.getSize() == 0)
1680 sequences = alignment.getSequencesArray();
1681 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1682 for (int i = 0; i < sequences.length; i++)
1684 // construct new sequence with subset of visible annotation
1685 sequences[i] = new Sequence(sequences[i], annots);
1690 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1697 public SequenceI[] getSequenceSelection()
1699 SequenceI[] sequences = null;
1700 if (selectionGroup != null)
1702 sequences = selectionGroup.getSequencesInOrder(alignment);
1704 if (sequences == null)
1706 sequences = alignment.getSequencesArray();
1712 public jalview.datamodel.AlignmentView getAlignmentView(
1713 boolean selectedOnly)
1715 return getAlignmentView(selectedOnly, false);
1719 public jalview.datamodel.AlignmentView getAlignmentView(
1720 boolean selectedOnly, boolean markGroups)
1722 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1724 alignment.getHiddenColumns() != null
1725 && alignment.getHiddenColumns().hasHiddenColumns(),
1726 selectedOnly, markGroups);
1730 public String[] getViewAsString(boolean selectedRegionOnly)
1732 return getViewAsString(selectedRegionOnly, true);
1736 public String[] getViewAsString(boolean selectedRegionOnly,
1737 boolean exportHiddenSeqs)
1739 String[] selection = null;
1740 SequenceI[] seqs = null;
1742 int start = 0, end = 0;
1743 if (selectedRegionOnly && selectionGroup != null)
1745 iSize = selectionGroup.getSize();
1746 seqs = selectionGroup.getSequencesInOrder(alignment);
1747 start = selectionGroup.getStartRes();
1748 end = selectionGroup.getEndRes() + 1;
1752 if (hasHiddenRows() && exportHiddenSeqs)
1754 AlignmentI fullAlignment = alignment.getHiddenSequences()
1755 .getFullAlignment();
1756 iSize = fullAlignment.getHeight();
1757 seqs = fullAlignment.getSequencesArray();
1758 end = fullAlignment.getWidth();
1762 iSize = alignment.getHeight();
1763 seqs = alignment.getSequencesArray();
1764 end = alignment.getWidth();
1768 selection = new String[iSize];
1769 if (alignment.getHiddenColumns() != null
1770 && alignment.getHiddenColumns().hasHiddenColumns())
1772 for (i = 0; i < iSize; i++)
1774 Iterator<int[]> blocks = alignment.getHiddenColumns()
1775 .getVisContigsIterator(start, end + 1, false);
1776 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1781 for (i = 0; i < iSize; i++)
1783 selection[i] = seqs[i].getSequenceAsString(start, end);
1791 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1793 ArrayList<int[]> regions = new ArrayList<>();
1799 HiddenColumns hidden = alignment.getHiddenColumns();
1800 if (hidden != null && hidden.hasHiddenColumns())
1804 start = hidden.visibleToAbsoluteColumn(start);
1807 end = hidden.getNextHiddenBoundary(false, start);
1818 regions.add(new int[] { start, end });
1820 if (hidden != null && hidden.hasHiddenColumns())
1822 start = hidden.visibleToAbsoluteColumn(end);
1823 start = hidden.getNextHiddenBoundary(true, start) + 1;
1825 } while (end < max);
1827 // int[][] startEnd = new int[regions.size()][2];
1833 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1834 boolean selectedOnly)
1836 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1837 AlignmentAnnotation[] aa;
1838 if ((aa = alignment.getAlignmentAnnotation()) != null)
1840 for (AlignmentAnnotation annot : aa)
1842 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1843 if (selectedOnly && selectionGroup != null)
1845 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1846 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1850 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1859 public boolean isPadGaps()
1865 public void setPadGaps(boolean padGaps)
1867 this.padGaps = padGaps;
1871 * apply any post-edit constraints and trigger any calculations needed after
1872 * an edit has been performed on the alignment
1877 public void alignmentChanged(AlignmentViewPanel ap)
1881 alignment.padGaps();
1883 if (autoCalculateConsensus)
1885 updateConsensus(ap);
1887 if (hconsensus != null && autoCalculateConsensus)
1889 updateConservation(ap);
1891 if (autoCalculateStrucConsensus)
1893 updateStrucConsensus(ap);
1896 // Reset endRes of groups if beyond alignment width
1897 int alWidth = alignment.getWidth();
1898 List<SequenceGroup> groups = alignment.getGroups();
1901 for (SequenceGroup sg : groups)
1903 if (sg.getEndRes() > alWidth)
1905 sg.setEndRes(alWidth - 1);
1910 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1912 selectionGroup.setEndRes(alWidth - 1);
1915 updateAllColourSchemes();
1916 calculator.restartWorkers();
1917 // alignment.adjustSequenceAnnotations();
1921 * reset scope and do calculations for all applied colourschemes on alignment
1923 void updateAllColourSchemes()
1925 ResidueShaderI rs = residueShading;
1928 rs.alignmentChanged(alignment, hiddenRepSequences);
1930 rs.setConsensus(hconsensus);
1931 if (rs.conservationApplied())
1933 rs.setConservation(Conservation.calculateConservation("All",
1934 alignment.getSequences(), 0, alignment.getWidth(), false,
1935 getConsPercGaps(), false));
1939 for (SequenceGroup sg : alignment.getGroups())
1943 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1945 sg.recalcConservation();
1949 protected void initAutoAnnotation()
1951 // TODO: add menu option action that nulls or creates consensus object
1952 // depending on if the user wants to see the annotation or not in a
1953 // specific alignment
1955 if (hconsensus == null && !isDataset)
1957 if (!alignment.isNucleotide())
1966 consensus = new AlignmentAnnotation("Consensus",
1967 MessageManager.getString("label.consensus_descr"),
1968 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1969 initConsensus(consensus);
1972 initComplementConsensus();
1977 * If this is a protein alignment and there are mappings to cDNA, adds the
1978 * cDNA consensus annotation and returns true, else returns false.
1980 public boolean initComplementConsensus()
1982 if (!alignment.isNucleotide())
1984 final List<AlignedCodonFrame> codonMappings = alignment
1986 if (codonMappings != null && !codonMappings.isEmpty())
1988 boolean doConsensus = false;
1989 for (AlignedCodonFrame mapping : codonMappings)
1991 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1992 MapList[] mapLists = mapping.getdnaToProt();
1993 // mapLists can be empty if project load has not finished resolving
1995 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2003 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2005 .getString("label.complement_consensus_descr"),
2006 new Annotation[1], 0f, 100f,
2007 AlignmentAnnotation.BAR_GRAPH);
2008 initConsensus(complementConsensus);
2016 private void initConsensus(AlignmentAnnotation aa)
2019 aa.autoCalculated = true;
2023 alignment.addAnnotation(aa);
2027 // these should be extracted from the view model - style and settings for
2028 // derived annotation
2029 private void initGapCounts()
2033 gapcounts = new AlignmentAnnotation("Occupancy",
2034 MessageManager.getString("label.occupancy_descr"),
2035 new Annotation[1], 0f, alignment.getHeight(),
2036 AlignmentAnnotation.BAR_GRAPH);
2037 gapcounts.hasText = true;
2038 gapcounts.autoCalculated = true;
2039 gapcounts.scaleColLabel = true;
2040 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2042 alignment.addAnnotation(gapcounts);
2046 private void initConservation()
2048 if (showConservation)
2050 if (conservation == null)
2052 conservation = new AlignmentAnnotation("Conservation",
2053 MessageManager.formatMessage("label.conservation_descr",
2055 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2056 conservation.hasText = true;
2057 conservation.autoCalculated = true;
2058 alignment.addAnnotation(conservation);
2063 private void initQuality()
2067 if (quality == null)
2069 quality = new AlignmentAnnotation("Quality",
2070 MessageManager.getString("label.quality_descr"),
2071 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2072 quality.hasText = true;
2073 quality.autoCalculated = true;
2074 alignment.addAnnotation(quality);
2079 private void initRNAStructure()
2081 if (alignment.hasRNAStructure() && strucConsensus == null)
2083 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2084 MessageManager.getString("label.strucconsensus_descr"),
2085 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2086 strucConsensus.hasText = true;
2087 strucConsensus.autoCalculated = true;
2091 alignment.addAnnotation(strucConsensus);
2099 * @see jalview.api.AlignViewportI#calcPanelHeight()
2102 public int calcPanelHeight()
2104 // setHeight of panels
2105 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2107 int charHeight = getCharHeight();
2110 BitSet graphgrp = new BitSet();
2111 for (AlignmentAnnotation aa : anns)
2115 System.err.println("Null annotation row: ignoring.");
2122 if (aa.graphGroup > -1)
2124 if (graphgrp.get(aa.graphGroup))
2130 graphgrp.set(aa.graphGroup);
2137 aa.height += charHeight;
2147 aa.height += aa.graphHeight;
2155 height += aa.height;
2167 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2168 boolean preserveNewGroupSettings)
2170 boolean updateCalcs = false;
2171 boolean conv = isShowGroupConservation();
2172 boolean cons = isShowGroupConsensus();
2173 boolean showprf = isShowSequenceLogo();
2174 boolean showConsHist = isShowConsensusHistogram();
2175 boolean normLogo = isNormaliseSequenceLogo();
2178 * TODO reorder the annotation rows according to group/sequence ordering on
2181 // boolean sortg = true;
2183 // remove old automatic annotation
2184 // add any new annotation
2186 // intersect alignment annotation with alignment groups
2188 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2189 List<SequenceGroup> oldrfs = new ArrayList<>();
2192 for (int an = 0; an < aan.length; an++)
2194 if (aan[an].autoCalculated && aan[an].groupRef != null)
2196 oldrfs.add(aan[an].groupRef);
2197 alignment.deleteAnnotation(aan[an], false);
2201 if (alignment.getGroups() != null)
2203 for (SequenceGroup sg : alignment.getGroups())
2205 updateCalcs = false;
2206 if (applyGlobalSettings
2207 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2209 // set defaults for this group's conservation/consensus
2210 sg.setshowSequenceLogo(showprf);
2211 sg.setShowConsensusHistogram(showConsHist);
2212 sg.setNormaliseSequenceLogo(normLogo);
2217 alignment.addAnnotation(sg.getConservationRow(), 0);
2222 alignment.addAnnotation(sg.getConsensus(), 0);
2224 // refresh the annotation rows
2227 sg.recalcConservation();
2235 public boolean isDisplayReferenceSeq()
2237 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2241 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2243 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2247 public boolean isColourByReferenceSeq()
2249 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2253 public Color getSequenceColour(SequenceI seq)
2255 Color sqc = sequenceColours.get(seq);
2256 return (sqc == null ? Color.white : sqc);
2260 public void setSequenceColour(SequenceI seq, Color col)
2264 sequenceColours.remove(seq);
2268 sequenceColours.put(seq, col);
2273 public void updateSequenceIdColours()
2275 for (SequenceGroup sg : alignment.getGroups())
2277 if (sg.idColour != null)
2279 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2281 sequenceColours.put(s, sg.idColour);
2288 public void clearSequenceColours()
2290 sequenceColours.clear();
2294 public AlignViewportI getCodingComplement()
2296 return this.codingComplement;
2300 * Set this as the (cDna/protein) complement of the given viewport. Also
2301 * ensures the reverse relationship is set on the given viewport.
2304 public void setCodingComplement(AlignViewportI av)
2308 System.err.println("Ignoring recursive setCodingComplement request");
2312 this.codingComplement = av;
2313 // avoid infinite recursion!
2314 if (av.getCodingComplement() != this)
2316 av.setCodingComplement(this);
2322 public boolean isNucleotide()
2324 return getAlignment() == null ? false : getAlignment().isNucleotide();
2328 public FeaturesDisplayedI getFeaturesDisplayed()
2330 return featuresDisplayed;
2334 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2336 featuresDisplayed = featuresDisplayedI;
2340 public boolean areFeaturesDisplayed()
2342 return featuresDisplayed != null
2343 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2350 * features are displayed if true
2353 public void setShowSequenceFeatures(boolean b)
2355 viewStyle.setShowSequenceFeatures(b);
2359 public boolean isShowSequenceFeatures()
2361 return viewStyle.isShowSequenceFeatures();
2365 public void setShowSequenceFeaturesHeight(boolean selected)
2367 viewStyle.setShowSequenceFeaturesHeight(selected);
2371 public boolean isShowSequenceFeaturesHeight()
2373 return viewStyle.isShowSequenceFeaturesHeight();
2377 public void setShowAnnotation(boolean b)
2379 viewStyle.setShowAnnotation(b);
2383 public boolean isShowAnnotation()
2385 return viewStyle.isShowAnnotation();
2389 public boolean isRightAlignIds()
2391 return viewStyle.isRightAlignIds();
2395 public void setRightAlignIds(boolean rightAlignIds)
2397 viewStyle.setRightAlignIds(rightAlignIds);
2401 public boolean getConservationSelected()
2403 return viewStyle.getConservationSelected();
2407 public void setShowBoxes(boolean state)
2409 viewStyle.setShowBoxes(state);
2414 * @see jalview.api.ViewStyleI#getTextColour()
2417 public Color getTextColour()
2419 return viewStyle.getTextColour();
2424 * @see jalview.api.ViewStyleI#getTextColour2()
2427 public Color getTextColour2()
2429 return viewStyle.getTextColour2();
2434 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2437 public int getThresholdTextColour()
2439 return viewStyle.getThresholdTextColour();
2444 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2447 public boolean isConservationColourSelected()
2449 return viewStyle.isConservationColourSelected();
2454 * @see jalview.api.ViewStyleI#isRenderGaps()
2457 public boolean isRenderGaps()
2459 return viewStyle.isRenderGaps();
2464 * @see jalview.api.ViewStyleI#isShowColourText()
2467 public boolean isShowColourText()
2469 return viewStyle.isShowColourText();
2473 * @param conservationColourSelected
2474 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2477 public void setConservationColourSelected(
2478 boolean conservationColourSelected)
2480 viewStyle.setConservationColourSelected(conservationColourSelected);
2484 * @param showColourText
2485 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2488 public void setShowColourText(boolean showColourText)
2490 viewStyle.setShowColourText(showColourText);
2495 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2498 public void setTextColour(Color textColour)
2500 viewStyle.setTextColour(textColour);
2504 * @param thresholdTextColour
2505 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2508 public void setThresholdTextColour(int thresholdTextColour)
2510 viewStyle.setThresholdTextColour(thresholdTextColour);
2514 * @param textColour2
2515 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2518 public void setTextColour2(Color textColour2)
2520 viewStyle.setTextColour2(textColour2);
2524 public ViewStyleI getViewStyle()
2526 return new ViewStyle(viewStyle);
2530 public void setViewStyle(ViewStyleI settingsForView)
2532 viewStyle = new ViewStyle(settingsForView);
2533 if (residueShading != null)
2535 residueShading.setConservationApplied(
2536 settingsForView.isConservationColourSelected());
2541 public boolean sameStyle(ViewStyleI them)
2543 return viewStyle.sameStyle(them);
2548 * @see jalview.api.ViewStyleI#getIdWidth()
2551 public int getIdWidth()
2553 return viewStyle.getIdWidth();
2558 * @see jalview.api.ViewStyleI#setIdWidth(int)
2561 public void setIdWidth(int i)
2563 viewStyle.setIdWidth(i);
2568 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2571 public boolean isCentreColumnLabels()
2573 return viewStyle.isCentreColumnLabels();
2577 * @param centreColumnLabels
2578 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2581 public void setCentreColumnLabels(boolean centreColumnLabels)
2583 viewStyle.setCentreColumnLabels(centreColumnLabels);
2588 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2591 public void setShowDBRefs(boolean showdbrefs)
2593 viewStyle.setShowDBRefs(showdbrefs);
2598 * @see jalview.api.ViewStyleI#isShowDBRefs()
2601 public boolean isShowDBRefs()
2603 return viewStyle.isShowDBRefs();
2608 * @see jalview.api.ViewStyleI#isShowNPFeats()
2611 public boolean isShowNPFeats()
2613 return viewStyle.isShowNPFeats();
2617 * @param shownpfeats
2618 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2621 public void setShowNPFeats(boolean shownpfeats)
2623 viewStyle.setShowNPFeats(shownpfeats);
2626 public abstract StructureSelectionManager getStructureSelectionManager();
2629 * Add one command to the command history list.
2633 public void addToHistoryList(CommandI command)
2635 if (this.historyList != null)
2637 this.historyList.push(command);
2638 broadcastCommand(command, false);
2642 protected void broadcastCommand(CommandI command, boolean undo)
2644 getStructureSelectionManager().commandPerformed(command, undo,
2649 * Add one command to the command redo list.
2653 public void addToRedoList(CommandI command)
2655 if (this.redoList != null)
2657 this.redoList.push(command);
2659 broadcastCommand(command, true);
2663 * Clear the command redo list.
2665 public void clearRedoList()
2667 if (this.redoList != null)
2669 this.redoList.clear();
2673 public void setHistoryList(Deque<CommandI> list)
2675 this.historyList = list;
2678 public Deque<CommandI> getHistoryList()
2680 return this.historyList;
2683 public void setRedoList(Deque<CommandI> list)
2685 this.redoList = list;
2688 public Deque<CommandI> getRedoList()
2690 return this.redoList;
2694 public VamsasSource getVamsasSource()
2699 public SequenceAnnotationOrder getSortAnnotationsBy()
2701 return sortAnnotationsBy;
2704 public void setSortAnnotationsBy(
2705 SequenceAnnotationOrder sortAnnotationsBy)
2707 this.sortAnnotationsBy = sortAnnotationsBy;
2710 public boolean isShowAutocalculatedAbove()
2712 return showAutocalculatedAbove;
2715 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2717 this.showAutocalculatedAbove = showAutocalculatedAbove;
2721 public boolean isScaleProteinAsCdna()
2723 return viewStyle.isScaleProteinAsCdna();
2727 public void setScaleProteinAsCdna(boolean b)
2729 viewStyle.setScaleProteinAsCdna(b);
2733 public boolean isProteinFontAsCdna()
2735 return viewStyle.isProteinFontAsCdna();
2739 public void setProteinFontAsCdna(boolean b)
2741 viewStyle.setProteinFontAsCdna(b);
2745 public void setShowComplementFeatures(boolean b)
2747 viewStyle.setShowComplementFeatures(b);
2751 public boolean isShowComplementFeatures()
2753 return viewStyle.isShowComplementFeatures();
2757 public void setShowComplementFeaturesOnTop(boolean b)
2759 viewStyle.setShowComplementFeaturesOnTop(b);
2763 public boolean isShowComplementFeaturesOnTop()
2765 return viewStyle.isShowComplementFeaturesOnTop();
2769 * @return true if view should scroll to show the highlighted region of a
2774 public final boolean isFollowHighlight()
2776 return followHighlight;
2780 public final void setFollowHighlight(boolean b)
2782 this.followHighlight = b;
2786 public ViewportRanges getRanges()
2792 * Helper method to populate the SearchResults with the location in the
2793 * complementary alignment to scroll to, in order to match this one.
2796 * the SearchResults to add to
2797 * @return the offset (below top of visible region) of the matched sequence
2799 protected int findComplementScrollTarget(SearchResultsI sr)
2801 final AlignViewportI complement = getCodingComplement();
2802 if (complement == null || !complement.isFollowHighlight())
2806 boolean iAmProtein = !getAlignment().isNucleotide();
2807 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2808 : complement.getAlignment();
2809 if (proteinAlignment == null)
2813 final List<AlignedCodonFrame> mappings = proteinAlignment
2817 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2818 * residue in the middle column of the visible region. Scroll the
2819 * complementary alignment to line up the corresponding residue.
2822 SequenceI sequence = null;
2825 * locate 'middle' column (true middle if an odd number visible, left of
2826 * middle if an even number visible)
2828 int middleColumn = ranges.getStartRes()
2829 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2830 final HiddenSequences hiddenSequences = getAlignment()
2831 .getHiddenSequences();
2834 * searching to the bottom of the alignment gives smoother scrolling across
2835 * all gapped visible regions
2837 int lastSeq = alignment.getHeight() - 1;
2838 List<AlignedCodonFrame> seqMappings = null;
2839 for (int seqNo = ranges
2840 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2842 sequence = getAlignment().getSequenceAt(seqNo);
2843 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2847 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2851 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2853 getCodingComplement().getAlignment().getSequences());
2854 if (!seqMappings.isEmpty())
2860 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2863 * No ungapped mapped sequence in middle column - do nothing
2867 MappingUtils.addSearchResults(sr, sequence,
2868 sequence.findPosition(middleColumn), seqMappings);
2873 * synthesize a column selection if none exists so it covers the given
2874 * selection group. if wholewidth is false, no column selection is made if the
2875 * selection group covers the whole alignment width.
2880 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2883 if (sg != null && (sgs = sg.getStartRes()) >= 0
2884 && sg.getStartRes() <= (sge = sg.getEndRes())
2885 && !this.hasSelectedColumns())
2887 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2894 colSel = new ColumnSelection();
2896 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2898 colSel.addElement(cspos);
2904 * hold status of current selection group - defined on alignment or not.
2906 private boolean selectionIsDefinedGroup = false;
2909 public boolean isSelectionDefinedGroup()
2911 if (selectionGroup == null)
2915 if (isSelectionGroupChanged(true))
2917 selectionIsDefinedGroup = false;
2918 List<SequenceGroup> gps = alignment.getGroups();
2919 if (gps == null || gps.size() == 0)
2921 selectionIsDefinedGroup = false;
2925 selectionIsDefinedGroup = gps.contains(selectionGroup);
2928 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2932 * null, or currently highlighted results on this view
2934 private SearchResultsI searchResults = null;
2936 protected TreeModel currentTree = null;
2939 public boolean hasSearchResults()
2941 return searchResults != null;
2945 public void setSearchResults(SearchResultsI results)
2947 searchResults = results;
2951 public SearchResultsI getSearchResults()
2953 return searchResults;
2957 * get the consensus sequence as displayed under the PID consensus annotation
2960 * @return consensus sequence as a new sequence object
2962 public SequenceI getConsensusSeq()
2964 if (consensus == null)
2966 updateConsensus(null);
2968 if (consensus == null)
2972 StringBuffer seqs = new StringBuffer();
2973 for (int i = 0; i < consensus.annotations.length; i++)
2975 Annotation annotation = consensus.annotations[i];
2976 if (annotation != null)
2978 String description = annotation.description;
2979 if (description != null && description.startsWith("["))
2981 // consensus is a tie - just pick the first one
2982 seqs.append(description.charAt(1));
2986 seqs.append(annotation.displayCharacter);
2991 SequenceI sq = new Sequence("Consensus", seqs.toString());
2992 sq.setDescription("Percentage Identity Consensus "
2993 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2998 public void setCurrentTree(TreeModel tree)
3004 public TreeModel getCurrentTree()
3010 public AlignmentExportData getAlignExportData(
3011 AlignExportSettingsI options)
3013 AlignmentI alignmentToExport = null;
3014 String[] omitHidden = null;
3015 alignmentToExport = null;
3017 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3019 omitHidden = getViewAsString(false,
3020 options.isExportHiddenSequences());
3023 int[] alignmentStartEnd = new int[2];
3024 if (hasHiddenRows() && options.isExportHiddenSequences())
3026 alignmentToExport = getAlignment().getHiddenSequences()
3027 .getFullAlignment();
3031 alignmentToExport = getAlignment();
3033 alignmentStartEnd = getAlignment().getHiddenColumns()
3034 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3035 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3036 omitHidden, alignmentStartEnd);
3041 * flag set to indicate if structure views might be out of sync with sequences
3045 private boolean needToUpdateStructureViews = false;
3048 public boolean isUpdateStructures()
3050 return needToUpdateStructureViews;
3054 public void setUpdateStructures(boolean update)
3056 needToUpdateStructureViews = update;
3060 public boolean needToUpdateStructureViews()
3062 boolean update = needToUpdateStructureViews;
3063 needToUpdateStructureViews = false;
3068 public void addSequenceGroup(SequenceGroup sequenceGroup)
3070 alignment.addGroup(sequenceGroup);
3072 Color col = sequenceGroup.idColour;
3075 col = col.brighter();
3077 for (SequenceI sq : sequenceGroup.getSequences())
3079 setSequenceColour(sq, col);
3083 if (codingComplement != null)
3085 SequenceGroup mappedGroup = MappingUtils
3086 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3087 if (mappedGroup.getSequences().size() > 0)
3089 codingComplement.getAlignment().addGroup(mappedGroup);
3093 for (SequenceI seq : mappedGroup.getSequences())
3095 codingComplement.setSequenceColour(seq, col);
3099 // propagate the structure view update flag according to our own setting
3100 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3105 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3109 if (selectedRegionOnly && selectionGroup != null)
3111 start = selectionGroup.getStartRes();
3112 end = selectionGroup.getEndRes() + 1;
3116 end = alignment.getWidth();
3118 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,