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.AlignExportSettingsI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.api.FeaturesDisplayedI;
31 import jalview.api.ViewStyleI;
32 import jalview.commands.CommandI;
33 import jalview.datamodel.AlignedCodonFrame;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentExportData;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.AlignmentView;
38 import jalview.datamodel.Annotation;
39 import jalview.datamodel.ColumnSelection;
40 import jalview.datamodel.HiddenColumns;
41 import jalview.datamodel.HiddenSequences;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.renderer.ResidueShader;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.ColourSchemeI;
51 import jalview.structure.CommandListener;
52 import jalview.structure.StructureSelectionManager;
53 import jalview.structure.VamsasSource;
54 import jalview.util.Comparison;
55 import jalview.util.MapList;
56 import jalview.util.MappingUtils;
57 import jalview.util.MessageManager;
58 import jalview.viewmodel.styles.ViewStyle;
59 import jalview.workers.AlignCalcManager;
60 import jalview.workers.ComplementConsensusThread;
61 import jalview.workers.ConsensusThread;
62 import jalview.workers.StrucConsensusThread;
64 import java.awt.Color;
65 import java.beans.PropertyChangeSupport;
66 import java.util.ArrayDeque;
67 import java.util.ArrayList;
68 import java.util.BitSet;
69 import java.util.Deque;
70 import java.util.HashMap;
71 import java.util.Hashtable;
72 import java.util.Iterator;
73 import java.util.List;
77 * base class holding visualization and analysis attributes and common logic for
78 * an active alignment view displayed in the GUI
83 public abstract class AlignmentViewport
84 implements AlignViewportI, CommandListener, VamsasSource
86 protected ViewportRanges ranges;
88 protected ViewStyleI viewStyle = new ViewStyle();
91 * A viewport that hosts the cDna view of this (protein), or vice versa (if
94 AlignViewportI codingComplement = null;
96 FeaturesDisplayedI featuresDisplayed = null;
98 protected Deque<CommandI> historyList = new ArrayDeque<>();
100 protected Deque<CommandI> redoList = new ArrayDeque<>();
103 * alignment displayed in the viewport. Please use get/setter
105 protected AlignmentI alignment;
107 public AlignmentViewport(AlignmentI al)
110 ranges = new ViewportRanges(al);
115 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
118 public void setFontName(String name)
120 viewStyle.setFontName(name);
125 * @see jalview.api.ViewStyleI#setFontStyle(int)
128 public void setFontStyle(int style)
130 viewStyle.setFontStyle(style);
135 * @see jalview.api.ViewStyleI#setFontSize(int)
138 public void setFontSize(int size)
140 viewStyle.setFontSize(size);
145 * @see jalview.api.ViewStyleI#getFontStyle()
148 public int getFontStyle()
150 return viewStyle.getFontStyle();
155 * @see jalview.api.ViewStyleI#getFontName()
158 public String getFontName()
160 return viewStyle.getFontName();
165 * @see jalview.api.ViewStyleI#getFontSize()
168 public int getFontSize()
170 return viewStyle.getFontSize();
174 * @param upperCasebold
175 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
178 public void setUpperCasebold(boolean upperCasebold)
180 viewStyle.setUpperCasebold(upperCasebold);
185 * @see jalview.api.ViewStyleI#isUpperCasebold()
188 public boolean isUpperCasebold()
190 return viewStyle.isUpperCasebold();
195 * @see jalview.api.ViewStyleI#isSeqNameItalics()
198 public boolean isSeqNameItalics()
200 return viewStyle.isSeqNameItalics();
204 * @param colourByReferenceSeq
205 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
208 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
210 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
215 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
218 public void setColourAppliesToAllGroups(boolean b)
220 viewStyle.setColourAppliesToAllGroups(b);
225 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
228 public boolean getColourAppliesToAllGroups()
230 return viewStyle.getColourAppliesToAllGroups();
235 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
238 public boolean getAbovePIDThreshold()
240 return viewStyle.getAbovePIDThreshold();
245 * @see jalview.api.ViewStyleI#setIncrement(int)
248 public void setIncrement(int inc)
250 viewStyle.setIncrement(inc);
255 * @see jalview.api.ViewStyleI#getIncrement()
258 public int getIncrement()
260 return viewStyle.getIncrement();
265 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
268 public void setConservationSelected(boolean b)
270 viewStyle.setConservationSelected(b);
275 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
278 public void setShowHiddenMarkers(boolean show)
280 viewStyle.setShowHiddenMarkers(show);
285 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
288 public boolean getShowHiddenMarkers()
290 return viewStyle.getShowHiddenMarkers();
295 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
298 public void setScaleRightWrapped(boolean b)
300 viewStyle.setScaleRightWrapped(b);
305 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
308 public void setScaleLeftWrapped(boolean b)
310 viewStyle.setScaleLeftWrapped(b);
315 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
318 public void setScaleAboveWrapped(boolean b)
320 viewStyle.setScaleAboveWrapped(b);
325 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
328 public boolean getScaleLeftWrapped()
330 return viewStyle.getScaleLeftWrapped();
335 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
338 public boolean getScaleAboveWrapped()
340 return viewStyle.getScaleAboveWrapped();
345 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
348 public boolean getScaleRightWrapped()
350 return viewStyle.getScaleRightWrapped();
355 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
358 public void setAbovePIDThreshold(boolean b)
360 viewStyle.setAbovePIDThreshold(b);
365 * @see jalview.api.ViewStyleI#setThreshold(int)
368 public void setThreshold(int thresh)
370 viewStyle.setThreshold(thresh);
375 * @see jalview.api.ViewStyleI#getThreshold()
378 public int getThreshold()
380 return viewStyle.getThreshold();
385 * @see jalview.api.ViewStyleI#getShowJVSuffix()
388 public boolean getShowJVSuffix()
390 return viewStyle.getShowJVSuffix();
395 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
398 public void setShowJVSuffix(boolean b)
400 viewStyle.setShowJVSuffix(b);
405 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
408 public void setWrapAlignment(boolean state)
410 viewStyle.setWrapAlignment(state);
411 ranges.setWrappedMode(state);
416 * @see jalview.api.ViewStyleI#setShowText(boolean)
419 public void setShowText(boolean state)
421 viewStyle.setShowText(state);
426 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
429 public void setRenderGaps(boolean state)
431 viewStyle.setRenderGaps(state);
436 * @see jalview.api.ViewStyleI#getColourText()
439 public boolean getColourText()
441 return viewStyle.getColourText();
446 * @see jalview.api.ViewStyleI#setColourText(boolean)
449 public void setColourText(boolean state)
451 viewStyle.setColourText(state);
456 * @see jalview.api.ViewStyleI#getWrapAlignment()
459 public boolean getWrapAlignment()
461 return viewStyle.getWrapAlignment();
466 * @see jalview.api.ViewStyleI#getShowText()
469 public boolean getShowText()
471 return viewStyle.getShowText();
476 * @see jalview.api.ViewStyleI#getWrappedWidth()
479 public int getWrappedWidth()
481 return viewStyle.getWrappedWidth();
486 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
489 public void setWrappedWidth(int w)
491 viewStyle.setWrappedWidth(w);
496 * @see jalview.api.ViewStyleI#getCharHeight()
499 public int getCharHeight()
501 return viewStyle.getCharHeight();
506 * @see jalview.api.ViewStyleI#setCharHeight(int)
509 public void setCharHeight(int h)
511 viewStyle.setCharHeight(h);
516 * @see jalview.api.ViewStyleI#getCharWidth()
519 public int getCharWidth()
521 return viewStyle.getCharWidth();
526 * @see jalview.api.ViewStyleI#setCharWidth(int)
529 public void setCharWidth(int w)
531 viewStyle.setCharWidth(w);
536 * @see jalview.api.ViewStyleI#getShowBoxes()
539 public boolean getShowBoxes()
541 return viewStyle.getShowBoxes();
546 * @see jalview.api.ViewStyleI#getShowUnconserved()
549 public boolean getShowUnconserved()
551 return viewStyle.getShowUnconserved();
555 * @param showunconserved
556 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
559 public void setShowUnconserved(boolean showunconserved)
561 viewStyle.setShowUnconserved(showunconserved);
566 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
569 public void setSeqNameItalics(boolean default1)
571 viewStyle.setSeqNameItalics(default1);
575 public AlignmentI getAlignment()
581 public char getGapCharacter()
583 return alignment.getGapCharacter();
586 protected String sequenceSetID;
589 * probably unused indicator that view is of a dataset rather than an
592 protected boolean isDataset = false;
594 public void setDataset(boolean b)
599 public boolean isDataset()
604 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
606 protected ColumnSelection colSel = new ColumnSelection();
608 public boolean autoCalculateConsensus = true;
610 protected boolean autoCalculateStrucConsensus = true;
612 protected boolean ignoreGapsInConsensusCalculation = false;
614 protected ResidueShaderI residueShading = new ResidueShader();
617 public void setGlobalColourScheme(ColourSchemeI cs)
619 // TODO: logic refactored from AlignFrame changeColour -
620 // TODO: autorecalc stuff should be changed to rely on the worker system
621 // check to see if we should implement a changeColour(cs) method rather than
622 // put the logic in here
623 // - means that caller decides if they want to just modify state and defer
624 // calculation till later or to do all calculations in thread.
628 * only instantiate alignment colouring once, thereafter update it;
629 * this means that any conservation or PID threshold settings
630 * persist when the alignment colour scheme is changed
632 if (residueShading == null)
634 residueShading = new ResidueShader(viewStyle);
636 residueShading.setColourScheme(cs);
638 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
639 // ...problem: groups need these, but do not currently have a ViewStyle
643 if (getConservationSelected())
645 residueShading.setConservation(hconservation);
648 * reset conservation flag in case just set to false if
649 * Conservation was null (calculation still in progress)
651 residueShading.setConservationApplied(getConservationSelected());
652 residueShading.alignmentChanged(alignment, hiddenRepSequences);
656 * if 'apply colour to all groups' is selected... do so
657 * (but don't transfer any colour threshold settings to groups)
659 if (getColourAppliesToAllGroups())
661 for (SequenceGroup sg : getAlignment().getGroups())
664 * retain any colour thresholds per group while
665 * changing choice of colour scheme (JAL-2386)
668 cs == null ? null : cs.getInstance(this, sg));
671 sg.getGroupColourScheme().alignmentChanged(sg,
679 public ColourSchemeI getGlobalColourScheme()
681 return residueShading == null ? null : residueShading.getColourScheme();
685 public ResidueShaderI getResidueShading()
687 return residueShading;
690 protected AlignmentAnnotation consensus;
692 protected AlignmentAnnotation complementConsensus;
694 protected AlignmentAnnotation gapcounts;
696 protected AlignmentAnnotation strucConsensus;
698 protected AlignmentAnnotation conservation;
700 protected AlignmentAnnotation quality;
702 protected AlignmentAnnotation[] groupConsensus;
704 protected AlignmentAnnotation[] groupConservation;
707 * results of alignment consensus analysis for visible portion of view
709 protected ProfilesI hconsensus = null;
712 * results of cDNA complement consensus visible portion of view
714 protected Hashtable[] hcomplementConsensus = null;
717 * results of secondary structure base pair consensus for visible portion of
720 protected Hashtable[] hStrucConsensus = null;
722 protected Conservation hconservation = null;
725 public void setConservation(Conservation cons)
727 hconservation = cons;
731 * percentage gaps allowed in a column before all amino acid properties should
732 * be considered unconserved
734 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
737 public int getConsPercGaps()
743 public void setSequenceConsensusHash(ProfilesI hconsensus)
745 this.hconsensus = hconsensus;
749 public void setComplementConsensusHash(Hashtable[] hconsensus)
751 this.hcomplementConsensus = hconsensus;
755 public ProfilesI getSequenceConsensusHash()
761 public Hashtable[] getComplementConsensusHash()
763 return hcomplementConsensus;
767 public Hashtable[] getRnaStructureConsensusHash()
769 return hStrucConsensus;
773 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
775 this.hStrucConsensus = hStrucConsensus;
780 public AlignmentAnnotation getAlignmentQualityAnnot()
786 public AlignmentAnnotation getAlignmentConservationAnnotation()
792 public AlignmentAnnotation getAlignmentConsensusAnnotation()
798 public AlignmentAnnotation getAlignmentGapAnnotation()
804 public AlignmentAnnotation getComplementConsensusAnnotation()
806 return complementConsensus;
810 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
812 return strucConsensus;
815 protected AlignCalcManagerI calculator = new AlignCalcManager();
818 * trigger update of conservation annotation
820 public void updateConservation(final AlignmentViewPanel ap)
822 // see note in mantis : issue number 8585
823 if (alignment.isNucleotide()
824 || (conservation == null && quality == null)
825 || !autoCalculateConsensus)
829 if (calculator.getRegisteredWorkersOfClass(
830 jalview.workers.ConservationThread.class) == null)
832 calculator.registerWorker(
833 new jalview.workers.ConservationThread(this, ap));
838 * trigger update of consensus annotation
840 public void updateConsensus(final AlignmentViewPanel ap)
842 // see note in mantis : issue number 8585
843 if (consensus == null || !autoCalculateConsensus)
848 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
850 calculator.registerWorker(new ConsensusThread(this, ap));
854 * A separate thread to compute cDNA consensus for a protein alignment
855 * which has mapping to cDNA
857 final AlignmentI al = this.getAlignment();
858 if (!al.isNucleotide() && al.getCodonFrames() != null
859 && !al.getCodonFrames().isEmpty())
862 * fudge - check first for protein-to-nucleotide mappings
863 * (we don't want to do this for protein-to-protein)
865 boolean doConsensus = false;
866 for (AlignedCodonFrame mapping : al.getCodonFrames())
868 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
869 MapList[] mapLists = mapping.getdnaToProt();
870 // mapLists can be empty if project load has not finished resolving seqs
871 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
879 if (calculator.getRegisteredWorkersOfClass(
880 ComplementConsensusThread.class) == null)
883 .registerWorker(new ComplementConsensusThread(this, ap));
889 // --------START Structure Conservation
890 public void updateStrucConsensus(final AlignmentViewPanel ap)
892 if (autoCalculateStrucConsensus && strucConsensus == null
893 && alignment.isNucleotide() && alignment.hasRNAStructure())
895 // secondary structure has been added - so init the consensus line
899 // see note in mantis : issue number 8585
900 if (strucConsensus == null || !autoCalculateStrucConsensus)
904 if (calculator.getRegisteredWorkersOfClass(
905 StrucConsensusThread.class) == null)
907 calculator.registerWorker(new StrucConsensusThread(this, ap));
911 public boolean isCalcInProgress()
913 return calculator.isWorking();
917 public boolean isCalculationInProgress(
918 AlignmentAnnotation alignmentAnnotation)
920 if (!alignmentAnnotation.autoCalculated)
924 if (calculator.workingInvolvedWith(alignmentAnnotation))
926 // System.err.println("grey out ("+alignmentAnnotation.label+")");
932 public void setAlignment(AlignmentI align)
934 this.alignment = align;
938 * Clean up references when this viewport is closed
941 public void dispose()
944 * defensively null out references to large objects in case
945 * this object is not garbage collected (as if!)
948 complementConsensus = null;
949 strucConsensus = null;
952 groupConsensus = null;
953 groupConservation = null;
955 hconservation = null;
956 hcomplementConsensus = null;
959 residueShading = null; // may hold a reference to Consensus
960 changeSupport = null;
963 selectionGroup = null;
968 public boolean isClosed()
970 // TODO: check that this isClosed is only true after panel is closed, not
971 // before it is fully constructed.
972 return alignment == null;
976 public AlignCalcManagerI getCalcManager()
982 * should conservation rows be shown for groups
984 protected boolean showGroupConservation = false;
987 * should consensus rows be shown for groups
989 protected boolean showGroupConsensus = false;
992 * should consensus profile be rendered by default
994 protected boolean showSequenceLogo = false;
997 * should consensus profile be rendered normalised to row height
999 protected boolean normaliseSequenceLogo = false;
1002 * should consensus histograms be rendered by default
1004 protected boolean showConsensusHistogram = true;
1007 * @return the showConsensusProfile
1010 public boolean isShowSequenceLogo()
1012 return showSequenceLogo;
1016 * @param showSequenceLogo
1019 public void setShowSequenceLogo(boolean showSequenceLogo)
1021 if (showSequenceLogo != this.showSequenceLogo)
1023 // TODO: decouple settings setting from calculation when refactoring
1024 // annotation update method from alignframe to viewport
1025 this.showSequenceLogo = showSequenceLogo;
1026 calculator.updateAnnotationFor(ConsensusThread.class);
1027 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1028 calculator.updateAnnotationFor(StrucConsensusThread.class);
1030 this.showSequenceLogo = showSequenceLogo;
1034 * @param showConsensusHistogram
1035 * the showConsensusHistogram to set
1037 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1039 this.showConsensusHistogram = showConsensusHistogram;
1043 * @return the showGroupConservation
1045 public boolean isShowGroupConservation()
1047 return showGroupConservation;
1051 * @param showGroupConservation
1052 * the showGroupConservation to set
1054 public void setShowGroupConservation(boolean showGroupConservation)
1056 this.showGroupConservation = showGroupConservation;
1060 * @return the showGroupConsensus
1062 public boolean isShowGroupConsensus()
1064 return showGroupConsensus;
1068 * @param showGroupConsensus
1069 * the showGroupConsensus to set
1071 public void setShowGroupConsensus(boolean showGroupConsensus)
1073 this.showGroupConsensus = showGroupConsensus;
1078 * @return flag to indicate if the consensus histogram should be rendered by
1082 public boolean isShowConsensusHistogram()
1084 return this.showConsensusHistogram;
1088 * when set, updateAlignment will always ensure sequences are of equal length
1090 private boolean padGaps = false;
1093 * when set, alignment should be reordered according to a newly opened tree
1095 public boolean sortByTree = false;
1100 * @return null or the currently selected sequence region
1103 public SequenceGroup getSelectionGroup()
1105 return selectionGroup;
1109 * Set the selection group for this window. Also sets the current alignment as
1110 * the context for the group, if it does not already have one.
1113 * - group holding references to sequences in this alignment view
1117 public void setSelectionGroup(SequenceGroup sg)
1119 selectionGroup = sg;
1120 if (sg != null && sg.getContext() == null)
1122 sg.setContext(alignment);
1126 public void setHiddenColumns(HiddenColumns hidden)
1128 this.alignment.setHiddenColumns(hidden);
1132 public ColumnSelection getColumnSelection()
1138 public void setColumnSelection(ColumnSelection colSel)
1140 this.colSel = colSel;
1143 updateHiddenColumns();
1145 isColSelChanged(true);
1153 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1155 return hiddenRepSequences;
1159 public void setHiddenRepSequences(
1160 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1162 this.hiddenRepSequences = hiddenRepSequences;
1166 public boolean hasSelectedColumns()
1168 ColumnSelection columnSelection = getColumnSelection();
1169 return columnSelection != null && columnSelection.hasSelectedColumns();
1173 public boolean hasHiddenColumns()
1175 return alignment.getHiddenColumns() != null
1176 && alignment.getHiddenColumns().hasHiddenColumns();
1179 public void updateHiddenColumns()
1181 // this method doesn't really do anything now. But - it could, since a
1182 // column Selection could be in the process of modification
1183 // hasHiddenColumns = colSel.hasHiddenColumns();
1187 public boolean hasHiddenRows()
1189 return alignment.getHiddenSequences().getSize() > 0;
1192 protected SequenceGroup selectionGroup;
1194 public void setSequenceSetId(String newid)
1196 if (sequenceSetID != null)
1199 "Warning - overwriting a sequenceSetId for a viewport!");
1201 sequenceSetID = new String(newid);
1205 public String getSequenceSetId()
1207 if (sequenceSetID == null)
1209 sequenceSetID = alignment.hashCode() + "";
1212 return sequenceSetID;
1216 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1219 protected String viewId = null;
1222 public String getViewId()
1226 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1231 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1233 ignoreGapsInConsensusCalculation = b;
1236 updateConsensus(ap);
1237 if (residueShading != null)
1239 residueShading.setThreshold(residueShading.getThreshold(),
1240 ignoreGapsInConsensusCalculation);
1246 private long sgrouphash = -1, colselhash = -1;
1249 * checks current SelectionGroup against record of last hash value, and
1253 * update the record of last hash value
1255 * @return true if SelectionGroup changed since last call (when b is true)
1257 public boolean isSelectionGroupChanged(boolean b)
1259 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1260 : selectionGroup.hashCode();
1261 if (hc != -1 && hc != sgrouphash)
1273 * checks current colsel against record of last hash value, and optionally
1277 * update the record of last hash value
1278 * @return true if colsel changed since last call (when b is true)
1280 public boolean isColSelChanged(boolean b)
1282 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1283 if (hc != -1 && hc != colselhash)
1295 public boolean isIgnoreGapsConsensus()
1297 return ignoreGapsInConsensusCalculation;
1300 // property change stuff
1301 // JBPNote Prolly only need this in the applet version.
1302 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1305 protected boolean showConservation = true;
1307 protected boolean showQuality = true;
1309 protected boolean showConsensus = true;
1311 protected boolean showOccupancy = true;
1313 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1315 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1317 protected boolean showAutocalculatedAbove;
1320 * when set, view will scroll to show the highlighted position
1322 private boolean followHighlight = true;
1325 * Property change listener for changes in alignment
1330 public void addPropertyChangeListener(
1331 java.beans.PropertyChangeListener listener)
1333 changeSupport.addPropertyChangeListener(listener);
1342 public void removePropertyChangeListener(
1343 java.beans.PropertyChangeListener listener)
1345 if (changeSupport != null)
1347 changeSupport.removePropertyChangeListener(listener);
1352 * Property change listener for changes in alignment
1361 public void firePropertyChange(String prop, Object oldvalue,
1364 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1367 // common hide/show column stuff
1369 public void hideSelectedColumns()
1371 if (colSel.isEmpty())
1376 colSel.hideSelectedColumns(alignment);
1377 setSelectionGroup(null);
1378 isColSelChanged(true);
1381 public void hideColumns(int start, int end)
1385 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1389 alignment.getHiddenColumns().hideColumns(start, end);
1391 isColSelChanged(true);
1394 public void showColumn(int col)
1396 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1397 isColSelChanged(true);
1400 public void showAllHiddenColumns()
1402 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1403 isColSelChanged(true);
1406 // common hide/show seq stuff
1407 public void showAllHiddenSeqs()
1409 int startSeq = ranges.getStartSeq();
1410 int endSeq = ranges.getEndSeq();
1412 if (alignment.getHiddenSequences().getSize() > 0)
1414 if (selectionGroup == null)
1416 selectionGroup = new SequenceGroup();
1417 selectionGroup.setEndRes(alignment.getWidth() - 1);
1419 List<SequenceI> tmp = alignment.getHiddenSequences()
1420 .showAll(hiddenRepSequences);
1421 for (SequenceI seq : tmp)
1423 selectionGroup.addSequence(seq, false);
1424 setSequenceAnnotationsVisible(seq, true);
1427 hiddenRepSequences = null;
1429 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1431 firePropertyChange("alignment", null, alignment.getSequences());
1432 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1438 public void showSequence(int index)
1440 int startSeq = ranges.getStartSeq();
1441 int endSeq = ranges.getEndSeq();
1443 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1444 hiddenRepSequences);
1447 if (selectionGroup == null)
1449 selectionGroup = new SequenceGroup();
1450 selectionGroup.setEndRes(alignment.getWidth() - 1);
1453 for (SequenceI seq : tmp)
1455 selectionGroup.addSequence(seq, false);
1456 setSequenceAnnotationsVisible(seq, true);
1459 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1461 firePropertyChange("alignment", null, alignment.getSequences());
1466 public void hideAllSelectedSeqs()
1468 if (selectionGroup == null || selectionGroup.getSize() < 1)
1473 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1477 setSelectionGroup(null);
1480 public void hideSequence(SequenceI[] seq)
1483 * cache offset to first visible sequence
1485 int startSeq = ranges.getStartSeq();
1489 for (int i = 0; i < seq.length; i++)
1491 alignment.getHiddenSequences().hideSequence(seq[i]);
1492 setSequenceAnnotationsVisible(seq[i], false);
1494 ranges.setStartSeq(startSeq);
1495 firePropertyChange("alignment", null, alignment.getSequences());
1500 * Hides the specified sequence, or the sequences it represents
1503 * the sequence to hide, or keep as representative
1504 * @param representGroup
1505 * if true, hide the current selection group except for the
1506 * representative sequence
1508 public void hideSequences(SequenceI sequence, boolean representGroup)
1510 if (selectionGroup == null || selectionGroup.getSize() < 1)
1512 hideSequence(new SequenceI[] { sequence });
1518 hideRepSequences(sequence, selectionGroup);
1519 setSelectionGroup(null);
1523 int gsize = selectionGroup.getSize();
1524 SequenceI[] hseqs = selectionGroup.getSequences()
1525 .toArray(new SequenceI[gsize]);
1527 hideSequence(hseqs);
1528 setSelectionGroup(null);
1533 * Set visibility for any annotations for the given sequence.
1537 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1540 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1543 for (AlignmentAnnotation ann : anns)
1545 if (ann.sequenceRef == sequenceI)
1547 ann.visible = visible;
1553 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1555 int sSize = sg.getSize();
1561 if (hiddenRepSequences == null)
1563 hiddenRepSequences = new Hashtable<>();
1566 hiddenRepSequences.put(repSequence, sg);
1568 // Hide all sequences except the repSequence
1569 SequenceI[] seqs = new SequenceI[sSize - 1];
1571 for (int i = 0; i < sSize; i++)
1573 if (sg.getSequenceAt(i) != repSequence)
1575 if (index == sSize - 1)
1580 seqs[index++] = sg.getSequenceAt(i);
1583 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1584 sg.setHidereps(true); // note: not done in 2.7applet
1591 * @return null or the current reference sequence
1593 public SequenceI getReferenceSeq()
1595 return alignment.getSeqrep();
1600 * @return true iff seq is the reference for the alignment
1602 public boolean isReferenceSeq(SequenceI seq)
1604 return alignment.getSeqrep() == seq;
1610 * @return true if there are sequences represented by this sequence that are
1613 public boolean isHiddenRepSequence(SequenceI seq)
1615 return (hiddenRepSequences != null
1616 && hiddenRepSequences.containsKey(seq));
1622 * @return null or a sequence group containing the sequences that seq
1625 public SequenceGroup getRepresentedSequences(SequenceI seq)
1627 return (SequenceGroup) (hiddenRepSequences == null ? null
1628 : hiddenRepSequences.get(seq));
1632 public int adjustForHiddenSeqs(int alignmentIndex)
1634 return alignment.getHiddenSequences()
1635 .adjustForHiddenSeqs(alignmentIndex);
1639 public void invertColumnSelection()
1641 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1642 isColSelChanged(true);
1646 public SequenceI[] getSelectionAsNewSequence()
1648 SequenceI[] sequences;
1649 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1650 // this was the only caller in the applet for this method
1651 // JBPNote: in applet, this method returned references to the alignment
1652 // sequences, and it did not honour the presence/absence of annotation
1653 // attached to the alignment (probably!)
1654 if (selectionGroup == null || selectionGroup.getSize() == 0)
1656 sequences = alignment.getSequencesArray();
1657 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1658 for (int i = 0; i < sequences.length; i++)
1660 // construct new sequence with subset of visible annotation
1661 sequences[i] = new Sequence(sequences[i], annots);
1666 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1673 public SequenceI[] getSequenceSelection()
1675 SequenceI[] sequences = null;
1676 if (selectionGroup != null)
1678 sequences = selectionGroup.getSequencesInOrder(alignment);
1680 if (sequences == null)
1682 sequences = alignment.getSequencesArray();
1688 public jalview.datamodel.AlignmentView getAlignmentView(
1689 boolean selectedOnly)
1691 return getAlignmentView(selectedOnly, false);
1695 public jalview.datamodel.AlignmentView getAlignmentView(
1696 boolean selectedOnly, boolean markGroups)
1698 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1700 alignment.getHiddenColumns() != null
1701 && alignment.getHiddenColumns().hasHiddenColumns(),
1702 selectedOnly, markGroups);
1706 public String[] getViewAsString(boolean selectedRegionOnly)
1708 return getViewAsString(selectedRegionOnly, true);
1712 public String[] getViewAsString(boolean selectedRegionOnly,
1713 boolean exportHiddenSeqs)
1715 String[] selection = null;
1716 SequenceI[] seqs = null;
1718 int start = 0, end = 0;
1719 if (selectedRegionOnly && selectionGroup != null)
1721 iSize = selectionGroup.getSize();
1722 seqs = selectionGroup.getSequencesInOrder(alignment);
1723 start = selectionGroup.getStartRes();
1724 end = selectionGroup.getEndRes() + 1;
1728 if (hasHiddenRows() && exportHiddenSeqs)
1730 AlignmentI fullAlignment = alignment.getHiddenSequences()
1731 .getFullAlignment();
1732 iSize = fullAlignment.getHeight();
1733 seqs = fullAlignment.getSequencesArray();
1734 end = fullAlignment.getWidth();
1738 iSize = alignment.getHeight();
1739 seqs = alignment.getSequencesArray();
1740 end = alignment.getWidth();
1744 selection = new String[iSize];
1745 if (alignment.getHiddenColumns() != null
1746 && alignment.getHiddenColumns().hasHiddenColumns())
1748 for (i = 0; i < iSize; i++)
1750 Iterator<int[]> blocks = alignment.getHiddenColumns()
1751 .getVisContigsIterator(start, end + 1, false);
1752 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1757 for (i = 0; i < iSize; i++)
1759 selection[i] = seqs[i].getSequenceAsString(start, end);
1767 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1769 ArrayList<int[]> regions = new ArrayList<>();
1775 HiddenColumns hidden = alignment.getHiddenColumns();
1776 if (hidden != null && hidden.hasHiddenColumns())
1780 start = hidden.visibleToAbsoluteColumn(start);
1783 end = hidden.getNextHiddenBoundary(false, start);
1794 regions.add(new int[] { start, end });
1796 if (hidden != null && hidden.hasHiddenColumns())
1798 start = hidden.visibleToAbsoluteColumn(end);
1799 start = hidden.getNextHiddenBoundary(true, start) + 1;
1801 } while (end < max);
1803 int[][] startEnd = new int[regions.size()][2];
1809 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1810 boolean selectedOnly)
1812 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1813 AlignmentAnnotation[] aa;
1814 if ((aa = alignment.getAlignmentAnnotation()) != null)
1816 for (AlignmentAnnotation annot : aa)
1818 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1819 if (selectedOnly && selectionGroup != null)
1821 clone.makeVisibleAnnotation(
1822 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1823 alignment.getHiddenColumns());
1827 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1836 public boolean isPadGaps()
1842 public void setPadGaps(boolean padGaps)
1844 this.padGaps = padGaps;
1848 * apply any post-edit constraints and trigger any calculations needed after
1849 * an edit has been performed on the alignment
1854 public void alignmentChanged(AlignmentViewPanel ap)
1858 alignment.padGaps();
1860 if (autoCalculateConsensus)
1862 updateConsensus(ap);
1864 if (hconsensus != null && autoCalculateConsensus)
1866 updateConservation(ap);
1868 if (autoCalculateStrucConsensus)
1870 updateStrucConsensus(ap);
1873 // Reset endRes of groups if beyond alignment width
1874 int alWidth = alignment.getWidth();
1875 List<SequenceGroup> groups = alignment.getGroups();
1878 for (SequenceGroup sg : groups)
1880 if (sg.getEndRes() > alWidth)
1882 sg.setEndRes(alWidth - 1);
1887 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1889 selectionGroup.setEndRes(alWidth - 1);
1892 updateAllColourSchemes();
1893 calculator.restartWorkers();
1894 // alignment.adjustSequenceAnnotations();
1898 * reset scope and do calculations for all applied colourschemes on alignment
1900 void updateAllColourSchemes()
1902 ResidueShaderI rs = residueShading;
1905 rs.alignmentChanged(alignment, hiddenRepSequences);
1907 rs.setConsensus(hconsensus);
1908 if (rs.conservationApplied())
1910 rs.setConservation(Conservation.calculateConservation("All",
1911 alignment.getSequences(), 0, alignment.getWidth(), false,
1912 getConsPercGaps(), false));
1916 for (SequenceGroup sg : alignment.getGroups())
1920 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1922 sg.recalcConservation();
1926 protected void initAutoAnnotation()
1928 // TODO: add menu option action that nulls or creates consensus object
1929 // depending on if the user wants to see the annotation or not in a
1930 // specific alignment
1932 if (hconsensus == null && !isDataset)
1934 if (!alignment.isNucleotide())
1943 consensus = new AlignmentAnnotation("Consensus",
1944 MessageManager.getString("label.consensus_descr"),
1945 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1946 initConsensus(consensus);
1949 initComplementConsensus();
1954 * If this is a protein alignment and there are mappings to cDNA, adds the
1955 * cDNA consensus annotation and returns true, else returns false.
1957 public boolean initComplementConsensus()
1959 if (!alignment.isNucleotide())
1961 final List<AlignedCodonFrame> codonMappings = alignment
1963 if (codonMappings != null && !codonMappings.isEmpty())
1965 boolean doConsensus = false;
1966 for (AlignedCodonFrame mapping : codonMappings)
1968 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1969 MapList[] mapLists = mapping.getdnaToProt();
1970 // mapLists can be empty if project load has not finished resolving
1972 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1980 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1982 .getString("label.complement_consensus_descr"),
1983 new Annotation[1], 0f, 100f,
1984 AlignmentAnnotation.BAR_GRAPH);
1985 initConsensus(complementConsensus);
1993 private void initConsensus(AlignmentAnnotation aa)
1996 aa.autoCalculated = true;
2000 alignment.addAnnotation(aa);
2004 // these should be extracted from the view model - style and settings for
2005 // derived annotation
2006 private void initGapCounts()
2010 gapcounts = new AlignmentAnnotation("Occupancy",
2011 MessageManager.getString("label.occupancy_descr"),
2012 new Annotation[1], 0f, alignment.getHeight(),
2013 AlignmentAnnotation.BAR_GRAPH);
2014 gapcounts.hasText = true;
2015 gapcounts.autoCalculated = true;
2016 gapcounts.scaleColLabel = true;
2017 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2019 alignment.addAnnotation(gapcounts);
2023 private void initConservation()
2025 if (showConservation)
2027 if (conservation == null)
2029 conservation = new AlignmentAnnotation("Conservation",
2030 MessageManager.formatMessage("label.conservation_descr",
2032 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2033 conservation.hasText = true;
2034 conservation.autoCalculated = true;
2035 alignment.addAnnotation(conservation);
2040 private void initQuality()
2044 if (quality == null)
2046 quality = new AlignmentAnnotation("Quality",
2047 MessageManager.getString("label.quality_descr"),
2048 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2049 quality.hasText = true;
2050 quality.autoCalculated = true;
2051 alignment.addAnnotation(quality);
2056 private void initRNAStructure()
2058 if (alignment.hasRNAStructure() && strucConsensus == null)
2060 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2061 MessageManager.getString("label.strucconsensus_descr"),
2062 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2063 strucConsensus.hasText = true;
2064 strucConsensus.autoCalculated = true;
2068 alignment.addAnnotation(strucConsensus);
2076 * @see jalview.api.AlignViewportI#calcPanelHeight()
2079 public int calcPanelHeight()
2081 // setHeight of panels
2082 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2084 int charHeight = getCharHeight();
2087 BitSet graphgrp = new BitSet();
2088 for (AlignmentAnnotation aa : anns)
2092 System.err.println("Null annotation row: ignoring.");
2099 if (aa.graphGroup > -1)
2101 if (graphgrp.get(aa.graphGroup))
2107 graphgrp.set(aa.graphGroup);
2114 aa.height += charHeight;
2124 aa.height += aa.graphHeight;
2132 height += aa.height;
2144 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2145 boolean preserveNewGroupSettings)
2147 boolean updateCalcs = false;
2148 boolean conv = isShowGroupConservation();
2149 boolean cons = isShowGroupConsensus();
2150 boolean showprf = isShowSequenceLogo();
2151 boolean showConsHist = isShowConsensusHistogram();
2152 boolean normLogo = isNormaliseSequenceLogo();
2155 * TODO reorder the annotation rows according to group/sequence ordering on
2158 boolean sortg = true;
2160 // remove old automatic annotation
2161 // add any new annotation
2163 // intersect alignment annotation with alignment groups
2165 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2166 List<SequenceGroup> oldrfs = new ArrayList<>();
2169 for (int an = 0; an < aan.length; an++)
2171 if (aan[an].autoCalculated && aan[an].groupRef != null)
2173 oldrfs.add(aan[an].groupRef);
2174 alignment.deleteAnnotation(aan[an], false);
2178 if (alignment.getGroups() != null)
2180 for (SequenceGroup sg : alignment.getGroups())
2182 updateCalcs = false;
2183 if (applyGlobalSettings
2184 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2186 // set defaults for this group's conservation/consensus
2187 sg.setshowSequenceLogo(showprf);
2188 sg.setShowConsensusHistogram(showConsHist);
2189 sg.setNormaliseSequenceLogo(normLogo);
2194 alignment.addAnnotation(sg.getConservationRow(), 0);
2199 alignment.addAnnotation(sg.getConsensus(), 0);
2201 // refresh the annotation rows
2204 sg.recalcConservation();
2212 public boolean isDisplayReferenceSeq()
2214 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2218 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2220 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2224 public boolean isColourByReferenceSeq()
2226 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2230 public Color getSequenceColour(SequenceI seq)
2232 Color sqc = sequenceColours.get(seq);
2233 return (sqc == null ? Color.white : sqc);
2237 public void setSequenceColour(SequenceI seq, Color col)
2241 sequenceColours.remove(seq);
2245 sequenceColours.put(seq, col);
2250 public void updateSequenceIdColours()
2252 for (SequenceGroup sg : alignment.getGroups())
2254 if (sg.idColour != null)
2256 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2258 sequenceColours.put(s, sg.idColour);
2265 public void clearSequenceColours()
2267 sequenceColours.clear();
2271 public AlignViewportI getCodingComplement()
2273 return this.codingComplement;
2277 * Set this as the (cDna/protein) complement of the given viewport. Also
2278 * ensures the reverse relationship is set on the given viewport.
2281 public void setCodingComplement(AlignViewportI av)
2285 System.err.println("Ignoring recursive setCodingComplement request");
2289 this.codingComplement = av;
2290 // avoid infinite recursion!
2291 if (av.getCodingComplement() != this)
2293 av.setCodingComplement(this);
2299 public boolean isNucleotide()
2301 return getAlignment() == null ? false : getAlignment().isNucleotide();
2305 public FeaturesDisplayedI getFeaturesDisplayed()
2307 return featuresDisplayed;
2311 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2313 featuresDisplayed = featuresDisplayedI;
2317 public boolean areFeaturesDisplayed()
2319 return featuresDisplayed != null
2320 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2327 * features are displayed if true
2330 public void setShowSequenceFeatures(boolean b)
2332 viewStyle.setShowSequenceFeatures(b);
2336 public boolean isShowSequenceFeatures()
2338 return viewStyle.isShowSequenceFeatures();
2342 public void setShowSequenceFeaturesHeight(boolean selected)
2344 viewStyle.setShowSequenceFeaturesHeight(selected);
2348 public boolean isShowSequenceFeaturesHeight()
2350 return viewStyle.isShowSequenceFeaturesHeight();
2354 public void setShowAnnotation(boolean b)
2356 viewStyle.setShowAnnotation(b);
2360 public boolean isShowAnnotation()
2362 return viewStyle.isShowAnnotation();
2366 public boolean isRightAlignIds()
2368 return viewStyle.isRightAlignIds();
2372 public void setRightAlignIds(boolean rightAlignIds)
2374 viewStyle.setRightAlignIds(rightAlignIds);
2378 public boolean getConservationSelected()
2380 return viewStyle.getConservationSelected();
2384 public void setShowBoxes(boolean state)
2386 viewStyle.setShowBoxes(state);
2391 * @see jalview.api.ViewStyleI#getTextColour()
2394 public Color getTextColour()
2396 return viewStyle.getTextColour();
2401 * @see jalview.api.ViewStyleI#getTextColour2()
2404 public Color getTextColour2()
2406 return viewStyle.getTextColour2();
2411 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2414 public int getThresholdTextColour()
2416 return viewStyle.getThresholdTextColour();
2421 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2424 public boolean isConservationColourSelected()
2426 return viewStyle.isConservationColourSelected();
2431 * @see jalview.api.ViewStyleI#isRenderGaps()
2434 public boolean isRenderGaps()
2436 return viewStyle.isRenderGaps();
2441 * @see jalview.api.ViewStyleI#isShowColourText()
2444 public boolean isShowColourText()
2446 return viewStyle.isShowColourText();
2450 * @param conservationColourSelected
2451 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2454 public void setConservationColourSelected(
2455 boolean conservationColourSelected)
2457 viewStyle.setConservationColourSelected(conservationColourSelected);
2461 * @param showColourText
2462 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2465 public void setShowColourText(boolean showColourText)
2467 viewStyle.setShowColourText(showColourText);
2472 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2475 public void setTextColour(Color textColour)
2477 viewStyle.setTextColour(textColour);
2481 * @param thresholdTextColour
2482 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2485 public void setThresholdTextColour(int thresholdTextColour)
2487 viewStyle.setThresholdTextColour(thresholdTextColour);
2491 * @param textColour2
2492 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2495 public void setTextColour2(Color textColour2)
2497 viewStyle.setTextColour2(textColour2);
2501 public ViewStyleI getViewStyle()
2503 return new ViewStyle(viewStyle);
2507 public void setViewStyle(ViewStyleI settingsForView)
2509 viewStyle = new ViewStyle(settingsForView);
2510 if (residueShading != null)
2512 residueShading.setConservationApplied(
2513 settingsForView.isConservationColourSelected());
2518 public boolean sameStyle(ViewStyleI them)
2520 return viewStyle.sameStyle(them);
2525 * @see jalview.api.ViewStyleI#getIdWidth()
2528 public int getIdWidth()
2530 return viewStyle.getIdWidth();
2535 * @see jalview.api.ViewStyleI#setIdWidth(int)
2538 public void setIdWidth(int i)
2540 viewStyle.setIdWidth(i);
2545 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2548 public boolean isCentreColumnLabels()
2550 return viewStyle.isCentreColumnLabels();
2554 * @param centreColumnLabels
2555 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2558 public void setCentreColumnLabels(boolean centreColumnLabels)
2560 viewStyle.setCentreColumnLabels(centreColumnLabels);
2565 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2568 public void setShowDBRefs(boolean showdbrefs)
2570 viewStyle.setShowDBRefs(showdbrefs);
2575 * @see jalview.api.ViewStyleI#isShowDBRefs()
2578 public boolean isShowDBRefs()
2580 return viewStyle.isShowDBRefs();
2585 * @see jalview.api.ViewStyleI#isShowNPFeats()
2588 public boolean isShowNPFeats()
2590 return viewStyle.isShowNPFeats();
2594 * @param shownpfeats
2595 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2598 public void setShowNPFeats(boolean shownpfeats)
2600 viewStyle.setShowNPFeats(shownpfeats);
2603 public abstract StructureSelectionManager getStructureSelectionManager();
2606 * Add one command to the command history list.
2610 public void addToHistoryList(CommandI command)
2612 if (this.historyList != null)
2614 this.historyList.push(command);
2615 broadcastCommand(command, false);
2619 protected void broadcastCommand(CommandI command, boolean undo)
2621 getStructureSelectionManager().commandPerformed(command, undo,
2626 * Add one command to the command redo list.
2630 public void addToRedoList(CommandI command)
2632 if (this.redoList != null)
2634 this.redoList.push(command);
2636 broadcastCommand(command, true);
2640 * Clear the command redo list.
2642 public void clearRedoList()
2644 if (this.redoList != null)
2646 this.redoList.clear();
2650 public void setHistoryList(Deque<CommandI> list)
2652 this.historyList = list;
2655 public Deque<CommandI> getHistoryList()
2657 return this.historyList;
2660 public void setRedoList(Deque<CommandI> list)
2662 this.redoList = list;
2665 public Deque<CommandI> getRedoList()
2667 return this.redoList;
2671 public VamsasSource getVamsasSource()
2676 public SequenceAnnotationOrder getSortAnnotationsBy()
2678 return sortAnnotationsBy;
2681 public void setSortAnnotationsBy(
2682 SequenceAnnotationOrder sortAnnotationsBy)
2684 this.sortAnnotationsBy = sortAnnotationsBy;
2687 public boolean isShowAutocalculatedAbove()
2689 return showAutocalculatedAbove;
2692 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2694 this.showAutocalculatedAbove = showAutocalculatedAbove;
2698 public boolean isScaleProteinAsCdna()
2700 return viewStyle.isScaleProteinAsCdna();
2704 public void setScaleProteinAsCdna(boolean b)
2706 viewStyle.setScaleProteinAsCdna(b);
2710 public boolean isProteinFontAsCdna()
2712 return viewStyle.isProteinFontAsCdna();
2716 public void setProteinFontAsCdna(boolean b)
2718 viewStyle.setProteinFontAsCdna(b);
2722 * @return true if view should scroll to show the highlighted region of a
2727 public final boolean isFollowHighlight()
2729 return followHighlight;
2733 public final void setFollowHighlight(boolean b)
2735 this.followHighlight = b;
2739 public ViewportRanges getRanges()
2745 * Helper method to populate the SearchResults with the location in the
2746 * complementary alignment to scroll to, in order to match this one.
2749 * the SearchResults to add to
2750 * @return the offset (below top of visible region) of the matched sequence
2752 protected int findComplementScrollTarget(SearchResultsI sr)
2754 final AlignViewportI complement = getCodingComplement();
2755 if (complement == null || !complement.isFollowHighlight())
2759 boolean iAmProtein = !getAlignment().isNucleotide();
2760 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2761 : complement.getAlignment();
2762 if (proteinAlignment == null)
2766 final List<AlignedCodonFrame> mappings = proteinAlignment
2770 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2771 * residue in the middle column of the visible region. Scroll the
2772 * complementary alignment to line up the corresponding residue.
2775 SequenceI sequence = null;
2778 * locate 'middle' column (true middle if an odd number visible, left of
2779 * middle if an even number visible)
2781 int middleColumn = ranges.getStartRes()
2782 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2783 final HiddenSequences hiddenSequences = getAlignment()
2784 .getHiddenSequences();
2787 * searching to the bottom of the alignment gives smoother scrolling across
2788 * all gapped visible regions
2790 int lastSeq = alignment.getHeight() - 1;
2791 List<AlignedCodonFrame> seqMappings = null;
2792 for (int seqNo = ranges
2793 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2795 sequence = getAlignment().getSequenceAt(seqNo);
2796 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2800 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2804 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2806 getCodingComplement().getAlignment().getSequences());
2807 if (!seqMappings.isEmpty())
2813 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2816 * No ungapped mapped sequence in middle column - do nothing
2820 MappingUtils.addSearchResults(sr, sequence,
2821 sequence.findPosition(middleColumn), seqMappings);
2826 * synthesize a column selection if none exists so it covers the given
2827 * selection group. if wholewidth is false, no column selection is made if the
2828 * selection group covers the whole alignment width.
2833 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2836 if (sg != null && (sgs = sg.getStartRes()) >= 0
2837 && sg.getStartRes() <= (sge = sg.getEndRes())
2838 && !this.hasSelectedColumns())
2840 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2847 colSel = new ColumnSelection();
2849 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2851 colSel.addElement(cspos);
2857 * hold status of current selection group - defined on alignment or not.
2859 private boolean selectionIsDefinedGroup = false;
2862 public boolean isSelectionDefinedGroup()
2864 if (selectionGroup == null)
2868 if (isSelectionGroupChanged(true))
2870 selectionIsDefinedGroup = false;
2871 List<SequenceGroup> gps = alignment.getGroups();
2872 if (gps == null || gps.size() == 0)
2874 selectionIsDefinedGroup = false;
2878 selectionIsDefinedGroup = gps.contains(selectionGroup);
2881 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2885 * null, or currently highlighted results on this view
2887 private SearchResultsI searchResults = null;
2889 protected TreeModel currentTree = null;
2892 public boolean hasSearchResults()
2894 return searchResults != null;
2898 public void setSearchResults(SearchResultsI results)
2900 searchResults = results;
2904 public SearchResultsI getSearchResults()
2906 return searchResults;
2910 * get the consensus sequence as displayed under the PID consensus annotation
2913 * @return consensus sequence as a new sequence object
2915 public SequenceI getConsensusSeq()
2917 if (consensus == null)
2919 updateConsensus(null);
2921 if (consensus == null)
2925 StringBuffer seqs = new StringBuffer();
2926 for (int i = 0; i < consensus.annotations.length; i++)
2928 Annotation annotation = consensus.annotations[i];
2929 if (annotation != null)
2931 String description = annotation.description;
2932 if (description != null && description.startsWith("["))
2934 // consensus is a tie - just pick the first one
2935 seqs.append(description.charAt(1));
2939 seqs.append(annotation.displayCharacter);
2944 SequenceI sq = new Sequence("Consensus", seqs.toString());
2945 sq.setDescription("Percentage Identity Consensus "
2946 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2951 public void setCurrentTree(TreeModel tree)
2957 public TreeModel getCurrentTree()
2963 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
2965 AlignmentI alignmentToExport = null;
2966 String[] omitHidden = null;
2967 alignmentToExport = null;
2969 if (hasHiddenColumns() && !options.isExportHiddenColumns())
2971 omitHidden = getViewAsString(false,
2972 options.isExportHiddenSequences());
2975 int[] alignmentStartEnd = new int[2];
2976 if (hasHiddenRows() && options.isExportHiddenSequences())
2978 alignmentToExport = getAlignment().getHiddenSequences()
2979 .getFullAlignment();
2983 alignmentToExport = getAlignment();
2985 alignmentStartEnd = getAlignment().getHiddenColumns()
2986 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
2987 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
2988 omitHidden, alignmentStartEnd);
2993 * flag set to indicate if structure views might be out of sync with sequences
2997 private boolean needToUpdateStructureViews = false;
3000 public boolean isUpdateStructures()
3002 return needToUpdateStructureViews;
3006 public void setUpdateStructures(boolean update)
3008 needToUpdateStructureViews = update;
3012 public boolean needToUpdateStructureViews()
3014 boolean update = needToUpdateStructureViews;
3015 needToUpdateStructureViews = false;
3020 public void addSequenceGroup(SequenceGroup sequenceGroup)
3022 alignment.addGroup(sequenceGroup);
3024 Color col = sequenceGroup.idColour;
3027 col = col.brighter();
3029 for (SequenceI sq : sequenceGroup.getSequences())
3031 setSequenceColour(sq, col);
3035 if (codingComplement != null)
3037 SequenceGroup mappedGroup = MappingUtils
3038 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3039 if (mappedGroup.getSequences().size() > 0)
3041 codingComplement.getAlignment().addGroup(mappedGroup);
3045 for (SequenceI seq : mappedGroup.getSequences())
3047 codingComplement.setSequenceColour(seq, col);
3051 // propagate the structure view update flag according to our own setting
3052 codingComplement.setUpdateStructures(needToUpdateStructureViews);