2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenSequences;
39 import jalview.datamodel.ProfilesI;
40 import jalview.datamodel.SearchResultsI;
41 import jalview.datamodel.Sequence;
42 import jalview.datamodel.SequenceCollectionI;
43 import jalview.datamodel.SequenceGroup;
44 import jalview.datamodel.SequenceI;
45 import jalview.schemes.Blosum62ColourScheme;
46 import jalview.schemes.ColourSchemeI;
47 import jalview.schemes.PIDColourScheme;
48 import jalview.structure.CommandListener;
49 import jalview.structure.StructureSelectionManager;
50 import jalview.structure.VamsasSource;
51 import jalview.util.Comparison;
52 import jalview.util.MapList;
53 import jalview.util.MappingUtils;
54 import jalview.viewmodel.styles.ViewStyle;
55 import jalview.workers.AlignCalcManager;
56 import jalview.workers.ComplementConsensusThread;
57 import jalview.workers.ConsensusThread;
58 import jalview.workers.StrucConsensusThread;
60 import java.awt.Color;
61 import java.beans.PropertyChangeSupport;
62 import java.util.ArrayDeque;
63 import java.util.ArrayList;
64 import java.util.BitSet;
65 import java.util.Deque;
66 import java.util.HashMap;
67 import java.util.Hashtable;
68 import java.util.List;
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("Gaps", "Number of Gaps",
1915 new Annotation[1], 0f, alignment.getHeight(),
1916 AlignmentAnnotation.LINE_GRAPH);
1917 initGapCounts(gapcounts);
1919 initComplementConsensus();
1924 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1925 * consensus annotation.
1927 public void initComplementConsensus()
1929 if (!alignment.isNucleotide())
1931 final List<AlignedCodonFrame> codonMappings = alignment
1933 if (codonMappings != null && !codonMappings.isEmpty())
1935 boolean doConsensus = false;
1936 for (AlignedCodonFrame mapping : codonMappings)
1938 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1939 MapList[] mapLists = mapping.getdnaToProt();
1940 // mapLists can be empty if project load has not finished resolving
1942 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1950 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1951 "PID for cDNA", new Annotation[1], 0f, 100f,
1952 AlignmentAnnotation.BAR_GRAPH);
1953 initConsensus(complementConsensus);
1959 private void initConsensus(AlignmentAnnotation aa)
1962 aa.autoCalculated = true;
1966 alignment.addAnnotation(aa);
1970 // these should be extracted from the view model - style and settings for
1971 // derived annotation
1972 private void initGapCounts(AlignmentAnnotation gapcounts)
1974 gapcounts.hasText = false;
1975 gapcounts.autoCalculated = true;
1976 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
1980 alignment.addAnnotation(gapcounts);
1984 private void initConservation()
1986 if (showConservation)
1988 if (conservation == null)
1990 conservation = new AlignmentAnnotation("Conservation",
1991 "Conservation of total alignment less than "
1992 + getConsPercGaps() + "% gaps", new Annotation[1],
1993 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1994 conservation.hasText = true;
1995 conservation.autoCalculated = true;
1996 alignment.addAnnotation(conservation);
2001 private void initQuality()
2005 if (quality == null)
2007 quality = new AlignmentAnnotation("Quality",
2008 "Alignment Quality based on Blosum62 scores",
2009 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2010 quality.hasText = true;
2011 quality.autoCalculated = true;
2012 alignment.addAnnotation(quality);
2017 private void initRNAStructure()
2019 if (alignment.hasRNAStructure() && strucConsensus == null)
2021 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
2022 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2023 strucConsensus.hasText = true;
2024 strucConsensus.autoCalculated = true;
2028 alignment.addAnnotation(strucConsensus);
2036 * @see jalview.api.AlignViewportI#calcPanelHeight()
2039 public int calcPanelHeight()
2041 // setHeight of panels
2042 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2044 int charHeight = getCharHeight();
2047 BitSet graphgrp = new BitSet();
2048 for (AlignmentAnnotation aa : anns)
2052 System.err.println("Null annotation row: ignoring.");
2059 if (aa.graphGroup > -1)
2061 if (graphgrp.get(aa.graphGroup))
2067 graphgrp.set(aa.graphGroup);
2074 aa.height += charHeight;
2084 aa.height += aa.graphHeight;
2092 height += aa.height;
2104 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2105 boolean preserveNewGroupSettings)
2107 boolean updateCalcs = false;
2108 boolean conv = isShowGroupConservation();
2109 boolean cons = isShowGroupConsensus();
2110 boolean showprf = isShowSequenceLogo();
2111 boolean showConsHist = isShowConsensusHistogram();
2112 boolean normLogo = isNormaliseSequenceLogo();
2115 * TODO reorder the annotation rows according to group/sequence ordering on
2118 boolean sortg = true;
2120 // remove old automatic annotation
2121 // add any new annotation
2123 // intersect alignment annotation with alignment groups
2125 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2126 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2129 for (int an = 0; an < aan.length; an++)
2131 if (aan[an].autoCalculated && aan[an].groupRef != null)
2133 oldrfs.add(aan[an].groupRef);
2134 alignment.deleteAnnotation(aan[an], false);
2138 if (alignment.getGroups() != null)
2140 for (SequenceGroup sg : alignment.getGroups())
2142 updateCalcs = false;
2143 if (applyGlobalSettings
2144 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2146 // set defaults for this group's conservation/consensus
2147 sg.setshowSequenceLogo(showprf);
2148 sg.setShowConsensusHistogram(showConsHist);
2149 sg.setNormaliseSequenceLogo(normLogo);
2154 alignment.addAnnotation(sg.getConservationRow(), 0);
2159 alignment.addAnnotation(sg.getConsensus(), 0);
2161 // refresh the annotation rows
2164 sg.recalcConservation();
2172 public boolean isDisplayReferenceSeq()
2174 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2178 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2180 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2184 public boolean isColourByReferenceSeq()
2186 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2190 public Color getSequenceColour(SequenceI seq)
2192 Color sqc = sequenceColours.get(seq);
2193 return (sqc == null ? Color.white : sqc);
2197 public void setSequenceColour(SequenceI seq, Color col)
2201 sequenceColours.remove(seq);
2205 sequenceColours.put(seq, col);
2210 public void updateSequenceIdColours()
2212 for (SequenceGroup sg : alignment.getGroups())
2214 if (sg.idColour != null)
2216 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2218 sequenceColours.put(s, sg.idColour);
2225 public void clearSequenceColours()
2227 sequenceColours.clear();
2231 public AlignViewportI getCodingComplement()
2233 return this.codingComplement;
2237 * Set this as the (cDna/protein) complement of the given viewport. Also
2238 * ensures the reverse relationship is set on the given viewport.
2241 public void setCodingComplement(AlignViewportI av)
2245 System.err.println("Ignoring recursive setCodingComplement request");
2249 this.codingComplement = av;
2250 // avoid infinite recursion!
2251 if (av.getCodingComplement() != this)
2253 av.setCodingComplement(this);
2259 public boolean isNucleotide()
2261 return getAlignment() == null ? false : getAlignment().isNucleotide();
2265 public FeaturesDisplayedI getFeaturesDisplayed()
2267 return featuresDisplayed;
2271 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2273 featuresDisplayed = featuresDisplayedI;
2277 public boolean areFeaturesDisplayed()
2279 return featuresDisplayed != null
2280 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2287 * features are displayed if true
2290 public void setShowSequenceFeatures(boolean b)
2292 viewStyle.setShowSequenceFeatures(b);
2296 public boolean isShowSequenceFeatures()
2298 return viewStyle.isShowSequenceFeatures();
2302 public void setShowSequenceFeaturesHeight(boolean selected)
2304 viewStyle.setShowSequenceFeaturesHeight(selected);
2308 public boolean isShowSequenceFeaturesHeight()
2310 return viewStyle.isShowSequenceFeaturesHeight();
2314 public void setShowAnnotation(boolean b)
2316 viewStyle.setShowAnnotation(b);
2320 public boolean isShowAnnotation()
2322 return viewStyle.isShowAnnotation();
2326 public boolean isRightAlignIds()
2328 return viewStyle.isRightAlignIds();
2332 public void setRightAlignIds(boolean rightAlignIds)
2334 viewStyle.setRightAlignIds(rightAlignIds);
2338 public boolean getConservationSelected()
2340 return viewStyle.getConservationSelected();
2344 public void setShowBoxes(boolean state)
2346 viewStyle.setShowBoxes(state);
2351 * @see jalview.api.ViewStyleI#getTextColour()
2354 public Color getTextColour()
2356 return viewStyle.getTextColour();
2361 * @see jalview.api.ViewStyleI#getTextColour2()
2364 public Color getTextColour2()
2366 return viewStyle.getTextColour2();
2371 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2374 public int getThresholdTextColour()
2376 return viewStyle.getThresholdTextColour();
2381 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2384 public boolean isConservationColourSelected()
2386 return viewStyle.isConservationColourSelected();
2391 * @see jalview.api.ViewStyleI#isRenderGaps()
2394 public boolean isRenderGaps()
2396 return viewStyle.isRenderGaps();
2401 * @see jalview.api.ViewStyleI#isShowColourText()
2404 public boolean isShowColourText()
2406 return viewStyle.isShowColourText();
2410 * @param conservationColourSelected
2411 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2414 public void setConservationColourSelected(
2415 boolean conservationColourSelected)
2417 viewStyle.setConservationColourSelected(conservationColourSelected);
2421 * @param showColourText
2422 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2425 public void setShowColourText(boolean showColourText)
2427 viewStyle.setShowColourText(showColourText);
2432 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2435 public void setTextColour(Color textColour)
2437 viewStyle.setTextColour(textColour);
2441 * @param thresholdTextColour
2442 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2445 public void setThresholdTextColour(int thresholdTextColour)
2447 viewStyle.setThresholdTextColour(thresholdTextColour);
2451 * @param textColour2
2452 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2455 public void setTextColour2(Color textColour2)
2457 viewStyle.setTextColour2(textColour2);
2461 public ViewStyleI getViewStyle()
2463 return new ViewStyle(viewStyle);
2467 public void setViewStyle(ViewStyleI settingsForView)
2469 viewStyle = new ViewStyle(settingsForView);
2473 public boolean sameStyle(ViewStyleI them)
2475 return viewStyle.sameStyle(them);
2480 * @see jalview.api.ViewStyleI#getIdWidth()
2483 public int getIdWidth()
2485 return viewStyle.getIdWidth();
2490 * @see jalview.api.ViewStyleI#setIdWidth(int)
2493 public void setIdWidth(int i)
2495 viewStyle.setIdWidth(i);
2500 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2503 public boolean isCentreColumnLabels()
2505 return viewStyle.isCentreColumnLabels();
2509 * @param centreColumnLabels
2510 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2513 public void setCentreColumnLabels(boolean centreColumnLabels)
2515 viewStyle.setCentreColumnLabels(centreColumnLabels);
2520 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2523 public void setShowDBRefs(boolean showdbrefs)
2525 viewStyle.setShowDBRefs(showdbrefs);
2530 * @see jalview.api.ViewStyleI#isShowDBRefs()
2533 public boolean isShowDBRefs()
2535 return viewStyle.isShowDBRefs();
2540 * @see jalview.api.ViewStyleI#isShowNPFeats()
2543 public boolean isShowNPFeats()
2545 return viewStyle.isShowNPFeats();
2549 * @param shownpfeats
2550 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2553 public void setShowNPFeats(boolean shownpfeats)
2555 viewStyle.setShowNPFeats(shownpfeats);
2558 public abstract StructureSelectionManager getStructureSelectionManager();
2561 * Add one command to the command history list.
2565 public void addToHistoryList(CommandI command)
2567 if (this.historyList != null)
2569 this.historyList.push(command);
2570 broadcastCommand(command, false);
2574 protected void broadcastCommand(CommandI command, boolean undo)
2576 getStructureSelectionManager().commandPerformed(command, undo,
2581 * Add one command to the command redo list.
2585 public void addToRedoList(CommandI command)
2587 if (this.redoList != null)
2589 this.redoList.push(command);
2591 broadcastCommand(command, true);
2595 * Clear the command redo list.
2597 public void clearRedoList()
2599 if (this.redoList != null)
2601 this.redoList.clear();
2605 public void setHistoryList(Deque<CommandI> list)
2607 this.historyList = list;
2610 public Deque<CommandI> getHistoryList()
2612 return this.historyList;
2615 public void setRedoList(Deque<CommandI> list)
2617 this.redoList = list;
2620 public Deque<CommandI> getRedoList()
2622 return this.redoList;
2626 public VamsasSource getVamsasSource()
2631 public SequenceAnnotationOrder getSortAnnotationsBy()
2633 return sortAnnotationsBy;
2636 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2638 this.sortAnnotationsBy = sortAnnotationsBy;
2641 public boolean isShowAutocalculatedAbove()
2643 return showAutocalculatedAbove;
2646 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2648 this.showAutocalculatedAbove = showAutocalculatedAbove;
2652 public boolean isScaleProteinAsCdna()
2654 return viewStyle.isScaleProteinAsCdna();
2658 public void setScaleProteinAsCdna(boolean b)
2660 viewStyle.setScaleProteinAsCdna(b);
2664 * @return true if view should scroll to show the highlighted region of a
2669 public final boolean isFollowHighlight()
2671 return followHighlight;
2675 public final void setFollowHighlight(boolean b)
2677 this.followHighlight = b;
2680 public int getStartRes()
2686 public int getEndRes()
2691 public int getStartSeq()
2696 public void setStartRes(int res)
2698 this.startRes = res;
2701 public void setStartSeq(int seq)
2703 this.startSeq = seq;
2706 public void setEndRes(int res)
2708 if (res > alignment.getWidth() - 1)
2710 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2711 // (alignment.getWidth()-1));
2712 res = alignment.getWidth() - 1;
2721 public void setEndSeq(int seq)
2723 if (seq > alignment.getHeight())
2725 seq = alignment.getHeight();
2734 public int getEndSeq()
2740 * Helper method to populate the SearchResults with the location in the
2741 * complementary alignment to scroll to, in order to match this one.
2744 * the SearchResults to add to
2745 * @return the offset (below top of visible region) of the matched sequence
2747 protected int findComplementScrollTarget(SearchResultsI sr)
2749 final AlignViewportI complement = getCodingComplement();
2750 if (complement == null || !complement.isFollowHighlight())
2754 boolean iAmProtein = !getAlignment().isNucleotide();
2755 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2757 if (proteinAlignment == null)
2761 final List<AlignedCodonFrame> mappings = proteinAlignment
2765 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2766 * residue in the middle column of the visible region. Scroll the
2767 * complementary alignment to line up the corresponding residue.
2770 SequenceI sequence = null;
2773 * locate 'middle' column (true middle if an odd number visible, left of
2774 * middle if an even number visible)
2776 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2777 final HiddenSequences hiddenSequences = getAlignment()
2778 .getHiddenSequences();
2781 * searching to the bottom of the alignment gives smoother scrolling across
2782 * all gapped visible regions
2784 int lastSeq = alignment.getHeight() - 1;
2785 List<AlignedCodonFrame> seqMappings = null;
2786 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2788 sequence = getAlignment().getSequenceAt(seqNo);
2789 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2793 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2797 seqMappings = MappingUtils
2798 .findMappingsForSequenceAndOthers(sequence, mappings,
2799 getCodingComplement().getAlignment().getSequences());
2800 if (!seqMappings.isEmpty())
2806 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2809 * No ungapped mapped sequence in middle column - do nothing
2813 MappingUtils.addSearchResults(sr, sequence,
2814 sequence.findPosition(middleColumn), seqMappings);
2819 * synthesize a column selection if none exists so it covers the given
2820 * selection group. if wholewidth is false, no column selection is made if the
2821 * selection group covers the whole alignment width.
2826 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2829 if (sg != null && (sgs = sg.getStartRes()) >= 0
2830 && sg.getStartRes() <= (sge = sg.getEndRes())
2831 && !this.hasSelectedColumns())
2833 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2840 colSel = new ColumnSelection();
2842 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2844 colSel.addElement(cspos);
2850 * hold status of current selection group - defined on alignment or not.
2852 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;