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 java.awt.Color;
24 import java.beans.PropertyChangeSupport;
25 import java.util.ArrayDeque;
26 import java.util.ArrayList;
27 import java.util.BitSet;
28 import java.util.Deque;
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.List;
35 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
36 import jalview.analysis.Conservation;
37 import jalview.analysis.TreeModel;
38 import jalview.api.AlignCalcManagerI;
39 import jalview.api.AlignExportSettingsI;
40 import jalview.api.AlignViewportI;
41 import jalview.api.AlignmentViewPanel;
42 import jalview.api.FeaturesDisplayedI;
43 import jalview.api.ViewStyleI;
44 import jalview.bin.Console;
45 import jalview.commands.CommandI;
46 import jalview.datamodel.AlignedCodonFrame;
47 import jalview.datamodel.AlignmentAnnotation;
48 import jalview.datamodel.AlignmentExportData;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.AlignmentView;
51 import jalview.datamodel.Annotation;
52 import jalview.datamodel.ColumnSelection;
53 import jalview.datamodel.ContactListI;
54 import jalview.datamodel.ContactMatrixI;
55 import jalview.datamodel.HiddenColumns;
56 import jalview.datamodel.HiddenSequences;
57 import jalview.datamodel.ProfilesI;
58 import jalview.datamodel.SearchResultsI;
59 import jalview.datamodel.Sequence;
60 import jalview.datamodel.SequenceCollectionI;
61 import jalview.datamodel.SequenceGroup;
62 import jalview.datamodel.SequenceI;
63 import jalview.gui.QuitHandler;
64 import jalview.project.Jalview2XML;
65 import jalview.renderer.ResidueShader;
66 import jalview.renderer.ResidueShaderI;
67 import jalview.schemes.ColourSchemeI;
68 import jalview.structure.CommandListener;
69 import jalview.structure.StructureSelectionManager;
70 import jalview.structure.VamsasSource;
71 import jalview.util.Comparison;
72 import jalview.util.MapList;
73 import jalview.util.MappingUtils;
74 import jalview.util.MessageManager;
75 import jalview.viewmodel.styles.ViewStyle;
76 import jalview.workers.AlignCalcManager;
77 import jalview.workers.ComplementConsensusThread;
78 import jalview.workers.ConsensusThread;
79 import jalview.workers.StrucConsensusThread;
82 * base class holding visualization and analysis attributes and common logic for
83 * an active alignment view displayed in the GUI
88 public abstract class AlignmentViewport
89 implements AlignViewportI, CommandListener, VamsasSource
91 protected ViewportRanges ranges;
93 protected ViewStyleI viewStyle = new ViewStyle();
96 * A viewport that hosts the cDna view of this (protein), or vice versa (if
99 AlignViewportI codingComplement = null;
101 FeaturesDisplayedI featuresDisplayed = null;
103 protected Deque<CommandI> historyList = new ArrayDeque<>();
105 protected Deque<CommandI> redoList = new ArrayDeque<>();
108 * used to determine if quit should be confirmed
110 private boolean savedUpToDate = false;
113 * alignment displayed in the viewport. Please use get/setter
115 protected AlignmentI alignment;
117 public AlignmentViewport(AlignmentI al)
120 ranges = new ViewportRanges(al);
125 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
128 public void setFontName(String name)
130 viewStyle.setFontName(name);
135 * @see jalview.api.ViewStyleI#setFontStyle(int)
138 public void setFontStyle(int style)
140 viewStyle.setFontStyle(style);
145 * @see jalview.api.ViewStyleI#setFontSize(int)
148 public void setFontSize(int size)
150 viewStyle.setFontSize(size);
155 * @see jalview.api.ViewStyleI#getFontStyle()
158 public int getFontStyle()
160 return viewStyle.getFontStyle();
165 * @see jalview.api.ViewStyleI#getFontName()
168 public String getFontName()
170 return viewStyle.getFontName();
175 * @see jalview.api.ViewStyleI#getFontSize()
178 public int getFontSize()
180 return viewStyle.getFontSize();
184 * @param upperCasebold
185 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
188 public void setUpperCasebold(boolean upperCasebold)
190 viewStyle.setUpperCasebold(upperCasebold);
195 * @see jalview.api.ViewStyleI#isUpperCasebold()
198 public boolean isUpperCasebold()
200 return viewStyle.isUpperCasebold();
205 * @see jalview.api.ViewStyleI#isSeqNameItalics()
208 public boolean isSeqNameItalics()
210 return viewStyle.isSeqNameItalics();
214 * @param colourByReferenceSeq
215 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
218 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
220 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
225 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
228 public void setColourAppliesToAllGroups(boolean b)
230 viewStyle.setColourAppliesToAllGroups(b);
235 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
238 public boolean getColourAppliesToAllGroups()
240 return viewStyle.getColourAppliesToAllGroups();
245 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
248 public boolean getAbovePIDThreshold()
250 return viewStyle.getAbovePIDThreshold();
255 * @see jalview.api.ViewStyleI#setIncrement(int)
258 public void setIncrement(int inc)
260 viewStyle.setIncrement(inc);
265 * @see jalview.api.ViewStyleI#getIncrement()
268 public int getIncrement()
270 return viewStyle.getIncrement();
275 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
278 public void setConservationSelected(boolean b)
280 viewStyle.setConservationSelected(b);
285 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
288 public void setShowHiddenMarkers(boolean show)
290 viewStyle.setShowHiddenMarkers(show);
295 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
298 public boolean getShowHiddenMarkers()
300 return viewStyle.getShowHiddenMarkers();
305 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
308 public void setScaleRightWrapped(boolean b)
310 viewStyle.setScaleRightWrapped(b);
315 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
318 public void setScaleLeftWrapped(boolean b)
320 viewStyle.setScaleLeftWrapped(b);
325 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
328 public void setScaleAboveWrapped(boolean b)
330 viewStyle.setScaleAboveWrapped(b);
335 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
338 public boolean getScaleLeftWrapped()
340 return viewStyle.getScaleLeftWrapped();
345 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
348 public boolean getScaleAboveWrapped()
350 return viewStyle.getScaleAboveWrapped();
355 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
358 public boolean getScaleRightWrapped()
360 return viewStyle.getScaleRightWrapped();
365 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
368 public void setAbovePIDThreshold(boolean b)
370 viewStyle.setAbovePIDThreshold(b);
375 * @see jalview.api.ViewStyleI#setThreshold(int)
378 public void setThreshold(int thresh)
380 viewStyle.setThreshold(thresh);
385 * @see jalview.api.ViewStyleI#getThreshold()
388 public int getThreshold()
390 return viewStyle.getThreshold();
395 * @see jalview.api.ViewStyleI#getShowJVSuffix()
398 public boolean getShowJVSuffix()
400 return viewStyle.getShowJVSuffix();
405 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
408 public void setShowJVSuffix(boolean b)
410 viewStyle.setShowJVSuffix(b);
415 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
418 public void setWrapAlignment(boolean state)
420 viewStyle.setWrapAlignment(state);
421 ranges.setWrappedMode(state);
426 * @see jalview.api.ViewStyleI#setShowText(boolean)
429 public void setShowText(boolean state)
431 viewStyle.setShowText(state);
436 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
439 public void setRenderGaps(boolean state)
441 viewStyle.setRenderGaps(state);
446 * @see jalview.api.ViewStyleI#getColourText()
449 public boolean getColourText()
451 return viewStyle.getColourText();
456 * @see jalview.api.ViewStyleI#setColourText(boolean)
459 public void setColourText(boolean state)
461 viewStyle.setColourText(state);
466 * @see jalview.api.ViewStyleI#getWrapAlignment()
469 public boolean getWrapAlignment()
471 return viewStyle.getWrapAlignment();
476 * @see jalview.api.ViewStyleI#getShowText()
479 public boolean getShowText()
481 return viewStyle.getShowText();
486 * @see jalview.api.ViewStyleI#getWrappedWidth()
489 public int getWrappedWidth()
491 return viewStyle.getWrappedWidth();
496 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
499 public void setWrappedWidth(int w)
501 viewStyle.setWrappedWidth(w);
506 * @see jalview.api.ViewStyleI#getCharHeight()
509 public int getCharHeight()
511 return viewStyle.getCharHeight();
516 * @see jalview.api.ViewStyleI#setCharHeight(int)
519 public void setCharHeight(int h)
521 viewStyle.setCharHeight(h);
526 * @see jalview.api.ViewStyleI#getCharWidth()
529 public int getCharWidth()
531 return viewStyle.getCharWidth();
536 * @see jalview.api.ViewStyleI#setCharWidth(int)
539 public void setCharWidth(int w)
541 viewStyle.setCharWidth(w);
546 * @see jalview.api.ViewStyleI#getShowBoxes()
549 public boolean getShowBoxes()
551 return viewStyle.getShowBoxes();
556 * @see jalview.api.ViewStyleI#getShowUnconserved()
559 public boolean getShowUnconserved()
561 return viewStyle.getShowUnconserved();
565 * @param showunconserved
566 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
569 public void setShowUnconserved(boolean showunconserved)
571 viewStyle.setShowUnconserved(showunconserved);
576 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
579 public void setSeqNameItalics(boolean default1)
581 viewStyle.setSeqNameItalics(default1);
585 public AlignmentI getAlignment()
591 public char getGapCharacter()
593 return alignment.getGapCharacter();
596 protected String sequenceSetID;
599 * probably unused indicator that view is of a dataset rather than an
602 protected boolean isDataset = false;
604 public void setDataset(boolean b)
609 public boolean isDataset()
614 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
616 protected ColumnSelection colSel = new ColumnSelection();
618 public boolean autoCalculateConsensus = true;
620 protected boolean autoCalculateStrucConsensus = true;
622 protected boolean ignoreGapsInConsensusCalculation = false;
624 protected ResidueShaderI residueShading = new ResidueShader();
627 public void setGlobalColourScheme(ColourSchemeI cs)
629 // TODO: logic refactored from AlignFrame changeColour -
630 // TODO: autorecalc stuff should be changed to rely on the worker system
631 // check to see if we should implement a changeColour(cs) method rather than
632 // put the logic in here
633 // - means that caller decides if they want to just modify state and defer
634 // calculation till later or to do all calculations in thread.
638 * only instantiate alignment colouring once, thereafter update it;
639 * this means that any conservation or PID threshold settings
640 * persist when the alignment colour scheme is changed
642 if (residueShading == null)
644 residueShading = new ResidueShader(viewStyle);
646 residueShading.setColourScheme(cs);
648 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
649 // ...problem: groups need these, but do not currently have a ViewStyle
653 if (getConservationSelected())
655 residueShading.setConservation(hconservation);
658 * reset conservation flag in case just set to false if
659 * Conservation was null (calculation still in progress)
661 residueShading.setConservationApplied(getConservationSelected());
662 residueShading.alignmentChanged(alignment, hiddenRepSequences);
666 * if 'apply colour to all groups' is selected... do so
667 * (but don't transfer any colour threshold settings to groups)
669 if (getColourAppliesToAllGroups())
671 for (SequenceGroup sg : getAlignment().getGroups())
674 * retain any colour thresholds per group while
675 * changing choice of colour scheme (JAL-2386)
677 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
680 sg.getGroupColourScheme().alignmentChanged(sg,
688 public ColourSchemeI getGlobalColourScheme()
690 return residueShading == null ? null : residueShading.getColourScheme();
694 public ResidueShaderI getResidueShading()
696 return residueShading;
699 protected AlignmentAnnotation consensus;
701 protected AlignmentAnnotation complementConsensus;
703 protected AlignmentAnnotation gapcounts;
705 protected AlignmentAnnotation strucConsensus;
707 protected AlignmentAnnotation conservation;
709 protected AlignmentAnnotation quality;
711 protected AlignmentAnnotation[] groupConsensus;
713 protected AlignmentAnnotation[] groupConservation;
716 * results of alignment consensus analysis for visible portion of view
718 protected ProfilesI hconsensus = null;
721 * results of cDNA complement consensus visible portion of view
723 protected Hashtable<String, Object>[] hcomplementConsensus = null;
726 * results of secondary structure base pair consensus for visible portion of
729 protected Hashtable<String, Object>[] hStrucConsensus = null;
731 protected Conservation hconservation = null;
734 public void setConservation(Conservation cons)
736 hconservation = cons;
740 * percentage gaps allowed in a column before all amino acid properties should
741 * be considered unconserved
743 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
746 public int getConsPercGaps()
752 public void setSequenceConsensusHash(ProfilesI hconsensus)
754 this.hconsensus = hconsensus;
758 public void setComplementConsensusHash(
759 Hashtable<String, Object>[] hconsensus)
761 this.hcomplementConsensus = hconsensus;
765 public ProfilesI getSequenceConsensusHash()
771 public Hashtable<String, Object>[] getComplementConsensusHash()
773 return hcomplementConsensus;
777 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
779 return hStrucConsensus;
783 public void setRnaStructureConsensusHash(
784 Hashtable<String, Object>[] hStrucConsensus)
786 this.hStrucConsensus = hStrucConsensus;
791 public AlignmentAnnotation getAlignmentQualityAnnot()
797 public AlignmentAnnotation getAlignmentConservationAnnotation()
803 public AlignmentAnnotation getAlignmentConsensusAnnotation()
809 public AlignmentAnnotation getAlignmentGapAnnotation()
815 public AlignmentAnnotation getComplementConsensusAnnotation()
817 return complementConsensus;
821 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
823 return strucConsensus;
826 protected AlignCalcManagerI calculator = new AlignCalcManager();
829 * trigger update of conservation annotation
831 public void updateConservation(final AlignmentViewPanel ap)
833 // see note in mantis : issue number 8585
834 if (alignment.isNucleotide()
835 || (conservation == null && quality == null)
836 || !autoCalculateConsensus)
840 if (calculator.getRegisteredWorkersOfClass(
841 jalview.workers.ConservationThread.class) == null)
843 calculator.registerWorker(
844 new jalview.workers.ConservationThread(this, ap));
849 * trigger update of consensus annotation
851 public void updateConsensus(final AlignmentViewPanel ap)
853 // see note in mantis : issue number 8585
854 if (consensus == null || !autoCalculateConsensus)
859 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
861 calculator.registerWorker(new ConsensusThread(this, ap));
865 * A separate thread to compute cDNA consensus for a protein alignment
866 * which has mapping to cDNA
868 final AlignmentI al = this.getAlignment();
869 if (!al.isNucleotide() && al.getCodonFrames() != null
870 && !al.getCodonFrames().isEmpty())
873 * fudge - check first for protein-to-nucleotide mappings
874 * (we don't want to do this for protein-to-protein)
876 boolean doConsensus = false;
877 for (AlignedCodonFrame mapping : al.getCodonFrames())
879 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
880 MapList[] mapLists = mapping.getdnaToProt();
881 // mapLists can be empty if project load has not finished resolving seqs
882 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
890 if (calculator.getRegisteredWorkersOfClass(
891 ComplementConsensusThread.class) == null)
894 .registerWorker(new ComplementConsensusThread(this, ap));
900 // --------START Structure Conservation
901 public void updateStrucConsensus(final AlignmentViewPanel ap)
903 if (autoCalculateStrucConsensus && strucConsensus == null
904 && alignment.isNucleotide() && alignment.hasRNAStructure())
906 // secondary structure has been added - so init the consensus line
910 // see note in mantis : issue number 8585
911 if (strucConsensus == null || !autoCalculateStrucConsensus)
915 if (calculator.getRegisteredWorkersOfClass(
916 StrucConsensusThread.class) == null)
918 calculator.registerWorker(new StrucConsensusThread(this, ap));
922 public boolean isCalcInProgress()
924 return calculator.isWorking();
928 public boolean isCalculationInProgress(
929 AlignmentAnnotation alignmentAnnotation)
931 if (!alignmentAnnotation.autoCalculated)
935 if (calculator.workingInvolvedWith(alignmentAnnotation))
937 // jalview.bin.Console.errPrintln("grey out
938 // ("+alignmentAnnotation.label+")");
944 public void setAlignment(AlignmentI align)
946 this.alignment = align;
950 * Clean up references when this viewport is closed
953 public void dispose()
956 * defensively null out references to large objects in case
957 * this object is not garbage collected (as if!)
960 complementConsensus = null;
961 strucConsensus = null;
964 groupConsensus = null;
965 groupConservation = null;
967 hconservation = null;
968 hcomplementConsensus = null;
971 residueShading = null; // may hold a reference to Consensus
972 changeSupport = null;
975 selectionGroup = null;
981 public boolean isClosed()
983 // TODO: check that this isClosed is only true after panel is closed, not
984 // before it is fully constructed.
985 return alignment == null;
989 public AlignCalcManagerI getCalcManager()
995 * should conservation rows be shown for groups
997 protected boolean showGroupConservation = false;
1000 * should consensus rows be shown for groups
1002 protected boolean showGroupConsensus = false;
1005 * should consensus profile be rendered by default
1007 protected boolean showSequenceLogo = false;
1010 * should consensus profile be rendered normalised to row height
1012 protected boolean normaliseSequenceLogo = false;
1015 * should consensus histograms be rendered by default
1017 protected boolean showConsensusHistogram = true;
1020 * @return the showConsensusProfile
1023 public boolean isShowSequenceLogo()
1025 return showSequenceLogo;
1029 * @param showSequenceLogo
1032 public void setShowSequenceLogo(boolean showSequenceLogo)
1034 if (showSequenceLogo != this.showSequenceLogo)
1036 // TODO: decouple settings setting from calculation when refactoring
1037 // annotation update method from alignframe to viewport
1038 this.showSequenceLogo = showSequenceLogo;
1039 calculator.updateAnnotationFor(ConsensusThread.class);
1040 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1041 calculator.updateAnnotationFor(StrucConsensusThread.class);
1043 this.showSequenceLogo = showSequenceLogo;
1047 * @param showConsensusHistogram
1048 * the showConsensusHistogram to set
1050 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1052 this.showConsensusHistogram = showConsensusHistogram;
1056 * @return the showGroupConservation
1058 public boolean isShowGroupConservation()
1060 return showGroupConservation;
1064 * @param showGroupConservation
1065 * the showGroupConservation to set
1067 public void setShowGroupConservation(boolean showGroupConservation)
1069 this.showGroupConservation = showGroupConservation;
1073 * @return the showGroupConsensus
1075 public boolean isShowGroupConsensus()
1077 return showGroupConsensus;
1081 * @param showGroupConsensus
1082 * the showGroupConsensus to set
1084 public void setShowGroupConsensus(boolean showGroupConsensus)
1086 this.showGroupConsensus = showGroupConsensus;
1091 * @return flag to indicate if the consensus histogram should be rendered by
1095 public boolean isShowConsensusHistogram()
1097 return this.showConsensusHistogram;
1101 * when set, updateAlignment will always ensure sequences are of equal length
1103 private boolean padGaps = false;
1106 * when set, alignment should be reordered according to a newly opened tree
1108 public boolean sortByTree = false;
1113 * @return null or the currently selected sequence region
1116 public SequenceGroup getSelectionGroup()
1118 return selectionGroup;
1122 * Set the selection group for this window. Also sets the current alignment as
1123 * the context for the group, if it does not already have one.
1126 * - group holding references to sequences in this alignment view
1130 public void setSelectionGroup(SequenceGroup sg)
1132 selectionGroup = sg;
1133 if (sg != null && sg.getContext() == null)
1135 sg.setContext(alignment);
1139 public void setHiddenColumns(HiddenColumns hidden)
1141 this.alignment.setHiddenColumns(hidden);
1145 public ColumnSelection getColumnSelection()
1151 public void setColumnSelection(ColumnSelection colSel)
1153 this.colSel = colSel;
1156 updateHiddenColumns();
1158 isColSelChanged(true);
1166 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1168 return hiddenRepSequences;
1172 public void setHiddenRepSequences(
1173 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1175 this.hiddenRepSequences = hiddenRepSequences;
1179 public boolean hasSelectedColumns()
1181 ColumnSelection columnSelection = getColumnSelection();
1182 return columnSelection != null && columnSelection.hasSelectedColumns();
1186 public boolean hasHiddenColumns()
1188 return alignment.getHiddenColumns() != null
1189 && alignment.getHiddenColumns().hasHiddenColumns();
1192 public void updateHiddenColumns()
1194 // this method doesn't really do anything now. But - it could, since a
1195 // column Selection could be in the process of modification
1196 // hasHiddenColumns = colSel.hasHiddenColumns();
1200 public boolean hasHiddenRows()
1202 return alignment.getHiddenSequences().getSize() > 0;
1205 protected SequenceGroup selectionGroup;
1207 public void setSequenceSetId(String newid)
1209 if (sequenceSetID != null)
1211 jalview.bin.Console.errPrintln(
1212 "Warning - overwriting a sequenceSetId for a viewport!");
1214 sequenceSetID = new String(newid);
1218 public String getSequenceSetId()
1220 if (sequenceSetID == null)
1222 sequenceSetID = alignment.hashCode() + "";
1225 return sequenceSetID;
1229 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1232 protected String viewId = null;
1235 public String getViewId()
1239 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1244 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1246 ignoreGapsInConsensusCalculation = b;
1249 updateConsensus(ap);
1250 if (residueShading != null)
1252 residueShading.setThreshold(residueShading.getThreshold(),
1253 ignoreGapsInConsensusCalculation);
1259 private long sgrouphash = -1, colselhash = -1;
1262 * checks current SelectionGroup against record of last hash value, and
1266 * update the record of last hash value
1268 * @return true if SelectionGroup changed since last call (when b is true)
1270 public boolean isSelectionGroupChanged(boolean b)
1272 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1273 : selectionGroup.hashCode();
1274 if (hc != -1 && hc != sgrouphash)
1286 * checks current colsel against record of last hash value, and optionally
1290 * update the record of last hash value
1291 * @return true if colsel changed since last call (when b is true)
1293 public boolean isColSelChanged(boolean b)
1295 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1296 if (hc != -1 && hc != colselhash)
1308 public boolean isIgnoreGapsConsensus()
1310 return ignoreGapsInConsensusCalculation;
1313 // property change stuff
1314 // JBPNote Prolly only need this in the applet version.
1315 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1318 protected boolean showConservation = true;
1320 protected boolean showQuality = true;
1322 protected boolean showConsensus = true;
1324 protected boolean showOccupancy = true;
1326 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1328 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1330 protected boolean showAutocalculatedAbove;
1333 * when set, view will scroll to show the highlighted position
1335 private boolean followHighlight = true;
1338 * Property change listener for changes in alignment
1343 public void addPropertyChangeListener(
1344 java.beans.PropertyChangeListener listener)
1346 changeSupport.addPropertyChangeListener(listener);
1355 public void removePropertyChangeListener(
1356 java.beans.PropertyChangeListener listener)
1358 if (changeSupport != null)
1360 changeSupport.removePropertyChangeListener(listener);
1365 * Property change listener for changes in alignment
1374 public void firePropertyChange(String prop, Object oldvalue,
1377 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1381 public void notifyAlignmentChanged()
1383 firePropertyChange("alignment", null, alignment);
1386 // common hide/show column stuff
1388 public void hideSelectedColumns()
1390 if (colSel.isEmpty())
1395 colSel.hideSelectedColumns(alignment);
1396 setSelectionGroup(null);
1397 isColSelChanged(true);
1400 public void hideColumns(int start, int end)
1404 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1408 alignment.getHiddenColumns().hideColumns(start, end);
1410 isColSelChanged(true);
1413 public void showColumn(int col)
1415 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1416 isColSelChanged(true);
1419 public void showAllHiddenColumns()
1421 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1422 isColSelChanged(true);
1425 // common hide/show seq stuff
1426 public void showAllHiddenSeqs()
1428 int startSeq = ranges.getStartSeq();
1429 int endSeq = ranges.getEndSeq();
1431 if (alignment.getHiddenSequences().getSize() > 0)
1433 if (selectionGroup == null)
1435 selectionGroup = new SequenceGroup();
1436 selectionGroup.setEndRes(alignment.getWidth() - 1);
1438 List<SequenceI> tmp = alignment.getHiddenSequences()
1439 .showAll(hiddenRepSequences);
1440 for (SequenceI seq : tmp)
1442 selectionGroup.addSequence(seq, false);
1443 setSequenceAnnotationsVisible(seq, true);
1446 hiddenRepSequences = null;
1448 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1450 firePropertyChange("alignment", null, alignment.getSequences());
1451 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1457 public void showSequence(int index)
1459 int startSeq = ranges.getStartSeq();
1460 int endSeq = ranges.getEndSeq();
1462 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1463 hiddenRepSequences);
1466 if (selectionGroup == null)
1468 selectionGroup = new SequenceGroup();
1469 selectionGroup.setEndRes(alignment.getWidth() - 1);
1472 for (SequenceI seq : tmp)
1474 selectionGroup.addSequence(seq, false);
1475 setSequenceAnnotationsVisible(seq, true);
1478 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1480 firePropertyChange("alignment", null, alignment.getSequences());
1485 public void hideAllSelectedSeqs()
1487 if (selectionGroup == null || selectionGroup.getSize() < 1)
1492 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1496 setSelectionGroup(null);
1499 public void hideSequence(SequenceI[] seq)
1502 * cache offset to first visible sequence
1504 int startSeq = ranges.getStartSeq();
1508 for (int i = 0; i < seq.length; i++)
1510 alignment.getHiddenSequences().hideSequence(seq[i]);
1511 setSequenceAnnotationsVisible(seq[i], false);
1513 ranges.setStartSeq(startSeq);
1514 firePropertyChange("alignment", null, alignment.getSequences());
1519 * Hides the specified sequence, or the sequences it represents
1522 * the sequence to hide, or keep as representative
1523 * @param representGroup
1524 * if true, hide the current selection group except for the
1525 * representative sequence
1527 public void hideSequences(SequenceI sequence, boolean representGroup)
1529 if (selectionGroup == null || selectionGroup.getSize() < 1)
1531 hideSequence(new SequenceI[] { sequence });
1537 hideRepSequences(sequence, selectionGroup);
1538 setSelectionGroup(null);
1542 int gsize = selectionGroup.getSize();
1543 SequenceI[] hseqs = selectionGroup.getSequences()
1544 .toArray(new SequenceI[gsize]);
1546 hideSequence(hseqs);
1547 setSelectionGroup(null);
1552 * Set visibility for any annotations for the given sequence.
1556 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1559 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1562 for (AlignmentAnnotation ann : anns)
1564 if (ann.sequenceRef == sequenceI)
1566 ann.visible = visible;
1572 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1574 int sSize = sg.getSize();
1580 if (hiddenRepSequences == null)
1582 hiddenRepSequences = new Hashtable<>();
1585 hiddenRepSequences.put(repSequence, sg);
1587 // Hide all sequences except the repSequence
1588 SequenceI[] seqs = new SequenceI[sSize - 1];
1590 for (int i = 0; i < sSize; i++)
1592 if (sg.getSequenceAt(i) != repSequence)
1594 if (index == sSize - 1)
1599 seqs[index++] = sg.getSequenceAt(i);
1602 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1603 sg.setHidereps(true); // note: not done in 2.7applet
1610 * @return null or the current reference sequence
1612 public SequenceI getReferenceSeq()
1614 return alignment.getSeqrep();
1619 * @return true iff seq is the reference for the alignment
1621 public boolean isReferenceSeq(SequenceI seq)
1623 return alignment.getSeqrep() == seq;
1629 * @return true if there are sequences represented by this sequence that are
1632 public boolean isHiddenRepSequence(SequenceI seq)
1634 return (hiddenRepSequences != null
1635 && hiddenRepSequences.containsKey(seq));
1641 * @return null or a sequence group containing the sequences that seq
1644 public SequenceGroup getRepresentedSequences(SequenceI seq)
1646 return (SequenceGroup) (hiddenRepSequences == null ? null
1647 : hiddenRepSequences.get(seq));
1651 public int adjustForHiddenSeqs(int alignmentIndex)
1653 return alignment.getHiddenSequences()
1654 .adjustForHiddenSeqs(alignmentIndex);
1658 public void invertColumnSelection()
1660 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1661 isColSelChanged(true);
1665 public SequenceI[] getSelectionAsNewSequence()
1667 SequenceI[] sequences;
1668 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1669 // this was the only caller in the applet for this method
1670 // JBPNote: in applet, this method returned references to the alignment
1671 // sequences, and it did not honour the presence/absence of annotation
1672 // attached to the alignment (probably!)
1673 if (selectionGroup == null || selectionGroup.getSize() == 0)
1675 sequences = alignment.getSequencesArray();
1676 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1677 for (int i = 0; i < sequences.length; i++)
1679 // construct new sequence with subset of visible annotation
1680 sequences[i] = new Sequence(sequences[i], annots);
1685 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1692 public SequenceI[] getSequenceSelection()
1694 SequenceI[] sequences = null;
1695 if (selectionGroup != null)
1697 sequences = selectionGroup.getSequencesInOrder(alignment);
1699 if (sequences == null)
1701 sequences = alignment.getSequencesArray();
1707 public jalview.datamodel.AlignmentView getAlignmentView(
1708 boolean selectedOnly)
1710 return getAlignmentView(selectedOnly, false);
1714 public jalview.datamodel.AlignmentView getAlignmentView(
1715 boolean selectedOnly, boolean markGroups)
1717 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1719 alignment.getHiddenColumns() != null
1720 && alignment.getHiddenColumns().hasHiddenColumns(),
1721 selectedOnly, markGroups);
1725 public String[] getViewAsString(boolean selectedRegionOnly)
1727 return getViewAsString(selectedRegionOnly, true);
1731 public String[] getViewAsString(boolean selectedRegionOnly,
1732 boolean exportHiddenSeqs)
1734 String[] selection = null;
1735 SequenceI[] seqs = null;
1737 int start = 0, end = 0;
1738 if (selectedRegionOnly && selectionGroup != null)
1740 iSize = selectionGroup.getSize();
1741 seqs = selectionGroup.getSequencesInOrder(alignment);
1742 start = selectionGroup.getStartRes();
1743 end = selectionGroup.getEndRes() + 1;
1747 if (hasHiddenRows() && exportHiddenSeqs)
1749 AlignmentI fullAlignment = alignment.getHiddenSequences()
1750 .getFullAlignment();
1751 iSize = fullAlignment.getHeight();
1752 seqs = fullAlignment.getSequencesArray();
1753 end = fullAlignment.getWidth();
1757 iSize = alignment.getHeight();
1758 seqs = alignment.getSequencesArray();
1759 end = alignment.getWidth();
1763 selection = new String[iSize];
1764 if (alignment.getHiddenColumns() != null
1765 && alignment.getHiddenColumns().hasHiddenColumns())
1767 for (i = 0; i < iSize; i++)
1769 Iterator<int[]> blocks = alignment.getHiddenColumns()
1770 .getVisContigsIterator(start, end + 1, false);
1771 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1776 for (i = 0; i < iSize; i++)
1778 selection[i] = seqs[i].getSequenceAsString(start, end);
1786 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1788 ArrayList<int[]> regions = new ArrayList<>();
1794 HiddenColumns hidden = alignment.getHiddenColumns();
1795 if (hidden != null && hidden.hasHiddenColumns())
1799 start = hidden.visibleToAbsoluteColumn(start);
1802 end = hidden.getNextHiddenBoundary(false, start);
1813 regions.add(new int[] { start, end });
1815 if (hidden != null && hidden.hasHiddenColumns())
1817 start = hidden.visibleToAbsoluteColumn(end);
1818 start = hidden.getNextHiddenBoundary(true, start) + 1;
1820 } while (end < max);
1822 // int[][] startEnd = new int[regions.size()][2];
1828 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1829 boolean selectedOnly)
1831 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1832 AlignmentAnnotation[] aa;
1833 if ((aa = alignment.getAlignmentAnnotation()) != null)
1835 for (AlignmentAnnotation annot : aa)
1837 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1838 if (selectedOnly && selectionGroup != null)
1840 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1841 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1845 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1854 public boolean isPadGaps()
1860 public void setPadGaps(boolean padGaps)
1862 this.padGaps = padGaps;
1866 * apply any post-edit constraints and trigger any calculations needed after
1867 * an edit has been performed on the alignment
1872 public void alignmentChanged(AlignmentViewPanel ap)
1876 alignment.padGaps();
1878 if (autoCalculateConsensus)
1880 updateConsensus(ap);
1882 if (hconsensus != null && autoCalculateConsensus)
1884 updateConservation(ap);
1886 if (autoCalculateStrucConsensus)
1888 updateStrucConsensus(ap);
1891 // Reset endRes of groups if beyond alignment width
1892 int alWidth = alignment.getWidth();
1893 List<SequenceGroup> groups = alignment.getGroups();
1896 for (SequenceGroup sg : groups)
1898 if (sg.getEndRes() > alWidth)
1900 sg.setEndRes(alWidth - 1);
1905 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1907 selectionGroup.setEndRes(alWidth - 1);
1910 updateAllColourSchemes();
1911 calculator.restartWorkers();
1912 // alignment.adjustSequenceAnnotations();
1916 * reset scope and do calculations for all applied colourschemes on alignment
1918 void updateAllColourSchemes()
1920 ResidueShaderI rs = residueShading;
1923 rs.alignmentChanged(alignment, hiddenRepSequences);
1925 rs.setConsensus(hconsensus);
1926 if (rs.conservationApplied())
1928 rs.setConservation(Conservation.calculateConservation("All",
1929 alignment.getSequences(), 0, alignment.getWidth(), false,
1930 getConsPercGaps(), false));
1934 for (SequenceGroup sg : alignment.getGroups())
1938 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1940 sg.recalcConservation();
1944 protected void initAutoAnnotation()
1946 // TODO: add menu option action that nulls or creates consensus object
1947 // depending on if the user wants to see the annotation or not in a
1948 // specific alignment
1950 if (hconsensus == null && !isDataset)
1952 if (!alignment.isNucleotide())
1961 consensus = new AlignmentAnnotation("Consensus",
1962 MessageManager.getString("label.consensus_descr"),
1963 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1964 initConsensus(consensus);
1967 initComplementConsensus();
1972 * If this is a protein alignment and there are mappings to cDNA, adds the
1973 * cDNA consensus annotation and returns true, else returns false.
1975 public boolean initComplementConsensus()
1977 if (!alignment.isNucleotide())
1979 final List<AlignedCodonFrame> codonMappings = alignment
1981 if (codonMappings != null && !codonMappings.isEmpty())
1983 boolean doConsensus = false;
1984 for (AlignedCodonFrame mapping : codonMappings)
1986 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1987 MapList[] mapLists = mapping.getdnaToProt();
1988 // mapLists can be empty if project load has not finished resolving
1990 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1998 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2000 .getString("label.complement_consensus_descr"),
2001 new Annotation[1], 0f, 100f,
2002 AlignmentAnnotation.BAR_GRAPH);
2003 initConsensus(complementConsensus);
2011 private void initConsensus(AlignmentAnnotation aa)
2014 aa.autoCalculated = true;
2018 alignment.addAnnotation(aa);
2022 // these should be extracted from the view model - style and settings for
2023 // derived annotation
2024 private void initGapCounts()
2028 gapcounts = new AlignmentAnnotation("Occupancy",
2029 MessageManager.getString("label.occupancy_descr"),
2030 new Annotation[1], 0f, alignment.getHeight(),
2031 AlignmentAnnotation.BAR_GRAPH);
2032 gapcounts.hasText = true;
2033 gapcounts.autoCalculated = true;
2034 gapcounts.scaleColLabel = true;
2035 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2037 alignment.addAnnotation(gapcounts);
2041 private void initConservation()
2043 if (showConservation)
2045 if (conservation == null)
2047 conservation = new AlignmentAnnotation("Conservation",
2048 MessageManager.formatMessage("label.conservation_descr",
2050 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2051 conservation.hasText = true;
2052 conservation.autoCalculated = true;
2053 alignment.addAnnotation(conservation);
2058 private void initQuality()
2062 if (quality == null)
2064 quality = new AlignmentAnnotation("Quality",
2065 MessageManager.getString("label.quality_descr"),
2066 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2067 quality.hasText = true;
2068 quality.autoCalculated = true;
2069 alignment.addAnnotation(quality);
2074 private void initRNAStructure()
2076 if (alignment.hasRNAStructure() && strucConsensus == null)
2078 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2079 MessageManager.getString("label.strucconsensus_descr"),
2080 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2081 strucConsensus.hasText = true;
2082 strucConsensus.autoCalculated = true;
2086 alignment.addAnnotation(strucConsensus);
2094 * @see jalview.api.AlignViewportI#calcPanelHeight()
2097 public int calcPanelHeight()
2099 // setHeight of panels
2100 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2102 int charHeight = getCharHeight();
2105 BitSet graphgrp = new BitSet();
2106 for (AlignmentAnnotation aa : anns)
2110 jalview.bin.Console.errPrintln("Null annotation row: ignoring.");
2117 if (aa.graphGroup > -1)
2119 if (graphgrp.get(aa.graphGroup))
2125 graphgrp.set(aa.graphGroup);
2132 aa.height += charHeight;
2142 aa.height += aa.graphHeight + 20;
2150 height += aa.height;
2162 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2163 boolean preserveNewGroupSettings)
2165 boolean updateCalcs = false;
2166 boolean conv = isShowGroupConservation();
2167 boolean cons = isShowGroupConsensus();
2168 boolean showprf = isShowSequenceLogo();
2169 boolean showConsHist = isShowConsensusHistogram();
2170 boolean normLogo = isNormaliseSequenceLogo();
2173 * TODO reorder the annotation rows according to group/sequence ordering on
2176 // boolean sortg = true;
2178 // remove old automatic annotation
2179 // add any new annotation
2181 // intersect alignment annotation with alignment groups
2183 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2184 List<SequenceGroup> oldrfs = new ArrayList<>();
2187 for (int an = 0; an < aan.length; an++)
2189 if (aan[an].autoCalculated && aan[an].groupRef != null)
2191 oldrfs.add(aan[an].groupRef);
2192 alignment.deleteAnnotation(aan[an], false);
2196 if (alignment.getGroups() != null)
2198 for (SequenceGroup sg : alignment.getGroups())
2200 updateCalcs = false;
2201 if (applyGlobalSettings
2202 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2204 // set defaults for this group's conservation/consensus
2205 sg.setshowSequenceLogo(showprf);
2206 sg.setShowConsensusHistogram(showConsHist);
2207 sg.setNormaliseSequenceLogo(normLogo);
2212 alignment.addAnnotation(sg.getConservationRow(), 0);
2217 alignment.addAnnotation(sg.getConsensus(), 0);
2219 // refresh the annotation rows
2222 sg.recalcConservation();
2230 public boolean isDisplayReferenceSeq()
2232 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2236 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2238 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2242 public boolean isColourByReferenceSeq()
2244 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2248 public Color getSequenceColour(SequenceI seq)
2250 Color sqc = sequenceColours.get(seq);
2251 return (sqc == null ? Color.white : sqc);
2255 public void setSequenceColour(SequenceI seq, Color col)
2259 sequenceColours.remove(seq);
2263 sequenceColours.put(seq, col);
2268 public void updateSequenceIdColours()
2270 for (SequenceGroup sg : alignment.getGroups())
2272 if (sg.idColour != null)
2274 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2276 sequenceColours.put(s, sg.idColour);
2283 public void clearSequenceColours()
2285 sequenceColours.clear();
2289 public AlignViewportI getCodingComplement()
2291 return this.codingComplement;
2295 * Set this as the (cDna/protein) complement of the given viewport. Also
2296 * ensures the reverse relationship is set on the given viewport.
2299 public void setCodingComplement(AlignViewportI av)
2304 .errPrintln("Ignoring recursive setCodingComplement request");
2308 this.codingComplement = av;
2309 // avoid infinite recursion!
2310 if (av.getCodingComplement() != this)
2312 av.setCodingComplement(this);
2318 public boolean isNucleotide()
2320 return getAlignment() == null ? false : getAlignment().isNucleotide();
2324 public FeaturesDisplayedI getFeaturesDisplayed()
2326 return featuresDisplayed;
2330 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2332 featuresDisplayed = featuresDisplayedI;
2336 public boolean areFeaturesDisplayed()
2338 return featuresDisplayed != null
2339 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2346 * features are displayed if true
2349 public void setShowSequenceFeatures(boolean b)
2351 viewStyle.setShowSequenceFeatures(b);
2355 public boolean isShowSequenceFeatures()
2357 return viewStyle.isShowSequenceFeatures();
2361 public void setShowSequenceFeaturesHeight(boolean selected)
2363 viewStyle.setShowSequenceFeaturesHeight(selected);
2367 public boolean isShowSequenceFeaturesHeight()
2369 return viewStyle.isShowSequenceFeaturesHeight();
2373 public void setShowAnnotation(boolean b)
2375 viewStyle.setShowAnnotation(b);
2379 public boolean isShowAnnotation()
2381 return viewStyle.isShowAnnotation();
2385 public boolean isRightAlignIds()
2387 return viewStyle.isRightAlignIds();
2391 public void setRightAlignIds(boolean rightAlignIds)
2393 viewStyle.setRightAlignIds(rightAlignIds);
2397 public boolean getConservationSelected()
2399 return viewStyle.getConservationSelected();
2403 public void setShowBoxes(boolean state)
2405 viewStyle.setShowBoxes(state);
2410 * @see jalview.api.ViewStyleI#getTextColour()
2413 public Color getTextColour()
2415 return viewStyle.getTextColour();
2420 * @see jalview.api.ViewStyleI#getTextColour2()
2423 public Color getTextColour2()
2425 return viewStyle.getTextColour2();
2430 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2433 public int getThresholdTextColour()
2435 return viewStyle.getThresholdTextColour();
2440 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2443 public boolean isConservationColourSelected()
2445 return viewStyle.isConservationColourSelected();
2450 * @see jalview.api.ViewStyleI#isRenderGaps()
2453 public boolean isRenderGaps()
2455 return viewStyle.isRenderGaps();
2460 * @see jalview.api.ViewStyleI#isShowColourText()
2463 public boolean isShowColourText()
2465 return viewStyle.isShowColourText();
2469 * @param conservationColourSelected
2470 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2473 public void setConservationColourSelected(
2474 boolean conservationColourSelected)
2476 viewStyle.setConservationColourSelected(conservationColourSelected);
2480 * @param showColourText
2481 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2484 public void setShowColourText(boolean showColourText)
2486 viewStyle.setShowColourText(showColourText);
2491 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2494 public void setTextColour(Color textColour)
2496 viewStyle.setTextColour(textColour);
2500 * @param thresholdTextColour
2501 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2504 public void setThresholdTextColour(int thresholdTextColour)
2506 viewStyle.setThresholdTextColour(thresholdTextColour);
2510 * @param textColour2
2511 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2514 public void setTextColour2(Color textColour2)
2516 viewStyle.setTextColour2(textColour2);
2520 public ViewStyleI getViewStyle()
2522 return new ViewStyle(viewStyle);
2526 public void setViewStyle(ViewStyleI settingsForView)
2528 viewStyle = new ViewStyle(settingsForView);
2529 if (residueShading != null)
2531 residueShading.setConservationApplied(
2532 settingsForView.isConservationColourSelected());
2537 public boolean sameStyle(ViewStyleI them)
2539 return viewStyle.sameStyle(them);
2544 * @see jalview.api.ViewStyleI#getIdWidth()
2547 public int getIdWidth()
2549 return viewStyle.getIdWidth();
2554 * @see jalview.api.ViewStyleI#setIdWidth(int)
2557 public void setIdWidth(int i)
2559 viewStyle.setIdWidth(i);
2564 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2567 public boolean isCentreColumnLabels()
2569 return viewStyle.isCentreColumnLabels();
2573 * @param centreColumnLabels
2574 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2577 public void setCentreColumnLabels(boolean centreColumnLabels)
2579 viewStyle.setCentreColumnLabels(centreColumnLabels);
2584 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2587 public void setShowDBRefs(boolean showdbrefs)
2589 viewStyle.setShowDBRefs(showdbrefs);
2594 * @see jalview.api.ViewStyleI#isShowDBRefs()
2597 public boolean isShowDBRefs()
2599 return viewStyle.isShowDBRefs();
2604 * @see jalview.api.ViewStyleI#isShowNPFeats()
2607 public boolean isShowNPFeats()
2609 return viewStyle.isShowNPFeats();
2613 * @param shownpfeats
2614 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2617 public void setShowNPFeats(boolean shownpfeats)
2619 viewStyle.setShowNPFeats(shownpfeats);
2622 public abstract StructureSelectionManager getStructureSelectionManager();
2625 * Add one command to the command history list.
2629 public void addToHistoryList(CommandI command)
2631 if (this.historyList != null)
2633 this.historyList.push(command);
2634 broadcastCommand(command, false);
2635 setSavedUpToDate(false);
2636 Jalview2XML.setStateSavedUpToDate(false);
2640 protected void broadcastCommand(CommandI command, boolean undo)
2642 getStructureSelectionManager().commandPerformed(command, undo,
2647 * Add one command to the command redo list.
2651 public void addToRedoList(CommandI command)
2653 if (this.redoList != null)
2655 this.redoList.push(command);
2657 broadcastCommand(command, true);
2661 * Clear the command redo list.
2663 public void clearRedoList()
2665 if (this.redoList != null)
2667 this.redoList.clear();
2671 public void setHistoryList(Deque<CommandI> list)
2673 this.historyList = list;
2676 public Deque<CommandI> getHistoryList()
2678 return this.historyList;
2681 public void setRedoList(Deque<CommandI> list)
2683 this.redoList = list;
2686 public Deque<CommandI> getRedoList()
2688 return this.redoList;
2692 public VamsasSource getVamsasSource()
2697 public SequenceAnnotationOrder getSortAnnotationsBy()
2699 return sortAnnotationsBy;
2702 public void setSortAnnotationsBy(
2703 SequenceAnnotationOrder sortAnnotationsBy)
2705 this.sortAnnotationsBy = sortAnnotationsBy;
2708 public boolean isShowAutocalculatedAbove()
2710 return showAutocalculatedAbove;
2713 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2715 this.showAutocalculatedAbove = showAutocalculatedAbove;
2719 public boolean isScaleProteinAsCdna()
2721 return viewStyle.isScaleProteinAsCdna();
2725 public void setScaleProteinAsCdna(boolean b)
2727 viewStyle.setScaleProteinAsCdna(b);
2731 public boolean isProteinFontAsCdna()
2733 return viewStyle.isProteinFontAsCdna();
2737 public void setProteinFontAsCdna(boolean b)
2739 viewStyle.setProteinFontAsCdna(b);
2743 public void setShowComplementFeatures(boolean b)
2745 viewStyle.setShowComplementFeatures(b);
2749 public boolean isShowComplementFeatures()
2751 return viewStyle.isShowComplementFeatures();
2755 public void setShowComplementFeaturesOnTop(boolean b)
2757 viewStyle.setShowComplementFeaturesOnTop(b);
2761 public boolean isShowComplementFeaturesOnTop()
2763 return viewStyle.isShowComplementFeaturesOnTop();
2767 * @return true if view should scroll to show the highlighted region of a
2772 public final boolean isFollowHighlight()
2774 return followHighlight;
2778 public final void setFollowHighlight(boolean b)
2780 this.followHighlight = b;
2784 public ViewportRanges getRanges()
2790 * Helper method to populate the SearchResults with the location in the
2791 * complementary alignment to scroll to, in order to match this one.
2794 * the SearchResults to add to
2795 * @return the offset (below top of visible region) of the matched sequence
2797 protected int findComplementScrollTarget(SearchResultsI sr)
2799 final AlignViewportI complement = getCodingComplement();
2800 if (complement == null || !complement.isFollowHighlight())
2804 boolean iAmProtein = !getAlignment().isNucleotide();
2805 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2806 : complement.getAlignment();
2807 if (proteinAlignment == null)
2811 final List<AlignedCodonFrame> mappings = proteinAlignment
2815 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2816 * residue in the middle column of the visible region. Scroll the
2817 * complementary alignment to line up the corresponding residue.
2820 SequenceI sequence = null;
2823 * locate 'middle' column (true middle if an odd number visible, left of
2824 * middle if an even number visible)
2826 int middleColumn = ranges.getStartRes()
2827 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2828 final HiddenSequences hiddenSequences = getAlignment()
2829 .getHiddenSequences();
2832 * searching to the bottom of the alignment gives smoother scrolling across
2833 * all gapped visible regions
2835 int lastSeq = alignment.getHeight() - 1;
2836 List<AlignedCodonFrame> seqMappings = null;
2837 for (int seqNo = ranges
2838 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2840 sequence = getAlignment().getSequenceAt(seqNo);
2841 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2845 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2849 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2851 getCodingComplement().getAlignment().getSequences());
2852 if (!seqMappings.isEmpty())
2858 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2861 * No ungapped mapped sequence in middle column - do nothing
2865 MappingUtils.addSearchResults(sr, sequence,
2866 sequence.findPosition(middleColumn), seqMappings);
2871 * synthesize a column selection if none exists so it covers the given
2872 * selection group. if wholewidth is false, no column selection is made if the
2873 * selection group covers the whole alignment width.
2878 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2881 if (sg != null && (sgs = sg.getStartRes()) >= 0
2882 && sg.getStartRes() <= (sge = sg.getEndRes())
2883 && !this.hasSelectedColumns())
2885 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2892 colSel = new ColumnSelection();
2894 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2896 colSel.addElement(cspos);
2902 * hold status of current selection group - defined on alignment or not.
2904 private boolean selectionIsDefinedGroup = false;
2907 public boolean isSelectionDefinedGroup()
2909 if (selectionGroup == null)
2913 if (isSelectionGroupChanged(true))
2915 selectionIsDefinedGroup = false;
2916 List<SequenceGroup> gps = alignment.getGroups();
2917 if (gps == null || gps.size() == 0)
2919 selectionIsDefinedGroup = false;
2923 selectionIsDefinedGroup = gps.contains(selectionGroup);
2926 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2930 * null, or currently highlighted results on this view
2932 private SearchResultsI searchResults = null;
2934 protected TreeModel currentTree = null;
2937 public boolean hasSearchResults()
2939 return searchResults != null;
2943 public void setSearchResults(SearchResultsI results)
2945 searchResults = results;
2949 public SearchResultsI getSearchResults()
2951 return searchResults;
2955 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
2957 return alignment.getContactListFor(_aa, column);
2961 public ContactMatrixI getContactMatrix(
2962 AlignmentAnnotation alignmentAnnotation)
2964 return alignment.getContactMatrixFor(alignmentAnnotation);
2968 * get the consensus sequence as displayed under the PID consensus annotation
2971 * @return consensus sequence as a new sequence object
2973 public SequenceI getConsensusSeq()
2975 if (consensus == null)
2977 updateConsensus(null);
2979 if (consensus == null)
2983 StringBuffer seqs = new StringBuffer();
2984 for (int i = 0; i < consensus.annotations.length; i++)
2986 Annotation annotation = consensus.annotations[i];
2987 if (annotation != null)
2989 String description = annotation.description;
2990 if (description != null && description.startsWith("["))
2992 // consensus is a tie - just pick the first one
2993 seqs.append(description.charAt(1));
2997 seqs.append(annotation.displayCharacter);
3002 SequenceI sq = new Sequence("Consensus", seqs.toString());
3003 sq.setDescription("Percentage Identity Consensus "
3004 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3009 public void setCurrentTree(TreeModel tree)
3015 public TreeModel getCurrentTree()
3021 public AlignmentExportData getAlignExportData(
3022 AlignExportSettingsI options)
3024 AlignmentI alignmentToExport = null;
3025 String[] omitHidden = null;
3026 alignmentToExport = null;
3028 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3030 omitHidden = getViewAsString(false,
3031 options.isExportHiddenSequences());
3034 int[] alignmentStartEnd = new int[2];
3035 if (hasHiddenRows() && options.isExportHiddenSequences())
3037 alignmentToExport = getAlignment().getHiddenSequences()
3038 .getFullAlignment();
3042 alignmentToExport = getAlignment();
3044 alignmentStartEnd = getAlignment().getHiddenColumns()
3045 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3046 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3047 omitHidden, alignmentStartEnd);
3052 * flag set to indicate if structure views might be out of sync with sequences
3056 private boolean needToUpdateStructureViews = false;
3059 public boolean isUpdateStructures()
3061 return needToUpdateStructureViews;
3065 public void setUpdateStructures(boolean update)
3067 needToUpdateStructureViews = update;
3071 public boolean needToUpdateStructureViews()
3073 boolean update = needToUpdateStructureViews;
3074 needToUpdateStructureViews = false;
3079 public void addSequenceGroup(SequenceGroup sequenceGroup)
3081 alignment.addGroup(sequenceGroup);
3083 Color col = sequenceGroup.idColour;
3086 col = col.brighter();
3088 for (SequenceI sq : sequenceGroup.getSequences())
3090 setSequenceColour(sq, col);
3094 if (codingComplement != null)
3096 SequenceGroup mappedGroup = MappingUtils
3097 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3098 if (mappedGroup.getSequences().size() > 0)
3100 codingComplement.getAlignment().addGroup(mappedGroup);
3104 for (SequenceI seq : mappedGroup.getSequences())
3106 codingComplement.setSequenceColour(seq, col);
3110 // propagate the structure view update flag according to our own setting
3111 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3116 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3120 if (selectedRegionOnly && selectionGroup != null)
3122 start = selectionGroup.getStartRes();
3123 end = selectionGroup.getEndRes() + 1;
3127 end = alignment.getWidth();
3129 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3133 public void setSavedUpToDate(boolean s)
3135 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3138 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3141 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3143 QuitHandler.setMessage(m);
3146 public boolean savedUpToDate()
3148 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3150 return savedUpToDate;