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.analysis.Profile;
26 import jalview.api.AlignCalcManagerI;
27 import jalview.api.AlignViewportI;
28 import jalview.api.AlignmentViewPanel;
29 import jalview.api.FeaturesDisplayedI;
30 import jalview.api.ViewStyleI;
31 import jalview.commands.CommandI;
32 import jalview.datamodel.AlignedCodonFrame;
33 import jalview.datamodel.AlignmentAnnotation;
34 import jalview.datamodel.AlignmentI;
35 import jalview.datamodel.AlignmentView;
36 import jalview.datamodel.Annotation;
37 import jalview.datamodel.CigarArray;
38 import jalview.datamodel.ColumnSelection;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.SearchResults;
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 cs.setConservationApplied(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.alignmentChanged(alignment, hiddenRepSequences);
635 if (getColourAppliesToAllGroups())
637 for (SequenceGroup sg : getAlignment().getGroups())
644 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
645 sg.setConsPercGaps(ConsPercGaps);
646 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
647 || cs instanceof Blosum62ColourScheme)
649 sg.cs.setThreshold(viewStyle.getThreshold(),
650 isIgnoreGapsConsensus());
655 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
658 if (getConservationSelected())
660 sg.cs.setConservationApplied(true);
665 sg.cs.setConservation(null);
666 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
670 sg.recalcConservation();
674 sg.cs.alignmentChanged(sg, hiddenRepSequences);
681 public ColourSchemeI getGlobalColourScheme()
683 return globalColourScheme;
686 protected AlignmentAnnotation consensus;
688 protected AlignmentAnnotation complementConsensus;
690 protected AlignmentAnnotation strucConsensus;
692 protected AlignmentAnnotation conservation;
694 protected AlignmentAnnotation quality;
696 protected AlignmentAnnotation[] groupConsensus;
698 protected AlignmentAnnotation[] groupConservation;
701 * results of alignment consensus analysis for visible portion of view
703 protected Profile[] hconsensus = null;
706 * results of cDNA complement consensus visible portion of view
708 protected Hashtable[] hcomplementConsensus = null;
711 * results of secondary structure base pair consensus for visible portion of
714 protected Hashtable[] hStrucConsensus = null;
716 protected Conservation hconservation = null;
719 public void setConservation(Conservation cons)
721 hconservation = cons;
725 * percentage gaps allowed in a column before all amino acid properties should
726 * be considered unconserved
728 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
731 public int getConsPercGaps()
737 public void setSequenceConsensusHash(Profile[] hconsensus)
739 this.hconsensus = hconsensus;
743 public void setComplementConsensusHash(Hashtable[] hconsensus)
745 this.hcomplementConsensus = hconsensus;
749 public Profile[] getSequenceConsensusHash()
755 public Hashtable[] getComplementConsensusHash()
757 return hcomplementConsensus;
761 public Hashtable[] getRnaStructureConsensusHash()
763 return hStrucConsensus;
767 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
769 this.hStrucConsensus = hStrucConsensus;
774 public AlignmentAnnotation getAlignmentQualityAnnot()
780 public AlignmentAnnotation getAlignmentConservationAnnotation()
786 public AlignmentAnnotation getAlignmentConsensusAnnotation()
792 public AlignmentAnnotation getComplementConsensusAnnotation()
794 return complementConsensus;
798 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
800 return strucConsensus;
803 protected AlignCalcManagerI calculator = new AlignCalcManager();
806 * trigger update of conservation annotation
808 public void updateConservation(final AlignmentViewPanel ap)
810 // see note in mantis : issue number 8585
811 if (alignment.isNucleotide()
812 || (conservation == null && quality == null)
813 || !autoCalculateConsensus)
818 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
820 calculator.registerWorker(new jalview.workers.ConservationThread(
826 * trigger update of consensus annotation
828 public void updateConsensus(final AlignmentViewPanel ap)
830 // see note in mantis : issue number 8585
831 if (consensus == null || !autoCalculateConsensus)
835 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
837 calculator.registerWorker(new ConsensusThread(this, ap));
841 * A separate thread to compute cDNA consensus for a protein alignment
842 * which has mapping to cDNA
844 final AlignmentI al = this.getAlignment();
845 if (!al.isNucleotide() && al.getCodonFrames() != null
846 && !al.getCodonFrames().isEmpty())
849 * fudge - check first for protein-to-nucleotide mappings
850 * (we don't want to do this for protein-to-protein)
852 boolean doConsensus = false;
853 for (AlignedCodonFrame mapping : al.getCodonFrames())
855 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
856 MapList[] mapLists = mapping.getdnaToProt();
857 // mapLists can be empty if project load has not finished resolving seqs
858 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
867 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
870 .registerWorker(new ComplementConsensusThread(this, ap));
876 // --------START Structure Conservation
877 public void updateStrucConsensus(final AlignmentViewPanel ap)
879 if (autoCalculateStrucConsensus && strucConsensus == null
880 && alignment.isNucleotide() && alignment.hasRNAStructure())
882 // secondary structure has been added - so init the consensus line
886 // see note in mantis : issue number 8585
887 if (strucConsensus == null || !autoCalculateStrucConsensus)
891 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
893 calculator.registerWorker(new StrucConsensusThread(this, ap));
897 public boolean isCalcInProgress()
899 return calculator.isWorking();
903 public boolean isCalculationInProgress(
904 AlignmentAnnotation alignmentAnnotation)
906 if (!alignmentAnnotation.autoCalculated)
910 if (calculator.workingInvolvedWith(alignmentAnnotation))
912 // System.err.println("grey out ("+alignmentAnnotation.label+")");
918 public void setAlignment(AlignmentI align)
920 this.alignment = align;
924 * Clean up references when this viewport is closed
927 public void dispose()
930 * defensively null out references to large objects in case
931 * this object is not garbage collected (as if!)
934 complementConsensus = null;
935 strucConsensus = null;
938 groupConsensus = null;
939 groupConservation = null;
941 hcomplementConsensus = null;
942 // colour scheme may hold reference to consensus
943 globalColourScheme = null;
944 // TODO remove listeners from changeSupport?
945 changeSupport = null;
950 public boolean isClosed()
952 // TODO: check that this isClosed is only true after panel is closed, not
953 // before it is fully constructed.
954 return alignment == null;
958 public AlignCalcManagerI getCalcManager()
964 * should conservation rows be shown for groups
966 protected boolean showGroupConservation = false;
969 * should consensus rows be shown for groups
971 protected boolean showGroupConsensus = false;
974 * should consensus profile be rendered by default
976 protected boolean showSequenceLogo = false;
979 * should consensus profile be rendered normalised to row height
981 protected boolean normaliseSequenceLogo = false;
984 * should consensus histograms be rendered by default
986 protected boolean showConsensusHistogram = true;
989 * @return the showConsensusProfile
992 public boolean isShowSequenceLogo()
994 return showSequenceLogo;
998 * @param showSequenceLogo
1001 public void setShowSequenceLogo(boolean showSequenceLogo)
1003 if (showSequenceLogo != this.showSequenceLogo)
1005 // TODO: decouple settings setting from calculation when refactoring
1006 // annotation update method from alignframe to viewport
1007 this.showSequenceLogo = showSequenceLogo;
1008 calculator.updateAnnotationFor(ConsensusThread.class);
1009 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1010 calculator.updateAnnotationFor(StrucConsensusThread.class);
1012 this.showSequenceLogo = showSequenceLogo;
1016 * @param showConsensusHistogram
1017 * the showConsensusHistogram to set
1019 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1021 this.showConsensusHistogram = showConsensusHistogram;
1025 * @return the showGroupConservation
1027 public boolean isShowGroupConservation()
1029 return showGroupConservation;
1033 * @param showGroupConservation
1034 * the showGroupConservation to set
1036 public void setShowGroupConservation(boolean showGroupConservation)
1038 this.showGroupConservation = showGroupConservation;
1042 * @return the showGroupConsensus
1044 public boolean isShowGroupConsensus()
1046 return showGroupConsensus;
1050 * @param showGroupConsensus
1051 * the showGroupConsensus to set
1053 public void setShowGroupConsensus(boolean showGroupConsensus)
1055 this.showGroupConsensus = showGroupConsensus;
1060 * @return flag to indicate if the consensus histogram should be rendered by
1064 public boolean isShowConsensusHistogram()
1066 return this.showConsensusHistogram;
1070 * when set, updateAlignment will always ensure sequences are of equal length
1072 private boolean padGaps = false;
1075 * when set, alignment should be reordered according to a newly opened tree
1077 public boolean sortByTree = false;
1082 * @return null or the currently selected sequence region
1085 public SequenceGroup getSelectionGroup()
1087 return selectionGroup;
1091 * Set the selection group for this window.
1094 * - group holding references to sequences in this alignment view
1098 public void setSelectionGroup(SequenceGroup sg)
1100 selectionGroup = sg;
1103 public void setHiddenColumns(ColumnSelection colsel)
1105 this.colSel = colsel;
1109 public ColumnSelection getColumnSelection()
1115 public void setColumnSelection(ColumnSelection colSel)
1117 this.colSel = colSel;
1120 updateHiddenColumns();
1122 isColSelChanged(true);
1130 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1132 return hiddenRepSequences;
1136 public void setHiddenRepSequences(
1137 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1139 this.hiddenRepSequences = hiddenRepSequences;
1143 public boolean hasSelectedColumns()
1145 ColumnSelection columnSelection = getColumnSelection();
1146 return columnSelection != null && columnSelection.hasSelectedColumns();
1150 public boolean hasHiddenColumns()
1152 return colSel != null && colSel.hasHiddenColumns();
1155 public void updateHiddenColumns()
1157 // this method doesn't really do anything now. But - it could, since a
1158 // column Selection could be in the process of modification
1159 // hasHiddenColumns = colSel.hasHiddenColumns();
1163 public boolean hasHiddenRows()
1165 return alignment.getHiddenSequences().getSize() > 0;
1168 protected SequenceGroup selectionGroup;
1170 public void setSequenceSetId(String newid)
1172 if (sequenceSetID != null)
1175 .println("Warning - overwriting a sequenceSetId for a viewport!");
1177 sequenceSetID = new String(newid);
1181 public String getSequenceSetId()
1183 if (sequenceSetID == null)
1185 sequenceSetID = alignment.hashCode() + "";
1188 return sequenceSetID;
1192 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1195 protected String viewId = null;
1198 public String getViewId()
1202 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1207 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1209 ignoreGapsInConsensusCalculation = b;
1212 updateConsensus(ap);
1213 if (globalColourScheme != null)
1215 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1216 ignoreGapsInConsensusCalculation);
1222 private long sgrouphash = -1, colselhash = -1;
1225 * checks current SelectionGroup against record of last hash value, and
1229 * update the record of last hash value
1231 * @return true if SelectionGroup changed since last call (when b is true)
1233 public boolean isSelectionGroupChanged(boolean b)
1235 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1236 : selectionGroup.hashCode();
1237 if (hc != -1 && hc != sgrouphash)
1249 * checks current colsel against record of last hash value, and optionally
1253 * update the record of last hash value
1254 * @return true if colsel changed since last call (when b is true)
1256 public boolean isColSelChanged(boolean b)
1258 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1259 if (hc != -1 && hc != colselhash)
1271 public boolean isIgnoreGapsConsensus()
1273 return ignoreGapsInConsensusCalculation;
1276 // property change stuff
1277 // JBPNote Prolly only need this in the applet version.
1278 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1281 protected boolean showConservation = true;
1283 protected boolean showQuality = true;
1285 protected boolean showConsensus = true;
1287 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1289 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1291 protected boolean showAutocalculatedAbove;
1294 * when set, view will scroll to show the highlighted position
1296 private boolean followHighlight = true;
1298 // TODO private with getters and setters?
1299 public int startRes;
1303 public int startSeq;
1308 * Property change listener for changes in alignment
1313 public void addPropertyChangeListener(
1314 java.beans.PropertyChangeListener listener)
1316 changeSupport.addPropertyChangeListener(listener);
1325 public void removePropertyChangeListener(
1326 java.beans.PropertyChangeListener listener)
1328 changeSupport.removePropertyChangeListener(listener);
1332 * Property change listener for changes in alignment
1341 public void firePropertyChange(String prop, Object oldvalue,
1344 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1347 // common hide/show column stuff
1349 public void hideSelectedColumns()
1351 if (colSel.isEmpty())
1356 colSel.hideSelectedColumns();
1357 setSelectionGroup(null);
1358 isColSelChanged(true);
1361 public void hideColumns(int start, int end)
1365 colSel.hideColumns(start);
1369 colSel.hideColumns(start, end);
1371 isColSelChanged(true);
1374 public void showColumn(int col)
1376 colSel.revealHiddenColumns(col);
1377 isColSelChanged(true);
1380 public void showAllHiddenColumns()
1382 colSel.revealAllHiddenColumns();
1383 isColSelChanged(true);
1386 // common hide/show seq stuff
1387 public void showAllHiddenSeqs()
1389 if (alignment.getHiddenSequences().getSize() > 0)
1391 if (selectionGroup == null)
1393 selectionGroup = new SequenceGroup();
1394 selectionGroup.setEndRes(alignment.getWidth() - 1);
1396 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1397 hiddenRepSequences);
1398 for (SequenceI seq : tmp)
1400 selectionGroup.addSequence(seq, false);
1401 setSequenceAnnotationsVisible(seq, true);
1404 hiddenRepSequences = null;
1406 firePropertyChange("alignment", null, alignment.getSequences());
1407 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1413 public void showSequence(int index)
1415 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1416 index, hiddenRepSequences);
1419 if (selectionGroup == null)
1421 selectionGroup = new SequenceGroup();
1422 selectionGroup.setEndRes(alignment.getWidth() - 1);
1425 for (SequenceI seq : tmp)
1427 selectionGroup.addSequence(seq, false);
1428 setSequenceAnnotationsVisible(seq, true);
1430 firePropertyChange("alignment", null, alignment.getSequences());
1435 public void hideAllSelectedSeqs()
1437 if (selectionGroup == null || selectionGroup.getSize() < 1)
1442 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1446 setSelectionGroup(null);
1449 public void hideSequence(SequenceI[] seq)
1453 for (int i = 0; i < seq.length; i++)
1455 alignment.getHiddenSequences().hideSequence(seq[i]);
1456 setSequenceAnnotationsVisible(seq[i], false);
1458 firePropertyChange("alignment", null, alignment.getSequences());
1463 * Hides the specified sequence, or the sequences it represents
1466 * the sequence to hide, or keep as representative
1467 * @param representGroup
1468 * if true, hide the current selection group except for the
1469 * representative sequence
1471 public void hideSequences(SequenceI sequence, boolean representGroup)
1473 if (selectionGroup == null || selectionGroup.getSize() < 1)
1475 hideSequence(new SequenceI[] { sequence });
1481 hideRepSequences(sequence, selectionGroup);
1482 setSelectionGroup(null);
1486 int gsize = selectionGroup.getSize();
1487 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1488 new SequenceI[gsize]);
1490 hideSequence(hseqs);
1491 setSelectionGroup(null);
1496 * Set visibility for any annotations for the given sequence.
1500 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1503 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1506 for (AlignmentAnnotation ann : anns)
1508 if (ann.sequenceRef == sequenceI)
1510 ann.visible = visible;
1516 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1518 int sSize = sg.getSize();
1524 if (hiddenRepSequences == null)
1526 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1529 hiddenRepSequences.put(repSequence, sg);
1531 // Hide all sequences except the repSequence
1532 SequenceI[] seqs = new SequenceI[sSize - 1];
1534 for (int i = 0; i < sSize; i++)
1536 if (sg.getSequenceAt(i) != repSequence)
1538 if (index == sSize - 1)
1543 seqs[index++] = sg.getSequenceAt(i);
1546 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1547 sg.setHidereps(true); // note: not done in 2.7applet
1554 * @return null or the current reference sequence
1556 public SequenceI getReferenceSeq()
1558 return alignment.getSeqrep();
1563 * @return true iff seq is the reference for the alignment
1565 public boolean isReferenceSeq(SequenceI seq)
1567 return alignment.getSeqrep() == seq;
1573 * @return true if there are sequences represented by this sequence that are
1576 public boolean isHiddenRepSequence(SequenceI seq)
1578 return (hiddenRepSequences != null && hiddenRepSequences
1585 * @return null or a sequence group containing the sequences that seq
1588 public SequenceGroup getRepresentedSequences(SequenceI seq)
1590 return (SequenceGroup) (hiddenRepSequences == null ? null
1591 : hiddenRepSequences.get(seq));
1595 public int adjustForHiddenSeqs(int alignmentIndex)
1597 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1602 public void invertColumnSelection()
1604 colSel.invertColumnSelection(0, alignment.getWidth());
1608 public SequenceI[] getSelectionAsNewSequence()
1610 SequenceI[] sequences;
1611 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1612 // this was the only caller in the applet for this method
1613 // JBPNote: in applet, this method returned references to the alignment
1614 // sequences, and it did not honour the presence/absence of annotation
1615 // attached to the alignment (probably!)
1616 if (selectionGroup == null || selectionGroup.getSize() == 0)
1618 sequences = alignment.getSequencesArray();
1619 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1620 for (int i = 0; i < sequences.length; i++)
1622 // construct new sequence with subset of visible annotation
1623 sequences[i] = new Sequence(sequences[i], annots);
1628 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1635 public SequenceI[] getSequenceSelection()
1637 SequenceI[] sequences = null;
1638 if (selectionGroup != null)
1640 sequences = selectionGroup.getSequencesInOrder(alignment);
1642 if (sequences == null)
1644 sequences = alignment.getSequencesArray();
1650 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1652 return new CigarArray(alignment, colSel,
1653 (selectedRegionOnly ? selectionGroup : null));
1657 public jalview.datamodel.AlignmentView getAlignmentView(
1658 boolean selectedOnly)
1660 return getAlignmentView(selectedOnly, false);
1664 public jalview.datamodel.AlignmentView getAlignmentView(
1665 boolean selectedOnly, boolean markGroups)
1667 return new AlignmentView(alignment, colSel, selectionGroup,
1668 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1673 public String[] getViewAsString(boolean selectedRegionOnly)
1675 return getViewAsString(selectedRegionOnly, true);
1679 public String[] getViewAsString(boolean selectedRegionOnly,
1680 boolean exportHiddenSeqs)
1682 String[] selection = null;
1683 SequenceI[] seqs = null;
1685 int start = 0, end = 0;
1686 if (selectedRegionOnly && selectionGroup != null)
1688 iSize = selectionGroup.getSize();
1689 seqs = selectionGroup.getSequencesInOrder(alignment);
1690 start = selectionGroup.getStartRes();
1691 end = selectionGroup.getEndRes() + 1;
1695 if (hasHiddenRows() && exportHiddenSeqs)
1697 AlignmentI fullAlignment = alignment.getHiddenSequences()
1698 .getFullAlignment();
1699 iSize = fullAlignment.getHeight();
1700 seqs = fullAlignment.getSequencesArray();
1701 end = fullAlignment.getWidth();
1705 iSize = alignment.getHeight();
1706 seqs = alignment.getSequencesArray();
1707 end = alignment.getWidth();
1711 selection = new String[iSize];
1712 if (colSel != null && colSel.hasHiddenColumns())
1714 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1718 for (i = 0; i < iSize; i++)
1720 selection[i] = seqs[i].getSequenceAsString(start, end);
1728 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1730 ArrayList<int[]> regions = new ArrayList<int[]>();
1736 if (colSel != null && colSel.hasHiddenColumns())
1740 start = colSel.adjustForHiddenColumns(start);
1743 end = colSel.getHiddenBoundaryRight(start);
1754 regions.add(new int[] { start, end });
1756 if (colSel != null && colSel.hasHiddenColumns())
1758 start = colSel.adjustForHiddenColumns(end);
1759 start = colSel.getHiddenBoundaryLeft(start) + 1;
1761 } while (end < max);
1763 int[][] startEnd = new int[regions.size()][2];
1769 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1770 boolean selectedOnly)
1772 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1773 AlignmentAnnotation[] aa;
1774 if ((aa = alignment.getAlignmentAnnotation()) != null)
1776 for (AlignmentAnnotation annot : aa)
1778 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1779 if (selectedOnly && selectionGroup != null)
1781 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1782 selectionGroup.getEndRes(), clone);
1786 colSel.makeVisibleAnnotation(clone);
1795 public boolean isPadGaps()
1801 public void setPadGaps(boolean padGaps)
1803 this.padGaps = padGaps;
1807 * apply any post-edit constraints and trigger any calculations needed after
1808 * an edit has been performed on the alignment
1813 public void alignmentChanged(AlignmentViewPanel ap)
1817 alignment.padGaps();
1819 if (autoCalculateConsensus)
1821 updateConsensus(ap);
1823 if (hconsensus != null && autoCalculateConsensus)
1825 updateConservation(ap);
1827 if (autoCalculateStrucConsensus)
1829 updateStrucConsensus(ap);
1832 // Reset endRes of groups if beyond alignment width
1833 int alWidth = alignment.getWidth();
1834 List<SequenceGroup> groups = alignment.getGroups();
1837 for (SequenceGroup sg : groups)
1839 if (sg.getEndRes() > alWidth)
1841 sg.setEndRes(alWidth - 1);
1846 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1848 selectionGroup.setEndRes(alWidth - 1);
1851 resetAllColourSchemes();
1852 calculator.restartWorkers();
1853 // alignment.adjustSequenceAnnotations();
1857 * reset scope and do calculations for all applied colourschemes on alignment
1859 void resetAllColourSchemes()
1861 ColourSchemeI cs = globalColourScheme;
1864 cs.alignmentChanged(alignment, hiddenRepSequences);
1866 cs.setConsensus(hconsensus);
1867 if (cs.conservationApplied())
1869 cs.setConservation(Conservation.calculateConservation("All", 3,
1870 alignment.getSequences(), 0, alignment.getWidth(), false,
1871 getConsPercGaps(), false));
1875 for (SequenceGroup sg : alignment.getGroups())
1879 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1881 sg.recalcConservation();
1885 protected void initAutoAnnotation()
1887 // TODO: add menu option action that nulls or creates consensus object
1888 // depending on if the user wants to see the annotation or not in a
1889 // specific alignment
1891 if (hconsensus == null && !isDataset)
1893 if (!alignment.isNucleotide())
1902 consensus = new AlignmentAnnotation("Consensus", "PID",
1903 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1904 initConsensus(consensus);
1906 initComplementConsensus();
1911 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1912 * consensus annotation.
1914 public void initComplementConsensus()
1916 if (!alignment.isNucleotide())
1918 final List<AlignedCodonFrame> codonMappings = alignment
1920 if (codonMappings != null && !codonMappings.isEmpty())
1922 boolean doConsensus = false;
1923 for (AlignedCodonFrame mapping : codonMappings)
1925 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1926 MapList[] mapLists = mapping.getdnaToProt();
1927 // mapLists can be empty if project load has not finished resolving
1929 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1937 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1938 "PID for cDNA", new Annotation[1], 0f, 100f,
1939 AlignmentAnnotation.BAR_GRAPH);
1940 initConsensus(complementConsensus);
1946 private void initConsensus(AlignmentAnnotation aa)
1949 aa.autoCalculated = true;
1953 alignment.addAnnotation(aa);
1957 private void initConservation()
1959 if (showConservation)
1961 if (conservation == null)
1963 conservation = new AlignmentAnnotation("Conservation",
1964 "Conservation of total alignment less than "
1965 + getConsPercGaps() + "% gaps", new Annotation[1],
1966 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1967 conservation.hasText = true;
1968 conservation.autoCalculated = true;
1969 alignment.addAnnotation(conservation);
1974 private void initQuality()
1978 if (quality == null)
1980 quality = new AlignmentAnnotation("Quality",
1981 "Alignment Quality based on Blosum62 scores",
1982 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1983 quality.hasText = true;
1984 quality.autoCalculated = true;
1985 alignment.addAnnotation(quality);
1990 private void initRNAStructure()
1992 if (alignment.hasRNAStructure() && strucConsensus == null)
1994 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1995 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1996 strucConsensus.hasText = true;
1997 strucConsensus.autoCalculated = true;
2001 alignment.addAnnotation(strucConsensus);
2009 * @see jalview.api.AlignViewportI#calcPanelHeight()
2012 public int calcPanelHeight()
2014 // setHeight of panels
2015 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2017 int charHeight = getCharHeight();
2020 BitSet graphgrp = new BitSet();
2021 for (AlignmentAnnotation aa : anns)
2025 System.err.println("Null annotation row: ignoring.");
2032 if (aa.graphGroup > -1)
2034 if (graphgrp.get(aa.graphGroup))
2040 graphgrp.set(aa.graphGroup);
2047 aa.height += charHeight;
2057 aa.height += aa.graphHeight;
2065 height += aa.height;
2077 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2078 boolean preserveNewGroupSettings)
2080 boolean updateCalcs = false;
2081 boolean conv = isShowGroupConservation();
2082 boolean cons = isShowGroupConsensus();
2083 boolean showprf = isShowSequenceLogo();
2084 boolean showConsHist = isShowConsensusHistogram();
2085 boolean normLogo = isNormaliseSequenceLogo();
2088 * TODO reorder the annotation rows according to group/sequence ordering on
2091 boolean sortg = true;
2093 // remove old automatic annotation
2094 // add any new annotation
2096 // intersect alignment annotation with alignment groups
2098 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2099 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2102 for (int an = 0; an < aan.length; an++)
2104 if (aan[an].autoCalculated && aan[an].groupRef != null)
2106 oldrfs.add(aan[an].groupRef);
2107 alignment.deleteAnnotation(aan[an], false);
2111 if (alignment.getGroups() != null)
2113 for (SequenceGroup sg : alignment.getGroups())
2115 updateCalcs = false;
2116 if (applyGlobalSettings
2117 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2119 // set defaults for this group's conservation/consensus
2120 sg.setshowSequenceLogo(showprf);
2121 sg.setShowConsensusHistogram(showConsHist);
2122 sg.setNormaliseSequenceLogo(normLogo);
2127 alignment.addAnnotation(sg.getConservationRow(), 0);
2132 alignment.addAnnotation(sg.getConsensus(), 0);
2134 // refresh the annotation rows
2137 sg.recalcConservation();
2145 public boolean isDisplayReferenceSeq()
2147 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2151 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2153 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2157 public boolean isColourByReferenceSeq()
2159 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2163 public Color getSequenceColour(SequenceI seq)
2165 Color sqc = sequenceColours.get(seq);
2166 return (sqc == null ? Color.white : sqc);
2170 public void setSequenceColour(SequenceI seq, Color col)
2174 sequenceColours.remove(seq);
2178 sequenceColours.put(seq, col);
2183 public void updateSequenceIdColours()
2185 for (SequenceGroup sg : alignment.getGroups())
2187 if (sg.idColour != null)
2189 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2191 sequenceColours.put(s, sg.idColour);
2198 public void clearSequenceColours()
2200 sequenceColours.clear();
2204 public AlignViewportI getCodingComplement()
2206 return this.codingComplement;
2210 * Set this as the (cDna/protein) complement of the given viewport. Also
2211 * ensures the reverse relationship is set on the given viewport.
2214 public void setCodingComplement(AlignViewportI av)
2218 System.err.println("Ignoring recursive setCodingComplement request");
2222 this.codingComplement = av;
2223 // avoid infinite recursion!
2224 if (av.getCodingComplement() != this)
2226 av.setCodingComplement(this);
2232 public boolean isNucleotide()
2234 return getAlignment() == null ? false : getAlignment().isNucleotide();
2238 public FeaturesDisplayedI getFeaturesDisplayed()
2240 return featuresDisplayed;
2244 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2246 featuresDisplayed = featuresDisplayedI;
2250 public boolean areFeaturesDisplayed()
2252 return featuresDisplayed != null
2253 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2260 * features are displayed if true
2263 public void setShowSequenceFeatures(boolean b)
2265 viewStyle.setShowSequenceFeatures(b);
2269 public boolean isShowSequenceFeatures()
2271 return viewStyle.isShowSequenceFeatures();
2275 public void setShowSequenceFeaturesHeight(boolean selected)
2277 viewStyle.setShowSequenceFeaturesHeight(selected);
2281 public boolean isShowSequenceFeaturesHeight()
2283 return viewStyle.isShowSequenceFeaturesHeight();
2287 public void setShowAnnotation(boolean b)
2289 viewStyle.setShowAnnotation(b);
2293 public boolean isShowAnnotation()
2295 return viewStyle.isShowAnnotation();
2299 public boolean isRightAlignIds()
2301 return viewStyle.isRightAlignIds();
2305 public void setRightAlignIds(boolean rightAlignIds)
2307 viewStyle.setRightAlignIds(rightAlignIds);
2311 public boolean getConservationSelected()
2313 return viewStyle.getConservationSelected();
2317 public void setShowBoxes(boolean state)
2319 viewStyle.setShowBoxes(state);
2324 * @see jalview.api.ViewStyleI#getTextColour()
2327 public Color getTextColour()
2329 return viewStyle.getTextColour();
2334 * @see jalview.api.ViewStyleI#getTextColour2()
2337 public Color getTextColour2()
2339 return viewStyle.getTextColour2();
2344 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2347 public int getThresholdTextColour()
2349 return viewStyle.getThresholdTextColour();
2354 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2357 public boolean isConservationColourSelected()
2359 return viewStyle.isConservationColourSelected();
2364 * @see jalview.api.ViewStyleI#isRenderGaps()
2367 public boolean isRenderGaps()
2369 return viewStyle.isRenderGaps();
2374 * @see jalview.api.ViewStyleI#isShowColourText()
2377 public boolean isShowColourText()
2379 return viewStyle.isShowColourText();
2383 * @param conservationColourSelected
2384 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2387 public void setConservationColourSelected(
2388 boolean conservationColourSelected)
2390 viewStyle.setConservationColourSelected(conservationColourSelected);
2394 * @param showColourText
2395 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2398 public void setShowColourText(boolean showColourText)
2400 viewStyle.setShowColourText(showColourText);
2405 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2408 public void setTextColour(Color textColour)
2410 viewStyle.setTextColour(textColour);
2414 * @param thresholdTextColour
2415 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2418 public void setThresholdTextColour(int thresholdTextColour)
2420 viewStyle.setThresholdTextColour(thresholdTextColour);
2424 * @param textColour2
2425 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2428 public void setTextColour2(Color textColour2)
2430 viewStyle.setTextColour2(textColour2);
2434 public ViewStyleI getViewStyle()
2436 return new ViewStyle(viewStyle);
2440 public void setViewStyle(ViewStyleI settingsForView)
2442 viewStyle = new ViewStyle(settingsForView);
2446 public boolean sameStyle(ViewStyleI them)
2448 return viewStyle.sameStyle(them);
2453 * @see jalview.api.ViewStyleI#getIdWidth()
2456 public int getIdWidth()
2458 return viewStyle.getIdWidth();
2463 * @see jalview.api.ViewStyleI#setIdWidth(int)
2466 public void setIdWidth(int i)
2468 viewStyle.setIdWidth(i);
2473 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2476 public boolean isCentreColumnLabels()
2478 return viewStyle.isCentreColumnLabels();
2482 * @param centreColumnLabels
2483 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2486 public void setCentreColumnLabels(boolean centreColumnLabels)
2488 viewStyle.setCentreColumnLabels(centreColumnLabels);
2493 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2496 public void setShowDBRefs(boolean showdbrefs)
2498 viewStyle.setShowDBRefs(showdbrefs);
2503 * @see jalview.api.ViewStyleI#isShowDBRefs()
2506 public boolean isShowDBRefs()
2508 return viewStyle.isShowDBRefs();
2513 * @see jalview.api.ViewStyleI#isShowNPFeats()
2516 public boolean isShowNPFeats()
2518 return viewStyle.isShowNPFeats();
2522 * @param shownpfeats
2523 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2526 public void setShowNPFeats(boolean shownpfeats)
2528 viewStyle.setShowNPFeats(shownpfeats);
2531 public abstract StructureSelectionManager getStructureSelectionManager();
2534 * Add one command to the command history list.
2538 public void addToHistoryList(CommandI command)
2540 if (this.historyList != null)
2542 this.historyList.push(command);
2543 broadcastCommand(command, false);
2547 protected void broadcastCommand(CommandI command, boolean undo)
2549 getStructureSelectionManager().commandPerformed(command, undo,
2554 * Add one command to the command redo list.
2558 public void addToRedoList(CommandI command)
2560 if (this.redoList != null)
2562 this.redoList.push(command);
2564 broadcastCommand(command, true);
2568 * Clear the command redo list.
2570 public void clearRedoList()
2572 if (this.redoList != null)
2574 this.redoList.clear();
2578 public void setHistoryList(Deque<CommandI> list)
2580 this.historyList = list;
2583 public Deque<CommandI> getHistoryList()
2585 return this.historyList;
2588 public void setRedoList(Deque<CommandI> list)
2590 this.redoList = list;
2593 public Deque<CommandI> getRedoList()
2595 return this.redoList;
2599 public VamsasSource getVamsasSource()
2604 public SequenceAnnotationOrder getSortAnnotationsBy()
2606 return sortAnnotationsBy;
2609 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2611 this.sortAnnotationsBy = sortAnnotationsBy;
2614 public boolean isShowAutocalculatedAbove()
2616 return showAutocalculatedAbove;
2619 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2621 this.showAutocalculatedAbove = showAutocalculatedAbove;
2625 public boolean isScaleProteinAsCdna()
2627 return viewStyle.isScaleProteinAsCdna();
2631 public void setScaleProteinAsCdna(boolean b)
2633 viewStyle.setScaleProteinAsCdna(b);
2637 * @return true if view should scroll to show the highlighted region of a
2642 public final boolean isFollowHighlight()
2644 return followHighlight;
2648 public final void setFollowHighlight(boolean b)
2650 this.followHighlight = b;
2653 public int getStartRes()
2659 public int getEndRes()
2664 public int getStartSeq()
2669 public void setStartRes(int res)
2671 this.startRes = res;
2674 public void setStartSeq(int seq)
2676 this.startSeq = seq;
2679 public void setEndRes(int res)
2681 if (res > alignment.getWidth() - 1)
2683 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2684 // (alignment.getWidth()-1));
2685 res = alignment.getWidth() - 1;
2694 public void setEndSeq(int seq)
2696 if (seq > alignment.getHeight())
2698 seq = alignment.getHeight();
2707 public int getEndSeq()
2713 * Helper method to populate the SearchResults with the location in the
2714 * complementary alignment to scroll to, in order to match this one.
2717 * the SearchResults to add to
2718 * @return the offset (below top of visible region) of the matched sequence
2720 protected int findComplementScrollTarget(SearchResults sr)
2722 final AlignViewportI complement = getCodingComplement();
2723 if (complement == null || !complement.isFollowHighlight())
2727 boolean iAmProtein = !getAlignment().isNucleotide();
2728 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2730 if (proteinAlignment == null)
2734 final List<AlignedCodonFrame> mappings = proteinAlignment
2738 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2739 * residue in the middle column of the visible region. Scroll the
2740 * complementary alignment to line up the corresponding residue.
2743 SequenceI sequence = null;
2746 * locate 'middle' column (true middle if an odd number visible, left of
2747 * middle if an even number visible)
2749 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2750 final HiddenSequences hiddenSequences = getAlignment()
2751 .getHiddenSequences();
2754 * searching to the bottom of the alignment gives smoother scrolling across
2755 * all gapped visible regions
2757 int lastSeq = alignment.getHeight() - 1;
2758 List<AlignedCodonFrame> seqMappings = null;
2759 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2761 sequence = getAlignment().getSequenceAt(seqNo);
2762 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2766 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2770 seqMappings = MappingUtils
2771 .findMappingsForSequenceAndOthers(sequence, mappings,
2772 getCodingComplement().getAlignment().getSequences());
2773 if (!seqMappings.isEmpty())
2779 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2782 * No ungapped mapped sequence in middle column - do nothing
2786 MappingUtils.addSearchResults(sr, sequence,
2787 sequence.findPosition(middleColumn), seqMappings);
2792 * synthesize a column selection if none exists so it covers the given
2793 * selection group. if wholewidth is false, no column selection is made if the
2794 * selection group covers the whole alignment width.
2799 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2802 if (sg != null && (sgs = sg.getStartRes()) >= 0
2803 && sg.getStartRes() <= (sge = sg.getEndRes())
2804 && !this.hasSelectedColumns())
2806 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2813 colSel = new ColumnSelection();
2815 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2817 colSel.addElement(cspos);
2823 * hold status of current selection group - defined on alignment or not.
2825 private boolean selectionIsDefinedGroup = false;
2828 public boolean isSelectionDefinedGroup()
2830 if (selectionGroup == null)
2834 if (isSelectionGroupChanged(true))
2836 selectionIsDefinedGroup = false;
2837 List<SequenceGroup> gps = alignment.getGroups();
2838 if (gps == null || gps.size() == 0)
2840 selectionIsDefinedGroup = false;
2844 selectionIsDefinedGroup = gps.contains(selectionGroup);
2847 return selectionGroup.getContext() == alignment
2848 || selectionIsDefinedGroup;