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);
1380 // common hide/show column stuff
1382 public void hideSelectedColumns()
1384 if (colSel.isEmpty())
1389 colSel.hideSelectedColumns(alignment);
1390 setSelectionGroup(null);
1391 isColSelChanged(true);
1394 public void hideColumns(int start, int end)
1398 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1402 alignment.getHiddenColumns().hideColumns(start, end);
1404 isColSelChanged(true);
1407 public void showColumn(int col)
1409 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1410 isColSelChanged(true);
1413 public void showAllHiddenColumns()
1415 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1416 isColSelChanged(true);
1419 // common hide/show seq stuff
1420 public void showAllHiddenSeqs()
1422 int startSeq = ranges.getStartSeq();
1423 int endSeq = ranges.getEndSeq();
1425 if (alignment.getHiddenSequences().getSize() > 0)
1427 if (selectionGroup == null)
1429 selectionGroup = new SequenceGroup();
1430 selectionGroup.setEndRes(alignment.getWidth() - 1);
1432 List<SequenceI> tmp = alignment.getHiddenSequences()
1433 .showAll(hiddenRepSequences);
1434 for (SequenceI seq : tmp)
1436 selectionGroup.addSequence(seq, false);
1437 setSequenceAnnotationsVisible(seq, true);
1440 hiddenRepSequences = null;
1442 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1444 firePropertyChange("alignment", null, alignment.getSequences());
1445 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1451 public void showSequence(int index)
1453 int startSeq = ranges.getStartSeq();
1454 int endSeq = ranges.getEndSeq();
1456 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1457 hiddenRepSequences);
1460 if (selectionGroup == null)
1462 selectionGroup = new SequenceGroup();
1463 selectionGroup.setEndRes(alignment.getWidth() - 1);
1466 for (SequenceI seq : tmp)
1468 selectionGroup.addSequence(seq, false);
1469 setSequenceAnnotationsVisible(seq, true);
1472 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1474 firePropertyChange("alignment", null, alignment.getSequences());
1479 public void hideAllSelectedSeqs()
1481 if (selectionGroup == null || selectionGroup.getSize() < 1)
1486 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1490 setSelectionGroup(null);
1493 public void hideSequence(SequenceI[] seq)
1496 * cache offset to first visible sequence
1498 int startSeq = ranges.getStartSeq();
1502 for (int i = 0; i < seq.length; i++)
1504 alignment.getHiddenSequences().hideSequence(seq[i]);
1505 setSequenceAnnotationsVisible(seq[i], false);
1507 ranges.setStartSeq(startSeq);
1508 firePropertyChange("alignment", null, alignment.getSequences());
1513 * Hides the specified sequence, or the sequences it represents
1516 * the sequence to hide, or keep as representative
1517 * @param representGroup
1518 * if true, hide the current selection group except for the
1519 * representative sequence
1521 public void hideSequences(SequenceI sequence, boolean representGroup)
1523 if (selectionGroup == null || selectionGroup.getSize() < 1)
1525 hideSequence(new SequenceI[] { sequence });
1531 hideRepSequences(sequence, selectionGroup);
1532 setSelectionGroup(null);
1536 int gsize = selectionGroup.getSize();
1537 SequenceI[] hseqs = selectionGroup.getSequences()
1538 .toArray(new SequenceI[gsize]);
1540 hideSequence(hseqs);
1541 setSelectionGroup(null);
1546 * Set visibility for any annotations for the given sequence.
1550 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1553 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1556 for (AlignmentAnnotation ann : anns)
1558 if (ann.sequenceRef == sequenceI)
1560 ann.visible = visible;
1566 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1568 int sSize = sg.getSize();
1574 if (hiddenRepSequences == null)
1576 hiddenRepSequences = new Hashtable<>();
1579 hiddenRepSequences.put(repSequence, sg);
1581 // Hide all sequences except the repSequence
1582 SequenceI[] seqs = new SequenceI[sSize - 1];
1584 for (int i = 0; i < sSize; i++)
1586 if (sg.getSequenceAt(i) != repSequence)
1588 if (index == sSize - 1)
1593 seqs[index++] = sg.getSequenceAt(i);
1596 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1597 sg.setHidereps(true); // note: not done in 2.7applet
1604 * @return null or the current reference sequence
1606 public SequenceI getReferenceSeq()
1608 return alignment.getSeqrep();
1613 * @return true iff seq is the reference for the alignment
1615 public boolean isReferenceSeq(SequenceI seq)
1617 return alignment.getSeqrep() == seq;
1623 * @return true if there are sequences represented by this sequence that are
1626 public boolean isHiddenRepSequence(SequenceI seq)
1628 return (hiddenRepSequences != null
1629 && hiddenRepSequences.containsKey(seq));
1635 * @return null or a sequence group containing the sequences that seq
1638 public SequenceGroup getRepresentedSequences(SequenceI seq)
1640 return (SequenceGroup) (hiddenRepSequences == null ? null
1641 : hiddenRepSequences.get(seq));
1645 public int adjustForHiddenSeqs(int alignmentIndex)
1647 return alignment.getHiddenSequences()
1648 .adjustForHiddenSeqs(alignmentIndex);
1652 public void invertColumnSelection()
1654 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1655 isColSelChanged(true);
1659 public SequenceI[] getSelectionAsNewSequence()
1661 SequenceI[] sequences;
1662 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1663 // this was the only caller in the applet for this method
1664 // JBPNote: in applet, this method returned references to the alignment
1665 // sequences, and it did not honour the presence/absence of annotation
1666 // attached to the alignment (probably!)
1667 if (selectionGroup == null || selectionGroup.getSize() == 0)
1669 sequences = alignment.getSequencesArray();
1670 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1671 for (int i = 0; i < sequences.length; i++)
1673 // construct new sequence with subset of visible annotation
1674 sequences[i] = new Sequence(sequences[i], annots);
1679 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1686 public SequenceI[] getSequenceSelection()
1688 SequenceI[] sequences = null;
1689 if (selectionGroup != null)
1691 sequences = selectionGroup.getSequencesInOrder(alignment);
1693 if (sequences == null)
1695 sequences = alignment.getSequencesArray();
1701 public jalview.datamodel.AlignmentView getAlignmentView(
1702 boolean selectedOnly)
1704 return getAlignmentView(selectedOnly, false);
1708 public jalview.datamodel.AlignmentView getAlignmentView(
1709 boolean selectedOnly, boolean markGroups)
1711 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1713 alignment.getHiddenColumns() != null
1714 && alignment.getHiddenColumns().hasHiddenColumns(),
1715 selectedOnly, markGroups);
1719 public String[] getViewAsString(boolean selectedRegionOnly)
1721 return getViewAsString(selectedRegionOnly, true);
1725 public String[] getViewAsString(boolean selectedRegionOnly,
1726 boolean exportHiddenSeqs)
1728 String[] selection = null;
1729 SequenceI[] seqs = null;
1731 int start = 0, end = 0;
1732 if (selectedRegionOnly && selectionGroup != null)
1734 iSize = selectionGroup.getSize();
1735 seqs = selectionGroup.getSequencesInOrder(alignment);
1736 start = selectionGroup.getStartRes();
1737 end = selectionGroup.getEndRes() + 1;
1741 if (hasHiddenRows() && exportHiddenSeqs)
1743 AlignmentI fullAlignment = alignment.getHiddenSequences()
1744 .getFullAlignment();
1745 iSize = fullAlignment.getHeight();
1746 seqs = fullAlignment.getSequencesArray();
1747 end = fullAlignment.getWidth();
1751 iSize = alignment.getHeight();
1752 seqs = alignment.getSequencesArray();
1753 end = alignment.getWidth();
1757 selection = new String[iSize];
1758 if (alignment.getHiddenColumns() != null
1759 && alignment.getHiddenColumns().hasHiddenColumns())
1761 for (i = 0; i < iSize; i++)
1763 Iterator<int[]> blocks = alignment.getHiddenColumns()
1764 .getVisContigsIterator(start, end + 1, false);
1765 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1770 for (i = 0; i < iSize; i++)
1772 selection[i] = seqs[i].getSequenceAsString(start, end);
1780 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1782 ArrayList<int[]> regions = new ArrayList<>();
1788 HiddenColumns hidden = alignment.getHiddenColumns();
1789 if (hidden != null && hidden.hasHiddenColumns())
1793 start = hidden.visibleToAbsoluteColumn(start);
1796 end = hidden.getNextHiddenBoundary(false, start);
1807 regions.add(new int[] { start, end });
1809 if (hidden != null && hidden.hasHiddenColumns())
1811 start = hidden.visibleToAbsoluteColumn(end);
1812 start = hidden.getNextHiddenBoundary(true, start) + 1;
1814 } while (end < max);
1816 // int[][] startEnd = new int[regions.size()][2];
1822 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1823 boolean selectedOnly)
1825 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1826 AlignmentAnnotation[] aa;
1827 if ((aa = alignment.getAlignmentAnnotation()) != null)
1829 for (AlignmentAnnotation annot : aa)
1831 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1832 if (selectedOnly && selectionGroup != null)
1834 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1835 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1839 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1848 public boolean isPadGaps()
1854 public void setPadGaps(boolean padGaps)
1856 this.padGaps = padGaps;
1860 * apply any post-edit constraints and trigger any calculations needed after
1861 * an edit has been performed on the alignment
1866 public void alignmentChanged(AlignmentViewPanel ap)
1870 alignment.padGaps();
1872 if (autoCalculateConsensus)
1874 updateConsensus(ap);
1876 if (hconsensus != null && autoCalculateConsensus)
1878 updateConservation(ap);
1880 if (autoCalculateStrucConsensus)
1882 updateStrucConsensus(ap);
1885 // Reset endRes of groups if beyond alignment width
1886 int alWidth = alignment.getWidth();
1887 List<SequenceGroup> groups = alignment.getGroups();
1890 for (SequenceGroup sg : groups)
1892 if (sg.getEndRes() > alWidth)
1894 sg.setEndRes(alWidth - 1);
1899 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1901 selectionGroup.setEndRes(alWidth - 1);
1904 updateAllColourSchemes();
1905 calculator.restartWorkers();
1906 // alignment.adjustSequenceAnnotations();
1910 * reset scope and do calculations for all applied colourschemes on alignment
1912 void updateAllColourSchemes()
1914 ResidueShaderI rs = residueShading;
1917 rs.alignmentChanged(alignment, hiddenRepSequences);
1919 rs.setConsensus(hconsensus);
1920 if (rs.conservationApplied())
1922 rs.setConservation(Conservation.calculateConservation("All",
1923 alignment.getSequences(), 0, alignment.getWidth(), false,
1924 getConsPercGaps(), false));
1928 for (SequenceGroup sg : alignment.getGroups())
1932 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1934 sg.recalcConservation();
1938 protected void initAutoAnnotation()
1940 // TODO: add menu option action that nulls or creates consensus object
1941 // depending on if the user wants to see the annotation or not in a
1942 // specific alignment
1944 if (hconsensus == null && !isDataset)
1946 if (!alignment.isNucleotide())
1955 consensus = new AlignmentAnnotation("Consensus",
1956 MessageManager.getString("label.consensus_descr"),
1957 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1958 initConsensus(consensus);
1961 initComplementConsensus();
1966 * If this is a protein alignment and there are mappings to cDNA, adds the
1967 * cDNA consensus annotation and returns true, else returns false.
1969 public boolean initComplementConsensus()
1971 if (!alignment.isNucleotide())
1973 final List<AlignedCodonFrame> codonMappings = alignment
1975 if (codonMappings != null && !codonMappings.isEmpty())
1977 boolean doConsensus = false;
1978 for (AlignedCodonFrame mapping : codonMappings)
1980 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1981 MapList[] mapLists = mapping.getdnaToProt();
1982 // mapLists can be empty if project load has not finished resolving
1984 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1992 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1994 .getString("label.complement_consensus_descr"),
1995 new Annotation[1], 0f, 100f,
1996 AlignmentAnnotation.BAR_GRAPH);
1997 initConsensus(complementConsensus);
2005 private void initConsensus(AlignmentAnnotation aa)
2008 aa.autoCalculated = true;
2012 alignment.addAnnotation(aa);
2016 // these should be extracted from the view model - style and settings for
2017 // derived annotation
2018 private void initGapCounts()
2022 gapcounts = new AlignmentAnnotation("Occupancy",
2023 MessageManager.getString("label.occupancy_descr"),
2024 new Annotation[1], 0f, alignment.getHeight(),
2025 AlignmentAnnotation.BAR_GRAPH);
2026 gapcounts.hasText = true;
2027 gapcounts.autoCalculated = true;
2028 gapcounts.scaleColLabel = true;
2029 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2031 alignment.addAnnotation(gapcounts);
2035 private void initConservation()
2037 if (showConservation)
2039 if (conservation == null)
2041 conservation = new AlignmentAnnotation("Conservation",
2042 MessageManager.formatMessage("label.conservation_descr",
2044 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2045 conservation.hasText = true;
2046 conservation.autoCalculated = true;
2047 alignment.addAnnotation(conservation);
2052 private void initQuality()
2056 if (quality == null)
2058 quality = new AlignmentAnnotation("Quality",
2059 MessageManager.getString("label.quality_descr"),
2060 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2061 quality.hasText = true;
2062 quality.autoCalculated = true;
2063 alignment.addAnnotation(quality);
2068 private void initRNAStructure()
2070 if (alignment.hasRNAStructure() && strucConsensus == null)
2072 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2073 MessageManager.getString("label.strucconsensus_descr"),
2074 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2075 strucConsensus.hasText = true;
2076 strucConsensus.autoCalculated = true;
2080 alignment.addAnnotation(strucConsensus);
2088 * @see jalview.api.AlignViewportI#calcPanelHeight()
2091 public int calcPanelHeight()
2093 // setHeight of panels
2094 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2096 int charHeight = getCharHeight();
2099 BitSet graphgrp = new BitSet();
2100 for (AlignmentAnnotation aa : anns)
2104 jalview.bin.Console.errPrintln("Null annotation row: ignoring.");
2111 if (aa.graphGroup > -1)
2113 if (graphgrp.get(aa.graphGroup))
2119 graphgrp.set(aa.graphGroup);
2126 aa.height += charHeight;
2136 aa.height += aa.graphHeight + 20;
2144 height += aa.height;
2156 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2157 boolean preserveNewGroupSettings)
2159 boolean updateCalcs = false;
2160 boolean conv = isShowGroupConservation();
2161 boolean cons = isShowGroupConsensus();
2162 boolean showprf = isShowSequenceLogo();
2163 boolean showConsHist = isShowConsensusHistogram();
2164 boolean normLogo = isNormaliseSequenceLogo();
2167 * TODO reorder the annotation rows according to group/sequence ordering on
2170 // boolean sortg = true;
2172 // remove old automatic annotation
2173 // add any new annotation
2175 // intersect alignment annotation with alignment groups
2177 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2178 List<SequenceGroup> oldrfs = new ArrayList<>();
2181 for (int an = 0; an < aan.length; an++)
2183 if (aan[an].autoCalculated && aan[an].groupRef != null)
2185 oldrfs.add(aan[an].groupRef);
2186 alignment.deleteAnnotation(aan[an], false);
2190 if (alignment.getGroups() != null)
2192 for (SequenceGroup sg : alignment.getGroups())
2194 updateCalcs = false;
2195 if (applyGlobalSettings
2196 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2198 // set defaults for this group's conservation/consensus
2199 sg.setshowSequenceLogo(showprf);
2200 sg.setShowConsensusHistogram(showConsHist);
2201 sg.setNormaliseSequenceLogo(normLogo);
2206 alignment.addAnnotation(sg.getConservationRow(), 0);
2211 alignment.addAnnotation(sg.getConsensus(), 0);
2213 // refresh the annotation rows
2216 sg.recalcConservation();
2224 public boolean isDisplayReferenceSeq()
2226 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2230 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2232 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2236 public boolean isColourByReferenceSeq()
2238 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2242 public Color getSequenceColour(SequenceI seq)
2244 Color sqc = sequenceColours.get(seq);
2245 return (sqc == null ? Color.white : sqc);
2249 public void setSequenceColour(SequenceI seq, Color col)
2253 sequenceColours.remove(seq);
2257 sequenceColours.put(seq, col);
2262 public void updateSequenceIdColours()
2264 for (SequenceGroup sg : alignment.getGroups())
2266 if (sg.idColour != null)
2268 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2270 sequenceColours.put(s, sg.idColour);
2277 public void clearSequenceColours()
2279 sequenceColours.clear();
2283 public AlignViewportI getCodingComplement()
2285 return this.codingComplement;
2289 * Set this as the (cDna/protein) complement of the given viewport. Also
2290 * ensures the reverse relationship is set on the given viewport.
2293 public void setCodingComplement(AlignViewportI av)
2298 .errPrintln("Ignoring recursive setCodingComplement request");
2302 this.codingComplement = av;
2303 // avoid infinite recursion!
2304 if (av.getCodingComplement() != this)
2306 av.setCodingComplement(this);
2312 public boolean isNucleotide()
2314 return getAlignment() == null ? false : getAlignment().isNucleotide();
2318 public FeaturesDisplayedI getFeaturesDisplayed()
2320 return featuresDisplayed;
2324 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2326 featuresDisplayed = featuresDisplayedI;
2330 public boolean areFeaturesDisplayed()
2332 return featuresDisplayed != null
2333 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2340 * features are displayed if true
2343 public void setShowSequenceFeatures(boolean b)
2345 viewStyle.setShowSequenceFeatures(b);
2349 public boolean isShowSequenceFeatures()
2351 return viewStyle.isShowSequenceFeatures();
2355 public void setShowSequenceFeaturesHeight(boolean selected)
2357 viewStyle.setShowSequenceFeaturesHeight(selected);
2361 public boolean isShowSequenceFeaturesHeight()
2363 return viewStyle.isShowSequenceFeaturesHeight();
2367 public void setShowAnnotation(boolean b)
2369 viewStyle.setShowAnnotation(b);
2373 public boolean isShowAnnotation()
2375 return viewStyle.isShowAnnotation();
2379 public boolean isRightAlignIds()
2381 return viewStyle.isRightAlignIds();
2385 public void setRightAlignIds(boolean rightAlignIds)
2387 viewStyle.setRightAlignIds(rightAlignIds);
2391 public boolean getConservationSelected()
2393 return viewStyle.getConservationSelected();
2397 public void setShowBoxes(boolean state)
2399 viewStyle.setShowBoxes(state);
2404 * @see jalview.api.ViewStyleI#getTextColour()
2407 public Color getTextColour()
2409 return viewStyle.getTextColour();
2414 * @see jalview.api.ViewStyleI#getTextColour2()
2417 public Color getTextColour2()
2419 return viewStyle.getTextColour2();
2424 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2427 public int getThresholdTextColour()
2429 return viewStyle.getThresholdTextColour();
2434 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2437 public boolean isConservationColourSelected()
2439 return viewStyle.isConservationColourSelected();
2444 * @see jalview.api.ViewStyleI#isRenderGaps()
2447 public boolean isRenderGaps()
2449 return viewStyle.isRenderGaps();
2454 * @see jalview.api.ViewStyleI#isShowColourText()
2457 public boolean isShowColourText()
2459 return viewStyle.isShowColourText();
2463 * @param conservationColourSelected
2464 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2467 public void setConservationColourSelected(
2468 boolean conservationColourSelected)
2470 viewStyle.setConservationColourSelected(conservationColourSelected);
2474 * @param showColourText
2475 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2478 public void setShowColourText(boolean showColourText)
2480 viewStyle.setShowColourText(showColourText);
2485 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2488 public void setTextColour(Color textColour)
2490 viewStyle.setTextColour(textColour);
2494 * @param thresholdTextColour
2495 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2498 public void setThresholdTextColour(int thresholdTextColour)
2500 viewStyle.setThresholdTextColour(thresholdTextColour);
2504 * @param textColour2
2505 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2508 public void setTextColour2(Color textColour2)
2510 viewStyle.setTextColour2(textColour2);
2514 public ViewStyleI getViewStyle()
2516 return new ViewStyle(viewStyle);
2520 public void setViewStyle(ViewStyleI settingsForView)
2522 viewStyle = new ViewStyle(settingsForView);
2523 if (residueShading != null)
2525 residueShading.setConservationApplied(
2526 settingsForView.isConservationColourSelected());
2531 public boolean sameStyle(ViewStyleI them)
2533 return viewStyle.sameStyle(them);
2538 * @see jalview.api.ViewStyleI#getIdWidth()
2541 public int getIdWidth()
2543 return viewStyle.getIdWidth();
2548 * @see jalview.api.ViewStyleI#setIdWidth(int)
2551 public void setIdWidth(int i)
2553 viewStyle.setIdWidth(i);
2558 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2561 public boolean isCentreColumnLabels()
2563 return viewStyle.isCentreColumnLabels();
2567 * @param centreColumnLabels
2568 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2571 public void setCentreColumnLabels(boolean centreColumnLabels)
2573 viewStyle.setCentreColumnLabels(centreColumnLabels);
2578 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2581 public void setShowDBRefs(boolean showdbrefs)
2583 viewStyle.setShowDBRefs(showdbrefs);
2588 * @see jalview.api.ViewStyleI#isShowDBRefs()
2591 public boolean isShowDBRefs()
2593 return viewStyle.isShowDBRefs();
2598 * @see jalview.api.ViewStyleI#isShowNPFeats()
2601 public boolean isShowNPFeats()
2603 return viewStyle.isShowNPFeats();
2607 * @param shownpfeats
2608 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2611 public void setShowNPFeats(boolean shownpfeats)
2613 viewStyle.setShowNPFeats(shownpfeats);
2616 public abstract StructureSelectionManager getStructureSelectionManager();
2619 * Add one command to the command history list.
2623 public void addToHistoryList(CommandI command)
2625 if (this.historyList != null)
2627 this.historyList.push(command);
2628 broadcastCommand(command, false);
2629 setSavedUpToDate(false);
2630 Jalview2XML.setStateSavedUpToDate(false);
2634 protected void broadcastCommand(CommandI command, boolean undo)
2636 getStructureSelectionManager().commandPerformed(command, undo,
2641 * Add one command to the command redo list.
2645 public void addToRedoList(CommandI command)
2647 if (this.redoList != null)
2649 this.redoList.push(command);
2651 broadcastCommand(command, true);
2655 * Clear the command redo list.
2657 public void clearRedoList()
2659 if (this.redoList != null)
2661 this.redoList.clear();
2665 public void setHistoryList(Deque<CommandI> list)
2667 this.historyList = list;
2670 public Deque<CommandI> getHistoryList()
2672 return this.historyList;
2675 public void setRedoList(Deque<CommandI> list)
2677 this.redoList = list;
2680 public Deque<CommandI> getRedoList()
2682 return this.redoList;
2686 public VamsasSource getVamsasSource()
2691 public SequenceAnnotationOrder getSortAnnotationsBy()
2693 return sortAnnotationsBy;
2696 public void setSortAnnotationsBy(
2697 SequenceAnnotationOrder sortAnnotationsBy)
2699 this.sortAnnotationsBy = sortAnnotationsBy;
2702 public boolean isShowAutocalculatedAbove()
2704 return showAutocalculatedAbove;
2707 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2709 this.showAutocalculatedAbove = showAutocalculatedAbove;
2713 public boolean isScaleProteinAsCdna()
2715 return viewStyle.isScaleProteinAsCdna();
2719 public void setScaleProteinAsCdna(boolean b)
2721 viewStyle.setScaleProteinAsCdna(b);
2725 public boolean isProteinFontAsCdna()
2727 return viewStyle.isProteinFontAsCdna();
2731 public void setProteinFontAsCdna(boolean b)
2733 viewStyle.setProteinFontAsCdna(b);
2737 public void setShowComplementFeatures(boolean b)
2739 viewStyle.setShowComplementFeatures(b);
2743 public boolean isShowComplementFeatures()
2745 return viewStyle.isShowComplementFeatures();
2749 public void setShowComplementFeaturesOnTop(boolean b)
2751 viewStyle.setShowComplementFeaturesOnTop(b);
2755 public boolean isShowComplementFeaturesOnTop()
2757 return viewStyle.isShowComplementFeaturesOnTop();
2761 * @return true if view should scroll to show the highlighted region of a
2766 public final boolean isFollowHighlight()
2768 return followHighlight;
2772 public final void setFollowHighlight(boolean b)
2774 this.followHighlight = b;
2778 public ViewportRanges getRanges()
2784 * Helper method to populate the SearchResults with the location in the
2785 * complementary alignment to scroll to, in order to match this one.
2788 * the SearchResults to add to
2789 * @return the offset (below top of visible region) of the matched sequence
2791 protected int findComplementScrollTarget(SearchResultsI sr)
2793 final AlignViewportI complement = getCodingComplement();
2794 if (complement == null || !complement.isFollowHighlight())
2798 boolean iAmProtein = !getAlignment().isNucleotide();
2799 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2800 : complement.getAlignment();
2801 if (proteinAlignment == null)
2805 final List<AlignedCodonFrame> mappings = proteinAlignment
2809 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2810 * residue in the middle column of the visible region. Scroll the
2811 * complementary alignment to line up the corresponding residue.
2814 SequenceI sequence = null;
2817 * locate 'middle' column (true middle if an odd number visible, left of
2818 * middle if an even number visible)
2820 int middleColumn = ranges.getStartRes()
2821 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2822 final HiddenSequences hiddenSequences = getAlignment()
2823 .getHiddenSequences();
2826 * searching to the bottom of the alignment gives smoother scrolling across
2827 * all gapped visible regions
2829 int lastSeq = alignment.getHeight() - 1;
2830 List<AlignedCodonFrame> seqMappings = null;
2831 for (int seqNo = ranges
2832 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2834 sequence = getAlignment().getSequenceAt(seqNo);
2835 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2839 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2843 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2845 getCodingComplement().getAlignment().getSequences());
2846 if (!seqMappings.isEmpty())
2852 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2855 * No ungapped mapped sequence in middle column - do nothing
2859 MappingUtils.addSearchResults(sr, sequence,
2860 sequence.findPosition(middleColumn), seqMappings);
2865 * synthesize a column selection if none exists so it covers the given
2866 * selection group. if wholewidth is false, no column selection is made if the
2867 * selection group covers the whole alignment width.
2872 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2875 if (sg != null && (sgs = sg.getStartRes()) >= 0
2876 && sg.getStartRes() <= (sge = sg.getEndRes())
2877 && !this.hasSelectedColumns())
2879 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2886 colSel = new ColumnSelection();
2888 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2890 colSel.addElement(cspos);
2896 * hold status of current selection group - defined on alignment or not.
2898 private boolean selectionIsDefinedGroup = false;
2901 public boolean isSelectionDefinedGroup()
2903 if (selectionGroup == null)
2907 if (isSelectionGroupChanged(true))
2909 selectionIsDefinedGroup = false;
2910 List<SequenceGroup> gps = alignment.getGroups();
2911 if (gps == null || gps.size() == 0)
2913 selectionIsDefinedGroup = false;
2917 selectionIsDefinedGroup = gps.contains(selectionGroup);
2920 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2924 * null, or currently highlighted results on this view
2926 private SearchResultsI searchResults = null;
2928 protected TreeModel currentTree = null;
2931 public boolean hasSearchResults()
2933 return searchResults != null;
2937 public void setSearchResults(SearchResultsI results)
2939 searchResults = results;
2943 public SearchResultsI getSearchResults()
2945 return searchResults;
2949 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
2951 return alignment.getContactListFor(_aa, column);
2955 public ContactMatrixI getContactMatrix(
2956 AlignmentAnnotation alignmentAnnotation)
2958 return alignment.getContactMatrixFor(alignmentAnnotation);
2962 * get the consensus sequence as displayed under the PID consensus annotation
2965 * @return consensus sequence as a new sequence object
2967 public SequenceI getConsensusSeq()
2969 if (consensus == null)
2971 updateConsensus(null);
2973 if (consensus == null)
2977 StringBuffer seqs = new StringBuffer();
2978 for (int i = 0; i < consensus.annotations.length; i++)
2980 Annotation annotation = consensus.annotations[i];
2981 if (annotation != null)
2983 String description = annotation.description;
2984 if (description != null && description.startsWith("["))
2986 // consensus is a tie - just pick the first one
2987 seqs.append(description.charAt(1));
2991 seqs.append(annotation.displayCharacter);
2996 SequenceI sq = new Sequence("Consensus", seqs.toString());
2997 sq.setDescription("Percentage Identity Consensus "
2998 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3003 public void setCurrentTree(TreeModel tree)
3009 public TreeModel getCurrentTree()
3015 public AlignmentExportData getAlignExportData(
3016 AlignExportSettingsI options)
3018 AlignmentI alignmentToExport = null;
3019 String[] omitHidden = null;
3020 alignmentToExport = null;
3022 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3024 omitHidden = getViewAsString(false,
3025 options.isExportHiddenSequences());
3028 int[] alignmentStartEnd = new int[2];
3029 if (hasHiddenRows() && options.isExportHiddenSequences())
3031 alignmentToExport = getAlignment().getHiddenSequences()
3032 .getFullAlignment();
3036 alignmentToExport = getAlignment();
3038 alignmentStartEnd = getAlignment().getHiddenColumns()
3039 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3040 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3041 omitHidden, alignmentStartEnd);
3046 * flag set to indicate if structure views might be out of sync with sequences
3050 private boolean needToUpdateStructureViews = false;
3053 public boolean isUpdateStructures()
3055 return needToUpdateStructureViews;
3059 public void setUpdateStructures(boolean update)
3061 needToUpdateStructureViews = update;
3065 public boolean needToUpdateStructureViews()
3067 boolean update = needToUpdateStructureViews;
3068 needToUpdateStructureViews = false;
3073 public void addSequenceGroup(SequenceGroup sequenceGroup)
3075 alignment.addGroup(sequenceGroup);
3077 Color col = sequenceGroup.idColour;
3080 col = col.brighter();
3082 for (SequenceI sq : sequenceGroup.getSequences())
3084 setSequenceColour(sq, col);
3088 if (codingComplement != null)
3090 SequenceGroup mappedGroup = MappingUtils
3091 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3092 if (mappedGroup.getSequences().size() > 0)
3094 codingComplement.getAlignment().addGroup(mappedGroup);
3098 for (SequenceI seq : mappedGroup.getSequences())
3100 codingComplement.setSequenceColour(seq, col);
3104 // propagate the structure view update flag according to our own setting
3105 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3110 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3114 if (selectedRegionOnly && selectionGroup != null)
3116 start = selectionGroup.getStartRes();
3117 end = selectionGroup.getEndRes() + 1;
3121 end = alignment.getWidth();
3123 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3127 public void setSavedUpToDate(boolean s)
3129 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3132 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3135 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3137 QuitHandler.setMessage(m);
3140 public boolean savedUpToDate()
3142 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3144 return savedUpToDate;