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 getAlignmentViewWithComplement(selectedOnly,markGroups,true);
1701 public jalview.datamodel.AlignmentView getAlignmentViewWithComplement(
1702 boolean selectedOnly, boolean markGroups,boolean withComplment)
1704 AlignmentView complementView = null;
1707 if (codingComplement != null)
1709 complementView = codingComplement.getAlignmentViewWithComplement(
1710 selectedOnly, markGroups, false);
1713 AlignmentView thisView = new AlignmentView(alignment,
1714 alignment.getHiddenColumns(), selectionGroup,
1715 alignment.getHiddenColumns() != null
1716 && alignment.getHiddenColumns().hasHiddenColumns(),
1717 selectedOnly, markGroups);
1718 thisView.setComplement(complementView);
1723 public String[] getViewAsString(boolean selectedRegionOnly)
1725 return getViewAsString(selectedRegionOnly, true);
1729 public String[] getViewAsString(boolean selectedRegionOnly,
1730 boolean exportHiddenSeqs)
1732 String[] selection = null;
1733 SequenceI[] seqs = null;
1735 int start = 0, end = 0;
1736 if (selectedRegionOnly && selectionGroup != null)
1738 iSize = selectionGroup.getSize();
1739 seqs = selectionGroup.getSequencesInOrder(alignment);
1740 start = selectionGroup.getStartRes();
1741 end = selectionGroup.getEndRes() + 1;
1745 if (hasHiddenRows() && exportHiddenSeqs)
1747 AlignmentI fullAlignment = alignment.getHiddenSequences()
1748 .getFullAlignment();
1749 iSize = fullAlignment.getHeight();
1750 seqs = fullAlignment.getSequencesArray();
1751 end = fullAlignment.getWidth();
1755 iSize = alignment.getHeight();
1756 seqs = alignment.getSequencesArray();
1757 end = alignment.getWidth();
1761 selection = new String[iSize];
1762 if (alignment.getHiddenColumns() != null
1763 && alignment.getHiddenColumns().hasHiddenColumns())
1765 for (i = 0; i < iSize; i++)
1767 Iterator<int[]> blocks = alignment.getHiddenColumns()
1768 .getVisContigsIterator(start, end + 1, false);
1769 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1774 for (i = 0; i < iSize; i++)
1776 selection[i] = seqs[i].getSequenceAsString(start, end);
1784 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1786 ArrayList<int[]> regions = new ArrayList<>();
1792 HiddenColumns hidden = alignment.getHiddenColumns();
1793 if (hidden != null && hidden.hasHiddenColumns())
1797 start = hidden.visibleToAbsoluteColumn(start);
1800 end = hidden.getNextHiddenBoundary(false, start);
1811 regions.add(new int[] { start, end });
1813 if (hidden != null && hidden.hasHiddenColumns())
1815 start = hidden.visibleToAbsoluteColumn(end);
1816 start = hidden.getNextHiddenBoundary(true, start) + 1;
1818 } while (end < max);
1820 int[][] startEnd = new int[regions.size()][2];
1826 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1827 boolean selectedOnly)
1829 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1830 AlignmentAnnotation[] aa;
1831 if ((aa = alignment.getAlignmentAnnotation()) != null)
1833 for (AlignmentAnnotation annot : aa)
1835 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1836 if (selectedOnly && selectionGroup != null)
1838 clone.makeVisibleAnnotation(
1839 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1840 alignment.getHiddenColumns());
1844 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1853 public boolean isPadGaps()
1859 public void setPadGaps(boolean padGaps)
1861 this.padGaps = padGaps;
1865 * apply any post-edit constraints and trigger any calculations needed after
1866 * an edit has been performed on the alignment
1871 public void alignmentChanged(AlignmentViewPanel ap)
1875 alignment.padGaps();
1877 if (autoCalculateConsensus)
1879 updateConsensus(ap);
1881 if (hconsensus != null && autoCalculateConsensus)
1883 updateConservation(ap);
1885 if (autoCalculateStrucConsensus)
1887 updateStrucConsensus(ap);
1890 // Reset endRes of groups if beyond alignment width
1891 int alWidth = alignment.getWidth();
1892 List<SequenceGroup> groups = alignment.getGroups();
1895 for (SequenceGroup sg : groups)
1897 if (sg.getEndRes() > alWidth)
1899 sg.setEndRes(alWidth - 1);
1904 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1906 selectionGroup.setEndRes(alWidth - 1);
1909 updateAllColourSchemes();
1910 calculator.restartWorkers();
1911 // alignment.adjustSequenceAnnotations();
1915 * reset scope and do calculations for all applied colourschemes on alignment
1917 void updateAllColourSchemes()
1919 ResidueShaderI rs = residueShading;
1922 rs.alignmentChanged(alignment, hiddenRepSequences);
1924 rs.setConsensus(hconsensus);
1925 if (rs.conservationApplied())
1927 rs.setConservation(Conservation.calculateConservation("All",
1928 alignment.getSequences(), 0, alignment.getWidth(), false,
1929 getConsPercGaps(), false));
1933 for (SequenceGroup sg : alignment.getGroups())
1937 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1939 sg.recalcConservation();
1943 protected void initAutoAnnotation()
1945 // TODO: add menu option action that nulls or creates consensus object
1946 // depending on if the user wants to see the annotation or not in a
1947 // specific alignment
1949 if (hconsensus == null && !isDataset)
1951 if (!alignment.isNucleotide())
1960 consensus = new AlignmentAnnotation("Consensus",
1961 MessageManager.getString("label.consensus_descr"),
1962 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1963 initConsensus(consensus);
1966 initComplementConsensus();
1971 * If this is a protein alignment and there are mappings to cDNA, adds the
1972 * cDNA consensus annotation and returns true, else returns false.
1974 public boolean initComplementConsensus()
1976 if (!alignment.isNucleotide())
1978 final List<AlignedCodonFrame> codonMappings = alignment
1980 if (codonMappings != null && !codonMappings.isEmpty())
1982 boolean doConsensus = false;
1983 for (AlignedCodonFrame mapping : codonMappings)
1985 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1986 MapList[] mapLists = mapping.getdnaToProt();
1987 // mapLists can be empty if project load has not finished resolving
1989 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1997 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1999 .getString("label.complement_consensus_descr"),
2000 new Annotation[1], 0f, 100f,
2001 AlignmentAnnotation.BAR_GRAPH);
2002 initConsensus(complementConsensus);
2010 private void initConsensus(AlignmentAnnotation aa)
2013 aa.autoCalculated = true;
2017 alignment.addAnnotation(aa);
2021 // these should be extracted from the view model - style and settings for
2022 // derived annotation
2023 private void initGapCounts()
2027 gapcounts = new AlignmentAnnotation("Occupancy",
2028 MessageManager.getString("label.occupancy_descr"),
2029 new Annotation[1], 0f, alignment.getHeight(),
2030 AlignmentAnnotation.BAR_GRAPH);
2031 gapcounts.hasText = true;
2032 gapcounts.autoCalculated = true;
2033 gapcounts.scaleColLabel = true;
2034 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2036 alignment.addAnnotation(gapcounts);
2040 private void initConservation()
2042 if (showConservation)
2044 if (conservation == null)
2046 conservation = new AlignmentAnnotation("Conservation",
2047 MessageManager.formatMessage("label.conservation_descr",
2049 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2050 conservation.hasText = true;
2051 conservation.autoCalculated = true;
2052 alignment.addAnnotation(conservation);
2057 private void initQuality()
2061 if (quality == null)
2063 quality = new AlignmentAnnotation("Quality",
2064 MessageManager.getString("label.quality_descr"),
2065 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2066 quality.hasText = true;
2067 quality.autoCalculated = true;
2068 alignment.addAnnotation(quality);
2073 private void initRNAStructure()
2075 if (alignment.hasRNAStructure() && strucConsensus == null)
2077 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2078 MessageManager.getString("label.strucconsensus_descr"),
2079 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2080 strucConsensus.hasText = true;
2081 strucConsensus.autoCalculated = true;
2085 alignment.addAnnotation(strucConsensus);
2093 * @see jalview.api.AlignViewportI#calcPanelHeight()
2096 public int calcPanelHeight()
2098 // setHeight of panels
2099 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2101 int charHeight = getCharHeight();
2104 BitSet graphgrp = new BitSet();
2105 for (AlignmentAnnotation aa : anns)
2109 System.err.println("Null annotation row: ignoring.");
2116 if (aa.graphGroup > -1)
2118 if (graphgrp.get(aa.graphGroup))
2124 graphgrp.set(aa.graphGroup);
2131 aa.height += charHeight;
2141 aa.height += aa.graphHeight;
2149 height += aa.height;
2161 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2162 boolean preserveNewGroupSettings)
2164 boolean updateCalcs = false;
2165 boolean conv = isShowGroupConservation();
2166 boolean cons = isShowGroupConsensus();
2167 boolean showprf = isShowSequenceLogo();
2168 boolean showConsHist = isShowConsensusHistogram();
2169 boolean normLogo = isNormaliseSequenceLogo();
2172 * TODO reorder the annotation rows according to group/sequence ordering on
2175 boolean sortg = true;
2177 // remove old automatic annotation
2178 // add any new annotation
2180 // intersect alignment annotation with alignment groups
2182 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2183 List<SequenceGroup> oldrfs = new ArrayList<>();
2186 for (int an = 0; an < aan.length; an++)
2188 if (aan[an].autoCalculated && aan[an].groupRef != null)
2190 oldrfs.add(aan[an].groupRef);
2191 alignment.deleteAnnotation(aan[an], false);
2195 if (alignment.getGroups() != null)
2197 for (SequenceGroup sg : alignment.getGroups())
2199 updateCalcs = false;
2200 if (applyGlobalSettings
2201 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2203 // set defaults for this group's conservation/consensus
2204 sg.setshowSequenceLogo(showprf);
2205 sg.setShowConsensusHistogram(showConsHist);
2206 sg.setNormaliseSequenceLogo(normLogo);
2211 alignment.addAnnotation(sg.getConservationRow(), 0);
2216 alignment.addAnnotation(sg.getConsensus(), 0);
2218 // refresh the annotation rows
2221 sg.recalcConservation();
2229 public boolean isDisplayReferenceSeq()
2231 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2235 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2237 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2241 public boolean isColourByReferenceSeq()
2243 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2247 public Color getSequenceColour(SequenceI seq)
2249 Color sqc = sequenceColours.get(seq);
2250 return (sqc == null ? Color.white : sqc);
2254 public void setSequenceColour(SequenceI seq, Color col)
2258 sequenceColours.remove(seq);
2262 sequenceColours.put(seq, col);
2267 public void updateSequenceIdColours()
2269 for (SequenceGroup sg : alignment.getGroups())
2271 if (sg.idColour != null)
2273 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2275 sequenceColours.put(s, sg.idColour);
2282 public void clearSequenceColours()
2284 sequenceColours.clear();
2288 public AlignViewportI getCodingComplement()
2290 return this.codingComplement;
2294 * Set this as the (cDna/protein) complement of the given viewport. Also
2295 * ensures the reverse relationship is set on the given viewport.
2298 public void setCodingComplement(AlignViewportI av)
2302 System.err.println("Ignoring recursive setCodingComplement request");
2306 this.codingComplement = av;
2307 // avoid infinite recursion!
2308 if (av.getCodingComplement() != this)
2310 av.setCodingComplement(this);
2316 public boolean isNucleotide()
2318 return getAlignment() == null ? false : getAlignment().isNucleotide();
2322 public FeaturesDisplayedI getFeaturesDisplayed()
2324 return featuresDisplayed;
2328 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2330 featuresDisplayed = featuresDisplayedI;
2334 public boolean areFeaturesDisplayed()
2336 return featuresDisplayed != null
2337 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2344 * features are displayed if true
2347 public void setShowSequenceFeatures(boolean b)
2349 viewStyle.setShowSequenceFeatures(b);
2353 public boolean isShowSequenceFeatures()
2355 return viewStyle.isShowSequenceFeatures();
2359 public void setShowSequenceFeaturesHeight(boolean selected)
2361 viewStyle.setShowSequenceFeaturesHeight(selected);
2365 public boolean isShowSequenceFeaturesHeight()
2367 return viewStyle.isShowSequenceFeaturesHeight();
2371 public void setShowAnnotation(boolean b)
2373 viewStyle.setShowAnnotation(b);
2377 public boolean isShowAnnotation()
2379 return viewStyle.isShowAnnotation();
2383 public boolean isRightAlignIds()
2385 return viewStyle.isRightAlignIds();
2389 public void setRightAlignIds(boolean rightAlignIds)
2391 viewStyle.setRightAlignIds(rightAlignIds);
2395 public boolean getConservationSelected()
2397 return viewStyle.getConservationSelected();
2401 public void setShowBoxes(boolean state)
2403 viewStyle.setShowBoxes(state);
2408 * @see jalview.api.ViewStyleI#getTextColour()
2411 public Color getTextColour()
2413 return viewStyle.getTextColour();
2418 * @see jalview.api.ViewStyleI#getTextColour2()
2421 public Color getTextColour2()
2423 return viewStyle.getTextColour2();
2428 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2431 public int getThresholdTextColour()
2433 return viewStyle.getThresholdTextColour();
2438 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2441 public boolean isConservationColourSelected()
2443 return viewStyle.isConservationColourSelected();
2448 * @see jalview.api.ViewStyleI#isRenderGaps()
2451 public boolean isRenderGaps()
2453 return viewStyle.isRenderGaps();
2458 * @see jalview.api.ViewStyleI#isShowColourText()
2461 public boolean isShowColourText()
2463 return viewStyle.isShowColourText();
2467 * @param conservationColourSelected
2468 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2471 public void setConservationColourSelected(
2472 boolean conservationColourSelected)
2474 viewStyle.setConservationColourSelected(conservationColourSelected);
2478 * @param showColourText
2479 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2482 public void setShowColourText(boolean showColourText)
2484 viewStyle.setShowColourText(showColourText);
2489 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2492 public void setTextColour(Color textColour)
2494 viewStyle.setTextColour(textColour);
2498 * @param thresholdTextColour
2499 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2502 public void setThresholdTextColour(int thresholdTextColour)
2504 viewStyle.setThresholdTextColour(thresholdTextColour);
2508 * @param textColour2
2509 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2512 public void setTextColour2(Color textColour2)
2514 viewStyle.setTextColour2(textColour2);
2518 public ViewStyleI getViewStyle()
2520 return new ViewStyle(viewStyle);
2524 public void setViewStyle(ViewStyleI settingsForView)
2526 viewStyle = new ViewStyle(settingsForView);
2527 if (residueShading != null)
2529 residueShading.setConservationApplied(
2530 settingsForView.isConservationColourSelected());
2535 public boolean sameStyle(ViewStyleI them)
2537 return viewStyle.sameStyle(them);
2542 * @see jalview.api.ViewStyleI#getIdWidth()
2545 public int getIdWidth()
2547 return viewStyle.getIdWidth();
2552 * @see jalview.api.ViewStyleI#setIdWidth(int)
2555 public void setIdWidth(int i)
2557 viewStyle.setIdWidth(i);
2562 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2565 public boolean isCentreColumnLabels()
2567 return viewStyle.isCentreColumnLabels();
2571 * @param centreColumnLabels
2572 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2575 public void setCentreColumnLabels(boolean centreColumnLabels)
2577 viewStyle.setCentreColumnLabels(centreColumnLabels);
2582 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2585 public void setShowDBRefs(boolean showdbrefs)
2587 viewStyle.setShowDBRefs(showdbrefs);
2592 * @see jalview.api.ViewStyleI#isShowDBRefs()
2595 public boolean isShowDBRefs()
2597 return viewStyle.isShowDBRefs();
2602 * @see jalview.api.ViewStyleI#isShowNPFeats()
2605 public boolean isShowNPFeats()
2607 return viewStyle.isShowNPFeats();
2611 * @param shownpfeats
2612 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2615 public void setShowNPFeats(boolean shownpfeats)
2617 viewStyle.setShowNPFeats(shownpfeats);
2620 public abstract StructureSelectionManager getStructureSelectionManager();
2623 * Add one command to the command history list.
2627 public void addToHistoryList(CommandI command)
2629 if (this.historyList != null)
2631 this.historyList.push(command);
2632 broadcastCommand(command, false);
2636 protected void broadcastCommand(CommandI command, boolean undo)
2638 getStructureSelectionManager().commandPerformed(command, undo,
2643 * Add one command to the command redo list.
2647 public void addToRedoList(CommandI command)
2649 if (this.redoList != null)
2651 this.redoList.push(command);
2653 broadcastCommand(command, true);
2657 * Clear the command redo list.
2659 public void clearRedoList()
2661 if (this.redoList != null)
2663 this.redoList.clear();
2667 public void setHistoryList(Deque<CommandI> list)
2669 this.historyList = list;
2672 public Deque<CommandI> getHistoryList()
2674 return this.historyList;
2677 public void setRedoList(Deque<CommandI> list)
2679 this.redoList = list;
2682 public Deque<CommandI> getRedoList()
2684 return this.redoList;
2688 public VamsasSource getVamsasSource()
2693 public SequenceAnnotationOrder getSortAnnotationsBy()
2695 return sortAnnotationsBy;
2698 public void setSortAnnotationsBy(
2699 SequenceAnnotationOrder sortAnnotationsBy)
2701 this.sortAnnotationsBy = sortAnnotationsBy;
2704 public boolean isShowAutocalculatedAbove()
2706 return showAutocalculatedAbove;
2709 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2711 this.showAutocalculatedAbove = showAutocalculatedAbove;
2715 public boolean isScaleProteinAsCdna()
2717 return viewStyle.isScaleProteinAsCdna();
2721 public void setScaleProteinAsCdna(boolean b)
2723 viewStyle.setScaleProteinAsCdna(b);
2727 public boolean isProteinFontAsCdna()
2729 return viewStyle.isProteinFontAsCdna();
2733 public void setProteinFontAsCdna(boolean b)
2735 viewStyle.setProteinFontAsCdna(b);
2739 public void setShowComplementFeatures(boolean b)
2741 viewStyle.setShowComplementFeatures(b);
2745 public boolean isShowComplementFeatures()
2747 return viewStyle.isShowComplementFeatures();
2751 public void setShowComplementFeaturesOnTop(boolean b)
2753 viewStyle.setShowComplementFeaturesOnTop(b);
2757 public boolean isShowComplementFeaturesOnTop()
2759 return viewStyle.isShowComplementFeaturesOnTop();
2763 * @return true if view should scroll to show the highlighted region of a
2768 public final boolean isFollowHighlight()
2770 return followHighlight;
2774 public final void setFollowHighlight(boolean b)
2776 this.followHighlight = b;
2780 public ViewportRanges getRanges()
2786 * Helper method to populate the SearchResults with the location in the
2787 * complementary alignment to scroll to, in order to match this one.
2790 * the SearchResults to add to
2791 * @return the offset (below top of visible region) of the matched sequence
2793 protected int findComplementScrollTarget(SearchResultsI sr)
2795 final AlignViewportI complement = getCodingComplement();
2796 if (complement == null || !complement.isFollowHighlight())
2800 boolean iAmProtein = !getAlignment().isNucleotide();
2801 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2802 : complement.getAlignment();
2803 if (proteinAlignment == null)
2807 final List<AlignedCodonFrame> mappings = proteinAlignment
2811 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2812 * residue in the middle column of the visible region. Scroll the
2813 * complementary alignment to line up the corresponding residue.
2816 SequenceI sequence = null;
2819 * locate 'middle' column (true middle if an odd number visible, left of
2820 * middle if an even number visible)
2822 int middleColumn = ranges.getStartRes()
2823 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2824 final HiddenSequences hiddenSequences = getAlignment()
2825 .getHiddenSequences();
2828 * searching to the bottom of the alignment gives smoother scrolling across
2829 * all gapped visible regions
2831 int lastSeq = alignment.getHeight() - 1;
2832 List<AlignedCodonFrame> seqMappings = null;
2833 for (int seqNo = ranges
2834 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2836 sequence = getAlignment().getSequenceAt(seqNo);
2837 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2841 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2845 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2847 getCodingComplement().getAlignment().getSequences());
2848 if (!seqMappings.isEmpty())
2854 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2857 * No ungapped mapped sequence in middle column - do nothing
2861 MappingUtils.addSearchResults(sr, sequence,
2862 sequence.findPosition(middleColumn), seqMappings);
2867 * synthesize a column selection if none exists so it covers the given
2868 * selection group. if wholewidth is false, no column selection is made if the
2869 * selection group covers the whole alignment width.
2874 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2877 if (sg != null && (sgs = sg.getStartRes()) >= 0
2878 && sg.getStartRes() <= (sge = sg.getEndRes())
2879 && !this.hasSelectedColumns())
2881 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2888 colSel = new ColumnSelection();
2890 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2892 colSel.addElement(cspos);
2898 * hold status of current selection group - defined on alignment or not.
2900 private boolean selectionIsDefinedGroup = false;
2903 public boolean isSelectionDefinedGroup()
2905 if (selectionGroup == null)
2909 if (isSelectionGroupChanged(true))
2911 selectionIsDefinedGroup = false;
2912 List<SequenceGroup> gps = alignment.getGroups();
2913 if (gps == null || gps.size() == 0)
2915 selectionIsDefinedGroup = false;
2919 selectionIsDefinedGroup = gps.contains(selectionGroup);
2922 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2926 * null, or currently highlighted results on this view
2928 private SearchResultsI searchResults = null;
2930 protected TreeModel currentTree = null;
2933 public boolean hasSearchResults()
2935 return searchResults != null;
2939 public void setSearchResults(SearchResultsI results)
2941 searchResults = results;
2945 public SearchResultsI getSearchResults()
2947 return searchResults;
2951 * get the consensus sequence as displayed under the PID consensus annotation
2954 * @return consensus sequence as a new sequence object
2956 public SequenceI getConsensusSeq()
2958 if (consensus == null)
2960 updateConsensus(null);
2962 if (consensus == null)
2966 StringBuffer seqs = new StringBuffer();
2967 for (int i = 0; i < consensus.annotations.length; i++)
2969 Annotation annotation = consensus.annotations[i];
2970 if (annotation != null)
2972 String description = annotation.description;
2973 if (description != null && description.startsWith("["))
2975 // consensus is a tie - just pick the first one
2976 seqs.append(description.charAt(1));
2980 seqs.append(annotation.displayCharacter);
2985 SequenceI sq = new Sequence("Consensus", seqs.toString());
2986 sq.setDescription("Percentage Identity Consensus "
2987 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2992 public void setCurrentTree(TreeModel tree)
2998 public TreeModel getCurrentTree()
3004 * flag set to indicate if structure views might be out of sync with sequences
3008 private boolean needToUpdateStructureViews = false;
3011 public boolean isUpdateStructures()
3013 return needToUpdateStructureViews;
3017 public void setUpdateStructures(boolean update)
3019 needToUpdateStructureViews = update;
3023 public boolean needToUpdateStructureViews()
3025 boolean update = needToUpdateStructureViews;
3026 needToUpdateStructureViews = false;
3031 public void addSequenceGroup(SequenceGroup sequenceGroup)
3033 alignment.addGroup(sequenceGroup);
3035 Color col = sequenceGroup.idColour;
3038 col = col.brighter();
3040 for (SequenceI sq : sequenceGroup.getSequences())
3042 setSequenceColour(sq, col);
3046 if (codingComplement != null)
3048 SequenceGroup mappedGroup = MappingUtils
3049 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3050 if (mappedGroup.getSequences().size() > 0)
3052 codingComplement.getAlignment().addGroup(mappedGroup);
3056 for (SequenceI seq : mappedGroup.getSequences())
3058 codingComplement.setSequenceColour(seq, col);
3062 // propagate the structure view update flag according to our own setting
3063 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3068 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3072 if (selectedRegionOnly && selectionGroup != null)
3074 start = selectionGroup.getStartRes();
3075 end = selectionGroup.getEndRes() + 1;
3079 end = alignment.getWidth();
3081 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,