2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.analysis.TreeModel;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignExportSettingsI;
28 import jalview.api.AlignViewportI;
29 import jalview.api.AlignmentViewPanel;
30 import jalview.api.FeaturesDisplayedI;
31 import jalview.api.ViewStyleI;
32 import jalview.commands.CommandI;
33 import jalview.datamodel.AlignedCodonFrame;
34 import jalview.datamodel.AlignmentAnnotation;
35 import jalview.datamodel.AlignmentExportData;
36 import jalview.datamodel.AlignmentI;
37 import jalview.datamodel.AlignmentView;
38 import jalview.datamodel.Annotation;
39 import jalview.datamodel.ColumnSelection;
40 import jalview.datamodel.HiddenColumns;
41 import jalview.datamodel.HiddenSequences;
42 import jalview.datamodel.ProfilesI;
43 import jalview.datamodel.SearchResultsI;
44 import jalview.datamodel.Sequence;
45 import jalview.datamodel.SequenceCollectionI;
46 import jalview.datamodel.SequenceGroup;
47 import jalview.datamodel.SequenceI;
48 import jalview.renderer.ResidueShader;
49 import jalview.renderer.ResidueShaderI;
50 import jalview.schemes.ColourSchemeI;
51 import jalview.structure.CommandListener;
52 import jalview.structure.StructureSelectionManager;
53 import jalview.structure.VamsasSource;
54 import jalview.util.Comparison;
55 import jalview.util.MapList;
56 import jalview.util.MappingUtils;
57 import jalview.util.MessageManager;
58 import jalview.viewmodel.styles.ViewStyle;
59 import jalview.workers.AlignCalcManager;
60 import jalview.workers.ComplementConsensusThread;
61 import jalview.workers.ConsensusThread;
62 import jalview.workers.StrucConsensusThread;
64 import java.awt.Color;
65 import java.beans.PropertyChangeSupport;
66 import java.util.ArrayDeque;
67 import java.util.ArrayList;
68 import java.util.BitSet;
69 import java.util.Deque;
70 import java.util.HashMap;
71 import java.util.Hashtable;
72 import java.util.Iterator;
73 import java.util.List;
77 * base class holding visualization and analysis attributes and common logic for
78 * an active alignment view displayed in the GUI
83 public abstract class AlignmentViewport
84 implements AlignViewportI, CommandListener, VamsasSource
86 protected ViewportRanges ranges;
88 protected ViewStyleI viewStyle = new ViewStyle();
91 * A viewport that hosts the cDna view of this (protein), or vice versa (if
94 AlignViewportI codingComplement = null;
96 FeaturesDisplayedI featuresDisplayed = null;
98 protected Deque<CommandI> historyList = new ArrayDeque<>();
100 protected Deque<CommandI> redoList = new ArrayDeque<>();
103 * alignment displayed in the viewport. Please use get/setter
105 protected AlignmentI alignment;
107 public AlignmentViewport(AlignmentI al)
110 ranges = new ViewportRanges(al);
115 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
118 public void setFontName(String name)
120 viewStyle.setFontName(name);
125 * @see jalview.api.ViewStyleI#setFontStyle(int)
128 public void setFontStyle(int style)
130 viewStyle.setFontStyle(style);
135 * @see jalview.api.ViewStyleI#setFontSize(int)
138 public void setFontSize(int size)
140 viewStyle.setFontSize(size);
145 * @see jalview.api.ViewStyleI#getFontStyle()
148 public int getFontStyle()
150 return viewStyle.getFontStyle();
155 * @see jalview.api.ViewStyleI#getFontName()
158 public String getFontName()
160 return viewStyle.getFontName();
165 * @see jalview.api.ViewStyleI#getFontSize()
168 public int getFontSize()
170 return viewStyle.getFontSize();
174 * @param upperCasebold
175 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
178 public void setUpperCasebold(boolean upperCasebold)
180 viewStyle.setUpperCasebold(upperCasebold);
185 * @see jalview.api.ViewStyleI#isUpperCasebold()
188 public boolean isUpperCasebold()
190 return viewStyle.isUpperCasebold();
195 * @see jalview.api.ViewStyleI#isSeqNameItalics()
198 public boolean isSeqNameItalics()
200 return viewStyle.isSeqNameItalics();
204 * @param colourByReferenceSeq
205 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
208 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
210 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
215 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
218 public void setColourAppliesToAllGroups(boolean b)
220 viewStyle.setColourAppliesToAllGroups(b);
225 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
228 public boolean getColourAppliesToAllGroups()
230 return viewStyle.getColourAppliesToAllGroups();
235 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
238 public boolean getAbovePIDThreshold()
240 return viewStyle.getAbovePIDThreshold();
245 * @see jalview.api.ViewStyleI#setIncrement(int)
248 public void setIncrement(int inc)
250 viewStyle.setIncrement(inc);
255 * @see jalview.api.ViewStyleI#getIncrement()
258 public int getIncrement()
260 return viewStyle.getIncrement();
265 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
268 public void setConservationSelected(boolean b)
270 viewStyle.setConservationSelected(b);
275 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
278 public void setShowHiddenMarkers(boolean show)
280 viewStyle.setShowHiddenMarkers(show);
285 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
288 public boolean getShowHiddenMarkers()
290 return viewStyle.getShowHiddenMarkers();
295 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
298 public void setScaleRightWrapped(boolean b)
300 viewStyle.setScaleRightWrapped(b);
305 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
308 public void setScaleLeftWrapped(boolean b)
310 viewStyle.setScaleLeftWrapped(b);
315 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
318 public void setScaleAboveWrapped(boolean b)
320 viewStyle.setScaleAboveWrapped(b);
325 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
328 public boolean getScaleLeftWrapped()
330 return viewStyle.getScaleLeftWrapped();
335 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
338 public boolean getScaleAboveWrapped()
340 return viewStyle.getScaleAboveWrapped();
345 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
348 public boolean getScaleRightWrapped()
350 return viewStyle.getScaleRightWrapped();
355 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
358 public void setAbovePIDThreshold(boolean b)
360 viewStyle.setAbovePIDThreshold(b);
365 * @see jalview.api.ViewStyleI#setThreshold(int)
368 public void setThreshold(int thresh)
370 viewStyle.setThreshold(thresh);
375 * @see jalview.api.ViewStyleI#getThreshold()
378 public int getThreshold()
380 return viewStyle.getThreshold();
385 * @see jalview.api.ViewStyleI#getShowJVSuffix()
388 public boolean getShowJVSuffix()
390 return viewStyle.getShowJVSuffix();
395 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
398 public void setShowJVSuffix(boolean b)
400 viewStyle.setShowJVSuffix(b);
405 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
408 public void setWrapAlignment(boolean state)
410 viewStyle.setWrapAlignment(state);
411 ranges.setWrappedMode(state);
416 * @see jalview.api.ViewStyleI#setShowText(boolean)
419 public void setShowText(boolean state)
421 viewStyle.setShowText(state);
426 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
429 public void setRenderGaps(boolean state)
431 viewStyle.setRenderGaps(state);
436 * @see jalview.api.ViewStyleI#getColourText()
439 public boolean getColourText()
441 return viewStyle.getColourText();
446 * @see jalview.api.ViewStyleI#setColourText(boolean)
449 public void setColourText(boolean state)
451 viewStyle.setColourText(state);
456 * @see jalview.api.ViewStyleI#getWrapAlignment()
459 public boolean getWrapAlignment()
461 return viewStyle.getWrapAlignment();
466 * @see jalview.api.ViewStyleI#getShowText()
469 public boolean getShowText()
471 return viewStyle.getShowText();
476 * @see jalview.api.ViewStyleI#getWrappedWidth()
479 public int getWrappedWidth()
481 return viewStyle.getWrappedWidth();
486 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
489 public void setWrappedWidth(int w)
491 viewStyle.setWrappedWidth(w);
496 * @see jalview.api.ViewStyleI#getCharHeight()
499 public int getCharHeight()
501 return viewStyle.getCharHeight();
506 * @see jalview.api.ViewStyleI#setCharHeight(int)
509 public void setCharHeight(int h)
511 viewStyle.setCharHeight(h);
516 * @see jalview.api.ViewStyleI#getCharWidth()
519 public int getCharWidth()
521 return viewStyle.getCharWidth();
526 * @see jalview.api.ViewStyleI#setCharWidth(int)
529 public void setCharWidth(int w)
531 viewStyle.setCharWidth(w);
536 * @see jalview.api.ViewStyleI#getShowBoxes()
539 public boolean getShowBoxes()
541 return viewStyle.getShowBoxes();
546 * @see jalview.api.ViewStyleI#getShowUnconserved()
549 public boolean getShowUnconserved()
551 return viewStyle.getShowUnconserved();
555 * @param showunconserved
556 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
559 public void setShowUnconserved(boolean showunconserved)
561 viewStyle.setShowUnconserved(showunconserved);
566 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
569 public void setSeqNameItalics(boolean default1)
571 viewStyle.setSeqNameItalics(default1);
575 public AlignmentI getAlignment()
581 public char getGapCharacter()
583 return alignment.getGapCharacter();
586 protected String sequenceSetID;
589 * probably unused indicator that view is of a dataset rather than an
592 protected boolean isDataset = false;
594 public void setDataset(boolean b)
599 public boolean isDataset()
604 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
606 protected ColumnSelection colSel = new ColumnSelection();
608 public boolean autoCalculateConsensus = true;
610 protected boolean autoCalculateStrucConsensus = true;
612 protected boolean ignoreGapsInConsensusCalculation = false;
614 protected ResidueShaderI residueShading = new ResidueShader();
617 public void setGlobalColourScheme(ColourSchemeI cs)
619 // TODO: logic refactored from AlignFrame changeColour -
620 // TODO: autorecalc stuff should be changed to rely on the worker system
621 // check to see if we should implement a changeColour(cs) method rather than
622 // put the logic in here
623 // - means that caller decides if they want to just modify state and defer
624 // calculation till later or to do all calculations in thread.
628 * only instantiate alignment colouring once, thereafter update it;
629 * this means that any conservation or PID threshold settings
630 * persist when the alignment colour scheme is changed
632 if (residueShading == null)
634 residueShading = new ResidueShader(viewStyle);
636 residueShading.setColourScheme(cs);
638 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
639 // ...problem: groups need these, but do not currently have a ViewStyle
643 if (getConservationSelected())
645 residueShading.setConservation(hconservation);
648 * reset conservation flag in case just set to false if
649 * Conservation was null (calculation still in progress)
651 residueShading.setConservationApplied(getConservationSelected());
652 residueShading.alignmentChanged(alignment, hiddenRepSequences);
656 * if 'apply colour to all groups' is selected... do so
657 * (but don't transfer any colour threshold settings to groups)
659 if (getColourAppliesToAllGroups())
661 for (SequenceGroup sg : getAlignment().getGroups())
664 * retain any colour thresholds per group while
665 * changing choice of colour scheme (JAL-2386)
667 sg.setColourScheme(cs);
670 sg.getGroupColourScheme().alignmentChanged(sg,
678 public ColourSchemeI getGlobalColourScheme()
680 return residueShading == null ? null : residueShading.getColourScheme();
684 public ResidueShaderI getResidueShading()
686 return residueShading;
689 protected AlignmentAnnotation consensus;
691 protected AlignmentAnnotation complementConsensus;
693 protected AlignmentAnnotation gapcounts;
695 protected AlignmentAnnotation strucConsensus;
697 protected AlignmentAnnotation conservation;
699 protected AlignmentAnnotation quality;
701 protected AlignmentAnnotation[] groupConsensus;
703 protected AlignmentAnnotation[] groupConservation;
706 * results of alignment consensus analysis for visible portion of view
708 protected ProfilesI hconsensus = null;
711 * results of cDNA complement consensus visible portion of view
713 protected Hashtable[] hcomplementConsensus = null;
716 * results of secondary structure base pair consensus for visible portion of
719 protected Hashtable[] hStrucConsensus = null;
721 protected Conservation hconservation = null;
724 public void setConservation(Conservation cons)
726 hconservation = cons;
730 * percentage gaps allowed in a column before all amino acid properties should
731 * be considered unconserved
733 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
736 public int getConsPercGaps()
742 public void setSequenceConsensusHash(ProfilesI hconsensus)
744 this.hconsensus = hconsensus;
748 public void setComplementConsensusHash(Hashtable[] hconsensus)
750 this.hcomplementConsensus = hconsensus;
754 public ProfilesI getSequenceConsensusHash()
760 public Hashtable[] getComplementConsensusHash()
762 return hcomplementConsensus;
766 public Hashtable[] getRnaStructureConsensusHash()
768 return hStrucConsensus;
772 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
774 this.hStrucConsensus = hStrucConsensus;
779 public AlignmentAnnotation getAlignmentQualityAnnot()
785 public AlignmentAnnotation getAlignmentConservationAnnotation()
791 public AlignmentAnnotation getAlignmentConsensusAnnotation()
797 public AlignmentAnnotation getAlignmentGapAnnotation()
803 public AlignmentAnnotation getComplementConsensusAnnotation()
805 return complementConsensus;
809 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
811 return strucConsensus;
814 protected AlignCalcManagerI calculator = new AlignCalcManager();
817 * trigger update of conservation annotation
819 public void updateConservation(final AlignmentViewPanel ap)
821 // see note in mantis : issue number 8585
822 if (alignment.isNucleotide()
823 || (conservation == null && quality == null)
824 || !autoCalculateConsensus)
828 if (calculator.getRegisteredWorkersOfClass(
829 jalview.workers.ConservationThread.class) == null)
831 calculator.registerWorker(
832 new jalview.workers.ConservationThread(this, ap));
837 * trigger update of consensus annotation
839 public void updateConsensus(final AlignmentViewPanel ap)
841 // see note in mantis : issue number 8585
842 if (consensus == null || !autoCalculateConsensus)
847 .getRegisteredWorkersOfClass(ConsensusThread.class) == null)
849 calculator.registerWorker(new ConsensusThread(this, ap));
853 * A separate thread to compute cDNA consensus for a protein alignment
854 * which has mapping to cDNA
856 final AlignmentI al = this.getAlignment();
857 if (!al.isNucleotide() && al.getCodonFrames() != null
858 && !al.getCodonFrames().isEmpty())
861 * fudge - check first for protein-to-nucleotide mappings
862 * (we don't want to do this for protein-to-protein)
864 boolean doConsensus = false;
865 for (AlignedCodonFrame mapping : al.getCodonFrames())
867 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
868 MapList[] mapLists = mapping.getdnaToProt();
869 // mapLists can be empty if project load has not finished resolving seqs
870 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
878 if (calculator.getRegisteredWorkersOfClass(
879 ComplementConsensusThread.class) == null)
882 .registerWorker(new ComplementConsensusThread(this, ap));
888 // --------START Structure Conservation
889 public void updateStrucConsensus(final AlignmentViewPanel ap)
891 if (autoCalculateStrucConsensus && strucConsensus == null
892 && alignment.isNucleotide() && alignment.hasRNAStructure())
894 // secondary structure has been added - so init the consensus line
898 // see note in mantis : issue number 8585
899 if (strucConsensus == null || !autoCalculateStrucConsensus)
903 if (calculator.getRegisteredWorkersOfClass(
904 StrucConsensusThread.class) == null)
906 calculator.registerWorker(new StrucConsensusThread(this, ap));
910 public boolean isCalcInProgress()
912 return calculator.isWorking();
916 public boolean isCalculationInProgress(
917 AlignmentAnnotation alignmentAnnotation)
919 if (!alignmentAnnotation.autoCalculated)
923 if (calculator.workingInvolvedWith(alignmentAnnotation))
925 // System.err.println("grey out ("+alignmentAnnotation.label+")");
931 public void setAlignment(AlignmentI align)
933 this.alignment = align;
937 * Clean up references when this viewport is closed
940 public void dispose()
943 * defensively null out references to large objects in case
944 * this object is not garbage collected (as if!)
947 complementConsensus = null;
948 strucConsensus = null;
951 groupConsensus = null;
952 groupConservation = null;
954 hconservation = null;
955 hcomplementConsensus = null;
958 residueShading = null; // may hold a reference to Consensus
959 changeSupport = null;
962 selectionGroup = null;
967 public boolean isClosed()
969 // TODO: check that this isClosed is only true after panel is closed, not
970 // before it is fully constructed.
971 return alignment == null;
975 public AlignCalcManagerI getCalcManager()
981 * should conservation rows be shown for groups
983 protected boolean showGroupConservation = false;
986 * should consensus rows be shown for groups
988 protected boolean showGroupConsensus = false;
991 * should consensus profile be rendered by default
993 protected boolean showSequenceLogo = false;
996 * should consensus profile be rendered normalised to row height
998 protected boolean normaliseSequenceLogo = false;
1001 * should consensus histograms be rendered by default
1003 protected boolean showConsensusHistogram = true;
1006 * @return the showConsensusProfile
1009 public boolean isShowSequenceLogo()
1011 return showSequenceLogo;
1015 * @param showSequenceLogo
1018 public void setShowSequenceLogo(boolean showSequenceLogo)
1020 if (showSequenceLogo != this.showSequenceLogo)
1022 // TODO: decouple settings setting from calculation when refactoring
1023 // annotation update method from alignframe to viewport
1024 this.showSequenceLogo = showSequenceLogo;
1025 calculator.updateAnnotationFor(ConsensusThread.class);
1026 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1027 calculator.updateAnnotationFor(StrucConsensusThread.class);
1029 this.showSequenceLogo = showSequenceLogo;
1033 * @param showConsensusHistogram
1034 * the showConsensusHistogram to set
1036 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1038 this.showConsensusHistogram = showConsensusHistogram;
1042 * @return the showGroupConservation
1044 public boolean isShowGroupConservation()
1046 return showGroupConservation;
1050 * @param showGroupConservation
1051 * the showGroupConservation to set
1053 public void setShowGroupConservation(boolean showGroupConservation)
1055 this.showGroupConservation = showGroupConservation;
1059 * @return the showGroupConsensus
1061 public boolean isShowGroupConsensus()
1063 return showGroupConsensus;
1067 * @param showGroupConsensus
1068 * the showGroupConsensus to set
1070 public void setShowGroupConsensus(boolean showGroupConsensus)
1072 this.showGroupConsensus = showGroupConsensus;
1077 * @return flag to indicate if the consensus histogram should be rendered by
1081 public boolean isShowConsensusHistogram()
1083 return this.showConsensusHistogram;
1087 * when set, updateAlignment will always ensure sequences are of equal length
1089 private boolean padGaps = false;
1092 * when set, alignment should be reordered according to a newly opened tree
1094 public boolean sortByTree = false;
1099 * @return null or the currently selected sequence region
1102 public SequenceGroup getSelectionGroup()
1104 return selectionGroup;
1108 * Set the selection group for this window. Also sets the current alignment as
1109 * the context for the group, if it does not already have one.
1112 * - group holding references to sequences in this alignment view
1116 public void setSelectionGroup(SequenceGroup sg)
1118 selectionGroup = sg;
1119 if (sg != null && sg.getContext() == null)
1121 sg.setContext(alignment);
1125 public void setHiddenColumns(HiddenColumns hidden)
1127 this.alignment.setHiddenColumns(hidden);
1131 public ColumnSelection getColumnSelection()
1137 public void setColumnSelection(ColumnSelection colSel)
1139 this.colSel = colSel;
1142 updateHiddenColumns();
1144 isColSelChanged(true);
1152 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1154 return hiddenRepSequences;
1158 public void setHiddenRepSequences(
1159 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1161 this.hiddenRepSequences = hiddenRepSequences;
1165 public boolean hasSelectedColumns()
1167 ColumnSelection columnSelection = getColumnSelection();
1168 return columnSelection != null && columnSelection.hasSelectedColumns();
1172 public boolean hasHiddenColumns()
1174 return alignment.getHiddenColumns() != null
1175 && alignment.getHiddenColumns().hasHiddenColumns();
1178 public void updateHiddenColumns()
1180 // this method doesn't really do anything now. But - it could, since a
1181 // column Selection could be in the process of modification
1182 // hasHiddenColumns = colSel.hasHiddenColumns();
1186 public boolean hasHiddenRows()
1188 return alignment.getHiddenSequences().getSize() > 0;
1191 protected SequenceGroup selectionGroup;
1193 public void setSequenceSetId(String newid)
1195 if (sequenceSetID != null)
1198 "Warning - overwriting a sequenceSetId for a viewport!");
1200 sequenceSetID = new String(newid);
1204 public String getSequenceSetId()
1206 if (sequenceSetID == null)
1208 sequenceSetID = alignment.hashCode() + "";
1211 return sequenceSetID;
1215 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1218 protected String viewId = null;
1221 public String getViewId()
1225 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1230 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1232 ignoreGapsInConsensusCalculation = b;
1235 updateConsensus(ap);
1236 if (residueShading != null)
1238 residueShading.setThreshold(residueShading.getThreshold(),
1239 ignoreGapsInConsensusCalculation);
1245 private long sgrouphash = -1, colselhash = -1;
1248 * checks current SelectionGroup against record of last hash value, and
1252 * update the record of last hash value
1254 * @return true if SelectionGroup changed since last call (when b is true)
1256 public boolean isSelectionGroupChanged(boolean b)
1258 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1259 : selectionGroup.hashCode();
1260 if (hc != -1 && hc != sgrouphash)
1272 * checks current colsel against record of last hash value, and optionally
1276 * update the record of last hash value
1277 * @return true if colsel changed since last call (when b is true)
1279 public boolean isColSelChanged(boolean b)
1281 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1282 if (hc != -1 && hc != colselhash)
1294 public boolean isIgnoreGapsConsensus()
1296 return ignoreGapsInConsensusCalculation;
1299 // property change stuff
1300 // JBPNote Prolly only need this in the applet version.
1301 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1304 protected boolean showConservation = true;
1306 protected boolean showQuality = true;
1308 protected boolean showConsensus = true;
1310 protected boolean showOccupancy = true;
1312 private Map<SequenceI, Color> sequenceColours = new HashMap<>();
1314 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1316 protected boolean showAutocalculatedAbove;
1319 * when set, view will scroll to show the highlighted position
1321 private boolean followHighlight = true;
1324 * Property change listener for changes in alignment
1329 public void addPropertyChangeListener(
1330 java.beans.PropertyChangeListener listener)
1332 changeSupport.addPropertyChangeListener(listener);
1341 public void removePropertyChangeListener(
1342 java.beans.PropertyChangeListener listener)
1344 if (changeSupport != null)
1346 changeSupport.removePropertyChangeListener(listener);
1351 * Property change listener for changes in alignment
1360 public void firePropertyChange(String prop, Object oldvalue,
1363 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1366 // common hide/show column stuff
1368 public void hideSelectedColumns()
1370 if (colSel.isEmpty())
1375 colSel.hideSelectedColumns(alignment);
1376 setSelectionGroup(null);
1377 isColSelChanged(true);
1380 public void hideColumns(int start, int end)
1384 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1388 alignment.getHiddenColumns().hideColumns(start, end);
1390 isColSelChanged(true);
1393 public void showColumn(int col)
1395 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1396 isColSelChanged(true);
1399 public void showAllHiddenColumns()
1401 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1402 isColSelChanged(true);
1405 // common hide/show seq stuff
1406 public void showAllHiddenSeqs()
1408 int startSeq = ranges.getStartSeq();
1409 int endSeq = ranges.getEndSeq();
1411 if (alignment.getHiddenSequences().getSize() > 0)
1413 if (selectionGroup == null)
1415 selectionGroup = new SequenceGroup();
1416 selectionGroup.setEndRes(alignment.getWidth() - 1);
1418 List<SequenceI> tmp = alignment.getHiddenSequences()
1419 .showAll(hiddenRepSequences);
1420 for (SequenceI seq : tmp)
1422 selectionGroup.addSequence(seq, false);
1423 setSequenceAnnotationsVisible(seq, true);
1426 hiddenRepSequences = null;
1428 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1430 firePropertyChange("alignment", null, alignment.getSequences());
1431 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1437 public void showSequence(int index)
1439 int startSeq = ranges.getStartSeq();
1440 int endSeq = ranges.getEndSeq();
1442 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(index,
1443 hiddenRepSequences);
1446 if (selectionGroup == null)
1448 selectionGroup = new SequenceGroup();
1449 selectionGroup.setEndRes(alignment.getWidth() - 1);
1452 for (SequenceI seq : tmp)
1454 selectionGroup.addSequence(seq, false);
1455 setSequenceAnnotationsVisible(seq, true);
1458 ranges.setStartEndSeq(startSeq, endSeq + tmp.size());
1460 firePropertyChange("alignment", null, alignment.getSequences());
1465 public void hideAllSelectedSeqs()
1467 if (selectionGroup == null || selectionGroup.getSize() < 1)
1472 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1476 setSelectionGroup(null);
1479 public void hideSequence(SequenceI[] seq)
1482 * cache offset to first visible sequence
1484 int startSeq = ranges.getStartSeq();
1488 for (int i = 0; i < seq.length; i++)
1490 alignment.getHiddenSequences().hideSequence(seq[i]);
1491 setSequenceAnnotationsVisible(seq[i], false);
1493 ranges.setStartSeq(startSeq);
1494 firePropertyChange("alignment", null, alignment.getSequences());
1499 * Hides the specified sequence, or the sequences it represents
1502 * the sequence to hide, or keep as representative
1503 * @param representGroup
1504 * if true, hide the current selection group except for the
1505 * representative sequence
1507 public void hideSequences(SequenceI sequence, boolean representGroup)
1509 if (selectionGroup == null || selectionGroup.getSize() < 1)
1511 hideSequence(new SequenceI[] { sequence });
1517 hideRepSequences(sequence, selectionGroup);
1518 setSelectionGroup(null);
1522 int gsize = selectionGroup.getSize();
1523 SequenceI[] hseqs = selectionGroup.getSequences()
1524 .toArray(new SequenceI[gsize]);
1526 hideSequence(hseqs);
1527 setSelectionGroup(null);
1532 * Set visibility for any annotations for the given sequence.
1536 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1539 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1542 for (AlignmentAnnotation ann : anns)
1544 if (ann.sequenceRef == sequenceI)
1546 ann.visible = visible;
1552 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1554 int sSize = sg.getSize();
1560 if (hiddenRepSequences == null)
1562 hiddenRepSequences = new Hashtable<>();
1565 hiddenRepSequences.put(repSequence, sg);
1567 // Hide all sequences except the repSequence
1568 SequenceI[] seqs = new SequenceI[sSize - 1];
1570 for (int i = 0; i < sSize; i++)
1572 if (sg.getSequenceAt(i) != repSequence)
1574 if (index == sSize - 1)
1579 seqs[index++] = sg.getSequenceAt(i);
1582 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1583 sg.setHidereps(true); // note: not done in 2.7applet
1590 * @return null or the current reference sequence
1592 public SequenceI getReferenceSeq()
1594 return alignment.getSeqrep();
1599 * @return true iff seq is the reference for the alignment
1601 public boolean isReferenceSeq(SequenceI seq)
1603 return alignment.getSeqrep() == seq;
1609 * @return true if there are sequences represented by this sequence that are
1612 public boolean isHiddenRepSequence(SequenceI seq)
1614 return (hiddenRepSequences != null
1615 && hiddenRepSequences.containsKey(seq));
1621 * @return null or a sequence group containing the sequences that seq
1624 public SequenceGroup getRepresentedSequences(SequenceI seq)
1626 return (SequenceGroup) (hiddenRepSequences == null ? null
1627 : hiddenRepSequences.get(seq));
1631 public int adjustForHiddenSeqs(int alignmentIndex)
1633 return alignment.getHiddenSequences()
1634 .adjustForHiddenSeqs(alignmentIndex);
1638 public void invertColumnSelection()
1640 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1644 public SequenceI[] getSelectionAsNewSequence()
1646 SequenceI[] sequences;
1647 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1648 // this was the only caller in the applet for this method
1649 // JBPNote: in applet, this method returned references to the alignment
1650 // sequences, and it did not honour the presence/absence of annotation
1651 // attached to the alignment (probably!)
1652 if (selectionGroup == null || selectionGroup.getSize() == 0)
1654 sequences = alignment.getSequencesArray();
1655 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1656 for (int i = 0; i < sequences.length; i++)
1658 // construct new sequence with subset of visible annotation
1659 sequences[i] = new Sequence(sequences[i], annots);
1664 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1671 public SequenceI[] getSequenceSelection()
1673 SequenceI[] sequences = null;
1674 if (selectionGroup != null)
1676 sequences = selectionGroup.getSequencesInOrder(alignment);
1678 if (sequences == null)
1680 sequences = alignment.getSequencesArray();
1686 public jalview.datamodel.AlignmentView getAlignmentView(
1687 boolean selectedOnly)
1689 return getAlignmentView(selectedOnly, false);
1693 public jalview.datamodel.AlignmentView getAlignmentView(
1694 boolean selectedOnly, boolean markGroups)
1696 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1698 alignment.getHiddenColumns() != null
1699 && alignment.getHiddenColumns().hasHiddenColumns(),
1700 selectedOnly, markGroups);
1704 public String[] getViewAsString(boolean selectedRegionOnly)
1706 return getViewAsString(selectedRegionOnly, true);
1710 public String[] getViewAsString(boolean selectedRegionOnly,
1711 boolean exportHiddenSeqs)
1713 String[] selection = null;
1714 SequenceI[] seqs = null;
1716 int start = 0, end = 0;
1717 if (selectedRegionOnly && selectionGroup != null)
1719 iSize = selectionGroup.getSize();
1720 seqs = selectionGroup.getSequencesInOrder(alignment);
1721 start = selectionGroup.getStartRes();
1722 end = selectionGroup.getEndRes() + 1;
1726 if (hasHiddenRows() && exportHiddenSeqs)
1728 AlignmentI fullAlignment = alignment.getHiddenSequences()
1729 .getFullAlignment();
1730 iSize = fullAlignment.getHeight();
1731 seqs = fullAlignment.getSequencesArray();
1732 end = fullAlignment.getWidth();
1736 iSize = alignment.getHeight();
1737 seqs = alignment.getSequencesArray();
1738 end = alignment.getWidth();
1742 selection = new String[iSize];
1743 if (alignment.getHiddenColumns() != null
1744 && alignment.getHiddenColumns().hasHiddenColumns())
1746 for (i = 0; i < iSize; i++)
1748 Iterator<int[]> blocks = alignment.getHiddenColumns()
1749 .getVisContigsIterator(start, end + 1, false);
1750 selection[i] = seqs[i].getSequenceStringFromIterator(blocks);
1755 for (i = 0; i < iSize; i++)
1757 selection[i] = seqs[i].getSequenceAsString(start, end);
1765 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1767 ArrayList<int[]> regions = new ArrayList<>();
1773 HiddenColumns hidden = alignment.getHiddenColumns();
1774 if (hidden != null && hidden.hasHiddenColumns())
1778 start = hidden.visibleToAbsoluteColumn(start);
1781 end = hidden.getNextHiddenBoundary(false, start);
1792 regions.add(new int[] { start, end });
1794 if (hidden != null && hidden.hasHiddenColumns())
1796 start = hidden.visibleToAbsoluteColumn(end);
1797 start = hidden.getNextHiddenBoundary(true, start) + 1;
1799 } while (end < max);
1801 int[][] startEnd = new int[regions.size()][2];
1807 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1808 boolean selectedOnly)
1810 ArrayList<AlignmentAnnotation> ala = new ArrayList<>();
1811 AlignmentAnnotation[] aa;
1812 if ((aa = alignment.getAlignmentAnnotation()) != null)
1814 for (AlignmentAnnotation annot : aa)
1816 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1817 if (selectedOnly && selectionGroup != null)
1819 clone.makeVisibleAnnotation(
1820 selectionGroup.getStartRes(), selectionGroup.getEndRes(),
1821 alignment.getHiddenColumns());
1825 clone.makeVisibleAnnotation(alignment.getHiddenColumns());
1834 public boolean isPadGaps()
1840 public void setPadGaps(boolean padGaps)
1842 this.padGaps = padGaps;
1846 * apply any post-edit constraints and trigger any calculations needed after
1847 * an edit has been performed on the alignment
1852 public void alignmentChanged(AlignmentViewPanel ap)
1856 alignment.padGaps();
1858 if (autoCalculateConsensus)
1860 updateConsensus(ap);
1862 if (hconsensus != null && autoCalculateConsensus)
1864 updateConservation(ap);
1866 if (autoCalculateStrucConsensus)
1868 updateStrucConsensus(ap);
1871 // Reset endRes of groups if beyond alignment width
1872 int alWidth = alignment.getWidth();
1873 List<SequenceGroup> groups = alignment.getGroups();
1876 for (SequenceGroup sg : groups)
1878 if (sg.getEndRes() > alWidth)
1880 sg.setEndRes(alWidth - 1);
1885 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1887 selectionGroup.setEndRes(alWidth - 1);
1890 updateAllColourSchemes();
1891 calculator.restartWorkers();
1892 // alignment.adjustSequenceAnnotations();
1896 * reset scope and do calculations for all applied colourschemes on alignment
1898 void updateAllColourSchemes()
1900 ResidueShaderI rs = residueShading;
1903 rs.alignmentChanged(alignment, hiddenRepSequences);
1905 rs.setConsensus(hconsensus);
1906 if (rs.conservationApplied())
1908 rs.setConservation(Conservation.calculateConservation("All",
1909 alignment.getSequences(), 0, alignment.getWidth(), false,
1910 getConsPercGaps(), false));
1914 for (SequenceGroup sg : alignment.getGroups())
1918 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1920 sg.recalcConservation();
1924 protected void initAutoAnnotation()
1926 // TODO: add menu option action that nulls or creates consensus object
1927 // depending on if the user wants to see the annotation or not in a
1928 // specific alignment
1930 if (hconsensus == null && !isDataset)
1932 if (!alignment.isNucleotide())
1941 consensus = new AlignmentAnnotation("Consensus",
1942 MessageManager.getString("label.consensus_descr"),
1943 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1944 initConsensus(consensus);
1947 initComplementConsensus();
1952 * If this is a protein alignment and there are mappings to cDNA, adds the
1953 * cDNA consensus annotation and returns true, else returns false.
1955 public boolean initComplementConsensus()
1957 if (!alignment.isNucleotide())
1959 final List<AlignedCodonFrame> codonMappings = alignment
1961 if (codonMappings != null && !codonMappings.isEmpty())
1963 boolean doConsensus = false;
1964 for (AlignedCodonFrame mapping : codonMappings)
1966 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1967 MapList[] mapLists = mapping.getdnaToProt();
1968 // mapLists can be empty if project load has not finished resolving
1970 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1978 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1980 .getString("label.complement_consensus_descr"),
1981 new Annotation[1], 0f, 100f,
1982 AlignmentAnnotation.BAR_GRAPH);
1983 initConsensus(complementConsensus);
1991 private void initConsensus(AlignmentAnnotation aa)
1994 aa.autoCalculated = true;
1998 alignment.addAnnotation(aa);
2002 // these should be extracted from the view model - style and settings for
2003 // derived annotation
2004 private void initGapCounts()
2008 gapcounts = new AlignmentAnnotation("Occupancy",
2009 MessageManager.getString("label.occupancy_descr"),
2010 new Annotation[1], 0f, alignment.getHeight(),
2011 AlignmentAnnotation.BAR_GRAPH);
2012 gapcounts.hasText = true;
2013 gapcounts.autoCalculated = true;
2014 gapcounts.scaleColLabel = true;
2015 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
2017 alignment.addAnnotation(gapcounts);
2021 private void initConservation()
2023 if (showConservation)
2025 if (conservation == null)
2027 conservation = new AlignmentAnnotation("Conservation",
2028 MessageManager.formatMessage("label.conservation_descr",
2030 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2031 conservation.hasText = true;
2032 conservation.autoCalculated = true;
2033 alignment.addAnnotation(conservation);
2038 private void initQuality()
2042 if (quality == null)
2044 quality = new AlignmentAnnotation("Quality",
2045 MessageManager.getString("label.quality_descr"),
2046 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2047 quality.hasText = true;
2048 quality.autoCalculated = true;
2049 alignment.addAnnotation(quality);
2054 private void initRNAStructure()
2056 if (alignment.hasRNAStructure() && strucConsensus == null)
2058 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2059 MessageManager.getString("label.strucconsensus_descr"),
2060 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2061 strucConsensus.hasText = true;
2062 strucConsensus.autoCalculated = true;
2066 alignment.addAnnotation(strucConsensus);
2074 * @see jalview.api.AlignViewportI#calcPanelHeight()
2077 public int calcPanelHeight()
2079 // setHeight of panels
2080 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2082 int charHeight = getCharHeight();
2085 BitSet graphgrp = new BitSet();
2086 for (AlignmentAnnotation aa : anns)
2090 System.err.println("Null annotation row: ignoring.");
2097 if (aa.graphGroup > -1)
2099 if (graphgrp.get(aa.graphGroup))
2105 graphgrp.set(aa.graphGroup);
2112 aa.height += charHeight;
2122 aa.height += aa.graphHeight;
2130 height += aa.height;
2142 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2143 boolean preserveNewGroupSettings)
2145 boolean updateCalcs = false;
2146 boolean conv = isShowGroupConservation();
2147 boolean cons = isShowGroupConsensus();
2148 boolean showprf = isShowSequenceLogo();
2149 boolean showConsHist = isShowConsensusHistogram();
2150 boolean normLogo = isNormaliseSequenceLogo();
2153 * TODO reorder the annotation rows according to group/sequence ordering on
2156 boolean sortg = true;
2158 // remove old automatic annotation
2159 // add any new annotation
2161 // intersect alignment annotation with alignment groups
2163 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2164 List<SequenceGroup> oldrfs = new ArrayList<>();
2167 for (int an = 0; an < aan.length; an++)
2169 if (aan[an].autoCalculated && aan[an].groupRef != null)
2171 oldrfs.add(aan[an].groupRef);
2172 alignment.deleteAnnotation(aan[an], false);
2176 if (alignment.getGroups() != null)
2178 for (SequenceGroup sg : alignment.getGroups())
2180 updateCalcs = false;
2181 if (applyGlobalSettings
2182 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2184 // set defaults for this group's conservation/consensus
2185 sg.setshowSequenceLogo(showprf);
2186 sg.setShowConsensusHistogram(showConsHist);
2187 sg.setNormaliseSequenceLogo(normLogo);
2192 alignment.addAnnotation(sg.getConservationRow(), 0);
2197 alignment.addAnnotation(sg.getConsensus(), 0);
2199 // refresh the annotation rows
2202 sg.recalcConservation();
2210 public boolean isDisplayReferenceSeq()
2212 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2216 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2218 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2222 public boolean isColourByReferenceSeq()
2224 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2228 public Color getSequenceColour(SequenceI seq)
2230 Color sqc = sequenceColours.get(seq);
2231 return (sqc == null ? Color.white : sqc);
2235 public void setSequenceColour(SequenceI seq, Color col)
2239 sequenceColours.remove(seq);
2243 sequenceColours.put(seq, col);
2248 public void updateSequenceIdColours()
2250 for (SequenceGroup sg : alignment.getGroups())
2252 if (sg.idColour != null)
2254 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2256 sequenceColours.put(s, sg.idColour);
2263 public void clearSequenceColours()
2265 sequenceColours.clear();
2269 public AlignViewportI getCodingComplement()
2271 return this.codingComplement;
2275 * Set this as the (cDna/protein) complement of the given viewport. Also
2276 * ensures the reverse relationship is set on the given viewport.
2279 public void setCodingComplement(AlignViewportI av)
2283 System.err.println("Ignoring recursive setCodingComplement request");
2287 this.codingComplement = av;
2288 // avoid infinite recursion!
2289 if (av.getCodingComplement() != this)
2291 av.setCodingComplement(this);
2297 public boolean isNucleotide()
2299 return getAlignment() == null ? false : getAlignment().isNucleotide();
2303 public FeaturesDisplayedI getFeaturesDisplayed()
2305 return featuresDisplayed;
2309 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2311 featuresDisplayed = featuresDisplayedI;
2315 public boolean areFeaturesDisplayed()
2317 return featuresDisplayed != null
2318 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2325 * features are displayed if true
2328 public void setShowSequenceFeatures(boolean b)
2330 viewStyle.setShowSequenceFeatures(b);
2334 public boolean isShowSequenceFeatures()
2336 return viewStyle.isShowSequenceFeatures();
2340 public void setShowSequenceFeaturesHeight(boolean selected)
2342 viewStyle.setShowSequenceFeaturesHeight(selected);
2346 public boolean isShowSequenceFeaturesHeight()
2348 return viewStyle.isShowSequenceFeaturesHeight();
2352 public void setShowAnnotation(boolean b)
2354 viewStyle.setShowAnnotation(b);
2358 public boolean isShowAnnotation()
2360 return viewStyle.isShowAnnotation();
2364 public boolean isRightAlignIds()
2366 return viewStyle.isRightAlignIds();
2370 public void setRightAlignIds(boolean rightAlignIds)
2372 viewStyle.setRightAlignIds(rightAlignIds);
2376 public boolean getConservationSelected()
2378 return viewStyle.getConservationSelected();
2382 public void setShowBoxes(boolean state)
2384 viewStyle.setShowBoxes(state);
2389 * @see jalview.api.ViewStyleI#getTextColour()
2392 public Color getTextColour()
2394 return viewStyle.getTextColour();
2399 * @see jalview.api.ViewStyleI#getTextColour2()
2402 public Color getTextColour2()
2404 return viewStyle.getTextColour2();
2409 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2412 public int getThresholdTextColour()
2414 return viewStyle.getThresholdTextColour();
2419 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2422 public boolean isConservationColourSelected()
2424 return viewStyle.isConservationColourSelected();
2429 * @see jalview.api.ViewStyleI#isRenderGaps()
2432 public boolean isRenderGaps()
2434 return viewStyle.isRenderGaps();
2439 * @see jalview.api.ViewStyleI#isShowColourText()
2442 public boolean isShowColourText()
2444 return viewStyle.isShowColourText();
2448 * @param conservationColourSelected
2449 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2452 public void setConservationColourSelected(
2453 boolean conservationColourSelected)
2455 viewStyle.setConservationColourSelected(conservationColourSelected);
2459 * @param showColourText
2460 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2463 public void setShowColourText(boolean showColourText)
2465 viewStyle.setShowColourText(showColourText);
2470 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2473 public void setTextColour(Color textColour)
2475 viewStyle.setTextColour(textColour);
2479 * @param thresholdTextColour
2480 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2483 public void setThresholdTextColour(int thresholdTextColour)
2485 viewStyle.setThresholdTextColour(thresholdTextColour);
2489 * @param textColour2
2490 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2493 public void setTextColour2(Color textColour2)
2495 viewStyle.setTextColour2(textColour2);
2499 public ViewStyleI getViewStyle()
2501 return new ViewStyle(viewStyle);
2505 public void setViewStyle(ViewStyleI settingsForView)
2507 viewStyle = new ViewStyle(settingsForView);
2508 if (residueShading != null)
2510 residueShading.setConservationApplied(
2511 settingsForView.isConservationColourSelected());
2516 public boolean sameStyle(ViewStyleI them)
2518 return viewStyle.sameStyle(them);
2523 * @see jalview.api.ViewStyleI#getIdWidth()
2526 public int getIdWidth()
2528 return viewStyle.getIdWidth();
2533 * @see jalview.api.ViewStyleI#setIdWidth(int)
2536 public void setIdWidth(int i)
2538 viewStyle.setIdWidth(i);
2543 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2546 public boolean isCentreColumnLabels()
2548 return viewStyle.isCentreColumnLabels();
2552 * @param centreColumnLabels
2553 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2556 public void setCentreColumnLabels(boolean centreColumnLabels)
2558 viewStyle.setCentreColumnLabels(centreColumnLabels);
2563 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2566 public void setShowDBRefs(boolean showdbrefs)
2568 viewStyle.setShowDBRefs(showdbrefs);
2573 * @see jalview.api.ViewStyleI#isShowDBRefs()
2576 public boolean isShowDBRefs()
2578 return viewStyle.isShowDBRefs();
2583 * @see jalview.api.ViewStyleI#isShowNPFeats()
2586 public boolean isShowNPFeats()
2588 return viewStyle.isShowNPFeats();
2592 * @param shownpfeats
2593 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2596 public void setShowNPFeats(boolean shownpfeats)
2598 viewStyle.setShowNPFeats(shownpfeats);
2601 public abstract StructureSelectionManager getStructureSelectionManager();
2604 * Add one command to the command history list.
2608 public void addToHistoryList(CommandI command)
2610 if (this.historyList != null)
2612 this.historyList.push(command);
2613 broadcastCommand(command, false);
2617 protected void broadcastCommand(CommandI command, boolean undo)
2619 getStructureSelectionManager().commandPerformed(command, undo,
2624 * Add one command to the command redo list.
2628 public void addToRedoList(CommandI command)
2630 if (this.redoList != null)
2632 this.redoList.push(command);
2634 broadcastCommand(command, true);
2638 * Clear the command redo list.
2640 public void clearRedoList()
2642 if (this.redoList != null)
2644 this.redoList.clear();
2648 public void setHistoryList(Deque<CommandI> list)
2650 this.historyList = list;
2653 public Deque<CommandI> getHistoryList()
2655 return this.historyList;
2658 public void setRedoList(Deque<CommandI> list)
2660 this.redoList = list;
2663 public Deque<CommandI> getRedoList()
2665 return this.redoList;
2669 public VamsasSource getVamsasSource()
2674 public SequenceAnnotationOrder getSortAnnotationsBy()
2676 return sortAnnotationsBy;
2679 public void setSortAnnotationsBy(
2680 SequenceAnnotationOrder sortAnnotationsBy)
2682 this.sortAnnotationsBy = sortAnnotationsBy;
2685 public boolean isShowAutocalculatedAbove()
2687 return showAutocalculatedAbove;
2690 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2692 this.showAutocalculatedAbove = showAutocalculatedAbove;
2696 public boolean isScaleProteinAsCdna()
2698 return viewStyle.isScaleProteinAsCdna();
2702 public void setScaleProteinAsCdna(boolean b)
2704 viewStyle.setScaleProteinAsCdna(b);
2708 public boolean isProteinFontAsCdna()
2710 return viewStyle.isProteinFontAsCdna();
2714 public void setProteinFontAsCdna(boolean b)
2716 viewStyle.setProteinFontAsCdna(b);
2720 * @return true if view should scroll to show the highlighted region of a
2725 public final boolean isFollowHighlight()
2727 return followHighlight;
2731 public final void setFollowHighlight(boolean b)
2733 this.followHighlight = b;
2737 public ViewportRanges getRanges()
2743 * Helper method to populate the SearchResults with the location in the
2744 * complementary alignment to scroll to, in order to match this one.
2747 * the SearchResults to add to
2748 * @return the offset (below top of visible region) of the matched sequence
2750 protected int findComplementScrollTarget(SearchResultsI sr)
2752 final AlignViewportI complement = getCodingComplement();
2753 if (complement == null || !complement.isFollowHighlight())
2757 boolean iAmProtein = !getAlignment().isNucleotide();
2758 AlignmentI proteinAlignment = iAmProtein ? getAlignment()
2759 : complement.getAlignment();
2760 if (proteinAlignment == null)
2764 final List<AlignedCodonFrame> mappings = proteinAlignment
2768 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2769 * residue in the middle column of the visible region. Scroll the
2770 * complementary alignment to line up the corresponding residue.
2773 SequenceI sequence = null;
2776 * locate 'middle' column (true middle if an odd number visible, left of
2777 * middle if an even number visible)
2779 int middleColumn = ranges.getStartRes()
2780 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2781 final HiddenSequences hiddenSequences = getAlignment()
2782 .getHiddenSequences();
2785 * searching to the bottom of the alignment gives smoother scrolling across
2786 * all gapped visible regions
2788 int lastSeq = alignment.getHeight() - 1;
2789 List<AlignedCodonFrame> seqMappings = null;
2790 for (int seqNo = ranges
2791 .getStartSeq(); seqNo <= lastSeq; seqNo++, seqOffset++)
2793 sequence = getAlignment().getSequenceAt(seqNo);
2794 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2798 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2802 seqMappings = MappingUtils.findMappingsForSequenceAndOthers(sequence,
2804 getCodingComplement().getAlignment().getSequences());
2805 if (!seqMappings.isEmpty())
2811 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2814 * No ungapped mapped sequence in middle column - do nothing
2818 MappingUtils.addSearchResults(sr, sequence,
2819 sequence.findPosition(middleColumn), seqMappings);
2824 * synthesize a column selection if none exists so it covers the given
2825 * selection group. if wholewidth is false, no column selection is made if the
2826 * selection group covers the whole alignment width.
2831 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2834 if (sg != null && (sgs = sg.getStartRes()) >= 0
2835 && sg.getStartRes() <= (sge = sg.getEndRes())
2836 && !this.hasSelectedColumns())
2838 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2845 colSel = new ColumnSelection();
2847 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2849 colSel.addElement(cspos);
2855 * hold status of current selection group - defined on alignment or not.
2857 private boolean selectionIsDefinedGroup = false;
2860 public boolean isSelectionDefinedGroup()
2862 if (selectionGroup == null)
2866 if (isSelectionGroupChanged(true))
2868 selectionIsDefinedGroup = false;
2869 List<SequenceGroup> gps = alignment.getGroups();
2870 if (gps == null || gps.size() == 0)
2872 selectionIsDefinedGroup = false;
2876 selectionIsDefinedGroup = gps.contains(selectionGroup);
2879 return selectionGroup.isDefined() || selectionIsDefinedGroup;
2883 * null, or currently highlighted results on this view
2885 private SearchResultsI searchResults = null;
2887 protected TreeModel currentTree = null;
2890 public boolean hasSearchResults()
2892 return searchResults != null;
2896 public void setSearchResults(SearchResultsI results)
2898 searchResults = results;
2902 public SearchResultsI getSearchResults()
2904 return searchResults;
2908 * get the consensus sequence as displayed under the PID consensus annotation
2911 * @return consensus sequence as a new sequence object
2913 public SequenceI getConsensusSeq()
2915 if (consensus == null)
2917 updateConsensus(null);
2919 if (consensus == null)
2923 StringBuffer seqs = new StringBuffer();
2924 for (int i = 0; i < consensus.annotations.length; i++)
2926 Annotation annotation = consensus.annotations[i];
2927 if (annotation != null)
2929 String description = annotation.description;
2930 if (description != null && description.startsWith("["))
2932 // consensus is a tie - just pick the first one
2933 seqs.append(description.charAt(1));
2937 seqs.append(annotation.displayCharacter);
2942 SequenceI sq = new Sequence("Consensus", seqs.toString());
2943 sq.setDescription("Percentage Identity Consensus "
2944 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
2949 public void setCurrentTree(TreeModel tree)
2955 public TreeModel getCurrentTree()
2961 public AlignmentExportData getAlignExportData(AlignExportSettingsI options)
2963 AlignmentI alignmentToExport = null;
2964 String[] omitHidden = null;
2965 alignmentToExport = null;
2967 if (hasHiddenColumns() && !options.isExportHiddenColumns())
2969 omitHidden = getViewAsString(false,
2970 options.isExportHiddenSequences());
2973 int[] alignmentStartEnd = new int[2];
2974 if (hasHiddenRows() && options.isExportHiddenSequences())
2976 alignmentToExport = getAlignment().getHiddenSequences()
2977 .getFullAlignment();
2981 alignmentToExport = getAlignment();
2983 alignmentStartEnd = getAlignment().getHiddenColumns()
2984 .getVisibleStartAndEndIndex(alignmentToExport.getWidth());
2985 AlignmentExportData ed = new AlignmentExportData(alignmentToExport,
2986 omitHidden, alignmentStartEnd);