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 alignment.setConservation(cons);
749 hconservation = cons;
753 * percentage gaps allowed in a column before all amino acid properties should
754 * be considered unconserved
756 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
759 public int getConsPercGaps()
765 public void setSequenceConsensusHash(ProfilesI hconsensus)
767 alignment.setSequenceConsensusHash(hconsensus);
768 this.hconsensus = hconsensus;
772 public void setComplementConsensusHash(
773 Hashtable<String, Object>[] hconsensus)
775 alignment.setComplementConsensusHash(hconsensus);
776 this.hcomplementConsensus = hconsensus;
780 public ProfilesI getSequenceConsensusHash()
786 public Hashtable<String, Object>[] getComplementConsensusHash()
788 return hcomplementConsensus;
792 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
794 return hStrucConsensus;
798 public void setRnaStructureConsensusHash(
799 Hashtable<String, Object>[] hStrucConsensus)
801 alignment.setRnaStructureConsensusHash(hStrucConsensus);
802 this.hStrucConsensus = hStrucConsensus;
807 public AlignmentAnnotation getAlignmentQualityAnnot()
813 public AlignmentAnnotation getAlignmentConservationAnnotation()
819 public AlignmentAnnotation getAlignmentConsensusAnnotation()
825 public AlignmentAnnotation getAlignmentGapAnnotation()
831 public AlignmentAnnotation getComplementConsensusAnnotation()
833 return complementConsensus;
837 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
839 return strucConsensus;
842 protected AlignCalcManagerI calculator = new AlignCalcManager();
845 * trigger update of conservation annotation
847 public void updateConservation(final AlignmentViewPanel ap)
849 // see note in mantis : issue number 8585
850 if (alignment.isNucleotide()
851 || (conservation == null && quality == null)
852 || !autoCalculateConsensus)
856 if (calculator.getRegisteredWorkersOfClass(
857 jalview.workers.ConservationThread.class) == null)
859 calculator.registerWorker(
860 new jalview.workers.ConservationThread(this, ap));
865 * trigger update of consensus annotation
867 public void updateConsensus(final AlignmentViewPanel ap)
869 // see note in mantis : issue number 8585
870 if (consensus == null || !autoCalculateConsensus)
875 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
877 calculator.registerWorker(new ConsensusThread(this, ap));
881 * A separate thread to compute cDNA consensus for a protein alignment
882 * which has mapping to cDNA
884 final AlignmentI al = this.getAlignment();
885 if (!al.isNucleotide() && al.getCodonFrames() != null
886 && !al.getCodonFrames().isEmpty())
889 * fudge - check first for protein-to-nucleotide mappings
890 * (we don't want to do this for protein-to-protein)
892 boolean doConsensus = false;
893 for (AlignedCodonFrame mapping : al.getCodonFrames())
895 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
896 MapList[] mapLists = mapping.getdnaToProt();
897 // mapLists can be empty if project load has not finished resolving seqs
898 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
906 if (calculator.getRegisteredWorkersOfClass(
907 ComplementConsensusThread.class) == null)
910 .registerWorker(new ComplementConsensusThread(this, ap));
916 // --------START Structure Conservation
917 public void updateStrucConsensus(final AlignmentViewPanel ap)
919 if (autoCalculateStrucConsensus && strucConsensus == null
920 && alignment.isNucleotide() && alignment.hasRNAStructure())
922 // secondary structure has been added - so init the consensus line
926 // see note in mantis : issue number 8585
927 if (strucConsensus == null || !autoCalculateStrucConsensus)
931 if (calculator.getRegisteredWorkersOfClass(
932 StrucConsensusThread.class) == null)
934 calculator.registerWorker(new StrucConsensusThread(this, ap));
938 public boolean isCalcInProgress()
940 return calculator.isWorking();
944 public boolean isCalculationInProgress(
945 AlignmentAnnotation alignmentAnnotation)
947 if (!alignmentAnnotation.autoCalculated)
951 if (calculator.workingInvolvedWith(alignmentAnnotation))
953 // System.err.println("grey out ("+alignmentAnnotation.label+")");
959 public void setAlignment(AlignmentI align)
961 this.alignment = align;
965 * Clean up references when this viewport is closed
968 public void dispose()
971 * defensively null out references to large objects in case
972 * this object is not garbage collected (as if!)
975 complementConsensus = null;
976 strucConsensus = null;
979 groupConsensus = null;
980 groupConservation = null;
982 hconservation = null;
983 hcomplementConsensus = null;
986 residueShading = null; // may hold a reference to Consensus
987 changeSupport = null;
990 selectionGroup = null;
996 public boolean isClosed()
998 // TODO: check that this isClosed is only true after panel is closed, not
999 // before it is fully constructed.
1000 return alignment == null;
1004 public AlignCalcManagerI getCalcManager()
1010 * should conservation rows be shown for groups
1012 protected boolean showGroupConservation = false;
1015 * should consensus rows be shown for groups
1017 protected boolean showGroupConsensus = false;
1020 * should consensus profile be rendered by default
1022 protected boolean showSequenceLogo = false;
1025 * should consensus profile be rendered normalised to row height
1027 protected boolean normaliseSequenceLogo = false;
1030 * should consensus histograms be rendered by default
1032 protected boolean showConsensusHistogram = true;
1035 * @return the showConsensusProfile
1038 public boolean isShowSequenceLogo()
1040 return showSequenceLogo;
1044 * @param showSequenceLogo
1047 public void setShowSequenceLogo(boolean showSequenceLogo)
1049 if (showSequenceLogo != this.showSequenceLogo)
1051 // TODO: decouple settings setting from calculation when refactoring
1052 // annotation update method from alignframe to viewport
1053 this.showSequenceLogo = showSequenceLogo;
1054 calculator.updateAnnotationFor(ConsensusThread.class);
1055 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1056 calculator.updateAnnotationFor(StrucConsensusThread.class);
1058 this.showSequenceLogo = showSequenceLogo;
1062 * @param showConsensusHistogram
1063 * the showConsensusHistogram to set
1065 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1067 this.showConsensusHistogram = showConsensusHistogram;
1071 * @return the showGroupConservation
1073 public boolean isShowGroupConservation()
1075 return showGroupConservation;
1079 * @param showGroupConservation
1080 * the showGroupConservation to set
1082 public void setShowGroupConservation(boolean showGroupConservation)
1084 this.showGroupConservation = showGroupConservation;
1088 * @return the showGroupConsensus
1090 public boolean isShowGroupConsensus()
1092 return showGroupConsensus;
1096 * @param showGroupConsensus
1097 * the showGroupConsensus to set
1099 public void setShowGroupConsensus(boolean showGroupConsensus)
1101 this.showGroupConsensus = showGroupConsensus;
1106 * @return flag to indicate if the consensus histogram should be rendered by
1110 public boolean isShowConsensusHistogram()
1112 return this.showConsensusHistogram;
1116 * when set, updateAlignment will always ensure sequences are of equal length
1118 private boolean padGaps = false;
1121 * when set, alignment should be reordered according to a newly opened tree
1123 public boolean sortByTree = false;
1128 * @return null or the currently selected sequence region
1131 public SequenceGroup getSelectionGroup()
1133 return selectionGroup;
1137 * Set the selection group for this window. Also sets the current alignment as
1138 * the context for the group, if it does not already have one.
1141 * - group holding references to sequences in this alignment view
1145 public void setSelectionGroup(SequenceGroup sg)
1147 selectionGroup = sg;
1148 if (sg != null && sg.getContext() == null)
1150 sg.setContext(alignment);
1154 public void setHiddenColumns(HiddenColumns hidden)
1156 this.alignment.setHiddenColumns(hidden);
1160 public ColumnSelection getColumnSelection()
1166 public void setColumnSelection(ColumnSelection colSel)
1168 this.colSel = colSel;
1171 updateHiddenColumns();
1173 isColSelChanged(true);
1181 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1183 return hiddenRepSequences;
1187 public void setHiddenRepSequences(
1188 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1190 this.hiddenRepSequences = hiddenRepSequences;
1194 public boolean hasSelectedColumns()
1196 ColumnSelection columnSelection = getColumnSelection();
1197 return columnSelection != null && columnSelection.hasSelectedColumns();
1201 public boolean hasHiddenColumns()
1203 return alignment.getHiddenColumns() != null
1204 && alignment.getHiddenColumns().hasHiddenColumns();
1207 public void updateHiddenColumns()
1209 // this method doesn't really do anything now. But - it could, since a
1210 // column Selection could be in the process of modification
1211 // hasHiddenColumns = colSel.hasHiddenColumns();
1215 public boolean hasHiddenRows()
1217 return alignment.getHiddenSequences().getSize() > 0;
1220 protected SequenceGroup selectionGroup;
1222 public void setSequenceSetId(String newid)
1224 if (sequenceSetID != null)
1227 "Warning - overwriting a sequenceSetId for a viewport!");
1229 sequenceSetID = new String(newid);
1233 public String getSequenceSetId()
1235 if (sequenceSetID == null)
1237 sequenceSetID = alignment.hashCode() + "";
1240 return sequenceSetID;
1244 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1247 protected String viewId = null;
1250 public String getViewId()
1254 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1259 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1261 ignoreGapsInConsensusCalculation = b;
1264 updateConsensus(ap);
1265 if (residueShading != null)
1267 residueShading.setThreshold(residueShading.getThreshold(),
1268 ignoreGapsInConsensusCalculation);
1274 private long sgrouphash = -1, colselhash = -1;
1277 * checks current SelectionGroup against record of last hash value, and
1281 * update the record of last hash value
1283 * @return true if SelectionGroup changed since last call (when b is true)
1285 public boolean isSelectionGroupChanged(boolean b)
1287 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1288 : selectionGroup.hashCode();
1289 if (hc != -1 && hc != sgrouphash)
1301 * checks current colsel against record of last hash value, and optionally
1305 * update the record of last hash value
1306 * @return true if colsel changed since last call (when b is true)
1308 public boolean isColSelChanged(boolean b)
1310 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1311 if (hc != -1 && hc != colselhash)
1323 public boolean isIgnoreGapsConsensus()
1325 return ignoreGapsInConsensusCalculation;
1328 // property change stuff
1329 // JBPNote Prolly only need this in the applet version.
1330 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1333 protected boolean showConservation = true;
1335 protected boolean showQuality = true;
1337 protected boolean showConsensus = true;
1339 protected boolean showOccupancy = true;
1341 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1343 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1345 protected boolean showAutocalculatedAbove;
1348 * when set, view will scroll to show the highlighted position
1350 private boolean followHighlight = true;
1353 * Property change listener for changes in alignment
1358 public void addPropertyChangeListener(
1359 java.beans.PropertyChangeListener listener)
1361 changeSupport.addPropertyChangeListener(listener);
1370 public void removePropertyChangeListener(
1371 java.beans.PropertyChangeListener listener)
1373 if (changeSupport != null)
1375 changeSupport.removePropertyChangeListener(listener);
1380 * Property change listener for changes in alignment
1389 public void firePropertyChange(String prop, Object oldvalue,
1392 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1395 // common hide/show column stuff
1397 public void hideSelectedColumns()
1399 if (colSel.isEmpty())
1404 colSel.hideSelectedColumns(alignment);
1405 setSelectionGroup(null);
1406 isColSelChanged(true);
1409 public void hideColumns(int start, int end)
1413 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1417 alignment.getHiddenColumns().hideColumns(start, end);
1419 isColSelChanged(true);
1422 public void showColumn(int col)
1424 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1425 isColSelChanged(true);
1428 public void showAllHiddenColumns()
1430 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1431 isColSelChanged(true);
1434 // common hide/show seq stuff
1435 public void showAllHiddenSeqs()
1437 int startSeq = ranges.getStartSeq();
1438 int endSeq = ranges.getEndSeq();
1440 if (alignment.getHiddenSequences().getSize() > 0)
1442 if (selectionGroup == null)
1444 selectionGroup = new SequenceGroup();
1445 selectionGroup.setEndRes(alignment.getWidth() - 1);
1447 List<SequenceI> tmp = alignment.getHiddenSequences()
1448 .showAll(hiddenRepSequences);
1449 for (SequenceI seq : tmp)
1451 selectionGroup.addSequence(seq, false);
1452 setSequenceAnnotationsVisible(seq, true);
1455 hiddenRepSequences = null;
1457 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1459 firePropertyChange("alignment", null, alignment.getSequences());
1460 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1466 public void showSequence(int index)
1468 int startSeq = ranges.getStartSeq();
1469 int endSeq = ranges.getEndSeq();
1471 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1472 hiddenRepSequences);
1475 if (selectionGroup == null)
1477 selectionGroup = new SequenceGroup();
1478 selectionGroup.setEndRes(alignment.getWidth() - 1);
1481 for (SequenceI seq : tmp)
1483 selectionGroup.addSequence(seq, false);
1484 setSequenceAnnotationsVisible(seq, true);
1487 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1489 firePropertyChange("alignment", null, alignment.getSequences());
1494 public void hideAllSelectedSeqs()
1496 if (selectionGroup == null || selectionGroup.getSize() < 1)
1501 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1505 setSelectionGroup(null);
1508 public void hideSequence(SequenceI[] seq)
1511 * cache offset to first visible sequence
1513 int startSeq = ranges.getStartSeq();
1517 for (int i = 0; i < seq.length; i++)
1519 alignment.getHiddenSequences().hideSequence(seq[i]);
1520 setSequenceAnnotationsVisible(seq[i], false);
1522 ranges.setStartSeq(startSeq);
1523 firePropertyChange("alignment", null, alignment.getSequences());
1528 * Hides the specified sequence, or the sequences it represents
1531 * the sequence to hide, or keep as representative
1532 * @param representGroup
1533 * if true, hide the current selection group except for the
1534 * representative sequence
1536 public void hideSequences(SequenceI sequence, boolean representGroup)
1538 if (selectionGroup == null || selectionGroup.getSize() < 1)
1540 hideSequence(new SequenceI[] { sequence });
1546 hideRepSequences(sequence, selectionGroup);
1547 setSelectionGroup(null);
1551 int gsize = selectionGroup.getSize();
1552 SequenceI[] hseqs = selectionGroup.getSequences()
1553 .toArray(new SequenceI[gsize]);
1555 hideSequence(hseqs);
1556 setSelectionGroup(null);
1561 * Set visibility for any annotations for the given sequence.
1565 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1568 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1571 for (AlignmentAnnotation ann : anns)
1573 if (ann.sequenceRef == sequenceI)
1575 ann.visible = visible;
1581 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1583 int sSize = sg.getSize();
1589 if (hiddenRepSequences == null)
1591 hiddenRepSequences = new Hashtable<>();
1594 hiddenRepSequences.put(repSequence, sg);
1596 // Hide all sequences except the repSequence
1597 SequenceI[] seqs = new SequenceI[sSize - 1];
1599 for (int i = 0; i < sSize; i++)
1601 if (sg.getSequenceAt(i) != repSequence)
1603 if (index == sSize - 1)
1608 seqs[index++] = sg.getSequenceAt(i);
1611 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1612 sg.setHidereps(true); // note: not done in 2.7applet
1619 * @return null or the current reference sequence
1621 public SequenceI getReferenceSeq()
1623 return alignment.getSeqrep();
1628 * @return true iff seq is the reference for the alignment
1630 public boolean isReferenceSeq(SequenceI seq)
1632 return alignment.getSeqrep() == seq;
1638 * @return true if there are sequences represented by this sequence that are
1641 public boolean isHiddenRepSequence(SequenceI seq)
1643 return (hiddenRepSequences != null
1644 && hiddenRepSequences.containsKey(seq));
1650 * @return null or a sequence group containing the sequences that seq
1653 public SequenceGroup getRepresentedSequences(SequenceI seq)
1655 return (SequenceGroup) (hiddenRepSequences == null ? null
1656 : hiddenRepSequences.get(seq));
1660 public int adjustForHiddenSeqs(int alignmentIndex)
1662 return alignment.getHiddenSequences()
1663 .adjustForHiddenSeqs(alignmentIndex);
1667 public void invertColumnSelection()
1669 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1670 isColSelChanged(true);
1674 public SequenceI[] getSelectionAsNewSequence()
1676 SequenceI[] sequences;
1677 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1678 // this was the only caller in the applet for this method
1679 // JBPNote: in applet, this method returned references to the alignment
1680 // sequences, and it did not honour the presence/absence of annotation
1681 // attached to the alignment (probably!)
1682 if (selectionGroup == null || selectionGroup.getSize() == 0)
1684 sequences = alignment.getSequencesArray();
1685 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1686 for (int i = 0; i < sequences.length; i++)
1688 // construct new sequence with subset of visible annotation
1689 sequences[i] = new Sequence(sequences[i], annots);
1694 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1701 public SequenceI[] getSequenceSelection()
1703 SequenceI[] sequences = null;
1704 if (selectionGroup != null)
1706 sequences = selectionGroup.getSequencesInOrder(alignment);
1708 if (sequences == null)
1710 sequences = alignment.getSequencesArray();
1716 public jalview.datamodel.AlignmentView getAlignmentView(
1717 boolean selectedOnly)
1719 return getAlignmentView(selectedOnly, false);
1723 public jalview.datamodel.AlignmentView getAlignmentView(
1724 boolean selectedOnly, boolean markGroups)
1726 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1728 alignment.getHiddenColumns() != null
1729 && alignment.getHiddenColumns().hasHiddenColumns(),
1730 selectedOnly, markGroups);
1734 public String[] getViewAsString(boolean selectedRegionOnly)
1736 return getViewAsString(selectedRegionOnly, true);
1740 public String[] getViewAsString(boolean selectedRegionOnly,
1741 boolean exportHiddenSeqs)
1743 String[] selection = null;
1744 SequenceI[] seqs = null;
1746 int start = 0, end = 0;
1747 if (selectedRegionOnly && selectionGroup != null)
1749 iSize = selectionGroup.getSize();
1750 seqs = selectionGroup.getSequencesInOrder(alignment);
1751 start = selectionGroup.getStartRes();
1752 end = selectionGroup.getEndRes() + 1;
1756 if (hasHiddenRows() && exportHiddenSeqs)
1758 AlignmentI fullAlignment = alignment.getHiddenSequences()
1759 .getFullAlignment();
1760 iSize = fullAlignment.getHeight();
1761 seqs = fullAlignment.getSequencesArray();
1762 end = fullAlignment.getWidth();
1766 iSize = alignment.getHeight();
1767 seqs = alignment.getSequencesArray();
1768 end = alignment.getWidth();
1772 selection = new String[iSize];
1773 if (alignment.getHiddenColumns() != null
1774 && alignment.getHiddenColumns().hasHiddenColumns())
1776 for (i = 0; i < iSize; i++)
1778 Iterator<int[]> blocks = alignment.getHiddenColumns()
1779 .getVisContigsIterator(start, end + 1, false);
1780 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1785 for (i = 0; i < iSize; i++)
1787 selection[i] = seqs[i].getSequenceAsString(start, end);
1795 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1797 ArrayList<int[]> regions = new ArrayList<>();
1803 HiddenColumns hidden = alignment.getHiddenColumns();
1804 if (hidden != null && hidden.hasHiddenColumns())
1808 start = hidden.visibleToAbsoluteColumn(start);
1811 end = hidden.getNextHiddenBoundary(false, start);
1822 regions.add(new int[] { start, end });
1824 if (hidden != null && hidden.hasHiddenColumns())
1826 start = hidden.visibleToAbsoluteColumn(end);
1827 start = hidden.getNextHiddenBoundary(true, start) + 1;
1829 } while (end < max);
1831 // int[][] startEnd = new int[regions.size()][2];
1837 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1838 boolean selectedOnly)
1840 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1841 AlignmentAnnotation[] aa;
1842 if ((aa = alignment.getAlignmentAnnotation()) != null)
1844 for (AlignmentAnnotation annot : aa)
1846 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1847 if (selectedOnly && selectionGroup != null)
1849 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1850 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1854 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1863 public boolean isPadGaps()
1869 public void setPadGaps(boolean padGaps)
1871 this.padGaps = padGaps;
1875 * apply any post-edit constraints and trigger any calculations needed after
1876 * an edit has been performed on the alignment
1881 public void alignmentChanged(AlignmentViewPanel ap)
1885 alignment.padGaps();
1887 if (autoCalculateConsensus)
1889 updateConsensus(ap);
1891 if (hconsensus != null && autoCalculateConsensus)
1893 updateConservation(ap);
1895 if (autoCalculateStrucConsensus)
1897 updateStrucConsensus(ap);
1900 // Reset endRes of groups if beyond alignment width
1901 int alWidth = alignment.getWidth();
1902 List<SequenceGroup> groups = alignment.getGroups();
1905 for (SequenceGroup sg : groups)
1907 if (sg.getEndRes() > alWidth)
1909 sg.setEndRes(alWidth - 1);
1914 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1916 selectionGroup.setEndRes(alWidth - 1);
1919 updateAllColourSchemes();
1920 calculator.restartWorkers();
1921 // alignment.adjustSequenceAnnotations();
1925 * reset scope and do calculations for all applied colourschemes on alignment
1927 void updateAllColourSchemes()
1929 ResidueShaderI rs = residueShading;
1932 rs.alignmentChanged(alignment, hiddenRepSequences);
1934 rs.setConsensus(hconsensus);
1935 if (rs.conservationApplied())
1937 rs.setConservation(Conservation.calculateConservation("All",
1938 alignment.getSequences(), 0, alignment.getWidth(), false,
1939 getConsPercGaps(), false));
1943 for (SequenceGroup sg : alignment.getGroups())
1947 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1949 sg.recalcConservation();
1953 protected void initAutoAnnotation()
1955 // TODO: add menu option action that nulls or creates consensus object
1956 // depending on if the user wants to see the annotation or not in a
1957 // specific alignment
1959 if (hconsensus == null && !isDataset)
1961 if (!alignment.isNucleotide())
1970 consensus = new AlignmentAnnotation("Consensus",
1971 MessageManager.getString("label.consensus_descr"),
1972 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1973 initConsensus(consensus);
1976 initComplementConsensus();
1981 * If this is a protein alignment and there are mappings to cDNA, adds the
1982 * cDNA consensus annotation and returns true, else returns false.
1984 public boolean initComplementConsensus()
1986 if (!alignment.isNucleotide())
1988 final List<AlignedCodonFrame> codonMappings = alignment
1990 if (codonMappings != null && !codonMappings.isEmpty())
1992 boolean doConsensus = false;
1993 for (AlignedCodonFrame mapping : codonMappings)
1995 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1996 MapList[] mapLists = mapping.getdnaToProt();
1997 // mapLists can be empty if project load has not finished resolving
1999 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2007 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2009 .getString("label.complement_consensus_descr"),
2010 new Annotation[1], 0f, 100f,
2011 AlignmentAnnotation.BAR_GRAPH);
2012 initConsensus(complementConsensus);
2020 private void initConsensus(AlignmentAnnotation aa)
2023 aa.autoCalculated = true;
2027 alignment.addAnnotation(aa);
2031 // these should be extracted from the view model - style and settings for
2032 // derived annotation
2033 private void initGapCounts()
2037 gapcounts = new AlignmentAnnotation("Occupancy",
2038 MessageManager.getString("label.occupancy_descr"),
2039 new Annotation[1], 0f, alignment.getHeight(),
2040 AlignmentAnnotation.BAR_GRAPH);
2041 gapcounts.hasText = true;
2042 gapcounts.autoCalculated = true;
2043 gapcounts.scaleColLabel = true;
2044 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2046 alignment.addAnnotation(gapcounts);
2050 private void initConservation()
2052 if (showConservation)
2054 if (conservation == null)
2056 conservation = new AlignmentAnnotation("Conservation",
2057 MessageManager.formatMessage("label.conservation_descr",
2059 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2060 conservation.hasText = true;
2061 conservation.autoCalculated = true;
2062 alignment.addAnnotation(conservation);
2067 private void initQuality()
2071 if (quality == null)
2073 quality = new AlignmentAnnotation("Quality",
2074 MessageManager.getString("label.quality_descr"),
2075 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2076 quality.hasText = true;
2077 quality.autoCalculated = true;
2078 alignment.addAnnotation(quality);
2083 private void initRNAStructure()
2085 if (alignment.hasRNAStructure() && strucConsensus == null)
2087 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2088 MessageManager.getString("label.strucconsensus_descr"),
2089 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2090 strucConsensus.hasText = true;
2091 strucConsensus.autoCalculated = true;
2095 alignment.addAnnotation(strucConsensus);
2103 * @see jalview.api.AlignViewportI#calcPanelHeight()
2106 public int calcPanelHeight()
2108 // setHeight of panels
2109 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2111 int charHeight = getCharHeight();
2114 BitSet graphgrp = new BitSet();
2115 for (AlignmentAnnotation aa : anns)
2119 System.err.println("Null annotation row: ignoring.");
2126 if (aa.graphGroup > -1)
2128 if (graphgrp.get(aa.graphGroup))
2134 graphgrp.set(aa.graphGroup);
2141 aa.height += charHeight;
2151 aa.height += aa.graphHeight;
2159 height += aa.height;
2171 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2172 boolean preserveNewGroupSettings)
2174 boolean updateCalcs = false;
2175 boolean conv = isShowGroupConservation();
2176 boolean cons = isShowGroupConsensus();
2177 boolean showprf = isShowSequenceLogo();
2178 boolean showConsHist = isShowConsensusHistogram();
2179 boolean normLogo = isNormaliseSequenceLogo();
2182 * TODO reorder the annotation rows according to group/sequence ordering on
2185 // boolean sortg = true;
2187 // remove old automatic annotation
2188 // add any new annotation
2190 // intersect alignment annotation with alignment groups
2192 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2193 List<SequenceGroup> oldrfs = new ArrayList<>();
2196 for (int an = 0; an < aan.length; an++)
2198 if (aan[an].autoCalculated && aan[an].groupRef != null)
2200 oldrfs.add(aan[an].groupRef);
2201 alignment.deleteAnnotation(aan[an], false);
2205 if (alignment.getGroups() != null)
2207 for (SequenceGroup sg : alignment.getGroups())
2209 updateCalcs = false;
2210 if (applyGlobalSettings
2211 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2213 // set defaults for this group's conservation/consensus
2214 sg.setshowSequenceLogo(showprf);
2215 sg.setShowConsensusHistogram(showConsHist);
2216 sg.setNormaliseSequenceLogo(normLogo);
2221 alignment.addAnnotation(sg.getConservationRow(), 0);
2226 alignment.addAnnotation(sg.getConsensus(), 0);
2228 // refresh the annotation rows
2231 sg.recalcConservation();
2239 public boolean isDisplayReferenceSeq()
2241 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2245 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2247 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2251 public boolean isColourByReferenceSeq()
2253 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2257 public Color getSequenceColour(SequenceI seq)
2259 Color sqc = sequenceColours.get(seq);
2260 return (sqc == null ? Color.white : sqc);
2264 public void setSequenceColour(SequenceI seq, Color col)
2268 sequenceColours.remove(seq);
2272 sequenceColours.put(seq, col);
2277 public void updateSequenceIdColours()
2279 for (SequenceGroup sg : alignment.getGroups())
2281 if (sg.idColour != null)
2283 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2285 sequenceColours.put(s, sg.idColour);
2292 public void clearSequenceColours()
2294 sequenceColours.clear();
2298 public AlignViewportI getCodingComplement()
2300 return this.codingComplement;
2304 * Set this as the (cDna/protein) complement of the given viewport. Also
2305 * ensures the reverse relationship is set on the given viewport.
2308 public void setCodingComplement(AlignViewportI av)
2312 System.err.println("Ignoring recursive setCodingComplement request");
2316 this.codingComplement = av;
2317 // avoid infinite recursion!
2318 if (av.getCodingComplement() != this)
2320 av.setCodingComplement(this);
2326 public boolean isNucleotide()
2328 return getAlignment() == null ? false : getAlignment().isNucleotide();
2332 public FeaturesDisplayedI getFeaturesDisplayed()
2334 return featuresDisplayed;
2338 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2340 featuresDisplayed = featuresDisplayedI;
2344 public boolean areFeaturesDisplayed()
2346 return featuresDisplayed != null
2347 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2354 * features are displayed if true
2357 public void setShowSequenceFeatures(boolean b)
2359 viewStyle.setShowSequenceFeatures(b);
2363 public boolean isShowSequenceFeatures()
2365 return viewStyle.isShowSequenceFeatures();
2369 public void setShowSequenceFeaturesHeight(boolean selected)
2371 viewStyle.setShowSequenceFeaturesHeight(selected);
2375 public boolean isShowSequenceFeaturesHeight()
2377 return viewStyle.isShowSequenceFeaturesHeight();
2381 public void setShowAnnotation(boolean b)
2383 viewStyle.setShowAnnotation(b);
2387 public boolean isShowAnnotation()
2389 return viewStyle.isShowAnnotation();
2393 public boolean isRightAlignIds()
2395 return viewStyle.isRightAlignIds();
2399 public void setRightAlignIds(boolean rightAlignIds)
2401 viewStyle.setRightAlignIds(rightAlignIds);
2405 public boolean getConservationSelected()
2407 return viewStyle.getConservationSelected();
2411 public void setShowBoxes(boolean state)
2413 viewStyle.setShowBoxes(state);
2418 * @see jalview.api.ViewStyleI#getTextColour()
2421 public Color getTextColour()
2423 return viewStyle.getTextColour();
2428 * @see jalview.api.ViewStyleI#getTextColour2()
2431 public Color getTextColour2()
2433 return viewStyle.getTextColour2();
2438 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2441 public int getThresholdTextColour()
2443 return viewStyle.getThresholdTextColour();
2448 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2451 public boolean isConservationColourSelected()
2453 return viewStyle.isConservationColourSelected();
2458 * @see jalview.api.ViewStyleI#isRenderGaps()
2461 public boolean isRenderGaps()
2463 return viewStyle.isRenderGaps();
2468 * @see jalview.api.ViewStyleI#isShowColourText()
2471 public boolean isShowColourText()
2473 return viewStyle.isShowColourText();
2477 * @param conservationColourSelected
2478 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2481 public void setConservationColourSelected(
2482 boolean conservationColourSelected)
2484 viewStyle.setConservationColourSelected(conservationColourSelected);
2488 * @param showColourText
2489 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2492 public void setShowColourText(boolean showColourText)
2494 viewStyle.setShowColourText(showColourText);
2499 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2502 public void setTextColour(Color textColour)
2504 viewStyle.setTextColour(textColour);
2508 * @param thresholdTextColour
2509 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2512 public void setThresholdTextColour(int thresholdTextColour)
2514 viewStyle.setThresholdTextColour(thresholdTextColour);
2518 * @param textColour2
2519 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2522 public void setTextColour2(Color textColour2)
2524 viewStyle.setTextColour2(textColour2);
2528 public ViewStyleI getViewStyle()
2530 return new ViewStyle(viewStyle);
2534 public void setViewStyle(ViewStyleI settingsForView)
2536 viewStyle = new ViewStyle(settingsForView);
2537 if (residueShading != null)
2539 residueShading.setConservationApplied(
2540 settingsForView.isConservationColourSelected());
2545 public boolean sameStyle(ViewStyleI them)
2547 return viewStyle.sameStyle(them);
2552 * @see jalview.api.ViewStyleI#getIdWidth()
2555 public int getIdWidth()
2557 return viewStyle.getIdWidth();
2562 * @see jalview.api.ViewStyleI#setIdWidth(int)
2565 public void setIdWidth(int i)
2567 viewStyle.setIdWidth(i);
2572 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2575 public boolean isCentreColumnLabels()
2577 return viewStyle.isCentreColumnLabels();
2581 * @param centreColumnLabels
2582 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2585 public void setCentreColumnLabels(boolean centreColumnLabels)
2587 viewStyle.setCentreColumnLabels(centreColumnLabels);
2592 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2595 public void setShowDBRefs(boolean showdbrefs)
2597 viewStyle.setShowDBRefs(showdbrefs);
2602 * @see jalview.api.ViewStyleI#isShowDBRefs()
2605 public boolean isShowDBRefs()
2607 return viewStyle.isShowDBRefs();
2612 * @see jalview.api.ViewStyleI#isShowNPFeats()
2615 public boolean isShowNPFeats()
2617 return viewStyle.isShowNPFeats();
2621 * @param shownpfeats
2622 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2625 public void setShowNPFeats(boolean shownpfeats)
2627 viewStyle.setShowNPFeats(shownpfeats);
2630 public abstract StructureSelectionManager getStructureSelectionManager();
2633 * Add one command to the command history list.
2637 public void addToHistoryList(CommandI command)
2639 if (this.historyList != null)
2641 this.historyList.push(command);
2642 broadcastCommand(command, false);
2646 protected void broadcastCommand(CommandI command, boolean undo)
2648 getStructureSelectionManager().commandPerformed(command, undo,
2653 * Add one command to the command redo list.
2657 public void addToRedoList(CommandI command)
2659 if (this.redoList != null)
2661 this.redoList.push(command);
2663 broadcastCommand(command, true);
2667 * Clear the command redo list.
2669 public void clearRedoList()
2671 if (this.redoList != null)
2673 this.redoList.clear();
2677 public void setHistoryList(Deque<CommandI> list)
2679 this.historyList = list;
2682 public Deque<CommandI> getHistoryList()
2684 return this.historyList;
2687 public void setRedoList(Deque<CommandI> list)
2689 this.redoList = list;
2692 public Deque<CommandI> getRedoList()
2694 return this.redoList;
2698 public VamsasSource getVamsasSource()
2703 public SequenceAnnotationOrder getSortAnnotationsBy()
2705 return sortAnnotationsBy;
2708 public void setSortAnnotationsBy(
2709 SequenceAnnotationOrder sortAnnotationsBy)
2711 this.sortAnnotationsBy = sortAnnotationsBy;
2714 public boolean isShowAutocalculatedAbove()
2716 return showAutocalculatedAbove;
2719 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2721 this.showAutocalculatedAbove = showAutocalculatedAbove;
2725 public boolean isScaleProteinAsCdna()
2727 return viewStyle.isScaleProteinAsCdna();
2731 public void setScaleProteinAsCdna(boolean b)
2733 viewStyle.setScaleProteinAsCdna(b);
2737 public boolean isProteinFontAsCdna()
2739 return viewStyle.isProteinFontAsCdna();
2743 public void setProteinFontAsCdna(boolean b)
2745 viewStyle.setProteinFontAsCdna(b);
2749 public void setShowComplementFeatures(boolean b)
2751 viewStyle.setShowComplementFeatures(b);
2755 public boolean isShowComplementFeatures()
2757 return viewStyle.isShowComplementFeatures();
2761 public void setShowComplementFeaturesOnTop(boolean b)
2763 viewStyle.setShowComplementFeaturesOnTop(b);
2767 public boolean isShowComplementFeaturesOnTop()
2769 return viewStyle.isShowComplementFeaturesOnTop();
2773 * @return true if view should scroll to show the highlighted region of a
2778 public final boolean isFollowHighlight()
2780 return followHighlight;
2784 public final void setFollowHighlight(boolean b)
2786 this.followHighlight = b;
2790 public ViewportRanges getRanges()
2796 * Helper method to populate the SearchResults with the location in the
2797 * complementary alignment to scroll to, in order to match this one.
2800 * the SearchResults to add to
2801 * @return the offset (below top of visible region) of the matched sequence
2803 protected int findComplementScrollTarget(SearchResultsI sr)
2805 final AlignViewportI complement = getCodingComplement();
2806 if (complement == null || !complement.isFollowHighlight())
2810 boolean iAmProtein = !getAlignment().isNucleotide();
2811 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2812 : complement.getAlignment();
2813 if (proteinAlignment == null)
2817 final List<AlignedCodonFrame> mappings = proteinAlignment
2821 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2822 * residue in the middle column of the visible region. Scroll the
2823 * complementary alignment to line up the corresponding residue.
2826 SequenceI sequence = null;
2829 * locate 'middle' column (true middle if an odd number visible, left of
2830 * middle if an even number visible)
2832 int middleColumn = ranges.getStartRes()
2833 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2834 final HiddenSequences hiddenSequences = getAlignment()
2835 .getHiddenSequences();
2838 * searching to the bottom of the alignment gives smoother scrolling across
2839 * all gapped visible regions
2841 int lastSeq = alignment.getHeight() - 1;
2842 List<AlignedCodonFrame> seqMappings = null;
2843 for (int seqNo = ranges
2844 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2846 sequence = getAlignment().getSequenceAt(seqNo);
2847 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2851 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2855 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2857 getCodingComplement().getAlignment().getSequences());
2858 if (!seqMappings.isEmpty())
2864 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2867 * No ungapped mapped sequence in middle column - do nothing
2871 MappingUtils.addSearchResults(sr, sequence,
2872 sequence.findPosition(middleColumn), seqMappings);
2877 * synthesize a column selection if none exists so it covers the given
2878 * selection group. if wholewidth is false, no column selection is made if the
2879 * selection group covers the whole alignment width.
2884 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2887 if (sg != null && (sgs = sg.getStartRes()) >= 0
2888 && sg.getStartRes() <= (sge = sg.getEndRes())
2889 && !this.hasSelectedColumns())
2891 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2898 colSel = new ColumnSelection();
2900 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2902 colSel.addElement(cspos);
2908 * hold status of current selection group - defined on alignment or not.
2910 private boolean selectionIsDefinedGroup = false;
2913 public boolean isSelectionDefinedGroup()
2915 if (selectionGroup == null)
2919 if (isSelectionGroupChanged(true))
2921 selectionIsDefinedGroup = false;
2922 List<SequenceGroup> gps = alignment.getGroups();
2923 if (gps == null || gps.size() == 0)
2925 selectionIsDefinedGroup = false;
2929 selectionIsDefinedGroup = gps.contains(selectionGroup);
2932 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2936 * null, or currently highlighted results on this view
2938 private SearchResultsI searchResults = null;
2940 protected TreeModel currentTree = null;
2943 public boolean hasSearchResults()
2945 return searchResults != null;
2949 public void setSearchResults(SearchResultsI results)
2951 searchResults = results;
2955 public SearchResultsI getSearchResults()
2957 return searchResults;
2961 * get the consensus sequence as displayed under the PID consensus annotation
2964 * @return consensus sequence as a new sequence object
2966 public SequenceI getConsensusSeq()
2968 if (consensus == null)
2970 updateConsensus(null);
2972 if (consensus == null)
2976 StringBuffer seqs = new StringBuffer();
2977 for (int i = 0; i < consensus.annotations.length; i++)
2979 Annotation annotation = consensus.annotations[i];
2980 if (annotation != null)
2982 String description = annotation.description;
2983 if (description != null && description.startsWith("["))
2985 // consensus is a tie - just pick the first one
2986 seqs.append(description.charAt(1));
2990 seqs.append(annotation.displayCharacter);
2995 SequenceI sq = new Sequence("Consensus", seqs.toString());
2996 sq.setDescription("Percentage Identity Consensus "
2997 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3002 public void setCurrentTree(TreeModel tree)
3008 public TreeModel getCurrentTree()
3014 public AlignmentExportData getAlignExportData(
3015 AlignExportSettingsI options)
3017 AlignmentI alignmentToExport = null;
3018 String[] omitHidden = null;
3019 alignmentToExport = null;
3021 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3023 omitHidden = getViewAsString(false,
3024 options.isExportHiddenSequences());
3027 int[] alignmentStartEnd = new int[2];
3028 if (hasHiddenRows() && options.isExportHiddenSequences())
3030 alignmentToExport = getAlignment().getHiddenSequences()
3031 .getFullAlignment();
3035 alignmentToExport = getAlignment();
3037 alignmentStartEnd = getAlignment().getHiddenColumns()
3038 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3039 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3040 omitHidden, alignmentStartEnd);
3045 * flag set to indicate if structure views might be out of sync with sequences
3049 private boolean needToUpdateStructureViews = false;
3052 public boolean isUpdateStructures()
3054 return needToUpdateStructureViews;
3058 public void setUpdateStructures(boolean update)
3060 needToUpdateStructureViews = update;
3064 public boolean needToUpdateStructureViews()
3066 boolean update = needToUpdateStructureViews;
3067 needToUpdateStructureViews = false;
3072 public void addSequenceGroup(SequenceGroup sequenceGroup)
3074 alignment.addGroup(sequenceGroup);
3076 Color col = sequenceGroup.idColour;
3079 col = col.brighter();
3081 for (SequenceI sq : sequenceGroup.getSequences())
3083 setSequenceColour(sq, col);
3087 if (codingComplement != null)
3089 SequenceGroup mappedGroup = MappingUtils
3090 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3091 if (mappedGroup.getSequences().size() > 0)
3093 codingComplement.getAlignment().addGroup(mappedGroup);
3097 for (SequenceI seq : mappedGroup.getSequences())
3099 codingComplement.setSequenceColour(seq, col);
3103 // propagate the structure view update flag according to our own setting
3104 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3109 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3113 if (selectedRegionOnly && selectionGroup != null)
3115 start = selectionGroup.getStartRes();
3116 end = selectionGroup.getEndRes() + 1;
3120 end = alignment.getWidth();
3122 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,