2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import java.awt.Color;
24 import java.beans.PropertyChangeSupport;
25 import java.util.ArrayDeque;
26 import java.util.ArrayList;
27 import java.util.BitSet;
28 import java.util.Deque;
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.List;
35 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
36 import jalview.analysis.Conservation;
37 import jalview.analysis.TreeModel;
38 import jalview.api.AlignCalcManagerI;
39 import jalview.api.AlignExportSettingsI;
40 import jalview.api.AlignViewportI;
41 import jalview.api.AlignmentViewPanel;
42 import jalview.api.FeaturesDisplayedI;
43 import jalview.api.ViewStyleI;
44 import jalview.bin.Console;
45 import jalview.commands.CommandI;
46 import jalview.datamodel.AlignedCodonFrame;
47 import jalview.datamodel.AlignmentAnnotation;
48 import jalview.datamodel.AlignmentExportData;
49 import jalview.datamodel.AlignmentI;
50 import jalview.datamodel.AlignmentView;
51 import jalview.datamodel.Annotation;
52 import jalview.datamodel.ColumnSelection;
53 import jalview.datamodel.ContactListI;
54 import jalview.datamodel.HiddenColumns;
55 import jalview.datamodel.HiddenSequences;
56 import jalview.datamodel.ProfilesI;
57 import jalview.datamodel.SearchResultsI;
58 import jalview.datamodel.Sequence;
59 import jalview.datamodel.SequenceCollectionI;
60 import jalview.datamodel.SequenceGroup;
61 import jalview.datamodel.SequenceI;
62 import jalview.gui.QuitHandler;
63 import jalview.project.Jalview2XML;
64 import jalview.renderer.ResidueShader;
65 import jalview.renderer.ResidueShaderI;
66 import jalview.schemes.ColourSchemeI;
67 import jalview.structure.CommandListener;
68 import jalview.structure.StructureSelectionManager;
69 import jalview.structure.VamsasSource;
70 import jalview.util.Comparison;
71 import jalview.util.MapList;
72 import jalview.util.MappingUtils;
73 import jalview.util.MessageManager;
74 import jalview.viewmodel.styles.ViewStyle;
75 import jalview.workers.AlignCalcManager;
76 import jalview.workers.ComplementConsensusThread;
77 import jalview.workers.ConsensusThread;
78 import jalview.workers.StrucConsensusThread;
81 * base class holding visualization and analysis attributes and common logic for
82 * an active alignment view displayed in the GUI
86 * @param <AlignmentPanelT>
87 * implementation of the AlignmentViewPanel used by the class
89 public abstract class AlignmentViewport<AlignmentPanelT extends AlignmentViewPanel>
90 implements AlignViewportI, CommandListener, VamsasSource
92 protected ViewportRanges ranges;
94 protected ViewStyleI viewStyle = new ViewStyle();
97 * A viewport that hosts the cDna view of this (protein), or vice versa (if
100 AlignViewportI codingComplement = null;
102 FeaturesDisplayedI featuresDisplayed = null;
104 protected Deque<CommandI> historyList = new ArrayDeque<>();
106 protected Deque<CommandI> redoList = new ArrayDeque<>();
109 * used to determine if quit should be confirmed
111 private boolean savedUpToDate = false;
114 * alignment displayed in the viewport. Please use get/setter
116 protected AlignmentI alignment;
118 public AlignmentViewport(AlignmentI al)
121 ranges = new ViewportRanges(al);
124 protected AlignmentPanelT alignPanel = null;
126 public void setAlignPanel(AlignmentPanelT ap)
132 * return the AlignmentViewPanel containing the given viewport. Use this to
133 * get the components currently handling the given viewport.
136 * @return null or an alignPanel guaranteed to have non-null alignFrame
139 public AlignmentPanelT getAlignPanel()
146 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
149 public void setFontName(String name)
151 viewStyle.setFontName(name);
156 * @see jalview.api.ViewStyleI#setFontStyle(int)
159 public void setFontStyle(int style)
161 viewStyle.setFontStyle(style);
166 * @see jalview.api.ViewStyleI#setFontSize(int)
169 public void setFontSize(int size)
171 viewStyle.setFontSize(size);
176 * @see jalview.api.ViewStyleI#getFontStyle()
179 public int getFontStyle()
181 return viewStyle.getFontStyle();
186 * @see jalview.api.ViewStyleI#getFontName()
189 public String getFontName()
191 return viewStyle.getFontName();
196 * @see jalview.api.ViewStyleI#getFontSize()
199 public int getFontSize()
201 return viewStyle.getFontSize();
205 * @param upperCasebold
206 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
209 public void setUpperCasebold(boolean upperCasebold)
211 viewStyle.setUpperCasebold(upperCasebold);
216 * @see jalview.api.ViewStyleI#isUpperCasebold()
219 public boolean isUpperCasebold()
221 return viewStyle.isUpperCasebold();
226 * @see jalview.api.ViewStyleI#isSeqNameItalics()
229 public boolean isSeqNameItalics()
231 return viewStyle.isSeqNameItalics();
235 * @param colourByReferenceSeq
236 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
239 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
241 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
246 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
249 public void setColourAppliesToAllGroups(boolean b)
251 viewStyle.setColourAppliesToAllGroups(b);
256 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
259 public boolean getColourAppliesToAllGroups()
261 return viewStyle.getColourAppliesToAllGroups();
266 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
269 public boolean getAbovePIDThreshold()
271 return viewStyle.getAbovePIDThreshold();
276 * @see jalview.api.ViewStyleI#setIncrement(int)
279 public void setIncrement(int inc)
281 viewStyle.setIncrement(inc);
286 * @see jalview.api.ViewStyleI#getIncrement()
289 public int getIncrement()
291 return viewStyle.getIncrement();
296 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
299 public void setConservationSelected(boolean b)
301 viewStyle.setConservationSelected(b);
306 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
309 public void setShowHiddenMarkers(boolean show)
311 viewStyle.setShowHiddenMarkers(show);
316 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
319 public boolean getShowHiddenMarkers()
321 return viewStyle.getShowHiddenMarkers();
326 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
329 public void setScaleRightWrapped(boolean b)
331 viewStyle.setScaleRightWrapped(b);
336 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
339 public void setScaleLeftWrapped(boolean b)
341 viewStyle.setScaleLeftWrapped(b);
346 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
349 public void setScaleAboveWrapped(boolean b)
351 viewStyle.setScaleAboveWrapped(b);
356 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
359 public boolean getScaleLeftWrapped()
361 return viewStyle.getScaleLeftWrapped();
366 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
369 public boolean getScaleAboveWrapped()
371 return viewStyle.getScaleAboveWrapped();
376 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
379 public boolean getScaleRightWrapped()
381 return viewStyle.getScaleRightWrapped();
386 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
389 public void setAbovePIDThreshold(boolean b)
391 viewStyle.setAbovePIDThreshold(b);
396 * @see jalview.api.ViewStyleI#setThreshold(int)
399 public void setThreshold(int thresh)
401 viewStyle.setThreshold(thresh);
406 * @see jalview.api.ViewStyleI#getThreshold()
409 public int getThreshold()
411 return viewStyle.getThreshold();
416 * @see jalview.api.ViewStyleI#getShowJVSuffix()
419 public boolean getShowJVSuffix()
421 return viewStyle.getShowJVSuffix();
426 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
429 public void setShowJVSuffix(boolean b)
431 viewStyle.setShowJVSuffix(b);
436 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
439 public void setWrapAlignment(boolean state)
441 viewStyle.setWrapAlignment(state);
442 ranges.setWrappedMode(state);
447 * @see jalview.api.ViewStyleI#setShowText(boolean)
450 public void setShowText(boolean state)
452 viewStyle.setShowText(state);
457 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
460 public void setRenderGaps(boolean state)
462 viewStyle.setRenderGaps(state);
467 * @see jalview.api.ViewStyleI#getColourText()
470 public boolean getColourText()
472 return viewStyle.getColourText();
477 * @see jalview.api.ViewStyleI#setColourText(boolean)
480 public void setColourText(boolean state)
482 viewStyle.setColourText(state);
487 * @see jalview.api.ViewStyleI#getWrapAlignment()
490 public boolean getWrapAlignment()
492 return viewStyle.getWrapAlignment();
497 * @see jalview.api.ViewStyleI#getShowText()
500 public boolean getShowText()
502 return viewStyle.getShowText();
507 * @see jalview.api.ViewStyleI#getWrappedWidth()
510 public int getWrappedWidth()
512 return viewStyle.getWrappedWidth();
517 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
520 public void setWrappedWidth(int w)
522 viewStyle.setWrappedWidth(w);
527 * @see jalview.api.ViewStyleI#getCharHeight()
530 public int getCharHeight()
532 return viewStyle.getCharHeight();
537 * @see jalview.api.ViewStyleI#setCharHeight(int)
540 public void setCharHeight(int h)
542 viewStyle.setCharHeight(h);
547 * @see jalview.api.ViewStyleI#getCharWidth()
550 public int getCharWidth()
552 return viewStyle.getCharWidth();
557 * @see jalview.api.ViewStyleI#setCharWidth(int)
560 public void setCharWidth(int w)
562 viewStyle.setCharWidth(w);
567 * @see jalview.api.ViewStyleI#getShowBoxes()
570 public boolean getShowBoxes()
572 return viewStyle.getShowBoxes();
577 * @see jalview.api.ViewStyleI#getShowUnconserved()
580 public boolean getShowUnconserved()
582 return viewStyle.getShowUnconserved();
586 * @param showunconserved
587 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
590 public void setShowUnconserved(boolean showunconserved)
592 viewStyle.setShowUnconserved(showunconserved);
597 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
600 public void setSeqNameItalics(boolean default1)
602 viewStyle.setSeqNameItalics(default1);
606 public AlignmentI getAlignment()
612 public char getGapCharacter()
614 return alignment.getGapCharacter();
617 protected String sequenceSetID;
620 * probably unused indicator that view is of a dataset rather than an
623 protected boolean isDataset = false;
625 public void setDataset(boolean b)
630 public boolean isDataset()
635 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
637 protected ColumnSelection colSel = new ColumnSelection();
639 public boolean autoCalculateConsensus = true;
641 protected boolean autoCalculateStrucConsensus = true;
643 protected boolean ignoreGapsInConsensusCalculation = false;
645 protected ResidueShaderI residueShading = new ResidueShader();
648 public void setGlobalColourScheme(ColourSchemeI cs)
650 // TODO: logic refactored from AlignFrame changeColour -
651 // TODO: autorecalc stuff should be changed to rely on the worker system
652 // check to see if we should implement a changeColour(cs) method rather than
653 // put the logic in here
654 // - means that caller decides if they want to just modify state and defer
655 // calculation till later or to do all calculations in thread.
659 * only instantiate alignment colouring once, thereafter update it;
660 * this means that any conservation or PID threshold settings
661 * persist when the alignment colour scheme is changed
663 if (residueShading == null)
665 residueShading = new ResidueShader(viewStyle);
667 residueShading.setColourScheme(cs);
669 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
670 // ...problem: groups need these, but do not currently have a ViewStyle
674 if (getConservationSelected())
676 residueShading.setConservation(hconservation);
679 * reset conservation flag in case just set to false if
680 * Conservation was null (calculation still in progress)
682 residueShading.setConservationApplied(getConservationSelected());
683 residueShading.alignmentChanged(alignment, hiddenRepSequences);
687 * if 'apply colour to all groups' is selected... do so
688 * (but don't transfer any colour threshold settings to groups)
690 if (getColourAppliesToAllGroups())
692 for (SequenceGroup sg : getAlignment().getGroups())
695 * retain any colour thresholds per group while
696 * changing choice of colour scheme (JAL-2386)
698 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
701 sg.getGroupColourScheme().alignmentChanged(sg,
709 public ColourSchemeI getGlobalColourScheme()
711 return residueShading == null ? null : residueShading.getColourScheme();
715 public ResidueShaderI getResidueShading()
717 return residueShading;
720 protected AlignmentAnnotation consensus;
722 protected AlignmentAnnotation complementConsensus;
724 protected AlignmentAnnotation gapcounts;
726 protected AlignmentAnnotation strucConsensus;
728 protected AlignmentAnnotation conservation;
730 protected AlignmentAnnotation quality;
732 protected AlignmentAnnotation[] groupConsensus;
734 protected AlignmentAnnotation[] groupConservation;
737 * results of alignment consensus analysis for visible portion of view
739 protected ProfilesI hconsensus = null;
742 * results of cDNA complement consensus visible portion of view
744 protected Hashtable<String, Object>[] hcomplementConsensus = null;
747 * results of secondary structure base pair consensus for visible portion of
750 protected Hashtable<String, Object>[] hStrucConsensus = null;
752 protected Conservation hconservation = null;
755 public void setConservation(Conservation cons)
757 hconservation = cons;
761 * percentage gaps allowed in a column before all amino acid properties should
762 * be considered unconserved
764 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
767 public int getConsPercGaps()
773 public void setSequenceConsensusHash(ProfilesI hconsensus)
775 this.hconsensus = hconsensus;
779 public void setComplementConsensusHash(
780 Hashtable<String, Object>[] hconsensus)
782 this.hcomplementConsensus = hconsensus;
786 public ProfilesI getSequenceConsensusHash()
792 public Hashtable<String, Object>[] getComplementConsensusHash()
794 return hcomplementConsensus;
798 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
800 return hStrucConsensus;
804 public void setRnaStructureConsensusHash(
805 Hashtable<String, Object>[] hStrucConsensus)
807 this.hStrucConsensus = hStrucConsensus;
812 public AlignmentAnnotation getAlignmentQualityAnnot()
818 public AlignmentAnnotation getAlignmentConservationAnnotation()
824 public AlignmentAnnotation getAlignmentConsensusAnnotation()
830 public AlignmentAnnotation getAlignmentGapAnnotation()
836 public AlignmentAnnotation getComplementConsensusAnnotation()
838 return complementConsensus;
842 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
844 return strucConsensus;
847 protected AlignCalcManagerI calculator = new AlignCalcManager();
850 * trigger update of conservation annotation
852 public void updateConservation(final AlignmentViewPanel ap)
854 // see note in mantis : issue number 8585
855 if (alignment.isNucleotide()
856 || (conservation == null && quality == null)
857 || !autoCalculateConsensus)
861 if (calculator.getRegisteredWorkersOfClass(
862 jalview.workers.ConservationThread.class) == null)
864 calculator.registerWorker(
865 new jalview.workers.ConservationThread(this, ap));
870 * trigger update of consensus annotation
872 public void updateConsensus(final AlignmentViewPanel ap)
874 // see note in mantis : issue number 8585
875 if (consensus == null || !autoCalculateConsensus)
880 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
882 calculator.registerWorker(new ConsensusThread(this, ap));
886 * A separate thread to compute cDNA consensus for a protein alignment
887 * which has mapping to cDNA
889 final AlignmentI al = this.getAlignment();
890 if (!al.isNucleotide() && al.getCodonFrames() != null
891 && !al.getCodonFrames().isEmpty())
894 * fudge - check first for protein-to-nucleotide mappings
895 * (we don't want to do this for protein-to-protein)
897 boolean doConsensus = false;
898 for (AlignedCodonFrame mapping : al.getCodonFrames())
900 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
901 MapList[] mapLists = mapping.getdnaToProt();
902 // mapLists can be empty if project load has not finished resolving seqs
903 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
911 if (calculator.getRegisteredWorkersOfClass(
912 ComplementConsensusThread.class) == null)
915 .registerWorker(new ComplementConsensusThread(this, ap));
921 // --------START Structure Conservation
922 public void updateStrucConsensus(final AlignmentViewPanel ap)
924 if (autoCalculateStrucConsensus && strucConsensus == null
925 && alignment.isNucleotide() && alignment.hasRNAStructure())
927 // secondary structure has been added - so init the consensus line
931 // see note in mantis : issue number 8585
932 if (strucConsensus == null || !autoCalculateStrucConsensus)
936 if (calculator.getRegisteredWorkersOfClass(
937 StrucConsensusThread.class) == null)
939 calculator.registerWorker(new StrucConsensusThread(this, ap));
943 public boolean isCalcInProgress()
945 return calculator.isWorking();
949 public boolean isCalculationInProgress(
950 AlignmentAnnotation alignmentAnnotation)
952 if (!alignmentAnnotation.autoCalculated)
956 if (calculator.workingInvolvedWith(alignmentAnnotation))
958 // System.err.println("grey out ("+alignmentAnnotation.label+")");
964 public void setAlignment(AlignmentI align)
966 this.alignment = align;
970 * Clean up references when this viewport is closed
973 public void dispose()
976 * defensively null out references to large objects in case
977 * this object is not garbage collected (as if!)
981 complementConsensus = null;
982 strucConsensus = null;
985 groupConsensus = null;
986 groupConservation = null;
988 hconservation = null;
989 hcomplementConsensus = null;
992 residueShading = null; // may hold a reference to Consensus
993 changeSupport = null;
996 selectionGroup = null;
1002 public boolean isClosed()
1004 // TODO: check that this isClosed is only true after panel is closed, not
1005 // before it is fully constructed.
1006 return alignment == null;
1010 public AlignCalcManagerI getCalcManager()
1016 * should conservation rows be shown for groups
1018 protected boolean showGroupConservation = false;
1021 * should consensus rows be shown for groups
1023 protected boolean showGroupConsensus = false;
1026 * should consensus profile be rendered by default
1028 protected boolean showSequenceLogo = false;
1031 * should consensus profile be rendered normalised to row height
1033 protected boolean normaliseSequenceLogo = false;
1036 * should consensus histograms be rendered by default
1038 protected boolean showConsensusHistogram = true;
1041 * @return the showConsensusProfile
1044 public boolean isShowSequenceLogo()
1046 return showSequenceLogo;
1050 * @param showSequenceLogo
1053 public void setShowSequenceLogo(boolean showSequenceLogo)
1055 if (showSequenceLogo != this.showSequenceLogo)
1057 // TODO: decouple settings setting from calculation when refactoring
1058 // annotation update method from alignframe to viewport
1059 this.showSequenceLogo = showSequenceLogo;
1060 calculator.updateAnnotationFor(ConsensusThread.class);
1061 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1062 calculator.updateAnnotationFor(StrucConsensusThread.class);
1064 this.showSequenceLogo = showSequenceLogo;
1068 * @param showConsensusHistogram
1069 * the showConsensusHistogram to set
1071 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1073 this.showConsensusHistogram = showConsensusHistogram;
1077 * @return the showGroupConservation
1079 public boolean isShowGroupConservation()
1081 return showGroupConservation;
1085 * @param showGroupConservation
1086 * the showGroupConservation to set
1088 public void setShowGroupConservation(boolean showGroupConservation)
1090 this.showGroupConservation = showGroupConservation;
1094 * @return the showGroupConsensus
1096 public boolean isShowGroupConsensus()
1098 return showGroupConsensus;
1102 * @param showGroupConsensus
1103 * the showGroupConsensus to set
1105 public void setShowGroupConsensus(boolean showGroupConsensus)
1107 this.showGroupConsensus = showGroupConsensus;
1112 * @return flag to indicate if the consensus histogram should be rendered by
1116 public boolean isShowConsensusHistogram()
1118 return this.showConsensusHistogram;
1122 * when set, updateAlignment will always ensure sequences are of equal length
1124 private boolean padGaps = false;
1127 * when set, alignment should be reordered according to a newly opened tree
1129 public boolean sortByTree = false;
1134 * @return null or the currently selected sequence region
1137 public SequenceGroup getSelectionGroup()
1139 return selectionGroup;
1143 * Set the selection group for this window. Also sets the current alignment as
1144 * the context for the group, if it does not already have one.
1147 * - group holding references to sequences in this alignment view
1151 public void setSelectionGroup(SequenceGroup sg)
1153 selectionGroup = sg;
1154 if (sg != null && sg.getContext() == null)
1156 sg.setContext(alignment);
1160 public void setHiddenColumns(HiddenColumns hidden)
1162 this.alignment.setHiddenColumns(hidden);
1166 public ColumnSelection getColumnSelection()
1172 public void setColumnSelection(ColumnSelection colSel)
1174 this.colSel = colSel;
1177 updateHiddenColumns();
1179 isColSelChanged(true);
1187 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1189 return hiddenRepSequences;
1193 public void setHiddenRepSequences(
1194 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1196 this.hiddenRepSequences = hiddenRepSequences;
1200 public boolean hasSelectedColumns()
1202 ColumnSelection columnSelection = getColumnSelection();
1203 return columnSelection != null && columnSelection.hasSelectedColumns();
1207 public boolean hasHiddenColumns()
1209 return alignment.getHiddenColumns() != null
1210 && alignment.getHiddenColumns().hasHiddenColumns();
1213 public void updateHiddenColumns()
1215 // this method doesn't really do anything now. But - it could, since a
1216 // column Selection could be in the process of modification
1217 // hasHiddenColumns = colSel.hasHiddenColumns();
1221 public boolean hasHiddenRows()
1223 return alignment.getHiddenSequences().getSize() > 0;
1226 protected SequenceGroup selectionGroup;
1228 public void setSequenceSetId(String newid)
1230 if (sequenceSetID != null)
1233 "Warning - overwriting a sequenceSetId for a viewport!");
1235 sequenceSetID = new String(newid);
1239 public String getSequenceSetId()
1241 if (sequenceSetID == null)
1243 sequenceSetID = alignment.hashCode() + "";
1246 return sequenceSetID;
1250 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1253 protected String viewId = null;
1256 public String getViewId()
1260 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1265 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1267 ignoreGapsInConsensusCalculation = b;
1270 updateConsensus(ap);
1271 if (residueShading != null)
1273 residueShading.setThreshold(residueShading.getThreshold(),
1274 ignoreGapsInConsensusCalculation);
1280 private long sgrouphash = -1, colselhash = -1;
1283 * checks current SelectionGroup against record of last hash value, and
1287 * update the record of last hash value
1289 * @return true if SelectionGroup changed since last call (when b is true)
1291 public boolean isSelectionGroupChanged(boolean b)
1293 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1294 : selectionGroup.hashCode();
1295 if (hc != -1 && hc != sgrouphash)
1307 * checks current colsel against record of last hash value, and optionally
1311 * update the record of last hash value
1312 * @return true if colsel changed since last call (when b is true)
1314 public boolean isColSelChanged(boolean b)
1316 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1317 if (hc != -1 && hc != colselhash)
1329 public boolean isIgnoreGapsConsensus()
1331 return ignoreGapsInConsensusCalculation;
1334 // property change stuff
1335 // JBPNote Prolly only need this in the applet version.
1336 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1339 protected boolean showConservation = true;
1341 protected boolean showQuality = true;
1343 protected boolean showConsensus = true;
1345 protected boolean showOccupancy = true;
1347 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1349 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1351 protected boolean showAutocalculatedAbove;
1354 * when set, view will scroll to show the highlighted position
1356 private boolean followHighlight = true;
1359 * Property change listener for changes in alignment
1364 public void addPropertyChangeListener(
1365 java.beans.PropertyChangeListener listener)
1367 changeSupport.addPropertyChangeListener(listener);
1376 public void removePropertyChangeListener(
1377 java.beans.PropertyChangeListener listener)
1379 if (changeSupport != null)
1381 changeSupport.removePropertyChangeListener(listener);
1386 * Property change listener for changes in alignment
1395 public void firePropertyChange(String prop, Object oldvalue,
1398 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1401 // common hide/show column stuff
1403 public void hideSelectedColumns()
1405 if (colSel.isEmpty())
1410 colSel.hideSelectedColumns(alignment);
1411 setSelectionGroup(null);
1412 isColSelChanged(true);
1415 public void hideColumns(int start, int end)
1419 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1423 alignment.getHiddenColumns().hideColumns(start, end);
1425 isColSelChanged(true);
1428 public void showColumn(int col)
1430 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1431 isColSelChanged(true);
1434 public void showAllHiddenColumns()
1436 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1437 isColSelChanged(true);
1440 // common hide/show seq stuff
1441 public void showAllHiddenSeqs()
1443 int startSeq = ranges.getStartSeq();
1444 int endSeq = ranges.getEndSeq();
1446 if (alignment.getHiddenSequences().getSize() > 0)
1448 if (selectionGroup == null)
1450 selectionGroup = new SequenceGroup();
1451 selectionGroup.setEndRes(alignment.getWidth() - 1);
1453 List<SequenceI> tmp = alignment.getHiddenSequences()
1454 .showAll(hiddenRepSequences);
1455 for (SequenceI seq : tmp)
1457 selectionGroup.addSequence(seq, false);
1458 setSequenceAnnotationsVisible(seq, true);
1461 hiddenRepSequences = null;
1463 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1465 firePropertyChange("alignment", null, alignment.getSequences());
1466 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1472 public void showSequence(int index)
1474 int startSeq = ranges.getStartSeq();
1475 int endSeq = ranges.getEndSeq();
1477 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1478 hiddenRepSequences);
1481 if (selectionGroup == null)
1483 selectionGroup = new SequenceGroup();
1484 selectionGroup.setEndRes(alignment.getWidth() - 1);
1487 for (SequenceI seq : tmp)
1489 selectionGroup.addSequence(seq, false);
1490 setSequenceAnnotationsVisible(seq, true);
1493 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1495 firePropertyChange("alignment", null, alignment.getSequences());
1500 public void hideAllSelectedSeqs()
1502 if (selectionGroup == null || selectionGroup.getSize() < 1)
1507 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1511 setSelectionGroup(null);
1514 public void hideSequence(SequenceI[] seq)
1517 * cache offset to first visible sequence
1519 int startSeq = ranges.getStartSeq();
1523 for (int i = 0; i < seq.length; i++)
1525 alignment.getHiddenSequences().hideSequence(seq[i]);
1526 setSequenceAnnotationsVisible(seq[i], false);
1528 ranges.setStartSeq(startSeq);
1529 firePropertyChange("alignment", null, alignment.getSequences());
1534 * Hides the specified sequence, or the sequences it represents
1537 * the sequence to hide, or keep as representative
1538 * @param representGroup
1539 * if true, hide the current selection group except for the
1540 * representative sequence
1542 public void hideSequences(SequenceI sequence, boolean representGroup)
1544 if (selectionGroup == null || selectionGroup.getSize() < 1)
1546 hideSequence(new SequenceI[] { sequence });
1552 hideRepSequences(sequence, selectionGroup);
1553 setSelectionGroup(null);
1557 int gsize = selectionGroup.getSize();
1558 SequenceI[] hseqs = selectionGroup.getSequences()
1559 .toArray(new SequenceI[gsize]);
1561 hideSequence(hseqs);
1562 setSelectionGroup(null);
1567 * Set visibility for any annotations for the given sequence.
1571 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1574 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1577 for (AlignmentAnnotation ann : anns)
1579 if (ann.sequenceRef == sequenceI)
1581 ann.visible = visible;
1587 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1589 int sSize = sg.getSize();
1595 if (hiddenRepSequences == null)
1597 hiddenRepSequences = new Hashtable<>();
1600 hiddenRepSequences.put(repSequence, sg);
1602 // Hide all sequences except the repSequence
1603 SequenceI[] seqs = new SequenceI[sSize - 1];
1605 for (int i = 0; i < sSize; i++)
1607 if (sg.getSequenceAt(i) != repSequence)
1609 if (index == sSize - 1)
1614 seqs[index++] = sg.getSequenceAt(i);
1617 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1618 sg.setHidereps(true); // note: not done in 2.7applet
1625 * @return null or the current reference sequence
1627 public SequenceI getReferenceSeq()
1629 return alignment.getSeqrep();
1634 * @return true iff seq is the reference for the alignment
1636 public boolean isReferenceSeq(SequenceI seq)
1638 return alignment.getSeqrep() == seq;
1644 * @return true if there are sequences represented by this sequence that are
1647 public boolean isHiddenRepSequence(SequenceI seq)
1649 return (hiddenRepSequences != null
1650 && hiddenRepSequences.containsKey(seq));
1656 * @return null or a sequence group containing the sequences that seq
1659 public SequenceGroup getRepresentedSequences(SequenceI seq)
1661 return (SequenceGroup) (hiddenRepSequences == null ? null
1662 : hiddenRepSequences.get(seq));
1666 public int adjustForHiddenSeqs(int alignmentIndex)
1668 return alignment.getHiddenSequences()
1669 .adjustForHiddenSeqs(alignmentIndex);
1673 public void invertColumnSelection()
1675 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1676 isColSelChanged(true);
1680 public SequenceI[] getSelectionAsNewSequence()
1682 SequenceI[] sequences;
1683 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1684 // this was the only caller in the applet for this method
1685 // JBPNote: in applet, this method returned references to the alignment
1686 // sequences, and it did not honour the presence/absence of annotation
1687 // attached to the alignment (probably!)
1688 if (selectionGroup == null || selectionGroup.getSize() == 0)
1690 sequences = alignment.getSequencesArray();
1691 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1692 for (int i = 0; i < sequences.length; i++)
1694 // construct new sequence with subset of visible annotation
1695 sequences[i] = new Sequence(sequences[i], annots);
1700 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1707 public SequenceI[] getSequenceSelection()
1709 SequenceI[] sequences = null;
1710 if (selectionGroup != null)
1712 sequences = selectionGroup.getSequencesInOrder(alignment);
1714 if (sequences == null)
1716 sequences = alignment.getSequencesArray();
1722 public jalview.datamodel.AlignmentView getAlignmentView(
1723 boolean selectedOnly)
1725 return getAlignmentView(selectedOnly, false);
1729 public jalview.datamodel.AlignmentView getAlignmentView(
1730 boolean selectedOnly, boolean markGroups)
1732 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1734 alignment.getHiddenColumns() != null
1735 && alignment.getHiddenColumns().hasHiddenColumns(),
1736 selectedOnly, markGroups);
1740 public String[] getViewAsString(boolean selectedRegionOnly)
1742 return getViewAsString(selectedRegionOnly, true);
1746 public String[] getViewAsString(boolean selectedRegionOnly,
1747 boolean exportHiddenSeqs)
1749 String[] selection = null;
1750 SequenceI[] seqs = null;
1752 int start = 0, end = 0;
1753 if (selectedRegionOnly && selectionGroup != null)
1755 iSize = selectionGroup.getSize();
1756 seqs = selectionGroup.getSequencesInOrder(alignment);
1757 start = selectionGroup.getStartRes();
1758 end = selectionGroup.getEndRes() + 1;
1762 if (hasHiddenRows() && exportHiddenSeqs)
1764 AlignmentI fullAlignment = alignment.getHiddenSequences()
1765 .getFullAlignment();
1766 iSize = fullAlignment.getHeight();
1767 seqs = fullAlignment.getSequencesArray();
1768 end = fullAlignment.getWidth();
1772 iSize = alignment.getHeight();
1773 seqs = alignment.getSequencesArray();
1774 end = alignment.getWidth();
1778 selection = new String[iSize];
1779 if (alignment.getHiddenColumns() != null
1780 && alignment.getHiddenColumns().hasHiddenColumns())
1782 for (i = 0; i < iSize; i++)
1784 Iterator<int[]> blocks = alignment.getHiddenColumns()
1785 .getVisContigsIterator(start, end + 1, false);
1786 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1791 for (i = 0; i < iSize; i++)
1793 selection[i] = seqs[i].getSequenceAsString(start, end);
1801 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1803 ArrayList<int[]> regions = new ArrayList<>();
1809 HiddenColumns hidden = alignment.getHiddenColumns();
1810 if (hidden != null && hidden.hasHiddenColumns())
1814 start = hidden.visibleToAbsoluteColumn(start);
1817 end = hidden.getNextHiddenBoundary(false, start);
1828 regions.add(new int[] { start, end });
1830 if (hidden != null && hidden.hasHiddenColumns())
1832 start = hidden.visibleToAbsoluteColumn(end);
1833 start = hidden.getNextHiddenBoundary(true, start) + 1;
1835 } while (end < max);
1837 // int[][] startEnd = new int[regions.size()][2];
1843 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1844 boolean selectedOnly)
1846 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1847 AlignmentAnnotation[] aa;
1848 if ((aa = alignment.getAlignmentAnnotation()) != null)
1850 for (AlignmentAnnotation annot : aa)
1852 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1853 if (selectedOnly && selectionGroup != null)
1855 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1856 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1860 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1869 public boolean isPadGaps()
1875 public void setPadGaps(boolean padGaps)
1877 this.padGaps = padGaps;
1881 * apply any post-edit constraints and trigger any calculations needed after
1882 * an edit has been performed on the alignment
1887 public void alignmentChanged(AlignmentViewPanel ap)
1891 alignment.padGaps();
1893 if (autoCalculateConsensus)
1895 updateConsensus(ap);
1897 if (hconsensus != null && autoCalculateConsensus)
1899 updateConservation(ap);
1901 if (autoCalculateStrucConsensus)
1903 updateStrucConsensus(ap);
1906 // Reset endRes of groups if beyond alignment width
1907 int alWidth = alignment.getWidth();
1908 List<SequenceGroup> groups = alignment.getGroups();
1911 for (SequenceGroup sg : groups)
1913 if (sg.getEndRes() > alWidth)
1915 sg.setEndRes(alWidth - 1);
1920 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1922 selectionGroup.setEndRes(alWidth - 1);
1925 updateAllColourSchemes();
1926 calculator.restartWorkers();
1927 // alignment.adjustSequenceAnnotations();
1931 * reset scope and do calculations for all applied colourschemes on alignment
1933 void updateAllColourSchemes()
1935 ResidueShaderI rs = residueShading;
1938 rs.alignmentChanged(alignment, hiddenRepSequences);
1940 rs.setConsensus(hconsensus);
1941 if (rs.conservationApplied())
1943 rs.setConservation(Conservation.calculateConservation("All",
1944 alignment.getSequences(), 0, alignment.getWidth(), false,
1945 getConsPercGaps(), false));
1949 for (SequenceGroup sg : alignment.getGroups())
1953 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1955 sg.recalcConservation();
1959 protected void initAutoAnnotation()
1961 // TODO: add menu option action that nulls or creates consensus object
1962 // depending on if the user wants to see the annotation or not in a
1963 // specific alignment
1965 if (hconsensus == null && !isDataset)
1967 if (!alignment.isNucleotide())
1976 consensus = new AlignmentAnnotation("Consensus",
1977 MessageManager.getString("label.consensus_descr"),
1978 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1979 initConsensus(consensus);
1982 initComplementConsensus();
1987 * If this is a protein alignment and there are mappings to cDNA, adds the
1988 * cDNA consensus annotation and returns true, else returns false.
1990 public boolean initComplementConsensus()
1992 if (!alignment.isNucleotide())
1994 final List<AlignedCodonFrame> codonMappings = alignment
1996 if (codonMappings != null && !codonMappings.isEmpty())
1998 boolean doConsensus = false;
1999 for (AlignedCodonFrame mapping : codonMappings)
2001 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
2002 MapList[] mapLists = mapping.getdnaToProt();
2003 // mapLists can be empty if project load has not finished resolving
2005 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
2013 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
2015 .getString("label.complement_consensus_descr"),
2016 new Annotation[1], 0f, 100f,
2017 AlignmentAnnotation.BAR_GRAPH);
2018 initConsensus(complementConsensus);
2026 private void initConsensus(AlignmentAnnotation aa)
2029 aa.autoCalculated = true;
2033 alignment.addAnnotation(aa);
2037 // these should be extracted from the view model - style and settings for
2038 // derived annotation
2039 private void initGapCounts()
2043 gapcounts = new AlignmentAnnotation("Occupancy",
2044 MessageManager.getString("label.occupancy_descr"),
2045 new Annotation[1], 0f, alignment.getHeight(),
2046 AlignmentAnnotation.BAR_GRAPH);
2047 gapcounts.hasText = true;
2048 gapcounts.autoCalculated = true;
2049 gapcounts.scaleColLabel = true;
2050 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2052 alignment.addAnnotation(gapcounts);
2056 private void initConservation()
2058 if (showConservation)
2060 if (conservation == null)
2062 conservation = new AlignmentAnnotation("Conservation",
2063 MessageManager.formatMessage("label.conservation_descr",
2065 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2066 conservation.hasText = true;
2067 conservation.autoCalculated = true;
2068 alignment.addAnnotation(conservation);
2073 private void initQuality()
2077 if (quality == null)
2079 quality = new AlignmentAnnotation("Quality",
2080 MessageManager.getString("label.quality_descr"),
2081 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2082 quality.hasText = true;
2083 quality.autoCalculated = true;
2084 alignment.addAnnotation(quality);
2089 private void initRNAStructure()
2091 if (alignment.hasRNAStructure() && strucConsensus == null)
2093 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2094 MessageManager.getString("label.strucconsensus_descr"),
2095 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2096 strucConsensus.hasText = true;
2097 strucConsensus.autoCalculated = true;
2101 alignment.addAnnotation(strucConsensus);
2109 * @see jalview.api.AlignViewportI#calcPanelHeight()
2112 public int calcPanelHeight()
2114 // setHeight of panels
2115 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2117 int charHeight = getCharHeight();
2120 BitSet graphgrp = new BitSet();
2121 for (AlignmentAnnotation aa : anns)
2125 System.err.println("Null annotation row: ignoring.");
2132 if (aa.graphGroup > -1)
2134 if (graphgrp.get(aa.graphGroup))
2140 graphgrp.set(aa.graphGroup);
2147 aa.height += charHeight;
2157 aa.height += aa.graphHeight;
2165 height += aa.height;
2177 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2178 boolean preserveNewGroupSettings)
2180 boolean updateCalcs = false;
2181 boolean conv = isShowGroupConservation();
2182 boolean cons = isShowGroupConsensus();
2183 boolean showprf = isShowSequenceLogo();
2184 boolean showConsHist = isShowConsensusHistogram();
2185 boolean normLogo = isNormaliseSequenceLogo();
2188 * TODO reorder the annotation rows according to group/sequence ordering on
2191 // boolean sortg = true;
2193 // remove old automatic annotation
2194 // add any new annotation
2196 // intersect alignment annotation with alignment groups
2198 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2199 List<SequenceGroup> oldrfs = new ArrayList<>();
2202 for (int an = 0; an < aan.length; an++)
2204 if (aan[an].autoCalculated && aan[an].groupRef != null)
2206 oldrfs.add(aan[an].groupRef);
2207 alignment.deleteAnnotation(aan[an], false);
2211 if (alignment.getGroups() != null)
2213 for (SequenceGroup sg : alignment.getGroups())
2215 updateCalcs = false;
2216 if (applyGlobalSettings
2217 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2219 // set defaults for this group's conservation/consensus
2220 sg.setshowSequenceLogo(showprf);
2221 sg.setShowConsensusHistogram(showConsHist);
2222 sg.setNormaliseSequenceLogo(normLogo);
2227 alignment.addAnnotation(sg.getConservationRow(), 0);
2232 alignment.addAnnotation(sg.getConsensus(), 0);
2234 // refresh the annotation rows
2237 sg.recalcConservation();
2245 public boolean isDisplayReferenceSeq()
2247 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2251 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2253 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2257 public boolean isColourByReferenceSeq()
2259 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2263 public Color getSequenceColour(SequenceI seq)
2265 Color sqc = sequenceColours.get(seq);
2266 return (sqc == null ? Color.white : sqc);
2270 public void setSequenceColour(SequenceI seq, Color col)
2274 sequenceColours.remove(seq);
2278 sequenceColours.put(seq, col);
2283 public void updateSequenceIdColours()
2285 for (SequenceGroup sg : alignment.getGroups())
2287 if (sg.idColour != null)
2289 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2291 sequenceColours.put(s, sg.idColour);
2298 public void clearSequenceColours()
2300 sequenceColours.clear();
2304 public AlignViewportI getCodingComplement()
2306 return this.codingComplement;
2310 * Set this as the (cDna/protein) complement of the given viewport. Also
2311 * ensures the reverse relationship is set on the given viewport.
2314 public void setCodingComplement(AlignViewportI av)
2318 System.err.println("Ignoring recursive setCodingComplement request");
2322 this.codingComplement = av;
2323 // avoid infinite recursion!
2324 if (av.getCodingComplement() != this)
2326 av.setCodingComplement(this);
2332 public boolean isNucleotide()
2334 return getAlignment() == null ? false : getAlignment().isNucleotide();
2338 public FeaturesDisplayedI getFeaturesDisplayed()
2340 return featuresDisplayed;
2344 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2346 featuresDisplayed = featuresDisplayedI;
2350 public boolean areFeaturesDisplayed()
2352 return featuresDisplayed != null
2353 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2360 * features are displayed if true
2363 public void setShowSequenceFeatures(boolean b)
2365 viewStyle.setShowSequenceFeatures(b);
2369 public boolean isShowSequenceFeatures()
2371 return viewStyle.isShowSequenceFeatures();
2375 public void setShowSequenceFeaturesHeight(boolean selected)
2377 viewStyle.setShowSequenceFeaturesHeight(selected);
2381 public boolean isShowSequenceFeaturesHeight()
2383 return viewStyle.isShowSequenceFeaturesHeight();
2387 public void setShowAnnotation(boolean b)
2389 viewStyle.setShowAnnotation(b);
2393 public boolean isShowAnnotation()
2395 return viewStyle.isShowAnnotation();
2399 public boolean isRightAlignIds()
2401 return viewStyle.isRightAlignIds();
2405 public void setRightAlignIds(boolean rightAlignIds)
2407 viewStyle.setRightAlignIds(rightAlignIds);
2411 public boolean getConservationSelected()
2413 return viewStyle.getConservationSelected();
2417 public void setShowBoxes(boolean state)
2419 viewStyle.setShowBoxes(state);
2424 * @see jalview.api.ViewStyleI#getTextColour()
2427 public Color getTextColour()
2429 return viewStyle.getTextColour();
2434 * @see jalview.api.ViewStyleI#getTextColour2()
2437 public Color getTextColour2()
2439 return viewStyle.getTextColour2();
2444 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2447 public int getThresholdTextColour()
2449 return viewStyle.getThresholdTextColour();
2454 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2457 public boolean isConservationColourSelected()
2459 return viewStyle.isConservationColourSelected();
2464 * @see jalview.api.ViewStyleI#isRenderGaps()
2467 public boolean isRenderGaps()
2469 return viewStyle.isRenderGaps();
2474 * @see jalview.api.ViewStyleI#isShowColourText()
2477 public boolean isShowColourText()
2479 return viewStyle.isShowColourText();
2483 * @param conservationColourSelected
2484 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2487 public void setConservationColourSelected(
2488 boolean conservationColourSelected)
2490 viewStyle.setConservationColourSelected(conservationColourSelected);
2494 * @param showColourText
2495 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2498 public void setShowColourText(boolean showColourText)
2500 viewStyle.setShowColourText(showColourText);
2505 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2508 public void setTextColour(Color textColour)
2510 viewStyle.setTextColour(textColour);
2514 * @param thresholdTextColour
2515 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2518 public void setThresholdTextColour(int thresholdTextColour)
2520 viewStyle.setThresholdTextColour(thresholdTextColour);
2524 * @param textColour2
2525 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2528 public void setTextColour2(Color textColour2)
2530 viewStyle.setTextColour2(textColour2);
2534 public ViewStyleI getViewStyle()
2536 return new ViewStyle(viewStyle);
2540 public void setViewStyle(ViewStyleI settingsForView)
2542 viewStyle = new ViewStyle(settingsForView);
2543 if (residueShading != null)
2545 residueShading.setConservationApplied(
2546 settingsForView.isConservationColourSelected());
2551 public boolean sameStyle(ViewStyleI them)
2553 return viewStyle.sameStyle(them);
2558 * @see jalview.api.ViewStyleI#getIdWidth()
2561 public int getIdWidth()
2563 return viewStyle.getIdWidth();
2568 * @see jalview.api.ViewStyleI#setIdWidth(int)
2571 public void setIdWidth(int i)
2573 viewStyle.setIdWidth(i);
2578 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2581 public boolean isCentreColumnLabels()
2583 return viewStyle.isCentreColumnLabels();
2587 * @param centreColumnLabels
2588 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2591 public void setCentreColumnLabels(boolean centreColumnLabels)
2593 viewStyle.setCentreColumnLabels(centreColumnLabels);
2598 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2601 public void setShowDBRefs(boolean showdbrefs)
2603 viewStyle.setShowDBRefs(showdbrefs);
2608 * @see jalview.api.ViewStyleI#isShowDBRefs()
2611 public boolean isShowDBRefs()
2613 return viewStyle.isShowDBRefs();
2618 * @see jalview.api.ViewStyleI#isShowNPFeats()
2621 public boolean isShowNPFeats()
2623 return viewStyle.isShowNPFeats();
2627 * @param shownpfeats
2628 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2631 public void setShowNPFeats(boolean shownpfeats)
2633 viewStyle.setShowNPFeats(shownpfeats);
2636 public abstract StructureSelectionManager getStructureSelectionManager();
2639 * Add one command to the command history list.
2643 public void addToHistoryList(CommandI command)
2645 if (this.historyList != null)
2647 this.historyList.push(command);
2648 broadcastCommand(command, false);
2649 setSavedUpToDate(false);
2650 Jalview2XML.setStateSavedUpToDate(false);
2654 protected void broadcastCommand(CommandI command, boolean undo)
2656 getStructureSelectionManager().commandPerformed(command, undo,
2661 * Add one command to the command redo list.
2665 public void addToRedoList(CommandI command)
2667 if (this.redoList != null)
2669 this.redoList.push(command);
2671 broadcastCommand(command, true);
2675 * Clear the command redo list.
2677 public void clearRedoList()
2679 if (this.redoList != null)
2681 this.redoList.clear();
2685 public void setHistoryList(Deque<CommandI> list)
2687 this.historyList = list;
2690 public Deque<CommandI> getHistoryList()
2692 return this.historyList;
2695 public void setRedoList(Deque<CommandI> list)
2697 this.redoList = list;
2700 public Deque<CommandI> getRedoList()
2702 return this.redoList;
2706 public VamsasSource getVamsasSource()
2711 public SequenceAnnotationOrder getSortAnnotationsBy()
2713 return sortAnnotationsBy;
2716 public void setSortAnnotationsBy(
2717 SequenceAnnotationOrder sortAnnotationsBy)
2719 this.sortAnnotationsBy = sortAnnotationsBy;
2722 public boolean isShowAutocalculatedAbove()
2724 return showAutocalculatedAbove;
2727 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2729 this.showAutocalculatedAbove = showAutocalculatedAbove;
2733 public boolean isScaleProteinAsCdna()
2735 return viewStyle.isScaleProteinAsCdna();
2739 public void setScaleProteinAsCdna(boolean b)
2741 viewStyle.setScaleProteinAsCdna(b);
2745 public boolean isProteinFontAsCdna()
2747 return viewStyle.isProteinFontAsCdna();
2751 public void setProteinFontAsCdna(boolean b)
2753 viewStyle.setProteinFontAsCdna(b);
2757 public void setShowComplementFeatures(boolean b)
2759 viewStyle.setShowComplementFeatures(b);
2763 public boolean isShowComplementFeatures()
2765 return viewStyle.isShowComplementFeatures();
2769 public void setShowComplementFeaturesOnTop(boolean b)
2771 viewStyle.setShowComplementFeaturesOnTop(b);
2775 public boolean isShowComplementFeaturesOnTop()
2777 return viewStyle.isShowComplementFeaturesOnTop();
2781 * @return true if view should scroll to show the highlighted region of a
2786 public final boolean isFollowHighlight()
2788 return followHighlight;
2792 public final void setFollowHighlight(boolean b)
2794 this.followHighlight = b;
2798 public ViewportRanges getRanges()
2804 * Helper method to populate the SearchResults with the location in the
2805 * complementary alignment to scroll to, in order to match this one.
2808 * the SearchResults to add to
2809 * @return the offset (below top of visible region) of the matched sequence
2811 protected int findComplementScrollTarget(SearchResultsI sr)
2813 final AlignViewportI complement = getCodingComplement();
2814 if (complement == null || !complement.isFollowHighlight())
2818 boolean iAmProtein = !getAlignment().isNucleotide();
2819 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2820 : complement.getAlignment();
2821 if (proteinAlignment == null)
2825 final List<AlignedCodonFrame> mappings = proteinAlignment
2829 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2830 * residue in the middle column of the visible region. Scroll the
2831 * complementary alignment to line up the corresponding residue.
2834 SequenceI sequence = null;
2837 * locate 'middle' column (true middle if an odd number visible, left of
2838 * middle if an even number visible)
2840 int middleColumn = ranges.getStartRes()
2841 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2842 final HiddenSequences hiddenSequences = getAlignment()
2843 .getHiddenSequences();
2846 * searching to the bottom of the alignment gives smoother scrolling across
2847 * all gapped visible regions
2849 int lastSeq = alignment.getHeight() - 1;
2850 List<AlignedCodonFrame> seqMappings = null;
2851 for (int seqNo = ranges
2852 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2854 sequence = getAlignment().getSequenceAt(seqNo);
2855 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2859 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2863 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2865 getCodingComplement().getAlignment().getSequences());
2866 if (!seqMappings.isEmpty())
2872 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2875 * No ungapped mapped sequence in middle column - do nothing
2879 MappingUtils.addSearchResults(sr, sequence,
2880 sequence.findPosition(middleColumn), seqMappings);
2885 * synthesize a column selection if none exists so it covers the given
2886 * selection group. if wholewidth is false, no column selection is made if the
2887 * selection group covers the whole alignment width.
2892 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2895 if (sg != null && (sgs = sg.getStartRes()) >= 0
2896 && sg.getStartRes() <= (sge = sg.getEndRes())
2897 && !this.hasSelectedColumns())
2899 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2906 colSel = new ColumnSelection();
2908 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2910 colSel.addElement(cspos);
2916 * hold status of current selection group - defined on alignment or not.
2918 private boolean selectionIsDefinedGroup = false;
2921 public boolean isSelectionDefinedGroup()
2923 if (selectionGroup == null)
2927 if (isSelectionGroupChanged(true))
2929 selectionIsDefinedGroup = false;
2930 List<SequenceGroup> gps = alignment.getGroups();
2931 if (gps == null || gps.size() == 0)
2933 selectionIsDefinedGroup = false;
2937 selectionIsDefinedGroup = gps.contains(selectionGroup);
2940 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2944 * null, or currently highlighted results on this view
2946 private SearchResultsI searchResults = null;
2948 protected TreeModel currentTree = null;
2951 public boolean hasSearchResults()
2953 return searchResults != null;
2957 public void setSearchResults(SearchResultsI results)
2959 searchResults = results;
2963 public SearchResultsI getSearchResults()
2965 return searchResults;
2969 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
2971 return alignment.getContactListFor(_aa, column);
2975 * get the consensus sequence as displayed under the PID consensus annotation
2978 * @return consensus sequence as a new sequence object
2980 public SequenceI getConsensusSeq()
2982 if (consensus == null)
2984 updateConsensus(null);
2986 if (consensus == null)
2990 StringBuffer seqs = new StringBuffer();
2991 for (int i = 0; i < consensus.annotations.length; i++)
2993 Annotation annotation = consensus.annotations[i];
2994 if (annotation != null)
2996 String description = annotation.description;
2997 if (description != null && description.startsWith("["))
2999 // consensus is a tie - just pick the first one
3000 seqs.append(description.charAt(1));
3004 seqs.append(annotation.displayCharacter);
3009 SequenceI sq = new Sequence("Consensus", seqs.toString());
3010 sq.setDescription("Percentage Identity Consensus "
3011 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
3016 public void setCurrentTree(TreeModel tree)
3022 public TreeModel getCurrentTree()
3028 public AlignmentExportData getAlignExportData(
3029 AlignExportSettingsI options)
3031 AlignmentI alignmentToExport = null;
3032 String[] omitHidden = null;
3033 alignmentToExport = null;
3035 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3037 omitHidden = getViewAsString(false,
3038 options.isExportHiddenSequences());
3041 int[] alignmentStartEnd = new int[2];
3042 if (hasHiddenRows() && options.isExportHiddenSequences())
3044 alignmentToExport = getAlignment().getHiddenSequences()
3045 .getFullAlignment();
3049 alignmentToExport = getAlignment();
3051 alignmentStartEnd = getAlignment().getHiddenColumns()
3052 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3053 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3054 omitHidden, alignmentStartEnd);
3059 * flag set to indicate if structure views might be out of sync with sequences
3063 private boolean needToUpdateStructureViews = false;
3066 public boolean isUpdateStructures()
3068 return needToUpdateStructureViews;
3072 public void setUpdateStructures(boolean update)
3074 needToUpdateStructureViews = update;
3078 public boolean needToUpdateStructureViews()
3080 boolean update = needToUpdateStructureViews;
3081 needToUpdateStructureViews = false;
3086 public void addSequenceGroup(SequenceGroup sequenceGroup)
3088 alignment.addGroup(sequenceGroup);
3090 Color col = sequenceGroup.idColour;
3093 col = col.brighter();
3095 for (SequenceI sq : sequenceGroup.getSequences())
3097 setSequenceColour(sq, col);
3101 if (codingComplement != null)
3103 SequenceGroup mappedGroup = MappingUtils
3104 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3105 if (mappedGroup.getSequences().size() > 0)
3107 codingComplement.getAlignment().addGroup(mappedGroup);
3111 for (SequenceI seq : mappedGroup.getSequences())
3113 codingComplement.setSequenceColour(seq, col);
3117 // propagate the structure view update flag according to our own setting
3118 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3123 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3127 if (selectedRegionOnly && selectionGroup != null)
3129 start = selectionGroup.getStartRes();
3130 end = selectionGroup.getEndRes() + 1;
3134 end = alignment.getWidth();
3136 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3140 public void setSavedUpToDate(boolean s)
3142 setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
3145 public void setSavedUpToDate(boolean s, QuitHandler.Message m)
3148 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3150 QuitHandler.setMessage(m);
3153 public boolean savedUpToDate()
3155 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3157 return savedUpToDate;