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 // // BH 2020.04.07 do we need to do this if it is the same?
1219 // // (Jalview project files)
1220 // if (newid.equals(sequenceSetID))
1225 if (sequenceSetID != null)
1228 "Warning - overwriting a sequenceSetId for a viewport!");
1230 sequenceSetID = new String(newid);
1234 public String getSequenceSetId()
1236 if (sequenceSetID == null)
1238 sequenceSetID = alignment.hashCode() + "";
1241 return sequenceSetID;
1245 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1248 protected String viewId = null;
1251 public String getViewId()
1255 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1260 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1262 ignoreGapsInConsensusCalculation = b;
1265 updateConsensus(ap);
1266 if (residueShading != null)
1268 residueShading.setThreshold(residueShading.getThreshold(),
1269 ignoreGapsInConsensusCalculation);
1275 private long sgrouphash = -1, colselhash = -1;
1278 * checks current SelectionGroup against record of last hash value, and
1282 * update the record of last hash value
1284 * @return true if SelectionGroup changed since last call (when b is true)
1286 public boolean isSelectionGroupChanged(boolean b)
1288 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1289 : selectionGroup.hashCode();
1290 if (hc != -1 && hc != sgrouphash)
1302 * checks current colsel against record of last hash value, and optionally
1306 * update the record of last hash value
1307 * @return true if colsel changed since last call (when b is true)
1309 public boolean isColSelChanged(boolean b)
1311 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1312 if (hc != -1 && hc != colselhash)
1324 public boolean isIgnoreGapsConsensus()
1326 return ignoreGapsInConsensusCalculation;
1329 // property change stuff
1330 // JBPNote Prolly only need this in the applet version.
1331 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1334 protected boolean showConservation = true;
1336 protected boolean showQuality = true;
1338 protected boolean showConsensus = true;
1340 protected boolean showOccupancy = true;
1342 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1344 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1346 protected boolean showAutocalculatedAbove;
1349 * when set, view will scroll to show the highlighted position
1351 private boolean followHighlight = true;
1354 * Property change listener for changes in alignment
1359 public void addPropertyChangeListener(
1360 java.beans.PropertyChangeListener listener)
1362 changeSupport.addPropertyChangeListener(listener);
1371 public void removePropertyChangeListener(
1372 java.beans.PropertyChangeListener listener)
1374 if (changeSupport != null)
1376 changeSupport.removePropertyChangeListener(listener);
1381 * Property change listener for changes in alignment
1390 public void firePropertyChange(String prop, Object oldvalue,
1393 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1396 // common hide/show column stuff
1398 public void hideSelectedColumns()
1400 if (colSel.isEmpty())
1405 colSel.hideSelectedColumns(alignment);
1406 setSelectionGroup(null);
1407 isColSelChanged(true);
1410 public void hideColumns(int start, int end)
1414 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1418 alignment.getHiddenColumns().hideColumns(start, end);
1420 isColSelChanged(true);
1423 public void showColumn(int col)
1425 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1426 isColSelChanged(true);
1429 public void showAllHiddenColumns()
1431 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1432 isColSelChanged(true);
1435 // common hide/show seq stuff
1436 public void showAllHiddenSeqs()
1438 int startSeq = ranges.getStartSeq();
1439 int endSeq = ranges.getEndSeq();
1441 if (alignment.getHiddenSequences().getSize() > 0)
1443 if (selectionGroup == null)
1445 selectionGroup = new SequenceGroup();
1446 selectionGroup.setEndRes(alignment.getWidth() - 1);
1448 List<SequenceI> tmp = alignment.getHiddenSequences()
1449 .showAll(hiddenRepSequences);
1450 for (SequenceI seq : tmp)
1452 selectionGroup.addSequence(seq, false);
1453 setSequenceAnnotationsVisible(seq, true);
1456 hiddenRepSequences = null;
1458 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1460 firePropertyChange("alignment", null, alignment.getSequences());
1461 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1467 public void showSequence(int index)
1469 int startSeq = ranges.getStartSeq();
1470 int endSeq = ranges.getEndSeq();
1472 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1473 hiddenRepSequences);
1476 if (selectionGroup == null)
1478 selectionGroup = new SequenceGroup();
1479 selectionGroup.setEndRes(alignment.getWidth() - 1);
1482 for (SequenceI seq : tmp)
1484 selectionGroup.addSequence(seq, false);
1485 setSequenceAnnotationsVisible(seq, true);
1488 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1490 firePropertyChange("alignment", null, alignment.getSequences());
1495 public void hideAllSelectedSeqs()
1497 if (selectionGroup == null || selectionGroup.getSize() < 1)
1502 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1506 setSelectionGroup(null);
1509 public void hideSequence(SequenceI[] seq)
1512 * cache offset to first visible sequence
1514 int startSeq = ranges.getStartSeq();
1518 for (int i = 0; i < seq.length; i++)
1520 alignment.getHiddenSequences().hideSequence(seq[i]);
1521 setSequenceAnnotationsVisible(seq[i], false);
1523 ranges.setStartSeq(startSeq);
1524 firePropertyChange("alignment", null, alignment.getSequences());
1529 * Hides the specified sequence, or the sequences it represents
1532 * the sequence to hide, or keep as representative
1533 * @param representGroup
1534 * if true, hide the current selection group except for the
1535 * representative sequence
1537 public void hideSequences(SequenceI sequence, boolean representGroup)
1539 if (selectionGroup == null || selectionGroup.getSize() < 1)
1541 hideSequence(new SequenceI[] { sequence });
1547 hideRepSequences(sequence, selectionGroup);
1548 setSelectionGroup(null);
1552 int gsize = selectionGroup.getSize();
1553 SequenceI[] hseqs = selectionGroup.getSequences()
1554 .toArray(new SequenceI[gsize]);
1556 hideSequence(hseqs);
1557 setSelectionGroup(null);
1562 * Set visibility for any annotations for the given sequence.
1566 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1569 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1572 for (AlignmentAnnotation ann : anns)
1574 if (ann.sequenceRef == sequenceI)
1576 ann.visible = visible;
1582 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1584 int sSize = sg.getSize();
1590 if (hiddenRepSequences == null)
1592 hiddenRepSequences = new Hashtable<>();
1595 hiddenRepSequences.put(repSequence, sg);
1597 // Hide all sequences except the repSequence
1598 SequenceI[] seqs = new SequenceI[sSize - 1];
1600 for (int i = 0; i < sSize; i++)
1602 if (sg.getSequenceAt(i) != repSequence)
1604 if (index == sSize - 1)
1609 seqs[index++] = sg.getSequenceAt(i);
1612 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1613 sg.setHidereps(true); // note: not done in 2.7applet
1620 * @return null or the current reference sequence
1622 public SequenceI getReferenceSeq()
1624 return alignment.getSeqrep();
1629 * @return true iff seq is the reference for the alignment
1631 public boolean isReferenceSeq(SequenceI seq)
1633 return alignment.getSeqrep() == seq;
1639 * @return true if there are sequences represented by this sequence that are
1642 public boolean isHiddenRepSequence(SequenceI seq)
1644 return (hiddenRepSequences != null
1645 && hiddenRepSequences.containsKey(seq));
1651 * @return null or a sequence group containing the sequences that seq
1654 public SequenceGroup getRepresentedSequences(SequenceI seq)
1656 return (SequenceGroup) (hiddenRepSequences == null ? null
1657 : hiddenRepSequences.get(seq));
1661 public int adjustForHiddenSeqs(int alignmentIndex)
1663 return alignment.getHiddenSequences()
1664 .adjustForHiddenSeqs(alignmentIndex);
1668 public void invertColumnSelection()
1670 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1671 isColSelChanged(true);
1675 public SequenceI[] getSelectionAsNewSequence()
1677 SequenceI[] sequences;
1678 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1679 // this was the only caller in the applet for this method
1680 // JBPNote: in applet, this method returned references to the alignment
1681 // sequences, and it did not honour the presence/absence of annotation
1682 // attached to the alignment (probably!)
1683 if (selectionGroup == null || selectionGroup.getSize() == 0)
1685 sequences = alignment.getSequencesArray();
1686 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1687 for (int i = 0; i < sequences.length; i++)
1689 // construct new sequence with subset of visible annotation
1690 sequences[i] = new Sequence(sequences[i], annots);
1695 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1702 public SequenceI[] getSequenceSelection()
1704 SequenceI[] sequences = null;
1705 if (selectionGroup != null)
1707 sequences = selectionGroup.getSequencesInOrder(alignment);
1709 if (sequences == null)
1711 sequences = alignment.getSequencesArray();
1717 public jalview.datamodel.AlignmentView getAlignmentView(
1718 boolean selectedOnly)
1720 return getAlignmentView(selectedOnly, false);
1724 public jalview.datamodel.AlignmentView getAlignmentView(
1725 boolean selectedOnly, boolean markGroups)
1727 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1729 alignment.getHiddenColumns() != null
1730 && alignment.getHiddenColumns().hasHiddenColumns(),
1731 selectedOnly, markGroups);
1735 public String[] getViewAsString(boolean selectedRegionOnly)
1737 return getViewAsString(selectedRegionOnly, true);
1741 public String[] getViewAsString(boolean selectedRegionOnly,
1742 boolean exportHiddenSeqs)
1744 String[] selection = null;
1745 SequenceI[] seqs = null;
1747 int start = 0, end = 0;
1748 if (selectedRegionOnly && selectionGroup != null)
1750 iSize = selectionGroup.getSize();
1751 seqs = selectionGroup.getSequencesInOrder(alignment);
1752 start = selectionGroup.getStartRes();
1753 end = selectionGroup.getEndRes() + 1;
1757 if (hasHiddenRows() && exportHiddenSeqs)
1759 AlignmentI fullAlignment = alignment.getHiddenSequences()
1760 .getFullAlignment();
1761 iSize = fullAlignment.getHeight();
1762 seqs = fullAlignment.getSequencesArray();
1763 end = fullAlignment.getWidth();
1767 iSize = alignment.getHeight();
1768 seqs = alignment.getSequencesArray();
1769 end = alignment.getWidth();
1773 selection = new String[iSize];
1774 if (alignment.getHiddenColumns() != null
1775 && alignment.getHiddenColumns().hasHiddenColumns())
1777 for (i = 0; i < iSize; i++)
1779 Iterator<int[]> blocks = alignment.getHiddenColumns()
1780 .getVisContigsIterator(start, end + 1, false);
1781 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1786 for (i = 0; i < iSize; i++)
1788 selection[i] = seqs[i].getSequenceAsString(start, end);
1796 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1798 ArrayList<int[]> regions = new ArrayList<>();
1804 HiddenColumns hidden = alignment.getHiddenColumns();
1805 if (hidden != null && hidden.hasHiddenColumns())
1809 start = hidden.visibleToAbsoluteColumn(start);
1812 end = hidden.getNextHiddenBoundary(false, start);
1823 regions.add(new int[] { start, end });
1825 if (hidden != null && hidden.hasHiddenColumns())
1827 start = hidden.visibleToAbsoluteColumn(end);
1828 start = hidden.getNextHiddenBoundary(true, start) + 1;
1830 } while (end < max);
1832 // int[][] startEnd = new int[regions.size()][2];
1838 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1839 boolean selectedOnly)
1841 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1842 AlignmentAnnotation[] aa;
1843 if ((aa = alignment.getAlignmentAnnotation()) != null)
1845 for (AlignmentAnnotation annot : aa)
1847 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1848 if (selectedOnly && selectionGroup != null)
1850 clone.makeVisibleAnnotation(
1851 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1852 alignment.getHiddenColumns());
1856 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1865 public boolean isPadGaps()
1871 public void setPadGaps(boolean padGaps)
1873 this.padGaps = padGaps;
1877 * apply any post-edit constraints and trigger any calculations needed after
1878 * an edit has been performed on the alignment
1883 public void alignmentChanged(AlignmentViewPanel ap)
1887 alignment.padGaps();
1889 if (autoCalculateConsensusAndConservation)
1891 updateConsensus(ap);
1893 if (hconsensus != null && autoCalculateConsensusAndConservation)
1895 updateConservation(ap);
1897 if (autoCalculateStrucConsensus)
1899 updateStrucConsensus(ap);
1902 // Reset endRes of groups if beyond alignment width
1903 int alWidth = alignment.getWidth();
1904 List<SequenceGroup> groups = alignment.getGroups();
1907 for (SequenceGroup sg : groups)
1909 if (sg.getEndRes() > alWidth)
1911 sg.setEndRes(alWidth - 1);
1916 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1918 selectionGroup.setEndRes(alWidth - 1);
1921 updateAllColourSchemes();
1922 calculator.restartWorkers();
1923 // alignment.adjustSequenceAnnotations();
1927 * reset scope and do calculations for all applied colourschemes on alignment
1929 void updateAllColourSchemes()
1931 ResidueShaderI rs = residueShading;
1934 rs.alignmentChanged(alignment, hiddenRepSequences);
1936 rs.setConsensus(hconsensus);
1937 if (rs.conservationApplied())
1939 rs.setConservation(Conservation.calculateConservation("All",
1940 alignment.getSequences(), 0, alignment.getWidth(), false,
1941 getConsPercGaps(), false));
1945 for (SequenceGroup sg : alignment.getGroups())
1949 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1951 sg.recalcConservation();
1955 protected void initAutoAnnotation()
1957 // TODO: add menu option action that nulls or creates consensus object
1958 // depending on if the user wants to see the annotation or not in a
1959 // specific alignment
1961 if (hconsensus == null && !isDataset)
1963 if (!alignment.isNucleotide())
1972 consensus = new AlignmentAnnotation("Consensus",
1973 MessageManager.getString("label.consensus_descr"),
1974 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1975 initConsensus(consensus);
1978 initComplementConsensus();
1983 * If this is a protein alignment and there are mappings to cDNA, adds the
1984 * cDNA consensus annotation and returns true, else returns false.
1986 public boolean initComplementConsensus()
1988 if (!alignment.isNucleotide())
1990 final List<AlignedCodonFrame> codonMappings = alignment
1992 if (codonMappings != null && !codonMappings.isEmpty())
1994 boolean doConsensus = false;
1995 for (AlignedCodonFrame mapping : codonMappings)
1997 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1998 MapList[] mapLists = mapping.getdnaToProt();
1999 // mapLists can be empty if project load has not finished resolving
2001 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2009 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2011 .getString("label.complement_consensus_descr"),
2012 new Annotation[1], 0f, 100f,
2013 AlignmentAnnotation.BAR_GRAPH);
2014 initConsensus(complementConsensus);
2022 private void initConsensus(AlignmentAnnotation aa)
2025 aa.autoCalculated = true;
2029 alignment.addAnnotation(aa);
2033 // these should be extracted from the view model - style and settings for
2034 // derived annotation
2035 private void initGapCounts()
2039 gapcounts = new AlignmentAnnotation("Occupancy",
2040 MessageManager.getString("label.occupancy_descr"),
2041 new Annotation[1], 0f, alignment.getHeight(),
2042 AlignmentAnnotation.BAR_GRAPH);
2043 gapcounts.hasText = true;
2044 gapcounts.autoCalculated = true;
2045 gapcounts.scaleColLabel = true;
2046 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2048 alignment.addAnnotation(gapcounts);
2052 private void initConservation()
2054 if (showConservation)
2056 if (conservation == null)
2058 conservation = new AlignmentAnnotation("Conservation",
2059 MessageManager.formatMessage("label.conservation_descr",
2061 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2062 conservation.hasText = true;
2063 conservation.autoCalculated = true;
2064 alignment.addAnnotation(conservation);
2069 private void initQuality()
2073 if (quality == null)
2075 quality = new AlignmentAnnotation("Quality",
2076 MessageManager.getString("label.quality_descr"),
2077 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2078 quality.hasText = true;
2079 quality.autoCalculated = true;
2080 alignment.addAnnotation(quality);
2085 private void initRNAStructure()
2087 if (alignment.hasRNAStructure() && strucConsensus == null)
2089 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2090 MessageManager.getString("label.strucconsensus_descr"),
2091 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2092 strucConsensus.hasText = true;
2093 strucConsensus.autoCalculated = true;
2097 alignment.addAnnotation(strucConsensus);
2105 * @see jalview.api.AlignViewportI#calcPanelHeight()
2108 public int calcPanelHeight()
2110 // setHeight of panels
2111 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2113 int charHeight = getCharHeight();
2116 BitSet graphgrp = new BitSet();
2117 for (AlignmentAnnotation aa : anns)
2121 System.err.println("Null annotation row: ignoring.");
2128 if (aa.graphGroup > -1)
2130 if (graphgrp.get(aa.graphGroup))
2136 graphgrp.set(aa.graphGroup);
2143 aa.height += charHeight;
2153 aa.height += aa.graphHeight;
2161 height += aa.height;
2173 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2174 boolean preserveNewGroupSettings)
2176 boolean updateCalcs = false;
2177 boolean conv = isShowGroupConservation();
2178 boolean cons = isShowGroupConsensus();
2179 boolean showprf = isShowSequenceLogo();
2180 boolean showConsHist = isShowConsensusHistogram();
2181 boolean normLogo = isNormaliseSequenceLogo();
2184 * TODO reorder the annotation rows according to group/sequence ordering on
2187 // boolean sortg = true;
2189 // remove old automatic annotation
2190 // add any new annotation
2192 // intersect alignment annotation with alignment groups
2194 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2195 List<SequenceGroup> oldrfs = new ArrayList<>();
2198 for (int an = 0; an < aan.length; an++)
2200 if (aan[an].autoCalculated && aan[an].groupRef != null)
2202 oldrfs.add(aan[an].groupRef);
2203 alignment.deleteAnnotation(aan[an], false);
2207 if (alignment.getGroups() != null)
2209 for (SequenceGroup sg : alignment.getGroups())
2211 updateCalcs = false;
2212 if (applyGlobalSettings
2213 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2215 // set defaults for this group's conservation/consensus
2216 sg.setshowSequenceLogo(showprf);
2217 sg.setShowConsensusHistogram(showConsHist);
2218 sg.setNormaliseSequenceLogo(normLogo);
2223 alignment.addAnnotation(sg.getConservationRow(), 0);
2228 alignment.addAnnotation(sg.getConsensus(), 0);
2230 // refresh the annotation rows
2233 sg.recalcConservation();
2241 public boolean isDisplayReferenceSeq()
2243 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2247 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2249 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2253 public boolean isColourByReferenceSeq()
2255 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2259 public Color getSequenceColour(SequenceI seq)
2261 Color sqc = sequenceColours.get(seq);
2262 return (sqc == null ? Color.white : sqc);
2266 public void setSequenceColour(SequenceI seq, Color col)
2270 sequenceColours.remove(seq);
2274 sequenceColours.put(seq, col);
2279 public void updateSequenceIdColours()
2281 for (SequenceGroup sg : alignment.getGroups())
2283 if (sg.idColour != null)
2285 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2287 sequenceColours.put(s, sg.idColour);
2294 public void clearSequenceColours()
2296 sequenceColours.clear();
2300 public AlignViewportI getCodingComplement()
2302 return this.codingComplement;
2306 * Set this as the (cDna/protein) complement of the given viewport. Also
2307 * ensures the reverse relationship is set on the given viewport.
2310 public void setCodingComplement(AlignViewportI av)
2314 System.err.println("Ignoring recursive setCodingComplement request");
2318 this.codingComplement = av;
2319 // avoid infinite recursion!
2320 if (av.getCodingComplement() != this)
2322 av.setCodingComplement(this);
2328 public boolean isNucleotide()
2330 return getAlignment() == null ? false : getAlignment().isNucleotide();
2334 public FeaturesDisplayedI getFeaturesDisplayed()
2336 return featuresDisplayed;
2340 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2342 featuresDisplayed = featuresDisplayedI;
2346 public boolean areFeaturesDisplayed()
2348 return featuresDisplayed != null
2349 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2356 * features are displayed if true
2359 public void setShowSequenceFeatures(boolean b)
2361 viewStyle.setShowSequenceFeatures(b);
2365 public boolean isShowSequenceFeatures()
2367 return viewStyle.isShowSequenceFeatures();
2371 public void setShowSequenceFeaturesHeight(boolean selected)
2373 viewStyle.setShowSequenceFeaturesHeight(selected);
2377 public boolean isShowSequenceFeaturesHeight()
2379 return viewStyle.isShowSequenceFeaturesHeight();
2383 public void setShowAnnotation(boolean b)
2385 viewStyle.setShowAnnotation(b);
2389 public boolean isShowAnnotation()
2391 return viewStyle.isShowAnnotation();
2395 public boolean isRightAlignIds()
2397 return viewStyle.isRightAlignIds();
2401 public void setRightAlignIds(boolean rightAlignIds)
2403 viewStyle.setRightAlignIds(rightAlignIds);
2407 public boolean getConservationSelected()
2409 return viewStyle.getConservationSelected();
2413 public void setShowBoxes(boolean state)
2415 viewStyle.setShowBoxes(state);
2420 * @see jalview.api.ViewStyleI#getTextColour()
2423 public Color getTextColour()
2425 return viewStyle.getTextColour();
2430 * @see jalview.api.ViewStyleI#getTextColour2()
2433 public Color getTextColour2()
2435 return viewStyle.getTextColour2();
2440 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2443 public int getThresholdTextColour()
2445 return viewStyle.getThresholdTextColour();
2450 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2453 public boolean isConservationColourSelected()
2455 return viewStyle.isConservationColourSelected();
2460 * @see jalview.api.ViewStyleI#isRenderGaps()
2463 public boolean isRenderGaps()
2465 return viewStyle.isRenderGaps();
2470 * @see jalview.api.ViewStyleI#isShowColourText()
2473 public boolean isShowColourText()
2475 return viewStyle.isShowColourText();
2479 * @param conservationColourSelected
2480 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2483 public void setConservationColourSelected(
2484 boolean conservationColourSelected)
2486 viewStyle.setConservationColourSelected(conservationColourSelected);
2490 * @param showColourText
2491 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2494 public void setShowColourText(boolean showColourText)
2496 viewStyle.setShowColourText(showColourText);
2501 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2504 public void setTextColour(Color textColour)
2506 viewStyle.setTextColour(textColour);
2510 * @param thresholdTextColour
2511 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2514 public void setThresholdTextColour(int thresholdTextColour)
2516 viewStyle.setThresholdTextColour(thresholdTextColour);
2520 * @param textColour2
2521 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2524 public void setTextColour2(Color textColour2)
2526 viewStyle.setTextColour2(textColour2);
2530 public ViewStyleI getViewStyle()
2532 return new ViewStyle(viewStyle);
2536 public void setViewStyle(ViewStyleI settingsForView)
2538 viewStyle = new ViewStyle(settingsForView);
2539 if (residueShading != null)
2541 residueShading.setConservationApplied(
2542 settingsForView.isConservationColourSelected());
2547 public boolean sameStyle(ViewStyleI them)
2549 return viewStyle.sameStyle(them);
2554 * @see jalview.api.ViewStyleI#getIdWidth()
2557 public int getIdWidth()
2559 return viewStyle.getIdWidth();
2564 * @see jalview.api.ViewStyleI#setIdWidth(int)
2567 public void setIdWidth(int i)
2569 viewStyle.setIdWidth(i);
2574 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2577 public boolean isCentreColumnLabels()
2579 return viewStyle.isCentreColumnLabels();
2583 * @param centreColumnLabels
2584 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2587 public void setCentreColumnLabels(boolean centreColumnLabels)
2589 viewStyle.setCentreColumnLabels(centreColumnLabels);
2594 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2597 public void setShowDBRefs(boolean showdbrefs)
2599 viewStyle.setShowDBRefs(showdbrefs);
2604 * @see jalview.api.ViewStyleI#isShowDBRefs()
2607 public boolean isShowDBRefs()
2609 return viewStyle.isShowDBRefs();
2614 * @see jalview.api.ViewStyleI#isShowNPFeats()
2617 public boolean isShowNPFeats()
2619 return viewStyle.isShowNPFeats();
2623 * @param shownpfeats
2624 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2627 public void setShowNPFeats(boolean shownpfeats)
2629 viewStyle.setShowNPFeats(shownpfeats);
2632 public abstract StructureSelectionManager getStructureSelectionManager();
2635 * Add one command to the command history list.
2639 public void addToHistoryList(CommandI command)
2641 if (this.historyList != null)
2643 this.historyList.push(command);
2644 broadcastCommand(command, false);
2648 protected void broadcastCommand(CommandI command, boolean undo)
2650 getStructureSelectionManager().commandPerformed(command, undo,
2655 * Add one command to the command redo list.
2659 public void addToRedoList(CommandI command)
2661 if (this.redoList != null)
2663 this.redoList.push(command);
2665 broadcastCommand(command, true);
2669 * Clear the command redo list.
2671 public void clearRedoList()
2673 if (this.redoList != null)
2675 this.redoList.clear();
2679 public void setHistoryList(Deque<CommandI> list)
2681 this.historyList = list;
2684 public Deque<CommandI> getHistoryList()
2686 return this.historyList;
2689 public void setRedoList(Deque<CommandI> list)
2691 this.redoList = list;
2694 public Deque<CommandI> getRedoList()
2696 return this.redoList;
2700 public VamsasSource getVamsasSource()
2705 public SequenceAnnotationOrder getSortAnnotationsBy()
2707 return sortAnnotationsBy;
2710 public void setSortAnnotationsBy(
2711 SequenceAnnotationOrder sortAnnotationsBy)
2713 this.sortAnnotationsBy = sortAnnotationsBy;
2716 public boolean isShowAutocalculatedAbove()
2718 return showAutocalculatedAbove;
2721 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2723 this.showAutocalculatedAbove = showAutocalculatedAbove;
2727 public boolean isScaleProteinAsCdna()
2729 return viewStyle.isScaleProteinAsCdna();
2733 public void setScaleProteinAsCdna(boolean b)
2735 viewStyle.setScaleProteinAsCdna(b);
2739 public boolean isProteinFontAsCdna()
2741 return viewStyle.isProteinFontAsCdna();
2745 public void setProteinFontAsCdna(boolean b)
2747 viewStyle.setProteinFontAsCdna(b);
2751 * @return true if view should scroll to show the highlighted region of a
2756 public final boolean isFollowHighlight()
2758 return followHighlight;
2762 public final void setFollowHighlight(boolean b)
2764 this.followHighlight = b;
2768 public ViewportRanges getRanges()
2774 * Helper method to populate the SearchResults with the location in the
2775 * complementary alignment to scroll to, in order to match this one.
2778 * the SearchResults to add to
2779 * @return the offset (below top of visible region) of the matched sequence
2781 protected int findComplementScrollTarget(SearchResultsI sr)
2783 final AlignViewportI complement = getCodingComplement();
2784 if (complement == null || !complement.isFollowHighlight())
2788 boolean iAmProtein = !getAlignment().isNucleotide();
2789 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2790 : complement.getAlignment();
2791 if (proteinAlignment == null)
2795 final List<AlignedCodonFrame> mappings = proteinAlignment
2799 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2800 * residue in the middle column of the visible region. Scroll the
2801 * complementary alignment to line up the corresponding residue.
2804 SequenceI sequence = null;
2807 * locate 'middle' column (true middle if an odd number visible, left of
2808 * middle if an even number visible)
2810 int middleColumn = ranges.getStartRes()
2811 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2812 final HiddenSequences hiddenSequences = getAlignment()
2813 .getHiddenSequences();
2816 * searching to the bottom of the alignment gives smoother scrolling across
2817 * all gapped visible regions
2819 int lastSeq = alignment.getHeight() - 1;
2820 List<AlignedCodonFrame> seqMappings = null;
2821 for (int seqNo = ranges
2822 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2824 sequence = getAlignment().getSequenceAt(seqNo);
2825 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2829 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2833 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2835 getCodingComplement().getAlignment().getSequences());
2836 if (!seqMappings.isEmpty())
2842 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2845 * No ungapped mapped sequence in middle column - do nothing
2849 MappingUtils.addSearchResults(sr, sequence,
2850 sequence.findPosition(middleColumn), seqMappings);
2855 * synthesize a column selection if none exists so it covers the given
2856 * selection group. if wholewidth is false, no column selection is made if the
2857 * selection group covers the whole alignment width.
2862 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2865 if (sg != null && (sgs = sg.getStartRes()) >= 0
2866 && sg.getStartRes() <= (sge = sg.getEndRes())
2867 && !this.hasSelectedColumns())
2869 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2876 colSel = new ColumnSelection();
2878 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2880 colSel.addElement(cspos);
2886 * hold status of current selection group - defined on alignment or not.
2888 private boolean selectionIsDefinedGroup = false;
2891 public boolean isSelectionDefinedGroup()
2893 if (selectionGroup == null)
2897 if (isSelectionGroupChanged(true))
2899 selectionIsDefinedGroup = false;
2900 List<SequenceGroup> gps = alignment.getGroups();
2901 if (gps == null || gps.size() == 0)
2903 selectionIsDefinedGroup = false;
2907 selectionIsDefinedGroup = gps.contains(selectionGroup);
2910 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2914 * null, or currently highlighted results on this view
2916 private SearchResultsI searchResults = null;
2918 protected TreeModel currentTree = null;
2921 public boolean hasSearchResults()
2923 return searchResults != null;
2927 public void setSearchResults(SearchResultsI results)
2929 searchResults = results;
2933 public SearchResultsI getSearchResults()
2935 return searchResults;
2939 * get the consensus sequence as displayed under the PID consensus annotation
2942 * @return consensus sequence as a new sequence object
2944 public SequenceI getConsensusSeq()
2946 if (consensus == null)
2948 updateConsensus(null);
2950 if (consensus == null)
2954 StringBuffer seqs = new StringBuffer();
2955 for (int i = 0; i < consensus.annotations.length; i++)
2957 Annotation annotation = consensus.annotations[i];
2958 if (annotation != null)
2960 String description = annotation.description;
2961 if (description != null && description.startsWith("["))
2963 // consensus is a tie - just pick the first one
2964 seqs.append(description.charAt(1));
2968 seqs.append(annotation.displayCharacter);
2973 SequenceI sq = new Sequence("Consensus", seqs.toString());
2974 sq.setDescription("Percentage Identity Consensus "
2975 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2980 public void setCurrentTree(TreeModel tree)
2986 public TreeModel getCurrentTree()
2992 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
2994 AlignmentI alignmentToExport = null;
2995 String[] omitHidden = null;
2996 alignmentToExport = null;
2998 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3000 omitHidden = getViewAsString(false,
3001 options.isExportHiddenSequences());
3004 int[] alignmentStartEnd = new int[2];
3005 if (hasHiddenRows() && options.isExportHiddenSequences())
3007 alignmentToExport = getAlignment().getHiddenSequences()
3008 .getFullAlignment();
3012 alignmentToExport = getAlignment();
3014 alignmentStartEnd = getAlignment().getHiddenColumns()
3015 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3016 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3017 omitHidden, alignmentStartEnd);
3022 * flag set to indicate if structure views might be out of sync with sequences
3026 private boolean needToUpdateStructureViews = false;
3029 public boolean isUpdateStructures()
3031 return needToUpdateStructureViews;
3035 public void setUpdateStructures(boolean update)
3037 needToUpdateStructureViews = update;
3041 public boolean needToUpdateStructureViews()
3043 boolean update = needToUpdateStructureViews;
3044 needToUpdateStructureViews = false;
3049 public void addSequenceGroup(SequenceGroup sequenceGroup)
3051 alignment.addGroup(sequenceGroup);
3053 Color col = sequenceGroup.idColour;
3056 col = col.brighter();
3058 for (SequenceI sq : sequenceGroup.getSequences())
3060 setSequenceColour(sq, col);
3064 if (codingComplement != null)
3066 SequenceGroup mappedGroup = MappingUtils
3067 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3068 if (mappedGroup.getSequences().size() > 0)
3070 codingComplement.getAlignment().addGroup(mappedGroup);
3074 for (SequenceI seq : mappedGroup.getSequences())
3076 codingComplement.setSequenceColour(seq, col);
3080 // propagate the structure view update flag according to our own setting
3081 codingComplement.setUpdateStructures(needToUpdateStructureViews);