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 jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignExportSettingsI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.api.FeaturesDisplayedI;
31 import jalview.api.ViewStyleI;
32 import jalview.commands.CommandI;
33 import jalview.datamodel.AlignedCodonFrame;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentExportData;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.AlignmentView;
38 import jalview.datamodel.Annotation;
39 import jalview.datamodel.ColumnSelection;
40 import jalview.datamodel.HiddenColumns;
41 import jalview.datamodel.HiddenSequences;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.renderer.ResidueShader;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.ColourSchemeI;
51 import jalview.structure.CommandListener;
52 import jalview.structure.StructureSelectionManager;
53 import jalview.structure.VamsasSource;
54 import jalview.util.Comparison;
55 import jalview.util.MapList;
56 import jalview.util.MappingUtils;
57 import jalview.util.MessageManager;
58 import jalview.viewmodel.styles.ViewStyle;
59 import jalview.workers.AlignCalcManager;
60 import jalview.workers.ComplementConsensusThread;
61 import jalview.workers.ConsensusThread;
62 import jalview.workers.StrucConsensusThread;
64 import java.awt.Color;
65 import java.beans.PropertyChangeSupport;
66 import java.util.ArrayDeque;
67 import java.util.ArrayList;
68 import java.util.BitSet;
69 import java.util.Deque;
70 import java.util.HashMap;
71 import java.util.Hashtable;
72 import java.util.Iterator;
73 import java.util.List;
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 public static final String PROPERTY_ALIGNMENT = "alignment";
87 public static final String PROPERTY_SEQUENCE = "sequence";
89 protected ViewportRanges ranges;
91 protected ViewStyleI viewStyle = new ViewStyle();
94 * A viewport that hosts the cDna view of this (protein), or vice versa (if
97 AlignViewportI codingComplement = null;
99 FeaturesDisplayedI featuresDisplayed = null;
101 protected Deque<CommandI> historyList = new ArrayDeque<>();
103 protected Deque<CommandI> redoList = new ArrayDeque<>();
106 * alignment displayed in the viewport. Please use get/setter
108 protected AlignmentI alignment;
110 public AlignmentViewport(AlignmentI al)
113 ranges = new ViewportRanges(al);
118 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
121 public void setFontName(String name)
123 viewStyle.setFontName(name);
128 * @see jalview.api.ViewStyleI#setFontStyle(int)
131 public void setFontStyle(int style)
133 viewStyle.setFontStyle(style);
138 * @see jalview.api.ViewStyleI#setFontSize(int)
141 public void setFontSize(int size)
143 viewStyle.setFontSize(size);
148 * @see jalview.api.ViewStyleI#getFontStyle()
151 public int getFontStyle()
153 return viewStyle.getFontStyle();
158 * @see jalview.api.ViewStyleI#getFontName()
161 public String getFontName()
163 return viewStyle.getFontName();
168 * @see jalview.api.ViewStyleI#getFontSize()
171 public int getFontSize()
173 return viewStyle.getFontSize();
177 * @param upperCasebold
178 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
181 public void setUpperCasebold(boolean upperCasebold)
183 viewStyle.setUpperCasebold(upperCasebold);
188 * @see jalview.api.ViewStyleI#isUpperCasebold()
191 public boolean isUpperCasebold()
193 return viewStyle.isUpperCasebold();
198 * @see jalview.api.ViewStyleI#isSeqNameItalics()
201 public boolean isSeqNameItalics()
203 return viewStyle.isSeqNameItalics();
207 * @param colourByReferenceSeq
208 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
211 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
213 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
218 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
221 public void setColourAppliesToAllGroups(boolean b)
223 viewStyle.setColourAppliesToAllGroups(b);
228 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
231 public boolean getColourAppliesToAllGroups()
233 return viewStyle.getColourAppliesToAllGroups();
238 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
241 public boolean getAbovePIDThreshold()
243 return viewStyle.getAbovePIDThreshold();
248 * @see jalview.api.ViewStyleI#setIncrement(int)
251 public void setIncrement(int inc)
253 viewStyle.setIncrement(inc);
258 * @see jalview.api.ViewStyleI#getIncrement()
261 public int getIncrement()
263 return viewStyle.getIncrement();
268 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
271 public void setConservationSelected(boolean b)
273 viewStyle.setConservationSelected(b);
278 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
281 public void setShowHiddenMarkers(boolean show)
283 viewStyle.setShowHiddenMarkers(show);
288 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
291 public boolean getShowHiddenMarkers()
293 return viewStyle.getShowHiddenMarkers();
298 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
301 public void setScaleRightWrapped(boolean b)
303 viewStyle.setScaleRightWrapped(b);
308 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
311 public void setScaleLeftWrapped(boolean b)
313 viewStyle.setScaleLeftWrapped(b);
318 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
321 public void setScaleAboveWrapped(boolean b)
323 viewStyle.setScaleAboveWrapped(b);
328 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
331 public boolean getScaleLeftWrapped()
333 return viewStyle.getScaleLeftWrapped();
338 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
341 public boolean getScaleAboveWrapped()
343 return viewStyle.getScaleAboveWrapped();
348 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
351 public boolean getScaleRightWrapped()
353 return viewStyle.getScaleRightWrapped();
358 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
361 public void setAbovePIDThreshold(boolean b)
363 viewStyle.setAbovePIDThreshold(b);
368 * @see jalview.api.ViewStyleI#setThreshold(int)
371 public void setThreshold(int thresh)
373 viewStyle.setThreshold(thresh);
378 * @see jalview.api.ViewStyleI#getThreshold()
381 public int getThreshold()
383 return viewStyle.getThreshold();
388 * @see jalview.api.ViewStyleI#getShowJVSuffix()
391 public boolean getShowJVSuffix()
393 return viewStyle.getShowJVSuffix();
398 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
401 public void setShowJVSuffix(boolean b)
403 viewStyle.setShowJVSuffix(b);
408 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
411 public void setWrapAlignment(boolean state)
413 viewStyle.setWrapAlignment(state);
414 ranges.setWrappedMode(state);
419 * @see jalview.api.ViewStyleI#setShowText(boolean)
422 public void setShowText(boolean state)
424 viewStyle.setShowText(state);
429 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
432 public void setRenderGaps(boolean state)
434 viewStyle.setRenderGaps(state);
439 * @see jalview.api.ViewStyleI#getColourText()
442 public boolean getColourText()
444 return viewStyle.getColourText();
449 * @see jalview.api.ViewStyleI#setColourText(boolean)
452 public void setColourText(boolean state)
454 viewStyle.setColourText(state);
459 * @see jalview.api.ViewStyleI#getWrapAlignment()
462 public boolean getWrapAlignment()
464 return viewStyle.getWrapAlignment();
469 * @see jalview.api.ViewStyleI#getShowText()
472 public boolean getShowText()
474 return viewStyle.getShowText();
479 * @see jalview.api.ViewStyleI#getWrappedWidth()
482 public int getWrappedWidth()
484 return viewStyle.getWrappedWidth();
489 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
492 public void setWrappedWidth(int w)
494 viewStyle.setWrappedWidth(w);
499 * @see jalview.api.ViewStyleI#getCharHeight()
502 public int getCharHeight()
504 return viewStyle.getCharHeight();
509 * @see jalview.api.ViewStyleI#setCharHeight(int)
512 public void setCharHeight(int h)
514 viewStyle.setCharHeight(h);
519 * @see jalview.api.ViewStyleI#getCharWidth()
522 public int getCharWidth()
524 return viewStyle.getCharWidth();
529 * @see jalview.api.ViewStyleI#setCharWidth(int)
532 public void setCharWidth(int w)
534 viewStyle.setCharWidth(w);
539 * @see jalview.api.ViewStyleI#getShowBoxes()
542 public boolean getShowBoxes()
544 return viewStyle.getShowBoxes();
549 * @see jalview.api.ViewStyleI#getShowUnconserved()
552 public boolean getShowUnconserved()
554 return viewStyle.getShowUnconserved();
558 * @param showunconserved
559 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
562 public void setShowUnconserved(boolean showunconserved)
564 viewStyle.setShowUnconserved(showunconserved);
569 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
572 public void setSeqNameItalics(boolean default1)
574 viewStyle.setSeqNameItalics(default1);
578 public AlignmentI getAlignment()
584 public char getGapCharacter()
586 return alignment.getGapCharacter();
589 protected String sequenceSetID;
592 * probably unused indicator that view is of a dataset rather than an
595 protected boolean isDataset = false;
597 public void setDataset(boolean b)
602 public boolean isDataset()
607 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
609 protected ColumnSelection colSel = new ColumnSelection();
611 protected boolean autoCalculateConsensusAndConservation = true;
613 public boolean getAutoCalculateConsensusAndConservation()
615 return autoCalculateConsensusAndConservation;
618 public void setAutoCalculateConsensusAndConservation(boolean b)
620 autoCalculateConsensusAndConservation = b;
623 protected boolean autoCalculateStrucConsensus = true;
625 public boolean getAutoCalculateStrucConsensus()
627 return autoCalculateStrucConsensus;
630 public void setAutoCalculateStrucConsensus(boolean b)
632 autoCalculateStrucConsensus = b;
636 protected boolean ignoreGapsInConsensusCalculation = false;
638 protected ResidueShaderI residueShading = new ResidueShader();
641 public void setGlobalColourScheme(ColourSchemeI cs)
643 // TODO: logic refactored from AlignFrame changeColour -
644 // TODO: autorecalc stuff should be changed to rely on the worker system
645 // check to see if we should implement a changeColour(cs) method rather than
646 // put the logic in here
647 // - means that caller decides if they want to just modify state and defer
648 // calculation till later or to do all calculations in thread.
652 * only instantiate alignment colouring once, thereafter update it;
653 * this means that any conservation or PID threshold settings
654 * persist when the alignment colour scheme is changed
656 if (residueShading == null)
658 residueShading = new ResidueShader(viewStyle);
660 residueShading.setColourScheme(cs);
662 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
663 // ...problem: groups need these, but do not currently have a ViewStyle
667 if (getConservationSelected())
669 residueShading.setConservation(hconservation);
672 * reset conservation flag in case just set to false if
673 * Conservation was null (calculation still in progress)
675 residueShading.setConservationApplied(getConservationSelected());
676 residueShading.alignmentChanged(alignment, hiddenRepSequences);
680 * if 'apply colour to all groups' is selected... do so
681 * (but don't transfer any colour threshold settings to groups)
683 if (getColourAppliesToAllGroups())
685 for (SequenceGroup sg : getAlignment().getGroups())
688 * retain any colour thresholds per group while
689 * changing choice of colour scheme (JAL-2386)
692 cs == null ? null : cs.getInstance(this, sg));
695 sg.getGroupColourScheme().alignmentChanged(sg,
703 public ColourSchemeI getGlobalColourScheme()
705 return residueShading == null ? null : residueShading.getColourScheme();
709 public ResidueShaderI getResidueShading()
711 return residueShading;
714 protected AlignmentAnnotation consensus;
716 protected AlignmentAnnotation complementConsensus;
718 protected AlignmentAnnotation gapcounts;
720 protected AlignmentAnnotation strucConsensus;
722 protected AlignmentAnnotation conservation;
724 protected AlignmentAnnotation quality;
726 protected AlignmentAnnotation[] groupConsensus;
728 protected AlignmentAnnotation[] groupConservation;
731 * results of alignment consensus analysis for visible portion of view
733 protected ProfilesI hconsensus = null;
736 * results of cDNA complement consensus visible portion of view
738 protected Hashtable<String, Object>[] hcomplementConsensus = null;
741 * results of secondary structure base pair consensus for visible portion of
744 protected Hashtable<String, Object>[] hStrucConsensus = null;
746 protected Conservation hconservation = null;
749 public void setConservation(Conservation cons)
751 hconservation = cons;
755 * percentage gaps allowed in a column before all amino acid properties should
756 * be considered unconserved
758 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
761 public int getConsPercGaps()
767 public void setSequenceConsensusHash(ProfilesI hconsensus)
769 this.hconsensus = hconsensus;
773 public void setComplementConsensusHash(
774 Hashtable<String, Object>[] 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 this.hStrucConsensus = hStrucConsensus;
806 public AlignmentAnnotation getAlignmentQualityAnnot()
812 public AlignmentAnnotation getAlignmentConservationAnnotation()
818 public AlignmentAnnotation getAlignmentConsensusAnnotation()
824 public AlignmentAnnotation getAlignmentGapAnnotation()
830 public AlignmentAnnotation getComplementConsensusAnnotation()
832 return complementConsensus;
836 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
838 return strucConsensus;
841 protected AlignCalcManagerI calculator = new AlignCalcManager();
844 * trigger update of conservation annotation
846 public void updateConservation(final AlignmentViewPanel ap)
848 // see note in mantis : issue number 8585
849 if (alignment.isNucleotide()
850 || (conservation == null && quality == null)
851 || !autoCalculateConsensusAndConservation)
855 if (calculator.getRegisteredWorkersOfClass(
856 jalview.workers.ConservationThread.class) == null)
858 calculator.registerWorker(
859 new jalview.workers.ConservationThread(this, ap));
864 * trigger update of consensus annotation
866 public void updateConsensus(final AlignmentViewPanel ap)
868 // see note in mantis : issue number 8585
869 if (consensus == null || !autoCalculateConsensusAndConservation)
874 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
876 calculator.registerWorker(new ConsensusThread(this, ap));
880 * A separate thread to compute cDNA consensus for a protein alignment
881 * which has mapping to cDNA
883 final AlignmentI al = this.getAlignment();
884 if (!al.isNucleotide() && al.getCodonFrames() != null
885 && !al.getCodonFrames().isEmpty())
888 * fudge - check first for protein-to-nucleotide mappings
889 * (we don't want to do this for protein-to-protein)
891 boolean doConsensus = false;
892 for (AlignedCodonFrame mapping : al.getCodonFrames())
894 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
895 MapList[] mapLists = mapping.getdnaToProt();
896 // mapLists can be empty if project load has not finished resolving seqs
897 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
905 if (calculator.getRegisteredWorkersOfClass(
906 ComplementConsensusThread.class) == null)
909 .registerWorker(new ComplementConsensusThread(this, ap));
915 // --------START Structure Conservation
916 public void updateStrucConsensus(final AlignmentViewPanel ap)
918 if (autoCalculateStrucConsensus && strucConsensus == null
919 && alignment.isNucleotide() && alignment.hasRNAStructure())
921 // secondary structure has been added - so init the consensus line
925 // see note in mantis : issue number 8585
926 if (strucConsensus == null || !autoCalculateStrucConsensus)
930 if (calculator.getRegisteredWorkersOfClass(
931 StrucConsensusThread.class) == null)
933 calculator.registerWorker(new StrucConsensusThread(this, ap));
937 public boolean isCalcInProgress()
939 return calculator.isWorking();
943 public boolean isCalculationInProgress(
944 AlignmentAnnotation alignmentAnnotation)
946 if (!alignmentAnnotation.autoCalculated)
950 if (calculator.workingInvolvedWith(alignmentAnnotation))
952 // System.err.println("grey out ("+alignmentAnnotation.label+")");
958 public void setAlignment(AlignmentI align)
960 this.alignment = align;
964 * Clean up references when this viewport is closed
967 public void dispose()
970 * defensively null out references to large objects in case
971 * this object is not garbage collected (as if!)
974 complementConsensus = null;
975 strucConsensus = null;
978 groupConsensus = null;
979 groupConservation = null;
981 hconservation = null;
982 hcomplementConsensus = null;
985 residueShading = null; // may hold a reference to Consensus
986 changeSupport = null;
989 selectionGroup = null;
994 public boolean isClosed()
996 // TODO: check that this isClosed is only true after panel is closed, not
997 // before it is fully constructed.
998 return alignment == null;
1002 public AlignCalcManagerI getCalcManager()
1008 * should conservation rows be shown for groups
1010 protected boolean showGroupConservation = false;
1013 * should consensus rows be shown for groups
1015 protected boolean showGroupConsensus = false;
1018 * should consensus profile be rendered by default
1020 protected boolean showSequenceLogo = false;
1023 * should consensus profile be rendered normalised to row height
1025 protected boolean normaliseSequenceLogo = false;
1028 * should consensus histograms be rendered by default
1030 protected boolean showConsensusHistogram = true;
1033 * @return the showConsensusProfile
1036 public boolean isShowSequenceLogo()
1038 return showSequenceLogo;
1042 * @param showSequenceLogo
1045 public void setShowSequenceLogo(boolean showSequenceLogo)
1047 if (showSequenceLogo != this.showSequenceLogo)
1049 // TODO: decouple settings setting from calculation when refactoring
1050 // annotation update method from alignframe to viewport
1051 this.showSequenceLogo = showSequenceLogo;
1052 calculator.updateAnnotationFor(ConsensusThread.class);
1053 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1054 calculator.updateAnnotationFor(StrucConsensusThread.class);
1056 this.showSequenceLogo = showSequenceLogo;
1060 * @param showConsensusHistogram
1061 * the showConsensusHistogram to set
1063 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1065 this.showConsensusHistogram = showConsensusHistogram;
1069 * @return the showGroupConservation
1071 public boolean isShowGroupConservation()
1073 return showGroupConservation;
1077 * @param showGroupConservation
1078 * the showGroupConservation to set
1080 public void setShowGroupConservation(boolean showGroupConservation)
1082 this.showGroupConservation = showGroupConservation;
1086 * @return the showGroupConsensus
1088 public boolean isShowGroupConsensus()
1090 return showGroupConsensus;
1094 * @param showGroupConsensus
1095 * the showGroupConsensus to set
1097 public void setShowGroupConsensus(boolean showGroupConsensus)
1099 this.showGroupConsensus = showGroupConsensus;
1104 * @return flag to indicate if the consensus histogram should be rendered by
1108 public boolean isShowConsensusHistogram()
1110 return this.showConsensusHistogram;
1114 * when set, updateAlignment will always ensure sequences are of equal length
1116 private boolean padGaps = false;
1119 * when set, alignment should be reordered according to a newly opened tree
1121 public boolean sortByTree = false;
1126 * @return null or the currently selected sequence region
1129 public SequenceGroup getSelectionGroup()
1131 return selectionGroup;
1135 * Set the selection group for this window. Also sets the current alignment as
1136 * the context for the group, if it does not already have one.
1139 * - group holding references to sequences in this alignment view
1143 public void setSelectionGroup(SequenceGroup sg)
1145 selectionGroup = sg;
1146 if (sg != null && sg.getContext() == null)
1148 sg.setContext(alignment);
1152 public void setHiddenColumns(HiddenColumns hidden)
1154 this.alignment.setHiddenColumns(hidden);
1158 public ColumnSelection getColumnSelection()
1164 public void setColumnSelection(ColumnSelection colSel)
1166 this.colSel = colSel;
1169 updateHiddenColumns();
1171 isColSelChanged(true);
1179 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1181 return hiddenRepSequences;
1185 public void setHiddenRepSequences(
1186 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1188 this.hiddenRepSequences = hiddenRepSequences;
1192 public boolean hasSelectedColumns()
1194 ColumnSelection columnSelection = getColumnSelection();
1195 return columnSelection != null && columnSelection.hasSelectedColumns();
1199 public boolean hasHiddenColumns()
1201 return alignment.getHiddenColumns() != null
1202 && alignment.getHiddenColumns().hasHiddenColumns();
1205 public void updateHiddenColumns()
1207 // this method doesn't really do anything now. But - it could, since a
1208 // column Selection could be in the process of modification
1209 // hasHiddenColumns = colSel.hasHiddenColumns();
1213 public boolean hasHiddenRows()
1215 return alignment.getHiddenSequences().getSize() > 0;
1218 protected SequenceGroup selectionGroup;
1220 public void setSequenceSetId(String newid)
1222 if (sequenceSetID != null)
1225 "Warning - overwriting a sequenceSetId for a viewport!");
1227 sequenceSetID = new String(newid);
1231 public String getSequenceSetId()
1233 if (sequenceSetID == null)
1235 sequenceSetID = alignment.hashCode() + "";
1238 return sequenceSetID;
1242 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1245 protected String viewId = null;
1248 public String getViewId()
1252 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1257 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1259 ignoreGapsInConsensusCalculation = b;
1262 updateConsensus(ap);
1263 if (residueShading != null)
1265 residueShading.setThreshold(residueShading.getThreshold(),
1266 ignoreGapsInConsensusCalculation);
1272 private long sgrouphash = -1, colselhash = -1;
1275 * checks current SelectionGroup against record of last hash value, and
1279 * update the record of last hash value
1281 * @return true if SelectionGroup changed since last call (when b is true)
1283 public boolean isSelectionGroupChanged(boolean b)
1285 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1286 : selectionGroup.hashCode();
1287 if (hc != -1 && hc != sgrouphash)
1299 * checks current colsel against record of last hash value, and optionally
1303 * update the record of last hash value
1304 * @return true if colsel changed since last call (when b is true)
1306 public boolean isColSelChanged(boolean updateHash)
1308 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1309 if (hc != -1 && hc != colselhash)
1322 public boolean isIgnoreGapsConsensus()
1324 return ignoreGapsInConsensusCalculation;
1327 // property change stuff
1328 // JBPNote Prolly only need this in the applet version.
1329 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1332 protected boolean showConservation = true;
1334 protected boolean showQuality = true;
1336 protected boolean showConsensus = true;
1338 protected boolean showOccupancy = true;
1340 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1342 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1344 protected boolean showAutocalculatedAbove;
1347 * when set, view will scroll to show the highlighted position
1349 private boolean followHighlight = true;
1352 * Property change listener for changes in alignment
1357 public void addPropertyChangeListener(
1358 java.beans.PropertyChangeListener listener)
1360 changeSupport.addPropertyChangeListener(listener);
1369 public void removePropertyChangeListener(
1370 java.beans.PropertyChangeListener listener)
1372 if (changeSupport != null)
1374 changeSupport.removePropertyChangeListener(listener);
1378 // common hide/show column stuff
1380 public void hideSelectedColumns()
1382 if (colSel.isEmpty())
1387 colSel.hideSelectedColumns(alignment);
1388 setSelectionGroup(null);
1389 isColSelChanged(true);
1392 public void hideColumns(int start, int end)
1396 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1400 alignment.getHiddenColumns().hideColumns(start, end);
1402 isColSelChanged(true);
1405 public void showColumn(int col)
1407 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1408 isColSelChanged(true);
1411 public void showAllHiddenColumns()
1413 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1414 isColSelChanged(true);
1417 // common hide/show seq stuff
1418 public void showAllHiddenSeqs()
1420 int startSeq = ranges.getStartSeq();
1421 int endSeq = ranges.getEndSeq();
1423 if (alignment.getHiddenSequences().getSize() > 0)
1425 if (selectionGroup == null)
1427 selectionGroup = new SequenceGroup();
1428 selectionGroup.setEndRes(alignment.getWidth() - 1);
1430 List<SequenceI> tmp = alignment.getHiddenSequences()
1431 .showAll(hiddenRepSequences);
1432 for (SequenceI seq : tmp)
1434 selectionGroup.addSequence(seq, false);
1435 setSequenceAnnotationsVisible(seq, true);
1438 hiddenRepSequences = null;
1440 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1442 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1450 public void showSequence(int index)
1452 int startSeq = ranges.getStartSeq();
1453 int endSeq = ranges.getEndSeq();
1455 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1456 hiddenRepSequences);
1459 if (selectionGroup == null)
1461 selectionGroup = new SequenceGroup();
1462 selectionGroup.setEndRes(alignment.getWidth() - 1);
1465 for (SequenceI seq : tmp)
1467 selectionGroup.addSequence(seq, false);
1468 setSequenceAnnotationsVisible(seq, true);
1471 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1477 public void hideAllSelectedSeqs()
1479 if (selectionGroup == null || selectionGroup.getSize() < 1)
1484 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1488 setSelectionGroup(null);
1491 public void hideSequence(SequenceI[] seq)
1494 * cache offset to first visible sequence
1496 int startSeq = ranges.getStartSeq();
1500 for (int i = 0; i < seq.length; i++)
1502 alignment.getHiddenSequences().hideSequence(seq[i]);
1503 setSequenceAnnotationsVisible(seq[i], false);
1505 ranges.setStartSeq(startSeq);
1511 * Hides the specified sequence, or the sequences it represents
1514 * the sequence to hide, or keep as representative
1515 * @param representGroup
1516 * if true, hide the current selection group except for the
1517 * representative sequence
1519 public void hideSequences(SequenceI sequence, boolean representGroup)
1521 if (selectionGroup == null || selectionGroup.getSize() < 1)
1523 hideSequence(new SequenceI[] { sequence });
1529 hideRepSequences(sequence, selectionGroup);
1530 setSelectionGroup(null);
1534 int gsize = selectionGroup.getSize();
1535 SequenceI[] hseqs = selectionGroup.getSequences()
1536 .toArray(new SequenceI[gsize]);
1538 hideSequence(hseqs);
1539 setSelectionGroup(null);
1544 * Set visibility for any annotations for the given sequence.
1548 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1551 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1554 for (AlignmentAnnotation ann : anns)
1556 if (ann.sequenceRef == sequenceI)
1558 ann.visible = visible;
1564 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1566 int sSize = sg.getSize();
1572 if (hiddenRepSequences == null)
1574 hiddenRepSequences = new Hashtable<>();
1577 hiddenRepSequences.put(repSequence, sg);
1579 // Hide all sequences except the repSequence
1580 SequenceI[] seqs = new SequenceI[sSize - 1];
1582 for (int i = 0; i < sSize; i++)
1584 if (sg.getSequenceAt(i) != repSequence)
1586 if (index == sSize - 1)
1591 seqs[index++] = sg.getSequenceAt(i);
1594 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1595 sg.setHidereps(true); // note: not done in 2.7applet
1602 * @return null or the current reference sequence
1604 public SequenceI getReferenceSeq()
1606 return alignment.getSeqrep();
1611 * @return true iff seq is the reference for the alignment
1613 public boolean isReferenceSeq(SequenceI seq)
1615 return alignment.getSeqrep() == seq;
1621 * @return true if there are sequences represented by this sequence that are
1624 public boolean isHiddenRepSequence(SequenceI seq)
1626 return (hiddenRepSequences != null
1627 && hiddenRepSequences.containsKey(seq));
1633 * @return null or a sequence group containing the sequences that seq
1636 public SequenceGroup getRepresentedSequences(SequenceI seq)
1638 return (SequenceGroup) (hiddenRepSequences == null ? null
1639 : hiddenRepSequences.get(seq));
1643 public int adjustForHiddenSeqs(int alignmentIndex)
1645 return alignment.getHiddenSequences()
1646 .adjustForHiddenSeqs(alignmentIndex);
1650 public void invertColumnSelection()
1652 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1653 isColSelChanged(true);
1657 public SequenceI[] getSelectionAsNewSequence()
1659 SequenceI[] sequences;
1660 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1661 // this was the only caller in the applet for this method
1662 // JBPNote: in applet, this method returned references to the alignment
1663 // sequences, and it did not honour the presence/absence of annotation
1664 // attached to the alignment (probably!)
1665 if (selectionGroup == null || selectionGroup.getSize() == 0)
1667 sequences = alignment.getSequencesArray();
1668 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1669 for (int i = 0; i < sequences.length; i++)
1671 // construct new sequence with subset of visible annotation
1672 sequences[i] = new Sequence(sequences[i], annots);
1677 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1684 public SequenceI[] getSequenceSelection()
1686 SequenceI[] sequences = null;
1687 if (selectionGroup != null)
1689 sequences = selectionGroup.getSequencesInOrder(alignment);
1691 if (sequences == null)
1693 sequences = alignment.getSequencesArray();
1699 public jalview.datamodel.AlignmentView getAlignmentView(
1700 boolean selectedOnly)
1702 return getAlignmentView(selectedOnly, false);
1706 public jalview.datamodel.AlignmentView getAlignmentView(
1707 boolean selectedOnly, boolean markGroups)
1709 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1711 alignment.getHiddenColumns() != null
1712 && alignment.getHiddenColumns().hasHiddenColumns(),
1713 selectedOnly, markGroups);
1717 public String[] getViewAsString(boolean selectedRegionOnly)
1719 return getViewAsString(selectedRegionOnly, true);
1723 public String[] getViewAsString(boolean selectedRegionOnly,
1724 boolean exportHiddenSeqs)
1726 String[] selection = null;
1727 SequenceI[] seqs = null;
1729 int start = 0, end = 0;
1730 if (selectedRegionOnly && selectionGroup != null)
1732 iSize = selectionGroup.getSize();
1733 seqs = selectionGroup.getSequencesInOrder(alignment);
1734 start = selectionGroup.getStartRes();
1735 end = selectionGroup.getEndRes() + 1;
1739 if (hasHiddenRows() && exportHiddenSeqs)
1741 AlignmentI fullAlignment = alignment.getHiddenSequences()
1742 .getFullAlignment();
1743 iSize = fullAlignment.getHeight();
1744 seqs = fullAlignment.getSequencesArray();
1745 end = fullAlignment.getWidth();
1749 iSize = alignment.getHeight();
1750 seqs = alignment.getSequencesArray();
1751 end = alignment.getWidth();
1755 selection = new String[iSize];
1756 if (alignment.getHiddenColumns() != null
1757 && alignment.getHiddenColumns().hasHiddenColumns())
1759 for (i = 0; i < iSize; i++)
1761 Iterator<int[]> blocks = alignment.getHiddenColumns()
1762 .getVisContigsIterator(start, end + 1, false);
1763 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1768 for (i = 0; i < iSize; i++)
1770 selection[i] = seqs[i].getSequenceAsString(start, end);
1778 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1780 ArrayList<int[]> regions = new ArrayList<>();
1786 HiddenColumns hidden = alignment.getHiddenColumns();
1787 if (hidden != null && hidden.hasHiddenColumns())
1791 start = hidden.visibleToAbsoluteColumn(start);
1794 end = hidden.getNextHiddenBoundary(false, start);
1805 regions.add(new int[] { start, end });
1807 if (hidden != null && hidden.hasHiddenColumns())
1809 start = hidden.visibleToAbsoluteColumn(end);
1810 start = hidden.getNextHiddenBoundary(true, start) + 1;
1812 } while (end < max);
1814 // int[][] startEnd = new int[regions.size()][2];
1820 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1821 boolean selectedOnly)
1823 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1824 AlignmentAnnotation[] aa;
1825 if ((aa = alignment.getAlignmentAnnotation()) != null)
1827 for (AlignmentAnnotation annot : aa)
1829 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1830 if (selectedOnly && selectionGroup != null)
1832 clone.makeVisibleAnnotation(
1833 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1834 alignment.getHiddenColumns());
1838 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1847 public boolean isPadGaps()
1853 public void setPadGaps(boolean padGaps)
1855 this.padGaps = padGaps;
1859 * apply any post-edit constraints and trigger any calculations needed after
1860 * an edit has been performed on the alignment
1865 public void alignmentChanged(AlignmentViewPanel ap)
1869 alignment.padGaps();
1871 if (autoCalculateConsensusAndConservation)
1873 updateConsensus(ap);
1875 if (hconsensus != null && autoCalculateConsensusAndConservation)
1877 updateConservation(ap);
1879 if (autoCalculateStrucConsensus)
1881 updateStrucConsensus(ap);
1884 // Reset endRes of groups if beyond alignment width
1885 int alWidth = alignment.getWidth();
1886 List<SequenceGroup> groups = alignment.getGroups();
1889 for (SequenceGroup sg : groups)
1891 if (sg.getEndRes() > alWidth)
1893 sg.setEndRes(alWidth - 1);
1898 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1900 selectionGroup.setEndRes(alWidth - 1);
1903 updateAllColourSchemes();
1904 calculator.restartWorkers();
1905 // alignment.adjustSequenceAnnotations();
1909 * reset scope and do calculations for all applied colourschemes on alignment
1911 void updateAllColourSchemes()
1913 ResidueShaderI rs = residueShading;
1916 rs.alignmentChanged(alignment, hiddenRepSequences);
1918 rs.setConsensus(hconsensus);
1919 if (rs.conservationApplied())
1921 rs.setConservation(Conservation.calculateConservation("All",
1922 alignment.getSequences(), 0, alignment.getWidth(), false,
1923 getConsPercGaps(), false));
1927 for (SequenceGroup sg : alignment.getGroups())
1931 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1933 sg.recalcConservation();
1937 protected void initAutoAnnotation()
1939 // TODO: add menu option action that nulls or creates consensus object
1940 // depending on if the user wants to see the annotation or not in a
1941 // specific alignment
1943 if (hconsensus == null && !isDataset)
1945 if (!alignment.isNucleotide())
1954 consensus = new AlignmentAnnotation("Consensus",
1955 MessageManager.getString("label.consensus_descr"),
1956 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1957 initConsensus(consensus);
1960 initComplementConsensus();
1965 * If this is a protein alignment and there are mappings to cDNA, adds the
1966 * cDNA consensus annotation and returns true, else returns false.
1968 public boolean initComplementConsensus()
1970 if (!alignment.isNucleotide())
1972 final List<AlignedCodonFrame> codonMappings = alignment
1974 if (codonMappings != null && !codonMappings.isEmpty())
1976 boolean doConsensus = false;
1977 for (AlignedCodonFrame mapping : codonMappings)
1979 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1980 MapList[] mapLists = mapping.getdnaToProt();
1981 // mapLists can be empty if project load has not finished resolving
1983 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1991 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1993 .getString("label.complement_consensus_descr"),
1994 new Annotation[1], 0f, 100f,
1995 AlignmentAnnotation.BAR_GRAPH);
1996 initConsensus(complementConsensus);
2004 private void initConsensus(AlignmentAnnotation aa)
2007 aa.autoCalculated = true;
2011 alignment.addAnnotation(aa);
2015 // these should be extracted from the view model - style and settings for
2016 // derived annotation
2017 private void initGapCounts()
2021 gapcounts = new AlignmentAnnotation("Occupancy",
2022 MessageManager.getString("label.occupancy_descr"),
2023 new Annotation[1], 0f, alignment.getHeight(),
2024 AlignmentAnnotation.BAR_GRAPH);
2025 gapcounts.hasText = true;
2026 gapcounts.autoCalculated = true;
2027 gapcounts.scaleColLabel = true;
2028 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2030 alignment.addAnnotation(gapcounts);
2034 private void initConservation()
2036 if (showConservation)
2038 if (conservation == null)
2040 conservation = new AlignmentAnnotation("Conservation",
2041 MessageManager.formatMessage("label.conservation_descr",
2043 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2044 conservation.hasText = true;
2045 conservation.autoCalculated = true;
2046 alignment.addAnnotation(conservation);
2051 private void initQuality()
2055 if (quality == null)
2057 quality = new AlignmentAnnotation("Quality",
2058 MessageManager.getString("label.quality_descr"),
2059 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2060 quality.hasText = true;
2061 quality.autoCalculated = true;
2062 alignment.addAnnotation(quality);
2067 private void initRNAStructure()
2069 if (alignment.hasRNAStructure() && strucConsensus == null)
2071 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2072 MessageManager.getString("label.strucconsensus_descr"),
2073 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2074 strucConsensus.hasText = true;
2075 strucConsensus.autoCalculated = true;
2079 alignment.addAnnotation(strucConsensus);
2087 * @see jalview.api.AlignViewportI#calcPanelHeight()
2090 public int calcPanelHeight()
2092 // setHeight of panels
2093 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2095 int charHeight = getCharHeight();
2098 BitSet graphgrp = new BitSet();
2099 for (AlignmentAnnotation aa : anns)
2103 System.err.println("Null annotation row: ignoring.");
2110 if (aa.graphGroup > -1)
2112 if (graphgrp.get(aa.graphGroup))
2118 graphgrp.set(aa.graphGroup);
2125 aa.height += charHeight;
2135 aa.height += aa.graphHeight;
2143 height += aa.height;
2155 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2156 boolean preserveNewGroupSettings)
2158 boolean updateCalcs = false;
2159 boolean conv = isShowGroupConservation();
2160 boolean cons = isShowGroupConsensus();
2161 boolean showprf = isShowSequenceLogo();
2162 boolean showConsHist = isShowConsensusHistogram();
2163 boolean normLogo = isNormaliseSequenceLogo();
2166 * TODO reorder the annotation rows according to group/sequence ordering on
2169 // boolean sortg = true;
2171 // remove old automatic annotation
2172 // add any new annotation
2174 // intersect alignment annotation with alignment groups
2176 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2177 List<SequenceGroup> oldrfs = new ArrayList<>();
2180 for (int an = 0; an < aan.length; an++)
2182 if (aan[an].autoCalculated && aan[an].groupRef != null)
2184 oldrfs.add(aan[an].groupRef);
2185 alignment.deleteAnnotation(aan[an], false);
2189 if (alignment.getGroups() != null)
2191 for (SequenceGroup sg : alignment.getGroups())
2193 updateCalcs = false;
2194 if (applyGlobalSettings
2195 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2197 // set defaults for this group's conservation/consensus
2198 sg.setshowSequenceLogo(showprf);
2199 sg.setShowConsensusHistogram(showConsHist);
2200 sg.setNormaliseSequenceLogo(normLogo);
2205 alignment.addAnnotation(sg.getConservationRow(), 0);
2210 alignment.addAnnotation(sg.getConsensus(), 0);
2212 // refresh the annotation rows
2215 sg.recalcConservation();
2223 public boolean isDisplayReferenceSeq()
2225 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2229 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2231 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2235 public boolean isColourByReferenceSeq()
2237 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2241 public Color getSequenceColour(SequenceI seq)
2243 Color sqc = sequenceColours.get(seq);
2244 return (sqc == null ? Color.white : sqc);
2248 public void setSequenceColour(SequenceI seq, Color col)
2252 sequenceColours.remove(seq);
2256 sequenceColours.put(seq, col);
2261 public void updateSequenceIdColours()
2263 for (SequenceGroup sg : alignment.getGroups())
2265 if (sg.idColour != null)
2267 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2269 sequenceColours.put(s, sg.idColour);
2276 public void clearSequenceColours()
2278 sequenceColours.clear();
2282 public AlignViewportI getCodingComplement()
2284 return this.codingComplement;
2288 * Set this as the (cDna/protein) complement of the given viewport. Also
2289 * ensures the reverse relationship is set on the given viewport.
2292 public void setCodingComplement(AlignViewportI av)
2296 System.err.println("Ignoring recursive setCodingComplement request");
2300 this.codingComplement = av;
2301 // avoid infinite recursion!
2302 if (av.getCodingComplement() != this)
2304 av.setCodingComplement(this);
2310 public boolean isNucleotide()
2312 return getAlignment() == null ? false : getAlignment().isNucleotide();
2316 public FeaturesDisplayedI getFeaturesDisplayed()
2318 return featuresDisplayed;
2322 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2324 featuresDisplayed = featuresDisplayedI;
2328 public boolean areFeaturesDisplayed()
2330 return featuresDisplayed != null
2331 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2338 * features are displayed if true
2341 public void setShowSequenceFeatures(boolean b)
2343 viewStyle.setShowSequenceFeatures(b);
2347 public boolean isShowSequenceFeatures()
2349 return viewStyle.isShowSequenceFeatures();
2353 public void setShowSequenceFeaturesHeight(boolean selected)
2355 viewStyle.setShowSequenceFeaturesHeight(selected);
2359 public boolean isShowSequenceFeaturesHeight()
2361 return viewStyle.isShowSequenceFeaturesHeight();
2365 public void setShowAnnotation(boolean b)
2367 viewStyle.setShowAnnotation(b);
2371 public boolean isShowAnnotation()
2373 return viewStyle.isShowAnnotation();
2377 public boolean isRightAlignIds()
2379 return viewStyle.isRightAlignIds();
2383 public void setRightAlignIds(boolean rightAlignIds)
2385 viewStyle.setRightAlignIds(rightAlignIds);
2389 public boolean getConservationSelected()
2391 return viewStyle.getConservationSelected();
2395 public void setShowBoxes(boolean state)
2397 viewStyle.setShowBoxes(state);
2402 * @see jalview.api.ViewStyleI#getTextColour()
2405 public Color getTextColour()
2407 return viewStyle.getTextColour();
2412 * @see jalview.api.ViewStyleI#getTextColour2()
2415 public Color getTextColour2()
2417 return viewStyle.getTextColour2();
2422 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2425 public int getThresholdTextColour()
2427 return viewStyle.getThresholdTextColour();
2432 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2435 public boolean isConservationColourSelected()
2437 return viewStyle.isConservationColourSelected();
2442 * @see jalview.api.ViewStyleI#isRenderGaps()
2445 public boolean isRenderGaps()
2447 return viewStyle.isRenderGaps();
2452 * @see jalview.api.ViewStyleI#isShowColourText()
2455 public boolean isShowColourText()
2457 return viewStyle.isShowColourText();
2461 * @param conservationColourSelected
2462 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2465 public void setConservationColourSelected(
2466 boolean conservationColourSelected)
2468 viewStyle.setConservationColourSelected(conservationColourSelected);
2472 * @param showColourText
2473 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2476 public void setShowColourText(boolean showColourText)
2478 viewStyle.setShowColourText(showColourText);
2483 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2486 public void setTextColour(Color textColour)
2488 viewStyle.setTextColour(textColour);
2492 * @param thresholdTextColour
2493 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2496 public void setThresholdTextColour(int thresholdTextColour)
2498 viewStyle.setThresholdTextColour(thresholdTextColour);
2502 * @param textColour2
2503 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2506 public void setTextColour2(Color textColour2)
2508 viewStyle.setTextColour2(textColour2);
2512 public ViewStyleI getViewStyle()
2514 return new ViewStyle(viewStyle);
2518 public void setViewStyle(ViewStyleI settingsForView)
2520 viewStyle = new ViewStyle(settingsForView);
2521 if (residueShading != null)
2523 residueShading.setConservationApplied(
2524 settingsForView.isConservationColourSelected());
2529 public boolean sameStyle(ViewStyleI them)
2531 return viewStyle.sameStyle(them);
2536 * @see jalview.api.ViewStyleI#getIdWidth()
2539 public int getIdWidth()
2541 return viewStyle.getIdWidth();
2546 * @see jalview.api.ViewStyleI#setIdWidth(int)
2549 public void setIdWidth(int i)
2551 viewStyle.setIdWidth(i);
2556 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2559 public boolean isCentreColumnLabels()
2561 return viewStyle.isCentreColumnLabels();
2565 * @param centreColumnLabels
2566 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2569 public void setCentreColumnLabels(boolean centreColumnLabels)
2571 viewStyle.setCentreColumnLabels(centreColumnLabels);
2576 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2579 public void setShowDBRefs(boolean showdbrefs)
2581 viewStyle.setShowDBRefs(showdbrefs);
2586 * @see jalview.api.ViewStyleI#isShowDBRefs()
2589 public boolean isShowDBRefs()
2591 return viewStyle.isShowDBRefs();
2596 * @see jalview.api.ViewStyleI#isShowNPFeats()
2599 public boolean isShowNPFeats()
2601 return viewStyle.isShowNPFeats();
2605 * @param shownpfeats
2606 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2609 public void setShowNPFeats(boolean shownpfeats)
2611 viewStyle.setShowNPFeats(shownpfeats);
2614 public abstract StructureSelectionManager getStructureSelectionManager();
2617 * Add one command to the command history list.
2621 public void addToHistoryList(CommandI command)
2623 if (this.historyList != null)
2625 this.historyList.push(command);
2626 broadcastCommand(command, false);
2630 protected void broadcastCommand(CommandI command, boolean undo)
2632 getStructureSelectionManager().commandPerformed(command, undo,
2637 * Add one command to the command redo list.
2641 public void addToRedoList(CommandI command)
2643 if (this.redoList != null)
2645 this.redoList.push(command);
2647 broadcastCommand(command, true);
2651 * Clear the command redo list.
2653 public void clearRedoList()
2655 if (this.redoList != null)
2657 this.redoList.clear();
2661 public void setHistoryList(Deque<CommandI> list)
2663 this.historyList = list;
2666 public Deque<CommandI> getHistoryList()
2668 return this.historyList;
2671 public void setRedoList(Deque<CommandI> list)
2673 this.redoList = list;
2676 public Deque<CommandI> getRedoList()
2678 return this.redoList;
2682 public VamsasSource getVamsasSource()
2687 public SequenceAnnotationOrder getSortAnnotationsBy()
2689 return sortAnnotationsBy;
2692 public void setSortAnnotationsBy(
2693 SequenceAnnotationOrder sortAnnotationsBy)
2695 this.sortAnnotationsBy = sortAnnotationsBy;
2698 public boolean isShowAutocalculatedAbove()
2700 return showAutocalculatedAbove;
2703 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2705 this.showAutocalculatedAbove = showAutocalculatedAbove;
2709 public boolean isScaleProteinAsCdna()
2711 return viewStyle.isScaleProteinAsCdna();
2715 public void setScaleProteinAsCdna(boolean b)
2717 viewStyle.setScaleProteinAsCdna(b);
2721 public boolean isProteinFontAsCdna()
2723 return viewStyle.isProteinFontAsCdna();
2727 public void setProteinFontAsCdna(boolean b)
2729 viewStyle.setProteinFontAsCdna(b);
2733 public void setShowComplementFeatures(boolean b)
2735 viewStyle.setShowComplementFeatures(b);
2739 public boolean isShowComplementFeatures()
2741 return viewStyle.isShowComplementFeatures();
2745 public void setShowComplementFeaturesOnTop(boolean b)
2747 viewStyle.setShowComplementFeaturesOnTop(b);
2751 public boolean isShowComplementFeaturesOnTop()
2753 return viewStyle.isShowComplementFeaturesOnTop();
2757 * @return true if view should scroll to show the highlighted region of a
2762 public final boolean isFollowHighlight()
2764 return followHighlight;
2768 public final void setFollowHighlight(boolean b)
2770 this.followHighlight = b;
2774 public ViewportRanges getRanges()
2780 * Helper method to populate the SearchResults with the location in the
2781 * complementary alignment to scroll to, in order to match this one.
2784 * the SearchResults to add to
2785 * @return the offset (below top of visible region) of the matched sequence
2787 protected int findComplementScrollTarget(SearchResultsI sr)
2789 final AlignViewportI complement = getCodingComplement();
2790 if (complement == null || !complement.isFollowHighlight())
2794 boolean iAmProtein = !getAlignment().isNucleotide();
2795 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2796 : complement.getAlignment();
2797 if (proteinAlignment == null)
2801 final List<AlignedCodonFrame> mappings = proteinAlignment
2805 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2806 * residue in the middle column of the visible region. Scroll the
2807 * complementary alignment to line up the corresponding residue.
2810 SequenceI sequence = null;
2813 * locate 'middle' column (true middle if an odd number visible, left of
2814 * middle if an even number visible)
2816 int middleColumn = ranges.getStartRes()
2817 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2818 final HiddenSequences hiddenSequences = getAlignment()
2819 .getHiddenSequences();
2822 * searching to the bottom of the alignment gives smoother scrolling across
2823 * all gapped visible regions
2825 int lastSeq = alignment.getHeight() - 1;
2826 List<AlignedCodonFrame> seqMappings = null;
2827 for (int seqNo = ranges
2828 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2830 sequence = getAlignment().getSequenceAt(seqNo);
2831 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2835 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2839 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2841 getCodingComplement().getAlignment().getSequences());
2842 if (!seqMappings.isEmpty())
2848 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2851 * No ungapped mapped sequence in middle column - do nothing
2855 MappingUtils.addSearchResults(sr, sequence,
2856 sequence.findPosition(middleColumn), seqMappings);
2861 * synthesize a column selection if none exists so it covers the given
2862 * selection group. if wholewidth is false, no column selection is made if the
2863 * selection group covers the whole alignment width.
2868 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2871 if (sg != null && (sgs = sg.getStartRes()) >= 0
2872 && sg.getStartRes() <= (sge = sg.getEndRes())
2873 && !this.hasSelectedColumns())
2875 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2882 colSel = new ColumnSelection();
2884 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2886 colSel.addElement(cspos);
2892 * hold status of current selection group - defined on alignment or not.
2894 private boolean selectionIsDefinedGroup = false;
2897 public boolean isSelectionDefinedGroup()
2899 if (selectionGroup == null)
2903 if (isSelectionGroupChanged(true))
2905 selectionIsDefinedGroup = false;
2906 List<SequenceGroup> gps = alignment.getGroups();
2907 if (gps == null || gps.size() == 0)
2909 selectionIsDefinedGroup = false;
2913 selectionIsDefinedGroup = gps.contains(selectionGroup);
2916 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2920 * null, or currently highlighted results on this view
2922 private SearchResultsI searchResults = null;
2924 protected TreeModel currentTree = null;
2927 public boolean hasSearchResults()
2929 return searchResults != null;
2933 public void setSearchResults(SearchResultsI results)
2935 searchResults = results;
2939 public SearchResultsI getSearchResults()
2941 return searchResults;
2945 * get the consensus sequence as displayed under the PID consensus annotation
2948 * @return consensus sequence as a new sequence object
2950 public SequenceI getConsensusSeq()
2952 if (consensus == null)
2954 updateConsensus(null);
2956 if (consensus == null)
2960 StringBuffer seqs = new StringBuffer();
2961 for (int i = 0; i < consensus.annotations.length; i++)
2963 Annotation annotation = consensus.annotations[i];
2964 if (annotation != null)
2966 String description = annotation.description;
2967 if (description != null && description.startsWith("["))
2969 // consensus is a tie - just pick the first one
2970 seqs.append(description.charAt(1));
2974 seqs.append(annotation.displayCharacter);
2979 SequenceI sq = new Sequence("Consensus", seqs.toString());
2980 sq.setDescription("Percentage Identity Consensus "
2981 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2986 public void setCurrentTree(TreeModel tree)
2992 public TreeModel getCurrentTree()
2998 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
3000 AlignmentI alignmentToExport = null;
3001 String[] omitHidden = null;
3002 alignmentToExport = null;
3004 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3006 omitHidden = getViewAsString(false,
3007 options.isExportHiddenSequences());
3010 int[] alignmentStartEnd = new int[2];
3011 if (hasHiddenRows() && options.isExportHiddenSequences())
3013 alignmentToExport = getAlignment().getHiddenSequences()
3014 .getFullAlignment();
3018 alignmentToExport = getAlignment();
3020 alignmentStartEnd = getAlignment().getHiddenColumns()
3021 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3022 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3023 omitHidden, alignmentStartEnd);
3028 * flag set to indicate if structure views might be out of sync with sequences
3032 private boolean needToUpdateStructureViews = false;
3035 public boolean isUpdateStructures()
3037 return needToUpdateStructureViews;
3041 public void setUpdateStructures(boolean update)
3043 needToUpdateStructureViews = update;
3047 public boolean needToUpdateStructureViews()
3049 boolean update = needToUpdateStructureViews;
3050 needToUpdateStructureViews = false;
3055 public void addSequenceGroup(SequenceGroup sequenceGroup)
3057 alignment.addGroup(sequenceGroup);
3059 Color col = sequenceGroup.idColour;
3062 col = col.brighter();
3064 for (SequenceI sq : sequenceGroup.getSequences())
3066 setSequenceColour(sq, col);
3070 if (codingComplement != null)
3072 SequenceGroup mappedGroup = MappingUtils
3073 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3074 if (mappedGroup.getSequences().size() > 0)
3076 codingComplement.getAlignment().addGroup(mappedGroup);
3080 for (SequenceI seq : mappedGroup.getSequences())
3082 codingComplement.setSequenceColour(seq, col);
3086 // propagate the structure view update flag according to our own setting
3087 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3093 * Notify TreePanel and AlignmentPanel of some sort of alignment change.
3095 public void notifyAlignment()
3097 changeSupport.firePropertyChange(PROPERTY_ALIGNMENT, null, alignment.getSequences());
3101 * Notify AlignmentPanel of a sequence column selection or visibility changes.
3103 public void notifySequence()
3105 changeSupport.firePropertyChange(PROPERTY_SEQUENCE, null, null);