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, add the cDNA
1916 * consensus annotation.
1918 public void 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);
1950 private void initConsensus(AlignmentAnnotation aa)
1953 aa.autoCalculated = true;
1957 alignment.addAnnotation(aa);
1961 // these should be extracted from the view model - style and settings for
1962 // derived annotation
1963 private void initGapCounts(AlignmentAnnotation counts)
1965 counts.hasText = false;
1966 counts.autoCalculated = true;
1967 counts.graph = AlignmentAnnotation.BAR_GRAPH;
1971 alignment.addAnnotation(counts);
1975 private void initConservation()
1977 if (showConservation)
1979 if (conservation == null)
1981 conservation = new AlignmentAnnotation("Conservation",
1982 "Conservation of total alignment less than "
1983 + getConsPercGaps() + "% gaps", new Annotation[1],
1984 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1985 conservation.hasText = true;
1986 conservation.autoCalculated = true;
1987 alignment.addAnnotation(conservation);
1992 private void initQuality()
1996 if (quality == null)
1998 quality = new AlignmentAnnotation("Quality",
1999 "Alignment Quality based on Blosum62 scores",
2000 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2001 quality.hasText = true;
2002 quality.autoCalculated = true;
2003 alignment.addAnnotation(quality);
2008 private void initRNAStructure()
2010 if (alignment.hasRNAStructure() && strucConsensus == null)
2012 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
2013 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2014 strucConsensus.hasText = true;
2015 strucConsensus.autoCalculated = true;
2019 alignment.addAnnotation(strucConsensus);
2027 * @see jalview.api.AlignViewportI#calcPanelHeight()
2030 public int calcPanelHeight()
2032 // setHeight of panels
2033 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2035 int charHeight = getCharHeight();
2038 BitSet graphgrp = new BitSet();
2039 for (AlignmentAnnotation aa : anns)
2043 System.err.println("Null annotation row: ignoring.");
2050 if (aa.graphGroup > -1)
2052 if (graphgrp.get(aa.graphGroup))
2058 graphgrp.set(aa.graphGroup);
2065 aa.height += charHeight;
2075 aa.height += aa.graphHeight;
2083 height += aa.height;
2095 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2096 boolean preserveNewGroupSettings)
2098 boolean updateCalcs = false;
2099 boolean conv = isShowGroupConservation();
2100 boolean cons = isShowGroupConsensus();
2101 boolean showprf = isShowSequenceLogo();
2102 boolean showConsHist = isShowConsensusHistogram();
2103 boolean normLogo = isNormaliseSequenceLogo();
2106 * TODO reorder the annotation rows according to group/sequence ordering on
2109 boolean sortg = true;
2111 // remove old automatic annotation
2112 // add any new annotation
2114 // intersect alignment annotation with alignment groups
2116 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2117 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2120 for (int an = 0; an < aan.length; an++)
2122 if (aan[an].autoCalculated && aan[an].groupRef != null)
2124 oldrfs.add(aan[an].groupRef);
2125 alignment.deleteAnnotation(aan[an], false);
2129 if (alignment.getGroups() != null)
2131 for (SequenceGroup sg : alignment.getGroups())
2133 updateCalcs = false;
2134 if (applyGlobalSettings
2135 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2137 // set defaults for this group's conservation/consensus
2138 sg.setshowSequenceLogo(showprf);
2139 sg.setShowConsensusHistogram(showConsHist);
2140 sg.setNormaliseSequenceLogo(normLogo);
2145 alignment.addAnnotation(sg.getConservationRow(), 0);
2150 alignment.addAnnotation(sg.getConsensus(), 0);
2152 // refresh the annotation rows
2155 sg.recalcConservation();
2163 public boolean isDisplayReferenceSeq()
2165 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2169 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2171 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2175 public boolean isColourByReferenceSeq()
2177 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2181 public Color getSequenceColour(SequenceI seq)
2183 Color sqc = sequenceColours.get(seq);
2184 return (sqc == null ? Color.white : sqc);
2188 public void setSequenceColour(SequenceI seq, Color col)
2192 sequenceColours.remove(seq);
2196 sequenceColours.put(seq, col);
2201 public void updateSequenceIdColours()
2203 for (SequenceGroup sg : alignment.getGroups())
2205 if (sg.idColour != null)
2207 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2209 sequenceColours.put(s, sg.idColour);
2216 public void clearSequenceColours()
2218 sequenceColours.clear();
2222 public AlignViewportI getCodingComplement()
2224 return this.codingComplement;
2228 * Set this as the (cDna/protein) complement of the given viewport. Also
2229 * ensures the reverse relationship is set on the given viewport.
2232 public void setCodingComplement(AlignViewportI av)
2236 System.err.println("Ignoring recursive setCodingComplement request");
2240 this.codingComplement = av;
2241 // avoid infinite recursion!
2242 if (av.getCodingComplement() != this)
2244 av.setCodingComplement(this);
2250 public boolean isNucleotide()
2252 return getAlignment() == null ? false : getAlignment().isNucleotide();
2256 public FeaturesDisplayedI getFeaturesDisplayed()
2258 return featuresDisplayed;
2262 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2264 featuresDisplayed = featuresDisplayedI;
2268 public boolean areFeaturesDisplayed()
2270 return featuresDisplayed != null
2271 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2278 * features are displayed if true
2281 public void setShowSequenceFeatures(boolean b)
2283 viewStyle.setShowSequenceFeatures(b);
2287 public boolean isShowSequenceFeatures()
2289 return viewStyle.isShowSequenceFeatures();
2293 public void setShowSequenceFeaturesHeight(boolean selected)
2295 viewStyle.setShowSequenceFeaturesHeight(selected);
2299 public boolean isShowSequenceFeaturesHeight()
2301 return viewStyle.isShowSequenceFeaturesHeight();
2305 public void setShowAnnotation(boolean b)
2307 viewStyle.setShowAnnotation(b);
2311 public boolean isShowAnnotation()
2313 return viewStyle.isShowAnnotation();
2317 public boolean isRightAlignIds()
2319 return viewStyle.isRightAlignIds();
2323 public void setRightAlignIds(boolean rightAlignIds)
2325 viewStyle.setRightAlignIds(rightAlignIds);
2329 public boolean getConservationSelected()
2331 return viewStyle.getConservationSelected();
2335 public void setShowBoxes(boolean state)
2337 viewStyle.setShowBoxes(state);
2342 * @see jalview.api.ViewStyleI#getTextColour()
2345 public Color getTextColour()
2347 return viewStyle.getTextColour();
2352 * @see jalview.api.ViewStyleI#getTextColour2()
2355 public Color getTextColour2()
2357 return viewStyle.getTextColour2();
2362 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2365 public int getThresholdTextColour()
2367 return viewStyle.getThresholdTextColour();
2372 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2375 public boolean isConservationColourSelected()
2377 return viewStyle.isConservationColourSelected();
2382 * @see jalview.api.ViewStyleI#isRenderGaps()
2385 public boolean isRenderGaps()
2387 return viewStyle.isRenderGaps();
2392 * @see jalview.api.ViewStyleI#isShowColourText()
2395 public boolean isShowColourText()
2397 return viewStyle.isShowColourText();
2401 * @param conservationColourSelected
2402 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2405 public void setConservationColourSelected(
2406 boolean conservationColourSelected)
2408 viewStyle.setConservationColourSelected(conservationColourSelected);
2412 * @param showColourText
2413 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2416 public void setShowColourText(boolean showColourText)
2418 viewStyle.setShowColourText(showColourText);
2423 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2426 public void setTextColour(Color textColour)
2428 viewStyle.setTextColour(textColour);
2432 * @param thresholdTextColour
2433 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2436 public void setThresholdTextColour(int thresholdTextColour)
2438 viewStyle.setThresholdTextColour(thresholdTextColour);
2442 * @param textColour2
2443 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2446 public void setTextColour2(Color textColour2)
2448 viewStyle.setTextColour2(textColour2);
2452 public ViewStyleI getViewStyle()
2454 return new ViewStyle(viewStyle);
2458 public void setViewStyle(ViewStyleI settingsForView)
2460 viewStyle = new ViewStyle(settingsForView);
2461 if (residueShading != null)
2463 residueShading.setConservationApplied(settingsForView
2464 .isConservationColourSelected());
2469 public boolean sameStyle(ViewStyleI them)
2471 return viewStyle.sameStyle(them);
2476 * @see jalview.api.ViewStyleI#getIdWidth()
2479 public int getIdWidth()
2481 return viewStyle.getIdWidth();
2486 * @see jalview.api.ViewStyleI#setIdWidth(int)
2489 public void setIdWidth(int i)
2491 viewStyle.setIdWidth(i);
2496 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2499 public boolean isCentreColumnLabels()
2501 return viewStyle.isCentreColumnLabels();
2505 * @param centreColumnLabels
2506 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2509 public void setCentreColumnLabels(boolean centreColumnLabels)
2511 viewStyle.setCentreColumnLabels(centreColumnLabels);
2516 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2519 public void setShowDBRefs(boolean showdbrefs)
2521 viewStyle.setShowDBRefs(showdbrefs);
2526 * @see jalview.api.ViewStyleI#isShowDBRefs()
2529 public boolean isShowDBRefs()
2531 return viewStyle.isShowDBRefs();
2536 * @see jalview.api.ViewStyleI#isShowNPFeats()
2539 public boolean isShowNPFeats()
2541 return viewStyle.isShowNPFeats();
2545 * @param shownpfeats
2546 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2549 public void setShowNPFeats(boolean shownpfeats)
2551 viewStyle.setShowNPFeats(shownpfeats);
2554 public abstract StructureSelectionManager getStructureSelectionManager();
2557 * Add one command to the command history list.
2561 public void addToHistoryList(CommandI command)
2563 if (this.historyList != null)
2565 this.historyList.push(command);
2566 broadcastCommand(command, false);
2570 protected void broadcastCommand(CommandI command, boolean undo)
2572 getStructureSelectionManager().commandPerformed(command, undo,
2577 * Add one command to the command redo list.
2581 public void addToRedoList(CommandI command)
2583 if (this.redoList != null)
2585 this.redoList.push(command);
2587 broadcastCommand(command, true);
2591 * Clear the command redo list.
2593 public void clearRedoList()
2595 if (this.redoList != null)
2597 this.redoList.clear();
2601 public void setHistoryList(Deque<CommandI> list)
2603 this.historyList = list;
2606 public Deque<CommandI> getHistoryList()
2608 return this.historyList;
2611 public void setRedoList(Deque<CommandI> list)
2613 this.redoList = list;
2616 public Deque<CommandI> getRedoList()
2618 return this.redoList;
2622 public VamsasSource getVamsasSource()
2627 public SequenceAnnotationOrder getSortAnnotationsBy()
2629 return sortAnnotationsBy;
2632 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2634 this.sortAnnotationsBy = sortAnnotationsBy;
2637 public boolean isShowAutocalculatedAbove()
2639 return showAutocalculatedAbove;
2642 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2644 this.showAutocalculatedAbove = showAutocalculatedAbove;
2648 public boolean isScaleProteinAsCdna()
2650 return viewStyle.isScaleProteinAsCdna();
2654 public void setScaleProteinAsCdna(boolean b)
2656 viewStyle.setScaleProteinAsCdna(b);
2660 * @return true if view should scroll to show the highlighted region of a
2665 public final boolean isFollowHighlight()
2667 return followHighlight;
2671 public final void setFollowHighlight(boolean b)
2673 this.followHighlight = b;
2677 public ViewportRanges getRanges()
2683 * Helper method to populate the SearchResults with the location in the
2684 * complementary alignment to scroll to, in order to match this one.
2687 * the SearchResults to add to
2688 * @return the offset (below top of visible region) of the matched sequence
2690 protected int findComplementScrollTarget(SearchResultsI sr)
2692 final AlignViewportI complement = getCodingComplement();
2693 if (complement == null || !complement.isFollowHighlight())
2697 boolean iAmProtein = !getAlignment().isNucleotide();
2698 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2700 if (proteinAlignment == null)
2704 final List<AlignedCodonFrame> mappings = proteinAlignment
2708 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2709 * residue in the middle column of the visible region. Scroll the
2710 * complementary alignment to line up the corresponding residue.
2713 SequenceI sequence = null;
2716 * locate 'middle' column (true middle if an odd number visible, left of
2717 * middle if an even number visible)
2719 int middleColumn = ranges.getStartRes()
2720 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2721 final HiddenSequences hiddenSequences = getAlignment()
2722 .getHiddenSequences();
2725 * searching to the bottom of the alignment gives smoother scrolling across
2726 * all gapped visible regions
2728 int lastSeq = alignment.getHeight() - 1;
2729 List<AlignedCodonFrame> seqMappings = null;
2730 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2732 sequence = getAlignment().getSequenceAt(seqNo);
2733 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2737 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2741 seqMappings = MappingUtils
2742 .findMappingsForSequenceAndOthers(sequence, mappings,
2743 getCodingComplement().getAlignment().getSequences());
2744 if (!seqMappings.isEmpty())
2750 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2753 * No ungapped mapped sequence in middle column - do nothing
2757 MappingUtils.addSearchResults(sr, sequence,
2758 sequence.findPosition(middleColumn), seqMappings);
2763 * synthesize a column selection if none exists so it covers the given
2764 * selection group. if wholewidth is false, no column selection is made if the
2765 * selection group covers the whole alignment width.
2770 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2773 if (sg != null && (sgs = sg.getStartRes()) >= 0
2774 && sg.getStartRes() <= (sge = sg.getEndRes())
2775 && !this.hasSelectedColumns())
2777 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2784 colSel = new ColumnSelection();
2786 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2788 colSel.addElement(cspos);
2794 * hold status of current selection group - defined on alignment or not.
2796 private boolean selectionIsDefinedGroup = false;
2799 public boolean isSelectionDefinedGroup()
2801 if (selectionGroup == null)
2805 if (isSelectionGroupChanged(true))
2807 selectionIsDefinedGroup = false;
2808 List<SequenceGroup> gps = alignment.getGroups();
2809 if (gps == null || gps.size() == 0)
2811 selectionIsDefinedGroup = false;
2815 selectionIsDefinedGroup = gps.contains(selectionGroup);
2818 return selectionGroup.getContext() == alignment
2819 || selectionIsDefinedGroup;
2823 * null, or currently highlighted results on this view
2825 private SearchResultsI searchResults = null;
2828 public boolean hasSearchResults()
2830 return searchResults != null;
2834 public void setSearchResults(SearchResultsI results)
2836 searchResults = results;
2840 public SearchResultsI getSearchResults()
2842 return searchResults;