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;
967 public boolean isClosed()
969 // TODO: check that this isClosed is only true after panel is closed, not
970 // before it is fully constructed.
971 return alignment == null;
975 public AlignCalcManagerI getCalcManager()
981 * should conservation rows be shown for groups
983 protected boolean showGroupConservation = false;
986 * should consensus rows be shown for groups
988 protected boolean showGroupConsensus = false;
991 * should consensus profile be rendered by default
993 protected boolean showSequenceLogo = false;
996 * should consensus profile be rendered normalised to row height
998 protected boolean normaliseSequenceLogo = false;
1001 * should consensus histograms be rendered by default
1003 protected boolean showConsensusHistogram = true;
1006 * @return the showConsensusProfile
1009 public boolean isShowSequenceLogo()
1011 return showSequenceLogo;
1015 * @param showSequenceLogo
1018 public void setShowSequenceLogo(boolean showSequenceLogo)
1020 if (showSequenceLogo != this.showSequenceLogo)
1022 // TODO: decouple settings setting from calculation when refactoring
1023 // annotation update method from alignframe to viewport
1024 this.showSequenceLogo = showSequenceLogo;
1025 calculator.updateAnnotationFor(ConsensusThread.class);
1026 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1027 calculator.updateAnnotationFor(StrucConsensusThread.class);
1029 this.showSequenceLogo = showSequenceLogo;
1033 * @param showConsensusHistogram
1034 * the showConsensusHistogram to set
1036 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1038 this.showConsensusHistogram = showConsensusHistogram;
1042 * @return the showGroupConservation
1044 public boolean isShowGroupConservation()
1046 return showGroupConservation;
1050 * @param showGroupConservation
1051 * the showGroupConservation to set
1053 public void setShowGroupConservation(boolean showGroupConservation)
1055 this.showGroupConservation = showGroupConservation;
1059 * @return the showGroupConsensus
1061 public boolean isShowGroupConsensus()
1063 return showGroupConsensus;
1067 * @param showGroupConsensus
1068 * the showGroupConsensus to set
1070 public void setShowGroupConsensus(boolean showGroupConsensus)
1072 this.showGroupConsensus = showGroupConsensus;
1077 * @return flag to indicate if the consensus histogram should be rendered by
1081 public boolean isShowConsensusHistogram()
1083 return this.showConsensusHistogram;
1087 * when set, updateAlignment will always ensure sequences are of equal length
1089 private boolean padGaps = false;
1092 * when set, alignment should be reordered according to a newly opened tree
1094 public boolean sortByTree = false;
1099 * @return null or the currently selected sequence region
1102 public SequenceGroup getSelectionGroup()
1104 return selectionGroup;
1108 * Set the selection group for this window. Also sets the current alignment as
1109 * the context for the group, if it does not already have one.
1112 * - group holding references to sequences in this alignment view
1116 public void setSelectionGroup(SequenceGroup sg)
1118 selectionGroup = sg;
1119 if (sg != null && sg.getContext() == null)
1121 sg.setContext(alignment);
1125 public void setHiddenColumns(HiddenColumns hidden)
1127 this.alignment.setHiddenColumns(hidden);
1131 public ColumnSelection getColumnSelection()
1137 public void setColumnSelection(ColumnSelection colSel)
1139 this.colSel = colSel;
1142 updateHiddenColumns();
1144 isColSelChanged(true);
1152 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1154 return hiddenRepSequences;
1158 public void setHiddenRepSequences(
1159 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1161 this.hiddenRepSequences = hiddenRepSequences;
1165 public boolean hasSelectedColumns()
1167 ColumnSelection columnSelection = getColumnSelection();
1168 return columnSelection != null && columnSelection.hasSelectedColumns();
1172 public boolean hasHiddenColumns()
1174 return alignment.getHiddenColumns() != null
1175 && alignment.getHiddenColumns().hasHiddenColumns();
1178 public void updateHiddenColumns()
1180 // this method doesn't really do anything now. But - it could, since a
1181 // column Selection could be in the process of modification
1182 // hasHiddenColumns = colSel.hasHiddenColumns();
1186 public boolean hasHiddenRows()
1188 return alignment.getHiddenSequences().getSize() > 0;
1191 protected SequenceGroup selectionGroup;
1193 public void setSequenceSetId(String newid)
1195 if (sequenceSetID != null)
1198 "Warning - overwriting a sequenceSetId for a viewport!");
1200 sequenceSetID = new String(newid);
1204 public String getSequenceSetId()
1206 if (sequenceSetID == null)
1208 sequenceSetID = alignment.hashCode() + "";
1211 return sequenceSetID;
1215 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1218 protected String viewId = null;
1221 public String getViewId()
1225 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1230 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1232 ignoreGapsInConsensusCalculation = b;
1235 updateConsensus(ap);
1236 if (residueShading != null)
1238 residueShading.setThreshold(residueShading.getThreshold(),
1239 ignoreGapsInConsensusCalculation);
1245 private long sgrouphash = -1, colselhash = -1;
1248 * checks current SelectionGroup against record of last hash value, and
1252 * update the record of last hash value
1254 * @return true if SelectionGroup changed since last call (when b is true)
1256 public boolean isSelectionGroupChanged(boolean b)
1258 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1259 : selectionGroup.hashCode();
1260 if (hc != -1 && hc != sgrouphash)
1272 * checks current colsel against record of last hash value, and optionally
1276 * update the record of last hash value
1277 * @return true if colsel changed since last call (when b is true)
1279 public boolean isColSelChanged(boolean b)
1281 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1282 if (hc != -1 && hc != colselhash)
1294 public boolean isIgnoreGapsConsensus()
1296 return ignoreGapsInConsensusCalculation;
1299 // property change stuff
1300 // JBPNote Prolly only need this in the applet version.
1301 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1304 protected boolean showConservation = true;
1306 protected boolean showQuality = true;
1308 protected boolean showConsensus = true;
1310 protected boolean showOccupancy = true;
1312 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1314 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1316 protected boolean showAutocalculatedAbove;
1319 * when set, view will scroll to show the highlighted position
1321 private boolean followHighlight = true;
1324 * Property change listener for changes in alignment
1329 public void addPropertyChangeListener(
1330 java.beans.PropertyChangeListener listener)
1332 changeSupport.addPropertyChangeListener(listener);
1341 public void removePropertyChangeListener(
1342 java.beans.PropertyChangeListener listener)
1344 if (changeSupport != null)
1346 changeSupport.removePropertyChangeListener(listener);
1351 * Property change listener for changes in alignment
1360 public void firePropertyChange(String prop, Object oldvalue,
1363 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1366 // common hide/show column stuff
1368 public void hideSelectedColumns()
1370 if (colSel.isEmpty())
1375 colSel.hideSelectedColumns(alignment);
1376 setSelectionGroup(null);
1377 isColSelChanged(true);
1380 public void hideColumns(int start, int end)
1384 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1388 alignment.getHiddenColumns().hideColumns(start, end);
1390 isColSelChanged(true);
1393 public void showColumn(int col)
1395 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1396 isColSelChanged(true);
1399 public void showAllHiddenColumns()
1401 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1402 isColSelChanged(true);
1405 // common hide/show seq stuff
1406 public void showAllHiddenSeqs()
1408 int startSeq = ranges.getStartSeq();
1409 int endSeq = ranges.getEndSeq();
1411 if (alignment.getHiddenSequences().getSize() > 0)
1413 if (selectionGroup == null)
1415 selectionGroup = new SequenceGroup();
1416 selectionGroup.setEndRes(alignment.getWidth() - 1);
1418 List<SequenceI> tmp = alignment.getHiddenSequences()
1419 .showAll(hiddenRepSequences);
1420 for (SequenceI seq : tmp)
1422 selectionGroup.addSequence(seq, false);
1423 setSequenceAnnotationsVisible(seq, true);
1426 hiddenRepSequences = null;
1428 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1430 firePropertyChange("alignment", null, alignment.getSequences());
1431 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1437 public void showSequence(int index)
1439 int startSeq = ranges.getStartSeq();
1440 int endSeq = ranges.getEndSeq();
1442 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1443 hiddenRepSequences);
1446 if (selectionGroup == null)
1448 selectionGroup = new SequenceGroup();
1449 selectionGroup.setEndRes(alignment.getWidth() - 1);
1452 for (SequenceI seq : tmp)
1454 selectionGroup.addSequence(seq, false);
1455 setSequenceAnnotationsVisible(seq, true);
1458 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1460 firePropertyChange("alignment", null, alignment.getSequences());
1465 public void hideAllSelectedSeqs()
1467 if (selectionGroup == null || selectionGroup.getSize() < 1)
1472 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1476 setSelectionGroup(null);
1479 public void hideSequence(SequenceI[] seq)
1482 * cache offset to first visible sequence
1484 int startSeq = ranges.getStartSeq();
1488 for (int i = 0; i < seq.length; i++)
1490 alignment.getHiddenSequences().hideSequence(seq[i]);
1491 setSequenceAnnotationsVisible(seq[i], false);
1493 ranges.setStartSeq(startSeq);
1494 firePropertyChange("alignment", null, alignment.getSequences());
1499 * Hides the specified sequence, or the sequences it represents
1502 * the sequence to hide, or keep as representative
1503 * @param representGroup
1504 * if true, hide the current selection group except for the
1505 * representative sequence
1507 public void hideSequences(SequenceI sequence, boolean representGroup)
1509 if (selectionGroup == null || selectionGroup.getSize() < 1)
1511 hideSequence(new SequenceI[] { sequence });
1517 hideRepSequences(sequence, selectionGroup);
1518 setSelectionGroup(null);
1522 int gsize = selectionGroup.getSize();
1523 SequenceI[] hseqs = selectionGroup.getSequences()
1524 .toArray(new SequenceI[gsize]);
1526 hideSequence(hseqs);
1527 setSelectionGroup(null);
1532 * Set visibility for any annotations for the given sequence.
1536 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1539 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1542 for (AlignmentAnnotation ann : anns)
1544 if (ann.sequenceRef == sequenceI)
1546 ann.visible = visible;
1552 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1554 int sSize = sg.getSize();
1560 if (hiddenRepSequences == null)
1562 hiddenRepSequences = new Hashtable<>();
1565 hiddenRepSequences.put(repSequence, sg);
1567 // Hide all sequences except the repSequence
1568 SequenceI[] seqs = new SequenceI[sSize - 1];
1570 for (int i = 0; i < sSize; i++)
1572 if (sg.getSequenceAt(i) != repSequence)
1574 if (index == sSize - 1)
1579 seqs[index++] = sg.getSequenceAt(i);
1582 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1583 sg.setHidereps(true); // note: not done in 2.7applet
1590 * @return null or the current reference sequence
1592 public SequenceI getReferenceSeq()
1594 return alignment.getSeqrep();
1599 * @return true iff seq is the reference for the alignment
1601 public boolean isReferenceSeq(SequenceI seq)
1603 return alignment.getSeqrep() == seq;
1609 * @return true if there are sequences represented by this sequence that are
1612 public boolean isHiddenRepSequence(SequenceI seq)
1614 return (hiddenRepSequences != null
1615 && hiddenRepSequences.containsKey(seq));
1621 * @return null or a sequence group containing the sequences that seq
1624 public SequenceGroup getRepresentedSequences(SequenceI seq)
1626 return (SequenceGroup) (hiddenRepSequences == null ? null
1627 : hiddenRepSequences.get(seq));
1631 public int adjustForHiddenSeqs(int alignmentIndex)
1633 return alignment.getHiddenSequences()
1634 .adjustForHiddenSeqs(alignmentIndex);
1638 public void invertColumnSelection()
1640 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1641 isColSelChanged(true);
1645 public SequenceI[] getSelectionAsNewSequence()
1647 SequenceI[] sequences;
1648 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1649 // this was the only caller in the applet for this method
1650 // JBPNote: in applet, this method returned references to the alignment
1651 // sequences, and it did not honour the presence/absence of annotation
1652 // attached to the alignment (probably!)
1653 if (selectionGroup == null || selectionGroup.getSize() == 0)
1655 sequences = alignment.getSequencesArray();
1656 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1657 for (int i = 0; i < sequences.length; i++)
1659 // construct new sequence with subset of visible annotation
1660 sequences[i] = new Sequence(sequences[i], annots);
1665 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1672 public SequenceI[] getSequenceSelection()
1674 SequenceI[] sequences = null;
1675 if (selectionGroup != null)
1677 sequences = selectionGroup.getSequencesInOrder(alignment);
1679 if (sequences == null)
1681 sequences = alignment.getSequencesArray();
1687 public jalview.datamodel.AlignmentView getAlignmentView(
1688 boolean selectedOnly)
1690 return getAlignmentView(selectedOnly, false);
1694 public jalview.datamodel.AlignmentView getAlignmentView(
1695 boolean selectedOnly, boolean markGroups)
1697 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1699 alignment.getHiddenColumns() != null
1700 && alignment.getHiddenColumns().hasHiddenColumns(),
1701 selectedOnly, markGroups);
1705 public String[] getViewAsString(boolean selectedRegionOnly)
1707 return getViewAsString(selectedRegionOnly, true);
1711 public String[] getViewAsString(boolean selectedRegionOnly,
1712 boolean exportHiddenSeqs)
1714 String[] selection = null;
1715 SequenceI[] seqs = null;
1717 int start = 0, end = 0;
1718 if (selectedRegionOnly && selectionGroup != null)
1720 iSize = selectionGroup.getSize();
1721 seqs = selectionGroup.getSequencesInOrder(alignment);
1722 start = selectionGroup.getStartRes();
1723 end = selectionGroup.getEndRes() + 1;
1727 if (hasHiddenRows() && exportHiddenSeqs)
1729 AlignmentI fullAlignment = alignment.getHiddenSequences()
1730 .getFullAlignment();
1731 iSize = fullAlignment.getHeight();
1732 seqs = fullAlignment.getSequencesArray();
1733 end = fullAlignment.getWidth();
1737 iSize = alignment.getHeight();
1738 seqs = alignment.getSequencesArray();
1739 end = alignment.getWidth();
1743 selection = new String[iSize];
1744 if (alignment.getHiddenColumns() != null
1745 && alignment.getHiddenColumns().hasHiddenColumns())
1747 for (i = 0; i < iSize; i++)
1749 Iterator<int[]> blocks = alignment.getHiddenColumns()
1750 .getVisContigsIterator(start, end + 1, false);
1751 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1756 for (i = 0; i < iSize; i++)
1758 selection[i] = seqs[i].getSequenceAsString(start, end);
1766 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1768 ArrayList<int[]> regions = new ArrayList<>();
1774 HiddenColumns hidden = alignment.getHiddenColumns();
1775 if (hidden != null && hidden.hasHiddenColumns())
1779 start = hidden.visibleToAbsoluteColumn(start);
1782 end = hidden.getNextHiddenBoundary(false, start);
1793 regions.add(new int[] { start, end });
1795 if (hidden != null && hidden.hasHiddenColumns())
1797 start = hidden.visibleToAbsoluteColumn(end);
1798 start = hidden.getNextHiddenBoundary(true, start) + 1;
1800 } while (end < max);
1802 int[][] startEnd = new int[regions.size()][2];
1808 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1809 boolean selectedOnly)
1811 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1812 AlignmentAnnotation[] aa;
1813 if ((aa = alignment.getAlignmentAnnotation()) != null)
1815 for (AlignmentAnnotation annot : aa)
1817 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1818 if (selectedOnly && selectionGroup != null)
1820 clone.makeVisibleAnnotation(
1821 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1822 alignment.getHiddenColumns());
1826 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1835 public boolean isPadGaps()
1841 public void setPadGaps(boolean padGaps)
1843 this.padGaps = padGaps;
1847 * apply any post-edit constraints and trigger any calculations needed after
1848 * an edit has been performed on the alignment
1853 public void alignmentChanged(AlignmentViewPanel ap)
1857 alignment.padGaps();
1859 if (autoCalculateConsensus)
1861 updateConsensus(ap);
1863 if (hconsensus != null && autoCalculateConsensus)
1865 updateConservation(ap);
1867 if (autoCalculateStrucConsensus)
1869 updateStrucConsensus(ap);
1872 // Reset endRes of groups if beyond alignment width
1873 int alWidth = alignment.getWidth();
1874 List<SequenceGroup> groups = alignment.getGroups();
1877 for (SequenceGroup sg : groups)
1879 if (sg.getEndRes() > alWidth)
1881 sg.setEndRes(alWidth - 1);
1886 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1888 selectionGroup.setEndRes(alWidth - 1);
1891 updateAllColourSchemes();
1892 calculator.restartWorkers();
1893 // alignment.adjustSequenceAnnotations();
1897 * reset scope and do calculations for all applied colourschemes on alignment
1899 void updateAllColourSchemes()
1901 ResidueShaderI rs = residueShading;
1904 rs.alignmentChanged(alignment, hiddenRepSequences);
1906 rs.setConsensus(hconsensus);
1907 if (rs.conservationApplied())
1909 rs.setConservation(Conservation.calculateConservation("All",
1910 alignment.getSequences(), 0, alignment.getWidth(), false,
1911 getConsPercGaps(), false));
1915 for (SequenceGroup sg : alignment.getGroups())
1919 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1921 sg.recalcConservation();
1925 protected void initAutoAnnotation()
1927 // TODO: add menu option action that nulls or creates consensus object
1928 // depending on if the user wants to see the annotation or not in a
1929 // specific alignment
1931 if (hconsensus == null && !isDataset)
1933 if (!alignment.isNucleotide())
1942 consensus = new AlignmentAnnotation("Consensus",
1943 MessageManager.getString("label.consensus_descr"),
1944 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1945 initConsensus(consensus);
1948 initComplementConsensus();
1953 * If this is a protein alignment and there are mappings to cDNA, adds the
1954 * cDNA consensus annotation and returns true, else returns false.
1956 public boolean initComplementConsensus()
1958 if (!alignment.isNucleotide())
1960 final List<AlignedCodonFrame> codonMappings = alignment
1962 if (codonMappings != null && !codonMappings.isEmpty())
1964 boolean doConsensus = false;
1965 for (AlignedCodonFrame mapping : codonMappings)
1967 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1968 MapList[] mapLists = mapping.getdnaToProt();
1969 // mapLists can be empty if project load has not finished resolving
1971 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1979 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1981 .getString("label.complement_consensus_descr"),
1982 new Annotation[1], 0f, 100f,
1983 AlignmentAnnotation.BAR_GRAPH);
1984 initConsensus(complementConsensus);
1992 private void initConsensus(AlignmentAnnotation aa)
1995 aa.autoCalculated = true;
1999 alignment.addAnnotation(aa);
2003 // these should be extracted from the view model - style and settings for
2004 // derived annotation
2005 private void initGapCounts()
2009 gapcounts = new AlignmentAnnotation("Occupancy",
2010 MessageManager.getString("label.occupancy_descr"),
2011 new Annotation[1], 0f, alignment.getHeight(),
2012 AlignmentAnnotation.BAR_GRAPH);
2013 gapcounts.hasText = true;
2014 gapcounts.autoCalculated = true;
2015 gapcounts.scaleColLabel = true;
2016 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2018 alignment.addAnnotation(gapcounts);
2022 private void initConservation()
2024 if (showConservation)
2026 if (conservation == null)
2028 conservation = new AlignmentAnnotation("Conservation",
2029 MessageManager.formatMessage("label.conservation_descr",
2031 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2032 conservation.hasText = true;
2033 conservation.autoCalculated = true;
2034 alignment.addAnnotation(conservation);
2039 private void initQuality()
2043 if (quality == null)
2045 quality = new AlignmentAnnotation("Quality",
2046 MessageManager.getString("label.quality_descr"),
2047 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2048 quality.hasText = true;
2049 quality.autoCalculated = true;
2050 alignment.addAnnotation(quality);
2055 private void initRNAStructure()
2057 if (alignment.hasRNAStructure() && strucConsensus == null)
2059 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2060 MessageManager.getString("label.strucconsensus_descr"),
2061 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2062 strucConsensus.hasText = true;
2063 strucConsensus.autoCalculated = true;
2067 alignment.addAnnotation(strucConsensus);
2075 * @see jalview.api.AlignViewportI#calcPanelHeight()
2078 public int calcPanelHeight()
2080 // setHeight of panels
2081 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2083 int charHeight = getCharHeight();
2086 BitSet graphgrp = new BitSet();
2087 for (AlignmentAnnotation aa : anns)
2091 System.err.println("Null annotation row: ignoring.");
2098 if (aa.graphGroup > -1)
2100 if (graphgrp.get(aa.graphGroup))
2106 graphgrp.set(aa.graphGroup);
2113 aa.height += charHeight;
2123 aa.height += aa.graphHeight;
2131 height += aa.height;
2143 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2144 boolean preserveNewGroupSettings)
2146 boolean updateCalcs = false;
2147 boolean conv = isShowGroupConservation();
2148 boolean cons = isShowGroupConsensus();
2149 boolean showprf = isShowSequenceLogo();
2150 boolean showConsHist = isShowConsensusHistogram();
2151 boolean normLogo = isNormaliseSequenceLogo();
2154 * TODO reorder the annotation rows according to group/sequence ordering on
2157 boolean sortg = true;
2159 // remove old automatic annotation
2160 // add any new annotation
2162 // intersect alignment annotation with alignment groups
2164 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2165 List<SequenceGroup> oldrfs = new ArrayList<>();
2168 for (int an = 0; an < aan.length; an++)
2170 if (aan[an].autoCalculated && aan[an].groupRef != null)
2172 oldrfs.add(aan[an].groupRef);
2173 alignment.deleteAnnotation(aan[an], false);
2177 if (alignment.getGroups() != null)
2179 for (SequenceGroup sg : alignment.getGroups())
2181 updateCalcs = false;
2182 if (applyGlobalSettings
2183 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2185 // set defaults for this group's conservation/consensus
2186 sg.setshowSequenceLogo(showprf);
2187 sg.setShowConsensusHistogram(showConsHist);
2188 sg.setNormaliseSequenceLogo(normLogo);
2193 alignment.addAnnotation(sg.getConservationRow(), 0);
2198 alignment.addAnnotation(sg.getConsensus(), 0);
2200 // refresh the annotation rows
2203 sg.recalcConservation();
2211 public boolean isDisplayReferenceSeq()
2213 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2217 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2219 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2223 public boolean isColourByReferenceSeq()
2225 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2229 public Color getSequenceColour(SequenceI seq)
2231 Color sqc = sequenceColours.get(seq);
2232 return (sqc == null ? Color.white : sqc);
2236 public void setSequenceColour(SequenceI seq, Color col)
2240 sequenceColours.remove(seq);
2244 sequenceColours.put(seq, col);
2249 public void updateSequenceIdColours()
2251 for (SequenceGroup sg : alignment.getGroups())
2253 if (sg.idColour != null)
2255 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2257 sequenceColours.put(s, sg.idColour);
2264 public void clearSequenceColours()
2266 sequenceColours.clear();
2270 public AlignViewportI getCodingComplement()
2272 return this.codingComplement;
2276 * Set this as the (cDna/protein) complement of the given viewport. Also
2277 * ensures the reverse relationship is set on the given viewport.
2280 public void setCodingComplement(AlignViewportI av)
2284 System.err.println("Ignoring recursive setCodingComplement request");
2288 this.codingComplement = av;
2289 // avoid infinite recursion!
2290 if (av.getCodingComplement() != this)
2292 av.setCodingComplement(this);
2298 public boolean isNucleotide()
2300 return getAlignment() == null ? false : getAlignment().isNucleotide();
2304 public FeaturesDisplayedI getFeaturesDisplayed()
2306 return featuresDisplayed;
2310 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2312 featuresDisplayed = featuresDisplayedI;
2316 public boolean areFeaturesDisplayed()
2318 return featuresDisplayed != null
2319 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2326 * features are displayed if true
2329 public void setShowSequenceFeatures(boolean b)
2331 viewStyle.setShowSequenceFeatures(b);
2335 public boolean isShowSequenceFeatures()
2337 return viewStyle.isShowSequenceFeatures();
2341 public void setShowSequenceFeaturesHeight(boolean selected)
2343 viewStyle.setShowSequenceFeaturesHeight(selected);
2347 public boolean isShowSequenceFeaturesHeight()
2349 return viewStyle.isShowSequenceFeaturesHeight();
2353 public void setShowAnnotation(boolean b)
2355 viewStyle.setShowAnnotation(b);
2359 public boolean isShowAnnotation()
2361 return viewStyle.isShowAnnotation();
2365 public boolean isRightAlignIds()
2367 return viewStyle.isRightAlignIds();
2371 public void setRightAlignIds(boolean rightAlignIds)
2373 viewStyle.setRightAlignIds(rightAlignIds);
2377 public boolean getConservationSelected()
2379 return viewStyle.getConservationSelected();
2383 public void setShowBoxes(boolean state)
2385 viewStyle.setShowBoxes(state);
2390 * @see jalview.api.ViewStyleI#getTextColour()
2393 public Color getTextColour()
2395 return viewStyle.getTextColour();
2400 * @see jalview.api.ViewStyleI#getTextColour2()
2403 public Color getTextColour2()
2405 return viewStyle.getTextColour2();
2410 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2413 public int getThresholdTextColour()
2415 return viewStyle.getThresholdTextColour();
2420 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2423 public boolean isConservationColourSelected()
2425 return viewStyle.isConservationColourSelected();
2430 * @see jalview.api.ViewStyleI#isRenderGaps()
2433 public boolean isRenderGaps()
2435 return viewStyle.isRenderGaps();
2440 * @see jalview.api.ViewStyleI#isShowColourText()
2443 public boolean isShowColourText()
2445 return viewStyle.isShowColourText();
2449 * @param conservationColourSelected
2450 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2453 public void setConservationColourSelected(
2454 boolean conservationColourSelected)
2456 viewStyle.setConservationColourSelected(conservationColourSelected);
2460 * @param showColourText
2461 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2464 public void setShowColourText(boolean showColourText)
2466 viewStyle.setShowColourText(showColourText);
2471 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2474 public void setTextColour(Color textColour)
2476 viewStyle.setTextColour(textColour);
2480 * @param thresholdTextColour
2481 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2484 public void setThresholdTextColour(int thresholdTextColour)
2486 viewStyle.setThresholdTextColour(thresholdTextColour);
2490 * @param textColour2
2491 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2494 public void setTextColour2(Color textColour2)
2496 viewStyle.setTextColour2(textColour2);
2500 public ViewStyleI getViewStyle()
2502 return new ViewStyle(viewStyle);
2506 public void setViewStyle(ViewStyleI settingsForView)
2508 viewStyle = new ViewStyle(settingsForView);
2509 if (residueShading != null)
2511 residueShading.setConservationApplied(
2512 settingsForView.isConservationColourSelected());
2517 public boolean sameStyle(ViewStyleI them)
2519 return viewStyle.sameStyle(them);
2524 * @see jalview.api.ViewStyleI#getIdWidth()
2527 public int getIdWidth()
2529 return viewStyle.getIdWidth();
2534 * @see jalview.api.ViewStyleI#setIdWidth(int)
2537 public void setIdWidth(int i)
2539 viewStyle.setIdWidth(i);
2544 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2547 public boolean isCentreColumnLabels()
2549 return viewStyle.isCentreColumnLabels();
2553 * @param centreColumnLabels
2554 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2557 public void setCentreColumnLabels(boolean centreColumnLabels)
2559 viewStyle.setCentreColumnLabels(centreColumnLabels);
2564 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2567 public void setShowDBRefs(boolean showdbrefs)
2569 viewStyle.setShowDBRefs(showdbrefs);
2574 * @see jalview.api.ViewStyleI#isShowDBRefs()
2577 public boolean isShowDBRefs()
2579 return viewStyle.isShowDBRefs();
2584 * @see jalview.api.ViewStyleI#isShowNPFeats()
2587 public boolean isShowNPFeats()
2589 return viewStyle.isShowNPFeats();
2593 * @param shownpfeats
2594 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2597 public void setShowNPFeats(boolean shownpfeats)
2599 viewStyle.setShowNPFeats(shownpfeats);
2602 public abstract StructureSelectionManager getStructureSelectionManager();
2605 * Add one command to the command history list.
2609 public void addToHistoryList(CommandI command)
2611 if (this.historyList != null)
2613 this.historyList.push(command);
2614 broadcastCommand(command, false);
2618 protected void broadcastCommand(CommandI command, boolean undo)
2620 getStructureSelectionManager().commandPerformed(command, undo,
2625 * Add one command to the command redo list.
2629 public void addToRedoList(CommandI command)
2631 if (this.redoList != null)
2633 this.redoList.push(command);
2635 broadcastCommand(command, true);
2639 * Clear the command redo list.
2641 public void clearRedoList()
2643 if (this.redoList != null)
2645 this.redoList.clear();
2649 public void setHistoryList(Deque<CommandI> list)
2651 this.historyList = list;
2654 public Deque<CommandI> getHistoryList()
2656 return this.historyList;
2659 public void setRedoList(Deque<CommandI> list)
2661 this.redoList = list;
2664 public Deque<CommandI> getRedoList()
2666 return this.redoList;
2670 public VamsasSource getVamsasSource()
2675 public SequenceAnnotationOrder getSortAnnotationsBy()
2677 return sortAnnotationsBy;
2680 public void setSortAnnotationsBy(
2681 SequenceAnnotationOrder sortAnnotationsBy)
2683 this.sortAnnotationsBy = sortAnnotationsBy;
2686 public boolean isShowAutocalculatedAbove()
2688 return showAutocalculatedAbove;
2691 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2693 this.showAutocalculatedAbove = showAutocalculatedAbove;
2697 public boolean isScaleProteinAsCdna()
2699 return viewStyle.isScaleProteinAsCdna();
2703 public void setScaleProteinAsCdna(boolean b)
2705 viewStyle.setScaleProteinAsCdna(b);
2709 public boolean isProteinFontAsCdna()
2711 return viewStyle.isProteinFontAsCdna();
2715 public void setProteinFontAsCdna(boolean b)
2717 viewStyle.setProteinFontAsCdna(b);
2721 public void setShowComplementFeatures(boolean b)
2723 viewStyle.setShowComplementFeatures(b);
2727 public boolean isShowComplementFeatures()
2729 return viewStyle.isShowComplementFeatures();
2733 public void setShowComplementFeaturesOnTop(boolean b)
2735 viewStyle.setShowComplementFeaturesOnTop(b);
2739 public boolean isShowComplementFeaturesOnTop()
2741 return viewStyle.isShowComplementFeaturesOnTop();
2745 * @return true if view should scroll to show the highlighted region of a
2750 public final boolean isFollowHighlight()
2752 return followHighlight;
2756 public final void setFollowHighlight(boolean b)
2758 this.followHighlight = b;
2762 public ViewportRanges getRanges()
2768 * Helper method to populate the SearchResults with the location in the
2769 * complementary alignment to scroll to, in order to match this one.
2772 * the SearchResults to add to
2773 * @return the offset (below top of visible region) of the matched sequence
2775 protected int findComplementScrollTarget(SearchResultsI sr)
2777 final AlignViewportI complement = getCodingComplement();
2778 if (complement == null || !complement.isFollowHighlight())
2782 boolean iAmProtein = !getAlignment().isNucleotide();
2783 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2784 : complement.getAlignment();
2785 if (proteinAlignment == null)
2789 final List<AlignedCodonFrame> mappings = proteinAlignment
2793 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2794 * residue in the middle column of the visible region. Scroll the
2795 * complementary alignment to line up the corresponding residue.
2798 SequenceI sequence = null;
2801 * locate 'middle' column (true middle if an odd number visible, left of
2802 * middle if an even number visible)
2804 int middleColumn = ranges.getStartRes()
2805 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2806 final HiddenSequences hiddenSequences = getAlignment()
2807 .getHiddenSequences();
2810 * searching to the bottom of the alignment gives smoother scrolling across
2811 * all gapped visible regions
2813 int lastSeq = alignment.getHeight() - 1;
2814 List<AlignedCodonFrame> seqMappings = null;
2815 for (int seqNo = ranges
2816 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2818 sequence = getAlignment().getSequenceAt(seqNo);
2819 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2823 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2827 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2829 getCodingComplement().getAlignment().getSequences());
2830 if (!seqMappings.isEmpty())
2836 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2839 * No ungapped mapped sequence in middle column - do nothing
2843 MappingUtils.addSearchResults(sr, sequence,
2844 sequence.findPosition(middleColumn), seqMappings);
2849 * synthesize a column selection if none exists so it covers the given
2850 * selection group. if wholewidth is false, no column selection is made if the
2851 * selection group covers the whole alignment width.
2856 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2859 if (sg != null && (sgs = sg.getStartRes()) >= 0
2860 && sg.getStartRes() <= (sge = sg.getEndRes())
2861 && !this.hasSelectedColumns())
2863 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2870 colSel = new ColumnSelection();
2872 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2874 colSel.addElement(cspos);
2880 * hold status of current selection group - defined on alignment or not.
2882 private boolean selectionIsDefinedGroup = false;
2885 public boolean isSelectionDefinedGroup()
2887 if (selectionGroup == null)
2891 if (isSelectionGroupChanged(true))
2893 selectionIsDefinedGroup = false;
2894 List<SequenceGroup> gps = alignment.getGroups();
2895 if (gps == null || gps.size() == 0)
2897 selectionIsDefinedGroup = false;
2901 selectionIsDefinedGroup = gps.contains(selectionGroup);
2904 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2908 * null, or currently highlighted results on this view
2910 private SearchResultsI searchResults = null;
2912 protected TreeModel currentTree = null;
2915 public boolean hasSearchResults()
2917 return searchResults != null;
2921 public void setSearchResults(SearchResultsI results)
2923 searchResults = results;
2927 public SearchResultsI getSearchResults()
2929 return searchResults;
2933 * get the consensus sequence as displayed under the PID consensus annotation
2936 * @return consensus sequence as a new sequence object
2938 public SequenceI getConsensusSeq()
2940 if (consensus == null)
2942 updateConsensus(null);
2944 if (consensus == null)
2948 StringBuffer seqs = new StringBuffer();
2949 for (int i = 0; i < consensus.annotations.length; i++)
2951 Annotation annotation = consensus.annotations[i];
2952 if (annotation != null)
2954 String description = annotation.description;
2955 if (description != null && description.startsWith("["))
2957 // consensus is a tie - just pick the first one
2958 seqs.append(description.charAt(1));
2962 seqs.append(annotation.displayCharacter);
2967 SequenceI sq = new Sequence("Consensus", seqs.toString());
2968 sq.setDescription("Percentage Identity Consensus "
2969 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2974 public void setCurrentTree(TreeModel tree)
2980 public TreeModel getCurrentTree()
2986 * flag set to indicate if structure views might be out of sync with sequences
2990 private boolean needToUpdateStructureViews = false;
2993 public boolean isUpdateStructures()
2995 return needToUpdateStructureViews;
2999 public void setUpdateStructures(boolean update)
3001 needToUpdateStructureViews = update;
3005 public boolean needToUpdateStructureViews()
3007 boolean update = needToUpdateStructureViews;
3008 needToUpdateStructureViews = false;
3013 public void addSequenceGroup(SequenceGroup sequenceGroup)
3015 alignment.addGroup(sequenceGroup);
3017 Color col = sequenceGroup.idColour;
3020 col = col.brighter();
3022 for (SequenceI sq : sequenceGroup.getSequences())
3024 setSequenceColour(sq, col);
3028 if (codingComplement != null)
3030 SequenceGroup mappedGroup = MappingUtils
3031 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3032 if (mappedGroup.getSequences().size() > 0)
3034 codingComplement.getAlignment().addGroup(mappedGroup);
3038 for (SequenceI seq : mappedGroup.getSequences())
3040 codingComplement.setSequenceColour(seq, col);
3044 // propagate the structure view update flag according to our own setting
3045 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3050 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3054 if (selectedRegionOnly && selectionGroup != null)
3056 start = selectionGroup.getStartRes();
3057 end = selectionGroup.getEndRes() + 1;
3061 end = alignment.getWidth();
3063 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,