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.schemes.Blosum62ColourScheme;
57 import jalview.schemes.ColourSchemeI;
58 import jalview.schemes.PIDColourScheme;
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 protected ViewStyleI viewStyle = new ViewStyle();
84 * A viewport that hosts the cDna view of this (protein), or vice versa (if
87 AlignViewportI codingComplement = null;
89 FeaturesDisplayedI featuresDisplayed = null;
91 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
93 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
97 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
100 public void setFontName(String name)
102 viewStyle.setFontName(name);
107 * @see jalview.api.ViewStyleI#setFontStyle(int)
110 public void setFontStyle(int style)
112 viewStyle.setFontStyle(style);
117 * @see jalview.api.ViewStyleI#setFontSize(int)
120 public void setFontSize(int size)
122 viewStyle.setFontSize(size);
127 * @see jalview.api.ViewStyleI#getFontStyle()
130 public int getFontStyle()
132 return viewStyle.getFontStyle();
137 * @see jalview.api.ViewStyleI#getFontName()
140 public String getFontName()
142 return viewStyle.getFontName();
147 * @see jalview.api.ViewStyleI#getFontSize()
150 public int getFontSize()
152 return viewStyle.getFontSize();
156 * @param upperCasebold
157 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
160 public void setUpperCasebold(boolean upperCasebold)
162 viewStyle.setUpperCasebold(upperCasebold);
167 * @see jalview.api.ViewStyleI#isUpperCasebold()
170 public boolean isUpperCasebold()
172 return viewStyle.isUpperCasebold();
177 * @see jalview.api.ViewStyleI#isSeqNameItalics()
180 public boolean isSeqNameItalics()
182 return viewStyle.isSeqNameItalics();
186 * @param colourByReferenceSeq
187 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
190 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
192 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
197 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
200 public void setColourAppliesToAllGroups(boolean b)
202 viewStyle.setColourAppliesToAllGroups(b);
207 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
210 public boolean getColourAppliesToAllGroups()
212 return viewStyle.getColourAppliesToAllGroups();
217 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
220 public boolean getAbovePIDThreshold()
222 return viewStyle.getAbovePIDThreshold();
227 * @see jalview.api.ViewStyleI#setIncrement(int)
230 public void setIncrement(int inc)
232 viewStyle.setIncrement(inc);
237 * @see jalview.api.ViewStyleI#getIncrement()
240 public int getIncrement()
242 return viewStyle.getIncrement();
247 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
250 public void setConservationSelected(boolean b)
252 viewStyle.setConservationSelected(b);
257 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
260 public void setShowHiddenMarkers(boolean show)
262 viewStyle.setShowHiddenMarkers(show);
267 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
270 public boolean getShowHiddenMarkers()
272 return viewStyle.getShowHiddenMarkers();
277 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
280 public void setScaleRightWrapped(boolean b)
282 viewStyle.setScaleRightWrapped(b);
287 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
290 public void setScaleLeftWrapped(boolean b)
292 viewStyle.setScaleLeftWrapped(b);
297 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
300 public void setScaleAboveWrapped(boolean b)
302 viewStyle.setScaleAboveWrapped(b);
307 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
310 public boolean getScaleLeftWrapped()
312 return viewStyle.getScaleLeftWrapped();
317 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
320 public boolean getScaleAboveWrapped()
322 return viewStyle.getScaleAboveWrapped();
327 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
330 public boolean getScaleRightWrapped()
332 return viewStyle.getScaleRightWrapped();
337 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
340 public void setAbovePIDThreshold(boolean b)
342 viewStyle.setAbovePIDThreshold(b);
347 * @see jalview.api.ViewStyleI#setThreshold(int)
350 public void setThreshold(int thresh)
352 viewStyle.setThreshold(thresh);
357 * @see jalview.api.ViewStyleI#getThreshold()
360 public int getThreshold()
362 return viewStyle.getThreshold();
367 * @see jalview.api.ViewStyleI#getShowJVSuffix()
370 public boolean getShowJVSuffix()
372 return viewStyle.getShowJVSuffix();
377 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
380 public void setShowJVSuffix(boolean b)
382 viewStyle.setShowJVSuffix(b);
387 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
390 public void setWrapAlignment(boolean state)
392 viewStyle.setWrapAlignment(state);
397 * @see jalview.api.ViewStyleI#setShowText(boolean)
400 public void setShowText(boolean state)
402 viewStyle.setShowText(state);
407 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
410 public void setRenderGaps(boolean state)
412 viewStyle.setRenderGaps(state);
417 * @see jalview.api.ViewStyleI#getColourText()
420 public boolean getColourText()
422 return viewStyle.getColourText();
427 * @see jalview.api.ViewStyleI#setColourText(boolean)
430 public void setColourText(boolean state)
432 viewStyle.setColourText(state);
437 * @see jalview.api.ViewStyleI#getWrapAlignment()
440 public boolean getWrapAlignment()
442 return viewStyle.getWrapAlignment();
447 * @see jalview.api.ViewStyleI#getShowText()
450 public boolean getShowText()
452 return viewStyle.getShowText();
457 * @see jalview.api.ViewStyleI#getWrappedWidth()
460 public int getWrappedWidth()
462 return viewStyle.getWrappedWidth();
467 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
470 public void setWrappedWidth(int w)
472 viewStyle.setWrappedWidth(w);
477 * @see jalview.api.ViewStyleI#getCharHeight()
480 public int getCharHeight()
482 return viewStyle.getCharHeight();
487 * @see jalview.api.ViewStyleI#setCharHeight(int)
490 public void setCharHeight(int h)
492 viewStyle.setCharHeight(h);
497 * @see jalview.api.ViewStyleI#getCharWidth()
500 public int getCharWidth()
502 return viewStyle.getCharWidth();
507 * @see jalview.api.ViewStyleI#setCharWidth(int)
510 public void setCharWidth(int w)
512 viewStyle.setCharWidth(w);
517 * @see jalview.api.ViewStyleI#getShowBoxes()
520 public boolean getShowBoxes()
522 return viewStyle.getShowBoxes();
527 * @see jalview.api.ViewStyleI#getShowUnconserved()
530 public boolean getShowUnconserved()
532 return viewStyle.getShowUnconserved();
536 * @param showunconserved
537 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
540 public void setShowUnconserved(boolean showunconserved)
542 viewStyle.setShowUnconserved(showunconserved);
547 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
550 public void setSeqNameItalics(boolean default1)
552 viewStyle.setSeqNameItalics(default1);
556 * alignment displayed in the viewport. Please use get/setter
558 protected AlignmentI alignment;
561 public AlignmentI getAlignment()
567 public char getGapCharacter()
569 return alignment.getGapCharacter();
572 protected String sequenceSetID;
575 * probably unused indicator that view is of a dataset rather than an
578 protected boolean isDataset = false;
580 public void setDataset(boolean b)
585 public boolean isDataset()
590 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
592 protected ColumnSelection colSel = new ColumnSelection();
594 public boolean autoCalculateConsensus = true;
596 protected boolean autoCalculateStrucConsensus = true;
598 protected boolean ignoreGapsInConsensusCalculation = false;
600 protected ColourSchemeI globalColourScheme = null;
603 public void setGlobalColourScheme(ColourSchemeI cs)
605 // TODO: logic refactored from AlignFrame changeColour -
606 // TODO: autorecalc stuff should be changed to rely on the worker system
607 // check to see if we should implement a changeColour(cs) method rather than
608 // put th logic in here
609 // - means that caller decides if they want to just modify state and defer
610 // calculation till later or to do all calculations in thread.
612 globalColourScheme = cs;
613 boolean recalc = false;
616 recalc = getConservationSelected();
617 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
618 || cs instanceof Blosum62ColourScheme)
621 cs.setThreshold(viewStyle.getThreshold(),
622 ignoreGapsInConsensusCalculation);
626 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
630 cs.setConsensus(hconsensus);
631 cs.setConservation(hconservation);
633 cs.setConservationApplied(getConservationSelected());
634 cs.alignmentChanged(alignment, hiddenRepSequences);
636 if (getColourAppliesToAllGroups())
638 for (SequenceGroup sg : getAlignment().getGroups())
645 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
646 sg.setConsPercGaps(ConsPercGaps);
647 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
648 || cs instanceof Blosum62ColourScheme)
650 sg.cs.setThreshold(viewStyle.getThreshold(),
651 isIgnoreGapsConsensus());
656 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
659 if (getConservationSelected())
661 sg.cs.setConservationApplied(true);
666 sg.cs.setConservation(null);
667 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
671 sg.recalcConservation();
675 sg.cs.alignmentChanged(sg, hiddenRepSequences);
682 public ColourSchemeI getGlobalColourScheme()
684 return globalColourScheme;
687 protected AlignmentAnnotation consensus;
689 protected AlignmentAnnotation complementConsensus;
691 protected AlignmentAnnotation gapcounts;
693 protected AlignmentAnnotation strucConsensus;
695 protected AlignmentAnnotation conservation;
697 protected AlignmentAnnotation quality;
699 protected AlignmentAnnotation[] groupConsensus;
701 protected AlignmentAnnotation[] groupConservation;
704 * results of alignment consensus analysis for visible portion of view
706 protected ProfilesI hconsensus = null;
709 * results of cDNA complement consensus visible portion of view
711 protected Hashtable[] hcomplementConsensus = null;
714 * results of secondary structure base pair consensus for visible portion of
717 protected Hashtable[] hStrucConsensus = null;
719 protected Conservation hconservation = null;
722 public void setConservation(Conservation cons)
724 hconservation = cons;
728 * percentage gaps allowed in a column before all amino acid properties should
729 * be considered unconserved
731 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
734 public int getConsPercGaps()
740 public void setSequenceConsensusHash(ProfilesI hconsensus)
742 this.hconsensus = hconsensus;
746 public void setComplementConsensusHash(Hashtable[] hconsensus)
748 this.hcomplementConsensus = hconsensus;
752 public ProfilesI getSequenceConsensusHash()
758 public Hashtable[] getComplementConsensusHash()
760 return hcomplementConsensus;
764 public Hashtable[] getRnaStructureConsensusHash()
766 return hStrucConsensus;
770 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
772 this.hStrucConsensus = hStrucConsensus;
777 public AlignmentAnnotation getAlignmentQualityAnnot()
783 public AlignmentAnnotation getAlignmentConservationAnnotation()
789 public AlignmentAnnotation getAlignmentConsensusAnnotation()
795 public AlignmentAnnotation getAlignmentGapAnnotation()
801 public AlignmentAnnotation getComplementConsensusAnnotation()
803 return complementConsensus;
807 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
809 return strucConsensus;
812 protected AlignCalcManagerI calculator = new AlignCalcManager();
815 * trigger update of conservation annotation
817 public void updateConservation(final AlignmentViewPanel ap)
819 // see note in mantis : issue number 8585
820 if (alignment.isNucleotide()
821 || (conservation == null && quality == null)
822 || !autoCalculateConsensus)
827 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
829 calculator.registerWorker(new jalview.workers.ConservationThread(
835 * trigger update of consensus annotation
837 public void updateConsensus(final AlignmentViewPanel ap)
839 // see note in mantis : issue number 8585
840 if ((consensus == null || gapcounts == null) || !autoCalculateConsensus)
844 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
846 calculator.registerWorker(new ConsensusThread(this, ap));
850 * A separate thread to compute cDNA consensus for a protein alignment
851 * which has mapping to cDNA
853 final AlignmentI al = this.getAlignment();
854 if (!al.isNucleotide() && al.getCodonFrames() != null
855 && !al.getCodonFrames().isEmpty())
858 * fudge - check first for protein-to-nucleotide mappings
859 * (we don't want to do this for protein-to-protein)
861 boolean doConsensus = false;
862 for (AlignedCodonFrame mapping : al.getCodonFrames())
864 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
865 MapList[] mapLists = mapping.getdnaToProt();
866 // mapLists can be empty if project load has not finished resolving seqs
867 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
876 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
879 .registerWorker(new ComplementConsensusThread(this, ap));
885 // --------START Structure Conservation
886 public void updateStrucConsensus(final AlignmentViewPanel ap)
888 if (autoCalculateStrucConsensus && strucConsensus == null
889 && alignment.isNucleotide() && alignment.hasRNAStructure())
891 // secondary structure has been added - so init the consensus line
895 // see note in mantis : issue number 8585
896 if (strucConsensus == null || !autoCalculateStrucConsensus)
900 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
902 calculator.registerWorker(new StrucConsensusThread(this, ap));
906 public boolean isCalcInProgress()
908 return calculator.isWorking();
912 public boolean isCalculationInProgress(
913 AlignmentAnnotation alignmentAnnotation)
915 if (!alignmentAnnotation.autoCalculated)
919 if (calculator.workingInvolvedWith(alignmentAnnotation))
921 // System.err.println("grey out ("+alignmentAnnotation.label+")");
927 public void setAlignment(AlignmentI align)
929 this.alignment = align;
933 * Clean up references when this viewport is closed
936 public void dispose()
939 * defensively null out references to large objects in case
940 * this object is not garbage collected (as if!)
943 complementConsensus = null;
944 strucConsensus = null;
947 groupConsensus = null;
948 groupConservation = null;
950 hcomplementConsensus = null;
951 // colour scheme may hold reference to consensus
952 globalColourScheme = null;
953 // TODO remove listeners from changeSupport?
954 changeSupport = null;
959 public boolean isClosed()
961 // TODO: check that this isClosed is only true after panel is closed, not
962 // before it is fully constructed.
963 return alignment == null;
967 public AlignCalcManagerI getCalcManager()
973 * should conservation rows be shown for groups
975 protected boolean showGroupConservation = false;
978 * should consensus rows be shown for groups
980 protected boolean showGroupConsensus = false;
983 * should consensus profile be rendered by default
985 protected boolean showSequenceLogo = false;
988 * should consensus profile be rendered normalised to row height
990 protected boolean normaliseSequenceLogo = false;
993 * should consensus histograms be rendered by default
995 protected boolean showConsensusHistogram = true;
998 * @return the showConsensusProfile
1001 public boolean isShowSequenceLogo()
1003 return showSequenceLogo;
1007 * @param showSequenceLogo
1010 public void setShowSequenceLogo(boolean showSequenceLogo)
1012 if (showSequenceLogo != this.showSequenceLogo)
1014 // TODO: decouple settings setting from calculation when refactoring
1015 // annotation update method from alignframe to viewport
1016 this.showSequenceLogo = showSequenceLogo;
1017 calculator.updateAnnotationFor(ConsensusThread.class);
1018 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1019 calculator.updateAnnotationFor(StrucConsensusThread.class);
1021 this.showSequenceLogo = showSequenceLogo;
1025 * @param showConsensusHistogram
1026 * the showConsensusHistogram to set
1028 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1030 this.showConsensusHistogram = showConsensusHistogram;
1034 * @return the showGroupConservation
1036 public boolean isShowGroupConservation()
1038 return showGroupConservation;
1042 * @param showGroupConservation
1043 * the showGroupConservation to set
1045 public void setShowGroupConservation(boolean showGroupConservation)
1047 this.showGroupConservation = showGroupConservation;
1051 * @return the showGroupConsensus
1053 public boolean isShowGroupConsensus()
1055 return showGroupConsensus;
1059 * @param showGroupConsensus
1060 * the showGroupConsensus to set
1062 public void setShowGroupConsensus(boolean showGroupConsensus)
1064 this.showGroupConsensus = showGroupConsensus;
1069 * @return flag to indicate if the consensus histogram should be rendered by
1073 public boolean isShowConsensusHistogram()
1075 return this.showConsensusHistogram;
1079 * when set, updateAlignment will always ensure sequences are of equal length
1081 private boolean padGaps = false;
1084 * when set, alignment should be reordered according to a newly opened tree
1086 public boolean sortByTree = false;
1091 * @return null or the currently selected sequence region
1094 public SequenceGroup getSelectionGroup()
1096 return selectionGroup;
1100 * Set the selection group for this window.
1103 * - group holding references to sequences in this alignment view
1107 public void setSelectionGroup(SequenceGroup sg)
1109 selectionGroup = sg;
1112 public void setHiddenColumns(ColumnSelection colsel)
1114 this.colSel = colsel;
1118 public ColumnSelection getColumnSelection()
1124 public void setColumnSelection(ColumnSelection colSel)
1126 this.colSel = colSel;
1129 updateHiddenColumns();
1131 isColSelChanged(true);
1139 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1141 return hiddenRepSequences;
1145 public void setHiddenRepSequences(
1146 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1148 this.hiddenRepSequences = hiddenRepSequences;
1152 public boolean hasSelectedColumns()
1154 ColumnSelection columnSelection = getColumnSelection();
1155 return columnSelection != null && columnSelection.hasSelectedColumns();
1159 public boolean hasHiddenColumns()
1161 return colSel != null && colSel.hasHiddenColumns();
1164 public void updateHiddenColumns()
1166 // this method doesn't really do anything now. But - it could, since a
1167 // column Selection could be in the process of modification
1168 // hasHiddenColumns = colSel.hasHiddenColumns();
1172 public boolean hasHiddenRows()
1174 return alignment.getHiddenSequences().getSize() > 0;
1177 protected SequenceGroup selectionGroup;
1179 public void setSequenceSetId(String newid)
1181 if (sequenceSetID != null)
1184 .println("Warning - overwriting a sequenceSetId for a viewport!");
1186 sequenceSetID = new String(newid);
1190 public String getSequenceSetId()
1192 if (sequenceSetID == null)
1194 sequenceSetID = alignment.hashCode() + "";
1197 return sequenceSetID;
1201 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1204 protected String viewId = null;
1207 public String getViewId()
1211 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1216 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1218 ignoreGapsInConsensusCalculation = b;
1221 updateConsensus(ap);
1222 if (globalColourScheme != null)
1224 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1225 ignoreGapsInConsensusCalculation);
1231 private long sgrouphash = -1, colselhash = -1;
1234 * checks current SelectionGroup against record of last hash value, and
1238 * update the record of last hash value
1240 * @return true if SelectionGroup changed since last call (when b is true)
1242 public boolean isSelectionGroupChanged(boolean b)
1244 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1245 : selectionGroup.hashCode();
1246 if (hc != -1 && hc != sgrouphash)
1258 * checks current colsel against record of last hash value, and optionally
1262 * update the record of last hash value
1263 * @return true if colsel changed since last call (when b is true)
1265 public boolean isColSelChanged(boolean b)
1267 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1268 if (hc != -1 && hc != colselhash)
1280 public boolean isIgnoreGapsConsensus()
1282 return ignoreGapsInConsensusCalculation;
1285 // property change stuff
1286 // JBPNote Prolly only need this in the applet version.
1287 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1290 protected boolean showConservation = true;
1292 protected boolean showQuality = true;
1294 protected boolean showConsensus = true;
1296 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1298 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1300 protected boolean showAutocalculatedAbove;
1303 * when set, view will scroll to show the highlighted position
1305 private boolean followHighlight = true;
1307 // TODO private with getters and setters?
1308 public int startRes;
1312 public int startSeq;
1317 * Property change listener for changes in alignment
1322 public void addPropertyChangeListener(
1323 java.beans.PropertyChangeListener listener)
1325 changeSupport.addPropertyChangeListener(listener);
1334 public void removePropertyChangeListener(
1335 java.beans.PropertyChangeListener listener)
1337 changeSupport.removePropertyChangeListener(listener);
1341 * Property change listener for changes in alignment
1350 public void firePropertyChange(String prop, Object oldvalue,
1353 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1356 // common hide/show column stuff
1358 public void hideSelectedColumns()
1360 if (colSel.isEmpty())
1365 colSel.hideSelectedColumns();
1366 setSelectionGroup(null);
1367 isColSelChanged(true);
1370 public void hideColumns(int start, int end)
1374 colSel.hideColumns(start);
1378 colSel.hideColumns(start, end);
1380 isColSelChanged(true);
1383 public void showColumn(int col)
1385 colSel.revealHiddenColumns(col);
1386 isColSelChanged(true);
1389 public void showAllHiddenColumns()
1391 colSel.revealAllHiddenColumns();
1392 isColSelChanged(true);
1395 // common hide/show seq stuff
1396 public void showAllHiddenSeqs()
1398 if (alignment.getHiddenSequences().getSize() > 0)
1400 if (selectionGroup == null)
1402 selectionGroup = new SequenceGroup();
1403 selectionGroup.setEndRes(alignment.getWidth() - 1);
1405 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1406 hiddenRepSequences);
1407 for (SequenceI seq : tmp)
1409 selectionGroup.addSequence(seq, false);
1410 setSequenceAnnotationsVisible(seq, true);
1413 hiddenRepSequences = null;
1415 firePropertyChange("alignment", null, alignment.getSequences());
1416 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1422 public void showSequence(int index)
1424 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1425 index, hiddenRepSequences);
1428 if (selectionGroup == null)
1430 selectionGroup = new SequenceGroup();
1431 selectionGroup.setEndRes(alignment.getWidth() - 1);
1434 for (SequenceI seq : tmp)
1436 selectionGroup.addSequence(seq, false);
1437 setSequenceAnnotationsVisible(seq, true);
1439 firePropertyChange("alignment", null, alignment.getSequences());
1444 public void hideAllSelectedSeqs()
1446 if (selectionGroup == null || selectionGroup.getSize() < 1)
1451 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1455 setSelectionGroup(null);
1458 public void hideSequence(SequenceI[] seq)
1462 for (int i = 0; i < seq.length; i++)
1464 alignment.getHiddenSequences().hideSequence(seq[i]);
1465 setSequenceAnnotationsVisible(seq[i], false);
1467 firePropertyChange("alignment", null, alignment.getSequences());
1472 * Hides the specified sequence, or the sequences it represents
1475 * the sequence to hide, or keep as representative
1476 * @param representGroup
1477 * if true, hide the current selection group except for the
1478 * representative sequence
1480 public void hideSequences(SequenceI sequence, boolean representGroup)
1482 if (selectionGroup == null || selectionGroup.getSize() < 1)
1484 hideSequence(new SequenceI[] { sequence });
1490 hideRepSequences(sequence, selectionGroup);
1491 setSelectionGroup(null);
1495 int gsize = selectionGroup.getSize();
1496 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1497 new SequenceI[gsize]);
1499 hideSequence(hseqs);
1500 setSelectionGroup(null);
1505 * Set visibility for any annotations for the given sequence.
1509 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1512 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1515 for (AlignmentAnnotation ann : anns)
1517 if (ann.sequenceRef == sequenceI)
1519 ann.visible = visible;
1525 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1527 int sSize = sg.getSize();
1533 if (hiddenRepSequences == null)
1535 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1538 hiddenRepSequences.put(repSequence, sg);
1540 // Hide all sequences except the repSequence
1541 SequenceI[] seqs = new SequenceI[sSize - 1];
1543 for (int i = 0; i < sSize; i++)
1545 if (sg.getSequenceAt(i) != repSequence)
1547 if (index == sSize - 1)
1552 seqs[index++] = sg.getSequenceAt(i);
1555 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1556 sg.setHidereps(true); // note: not done in 2.7applet
1563 * @return null or the current reference sequence
1565 public SequenceI getReferenceSeq()
1567 return alignment.getSeqrep();
1572 * @return true iff seq is the reference for the alignment
1574 public boolean isReferenceSeq(SequenceI seq)
1576 return alignment.getSeqrep() == seq;
1582 * @return true if there are sequences represented by this sequence that are
1585 public boolean isHiddenRepSequence(SequenceI seq)
1587 return (hiddenRepSequences != null && hiddenRepSequences
1594 * @return null or a sequence group containing the sequences that seq
1597 public SequenceGroup getRepresentedSequences(SequenceI seq)
1599 return (SequenceGroup) (hiddenRepSequences == null ? null
1600 : hiddenRepSequences.get(seq));
1604 public int adjustForHiddenSeqs(int alignmentIndex)
1606 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1611 public void invertColumnSelection()
1613 colSel.invertColumnSelection(0, alignment.getWidth());
1617 public SequenceI[] getSelectionAsNewSequence()
1619 SequenceI[] sequences;
1620 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1621 // this was the only caller in the applet for this method
1622 // JBPNote: in applet, this method returned references to the alignment
1623 // sequences, and it did not honour the presence/absence of annotation
1624 // attached to the alignment (probably!)
1625 if (selectionGroup == null || selectionGroup.getSize() == 0)
1627 sequences = alignment.getSequencesArray();
1628 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1629 for (int i = 0; i < sequences.length; i++)
1631 // construct new sequence with subset of visible annotation
1632 sequences[i] = new Sequence(sequences[i], annots);
1637 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1644 public SequenceI[] getSequenceSelection()
1646 SequenceI[] sequences = null;
1647 if (selectionGroup != null)
1649 sequences = selectionGroup.getSequencesInOrder(alignment);
1651 if (sequences == null)
1653 sequences = alignment.getSequencesArray();
1659 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1661 return new CigarArray(alignment, colSel,
1662 (selectedRegionOnly ? selectionGroup : null));
1666 public jalview.datamodel.AlignmentView getAlignmentView(
1667 boolean selectedOnly)
1669 return getAlignmentView(selectedOnly, false);
1673 public jalview.datamodel.AlignmentView getAlignmentView(
1674 boolean selectedOnly, boolean markGroups)
1676 return new AlignmentView(alignment, colSel, selectionGroup,
1677 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1682 public String[] getViewAsString(boolean selectedRegionOnly)
1684 return getViewAsString(selectedRegionOnly, true);
1688 public String[] getViewAsString(boolean selectedRegionOnly,
1689 boolean exportHiddenSeqs)
1691 String[] selection = null;
1692 SequenceI[] seqs = null;
1694 int start = 0, end = 0;
1695 if (selectedRegionOnly && selectionGroup != null)
1697 iSize = selectionGroup.getSize();
1698 seqs = selectionGroup.getSequencesInOrder(alignment);
1699 start = selectionGroup.getStartRes();
1700 end = selectionGroup.getEndRes() + 1;
1704 if (hasHiddenRows() && exportHiddenSeqs)
1706 AlignmentI fullAlignment = alignment.getHiddenSequences()
1707 .getFullAlignment();
1708 iSize = fullAlignment.getHeight();
1709 seqs = fullAlignment.getSequencesArray();
1710 end = fullAlignment.getWidth();
1714 iSize = alignment.getHeight();
1715 seqs = alignment.getSequencesArray();
1716 end = alignment.getWidth();
1720 selection = new String[iSize];
1721 if (colSel != null && colSel.hasHiddenColumns())
1723 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1727 for (i = 0; i < iSize; i++)
1729 selection[i] = seqs[i].getSequenceAsString(start, end);
1737 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1739 ArrayList<int[]> regions = new ArrayList<int[]>();
1745 if (colSel != null && colSel.hasHiddenColumns())
1749 start = colSel.adjustForHiddenColumns(start);
1752 end = colSel.getHiddenBoundaryRight(start);
1763 regions.add(new int[] { start, end });
1765 if (colSel != null && colSel.hasHiddenColumns())
1767 start = colSel.adjustForHiddenColumns(end);
1768 start = colSel.getHiddenBoundaryLeft(start) + 1;
1770 } while (end < max);
1772 int[][] startEnd = new int[regions.size()][2];
1778 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1779 boolean selectedOnly)
1781 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1782 AlignmentAnnotation[] aa;
1783 if ((aa = alignment.getAlignmentAnnotation()) != null)
1785 for (AlignmentAnnotation annot : aa)
1787 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1788 if (selectedOnly && selectionGroup != null)
1790 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1791 selectionGroup.getEndRes(), clone);
1795 colSel.makeVisibleAnnotation(clone);
1804 public boolean isPadGaps()
1810 public void setPadGaps(boolean padGaps)
1812 this.padGaps = padGaps;
1816 * apply any post-edit constraints and trigger any calculations needed after
1817 * an edit has been performed on the alignment
1822 public void alignmentChanged(AlignmentViewPanel ap)
1826 alignment.padGaps();
1828 if (autoCalculateConsensus)
1830 updateConsensus(ap);
1832 if (hconsensus != null && autoCalculateConsensus)
1834 updateConservation(ap);
1836 if (autoCalculateStrucConsensus)
1838 updateStrucConsensus(ap);
1841 // Reset endRes of groups if beyond alignment width
1842 int alWidth = alignment.getWidth();
1843 List<SequenceGroup> groups = alignment.getGroups();
1846 for (SequenceGroup sg : groups)
1848 if (sg.getEndRes() > alWidth)
1850 sg.setEndRes(alWidth - 1);
1855 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1857 selectionGroup.setEndRes(alWidth - 1);
1860 resetAllColourSchemes();
1861 calculator.restartWorkers();
1862 // alignment.adjustSequenceAnnotations();
1866 * reset scope and do calculations for all applied colourschemes on alignment
1868 void resetAllColourSchemes()
1870 ColourSchemeI cs = globalColourScheme;
1873 cs.alignmentChanged(alignment, hiddenRepSequences);
1875 cs.setConsensus(hconsensus);
1876 if (cs.conservationApplied())
1878 cs.setConservation(Conservation.calculateConservation("All",
1879 alignment.getSequences(), 0, alignment.getWidth(), false,
1880 getConsPercGaps(), false));
1884 for (SequenceGroup sg : alignment.getGroups())
1888 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1890 sg.recalcConservation();
1894 protected void initAutoAnnotation()
1896 // TODO: add menu option action that nulls or creates consensus object
1897 // depending on if the user wants to see the annotation or not in a
1898 // specific alignment
1900 if (hconsensus == null && !isDataset)
1902 if (!alignment.isNucleotide())
1911 consensus = new AlignmentAnnotation("Consensus", "PID",
1912 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1913 initConsensus(consensus);
1914 gapcounts = new AlignmentAnnotation("Occupancy",
1915 "Number of aligned positions",
1916 new Annotation[1], 0f, alignment.getHeight(),
1917 AlignmentAnnotation.BAR_GRAPH);
1918 initGapCounts(gapcounts);
1920 initComplementConsensus();
1925 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1926 * consensus annotation.
1928 public void initComplementConsensus()
1930 if (!alignment.isNucleotide())
1932 final List<AlignedCodonFrame> codonMappings = alignment
1934 if (codonMappings != null && !codonMappings.isEmpty())
1936 boolean doConsensus = false;
1937 for (AlignedCodonFrame mapping : codonMappings)
1939 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1940 MapList[] mapLists = mapping.getdnaToProt();
1941 // mapLists can be empty if project load has not finished resolving
1943 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1951 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1952 "PID for cDNA", new Annotation[1], 0f, 100f,
1953 AlignmentAnnotation.BAR_GRAPH);
1954 initConsensus(complementConsensus);
1960 private void initConsensus(AlignmentAnnotation aa)
1963 aa.autoCalculated = true;
1967 alignment.addAnnotation(aa);
1971 // these should be extracted from the view model - style and settings for
1972 // derived annotation
1973 private void initGapCounts(AlignmentAnnotation counts)
1975 counts.hasText = false;
1976 counts.autoCalculated = true;
1977 counts.graph = AlignmentAnnotation.BAR_GRAPH;
1981 alignment.addAnnotation(counts);
1985 private void initConservation()
1987 if (showConservation)
1989 if (conservation == null)
1991 conservation = new AlignmentAnnotation("Conservation",
1992 "Conservation of total alignment less than "
1993 + getConsPercGaps() + "% gaps", new Annotation[1],
1994 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1995 conservation.hasText = true;
1996 conservation.autoCalculated = true;
1997 alignment.addAnnotation(conservation);
2002 private void initQuality()
2006 if (quality == null)
2008 quality = new AlignmentAnnotation("Quality",
2009 "Alignment Quality based on Blosum62 scores",
2010 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2011 quality.hasText = true;
2012 quality.autoCalculated = true;
2013 alignment.addAnnotation(quality);
2018 private void initRNAStructure()
2020 if (alignment.hasRNAStructure() && strucConsensus == null)
2022 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
2023 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2024 strucConsensus.hasText = true;
2025 strucConsensus.autoCalculated = true;
2029 alignment.addAnnotation(strucConsensus);
2037 * @see jalview.api.AlignViewportI#calcPanelHeight()
2040 public int calcPanelHeight()
2042 // setHeight of panels
2043 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2045 int charHeight = getCharHeight();
2048 BitSet graphgrp = new BitSet();
2049 for (AlignmentAnnotation aa : anns)
2053 System.err.println("Null annotation row: ignoring.");
2060 if (aa.graphGroup > -1)
2062 if (graphgrp.get(aa.graphGroup))
2068 graphgrp.set(aa.graphGroup);
2075 aa.height += charHeight;
2085 aa.height += aa.graphHeight;
2093 height += aa.height;
2105 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2106 boolean preserveNewGroupSettings)
2108 boolean updateCalcs = false;
2109 boolean conv = isShowGroupConservation();
2110 boolean cons = isShowGroupConsensus();
2111 boolean showprf = isShowSequenceLogo();
2112 boolean showConsHist = isShowConsensusHistogram();
2113 boolean normLogo = isNormaliseSequenceLogo();
2116 * TODO reorder the annotation rows according to group/sequence ordering on
2119 boolean sortg = true;
2121 // remove old automatic annotation
2122 // add any new annotation
2124 // intersect alignment annotation with alignment groups
2126 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2127 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2130 for (int an = 0; an < aan.length; an++)
2132 if (aan[an].autoCalculated && aan[an].groupRef != null)
2134 oldrfs.add(aan[an].groupRef);
2135 alignment.deleteAnnotation(aan[an], false);
2139 if (alignment.getGroups() != null)
2141 for (SequenceGroup sg : alignment.getGroups())
2143 updateCalcs = false;
2144 if (applyGlobalSettings
2145 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2147 // set defaults for this group's conservation/consensus
2148 sg.setshowSequenceLogo(showprf);
2149 sg.setShowConsensusHistogram(showConsHist);
2150 sg.setNormaliseSequenceLogo(normLogo);
2155 alignment.addAnnotation(sg.getConservationRow(), 0);
2160 alignment.addAnnotation(sg.getConsensus(), 0);
2162 // refresh the annotation rows
2165 sg.recalcConservation();
2173 public boolean isDisplayReferenceSeq()
2175 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2179 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2181 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2185 public boolean isColourByReferenceSeq()
2187 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2191 public Color getSequenceColour(SequenceI seq)
2193 Color sqc = sequenceColours.get(seq);
2194 return (sqc == null ? Color.white : sqc);
2198 public void setSequenceColour(SequenceI seq, Color col)
2202 sequenceColours.remove(seq);
2206 sequenceColours.put(seq, col);
2211 public void updateSequenceIdColours()
2213 for (SequenceGroup sg : alignment.getGroups())
2215 if (sg.idColour != null)
2217 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2219 sequenceColours.put(s, sg.idColour);
2226 public void clearSequenceColours()
2228 sequenceColours.clear();
2232 public AlignViewportI getCodingComplement()
2234 return this.codingComplement;
2238 * Set this as the (cDna/protein) complement of the given viewport. Also
2239 * ensures the reverse relationship is set on the given viewport.
2242 public void setCodingComplement(AlignViewportI av)
2246 System.err.println("Ignoring recursive setCodingComplement request");
2250 this.codingComplement = av;
2251 // avoid infinite recursion!
2252 if (av.getCodingComplement() != this)
2254 av.setCodingComplement(this);
2260 public boolean isNucleotide()
2262 return getAlignment() == null ? false : getAlignment().isNucleotide();
2266 public FeaturesDisplayedI getFeaturesDisplayed()
2268 return featuresDisplayed;
2272 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2274 featuresDisplayed = featuresDisplayedI;
2278 public boolean areFeaturesDisplayed()
2280 return featuresDisplayed != null
2281 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2288 * features are displayed if true
2291 public void setShowSequenceFeatures(boolean b)
2293 viewStyle.setShowSequenceFeatures(b);
2297 public boolean isShowSequenceFeatures()
2299 return viewStyle.isShowSequenceFeatures();
2303 public void setShowSequenceFeaturesHeight(boolean selected)
2305 viewStyle.setShowSequenceFeaturesHeight(selected);
2309 public boolean isShowSequenceFeaturesHeight()
2311 return viewStyle.isShowSequenceFeaturesHeight();
2315 public void setShowAnnotation(boolean b)
2317 viewStyle.setShowAnnotation(b);
2321 public boolean isShowAnnotation()
2323 return viewStyle.isShowAnnotation();
2327 public boolean isRightAlignIds()
2329 return viewStyle.isRightAlignIds();
2333 public void setRightAlignIds(boolean rightAlignIds)
2335 viewStyle.setRightAlignIds(rightAlignIds);
2339 public boolean getConservationSelected()
2341 return viewStyle.getConservationSelected();
2345 public void setShowBoxes(boolean state)
2347 viewStyle.setShowBoxes(state);
2352 * @see jalview.api.ViewStyleI#getTextColour()
2355 public Color getTextColour()
2357 return viewStyle.getTextColour();
2362 * @see jalview.api.ViewStyleI#getTextColour2()
2365 public Color getTextColour2()
2367 return viewStyle.getTextColour2();
2372 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2375 public int getThresholdTextColour()
2377 return viewStyle.getThresholdTextColour();
2382 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2385 public boolean isConservationColourSelected()
2387 return viewStyle.isConservationColourSelected();
2392 * @see jalview.api.ViewStyleI#isRenderGaps()
2395 public boolean isRenderGaps()
2397 return viewStyle.isRenderGaps();
2402 * @see jalview.api.ViewStyleI#isShowColourText()
2405 public boolean isShowColourText()
2407 return viewStyle.isShowColourText();
2411 * @param conservationColourSelected
2412 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2415 public void setConservationColourSelected(
2416 boolean conservationColourSelected)
2418 viewStyle.setConservationColourSelected(conservationColourSelected);
2422 * @param showColourText
2423 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2426 public void setShowColourText(boolean showColourText)
2428 viewStyle.setShowColourText(showColourText);
2433 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2436 public void setTextColour(Color textColour)
2438 viewStyle.setTextColour(textColour);
2442 * @param thresholdTextColour
2443 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2446 public void setThresholdTextColour(int thresholdTextColour)
2448 viewStyle.setThresholdTextColour(thresholdTextColour);
2452 * @param textColour2
2453 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2456 public void setTextColour2(Color textColour2)
2458 viewStyle.setTextColour2(textColour2);
2462 public ViewStyleI getViewStyle()
2464 return new ViewStyle(viewStyle);
2468 public void setViewStyle(ViewStyleI settingsForView)
2470 viewStyle = new ViewStyle(settingsForView);
2474 public boolean sameStyle(ViewStyleI them)
2476 return viewStyle.sameStyle(them);
2481 * @see jalview.api.ViewStyleI#getIdWidth()
2484 public int getIdWidth()
2486 return viewStyle.getIdWidth();
2491 * @see jalview.api.ViewStyleI#setIdWidth(int)
2494 public void setIdWidth(int i)
2496 viewStyle.setIdWidth(i);
2501 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2504 public boolean isCentreColumnLabels()
2506 return viewStyle.isCentreColumnLabels();
2510 * @param centreColumnLabels
2511 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2514 public void setCentreColumnLabels(boolean centreColumnLabels)
2516 viewStyle.setCentreColumnLabels(centreColumnLabels);
2521 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2524 public void setShowDBRefs(boolean showdbrefs)
2526 viewStyle.setShowDBRefs(showdbrefs);
2531 * @see jalview.api.ViewStyleI#isShowDBRefs()
2534 public boolean isShowDBRefs()
2536 return viewStyle.isShowDBRefs();
2541 * @see jalview.api.ViewStyleI#isShowNPFeats()
2544 public boolean isShowNPFeats()
2546 return viewStyle.isShowNPFeats();
2550 * @param shownpfeats
2551 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2554 public void setShowNPFeats(boolean shownpfeats)
2556 viewStyle.setShowNPFeats(shownpfeats);
2559 public abstract StructureSelectionManager getStructureSelectionManager();
2562 * Add one command to the command history list.
2566 public void addToHistoryList(CommandI command)
2568 if (this.historyList != null)
2570 this.historyList.push(command);
2571 broadcastCommand(command, false);
2575 protected void broadcastCommand(CommandI command, boolean undo)
2577 getStructureSelectionManager().commandPerformed(command, undo,
2582 * Add one command to the command redo list.
2586 public void addToRedoList(CommandI command)
2588 if (this.redoList != null)
2590 this.redoList.push(command);
2592 broadcastCommand(command, true);
2596 * Clear the command redo list.
2598 public void clearRedoList()
2600 if (this.redoList != null)
2602 this.redoList.clear();
2606 public void setHistoryList(Deque<CommandI> list)
2608 this.historyList = list;
2611 public Deque<CommandI> getHistoryList()
2613 return this.historyList;
2616 public void setRedoList(Deque<CommandI> list)
2618 this.redoList = list;
2621 public Deque<CommandI> getRedoList()
2623 return this.redoList;
2627 public VamsasSource getVamsasSource()
2632 public SequenceAnnotationOrder getSortAnnotationsBy()
2634 return sortAnnotationsBy;
2637 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2639 this.sortAnnotationsBy = sortAnnotationsBy;
2642 public boolean isShowAutocalculatedAbove()
2644 return showAutocalculatedAbove;
2647 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2649 this.showAutocalculatedAbove = showAutocalculatedAbove;
2653 public boolean isScaleProteinAsCdna()
2655 return viewStyle.isScaleProteinAsCdna();
2659 public void setScaleProteinAsCdna(boolean b)
2661 viewStyle.setScaleProteinAsCdna(b);
2665 * @return true if view should scroll to show the highlighted region of a
2670 public final boolean isFollowHighlight()
2672 return followHighlight;
2676 public final void setFollowHighlight(boolean b)
2678 this.followHighlight = b;
2681 public int getStartRes()
2687 public int getEndRes()
2692 public int getStartSeq()
2697 public void setStartRes(int res)
2699 this.startRes = res;
2702 public void setStartSeq(int seq)
2704 this.startSeq = seq;
2707 public void setEndRes(int res)
2709 if (res > alignment.getWidth() - 1)
2711 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2712 // (alignment.getWidth()-1));
2713 res = alignment.getWidth() - 1;
2722 public void setEndSeq(int seq)
2724 if (seq > alignment.getHeight())
2726 seq = alignment.getHeight();
2735 public int getEndSeq()
2741 * Helper method to populate the SearchResults with the location in the
2742 * complementary alignment to scroll to, in order to match this one.
2745 * the SearchResults to add to
2746 * @return the offset (below top of visible region) of the matched sequence
2748 protected int findComplementScrollTarget(SearchResultsI sr)
2750 final AlignViewportI complement = getCodingComplement();
2751 if (complement == null || !complement.isFollowHighlight())
2755 boolean iAmProtein = !getAlignment().isNucleotide();
2756 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2758 if (proteinAlignment == null)
2762 final List<AlignedCodonFrame> mappings = proteinAlignment
2766 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2767 * residue in the middle column of the visible region. Scroll the
2768 * complementary alignment to line up the corresponding residue.
2771 SequenceI sequence = null;
2774 * locate 'middle' column (true middle if an odd number visible, left of
2775 * middle if an even number visible)
2777 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2778 final HiddenSequences hiddenSequences = getAlignment()
2779 .getHiddenSequences();
2782 * searching to the bottom of the alignment gives smoother scrolling across
2783 * all gapped visible regions
2785 int lastSeq = alignment.getHeight() - 1;
2786 List<AlignedCodonFrame> seqMappings = null;
2787 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2789 sequence = getAlignment().getSequenceAt(seqNo);
2790 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2794 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2798 seqMappings = MappingUtils
2799 .findMappingsForSequenceAndOthers(sequence, mappings,
2800 getCodingComplement().getAlignment().getSequences());
2801 if (!seqMappings.isEmpty())
2807 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2810 * No ungapped mapped sequence in middle column - do nothing
2814 MappingUtils.addSearchResults(sr, sequence,
2815 sequence.findPosition(middleColumn), seqMappings);
2820 * synthesize a column selection if none exists so it covers the given
2821 * selection group. if wholewidth is false, no column selection is made if the
2822 * selection group covers the whole alignment width.
2827 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2830 if (sg != null && (sgs = sg.getStartRes()) >= 0
2831 && sg.getStartRes() <= (sge = sg.getEndRes())
2832 && !this.hasSelectedColumns())
2834 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2841 colSel = new ColumnSelection();
2843 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2845 colSel.addElement(cspos);
2851 * hold status of current selection group - defined on alignment or not.
2853 private boolean selectionIsDefinedGroup = false;
2856 public boolean isSelectionDefinedGroup()
2858 if (selectionGroup == null)
2862 if (isSelectionGroupChanged(true))
2864 selectionIsDefinedGroup = false;
2865 List<SequenceGroup> gps = alignment.getGroups();
2866 if (gps == null || gps.size() == 0)
2868 selectionIsDefinedGroup = false;
2872 selectionIsDefinedGroup = gps.contains(selectionGroup);
2875 return selectionGroup.getContext() == alignment
2876 || selectionIsDefinedGroup;
2880 * null, or currently highlighted results on this view
2882 private SearchResultsI searchResults = null;
2885 public boolean hasSearchResults()
2887 return searchResults != null;
2891 public void setSearchResults(SearchResultsI results)
2893 searchResults = results;
2897 public SearchResultsI getSearchResults()
2899 return searchResults;