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 protected boolean autoCalculateConsensusAndConservation = true;
610 public boolean getAutoCalculateConsensusAndConservation()
612 return autoCalculateConsensusAndConservation;
615 public void setAutoCalculateConsensusAndConservation(boolean b)
617 autoCalculateConsensusAndConservation = b;
620 protected boolean autoCalculateStrucConsensus = true;
622 public boolean getAutoCalculateStrucConsensus()
624 return autoCalculateStrucConsensus;
627 public void setAutoCalculateStrucConsensus(boolean b)
629 autoCalculateStrucConsensus = b;
632 protected boolean ignoreGapsInConsensusCalculation = false;
634 protected ResidueShaderI residueShading = new ResidueShader();
637 public void setGlobalColourScheme(ColourSchemeI cs)
639 // TODO: logic refactored from AlignFrame changeColour -
640 // TODO: autorecalc stuff should be changed to rely on the worker system
641 // check to see if we should implement a changeColour(cs) method rather than
642 // put the logic in here
643 // - means that caller decides if they want to just modify state and defer
644 // calculation till later or to do all calculations in thread.
648 * only instantiate alignment colouring once, thereafter update it;
649 * this means that any conservation or PID threshold settings
650 * persist when the alignment colour scheme is changed
652 if (residueShading == null)
654 residueShading = new ResidueShader(viewStyle);
656 residueShading.setColourScheme(cs);
658 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
659 // ...problem: groups need these, but do not currently have a ViewStyle
663 if (getConservationSelected())
665 residueShading.setConservation(hconservation);
668 * reset conservation flag in case just set to false if
669 * Conservation was null (calculation still in progress)
671 residueShading.setConservationApplied(getConservationSelected());
672 residueShading.alignmentChanged(alignment, hiddenRepSequences);
676 * if 'apply colour to all groups' is selected... do so
677 * (but don't transfer any colour threshold settings to groups)
679 if (getColourAppliesToAllGroups())
681 for (SequenceGroup sg : getAlignment().getGroups())
684 * retain any colour thresholds per group while
685 * changing choice of colour scheme (JAL-2386)
688 cs == null ? null : cs.getInstance(this, sg));
691 sg.getGroupColourScheme().alignmentChanged(sg,
699 public ColourSchemeI getGlobalColourScheme()
701 return residueShading == null ? null : residueShading.getColourScheme();
705 public ResidueShaderI getResidueShading()
707 return residueShading;
710 protected AlignmentAnnotation consensus;
712 protected AlignmentAnnotation complementConsensus;
714 protected AlignmentAnnotation gapcounts;
716 protected AlignmentAnnotation strucConsensus;
718 protected AlignmentAnnotation conservation;
720 protected AlignmentAnnotation quality;
722 protected AlignmentAnnotation[] groupConsensus;
724 protected AlignmentAnnotation[] groupConservation;
727 * results of alignment consensus analysis for visible portion of view
729 protected ProfilesI hconsensus = null;
732 * results of cDNA complement consensus visible portion of view
734 protected Hashtable<String, Object>[] hcomplementConsensus = null;
737 * results of secondary structure base pair consensus for visible portion of
740 protected Hashtable<String, Object>[] hStrucConsensus = null;
742 protected Conservation hconservation = null;
745 public void setConservation(Conservation cons)
747 hconservation = cons;
751 * percentage gaps allowed in a column before all amino acid properties should
752 * be considered unconserved
754 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
757 public int getConsPercGaps()
763 public void setSequenceConsensusHash(ProfilesI hconsensus)
765 this.hconsensus = hconsensus;
769 public void setComplementConsensusHash(
770 Hashtable<String, Object>[] hconsensus)
772 this.hcomplementConsensus = hconsensus;
776 public ProfilesI getSequenceConsensusHash()
782 public Hashtable<String, Object>[] getComplementConsensusHash()
784 return hcomplementConsensus;
788 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
790 return hStrucConsensus;
794 public void setRnaStructureConsensusHash(
795 Hashtable<String, Object>[] hStrucConsensus)
797 this.hStrucConsensus = hStrucConsensus;
802 public AlignmentAnnotation getAlignmentQualityAnnot()
808 public AlignmentAnnotation getAlignmentConservationAnnotation()
814 public AlignmentAnnotation getAlignmentConsensusAnnotation()
820 public AlignmentAnnotation getAlignmentGapAnnotation()
826 public AlignmentAnnotation getComplementConsensusAnnotation()
828 return complementConsensus;
832 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
834 return strucConsensus;
837 protected AlignCalcManagerI calculator = new AlignCalcManager();
840 * trigger update of conservation annotation
842 public void updateConservation(final AlignmentViewPanel ap)
844 // see note in mantis : issue number 8585
845 if (alignment.isNucleotide()
846 || (conservation == null && quality == null)
847 || !autoCalculateConsensusAndConservation)
851 if (calculator.getRegisteredWorkersOfClass(
852 jalview.workers.ConservationThread.class) == null)
854 calculator.registerWorker(
855 new jalview.workers.ConservationThread(this, ap));
860 * trigger update of consensus annotation
862 public void updateConsensus(final AlignmentViewPanel ap)
864 // see note in mantis : issue number 8585
865 if (consensus == null || !autoCalculateConsensusAndConservation)
870 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
872 calculator.registerWorker(new ConsensusThread(this, ap));
876 * A separate thread to compute cDNA consensus for a protein alignment
877 * which has mapping to cDNA
879 final AlignmentI al = this.getAlignment();
880 if (!al.isNucleotide() && al.getCodonFrames() != null
881 && !al.getCodonFrames().isEmpty())
884 * fudge - check first for protein-to-nucleotide mappings
885 * (we don't want to do this for protein-to-protein)
887 boolean doConsensus = false;
888 for (AlignedCodonFrame mapping : al.getCodonFrames())
890 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
891 MapList[] mapLists = mapping.getdnaToProt();
892 // mapLists can be empty if project load has not finished resolving seqs
893 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
901 if (calculator.getRegisteredWorkersOfClass(
902 ComplementConsensusThread.class) == null)
905 .registerWorker(new ComplementConsensusThread(this, ap));
911 // --------START Structure Conservation
912 public void updateStrucConsensus(final AlignmentViewPanel ap)
914 if (autoCalculateStrucConsensus && strucConsensus == null
915 && alignment.isNucleotide() && alignment.hasRNAStructure())
917 // secondary structure has been added - so init the consensus line
921 // see note in mantis : issue number 8585
922 if (strucConsensus == null || !autoCalculateStrucConsensus)
926 if (calculator.getRegisteredWorkersOfClass(
927 StrucConsensusThread.class) == null)
929 calculator.registerWorker(new StrucConsensusThread(this, ap));
933 public boolean isCalcInProgress()
935 return calculator.isWorking();
939 public boolean isCalculationInProgress(
940 AlignmentAnnotation alignmentAnnotation)
942 if (!alignmentAnnotation.autoCalculated)
946 if (calculator.workingInvolvedWith(alignmentAnnotation))
948 // System.err.println("grey out ("+alignmentAnnotation.label+")");
954 public void setAlignment(AlignmentI align)
956 this.alignment = align;
960 * Clean up references when this viewport is closed
963 public void dispose()
966 * defensively null out references to large objects in case
967 * this object is not garbage collected (as if!)
970 complementConsensus = null;
971 strucConsensus = null;
974 groupConsensus = null;
975 groupConservation = null;
977 hconservation = null;
978 hcomplementConsensus = null;
981 residueShading = null; // may hold a reference to Consensus
982 changeSupport = null;
985 selectionGroup = null;
990 public boolean isClosed()
992 // TODO: check that this isClosed is only true after panel is closed, not
993 // before it is fully constructed.
994 return alignment == null;
998 public AlignCalcManagerI getCalcManager()
1004 * should conservation rows be shown for groups
1006 protected boolean showGroupConservation = false;
1009 * should consensus rows be shown for groups
1011 protected boolean showGroupConsensus = false;
1014 * should consensus profile be rendered by default
1016 protected boolean showSequenceLogo = false;
1019 * should consensus profile be rendered normalised to row height
1021 protected boolean normaliseSequenceLogo = false;
1024 * should consensus histograms be rendered by default
1026 protected boolean showConsensusHistogram = true;
1029 * @return the showConsensusProfile
1032 public boolean isShowSequenceLogo()
1034 return showSequenceLogo;
1038 * @param showSequenceLogo
1041 public void setShowSequenceLogo(boolean showSequenceLogo)
1043 if (showSequenceLogo != this.showSequenceLogo)
1045 // TODO: decouple settings setting from calculation when refactoring
1046 // annotation update method from alignframe to viewport
1047 this.showSequenceLogo = showSequenceLogo;
1048 calculator.updateAnnotationFor(ConsensusThread.class);
1049 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1050 calculator.updateAnnotationFor(StrucConsensusThread.class);
1052 this.showSequenceLogo = showSequenceLogo;
1056 * @param showConsensusHistogram
1057 * the showConsensusHistogram to set
1059 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1061 this.showConsensusHistogram = showConsensusHistogram;
1065 * @return the showGroupConservation
1067 public boolean isShowGroupConservation()
1069 return showGroupConservation;
1073 * @param showGroupConservation
1074 * the showGroupConservation to set
1076 public void setShowGroupConservation(boolean showGroupConservation)
1078 this.showGroupConservation = showGroupConservation;
1082 * @return the showGroupConsensus
1084 public boolean isShowGroupConsensus()
1086 return showGroupConsensus;
1090 * @param showGroupConsensus
1091 * the showGroupConsensus to set
1093 public void setShowGroupConsensus(boolean showGroupConsensus)
1095 this.showGroupConsensus = showGroupConsensus;
1100 * @return flag to indicate if the consensus histogram should be rendered by
1104 public boolean isShowConsensusHistogram()
1106 return this.showConsensusHistogram;
1110 * when set, updateAlignment will always ensure sequences are of equal length
1112 private boolean padGaps = false;
1115 * when set, alignment should be reordered according to a newly opened tree
1117 public boolean sortByTree = false;
1122 * @return null or the currently selected sequence region
1125 public SequenceGroup getSelectionGroup()
1127 return selectionGroup;
1131 * Set the selection group for this window. Also sets the current alignment as
1132 * the context for the group, if it does not already have one.
1135 * - group holding references to sequences in this alignment view
1139 public void setSelectionGroup(SequenceGroup sg)
1141 selectionGroup = sg;
1142 if (sg != null && sg.getContext() == null)
1144 sg.setContext(alignment);
1148 public void setHiddenColumns(HiddenColumns hidden)
1150 this.alignment.setHiddenColumns(hidden);
1154 public ColumnSelection getColumnSelection()
1160 public void setColumnSelection(ColumnSelection colSel)
1162 this.colSel = colSel;
1165 updateHiddenColumns();
1167 isColSelChanged(true);
1175 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1177 return hiddenRepSequences;
1181 public void setHiddenRepSequences(
1182 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1184 this.hiddenRepSequences = hiddenRepSequences;
1188 public boolean hasSelectedColumns()
1190 ColumnSelection columnSelection = getColumnSelection();
1191 return columnSelection != null && columnSelection.hasSelectedColumns();
1195 public boolean hasHiddenColumns()
1197 return alignment.getHiddenColumns() != null
1198 && alignment.getHiddenColumns().hasHiddenColumns();
1201 public void updateHiddenColumns()
1203 // this method doesn't really do anything now. But - it could, since a
1204 // column Selection could be in the process of modification
1205 // hasHiddenColumns = colSel.hasHiddenColumns();
1209 public boolean hasHiddenRows()
1211 return alignment.getHiddenSequences().getSize() > 0;
1214 protected SequenceGroup selectionGroup;
1216 public void setSequenceSetId(String newid)
1218 if (sequenceSetID != null)
1221 "Warning - overwriting a sequenceSetId for a viewport!");
1223 sequenceSetID = new String(newid);
1227 public String getSequenceSetId()
1229 if (sequenceSetID == null)
1231 sequenceSetID = alignment.hashCode() + "";
1234 return sequenceSetID;
1238 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1241 protected String viewId = null;
1244 public String getViewId()
1248 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1253 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1255 ignoreGapsInConsensusCalculation = b;
1258 updateConsensus(ap);
1259 if (residueShading != null)
1261 residueShading.setThreshold(residueShading.getThreshold(),
1262 ignoreGapsInConsensusCalculation);
1268 private long sgrouphash = -1, colselhash = -1;
1271 * checks current SelectionGroup against record of last hash value, and
1275 * update the record of last hash value
1277 * @return true if SelectionGroup changed since last call (when b is true)
1279 public boolean isSelectionGroupChanged(boolean b)
1281 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1282 : selectionGroup.hashCode();
1283 if (hc != -1 && hc != sgrouphash)
1295 * checks current colsel against record of last hash value, and optionally
1299 * update the record of last hash value
1300 * @return true if colsel changed since last call (when b is true)
1302 public boolean isColSelChanged(boolean b)
1304 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1305 if (hc != -1 && hc != colselhash)
1317 public boolean isIgnoreGapsConsensus()
1319 return ignoreGapsInConsensusCalculation;
1322 // property change stuff
1323 // JBPNote Prolly only need this in the applet version.
1324 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1327 protected boolean showConservation = true;
1329 protected boolean showQuality = true;
1331 protected boolean showConsensus = true;
1333 protected boolean showOccupancy = true;
1335 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1337 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1339 protected boolean showAutocalculatedAbove;
1342 * when set, view will scroll to show the highlighted position
1344 private boolean followHighlight = true;
1347 * Property change listener for changes in alignment
1352 public void addPropertyChangeListener(
1353 java.beans.PropertyChangeListener listener)
1355 changeSupport.addPropertyChangeListener(listener);
1364 public void removePropertyChangeListener(
1365 java.beans.PropertyChangeListener listener)
1367 if (changeSupport != null)
1369 changeSupport.removePropertyChangeListener(listener);
1374 * Property change listener for changes in alignment
1383 public void firePropertyChange(String prop, Object oldvalue,
1386 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1389 // common hide/show column stuff
1391 public void hideSelectedColumns()
1393 if (colSel.isEmpty())
1398 colSel.hideSelectedColumns(alignment);
1399 setSelectionGroup(null);
1400 isColSelChanged(true);
1403 public void hideColumns(int start, int end)
1407 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1411 alignment.getHiddenColumns().hideColumns(start, end);
1413 isColSelChanged(true);
1416 public void showColumn(int col)
1418 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1419 isColSelChanged(true);
1422 public void showAllHiddenColumns()
1424 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1425 isColSelChanged(true);
1428 // common hide/show seq stuff
1429 public void showAllHiddenSeqs()
1431 int startSeq = ranges.getStartSeq();
1432 int endSeq = ranges.getEndSeq();
1434 if (alignment.getHiddenSequences().getSize() > 0)
1436 if (selectionGroup == null)
1438 selectionGroup = new SequenceGroup();
1439 selectionGroup.setEndRes(alignment.getWidth() - 1);
1441 List<SequenceI> tmp = alignment.getHiddenSequences()
1442 .showAll(hiddenRepSequences);
1443 for (SequenceI seq : tmp)
1445 selectionGroup.addSequence(seq, false);
1446 setSequenceAnnotationsVisible(seq, true);
1449 hiddenRepSequences = null;
1451 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1453 firePropertyChange("alignment", null, alignment.getSequences());
1454 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1460 public void showSequence(int index)
1462 int startSeq = ranges.getStartSeq();
1463 int endSeq = ranges.getEndSeq();
1465 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1466 hiddenRepSequences);
1469 if (selectionGroup == null)
1471 selectionGroup = new SequenceGroup();
1472 selectionGroup.setEndRes(alignment.getWidth() - 1);
1475 for (SequenceI seq : tmp)
1477 selectionGroup.addSequence(seq, false);
1478 setSequenceAnnotationsVisible(seq, true);
1481 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1483 firePropertyChange("alignment", null, alignment.getSequences());
1488 public void hideAllSelectedSeqs()
1490 if (selectionGroup == null || selectionGroup.getSize() < 1)
1495 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1499 setSelectionGroup(null);
1502 public void hideSequence(SequenceI[] seq)
1505 * cache offset to first visible sequence
1507 int startSeq = ranges.getStartSeq();
1511 for (int i = 0; i < seq.length; i++)
1513 alignment.getHiddenSequences().hideSequence(seq[i]);
1514 setSequenceAnnotationsVisible(seq[i], false);
1516 ranges.setStartSeq(startSeq);
1517 firePropertyChange("alignment", null, alignment.getSequences());
1522 * Hides the specified sequence, or the sequences it represents
1525 * the sequence to hide, or keep as representative
1526 * @param representGroup
1527 * if true, hide the current selection group except for the
1528 * representative sequence
1530 public void hideSequences(SequenceI sequence, boolean representGroup)
1532 if (selectionGroup == null || selectionGroup.getSize() < 1)
1534 hideSequence(new SequenceI[] { sequence });
1540 hideRepSequences(sequence, selectionGroup);
1541 setSelectionGroup(null);
1545 int gsize = selectionGroup.getSize();
1546 SequenceI[] hseqs = selectionGroup.getSequences()
1547 .toArray(new SequenceI[gsize]);
1549 hideSequence(hseqs);
1550 setSelectionGroup(null);
1555 * Set visibility for any annotations for the given sequence.
1559 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1562 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1565 for (AlignmentAnnotation ann : anns)
1567 if (ann.sequenceRef == sequenceI)
1569 ann.visible = visible;
1575 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1577 int sSize = sg.getSize();
1583 if (hiddenRepSequences == null)
1585 hiddenRepSequences = new Hashtable<>();
1588 hiddenRepSequences.put(repSequence, sg);
1590 // Hide all sequences except the repSequence
1591 SequenceI[] seqs = new SequenceI[sSize - 1];
1593 for (int i = 0; i < sSize; i++)
1595 if (sg.getSequenceAt(i) != repSequence)
1597 if (index == sSize - 1)
1602 seqs[index++] = sg.getSequenceAt(i);
1605 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1606 sg.setHidereps(true); // note: not done in 2.7applet
1613 * @return null or the current reference sequence
1615 public SequenceI getReferenceSeq()
1617 return alignment.getSeqrep();
1622 * @return true iff seq is the reference for the alignment
1624 public boolean isReferenceSeq(SequenceI seq)
1626 return alignment.getSeqrep() == seq;
1632 * @return true if there are sequences represented by this sequence that are
1635 public boolean isHiddenRepSequence(SequenceI seq)
1637 return (hiddenRepSequences != null
1638 && hiddenRepSequences.containsKey(seq));
1644 * @return null or a sequence group containing the sequences that seq
1647 public SequenceGroup getRepresentedSequences(SequenceI seq)
1649 return (SequenceGroup) (hiddenRepSequences == null ? null
1650 : hiddenRepSequences.get(seq));
1654 public int adjustForHiddenSeqs(int alignmentIndex)
1656 return alignment.getHiddenSequences()
1657 .adjustForHiddenSeqs(alignmentIndex);
1661 public void invertColumnSelection()
1663 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1664 isColSelChanged(true);
1668 public SequenceI[] getSelectionAsNewSequence()
1670 SequenceI[] sequences;
1671 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1672 // this was the only caller in the applet for this method
1673 // JBPNote: in applet, this method returned references to the alignment
1674 // sequences, and it did not honour the presence/absence of annotation
1675 // attached to the alignment (probably!)
1676 if (selectionGroup == null || selectionGroup.getSize() == 0)
1678 sequences = alignment.getSequencesArray();
1679 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1680 for (int i = 0; i < sequences.length; i++)
1682 // construct new sequence with subset of visible annotation
1683 sequences[i] = new Sequence(sequences[i], annots);
1688 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1695 public SequenceI[] getSequenceSelection()
1697 SequenceI[] sequences = null;
1698 if (selectionGroup != null)
1700 sequences = selectionGroup.getSequencesInOrder(alignment);
1702 if (sequences == null)
1704 sequences = alignment.getSequencesArray();
1710 public jalview.datamodel.AlignmentView getAlignmentView(
1711 boolean selectedOnly)
1713 return getAlignmentView(selectedOnly, false);
1717 public jalview.datamodel.AlignmentView getAlignmentView(
1718 boolean selectedOnly, boolean markGroups)
1720 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1722 alignment.getHiddenColumns() != null
1723 && alignment.getHiddenColumns().hasHiddenColumns(),
1724 selectedOnly, markGroups);
1728 public String[] getViewAsString(boolean selectedRegionOnly)
1730 return getViewAsString(selectedRegionOnly, true);
1734 public String[] getViewAsString(boolean selectedRegionOnly,
1735 boolean exportHiddenSeqs)
1737 String[] selection = null;
1738 SequenceI[] seqs = null;
1740 int start = 0, end = 0;
1741 if (selectedRegionOnly && selectionGroup != null)
1743 iSize = selectionGroup.getSize();
1744 seqs = selectionGroup.getSequencesInOrder(alignment);
1745 start = selectionGroup.getStartRes();
1746 end = selectionGroup.getEndRes() + 1;
1750 if (hasHiddenRows() && exportHiddenSeqs)
1752 AlignmentI fullAlignment = alignment.getHiddenSequences()
1753 .getFullAlignment();
1754 iSize = fullAlignment.getHeight();
1755 seqs = fullAlignment.getSequencesArray();
1756 end = fullAlignment.getWidth();
1760 iSize = alignment.getHeight();
1761 seqs = alignment.getSequencesArray();
1762 end = alignment.getWidth();
1766 selection = new String[iSize];
1767 if (alignment.getHiddenColumns() != null
1768 && alignment.getHiddenColumns().hasHiddenColumns())
1770 for (i = 0; i < iSize; i++)
1772 Iterator<int[]> blocks = alignment.getHiddenColumns()
1773 .getVisContigsIterator(start, end + 1, false);
1774 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1779 for (i = 0; i < iSize; i++)
1781 selection[i] = seqs[i].getSequenceAsString(start, end);
1789 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1791 ArrayList<int[]> regions = new ArrayList<>();
1797 HiddenColumns hidden = alignment.getHiddenColumns();
1798 if (hidden != null && hidden.hasHiddenColumns())
1802 start = hidden.visibleToAbsoluteColumn(start);
1805 end = hidden.getNextHiddenBoundary(false, start);
1816 regions.add(new int[] { start, end });
1818 if (hidden != null && hidden.hasHiddenColumns())
1820 start = hidden.visibleToAbsoluteColumn(end);
1821 start = hidden.getNextHiddenBoundary(true, start) + 1;
1823 } while (end < max);
1825 // int[][] startEnd = new int[regions.size()][2];
1831 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1832 boolean selectedOnly)
1834 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1835 AlignmentAnnotation[] aa;
1836 if ((aa = alignment.getAlignmentAnnotation()) != null)
1838 for (AlignmentAnnotation annot : aa)
1840 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1841 if (selectedOnly && selectionGroup != null)
1843 clone.makeVisibleAnnotation(
1844 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1845 alignment.getHiddenColumns());
1849 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1858 public boolean isPadGaps()
1864 public void setPadGaps(boolean padGaps)
1866 this.padGaps = padGaps;
1870 * apply any post-edit constraints and trigger any calculations needed after
1871 * an edit has been performed on the alignment
1876 public void alignmentChanged(AlignmentViewPanel ap)
1880 alignment.padGaps();
1882 if (autoCalculateConsensusAndConservation)
1884 updateConsensus(ap);
1886 if (hconsensus != null && autoCalculateConsensusAndConservation)
1888 updateConservation(ap);
1890 if (autoCalculateStrucConsensus)
1892 updateStrucConsensus(ap);
1895 // Reset endRes of groups if beyond alignment width
1896 int alWidth = alignment.getWidth();
1897 List<SequenceGroup> groups = alignment.getGroups();
1900 for (SequenceGroup sg : groups)
1902 if (sg.getEndRes() > alWidth)
1904 sg.setEndRes(alWidth - 1);
1909 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1911 selectionGroup.setEndRes(alWidth - 1);
1914 updateAllColourSchemes();
1915 calculator.restartWorkers();
1916 // alignment.adjustSequenceAnnotations();
1920 * reset scope and do calculations for all applied colourschemes on alignment
1922 void updateAllColourSchemes()
1924 ResidueShaderI rs = residueShading;
1927 rs.alignmentChanged(alignment, hiddenRepSequences);
1929 rs.setConsensus(hconsensus);
1930 if (rs.conservationApplied())
1932 rs.setConservation(Conservation.calculateConservation("All",
1933 alignment.getSequences(), 0, alignment.getWidth(), false,
1934 getConsPercGaps(), false));
1938 for (SequenceGroup sg : alignment.getGroups())
1942 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1944 sg.recalcConservation();
1948 protected void initAutoAnnotation()
1950 // TODO: add menu option action that nulls or creates consensus object
1951 // depending on if the user wants to see the annotation or not in a
1952 // specific alignment
1954 if (hconsensus == null && !isDataset)
1956 if (!alignment.isNucleotide())
1965 consensus = new AlignmentAnnotation("Consensus",
1966 MessageManager.getString("label.consensus_descr"),
1967 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1968 initConsensus(consensus);
1971 initComplementConsensus();
1976 * If this is a protein alignment and there are mappings to cDNA, adds the
1977 * cDNA consensus annotation and returns true, else returns false.
1979 public boolean initComplementConsensus()
1981 if (!alignment.isNucleotide())
1983 final List<AlignedCodonFrame> codonMappings = alignment
1985 if (codonMappings != null && !codonMappings.isEmpty())
1987 boolean doConsensus = false;
1988 for (AlignedCodonFrame mapping : codonMappings)
1990 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1991 MapList[] mapLists = mapping.getdnaToProt();
1992 // mapLists can be empty if project load has not finished resolving
1994 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2002 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2004 .getString("label.complement_consensus_descr"),
2005 new Annotation[1], 0f, 100f,
2006 AlignmentAnnotation.BAR_GRAPH);
2007 initConsensus(complementConsensus);
2015 private void initConsensus(AlignmentAnnotation aa)
2018 aa.autoCalculated = true;
2022 alignment.addAnnotation(aa);
2026 // these should be extracted from the view model - style and settings for
2027 // derived annotation
2028 private void initGapCounts()
2032 gapcounts = new AlignmentAnnotation("Occupancy",
2033 MessageManager.getString("label.occupancy_descr"),
2034 new Annotation[1], 0f, alignment.getHeight(),
2035 AlignmentAnnotation.BAR_GRAPH);
2036 gapcounts.hasText = true;
2037 gapcounts.autoCalculated = true;
2038 gapcounts.scaleColLabel = true;
2039 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2041 alignment.addAnnotation(gapcounts);
2045 private void initConservation()
2047 if (showConservation)
2049 if (conservation == null)
2051 conservation = new AlignmentAnnotation("Conservation",
2052 MessageManager.formatMessage("label.conservation_descr",
2054 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2055 conservation.hasText = true;
2056 conservation.autoCalculated = true;
2057 alignment.addAnnotation(conservation);
2062 private void initQuality()
2066 if (quality == null)
2068 quality = new AlignmentAnnotation("Quality",
2069 MessageManager.getString("label.quality_descr"),
2070 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2071 quality.hasText = true;
2072 quality.autoCalculated = true;
2073 alignment.addAnnotation(quality);
2078 private void initRNAStructure()
2080 if (alignment.hasRNAStructure() && strucConsensus == null)
2082 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2083 MessageManager.getString("label.strucconsensus_descr"),
2084 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2085 strucConsensus.hasText = true;
2086 strucConsensus.autoCalculated = true;
2090 alignment.addAnnotation(strucConsensus);
2098 * @see jalview.api.AlignViewportI#calcPanelHeight()
2101 public int calcPanelHeight()
2103 // setHeight of panels
2104 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2106 int charHeight = getCharHeight();
2109 BitSet graphgrp = new BitSet();
2110 for (AlignmentAnnotation aa : anns)
2114 System.err.println("Null annotation row: ignoring.");
2121 if (aa.graphGroup > -1)
2123 if (graphgrp.get(aa.graphGroup))
2129 graphgrp.set(aa.graphGroup);
2136 aa.height += charHeight;
2146 aa.height += aa.graphHeight;
2154 height += aa.height;
2166 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2167 boolean preserveNewGroupSettings)
2169 boolean updateCalcs = false;
2170 boolean conv = isShowGroupConservation();
2171 boolean cons = isShowGroupConsensus();
2172 boolean showprf = isShowSequenceLogo();
2173 boolean showConsHist = isShowConsensusHistogram();
2174 boolean normLogo = isNormaliseSequenceLogo();
2177 * TODO reorder the annotation rows according to group/sequence ordering on
2180 // boolean sortg = true;
2182 // remove old automatic annotation
2183 // add any new annotation
2185 // intersect alignment annotation with alignment groups
2187 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2188 List<SequenceGroup> oldrfs = new ArrayList<>();
2191 for (int an = 0; an < aan.length; an++)
2193 if (aan[an].autoCalculated && aan[an].groupRef != null)
2195 oldrfs.add(aan[an].groupRef);
2196 alignment.deleteAnnotation(aan[an], false);
2200 if (alignment.getGroups() != null)
2202 for (SequenceGroup sg : alignment.getGroups())
2204 updateCalcs = false;
2205 if (applyGlobalSettings
2206 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2208 // set defaults for this group's conservation/consensus
2209 sg.setshowSequenceLogo(showprf);
2210 sg.setShowConsensusHistogram(showConsHist);
2211 sg.setNormaliseSequenceLogo(normLogo);
2216 alignment.addAnnotation(sg.getConservationRow(), 0);
2221 alignment.addAnnotation(sg.getConsensus(), 0);
2223 // refresh the annotation rows
2226 sg.recalcConservation();
2234 public boolean isDisplayReferenceSeq()
2236 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2240 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2242 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2246 public boolean isColourByReferenceSeq()
2248 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2252 public Color getSequenceColour(SequenceI seq)
2254 Color sqc = sequenceColours.get(seq);
2255 return (sqc == null ? Color.white : sqc);
2259 public void setSequenceColour(SequenceI seq, Color col)
2263 sequenceColours.remove(seq);
2267 sequenceColours.put(seq, col);
2272 public void updateSequenceIdColours()
2274 for (SequenceGroup sg : alignment.getGroups())
2276 if (sg.idColour != null)
2278 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2280 sequenceColours.put(s, sg.idColour);
2287 public void clearSequenceColours()
2289 sequenceColours.clear();
2293 public AlignViewportI getCodingComplement()
2295 return this.codingComplement;
2299 * Set this as the (cDna/protein) complement of the given viewport. Also
2300 * ensures the reverse relationship is set on the given viewport.
2303 public void setCodingComplement(AlignViewportI av)
2307 System.err.println("Ignoring recursive setCodingComplement request");
2311 this.codingComplement = av;
2312 // avoid infinite recursion!
2313 if (av.getCodingComplement() != this)
2315 av.setCodingComplement(this);
2321 public boolean isNucleotide()
2323 return getAlignment() == null ? false : getAlignment().isNucleotide();
2327 public FeaturesDisplayedI getFeaturesDisplayed()
2329 return featuresDisplayed;
2333 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2335 featuresDisplayed = featuresDisplayedI;
2339 public boolean areFeaturesDisplayed()
2341 return featuresDisplayed != null
2342 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2349 * features are displayed if true
2352 public void setShowSequenceFeatures(boolean b)
2354 viewStyle.setShowSequenceFeatures(b);
2358 public boolean isShowSequenceFeatures()
2360 return viewStyle.isShowSequenceFeatures();
2364 public void setShowSequenceFeaturesHeight(boolean selected)
2366 viewStyle.setShowSequenceFeaturesHeight(selected);
2370 public boolean isShowSequenceFeaturesHeight()
2372 return viewStyle.isShowSequenceFeaturesHeight();
2376 public void setShowAnnotation(boolean b)
2378 viewStyle.setShowAnnotation(b);
2382 public boolean isShowAnnotation()
2384 return viewStyle.isShowAnnotation();
2388 public boolean isRightAlignIds()
2390 return viewStyle.isRightAlignIds();
2394 public void setRightAlignIds(boolean rightAlignIds)
2396 viewStyle.setRightAlignIds(rightAlignIds);
2400 public boolean getConservationSelected()
2402 return viewStyle.getConservationSelected();
2406 public void setShowBoxes(boolean state)
2408 viewStyle.setShowBoxes(state);
2413 * @see jalview.api.ViewStyleI#getTextColour()
2416 public Color getTextColour()
2418 return viewStyle.getTextColour();
2423 * @see jalview.api.ViewStyleI#getTextColour2()
2426 public Color getTextColour2()
2428 return viewStyle.getTextColour2();
2433 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2436 public int getThresholdTextColour()
2438 return viewStyle.getThresholdTextColour();
2443 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2446 public boolean isConservationColourSelected()
2448 return viewStyle.isConservationColourSelected();
2453 * @see jalview.api.ViewStyleI#isRenderGaps()
2456 public boolean isRenderGaps()
2458 return viewStyle.isRenderGaps();
2463 * @see jalview.api.ViewStyleI#isShowColourText()
2466 public boolean isShowColourText()
2468 return viewStyle.isShowColourText();
2472 * @param conservationColourSelected
2473 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2476 public void setConservationColourSelected(
2477 boolean conservationColourSelected)
2479 viewStyle.setConservationColourSelected(conservationColourSelected);
2483 * @param showColourText
2484 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2487 public void setShowColourText(boolean showColourText)
2489 viewStyle.setShowColourText(showColourText);
2494 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2497 public void setTextColour(Color textColour)
2499 viewStyle.setTextColour(textColour);
2503 * @param thresholdTextColour
2504 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2507 public void setThresholdTextColour(int thresholdTextColour)
2509 viewStyle.setThresholdTextColour(thresholdTextColour);
2513 * @param textColour2
2514 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2517 public void setTextColour2(Color textColour2)
2519 viewStyle.setTextColour2(textColour2);
2523 public ViewStyleI getViewStyle()
2525 return new ViewStyle(viewStyle);
2529 public void setViewStyle(ViewStyleI settingsForView)
2531 viewStyle = new ViewStyle(settingsForView);
2532 if (residueShading != null)
2534 residueShading.setConservationApplied(
2535 settingsForView.isConservationColourSelected());
2540 public boolean sameStyle(ViewStyleI them)
2542 return viewStyle.sameStyle(them);
2547 * @see jalview.api.ViewStyleI#getIdWidth()
2550 public int getIdWidth()
2552 return viewStyle.getIdWidth();
2557 * @see jalview.api.ViewStyleI#setIdWidth(int)
2560 public void setIdWidth(int i)
2562 viewStyle.setIdWidth(i);
2567 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2570 public boolean isCentreColumnLabels()
2572 return viewStyle.isCentreColumnLabels();
2576 * @param centreColumnLabels
2577 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2580 public void setCentreColumnLabels(boolean centreColumnLabels)
2582 viewStyle.setCentreColumnLabels(centreColumnLabels);
2587 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2590 public void setShowDBRefs(boolean showdbrefs)
2592 viewStyle.setShowDBRefs(showdbrefs);
2597 * @see jalview.api.ViewStyleI#isShowDBRefs()
2600 public boolean isShowDBRefs()
2602 return viewStyle.isShowDBRefs();
2607 * @see jalview.api.ViewStyleI#isShowNPFeats()
2610 public boolean isShowNPFeats()
2612 return viewStyle.isShowNPFeats();
2616 * @param shownpfeats
2617 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2620 public void setShowNPFeats(boolean shownpfeats)
2622 viewStyle.setShowNPFeats(shownpfeats);
2625 public abstract StructureSelectionManager getStructureSelectionManager();
2628 * Add one command to the command history list.
2632 public void addToHistoryList(CommandI command)
2634 if (this.historyList != null)
2636 this.historyList.push(command);
2637 broadcastCommand(command, false);
2641 protected void broadcastCommand(CommandI command, boolean undo)
2643 getStructureSelectionManager().commandPerformed(command, undo,
2648 * Add one command to the command redo list.
2652 public void addToRedoList(CommandI command)
2654 if (this.redoList != null)
2656 this.redoList.push(command);
2658 broadcastCommand(command, true);
2662 * Clear the command redo list.
2664 public void clearRedoList()
2666 if (this.redoList != null)
2668 this.redoList.clear();
2672 public void setHistoryList(Deque<CommandI> list)
2674 this.historyList = list;
2677 public Deque<CommandI> getHistoryList()
2679 return this.historyList;
2682 public void setRedoList(Deque<CommandI> list)
2684 this.redoList = list;
2687 public Deque<CommandI> getRedoList()
2689 return this.redoList;
2693 public VamsasSource getVamsasSource()
2698 public SequenceAnnotationOrder getSortAnnotationsBy()
2700 return sortAnnotationsBy;
2703 public void setSortAnnotationsBy(
2704 SequenceAnnotationOrder sortAnnotationsBy)
2706 this.sortAnnotationsBy = sortAnnotationsBy;
2709 public boolean isShowAutocalculatedAbove()
2711 return showAutocalculatedAbove;
2714 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2716 this.showAutocalculatedAbove = showAutocalculatedAbove;
2720 public boolean isScaleProteinAsCdna()
2722 return viewStyle.isScaleProteinAsCdna();
2726 public void setScaleProteinAsCdna(boolean b)
2728 viewStyle.setScaleProteinAsCdna(b);
2732 public boolean isProteinFontAsCdna()
2734 return viewStyle.isProteinFontAsCdna();
2738 public void setProteinFontAsCdna(boolean b)
2740 viewStyle.setProteinFontAsCdna(b);
2744 * @return true if view should scroll to show the highlighted region of a
2749 public final boolean isFollowHighlight()
2751 return followHighlight;
2755 public final void setFollowHighlight(boolean b)
2757 this.followHighlight = b;
2761 public ViewportRanges getRanges()
2767 * Helper method to populate the SearchResults with the location in the
2768 * complementary alignment to scroll to, in order to match this one.
2771 * the SearchResults to add to
2772 * @return the offset (below top of visible region) of the matched sequence
2774 protected int findComplementScrollTarget(SearchResultsI sr)
2776 final AlignViewportI complement = getCodingComplement();
2777 if (complement == null || !complement.isFollowHighlight())
2781 boolean iAmProtein = !getAlignment().isNucleotide();
2782 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2783 : complement.getAlignment();
2784 if (proteinAlignment == null)
2788 final List<AlignedCodonFrame> mappings = proteinAlignment
2792 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2793 * residue in the middle column of the visible region. Scroll the
2794 * complementary alignment to line up the corresponding residue.
2797 SequenceI sequence = null;
2800 * locate 'middle' column (true middle if an odd number visible, left of
2801 * middle if an even number visible)
2803 int middleColumn = ranges.getStartRes()
2804 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2805 final HiddenSequences hiddenSequences = getAlignment()
2806 .getHiddenSequences();
2809 * searching to the bottom of the alignment gives smoother scrolling across
2810 * all gapped visible regions
2812 int lastSeq = alignment.getHeight() - 1;
2813 List<AlignedCodonFrame> seqMappings = null;
2814 for (int seqNo = ranges
2815 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2817 sequence = getAlignment().getSequenceAt(seqNo);
2818 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2822 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2826 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2828 getCodingComplement().getAlignment().getSequences());
2829 if (!seqMappings.isEmpty())
2835 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2838 * No ungapped mapped sequence in middle column - do nothing
2842 MappingUtils.addSearchResults(sr, sequence,
2843 sequence.findPosition(middleColumn), seqMappings);
2848 * synthesize a column selection if none exists so it covers the given
2849 * selection group. if wholewidth is false, no column selection is made if the
2850 * selection group covers the whole alignment width.
2855 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2858 if (sg != null && (sgs = sg.getStartRes()) >= 0
2859 && sg.getStartRes() <= (sge = sg.getEndRes())
2860 && !this.hasSelectedColumns())
2862 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2869 colSel = new ColumnSelection();
2871 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2873 colSel.addElement(cspos);
2879 * hold status of current selection group - defined on alignment or not.
2881 private boolean selectionIsDefinedGroup = false;
2884 public boolean isSelectionDefinedGroup()
2886 if (selectionGroup == null)
2890 if (isSelectionGroupChanged(true))
2892 selectionIsDefinedGroup = false;
2893 List<SequenceGroup> gps = alignment.getGroups();
2894 if (gps == null || gps.size() == 0)
2896 selectionIsDefinedGroup = false;
2900 selectionIsDefinedGroup = gps.contains(selectionGroup);
2903 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2907 * null, or currently highlighted results on this view
2909 private SearchResultsI searchResults = null;
2911 protected TreeModel currentTree = null;
2914 public boolean hasSearchResults()
2916 return searchResults != null;
2920 public void setSearchResults(SearchResultsI results)
2922 searchResults = results;
2926 public SearchResultsI getSearchResults()
2928 return searchResults;
2932 * get the consensus sequence as displayed under the PID consensus annotation
2935 * @return consensus sequence as a new sequence object
2937 public SequenceI getConsensusSeq()
2939 if (consensus == null)
2941 updateConsensus(null);
2943 if (consensus == null)
2947 StringBuffer seqs = new StringBuffer();
2948 for (int i = 0; i < consensus.annotations.length; i++)
2950 Annotation annotation = consensus.annotations[i];
2951 if (annotation != null)
2953 String description = annotation.description;
2954 if (description != null && description.startsWith("["))
2956 // consensus is a tie - just pick the first one
2957 seqs.append(description.charAt(1));
2961 seqs.append(annotation.displayCharacter);
2966 SequenceI sq = new Sequence("Consensus", seqs.toString());
2967 sq.setDescription("Percentage Identity Consensus "
2968 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2973 public void setCurrentTree(TreeModel tree)
2979 public TreeModel getCurrentTree()
2985 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
2987 AlignmentI alignmentToExport = null;
2988 String[] omitHidden = null;
2989 alignmentToExport = null;
2991 if (hasHiddenColumns() && !options.isExportHiddenColumns())
2993 omitHidden = getViewAsString(false,
2994 options.isExportHiddenSequences());
2997 int[] alignmentStartEnd = new int[2];
2998 if (hasHiddenRows() && options.isExportHiddenSequences())
3000 alignmentToExport = getAlignment().getHiddenSequences()
3001 .getFullAlignment();
3005 alignmentToExport = getAlignment();
3007 alignmentStartEnd = getAlignment().getHiddenColumns()
3008 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3009 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3010 omitHidden, alignmentStartEnd);
3015 * flag set to indicate if structure views might be out of sync with sequences
3019 private boolean needToUpdateStructureViews = false;
3022 public boolean isUpdateStructures()
3024 return needToUpdateStructureViews;
3028 public void setUpdateStructures(boolean update)
3030 needToUpdateStructureViews = update;
3034 public boolean needToUpdateStructureViews()
3036 boolean update = needToUpdateStructureViews;
3037 needToUpdateStructureViews = false;
3042 public void addSequenceGroup(SequenceGroup sequenceGroup)
3044 alignment.addGroup(sequenceGroup);
3046 Color col = sequenceGroup.idColour;
3049 col = col.brighter();
3051 for (SequenceI sq : sequenceGroup.getSequences())
3053 setSequenceColour(sq, col);
3057 if (codingComplement != null)
3059 SequenceGroup mappedGroup = MappingUtils
3060 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3061 if (mappedGroup.getSequences().size() > 0)
3063 codingComplement.getAlignment().addGroup(mappedGroup);
3067 for (SequenceI seq : mappedGroup.getSequences())
3069 codingComplement.setSequenceColour(seq, col);
3073 // propagate the structure view update flag according to our own setting
3074 codingComplement.setUpdateStructures(needToUpdateStructureViews);