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 final 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>();
100 * alignment displayed in the viewport. Please use get/setter
102 protected AlignmentI alignment;
104 public AlignmentViewport(AlignmentI al)
107 ranges = new ViewportRanges(al);
112 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
115 public void setFontName(String name)
117 viewStyle.setFontName(name);
122 * @see jalview.api.ViewStyleI#setFontStyle(int)
125 public void setFontStyle(int style)
127 viewStyle.setFontStyle(style);
132 * @see jalview.api.ViewStyleI#setFontSize(int)
135 public void setFontSize(int size)
137 viewStyle.setFontSize(size);
142 * @see jalview.api.ViewStyleI#getFontStyle()
145 public int getFontStyle()
147 return viewStyle.getFontStyle();
152 * @see jalview.api.ViewStyleI#getFontName()
155 public String getFontName()
157 return viewStyle.getFontName();
162 * @see jalview.api.ViewStyleI#getFontSize()
165 public int getFontSize()
167 return viewStyle.getFontSize();
171 * @param upperCasebold
172 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
175 public void setUpperCasebold(boolean upperCasebold)
177 viewStyle.setUpperCasebold(upperCasebold);
182 * @see jalview.api.ViewStyleI#isUpperCasebold()
185 public boolean isUpperCasebold()
187 return viewStyle.isUpperCasebold();
192 * @see jalview.api.ViewStyleI#isSeqNameItalics()
195 public boolean isSeqNameItalics()
197 return viewStyle.isSeqNameItalics();
201 * @param colourByReferenceSeq
202 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
205 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
207 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
212 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
215 public void setColourAppliesToAllGroups(boolean b)
217 viewStyle.setColourAppliesToAllGroups(b);
222 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
225 public boolean getColourAppliesToAllGroups()
227 return viewStyle.getColourAppliesToAllGroups();
232 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
235 public boolean getAbovePIDThreshold()
237 return viewStyle.getAbovePIDThreshold();
242 * @see jalview.api.ViewStyleI#setIncrement(int)
245 public void setIncrement(int inc)
247 viewStyle.setIncrement(inc);
252 * @see jalview.api.ViewStyleI#getIncrement()
255 public int getIncrement()
257 return viewStyle.getIncrement();
262 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
265 public void setConservationSelected(boolean b)
267 viewStyle.setConservationSelected(b);
272 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
275 public void setShowHiddenMarkers(boolean show)
277 viewStyle.setShowHiddenMarkers(show);
282 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
285 public boolean getShowHiddenMarkers()
287 return viewStyle.getShowHiddenMarkers();
292 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
295 public void setScaleRightWrapped(boolean b)
297 viewStyle.setScaleRightWrapped(b);
302 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
305 public void setScaleLeftWrapped(boolean b)
307 viewStyle.setScaleLeftWrapped(b);
312 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
315 public void setScaleAboveWrapped(boolean b)
317 viewStyle.setScaleAboveWrapped(b);
322 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
325 public boolean getScaleLeftWrapped()
327 return viewStyle.getScaleLeftWrapped();
332 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
335 public boolean getScaleAboveWrapped()
337 return viewStyle.getScaleAboveWrapped();
342 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
345 public boolean getScaleRightWrapped()
347 return viewStyle.getScaleRightWrapped();
352 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
355 public void setAbovePIDThreshold(boolean b)
357 viewStyle.setAbovePIDThreshold(b);
362 * @see jalview.api.ViewStyleI#setThreshold(int)
365 public void setThreshold(int thresh)
367 viewStyle.setThreshold(thresh);
372 * @see jalview.api.ViewStyleI#getThreshold()
375 public int getThreshold()
377 return viewStyle.getThreshold();
382 * @see jalview.api.ViewStyleI#getShowJVSuffix()
385 public boolean getShowJVSuffix()
387 return viewStyle.getShowJVSuffix();
392 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
395 public void setShowJVSuffix(boolean b)
397 viewStyle.setShowJVSuffix(b);
402 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
405 public void setWrapAlignment(boolean state)
407 viewStyle.setWrapAlignment(state);
412 * @see jalview.api.ViewStyleI#setShowText(boolean)
415 public void setShowText(boolean state)
417 viewStyle.setShowText(state);
422 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
425 public void setRenderGaps(boolean state)
427 viewStyle.setRenderGaps(state);
432 * @see jalview.api.ViewStyleI#getColourText()
435 public boolean getColourText()
437 return viewStyle.getColourText();
442 * @see jalview.api.ViewStyleI#setColourText(boolean)
445 public void setColourText(boolean state)
447 viewStyle.setColourText(state);
452 * @see jalview.api.ViewStyleI#getWrapAlignment()
455 public boolean getWrapAlignment()
457 return viewStyle.getWrapAlignment();
462 * @see jalview.api.ViewStyleI#getShowText()
465 public boolean getShowText()
467 return viewStyle.getShowText();
472 * @see jalview.api.ViewStyleI#getWrappedWidth()
475 public int getWrappedWidth()
477 return viewStyle.getWrappedWidth();
482 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
485 public void setWrappedWidth(int w)
487 viewStyle.setWrappedWidth(w);
492 * @see jalview.api.ViewStyleI#getCharHeight()
495 public int getCharHeight()
497 return viewStyle.getCharHeight();
502 * @see jalview.api.ViewStyleI#setCharHeight(int)
505 public void setCharHeight(int h)
507 viewStyle.setCharHeight(h);
512 * @see jalview.api.ViewStyleI#getCharWidth()
515 public int getCharWidth()
517 return viewStyle.getCharWidth();
522 * @see jalview.api.ViewStyleI#setCharWidth(int)
525 public void setCharWidth(int w)
527 viewStyle.setCharWidth(w);
532 * @see jalview.api.ViewStyleI#getShowBoxes()
535 public boolean getShowBoxes()
537 return viewStyle.getShowBoxes();
542 * @see jalview.api.ViewStyleI#getShowUnconserved()
545 public boolean getShowUnconserved()
547 return viewStyle.getShowUnconserved();
551 * @param showunconserved
552 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
555 public void setShowUnconserved(boolean showunconserved)
557 viewStyle.setShowUnconserved(showunconserved);
562 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
565 public void setSeqNameItalics(boolean default1)
567 viewStyle.setSeqNameItalics(default1);
573 public AlignmentI getAlignment()
579 public char getGapCharacter()
581 return alignment.getGapCharacter();
584 protected String sequenceSetID;
587 * probably unused indicator that view is of a dataset rather than an
590 protected boolean isDataset = false;
592 public void setDataset(boolean b)
597 public boolean isDataset()
602 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
604 protected ColumnSelection colSel = new ColumnSelection();
606 public boolean autoCalculateConsensus = true;
608 protected boolean autoCalculateStrucConsensus = true;
610 protected boolean ignoreGapsInConsensusCalculation = false;
612 protected ResidueShaderI residueShading = new ResidueShader();
615 public void setGlobalColourScheme(ColourSchemeI cs)
617 // TODO: logic refactored from AlignFrame changeColour -
618 // TODO: autorecalc stuff should be changed to rely on the worker system
619 // check to see if we should implement a changeColour(cs) method rather than
620 // put the logic in here
621 // - means that caller decides if they want to just modify state and defer
622 // calculation till later or to do all calculations in thread.
626 * only instantiate alignment colouring once, thereafter update it;
627 * this means that any conservation or PID threshold settings
628 * persist when the alignment colour scheme is changed
630 if (residueShading == null)
632 residueShading = new ResidueShader(viewStyle);
634 residueShading.setColourScheme(cs);
636 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
637 // ...problem: groups need these, but do not currently have a ViewStyle
641 if (getConservationSelected())
643 residueShading.setConservation(hconservation);
645 residueShading.alignmentChanged(alignment, hiddenRepSequences);
649 * if 'apply colour to all groups' is selected... do so
650 * (but don't transfer any colour threshold settings to groups)
652 if (getColourAppliesToAllGroups())
654 for (SequenceGroup sg : getAlignment().getGroups())
657 * retain any colour thresholds per group while
658 * changing choice of colour scheme (JAL-2386)
660 sg.setColourScheme(cs);
663 sg.getGroupColourScheme()
664 .alignmentChanged(sg, hiddenRepSequences);
671 public ColourSchemeI getGlobalColourScheme()
673 return residueShading == null ? null : residueShading
678 public ResidueShaderI getResidueShading()
680 return residueShading;
683 protected AlignmentAnnotation consensus;
685 protected AlignmentAnnotation complementConsensus;
687 protected AlignmentAnnotation gapcounts;
689 protected AlignmentAnnotation strucConsensus;
691 protected AlignmentAnnotation conservation;
693 protected AlignmentAnnotation quality;
695 protected AlignmentAnnotation[] groupConsensus;
697 protected AlignmentAnnotation[] groupConservation;
700 * results of alignment consensus analysis for visible portion of view
702 protected ProfilesI hconsensus = null;
705 * results of cDNA complement consensus visible portion of view
707 protected Hashtable[] hcomplementConsensus = null;
710 * results of secondary structure base pair consensus for visible portion of
713 protected Hashtable[] hStrucConsensus = null;
715 protected Conservation hconservation = null;
718 public void setConservation(Conservation cons)
720 hconservation = cons;
724 * percentage gaps allowed in a column before all amino acid properties should
725 * be considered unconserved
727 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
730 public int getConsPercGaps()
736 public void setSequenceConsensusHash(ProfilesI hconsensus)
738 this.hconsensus = hconsensus;
742 public void setComplementConsensusHash(Hashtable[] hconsensus)
744 this.hcomplementConsensus = hconsensus;
748 public ProfilesI getSequenceConsensusHash()
754 public Hashtable[] getComplementConsensusHash()
756 return hcomplementConsensus;
760 public Hashtable[] getRnaStructureConsensusHash()
762 return hStrucConsensus;
766 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
768 this.hStrucConsensus = hStrucConsensus;
773 public AlignmentAnnotation getAlignmentQualityAnnot()
779 public AlignmentAnnotation getAlignmentConservationAnnotation()
785 public AlignmentAnnotation getAlignmentConsensusAnnotation()
791 public AlignmentAnnotation getAlignmentGapAnnotation()
797 public AlignmentAnnotation getComplementConsensusAnnotation()
799 return complementConsensus;
803 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
805 return strucConsensus;
808 protected AlignCalcManagerI calculator = new AlignCalcManager();
811 * trigger update of conservation annotation
813 public void updateConservation(final AlignmentViewPanel ap)
815 // see note in mantis : issue number 8585
816 if (alignment.isNucleotide()
817 || (conservation == null && quality == null)
818 || !autoCalculateConsensus)
823 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
825 calculator.registerWorker(new jalview.workers.ConservationThread(
831 * trigger update of consensus annotation
833 public void updateConsensus(final AlignmentViewPanel ap)
835 // see note in mantis : issue number 8585
836 if (consensus == null || !autoCalculateConsensus)
840 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
842 calculator.registerWorker(new ConsensusThread(this, ap));
846 * A separate thread to compute cDNA consensus for a protein alignment
847 * which has mapping to cDNA
849 final AlignmentI al = this.getAlignment();
850 if (!al.isNucleotide() && al.getCodonFrames() != null
851 && !al.getCodonFrames().isEmpty())
854 * fudge - check first for protein-to-nucleotide mappings
855 * (we don't want to do this for protein-to-protein)
857 boolean doConsensus = false;
858 for (AlignedCodonFrame mapping : al.getCodonFrames())
860 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
861 MapList[] mapLists = mapping.getdnaToProt();
862 // mapLists can be empty if project load has not finished resolving seqs
863 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
872 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
875 .registerWorker(new ComplementConsensusThread(this, ap));
881 // --------START Structure Conservation
882 public void updateStrucConsensus(final AlignmentViewPanel ap)
884 if (autoCalculateStrucConsensus && strucConsensus == null
885 && alignment.isNucleotide() && alignment.hasRNAStructure())
887 // secondary structure has been added - so init the consensus line
891 // see note in mantis : issue number 8585
892 if (strucConsensus == null || !autoCalculateStrucConsensus)
896 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
898 calculator.registerWorker(new StrucConsensusThread(this, ap));
902 public boolean isCalcInProgress()
904 return calculator.isWorking();
908 public boolean isCalculationInProgress(
909 AlignmentAnnotation alignmentAnnotation)
911 if (!alignmentAnnotation.autoCalculated)
915 if (calculator.workingInvolvedWith(alignmentAnnotation))
917 // System.err.println("grey out ("+alignmentAnnotation.label+")");
923 public void setAlignment(AlignmentI align)
925 this.alignment = align;
929 * Clean up references when this viewport is closed
932 public void dispose()
935 * defensively null out references to large objects in case
936 * this object is not garbage collected (as if!)
939 complementConsensus = null;
940 strucConsensus = null;
943 groupConsensus = null;
944 groupConservation = null;
946 hcomplementConsensus = null;
947 // colour scheme may hold reference to consensus
948 residueShading = null;
949 // TODO remove listeners from changeSupport?
950 changeSupport = null;
955 public boolean isClosed()
957 // TODO: check that this isClosed is only true after panel is closed, not
958 // before it is fully constructed.
959 return alignment == null;
963 public AlignCalcManagerI getCalcManager()
969 * should conservation rows be shown for groups
971 protected boolean showGroupConservation = false;
974 * should consensus rows be shown for groups
976 protected boolean showGroupConsensus = false;
979 * should consensus profile be rendered by default
981 protected boolean showSequenceLogo = false;
984 * should consensus profile be rendered normalised to row height
986 protected boolean normaliseSequenceLogo = false;
989 * should consensus histograms be rendered by default
991 protected boolean showConsensusHistogram = true;
994 * @return the showConsensusProfile
997 public boolean isShowSequenceLogo()
999 return showSequenceLogo;
1003 * @param showSequenceLogo
1006 public void setShowSequenceLogo(boolean showSequenceLogo)
1008 if (showSequenceLogo != this.showSequenceLogo)
1010 // TODO: decouple settings setting from calculation when refactoring
1011 // annotation update method from alignframe to viewport
1012 this.showSequenceLogo = showSequenceLogo;
1013 calculator.updateAnnotationFor(ConsensusThread.class);
1014 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1015 calculator.updateAnnotationFor(StrucConsensusThread.class);
1017 this.showSequenceLogo = showSequenceLogo;
1021 * @param showConsensusHistogram
1022 * the showConsensusHistogram to set
1024 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1026 this.showConsensusHistogram = showConsensusHistogram;
1030 * @return the showGroupConservation
1032 public boolean isShowGroupConservation()
1034 return showGroupConservation;
1038 * @param showGroupConservation
1039 * the showGroupConservation to set
1041 public void setShowGroupConservation(boolean showGroupConservation)
1043 this.showGroupConservation = showGroupConservation;
1047 * @return the showGroupConsensus
1049 public boolean isShowGroupConsensus()
1051 return showGroupConsensus;
1055 * @param showGroupConsensus
1056 * the showGroupConsensus to set
1058 public void setShowGroupConsensus(boolean showGroupConsensus)
1060 this.showGroupConsensus = showGroupConsensus;
1065 * @return flag to indicate if the consensus histogram should be rendered by
1069 public boolean isShowConsensusHistogram()
1071 return this.showConsensusHistogram;
1075 * when set, updateAlignment will always ensure sequences are of equal length
1077 private boolean padGaps = false;
1080 * when set, alignment should be reordered according to a newly opened tree
1082 public boolean sortByTree = false;
1087 * @return null or the currently selected sequence region
1090 public SequenceGroup getSelectionGroup()
1092 return selectionGroup;
1096 * Set the selection group for this window. Also sets the current alignment as
1097 * the context for the group, if it does not already have one.
1100 * - group holding references to sequences in this alignment view
1104 public void setSelectionGroup(SequenceGroup sg)
1106 selectionGroup = sg;
1107 if (sg != null && sg.getContext() == null)
1109 sg.setContext(alignment);
1113 public void setHiddenColumns(HiddenColumns hidden)
1115 this.alignment.setHiddenColumns(hidden);
1116 // this.colSel = colsel;
1120 public ColumnSelection getColumnSelection()
1126 public void setColumnSelection(ColumnSelection colSel)
1128 this.colSel = colSel;
1131 updateHiddenColumns();
1133 isColSelChanged(true);
1141 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1143 return hiddenRepSequences;
1147 public void setHiddenRepSequences(
1148 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1150 this.hiddenRepSequences = hiddenRepSequences;
1154 public boolean hasSelectedColumns()
1156 ColumnSelection columnSelection = getColumnSelection();
1157 return columnSelection != null && columnSelection.hasSelectedColumns();
1161 public boolean hasHiddenColumns()
1163 return colSel != null
1164 && alignment.getHiddenColumns().hasHiddenColumns();
1167 public void updateHiddenColumns()
1169 // this method doesn't really do anything now. But - it could, since a
1170 // column Selection could be in the process of modification
1171 // hasHiddenColumns = colSel.hasHiddenColumns();
1175 public boolean hasHiddenRows()
1177 return alignment.getHiddenSequences().getSize() > 0;
1180 protected SequenceGroup selectionGroup;
1182 public void setSequenceSetId(String newid)
1184 if (sequenceSetID != null)
1187 .println("Warning - overwriting a sequenceSetId for a viewport!");
1189 sequenceSetID = new String(newid);
1193 public String getSequenceSetId()
1195 if (sequenceSetID == null)
1197 sequenceSetID = alignment.hashCode() + "";
1200 return sequenceSetID;
1204 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1207 protected String viewId = null;
1210 public String getViewId()
1214 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1219 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1221 ignoreGapsInConsensusCalculation = b;
1224 updateConsensus(ap);
1225 if (residueShading != null)
1227 residueShading.setThreshold(residueShading.getThreshold(),
1228 ignoreGapsInConsensusCalculation);
1234 private long sgrouphash = -1, colselhash = -1;
1237 * checks current SelectionGroup against record of last hash value, and
1241 * update the record of last hash value
1243 * @return true if SelectionGroup changed since last call (when b is true)
1245 public boolean isSelectionGroupChanged(boolean b)
1247 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1248 : selectionGroup.hashCode();
1249 if (hc != -1 && hc != sgrouphash)
1261 * checks current colsel against record of last hash value, and optionally
1265 * update the record of last hash value
1266 * @return true if colsel changed since last call (when b is true)
1268 public boolean isColSelChanged(boolean b)
1270 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1271 if (hc != -1 && hc != colselhash)
1283 public boolean isIgnoreGapsConsensus()
1285 return ignoreGapsInConsensusCalculation;
1288 // property change stuff
1289 // JBPNote Prolly only need this in the applet version.
1290 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1293 protected boolean showConservation = true;
1295 protected boolean showQuality = true;
1297 protected boolean showConsensus = true;
1299 protected boolean showOccupancy = true;
1301 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1303 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1305 protected boolean showAutocalculatedAbove;
1308 * when set, view will scroll to show the highlighted position
1310 private boolean followHighlight = true;
1313 * Property change listener for changes in alignment
1318 public void addPropertyChangeListener(
1319 java.beans.PropertyChangeListener listener)
1321 changeSupport.addPropertyChangeListener(listener);
1330 public void removePropertyChangeListener(
1331 java.beans.PropertyChangeListener listener)
1333 changeSupport.removePropertyChangeListener(listener);
1337 * Property change listener for changes in alignment
1346 public void firePropertyChange(String prop, Object oldvalue,
1349 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1352 // common hide/show column stuff
1354 public void hideSelectedColumns()
1356 if (colSel.isEmpty())
1361 colSel.hideSelectedColumns(alignment);
1362 setSelectionGroup(null);
1363 isColSelChanged(true);
1366 public void hideColumns(int start, int end)
1370 colSel.hideSelectedColumns(start, alignment.getHiddenColumns());
1374 alignment.getHiddenColumns().hideColumns(start, end);
1376 isColSelChanged(true);
1379 public void showColumn(int col)
1381 alignment.getHiddenColumns().revealHiddenColumns(col, colSel);
1382 isColSelChanged(true);
1385 public void showAllHiddenColumns()
1387 alignment.getHiddenColumns().revealAllHiddenColumns(colSel);
1388 isColSelChanged(true);
1391 // common hide/show seq stuff
1392 public void showAllHiddenSeqs()
1394 if (alignment.getHiddenSequences().getSize() > 0)
1396 if (selectionGroup == null)
1398 selectionGroup = new SequenceGroup();
1399 selectionGroup.setEndRes(alignment.getWidth() - 1);
1401 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1402 hiddenRepSequences);
1403 for (SequenceI seq : tmp)
1405 selectionGroup.addSequence(seq, false);
1406 setSequenceAnnotationsVisible(seq, true);
1409 hiddenRepSequences = null;
1411 firePropertyChange("alignment", null, alignment.getSequences());
1412 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1418 public void showSequence(int index)
1420 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1421 index, hiddenRepSequences);
1424 if (selectionGroup == null)
1426 selectionGroup = new SequenceGroup();
1427 selectionGroup.setEndRes(alignment.getWidth() - 1);
1430 for (SequenceI seq : tmp)
1432 selectionGroup.addSequence(seq, false);
1433 setSequenceAnnotationsVisible(seq, true);
1435 firePropertyChange("alignment", null, alignment.getSequences());
1440 public void hideAllSelectedSeqs()
1442 if (selectionGroup == null || selectionGroup.getSize() < 1)
1447 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1451 setSelectionGroup(null);
1454 public void hideSequence(SequenceI[] seq)
1458 for (int i = 0; i < seq.length; i++)
1460 alignment.getHiddenSequences().hideSequence(seq[i]);
1461 setSequenceAnnotationsVisible(seq[i], false);
1463 firePropertyChange("alignment", null, alignment.getSequences());
1468 * Hides the specified sequence, or the sequences it represents
1471 * the sequence to hide, or keep as representative
1472 * @param representGroup
1473 * if true, hide the current selection group except for the
1474 * representative sequence
1476 public void hideSequences(SequenceI sequence, boolean representGroup)
1478 if (selectionGroup == null || selectionGroup.getSize() < 1)
1480 hideSequence(new SequenceI[] { sequence });
1486 hideRepSequences(sequence, selectionGroup);
1487 setSelectionGroup(null);
1491 int gsize = selectionGroup.getSize();
1492 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1493 new SequenceI[gsize]);
1495 hideSequence(hseqs);
1496 setSelectionGroup(null);
1501 * Set visibility for any annotations for the given sequence.
1505 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1508 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1511 for (AlignmentAnnotation ann : anns)
1513 if (ann.sequenceRef == sequenceI)
1515 ann.visible = visible;
1521 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1523 int sSize = sg.getSize();
1529 if (hiddenRepSequences == null)
1531 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1534 hiddenRepSequences.put(repSequence, sg);
1536 // Hide all sequences except the repSequence
1537 SequenceI[] seqs = new SequenceI[sSize - 1];
1539 for (int i = 0; i < sSize; i++)
1541 if (sg.getSequenceAt(i) != repSequence)
1543 if (index == sSize - 1)
1548 seqs[index++] = sg.getSequenceAt(i);
1551 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1552 sg.setHidereps(true); // note: not done in 2.7applet
1559 * @return null or the current reference sequence
1561 public SequenceI getReferenceSeq()
1563 return alignment.getSeqrep();
1568 * @return true iff seq is the reference for the alignment
1570 public boolean isReferenceSeq(SequenceI seq)
1572 return alignment.getSeqrep() == seq;
1578 * @return true if there are sequences represented by this sequence that are
1581 public boolean isHiddenRepSequence(SequenceI seq)
1583 return (hiddenRepSequences != null && hiddenRepSequences
1590 * @return null or a sequence group containing the sequences that seq
1593 public SequenceGroup getRepresentedSequences(SequenceI seq)
1595 return (SequenceGroup) (hiddenRepSequences == null ? null
1596 : hiddenRepSequences.get(seq));
1600 public int adjustForHiddenSeqs(int alignmentIndex)
1602 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1607 public void invertColumnSelection()
1609 colSel.invertColumnSelection(0, alignment.getWidth(), alignment);
1613 public SequenceI[] getSelectionAsNewSequence()
1615 SequenceI[] sequences;
1616 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1617 // this was the only caller in the applet for this method
1618 // JBPNote: in applet, this method returned references to the alignment
1619 // sequences, and it did not honour the presence/absence of annotation
1620 // attached to the alignment (probably!)
1621 if (selectionGroup == null || selectionGroup.getSize() == 0)
1623 sequences = alignment.getSequencesArray();
1624 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1625 for (int i = 0; i < sequences.length; i++)
1627 // construct new sequence with subset of visible annotation
1628 sequences[i] = new Sequence(sequences[i], annots);
1633 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1640 public SequenceI[] getSequenceSelection()
1642 SequenceI[] sequences = null;
1643 if (selectionGroup != null)
1645 sequences = selectionGroup.getSequencesInOrder(alignment);
1647 if (sequences == null)
1649 sequences = alignment.getSequencesArray();
1655 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1657 return new CigarArray(alignment, alignment.getHiddenColumns(),
1658 (selectedRegionOnly ? selectionGroup : null));
1662 public jalview.datamodel.AlignmentView getAlignmentView(
1663 boolean selectedOnly)
1665 return getAlignmentView(selectedOnly, false);
1669 public jalview.datamodel.AlignmentView getAlignmentView(
1670 boolean selectedOnly, boolean markGroups)
1672 return new AlignmentView(alignment, alignment.getHiddenColumns(),
1673 selectionGroup, alignment.getHiddenColumns() != null
1674 && alignment.getHiddenColumns().hasHiddenColumns(),
1680 public String[] getViewAsString(boolean selectedRegionOnly)
1682 return getViewAsString(selectedRegionOnly, true);
1686 public String[] getViewAsString(boolean selectedRegionOnly,
1687 boolean exportHiddenSeqs)
1689 String[] selection = null;
1690 SequenceI[] seqs = null;
1692 int start = 0, end = 0;
1693 if (selectedRegionOnly && selectionGroup != null)
1695 iSize = selectionGroup.getSize();
1696 seqs = selectionGroup.getSequencesInOrder(alignment);
1697 start = selectionGroup.getStartRes();
1698 end = selectionGroup.getEndRes() + 1;
1702 if (hasHiddenRows() && exportHiddenSeqs)
1704 AlignmentI fullAlignment = alignment.getHiddenSequences()
1705 .getFullAlignment();
1706 iSize = fullAlignment.getHeight();
1707 seqs = fullAlignment.getSequencesArray();
1708 end = fullAlignment.getWidth();
1712 iSize = alignment.getHeight();
1713 seqs = alignment.getSequencesArray();
1714 end = alignment.getWidth();
1718 selection = new String[iSize];
1719 if (alignment.getHiddenColumns() != null
1720 && alignment.getHiddenColumns().hasHiddenColumns())
1722 selection = alignment.getHiddenColumns().getVisibleSequenceStrings(
1727 for (i = 0; i < iSize; i++)
1729 selection[i] = seqs[i].getSequenceAsString(start, end);
1737 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1739 ArrayList<int[]> regions = new ArrayList<int[]>();
1745 HiddenColumns hidden = alignment.getHiddenColumns();
1746 if (hidden != null && hidden.hasHiddenColumns())
1750 start = hidden.adjustForHiddenColumns(start);
1753 end = hidden.getHiddenBoundaryRight(start);
1764 regions.add(new int[] { start, end });
1766 if (hidden != null && hidden.hasHiddenColumns())
1768 start = hidden.adjustForHiddenColumns(end);
1769 start = hidden.getHiddenBoundaryLeft(start) + 1;
1771 } while (end < max);
1773 int[][] startEnd = new int[regions.size()][2];
1779 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1780 boolean selectedOnly)
1782 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1783 AlignmentAnnotation[] aa;
1784 if ((aa = alignment.getAlignmentAnnotation()) != null)
1786 for (AlignmentAnnotation annot : aa)
1788 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1789 if (selectedOnly && selectionGroup != null)
1791 alignment.getHiddenColumns().makeVisibleAnnotation(
1792 selectionGroup.getStartRes(),
1793 selectionGroup.getEndRes(), clone);
1797 alignment.getHiddenColumns().makeVisibleAnnotation(clone);
1806 public boolean isPadGaps()
1812 public void setPadGaps(boolean padGaps)
1814 this.padGaps = padGaps;
1818 * apply any post-edit constraints and trigger any calculations needed after
1819 * an edit has been performed on the alignment
1824 public void alignmentChanged(AlignmentViewPanel ap)
1828 alignment.padGaps();
1830 if (autoCalculateConsensus)
1832 updateConsensus(ap);
1834 if (hconsensus != null && autoCalculateConsensus)
1836 updateConservation(ap);
1838 if (autoCalculateStrucConsensus)
1840 updateStrucConsensus(ap);
1843 // Reset endRes of groups if beyond alignment width
1844 int alWidth = alignment.getWidth();
1845 List<SequenceGroup> groups = alignment.getGroups();
1848 for (SequenceGroup sg : groups)
1850 if (sg.getEndRes() > alWidth)
1852 sg.setEndRes(alWidth - 1);
1857 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1859 selectionGroup.setEndRes(alWidth - 1);
1862 updateAllColourSchemes();
1863 calculator.restartWorkers();
1864 // alignment.adjustSequenceAnnotations();
1868 * reset scope and do calculations for all applied colourschemes on alignment
1870 void updateAllColourSchemes()
1872 ResidueShaderI rs = residueShading;
1875 rs.alignmentChanged(alignment, hiddenRepSequences);
1877 rs.setConsensus(hconsensus);
1878 if (rs.conservationApplied())
1880 rs.setConservation(Conservation.calculateConservation("All",
1881 alignment.getSequences(), 0, alignment.getWidth(), false,
1882 getConsPercGaps(), false));
1886 for (SequenceGroup sg : alignment.getGroups())
1890 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1892 sg.recalcConservation();
1896 protected void initAutoAnnotation()
1898 // TODO: add menu option action that nulls or creates consensus object
1899 // depending on if the user wants to see the annotation or not in a
1900 // specific alignment
1902 if (hconsensus == null && !isDataset)
1904 if (!alignment.isNucleotide())
1913 consensus = new AlignmentAnnotation("Consensus",
1914 MessageManager.getString("label.consensus_descr"),
1915 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1916 initConsensus(consensus);
1919 initComplementConsensus();
1924 * If this is a protein alignment and there are mappings to cDNA, adds the
1925 * cDNA consensus annotation and returns true, else returns false.
1927 public boolean initComplementConsensus()
1929 if (!alignment.isNucleotide())
1931 final List<AlignedCodonFrame> codonMappings = alignment
1933 if (codonMappings != null && !codonMappings.isEmpty())
1935 boolean doConsensus = false;
1936 for (AlignedCodonFrame mapping : codonMappings)
1938 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1939 MapList[] mapLists = mapping.getdnaToProt();
1940 // mapLists can be empty if project load has not finished resolving
1942 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1950 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1952 .getString("label.complement_consensus_descr"),
1953 new Annotation[1], 0f, 100f,
1954 AlignmentAnnotation.BAR_GRAPH);
1955 initConsensus(complementConsensus);
1963 private void initConsensus(AlignmentAnnotation aa)
1966 aa.autoCalculated = true;
1970 alignment.addAnnotation(aa);
1974 // these should be extracted from the view model - style and settings for
1975 // derived annotation
1976 private void initGapCounts()
1980 gapcounts = new AlignmentAnnotation("Occupancy",
1981 MessageManager.getString("label.occupancy_descr"),
1982 new Annotation[1], 0f,
1983 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
1984 gapcounts.hasText = true;
1985 gapcounts.autoCalculated = true;
1986 gapcounts.scaleColLabel = true;
1987 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
1989 alignment.addAnnotation(gapcounts);
1993 private void initConservation()
1995 if (showConservation)
1997 if (conservation == null)
1999 conservation = new AlignmentAnnotation("Conservation",
2000 MessageManager.formatMessage("label.conservation_descr",
2001 getConsPercGaps()), new Annotation[1],
2002 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2003 conservation.hasText = true;
2004 conservation.autoCalculated = true;
2005 alignment.addAnnotation(conservation);
2010 private void initQuality()
2014 if (quality == null)
2016 quality = new AlignmentAnnotation("Quality",
2017 MessageManager.getString("label.quality_descr"),
2018 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2019 quality.hasText = true;
2020 quality.autoCalculated = true;
2021 alignment.addAnnotation(quality);
2026 private void initRNAStructure()
2028 if (alignment.hasRNAStructure() && strucConsensus == null)
2030 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2031 MessageManager.getString("label.strucconsensus_descr"),
2032 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2033 strucConsensus.hasText = true;
2034 strucConsensus.autoCalculated = true;
2038 alignment.addAnnotation(strucConsensus);
2046 * @see jalview.api.AlignViewportI#calcPanelHeight()
2049 public int calcPanelHeight()
2051 // setHeight of panels
2052 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2054 int charHeight = getCharHeight();
2057 BitSet graphgrp = new BitSet();
2058 for (AlignmentAnnotation aa : anns)
2062 System.err.println("Null annotation row: ignoring.");
2069 if (aa.graphGroup > -1)
2071 if (graphgrp.get(aa.graphGroup))
2077 graphgrp.set(aa.graphGroup);
2084 aa.height += charHeight;
2094 aa.height += aa.graphHeight;
2102 height += aa.height;
2114 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2115 boolean preserveNewGroupSettings)
2117 boolean updateCalcs = false;
2118 boolean conv = isShowGroupConservation();
2119 boolean cons = isShowGroupConsensus();
2120 boolean showprf = isShowSequenceLogo();
2121 boolean showConsHist = isShowConsensusHistogram();
2122 boolean normLogo = isNormaliseSequenceLogo();
2125 * TODO reorder the annotation rows according to group/sequence ordering on
2128 boolean sortg = true;
2130 // remove old automatic annotation
2131 // add any new annotation
2133 // intersect alignment annotation with alignment groups
2135 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2136 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2139 for (int an = 0; an < aan.length; an++)
2141 if (aan[an].autoCalculated && aan[an].groupRef != null)
2143 oldrfs.add(aan[an].groupRef);
2144 alignment.deleteAnnotation(aan[an], false);
2148 if (alignment.getGroups() != null)
2150 for (SequenceGroup sg : alignment.getGroups())
2152 updateCalcs = false;
2153 if (applyGlobalSettings
2154 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2156 // set defaults for this group's conservation/consensus
2157 sg.setshowSequenceLogo(showprf);
2158 sg.setShowConsensusHistogram(showConsHist);
2159 sg.setNormaliseSequenceLogo(normLogo);
2164 alignment.addAnnotation(sg.getConservationRow(), 0);
2169 alignment.addAnnotation(sg.getConsensus(), 0);
2171 // refresh the annotation rows
2174 sg.recalcConservation();
2182 public boolean isDisplayReferenceSeq()
2184 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2188 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2190 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2194 public boolean isColourByReferenceSeq()
2196 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2200 public Color getSequenceColour(SequenceI seq)
2202 Color sqc = sequenceColours.get(seq);
2203 return (sqc == null ? Color.white : sqc);
2207 public void setSequenceColour(SequenceI seq, Color col)
2211 sequenceColours.remove(seq);
2215 sequenceColours.put(seq, col);
2220 public void updateSequenceIdColours()
2222 for (SequenceGroup sg : alignment.getGroups())
2224 if (sg.idColour != null)
2226 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2228 sequenceColours.put(s, sg.idColour);
2235 public void clearSequenceColours()
2237 sequenceColours.clear();
2241 public AlignViewportI getCodingComplement()
2243 return this.codingComplement;
2247 * Set this as the (cDna/protein) complement of the given viewport. Also
2248 * ensures the reverse relationship is set on the given viewport.
2251 public void setCodingComplement(AlignViewportI av)
2255 System.err.println("Ignoring recursive setCodingComplement request");
2259 this.codingComplement = av;
2260 // avoid infinite recursion!
2261 if (av.getCodingComplement() != this)
2263 av.setCodingComplement(this);
2269 public boolean isNucleotide()
2271 return getAlignment() == null ? false : getAlignment().isNucleotide();
2275 public FeaturesDisplayedI getFeaturesDisplayed()
2277 return featuresDisplayed;
2281 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2283 featuresDisplayed = featuresDisplayedI;
2287 public boolean areFeaturesDisplayed()
2289 return featuresDisplayed != null
2290 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2297 * features are displayed if true
2300 public void setShowSequenceFeatures(boolean b)
2302 viewStyle.setShowSequenceFeatures(b);
2306 public boolean isShowSequenceFeatures()
2308 return viewStyle.isShowSequenceFeatures();
2312 public void setShowSequenceFeaturesHeight(boolean selected)
2314 viewStyle.setShowSequenceFeaturesHeight(selected);
2318 public boolean isShowSequenceFeaturesHeight()
2320 return viewStyle.isShowSequenceFeaturesHeight();
2324 public void setShowAnnotation(boolean b)
2326 viewStyle.setShowAnnotation(b);
2330 public boolean isShowAnnotation()
2332 return viewStyle.isShowAnnotation();
2336 public boolean isRightAlignIds()
2338 return viewStyle.isRightAlignIds();
2342 public void setRightAlignIds(boolean rightAlignIds)
2344 viewStyle.setRightAlignIds(rightAlignIds);
2348 public boolean getConservationSelected()
2350 return viewStyle.getConservationSelected();
2354 public void setShowBoxes(boolean state)
2356 viewStyle.setShowBoxes(state);
2361 * @see jalview.api.ViewStyleI#getTextColour()
2364 public Color getTextColour()
2366 return viewStyle.getTextColour();
2371 * @see jalview.api.ViewStyleI#getTextColour2()
2374 public Color getTextColour2()
2376 return viewStyle.getTextColour2();
2381 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2384 public int getThresholdTextColour()
2386 return viewStyle.getThresholdTextColour();
2391 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2394 public boolean isConservationColourSelected()
2396 return viewStyle.isConservationColourSelected();
2401 * @see jalview.api.ViewStyleI#isRenderGaps()
2404 public boolean isRenderGaps()
2406 return viewStyle.isRenderGaps();
2411 * @see jalview.api.ViewStyleI#isShowColourText()
2414 public boolean isShowColourText()
2416 return viewStyle.isShowColourText();
2420 * @param conservationColourSelected
2421 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2424 public void setConservationColourSelected(
2425 boolean conservationColourSelected)
2427 viewStyle.setConservationColourSelected(conservationColourSelected);
2431 * @param showColourText
2432 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2435 public void setShowColourText(boolean showColourText)
2437 viewStyle.setShowColourText(showColourText);
2442 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2445 public void setTextColour(Color textColour)
2447 viewStyle.setTextColour(textColour);
2451 * @param thresholdTextColour
2452 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2455 public void setThresholdTextColour(int thresholdTextColour)
2457 viewStyle.setThresholdTextColour(thresholdTextColour);
2461 * @param textColour2
2462 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2465 public void setTextColour2(Color textColour2)
2467 viewStyle.setTextColour2(textColour2);
2471 public ViewStyleI getViewStyle()
2473 return new ViewStyle(viewStyle);
2477 public void setViewStyle(ViewStyleI settingsForView)
2479 viewStyle = new ViewStyle(settingsForView);
2480 if (residueShading != null)
2482 residueShading.setConservationApplied(settingsForView
2483 .isConservationColourSelected());
2488 public boolean sameStyle(ViewStyleI them)
2490 return viewStyle.sameStyle(them);
2495 * @see jalview.api.ViewStyleI#getIdWidth()
2498 public int getIdWidth()
2500 return viewStyle.getIdWidth();
2505 * @see jalview.api.ViewStyleI#setIdWidth(int)
2508 public void setIdWidth(int i)
2510 viewStyle.setIdWidth(i);
2515 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2518 public boolean isCentreColumnLabels()
2520 return viewStyle.isCentreColumnLabels();
2524 * @param centreColumnLabels
2525 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2528 public void setCentreColumnLabels(boolean centreColumnLabels)
2530 viewStyle.setCentreColumnLabels(centreColumnLabels);
2535 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2538 public void setShowDBRefs(boolean showdbrefs)
2540 viewStyle.setShowDBRefs(showdbrefs);
2545 * @see jalview.api.ViewStyleI#isShowDBRefs()
2548 public boolean isShowDBRefs()
2550 return viewStyle.isShowDBRefs();
2555 * @see jalview.api.ViewStyleI#isShowNPFeats()
2558 public boolean isShowNPFeats()
2560 return viewStyle.isShowNPFeats();
2564 * @param shownpfeats
2565 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2568 public void setShowNPFeats(boolean shownpfeats)
2570 viewStyle.setShowNPFeats(shownpfeats);
2573 public abstract StructureSelectionManager getStructureSelectionManager();
2576 * Add one command to the command history list.
2580 public void addToHistoryList(CommandI command)
2582 if (this.historyList != null)
2584 this.historyList.push(command);
2585 broadcastCommand(command, false);
2589 protected void broadcastCommand(CommandI command, boolean undo)
2591 getStructureSelectionManager().commandPerformed(command, undo,
2596 * Add one command to the command redo list.
2600 public void addToRedoList(CommandI command)
2602 if (this.redoList != null)
2604 this.redoList.push(command);
2606 broadcastCommand(command, true);
2610 * Clear the command redo list.
2612 public void clearRedoList()
2614 if (this.redoList != null)
2616 this.redoList.clear();
2620 public void setHistoryList(Deque<CommandI> list)
2622 this.historyList = list;
2625 public Deque<CommandI> getHistoryList()
2627 return this.historyList;
2630 public void setRedoList(Deque<CommandI> list)
2632 this.redoList = list;
2635 public Deque<CommandI> getRedoList()
2637 return this.redoList;
2641 public VamsasSource getVamsasSource()
2646 public SequenceAnnotationOrder getSortAnnotationsBy()
2648 return sortAnnotationsBy;
2651 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2653 this.sortAnnotationsBy = sortAnnotationsBy;
2656 public boolean isShowAutocalculatedAbove()
2658 return showAutocalculatedAbove;
2661 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2663 this.showAutocalculatedAbove = showAutocalculatedAbove;
2667 public boolean isScaleProteinAsCdna()
2669 return viewStyle.isScaleProteinAsCdna();
2673 public void setScaleProteinAsCdna(boolean b)
2675 viewStyle.setScaleProteinAsCdna(b);
2679 public boolean isProteinFontAsCdna()
2681 return viewStyle.isProteinFontAsCdna();
2685 public void setProteinFontAsCdna(boolean b)
2687 viewStyle.setProteinFontAsCdna(b);
2691 * @return true if view should scroll to show the highlighted region of a
2696 public final boolean isFollowHighlight()
2698 return followHighlight;
2702 public final void setFollowHighlight(boolean b)
2704 this.followHighlight = b;
2708 public ViewportRanges getRanges()
2714 * Helper method to populate the SearchResults with the location in the
2715 * complementary alignment to scroll to, in order to match this one.
2718 * the SearchResults to add to
2719 * @return the offset (below top of visible region) of the matched sequence
2721 protected int findComplementScrollTarget(SearchResultsI sr)
2723 final AlignViewportI complement = getCodingComplement();
2724 if (complement == null || !complement.isFollowHighlight())
2728 boolean iAmProtein = !getAlignment().isNucleotide();
2729 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2731 if (proteinAlignment == null)
2735 final List<AlignedCodonFrame> mappings = proteinAlignment
2739 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2740 * residue in the middle column of the visible region. Scroll the
2741 * complementary alignment to line up the corresponding residue.
2744 SequenceI sequence = null;
2747 * locate 'middle' column (true middle if an odd number visible, left of
2748 * middle if an even number visible)
2750 int middleColumn = ranges.getStartRes()
2751 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2752 final HiddenSequences hiddenSequences = getAlignment()
2753 .getHiddenSequences();
2756 * searching to the bottom of the alignment gives smoother scrolling across
2757 * all gapped visible regions
2759 int lastSeq = alignment.getHeight() - 1;
2760 List<AlignedCodonFrame> seqMappings = null;
2761 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2763 sequence = getAlignment().getSequenceAt(seqNo);
2764 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2768 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2772 seqMappings = MappingUtils
2773 .findMappingsForSequenceAndOthers(sequence, mappings,
2774 getCodingComplement().getAlignment().getSequences());
2775 if (!seqMappings.isEmpty())
2781 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2784 * No ungapped mapped sequence in middle column - do nothing
2788 MappingUtils.addSearchResults(sr, sequence,
2789 sequence.findPosition(middleColumn), seqMappings);
2794 * synthesize a column selection if none exists so it covers the given
2795 * selection group. if wholewidth is false, no column selection is made if the
2796 * selection group covers the whole alignment width.
2801 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2804 if (sg != null && (sgs = sg.getStartRes()) >= 0
2805 && sg.getStartRes() <= (sge = sg.getEndRes())
2806 && !this.hasSelectedColumns())
2808 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2815 colSel = new ColumnSelection();
2817 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2819 colSel.addElement(cspos);
2825 * hold status of current selection group - defined on alignment or not.
2827 private boolean selectionIsDefinedGroup = false;
2830 public boolean isSelectionDefinedGroup()
2832 if (selectionGroup == null)
2836 if (isSelectionGroupChanged(true))
2838 selectionIsDefinedGroup = false;
2839 List<SequenceGroup> gps = alignment.getGroups();
2840 if (gps == null || gps.size() == 0)
2842 selectionIsDefinedGroup = false;
2846 selectionIsDefinedGroup = gps.contains(selectionGroup);
2849 return selectionGroup.getContext() == alignment
2850 || selectionIsDefinedGroup;
2854 * null, or currently highlighted results on this view
2856 private SearchResultsI searchResults = null;
2859 public boolean hasSearchResults()
2861 return searchResults != null;
2865 public void setSearchResults(SearchResultsI results)
2867 searchResults = results;
2871 public SearchResultsI getSearchResults()
2873 return searchResults;