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.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenColumns;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.renderer.ResidueShader;
47 import jalview.renderer.ResidueShaderI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.util.MessageManager;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.StrucConsensusThread;
62 import java.awt.Color;
63 import java.beans.PropertyChangeSupport;
64 import java.util.ArrayDeque;
65 import java.util.ArrayList;
66 import java.util.BitSet;
67 import java.util.Deque;
68 import java.util.HashMap;
69 import java.util.Hashtable;
70 import java.util.List;
74 * base class holding visualization and analysis attributes and common logic for
75 * an active alignment view displayed in the GUI
80 public abstract class AlignmentViewport implements AlignViewportI,
81 CommandListener, VamsasSource
83 protected ViewportRanges ranges;
85 protected ViewStyleI viewStyle = new ViewStyle();
88 * A viewport that hosts the cDna view of this (protein), or vice versa (if
91 AlignViewportI codingComplement = null;
93 FeaturesDisplayedI featuresDisplayed = null;
95 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
97 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
101 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
104 public void setFontName(String name)
106 viewStyle.setFontName(name);
111 * @see jalview.api.ViewStyleI#setFontStyle(int)
114 public void setFontStyle(int style)
116 viewStyle.setFontStyle(style);
121 * @see jalview.api.ViewStyleI#setFontSize(int)
124 public void setFontSize(int size)
126 viewStyle.setFontSize(size);
131 * @see jalview.api.ViewStyleI#getFontStyle()
134 public int getFontStyle()
136 return viewStyle.getFontStyle();
141 * @see jalview.api.ViewStyleI#getFontName()
144 public String getFontName()
146 return viewStyle.getFontName();
151 * @see jalview.api.ViewStyleI#getFontSize()
154 public int getFontSize()
156 return viewStyle.getFontSize();
160 * @param upperCasebold
161 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
164 public void setUpperCasebold(boolean upperCasebold)
166 viewStyle.setUpperCasebold(upperCasebold);
171 * @see jalview.api.ViewStyleI#isUpperCasebold()
174 public boolean isUpperCasebold()
176 return viewStyle.isUpperCasebold();
181 * @see jalview.api.ViewStyleI#isSeqNameItalics()
184 public boolean isSeqNameItalics()
186 return viewStyle.isSeqNameItalics();
190 * @param colourByReferenceSeq
191 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
194 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
196 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
201 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
204 public void setColourAppliesToAllGroups(boolean b)
206 viewStyle.setColourAppliesToAllGroups(b);
211 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
214 public boolean getColourAppliesToAllGroups()
216 return viewStyle.getColourAppliesToAllGroups();
221 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
224 public boolean getAbovePIDThreshold()
226 return viewStyle.getAbovePIDThreshold();
231 * @see jalview.api.ViewStyleI#setIncrement(int)
234 public void setIncrement(int inc)
236 viewStyle.setIncrement(inc);
241 * @see jalview.api.ViewStyleI#getIncrement()
244 public int getIncrement()
246 return viewStyle.getIncrement();
251 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
254 public void setConservationSelected(boolean b)
256 viewStyle.setConservationSelected(b);
261 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
264 public void setShowHiddenMarkers(boolean show)
266 viewStyle.setShowHiddenMarkers(show);
271 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
274 public boolean getShowHiddenMarkers()
276 return viewStyle.getShowHiddenMarkers();
281 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
284 public void setScaleRightWrapped(boolean b)
286 viewStyle.setScaleRightWrapped(b);
291 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
294 public void setScaleLeftWrapped(boolean b)
296 viewStyle.setScaleLeftWrapped(b);
301 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
304 public void setScaleAboveWrapped(boolean b)
306 viewStyle.setScaleAboveWrapped(b);
311 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
314 public boolean getScaleLeftWrapped()
316 return viewStyle.getScaleLeftWrapped();
321 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
324 public boolean getScaleAboveWrapped()
326 return viewStyle.getScaleAboveWrapped();
331 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
334 public boolean getScaleRightWrapped()
336 return viewStyle.getScaleRightWrapped();
341 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
344 public void setAbovePIDThreshold(boolean b)
346 viewStyle.setAbovePIDThreshold(b);
351 * @see jalview.api.ViewStyleI#setThreshold(int)
354 public void setThreshold(int thresh)
356 viewStyle.setThreshold(thresh);
361 * @see jalview.api.ViewStyleI#getThreshold()
364 public int getThreshold()
366 return viewStyle.getThreshold();
371 * @see jalview.api.ViewStyleI#getShowJVSuffix()
374 public boolean getShowJVSuffix()
376 return viewStyle.getShowJVSuffix();
381 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
384 public void setShowJVSuffix(boolean b)
386 viewStyle.setShowJVSuffix(b);
391 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
394 public void setWrapAlignment(boolean state)
396 viewStyle.setWrapAlignment(state);
401 * @see jalview.api.ViewStyleI#setShowText(boolean)
404 public void setShowText(boolean state)
406 viewStyle.setShowText(state);
411 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
414 public void setRenderGaps(boolean state)
416 viewStyle.setRenderGaps(state);
421 * @see jalview.api.ViewStyleI#getColourText()
424 public boolean getColourText()
426 return viewStyle.getColourText();
431 * @see jalview.api.ViewStyleI#setColourText(boolean)
434 public void setColourText(boolean state)
436 viewStyle.setColourText(state);
441 * @see jalview.api.ViewStyleI#getWrapAlignment()
444 public boolean getWrapAlignment()
446 return viewStyle.getWrapAlignment();
451 * @see jalview.api.ViewStyleI#getShowText()
454 public boolean getShowText()
456 return viewStyle.getShowText();
461 * @see jalview.api.ViewStyleI#getWrappedWidth()
464 public int getWrappedWidth()
466 return viewStyle.getWrappedWidth();
471 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
474 public void setWrappedWidth(int w)
476 viewStyle.setWrappedWidth(w);
481 * @see jalview.api.ViewStyleI#getCharHeight()
484 public int getCharHeight()
486 return viewStyle.getCharHeight();
491 * @see jalview.api.ViewStyleI#setCharHeight(int)
494 public void setCharHeight(int h)
496 viewStyle.setCharHeight(h);
501 * @see jalview.api.ViewStyleI#getCharWidth()
504 public int getCharWidth()
506 return viewStyle.getCharWidth();
511 * @see jalview.api.ViewStyleI#setCharWidth(int)
514 public void setCharWidth(int w)
516 viewStyle.setCharWidth(w);
521 * @see jalview.api.ViewStyleI#getShowBoxes()
524 public boolean getShowBoxes()
526 return viewStyle.getShowBoxes();
531 * @see jalview.api.ViewStyleI#getShowUnconserved()
534 public boolean getShowUnconserved()
536 return viewStyle.getShowUnconserved();
540 * @param showunconserved
541 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
544 public void setShowUnconserved(boolean showunconserved)
546 viewStyle.setShowUnconserved(showunconserved);
551 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
554 public void setSeqNameItalics(boolean default1)
556 viewStyle.setSeqNameItalics(default1);
560 * alignment displayed in the viewport. Please use get/setter
562 protected AlignmentI alignment;
565 public AlignmentI getAlignment()
571 public char getGapCharacter()
573 return alignment.getGapCharacter();
576 protected String sequenceSetID;
579 * probably unused indicator that view is of a dataset rather than an
582 protected boolean isDataset = false;
584 public void setDataset(boolean b)
589 public boolean isDataset()
594 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
596 protected ColumnSelection colSel = new ColumnSelection();
598 public boolean autoCalculateConsensus = true;
600 protected boolean autoCalculateStrucConsensus = true;
602 protected boolean ignoreGapsInConsensusCalculation = false;
604 protected ResidueShaderI residueShading;
607 public void setGlobalColourScheme(ColourSchemeI cs)
609 // TODO: logic refactored from AlignFrame changeColour -
610 // TODO: autorecalc stuff should be changed to rely on the worker system
611 // check to see if we should implement a changeColour(cs) method rather than
612 // put the logic in here
613 // - means that caller decides if they want to just modify state and defer
614 // calculation till later or to do all calculations in thread.
618 * only instantiate alignment colouring once, thereafter update it;
619 * this means that any conservation or PID threshold settings
620 * persist when the alignment colour scheme is changed
622 if (residueShading == null)
624 residueShading = new ResidueShader(viewStyle);
626 residueShading.setColourScheme(cs);
628 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
629 // ...problem: groups need these, but do not currently have a ViewStyle
633 if (getConservationSelected())
635 residueShading.setConservation(hconservation);
637 residueShading.alignmentChanged(alignment, hiddenRepSequences);
641 * if 'apply colour to all groups' is selected... do so
642 * (but don't transfer any colour threshold settings to groups)
644 if (getColourAppliesToAllGroups())
646 for (SequenceGroup sg : getAlignment().getGroups())
649 * retain any colour thresholds per group while
650 * changing choice of colour scheme (JAL-2386)
652 sg.setColourScheme(cs);
655 sg.getGroupColourScheme()
656 .alignmentChanged(sg, hiddenRepSequences);
663 public ColourSchemeI getGlobalColourScheme()
665 return residueShading == null ? null : residueShading
670 public ResidueShaderI getResidueShading()
672 return residueShading;
675 protected AlignmentAnnotation consensus;
677 protected AlignmentAnnotation complementConsensus;
679 protected AlignmentAnnotation gapcounts;
681 protected AlignmentAnnotation strucConsensus;
683 protected AlignmentAnnotation conservation;
685 protected AlignmentAnnotation quality;
687 protected AlignmentAnnotation[] groupConsensus;
689 protected AlignmentAnnotation[] groupConservation;
692 * results of alignment consensus analysis for visible portion of view
694 protected ProfilesI hconsensus = null;
697 * results of cDNA complement consensus visible portion of view
699 protected Hashtable[] hcomplementConsensus = null;
702 * results of secondary structure base pair consensus for visible portion of
705 protected Hashtable[] hStrucConsensus = null;
707 protected Conservation hconservation = null;
710 public void setConservation(Conservation cons)
712 hconservation = cons;
716 * percentage gaps allowed in a column before all amino acid properties should
717 * be considered unconserved
719 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
722 public int getConsPercGaps()
728 public void setSequenceConsensusHash(ProfilesI hconsensus)
730 this.hconsensus = hconsensus;
734 public void setComplementConsensusHash(Hashtable[] hconsensus)
736 this.hcomplementConsensus = hconsensus;
740 public ProfilesI getSequenceConsensusHash()
746 public Hashtable[] getComplementConsensusHash()
748 return hcomplementConsensus;
752 public Hashtable[] getRnaStructureConsensusHash()
754 return hStrucConsensus;
758 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
760 this.hStrucConsensus = hStrucConsensus;
765 public AlignmentAnnotation getAlignmentQualityAnnot()
771 public AlignmentAnnotation getAlignmentConservationAnnotation()
777 public AlignmentAnnotation getAlignmentConsensusAnnotation()
783 public AlignmentAnnotation getAlignmentGapAnnotation()
789 public AlignmentAnnotation getComplementConsensusAnnotation()
791 return complementConsensus;
795 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
797 return strucConsensus;
800 protected AlignCalcManagerI calculator = new AlignCalcManager();
803 * trigger update of conservation annotation
805 public void updateConservation(final AlignmentViewPanel ap)
807 // see note in mantis : issue number 8585
808 if (alignment.isNucleotide()
809 || (conservation == null && quality == null)
810 || !autoCalculateConsensus)
815 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
817 calculator.registerWorker(new jalview.workers.ConservationThread(
823 * trigger update of consensus annotation
825 public void updateConsensus(final AlignmentViewPanel ap)
827 // see note in mantis : issue number 8585
828 if (consensus == null || !autoCalculateConsensus)
832 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
834 calculator.registerWorker(new ConsensusThread(this, ap));
838 * A separate thread to compute cDNA consensus for a protein alignment
839 * which has mapping to cDNA
841 final AlignmentI al = this.getAlignment();
842 if (!al.isNucleotide() && al.getCodonFrames() != null
843 && !al.getCodonFrames().isEmpty())
846 * fudge - check first for protein-to-nucleotide mappings
847 * (we don't want to do this for protein-to-protein)
849 boolean doConsensus = false;
850 for (AlignedCodonFrame mapping : al.getCodonFrames())
852 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
853 MapList[] mapLists = mapping.getdnaToProt();
854 // mapLists can be empty if project load has not finished resolving seqs
855 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
864 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
867 .registerWorker(new ComplementConsensusThread(this, ap));
873 // --------START Structure Conservation
874 public void updateStrucConsensus(final AlignmentViewPanel ap)
876 if (autoCalculateStrucConsensus && strucConsensus == null
877 && alignment.isNucleotide() && alignment.hasRNAStructure())
879 // secondary structure has been added - so init the consensus line
883 // see note in mantis : issue number 8585
884 if (strucConsensus == null || !autoCalculateStrucConsensus)
888 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
890 calculator.registerWorker(new StrucConsensusThread(this, ap));
894 public boolean isCalcInProgress()
896 return calculator.isWorking();
900 public boolean isCalculationInProgress(
901 AlignmentAnnotation alignmentAnnotation)
903 if (!alignmentAnnotation.autoCalculated)
907 if (calculator.workingInvolvedWith(alignmentAnnotation))
909 // System.err.println("grey out ("+alignmentAnnotation.label+")");
915 public void setAlignment(AlignmentI align)
917 this.alignment = align;
921 * Clean up references when this viewport is closed
924 public void dispose()
927 * defensively null out references to large objects in case
928 * this object is not garbage collected (as if!)
931 complementConsensus = null;
932 strucConsensus = null;
935 groupConsensus = null;
936 groupConservation = null;
938 hcomplementConsensus = null;
939 // colour scheme may hold reference to consensus
940 residueShading = null;
941 // TODO remove listeners from changeSupport?
942 changeSupport = null;
947 public boolean isClosed()
949 // TODO: check that this isClosed is only true after panel is closed, not
950 // before it is fully constructed.
951 return alignment == null;
955 public AlignCalcManagerI getCalcManager()
961 * should conservation rows be shown for groups
963 protected boolean showGroupConservation = false;
966 * should consensus rows be shown for groups
968 protected boolean showGroupConsensus = false;
971 * should consensus profile be rendered by default
973 protected boolean showSequenceLogo = false;
976 * should consensus profile be rendered normalised to row height
978 protected boolean normaliseSequenceLogo = false;
981 * should consensus histograms be rendered by default
983 protected boolean showConsensusHistogram = true;
986 * @return the showConsensusProfile
989 public boolean isShowSequenceLogo()
991 return showSequenceLogo;
995 * @param showSequenceLogo
998 public void setShowSequenceLogo(boolean showSequenceLogo)
1000 if (showSequenceLogo != this.showSequenceLogo)
1002 // TODO: decouple settings setting from calculation when refactoring
1003 // annotation update method from alignframe to viewport
1004 this.showSequenceLogo = showSequenceLogo;
1005 calculator.updateAnnotationFor(ConsensusThread.class);
1006 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1007 calculator.updateAnnotationFor(StrucConsensusThread.class);
1009 this.showSequenceLogo = showSequenceLogo;
1013 * @param showConsensusHistogram
1014 * the showConsensusHistogram to set
1016 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1018 this.showConsensusHistogram = showConsensusHistogram;
1022 * @return the showGroupConservation
1024 public boolean isShowGroupConservation()
1026 return showGroupConservation;
1030 * @param showGroupConservation
1031 * the showGroupConservation to set
1033 public void setShowGroupConservation(boolean showGroupConservation)
1035 this.showGroupConservation = showGroupConservation;
1039 * @return the showGroupConsensus
1041 public boolean isShowGroupConsensus()
1043 return showGroupConsensus;
1047 * @param showGroupConsensus
1048 * the showGroupConsensus to set
1050 public void setShowGroupConsensus(boolean showGroupConsensus)
1052 this.showGroupConsensus = showGroupConsensus;
1057 * @return flag to indicate if the consensus histogram should be rendered by
1061 public boolean isShowConsensusHistogram()
1063 return this.showConsensusHistogram;
1067 * when set, updateAlignment will always ensure sequences are of equal length
1069 private boolean padGaps = false;
1072 * when set, alignment should be reordered according to a newly opened tree
1074 public boolean sortByTree = false;
1079 * @return null or the currently selected sequence region
1082 public SequenceGroup getSelectionGroup()
1084 return selectionGroup;
1088 * Set the selection group for this window. Also sets the current alignment as
1089 * the context for the group, if it does not already have one.
1092 * - group holding references to sequences in this alignment view
1096 public void setSelectionGroup(SequenceGroup sg)
1098 selectionGroup = sg;
1099 if (sg != null && sg.getContext() == null)
1101 sg.setContext(alignment);
1105 public void setHiddenColumns(HiddenColumns hidden)
1107 this.alignment.setHiddenColumns(hidden);
1108 // this.colSel = colsel;
1112 public ColumnSelection getColumnSelection()
1118 public void setColumnSelection(ColumnSelection colSel)
1120 this.colSel = colSel;
1123 updateHiddenColumns();
1125 isColSelChanged(true);
1133 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1135 return hiddenRepSequences;
1139 public void setHiddenRepSequences(
1140 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1142 this.hiddenRepSequences = hiddenRepSequences;
1146 public boolean hasSelectedColumns()
1148 ColumnSelection columnSelection = getColumnSelection();
1149 return columnSelection != null && columnSelection.hasSelectedColumns();
1153 public boolean hasHiddenColumns()
1155 return colSel != null
1156 && alignment.getHiddenColumns().hasHiddenColumns();
1159 public void updateHiddenColumns()
1161 // this method doesn't really do anything now. But - it could, since a
1162 // column Selection could be in the process of modification
1163 // hasHiddenColumns = colSel.hasHiddenColumns();
1167 public boolean hasHiddenRows()
1169 return alignment.getHiddenSequences().getSize() > 0;
1172 protected SequenceGroup selectionGroup;
1174 public void setSequenceSetId(String newid)
1176 if (sequenceSetID != null)
1179 .println("Warning - overwriting a sequenceSetId for a viewport!");
1181 sequenceSetID = new String(newid);
1185 public String getSequenceSetId()
1187 if (sequenceSetID == null)
1189 sequenceSetID = alignment.hashCode() + "";
1192 return sequenceSetID;
1196 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1199 protected String viewId = null;
1202 public String getViewId()
1206 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1211 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1213 ignoreGapsInConsensusCalculation = b;
1216 updateConsensus(ap);
1217 if (residueShading != null)
1219 residueShading.setThreshold(residueShading.getThreshold(),
1220 ignoreGapsInConsensusCalculation);
1226 private long sgrouphash = -1, colselhash = -1;
1229 * checks current SelectionGroup against record of last hash value, and
1233 * update the record of last hash value
1235 * @return true if SelectionGroup changed since last call (when b is true)
1237 public boolean isSelectionGroupChanged(boolean b)
1239 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1240 : selectionGroup.hashCode();
1241 if (hc != -1 && hc != sgrouphash)
1253 * checks current colsel against record of last hash value, and optionally
1257 * update the record of last hash value
1258 * @return true if colsel changed since last call (when b is true)
1260 public boolean isColSelChanged(boolean b)
1262 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1263 if (hc != -1 && hc != colselhash)
1275 public boolean isIgnoreGapsConsensus()
1277 return ignoreGapsInConsensusCalculation;
1280 // property change stuff
1281 // JBPNote Prolly only need this in the applet version.
1282 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1285 protected boolean showConservation = true;
1287 protected boolean showQuality = true;
1289 protected boolean showConsensus = true;
1291 protected boolean showOccupancy = true;
1293 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1295 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1297 protected boolean showAutocalculatedAbove;
1300 * when set, view will scroll to show the highlighted position
1302 private boolean followHighlight = true;
1305 * Property change listener for changes in alignment
1310 public void addPropertyChangeListener(
1311 java.beans.PropertyChangeListener listener)
1313 changeSupport.addPropertyChangeListener(listener);
1322 public void removePropertyChangeListener(
1323 java.beans.PropertyChangeListener listener)
1325 changeSupport.removePropertyChangeListener(listener);
1329 * Property change listener for changes in alignment
1338 public void firePropertyChange(String prop, Object oldvalue,
1341 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1344 // common hide/show column stuff
1346 public void hideSelectedColumns()
1348 if (colSel.isEmpty())
1353 colSel.hideSelectedColumns(alignment);
1354 setSelectionGroup(null);
1355 isColSelChanged(true);
1358 public void hideColumns(int start, int end)
1362 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1366 alignment.getHiddenColumns().hideColumns(start, end);
1368 isColSelChanged(true);
1371 public void showColumn(int col)
1373 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1374 isColSelChanged(true);
1377 public void showAllHiddenColumns()
1379 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1380 isColSelChanged(true);
1383 // common hide/show seq stuff
1384 public void showAllHiddenSeqs()
1386 if (alignment.getHiddenSequences().getSize() > 0)
1388 if (selectionGroup == null)
1390 selectionGroup = new SequenceGroup();
1391 selectionGroup.setEndRes(alignment.getWidth() - 1);
1393 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1394 hiddenRepSequences);
1395 for (SequenceI seq : tmp)
1397 selectionGroup.addSequence(seq, false);
1398 setSequenceAnnotationsVisible(seq, true);
1401 hiddenRepSequences = null;
1403 firePropertyChange("alignment", null, alignment.getSequences());
1404 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1410 public void showSequence(int index)
1412 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1413 index, hiddenRepSequences);
1416 if (selectionGroup == null)
1418 selectionGroup = new SequenceGroup();
1419 selectionGroup.setEndRes(alignment.getWidth() - 1);
1422 for (SequenceI seq : tmp)
1424 selectionGroup.addSequence(seq, false);
1425 setSequenceAnnotationsVisible(seq, true);
1427 firePropertyChange("alignment", null, alignment.getSequences());
1432 public void hideAllSelectedSeqs()
1434 if (selectionGroup == null || selectionGroup.getSize() < 1)
1439 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1443 setSelectionGroup(null);
1446 public void hideSequence(SequenceI[] seq)
1450 for (int i = 0; i < seq.length; i++)
1452 alignment.getHiddenSequences().hideSequence(seq[i]);
1453 setSequenceAnnotationsVisible(seq[i], false);
1455 firePropertyChange("alignment", null, alignment.getSequences());
1460 * Hides the specified sequence, or the sequences it represents
1463 * the sequence to hide, or keep as representative
1464 * @param representGroup
1465 * if true, hide the current selection group except for the
1466 * representative sequence
1468 public void hideSequences(SequenceI sequence, boolean representGroup)
1470 if (selectionGroup == null || selectionGroup.getSize() < 1)
1472 hideSequence(new SequenceI[] { sequence });
1478 hideRepSequences(sequence, selectionGroup);
1479 setSelectionGroup(null);
1483 int gsize = selectionGroup.getSize();
1484 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1485 new SequenceI[gsize]);
1487 hideSequence(hseqs);
1488 setSelectionGroup(null);
1493 * Set visibility for any annotations for the given sequence.
1497 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1500 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1503 for (AlignmentAnnotation ann : anns)
1505 if (ann.sequenceRef == sequenceI)
1507 ann.visible = visible;
1513 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1515 int sSize = sg.getSize();
1521 if (hiddenRepSequences == null)
1523 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1526 hiddenRepSequences.put(repSequence, sg);
1528 // Hide all sequences except the repSequence
1529 SequenceI[] seqs = new SequenceI[sSize - 1];
1531 for (int i = 0; i < sSize; i++)
1533 if (sg.getSequenceAt(i) != repSequence)
1535 if (index == sSize - 1)
1540 seqs[index++] = sg.getSequenceAt(i);
1543 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1544 sg.setHidereps(true); // note: not done in 2.7applet
1551 * @return null or the current reference sequence
1553 public SequenceI getReferenceSeq()
1555 return alignment.getSeqrep();
1560 * @return true iff seq is the reference for the alignment
1562 public boolean isReferenceSeq(SequenceI seq)
1564 return alignment.getSeqrep() == seq;
1570 * @return true if there are sequences represented by this sequence that are
1573 public boolean isHiddenRepSequence(SequenceI seq)
1575 return (hiddenRepSequences != null && hiddenRepSequences
1582 * @return null or a sequence group containing the sequences that seq
1585 public SequenceGroup getRepresentedSequences(SequenceI seq)
1587 return (SequenceGroup) (hiddenRepSequences == null ? null
1588 : hiddenRepSequences.get(seq));
1592 public int adjustForHiddenSeqs(int alignmentIndex)
1594 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1599 public void invertColumnSelection()
1601 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1605 public SequenceI[] getSelectionAsNewSequence()
1607 SequenceI[] sequences;
1608 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1609 // this was the only caller in the applet for this method
1610 // JBPNote: in applet, this method returned references to the alignment
1611 // sequences, and it did not honour the presence/absence of annotation
1612 // attached to the alignment (probably!)
1613 if (selectionGroup == null || selectionGroup.getSize() == 0)
1615 sequences = alignment.getSequencesArray();
1616 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1617 for (int i = 0; i < sequences.length; i++)
1619 // construct new sequence with subset of visible annotation
1620 sequences[i] = new Sequence(sequences[i], annots);
1625 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1632 public SequenceI[] getSequenceSelection()
1634 SequenceI[] sequences = null;
1635 if (selectionGroup != null)
1637 sequences = selectionGroup.getSequencesInOrder(alignment);
1639 if (sequences == null)
1641 sequences = alignment.getSequencesArray();
1647 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1649 return new CigarArray(alignment, alignment.getHiddenColumns(),
1650 (selectedRegionOnly ? selectionGroup : null));
1654 public jalview.datamodel.AlignmentView getAlignmentView(
1655 boolean selectedOnly)
1657 return getAlignmentView(selectedOnly, false);
1661 public jalview.datamodel.AlignmentView getAlignmentView(
1662 boolean selectedOnly, boolean markGroups)
1664 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1665 selectionGroup, alignment.getHiddenColumns() != null
1666 && alignment.getHiddenColumns().hasHiddenColumns(),
1672 public String[] getViewAsString(boolean selectedRegionOnly)
1674 return getViewAsString(selectedRegionOnly, true);
1678 public String[] getViewAsString(boolean selectedRegionOnly,
1679 boolean exportHiddenSeqs)
1681 String[] selection = null;
1682 SequenceI[] seqs = null;
1684 int start = 0, end = 0;
1685 if (selectedRegionOnly && selectionGroup != null)
1687 iSize = selectionGroup.getSize();
1688 seqs = selectionGroup.getSequencesInOrder(alignment);
1689 start = selectionGroup.getStartRes();
1690 end = selectionGroup.getEndRes() + 1;
1694 if (hasHiddenRows() && exportHiddenSeqs)
1696 AlignmentI fullAlignment = alignment.getHiddenSequences()
1697 .getFullAlignment();
1698 iSize = fullAlignment.getHeight();
1699 seqs = fullAlignment.getSequencesArray();
1700 end = fullAlignment.getWidth();
1704 iSize = alignment.getHeight();
1705 seqs = alignment.getSequencesArray();
1706 end = alignment.getWidth();
1710 selection = new String[iSize];
1711 if (alignment.getHiddenColumns() != null
1712 && alignment.getHiddenColumns().hasHiddenColumns())
1714 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1719 for (i = 0; i < iSize; i++)
1721 selection[i] = seqs[i].getSequenceAsString(start, end);
1729 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1731 ArrayList<int[]> regions = new ArrayList<int[]>();
1737 HiddenColumns hidden = alignment.getHiddenColumns();
1738 if (hidden != null && hidden.hasHiddenColumns())
1742 start = hidden.adjustForHiddenColumns(start);
1745 end = hidden.getHiddenBoundaryRight(start);
1756 regions.add(new int[] { start, end });
1758 if (hidden != null && hidden.hasHiddenColumns())
1760 start = hidden.adjustForHiddenColumns(end);
1761 start = hidden.getHiddenBoundaryLeft(start) + 1;
1763 } while (end < max);
1765 int[][] startEnd = new int[regions.size()][2];
1771 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1772 boolean selectedOnly)
1774 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1775 AlignmentAnnotation[] aa;
1776 if ((aa = alignment.getAlignmentAnnotation()) != null)
1778 for (AlignmentAnnotation annot : aa)
1780 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1781 if (selectedOnly && selectionGroup != null)
1783 alignment.getHiddenColumns().makeVisibleAnnotation(
1784 selectionGroup.getStartRes(),
1785 selectionGroup.getEndRes(), clone);
1789 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1798 public boolean isPadGaps()
1804 public void setPadGaps(boolean padGaps)
1806 this.padGaps = padGaps;
1810 * apply any post-edit constraints and trigger any calculations needed after
1811 * an edit has been performed on the alignment
1816 public void alignmentChanged(AlignmentViewPanel ap)
1820 alignment.padGaps();
1822 if (autoCalculateConsensus)
1824 updateConsensus(ap);
1826 if (hconsensus != null && autoCalculateConsensus)
1828 updateConservation(ap);
1830 if (autoCalculateStrucConsensus)
1832 updateStrucConsensus(ap);
1835 // Reset endRes of groups if beyond alignment width
1836 int alWidth = alignment.getWidth();
1837 List<SequenceGroup> groups = alignment.getGroups();
1840 for (SequenceGroup sg : groups)
1842 if (sg.getEndRes() > alWidth)
1844 sg.setEndRes(alWidth - 1);
1849 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1851 selectionGroup.setEndRes(alWidth - 1);
1854 updateAllColourSchemes();
1855 calculator.restartWorkers();
1856 // alignment.adjustSequenceAnnotations();
1860 * reset scope and do calculations for all applied colourschemes on alignment
1862 void updateAllColourSchemes()
1864 ResidueShaderI rs = residueShading;
1867 rs.alignmentChanged(alignment, hiddenRepSequences);
1869 rs.setConsensus(hconsensus);
1870 if (rs.conservationApplied())
1872 rs.setConservation(Conservation.calculateConservation("All",
1873 alignment.getSequences(), 0, alignment.getWidth(), false,
1874 getConsPercGaps(), false));
1878 for (SequenceGroup sg : alignment.getGroups())
1882 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1884 sg.recalcConservation();
1888 protected void initAutoAnnotation()
1890 // TODO: add menu option action that nulls or creates consensus object
1891 // depending on if the user wants to see the annotation or not in a
1892 // specific alignment
1894 if (hconsensus == null && !isDataset)
1896 if (!alignment.isNucleotide())
1905 consensus = new AlignmentAnnotation("Consensus",
1906 MessageManager.getString("label.consensus_descr"),
1907 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1908 initConsensus(consensus);
1911 initComplementConsensus();
1916 * If this is a protein alignment and there are mappings to cDNA, adds the
1917 * cDNA consensus annotation and returns true, else returns false.
1919 public boolean initComplementConsensus()
1921 if (!alignment.isNucleotide())
1923 final List<AlignedCodonFrame> codonMappings = alignment
1925 if (codonMappings != null && !codonMappings.isEmpty())
1927 boolean doConsensus = false;
1928 for (AlignedCodonFrame mapping : codonMappings)
1930 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1931 MapList[] mapLists = mapping.getdnaToProt();
1932 // mapLists can be empty if project load has not finished resolving
1934 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1942 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1944 .getString("label.complement_consensus_descr"),
1945 new Annotation[1], 0f, 100f,
1946 AlignmentAnnotation.BAR_GRAPH);
1947 initConsensus(complementConsensus);
1955 private void initConsensus(AlignmentAnnotation aa)
1958 aa.autoCalculated = true;
1962 alignment.addAnnotation(aa);
1966 // these should be extracted from the view model - style and settings for
1967 // derived annotation
1968 private void initGapCounts()
1972 gapcounts = new AlignmentAnnotation("Occupancy",
1973 MessageManager.getString("label.occupancy_descr"),
1974 new Annotation[1], 0f,
1975 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
1976 gapcounts.hasText = true;
1977 gapcounts.autoCalculated = true;
1978 gapcounts.scaleColLabel = true;
1979 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
1981 alignment.addAnnotation(gapcounts);
1985 private void initConservation()
1987 if (showConservation)
1989 if (conservation == null)
1991 conservation = new AlignmentAnnotation("Conservation",
1992 MessageManager.formatMessage("label.conservation_descr",
1993 getConsPercGaps()), new Annotation[1],
1994 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1995 conservation.hasText = true;
1996 conservation.autoCalculated = true;
1997 alignment.addAnnotation(conservation);
2002 private void initQuality()
2006 if (quality == null)
2008 quality = new AlignmentAnnotation("Quality",
2009 MessageManager.getString("label.quality_descr"),
2010 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2011 quality.hasText = true;
2012 quality.autoCalculated = true;
2013 alignment.addAnnotation(quality);
2018 private void initRNAStructure()
2020 if (alignment.hasRNAStructure() && strucConsensus == null)
2022 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2023 MessageManager.getString("label.strucconsensus_descr"),
2024 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2025 strucConsensus.hasText = true;
2026 strucConsensus.autoCalculated = true;
2030 alignment.addAnnotation(strucConsensus);
2038 * @see jalview.api.AlignViewportI#calcPanelHeight()
2041 public int calcPanelHeight()
2043 // setHeight of panels
2044 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2046 int charHeight = getCharHeight();
2049 BitSet graphgrp = new BitSet();
2050 for (AlignmentAnnotation aa : anns)
2054 System.err.println("Null annotation row: ignoring.");
2061 if (aa.graphGroup > -1)
2063 if (graphgrp.get(aa.graphGroup))
2069 graphgrp.set(aa.graphGroup);
2076 aa.height += charHeight;
2086 aa.height += aa.graphHeight;
2094 height += aa.height;
2106 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2107 boolean preserveNewGroupSettings)
2109 boolean updateCalcs = false;
2110 boolean conv = isShowGroupConservation();
2111 boolean cons = isShowGroupConsensus();
2112 boolean showprf = isShowSequenceLogo();
2113 boolean showConsHist = isShowConsensusHistogram();
2114 boolean normLogo = isNormaliseSequenceLogo();
2117 * TODO reorder the annotation rows according to group/sequence ordering on
2120 boolean sortg = true;
2122 // remove old automatic annotation
2123 // add any new annotation
2125 // intersect alignment annotation with alignment groups
2127 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2128 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2131 for (int an = 0; an < aan.length; an++)
2133 if (aan[an].autoCalculated && aan[an].groupRef != null)
2135 oldrfs.add(aan[an].groupRef);
2136 alignment.deleteAnnotation(aan[an], false);
2140 if (alignment.getGroups() != null)
2142 for (SequenceGroup sg : alignment.getGroups())
2144 updateCalcs = false;
2145 if (applyGlobalSettings
2146 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2148 // set defaults for this group's conservation/consensus
2149 sg.setshowSequenceLogo(showprf);
2150 sg.setShowConsensusHistogram(showConsHist);
2151 sg.setNormaliseSequenceLogo(normLogo);
2156 alignment.addAnnotation(sg.getConservationRow(), 0);
2161 alignment.addAnnotation(sg.getConsensus(), 0);
2163 // refresh the annotation rows
2166 sg.recalcConservation();
2174 public boolean isDisplayReferenceSeq()
2176 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2180 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2182 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2186 public boolean isColourByReferenceSeq()
2188 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2192 public Color getSequenceColour(SequenceI seq)
2194 Color sqc = sequenceColours.get(seq);
2195 return (sqc == null ? Color.white : sqc);
2199 public void setSequenceColour(SequenceI seq, Color col)
2203 sequenceColours.remove(seq);
2207 sequenceColours.put(seq, col);
2212 public void updateSequenceIdColours()
2214 for (SequenceGroup sg : alignment.getGroups())
2216 if (sg.idColour != null)
2218 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2220 sequenceColours.put(s, sg.idColour);
2227 public void clearSequenceColours()
2229 sequenceColours.clear();
2233 public AlignViewportI getCodingComplement()
2235 return this.codingComplement;
2239 * Set this as the (cDna/protein) complement of the given viewport. Also
2240 * ensures the reverse relationship is set on the given viewport.
2243 public void setCodingComplement(AlignViewportI av)
2247 System.err.println("Ignoring recursive setCodingComplement request");
2251 this.codingComplement = av;
2252 // avoid infinite recursion!
2253 if (av.getCodingComplement() != this)
2255 av.setCodingComplement(this);
2261 public boolean isNucleotide()
2263 return getAlignment() == null ? false : getAlignment().isNucleotide();
2267 public FeaturesDisplayedI getFeaturesDisplayed()
2269 return featuresDisplayed;
2273 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2275 featuresDisplayed = featuresDisplayedI;
2279 public boolean areFeaturesDisplayed()
2281 return featuresDisplayed != null
2282 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2289 * features are displayed if true
2292 public void setShowSequenceFeatures(boolean b)
2294 viewStyle.setShowSequenceFeatures(b);
2298 public boolean isShowSequenceFeatures()
2300 return viewStyle.isShowSequenceFeatures();
2304 public void setShowSequenceFeaturesHeight(boolean selected)
2306 viewStyle.setShowSequenceFeaturesHeight(selected);
2310 public boolean isShowSequenceFeaturesHeight()
2312 return viewStyle.isShowSequenceFeaturesHeight();
2316 public void setShowAnnotation(boolean b)
2318 viewStyle.setShowAnnotation(b);
2322 public boolean isShowAnnotation()
2324 return viewStyle.isShowAnnotation();
2328 public boolean isRightAlignIds()
2330 return viewStyle.isRightAlignIds();
2334 public void setRightAlignIds(boolean rightAlignIds)
2336 viewStyle.setRightAlignIds(rightAlignIds);
2340 public boolean getConservationSelected()
2342 return viewStyle.getConservationSelected();
2346 public void setShowBoxes(boolean state)
2348 viewStyle.setShowBoxes(state);
2353 * @see jalview.api.ViewStyleI#getTextColour()
2356 public Color getTextColour()
2358 return viewStyle.getTextColour();
2363 * @see jalview.api.ViewStyleI#getTextColour2()
2366 public Color getTextColour2()
2368 return viewStyle.getTextColour2();
2373 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2376 public int getThresholdTextColour()
2378 return viewStyle.getThresholdTextColour();
2383 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2386 public boolean isConservationColourSelected()
2388 return viewStyle.isConservationColourSelected();
2393 * @see jalview.api.ViewStyleI#isRenderGaps()
2396 public boolean isRenderGaps()
2398 return viewStyle.isRenderGaps();
2403 * @see jalview.api.ViewStyleI#isShowColourText()
2406 public boolean isShowColourText()
2408 return viewStyle.isShowColourText();
2412 * @param conservationColourSelected
2413 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2416 public void setConservationColourSelected(
2417 boolean conservationColourSelected)
2419 viewStyle.setConservationColourSelected(conservationColourSelected);
2423 * @param showColourText
2424 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2427 public void setShowColourText(boolean showColourText)
2429 viewStyle.setShowColourText(showColourText);
2434 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2437 public void setTextColour(Color textColour)
2439 viewStyle.setTextColour(textColour);
2443 * @param thresholdTextColour
2444 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2447 public void setThresholdTextColour(int thresholdTextColour)
2449 viewStyle.setThresholdTextColour(thresholdTextColour);
2453 * @param textColour2
2454 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2457 public void setTextColour2(Color textColour2)
2459 viewStyle.setTextColour2(textColour2);
2463 public ViewStyleI getViewStyle()
2465 return new ViewStyle(viewStyle);
2469 public void setViewStyle(ViewStyleI settingsForView)
2471 viewStyle = new ViewStyle(settingsForView);
2472 if (residueShading != null)
2474 residueShading.setConservationApplied(settingsForView
2475 .isConservationColourSelected());
2480 public boolean sameStyle(ViewStyleI them)
2482 return viewStyle.sameStyle(them);
2487 * @see jalview.api.ViewStyleI#getIdWidth()
2490 public int getIdWidth()
2492 return viewStyle.getIdWidth();
2497 * @see jalview.api.ViewStyleI#setIdWidth(int)
2500 public void setIdWidth(int i)
2502 viewStyle.setIdWidth(i);
2507 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2510 public boolean isCentreColumnLabels()
2512 return viewStyle.isCentreColumnLabels();
2516 * @param centreColumnLabels
2517 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2520 public void setCentreColumnLabels(boolean centreColumnLabels)
2522 viewStyle.setCentreColumnLabels(centreColumnLabels);
2527 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2530 public void setShowDBRefs(boolean showdbrefs)
2532 viewStyle.setShowDBRefs(showdbrefs);
2537 * @see jalview.api.ViewStyleI#isShowDBRefs()
2540 public boolean isShowDBRefs()
2542 return viewStyle.isShowDBRefs();
2547 * @see jalview.api.ViewStyleI#isShowNPFeats()
2550 public boolean isShowNPFeats()
2552 return viewStyle.isShowNPFeats();
2556 * @param shownpfeats
2557 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2560 public void setShowNPFeats(boolean shownpfeats)
2562 viewStyle.setShowNPFeats(shownpfeats);
2565 public abstract StructureSelectionManager getStructureSelectionManager();
2568 * Add one command to the command history list.
2572 public void addToHistoryList(CommandI command)
2574 if (this.historyList != null)
2576 this.historyList.push(command);
2577 broadcastCommand(command, false);
2581 protected void broadcastCommand(CommandI command, boolean undo)
2583 getStructureSelectionManager().commandPerformed(command, undo,
2588 * Add one command to the command redo list.
2592 public void addToRedoList(CommandI command)
2594 if (this.redoList != null)
2596 this.redoList.push(command);
2598 broadcastCommand(command, true);
2602 * Clear the command redo list.
2604 public void clearRedoList()
2606 if (this.redoList != null)
2608 this.redoList.clear();
2612 public void setHistoryList(Deque<CommandI> list)
2614 this.historyList = list;
2617 public Deque<CommandI> getHistoryList()
2619 return this.historyList;
2622 public void setRedoList(Deque<CommandI> list)
2624 this.redoList = list;
2627 public Deque<CommandI> getRedoList()
2629 return this.redoList;
2633 public VamsasSource getVamsasSource()
2638 public SequenceAnnotationOrder getSortAnnotationsBy()
2640 return sortAnnotationsBy;
2643 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2645 this.sortAnnotationsBy = sortAnnotationsBy;
2648 public boolean isShowAutocalculatedAbove()
2650 return showAutocalculatedAbove;
2653 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2655 this.showAutocalculatedAbove = showAutocalculatedAbove;
2659 public boolean isScaleProteinAsCdna()
2661 return viewStyle.isScaleProteinAsCdna();
2665 public void setScaleProteinAsCdna(boolean b)
2667 viewStyle.setScaleProteinAsCdna(b);
2671 * @return true if view should scroll to show the highlighted region of a
2676 public final boolean isFollowHighlight()
2678 return followHighlight;
2682 public final void setFollowHighlight(boolean b)
2684 this.followHighlight = b;
2688 public ViewportRanges getRanges()
2694 * Helper method to populate the SearchResults with the location in the
2695 * complementary alignment to scroll to, in order to match this one.
2698 * the SearchResults to add to
2699 * @return the offset (below top of visible region) of the matched sequence
2701 protected int findComplementScrollTarget(SearchResultsI sr)
2703 final AlignViewportI complement = getCodingComplement();
2704 if (complement == null || !complement.isFollowHighlight())
2708 boolean iAmProtein = !getAlignment().isNucleotide();
2709 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2711 if (proteinAlignment == null)
2715 final List<AlignedCodonFrame> mappings = proteinAlignment
2719 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2720 * residue in the middle column of the visible region. Scroll the
2721 * complementary alignment to line up the corresponding residue.
2724 SequenceI sequence = null;
2727 * locate 'middle' column (true middle if an odd number visible, left of
2728 * middle if an even number visible)
2730 int middleColumn = ranges.getStartRes()
2731 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2732 final HiddenSequences hiddenSequences = getAlignment()
2733 .getHiddenSequences();
2736 * searching to the bottom of the alignment gives smoother scrolling across
2737 * all gapped visible regions
2739 int lastSeq = alignment.getHeight() - 1;
2740 List<AlignedCodonFrame> seqMappings = null;
2741 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2743 sequence = getAlignment().getSequenceAt(seqNo);
2744 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2748 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2752 seqMappings = MappingUtils
2753 .findMappingsForSequenceAndOthers(sequence, mappings,
2754 getCodingComplement().getAlignment().getSequences());
2755 if (!seqMappings.isEmpty())
2761 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2764 * No ungapped mapped sequence in middle column - do nothing
2768 MappingUtils.addSearchResults(sr, sequence,
2769 sequence.findPosition(middleColumn), seqMappings);
2774 * synthesize a column selection if none exists so it covers the given
2775 * selection group. if wholewidth is false, no column selection is made if the
2776 * selection group covers the whole alignment width.
2781 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2784 if (sg != null && (sgs = sg.getStartRes()) >= 0
2785 && sg.getStartRes() <= (sge = sg.getEndRes())
2786 && !this.hasSelectedColumns())
2788 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2795 colSel = new ColumnSelection();
2797 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2799 colSel.addElement(cspos);
2805 * hold status of current selection group - defined on alignment or not.
2807 private boolean selectionIsDefinedGroup = false;
2810 public boolean isSelectionDefinedGroup()
2812 if (selectionGroup == null)
2816 if (isSelectionGroupChanged(true))
2818 selectionIsDefinedGroup = false;
2819 List<SequenceGroup> gps = alignment.getGroups();
2820 if (gps == null || gps.size() == 0)
2822 selectionIsDefinedGroup = false;
2826 selectionIsDefinedGroup = gps.contains(selectionGroup);
2829 return selectionGroup.getContext() == alignment
2830 || selectionIsDefinedGroup;
2834 * null, or currently highlighted results on this view
2836 private SearchResultsI searchResults = null;
2839 public boolean hasSearchResults()
2841 return searchResults != null;
2845 public void setSearchResults(SearchResultsI results)
2847 searchResults = results;
2851 public SearchResultsI getSearchResults()
2853 return searchResults;