2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import java.awt.Color;
24 import java.beans.PropertyChangeSupport;
25 import java.util.ArrayDeque;
26 import java.util.ArrayList;
27 import java.util.BitSet;
28 import java.util.Deque;
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.List;
34 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
35 import jalview.analysis.Conservation;
36 import jalview.api.AlignCalcManagerI;
37 import jalview.api.AlignViewportI;
38 import jalview.api.AlignmentViewPanel;
39 import jalview.api.FeaturesDisplayedI;
40 import jalview.api.ViewStyleI;
41 import jalview.commands.CommandI;
42 import jalview.datamodel.AlignedCodonFrame;
43 import jalview.datamodel.AlignmentAnnotation;
44 import jalview.datamodel.AlignmentI;
45 import jalview.datamodel.AlignmentView;
46 import jalview.datamodel.Annotation;
47 import jalview.datamodel.CigarArray;
48 import jalview.datamodel.ColumnSelection;
49 import jalview.datamodel.HiddenSequences;
50 import jalview.datamodel.ProfilesI;
51 import jalview.datamodel.SearchResultsI;
52 import jalview.datamodel.Sequence;
53 import jalview.datamodel.SequenceCollectionI;
54 import jalview.datamodel.SequenceGroup;
55 import jalview.datamodel.SequenceI;
56 import jalview.renderer.ResidueShader;
57 import jalview.renderer.ResidueShaderI;
58 import jalview.schemes.ColourSchemeI;
59 import jalview.structure.CommandListener;
60 import jalview.structure.StructureSelectionManager;
61 import jalview.structure.VamsasSource;
62 import jalview.util.Comparison;
63 import jalview.util.MapList;
64 import jalview.util.MappingUtils;
65 import jalview.viewmodel.styles.ViewStyle;
66 import jalview.workers.AlignCalcManager;
67 import jalview.workers.ComplementConsensusThread;
68 import jalview.workers.ConsensusThread;
69 import jalview.workers.StrucConsensusThread;
72 * base class holding visualization and analysis attributes and common logic for
73 * an active alignment view displayed in the GUI
78 public abstract class AlignmentViewport implements AlignViewportI,
79 CommandListener, VamsasSource
81 final protected ViewportRanges ranges;
83 protected ViewStyleI viewStyle = new ViewStyle();
86 * A viewport that hosts the cDna view of this (protein), or vice versa (if
89 AlignViewportI codingComplement = null;
91 FeaturesDisplayedI featuresDisplayed = null;
93 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
95 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
98 * alignment displayed in the viewport. Please use get/setter
100 protected AlignmentI alignment;
102 public AlignmentViewport(AlignmentI al)
105 ranges = new ViewportRanges(al);
110 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
113 public void setFontName(String name)
115 viewStyle.setFontName(name);
120 * @see jalview.api.ViewStyleI#setFontStyle(int)
123 public void setFontStyle(int style)
125 viewStyle.setFontStyle(style);
130 * @see jalview.api.ViewStyleI#setFontSize(int)
133 public void setFontSize(int size)
135 viewStyle.setFontSize(size);
140 * @see jalview.api.ViewStyleI#getFontStyle()
143 public int getFontStyle()
145 return viewStyle.getFontStyle();
150 * @see jalview.api.ViewStyleI#getFontName()
153 public String getFontName()
155 return viewStyle.getFontName();
160 * @see jalview.api.ViewStyleI#getFontSize()
163 public int getFontSize()
165 return viewStyle.getFontSize();
169 * @param upperCasebold
170 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
173 public void setUpperCasebold(boolean upperCasebold)
175 viewStyle.setUpperCasebold(upperCasebold);
180 * @see jalview.api.ViewStyleI#isUpperCasebold()
183 public boolean isUpperCasebold()
185 return viewStyle.isUpperCasebold();
190 * @see jalview.api.ViewStyleI#isSeqNameItalics()
193 public boolean isSeqNameItalics()
195 return viewStyle.isSeqNameItalics();
199 * @param colourByReferenceSeq
200 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
203 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
205 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
210 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
213 public void setColourAppliesToAllGroups(boolean b)
215 viewStyle.setColourAppliesToAllGroups(b);
220 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
223 public boolean getColourAppliesToAllGroups()
225 return viewStyle.getColourAppliesToAllGroups();
230 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
233 public boolean getAbovePIDThreshold()
235 return viewStyle.getAbovePIDThreshold();
240 * @see jalview.api.ViewStyleI#setIncrement(int)
243 public void setIncrement(int inc)
245 viewStyle.setIncrement(inc);
250 * @see jalview.api.ViewStyleI#getIncrement()
253 public int getIncrement()
255 return viewStyle.getIncrement();
260 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
263 public void setConservationSelected(boolean b)
265 viewStyle.setConservationSelected(b);
270 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
273 public void setShowHiddenMarkers(boolean show)
275 viewStyle.setShowHiddenMarkers(show);
280 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
283 public boolean getShowHiddenMarkers()
285 return viewStyle.getShowHiddenMarkers();
290 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
293 public void setScaleRightWrapped(boolean b)
295 viewStyle.setScaleRightWrapped(b);
300 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
303 public void setScaleLeftWrapped(boolean b)
305 viewStyle.setScaleLeftWrapped(b);
310 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
313 public void setScaleAboveWrapped(boolean b)
315 viewStyle.setScaleAboveWrapped(b);
320 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
323 public boolean getScaleLeftWrapped()
325 return viewStyle.getScaleLeftWrapped();
330 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
333 public boolean getScaleAboveWrapped()
335 return viewStyle.getScaleAboveWrapped();
340 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
343 public boolean getScaleRightWrapped()
345 return viewStyle.getScaleRightWrapped();
350 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
353 public void setAbovePIDThreshold(boolean b)
355 viewStyle.setAbovePIDThreshold(b);
360 * @see jalview.api.ViewStyleI#setThreshold(int)
363 public void setThreshold(int thresh)
365 viewStyle.setThreshold(thresh);
370 * @see jalview.api.ViewStyleI#getThreshold()
373 public int getThreshold()
375 return viewStyle.getThreshold();
380 * @see jalview.api.ViewStyleI#getShowJVSuffix()
383 public boolean getShowJVSuffix()
385 return viewStyle.getShowJVSuffix();
390 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
393 public void setShowJVSuffix(boolean b)
395 viewStyle.setShowJVSuffix(b);
400 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
403 public void setWrapAlignment(boolean state)
405 viewStyle.setWrapAlignment(state);
410 * @see jalview.api.ViewStyleI#setShowText(boolean)
413 public void setShowText(boolean state)
415 viewStyle.setShowText(state);
420 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
423 public void setRenderGaps(boolean state)
425 viewStyle.setRenderGaps(state);
430 * @see jalview.api.ViewStyleI#getColourText()
433 public boolean getColourText()
435 return viewStyle.getColourText();
440 * @see jalview.api.ViewStyleI#setColourText(boolean)
443 public void setColourText(boolean state)
445 viewStyle.setColourText(state);
450 * @see jalview.api.ViewStyleI#getWrapAlignment()
453 public boolean getWrapAlignment()
455 return viewStyle.getWrapAlignment();
460 * @see jalview.api.ViewStyleI#getShowText()
463 public boolean getShowText()
465 return viewStyle.getShowText();
470 * @see jalview.api.ViewStyleI#getWrappedWidth()
473 public int getWrappedWidth()
475 return viewStyle.getWrappedWidth();
480 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
483 public void setWrappedWidth(int w)
485 viewStyle.setWrappedWidth(w);
490 * @see jalview.api.ViewStyleI#getCharHeight()
493 public int getCharHeight()
495 return viewStyle.getCharHeight();
500 * @see jalview.api.ViewStyleI#setCharHeight(int)
503 public void setCharHeight(int h)
505 viewStyle.setCharHeight(h);
510 * @see jalview.api.ViewStyleI#getCharWidth()
513 public int getCharWidth()
515 return viewStyle.getCharWidth();
520 * @see jalview.api.ViewStyleI#setCharWidth(int)
523 public void setCharWidth(int w)
525 viewStyle.setCharWidth(w);
530 * @see jalview.api.ViewStyleI#getShowBoxes()
533 public boolean getShowBoxes()
535 return viewStyle.getShowBoxes();
540 * @see jalview.api.ViewStyleI#getShowUnconserved()
543 public boolean getShowUnconserved()
545 return viewStyle.getShowUnconserved();
549 * @param showunconserved
550 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
553 public void setShowUnconserved(boolean showunconserved)
555 viewStyle.setShowUnconserved(showunconserved);
560 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
563 public void setSeqNameItalics(boolean default1)
565 viewStyle.setSeqNameItalics(default1);
571 public AlignmentI getAlignment()
577 public char getGapCharacter()
579 return alignment.getGapCharacter();
582 protected String sequenceSetID;
585 * probably unused indicator that view is of a dataset rather than an
588 protected boolean isDataset = false;
590 public void setDataset(boolean b)
595 public boolean isDataset()
600 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
602 protected ColumnSelection colSel = new ColumnSelection();
604 public boolean autoCalculateConsensus = true;
606 protected boolean autoCalculateStrucConsensus = true;
608 protected boolean ignoreGapsInConsensusCalculation = false;
610 protected ResidueShaderI residueShading;
613 public void setGlobalColourScheme(ColourSchemeI cs)
615 // TODO: logic refactored from AlignFrame changeColour -
616 // TODO: autorecalc stuff should be changed to rely on the worker system
617 // check to see if we should implement a changeColour(cs) method rather than
618 // put the logic in here
619 // - means that caller decides if they want to just modify state and defer
620 // calculation till later or to do all calculations in thread.
624 * only instantiate alignment colouring once, thereafter update it;
625 * this means that any conservation or PID threshold settings
626 * persist when the alignment colour scheme is changed
628 if (residueShading == null)
630 residueShading = new ResidueShader(viewStyle);
632 residueShading.setColourScheme(cs);
634 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
635 // ...problem: groups need these, but do not currently have a ViewStyle
639 if (getConservationSelected())
641 residueShading.setConservation(hconservation);
643 residueShading.alignmentChanged(alignment, hiddenRepSequences);
647 * if 'apply colour to all groups' is selected... do so
648 * (but don't transfer any colour threshold settings to groups)
650 if (getColourAppliesToAllGroups())
652 for (SequenceGroup sg : getAlignment().getGroups())
655 * retain any colour thresholds per group while
656 * changing choice of colour scheme (JAL-2386)
658 sg.setColourScheme(cs);
661 sg.getGroupColourScheme()
662 .alignmentChanged(sg, hiddenRepSequences);
669 public ColourSchemeI getGlobalColourScheme()
671 return residueShading == null ? null : residueShading
676 public ResidueShaderI getResidueShading()
678 return residueShading;
681 protected AlignmentAnnotation consensus;
683 protected AlignmentAnnotation complementConsensus;
685 protected AlignmentAnnotation gapcounts;
687 protected AlignmentAnnotation strucConsensus;
689 protected AlignmentAnnotation conservation;
691 protected AlignmentAnnotation quality;
693 protected AlignmentAnnotation[] groupConsensus;
695 protected AlignmentAnnotation[] groupConservation;
698 * results of alignment consensus analysis for visible portion of view
700 protected ProfilesI hconsensus = null;
703 * results of cDNA complement consensus visible portion of view
705 protected Hashtable[] hcomplementConsensus = null;
708 * results of secondary structure base pair consensus for visible portion of
711 protected Hashtable[] hStrucConsensus = null;
713 protected Conservation hconservation = null;
716 public void setConservation(Conservation cons)
718 hconservation = cons;
722 * percentage gaps allowed in a column before all amino acid properties should
723 * be considered unconserved
725 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
728 public int getConsPercGaps()
734 public void setSequenceConsensusHash(ProfilesI hconsensus)
736 this.hconsensus = hconsensus;
740 public void setComplementConsensusHash(Hashtable[] hconsensus)
742 this.hcomplementConsensus = hconsensus;
746 public ProfilesI getSequenceConsensusHash()
752 public Hashtable[] getComplementConsensusHash()
754 return hcomplementConsensus;
758 public Hashtable[] getRnaStructureConsensusHash()
760 return hStrucConsensus;
764 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
766 this.hStrucConsensus = hStrucConsensus;
771 public AlignmentAnnotation getAlignmentQualityAnnot()
777 public AlignmentAnnotation getAlignmentConservationAnnotation()
783 public AlignmentAnnotation getAlignmentConsensusAnnotation()
789 public AlignmentAnnotation getAlignmentGapAnnotation()
795 public AlignmentAnnotation getComplementConsensusAnnotation()
797 return complementConsensus;
801 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
803 return strucConsensus;
806 protected AlignCalcManagerI calculator = new AlignCalcManager();
809 * trigger update of conservation annotation
811 public void updateConservation(final AlignmentViewPanel ap)
813 // see note in mantis : issue number 8585
814 if (alignment.isNucleotide()
815 || (conservation == null && quality == null)
816 || !autoCalculateConsensus)
821 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
823 calculator.registerWorker(new jalview.workers.ConservationThread(
829 * trigger update of consensus annotation
831 public void updateConsensus(final AlignmentViewPanel ap)
833 // see note in mantis : issue number 8585
834 if ((consensus == null || gapcounts == null) || !autoCalculateConsensus)
838 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
840 calculator.registerWorker(new ConsensusThread(this, ap));
844 * A separate thread to compute cDNA consensus for a protein alignment
845 * which has mapping to cDNA
847 final AlignmentI al = this.getAlignment();
848 if (!al.isNucleotide() && al.getCodonFrames() != null
849 && !al.getCodonFrames().isEmpty())
852 * fudge - check first for protein-to-nucleotide mappings
853 * (we don't want to do this for protein-to-protein)
855 boolean doConsensus = false;
856 for (AlignedCodonFrame mapping : al.getCodonFrames())
858 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
859 MapList[] mapLists = mapping.getdnaToProt();
860 // mapLists can be empty if project load has not finished resolving seqs
861 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
870 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
873 .registerWorker(new ComplementConsensusThread(this, ap));
879 // --------START Structure Conservation
880 public void updateStrucConsensus(final AlignmentViewPanel ap)
882 if (autoCalculateStrucConsensus && strucConsensus == null
883 && alignment.isNucleotide() && alignment.hasRNAStructure())
885 // secondary structure has been added - so init the consensus line
889 // see note in mantis : issue number 8585
890 if (strucConsensus == null || !autoCalculateStrucConsensus)
894 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
896 calculator.registerWorker(new StrucConsensusThread(this, ap));
900 public boolean isCalcInProgress()
902 return calculator.isWorking();
906 public boolean isCalculationInProgress(
907 AlignmentAnnotation alignmentAnnotation)
909 if (!alignmentAnnotation.autoCalculated)
913 if (calculator.workingInvolvedWith(alignmentAnnotation))
915 // System.err.println("grey out ("+alignmentAnnotation.label+")");
921 public void setAlignment(AlignmentI align)
923 this.alignment = align;
927 * Clean up references when this viewport is closed
930 public void dispose()
933 * defensively null out references to large objects in case
934 * this object is not garbage collected (as if!)
937 complementConsensus = null;
938 strucConsensus = null;
941 groupConsensus = null;
942 groupConservation = null;
944 hcomplementConsensus = null;
945 // colour scheme may hold reference to consensus
946 residueShading = null;
947 // TODO remove listeners from changeSupport?
948 changeSupport = null;
953 public boolean isClosed()
955 // TODO: check that this isClosed is only true after panel is closed, not
956 // before it is fully constructed.
957 return alignment == null;
961 public AlignCalcManagerI getCalcManager()
967 * should conservation rows be shown for groups
969 protected boolean showGroupConservation = false;
972 * should consensus rows be shown for groups
974 protected boolean showGroupConsensus = false;
977 * should consensus profile be rendered by default
979 protected boolean showSequenceLogo = false;
982 * should consensus profile be rendered normalised to row height
984 protected boolean normaliseSequenceLogo = false;
987 * should consensus histograms be rendered by default
989 protected boolean showConsensusHistogram = true;
992 * @return the showConsensusProfile
995 public boolean isShowSequenceLogo()
997 return showSequenceLogo;
1001 * @param showSequenceLogo
1004 public void setShowSequenceLogo(boolean showSequenceLogo)
1006 if (showSequenceLogo != this.showSequenceLogo)
1008 // TODO: decouple settings setting from calculation when refactoring
1009 // annotation update method from alignframe to viewport
1010 this.showSequenceLogo = showSequenceLogo;
1011 calculator.updateAnnotationFor(ConsensusThread.class);
1012 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1013 calculator.updateAnnotationFor(StrucConsensusThread.class);
1015 this.showSequenceLogo = showSequenceLogo;
1019 * @param showConsensusHistogram
1020 * the showConsensusHistogram to set
1022 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1024 this.showConsensusHistogram = showConsensusHistogram;
1028 * @return the showGroupConservation
1030 public boolean isShowGroupConservation()
1032 return showGroupConservation;
1036 * @param showGroupConservation
1037 * the showGroupConservation to set
1039 public void setShowGroupConservation(boolean showGroupConservation)
1041 this.showGroupConservation = showGroupConservation;
1045 * @return the showGroupConsensus
1047 public boolean isShowGroupConsensus()
1049 return showGroupConsensus;
1053 * @param showGroupConsensus
1054 * the showGroupConsensus to set
1056 public void setShowGroupConsensus(boolean showGroupConsensus)
1058 this.showGroupConsensus = showGroupConsensus;
1063 * @return flag to indicate if the consensus histogram should be rendered by
1067 public boolean isShowConsensusHistogram()
1069 return this.showConsensusHistogram;
1073 * when set, updateAlignment will always ensure sequences are of equal length
1075 private boolean padGaps = false;
1078 * when set, alignment should be reordered according to a newly opened tree
1080 public boolean sortByTree = false;
1085 * @return null or the currently selected sequence region
1088 public SequenceGroup getSelectionGroup()
1090 return selectionGroup;
1094 * Set the selection group for this window. Also sets the current alignment as
1095 * the context for the group, if it does not already have one.
1098 * - group holding references to sequences in this alignment view
1102 public void setSelectionGroup(SequenceGroup sg)
1104 selectionGroup = sg;
1105 if (sg != null && sg.getContext() == null)
1107 sg.setContext(alignment);
1111 public void setHiddenColumns(ColumnSelection colsel)
1113 this.colSel = colsel;
1117 public ColumnSelection getColumnSelection()
1123 public void setColumnSelection(ColumnSelection colSel)
1125 this.colSel = colSel;
1128 updateHiddenColumns();
1130 isColSelChanged(true);
1138 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1140 return hiddenRepSequences;
1144 public void setHiddenRepSequences(
1145 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1147 this.hiddenRepSequences = hiddenRepSequences;
1151 public boolean hasSelectedColumns()
1153 ColumnSelection columnSelection = getColumnSelection();
1154 return columnSelection != null && columnSelection.hasSelectedColumns();
1158 public boolean hasHiddenColumns()
1160 return colSel != null && colSel.hasHiddenColumns();
1163 public void updateHiddenColumns()
1165 // this method doesn't really do anything now. But - it could, since a
1166 // column Selection could be in the process of modification
1167 // hasHiddenColumns = colSel.hasHiddenColumns();
1171 public boolean hasHiddenRows()
1173 return alignment.getHiddenSequences().getSize() > 0;
1176 protected SequenceGroup selectionGroup;
1178 public void setSequenceSetId(String newid)
1180 if (sequenceSetID != null)
1183 .println("Warning - overwriting a sequenceSetId for a viewport!");
1185 sequenceSetID = new String(newid);
1189 public String getSequenceSetId()
1191 if (sequenceSetID == null)
1193 sequenceSetID = alignment.hashCode() + "";
1196 return sequenceSetID;
1200 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1203 protected String viewId = null;
1206 public String getViewId()
1210 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1215 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1217 ignoreGapsInConsensusCalculation = b;
1220 updateConsensus(ap);
1221 if (residueShading != null)
1223 residueShading.setThreshold(residueShading.getThreshold(),
1224 ignoreGapsInConsensusCalculation);
1230 private long sgrouphash = -1, colselhash = -1;
1233 * checks current SelectionGroup against record of last hash value, and
1237 * update the record of last hash value
1239 * @return true if SelectionGroup changed since last call (when b is true)
1241 public boolean isSelectionGroupChanged(boolean b)
1243 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1244 : selectionGroup.hashCode();
1245 if (hc != -1 && hc != sgrouphash)
1257 * checks current colsel against record of last hash value, and optionally
1261 * update the record of last hash value
1262 * @return true if colsel changed since last call (when b is true)
1264 public boolean isColSelChanged(boolean b)
1266 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1267 if (hc != -1 && hc != colselhash)
1279 public boolean isIgnoreGapsConsensus()
1281 return ignoreGapsInConsensusCalculation;
1284 // property change stuff
1285 // JBPNote Prolly only need this in the applet version.
1286 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1289 protected boolean showConservation = true;
1291 protected boolean showQuality = true;
1293 protected boolean showConsensus = true;
1295 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1297 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1299 protected boolean showAutocalculatedAbove;
1302 * when set, view will scroll to show the highlighted position
1304 private boolean followHighlight = true;
1307 * Property change listener for changes in alignment
1312 public void addPropertyChangeListener(
1313 java.beans.PropertyChangeListener listener)
1315 changeSupport.addPropertyChangeListener(listener);
1324 public void removePropertyChangeListener(
1325 java.beans.PropertyChangeListener listener)
1327 changeSupport.removePropertyChangeListener(listener);
1331 * Property change listener for changes in alignment
1340 public void firePropertyChange(String prop, Object oldvalue,
1343 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1346 // common hide/show column stuff
1348 public void hideSelectedColumns()
1350 if (colSel.isEmpty())
1355 colSel.hideSelectedColumns();
1356 setSelectionGroup(null);
1357 isColSelChanged(true);
1360 public void hideColumns(int start, int end)
1364 colSel.hideColumns(start);
1368 colSel.hideColumns(start, end);
1370 isColSelChanged(true);
1373 public void showColumn(int col)
1375 colSel.revealHiddenColumns(col);
1376 isColSelChanged(true);
1379 public void showAllHiddenColumns()
1381 colSel.revealAllHiddenColumns();
1382 isColSelChanged(true);
1385 // common hide/show seq stuff
1386 public void showAllHiddenSeqs()
1388 if (alignment.getHiddenSequences().getSize() > 0)
1390 if (selectionGroup == null)
1392 selectionGroup = new SequenceGroup();
1393 selectionGroup.setEndRes(alignment.getWidth() - 1);
1395 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1396 hiddenRepSequences);
1397 for (SequenceI seq : tmp)
1399 selectionGroup.addSequence(seq, false);
1400 setSequenceAnnotationsVisible(seq, true);
1403 hiddenRepSequences = null;
1405 firePropertyChange("alignment", null, alignment.getSequences());
1406 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1412 public void showSequence(int index)
1414 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1415 index, hiddenRepSequences);
1418 if (selectionGroup == null)
1420 selectionGroup = new SequenceGroup();
1421 selectionGroup.setEndRes(alignment.getWidth() - 1);
1424 for (SequenceI seq : tmp)
1426 selectionGroup.addSequence(seq, false);
1427 setSequenceAnnotationsVisible(seq, true);
1429 firePropertyChange("alignment", null, alignment.getSequences());
1434 public void hideAllSelectedSeqs()
1436 if (selectionGroup == null || selectionGroup.getSize() < 1)
1441 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1445 setSelectionGroup(null);
1448 public void hideSequence(SequenceI[] seq)
1452 for (int i = 0; i < seq.length; i++)
1454 alignment.getHiddenSequences().hideSequence(seq[i]);
1455 setSequenceAnnotationsVisible(seq[i], false);
1457 firePropertyChange("alignment", null, alignment.getSequences());
1462 * Hides the specified sequence, or the sequences it represents
1465 * the sequence to hide, or keep as representative
1466 * @param representGroup
1467 * if true, hide the current selection group except for the
1468 * representative sequence
1470 public void hideSequences(SequenceI sequence, boolean representGroup)
1472 if (selectionGroup == null || selectionGroup.getSize() < 1)
1474 hideSequence(new SequenceI[] { sequence });
1480 hideRepSequences(sequence, selectionGroup);
1481 setSelectionGroup(null);
1485 int gsize = selectionGroup.getSize();
1486 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1487 new SequenceI[gsize]);
1489 hideSequence(hseqs);
1490 setSelectionGroup(null);
1495 * Set visibility for any annotations for the given sequence.
1499 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1502 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1505 for (AlignmentAnnotation ann : anns)
1507 if (ann.sequenceRef == sequenceI)
1509 ann.visible = visible;
1515 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1517 int sSize = sg.getSize();
1523 if (hiddenRepSequences == null)
1525 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1528 hiddenRepSequences.put(repSequence, sg);
1530 // Hide all sequences except the repSequence
1531 SequenceI[] seqs = new SequenceI[sSize - 1];
1533 for (int i = 0; i < sSize; i++)
1535 if (sg.getSequenceAt(i) != repSequence)
1537 if (index == sSize - 1)
1542 seqs[index++] = sg.getSequenceAt(i);
1545 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1546 sg.setHidereps(true); // note: not done in 2.7applet
1553 * @return null or the current reference sequence
1555 public SequenceI getReferenceSeq()
1557 return alignment.getSeqrep();
1562 * @return true iff seq is the reference for the alignment
1564 public boolean isReferenceSeq(SequenceI seq)
1566 return alignment.getSeqrep() == seq;
1572 * @return true if there are sequences represented by this sequence that are
1575 public boolean isHiddenRepSequence(SequenceI seq)
1577 return (hiddenRepSequences != null && hiddenRepSequences
1584 * @return null or a sequence group containing the sequences that seq
1587 public SequenceGroup getRepresentedSequences(SequenceI seq)
1589 return (SequenceGroup) (hiddenRepSequences == null ? null
1590 : hiddenRepSequences.get(seq));
1594 public int adjustForHiddenSeqs(int alignmentIndex)
1596 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1601 public void invertColumnSelection()
1603 colSel.invertColumnSelection(0, alignment.getWidth());
1607 public SequenceI[] getSelectionAsNewSequence()
1609 SequenceI[] sequences;
1610 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1611 // this was the only caller in the applet for this method
1612 // JBPNote: in applet, this method returned references to the alignment
1613 // sequences, and it did not honour the presence/absence of annotation
1614 // attached to the alignment (probably!)
1615 if (selectionGroup == null || selectionGroup.getSize() == 0)
1617 sequences = alignment.getSequencesArray();
1618 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1619 for (int i = 0; i < sequences.length; i++)
1621 // construct new sequence with subset of visible annotation
1622 sequences[i] = new Sequence(sequences[i], annots);
1627 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1634 public SequenceI[] getSequenceSelection()
1636 SequenceI[] sequences = null;
1637 if (selectionGroup != null)
1639 sequences = selectionGroup.getSequencesInOrder(alignment);
1641 if (sequences == null)
1643 sequences = alignment.getSequencesArray();
1649 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1651 return new CigarArray(alignment, colSel,
1652 (selectedRegionOnly ? selectionGroup : null));
1656 public jalview.datamodel.AlignmentView getAlignmentView(
1657 boolean selectedOnly)
1659 return getAlignmentView(selectedOnly, false);
1663 public jalview.datamodel.AlignmentView getAlignmentView(
1664 boolean selectedOnly, boolean markGroups)
1666 return new AlignmentView(alignment, colSel, selectionGroup,
1667 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
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 (colSel != null && colSel.hasHiddenColumns())
1713 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1717 for (i = 0; i < iSize; i++)
1719 selection[i] = seqs[i].getSequenceAsString(start, end);
1727 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1729 ArrayList<int[]> regions = new ArrayList<int[]>();
1735 if (colSel != null && colSel.hasHiddenColumns())
1739 start = colSel.adjustForHiddenColumns(start);
1742 end = colSel.getHiddenBoundaryRight(start);
1753 regions.add(new int[] { start, end });
1755 if (colSel != null && colSel.hasHiddenColumns())
1757 start = colSel.adjustForHiddenColumns(end);
1758 start = colSel.getHiddenBoundaryLeft(start) + 1;
1760 } while (end < max);
1762 int[][] startEnd = new int[regions.size()][2];
1768 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1769 boolean selectedOnly)
1771 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1772 AlignmentAnnotation[] aa;
1773 if ((aa = alignment.getAlignmentAnnotation()) != null)
1775 for (AlignmentAnnotation annot : aa)
1777 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1778 if (selectedOnly && selectionGroup != null)
1780 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1781 selectionGroup.getEndRes(), clone);
1785 colSel.makeVisibleAnnotation(clone);
1794 public boolean isPadGaps()
1800 public void setPadGaps(boolean padGaps)
1802 this.padGaps = padGaps;
1806 * apply any post-edit constraints and trigger any calculations needed after
1807 * an edit has been performed on the alignment
1812 public void alignmentChanged(AlignmentViewPanel ap)
1816 alignment.padGaps();
1818 if (autoCalculateConsensus)
1820 updateConsensus(ap);
1822 if (hconsensus != null && autoCalculateConsensus)
1824 updateConservation(ap);
1826 if (autoCalculateStrucConsensus)
1828 updateStrucConsensus(ap);
1831 // Reset endRes of groups if beyond alignment width
1832 int alWidth = alignment.getWidth();
1833 List<SequenceGroup> groups = alignment.getGroups();
1836 for (SequenceGroup sg : groups)
1838 if (sg.getEndRes() > alWidth)
1840 sg.setEndRes(alWidth - 1);
1845 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1847 selectionGroup.setEndRes(alWidth - 1);
1850 updateAllColourSchemes();
1851 calculator.restartWorkers();
1852 // alignment.adjustSequenceAnnotations();
1856 * reset scope and do calculations for all applied colourschemes on alignment
1858 void updateAllColourSchemes()
1860 ResidueShaderI rs = residueShading;
1863 rs.alignmentChanged(alignment, hiddenRepSequences);
1865 rs.setConsensus(hconsensus);
1866 if (rs.conservationApplied())
1868 rs.setConservation(Conservation.calculateConservation("All",
1869 alignment.getSequences(), 0, alignment.getWidth(), false,
1870 getConsPercGaps(), false));
1874 for (SequenceGroup sg : alignment.getGroups())
1878 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1880 sg.recalcConservation();
1884 protected void initAutoAnnotation()
1886 // TODO: add menu option action that nulls or creates consensus object
1887 // depending on if the user wants to see the annotation or not in a
1888 // specific alignment
1890 if (hconsensus == null && !isDataset)
1892 if (!alignment.isNucleotide())
1901 consensus = new AlignmentAnnotation("Consensus", "PID",
1902 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1903 initConsensus(consensus);
1904 gapcounts = new AlignmentAnnotation("Occupancy",
1905 "Number of aligned positions",
1906 new Annotation[1], 0f, alignment.getHeight(),
1907 AlignmentAnnotation.BAR_GRAPH);
1908 initGapCounts(gapcounts);
1910 initComplementConsensus();
1915 * If this is a protein alignment and there are mappings to cDNA, adds the
1916 * cDNA consensus annotation and returns true, else returns false.
1918 public boolean initComplementConsensus()
1920 if (!alignment.isNucleotide())
1922 final List<AlignedCodonFrame> codonMappings = alignment
1924 if (codonMappings != null && !codonMappings.isEmpty())
1926 boolean doConsensus = false;
1927 for (AlignedCodonFrame mapping : codonMappings)
1929 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1930 MapList[] mapLists = mapping.getdnaToProt();
1931 // mapLists can be empty if project load has not finished resolving
1933 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1941 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1942 "PID for cDNA", new Annotation[1], 0f, 100f,
1943 AlignmentAnnotation.BAR_GRAPH);
1944 initConsensus(complementConsensus);
1952 private void initConsensus(AlignmentAnnotation aa)
1955 aa.autoCalculated = true;
1959 alignment.addAnnotation(aa);
1963 // these should be extracted from the view model - style and settings for
1964 // derived annotation
1965 private void initGapCounts(AlignmentAnnotation counts)
1967 counts.hasText = false;
1968 counts.autoCalculated = true;
1969 counts.graph = AlignmentAnnotation.BAR_GRAPH;
1973 alignment.addAnnotation(counts);
1977 private void initConservation()
1979 if (showConservation)
1981 if (conservation == null)
1983 conservation = new AlignmentAnnotation("Conservation",
1984 "Conservation of total alignment less than "
1985 + getConsPercGaps() + "% gaps", new Annotation[1],
1986 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1987 conservation.hasText = true;
1988 conservation.autoCalculated = true;
1989 alignment.addAnnotation(conservation);
1994 private void initQuality()
1998 if (quality == null)
2000 quality = new AlignmentAnnotation("Quality",
2001 "Alignment Quality based on Blosum62 scores",
2002 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2003 quality.hasText = true;
2004 quality.autoCalculated = true;
2005 alignment.addAnnotation(quality);
2010 private void initRNAStructure()
2012 if (alignment.hasRNAStructure() && strucConsensus == null)
2014 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
2015 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2016 strucConsensus.hasText = true;
2017 strucConsensus.autoCalculated = true;
2021 alignment.addAnnotation(strucConsensus);
2029 * @see jalview.api.AlignViewportI#calcPanelHeight()
2032 public int calcPanelHeight()
2034 // setHeight of panels
2035 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2037 int charHeight = getCharHeight();
2040 BitSet graphgrp = new BitSet();
2041 for (AlignmentAnnotation aa : anns)
2045 System.err.println("Null annotation row: ignoring.");
2052 if (aa.graphGroup > -1)
2054 if (graphgrp.get(aa.graphGroup))
2060 graphgrp.set(aa.graphGroup);
2067 aa.height += charHeight;
2077 aa.height += aa.graphHeight;
2085 height += aa.height;
2097 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2098 boolean preserveNewGroupSettings)
2100 boolean updateCalcs = false;
2101 boolean conv = isShowGroupConservation();
2102 boolean cons = isShowGroupConsensus();
2103 boolean showprf = isShowSequenceLogo();
2104 boolean showConsHist = isShowConsensusHistogram();
2105 boolean normLogo = isNormaliseSequenceLogo();
2108 * TODO reorder the annotation rows according to group/sequence ordering on
2111 boolean sortg = true;
2113 // remove old automatic annotation
2114 // add any new annotation
2116 // intersect alignment annotation with alignment groups
2118 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2119 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2122 for (int an = 0; an < aan.length; an++)
2124 if (aan[an].autoCalculated && aan[an].groupRef != null)
2126 oldrfs.add(aan[an].groupRef);
2127 alignment.deleteAnnotation(aan[an], false);
2131 if (alignment.getGroups() != null)
2133 for (SequenceGroup sg : alignment.getGroups())
2135 updateCalcs = false;
2136 if (applyGlobalSettings
2137 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2139 // set defaults for this group's conservation/consensus
2140 sg.setshowSequenceLogo(showprf);
2141 sg.setShowConsensusHistogram(showConsHist);
2142 sg.setNormaliseSequenceLogo(normLogo);
2147 alignment.addAnnotation(sg.getConservationRow(), 0);
2152 alignment.addAnnotation(sg.getConsensus(), 0);
2154 // refresh the annotation rows
2157 sg.recalcConservation();
2165 public boolean isDisplayReferenceSeq()
2167 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2171 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2173 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2177 public boolean isColourByReferenceSeq()
2179 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2183 public Color getSequenceColour(SequenceI seq)
2185 Color sqc = sequenceColours.get(seq);
2186 return (sqc == null ? Color.white : sqc);
2190 public void setSequenceColour(SequenceI seq, Color col)
2194 sequenceColours.remove(seq);
2198 sequenceColours.put(seq, col);
2203 public void updateSequenceIdColours()
2205 for (SequenceGroup sg : alignment.getGroups())
2207 if (sg.idColour != null)
2209 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2211 sequenceColours.put(s, sg.idColour);
2218 public void clearSequenceColours()
2220 sequenceColours.clear();
2224 public AlignViewportI getCodingComplement()
2226 return this.codingComplement;
2230 * Set this as the (cDna/protein) complement of the given viewport. Also
2231 * ensures the reverse relationship is set on the given viewport.
2234 public void setCodingComplement(AlignViewportI av)
2238 System.err.println("Ignoring recursive setCodingComplement request");
2242 this.codingComplement = av;
2243 // avoid infinite recursion!
2244 if (av.getCodingComplement() != this)
2246 av.setCodingComplement(this);
2252 public boolean isNucleotide()
2254 return getAlignment() == null ? false : getAlignment().isNucleotide();
2258 public FeaturesDisplayedI getFeaturesDisplayed()
2260 return featuresDisplayed;
2264 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2266 featuresDisplayed = featuresDisplayedI;
2270 public boolean areFeaturesDisplayed()
2272 return featuresDisplayed != null
2273 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2280 * features are displayed if true
2283 public void setShowSequenceFeatures(boolean b)
2285 viewStyle.setShowSequenceFeatures(b);
2289 public boolean isShowSequenceFeatures()
2291 return viewStyle.isShowSequenceFeatures();
2295 public void setShowSequenceFeaturesHeight(boolean selected)
2297 viewStyle.setShowSequenceFeaturesHeight(selected);
2301 public boolean isShowSequenceFeaturesHeight()
2303 return viewStyle.isShowSequenceFeaturesHeight();
2307 public void setShowAnnotation(boolean b)
2309 viewStyle.setShowAnnotation(b);
2313 public boolean isShowAnnotation()
2315 return viewStyle.isShowAnnotation();
2319 public boolean isRightAlignIds()
2321 return viewStyle.isRightAlignIds();
2325 public void setRightAlignIds(boolean rightAlignIds)
2327 viewStyle.setRightAlignIds(rightAlignIds);
2331 public boolean getConservationSelected()
2333 return viewStyle.getConservationSelected();
2337 public void setShowBoxes(boolean state)
2339 viewStyle.setShowBoxes(state);
2344 * @see jalview.api.ViewStyleI#getTextColour()
2347 public Color getTextColour()
2349 return viewStyle.getTextColour();
2354 * @see jalview.api.ViewStyleI#getTextColour2()
2357 public Color getTextColour2()
2359 return viewStyle.getTextColour2();
2364 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2367 public int getThresholdTextColour()
2369 return viewStyle.getThresholdTextColour();
2374 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2377 public boolean isConservationColourSelected()
2379 return viewStyle.isConservationColourSelected();
2384 * @see jalview.api.ViewStyleI#isRenderGaps()
2387 public boolean isRenderGaps()
2389 return viewStyle.isRenderGaps();
2394 * @see jalview.api.ViewStyleI#isShowColourText()
2397 public boolean isShowColourText()
2399 return viewStyle.isShowColourText();
2403 * @param conservationColourSelected
2404 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2407 public void setConservationColourSelected(
2408 boolean conservationColourSelected)
2410 viewStyle.setConservationColourSelected(conservationColourSelected);
2414 * @param showColourText
2415 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2418 public void setShowColourText(boolean showColourText)
2420 viewStyle.setShowColourText(showColourText);
2425 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2428 public void setTextColour(Color textColour)
2430 viewStyle.setTextColour(textColour);
2434 * @param thresholdTextColour
2435 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2438 public void setThresholdTextColour(int thresholdTextColour)
2440 viewStyle.setThresholdTextColour(thresholdTextColour);
2444 * @param textColour2
2445 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2448 public void setTextColour2(Color textColour2)
2450 viewStyle.setTextColour2(textColour2);
2454 public ViewStyleI getViewStyle()
2456 return new ViewStyle(viewStyle);
2460 public void setViewStyle(ViewStyleI settingsForView)
2462 viewStyle = new ViewStyle(settingsForView);
2463 if (residueShading != null)
2465 residueShading.setConservationApplied(settingsForView
2466 .isConservationColourSelected());
2471 public boolean sameStyle(ViewStyleI them)
2473 return viewStyle.sameStyle(them);
2478 * @see jalview.api.ViewStyleI#getIdWidth()
2481 public int getIdWidth()
2483 return viewStyle.getIdWidth();
2488 * @see jalview.api.ViewStyleI#setIdWidth(int)
2491 public void setIdWidth(int i)
2493 viewStyle.setIdWidth(i);
2498 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2501 public boolean isCentreColumnLabels()
2503 return viewStyle.isCentreColumnLabels();
2507 * @param centreColumnLabels
2508 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2511 public void setCentreColumnLabels(boolean centreColumnLabels)
2513 viewStyle.setCentreColumnLabels(centreColumnLabels);
2518 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2521 public void setShowDBRefs(boolean showdbrefs)
2523 viewStyle.setShowDBRefs(showdbrefs);
2528 * @see jalview.api.ViewStyleI#isShowDBRefs()
2531 public boolean isShowDBRefs()
2533 return viewStyle.isShowDBRefs();
2538 * @see jalview.api.ViewStyleI#isShowNPFeats()
2541 public boolean isShowNPFeats()
2543 return viewStyle.isShowNPFeats();
2547 * @param shownpfeats
2548 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2551 public void setShowNPFeats(boolean shownpfeats)
2553 viewStyle.setShowNPFeats(shownpfeats);
2556 public abstract StructureSelectionManager getStructureSelectionManager();
2559 * Add one command to the command history list.
2563 public void addToHistoryList(CommandI command)
2565 if (this.historyList != null)
2567 this.historyList.push(command);
2568 broadcastCommand(command, false);
2572 protected void broadcastCommand(CommandI command, boolean undo)
2574 getStructureSelectionManager().commandPerformed(command, undo,
2579 * Add one command to the command redo list.
2583 public void addToRedoList(CommandI command)
2585 if (this.redoList != null)
2587 this.redoList.push(command);
2589 broadcastCommand(command, true);
2593 * Clear the command redo list.
2595 public void clearRedoList()
2597 if (this.redoList != null)
2599 this.redoList.clear();
2603 public void setHistoryList(Deque<CommandI> list)
2605 this.historyList = list;
2608 public Deque<CommandI> getHistoryList()
2610 return this.historyList;
2613 public void setRedoList(Deque<CommandI> list)
2615 this.redoList = list;
2618 public Deque<CommandI> getRedoList()
2620 return this.redoList;
2624 public VamsasSource getVamsasSource()
2629 public SequenceAnnotationOrder getSortAnnotationsBy()
2631 return sortAnnotationsBy;
2634 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2636 this.sortAnnotationsBy = sortAnnotationsBy;
2639 public boolean isShowAutocalculatedAbove()
2641 return showAutocalculatedAbove;
2644 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2646 this.showAutocalculatedAbove = showAutocalculatedAbove;
2650 public boolean isScaleProteinAsCdna()
2652 return viewStyle.isScaleProteinAsCdna();
2656 public void setScaleProteinAsCdna(boolean b)
2658 viewStyle.setScaleProteinAsCdna(b);
2662 * @return true if view should scroll to show the highlighted region of a
2667 public final boolean isFollowHighlight()
2669 return followHighlight;
2673 public final void setFollowHighlight(boolean b)
2675 this.followHighlight = b;
2679 public ViewportRanges getRanges()
2685 * Helper method to populate the SearchResults with the location in the
2686 * complementary alignment to scroll to, in order to match this one.
2689 * the SearchResults to add to
2690 * @return the offset (below top of visible region) of the matched sequence
2692 protected int findComplementScrollTarget(SearchResultsI sr)
2694 final AlignViewportI complement = getCodingComplement();
2695 if (complement == null || !complement.isFollowHighlight())
2699 boolean iAmProtein = !getAlignment().isNucleotide();
2700 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2702 if (proteinAlignment == null)
2706 final List<AlignedCodonFrame> mappings = proteinAlignment
2710 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2711 * residue in the middle column of the visible region. Scroll the
2712 * complementary alignment to line up the corresponding residue.
2715 SequenceI sequence = null;
2718 * locate 'middle' column (true middle if an odd number visible, left of
2719 * middle if an even number visible)
2721 int middleColumn = ranges.getStartRes()
2722 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2723 final HiddenSequences hiddenSequences = getAlignment()
2724 .getHiddenSequences();
2727 * searching to the bottom of the alignment gives smoother scrolling across
2728 * all gapped visible regions
2730 int lastSeq = alignment.getHeight() - 1;
2731 List<AlignedCodonFrame> seqMappings = null;
2732 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2734 sequence = getAlignment().getSequenceAt(seqNo);
2735 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2739 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2743 seqMappings = MappingUtils
2744 .findMappingsForSequenceAndOthers(sequence, mappings,
2745 getCodingComplement().getAlignment().getSequences());
2746 if (!seqMappings.isEmpty())
2752 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2755 * No ungapped mapped sequence in middle column - do nothing
2759 MappingUtils.addSearchResults(sr, sequence,
2760 sequence.findPosition(middleColumn), seqMappings);
2765 * synthesize a column selection if none exists so it covers the given
2766 * selection group. if wholewidth is false, no column selection is made if the
2767 * selection group covers the whole alignment width.
2772 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2775 if (sg != null && (sgs = sg.getStartRes()) >= 0
2776 && sg.getStartRes() <= (sge = sg.getEndRes())
2777 && !this.hasSelectedColumns())
2779 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2786 colSel = new ColumnSelection();
2788 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2790 colSel.addElement(cspos);
2796 * hold status of current selection group - defined on alignment or not.
2798 private boolean selectionIsDefinedGroup = false;
2801 public boolean isSelectionDefinedGroup()
2803 if (selectionGroup == null)
2807 if (isSelectionGroupChanged(true))
2809 selectionIsDefinedGroup = false;
2810 List<SequenceGroup> gps = alignment.getGroups();
2811 if (gps == null || gps.size() == 0)
2813 selectionIsDefinedGroup = false;
2817 selectionIsDefinedGroup = gps.contains(selectionGroup);
2820 return selectionGroup.getContext() == alignment
2821 || selectionIsDefinedGroup;
2825 * null, or currently highlighted results on this view
2827 private SearchResultsI searchResults = null;
2830 public boolean hasSearchResults()
2832 return searchResults != null;
2836 public void setSearchResults(SearchResultsI results)
2838 searchResults = results;
2842 public SearchResultsI getSearchResults()
2844 return searchResults;