2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignExportSettingsI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.api.FeaturesDisplayedI;
31 import jalview.api.ViewStyleI;
32 import jalview.commands.CommandI;
33 import jalview.datamodel.AlignedCodonFrame;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentExportData;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.AlignmentView;
38 import jalview.datamodel.Annotation;
39 import jalview.datamodel.ColumnSelection;
40 import jalview.datamodel.HiddenColumns;
41 import jalview.datamodel.HiddenSequences;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.renderer.ResidueShader;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.ColourSchemeI;
51 import jalview.structure.CommandListener;
52 import jalview.structure.StructureSelectionManager;
53 import jalview.structure.VamsasSource;
54 import jalview.util.Comparison;
55 import jalview.util.MapList;
56 import jalview.util.MappingUtils;
57 import jalview.util.MessageManager;
58 import jalview.viewmodel.styles.ViewStyle;
59 import jalview.workers.AlignCalcManager;
60 import jalview.workers.ComplementConsensusThread;
61 import jalview.workers.ConsensusThread;
62 import jalview.workers.StrucConsensusThread;
64 import java.awt.Color;
65 import java.beans.PropertyChangeSupport;
66 import java.util.ArrayDeque;
67 import java.util.ArrayList;
68 import java.util.BitSet;
69 import java.util.Deque;
70 import java.util.HashMap;
71 import java.util.Hashtable;
72 import java.util.Iterator;
73 import java.util.List;
77 * base class holding visualization and analysis attributes and common logic for
78 * an active alignment view displayed in the GUI
83 public abstract class AlignmentViewport
84 implements AlignViewportI, CommandListener, VamsasSource
86 protected ViewportRanges ranges;
88 protected ViewStyleI viewStyle = new ViewStyle();
91 * A viewport that hosts the cDna view of this (protein), or vice versa (if
94 AlignViewportI codingComplement = null;
96 FeaturesDisplayedI featuresDisplayed = null;
98 protected Deque<CommandI> historyList = new ArrayDeque<>();
100 protected Deque<CommandI> redoList = new ArrayDeque<>();
103 * alignment displayed in the viewport. Please use get/setter
105 protected AlignmentI alignment;
107 public AlignmentViewport(AlignmentI al)
110 ranges = new ViewportRanges(al);
115 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
118 public void setFontName(String name)
120 viewStyle.setFontName(name);
125 * @see jalview.api.ViewStyleI#setFontStyle(int)
128 public void setFontStyle(int style)
130 viewStyle.setFontStyle(style);
135 * @see jalview.api.ViewStyleI#setFontSize(int)
138 public void setFontSize(int size)
140 viewStyle.setFontSize(size);
145 * @see jalview.api.ViewStyleI#getFontStyle()
148 public int getFontStyle()
150 return viewStyle.getFontStyle();
155 * @see jalview.api.ViewStyleI#getFontName()
158 public String getFontName()
160 return viewStyle.getFontName();
165 * @see jalview.api.ViewStyleI#getFontSize()
168 public int getFontSize()
170 return viewStyle.getFontSize();
174 * @param upperCasebold
175 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
178 public void setUpperCasebold(boolean upperCasebold)
180 viewStyle.setUpperCasebold(upperCasebold);
185 * @see jalview.api.ViewStyleI#isUpperCasebold()
188 public boolean isUpperCasebold()
190 return viewStyle.isUpperCasebold();
195 * @see jalview.api.ViewStyleI#isSeqNameItalics()
198 public boolean isSeqNameItalics()
200 return viewStyle.isSeqNameItalics();
204 * @param colourByReferenceSeq
205 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
208 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
210 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
215 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
218 public void setColourAppliesToAllGroups(boolean b)
220 viewStyle.setColourAppliesToAllGroups(b);
225 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
228 public boolean getColourAppliesToAllGroups()
230 return viewStyle.getColourAppliesToAllGroups();
235 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
238 public boolean getAbovePIDThreshold()
240 return viewStyle.getAbovePIDThreshold();
245 * @see jalview.api.ViewStyleI#setIncrement(int)
248 public void setIncrement(int inc)
250 viewStyle.setIncrement(inc);
255 * @see jalview.api.ViewStyleI#getIncrement()
258 public int getIncrement()
260 return viewStyle.getIncrement();
265 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
268 public void setConservationSelected(boolean b)
270 viewStyle.setConservationSelected(b);
275 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
278 public void setShowHiddenMarkers(boolean show)
280 viewStyle.setShowHiddenMarkers(show);
285 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
288 public boolean getShowHiddenMarkers()
290 return viewStyle.getShowHiddenMarkers();
295 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
298 public void setScaleRightWrapped(boolean b)
300 viewStyle.setScaleRightWrapped(b);
305 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
308 public void setScaleLeftWrapped(boolean b)
310 viewStyle.setScaleLeftWrapped(b);
315 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
318 public void setScaleAboveWrapped(boolean b)
320 viewStyle.setScaleAboveWrapped(b);
325 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
328 public boolean getScaleLeftWrapped()
330 return viewStyle.getScaleLeftWrapped();
335 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
338 public boolean getScaleAboveWrapped()
340 return viewStyle.getScaleAboveWrapped();
345 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
348 public boolean getScaleRightWrapped()
350 return viewStyle.getScaleRightWrapped();
355 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
358 public void setAbovePIDThreshold(boolean b)
360 viewStyle.setAbovePIDThreshold(b);
365 * @see jalview.api.ViewStyleI#setThreshold(int)
368 public void setThreshold(int thresh)
370 viewStyle.setThreshold(thresh);
375 * @see jalview.api.ViewStyleI#getThreshold()
378 public int getThreshold()
380 return viewStyle.getThreshold();
385 * @see jalview.api.ViewStyleI#getShowJVSuffix()
388 public boolean getShowJVSuffix()
390 return viewStyle.getShowJVSuffix();
395 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
398 public void setShowJVSuffix(boolean b)
400 viewStyle.setShowJVSuffix(b);
405 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
408 public void setWrapAlignment(boolean state)
410 viewStyle.setWrapAlignment(state);
411 ranges.setWrappedMode(state);
416 * @see jalview.api.ViewStyleI#setShowText(boolean)
419 public void setShowText(boolean state)
421 viewStyle.setShowText(state);
426 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
429 public void setRenderGaps(boolean state)
431 viewStyle.setRenderGaps(state);
436 * @see jalview.api.ViewStyleI#getColourText()
439 public boolean getColourText()
441 return viewStyle.getColourText();
446 * @see jalview.api.ViewStyleI#setColourText(boolean)
449 public void setColourText(boolean state)
451 viewStyle.setColourText(state);
456 * @see jalview.api.ViewStyleI#getWrapAlignment()
459 public boolean getWrapAlignment()
461 return viewStyle.getWrapAlignment();
466 * @see jalview.api.ViewStyleI#getShowText()
469 public boolean getShowText()
471 return viewStyle.getShowText();
476 * @see jalview.api.ViewStyleI#getWrappedWidth()
479 public int getWrappedWidth()
481 return viewStyle.getWrappedWidth();
486 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
489 public void setWrappedWidth(int w)
491 viewStyle.setWrappedWidth(w);
496 * @see jalview.api.ViewStyleI#getCharHeight()
499 public int getCharHeight()
501 return viewStyle.getCharHeight();
506 * @see jalview.api.ViewStyleI#setCharHeight(int)
509 public void setCharHeight(int h)
511 viewStyle.setCharHeight(h);
516 * @see jalview.api.ViewStyleI#getCharWidth()
519 public int getCharWidth()
521 return viewStyle.getCharWidth();
526 * @see jalview.api.ViewStyleI#setCharWidth(int)
529 public void setCharWidth(int w)
531 viewStyle.setCharWidth(w);
536 * @see jalview.api.ViewStyleI#getShowBoxes()
539 public boolean getShowBoxes()
541 return viewStyle.getShowBoxes();
546 * @see jalview.api.ViewStyleI#getShowUnconserved()
549 public boolean getShowUnconserved()
551 return viewStyle.getShowUnconserved();
555 * @param showunconserved
556 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
559 public void setShowUnconserved(boolean showunconserved)
561 viewStyle.setShowUnconserved(showunconserved);
566 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
569 public void setSeqNameItalics(boolean default1)
571 viewStyle.setSeqNameItalics(default1);
575 public AlignmentI getAlignment()
581 public char getGapCharacter()
583 return alignment.getGapCharacter();
586 protected String sequenceSetID;
589 * probably unused indicator that view is of a dataset rather than an
592 protected boolean isDataset = false;
594 public void setDataset(boolean b)
599 public boolean isDataset()
604 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
606 protected ColumnSelection colSel = new ColumnSelection();
608 public boolean autoCalculateConsensus = true;
610 protected boolean autoCalculateStrucConsensus = true;
612 protected boolean ignoreGapsInConsensusCalculation = false;
614 protected ResidueShaderI residueShading = new ResidueShader();
617 public void setGlobalColourScheme(ColourSchemeI cs)
619 // TODO: logic refactored from AlignFrame changeColour -
620 // TODO: autorecalc stuff should be changed to rely on the worker system
621 // check to see if we should implement a changeColour(cs) method rather than
622 // put the logic in here
623 // - means that caller decides if they want to just modify state and defer
624 // calculation till later or to do all calculations in thread.
628 * only instantiate alignment colouring once, thereafter update it;
629 * this means that any conservation or PID threshold settings
630 * persist when the alignment colour scheme is changed
632 if (residueShading == null)
634 residueShading = new ResidueShader(viewStyle);
636 residueShading.setColourScheme(cs);
638 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
639 // ...problem: groups need these, but do not currently have a ViewStyle
643 if (getConservationSelected())
645 residueShading.setConservation(hconservation);
648 * reset conservation flag in case just set to false if
649 * Conservation was null (calculation still in progress)
651 residueShading.setConservationApplied(getConservationSelected());
652 residueShading.alignmentChanged(alignment, hiddenRepSequences);
656 * if 'apply colour to all groups' is selected... do so
657 * (but don't transfer any colour threshold settings to groups)
659 if (getColourAppliesToAllGroups())
661 for (SequenceGroup sg : getAlignment().getGroups())
664 * retain any colour thresholds per group while
665 * changing choice of colour scheme (JAL-2386)
667 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
670 sg.getGroupColourScheme().alignmentChanged(sg,
678 public ColourSchemeI getGlobalColourScheme()
680 return residueShading == null ? null : residueShading.getColourScheme();
684 public ResidueShaderI getResidueShading()
686 return residueShading;
689 protected AlignmentAnnotation consensus;
691 protected AlignmentAnnotation complementConsensus;
693 protected AlignmentAnnotation gapcounts;
695 protected AlignmentAnnotation strucConsensus;
697 protected AlignmentAnnotation conservation;
699 protected AlignmentAnnotation quality;
701 protected AlignmentAnnotation[] groupConsensus;
703 protected AlignmentAnnotation[] groupConservation;
706 * results of alignment consensus analysis for visible portion of view
708 protected ProfilesI hconsensus = null;
711 * results of cDNA complement consensus visible portion of view
713 protected Hashtable<String, Object>[] hcomplementConsensus = null;
716 * results of secondary structure base pair consensus for visible portion of
719 protected Hashtable<String, Object>[] hStrucConsensus = null;
721 protected Conservation hconservation = null;
724 public void setConservation(Conservation cons)
726 hconservation = cons;
730 * percentage gaps allowed in a column before all amino acid properties should
731 * be considered unconserved
733 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
736 public int getConsPercGaps()
742 public void setSequenceConsensusHash(ProfilesI hconsensus)
744 this.hconsensus = hconsensus;
748 public void setComplementConsensusHash(
749 Hashtable<String, Object>[] hconsensus)
751 this.hcomplementConsensus = hconsensus;
755 public ProfilesI getSequenceConsensusHash()
761 public Hashtable<String, Object>[] getComplementConsensusHash()
763 return hcomplementConsensus;
767 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
769 return hStrucConsensus;
773 public void setRnaStructureConsensusHash(
774 Hashtable<String, Object>[] hStrucConsensus)
776 this.hStrucConsensus = hStrucConsensus;
781 public AlignmentAnnotation getAlignmentQualityAnnot()
787 public AlignmentAnnotation getAlignmentConservationAnnotation()
793 public AlignmentAnnotation getAlignmentConsensusAnnotation()
799 public AlignmentAnnotation getAlignmentGapAnnotation()
805 public AlignmentAnnotation getComplementConsensusAnnotation()
807 return complementConsensus;
811 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
813 return strucConsensus;
816 protected AlignCalcManagerI calculator = new AlignCalcManager();
819 * trigger update of conservation annotation
821 public void updateConservation(final AlignmentViewPanel ap)
823 // see note in mantis : issue number 8585
824 if (alignment.isNucleotide()
825 || (conservation == null && quality == null)
826 || !autoCalculateConsensus)
830 if (calculator.getRegisteredWorkersOfClass(
831 jalview.workers.ConservationThread.class) == null)
833 calculator.registerWorker(
834 new jalview.workers.ConservationThread(this, ap));
839 * trigger update of consensus annotation
841 public void updateConsensus(final AlignmentViewPanel ap)
843 // see note in mantis : issue number 8585
844 if (consensus == null || !autoCalculateConsensus)
849 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
851 calculator.registerWorker(new ConsensusThread(this, ap));
855 * A separate thread to compute cDNA consensus for a protein alignment
856 * which has mapping to cDNA
858 final AlignmentI al = this.getAlignment();
859 if (!al.isNucleotide() && al.getCodonFrames() != null
860 && !al.getCodonFrames().isEmpty())
863 * fudge - check first for protein-to-nucleotide mappings
864 * (we don't want to do this for protein-to-protein)
866 boolean doConsensus = false;
867 for (AlignedCodonFrame mapping : al.getCodonFrames())
869 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
870 MapList[] mapLists = mapping.getdnaToProt();
871 // mapLists can be empty if project load has not finished resolving seqs
872 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
880 if (calculator.getRegisteredWorkersOfClass(
881 ComplementConsensusThread.class) == null)
884 .registerWorker(new ComplementConsensusThread(this, ap));
890 // --------START Structure Conservation
891 public void updateStrucConsensus(final AlignmentViewPanel ap)
893 if (autoCalculateStrucConsensus && strucConsensus == null
894 && alignment.isNucleotide() && alignment.hasRNAStructure())
896 // secondary structure has been added - so init the consensus line
900 // see note in mantis : issue number 8585
901 if (strucConsensus == null || !autoCalculateStrucConsensus)
905 if (calculator.getRegisteredWorkersOfClass(
906 StrucConsensusThread.class) == null)
908 calculator.registerWorker(new StrucConsensusThread(this, ap));
912 public boolean isCalcInProgress()
914 return calculator.isWorking();
918 public boolean isCalculationInProgress(
919 AlignmentAnnotation alignmentAnnotation)
921 if (!alignmentAnnotation.autoCalculated)
925 if (calculator.workingInvolvedWith(alignmentAnnotation))
927 // System.err.println("grey out ("+alignmentAnnotation.label+")");
933 public void setAlignment(AlignmentI align)
935 this.alignment = align;
939 * Clean up references when this viewport is closed
942 public void dispose()
945 * defensively null out references to large objects in case
946 * this object is not garbage collected (as if!)
949 complementConsensus = null;
950 strucConsensus = null;
953 groupConsensus = null;
954 groupConservation = null;
956 hconservation = null;
957 hcomplementConsensus = null;
960 residueShading = null; // may hold a reference to Consensus
961 changeSupport = null;
964 selectionGroup = null;
970 public boolean isClosed()
972 // TODO: check that this isClosed is only true after panel is closed, not
973 // before it is fully constructed.
974 return alignment == null;
978 public AlignCalcManagerI getCalcManager()
984 * should conservation rows be shown for groups
986 protected boolean showGroupConservation = false;
989 * should consensus rows be shown for groups
991 protected boolean showGroupConsensus = false;
994 * should consensus profile be rendered by default
996 protected boolean showSequenceLogo = false;
999 * should consensus profile be rendered normalised to row height
1001 protected boolean normaliseSequenceLogo = false;
1004 * should consensus histograms be rendered by default
1006 protected boolean showConsensusHistogram = true;
1009 * @return the showConsensusProfile
1012 public boolean isShowSequenceLogo()
1014 return showSequenceLogo;
1018 * @param showSequenceLogo
1021 public void setShowSequenceLogo(boolean showSequenceLogo)
1023 if (showSequenceLogo != this.showSequenceLogo)
1025 // TODO: decouple settings setting from calculation when refactoring
1026 // annotation update method from alignframe to viewport
1027 this.showSequenceLogo = showSequenceLogo;
1028 calculator.updateAnnotationFor(ConsensusThread.class);
1029 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1030 calculator.updateAnnotationFor(StrucConsensusThread.class);
1032 this.showSequenceLogo = showSequenceLogo;
1036 * @param showConsensusHistogram
1037 * the showConsensusHistogram to set
1039 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1041 this.showConsensusHistogram = showConsensusHistogram;
1045 * @return the showGroupConservation
1047 public boolean isShowGroupConservation()
1049 return showGroupConservation;
1053 * @param showGroupConservation
1054 * the showGroupConservation to set
1056 public void setShowGroupConservation(boolean showGroupConservation)
1058 this.showGroupConservation = showGroupConservation;
1062 * @return the showGroupConsensus
1064 public boolean isShowGroupConsensus()
1066 return showGroupConsensus;
1070 * @param showGroupConsensus
1071 * the showGroupConsensus to set
1073 public void setShowGroupConsensus(boolean showGroupConsensus)
1075 this.showGroupConsensus = showGroupConsensus;
1080 * @return flag to indicate if the consensus histogram should be rendered by
1084 public boolean isShowConsensusHistogram()
1086 return this.showConsensusHistogram;
1090 * when set, updateAlignment will always ensure sequences are of equal length
1092 private boolean padGaps = false;
1095 * when set, alignment should be reordered according to a newly opened tree
1097 public boolean sortByTree = false;
1102 * @return null or the currently selected sequence region
1105 public SequenceGroup getSelectionGroup()
1107 return selectionGroup;
1111 * Set the selection group for this window. Also sets the current alignment as
1112 * the context for the group, if it does not already have one.
1115 * - group holding references to sequences in this alignment view
1119 public void setSelectionGroup(SequenceGroup sg)
1121 selectionGroup = sg;
1122 if (sg != null && sg.getContext() == null)
1124 sg.setContext(alignment);
1128 public void setHiddenColumns(HiddenColumns hidden)
1130 this.alignment.setHiddenColumns(hidden);
1134 public ColumnSelection getColumnSelection()
1140 public void setColumnSelection(ColumnSelection colSel)
1142 this.colSel = colSel;
1145 updateHiddenColumns();
1147 isColSelChanged(true);
1155 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1157 return hiddenRepSequences;
1161 public void setHiddenRepSequences(
1162 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1164 this.hiddenRepSequences = hiddenRepSequences;
1168 public boolean hasSelectedColumns()
1170 ColumnSelection columnSelection = getColumnSelection();
1171 return columnSelection != null && columnSelection.hasSelectedColumns();
1175 public boolean hasHiddenColumns()
1177 return alignment.getHiddenColumns() != null
1178 && alignment.getHiddenColumns().hasHiddenColumns();
1181 public void updateHiddenColumns()
1183 // this method doesn't really do anything now. But - it could, since a
1184 // column Selection could be in the process of modification
1185 // hasHiddenColumns = colSel.hasHiddenColumns();
1189 public boolean hasHiddenRows()
1191 return alignment.getHiddenSequences().getSize() > 0;
1194 protected SequenceGroup selectionGroup;
1196 public void setSequenceSetId(String newid)
1198 if (sequenceSetID != null)
1201 "Warning - overwriting a sequenceSetId for a viewport!");
1203 sequenceSetID = new String(newid);
1207 public String getSequenceSetId()
1209 if (sequenceSetID == null)
1211 sequenceSetID = alignment.hashCode() + "";
1214 return sequenceSetID;
1218 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1221 protected String viewId = null;
1224 public String getViewId()
1228 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1233 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1235 ignoreGapsInConsensusCalculation = b;
1238 updateConsensus(ap);
1239 if (residueShading != null)
1241 residueShading.setThreshold(residueShading.getThreshold(),
1242 ignoreGapsInConsensusCalculation);
1248 private long sgrouphash = -1, colselhash = -1;
1251 * checks current SelectionGroup against record of last hash value, and
1255 * update the record of last hash value
1257 * @return true if SelectionGroup changed since last call (when b is true)
1259 public boolean isSelectionGroupChanged(boolean b)
1261 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1262 : selectionGroup.hashCode();
1263 if (hc != -1 && hc != sgrouphash)
1275 * checks current colsel against record of last hash value, and optionally
1279 * update the record of last hash value
1280 * @return true if colsel changed since last call (when b is true)
1282 public boolean isColSelChanged(boolean b)
1284 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1285 if (hc != -1 && hc != colselhash)
1297 public boolean isIgnoreGapsConsensus()
1299 return ignoreGapsInConsensusCalculation;
1302 // property change stuff
1303 // JBPNote Prolly only need this in the applet version.
1304 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1307 protected boolean showConservation = true;
1309 protected boolean showQuality = true;
1311 protected boolean showConsensus = true;
1313 protected boolean showOccupancy = true;
1315 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1317 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1319 protected boolean showAutocalculatedAbove;
1322 * when set, view will scroll to show the highlighted position
1324 private boolean followHighlight = true;
1327 * Property change listener for changes in alignment
1332 public void addPropertyChangeListener(
1333 java.beans.PropertyChangeListener listener)
1335 changeSupport.addPropertyChangeListener(listener);
1344 public void removePropertyChangeListener(
1345 java.beans.PropertyChangeListener listener)
1347 if (changeSupport != null)
1349 changeSupport.removePropertyChangeListener(listener);
1354 * Property change listener for changes in alignment
1363 public void firePropertyChange(String prop, Object oldvalue,
1366 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1369 // common hide/show column stuff
1371 public void hideSelectedColumns()
1373 if (colSel.isEmpty())
1378 colSel.hideSelectedColumns(alignment);
1379 setSelectionGroup(null);
1380 isColSelChanged(true);
1383 public void hideColumns(int start, int end)
1387 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1391 alignment.getHiddenColumns().hideColumns(start, end);
1393 isColSelChanged(true);
1396 public void showColumn(int col)
1398 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1399 isColSelChanged(true);
1402 public void showAllHiddenColumns()
1404 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1405 isColSelChanged(true);
1408 // common hide/show seq stuff
1409 public void showAllHiddenSeqs()
1411 int startSeq = ranges.getStartSeq();
1412 int endSeq = ranges.getEndSeq();
1414 if (alignment.getHiddenSequences().getSize() > 0)
1416 if (selectionGroup == null)
1418 selectionGroup = new SequenceGroup();
1419 selectionGroup.setEndRes(alignment.getWidth() - 1);
1421 List<SequenceI> tmp = alignment.getHiddenSequences()
1422 .showAll(hiddenRepSequences);
1423 for (SequenceI seq : tmp)
1425 selectionGroup.addSequence(seq, false);
1426 setSequenceAnnotationsVisible(seq, true);
1429 hiddenRepSequences = null;
1431 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1433 firePropertyChange("alignment", null, alignment.getSequences());
1434 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1440 public void showSequence(int index)
1442 int startSeq = ranges.getStartSeq();
1443 int endSeq = ranges.getEndSeq();
1445 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1446 hiddenRepSequences);
1449 if (selectionGroup == null)
1451 selectionGroup = new SequenceGroup();
1452 selectionGroup.setEndRes(alignment.getWidth() - 1);
1455 for (SequenceI seq : tmp)
1457 selectionGroup.addSequence(seq, false);
1458 setSequenceAnnotationsVisible(seq, true);
1461 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1463 firePropertyChange("alignment", null, alignment.getSequences());
1468 public void hideAllSelectedSeqs()
1470 if (selectionGroup == null || selectionGroup.getSize() < 1)
1475 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1479 setSelectionGroup(null);
1482 public void hideSequence(SequenceI[] seq)
1485 * cache offset to first visible sequence
1487 int startSeq = ranges.getStartSeq();
1491 for (int i = 0; i < seq.length; i++)
1493 alignment.getHiddenSequences().hideSequence(seq[i]);
1494 setSequenceAnnotationsVisible(seq[i], false);
1496 ranges.setStartSeq(startSeq);
1497 firePropertyChange("alignment", null, alignment.getSequences());
1502 * Hides the specified sequence, or the sequences it represents
1505 * the sequence to hide, or keep as representative
1506 * @param representGroup
1507 * if true, hide the current selection group except for the
1508 * representative sequence
1510 public void hideSequences(SequenceI sequence, boolean representGroup)
1512 if (selectionGroup == null || selectionGroup.getSize() < 1)
1514 hideSequence(new SequenceI[] { sequence });
1520 hideRepSequences(sequence, selectionGroup);
1521 setSelectionGroup(null);
1525 int gsize = selectionGroup.getSize();
1526 SequenceI[] hseqs = selectionGroup.getSequences()
1527 .toArray(new SequenceI[gsize]);
1529 hideSequence(hseqs);
1530 setSelectionGroup(null);
1535 * Set visibility for any annotations for the given sequence.
1539 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1542 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1545 for (AlignmentAnnotation ann : anns)
1547 if (ann.sequenceRef == sequenceI)
1549 ann.visible = visible;
1555 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1557 int sSize = sg.getSize();
1563 if (hiddenRepSequences == null)
1565 hiddenRepSequences = new Hashtable<>();
1568 hiddenRepSequences.put(repSequence, sg);
1570 // Hide all sequences except the repSequence
1571 SequenceI[] seqs = new SequenceI[sSize - 1];
1573 for (int i = 0; i < sSize; i++)
1575 if (sg.getSequenceAt(i) != repSequence)
1577 if (index == sSize - 1)
1582 seqs[index++] = sg.getSequenceAt(i);
1585 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1586 sg.setHidereps(true); // note: not done in 2.7applet
1593 * @return null or the current reference sequence
1595 public SequenceI getReferenceSeq()
1597 return alignment.getSeqrep();
1602 * @return true iff seq is the reference for the alignment
1604 public boolean isReferenceSeq(SequenceI seq)
1606 return alignment.getSeqrep() == seq;
1612 * @return true if there are sequences represented by this sequence that are
1615 public boolean isHiddenRepSequence(SequenceI seq)
1617 return (hiddenRepSequences != null
1618 && hiddenRepSequences.containsKey(seq));
1624 * @return null or a sequence group containing the sequences that seq
1627 public SequenceGroup getRepresentedSequences(SequenceI seq)
1629 return (SequenceGroup) (hiddenRepSequences == null ? null
1630 : hiddenRepSequences.get(seq));
1634 public int adjustForHiddenSeqs(int alignmentIndex)
1636 return alignment.getHiddenSequences()
1637 .adjustForHiddenSeqs(alignmentIndex);
1641 public void invertColumnSelection()
1643 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1644 isColSelChanged(true);
1648 public SequenceI[] getSelectionAsNewSequence()
1650 SequenceI[] sequences;
1651 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1652 // this was the only caller in the applet for this method
1653 // JBPNote: in applet, this method returned references to the alignment
1654 // sequences, and it did not honour the presence/absence of annotation
1655 // attached to the alignment (probably!)
1656 if (selectionGroup == null || selectionGroup.getSize() == 0)
1658 sequences = alignment.getSequencesArray();
1659 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1660 for (int i = 0; i < sequences.length; i++)
1662 // construct new sequence with subset of visible annotation
1663 sequences[i] = new Sequence(sequences[i], annots);
1668 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1675 public SequenceI[] getSequenceSelection()
1677 SequenceI[] sequences = null;
1678 if (selectionGroup != null)
1680 sequences = selectionGroup.getSequencesInOrder(alignment);
1682 if (sequences == null)
1684 sequences = alignment.getSequencesArray();
1690 public jalview.datamodel.AlignmentView getAlignmentView(
1691 boolean selectedOnly)
1693 return getAlignmentView(selectedOnly, false);
1697 public jalview.datamodel.AlignmentView getAlignmentView(
1698 boolean selectedOnly, boolean markGroups)
1700 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1702 alignment.getHiddenColumns() != null
1703 && alignment.getHiddenColumns().hasHiddenColumns(),
1704 selectedOnly, markGroups);
1708 public String[] getViewAsString(boolean selectedRegionOnly)
1710 return getViewAsString(selectedRegionOnly, true);
1714 public String[] getViewAsString(boolean selectedRegionOnly,
1715 boolean exportHiddenSeqs)
1717 String[] selection = null;
1718 SequenceI[] seqs = null;
1720 int start = 0, end = 0;
1721 if (selectedRegionOnly && selectionGroup != null)
1723 iSize = selectionGroup.getSize();
1724 seqs = selectionGroup.getSequencesInOrder(alignment);
1725 start = selectionGroup.getStartRes();
1726 end = selectionGroup.getEndRes() + 1;
1730 if (hasHiddenRows() && exportHiddenSeqs)
1732 AlignmentI fullAlignment = alignment.getHiddenSequences()
1733 .getFullAlignment();
1734 iSize = fullAlignment.getHeight();
1735 seqs = fullAlignment.getSequencesArray();
1736 end = fullAlignment.getWidth();
1740 iSize = alignment.getHeight();
1741 seqs = alignment.getSequencesArray();
1742 end = alignment.getWidth();
1746 selection = new String[iSize];
1747 if (alignment.getHiddenColumns() != null
1748 && alignment.getHiddenColumns().hasHiddenColumns())
1750 for (i = 0; i < iSize; i++)
1752 Iterator<int[]> blocks = alignment.getHiddenColumns()
1753 .getVisContigsIterator(start, end + 1, false);
1754 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1759 for (i = 0; i < iSize; i++)
1761 selection[i] = seqs[i].getSequenceAsString(start, end);
1769 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1771 ArrayList<int[]> regions = new ArrayList<>();
1777 HiddenColumns hidden = alignment.getHiddenColumns();
1778 if (hidden != null && hidden.hasHiddenColumns())
1782 start = hidden.visibleToAbsoluteColumn(start);
1785 end = hidden.getNextHiddenBoundary(false, start);
1796 regions.add(new int[] { start, end });
1798 if (hidden != null && hidden.hasHiddenColumns())
1800 start = hidden.visibleToAbsoluteColumn(end);
1801 start = hidden.getNextHiddenBoundary(true, start) + 1;
1803 } while (end < max);
1805 // int[][] startEnd = new int[regions.size()][2];
1811 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1812 boolean selectedOnly)
1814 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1815 AlignmentAnnotation[] aa;
1816 if ((aa = alignment.getAlignmentAnnotation()) != null)
1818 for (AlignmentAnnotation annot : aa)
1820 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1821 if (selectedOnly && selectionGroup != null)
1823 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1824 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1828 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1837 public boolean isPadGaps()
1843 public void setPadGaps(boolean padGaps)
1845 this.padGaps = padGaps;
1849 * apply any post-edit constraints and trigger any calculations needed after
1850 * an edit has been performed on the alignment
1855 public void alignmentChanged(AlignmentViewPanel ap)
1859 alignment.padGaps();
1861 if (autoCalculateConsensus)
1863 updateConsensus(ap);
1865 if (hconsensus != null && autoCalculateConsensus)
1867 updateConservation(ap);
1869 if (autoCalculateStrucConsensus)
1871 updateStrucConsensus(ap);
1874 // Reset endRes of groups if beyond alignment width
1875 int alWidth = alignment.getWidth();
1876 List<SequenceGroup> groups = alignment.getGroups();
1879 for (SequenceGroup sg : groups)
1881 if (sg.getEndRes() > alWidth)
1883 sg.setEndRes(alWidth - 1);
1888 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1890 selectionGroup.setEndRes(alWidth - 1);
1893 updateAllColourSchemes();
1894 calculator.restartWorkers();
1895 // alignment.adjustSequenceAnnotations();
1899 * reset scope and do calculations for all applied colourschemes on alignment
1901 void updateAllColourSchemes()
1903 ResidueShaderI rs = residueShading;
1906 rs.alignmentChanged(alignment, hiddenRepSequences);
1908 rs.setConsensus(hconsensus);
1909 if (rs.conservationApplied())
1911 rs.setConservation(Conservation.calculateConservation("All",
1912 alignment.getSequences(), 0, alignment.getWidth(), false,
1913 getConsPercGaps(), false));
1917 for (SequenceGroup sg : alignment.getGroups())
1921 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1923 sg.recalcConservation();
1927 protected void initAutoAnnotation()
1929 // TODO: add menu option action that nulls or creates consensus object
1930 // depending on if the user wants to see the annotation or not in a
1931 // specific alignment
1933 if (hconsensus == null && !isDataset)
1935 if (!alignment.isNucleotide())
1944 consensus = new AlignmentAnnotation("Consensus",
1945 MessageManager.getString("label.consensus_descr"),
1946 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1947 initConsensus(consensus);
1950 initComplementConsensus();
1955 * If this is a protein alignment and there are mappings to cDNA, adds the
1956 * cDNA consensus annotation and returns true, else returns false.
1958 public boolean initComplementConsensus()
1960 if (!alignment.isNucleotide())
1962 final List<AlignedCodonFrame> codonMappings = alignment
1964 if (codonMappings != null && !codonMappings.isEmpty())
1966 boolean doConsensus = false;
1967 for (AlignedCodonFrame mapping : codonMappings)
1969 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1970 MapList[] mapLists = mapping.getdnaToProt();
1971 // mapLists can be empty if project load has not finished resolving
1973 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1981 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1983 .getString("label.complement_consensus_descr"),
1984 new Annotation[1], 0f, 100f,
1985 AlignmentAnnotation.BAR_GRAPH);
1986 initConsensus(complementConsensus);
1994 private void initConsensus(AlignmentAnnotation aa)
1997 aa.autoCalculated = true;
2001 alignment.addAnnotation(aa);
2005 // these should be extracted from the view model - style and settings for
2006 // derived annotation
2007 private void initGapCounts()
2011 gapcounts = new AlignmentAnnotation("Occupancy",
2012 MessageManager.getString("label.occupancy_descr"),
2013 new Annotation[1], 0f, alignment.getHeight(),
2014 AlignmentAnnotation.BAR_GRAPH);
2015 gapcounts.hasText = true;
2016 gapcounts.autoCalculated = true;
2017 gapcounts.scaleColLabel = true;
2018 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2020 alignment.addAnnotation(gapcounts);
2024 private void initConservation()
2026 if (showConservation)
2028 if (conservation == null)
2030 conservation = new AlignmentAnnotation("Conservation",
2031 MessageManager.formatMessage("label.conservation_descr",
2033 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2034 conservation.hasText = true;
2035 conservation.autoCalculated = true;
2036 alignment.addAnnotation(conservation);
2041 private void initQuality()
2045 if (quality == null)
2047 quality = new AlignmentAnnotation("Quality",
2048 MessageManager.getString("label.quality_descr"),
2049 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2050 quality.hasText = true;
2051 quality.autoCalculated = true;
2052 alignment.addAnnotation(quality);
2057 private void initRNAStructure()
2059 if (alignment.hasRNAStructure() && strucConsensus == null)
2061 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2062 MessageManager.getString("label.strucconsensus_descr"),
2063 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2064 strucConsensus.hasText = true;
2065 strucConsensus.autoCalculated = true;
2069 alignment.addAnnotation(strucConsensus);
2077 * @see jalview.api.AlignViewportI#calcPanelHeight()
2080 public int calcPanelHeight()
2082 // setHeight of panels
2083 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2085 int charHeight = getCharHeight();
2088 BitSet graphgrp = new BitSet();
2089 for (AlignmentAnnotation aa : anns)
2093 System.err.println("Null annotation row: ignoring.");
2100 if (aa.graphGroup > -1)
2102 if (graphgrp.get(aa.graphGroup))
2108 graphgrp.set(aa.graphGroup);
2115 aa.height += charHeight;
2125 aa.height += aa.graphHeight;
2133 height += aa.height;
2145 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2146 boolean preserveNewGroupSettings)
2148 boolean updateCalcs = false;
2149 boolean conv = isShowGroupConservation();
2150 boolean cons = isShowGroupConsensus();
2151 boolean showprf = isShowSequenceLogo();
2152 boolean showConsHist = isShowConsensusHistogram();
2153 boolean normLogo = isNormaliseSequenceLogo();
2156 * TODO reorder the annotation rows according to group/sequence ordering on
2159 // boolean sortg = true;
2161 // remove old automatic annotation
2162 // add any new annotation
2164 // intersect alignment annotation with alignment groups
2166 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2167 List<SequenceGroup> oldrfs = new ArrayList<>();
2170 for (int an = 0; an < aan.length; an++)
2172 if (aan[an].autoCalculated && aan[an].groupRef != null)
2174 oldrfs.add(aan[an].groupRef);
2175 alignment.deleteAnnotation(aan[an], false);
2179 if (alignment.getGroups() != null)
2181 for (SequenceGroup sg : alignment.getGroups())
2183 updateCalcs = false;
2184 if (applyGlobalSettings
2185 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2187 // set defaults for this group's conservation/consensus
2188 sg.setshowSequenceLogo(showprf);
2189 sg.setShowConsensusHistogram(showConsHist);
2190 sg.setNormaliseSequenceLogo(normLogo);
2195 alignment.addAnnotation(sg.getConservationRow(), 0);
2200 alignment.addAnnotation(sg.getConsensus(), 0);
2202 // refresh the annotation rows
2205 sg.recalcConservation();
2213 public boolean isDisplayReferenceSeq()
2215 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2219 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2221 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2225 public boolean isColourByReferenceSeq()
2227 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2231 public Color getSequenceColour(SequenceI seq)
2233 Color sqc = sequenceColours.get(seq);
2234 return (sqc == null ? Color.white : sqc);
2238 public void setSequenceColour(SequenceI seq, Color col)
2242 sequenceColours.remove(seq);
2246 sequenceColours.put(seq, col);
2251 public void updateSequenceIdColours()
2253 for (SequenceGroup sg : alignment.getGroups())
2255 if (sg.idColour != null)
2257 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2259 sequenceColours.put(s, sg.idColour);
2266 public void clearSequenceColours()
2268 sequenceColours.clear();
2272 public AlignViewportI getCodingComplement()
2274 return this.codingComplement;
2278 * Set this as the (cDna/protein) complement of the given viewport. Also
2279 * ensures the reverse relationship is set on the given viewport.
2282 public void setCodingComplement(AlignViewportI av)
2286 System.err.println("Ignoring recursive setCodingComplement request");
2290 this.codingComplement = av;
2291 // avoid infinite recursion!
2292 if (av.getCodingComplement() != this)
2294 av.setCodingComplement(this);
2300 public boolean isNucleotide()
2302 return getAlignment() == null ? false : getAlignment().isNucleotide();
2306 public FeaturesDisplayedI getFeaturesDisplayed()
2308 return featuresDisplayed;
2312 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2314 featuresDisplayed = featuresDisplayedI;
2318 public boolean areFeaturesDisplayed()
2320 return featuresDisplayed != null
2321 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2328 * features are displayed if true
2331 public void setShowSequenceFeatures(boolean b)
2333 viewStyle.setShowSequenceFeatures(b);
2337 public boolean isShowSequenceFeatures()
2339 return viewStyle.isShowSequenceFeatures();
2343 public void setShowSequenceFeaturesHeight(boolean selected)
2345 viewStyle.setShowSequenceFeaturesHeight(selected);
2349 public boolean isShowSequenceFeaturesHeight()
2351 return viewStyle.isShowSequenceFeaturesHeight();
2355 public void setShowAnnotation(boolean b)
2357 viewStyle.setShowAnnotation(b);
2361 public boolean isShowAnnotation()
2363 return viewStyle.isShowAnnotation();
2367 public boolean isRightAlignIds()
2369 return viewStyle.isRightAlignIds();
2373 public void setRightAlignIds(boolean rightAlignIds)
2375 viewStyle.setRightAlignIds(rightAlignIds);
2379 public boolean getConservationSelected()
2381 return viewStyle.getConservationSelected();
2385 public void setShowBoxes(boolean state)
2387 viewStyle.setShowBoxes(state);
2392 * @see jalview.api.ViewStyleI#getTextColour()
2395 public Color getTextColour()
2397 return viewStyle.getTextColour();
2402 * @see jalview.api.ViewStyleI#getTextColour2()
2405 public Color getTextColour2()
2407 return viewStyle.getTextColour2();
2412 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2415 public int getThresholdTextColour()
2417 return viewStyle.getThresholdTextColour();
2422 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2425 public boolean isConservationColourSelected()
2427 return viewStyle.isConservationColourSelected();
2432 * @see jalview.api.ViewStyleI#isRenderGaps()
2435 public boolean isRenderGaps()
2437 return viewStyle.isRenderGaps();
2442 * @see jalview.api.ViewStyleI#isShowColourText()
2445 public boolean isShowColourText()
2447 return viewStyle.isShowColourText();
2451 * @param conservationColourSelected
2452 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2455 public void setConservationColourSelected(
2456 boolean conservationColourSelected)
2458 viewStyle.setConservationColourSelected(conservationColourSelected);
2462 * @param showColourText
2463 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2466 public void setShowColourText(boolean showColourText)
2468 viewStyle.setShowColourText(showColourText);
2473 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2476 public void setTextColour(Color textColour)
2478 viewStyle.setTextColour(textColour);
2482 * @param thresholdTextColour
2483 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2486 public void setThresholdTextColour(int thresholdTextColour)
2488 viewStyle.setThresholdTextColour(thresholdTextColour);
2492 * @param textColour2
2493 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2496 public void setTextColour2(Color textColour2)
2498 viewStyle.setTextColour2(textColour2);
2502 public ViewStyleI getViewStyle()
2504 return new ViewStyle(viewStyle);
2508 public void setViewStyle(ViewStyleI settingsForView)
2510 viewStyle = new ViewStyle(settingsForView);
2511 if (residueShading != null)
2513 residueShading.setConservationApplied(
2514 settingsForView.isConservationColourSelected());
2519 public boolean sameStyle(ViewStyleI them)
2521 return viewStyle.sameStyle(them);
2526 * @see jalview.api.ViewStyleI#getIdWidth()
2529 public int getIdWidth()
2531 return viewStyle.getIdWidth();
2536 * @see jalview.api.ViewStyleI#setIdWidth(int)
2539 public void setIdWidth(int i)
2541 viewStyle.setIdWidth(i);
2546 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2549 public boolean isCentreColumnLabels()
2551 return viewStyle.isCentreColumnLabels();
2555 * @param centreColumnLabels
2556 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2559 public void setCentreColumnLabels(boolean centreColumnLabels)
2561 viewStyle.setCentreColumnLabels(centreColumnLabels);
2566 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2569 public void setShowDBRefs(boolean showdbrefs)
2571 viewStyle.setShowDBRefs(showdbrefs);
2576 * @see jalview.api.ViewStyleI#isShowDBRefs()
2579 public boolean isShowDBRefs()
2581 return viewStyle.isShowDBRefs();
2586 * @see jalview.api.ViewStyleI#isShowNPFeats()
2589 public boolean isShowNPFeats()
2591 return viewStyle.isShowNPFeats();
2595 * @param shownpfeats
2596 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2599 public void setShowNPFeats(boolean shownpfeats)
2601 viewStyle.setShowNPFeats(shownpfeats);
2604 public abstract StructureSelectionManager getStructureSelectionManager();
2607 * Add one command to the command history list.
2611 public void addToHistoryList(CommandI command)
2613 if (this.historyList != null)
2615 this.historyList.push(command);
2616 broadcastCommand(command, false);
2620 protected void broadcastCommand(CommandI command, boolean undo)
2622 getStructureSelectionManager().commandPerformed(command, undo,
2627 * Add one command to the command redo list.
2631 public void addToRedoList(CommandI command)
2633 if (this.redoList != null)
2635 this.redoList.push(command);
2637 broadcastCommand(command, true);
2641 * Clear the command redo list.
2643 public void clearRedoList()
2645 if (this.redoList != null)
2647 this.redoList.clear();
2651 public void setHistoryList(Deque<CommandI> list)
2653 this.historyList = list;
2656 public Deque<CommandI> getHistoryList()
2658 return this.historyList;
2661 public void setRedoList(Deque<CommandI> list)
2663 this.redoList = list;
2666 public Deque<CommandI> getRedoList()
2668 return this.redoList;
2672 public VamsasSource getVamsasSource()
2677 public SequenceAnnotationOrder getSortAnnotationsBy()
2679 return sortAnnotationsBy;
2682 public void setSortAnnotationsBy(
2683 SequenceAnnotationOrder sortAnnotationsBy)
2685 this.sortAnnotationsBy = sortAnnotationsBy;
2688 public boolean isShowAutocalculatedAbove()
2690 return showAutocalculatedAbove;
2693 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2695 this.showAutocalculatedAbove = showAutocalculatedAbove;
2699 public boolean isScaleProteinAsCdna()
2701 return viewStyle.isScaleProteinAsCdna();
2705 public void setScaleProteinAsCdna(boolean b)
2707 viewStyle.setScaleProteinAsCdna(b);
2711 public boolean isProteinFontAsCdna()
2713 return viewStyle.isProteinFontAsCdna();
2717 public void setProteinFontAsCdna(boolean b)
2719 viewStyle.setProteinFontAsCdna(b);
2723 public void setShowComplementFeatures(boolean b)
2725 viewStyle.setShowComplementFeatures(b);
2729 public boolean isShowComplementFeatures()
2731 return viewStyle.isShowComplementFeatures();
2735 public void setShowComplementFeaturesOnTop(boolean b)
2737 viewStyle.setShowComplementFeaturesOnTop(b);
2741 public boolean isShowComplementFeaturesOnTop()
2743 return viewStyle.isShowComplementFeaturesOnTop();
2747 * @return true if view should scroll to show the highlighted region of a
2752 public final boolean isFollowHighlight()
2754 return followHighlight;
2758 public final void setFollowHighlight(boolean b)
2760 this.followHighlight = b;
2764 public ViewportRanges getRanges()
2770 * Helper method to populate the SearchResults with the location in the
2771 * complementary alignment to scroll to, in order to match this one.
2774 * the SearchResults to add to
2775 * @return the offset (below top of visible region) of the matched sequence
2777 protected int findComplementScrollTarget(SearchResultsI sr)
2779 final AlignViewportI complement = getCodingComplement();
2780 if (complement == null || !complement.isFollowHighlight())
2784 boolean iAmProtein = !getAlignment().isNucleotide();
2785 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2786 : complement.getAlignment();
2787 if (proteinAlignment == null)
2791 final List<AlignedCodonFrame> mappings = proteinAlignment
2795 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2796 * residue in the middle column of the visible region. Scroll the
2797 * complementary alignment to line up the corresponding residue.
2800 SequenceI sequence = null;
2803 * locate 'middle' column (true middle if an odd number visible, left of
2804 * middle if an even number visible)
2806 int middleColumn = ranges.getStartRes()
2807 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2808 final HiddenSequences hiddenSequences = getAlignment()
2809 .getHiddenSequences();
2812 * searching to the bottom of the alignment gives smoother scrolling across
2813 * all gapped visible regions
2815 int lastSeq = alignment.getHeight() - 1;
2816 List<AlignedCodonFrame> seqMappings = null;
2817 for (int seqNo = ranges
2818 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2820 sequence = getAlignment().getSequenceAt(seqNo);
2821 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2825 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2829 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2831 getCodingComplement().getAlignment().getSequences());
2832 if (!seqMappings.isEmpty())
2838 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2841 * No ungapped mapped sequence in middle column - do nothing
2845 MappingUtils.addSearchResults(sr, sequence,
2846 sequence.findPosition(middleColumn), seqMappings);
2851 * synthesize a column selection if none exists so it covers the given
2852 * selection group. if wholewidth is false, no column selection is made if the
2853 * selection group covers the whole alignment width.
2858 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2861 if (sg != null && (sgs = sg.getStartRes()) >= 0
2862 && sg.getStartRes() <= (sge = sg.getEndRes())
2863 && !this.hasSelectedColumns())
2865 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2872 colSel = new ColumnSelection();
2874 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2876 colSel.addElement(cspos);
2882 * hold status of current selection group - defined on alignment or not.
2884 private boolean selectionIsDefinedGroup = false;
2887 public boolean isSelectionDefinedGroup()
2889 if (selectionGroup == null)
2893 if (isSelectionGroupChanged(true))
2895 selectionIsDefinedGroup = false;
2896 List<SequenceGroup> gps = alignment.getGroups();
2897 if (gps == null || gps.size() == 0)
2899 selectionIsDefinedGroup = false;
2903 selectionIsDefinedGroup = gps.contains(selectionGroup);
2906 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2910 * null, or currently highlighted results on this view
2912 private SearchResultsI searchResults = null;
2914 protected TreeModel currentTree = null;
2917 public boolean hasSearchResults()
2919 return searchResults != null;
2923 public void setSearchResults(SearchResultsI results)
2925 searchResults = results;
2929 public SearchResultsI getSearchResults()
2931 return searchResults;
2935 * get the consensus sequence as displayed under the PID consensus annotation
2938 * @return consensus sequence as a new sequence object
2940 public SequenceI getConsensusSeq()
2942 if (consensus == null)
2944 updateConsensus(null);
2946 if (consensus == null)
2950 StringBuffer seqs = new StringBuffer();
2951 for (int i = 0; i < consensus.annotations.length; i++)
2953 Annotation annotation = consensus.annotations[i];
2954 if (annotation != null)
2956 String description = annotation.description;
2957 if (description != null && description.startsWith("["))
2959 // consensus is a tie - just pick the first one
2960 seqs.append(description.charAt(1));
2964 seqs.append(annotation.displayCharacter);
2969 SequenceI sq = new Sequence("Consensus", seqs.toString());
2970 sq.setDescription("Percentage Identity Consensus "
2971 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2976 public void setCurrentTree(TreeModel tree)
2982 public TreeModel getCurrentTree()
2988 public AlignmentExportData getAlignExportData(
2989 AlignExportSettingsI options)
2991 AlignmentI alignmentToExport = null;
2992 String[] omitHidden = null;
2993 alignmentToExport = null;
2995 if (hasHiddenColumns() && !options.isExportHiddenColumns())
2997 omitHidden = getViewAsString(false,
2998 options.isExportHiddenSequences());
3001 int[] alignmentStartEnd = new int[2];
3002 if (hasHiddenRows() && options.isExportHiddenSequences())
3004 alignmentToExport = getAlignment().getHiddenSequences()
3005 .getFullAlignment();
3009 alignmentToExport = getAlignment();
3011 alignmentStartEnd = getAlignment().getHiddenColumns()
3012 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3013 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3014 omitHidden, alignmentStartEnd);
3019 * flag set to indicate if structure views might be out of sync with sequences
3023 private boolean needToUpdateStructureViews = false;
3026 public boolean isUpdateStructures()
3028 return needToUpdateStructureViews;
3032 public void setUpdateStructures(boolean update)
3034 needToUpdateStructureViews = update;
3038 public boolean needToUpdateStructureViews()
3040 boolean update = needToUpdateStructureViews;
3041 needToUpdateStructureViews = false;
3046 public void addSequenceGroup(SequenceGroup sequenceGroup)
3048 alignment.addGroup(sequenceGroup);
3050 Color col = sequenceGroup.idColour;
3053 col = col.brighter();
3055 for (SequenceI sq : sequenceGroup.getSequences())
3057 setSequenceColour(sq, col);
3061 if (codingComplement != null)
3063 SequenceGroup mappedGroup = MappingUtils
3064 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3065 if (mappedGroup.getSequences().size() > 0)
3067 codingComplement.getAlignment().addGroup(mappedGroup);
3071 for (SequenceI seq : mappedGroup.getSequences())
3073 codingComplement.setSequenceColour(seq, col);
3077 // propagate the structure view update flag according to our own setting
3078 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3083 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3087 if (selectedRegionOnly && selectionGroup != null)
3089 start = selectionGroup.getStartRes();
3090 end = selectionGroup.getEndRes() + 1;
3094 end = alignment.getWidth();
3096 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,