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.AlignViewportI;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.api.FeaturesDisplayedI;
30 import jalview.api.ViewStyleI;
31 import jalview.commands.CommandI;
32 import jalview.datamodel.AlignedCodonFrame;
33 import jalview.datamodel.AlignmentAnnotation;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentView;
36 import jalview.datamodel.Annotation;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.renderer.ResidueShader;
47 import jalview.renderer.ResidueShaderI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.util.MessageManager;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.StrucConsensusThread;
62 import java.awt.Color;
63 import java.beans.PropertyChangeSupport;
64 import java.util.ArrayDeque;
65 import java.util.ArrayList;
66 import java.util.BitSet;
67 import java.util.Deque;
68 import java.util.HashMap;
69 import java.util.Hashtable;
70 import java.util.Iterator;
71 import java.util.List;
75 * base class holding visualization and analysis attributes and common logic for
76 * an active alignment view displayed in the GUI
81 public abstract class AlignmentViewport
82 implements AlignViewportI, CommandListener, VamsasSource
85 * An enum for auto-calculated annotations, with constants for the
86 * annotation's label, and the key for the property to show it or not
88 public enum AutoAnnotation
90 CONSERVATION("Conservation", "SHOW_CONSERVATION"),
91 QUALITY("Quality", "SHOW_QUALITY"),
92 CONSENSUS("Consensus", "SHOW_IDENTITY"),
93 CDNA_CONSENSUS("cDNA Consensus", null),
94 STRUCTURE_CONSENSUS("StrucConsensus", null),
95 OCCUPANCY("Occupancy", "SHOW_OCCUPANCY");
97 public final String label;
98 public final String preferenceKey;
100 private AutoAnnotation(String lbl, String prefKey)
103 this.preferenceKey = prefKey;
107 protected ViewportRanges ranges;
109 protected ViewStyleI viewStyle = new ViewStyle();
112 * A viewport that hosts the cDna view of this (protein), or vice versa (if
115 AlignViewportI codingComplement = null;
117 FeaturesDisplayedI featuresDisplayed = null;
119 protected Deque<CommandI> historyList = new ArrayDeque<>();
121 protected Deque<CommandI> redoList = new ArrayDeque<>();
124 * alignment displayed in the viewport. Please use get/setter
126 protected AlignmentI alignment;
128 public AlignmentViewport(AlignmentI al)
131 ranges = new ViewportRanges(al);
136 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
139 public void setFontName(String name)
141 viewStyle.setFontName(name);
146 * @see jalview.api.ViewStyleI#setFontStyle(int)
149 public void setFontStyle(int style)
151 viewStyle.setFontStyle(style);
156 * @see jalview.api.ViewStyleI#setFontSize(int)
159 public void setFontSize(int size)
161 viewStyle.setFontSize(size);
166 * @see jalview.api.ViewStyleI#getFontStyle()
169 public int getFontStyle()
171 return viewStyle.getFontStyle();
176 * @see jalview.api.ViewStyleI#getFontName()
179 public String getFontName()
181 return viewStyle.getFontName();
186 * @see jalview.api.ViewStyleI#getFontSize()
189 public int getFontSize()
191 return viewStyle.getFontSize();
195 * @param upperCasebold
196 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
199 public void setUpperCasebold(boolean upperCasebold)
201 viewStyle.setUpperCasebold(upperCasebold);
206 * @see jalview.api.ViewStyleI#isUpperCasebold()
209 public boolean isUpperCasebold()
211 return viewStyle.isUpperCasebold();
216 * @see jalview.api.ViewStyleI#isSeqNameItalics()
219 public boolean isSeqNameItalics()
221 return viewStyle.isSeqNameItalics();
225 * @param colourByReferenceSeq
226 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
229 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
231 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
236 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
239 public void setColourAppliesToAllGroups(boolean b)
241 viewStyle.setColourAppliesToAllGroups(b);
246 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
249 public boolean getColourAppliesToAllGroups()
251 return viewStyle.getColourAppliesToAllGroups();
256 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
259 public boolean getAbovePIDThreshold()
261 return viewStyle.getAbovePIDThreshold();
266 * @see jalview.api.ViewStyleI#setIncrement(int)
269 public void setIncrement(int inc)
271 viewStyle.setIncrement(inc);
276 * @see jalview.api.ViewStyleI#getIncrement()
279 public int getIncrement()
281 return viewStyle.getIncrement();
286 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
289 public void setConservationSelected(boolean b)
291 viewStyle.setConservationSelected(b);
296 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
299 public void setShowHiddenMarkers(boolean show)
301 viewStyle.setShowHiddenMarkers(show);
306 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
309 public boolean getShowHiddenMarkers()
311 return viewStyle.getShowHiddenMarkers();
316 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
319 public void setScaleRightWrapped(boolean b)
321 viewStyle.setScaleRightWrapped(b);
326 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
329 public void setScaleLeftWrapped(boolean b)
331 viewStyle.setScaleLeftWrapped(b);
336 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
339 public void setScaleAboveWrapped(boolean b)
341 viewStyle.setScaleAboveWrapped(b);
346 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
349 public boolean getScaleLeftWrapped()
351 return viewStyle.getScaleLeftWrapped();
356 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
359 public boolean getScaleAboveWrapped()
361 return viewStyle.getScaleAboveWrapped();
366 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
369 public boolean getScaleRightWrapped()
371 return viewStyle.getScaleRightWrapped();
376 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
379 public void setAbovePIDThreshold(boolean b)
381 viewStyle.setAbovePIDThreshold(b);
386 * @see jalview.api.ViewStyleI#setThreshold(int)
389 public void setThreshold(int thresh)
391 viewStyle.setThreshold(thresh);
396 * @see jalview.api.ViewStyleI#getThreshold()
399 public int getThreshold()
401 return viewStyle.getThreshold();
406 * @see jalview.api.ViewStyleI#getShowJVSuffix()
409 public boolean getShowJVSuffix()
411 return viewStyle.getShowJVSuffix();
416 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
419 public void setShowJVSuffix(boolean b)
421 viewStyle.setShowJVSuffix(b);
426 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
429 public void setWrapAlignment(boolean state)
431 viewStyle.setWrapAlignment(state);
432 ranges.setWrappedMode(state);
437 * @see jalview.api.ViewStyleI#setShowText(boolean)
440 public void setShowText(boolean state)
442 viewStyle.setShowText(state);
447 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
450 public void setRenderGaps(boolean state)
452 viewStyle.setRenderGaps(state);
457 * @see jalview.api.ViewStyleI#getColourText()
460 public boolean getColourText()
462 return viewStyle.getColourText();
467 * @see jalview.api.ViewStyleI#setColourText(boolean)
470 public void setColourText(boolean state)
472 viewStyle.setColourText(state);
477 * @see jalview.api.ViewStyleI#getWrapAlignment()
480 public boolean getWrapAlignment()
482 return viewStyle.getWrapAlignment();
487 * @see jalview.api.ViewStyleI#getShowText()
490 public boolean getShowText()
492 return viewStyle.getShowText();
497 * @see jalview.api.ViewStyleI#getWrappedWidth()
500 public int getWrappedWidth()
502 return viewStyle.getWrappedWidth();
507 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
510 public void setWrappedWidth(int w)
512 viewStyle.setWrappedWidth(w);
517 * @see jalview.api.ViewStyleI#getCharHeight()
520 public int getCharHeight()
522 return viewStyle.getCharHeight();
527 * @see jalview.api.ViewStyleI#setCharHeight(int)
530 public void setCharHeight(int h)
532 viewStyle.setCharHeight(h);
537 * @see jalview.api.ViewStyleI#getCharWidth()
540 public int getCharWidth()
542 return viewStyle.getCharWidth();
547 * @see jalview.api.ViewStyleI#setCharWidth(int)
550 public void setCharWidth(int w)
552 viewStyle.setCharWidth(w);
557 * @see jalview.api.ViewStyleI#getShowBoxes()
560 public boolean getShowBoxes()
562 return viewStyle.getShowBoxes();
567 * @see jalview.api.ViewStyleI#getShowUnconserved()
570 public boolean getShowUnconserved()
572 return viewStyle.getShowUnconserved();
576 * @param showunconserved
577 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
580 public void setShowUnconserved(boolean showunconserved)
582 viewStyle.setShowUnconserved(showunconserved);
587 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
590 public void setSeqNameItalics(boolean default1)
592 viewStyle.setSeqNameItalics(default1);
596 public AlignmentI getAlignment()
602 public char getGapCharacter()
604 return alignment.getGapCharacter();
607 protected String sequenceSetID;
610 * probably unused indicator that view is of a dataset rather than an
613 protected boolean isDataset = false;
615 public void setDataset(boolean b)
620 public boolean isDataset()
625 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
627 protected ColumnSelection colSel = new ColumnSelection();
629 public boolean autoCalculateConsensus = true;
631 protected boolean autoCalculateStrucConsensus = true;
633 protected boolean ignoreGapsInConsensusCalculation = false;
635 protected ResidueShaderI residueShading = new ResidueShader();
638 public void setGlobalColourScheme(ColourSchemeI cs)
640 // TODO: logic refactored from AlignFrame changeColour -
641 // TODO: autorecalc stuff should be changed to rely on the worker system
642 // check to see if we should implement a changeColour(cs) method rather than
643 // put the logic in here
644 // - means that caller decides if they want to just modify state and defer
645 // calculation till later or to do all calculations in thread.
649 * only instantiate alignment colouring once, thereafter update it;
650 * this means that any conservation or PID threshold settings
651 * persist when the alignment colour scheme is changed
653 if (residueShading == null)
655 residueShading = new ResidueShader(viewStyle);
657 residueShading.setColourScheme(cs);
659 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
660 // ...problem: groups need these, but do not currently have a ViewStyle
664 if (getConservationSelected())
666 residueShading.setConservation(hconservation);
669 * reset conservation flag in case just set to false if
670 * Conservation was null (calculation still in progress)
672 residueShading.setConservationApplied(getConservationSelected());
673 residueShading.alignmentChanged(alignment, hiddenRepSequences);
677 * if 'apply colour to all groups' is selected... do so
678 * (but don't transfer any colour threshold settings to groups)
680 if (getColourAppliesToAllGroups())
682 for (SequenceGroup sg : getAlignment().getGroups())
685 * retain any colour thresholds per group while
686 * changing choice of colour scheme (JAL-2386)
689 cs == null ? null : cs.getInstance(this, sg));
692 sg.getGroupColourScheme().alignmentChanged(sg,
700 public ColourSchemeI getGlobalColourScheme()
702 return residueShading == null ? null : residueShading.getColourScheme();
706 public ResidueShaderI getResidueShading()
708 return residueShading;
711 protected AlignmentAnnotation consensus;
713 protected AlignmentAnnotation complementConsensus;
715 protected AlignmentAnnotation gapcounts;
717 protected AlignmentAnnotation strucConsensus;
719 protected AlignmentAnnotation conservation;
721 protected AlignmentAnnotation quality;
723 protected AlignmentAnnotation[] groupConsensus;
725 protected AlignmentAnnotation[] groupConservation;
728 * results of alignment consensus analysis for visible portion of view
730 protected ProfilesI hconsensus = null;
733 * results of cDNA complement consensus visible portion of view
735 protected Hashtable[] hcomplementConsensus = null;
738 * results of secondary structure base pair consensus for visible portion of
741 protected Hashtable[] hStrucConsensus = null;
743 protected Conservation hconservation = null;
746 public void setConservation(Conservation cons)
748 hconservation = cons;
752 * percentage gaps allowed in a column before all amino acid properties should
753 * be considered unconserved
755 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
758 public int getConsPercGaps()
764 public void setSequenceConsensusHash(ProfilesI hconsensus)
766 this.hconsensus = hconsensus;
770 public void setComplementConsensusHash(Hashtable[] hconsensus)
772 this.hcomplementConsensus = hconsensus;
776 public ProfilesI getSequenceConsensusHash()
782 public Hashtable[] getComplementConsensusHash()
784 return hcomplementConsensus;
788 public Hashtable[] getRnaStructureConsensusHash()
790 return hStrucConsensus;
794 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
796 this.hStrucConsensus = hStrucConsensus;
801 public AlignmentAnnotation getAlignmentQualityAnnot()
807 public AlignmentAnnotation getAlignmentConservationAnnotation()
813 public AlignmentAnnotation getAlignmentConsensusAnnotation()
819 public AlignmentAnnotation getAlignmentGapAnnotation()
825 public AlignmentAnnotation getComplementConsensusAnnotation()
827 return complementConsensus;
831 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
833 return strucConsensus;
836 protected AlignCalcManagerI calculator = new AlignCalcManager();
839 * trigger update of conservation annotation
841 public void updateConservation(final AlignmentViewPanel ap)
843 // see note in mantis : issue number 8585
844 if (alignment.isNucleotide()
845 || (conservation == null && quality == null)
846 || !autoCalculateConsensus)
850 if (calculator.getRegisteredWorkersOfClass(
851 jalview.workers.ConservationThread.class) == null)
853 calculator.registerWorker(
854 new jalview.workers.ConservationThread(this, ap));
859 * trigger update of consensus annotation
861 public void updateConsensus(final AlignmentViewPanel ap)
863 // see note in mantis : issue number 8585
864 if (consensus == null || !autoCalculateConsensus)
869 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
871 calculator.registerWorker(new ConsensusThread(this, ap));
875 * A separate thread to compute cDNA consensus for a protein alignment
876 * which has mapping to cDNA
878 final AlignmentI al = this.getAlignment();
879 if (!al.isNucleotide() && al.getCodonFrames() != null
880 && !al.getCodonFrames().isEmpty())
883 * fudge - check first for protein-to-nucleotide mappings
884 * (we don't want to do this for protein-to-protein)
886 boolean doConsensus = false;
887 for (AlignedCodonFrame mapping : al.getCodonFrames())
889 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
890 MapList[] mapLists = mapping.getdnaToProt();
891 // mapLists can be empty if project load has not finished resolving seqs
892 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
900 if (calculator.getRegisteredWorkersOfClass(
901 ComplementConsensusThread.class) == null)
904 .registerWorker(new ComplementConsensusThread(this, ap));
910 // --------START Structure Conservation
911 public void updateStrucConsensus(final AlignmentViewPanel ap)
913 if (autoCalculateStrucConsensus && strucConsensus == null
914 && alignment.isNucleotide() && alignment.hasRNAStructure())
916 // secondary structure has been added - so init the consensus line
920 // see note in mantis : issue number 8585
921 if (strucConsensus == null || !autoCalculateStrucConsensus)
925 if (calculator.getRegisteredWorkersOfClass(
926 StrucConsensusThread.class) == null)
928 calculator.registerWorker(new StrucConsensusThread(this, ap));
932 public boolean isCalcInProgress()
934 return calculator.isWorking();
938 public boolean isCalculationInProgress(
939 AlignmentAnnotation alignmentAnnotation)
941 if (!alignmentAnnotation.autoCalculated)
945 if (calculator.workingInvolvedWith(alignmentAnnotation))
947 // System.err.println("grey out ("+alignmentAnnotation.label+")");
953 public void setAlignment(AlignmentI align)
955 this.alignment = align;
959 * Clean up references when this viewport is closed
962 public void dispose()
965 * defensively null out references to large objects in case
966 * this object is not garbage collected (as if!)
969 complementConsensus = null;
970 strucConsensus = null;
973 groupConsensus = null;
974 groupConservation = null;
976 hconservation = null;
977 hcomplementConsensus = null;
980 residueShading = null; // may hold a reference to Consensus
981 changeSupport = null;
984 selectionGroup = null;
989 public boolean isClosed()
991 // TODO: check that this isClosed is only true after panel is closed, not
992 // before it is fully constructed.
993 return alignment == null;
997 public AlignCalcManagerI getCalcManager()
1003 * should conservation rows be shown for groups
1005 protected boolean showGroupConservation = false;
1008 * should consensus rows be shown for groups
1010 protected boolean showGroupConsensus = false;
1013 * should consensus profile be rendered by default
1015 protected boolean showSequenceLogo = false;
1018 * should consensus profile be rendered normalised to row height
1020 protected boolean normaliseSequenceLogo = false;
1023 * should consensus histograms be rendered by default
1025 protected boolean showConsensusHistogram = true;
1028 * @return the showConsensusProfile
1031 public boolean isShowSequenceLogo()
1033 return showSequenceLogo;
1037 * @param showSequenceLogo
1040 public void setShowSequenceLogo(boolean showSequenceLogo)
1042 if (showSequenceLogo != this.showSequenceLogo)
1044 // TODO: decouple settings setting from calculation when refactoring
1045 // annotation update method from alignframe to viewport
1046 this.showSequenceLogo = showSequenceLogo;
1047 calculator.updateAnnotationFor(ConsensusThread.class);
1048 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1049 calculator.updateAnnotationFor(StrucConsensusThread.class);
1051 this.showSequenceLogo = showSequenceLogo;
1055 * @param showConsensusHistogram
1056 * the showConsensusHistogram to set
1058 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1060 this.showConsensusHistogram = showConsensusHistogram;
1064 * @return the showGroupConservation
1066 public boolean isShowGroupConservation()
1068 return showGroupConservation;
1072 * @param showGroupConservation
1073 * the showGroupConservation to set
1075 public void setShowGroupConservation(boolean showGroupConservation)
1077 this.showGroupConservation = showGroupConservation;
1081 * @return the showGroupConsensus
1083 public boolean isShowGroupConsensus()
1085 return showGroupConsensus;
1089 * @param showGroupConsensus
1090 * the showGroupConsensus to set
1092 public void setShowGroupConsensus(boolean showGroupConsensus)
1094 this.showGroupConsensus = showGroupConsensus;
1099 * @return flag to indicate if the consensus histogram should be rendered by
1103 public boolean isShowConsensusHistogram()
1105 return this.showConsensusHistogram;
1109 * when set, updateAlignment will always ensure sequences are of equal length
1111 private boolean padGaps = false;
1114 * when set, alignment should be reordered according to a newly opened tree
1116 public boolean sortByTree = false;
1121 * @return null or the currently selected sequence region
1124 public SequenceGroup getSelectionGroup()
1126 return selectionGroup;
1130 * Set the selection group for this window. Also sets the current alignment as
1131 * the context for the group, if it does not already have one.
1134 * - group holding references to sequences in this alignment view
1138 public void setSelectionGroup(SequenceGroup sg)
1140 selectionGroup = sg;
1141 if (sg != null && sg.getContext() == null)
1143 sg.setContext(alignment);
1147 public void setHiddenColumns(HiddenColumns hidden)
1149 this.alignment.setHiddenColumns(hidden);
1153 public ColumnSelection getColumnSelection()
1159 public void setColumnSelection(ColumnSelection colSel)
1161 this.colSel = colSel;
1164 updateHiddenColumns();
1166 isColSelChanged(true);
1174 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1176 return hiddenRepSequences;
1180 public void setHiddenRepSequences(
1181 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1183 this.hiddenRepSequences = hiddenRepSequences;
1187 public boolean hasSelectedColumns()
1189 ColumnSelection columnSelection = getColumnSelection();
1190 return columnSelection != null && columnSelection.hasSelectedColumns();
1194 public boolean hasHiddenColumns()
1196 return alignment.getHiddenColumns() != null
1197 && alignment.getHiddenColumns().hasHiddenColumns();
1200 public void updateHiddenColumns()
1202 // this method doesn't really do anything now. But - it could, since a
1203 // column Selection could be in the process of modification
1204 // hasHiddenColumns = colSel.hasHiddenColumns();
1208 public boolean hasHiddenRows()
1210 return alignment.getHiddenSequences().getSize() > 0;
1213 protected SequenceGroup selectionGroup;
1215 public void setSequenceSetId(String newid)
1217 if (sequenceSetID != null)
1220 "Warning - overwriting a sequenceSetId for a viewport!");
1222 sequenceSetID = new String(newid);
1226 public String getSequenceSetId()
1228 if (sequenceSetID == null)
1230 sequenceSetID = alignment.hashCode() + "";
1233 return sequenceSetID;
1237 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1240 protected String viewId = null;
1243 public String getViewId()
1247 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1252 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1254 ignoreGapsInConsensusCalculation = b;
1257 updateConsensus(ap);
1258 if (residueShading != null)
1260 residueShading.setThreshold(residueShading.getThreshold(),
1261 ignoreGapsInConsensusCalculation);
1267 private long sgrouphash = -1, colselhash = -1;
1270 * checks current SelectionGroup against record of last hash value, and
1274 * update the record of last hash value
1276 * @return true if SelectionGroup changed since last call (when b is true)
1278 public boolean isSelectionGroupChanged(boolean b)
1280 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1281 : selectionGroup.hashCode();
1282 if (hc != -1 && hc != sgrouphash)
1294 * checks current colsel against record of last hash value, and optionally
1298 * update the record of last hash value
1299 * @return true if colsel changed since last call (when b is true)
1301 public boolean isColSelChanged(boolean b)
1303 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1304 if (hc != -1 && hc != colselhash)
1316 public boolean isIgnoreGapsConsensus()
1318 return ignoreGapsInConsensusCalculation;
1321 // property change stuff
1322 // JBPNote Prolly only need this in the applet version.
1323 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1326 protected boolean showConservation = true;
1328 protected boolean showQuality = true;
1330 protected boolean showConsensus = true;
1332 protected boolean showOccupancy = true;
1334 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1336 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1338 protected boolean showAutocalculatedAbove;
1341 * when set, view will scroll to show the highlighted position
1343 private boolean followHighlight = true;
1346 * Property change listener for changes in alignment
1351 public void addPropertyChangeListener(
1352 java.beans.PropertyChangeListener listener)
1354 changeSupport.addPropertyChangeListener(listener);
1363 public void removePropertyChangeListener(
1364 java.beans.PropertyChangeListener listener)
1366 if (changeSupport != null)
1368 changeSupport.removePropertyChangeListener(listener);
1373 * Property change listener for changes in alignment
1382 public void firePropertyChange(String prop, Object oldvalue,
1385 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1388 // common hide/show column stuff
1390 public void hideSelectedColumns()
1392 if (colSel.isEmpty())
1397 colSel.hideSelectedColumns(alignment);
1398 setSelectionGroup(null);
1399 isColSelChanged(true);
1402 public void hideColumns(int start, int end)
1406 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1410 alignment.getHiddenColumns().hideColumns(start, end);
1412 isColSelChanged(true);
1415 public void showColumn(int col)
1417 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1418 isColSelChanged(true);
1421 public void showAllHiddenColumns()
1423 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1424 isColSelChanged(true);
1427 // common hide/show seq stuff
1428 public void showAllHiddenSeqs()
1430 int startSeq = ranges.getStartSeq();
1431 int endSeq = ranges.getEndSeq();
1433 if (alignment.getHiddenSequences().getSize() > 0)
1435 if (selectionGroup == null)
1437 selectionGroup = new SequenceGroup();
1438 selectionGroup.setEndRes(alignment.getWidth() - 1);
1440 List<SequenceI> tmp = alignment.getHiddenSequences()
1441 .showAll(hiddenRepSequences);
1442 for (SequenceI seq : tmp)
1444 selectionGroup.addSequence(seq, false);
1445 setSequenceAnnotationsVisible(seq, true);
1448 hiddenRepSequences = null;
1450 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1452 firePropertyChange("alignment", null, alignment.getSequences());
1453 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1459 public void showSequence(int index)
1461 int startSeq = ranges.getStartSeq();
1462 int endSeq = ranges.getEndSeq();
1464 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1465 hiddenRepSequences);
1468 if (selectionGroup == null)
1470 selectionGroup = new SequenceGroup();
1471 selectionGroup.setEndRes(alignment.getWidth() - 1);
1474 for (SequenceI seq : tmp)
1476 selectionGroup.addSequence(seq, false);
1477 setSequenceAnnotationsVisible(seq, true);
1480 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1482 firePropertyChange("alignment", null, alignment.getSequences());
1487 public void hideAllSelectedSeqs()
1489 if (selectionGroup == null || selectionGroup.getSize() < 1)
1494 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1498 setSelectionGroup(null);
1501 public void hideSequence(SequenceI[] seq)
1504 * cache offset to first visible sequence
1506 int startSeq = ranges.getStartSeq();
1510 for (int i = 0; i < seq.length; i++)
1512 alignment.getHiddenSequences().hideSequence(seq[i]);
1513 setSequenceAnnotationsVisible(seq[i], false);
1515 ranges.setStartSeq(startSeq);
1516 firePropertyChange("alignment", null, alignment.getSequences());
1521 * Hides the specified sequence, or the sequences it represents
1524 * the sequence to hide, or keep as representative
1525 * @param representGroup
1526 * if true, hide the current selection group except for the
1527 * representative sequence
1529 public void hideSequences(SequenceI sequence, boolean representGroup)
1531 if (selectionGroup == null || selectionGroup.getSize() < 1)
1533 hideSequence(new SequenceI[] { sequence });
1539 hideRepSequences(sequence, selectionGroup);
1540 setSelectionGroup(null);
1544 int gsize = selectionGroup.getSize();
1545 SequenceI[] hseqs = selectionGroup.getSequences()
1546 .toArray(new SequenceI[gsize]);
1548 hideSequence(hseqs);
1549 setSelectionGroup(null);
1554 * Set visibility for any annotations for the given sequence.
1558 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1561 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1564 for (AlignmentAnnotation ann : anns)
1566 if (ann.sequenceRef == sequenceI)
1568 ann.visible = visible;
1574 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1576 int sSize = sg.getSize();
1582 if (hiddenRepSequences == null)
1584 hiddenRepSequences = new Hashtable<>();
1587 hiddenRepSequences.put(repSequence, sg);
1589 // Hide all sequences except the repSequence
1590 SequenceI[] seqs = new SequenceI[sSize - 1];
1592 for (int i = 0; i < sSize; i++)
1594 if (sg.getSequenceAt(i) != repSequence)
1596 if (index == sSize - 1)
1601 seqs[index++] = sg.getSequenceAt(i);
1604 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1605 sg.setHidereps(true); // note: not done in 2.7applet
1612 * @return null or the current reference sequence
1614 public SequenceI getReferenceSeq()
1616 return alignment.getSeqrep();
1621 * @return true iff seq is the reference for the alignment
1623 public boolean isReferenceSeq(SequenceI seq)
1625 return alignment.getSeqrep() == seq;
1631 * @return true if there are sequences represented by this sequence that are
1634 public boolean isHiddenRepSequence(SequenceI seq)
1636 return (hiddenRepSequences != null
1637 && hiddenRepSequences.containsKey(seq));
1643 * @return null or a sequence group containing the sequences that seq
1646 public SequenceGroup getRepresentedSequences(SequenceI seq)
1648 return (SequenceGroup) (hiddenRepSequences == null ? null
1649 : hiddenRepSequences.get(seq));
1653 public int adjustForHiddenSeqs(int alignmentIndex)
1655 return alignment.getHiddenSequences()
1656 .adjustForHiddenSeqs(alignmentIndex);
1660 public void invertColumnSelection()
1662 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1663 isColSelChanged(true);
1667 public SequenceI[] getSelectionAsNewSequence()
1669 SequenceI[] sequences;
1670 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1671 // this was the only caller in the applet for this method
1672 // JBPNote: in applet, this method returned references to the alignment
1673 // sequences, and it did not honour the presence/absence of annotation
1674 // attached to the alignment (probably!)
1675 if (selectionGroup == null || selectionGroup.getSize() == 0)
1677 sequences = alignment.getSequencesArray();
1678 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1679 for (int i = 0; i < sequences.length; i++)
1681 // construct new sequence with subset of visible annotation
1682 sequences[i] = new Sequence(sequences[i], annots);
1687 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1694 public SequenceI[] getSequenceSelection()
1696 SequenceI[] sequences = null;
1697 if (selectionGroup != null)
1699 sequences = selectionGroup.getSequencesInOrder(alignment);
1701 if (sequences == null)
1703 sequences = alignment.getSequencesArray();
1709 public jalview.datamodel.AlignmentView getAlignmentView(
1710 boolean selectedOnly)
1712 return getAlignmentView(selectedOnly, false);
1716 public jalview.datamodel.AlignmentView getAlignmentView(
1717 boolean selectedOnly, boolean markGroups)
1719 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1721 alignment.getHiddenColumns() != null
1722 && alignment.getHiddenColumns().hasHiddenColumns(),
1723 selectedOnly, markGroups);
1727 public String[] getViewAsString(boolean selectedRegionOnly)
1729 return getViewAsString(selectedRegionOnly, true);
1733 public String[] getViewAsString(boolean selectedRegionOnly,
1734 boolean exportHiddenSeqs)
1736 String[] selection = null;
1737 SequenceI[] seqs = null;
1739 int start = 0, end = 0;
1740 if (selectedRegionOnly && selectionGroup != null)
1742 iSize = selectionGroup.getSize();
1743 seqs = selectionGroup.getSequencesInOrder(alignment);
1744 start = selectionGroup.getStartRes();
1745 end = selectionGroup.getEndRes() + 1;
1749 if (hasHiddenRows() && exportHiddenSeqs)
1751 AlignmentI fullAlignment = alignment.getHiddenSequences()
1752 .getFullAlignment();
1753 iSize = fullAlignment.getHeight();
1754 seqs = fullAlignment.getSequencesArray();
1755 end = fullAlignment.getWidth();
1759 iSize = alignment.getHeight();
1760 seqs = alignment.getSequencesArray();
1761 end = alignment.getWidth();
1765 selection = new String[iSize];
1766 if (alignment.getHiddenColumns() != null
1767 && alignment.getHiddenColumns().hasHiddenColumns())
1769 for (i = 0; i < iSize; i++)
1771 Iterator<int[]> blocks = alignment.getHiddenColumns()
1772 .getVisContigsIterator(start, end + 1, false);
1773 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1778 for (i = 0; i < iSize; i++)
1780 selection[i] = seqs[i].getSequenceAsString(start, end);
1788 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1790 ArrayList<int[]> regions = new ArrayList<>();
1796 HiddenColumns hidden = alignment.getHiddenColumns();
1797 if (hidden != null && hidden.hasHiddenColumns())
1801 start = hidden.visibleToAbsoluteColumn(start);
1804 end = hidden.getNextHiddenBoundary(false, start);
1815 regions.add(new int[] { start, end });
1817 if (hidden != null && hidden.hasHiddenColumns())
1819 start = hidden.visibleToAbsoluteColumn(end);
1820 start = hidden.getNextHiddenBoundary(true, start) + 1;
1822 } while (end < max);
1824 int[][] startEnd = new int[regions.size()][2];
1830 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1831 boolean selectedOnly)
1833 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1834 AlignmentAnnotation[] aa;
1835 if ((aa = alignment.getAlignmentAnnotation()) != null)
1837 for (AlignmentAnnotation annot : aa)
1839 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1840 if (selectedOnly && selectionGroup != null)
1842 clone.makeVisibleAnnotation(
1843 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1844 alignment.getHiddenColumns());
1848 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1857 public boolean isPadGaps()
1863 public void setPadGaps(boolean padGaps)
1865 this.padGaps = padGaps;
1869 * apply any post-edit constraints and trigger any calculations needed after
1870 * an edit has been performed on the alignment
1875 public void alignmentChanged(AlignmentViewPanel ap)
1879 alignment.padGaps();
1881 if (autoCalculateConsensus)
1883 updateConsensus(ap);
1885 if (hconsensus != null && autoCalculateConsensus)
1887 updateConservation(ap);
1889 if (autoCalculateStrucConsensus)
1891 updateStrucConsensus(ap);
1894 // Reset endRes of groups if beyond alignment width
1895 int alWidth = alignment.getWidth();
1896 List<SequenceGroup> groups = alignment.getGroups();
1899 for (SequenceGroup sg : groups)
1901 if (sg.getEndRes() > alWidth)
1903 sg.setEndRes(alWidth - 1);
1908 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1910 selectionGroup.setEndRes(alWidth - 1);
1913 updateAllColourSchemes();
1914 calculator.restartWorkers();
1915 // alignment.adjustSequenceAnnotations();
1919 * reset scope and do calculations for all applied colourschemes on alignment
1921 void updateAllColourSchemes()
1923 ResidueShaderI rs = residueShading;
1926 rs.alignmentChanged(alignment, hiddenRepSequences);
1928 rs.setConsensus(hconsensus);
1929 if (rs.conservationApplied())
1931 rs.setConservation(Conservation.calculateConservation("All",
1932 alignment.getSequences(), 0, alignment.getWidth(), false,
1933 getConsPercGaps(), false));
1937 for (SequenceGroup sg : alignment.getGroups())
1941 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1943 sg.recalcConservation();
1947 protected void initAutoAnnotation()
1949 // TODO: add menu option action that nulls or creates consensus object
1950 // depending on if the user wants to see the annotation or not in a
1951 // specific alignment
1953 if (hconsensus == null && !isDataset)
1955 if (!alignment.isNucleotide())
1964 consensus = new AlignmentAnnotation(AutoAnnotation.CONSENSUS.label,
1965 MessageManager.getString("label.consensus_descr"),
1966 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1967 initConsensus(consensus);
1970 initComplementConsensus();
1975 * If this is a protein alignment and there are mappings to cDNA, adds the
1976 * cDNA consensus annotation and returns true, else returns false.
1978 public boolean initComplementConsensus()
1980 if (!alignment.isNucleotide())
1982 final List<AlignedCodonFrame> codonMappings = alignment
1984 if (codonMappings != null && !codonMappings.isEmpty())
1986 boolean doConsensus = false;
1987 for (AlignedCodonFrame mapping : codonMappings)
1989 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1990 MapList[] mapLists = mapping.getdnaToProt();
1991 // mapLists can be empty if project load has not finished resolving
1993 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2001 complementConsensus = new AlignmentAnnotation(
2002 AutoAnnotation.CDNA_CONSENSUS.label,
2004 .getString("label.complement_consensus_descr"),
2005 new Annotation[1], 0f, 100f,
2006 AlignmentAnnotation.BAR_GRAPH);
2007 initConsensus(complementConsensus);
2015 private void initConsensus(AlignmentAnnotation aa)
2018 aa.autoCalculated = true;
2022 alignment.addAnnotation(aa);
2026 private void initGapCounts()
2030 gapcounts = new AlignmentAnnotation(AutoAnnotation.OCCUPANCY.label,
2031 MessageManager.getString("label.occupancy_descr"),
2032 new Annotation[1], 0f, alignment.getHeight(),
2033 AlignmentAnnotation.BAR_GRAPH);
2034 gapcounts.hasText = true;
2035 gapcounts.autoCalculated = true;
2036 gapcounts.scaleColLabel = true;
2037 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2039 alignment.addAnnotation(gapcounts);
2043 private void initConservation()
2045 if (showConservation)
2047 if (conservation == null)
2049 conservation = new AlignmentAnnotation(
2050 AutoAnnotation.CONSERVATION.label,
2051 MessageManager.formatMessage("label.conservation_descr",
2053 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2054 conservation.hasText = true;
2055 conservation.autoCalculated = true;
2056 alignment.addAnnotation(conservation);
2061 private void initQuality()
2065 if (quality == null)
2067 quality = new AlignmentAnnotation(AutoAnnotation.QUALITY.label,
2068 MessageManager.getString("label.quality_descr"),
2069 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2070 quality.hasText = true;
2071 quality.autoCalculated = true;
2072 alignment.addAnnotation(quality);
2077 private void initRNAStructure()
2079 if (alignment.hasRNAStructure() && strucConsensus == null)
2081 strucConsensus = new AlignmentAnnotation(
2082 AutoAnnotation.STRUCTURE_CONSENSUS.label,
2083 MessageManager.getString("label.strucconsensus_descr"),
2084 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2085 strucConsensus.hasText = true;
2086 strucConsensus.autoCalculated = true;
2090 alignment.addAnnotation(strucConsensus);
2098 * @see jalview.api.AlignViewportI#calcPanelHeight()
2101 public int calcPanelHeight()
2103 // setHeight of panels
2104 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2106 int charHeight = getCharHeight();
2109 BitSet graphgrp = new BitSet();
2110 for (AlignmentAnnotation aa : anns)
2114 System.err.println("Null annotation row: ignoring.");
2121 if (aa.graphGroup > -1)
2123 if (graphgrp.get(aa.graphGroup))
2129 graphgrp.set(aa.graphGroup);
2136 aa.height += charHeight;
2146 aa.height += aa.graphHeight;
2154 height += aa.height;
2166 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2167 boolean preserveNewGroupSettings)
2169 boolean updateCalcs = false;
2170 boolean conv = isShowGroupConservation();
2171 boolean cons = isShowGroupConsensus();
2172 boolean showprf = isShowSequenceLogo();
2173 boolean showConsHist = isShowConsensusHistogram();
2174 boolean normLogo = isNormaliseSequenceLogo();
2177 * TODO reorder the annotation rows according to group/sequence ordering on
2180 boolean sortg = true;
2182 // remove old automatic annotation
2183 // add any new annotation
2185 // intersect alignment annotation with alignment groups
2187 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2188 List<SequenceGroup> oldrfs = new ArrayList<>();
2191 for (int an = 0; an < aan.length; an++)
2193 if (aan[an].autoCalculated && aan[an].groupRef != null)
2195 oldrfs.add(aan[an].groupRef);
2196 alignment.deleteAnnotation(aan[an], false);
2200 if (alignment.getGroups() != null)
2202 for (SequenceGroup sg : alignment.getGroups())
2204 updateCalcs = false;
2205 if (applyGlobalSettings
2206 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2208 // set defaults for this group's conservation/consensus
2209 sg.setshowSequenceLogo(showprf);
2210 sg.setShowConsensusHistogram(showConsHist);
2211 sg.setNormaliseSequenceLogo(normLogo);
2216 alignment.addAnnotation(sg.getConservationRow(), 0);
2221 alignment.addAnnotation(sg.getConsensus(), 0);
2223 // refresh the annotation rows
2226 sg.recalcConservation();
2234 public boolean isDisplayReferenceSeq()
2236 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2240 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2242 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2246 public boolean isColourByReferenceSeq()
2248 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2252 public Color getSequenceColour(SequenceI seq)
2254 Color sqc = sequenceColours.get(seq);
2255 return (sqc == null ? Color.white : sqc);
2259 public void setSequenceColour(SequenceI seq, Color col)
2263 sequenceColours.remove(seq);
2267 sequenceColours.put(seq, col);
2272 public void updateSequenceIdColours()
2274 for (SequenceGroup sg : alignment.getGroups())
2276 if (sg.idColour != null)
2278 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2280 sequenceColours.put(s, sg.idColour);
2287 public void clearSequenceColours()
2289 sequenceColours.clear();
2293 public AlignViewportI getCodingComplement()
2295 return this.codingComplement;
2299 * Set this as the (cDna/protein) complement of the given viewport. Also
2300 * ensures the reverse relationship is set on the given viewport.
2303 public void setCodingComplement(AlignViewportI av)
2307 System.err.println("Ignoring recursive setCodingComplement request");
2311 this.codingComplement = av;
2312 // avoid infinite recursion!
2313 if (av.getCodingComplement() != this)
2315 av.setCodingComplement(this);
2321 public boolean isNucleotide()
2323 return getAlignment() == null ? false : getAlignment().isNucleotide();
2327 public FeaturesDisplayedI getFeaturesDisplayed()
2329 return featuresDisplayed;
2333 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2335 featuresDisplayed = featuresDisplayedI;
2339 public boolean areFeaturesDisplayed()
2341 return featuresDisplayed != null
2342 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2349 * features are displayed if true
2352 public void setShowSequenceFeatures(boolean b)
2354 viewStyle.setShowSequenceFeatures(b);
2358 public boolean isShowSequenceFeatures()
2360 return viewStyle.isShowSequenceFeatures();
2364 public void setShowSequenceFeaturesHeight(boolean selected)
2366 viewStyle.setShowSequenceFeaturesHeight(selected);
2370 public boolean isShowSequenceFeaturesHeight()
2372 return viewStyle.isShowSequenceFeaturesHeight();
2376 public void setShowAnnotation(boolean b)
2378 viewStyle.setShowAnnotation(b);
2382 public boolean isShowAnnotation()
2384 return viewStyle.isShowAnnotation();
2388 public boolean isRightAlignIds()
2390 return viewStyle.isRightAlignIds();
2394 public void setRightAlignIds(boolean rightAlignIds)
2396 viewStyle.setRightAlignIds(rightAlignIds);
2400 public boolean getConservationSelected()
2402 return viewStyle.getConservationSelected();
2406 public void setShowBoxes(boolean state)
2408 viewStyle.setShowBoxes(state);
2413 * @see jalview.api.ViewStyleI#getTextColour()
2416 public Color getTextColour()
2418 return viewStyle.getTextColour();
2423 * @see jalview.api.ViewStyleI#getTextColour2()
2426 public Color getTextColour2()
2428 return viewStyle.getTextColour2();
2433 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2436 public int getThresholdTextColour()
2438 return viewStyle.getThresholdTextColour();
2443 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2446 public boolean isConservationColourSelected()
2448 return viewStyle.isConservationColourSelected();
2453 * @see jalview.api.ViewStyleI#isRenderGaps()
2456 public boolean isRenderGaps()
2458 return viewStyle.isRenderGaps();
2463 * @see jalview.api.ViewStyleI#isShowColourText()
2466 public boolean isShowColourText()
2468 return viewStyle.isShowColourText();
2472 * @param conservationColourSelected
2473 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2476 public void setConservationColourSelected(
2477 boolean conservationColourSelected)
2479 viewStyle.setConservationColourSelected(conservationColourSelected);
2483 * @param showColourText
2484 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2487 public void setShowColourText(boolean showColourText)
2489 viewStyle.setShowColourText(showColourText);
2494 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2497 public void setTextColour(Color textColour)
2499 viewStyle.setTextColour(textColour);
2503 * @param thresholdTextColour
2504 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2507 public void setThresholdTextColour(int thresholdTextColour)
2509 viewStyle.setThresholdTextColour(thresholdTextColour);
2513 * @param textColour2
2514 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2517 public void setTextColour2(Color textColour2)
2519 viewStyle.setTextColour2(textColour2);
2523 public ViewStyleI getViewStyle()
2525 return new ViewStyle(viewStyle);
2529 public void setViewStyle(ViewStyleI settingsForView)
2531 viewStyle = new ViewStyle(settingsForView);
2532 if (residueShading != null)
2534 residueShading.setConservationApplied(
2535 settingsForView.isConservationColourSelected());
2540 public boolean sameStyle(ViewStyleI them)
2542 return viewStyle.sameStyle(them);
2547 * @see jalview.api.ViewStyleI#getIdWidth()
2550 public int getIdWidth()
2552 return viewStyle.getIdWidth();
2557 * @see jalview.api.ViewStyleI#setIdWidth(int)
2560 public void setIdWidth(int i)
2562 viewStyle.setIdWidth(i);
2567 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2570 public boolean isCentreColumnLabels()
2572 return viewStyle.isCentreColumnLabels();
2576 * @param centreColumnLabels
2577 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2580 public void setCentreColumnLabels(boolean centreColumnLabels)
2582 viewStyle.setCentreColumnLabels(centreColumnLabels);
2587 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2590 public void setShowDBRefs(boolean showdbrefs)
2592 viewStyle.setShowDBRefs(showdbrefs);
2597 * @see jalview.api.ViewStyleI#isShowDBRefs()
2600 public boolean isShowDBRefs()
2602 return viewStyle.isShowDBRefs();
2607 * @see jalview.api.ViewStyleI#isShowNPFeats()
2610 public boolean isShowNPFeats()
2612 return viewStyle.isShowNPFeats();
2616 * @param shownpfeats
2617 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2620 public void setShowNPFeats(boolean shownpfeats)
2622 viewStyle.setShowNPFeats(shownpfeats);
2625 public abstract StructureSelectionManager getStructureSelectionManager();
2628 * Add one command to the command history list.
2632 public void addToHistoryList(CommandI command)
2634 if (this.historyList != null)
2636 this.historyList.push(command);
2637 broadcastCommand(command, false);
2641 protected void broadcastCommand(CommandI command, boolean undo)
2643 getStructureSelectionManager().commandPerformed(command, undo,
2648 * Add one command to the command redo list.
2652 public void addToRedoList(CommandI command)
2654 if (this.redoList != null)
2656 this.redoList.push(command);
2658 broadcastCommand(command, true);
2662 * Clear the command redo list.
2664 public void clearRedoList()
2666 if (this.redoList != null)
2668 this.redoList.clear();
2672 public void setHistoryList(Deque<CommandI> list)
2674 this.historyList = list;
2677 public Deque<CommandI> getHistoryList()
2679 return this.historyList;
2682 public void setRedoList(Deque<CommandI> list)
2684 this.redoList = list;
2687 public Deque<CommandI> getRedoList()
2689 return this.redoList;
2693 public VamsasSource getVamsasSource()
2698 public SequenceAnnotationOrder getSortAnnotationsBy()
2700 return sortAnnotationsBy;
2704 public void setSortAnnotationsBy(
2705 SequenceAnnotationOrder sortAnnotationsBy)
2707 this.sortAnnotationsBy = sortAnnotationsBy;
2711 public boolean isShowAutocalculatedAbove()
2713 return showAutocalculatedAbove;
2717 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2719 this.showAutocalculatedAbove = showAutocalculatedAbove;
2723 public boolean isScaleProteinAsCdna()
2725 return viewStyle.isScaleProteinAsCdna();
2729 public void setScaleProteinAsCdna(boolean b)
2731 viewStyle.setScaleProteinAsCdna(b);
2735 public boolean isProteinFontAsCdna()
2737 return viewStyle.isProteinFontAsCdna();
2741 public void setProteinFontAsCdna(boolean b)
2743 viewStyle.setProteinFontAsCdna(b);
2747 * @return true if view should scroll to show the highlighted region of a
2752 public final boolean isFollowHighlight()
2754 return followHighlight;
2758 public final void setFollowHighlight(boolean b)
2760 this.followHighlight = b;
2764 public ViewportRanges getRanges()
2770 * Helper method to populate the SearchResults with the location in the
2771 * complementary alignment to scroll to, in order to match this one.
2774 * the SearchResults to add to
2775 * @return the offset (below top of visible region) of the matched sequence
2777 protected int findComplementScrollTarget(SearchResultsI sr)
2779 final AlignViewportI complement = getCodingComplement();
2780 if (complement == null || !complement.isFollowHighlight())
2784 boolean iAmProtein = !getAlignment().isNucleotide();
2785 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2786 : complement.getAlignment();
2787 if (proteinAlignment == null)
2791 final List<AlignedCodonFrame> mappings = proteinAlignment
2795 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2796 * residue in the middle column of the visible region. Scroll the
2797 * complementary alignment to line up the corresponding residue.
2800 SequenceI sequence = null;
2803 * locate 'middle' column (true middle if an odd number visible, left of
2804 * middle if an even number visible)
2806 int middleColumn = ranges.getStartRes()
2807 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2808 final HiddenSequences hiddenSequences = getAlignment()
2809 .getHiddenSequences();
2812 * searching to the bottom of the alignment gives smoother scrolling across
2813 * all gapped visible regions
2815 int lastSeq = alignment.getHeight() - 1;
2816 List<AlignedCodonFrame> seqMappings = null;
2817 for (int seqNo = ranges
2818 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2820 sequence = getAlignment().getSequenceAt(seqNo);
2821 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2825 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2829 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2831 getCodingComplement().getAlignment().getSequences());
2832 if (!seqMappings.isEmpty())
2838 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2841 * No ungapped mapped sequence in middle column - do nothing
2845 MappingUtils.addSearchResults(sr, sequence,
2846 sequence.findPosition(middleColumn), seqMappings);
2851 * synthesize a column selection if none exists so it covers the given
2852 * selection group. if wholewidth is false, no column selection is made if the
2853 * selection group covers the whole alignment width.
2858 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2861 if (sg != null && (sgs = sg.getStartRes()) >= 0
2862 && sg.getStartRes() <= (sge = sg.getEndRes())
2863 && !this.hasSelectedColumns())
2865 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2872 colSel = new ColumnSelection();
2874 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2876 colSel.addElement(cspos);
2882 * hold status of current selection group - defined on alignment or not.
2884 private boolean selectionIsDefinedGroup = false;
2887 public boolean isSelectionDefinedGroup()
2889 if (selectionGroup == null)
2893 if (isSelectionGroupChanged(true))
2895 selectionIsDefinedGroup = false;
2896 List<SequenceGroup> gps = alignment.getGroups();
2897 if (gps == null || gps.size() == 0)
2899 selectionIsDefinedGroup = false;
2903 selectionIsDefinedGroup = gps.contains(selectionGroup);
2906 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2910 * null, or currently highlighted results on this view
2912 private SearchResultsI searchResults = null;
2914 protected TreeModel currentTree = null;
2917 public boolean hasSearchResults()
2919 return searchResults != null;
2923 public void setSearchResults(SearchResultsI results)
2925 searchResults = results;
2929 public SearchResultsI getSearchResults()
2931 return searchResults;
2935 * get the consensus sequence as displayed under the PID consensus annotation
2938 * @return consensus sequence as a new sequence object
2940 public SequenceI getConsensusSeq()
2942 if (consensus == null)
2944 updateConsensus(null);
2946 if (consensus == null)
2950 StringBuffer seqs = new StringBuffer();
2951 for (int i = 0; i < consensus.annotations.length; i++)
2953 Annotation annotation = consensus.annotations[i];
2954 if (annotation != null)
2956 String description = annotation.description;
2957 if (description != null && description.startsWith("["))
2959 // consensus is a tie - just pick the first one
2960 seqs.append(description.charAt(1));
2964 seqs.append(annotation.displayCharacter);
2969 SequenceI sq = new Sequence("Consensus", seqs.toString());
2970 sq.setDescription("Percentage Identity Consensus "
2971 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2976 public void setCurrentTree(TreeModel tree)
2982 public TreeModel getCurrentTree()
2988 * flag set to indicate if structure views might be out of sync with sequences
2992 private boolean needToUpdateStructureViews = false;
2995 public boolean isUpdateStructures()
2997 return needToUpdateStructureViews;
3001 public void setUpdateStructures(boolean update)
3003 needToUpdateStructureViews = update;
3007 public boolean needToUpdateStructureViews()
3009 boolean update = needToUpdateStructureViews;
3010 needToUpdateStructureViews = false;
3015 public void addSequenceGroup(SequenceGroup sequenceGroup)
3017 alignment.addGroup(sequenceGroup);
3019 Color col = sequenceGroup.idColour;
3022 col = col.brighter();
3024 for (SequenceI sq : sequenceGroup.getSequences())
3026 setSequenceColour(sq, col);
3030 if (codingComplement != null)
3032 SequenceGroup mappedGroup = MappingUtils
3033 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3034 if (mappedGroup.getSequences().size() > 0)
3036 codingComplement.getAlignment().addGroup(mappedGroup);
3040 for (SequenceI seq : mappedGroup.getSequences())
3042 codingComplement.setSequenceColour(seq, col);
3046 // propagate the structure view update flag according to our own setting
3047 codingComplement.setUpdateStructures(needToUpdateStructureViews);