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
84 protected ViewportRanges ranges;
86 protected ViewStyleI viewStyle = new ViewStyle();
89 * A viewport that hosts the cDna view of this (protein), or vice versa (if
92 AlignViewportI codingComplement = null;
94 FeaturesDisplayedI featuresDisplayed = null;
96 protected Deque<CommandI> historyList = new ArrayDeque<>();
98 protected Deque<CommandI> redoList = new ArrayDeque<>();
101 * alignment displayed in the viewport. Please use get/setter
103 protected AlignmentI alignment;
105 public AlignmentViewport(AlignmentI al)
108 ranges = new ViewportRanges(al);
113 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
116 public void setFontName(String name)
118 viewStyle.setFontName(name);
123 * @see jalview.api.ViewStyleI#setFontStyle(int)
126 public void setFontStyle(int style)
128 viewStyle.setFontStyle(style);
133 * @see jalview.api.ViewStyleI#setFontSize(int)
136 public void setFontSize(int size)
138 viewStyle.setFontSize(size);
143 * @see jalview.api.ViewStyleI#getFontStyle()
146 public int getFontStyle()
148 return viewStyle.getFontStyle();
153 * @see jalview.api.ViewStyleI#getFontName()
156 public String getFontName()
158 return viewStyle.getFontName();
163 * @see jalview.api.ViewStyleI#getFontSize()
166 public int getFontSize()
168 return viewStyle.getFontSize();
172 * @param upperCasebold
173 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
176 public void setUpperCasebold(boolean upperCasebold)
178 viewStyle.setUpperCasebold(upperCasebold);
183 * @see jalview.api.ViewStyleI#isUpperCasebold()
186 public boolean isUpperCasebold()
188 return viewStyle.isUpperCasebold();
193 * @see jalview.api.ViewStyleI#isSeqNameItalics()
196 public boolean isSeqNameItalics()
198 return viewStyle.isSeqNameItalics();
202 * @param colourByReferenceSeq
203 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
206 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
208 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
213 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
216 public void setColourAppliesToAllGroups(boolean b)
218 viewStyle.setColourAppliesToAllGroups(b);
223 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
226 public boolean getColourAppliesToAllGroups()
228 return viewStyle.getColourAppliesToAllGroups();
233 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
236 public boolean getAbovePIDThreshold()
238 return viewStyle.getAbovePIDThreshold();
243 * @see jalview.api.ViewStyleI#setIncrement(int)
246 public void setIncrement(int inc)
248 viewStyle.setIncrement(inc);
253 * @see jalview.api.ViewStyleI#getIncrement()
256 public int getIncrement()
258 return viewStyle.getIncrement();
263 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
266 public void setConservationSelected(boolean b)
268 viewStyle.setConservationSelected(b);
273 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
276 public void setShowHiddenMarkers(boolean show)
278 viewStyle.setShowHiddenMarkers(show);
283 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
286 public boolean getShowHiddenMarkers()
288 return viewStyle.getShowHiddenMarkers();
293 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
296 public void setScaleRightWrapped(boolean b)
298 viewStyle.setScaleRightWrapped(b);
303 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
306 public void setScaleLeftWrapped(boolean b)
308 viewStyle.setScaleLeftWrapped(b);
313 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
316 public void setScaleAboveWrapped(boolean b)
318 viewStyle.setScaleAboveWrapped(b);
323 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
326 public boolean getScaleLeftWrapped()
328 return viewStyle.getScaleLeftWrapped();
333 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
336 public boolean getScaleAboveWrapped()
338 return viewStyle.getScaleAboveWrapped();
343 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
346 public boolean getScaleRightWrapped()
348 return viewStyle.getScaleRightWrapped();
353 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
356 public void setAbovePIDThreshold(boolean b)
358 viewStyle.setAbovePIDThreshold(b);
363 * @see jalview.api.ViewStyleI#setThreshold(int)
366 public void setThreshold(int thresh)
368 viewStyle.setThreshold(thresh);
373 * @see jalview.api.ViewStyleI#getThreshold()
376 public int getThreshold()
378 return viewStyle.getThreshold();
383 * @see jalview.api.ViewStyleI#getShowJVSuffix()
386 public boolean getShowJVSuffix()
388 return viewStyle.getShowJVSuffix();
393 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
396 public void setShowJVSuffix(boolean b)
398 viewStyle.setShowJVSuffix(b);
403 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
406 public void setWrapAlignment(boolean state)
408 viewStyle.setWrapAlignment(state);
409 ranges.setWrappedMode(state);
414 * @see jalview.api.ViewStyleI#setShowText(boolean)
417 public void setShowText(boolean state)
419 viewStyle.setShowText(state);
424 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
427 public void setRenderGaps(boolean state)
429 viewStyle.setRenderGaps(state);
434 * @see jalview.api.ViewStyleI#getColourText()
437 public boolean getColourText()
439 return viewStyle.getColourText();
444 * @see jalview.api.ViewStyleI#setColourText(boolean)
447 public void setColourText(boolean state)
449 viewStyle.setColourText(state);
454 * @see jalview.api.ViewStyleI#getWrapAlignment()
457 public boolean getWrapAlignment()
459 return viewStyle.getWrapAlignment();
464 * @see jalview.api.ViewStyleI#getShowText()
467 public boolean getShowText()
469 return viewStyle.getShowText();
474 * @see jalview.api.ViewStyleI#getWrappedWidth()
477 public int getWrappedWidth()
479 return viewStyle.getWrappedWidth();
484 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
487 public void setWrappedWidth(int w)
489 viewStyle.setWrappedWidth(w);
494 * @see jalview.api.ViewStyleI#getCharHeight()
497 public int getCharHeight()
499 return viewStyle.getCharHeight();
504 * @see jalview.api.ViewStyleI#setCharHeight(int)
507 public void setCharHeight(int h)
509 viewStyle.setCharHeight(h);
514 * @see jalview.api.ViewStyleI#getCharWidth()
517 public int getCharWidth()
519 return viewStyle.getCharWidth();
524 * @see jalview.api.ViewStyleI#setCharWidth(int)
527 public void setCharWidth(int w)
529 viewStyle.setCharWidth(w);
534 * @see jalview.api.ViewStyleI#getShowBoxes()
537 public boolean getShowBoxes()
539 return viewStyle.getShowBoxes();
544 * @see jalview.api.ViewStyleI#getShowUnconserved()
547 public boolean getShowUnconserved()
549 return viewStyle.getShowUnconserved();
553 * @param showunconserved
554 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
557 public void setShowUnconserved(boolean showunconserved)
559 viewStyle.setShowUnconserved(showunconserved);
564 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
567 public void setSeqNameItalics(boolean default1)
569 viewStyle.setSeqNameItalics(default1);
573 public AlignmentI getAlignment()
579 public char getGapCharacter()
581 return alignment.getGapCharacter();
584 protected String sequenceSetID;
587 * probably unused indicator that view is of a dataset rather than an
590 protected boolean isDataset = false;
592 public void setDataset(boolean b)
597 public boolean isDataset()
602 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
604 protected ColumnSelection colSel = new ColumnSelection();
606 public boolean autoCalculateConsensus = true;
608 protected boolean autoCalculateStrucConsensus = true;
610 protected boolean ignoreGapsInConsensusCalculation = false;
612 protected ResidueShaderI residueShading = new ResidueShader();
615 public void setGlobalColourScheme(ColourSchemeI cs)
617 // TODO: logic refactored from AlignFrame changeColour -
618 // TODO: autorecalc stuff should be changed to rely on the worker system
619 // check to see if we should implement a changeColour(cs) method rather than
620 // put the logic in here
621 // - means that caller decides if they want to just modify state and defer
622 // calculation till later or to do all calculations in thread.
626 * only instantiate alignment colouring once, thereafter update it;
627 * this means that any conservation or PID threshold settings
628 * persist when the alignment colour scheme is changed
630 if (residueShading == null)
632 residueShading = new ResidueShader(viewStyle);
634 residueShading.setColourScheme(cs);
636 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
637 // ...problem: groups need these, but do not currently have a ViewStyle
641 if (getConservationSelected())
643 residueShading.setConservation(hconservation);
646 * reset conservation flag in case just set to false if
647 * Conservation was null (calculation still in progress)
649 residueShading.setConservationApplied(getConservationSelected());
650 residueShading.alignmentChanged(alignment, hiddenRepSequences);
654 * if 'apply colour to all groups' is selected... do so
655 * (but don't transfer any colour threshold settings to groups)
657 if (getColourAppliesToAllGroups())
659 for (SequenceGroup sg : getAlignment().getGroups())
662 * retain any colour thresholds per group while
663 * changing choice of colour scheme (JAL-2386)
666 cs == null ? null : cs.getInstance(this, sg));
669 sg.getGroupColourScheme().alignmentChanged(sg,
677 public ColourSchemeI getGlobalColourScheme()
679 return residueShading == null ? null : residueShading.getColourScheme();
683 public ResidueShaderI getResidueShading()
685 return residueShading;
688 protected AlignmentAnnotation consensus;
690 protected AlignmentAnnotation complementConsensus;
692 protected AlignmentAnnotation gapcounts;
694 protected AlignmentAnnotation strucConsensus;
696 protected AlignmentAnnotation conservation;
698 protected AlignmentAnnotation quality;
700 protected AlignmentAnnotation[] groupConsensus;
702 protected AlignmentAnnotation[] groupConservation;
705 * results of alignment consensus analysis for visible portion of view
707 protected ProfilesI hconsensus = null;
710 * results of cDNA complement consensus visible portion of view
712 protected Hashtable[] hcomplementConsensus = null;
715 * results of secondary structure base pair consensus for visible portion of
718 protected Hashtable[] hStrucConsensus = null;
720 protected Conservation hconservation = null;
723 public void setConservation(Conservation cons)
725 hconservation = cons;
729 * percentage gaps allowed in a column before all amino acid properties should
730 * be considered unconserved
732 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
735 public int getConsPercGaps()
741 public void setSequenceConsensusHash(ProfilesI hconsensus)
743 this.hconsensus = hconsensus;
747 public void setComplementConsensusHash(Hashtable[] hconsensus)
749 this.hcomplementConsensus = hconsensus;
753 public ProfilesI getSequenceConsensusHash()
759 public Hashtable[] getComplementConsensusHash()
761 return hcomplementConsensus;
765 public Hashtable[] getRnaStructureConsensusHash()
767 return hStrucConsensus;
771 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
773 this.hStrucConsensus = hStrucConsensus;
778 public AlignmentAnnotation getAlignmentQualityAnnot()
784 public AlignmentAnnotation getAlignmentConservationAnnotation()
790 public AlignmentAnnotation getAlignmentConsensusAnnotation()
796 public AlignmentAnnotation getAlignmentGapAnnotation()
802 public AlignmentAnnotation getComplementConsensusAnnotation()
804 return complementConsensus;
808 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
810 return strucConsensus;
813 protected AlignCalcManagerI calculator = new AlignCalcManager();
816 * trigger update of conservation annotation
818 public void updateConservation(final AlignmentViewPanel ap)
820 // see note in mantis : issue number 8585
821 if (alignment.isNucleotide()
822 || (conservation == null && quality == null)
823 || !autoCalculateConsensus)
827 if (calculator.getRegisteredWorkersOfClass(
828 jalview.workers.ConservationThread.class) == null)
830 calculator.registerWorker(
831 new jalview.workers.ConservationThread(this, ap));
836 * trigger update of consensus annotation
838 public void updateConsensus(final AlignmentViewPanel ap)
840 // see note in mantis : issue number 8585
841 if (consensus == null || !autoCalculateConsensus)
846 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
848 calculator.registerWorker(new ConsensusThread(this, ap));
852 * A separate thread to compute cDNA consensus for a protein alignment
853 * which has mapping to cDNA
855 final AlignmentI al = this.getAlignment();
856 if (!al.isNucleotide() && al.getCodonFrames() != null
857 && !al.getCodonFrames().isEmpty())
860 * fudge - check first for protein-to-nucleotide mappings
861 * (we don't want to do this for protein-to-protein)
863 boolean doConsensus = false;
864 for (AlignedCodonFrame mapping : al.getCodonFrames())
866 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
867 MapList[] mapLists = mapping.getdnaToProt();
868 // mapLists can be empty if project load has not finished resolving seqs
869 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
877 if (calculator.getRegisteredWorkersOfClass(
878 ComplementConsensusThread.class) == null)
881 .registerWorker(new ComplementConsensusThread(this, ap));
887 // --------START Structure Conservation
888 public void updateStrucConsensus(final AlignmentViewPanel ap)
890 if (autoCalculateStrucConsensus && strucConsensus == null
891 && alignment.isNucleotide() && alignment.hasRNAStructure())
893 // secondary structure has been added - so init the consensus line
897 // see note in mantis : issue number 8585
898 if (strucConsensus == null || !autoCalculateStrucConsensus)
902 if (calculator.getRegisteredWorkersOfClass(
903 StrucConsensusThread.class) == null)
905 calculator.registerWorker(new StrucConsensusThread(this, ap));
909 public boolean isCalcInProgress()
911 return calculator.isWorking();
915 public boolean isCalculationInProgress(
916 AlignmentAnnotation alignmentAnnotation)
918 if (!alignmentAnnotation.autoCalculated)
922 if (calculator.workingInvolvedWith(alignmentAnnotation))
924 // System.err.println("grey out ("+alignmentAnnotation.label+")");
930 public void setAlignment(AlignmentI align)
932 this.alignment = align;
936 * Clean up references when this viewport is closed
939 public void dispose()
942 * defensively null out references to large objects in case
943 * this object is not garbage collected (as if!)
946 complementConsensus = null;
947 strucConsensus = null;
950 groupConsensus = null;
951 groupConservation = null;
953 hconservation = null;
954 hcomplementConsensus = null;
957 residueShading = null; // may hold a reference to Consensus
958 changeSupport = null;
961 selectionGroup = null;
966 public boolean isClosed()
968 // TODO: check that this isClosed is only true after panel is closed, not
969 // before it is fully constructed.
970 return alignment == null;
974 public AlignCalcManagerI getCalcManager()
980 * should conservation rows be shown for groups
982 protected boolean showGroupConservation = false;
985 * should consensus rows be shown for groups
987 protected boolean showGroupConsensus = false;
990 * should consensus profile be rendered by default
992 protected boolean showSequenceLogo = false;
995 * should consensus profile be rendered normalised to row height
997 protected boolean normaliseSequenceLogo = false;
1000 * should consensus histograms be rendered by default
1002 protected boolean showConsensusHistogram = true;
1005 * @return the showConsensusProfile
1008 public boolean isShowSequenceLogo()
1010 return showSequenceLogo;
1014 * @param showSequenceLogo
1017 public void setShowSequenceLogo(boolean showSequenceLogo)
1019 if (showSequenceLogo != this.showSequenceLogo)
1021 // TODO: decouple settings setting from calculation when refactoring
1022 // annotation update method from alignframe to viewport
1023 this.showSequenceLogo = showSequenceLogo;
1024 calculator.updateAnnotationFor(ConsensusThread.class);
1025 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1026 calculator.updateAnnotationFor(StrucConsensusThread.class);
1028 this.showSequenceLogo = showSequenceLogo;
1032 * @param showConsensusHistogram
1033 * the showConsensusHistogram to set
1035 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1037 this.showConsensusHistogram = showConsensusHistogram;
1041 * @return the showGroupConservation
1043 public boolean isShowGroupConservation()
1045 return showGroupConservation;
1049 * @param showGroupConservation
1050 * the showGroupConservation to set
1052 public void setShowGroupConservation(boolean showGroupConservation)
1054 this.showGroupConservation = showGroupConservation;
1058 * @return the showGroupConsensus
1060 public boolean isShowGroupConsensus()
1062 return showGroupConsensus;
1066 * @param showGroupConsensus
1067 * the showGroupConsensus to set
1069 public void setShowGroupConsensus(boolean showGroupConsensus)
1071 this.showGroupConsensus = showGroupConsensus;
1076 * @return flag to indicate if the consensus histogram should be rendered by
1080 public boolean isShowConsensusHistogram()
1082 return this.showConsensusHistogram;
1086 * when set, updateAlignment will always ensure sequences are of equal length
1088 private boolean padGaps = false;
1091 * when set, alignment should be reordered according to a newly opened tree
1093 public boolean sortByTree = false;
1098 * @return null or the currently selected sequence region
1101 public SequenceGroup getSelectionGroup()
1103 return selectionGroup;
1107 * Set the selection group for this window. Also sets the current alignment as
1108 * the context for the group, if it does not already have one.
1111 * - group holding references to sequences in this alignment view
1115 public void setSelectionGroup(SequenceGroup sg)
1117 selectionGroup = sg;
1118 if (sg != null && sg.getContext() == null)
1120 sg.setContext(alignment);
1124 public void setHiddenColumns(HiddenColumns hidden)
1126 this.alignment.setHiddenColumns(hidden);
1130 public ColumnSelection getColumnSelection()
1136 public void setColumnSelection(ColumnSelection colSel)
1138 this.colSel = colSel;
1141 updateHiddenColumns();
1143 isColSelChanged(true);
1151 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1153 return hiddenRepSequences;
1157 public void setHiddenRepSequences(
1158 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1160 this.hiddenRepSequences = hiddenRepSequences;
1164 public boolean hasSelectedColumns()
1166 ColumnSelection columnSelection = getColumnSelection();
1167 return columnSelection != null && columnSelection.hasSelectedColumns();
1171 public boolean hasHiddenColumns()
1173 return alignment.getHiddenColumns() != null
1174 && alignment.getHiddenColumns().hasHiddenColumns();
1177 public void updateHiddenColumns()
1179 // this method doesn't really do anything now. But - it could, since a
1180 // column Selection could be in the process of modification
1181 // hasHiddenColumns = colSel.hasHiddenColumns();
1185 public boolean hasHiddenRows()
1187 return alignment.getHiddenSequences().getSize() > 0;
1190 protected SequenceGroup selectionGroup;
1192 public void setSequenceSetId(String newid)
1194 if (sequenceSetID != null)
1197 "Warning - overwriting a sequenceSetId for a viewport!");
1199 sequenceSetID = new String(newid);
1203 public String getSequenceSetId()
1205 if (sequenceSetID == null)
1207 sequenceSetID = alignment.hashCode() + "";
1210 return sequenceSetID;
1214 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1217 protected String viewId = null;
1220 public String getViewId()
1224 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1229 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1231 ignoreGapsInConsensusCalculation = b;
1234 updateConsensus(ap);
1235 if (residueShading != null)
1237 residueShading.setThreshold(residueShading.getThreshold(),
1238 ignoreGapsInConsensusCalculation);
1244 private long sgrouphash = -1, colselhash = -1;
1247 * checks current SelectionGroup against record of last hash value, and
1251 * update the record of last hash value
1253 * @return true if SelectionGroup changed since last call (when b is true)
1255 public boolean isSelectionGroupChanged(boolean b)
1257 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1258 : selectionGroup.hashCode();
1259 if (hc != -1 && hc != sgrouphash)
1271 * checks current colsel against record of last hash value, and optionally
1275 * update the record of last hash value
1276 * @return true if colsel changed since last call (when b is true)
1278 public boolean isColSelChanged(boolean b)
1280 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1281 if (hc != -1 && hc != colselhash)
1293 public boolean isIgnoreGapsConsensus()
1295 return ignoreGapsInConsensusCalculation;
1298 // property change stuff
1299 // JBPNote Prolly only need this in the applet version.
1300 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1303 protected boolean showConservation = true;
1305 protected boolean showQuality = true;
1307 protected boolean showConsensus = true;
1309 protected boolean showOccupancy = true;
1311 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1313 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1315 protected boolean showAutocalculatedAbove;
1318 * when set, view will scroll to show the highlighted position
1320 private boolean followHighlight = true;
1323 * Property change listener for changes in alignment
1328 public void addPropertyChangeListener(
1329 java.beans.PropertyChangeListener listener)
1331 changeSupport.addPropertyChangeListener(listener);
1340 public void removePropertyChangeListener(
1341 java.beans.PropertyChangeListener listener)
1343 if (changeSupport != null)
1345 changeSupport.removePropertyChangeListener(listener);
1350 * Property change listener for changes in alignment
1359 public void firePropertyChange(String prop, Object oldvalue,
1362 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1365 // common hide/show column stuff
1367 public void hideSelectedColumns()
1369 if (colSel.isEmpty())
1374 colSel.hideSelectedColumns(alignment);
1375 setSelectionGroup(null);
1376 isColSelChanged(true);
1379 public void hideColumns(int start, int end)
1383 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1387 alignment.getHiddenColumns().hideColumns(start, end);
1389 isColSelChanged(true);
1392 public void showColumn(int col)
1394 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1395 isColSelChanged(true);
1398 public void showAllHiddenColumns()
1400 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1401 isColSelChanged(true);
1404 // common hide/show seq stuff
1405 public void showAllHiddenSeqs()
1407 int startSeq = ranges.getStartSeq();
1408 int endSeq = ranges.getEndSeq();
1410 if (alignment.getHiddenSequences().getSize() > 0)
1412 if (selectionGroup == null)
1414 selectionGroup = new SequenceGroup();
1415 selectionGroup.setEndRes(alignment.getWidth() - 1);
1417 List<SequenceI> tmp = alignment.getHiddenSequences()
1418 .showAll(hiddenRepSequences);
1419 for (SequenceI seq : tmp)
1421 selectionGroup.addSequence(seq, false);
1422 setSequenceAnnotationsVisible(seq, true);
1425 hiddenRepSequences = null;
1427 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1429 firePropertyChange("alignment", null, alignment.getSequences());
1430 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1436 public void showSequence(int index)
1438 int startSeq = ranges.getStartSeq();
1439 int endSeq = ranges.getEndSeq();
1441 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1442 hiddenRepSequences);
1445 if (selectionGroup == null)
1447 selectionGroup = new SequenceGroup();
1448 selectionGroup.setEndRes(alignment.getWidth() - 1);
1451 for (SequenceI seq : tmp)
1453 selectionGroup.addSequence(seq, false);
1454 setSequenceAnnotationsVisible(seq, true);
1457 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1459 firePropertyChange("alignment", null, alignment.getSequences());
1464 public void hideAllSelectedSeqs()
1466 if (selectionGroup == null || selectionGroup.getSize() < 1)
1471 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1475 setSelectionGroup(null);
1478 public void hideSequence(SequenceI[] seq)
1481 * cache offset to first visible sequence
1483 int startSeq = ranges.getStartSeq();
1487 for (int i = 0; i < seq.length; i++)
1489 alignment.getHiddenSequences().hideSequence(seq[i]);
1490 setSequenceAnnotationsVisible(seq[i], false);
1492 ranges.setStartSeq(startSeq);
1493 firePropertyChange("alignment", null, alignment.getSequences());
1498 * Hides the specified sequence, or the sequences it represents
1501 * the sequence to hide, or keep as representative
1502 * @param representGroup
1503 * if true, hide the current selection group except for the
1504 * representative sequence
1506 public void hideSequences(SequenceI sequence, boolean representGroup)
1508 if (selectionGroup == null || selectionGroup.getSize() < 1)
1510 hideSequence(new SequenceI[] { sequence });
1516 hideRepSequences(sequence, selectionGroup);
1517 setSelectionGroup(null);
1521 int gsize = selectionGroup.getSize();
1522 SequenceI[] hseqs = selectionGroup.getSequences()
1523 .toArray(new SequenceI[gsize]);
1525 hideSequence(hseqs);
1526 setSelectionGroup(null);
1531 * Set visibility for any annotations for the given sequence.
1535 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1538 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1541 for (AlignmentAnnotation ann : anns)
1543 if (ann.sequenceRef == sequenceI)
1545 ann.visible = visible;
1551 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1553 int sSize = sg.getSize();
1559 if (hiddenRepSequences == null)
1561 hiddenRepSequences = new Hashtable<>();
1564 hiddenRepSequences.put(repSequence, sg);
1566 // Hide all sequences except the repSequence
1567 SequenceI[] seqs = new SequenceI[sSize - 1];
1569 for (int i = 0; i < sSize; i++)
1571 if (sg.getSequenceAt(i) != repSequence)
1573 if (index == sSize - 1)
1578 seqs[index++] = sg.getSequenceAt(i);
1581 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1582 sg.setHidereps(true); // note: not done in 2.7applet
1589 * @return null or the current reference sequence
1591 public SequenceI getReferenceSeq()
1593 return alignment.getSeqrep();
1598 * @return true iff seq is the reference for the alignment
1600 public boolean isReferenceSeq(SequenceI seq)
1602 return alignment.getSeqrep() == seq;
1608 * @return true if there are sequences represented by this sequence that are
1611 public boolean isHiddenRepSequence(SequenceI seq)
1613 return (hiddenRepSequences != null
1614 && hiddenRepSequences.containsKey(seq));
1620 * @return null or a sequence group containing the sequences that seq
1623 public SequenceGroup getRepresentedSequences(SequenceI seq)
1625 return (SequenceGroup) (hiddenRepSequences == null ? null
1626 : hiddenRepSequences.get(seq));
1630 public int adjustForHiddenSeqs(int alignmentIndex)
1632 return alignment.getHiddenSequences()
1633 .adjustForHiddenSeqs(alignmentIndex);
1637 public void invertColumnSelection()
1639 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1640 isColSelChanged(true);
1644 public SequenceI[] getSelectionAsNewSequence()
1646 SequenceI[] sequences;
1647 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1648 // this was the only caller in the applet for this method
1649 // JBPNote: in applet, this method returned references to the alignment
1650 // sequences, and it did not honour the presence/absence of annotation
1651 // attached to the alignment (probably!)
1652 if (selectionGroup == null || selectionGroup.getSize() == 0)
1654 sequences = alignment.getSequencesArray();
1655 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1656 for (int i = 0; i < sequences.length; i++)
1658 // construct new sequence with subset of visible annotation
1659 sequences[i] = new Sequence(sequences[i], annots);
1664 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1671 public SequenceI[] getSequenceSelection()
1673 SequenceI[] sequences = null;
1674 if (selectionGroup != null)
1676 sequences = selectionGroup.getSequencesInOrder(alignment);
1678 if (sequences == null)
1680 sequences = alignment.getSequencesArray();
1686 public jalview.datamodel.AlignmentView getAlignmentView(
1687 boolean selectedOnly)
1689 return getAlignmentView(selectedOnly, false);
1693 public jalview.datamodel.AlignmentView getAlignmentView(
1694 boolean selectedOnly, boolean markGroups)
1696 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1698 alignment.getHiddenColumns() != null
1699 && alignment.getHiddenColumns().hasHiddenColumns(),
1700 selectedOnly, markGroups);
1704 public String[] getViewAsString(boolean selectedRegionOnly)
1706 return getViewAsString(selectedRegionOnly, true);
1710 public String[] getViewAsString(boolean selectedRegionOnly,
1711 boolean exportHiddenSeqs)
1713 String[] selection = null;
1714 SequenceI[] seqs = null;
1716 int start = 0, end = 0;
1717 if (selectedRegionOnly && selectionGroup != null)
1719 iSize = selectionGroup.getSize();
1720 seqs = selectionGroup.getSequencesInOrder(alignment);
1721 start = selectionGroup.getStartRes();
1722 end = selectionGroup.getEndRes() + 1;
1726 if (hasHiddenRows() && exportHiddenSeqs)
1728 AlignmentI fullAlignment = alignment.getHiddenSequences()
1729 .getFullAlignment();
1730 iSize = fullAlignment.getHeight();
1731 seqs = fullAlignment.getSequencesArray();
1732 end = fullAlignment.getWidth();
1736 iSize = alignment.getHeight();
1737 seqs = alignment.getSequencesArray();
1738 end = alignment.getWidth();
1742 selection = new String[iSize];
1743 if (alignment.getHiddenColumns() != null
1744 && alignment.getHiddenColumns().hasHiddenColumns())
1746 for (i = 0; i < iSize; i++)
1748 Iterator<int[]> blocks = alignment.getHiddenColumns()
1749 .getVisContigsIterator(start, end + 1, false);
1750 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1755 for (i = 0; i < iSize; i++)
1757 selection[i] = seqs[i].getSequenceAsString(start, end);
1765 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1767 ArrayList<int[]> regions = new ArrayList<>();
1773 HiddenColumns hidden = alignment.getHiddenColumns();
1774 if (hidden != null && hidden.hasHiddenColumns())
1778 start = hidden.visibleToAbsoluteColumn(start);
1781 end = hidden.getNextHiddenBoundary(false, start);
1792 regions.add(new int[] { start, end });
1794 if (hidden != null && hidden.hasHiddenColumns())
1796 start = hidden.visibleToAbsoluteColumn(end);
1797 start = hidden.getNextHiddenBoundary(true, start) + 1;
1799 } while (end < max);
1801 int[][] startEnd = new int[regions.size()][2];
1807 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1808 boolean selectedOnly)
1810 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1811 AlignmentAnnotation[] aa;
1812 if ((aa = alignment.getAlignmentAnnotation()) != null)
1814 for (AlignmentAnnotation annot : aa)
1816 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1817 if (selectedOnly && selectionGroup != null)
1819 clone.makeVisibleAnnotation(
1820 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1821 alignment.getHiddenColumns());
1825 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1834 public boolean isPadGaps()
1840 public void setPadGaps(boolean padGaps)
1842 this.padGaps = padGaps;
1846 * apply any post-edit constraints and trigger any calculations needed after
1847 * an edit has been performed on the alignment
1852 public void alignmentChanged(AlignmentViewPanel ap)
1856 alignment.padGaps();
1858 if (autoCalculateConsensus)
1860 updateConsensus(ap);
1862 if (hconsensus != null && autoCalculateConsensus)
1864 updateConservation(ap);
1866 if (autoCalculateStrucConsensus)
1868 updateStrucConsensus(ap);
1871 // Reset endRes of groups if beyond alignment width
1872 int alWidth = alignment.getWidth();
1873 List<SequenceGroup> groups = alignment.getGroups();
1876 for (SequenceGroup sg : groups)
1878 if (sg.getEndRes() > alWidth)
1880 sg.setEndRes(alWidth - 1);
1885 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1887 selectionGroup.setEndRes(alWidth - 1);
1890 updateAllColourSchemes();
1891 calculator.restartWorkers();
1892 // alignment.adjustSequenceAnnotations();
1896 * reset scope and do calculations for all applied colourschemes on alignment
1898 void updateAllColourSchemes()
1900 ResidueShaderI rs = residueShading;
1903 rs.alignmentChanged(alignment, hiddenRepSequences);
1905 rs.setConsensus(hconsensus);
1906 if (rs.conservationApplied())
1908 rs.setConservation(Conservation.calculateConservation("All",
1909 alignment.getSequences(), 0, alignment.getWidth(), false,
1910 getConsPercGaps(), false));
1914 for (SequenceGroup sg : alignment.getGroups())
1918 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1920 sg.recalcConservation();
1924 protected void initAutoAnnotation()
1926 // TODO: add menu option action that nulls or creates consensus object
1927 // depending on if the user wants to see the annotation or not in a
1928 // specific alignment
1930 if (hconsensus == null && !isDataset)
1932 if (!alignment.isNucleotide())
1941 consensus = new AlignmentAnnotation("Consensus",
1942 MessageManager.getString("label.consensus_descr"),
1943 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1944 initConsensus(consensus);
1947 initComplementConsensus();
1952 * If this is a protein alignment and there are mappings to cDNA, adds the
1953 * cDNA consensus annotation and returns true, else returns false.
1955 public boolean initComplementConsensus()
1957 if (!alignment.isNucleotide())
1959 final List<AlignedCodonFrame> codonMappings = alignment
1961 if (codonMappings != null && !codonMappings.isEmpty())
1963 boolean doConsensus = false;
1964 for (AlignedCodonFrame mapping : codonMappings)
1966 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1967 MapList[] mapLists = mapping.getdnaToProt();
1968 // mapLists can be empty if project load has not finished resolving
1970 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1978 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1980 .getString("label.complement_consensus_descr"),
1981 new Annotation[1], 0f, 100f,
1982 AlignmentAnnotation.BAR_GRAPH);
1983 initConsensus(complementConsensus);
1991 private void initConsensus(AlignmentAnnotation aa)
1994 aa.autoCalculated = true;
1998 alignment.addAnnotation(aa);
2002 // these should be extracted from the view model - style and settings for
2003 // derived annotation
2004 private void initGapCounts()
2008 gapcounts = new AlignmentAnnotation("Occupancy",
2009 MessageManager.getString("label.occupancy_descr"),
2010 new Annotation[1], 0f, alignment.getHeight(),
2011 AlignmentAnnotation.BAR_GRAPH);
2012 gapcounts.hasText = true;
2013 gapcounts.autoCalculated = true;
2014 gapcounts.scaleColLabel = true;
2015 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2017 alignment.addAnnotation(gapcounts);
2021 private void initConservation()
2023 if (showConservation)
2025 if (conservation == null)
2027 conservation = new AlignmentAnnotation("Conservation",
2028 MessageManager.formatMessage("label.conservation_descr",
2030 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2031 conservation.hasText = true;
2032 conservation.autoCalculated = true;
2033 alignment.addAnnotation(conservation);
2038 private void initQuality()
2042 if (quality == null)
2044 quality = new AlignmentAnnotation("Quality",
2045 MessageManager.getString("label.quality_descr"),
2046 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2047 quality.hasText = true;
2048 quality.autoCalculated = true;
2049 alignment.addAnnotation(quality);
2054 private void initRNAStructure()
2056 if (alignment.hasRNAStructure() && strucConsensus == null)
2058 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2059 MessageManager.getString("label.strucconsensus_descr"),
2060 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2061 strucConsensus.hasText = true;
2062 strucConsensus.autoCalculated = true;
2066 alignment.addAnnotation(strucConsensus);
2074 * @see jalview.api.AlignViewportI#calcPanelHeight()
2077 public int calcPanelHeight()
2079 // setHeight of panels
2080 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2082 int charHeight = getCharHeight();
2085 BitSet graphgrp = new BitSet();
2086 for (AlignmentAnnotation aa : anns)
2090 System.err.println("Null annotation row: ignoring.");
2097 if (aa.graphGroup > -1)
2099 if (graphgrp.get(aa.graphGroup))
2105 graphgrp.set(aa.graphGroup);
2112 aa.height += charHeight;
2122 aa.height += aa.graphHeight;
2130 height += aa.height;
2142 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2143 boolean preserveNewGroupSettings)
2145 boolean updateCalcs = false;
2146 boolean conv = isShowGroupConservation();
2147 boolean cons = isShowGroupConsensus();
2148 boolean showprf = isShowSequenceLogo();
2149 boolean showConsHist = isShowConsensusHistogram();
2150 boolean normLogo = isNormaliseSequenceLogo();
2153 * TODO reorder the annotation rows according to group/sequence ordering on
2156 boolean sortg = true;
2158 // remove old automatic annotation
2159 // add any new annotation
2161 // intersect alignment annotation with alignment groups
2163 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2164 List<SequenceGroup> oldrfs = new ArrayList<>();
2167 for (int an = 0; an < aan.length; an++)
2169 if (aan[an].autoCalculated && aan[an].groupRef != null)
2171 oldrfs.add(aan[an].groupRef);
2172 alignment.deleteAnnotation(aan[an], false);
2176 if (alignment.getGroups() != null)
2178 for (SequenceGroup sg : alignment.getGroups())
2180 updateCalcs = false;
2181 if (applyGlobalSettings
2182 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2184 // set defaults for this group's conservation/consensus
2185 sg.setshowSequenceLogo(showprf);
2186 sg.setShowConsensusHistogram(showConsHist);
2187 sg.setNormaliseSequenceLogo(normLogo);
2192 alignment.addAnnotation(sg.getConservationRow(), 0);
2197 alignment.addAnnotation(sg.getConsensus(), 0);
2199 // refresh the annotation rows
2202 sg.recalcConservation();
2210 public boolean isDisplayReferenceSeq()
2212 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2216 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2218 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2222 public boolean isColourByReferenceSeq()
2224 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2228 public Color getSequenceColour(SequenceI seq)
2230 Color sqc = sequenceColours.get(seq);
2231 return (sqc == null ? Color.white : sqc);
2235 public void setSequenceColour(SequenceI seq, Color col)
2239 sequenceColours.remove(seq);
2243 sequenceColours.put(seq, col);
2248 public void updateSequenceIdColours()
2250 for (SequenceGroup sg : alignment.getGroups())
2252 if (sg.idColour != null)
2254 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2256 sequenceColours.put(s, sg.idColour);
2263 public void clearSequenceColours()
2265 sequenceColours.clear();
2269 public AlignViewportI getCodingComplement()
2271 return this.codingComplement;
2275 * Set this as the (cDna/protein) complement of the given viewport. Also
2276 * ensures the reverse relationship is set on the given viewport.
2279 public void setCodingComplement(AlignViewportI av)
2283 System.err.println("Ignoring recursive setCodingComplement request");
2287 this.codingComplement = av;
2288 // avoid infinite recursion!
2289 if (av.getCodingComplement() != this)
2291 av.setCodingComplement(this);
2297 public boolean isNucleotide()
2299 return getAlignment() == null ? false : getAlignment().isNucleotide();
2303 public FeaturesDisplayedI getFeaturesDisplayed()
2305 return featuresDisplayed;
2309 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2311 featuresDisplayed = featuresDisplayedI;
2315 public boolean areFeaturesDisplayed()
2317 return featuresDisplayed != null
2318 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2325 * features are displayed if true
2328 public void setShowSequenceFeatures(boolean b)
2330 viewStyle.setShowSequenceFeatures(b);
2334 public boolean isShowSequenceFeatures()
2336 return viewStyle.isShowSequenceFeatures();
2340 public void setShowSequenceFeaturesHeight(boolean selected)
2342 viewStyle.setShowSequenceFeaturesHeight(selected);
2346 public boolean isShowSequenceFeaturesHeight()
2348 return viewStyle.isShowSequenceFeaturesHeight();
2352 public void setShowAnnotation(boolean b)
2354 viewStyle.setShowAnnotation(b);
2358 public boolean isShowAnnotation()
2360 return viewStyle.isShowAnnotation();
2364 public boolean isRightAlignIds()
2366 return viewStyle.isRightAlignIds();
2370 public void setRightAlignIds(boolean rightAlignIds)
2372 viewStyle.setRightAlignIds(rightAlignIds);
2376 public boolean getConservationSelected()
2378 return viewStyle.getConservationSelected();
2382 public void setShowBoxes(boolean state)
2384 viewStyle.setShowBoxes(state);
2389 * @see jalview.api.ViewStyleI#getTextColour()
2392 public Color getTextColour()
2394 return viewStyle.getTextColour();
2399 * @see jalview.api.ViewStyleI#getTextColour2()
2402 public Color getTextColour2()
2404 return viewStyle.getTextColour2();
2409 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2412 public int getThresholdTextColour()
2414 return viewStyle.getThresholdTextColour();
2419 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2422 public boolean isConservationColourSelected()
2424 return viewStyle.isConservationColourSelected();
2429 * @see jalview.api.ViewStyleI#isRenderGaps()
2432 public boolean isRenderGaps()
2434 return viewStyle.isRenderGaps();
2439 * @see jalview.api.ViewStyleI#isShowColourText()
2442 public boolean isShowColourText()
2444 return viewStyle.isShowColourText();
2448 * @param conservationColourSelected
2449 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2452 public void setConservationColourSelected(
2453 boolean conservationColourSelected)
2455 viewStyle.setConservationColourSelected(conservationColourSelected);
2459 * @param showColourText
2460 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2463 public void setShowColourText(boolean showColourText)
2465 viewStyle.setShowColourText(showColourText);
2470 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2473 public void setTextColour(Color textColour)
2475 viewStyle.setTextColour(textColour);
2479 * @param thresholdTextColour
2480 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2483 public void setThresholdTextColour(int thresholdTextColour)
2485 viewStyle.setThresholdTextColour(thresholdTextColour);
2489 * @param textColour2
2490 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2493 public void setTextColour2(Color textColour2)
2495 viewStyle.setTextColour2(textColour2);
2499 public ViewStyleI getViewStyle()
2501 return new ViewStyle(viewStyle);
2505 public void setViewStyle(ViewStyleI settingsForView)
2507 viewStyle = new ViewStyle(settingsForView);
2508 if (residueShading != null)
2510 residueShading.setConservationApplied(
2511 settingsForView.isConservationColourSelected());
2516 public boolean sameStyle(ViewStyleI them)
2518 return viewStyle.sameStyle(them);
2523 * @see jalview.api.ViewStyleI#getIdWidth()
2526 public int getIdWidth()
2528 return viewStyle.getIdWidth();
2533 * @see jalview.api.ViewStyleI#setIdWidth(int)
2536 public void setIdWidth(int i)
2538 viewStyle.setIdWidth(i);
2543 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2546 public boolean isCentreColumnLabels()
2548 return viewStyle.isCentreColumnLabels();
2552 * @param centreColumnLabels
2553 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2556 public void setCentreColumnLabels(boolean centreColumnLabels)
2558 viewStyle.setCentreColumnLabels(centreColumnLabels);
2563 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2566 public void setShowDBRefs(boolean showdbrefs)
2568 viewStyle.setShowDBRefs(showdbrefs);
2573 * @see jalview.api.ViewStyleI#isShowDBRefs()
2576 public boolean isShowDBRefs()
2578 return viewStyle.isShowDBRefs();
2583 * @see jalview.api.ViewStyleI#isShowNPFeats()
2586 public boolean isShowNPFeats()
2588 return viewStyle.isShowNPFeats();
2592 * @param shownpfeats
2593 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2596 public void setShowNPFeats(boolean shownpfeats)
2598 viewStyle.setShowNPFeats(shownpfeats);
2601 public abstract StructureSelectionManager getStructureSelectionManager();
2604 * Add one command to the command history list.
2608 public void addToHistoryList(CommandI command)
2610 if (this.historyList != null)
2612 this.historyList.push(command);
2613 broadcastCommand(command, false);
2617 protected void broadcastCommand(CommandI command, boolean undo)
2619 getStructureSelectionManager().commandPerformed(command, undo,
2624 * Add one command to the command redo list.
2628 public void addToRedoList(CommandI command)
2630 if (this.redoList != null)
2632 this.redoList.push(command);
2634 broadcastCommand(command, true);
2638 * Clear the command redo list.
2640 public void clearRedoList()
2642 if (this.redoList != null)
2644 this.redoList.clear();
2648 public void setHistoryList(Deque<CommandI> list)
2650 this.historyList = list;
2653 public Deque<CommandI> getHistoryList()
2655 return this.historyList;
2658 public void setRedoList(Deque<CommandI> list)
2660 this.redoList = list;
2663 public Deque<CommandI> getRedoList()
2665 return this.redoList;
2669 public VamsasSource getVamsasSource()
2674 public SequenceAnnotationOrder getSortAnnotationsBy()
2676 return sortAnnotationsBy;
2679 public void setSortAnnotationsBy(
2680 SequenceAnnotationOrder sortAnnotationsBy)
2682 this.sortAnnotationsBy = sortAnnotationsBy;
2685 public boolean isShowAutocalculatedAbove()
2687 return showAutocalculatedAbove;
2690 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2692 this.showAutocalculatedAbove = showAutocalculatedAbove;
2696 public boolean isScaleProteinAsCdna()
2698 return viewStyle.isScaleProteinAsCdna();
2702 public void setScaleProteinAsCdna(boolean b)
2704 viewStyle.setScaleProteinAsCdna(b);
2708 public boolean isProteinFontAsCdna()
2710 return viewStyle.isProteinFontAsCdna();
2714 public void setProteinFontAsCdna(boolean b)
2716 viewStyle.setProteinFontAsCdna(b);
2720 public void setShowComplementFeatures(boolean b)
2722 viewStyle.setShowComplementFeatures(b);
2726 public boolean isShowComplementFeatures()
2728 return viewStyle.isShowComplementFeatures();
2732 public void setShowComplementFeaturesOnTop(boolean b)
2734 viewStyle.setShowComplementFeaturesOnTop(b);
2738 public boolean isShowComplementFeaturesOnTop()
2740 return viewStyle.isShowComplementFeaturesOnTop();
2744 * @return true if view should scroll to show the highlighted region of a
2749 public final boolean isFollowHighlight()
2751 return followHighlight;
2755 public final void setFollowHighlight(boolean b)
2757 this.followHighlight = b;
2761 public ViewportRanges getRanges()
2767 * Helper method to populate the SearchResults with the location in the
2768 * complementary alignment to scroll to, in order to match this one.
2771 * the SearchResults to add to
2772 * @return the offset (below top of visible region) of the matched sequence
2774 protected int findComplementScrollTarget(SearchResultsI sr)
2776 final AlignViewportI complement = getCodingComplement();
2777 if (complement == null || !complement.isFollowHighlight())
2781 boolean iAmProtein = !getAlignment().isNucleotide();
2782 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2783 : complement.getAlignment();
2784 if (proteinAlignment == null)
2788 final List<AlignedCodonFrame> mappings = proteinAlignment
2792 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2793 * residue in the middle column of the visible region. Scroll the
2794 * complementary alignment to line up the corresponding residue.
2797 SequenceI sequence = null;
2800 * locate 'middle' column (true middle if an odd number visible, left of
2801 * middle if an even number visible)
2803 int middleColumn = ranges.getStartRes()
2804 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2805 final HiddenSequences hiddenSequences = getAlignment()
2806 .getHiddenSequences();
2809 * searching to the bottom of the alignment gives smoother scrolling across
2810 * all gapped visible regions
2812 int lastSeq = alignment.getHeight() - 1;
2813 List<AlignedCodonFrame> seqMappings = null;
2814 for (int seqNo = ranges
2815 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2817 sequence = getAlignment().getSequenceAt(seqNo);
2818 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2822 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2826 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2828 getCodingComplement().getAlignment().getSequences());
2829 if (!seqMappings.isEmpty())
2835 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2838 * No ungapped mapped sequence in middle column - do nothing
2842 MappingUtils.addSearchResults(sr, sequence,
2843 sequence.findPosition(middleColumn), seqMappings);
2848 * synthesize a column selection if none exists so it covers the given
2849 * selection group. if wholewidth is false, no column selection is made if the
2850 * selection group covers the whole alignment width.
2855 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2858 if (sg != null && (sgs = sg.getStartRes()) >= 0
2859 && sg.getStartRes() <= (sge = sg.getEndRes())
2860 && !this.hasSelectedColumns())
2862 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2869 colSel = new ColumnSelection();
2871 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2873 colSel.addElement(cspos);
2879 * hold status of current selection group - defined on alignment or not.
2881 private boolean selectionIsDefinedGroup = false;
2884 public boolean isSelectionDefinedGroup()
2886 if (selectionGroup == null)
2890 if (isSelectionGroupChanged(true))
2892 selectionIsDefinedGroup = false;
2893 List<SequenceGroup> gps = alignment.getGroups();
2894 if (gps == null || gps.size() == 0)
2896 selectionIsDefinedGroup = false;
2900 selectionIsDefinedGroup = gps.contains(selectionGroup);
2903 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2907 * null, or currently highlighted results on this view
2909 private SearchResultsI searchResults = null;
2911 protected TreeModel currentTree = null;
2914 public boolean hasSearchResults()
2916 return searchResults != null;
2920 public void setSearchResults(SearchResultsI results)
2922 searchResults = results;
2926 public SearchResultsI getSearchResults()
2928 return searchResults;
2932 * get the consensus sequence as displayed under the PID consensus annotation
2935 * @return consensus sequence as a new sequence object
2937 public SequenceI getConsensusSeq()
2939 if (consensus == null)
2941 updateConsensus(null);
2943 if (consensus == null)
2947 StringBuffer seqs = new StringBuffer();
2948 for (int i = 0; i < consensus.annotations.length; i++)
2950 Annotation annotation = consensus.annotations[i];
2951 if (annotation != null)
2953 String description = annotation.description;
2954 if (description != null && description.startsWith("["))
2956 // consensus is a tie - just pick the first one
2957 seqs.append(description.charAt(1));
2961 seqs.append(annotation.displayCharacter);
2966 SequenceI sq = new Sequence("Consensus", seqs.toString());
2967 sq.setDescription("Percentage Identity Consensus "
2968 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2973 public void setCurrentTree(TreeModel tree)
2979 public TreeModel getCurrentTree()
2985 * flag set to indicate if structure views might be out of sync with sequences
2989 private boolean needToUpdateStructureViews = false;
2992 public boolean isUpdateStructures()
2994 return needToUpdateStructureViews;
2998 public void setUpdateStructures(boolean update)
3000 needToUpdateStructureViews = update;
3004 public boolean needToUpdateStructureViews()
3006 boolean update = needToUpdateStructureViews;
3007 needToUpdateStructureViews = false;
3012 public void addSequenceGroup(SequenceGroup sequenceGroup)
3014 alignment.addGroup(sequenceGroup);
3016 Color col = sequenceGroup.idColour;
3019 col = col.brighter();
3021 for (SequenceI sq : sequenceGroup.getSequences())
3023 setSequenceColour(sq, col);
3027 if (codingComplement != null)
3029 SequenceGroup mappedGroup = MappingUtils
3030 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3031 if (mappedGroup.getSequences().size() > 0)
3033 codingComplement.getAlignment().addGroup(mappedGroup);
3037 for (SequenceI seq : mappedGroup.getSequences())
3039 codingComplement.setSequenceColour(seq, col);
3043 // propagate the structure view update flag according to our own setting
3044 codingComplement.setUpdateStructures(needToUpdateStructureViews);