2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import java.awt.Color;
24 import java.beans.PropertyChangeSupport;
25 import java.util.ArrayDeque;
26 import java.util.ArrayList;
27 import java.util.BitSet;
28 import java.util.Deque;
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.List;
35 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
36 import jalview.analysis.Conservation;
37 import jalview.analysis.TreeModel;
38 import jalview.api.AlignCalcManagerI;
39 import jalview.api.AlignExportSettingsI;
40 import jalview.api.AlignViewportI;
41 import jalview.api.AlignmentViewPanel;
42 import jalview.api.FeaturesDisplayedI;
43 import jalview.api.ViewStyleI;
44 import jalview.bin.Console;
45 import jalview.commands.CommandI;
46 import jalview.datamodel.AlignedCodonFrame;
47 import jalview.datamodel.AlignmentAnnotation;
48 import jalview.datamodel.AlignmentExportData;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.AlignmentView;
51 import jalview.datamodel.Annotation;
52 import jalview.datamodel.ColumnSelection;
53 import jalview.datamodel.ContactListI;
54 import jalview.datamodel.HiddenColumns;
55 import jalview.datamodel.HiddenSequences;
56 import jalview.datamodel.ProfilesI;
57 import jalview.datamodel.SearchResultsI;
58 import jalview.datamodel.Sequence;
59 import jalview.datamodel.SequenceCollectionI;
60 import jalview.datamodel.SequenceGroup;
61 import jalview.datamodel.SequenceI;
62 import jalview.project.Jalview2XML;
63 import jalview.renderer.ResidueShader;
64 import jalview.renderer.ResidueShaderI;
65 import jalview.schemes.ColourSchemeI;
66 import jalview.structure.CommandListener;
67 import jalview.structure.StructureSelectionManager;
68 import jalview.structure.VamsasSource;
69 import jalview.util.Comparison;
70 import jalview.util.MapList;
71 import jalview.util.MappingUtils;
72 import jalview.util.MessageManager;
73 import jalview.viewmodel.styles.ViewStyle;
74 import jalview.workers.AlignCalcManager;
75 import jalview.workers.ComplementConsensusThread;
76 import jalview.workers.ConsensusThread;
77 import jalview.workers.StrucConsensusThread;
80 * base class holding visualization and analysis attributes and common logic for
81 * an active alignment view displayed in the GUI
86 public abstract class AlignmentViewport
87 implements AlignViewportI, CommandListener, VamsasSource
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 * used to determine if quit should be confirmed
108 private boolean savedUpToDate = false;
111 * alignment displayed in the viewport. Please use get/setter
113 protected AlignmentI alignment;
115 public AlignmentViewport(AlignmentI al)
118 ranges = new ViewportRanges(al);
123 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
126 public void setFontName(String name)
128 viewStyle.setFontName(name);
133 * @see jalview.api.ViewStyleI#setFontStyle(int)
136 public void setFontStyle(int style)
138 viewStyle.setFontStyle(style);
143 * @see jalview.api.ViewStyleI#setFontSize(int)
146 public void setFontSize(int size)
148 viewStyle.setFontSize(size);
153 * @see jalview.api.ViewStyleI#getFontStyle()
156 public int getFontStyle()
158 return viewStyle.getFontStyle();
163 * @see jalview.api.ViewStyleI#getFontName()
166 public String getFontName()
168 return viewStyle.getFontName();
173 * @see jalview.api.ViewStyleI#getFontSize()
176 public int getFontSize()
178 return viewStyle.getFontSize();
182 * @param upperCasebold
183 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
186 public void setUpperCasebold(boolean upperCasebold)
188 viewStyle.setUpperCasebold(upperCasebold);
193 * @see jalview.api.ViewStyleI#isUpperCasebold()
196 public boolean isUpperCasebold()
198 return viewStyle.isUpperCasebold();
203 * @see jalview.api.ViewStyleI#isSeqNameItalics()
206 public boolean isSeqNameItalics()
208 return viewStyle.isSeqNameItalics();
212 * @param colourByReferenceSeq
213 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
216 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
218 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
223 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
226 public void setColourAppliesToAllGroups(boolean b)
228 viewStyle.setColourAppliesToAllGroups(b);
233 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
236 public boolean getColourAppliesToAllGroups()
238 return viewStyle.getColourAppliesToAllGroups();
243 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
246 public boolean getAbovePIDThreshold()
248 return viewStyle.getAbovePIDThreshold();
253 * @see jalview.api.ViewStyleI#setIncrement(int)
256 public void setIncrement(int inc)
258 viewStyle.setIncrement(inc);
263 * @see jalview.api.ViewStyleI#getIncrement()
266 public int getIncrement()
268 return viewStyle.getIncrement();
273 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
276 public void setConservationSelected(boolean b)
278 viewStyle.setConservationSelected(b);
283 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
286 public void setShowHiddenMarkers(boolean show)
288 viewStyle.setShowHiddenMarkers(show);
293 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
296 public boolean getShowHiddenMarkers()
298 return viewStyle.getShowHiddenMarkers();
303 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
306 public void setScaleRightWrapped(boolean b)
308 viewStyle.setScaleRightWrapped(b);
313 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
316 public void setScaleLeftWrapped(boolean b)
318 viewStyle.setScaleLeftWrapped(b);
323 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
326 public void setScaleAboveWrapped(boolean b)
328 viewStyle.setScaleAboveWrapped(b);
333 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
336 public boolean getScaleLeftWrapped()
338 return viewStyle.getScaleLeftWrapped();
343 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
346 public boolean getScaleAboveWrapped()
348 return viewStyle.getScaleAboveWrapped();
353 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
356 public boolean getScaleRightWrapped()
358 return viewStyle.getScaleRightWrapped();
363 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
366 public void setAbovePIDThreshold(boolean b)
368 viewStyle.setAbovePIDThreshold(b);
373 * @see jalview.api.ViewStyleI#setThreshold(int)
376 public void setThreshold(int thresh)
378 viewStyle.setThreshold(thresh);
383 * @see jalview.api.ViewStyleI#getThreshold()
386 public int getThreshold()
388 return viewStyle.getThreshold();
393 * @see jalview.api.ViewStyleI#getShowJVSuffix()
396 public boolean getShowJVSuffix()
398 return viewStyle.getShowJVSuffix();
403 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
406 public void setShowJVSuffix(boolean b)
408 viewStyle.setShowJVSuffix(b);
413 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
416 public void setWrapAlignment(boolean state)
418 viewStyle.setWrapAlignment(state);
419 ranges.setWrappedMode(state);
424 * @see jalview.api.ViewStyleI#setShowText(boolean)
427 public void setShowText(boolean state)
429 viewStyle.setShowText(state);
434 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
437 public void setRenderGaps(boolean state)
439 viewStyle.setRenderGaps(state);
444 * @see jalview.api.ViewStyleI#getColourText()
447 public boolean getColourText()
449 return viewStyle.getColourText();
454 * @see jalview.api.ViewStyleI#setColourText(boolean)
457 public void setColourText(boolean state)
459 viewStyle.setColourText(state);
464 * @see jalview.api.ViewStyleI#getWrapAlignment()
467 public boolean getWrapAlignment()
469 return viewStyle.getWrapAlignment();
474 * @see jalview.api.ViewStyleI#getShowText()
477 public boolean getShowText()
479 return viewStyle.getShowText();
484 * @see jalview.api.ViewStyleI#getWrappedWidth()
487 public int getWrappedWidth()
489 return viewStyle.getWrappedWidth();
494 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
497 public void setWrappedWidth(int w)
499 viewStyle.setWrappedWidth(w);
504 * @see jalview.api.ViewStyleI#getCharHeight()
507 public int getCharHeight()
509 return viewStyle.getCharHeight();
514 * @see jalview.api.ViewStyleI#setCharHeight(int)
517 public void setCharHeight(int h)
519 viewStyle.setCharHeight(h);
524 * @see jalview.api.ViewStyleI#getCharWidth()
527 public int getCharWidth()
529 return viewStyle.getCharWidth();
534 * @see jalview.api.ViewStyleI#setCharWidth(int)
537 public void setCharWidth(int w)
539 viewStyle.setCharWidth(w);
544 * @see jalview.api.ViewStyleI#getShowBoxes()
547 public boolean getShowBoxes()
549 return viewStyle.getShowBoxes();
554 * @see jalview.api.ViewStyleI#getShowUnconserved()
557 public boolean getShowUnconserved()
559 return viewStyle.getShowUnconserved();
563 * @param showunconserved
564 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
567 public void setShowUnconserved(boolean showunconserved)
569 viewStyle.setShowUnconserved(showunconserved);
574 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
577 public void setSeqNameItalics(boolean default1)
579 viewStyle.setSeqNameItalics(default1);
583 public AlignmentI getAlignment()
589 public char getGapCharacter()
591 return alignment.getGapCharacter();
594 protected String sequenceSetID;
597 * probably unused indicator that view is of a dataset rather than an
600 protected boolean isDataset = false;
602 public void setDataset(boolean b)
607 public boolean isDataset()
612 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
614 protected ColumnSelection colSel = new ColumnSelection();
616 public boolean autoCalculateConsensus = true;
618 protected boolean autoCalculateStrucConsensus = true;
620 protected boolean ignoreGapsInConsensusCalculation = false;
622 protected ResidueShaderI residueShading = new ResidueShader();
625 public void setGlobalColourScheme(ColourSchemeI cs)
627 // TODO: logic refactored from AlignFrame changeColour -
628 // TODO: autorecalc stuff should be changed to rely on the worker system
629 // check to see if we should implement a changeColour(cs) method rather than
630 // put the logic in here
631 // - means that caller decides if they want to just modify state and defer
632 // calculation till later or to do all calculations in thread.
636 * only instantiate alignment colouring once, thereafter update it;
637 * this means that any conservation or PID threshold settings
638 * persist when the alignment colour scheme is changed
640 if (residueShading == null)
642 residueShading = new ResidueShader(viewStyle);
644 residueShading.setColourScheme(cs);
646 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
647 // ...problem: groups need these, but do not currently have a ViewStyle
651 if (getConservationSelected())
653 residueShading.setConservation(hconservation);
656 * reset conservation flag in case just set to false if
657 * Conservation was null (calculation still in progress)
659 residueShading.setConservationApplied(getConservationSelected());
660 residueShading.alignmentChanged(alignment, hiddenRepSequences);
664 * if 'apply colour to all groups' is selected... do so
665 * (but don't transfer any colour threshold settings to groups)
667 if (getColourAppliesToAllGroups())
669 for (SequenceGroup sg : getAlignment().getGroups())
672 * retain any colour thresholds per group while
673 * changing choice of colour scheme (JAL-2386)
675 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
678 sg.getGroupColourScheme().alignmentChanged(sg,
686 public ColourSchemeI getGlobalColourScheme()
688 return residueShading == null ? null : residueShading.getColourScheme();
692 public ResidueShaderI getResidueShading()
694 return residueShading;
697 protected AlignmentAnnotation consensus;
699 protected AlignmentAnnotation complementConsensus;
701 protected AlignmentAnnotation gapcounts;
703 protected AlignmentAnnotation strucConsensus;
705 protected AlignmentAnnotation conservation;
707 protected AlignmentAnnotation quality;
709 protected AlignmentAnnotation[] groupConsensus;
711 protected AlignmentAnnotation[] groupConservation;
714 * results of alignment consensus analysis for visible portion of view
716 protected ProfilesI hconsensus = null;
719 * results of cDNA complement consensus visible portion of view
721 protected Hashtable<String, Object>[] hcomplementConsensus = null;
724 * results of secondary structure base pair consensus for visible portion of
727 protected Hashtable<String, Object>[] hStrucConsensus = null;
729 protected Conservation hconservation = null;
732 public void setConservation(Conservation cons)
734 hconservation = cons;
738 * percentage gaps allowed in a column before all amino acid properties should
739 * be considered unconserved
741 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
744 public int getConsPercGaps()
750 public void setSequenceConsensusHash(ProfilesI hconsensus)
752 this.hconsensus = hconsensus;
756 public void setComplementConsensusHash(
757 Hashtable<String, Object>[] hconsensus)
759 this.hcomplementConsensus = hconsensus;
763 public ProfilesI getSequenceConsensusHash()
769 public Hashtable<String, Object>[] getComplementConsensusHash()
771 return hcomplementConsensus;
775 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
777 return hStrucConsensus;
781 public void setRnaStructureConsensusHash(
782 Hashtable<String, Object>[] hStrucConsensus)
784 this.hStrucConsensus = hStrucConsensus;
789 public AlignmentAnnotation getAlignmentQualityAnnot()
795 public AlignmentAnnotation getAlignmentConservationAnnotation()
801 public AlignmentAnnotation getAlignmentConsensusAnnotation()
807 public AlignmentAnnotation getAlignmentGapAnnotation()
813 public AlignmentAnnotation getComplementConsensusAnnotation()
815 return complementConsensus;
819 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
821 return strucConsensus;
824 protected AlignCalcManagerI calculator = new AlignCalcManager();
827 * trigger update of conservation annotation
829 public void updateConservation(final AlignmentViewPanel ap)
831 // see note in mantis : issue number 8585
832 if (alignment.isNucleotide()
833 || (conservation == null && quality == null)
834 || !autoCalculateConsensus)
838 if (calculator.getRegisteredWorkersOfClass(
839 jalview.workers.ConservationThread.class) == null)
841 calculator.registerWorker(
842 new jalview.workers.ConservationThread(this, ap));
847 * trigger update of consensus annotation
849 public void updateConsensus(final AlignmentViewPanel ap)
851 // see note in mantis : issue number 8585
852 if (consensus == null || !autoCalculateConsensus)
857 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
859 calculator.registerWorker(new ConsensusThread(this, ap));
863 * A separate thread to compute cDNA consensus for a protein alignment
864 * which has mapping to cDNA
866 final AlignmentI al = this.getAlignment();
867 if (!al.isNucleotide() && al.getCodonFrames() != null
868 && !al.getCodonFrames().isEmpty())
871 * fudge - check first for protein-to-nucleotide mappings
872 * (we don't want to do this for protein-to-protein)
874 boolean doConsensus = false;
875 for (AlignedCodonFrame mapping : al.getCodonFrames())
877 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
878 MapList[] mapLists = mapping.getdnaToProt();
879 // mapLists can be empty if project load has not finished resolving seqs
880 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
888 if (calculator.getRegisteredWorkersOfClass(
889 ComplementConsensusThread.class) == null)
892 .registerWorker(new ComplementConsensusThread(this, ap));
898 // --------START Structure Conservation
899 public void updateStrucConsensus(final AlignmentViewPanel ap)
901 if (autoCalculateStrucConsensus && strucConsensus == null
902 && alignment.isNucleotide() && alignment.hasRNAStructure())
904 // secondary structure has been added - so init the consensus line
908 // see note in mantis : issue number 8585
909 if (strucConsensus == null || !autoCalculateStrucConsensus)
913 if (calculator.getRegisteredWorkersOfClass(
914 StrucConsensusThread.class) == null)
916 calculator.registerWorker(new StrucConsensusThread(this, ap));
920 public boolean isCalcInProgress()
922 return calculator.isWorking();
926 public boolean isCalculationInProgress(
927 AlignmentAnnotation alignmentAnnotation)
929 if (!alignmentAnnotation.autoCalculated)
933 if (calculator.workingInvolvedWith(alignmentAnnotation))
935 // System.err.println("grey out ("+alignmentAnnotation.label+")");
941 public void setAlignment(AlignmentI align)
943 this.alignment = align;
947 * Clean up references when this viewport is closed
950 public void dispose()
953 * defensively null out references to large objects in case
954 * this object is not garbage collected (as if!)
957 complementConsensus = null;
958 strucConsensus = null;
961 groupConsensus = null;
962 groupConservation = null;
964 hconservation = null;
965 hcomplementConsensus = null;
968 residueShading = null; // may hold a reference to Consensus
969 changeSupport = null;
972 selectionGroup = null;
978 public boolean isClosed()
980 // TODO: check that this isClosed is only true after panel is closed, not
981 // before it is fully constructed.
982 return alignment == null;
986 public AlignCalcManagerI getCalcManager()
992 * should conservation rows be shown for groups
994 protected boolean showGroupConservation = false;
997 * should consensus rows be shown for groups
999 protected boolean showGroupConsensus = false;
1002 * should consensus profile be rendered by default
1004 protected boolean showSequenceLogo = false;
1007 * should consensus profile be rendered normalised to row height
1009 protected boolean normaliseSequenceLogo = false;
1012 * should consensus histograms be rendered by default
1014 protected boolean showConsensusHistogram = true;
1017 * @return the showConsensusProfile
1020 public boolean isShowSequenceLogo()
1022 return showSequenceLogo;
1026 * @param showSequenceLogo
1029 public void setShowSequenceLogo(boolean showSequenceLogo)
1031 if (showSequenceLogo != this.showSequenceLogo)
1033 // TODO: decouple settings setting from calculation when refactoring
1034 // annotation update method from alignframe to viewport
1035 this.showSequenceLogo = showSequenceLogo;
1036 calculator.updateAnnotationFor(ConsensusThread.class);
1037 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1038 calculator.updateAnnotationFor(StrucConsensusThread.class);
1040 this.showSequenceLogo = showSequenceLogo;
1044 * @param showConsensusHistogram
1045 * the showConsensusHistogram to set
1047 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1049 this.showConsensusHistogram = showConsensusHistogram;
1053 * @return the showGroupConservation
1055 public boolean isShowGroupConservation()
1057 return showGroupConservation;
1061 * @param showGroupConservation
1062 * the showGroupConservation to set
1064 public void setShowGroupConservation(boolean showGroupConservation)
1066 this.showGroupConservation = showGroupConservation;
1070 * @return the showGroupConsensus
1072 public boolean isShowGroupConsensus()
1074 return showGroupConsensus;
1078 * @param showGroupConsensus
1079 * the showGroupConsensus to set
1081 public void setShowGroupConsensus(boolean showGroupConsensus)
1083 this.showGroupConsensus = showGroupConsensus;
1088 * @return flag to indicate if the consensus histogram should be rendered by
1092 public boolean isShowConsensusHistogram()
1094 return this.showConsensusHistogram;
1098 * when set, updateAlignment will always ensure sequences are of equal length
1100 private boolean padGaps = false;
1103 * when set, alignment should be reordered according to a newly opened tree
1105 public boolean sortByTree = false;
1110 * @return null or the currently selected sequence region
1113 public SequenceGroup getSelectionGroup()
1115 return selectionGroup;
1119 * Set the selection group for this window. Also sets the current alignment as
1120 * the context for the group, if it does not already have one.
1123 * - group holding references to sequences in this alignment view
1127 public void setSelectionGroup(SequenceGroup sg)
1129 selectionGroup = sg;
1130 if (sg != null && sg.getContext() == null)
1132 sg.setContext(alignment);
1136 public void setHiddenColumns(HiddenColumns hidden)
1138 this.alignment.setHiddenColumns(hidden);
1142 public ColumnSelection getColumnSelection()
1148 public void setColumnSelection(ColumnSelection colSel)
1150 this.colSel = colSel;
1153 updateHiddenColumns();
1155 isColSelChanged(true);
1163 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1165 return hiddenRepSequences;
1169 public void setHiddenRepSequences(
1170 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1172 this.hiddenRepSequences = hiddenRepSequences;
1176 public boolean hasSelectedColumns()
1178 ColumnSelection columnSelection = getColumnSelection();
1179 return columnSelection != null && columnSelection.hasSelectedColumns();
1183 public boolean hasHiddenColumns()
1185 return alignment.getHiddenColumns() != null
1186 && alignment.getHiddenColumns().hasHiddenColumns();
1189 public void updateHiddenColumns()
1191 // this method doesn't really do anything now. But - it could, since a
1192 // column Selection could be in the process of modification
1193 // hasHiddenColumns = colSel.hasHiddenColumns();
1197 public boolean hasHiddenRows()
1199 return alignment.getHiddenSequences().getSize() > 0;
1202 protected SequenceGroup selectionGroup;
1204 public void setSequenceSetId(String newid)
1206 if (sequenceSetID != null)
1209 "Warning - overwriting a sequenceSetId for a viewport!");
1211 sequenceSetID = new String(newid);
1215 public String getSequenceSetId()
1217 if (sequenceSetID == null)
1219 sequenceSetID = alignment.hashCode() + "";
1222 return sequenceSetID;
1226 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1229 protected String viewId = null;
1232 public String getViewId()
1236 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1241 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1243 ignoreGapsInConsensusCalculation = b;
1246 updateConsensus(ap);
1247 if (residueShading != null)
1249 residueShading.setThreshold(residueShading.getThreshold(),
1250 ignoreGapsInConsensusCalculation);
1256 private long sgrouphash = -1, colselhash = -1;
1259 * checks current SelectionGroup against record of last hash value, and
1263 * update the record of last hash value
1265 * @return true if SelectionGroup changed since last call (when b is true)
1267 public boolean isSelectionGroupChanged(boolean b)
1269 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1270 : selectionGroup.hashCode();
1271 if (hc != -1 && hc != sgrouphash)
1283 * checks current colsel against record of last hash value, and optionally
1287 * update the record of last hash value
1288 * @return true if colsel changed since last call (when b is true)
1290 public boolean isColSelChanged(boolean b)
1292 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1293 if (hc != -1 && hc != colselhash)
1305 public boolean isIgnoreGapsConsensus()
1307 return ignoreGapsInConsensusCalculation;
1310 // property change stuff
1311 // JBPNote Prolly only need this in the applet version.
1312 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1315 protected boolean showConservation = true;
1317 protected boolean showQuality = true;
1319 protected boolean showConsensus = true;
1321 protected boolean showOccupancy = true;
1323 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1325 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1327 protected boolean showAutocalculatedAbove;
1330 * when set, view will scroll to show the highlighted position
1332 private boolean followHighlight = true;
1335 * Property change listener for changes in alignment
1340 public void addPropertyChangeListener(
1341 java.beans.PropertyChangeListener listener)
1343 changeSupport.addPropertyChangeListener(listener);
1352 public void removePropertyChangeListener(
1353 java.beans.PropertyChangeListener listener)
1355 if (changeSupport != null)
1357 changeSupport.removePropertyChangeListener(listener);
1362 * Property change listener for changes in alignment
1371 public void firePropertyChange(String prop, Object oldvalue,
1374 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1377 // common hide/show column stuff
1379 public void hideSelectedColumns()
1381 if (colSel.isEmpty())
1386 colSel.hideSelectedColumns(alignment);
1387 setSelectionGroup(null);
1388 isColSelChanged(true);
1391 public void hideColumns(int start, int end)
1395 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1399 alignment.getHiddenColumns().hideColumns(start, end);
1401 isColSelChanged(true);
1404 public void showColumn(int col)
1406 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1407 isColSelChanged(true);
1410 public void showAllHiddenColumns()
1412 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1413 isColSelChanged(true);
1416 // common hide/show seq stuff
1417 public void showAllHiddenSeqs()
1419 int startSeq = ranges.getStartSeq();
1420 int endSeq = ranges.getEndSeq();
1422 if (alignment.getHiddenSequences().getSize() > 0)
1424 if (selectionGroup == null)
1426 selectionGroup = new SequenceGroup();
1427 selectionGroup.setEndRes(alignment.getWidth() - 1);
1429 List<SequenceI> tmp = alignment.getHiddenSequences()
1430 .showAll(hiddenRepSequences);
1431 for (SequenceI seq : tmp)
1433 selectionGroup.addSequence(seq, false);
1434 setSequenceAnnotationsVisible(seq, true);
1437 hiddenRepSequences = null;
1439 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1441 firePropertyChange("alignment", null, alignment.getSequences());
1442 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1448 public void showSequence(int index)
1450 int startSeq = ranges.getStartSeq();
1451 int endSeq = ranges.getEndSeq();
1453 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1454 hiddenRepSequences);
1457 if (selectionGroup == null)
1459 selectionGroup = new SequenceGroup();
1460 selectionGroup.setEndRes(alignment.getWidth() - 1);
1463 for (SequenceI seq : tmp)
1465 selectionGroup.addSequence(seq, false);
1466 setSequenceAnnotationsVisible(seq, true);
1469 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1471 firePropertyChange("alignment", null, alignment.getSequences());
1476 public void hideAllSelectedSeqs()
1478 if (selectionGroup == null || selectionGroup.getSize() < 1)
1483 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1487 setSelectionGroup(null);
1490 public void hideSequence(SequenceI[] seq)
1493 * cache offset to first visible sequence
1495 int startSeq = ranges.getStartSeq();
1499 for (int i = 0; i < seq.length; i++)
1501 alignment.getHiddenSequences().hideSequence(seq[i]);
1502 setSequenceAnnotationsVisible(seq[i], false);
1504 ranges.setStartSeq(startSeq);
1505 firePropertyChange("alignment", null, alignment.getSequences());
1510 * Hides the specified sequence, or the sequences it represents
1513 * the sequence to hide, or keep as representative
1514 * @param representGroup
1515 * if true, hide the current selection group except for the
1516 * representative sequence
1518 public void hideSequences(SequenceI sequence, boolean representGroup)
1520 if (selectionGroup == null || selectionGroup.getSize() < 1)
1522 hideSequence(new SequenceI[] { sequence });
1528 hideRepSequences(sequence, selectionGroup);
1529 setSelectionGroup(null);
1533 int gsize = selectionGroup.getSize();
1534 SequenceI[] hseqs = selectionGroup.getSequences()
1535 .toArray(new SequenceI[gsize]);
1537 hideSequence(hseqs);
1538 setSelectionGroup(null);
1543 * Set visibility for any annotations for the given sequence.
1547 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1550 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1553 for (AlignmentAnnotation ann : anns)
1555 if (ann.sequenceRef == sequenceI)
1557 ann.visible = visible;
1563 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1565 int sSize = sg.getSize();
1571 if (hiddenRepSequences == null)
1573 hiddenRepSequences = new Hashtable<>();
1576 hiddenRepSequences.put(repSequence, sg);
1578 // Hide all sequences except the repSequence
1579 SequenceI[] seqs = new SequenceI[sSize - 1];
1581 for (int i = 0; i < sSize; i++)
1583 if (sg.getSequenceAt(i) != repSequence)
1585 if (index == sSize - 1)
1590 seqs[index++] = sg.getSequenceAt(i);
1593 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1594 sg.setHidereps(true); // note: not done in 2.7applet
1601 * @return null or the current reference sequence
1603 public SequenceI getReferenceSeq()
1605 return alignment.getSeqrep();
1610 * @return true iff seq is the reference for the alignment
1612 public boolean isReferenceSeq(SequenceI seq)
1614 return alignment.getSeqrep() == seq;
1620 * @return true if there are sequences represented by this sequence that are
1623 public boolean isHiddenRepSequence(SequenceI seq)
1625 return (hiddenRepSequences != null
1626 && hiddenRepSequences.containsKey(seq));
1632 * @return null or a sequence group containing the sequences that seq
1635 public SequenceGroup getRepresentedSequences(SequenceI seq)
1637 return (SequenceGroup) (hiddenRepSequences == null ? null
1638 : hiddenRepSequences.get(seq));
1642 public int adjustForHiddenSeqs(int alignmentIndex)
1644 return alignment.getHiddenSequences()
1645 .adjustForHiddenSeqs(alignmentIndex);
1649 public void invertColumnSelection()
1651 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1652 isColSelChanged(true);
1656 public SequenceI[] getSelectionAsNewSequence()
1658 SequenceI[] sequences;
1659 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1660 // this was the only caller in the applet for this method
1661 // JBPNote: in applet, this method returned references to the alignment
1662 // sequences, and it did not honour the presence/absence of annotation
1663 // attached to the alignment (probably!)
1664 if (selectionGroup == null || selectionGroup.getSize() == 0)
1666 sequences = alignment.getSequencesArray();
1667 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1668 for (int i = 0; i < sequences.length; i++)
1670 // construct new sequence with subset of visible annotation
1671 sequences[i] = new Sequence(sequences[i], annots);
1676 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1683 public SequenceI[] getSequenceSelection()
1685 SequenceI[] sequences = null;
1686 if (selectionGroup != null)
1688 sequences = selectionGroup.getSequencesInOrder(alignment);
1690 if (sequences == null)
1692 sequences = alignment.getSequencesArray();
1698 public jalview.datamodel.AlignmentView getAlignmentView(
1699 boolean selectedOnly)
1701 return getAlignmentView(selectedOnly, false);
1705 public jalview.datamodel.AlignmentView getAlignmentView(
1706 boolean selectedOnly, boolean markGroups)
1708 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1710 alignment.getHiddenColumns() != null
1711 && alignment.getHiddenColumns().hasHiddenColumns(),
1712 selectedOnly, markGroups);
1716 public String[] getViewAsString(boolean selectedRegionOnly)
1718 return getViewAsString(selectedRegionOnly, true);
1722 public String[] getViewAsString(boolean selectedRegionOnly,
1723 boolean exportHiddenSeqs)
1725 String[] selection = null;
1726 SequenceI[] seqs = null;
1728 int start = 0, end = 0;
1729 if (selectedRegionOnly && selectionGroup != null)
1731 iSize = selectionGroup.getSize();
1732 seqs = selectionGroup.getSequencesInOrder(alignment);
1733 start = selectionGroup.getStartRes();
1734 end = selectionGroup.getEndRes() + 1;
1738 if (hasHiddenRows() && exportHiddenSeqs)
1740 AlignmentI fullAlignment = alignment.getHiddenSequences()
1741 .getFullAlignment();
1742 iSize = fullAlignment.getHeight();
1743 seqs = fullAlignment.getSequencesArray();
1744 end = fullAlignment.getWidth();
1748 iSize = alignment.getHeight();
1749 seqs = alignment.getSequencesArray();
1750 end = alignment.getWidth();
1754 selection = new String[iSize];
1755 if (alignment.getHiddenColumns() != null
1756 && alignment.getHiddenColumns().hasHiddenColumns())
1758 for (i = 0; i < iSize; i++)
1760 Iterator<int[]> blocks = alignment.getHiddenColumns()
1761 .getVisContigsIterator(start, end + 1, false);
1762 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1767 for (i = 0; i < iSize; i++)
1769 selection[i] = seqs[i].getSequenceAsString(start, end);
1777 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1779 ArrayList<int[]> regions = new ArrayList<>();
1785 HiddenColumns hidden = alignment.getHiddenColumns();
1786 if (hidden != null && hidden.hasHiddenColumns())
1790 start = hidden.visibleToAbsoluteColumn(start);
1793 end = hidden.getNextHiddenBoundary(false, start);
1804 regions.add(new int[] { start, end });
1806 if (hidden != null && hidden.hasHiddenColumns())
1808 start = hidden.visibleToAbsoluteColumn(end);
1809 start = hidden.getNextHiddenBoundary(true, start) + 1;
1811 } while (end < max);
1813 // int[][] startEnd = new int[regions.size()][2];
1819 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1820 boolean selectedOnly)
1822 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1823 AlignmentAnnotation[] aa;
1824 if ((aa = alignment.getAlignmentAnnotation()) != null)
1826 for (AlignmentAnnotation annot : aa)
1828 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1829 if (selectedOnly && selectionGroup != null)
1831 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1832 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1836 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1845 public boolean isPadGaps()
1851 public void setPadGaps(boolean padGaps)
1853 this.padGaps = padGaps;
1857 * apply any post-edit constraints and trigger any calculations needed after
1858 * an edit has been performed on the alignment
1863 public void alignmentChanged(AlignmentViewPanel ap)
1867 alignment.padGaps();
1869 if (autoCalculateConsensus)
1871 updateConsensus(ap);
1873 if (hconsensus != null && autoCalculateConsensus)
1875 updateConservation(ap);
1877 if (autoCalculateStrucConsensus)
1879 updateStrucConsensus(ap);
1882 // Reset endRes of groups if beyond alignment width
1883 int alWidth = alignment.getWidth();
1884 List<SequenceGroup> groups = alignment.getGroups();
1887 for (SequenceGroup sg : groups)
1889 if (sg.getEndRes() > alWidth)
1891 sg.setEndRes(alWidth - 1);
1896 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1898 selectionGroup.setEndRes(alWidth - 1);
1901 updateAllColourSchemes();
1902 calculator.restartWorkers();
1903 // alignment.adjustSequenceAnnotations();
1907 * reset scope and do calculations for all applied colourschemes on alignment
1909 void updateAllColourSchemes()
1911 ResidueShaderI rs = residueShading;
1914 rs.alignmentChanged(alignment, hiddenRepSequences);
1916 rs.setConsensus(hconsensus);
1917 if (rs.conservationApplied())
1919 rs.setConservation(Conservation.calculateConservation("All",
1920 alignment.getSequences(), 0, alignment.getWidth(), false,
1921 getConsPercGaps(), false));
1925 for (SequenceGroup sg : alignment.getGroups())
1929 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1931 sg.recalcConservation();
1935 protected void initAutoAnnotation()
1937 // TODO: add menu option action that nulls or creates consensus object
1938 // depending on if the user wants to see the annotation or not in a
1939 // specific alignment
1941 if (hconsensus == null && !isDataset)
1943 if (!alignment.isNucleotide())
1952 consensus = new AlignmentAnnotation("Consensus",
1953 MessageManager.getString("label.consensus_descr"),
1954 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1955 initConsensus(consensus);
1958 initComplementConsensus();
1963 * If this is a protein alignment and there are mappings to cDNA, adds the
1964 * cDNA consensus annotation and returns true, else returns false.
1966 public boolean initComplementConsensus()
1968 if (!alignment.isNucleotide())
1970 final List<AlignedCodonFrame> codonMappings = alignment
1972 if (codonMappings != null && !codonMappings.isEmpty())
1974 boolean doConsensus = false;
1975 for (AlignedCodonFrame mapping : codonMappings)
1977 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1978 MapList[] mapLists = mapping.getdnaToProt();
1979 // mapLists can be empty if project load has not finished resolving
1981 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1989 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1991 .getString("label.complement_consensus_descr"),
1992 new Annotation[1], 0f, 100f,
1993 AlignmentAnnotation.BAR_GRAPH);
1994 initConsensus(complementConsensus);
2002 private void initConsensus(AlignmentAnnotation aa)
2005 aa.autoCalculated = true;
2009 alignment.addAnnotation(aa);
2013 // these should be extracted from the view model - style and settings for
2014 // derived annotation
2015 private void initGapCounts()
2019 gapcounts = new AlignmentAnnotation("Occupancy",
2020 MessageManager.getString("label.occupancy_descr"),
2021 new Annotation[1], 0f, alignment.getHeight(),
2022 AlignmentAnnotation.BAR_GRAPH);
2023 gapcounts.hasText = true;
2024 gapcounts.autoCalculated = true;
2025 gapcounts.scaleColLabel = true;
2026 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2028 alignment.addAnnotation(gapcounts);
2032 private void initConservation()
2034 if (showConservation)
2036 if (conservation == null)
2038 conservation = new AlignmentAnnotation("Conservation",
2039 MessageManager.formatMessage("label.conservation_descr",
2041 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2042 conservation.hasText = true;
2043 conservation.autoCalculated = true;
2044 alignment.addAnnotation(conservation);
2049 private void initQuality()
2053 if (quality == null)
2055 quality = new AlignmentAnnotation("Quality",
2056 MessageManager.getString("label.quality_descr"),
2057 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2058 quality.hasText = true;
2059 quality.autoCalculated = true;
2060 alignment.addAnnotation(quality);
2065 private void initRNAStructure()
2067 if (alignment.hasRNAStructure() && strucConsensus == null)
2069 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2070 MessageManager.getString("label.strucconsensus_descr"),
2071 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2072 strucConsensus.hasText = true;
2073 strucConsensus.autoCalculated = true;
2077 alignment.addAnnotation(strucConsensus);
2085 * @see jalview.api.AlignViewportI#calcPanelHeight()
2088 public int calcPanelHeight()
2090 // setHeight of panels
2091 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2093 int charHeight = getCharHeight();
2096 BitSet graphgrp = new BitSet();
2097 for (AlignmentAnnotation aa : anns)
2101 System.err.println("Null annotation row: ignoring.");
2108 if (aa.graphGroup > -1)
2110 if (graphgrp.get(aa.graphGroup))
2116 graphgrp.set(aa.graphGroup);
2123 aa.height += charHeight;
2133 aa.height += aa.graphHeight;
2141 height += aa.height;
2153 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2154 boolean preserveNewGroupSettings)
2156 boolean updateCalcs = false;
2157 boolean conv = isShowGroupConservation();
2158 boolean cons = isShowGroupConsensus();
2159 boolean showprf = isShowSequenceLogo();
2160 boolean showConsHist = isShowConsensusHistogram();
2161 boolean normLogo = isNormaliseSequenceLogo();
2164 * TODO reorder the annotation rows according to group/sequence ordering on
2167 // boolean sortg = true;
2169 // remove old automatic annotation
2170 // add any new annotation
2172 // intersect alignment annotation with alignment groups
2174 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2175 List<SequenceGroup> oldrfs = new ArrayList<>();
2178 for (int an = 0; an < aan.length; an++)
2180 if (aan[an].autoCalculated && aan[an].groupRef != null)
2182 oldrfs.add(aan[an].groupRef);
2183 alignment.deleteAnnotation(aan[an], false);
2187 if (alignment.getGroups() != null)
2189 for (SequenceGroup sg : alignment.getGroups())
2191 updateCalcs = false;
2192 if (applyGlobalSettings
2193 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2195 // set defaults for this group's conservation/consensus
2196 sg.setshowSequenceLogo(showprf);
2197 sg.setShowConsensusHistogram(showConsHist);
2198 sg.setNormaliseSequenceLogo(normLogo);
2203 alignment.addAnnotation(sg.getConservationRow(), 0);
2208 alignment.addAnnotation(sg.getConsensus(), 0);
2210 // refresh the annotation rows
2213 sg.recalcConservation();
2221 public boolean isDisplayReferenceSeq()
2223 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2227 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2229 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2233 public boolean isColourByReferenceSeq()
2235 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2239 public Color getSequenceColour(SequenceI seq)
2241 Color sqc = sequenceColours.get(seq);
2242 return (sqc == null ? Color.white : sqc);
2246 public void setSequenceColour(SequenceI seq, Color col)
2250 sequenceColours.remove(seq);
2254 sequenceColours.put(seq, col);
2259 public void updateSequenceIdColours()
2261 for (SequenceGroup sg : alignment.getGroups())
2263 if (sg.idColour != null)
2265 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2267 sequenceColours.put(s, sg.idColour);
2274 public void clearSequenceColours()
2276 sequenceColours.clear();
2280 public AlignViewportI getCodingComplement()
2282 return this.codingComplement;
2286 * Set this as the (cDna/protein) complement of the given viewport. Also
2287 * ensures the reverse relationship is set on the given viewport.
2290 public void setCodingComplement(AlignViewportI av)
2294 System.err.println("Ignoring recursive setCodingComplement request");
2298 this.codingComplement = av;
2299 // avoid infinite recursion!
2300 if (av.getCodingComplement() != this)
2302 av.setCodingComplement(this);
2308 public boolean isNucleotide()
2310 return getAlignment() == null ? false : getAlignment().isNucleotide();
2314 public FeaturesDisplayedI getFeaturesDisplayed()
2316 return featuresDisplayed;
2320 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2322 featuresDisplayed = featuresDisplayedI;
2326 public boolean areFeaturesDisplayed()
2328 return featuresDisplayed != null
2329 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2336 * features are displayed if true
2339 public void setShowSequenceFeatures(boolean b)
2341 viewStyle.setShowSequenceFeatures(b);
2345 public boolean isShowSequenceFeatures()
2347 return viewStyle.isShowSequenceFeatures();
2351 public void setShowSequenceFeaturesHeight(boolean selected)
2353 viewStyle.setShowSequenceFeaturesHeight(selected);
2357 public boolean isShowSequenceFeaturesHeight()
2359 return viewStyle.isShowSequenceFeaturesHeight();
2363 public void setShowAnnotation(boolean b)
2365 viewStyle.setShowAnnotation(b);
2369 public boolean isShowAnnotation()
2371 return viewStyle.isShowAnnotation();
2375 public boolean isRightAlignIds()
2377 return viewStyle.isRightAlignIds();
2381 public void setRightAlignIds(boolean rightAlignIds)
2383 viewStyle.setRightAlignIds(rightAlignIds);
2387 public boolean getConservationSelected()
2389 return viewStyle.getConservationSelected();
2393 public void setShowBoxes(boolean state)
2395 viewStyle.setShowBoxes(state);
2400 * @see jalview.api.ViewStyleI#getTextColour()
2403 public Color getTextColour()
2405 return viewStyle.getTextColour();
2410 * @see jalview.api.ViewStyleI#getTextColour2()
2413 public Color getTextColour2()
2415 return viewStyle.getTextColour2();
2420 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2423 public int getThresholdTextColour()
2425 return viewStyle.getThresholdTextColour();
2430 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2433 public boolean isConservationColourSelected()
2435 return viewStyle.isConservationColourSelected();
2440 * @see jalview.api.ViewStyleI#isRenderGaps()
2443 public boolean isRenderGaps()
2445 return viewStyle.isRenderGaps();
2450 * @see jalview.api.ViewStyleI#isShowColourText()
2453 public boolean isShowColourText()
2455 return viewStyle.isShowColourText();
2459 * @param conservationColourSelected
2460 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2463 public void setConservationColourSelected(
2464 boolean conservationColourSelected)
2466 viewStyle.setConservationColourSelected(conservationColourSelected);
2470 * @param showColourText
2471 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2474 public void setShowColourText(boolean showColourText)
2476 viewStyle.setShowColourText(showColourText);
2481 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2484 public void setTextColour(Color textColour)
2486 viewStyle.setTextColour(textColour);
2490 * @param thresholdTextColour
2491 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2494 public void setThresholdTextColour(int thresholdTextColour)
2496 viewStyle.setThresholdTextColour(thresholdTextColour);
2500 * @param textColour2
2501 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2504 public void setTextColour2(Color textColour2)
2506 viewStyle.setTextColour2(textColour2);
2510 public ViewStyleI getViewStyle()
2512 return new ViewStyle(viewStyle);
2516 public void setViewStyle(ViewStyleI settingsForView)
2518 viewStyle = new ViewStyle(settingsForView);
2519 if (residueShading != null)
2521 residueShading.setConservationApplied(
2522 settingsForView.isConservationColourSelected());
2527 public boolean sameStyle(ViewStyleI them)
2529 return viewStyle.sameStyle(them);
2534 * @see jalview.api.ViewStyleI#getIdWidth()
2537 public int getIdWidth()
2539 return viewStyle.getIdWidth();
2544 * @see jalview.api.ViewStyleI#setIdWidth(int)
2547 public void setIdWidth(int i)
2549 viewStyle.setIdWidth(i);
2554 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2557 public boolean isCentreColumnLabels()
2559 return viewStyle.isCentreColumnLabels();
2563 * @param centreColumnLabels
2564 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2567 public void setCentreColumnLabels(boolean centreColumnLabels)
2569 viewStyle.setCentreColumnLabels(centreColumnLabels);
2574 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2577 public void setShowDBRefs(boolean showdbrefs)
2579 viewStyle.setShowDBRefs(showdbrefs);
2584 * @see jalview.api.ViewStyleI#isShowDBRefs()
2587 public boolean isShowDBRefs()
2589 return viewStyle.isShowDBRefs();
2594 * @see jalview.api.ViewStyleI#isShowNPFeats()
2597 public boolean isShowNPFeats()
2599 return viewStyle.isShowNPFeats();
2603 * @param shownpfeats
2604 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2607 public void setShowNPFeats(boolean shownpfeats)
2609 viewStyle.setShowNPFeats(shownpfeats);
2612 public abstract StructureSelectionManager getStructureSelectionManager();
2615 * Add one command to the command history list.
2619 public void addToHistoryList(CommandI command)
2621 if (this.historyList != null)
2623 this.historyList.push(command);
2624 broadcastCommand(command, false);
2625 setSavedUpToDate(false);
2626 Jalview2XML.setStateSavedUpToDate(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 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
2947 return alignment.getContactListFor(_aa, column);
2951 * get the consensus sequence as displayed under the PID consensus annotation
2954 * @return consensus sequence as a new sequence object
2956 public SequenceI getConsensusSeq()
2958 if (consensus == null)
2960 updateConsensus(null);
2962 if (consensus == null)
2966 StringBuffer seqs = new StringBuffer();
2967 for (int i = 0; i < consensus.annotations.length; i++)
2969 Annotation annotation = consensus.annotations[i];
2970 if (annotation != null)
2972 String description = annotation.description;
2973 if (description != null && description.startsWith("["))
2975 // consensus is a tie - just pick the first one
2976 seqs.append(description.charAt(1));
2980 seqs.append(annotation.displayCharacter);
2985 SequenceI sq = new Sequence("Consensus", seqs.toString());
2986 sq.setDescription("Percentage Identity Consensus "
2987 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2992 public void setCurrentTree(TreeModel tree)
2998 public TreeModel getCurrentTree()
3004 public AlignmentExportData getAlignExportData(
3005 AlignExportSettingsI options)
3007 AlignmentI alignmentToExport = null;
3008 String[] omitHidden = null;
3009 alignmentToExport = null;
3011 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3013 omitHidden = getViewAsString(false,
3014 options.isExportHiddenSequences());
3017 int[] alignmentStartEnd = new int[2];
3018 if (hasHiddenRows() && options.isExportHiddenSequences())
3020 alignmentToExport = getAlignment().getHiddenSequences()
3021 .getFullAlignment();
3025 alignmentToExport = getAlignment();
3027 alignmentStartEnd = getAlignment().getHiddenColumns()
3028 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3029 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3030 omitHidden, alignmentStartEnd);
3035 * flag set to indicate if structure views might be out of sync with sequences
3039 private boolean needToUpdateStructureViews = false;
3042 public boolean isUpdateStructures()
3044 return needToUpdateStructureViews;
3048 public void setUpdateStructures(boolean update)
3050 needToUpdateStructureViews = update;
3054 public boolean needToUpdateStructureViews()
3056 boolean update = needToUpdateStructureViews;
3057 needToUpdateStructureViews = false;
3062 public void addSequenceGroup(SequenceGroup sequenceGroup)
3064 alignment.addGroup(sequenceGroup);
3066 Color col = sequenceGroup.idColour;
3069 col = col.brighter();
3071 for (SequenceI sq : sequenceGroup.getSequences())
3073 setSequenceColour(sq, col);
3077 if (codingComplement != null)
3079 SequenceGroup mappedGroup = MappingUtils
3080 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3081 if (mappedGroup.getSequences().size() > 0)
3083 codingComplement.getAlignment().addGroup(mappedGroup);
3087 for (SequenceI seq : mappedGroup.getSequences())
3089 codingComplement.setSequenceColour(seq, col);
3093 // propagate the structure view update flag according to our own setting
3094 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3099 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3103 if (selectedRegionOnly && selectionGroup != null)
3105 start = selectionGroup.getStartRes();
3106 end = selectionGroup.getEndRes() + 1;
3110 end = alignment.getWidth();
3112 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3116 public void setSavedUpToDate(boolean s)
3119 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3123 public boolean savedUpToDate()
3125 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3127 return savedUpToDate;