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.HiddenColumns;
54 import jalview.datamodel.HiddenSequences;
55 import jalview.datamodel.ProfilesI;
56 import jalview.datamodel.SearchResultsI;
57 import jalview.datamodel.Sequence;
58 import jalview.datamodel.SequenceCollectionI;
59 import jalview.datamodel.SequenceGroup;
60 import jalview.datamodel.SequenceI;
61 import jalview.project.Jalview2XML;
62 import jalview.renderer.ResidueShader;
63 import jalview.renderer.ResidueShaderI;
64 import jalview.schemes.ColourSchemeI;
65 import jalview.structure.CommandListener;
66 import jalview.structure.StructureSelectionManager;
67 import jalview.structure.VamsasSource;
68 import jalview.util.Comparison;
69 import jalview.util.MapList;
70 import jalview.util.MappingUtils;
71 import jalview.util.MessageManager;
72 import jalview.viewmodel.styles.ViewStyle;
73 import jalview.workers.AlignCalcManager;
74 import jalview.workers.ComplementConsensusThread;
75 import jalview.workers.ConsensusThread;
76 import jalview.workers.StrucConsensusThread;
79 * base class holding visualization and analysis attributes and common logic for
80 * an active alignment view displayed in the GUI
85 public abstract class AlignmentViewport
86 implements AlignViewportI, CommandListener, VamsasSource
88 protected ViewportRanges ranges;
90 protected ViewStyleI viewStyle = new ViewStyle();
93 * A viewport that hosts the cDna view of this (protein), or vice versa (if
96 AlignViewportI codingComplement = null;
98 FeaturesDisplayedI featuresDisplayed = null;
100 protected Deque<CommandI> historyList = new ArrayDeque<>();
102 protected Deque<CommandI> redoList = new ArrayDeque<>();
105 * used to determine if quit should be confirmed
107 private boolean savedUpToDate = false;
110 * alignment displayed in the viewport. Please use get/setter
112 protected AlignmentI alignment;
114 public AlignmentViewport(AlignmentI al)
117 ranges = new ViewportRanges(al);
122 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
125 public void setFontName(String name)
127 viewStyle.setFontName(name);
132 * @see jalview.api.ViewStyleI#setFontStyle(int)
135 public void setFontStyle(int style)
137 viewStyle.setFontStyle(style);
142 * @see jalview.api.ViewStyleI#setFontSize(int)
145 public void setFontSize(int size)
147 viewStyle.setFontSize(size);
152 * @see jalview.api.ViewStyleI#getFontStyle()
155 public int getFontStyle()
157 return viewStyle.getFontStyle();
162 * @see jalview.api.ViewStyleI#getFontName()
165 public String getFontName()
167 return viewStyle.getFontName();
172 * @see jalview.api.ViewStyleI#getFontSize()
175 public int getFontSize()
177 return viewStyle.getFontSize();
181 * @param upperCasebold
182 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
185 public void setUpperCasebold(boolean upperCasebold)
187 viewStyle.setUpperCasebold(upperCasebold);
192 * @see jalview.api.ViewStyleI#isUpperCasebold()
195 public boolean isUpperCasebold()
197 return viewStyle.isUpperCasebold();
202 * @see jalview.api.ViewStyleI#isSeqNameItalics()
205 public boolean isSeqNameItalics()
207 return viewStyle.isSeqNameItalics();
211 * @param colourByReferenceSeq
212 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
215 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
217 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
222 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
225 public void setColourAppliesToAllGroups(boolean b)
227 viewStyle.setColourAppliesToAllGroups(b);
232 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
235 public boolean getColourAppliesToAllGroups()
237 return viewStyle.getColourAppliesToAllGroups();
242 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
245 public boolean getAbovePIDThreshold()
247 return viewStyle.getAbovePIDThreshold();
252 * @see jalview.api.ViewStyleI#setIncrement(int)
255 public void setIncrement(int inc)
257 viewStyle.setIncrement(inc);
262 * @see jalview.api.ViewStyleI#getIncrement()
265 public int getIncrement()
267 return viewStyle.getIncrement();
272 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
275 public void setConservationSelected(boolean b)
277 viewStyle.setConservationSelected(b);
282 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
285 public void setShowHiddenMarkers(boolean show)
287 viewStyle.setShowHiddenMarkers(show);
292 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
295 public boolean getShowHiddenMarkers()
297 return viewStyle.getShowHiddenMarkers();
302 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
305 public void setScaleRightWrapped(boolean b)
307 viewStyle.setScaleRightWrapped(b);
312 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
315 public void setScaleLeftWrapped(boolean b)
317 viewStyle.setScaleLeftWrapped(b);
322 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
325 public void setScaleAboveWrapped(boolean b)
327 viewStyle.setScaleAboveWrapped(b);
332 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
335 public boolean getScaleLeftWrapped()
337 return viewStyle.getScaleLeftWrapped();
342 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
345 public boolean getScaleAboveWrapped()
347 return viewStyle.getScaleAboveWrapped();
352 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
355 public boolean getScaleRightWrapped()
357 return viewStyle.getScaleRightWrapped();
362 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
365 public void setAbovePIDThreshold(boolean b)
367 viewStyle.setAbovePIDThreshold(b);
372 * @see jalview.api.ViewStyleI#setThreshold(int)
375 public void setThreshold(int thresh)
377 viewStyle.setThreshold(thresh);
382 * @see jalview.api.ViewStyleI#getThreshold()
385 public int getThreshold()
387 return viewStyle.getThreshold();
392 * @see jalview.api.ViewStyleI#getShowJVSuffix()
395 public boolean getShowJVSuffix()
397 return viewStyle.getShowJVSuffix();
402 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
405 public void setShowJVSuffix(boolean b)
407 viewStyle.setShowJVSuffix(b);
412 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
415 public void setWrapAlignment(boolean state)
417 viewStyle.setWrapAlignment(state);
418 ranges.setWrappedMode(state);
423 * @see jalview.api.ViewStyleI#setShowText(boolean)
426 public void setShowText(boolean state)
428 viewStyle.setShowText(state);
433 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
436 public void setRenderGaps(boolean state)
438 viewStyle.setRenderGaps(state);
443 * @see jalview.api.ViewStyleI#getColourText()
446 public boolean getColourText()
448 return viewStyle.getColourText();
453 * @see jalview.api.ViewStyleI#setColourText(boolean)
456 public void setColourText(boolean state)
458 viewStyle.setColourText(state);
463 * @see jalview.api.ViewStyleI#getWrapAlignment()
466 public boolean getWrapAlignment()
468 return viewStyle.getWrapAlignment();
473 * @see jalview.api.ViewStyleI#getShowText()
476 public boolean getShowText()
478 return viewStyle.getShowText();
483 * @see jalview.api.ViewStyleI#getWrappedWidth()
486 public int getWrappedWidth()
488 return viewStyle.getWrappedWidth();
493 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
496 public void setWrappedWidth(int w)
498 viewStyle.setWrappedWidth(w);
503 * @see jalview.api.ViewStyleI#getCharHeight()
506 public int getCharHeight()
508 return viewStyle.getCharHeight();
513 * @see jalview.api.ViewStyleI#setCharHeight(int)
516 public void setCharHeight(int h)
518 viewStyle.setCharHeight(h);
523 * @see jalview.api.ViewStyleI#getCharWidth()
526 public int getCharWidth()
528 return viewStyle.getCharWidth();
533 * @see jalview.api.ViewStyleI#setCharWidth(int)
536 public void setCharWidth(int w)
538 viewStyle.setCharWidth(w);
543 * @see jalview.api.ViewStyleI#getShowBoxes()
546 public boolean getShowBoxes()
548 return viewStyle.getShowBoxes();
553 * @see jalview.api.ViewStyleI#getShowUnconserved()
556 public boolean getShowUnconserved()
558 return viewStyle.getShowUnconserved();
562 * @param showunconserved
563 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
566 public void setShowUnconserved(boolean showunconserved)
568 viewStyle.setShowUnconserved(showunconserved);
573 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
576 public void setSeqNameItalics(boolean default1)
578 viewStyle.setSeqNameItalics(default1);
582 public AlignmentI getAlignment()
588 public char getGapCharacter()
590 return alignment.getGapCharacter();
593 protected String sequenceSetID;
596 * probably unused indicator that view is of a dataset rather than an
599 protected boolean isDataset = false;
601 public void setDataset(boolean b)
606 public boolean isDataset()
611 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
613 protected ColumnSelection colSel = new ColumnSelection();
615 public boolean autoCalculateConsensus = true;
617 protected boolean autoCalculateStrucConsensus = true;
619 protected boolean ignoreGapsInConsensusCalculation = false;
621 protected ResidueShaderI residueShading = new ResidueShader();
624 public void setGlobalColourScheme(ColourSchemeI cs)
626 // TODO: logic refactored from AlignFrame changeColour -
627 // TODO: autorecalc stuff should be changed to rely on the worker system
628 // check to see if we should implement a changeColour(cs) method rather than
629 // put the logic in here
630 // - means that caller decides if they want to just modify state and defer
631 // calculation till later or to do all calculations in thread.
635 * only instantiate alignment colouring once, thereafter update it;
636 * this means that any conservation or PID threshold settings
637 * persist when the alignment colour scheme is changed
639 if (residueShading == null)
641 residueShading = new ResidueShader(viewStyle);
643 residueShading.setColourScheme(cs);
645 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
646 // ...problem: groups need these, but do not currently have a ViewStyle
650 if (getConservationSelected())
652 residueShading.setConservation(hconservation);
655 * reset conservation flag in case just set to false if
656 * Conservation was null (calculation still in progress)
658 residueShading.setConservationApplied(getConservationSelected());
659 residueShading.alignmentChanged(alignment, hiddenRepSequences);
663 * if 'apply colour to all groups' is selected... do so
664 * (but don't transfer any colour threshold settings to groups)
666 if (getColourAppliesToAllGroups())
668 for (SequenceGroup sg : getAlignment().getGroups())
671 * retain any colour thresholds per group while
672 * changing choice of colour scheme (JAL-2386)
674 sg.setColourScheme(cs == null ? null : cs.getInstance(this, sg));
677 sg.getGroupColourScheme().alignmentChanged(sg,
685 public ColourSchemeI getGlobalColourScheme()
687 return residueShading == null ? null : residueShading.getColourScheme();
691 public ResidueShaderI getResidueShading()
693 return residueShading;
696 protected AlignmentAnnotation consensus;
698 protected AlignmentAnnotation complementConsensus;
700 protected AlignmentAnnotation gapcounts;
702 protected AlignmentAnnotation strucConsensus;
704 protected AlignmentAnnotation conservation;
706 protected AlignmentAnnotation quality;
708 protected AlignmentAnnotation[] groupConsensus;
710 protected AlignmentAnnotation[] groupConservation;
713 * results of alignment consensus analysis for visible portion of view
715 protected ProfilesI hconsensus = null;
718 * results of cDNA complement consensus visible portion of view
720 protected Hashtable<String, Object>[] hcomplementConsensus = null;
723 * results of secondary structure base pair consensus for visible portion of
726 protected Hashtable<String, Object>[] hStrucConsensus = null;
728 protected Conservation hconservation = null;
731 public void setConservation(Conservation cons)
733 hconservation = cons;
737 * percentage gaps allowed in a column before all amino acid properties should
738 * be considered unconserved
740 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
743 public int getConsPercGaps()
749 public void setSequenceConsensusHash(ProfilesI hconsensus)
751 this.hconsensus = hconsensus;
755 public void setComplementConsensusHash(
756 Hashtable<String, Object>[] hconsensus)
758 this.hcomplementConsensus = hconsensus;
762 public ProfilesI getSequenceConsensusHash()
768 public Hashtable<String, Object>[] getComplementConsensusHash()
770 return hcomplementConsensus;
774 public Hashtable<String, Object>[] getRnaStructureConsensusHash()
776 return hStrucConsensus;
780 public void setRnaStructureConsensusHash(
781 Hashtable<String, Object>[] hStrucConsensus)
783 this.hStrucConsensus = hStrucConsensus;
788 public AlignmentAnnotation getAlignmentQualityAnnot()
794 public AlignmentAnnotation getAlignmentConservationAnnotation()
800 public AlignmentAnnotation getAlignmentConsensusAnnotation()
806 public AlignmentAnnotation getAlignmentGapAnnotation()
812 public AlignmentAnnotation getComplementConsensusAnnotation()
814 return complementConsensus;
818 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
820 return strucConsensus;
823 protected AlignCalcManagerI calculator = new AlignCalcManager();
826 * trigger update of conservation annotation
828 public void updateConservation(final AlignmentViewPanel ap)
830 // see note in mantis : issue number 8585
831 if (alignment.isNucleotide()
832 || (conservation == null && quality == null)
833 || !autoCalculateConsensus)
837 if (calculator.getRegisteredWorkersOfClass(
838 jalview.workers.ConservationThread.class) == null)
840 calculator.registerWorker(
841 new jalview.workers.ConservationThread(this, ap));
846 * trigger update of consensus annotation
848 public void updateConsensus(final AlignmentViewPanel ap)
850 // see note in mantis : issue number 8585
851 if (consensus == null || !autoCalculateConsensus)
856 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
858 calculator.registerWorker(new ConsensusThread(this, ap));
862 * A separate thread to compute cDNA consensus for a protein alignment
863 * which has mapping to cDNA
865 final AlignmentI al = this.getAlignment();
866 if (!al.isNucleotide() && al.getCodonFrames() != null
867 && !al.getCodonFrames().isEmpty())
870 * fudge - check first for protein-to-nucleotide mappings
871 * (we don't want to do this for protein-to-protein)
873 boolean doConsensus = false;
874 for (AlignedCodonFrame mapping : al.getCodonFrames())
876 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
877 MapList[] mapLists = mapping.getdnaToProt();
878 // mapLists can be empty if project load has not finished resolving seqs
879 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
887 if (calculator.getRegisteredWorkersOfClass(
888 ComplementConsensusThread.class) == null)
891 .registerWorker(new ComplementConsensusThread(this, ap));
897 // --------START Structure Conservation
898 public void updateStrucConsensus(final AlignmentViewPanel ap)
900 if (autoCalculateStrucConsensus && strucConsensus == null
901 && alignment.isNucleotide() && alignment.hasRNAStructure())
903 // secondary structure has been added - so init the consensus line
907 // see note in mantis : issue number 8585
908 if (strucConsensus == null || !autoCalculateStrucConsensus)
912 if (calculator.getRegisteredWorkersOfClass(
913 StrucConsensusThread.class) == null)
915 calculator.registerWorker(new StrucConsensusThread(this, ap));
919 public boolean isCalcInProgress()
921 return calculator.isWorking();
925 public boolean isCalculationInProgress(
926 AlignmentAnnotation alignmentAnnotation)
928 if (!alignmentAnnotation.autoCalculated)
932 if (calculator.workingInvolvedWith(alignmentAnnotation))
934 // System.err.println("grey out ("+alignmentAnnotation.label+")");
940 public void setAlignment(AlignmentI align)
942 this.alignment = align;
946 * Clean up references when this viewport is closed
949 public void dispose()
952 * defensively null out references to large objects in case
953 * this object is not garbage collected (as if!)
956 complementConsensus = null;
957 strucConsensus = null;
960 groupConsensus = null;
961 groupConservation = null;
963 hconservation = null;
964 hcomplementConsensus = null;
967 residueShading = null; // may hold a reference to Consensus
968 changeSupport = null;
971 selectionGroup = null;
977 public boolean isClosed()
979 // TODO: check that this isClosed is only true after panel is closed, not
980 // before it is fully constructed.
981 return alignment == null;
985 public AlignCalcManagerI getCalcManager()
991 * should conservation rows be shown for groups
993 protected boolean showGroupConservation = false;
996 * should consensus rows be shown for groups
998 protected boolean showGroupConsensus = false;
1001 * should consensus profile be rendered by default
1003 protected boolean showSequenceLogo = false;
1006 * should consensus profile be rendered normalised to row height
1008 protected boolean normaliseSequenceLogo = false;
1011 * should consensus histograms be rendered by default
1013 protected boolean showConsensusHistogram = true;
1016 * @return the showConsensusProfile
1019 public boolean isShowSequenceLogo()
1021 return showSequenceLogo;
1025 * @param showSequenceLogo
1028 public void setShowSequenceLogo(boolean showSequenceLogo)
1030 if (showSequenceLogo != this.showSequenceLogo)
1032 // TODO: decouple settings setting from calculation when refactoring
1033 // annotation update method from alignframe to viewport
1034 this.showSequenceLogo = showSequenceLogo;
1035 calculator.updateAnnotationFor(ConsensusThread.class);
1036 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1037 calculator.updateAnnotationFor(StrucConsensusThread.class);
1039 this.showSequenceLogo = showSequenceLogo;
1043 * @param showConsensusHistogram
1044 * the showConsensusHistogram to set
1046 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1048 this.showConsensusHistogram = showConsensusHistogram;
1052 * @return the showGroupConservation
1054 public boolean isShowGroupConservation()
1056 return showGroupConservation;
1060 * @param showGroupConservation
1061 * the showGroupConservation to set
1063 public void setShowGroupConservation(boolean showGroupConservation)
1065 this.showGroupConservation = showGroupConservation;
1069 * @return the showGroupConsensus
1071 public boolean isShowGroupConsensus()
1073 return showGroupConsensus;
1077 * @param showGroupConsensus
1078 * the showGroupConsensus to set
1080 public void setShowGroupConsensus(boolean showGroupConsensus)
1082 this.showGroupConsensus = showGroupConsensus;
1087 * @return flag to indicate if the consensus histogram should be rendered by
1091 public boolean isShowConsensusHistogram()
1093 return this.showConsensusHistogram;
1097 * when set, updateAlignment will always ensure sequences are of equal length
1099 private boolean padGaps = false;
1102 * when set, alignment should be reordered according to a newly opened tree
1104 public boolean sortByTree = false;
1109 * @return null or the currently selected sequence region
1112 public SequenceGroup getSelectionGroup()
1114 return selectionGroup;
1118 * Set the selection group for this window. Also sets the current alignment as
1119 * the context for the group, if it does not already have one.
1122 * - group holding references to sequences in this alignment view
1126 public void setSelectionGroup(SequenceGroup sg)
1128 selectionGroup = sg;
1129 if (sg != null && sg.getContext() == null)
1131 sg.setContext(alignment);
1135 public void setHiddenColumns(HiddenColumns hidden)
1137 this.alignment.setHiddenColumns(hidden);
1141 public ColumnSelection getColumnSelection()
1147 public void setColumnSelection(ColumnSelection colSel)
1149 this.colSel = colSel;
1152 updateHiddenColumns();
1154 isColSelChanged(true);
1162 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1164 return hiddenRepSequences;
1168 public void setHiddenRepSequences(
1169 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1171 this.hiddenRepSequences = hiddenRepSequences;
1175 public boolean hasSelectedColumns()
1177 ColumnSelection columnSelection = getColumnSelection();
1178 return columnSelection != null && columnSelection.hasSelectedColumns();
1182 public boolean hasHiddenColumns()
1184 return alignment.getHiddenColumns() != null
1185 && alignment.getHiddenColumns().hasHiddenColumns();
1188 public void updateHiddenColumns()
1190 // this method doesn't really do anything now. But - it could, since a
1191 // column Selection could be in the process of modification
1192 // hasHiddenColumns = colSel.hasHiddenColumns();
1196 public boolean hasHiddenRows()
1198 return alignment.getHiddenSequences().getSize() > 0;
1201 protected SequenceGroup selectionGroup;
1203 public void setSequenceSetId(String newid)
1205 if (sequenceSetID != null)
1208 "Warning - overwriting a sequenceSetId for a viewport!");
1210 sequenceSetID = new String(newid);
1214 public String getSequenceSetId()
1216 if (sequenceSetID == null)
1218 sequenceSetID = alignment.hashCode() + "";
1221 return sequenceSetID;
1225 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1228 protected String viewId = null;
1231 public String getViewId()
1235 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1240 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1242 ignoreGapsInConsensusCalculation = b;
1245 updateConsensus(ap);
1246 if (residueShading != null)
1248 residueShading.setThreshold(residueShading.getThreshold(),
1249 ignoreGapsInConsensusCalculation);
1255 private long sgrouphash = -1, colselhash = -1;
1258 * checks current SelectionGroup against record of last hash value, and
1262 * update the record of last hash value
1264 * @return true if SelectionGroup changed since last call (when b is true)
1266 public boolean isSelectionGroupChanged(boolean b)
1268 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1269 : selectionGroup.hashCode();
1270 if (hc != -1 && hc != sgrouphash)
1282 * checks current colsel against record of last hash value, and optionally
1286 * update the record of last hash value
1287 * @return true if colsel changed since last call (when b is true)
1289 public boolean isColSelChanged(boolean b)
1291 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1292 if (hc != -1 && hc != colselhash)
1304 public boolean isIgnoreGapsConsensus()
1306 return ignoreGapsInConsensusCalculation;
1309 // property change stuff
1310 // JBPNote Prolly only need this in the applet version.
1311 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1314 protected boolean showConservation = true;
1316 protected boolean showQuality = true;
1318 protected boolean showConsensus = true;
1320 protected boolean showOccupancy = true;
1322 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1324 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1326 protected boolean showAutocalculatedAbove;
1329 * when set, view will scroll to show the highlighted position
1331 private boolean followHighlight = true;
1334 * Property change listener for changes in alignment
1339 public void addPropertyChangeListener(
1340 java.beans.PropertyChangeListener listener)
1342 changeSupport.addPropertyChangeListener(listener);
1351 public void removePropertyChangeListener(
1352 java.beans.PropertyChangeListener listener)
1354 if (changeSupport != null)
1356 changeSupport.removePropertyChangeListener(listener);
1361 * Property change listener for changes in alignment
1370 public void firePropertyChange(String prop, Object oldvalue,
1373 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1376 // common hide/show column stuff
1378 public void hideSelectedColumns()
1380 if (colSel.isEmpty())
1385 colSel.hideSelectedColumns(alignment);
1386 setSelectionGroup(null);
1387 isColSelChanged(true);
1390 public void hideColumns(int start, int end)
1394 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1398 alignment.getHiddenColumns().hideColumns(start, end);
1400 isColSelChanged(true);
1403 public void showColumn(int col)
1405 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1406 isColSelChanged(true);
1409 public void showAllHiddenColumns()
1411 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1412 isColSelChanged(true);
1415 // common hide/show seq stuff
1416 public void showAllHiddenSeqs()
1418 int startSeq = ranges.getStartSeq();
1419 int endSeq = ranges.getEndSeq();
1421 if (alignment.getHiddenSequences().getSize() > 0)
1423 if (selectionGroup == null)
1425 selectionGroup = new SequenceGroup();
1426 selectionGroup.setEndRes(alignment.getWidth() - 1);
1428 List<SequenceI> tmp = alignment.getHiddenSequences()
1429 .showAll(hiddenRepSequences);
1430 for (SequenceI seq : tmp)
1432 selectionGroup.addSequence(seq, false);
1433 setSequenceAnnotationsVisible(seq, true);
1436 hiddenRepSequences = null;
1438 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1440 firePropertyChange("alignment", null, alignment.getSequences());
1441 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1447 public void showSequence(int index)
1449 int startSeq = ranges.getStartSeq();
1450 int endSeq = ranges.getEndSeq();
1452 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1453 hiddenRepSequences);
1456 if (selectionGroup == null)
1458 selectionGroup = new SequenceGroup();
1459 selectionGroup.setEndRes(alignment.getWidth() - 1);
1462 for (SequenceI seq : tmp)
1464 selectionGroup.addSequence(seq, false);
1465 setSequenceAnnotationsVisible(seq, true);
1468 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1470 firePropertyChange("alignment", null, alignment.getSequences());
1475 public void hideAllSelectedSeqs()
1477 if (selectionGroup == null || selectionGroup.getSize() < 1)
1482 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1486 setSelectionGroup(null);
1489 public void hideSequence(SequenceI[] seq)
1492 * cache offset to first visible sequence
1494 int startSeq = ranges.getStartSeq();
1498 for (int i = 0; i < seq.length; i++)
1500 alignment.getHiddenSequences().hideSequence(seq[i]);
1501 setSequenceAnnotationsVisible(seq[i], false);
1503 ranges.setStartSeq(startSeq);
1504 firePropertyChange("alignment", null, alignment.getSequences());
1509 * Hides the specified sequence, or the sequences it represents
1512 * the sequence to hide, or keep as representative
1513 * @param representGroup
1514 * if true, hide the current selection group except for the
1515 * representative sequence
1517 public void hideSequences(SequenceI sequence, boolean representGroup)
1519 if (selectionGroup == null || selectionGroup.getSize() < 1)
1521 hideSequence(new SequenceI[] { sequence });
1527 hideRepSequences(sequence, selectionGroup);
1528 setSelectionGroup(null);
1532 int gsize = selectionGroup.getSize();
1533 SequenceI[] hseqs = selectionGroup.getSequences()
1534 .toArray(new SequenceI[gsize]);
1536 hideSequence(hseqs);
1537 setSelectionGroup(null);
1542 * Set visibility for any annotations for the given sequence.
1546 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1549 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1552 for (AlignmentAnnotation ann : anns)
1554 if (ann.sequenceRef == sequenceI)
1556 ann.visible = visible;
1562 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1564 int sSize = sg.getSize();
1570 if (hiddenRepSequences == null)
1572 hiddenRepSequences = new Hashtable<>();
1575 hiddenRepSequences.put(repSequence, sg);
1577 // Hide all sequences except the repSequence
1578 SequenceI[] seqs = new SequenceI[sSize - 1];
1580 for (int i = 0; i < sSize; i++)
1582 if (sg.getSequenceAt(i) != repSequence)
1584 if (index == sSize - 1)
1589 seqs[index++] = sg.getSequenceAt(i);
1592 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1593 sg.setHidereps(true); // note: not done in 2.7applet
1600 * @return null or the current reference sequence
1602 public SequenceI getReferenceSeq()
1604 return alignment.getSeqrep();
1609 * @return true iff seq is the reference for the alignment
1611 public boolean isReferenceSeq(SequenceI seq)
1613 return alignment.getSeqrep() == seq;
1619 * @return true if there are sequences represented by this sequence that are
1622 public boolean isHiddenRepSequence(SequenceI seq)
1624 return (hiddenRepSequences != null
1625 && hiddenRepSequences.containsKey(seq));
1631 * @return null or a sequence group containing the sequences that seq
1634 public SequenceGroup getRepresentedSequences(SequenceI seq)
1636 return (SequenceGroup) (hiddenRepSequences == null ? null
1637 : hiddenRepSequences.get(seq));
1641 public int adjustForHiddenSeqs(int alignmentIndex)
1643 return alignment.getHiddenSequences()
1644 .adjustForHiddenSeqs(alignmentIndex);
1648 public void invertColumnSelection()
1650 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1651 isColSelChanged(true);
1655 public SequenceI[] getSelectionAsNewSequence()
1657 SequenceI[] sequences;
1658 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1659 // this was the only caller in the applet for this method
1660 // JBPNote: in applet, this method returned references to the alignment
1661 // sequences, and it did not honour the presence/absence of annotation
1662 // attached to the alignment (probably!)
1663 if (selectionGroup == null || selectionGroup.getSize() == 0)
1665 sequences = alignment.getSequencesArray();
1666 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1667 for (int i = 0; i < sequences.length; i++)
1669 // construct new sequence with subset of visible annotation
1670 sequences[i] = new Sequence(sequences[i], annots);
1675 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1682 public SequenceI[] getSequenceSelection()
1684 SequenceI[] sequences = null;
1685 if (selectionGroup != null)
1687 sequences = selectionGroup.getSequencesInOrder(alignment);
1689 if (sequences == null)
1691 sequences = alignment.getSequencesArray();
1697 public jalview.datamodel.AlignmentView getAlignmentView(
1698 boolean selectedOnly)
1700 return getAlignmentView(selectedOnly, false);
1704 public jalview.datamodel.AlignmentView getAlignmentView(
1705 boolean selectedOnly, boolean markGroups)
1707 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1709 alignment.getHiddenColumns() != null
1710 && alignment.getHiddenColumns().hasHiddenColumns(),
1711 selectedOnly, markGroups);
1715 public String[] getViewAsString(boolean selectedRegionOnly)
1717 return getViewAsString(selectedRegionOnly, true);
1721 public String[] getViewAsString(boolean selectedRegionOnly,
1722 boolean exportHiddenSeqs)
1724 String[] selection = null;
1725 SequenceI[] seqs = null;
1727 int start = 0, end = 0;
1728 if (selectedRegionOnly && selectionGroup != null)
1730 iSize = selectionGroup.getSize();
1731 seqs = selectionGroup.getSequencesInOrder(alignment);
1732 start = selectionGroup.getStartRes();
1733 end = selectionGroup.getEndRes() + 1;
1737 if (hasHiddenRows() && exportHiddenSeqs)
1739 AlignmentI fullAlignment = alignment.getHiddenSequences()
1740 .getFullAlignment();
1741 iSize = fullAlignment.getHeight();
1742 seqs = fullAlignment.getSequencesArray();
1743 end = fullAlignment.getWidth();
1747 iSize = alignment.getHeight();
1748 seqs = alignment.getSequencesArray();
1749 end = alignment.getWidth();
1753 selection = new String[iSize];
1754 if (alignment.getHiddenColumns() != null
1755 && alignment.getHiddenColumns().hasHiddenColumns())
1757 for (i = 0; i < iSize; i++)
1759 Iterator<int[]> blocks = alignment.getHiddenColumns()
1760 .getVisContigsIterator(start, end + 1, false);
1761 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1766 for (i = 0; i < iSize; i++)
1768 selection[i] = seqs[i].getSequenceAsString(start, end);
1776 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1778 ArrayList<int[]> regions = new ArrayList<>();
1784 HiddenColumns hidden = alignment.getHiddenColumns();
1785 if (hidden != null && hidden.hasHiddenColumns())
1789 start = hidden.visibleToAbsoluteColumn(start);
1792 end = hidden.getNextHiddenBoundary(false, start);
1803 regions.add(new int[] { start, end });
1805 if (hidden != null && hidden.hasHiddenColumns())
1807 start = hidden.visibleToAbsoluteColumn(end);
1808 start = hidden.getNextHiddenBoundary(true, start) + 1;
1810 } while (end < max);
1812 // int[][] startEnd = new int[regions.size()][2];
1818 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1819 boolean selectedOnly)
1821 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1822 AlignmentAnnotation[] aa;
1823 if ((aa = alignment.getAlignmentAnnotation()) != null)
1825 for (AlignmentAnnotation annot : aa)
1827 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1828 if (selectedOnly && selectionGroup != null)
1830 clone.makeVisibleAnnotation(selectionGroup.getStartRes(),
1831 selectionGroup.getEndRes(), alignment.getHiddenColumns());
1835 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1844 public boolean isPadGaps()
1850 public void setPadGaps(boolean padGaps)
1852 this.padGaps = padGaps;
1856 * apply any post-edit constraints and trigger any calculations needed after
1857 * an edit has been performed on the alignment
1862 public void alignmentChanged(AlignmentViewPanel ap)
1866 alignment.padGaps();
1868 if (autoCalculateConsensus)
1870 updateConsensus(ap);
1872 if (hconsensus != null && autoCalculateConsensus)
1874 updateConservation(ap);
1876 if (autoCalculateStrucConsensus)
1878 updateStrucConsensus(ap);
1881 // Reset endRes of groups if beyond alignment width
1882 int alWidth = alignment.getWidth();
1883 List<SequenceGroup> groups = alignment.getGroups();
1886 for (SequenceGroup sg : groups)
1888 if (sg.getEndRes() > alWidth)
1890 sg.setEndRes(alWidth - 1);
1895 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1897 selectionGroup.setEndRes(alWidth - 1);
1900 updateAllColourSchemes();
1901 calculator.restartWorkers();
1902 // alignment.adjustSequenceAnnotations();
1906 * reset scope and do calculations for all applied colourschemes on alignment
1908 void updateAllColourSchemes()
1910 ResidueShaderI rs = residueShading;
1913 rs.alignmentChanged(alignment, hiddenRepSequences);
1915 rs.setConsensus(hconsensus);
1916 if (rs.conservationApplied())
1918 rs.setConservation(Conservation.calculateConservation("All",
1919 alignment.getSequences(), 0, alignment.getWidth(), false,
1920 getConsPercGaps(), false));
1924 for (SequenceGroup sg : alignment.getGroups())
1928 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1930 sg.recalcConservation();
1934 protected void initAutoAnnotation()
1936 // TODO: add menu option action that nulls or creates consensus object
1937 // depending on if the user wants to see the annotation or not in a
1938 // specific alignment
1940 if (hconsensus == null && !isDataset)
1942 if (!alignment.isNucleotide())
1951 consensus = new AlignmentAnnotation("Consensus",
1952 MessageManager.getString("label.consensus_descr"),
1953 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1954 initConsensus(consensus);
1957 initComplementConsensus();
1962 * If this is a protein alignment and there are mappings to cDNA, adds the
1963 * cDNA consensus annotation and returns true, else returns false.
1965 public boolean initComplementConsensus()
1967 if (!alignment.isNucleotide())
1969 final List<AlignedCodonFrame> codonMappings = alignment
1971 if (codonMappings != null && !codonMappings.isEmpty())
1973 boolean doConsensus = false;
1974 for (AlignedCodonFrame mapping : codonMappings)
1976 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1977 MapList[] mapLists = mapping.getdnaToProt();
1978 // mapLists can be empty if project load has not finished resolving
1980 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1988 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1990 .getString("label.complement_consensus_descr"),
1991 new Annotation[1], 0f, 100f,
1992 AlignmentAnnotation.BAR_GRAPH);
1993 initConsensus(complementConsensus);
2001 private void initConsensus(AlignmentAnnotation aa)
2004 aa.autoCalculated = true;
2008 alignment.addAnnotation(aa);
2012 // these should be extracted from the view model - style and settings for
2013 // derived annotation
2014 private void initGapCounts()
2018 gapcounts = new AlignmentAnnotation("Occupancy",
2019 MessageManager.getString("label.occupancy_descr"),
2020 new Annotation[1], 0f, alignment.getHeight(),
2021 AlignmentAnnotation.BAR_GRAPH);
2022 gapcounts.hasText = true;
2023 gapcounts.autoCalculated = true;
2024 gapcounts.scaleColLabel = true;
2025 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2027 alignment.addAnnotation(gapcounts);
2031 private void initConservation()
2033 if (showConservation)
2035 if (conservation == null)
2037 conservation = new AlignmentAnnotation("Conservation",
2038 MessageManager.formatMessage("label.conservation_descr",
2040 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2041 conservation.hasText = true;
2042 conservation.autoCalculated = true;
2043 alignment.addAnnotation(conservation);
2048 private void initQuality()
2052 if (quality == null)
2054 quality = new AlignmentAnnotation("Quality",
2055 MessageManager.getString("label.quality_descr"),
2056 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2057 quality.hasText = true;
2058 quality.autoCalculated = true;
2059 alignment.addAnnotation(quality);
2064 private void initRNAStructure()
2066 if (alignment.hasRNAStructure() && strucConsensus == null)
2068 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2069 MessageManager.getString("label.strucconsensus_descr"),
2070 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2071 strucConsensus.hasText = true;
2072 strucConsensus.autoCalculated = true;
2076 alignment.addAnnotation(strucConsensus);
2084 * @see jalview.api.AlignViewportI#calcPanelHeight()
2087 public int calcPanelHeight()
2089 // setHeight of panels
2090 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2092 int charHeight = getCharHeight();
2095 BitSet graphgrp = new BitSet();
2096 for (AlignmentAnnotation aa : anns)
2100 System.err.println("Null annotation row: ignoring.");
2107 if (aa.graphGroup > -1)
2109 if (graphgrp.get(aa.graphGroup))
2115 graphgrp.set(aa.graphGroup);
2122 aa.height += charHeight;
2132 aa.height += aa.graphHeight;
2140 height += aa.height;
2152 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2153 boolean preserveNewGroupSettings)
2155 boolean updateCalcs = false;
2156 boolean conv = isShowGroupConservation();
2157 boolean cons = isShowGroupConsensus();
2158 boolean showprf = isShowSequenceLogo();
2159 boolean showConsHist = isShowConsensusHistogram();
2160 boolean normLogo = isNormaliseSequenceLogo();
2163 * TODO reorder the annotation rows according to group/sequence ordering on
2166 // boolean sortg = true;
2168 // remove old automatic annotation
2169 // add any new annotation
2171 // intersect alignment annotation with alignment groups
2173 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2174 List<SequenceGroup> oldrfs = new ArrayList<>();
2177 for (int an = 0; an < aan.length; an++)
2179 if (aan[an].autoCalculated && aan[an].groupRef != null)
2181 oldrfs.add(aan[an].groupRef);
2182 alignment.deleteAnnotation(aan[an], false);
2186 if (alignment.getGroups() != null)
2188 for (SequenceGroup sg : alignment.getGroups())
2190 updateCalcs = false;
2191 if (applyGlobalSettings
2192 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2194 // set defaults for this group's conservation/consensus
2195 sg.setshowSequenceLogo(showprf);
2196 sg.setShowConsensusHistogram(showConsHist);
2197 sg.setNormaliseSequenceLogo(normLogo);
2202 alignment.addAnnotation(sg.getConservationRow(), 0);
2207 alignment.addAnnotation(sg.getConsensus(), 0);
2209 // refresh the annotation rows
2212 sg.recalcConservation();
2220 public boolean isDisplayReferenceSeq()
2222 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2226 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2228 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2232 public boolean isColourByReferenceSeq()
2234 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2238 public Color getSequenceColour(SequenceI seq)
2240 Color sqc = sequenceColours.get(seq);
2241 return (sqc == null ? Color.white : sqc);
2245 public void setSequenceColour(SequenceI seq, Color col)
2249 sequenceColours.remove(seq);
2253 sequenceColours.put(seq, col);
2258 public void updateSequenceIdColours()
2260 for (SequenceGroup sg : alignment.getGroups())
2262 if (sg.idColour != null)
2264 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2266 sequenceColours.put(s, sg.idColour);
2273 public void clearSequenceColours()
2275 sequenceColours.clear();
2279 public AlignViewportI getCodingComplement()
2281 return this.codingComplement;
2285 * Set this as the (cDna/protein) complement of the given viewport. Also
2286 * ensures the reverse relationship is set on the given viewport.
2289 public void setCodingComplement(AlignViewportI av)
2293 System.err.println("Ignoring recursive setCodingComplement request");
2297 this.codingComplement = av;
2298 // avoid infinite recursion!
2299 if (av.getCodingComplement() != this)
2301 av.setCodingComplement(this);
2307 public boolean isNucleotide()
2309 return getAlignment() == null ? false : getAlignment().isNucleotide();
2313 public FeaturesDisplayedI getFeaturesDisplayed()
2315 return featuresDisplayed;
2319 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2321 featuresDisplayed = featuresDisplayedI;
2325 public boolean areFeaturesDisplayed()
2327 return featuresDisplayed != null
2328 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2335 * features are displayed if true
2338 public void setShowSequenceFeatures(boolean b)
2340 viewStyle.setShowSequenceFeatures(b);
2344 public boolean isShowSequenceFeatures()
2346 return viewStyle.isShowSequenceFeatures();
2350 public void setShowSequenceFeaturesHeight(boolean selected)
2352 viewStyle.setShowSequenceFeaturesHeight(selected);
2356 public boolean isShowSequenceFeaturesHeight()
2358 return viewStyle.isShowSequenceFeaturesHeight();
2362 public void setShowAnnotation(boolean b)
2364 viewStyle.setShowAnnotation(b);
2368 public boolean isShowAnnotation()
2370 return viewStyle.isShowAnnotation();
2374 public boolean isRightAlignIds()
2376 return viewStyle.isRightAlignIds();
2380 public void setRightAlignIds(boolean rightAlignIds)
2382 viewStyle.setRightAlignIds(rightAlignIds);
2386 public boolean getConservationSelected()
2388 return viewStyle.getConservationSelected();
2392 public void setShowBoxes(boolean state)
2394 viewStyle.setShowBoxes(state);
2399 * @see jalview.api.ViewStyleI#getTextColour()
2402 public Color getTextColour()
2404 return viewStyle.getTextColour();
2409 * @see jalview.api.ViewStyleI#getTextColour2()
2412 public Color getTextColour2()
2414 return viewStyle.getTextColour2();
2419 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2422 public int getThresholdTextColour()
2424 return viewStyle.getThresholdTextColour();
2429 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2432 public boolean isConservationColourSelected()
2434 return viewStyle.isConservationColourSelected();
2439 * @see jalview.api.ViewStyleI#isRenderGaps()
2442 public boolean isRenderGaps()
2444 return viewStyle.isRenderGaps();
2449 * @see jalview.api.ViewStyleI#isShowColourText()
2452 public boolean isShowColourText()
2454 return viewStyle.isShowColourText();
2458 * @param conservationColourSelected
2459 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2462 public void setConservationColourSelected(
2463 boolean conservationColourSelected)
2465 viewStyle.setConservationColourSelected(conservationColourSelected);
2469 * @param showColourText
2470 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2473 public void setShowColourText(boolean showColourText)
2475 viewStyle.setShowColourText(showColourText);
2480 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2483 public void setTextColour(Color textColour)
2485 viewStyle.setTextColour(textColour);
2489 * @param thresholdTextColour
2490 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2493 public void setThresholdTextColour(int thresholdTextColour)
2495 viewStyle.setThresholdTextColour(thresholdTextColour);
2499 * @param textColour2
2500 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2503 public void setTextColour2(Color textColour2)
2505 viewStyle.setTextColour2(textColour2);
2509 public ViewStyleI getViewStyle()
2511 return new ViewStyle(viewStyle);
2515 public void setViewStyle(ViewStyleI settingsForView)
2517 viewStyle = new ViewStyle(settingsForView);
2518 if (residueShading != null)
2520 residueShading.setConservationApplied(
2521 settingsForView.isConservationColourSelected());
2526 public boolean sameStyle(ViewStyleI them)
2528 return viewStyle.sameStyle(them);
2533 * @see jalview.api.ViewStyleI#getIdWidth()
2536 public int getIdWidth()
2538 return viewStyle.getIdWidth();
2543 * @see jalview.api.ViewStyleI#setIdWidth(int)
2546 public void setIdWidth(int i)
2548 viewStyle.setIdWidth(i);
2553 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2556 public boolean isCentreColumnLabels()
2558 return viewStyle.isCentreColumnLabels();
2562 * @param centreColumnLabels
2563 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2566 public void setCentreColumnLabels(boolean centreColumnLabels)
2568 viewStyle.setCentreColumnLabels(centreColumnLabels);
2573 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2576 public void setShowDBRefs(boolean showdbrefs)
2578 viewStyle.setShowDBRefs(showdbrefs);
2583 * @see jalview.api.ViewStyleI#isShowDBRefs()
2586 public boolean isShowDBRefs()
2588 return viewStyle.isShowDBRefs();
2593 * @see jalview.api.ViewStyleI#isShowNPFeats()
2596 public boolean isShowNPFeats()
2598 return viewStyle.isShowNPFeats();
2602 * @param shownpfeats
2603 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2606 public void setShowNPFeats(boolean shownpfeats)
2608 viewStyle.setShowNPFeats(shownpfeats);
2611 public abstract StructureSelectionManager getStructureSelectionManager();
2614 * Add one command to the command history list.
2618 public void addToHistoryList(CommandI command)
2620 if (this.historyList != null)
2622 this.historyList.push(command);
2623 broadcastCommand(command, false);
2624 setSavedUpToDate(false);
2625 Jalview2XML.setStateSavedUpToDate(false);
2629 protected void broadcastCommand(CommandI command, boolean undo)
2631 getStructureSelectionManager().commandPerformed(command, undo,
2636 * Add one command to the command redo list.
2640 public void addToRedoList(CommandI command)
2642 if (this.redoList != null)
2644 this.redoList.push(command);
2646 broadcastCommand(command, true);
2650 * Clear the command redo list.
2652 public void clearRedoList()
2654 if (this.redoList != null)
2656 this.redoList.clear();
2660 public void setHistoryList(Deque<CommandI> list)
2662 this.historyList = list;
2665 public Deque<CommandI> getHistoryList()
2667 return this.historyList;
2670 public void setRedoList(Deque<CommandI> list)
2672 this.redoList = list;
2675 public Deque<CommandI> getRedoList()
2677 return this.redoList;
2681 public VamsasSource getVamsasSource()
2686 public SequenceAnnotationOrder getSortAnnotationsBy()
2688 return sortAnnotationsBy;
2691 public void setSortAnnotationsBy(
2692 SequenceAnnotationOrder sortAnnotationsBy)
2694 this.sortAnnotationsBy = sortAnnotationsBy;
2697 public boolean isShowAutocalculatedAbove()
2699 return showAutocalculatedAbove;
2702 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2704 this.showAutocalculatedAbove = showAutocalculatedAbove;
2708 public boolean isScaleProteinAsCdna()
2710 return viewStyle.isScaleProteinAsCdna();
2714 public void setScaleProteinAsCdna(boolean b)
2716 viewStyle.setScaleProteinAsCdna(b);
2720 public boolean isProteinFontAsCdna()
2722 return viewStyle.isProteinFontAsCdna();
2726 public void setProteinFontAsCdna(boolean b)
2728 viewStyle.setProteinFontAsCdna(b);
2732 public void setShowComplementFeatures(boolean b)
2734 viewStyle.setShowComplementFeatures(b);
2738 public boolean isShowComplementFeatures()
2740 return viewStyle.isShowComplementFeatures();
2744 public void setShowComplementFeaturesOnTop(boolean b)
2746 viewStyle.setShowComplementFeaturesOnTop(b);
2750 public boolean isShowComplementFeaturesOnTop()
2752 return viewStyle.isShowComplementFeaturesOnTop();
2756 * @return true if view should scroll to show the highlighted region of a
2761 public final boolean isFollowHighlight()
2763 return followHighlight;
2767 public final void setFollowHighlight(boolean b)
2769 this.followHighlight = b;
2773 public ViewportRanges getRanges()
2779 * Helper method to populate the SearchResults with the location in the
2780 * complementary alignment to scroll to, in order to match this one.
2783 * the SearchResults to add to
2784 * @return the offset (below top of visible region) of the matched sequence
2786 protected int findComplementScrollTarget(SearchResultsI sr)
2788 final AlignViewportI complement = getCodingComplement();
2789 if (complement == null || !complement.isFollowHighlight())
2793 boolean iAmProtein = !getAlignment().isNucleotide();
2794 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2795 : complement.getAlignment();
2796 if (proteinAlignment == null)
2800 final List<AlignedCodonFrame> mappings = proteinAlignment
2804 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2805 * residue in the middle column of the visible region. Scroll the
2806 * complementary alignment to line up the corresponding residue.
2809 SequenceI sequence = null;
2812 * locate 'middle' column (true middle if an odd number visible, left of
2813 * middle if an even number visible)
2815 int middleColumn = ranges.getStartRes()
2816 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2817 final HiddenSequences hiddenSequences = getAlignment()
2818 .getHiddenSequences();
2821 * searching to the bottom of the alignment gives smoother scrolling across
2822 * all gapped visible regions
2824 int lastSeq = alignment.getHeight() - 1;
2825 List<AlignedCodonFrame> seqMappings = null;
2826 for (int seqNo = ranges
2827 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2829 sequence = getAlignment().getSequenceAt(seqNo);
2830 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2834 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2838 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2840 getCodingComplement().getAlignment().getSequences());
2841 if (!seqMappings.isEmpty())
2847 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2850 * No ungapped mapped sequence in middle column - do nothing
2854 MappingUtils.addSearchResults(sr, sequence,
2855 sequence.findPosition(middleColumn), seqMappings);
2860 * synthesize a column selection if none exists so it covers the given
2861 * selection group. if wholewidth is false, no column selection is made if the
2862 * selection group covers the whole alignment width.
2867 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2870 if (sg != null && (sgs = sg.getStartRes()) >= 0
2871 && sg.getStartRes() <= (sge = sg.getEndRes())
2872 && !this.hasSelectedColumns())
2874 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2881 colSel = new ColumnSelection();
2883 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2885 colSel.addElement(cspos);
2891 * hold status of current selection group - defined on alignment or not.
2893 private boolean selectionIsDefinedGroup = false;
2896 public boolean isSelectionDefinedGroup()
2898 if (selectionGroup == null)
2902 if (isSelectionGroupChanged(true))
2904 selectionIsDefinedGroup = false;
2905 List<SequenceGroup> gps = alignment.getGroups();
2906 if (gps == null || gps.size() == 0)
2908 selectionIsDefinedGroup = false;
2912 selectionIsDefinedGroup = gps.contains(selectionGroup);
2915 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2919 * null, or currently highlighted results on this view
2921 private SearchResultsI searchResults = null;
2923 protected TreeModel currentTree = null;
2926 public boolean hasSearchResults()
2928 return searchResults != null;
2932 public void setSearchResults(SearchResultsI results)
2934 searchResults = results;
2938 public SearchResultsI getSearchResults()
2940 return searchResults;
2944 * get the consensus sequence as displayed under the PID consensus annotation
2947 * @return consensus sequence as a new sequence object
2949 public SequenceI getConsensusSeq()
2951 if (consensus == null)
2953 updateConsensus(null);
2955 if (consensus == null)
2959 StringBuffer seqs = new StringBuffer();
2960 for (int i = 0; i < consensus.annotations.length; i++)
2962 Annotation annotation = consensus.annotations[i];
2963 if (annotation != null)
2965 String description = annotation.description;
2966 if (description != null && description.startsWith("["))
2968 // consensus is a tie - just pick the first one
2969 seqs.append(description.charAt(1));
2973 seqs.append(annotation.displayCharacter);
2978 SequenceI sq = new Sequence("Consensus", seqs.toString());
2979 sq.setDescription("Percentage Identity Consensus "
2980 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2985 public void setCurrentTree(TreeModel tree)
2991 public TreeModel getCurrentTree()
2997 public AlignmentExportData getAlignExportData(
2998 AlignExportSettingsI options)
3000 AlignmentI alignmentToExport = null;
3001 String[] omitHidden = null;
3002 alignmentToExport = null;
3004 if (hasHiddenColumns() && !options.isExportHiddenColumns())
3006 omitHidden = getViewAsString(false,
3007 options.isExportHiddenSequences());
3010 int[] alignmentStartEnd = new int[2];
3011 if (hasHiddenRows() && options.isExportHiddenSequences())
3013 alignmentToExport = getAlignment().getHiddenSequences()
3014 .getFullAlignment();
3018 alignmentToExport = getAlignment();
3020 alignmentStartEnd = getAlignment().getHiddenColumns()
3021 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
3022 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
3023 omitHidden, alignmentStartEnd);
3028 * flag set to indicate if structure views might be out of sync with sequences
3032 private boolean needToUpdateStructureViews = false;
3035 public boolean isUpdateStructures()
3037 return needToUpdateStructureViews;
3041 public void setUpdateStructures(boolean update)
3043 needToUpdateStructureViews = update;
3047 public boolean needToUpdateStructureViews()
3049 boolean update = needToUpdateStructureViews;
3050 needToUpdateStructureViews = false;
3055 public void addSequenceGroup(SequenceGroup sequenceGroup)
3057 alignment.addGroup(sequenceGroup);
3059 Color col = sequenceGroup.idColour;
3062 col = col.brighter();
3064 for (SequenceI sq : sequenceGroup.getSequences())
3066 setSequenceColour(sq, col);
3070 if (codingComplement != null)
3072 SequenceGroup mappedGroup = MappingUtils
3073 .mapSequenceGroup(sequenceGroup, this, codingComplement);
3074 if (mappedGroup.getSequences().size() > 0)
3076 codingComplement.getAlignment().addGroup(mappedGroup);
3080 for (SequenceI seq : mappedGroup.getSequences())
3082 codingComplement.setSequenceColour(seq, col);
3086 // propagate the structure view update flag according to our own setting
3087 codingComplement.setUpdateStructures(needToUpdateStructureViews);
3092 public Iterator<int[]> getViewAsVisibleContigs(boolean selectedRegionOnly)
3096 if (selectedRegionOnly && selectionGroup != null)
3098 start = selectionGroup.getStartRes();
3099 end = selectionGroup.getEndRes() + 1;
3103 end = alignment.getWidth();
3105 return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
3109 public void setSavedUpToDate(boolean s)
3112 "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
3116 public boolean savedUpToDate()
3118 Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
3120 return savedUpToDate;