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.ContactListI;
39 import jalview.datamodel.HiddenSequences;
40 import jalview.datamodel.ProfilesI;
41 import jalview.datamodel.SearchResultsI;
42 import jalview.datamodel.Sequence;
43 import jalview.datamodel.SequenceCollectionI;
44 import jalview.datamodel.SequenceGroup;
45 import jalview.datamodel.SequenceI;
46 import jalview.schemes.Blosum62ColourScheme;
47 import jalview.schemes.ColourSchemeI;
48 import jalview.schemes.PIDColourScheme;
49 import jalview.structure.CommandListener;
50 import jalview.structure.StructureSelectionManager;
51 import jalview.structure.VamsasSource;
52 import jalview.util.Comparison;
53 import jalview.util.MapList;
54 import jalview.util.MappingUtils;
55 import jalview.viewmodel.styles.ViewStyle;
56 import jalview.workers.AlignCalcManager;
57 import jalview.workers.ComplementConsensusThread;
58 import jalview.workers.ConsensusThread;
59 import jalview.workers.StrucConsensusThread;
61 import java.awt.Color;
62 import java.beans.PropertyChangeSupport;
63 import java.util.ArrayDeque;
64 import java.util.ArrayList;
65 import java.util.BitSet;
66 import java.util.Deque;
67 import java.util.HashMap;
68 import java.util.Hashtable;
69 import java.util.List;
73 * base class holding visualization and analysis attributes and common logic for
74 * an active alignment view displayed in the GUI
79 public abstract class AlignmentViewport implements AlignViewportI,
80 CommandListener, VamsasSource
82 protected ViewStyleI viewStyle = new ViewStyle();
85 * A viewport that hosts the cDna view of this (protein), or vice versa (if
88 AlignViewportI codingComplement = null;
90 FeaturesDisplayedI featuresDisplayed = null;
92 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
94 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
98 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
101 public void setFontName(String name)
103 viewStyle.setFontName(name);
108 * @see jalview.api.ViewStyleI#setFontStyle(int)
111 public void setFontStyle(int style)
113 viewStyle.setFontStyle(style);
118 * @see jalview.api.ViewStyleI#setFontSize(int)
121 public void setFontSize(int size)
123 viewStyle.setFontSize(size);
128 * @see jalview.api.ViewStyleI#getFontStyle()
131 public int getFontStyle()
133 return viewStyle.getFontStyle();
138 * @see jalview.api.ViewStyleI#getFontName()
141 public String getFontName()
143 return viewStyle.getFontName();
148 * @see jalview.api.ViewStyleI#getFontSize()
151 public int getFontSize()
153 return viewStyle.getFontSize();
157 * @param upperCasebold
158 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
161 public void setUpperCasebold(boolean upperCasebold)
163 viewStyle.setUpperCasebold(upperCasebold);
168 * @see jalview.api.ViewStyleI#isUpperCasebold()
171 public boolean isUpperCasebold()
173 return viewStyle.isUpperCasebold();
178 * @see jalview.api.ViewStyleI#isSeqNameItalics()
181 public boolean isSeqNameItalics()
183 return viewStyle.isSeqNameItalics();
187 * @param colourByReferenceSeq
188 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
191 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
193 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
198 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
201 public void setColourAppliesToAllGroups(boolean b)
203 viewStyle.setColourAppliesToAllGroups(b);
208 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
211 public boolean getColourAppliesToAllGroups()
213 return viewStyle.getColourAppliesToAllGroups();
218 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
221 public boolean getAbovePIDThreshold()
223 return viewStyle.getAbovePIDThreshold();
228 * @see jalview.api.ViewStyleI#setIncrement(int)
231 public void setIncrement(int inc)
233 viewStyle.setIncrement(inc);
238 * @see jalview.api.ViewStyleI#getIncrement()
241 public int getIncrement()
243 return viewStyle.getIncrement();
248 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
251 public void setConservationSelected(boolean b)
253 viewStyle.setConservationSelected(b);
258 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
261 public void setShowHiddenMarkers(boolean show)
263 viewStyle.setShowHiddenMarkers(show);
268 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
271 public boolean getShowHiddenMarkers()
273 return viewStyle.getShowHiddenMarkers();
278 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
281 public void setScaleRightWrapped(boolean b)
283 viewStyle.setScaleRightWrapped(b);
288 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
291 public void setScaleLeftWrapped(boolean b)
293 viewStyle.setScaleLeftWrapped(b);
298 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
301 public void setScaleAboveWrapped(boolean b)
303 viewStyle.setScaleAboveWrapped(b);
308 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
311 public boolean getScaleLeftWrapped()
313 return viewStyle.getScaleLeftWrapped();
318 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
321 public boolean getScaleAboveWrapped()
323 return viewStyle.getScaleAboveWrapped();
328 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
331 public boolean getScaleRightWrapped()
333 return viewStyle.getScaleRightWrapped();
338 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
341 public void setAbovePIDThreshold(boolean b)
343 viewStyle.setAbovePIDThreshold(b);
348 * @see jalview.api.ViewStyleI#setThreshold(int)
351 public void setThreshold(int thresh)
353 viewStyle.setThreshold(thresh);
358 * @see jalview.api.ViewStyleI#getThreshold()
361 public int getThreshold()
363 return viewStyle.getThreshold();
368 * @see jalview.api.ViewStyleI#getShowJVSuffix()
371 public boolean getShowJVSuffix()
373 return viewStyle.getShowJVSuffix();
378 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
381 public void setShowJVSuffix(boolean b)
383 viewStyle.setShowJVSuffix(b);
388 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
391 public void setWrapAlignment(boolean state)
393 viewStyle.setWrapAlignment(state);
398 * @see jalview.api.ViewStyleI#setShowText(boolean)
401 public void setShowText(boolean state)
403 viewStyle.setShowText(state);
408 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
411 public void setRenderGaps(boolean state)
413 viewStyle.setRenderGaps(state);
418 * @see jalview.api.ViewStyleI#getColourText()
421 public boolean getColourText()
423 return viewStyle.getColourText();
428 * @see jalview.api.ViewStyleI#setColourText(boolean)
431 public void setColourText(boolean state)
433 viewStyle.setColourText(state);
438 * @see jalview.api.ViewStyleI#getWrapAlignment()
441 public boolean getWrapAlignment()
443 return viewStyle.getWrapAlignment();
448 * @see jalview.api.ViewStyleI#getShowText()
451 public boolean getShowText()
453 return viewStyle.getShowText();
458 * @see jalview.api.ViewStyleI#getWrappedWidth()
461 public int getWrappedWidth()
463 return viewStyle.getWrappedWidth();
468 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
471 public void setWrappedWidth(int w)
473 viewStyle.setWrappedWidth(w);
478 * @see jalview.api.ViewStyleI#getCharHeight()
481 public int getCharHeight()
483 return viewStyle.getCharHeight();
488 * @see jalview.api.ViewStyleI#setCharHeight(int)
491 public void setCharHeight(int h)
493 viewStyle.setCharHeight(h);
498 * @see jalview.api.ViewStyleI#getCharWidth()
501 public int getCharWidth()
503 return viewStyle.getCharWidth();
508 * @see jalview.api.ViewStyleI#setCharWidth(int)
511 public void setCharWidth(int w)
513 viewStyle.setCharWidth(w);
518 * @see jalview.api.ViewStyleI#getShowBoxes()
521 public boolean getShowBoxes()
523 return viewStyle.getShowBoxes();
528 * @see jalview.api.ViewStyleI#getShowUnconserved()
531 public boolean getShowUnconserved()
533 return viewStyle.getShowUnconserved();
537 * @param showunconserved
538 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
541 public void setShowUnconserved(boolean showunconserved)
543 viewStyle.setShowUnconserved(showunconserved);
548 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
551 public void setSeqNameItalics(boolean default1)
553 viewStyle.setSeqNameItalics(default1);
557 * alignment displayed in the viewport. Please use get/setter
559 protected AlignmentI alignment;
562 public AlignmentI getAlignment()
568 public char getGapCharacter()
570 return alignment.getGapCharacter();
573 protected String sequenceSetID;
576 * probably unused indicator that view is of a dataset rather than an
579 protected boolean isDataset = false;
581 public void setDataset(boolean b)
586 public boolean isDataset()
591 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
593 protected ColumnSelection colSel = new ColumnSelection();
595 public boolean autoCalculateConsensus = true;
597 protected boolean autoCalculateStrucConsensus = true;
599 protected boolean ignoreGapsInConsensusCalculation = false;
601 protected ColourSchemeI globalColourScheme = null;
604 public void setGlobalColourScheme(ColourSchemeI cs)
606 // TODO: logic refactored from AlignFrame changeColour -
607 // TODO: autorecalc stuff should be changed to rely on the worker system
608 // check to see if we should implement a changeColour(cs) method rather than
609 // put th logic in here
610 // - means that caller decides if they want to just modify state and defer
611 // calculation till later or to do all calculations in thread.
613 globalColourScheme = cs;
614 boolean recalc = false;
617 recalc = getConservationSelected();
618 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
619 || cs instanceof Blosum62ColourScheme)
622 cs.setThreshold(viewStyle.getThreshold(),
623 ignoreGapsInConsensusCalculation);
627 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
631 cs.setConsensus(hconsensus);
632 cs.setConservation(hconservation);
634 cs.setConservationApplied(getConservationSelected());
635 cs.alignmentChanged(alignment, hiddenRepSequences);
637 if (getColourAppliesToAllGroups())
639 for (SequenceGroup sg : getAlignment().getGroups())
646 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
647 sg.setConsPercGaps(ConsPercGaps);
648 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
649 || cs instanceof Blosum62ColourScheme)
651 sg.cs.setThreshold(viewStyle.getThreshold(),
652 isIgnoreGapsConsensus());
657 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
660 if (getConservationSelected())
662 sg.cs.setConservationApplied(true);
667 sg.cs.setConservation(null);
668 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
672 sg.recalcConservation();
676 sg.cs.alignmentChanged(sg, hiddenRepSequences);
683 public ColourSchemeI getGlobalColourScheme()
685 return globalColourScheme;
688 protected AlignmentAnnotation consensus;
690 protected AlignmentAnnotation complementConsensus;
692 protected AlignmentAnnotation strucConsensus;
694 protected AlignmentAnnotation conservation;
696 protected AlignmentAnnotation quality;
698 protected AlignmentAnnotation[] groupConsensus;
700 protected AlignmentAnnotation[] groupConservation;
703 * results of alignment consensus analysis for visible portion of view
705 protected ProfilesI hconsensus = null;
708 * results of cDNA complement consensus visible portion of view
710 protected Hashtable[] hcomplementConsensus = null;
713 * results of secondary structure base pair consensus for visible portion of
716 protected Hashtable[] hStrucConsensus = null;
718 protected Conservation hconservation = null;
721 public void setConservation(Conservation cons)
723 hconservation = cons;
727 * percentage gaps allowed in a column before all amino acid properties should
728 * be considered unconserved
730 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
733 public int getConsPercGaps()
739 public void setSequenceConsensusHash(ProfilesI hconsensus)
741 this.hconsensus = hconsensus;
745 public void setComplementConsensusHash(Hashtable[] hconsensus)
747 this.hcomplementConsensus = hconsensus;
751 public ProfilesI getSequenceConsensusHash()
757 public Hashtable[] getComplementConsensusHash()
759 return hcomplementConsensus;
763 public Hashtable[] getRnaStructureConsensusHash()
765 return hStrucConsensus;
769 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
771 this.hStrucConsensus = hStrucConsensus;
776 public AlignmentAnnotation getAlignmentQualityAnnot()
782 public AlignmentAnnotation getAlignmentConservationAnnotation()
788 public AlignmentAnnotation getAlignmentConsensusAnnotation()
794 public AlignmentAnnotation getComplementConsensusAnnotation()
796 return complementConsensus;
800 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
802 return strucConsensus;
805 protected AlignCalcManagerI calculator = new AlignCalcManager();
808 * trigger update of conservation annotation
810 public void updateConservation(final AlignmentViewPanel ap)
812 // see note in mantis : issue number 8585
813 if (alignment.isNucleotide()
814 || (conservation == null && quality == null)
815 || !autoCalculateConsensus)
820 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
822 calculator.registerWorker(new jalview.workers.ConservationThread(
828 * trigger update of consensus annotation
830 public void updateConsensus(final AlignmentViewPanel ap)
832 // see note in mantis : issue number 8585
833 if (consensus == null || !autoCalculateConsensus)
837 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
839 calculator.registerWorker(new ConsensusThread(this, ap));
843 * A separate thread to compute cDNA consensus for a protein alignment
844 * which has mapping to cDNA
846 final AlignmentI al = this.getAlignment();
847 if (!al.isNucleotide() && al.getCodonFrames() != null
848 && !al.getCodonFrames().isEmpty())
851 * fudge - check first for protein-to-nucleotide mappings
852 * (we don't want to do this for protein-to-protein)
854 boolean doConsensus = false;
855 for (AlignedCodonFrame mapping : al.getCodonFrames())
857 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
858 MapList[] mapLists = mapping.getdnaToProt();
859 // mapLists can be empty if project load has not finished resolving seqs
860 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
869 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
872 .registerWorker(new ComplementConsensusThread(this, ap));
878 // --------START Structure Conservation
879 public void updateStrucConsensus(final AlignmentViewPanel ap)
881 if (autoCalculateStrucConsensus && strucConsensus == null
882 && alignment.isNucleotide() && alignment.hasRNAStructure())
884 // secondary structure has been added - so init the consensus line
888 // see note in mantis : issue number 8585
889 if (strucConsensus == null || !autoCalculateStrucConsensus)
893 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
895 calculator.registerWorker(new StrucConsensusThread(this, ap));
899 public boolean isCalcInProgress()
901 return calculator.isWorking();
905 public boolean isCalculationInProgress(
906 AlignmentAnnotation alignmentAnnotation)
908 if (!alignmentAnnotation.autoCalculated)
912 if (calculator.workingInvolvedWith(alignmentAnnotation))
914 // System.err.println("grey out ("+alignmentAnnotation.label+")");
920 public void setAlignment(AlignmentI align)
922 this.alignment = align;
926 * Clean up references when this viewport is closed
929 public void dispose()
932 * defensively null out references to large objects in case
933 * this object is not garbage collected (as if!)
936 complementConsensus = null;
937 strucConsensus = null;
940 groupConsensus = null;
941 groupConservation = null;
943 hcomplementConsensus = null;
944 // colour scheme may hold reference to consensus
945 globalColourScheme = null;
946 // TODO remove listeners from changeSupport?
947 changeSupport = null;
952 public boolean isClosed()
954 // TODO: check that this isClosed is only true after panel is closed, not
955 // before it is fully constructed.
956 return alignment == null;
960 public AlignCalcManagerI getCalcManager()
966 * should conservation rows be shown for groups
968 protected boolean showGroupConservation = false;
971 * should consensus rows be shown for groups
973 protected boolean showGroupConsensus = false;
976 * should consensus profile be rendered by default
978 protected boolean showSequenceLogo = false;
981 * should consensus profile be rendered normalised to row height
983 protected boolean normaliseSequenceLogo = false;
986 * should consensus histograms be rendered by default
988 protected boolean showConsensusHistogram = true;
991 * @return the showConsensusProfile
994 public boolean isShowSequenceLogo()
996 return showSequenceLogo;
1000 * @param showSequenceLogo
1003 public void setShowSequenceLogo(boolean showSequenceLogo)
1005 if (showSequenceLogo != this.showSequenceLogo)
1007 // TODO: decouple settings setting from calculation when refactoring
1008 // annotation update method from alignframe to viewport
1009 this.showSequenceLogo = showSequenceLogo;
1010 calculator.updateAnnotationFor(ConsensusThread.class);
1011 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1012 calculator.updateAnnotationFor(StrucConsensusThread.class);
1014 this.showSequenceLogo = showSequenceLogo;
1018 * @param showConsensusHistogram
1019 * the showConsensusHistogram to set
1021 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1023 this.showConsensusHistogram = showConsensusHistogram;
1027 * @return the showGroupConservation
1029 public boolean isShowGroupConservation()
1031 return showGroupConservation;
1035 * @param showGroupConservation
1036 * the showGroupConservation to set
1038 public void setShowGroupConservation(boolean showGroupConservation)
1040 this.showGroupConservation = showGroupConservation;
1044 * @return the showGroupConsensus
1046 public boolean isShowGroupConsensus()
1048 return showGroupConsensus;
1052 * @param showGroupConsensus
1053 * the showGroupConsensus to set
1055 public void setShowGroupConsensus(boolean showGroupConsensus)
1057 this.showGroupConsensus = showGroupConsensus;
1062 * @return flag to indicate if the consensus histogram should be rendered by
1066 public boolean isShowConsensusHistogram()
1068 return this.showConsensusHistogram;
1072 * when set, updateAlignment will always ensure sequences are of equal length
1074 private boolean padGaps = false;
1077 * when set, alignment should be reordered according to a newly opened tree
1079 public boolean sortByTree = false;
1084 * @return null or the currently selected sequence region
1087 public SequenceGroup getSelectionGroup()
1089 return selectionGroup;
1093 * Set the selection group for this window.
1096 * - group holding references to sequences in this alignment view
1100 public void setSelectionGroup(SequenceGroup sg)
1102 selectionGroup = sg;
1105 public void setHiddenColumns(ColumnSelection colsel)
1107 this.colSel = colsel;
1111 public ColumnSelection getColumnSelection()
1117 public void setColumnSelection(ColumnSelection colSel)
1119 this.colSel = colSel;
1122 updateHiddenColumns();
1124 isColSelChanged(true);
1132 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1134 return hiddenRepSequences;
1138 public void setHiddenRepSequences(
1139 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1141 this.hiddenRepSequences = hiddenRepSequences;
1145 public boolean hasSelectedColumns()
1147 ColumnSelection columnSelection = getColumnSelection();
1148 return columnSelection != null && columnSelection.hasSelectedColumns();
1152 public boolean hasHiddenColumns()
1154 return colSel != null && colSel.hasHiddenColumns();
1157 public void updateHiddenColumns()
1159 // this method doesn't really do anything now. But - it could, since a
1160 // column Selection could be in the process of modification
1161 // hasHiddenColumns = colSel.hasHiddenColumns();
1165 public boolean hasHiddenRows()
1167 return alignment.getHiddenSequences().getSize() > 0;
1170 protected SequenceGroup selectionGroup;
1172 public void setSequenceSetId(String newid)
1174 if (sequenceSetID != null)
1177 .println("Warning - overwriting a sequenceSetId for a viewport!");
1179 sequenceSetID = new String(newid);
1183 public String getSequenceSetId()
1185 if (sequenceSetID == null)
1187 sequenceSetID = alignment.hashCode() + "";
1190 return sequenceSetID;
1194 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1197 protected String viewId = null;
1200 public String getViewId()
1204 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1209 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1211 ignoreGapsInConsensusCalculation = b;
1214 updateConsensus(ap);
1215 if (globalColourScheme != null)
1217 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1218 ignoreGapsInConsensusCalculation);
1224 private long sgrouphash = -1, colselhash = -1;
1227 * checks current SelectionGroup against record of last hash value, and
1231 * update the record of last hash value
1233 * @return true if SelectionGroup changed since last call (when b is true)
1235 public boolean isSelectionGroupChanged(boolean b)
1237 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1238 : selectionGroup.hashCode();
1239 if (hc != -1 && hc != sgrouphash)
1251 * checks current colsel against record of last hash value, and optionally
1255 * update the record of last hash value
1256 * @return true if colsel changed since last call (when b is true)
1258 public boolean isColSelChanged(boolean b)
1260 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1261 if (hc != -1 && hc != colselhash)
1273 public boolean isIgnoreGapsConsensus()
1275 return ignoreGapsInConsensusCalculation;
1278 // property change stuff
1279 // JBPNote Prolly only need this in the applet version.
1280 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1283 protected boolean showConservation = true;
1285 protected boolean showQuality = true;
1287 protected boolean showConsensus = true;
1289 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1291 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1293 protected boolean showAutocalculatedAbove;
1296 * when set, view will scroll to show the highlighted position
1298 private boolean followHighlight = true;
1300 // TODO private with getters and setters?
1301 public int startRes;
1305 public int startSeq;
1310 * Property change listener for changes in alignment
1315 public void addPropertyChangeListener(
1316 java.beans.PropertyChangeListener listener)
1318 changeSupport.addPropertyChangeListener(listener);
1327 public void removePropertyChangeListener(
1328 java.beans.PropertyChangeListener listener)
1330 changeSupport.removePropertyChangeListener(listener);
1334 * Property change listener for changes in alignment
1343 public void firePropertyChange(String prop, Object oldvalue,
1346 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1349 // common hide/show column stuff
1351 public void hideSelectedColumns()
1353 if (colSel.isEmpty())
1358 colSel.hideSelectedColumns();
1359 setSelectionGroup(null);
1360 isColSelChanged(true);
1363 public void hideColumns(int start, int end)
1367 colSel.hideColumns(start);
1371 colSel.hideColumns(start, end);
1373 isColSelChanged(true);
1376 public void showColumn(int col)
1378 colSel.revealHiddenColumns(col);
1379 isColSelChanged(true);
1382 public void showAllHiddenColumns()
1384 colSel.revealAllHiddenColumns();
1385 isColSelChanged(true);
1388 // common hide/show seq stuff
1389 public void showAllHiddenSeqs()
1391 if (alignment.getHiddenSequences().getSize() > 0)
1393 if (selectionGroup == null)
1395 selectionGroup = new SequenceGroup();
1396 selectionGroup.setEndRes(alignment.getWidth() - 1);
1398 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1399 hiddenRepSequences);
1400 for (SequenceI seq : tmp)
1402 selectionGroup.addSequence(seq, false);
1403 setSequenceAnnotationsVisible(seq, true);
1406 hiddenRepSequences = null;
1408 firePropertyChange("alignment", null, alignment.getSequences());
1409 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1415 public void showSequence(int index)
1417 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1418 index, hiddenRepSequences);
1421 if (selectionGroup == null)
1423 selectionGroup = new SequenceGroup();
1424 selectionGroup.setEndRes(alignment.getWidth() - 1);
1427 for (SequenceI seq : tmp)
1429 selectionGroup.addSequence(seq, false);
1430 setSequenceAnnotationsVisible(seq, true);
1432 firePropertyChange("alignment", null, alignment.getSequences());
1437 public void hideAllSelectedSeqs()
1439 if (selectionGroup == null || selectionGroup.getSize() < 1)
1444 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1448 setSelectionGroup(null);
1451 public void hideSequence(SequenceI[] seq)
1455 for (int i = 0; i < seq.length; i++)
1457 alignment.getHiddenSequences().hideSequence(seq[i]);
1458 setSequenceAnnotationsVisible(seq[i], false);
1460 firePropertyChange("alignment", null, alignment.getSequences());
1465 * Hides the specified sequence, or the sequences it represents
1468 * the sequence to hide, or keep as representative
1469 * @param representGroup
1470 * if true, hide the current selection group except for the
1471 * representative sequence
1473 public void hideSequences(SequenceI sequence, boolean representGroup)
1475 if (selectionGroup == null || selectionGroup.getSize() < 1)
1477 hideSequence(new SequenceI[] { sequence });
1483 hideRepSequences(sequence, selectionGroup);
1484 setSelectionGroup(null);
1488 int gsize = selectionGroup.getSize();
1489 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1490 new SequenceI[gsize]);
1492 hideSequence(hseqs);
1493 setSelectionGroup(null);
1498 * Set visibility for any annotations for the given sequence.
1502 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1505 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1508 for (AlignmentAnnotation ann : anns)
1510 if (ann.sequenceRef == sequenceI)
1512 ann.visible = visible;
1518 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1520 int sSize = sg.getSize();
1526 if (hiddenRepSequences == null)
1528 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1531 hiddenRepSequences.put(repSequence, sg);
1533 // Hide all sequences except the repSequence
1534 SequenceI[] seqs = new SequenceI[sSize - 1];
1536 for (int i = 0; i < sSize; i++)
1538 if (sg.getSequenceAt(i) != repSequence)
1540 if (index == sSize - 1)
1545 seqs[index++] = sg.getSequenceAt(i);
1548 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1549 sg.setHidereps(true); // note: not done in 2.7applet
1556 * @return null or the current reference sequence
1558 public SequenceI getReferenceSeq()
1560 return alignment.getSeqrep();
1565 * @return true iff seq is the reference for the alignment
1567 public boolean isReferenceSeq(SequenceI seq)
1569 return alignment.getSeqrep() == seq;
1575 * @return true if there are sequences represented by this sequence that are
1578 public boolean isHiddenRepSequence(SequenceI seq)
1580 return (hiddenRepSequences != null && hiddenRepSequences
1587 * @return null or a sequence group containing the sequences that seq
1590 public SequenceGroup getRepresentedSequences(SequenceI seq)
1592 return (SequenceGroup) (hiddenRepSequences == null ? null
1593 : hiddenRepSequences.get(seq));
1597 public int adjustForHiddenSeqs(int alignmentIndex)
1599 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1604 public void invertColumnSelection()
1606 colSel.invertColumnSelection(0, alignment.getWidth());
1610 public SequenceI[] getSelectionAsNewSequence()
1612 SequenceI[] sequences;
1613 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1614 // this was the only caller in the applet for this method
1615 // JBPNote: in applet, this method returned references to the alignment
1616 // sequences, and it did not honour the presence/absence of annotation
1617 // attached to the alignment (probably!)
1618 if (selectionGroup == null || selectionGroup.getSize() == 0)
1620 sequences = alignment.getSequencesArray();
1621 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1622 for (int i = 0; i < sequences.length; i++)
1624 // construct new sequence with subset of visible annotation
1625 sequences[i] = new Sequence(sequences[i], annots);
1630 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1637 public SequenceI[] getSequenceSelection()
1639 SequenceI[] sequences = null;
1640 if (selectionGroup != null)
1642 sequences = selectionGroup.getSequencesInOrder(alignment);
1644 if (sequences == null)
1646 sequences = alignment.getSequencesArray();
1652 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1654 return new CigarArray(alignment, colSel,
1655 (selectedRegionOnly ? selectionGroup : null));
1659 public jalview.datamodel.AlignmentView getAlignmentView(
1660 boolean selectedOnly)
1662 return getAlignmentView(selectedOnly, false);
1666 public jalview.datamodel.AlignmentView getAlignmentView(
1667 boolean selectedOnly, boolean markGroups)
1669 return new AlignmentView(alignment, colSel, selectionGroup,
1670 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1675 public String[] getViewAsString(boolean selectedRegionOnly)
1677 return getViewAsString(selectedRegionOnly, true);
1681 public String[] getViewAsString(boolean selectedRegionOnly,
1682 boolean exportHiddenSeqs)
1684 String[] selection = null;
1685 SequenceI[] seqs = null;
1687 int start = 0, end = 0;
1688 if (selectedRegionOnly && selectionGroup != null)
1690 iSize = selectionGroup.getSize();
1691 seqs = selectionGroup.getSequencesInOrder(alignment);
1692 start = selectionGroup.getStartRes();
1693 end = selectionGroup.getEndRes() + 1;
1697 if (hasHiddenRows() && exportHiddenSeqs)
1699 AlignmentI fullAlignment = alignment.getHiddenSequences()
1700 .getFullAlignment();
1701 iSize = fullAlignment.getHeight();
1702 seqs = fullAlignment.getSequencesArray();
1703 end = fullAlignment.getWidth();
1707 iSize = alignment.getHeight();
1708 seqs = alignment.getSequencesArray();
1709 end = alignment.getWidth();
1713 selection = new String[iSize];
1714 if (colSel != null && colSel.hasHiddenColumns())
1716 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1720 for (i = 0; i < iSize; i++)
1722 selection[i] = seqs[i].getSequenceAsString(start, end);
1730 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1732 ArrayList<int[]> regions = new ArrayList<int[]>();
1738 if (colSel != null && colSel.hasHiddenColumns())
1742 start = colSel.adjustForHiddenColumns(start);
1745 end = colSel.getHiddenBoundaryRight(start);
1756 regions.add(new int[] { start, end });
1758 if (colSel != null && colSel.hasHiddenColumns())
1760 start = colSel.adjustForHiddenColumns(end);
1761 start = colSel.getHiddenBoundaryLeft(start) + 1;
1763 } while (end < max);
1765 int[][] startEnd = new int[regions.size()][2];
1771 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1772 boolean selectedOnly)
1774 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1775 AlignmentAnnotation[] aa;
1776 if ((aa = alignment.getAlignmentAnnotation()) != null)
1778 for (AlignmentAnnotation annot : aa)
1780 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1781 if (selectedOnly && selectionGroup != null)
1783 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1784 selectionGroup.getEndRes(), clone);
1788 colSel.makeVisibleAnnotation(clone);
1797 public boolean isPadGaps()
1803 public void setPadGaps(boolean padGaps)
1805 this.padGaps = padGaps;
1809 * apply any post-edit constraints and trigger any calculations needed after
1810 * an edit has been performed on the alignment
1815 public void alignmentChanged(AlignmentViewPanel ap)
1819 alignment.padGaps();
1821 if (autoCalculateConsensus)
1823 updateConsensus(ap);
1825 if (hconsensus != null && autoCalculateConsensus)
1827 updateConservation(ap);
1829 if (autoCalculateStrucConsensus)
1831 updateStrucConsensus(ap);
1834 // Reset endRes of groups if beyond alignment width
1835 int alWidth = alignment.getWidth();
1836 List<SequenceGroup> groups = alignment.getGroups();
1839 for (SequenceGroup sg : groups)
1841 if (sg.getEndRes() > alWidth)
1843 sg.setEndRes(alWidth - 1);
1848 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1850 selectionGroup.setEndRes(alWidth - 1);
1853 resetAllColourSchemes();
1854 calculator.restartWorkers();
1855 // alignment.adjustSequenceAnnotations();
1859 * reset scope and do calculations for all applied colourschemes on alignment
1861 void resetAllColourSchemes()
1863 ColourSchemeI cs = globalColourScheme;
1866 cs.alignmentChanged(alignment, hiddenRepSequences);
1868 cs.setConsensus(hconsensus);
1869 if (cs.conservationApplied())
1871 cs.setConservation(Conservation.calculateConservation("All",
1872 alignment.getSequences(), 0, alignment.getWidth(), false,
1873 getConsPercGaps(), false));
1877 for (SequenceGroup sg : alignment.getGroups())
1881 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1883 sg.recalcConservation();
1887 protected void initAutoAnnotation()
1889 // TODO: add menu option action that nulls or creates consensus object
1890 // depending on if the user wants to see the annotation or not in a
1891 // specific alignment
1893 if (hconsensus == null && !isDataset)
1895 if (!alignment.isNucleotide())
1904 consensus = new AlignmentAnnotation("Consensus", "PID",
1905 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1906 initConsensus(consensus);
1908 initComplementConsensus();
1913 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1914 * consensus annotation.
1916 public void initComplementConsensus()
1918 if (!alignment.isNucleotide())
1920 final List<AlignedCodonFrame> codonMappings = alignment
1922 if (codonMappings != null && !codonMappings.isEmpty())
1924 boolean doConsensus = false;
1925 for (AlignedCodonFrame mapping : codonMappings)
1927 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1928 MapList[] mapLists = mapping.getdnaToProt();
1929 // mapLists can be empty if project load has not finished resolving
1931 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1939 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1940 "PID for cDNA", new Annotation[1], 0f, 100f,
1941 AlignmentAnnotation.BAR_GRAPH);
1942 initConsensus(complementConsensus);
1948 private void initConsensus(AlignmentAnnotation aa)
1951 aa.autoCalculated = true;
1955 alignment.addAnnotation(aa);
1959 private void initConservation()
1961 if (showConservation)
1963 if (conservation == null)
1965 conservation = new AlignmentAnnotation("Conservation",
1966 "Conservation of total alignment less than "
1967 + getConsPercGaps() + "% gaps", new Annotation[1],
1968 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1969 conservation.hasText = true;
1970 conservation.autoCalculated = true;
1971 alignment.addAnnotation(conservation);
1976 private void initQuality()
1980 if (quality == null)
1982 quality = new AlignmentAnnotation("Quality",
1983 "Alignment Quality based on Blosum62 scores",
1984 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1985 quality.hasText = true;
1986 quality.autoCalculated = true;
1987 alignment.addAnnotation(quality);
1992 private void initRNAStructure()
1994 if (alignment.hasRNAStructure() && strucConsensus == null)
1996 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1997 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1998 strucConsensus.hasText = true;
1999 strucConsensus.autoCalculated = true;
2003 alignment.addAnnotation(strucConsensus);
2011 * @see jalview.api.AlignViewportI#calcPanelHeight()
2014 public int calcPanelHeight()
2016 // setHeight of panels
2017 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2019 int charHeight = getCharHeight();
2022 BitSet graphgrp = new BitSet();
2023 for (AlignmentAnnotation aa : anns)
2027 System.err.println("Null annotation row: ignoring.");
2034 if (aa.graphGroup > -1)
2036 if (graphgrp.get(aa.graphGroup))
2042 graphgrp.set(aa.graphGroup);
2049 aa.height += charHeight;
2059 aa.height += aa.graphHeight;
2067 height += aa.height;
2079 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2080 boolean preserveNewGroupSettings)
2082 boolean updateCalcs = false;
2083 boolean conv = isShowGroupConservation();
2084 boolean cons = isShowGroupConsensus();
2085 boolean showprf = isShowSequenceLogo();
2086 boolean showConsHist = isShowConsensusHistogram();
2087 boolean normLogo = isNormaliseSequenceLogo();
2090 * TODO reorder the annotation rows according to group/sequence ordering on
2093 boolean sortg = true;
2095 // remove old automatic annotation
2096 // add any new annotation
2098 // intersect alignment annotation with alignment groups
2100 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2101 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2104 for (int an = 0; an < aan.length; an++)
2106 if (aan[an].autoCalculated && aan[an].groupRef != null)
2108 oldrfs.add(aan[an].groupRef);
2109 alignment.deleteAnnotation(aan[an], false);
2113 if (alignment.getGroups() != null)
2115 for (SequenceGroup sg : alignment.getGroups())
2117 updateCalcs = false;
2118 if (applyGlobalSettings
2119 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2121 // set defaults for this group's conservation/consensus
2122 sg.setshowSequenceLogo(showprf);
2123 sg.setShowConsensusHistogram(showConsHist);
2124 sg.setNormaliseSequenceLogo(normLogo);
2129 alignment.addAnnotation(sg.getConservationRow(), 0);
2134 alignment.addAnnotation(sg.getConsensus(), 0);
2136 // refresh the annotation rows
2139 sg.recalcConservation();
2147 public boolean isDisplayReferenceSeq()
2149 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2153 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2155 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2159 public boolean isColourByReferenceSeq()
2161 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2165 public Color getSequenceColour(SequenceI seq)
2167 Color sqc = sequenceColours.get(seq);
2168 return (sqc == null ? Color.white : sqc);
2172 public void setSequenceColour(SequenceI seq, Color col)
2176 sequenceColours.remove(seq);
2180 sequenceColours.put(seq, col);
2185 public void updateSequenceIdColours()
2187 for (SequenceGroup sg : alignment.getGroups())
2189 if (sg.idColour != null)
2191 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2193 sequenceColours.put(s, sg.idColour);
2200 public void clearSequenceColours()
2202 sequenceColours.clear();
2206 public AlignViewportI getCodingComplement()
2208 return this.codingComplement;
2212 * Set this as the (cDna/protein) complement of the given viewport. Also
2213 * ensures the reverse relationship is set on the given viewport.
2216 public void setCodingComplement(AlignViewportI av)
2220 System.err.println("Ignoring recursive setCodingComplement request");
2224 this.codingComplement = av;
2225 // avoid infinite recursion!
2226 if (av.getCodingComplement() != this)
2228 av.setCodingComplement(this);
2234 public boolean isNucleotide()
2236 return getAlignment() == null ? false : getAlignment().isNucleotide();
2240 public FeaturesDisplayedI getFeaturesDisplayed()
2242 return featuresDisplayed;
2246 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2248 featuresDisplayed = featuresDisplayedI;
2252 public boolean areFeaturesDisplayed()
2254 return featuresDisplayed != null
2255 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2262 * features are displayed if true
2265 public void setShowSequenceFeatures(boolean b)
2267 viewStyle.setShowSequenceFeatures(b);
2271 public boolean isShowSequenceFeatures()
2273 return viewStyle.isShowSequenceFeatures();
2277 public void setShowSequenceFeaturesHeight(boolean selected)
2279 viewStyle.setShowSequenceFeaturesHeight(selected);
2283 public boolean isShowSequenceFeaturesHeight()
2285 return viewStyle.isShowSequenceFeaturesHeight();
2289 public void setShowAnnotation(boolean b)
2291 viewStyle.setShowAnnotation(b);
2295 public boolean isShowAnnotation()
2297 return viewStyle.isShowAnnotation();
2301 public boolean isRightAlignIds()
2303 return viewStyle.isRightAlignIds();
2307 public void setRightAlignIds(boolean rightAlignIds)
2309 viewStyle.setRightAlignIds(rightAlignIds);
2313 public boolean getConservationSelected()
2315 return viewStyle.getConservationSelected();
2319 public void setShowBoxes(boolean state)
2321 viewStyle.setShowBoxes(state);
2326 * @see jalview.api.ViewStyleI#getTextColour()
2329 public Color getTextColour()
2331 return viewStyle.getTextColour();
2336 * @see jalview.api.ViewStyleI#getTextColour2()
2339 public Color getTextColour2()
2341 return viewStyle.getTextColour2();
2346 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2349 public int getThresholdTextColour()
2351 return viewStyle.getThresholdTextColour();
2356 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2359 public boolean isConservationColourSelected()
2361 return viewStyle.isConservationColourSelected();
2366 * @see jalview.api.ViewStyleI#isRenderGaps()
2369 public boolean isRenderGaps()
2371 return viewStyle.isRenderGaps();
2376 * @see jalview.api.ViewStyleI#isShowColourText()
2379 public boolean isShowColourText()
2381 return viewStyle.isShowColourText();
2385 * @param conservationColourSelected
2386 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2389 public void setConservationColourSelected(
2390 boolean conservationColourSelected)
2392 viewStyle.setConservationColourSelected(conservationColourSelected);
2396 * @param showColourText
2397 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2400 public void setShowColourText(boolean showColourText)
2402 viewStyle.setShowColourText(showColourText);
2407 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2410 public void setTextColour(Color textColour)
2412 viewStyle.setTextColour(textColour);
2416 * @param thresholdTextColour
2417 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2420 public void setThresholdTextColour(int thresholdTextColour)
2422 viewStyle.setThresholdTextColour(thresholdTextColour);
2426 * @param textColour2
2427 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2430 public void setTextColour2(Color textColour2)
2432 viewStyle.setTextColour2(textColour2);
2436 public ViewStyleI getViewStyle()
2438 return new ViewStyle(viewStyle);
2442 public void setViewStyle(ViewStyleI settingsForView)
2444 viewStyle = new ViewStyle(settingsForView);
2448 public boolean sameStyle(ViewStyleI them)
2450 return viewStyle.sameStyle(them);
2455 * @see jalview.api.ViewStyleI#getIdWidth()
2458 public int getIdWidth()
2460 return viewStyle.getIdWidth();
2465 * @see jalview.api.ViewStyleI#setIdWidth(int)
2468 public void setIdWidth(int i)
2470 viewStyle.setIdWidth(i);
2475 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2478 public boolean isCentreColumnLabels()
2480 return viewStyle.isCentreColumnLabels();
2484 * @param centreColumnLabels
2485 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2488 public void setCentreColumnLabels(boolean centreColumnLabels)
2490 viewStyle.setCentreColumnLabels(centreColumnLabels);
2495 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2498 public void setShowDBRefs(boolean showdbrefs)
2500 viewStyle.setShowDBRefs(showdbrefs);
2505 * @see jalview.api.ViewStyleI#isShowDBRefs()
2508 public boolean isShowDBRefs()
2510 return viewStyle.isShowDBRefs();
2515 * @see jalview.api.ViewStyleI#isShowNPFeats()
2518 public boolean isShowNPFeats()
2520 return viewStyle.isShowNPFeats();
2524 * @param shownpfeats
2525 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2528 public void setShowNPFeats(boolean shownpfeats)
2530 viewStyle.setShowNPFeats(shownpfeats);
2533 public abstract StructureSelectionManager getStructureSelectionManager();
2536 * Add one command to the command history list.
2540 public void addToHistoryList(CommandI command)
2542 if (this.historyList != null)
2544 this.historyList.push(command);
2545 broadcastCommand(command, false);
2549 protected void broadcastCommand(CommandI command, boolean undo)
2551 getStructureSelectionManager().commandPerformed(command, undo,
2556 * Add one command to the command redo list.
2560 public void addToRedoList(CommandI command)
2562 if (this.redoList != null)
2564 this.redoList.push(command);
2566 broadcastCommand(command, true);
2570 * Clear the command redo list.
2572 public void clearRedoList()
2574 if (this.redoList != null)
2576 this.redoList.clear();
2580 public void setHistoryList(Deque<CommandI> list)
2582 this.historyList = list;
2585 public Deque<CommandI> getHistoryList()
2587 return this.historyList;
2590 public void setRedoList(Deque<CommandI> list)
2592 this.redoList = list;
2595 public Deque<CommandI> getRedoList()
2597 return this.redoList;
2601 public VamsasSource getVamsasSource()
2606 public SequenceAnnotationOrder getSortAnnotationsBy()
2608 return sortAnnotationsBy;
2611 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2613 this.sortAnnotationsBy = sortAnnotationsBy;
2616 public boolean isShowAutocalculatedAbove()
2618 return showAutocalculatedAbove;
2621 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2623 this.showAutocalculatedAbove = showAutocalculatedAbove;
2627 public boolean isScaleProteinAsCdna()
2629 return viewStyle.isScaleProteinAsCdna();
2633 public void setScaleProteinAsCdna(boolean b)
2635 viewStyle.setScaleProteinAsCdna(b);
2639 * @return true if view should scroll to show the highlighted region of a
2644 public final boolean isFollowHighlight()
2646 return followHighlight;
2650 public final void setFollowHighlight(boolean b)
2652 this.followHighlight = b;
2655 public int getStartRes()
2661 public int getEndRes()
2666 public int getStartSeq()
2671 public void setStartRes(int res)
2673 this.startRes = res;
2676 public void setStartSeq(int seq)
2678 this.startSeq = seq;
2681 public void setEndRes(int res)
2683 if (res > alignment.getWidth() - 1)
2685 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2686 // (alignment.getWidth()-1));
2687 res = alignment.getWidth() - 1;
2696 public void setEndSeq(int seq)
2698 if (seq > alignment.getHeight())
2700 seq = alignment.getHeight();
2709 public int getEndSeq()
2715 * Helper method to populate the SearchResults with the location in the
2716 * complementary alignment to scroll to, in order to match this one.
2719 * the SearchResults to add to
2720 * @return the offset (below top of visible region) of the matched sequence
2722 protected int findComplementScrollTarget(SearchResultsI sr)
2724 final AlignViewportI complement = getCodingComplement();
2725 if (complement == null || !complement.isFollowHighlight())
2729 boolean iAmProtein = !getAlignment().isNucleotide();
2730 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2732 if (proteinAlignment == null)
2736 final List<AlignedCodonFrame> mappings = proteinAlignment
2740 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2741 * residue in the middle column of the visible region. Scroll the
2742 * complementary alignment to line up the corresponding residue.
2745 SequenceI sequence = null;
2748 * locate 'middle' column (true middle if an odd number visible, left of
2749 * middle if an even number visible)
2751 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2752 final HiddenSequences hiddenSequences = getAlignment()
2753 .getHiddenSequences();
2756 * searching to the bottom of the alignment gives smoother scrolling across
2757 * all gapped visible regions
2759 int lastSeq = alignment.getHeight() - 1;
2760 List<AlignedCodonFrame> seqMappings = null;
2761 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2763 sequence = getAlignment().getSequenceAt(seqNo);
2764 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2768 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2772 seqMappings = MappingUtils
2773 .findMappingsForSequenceAndOthers(sequence, mappings,
2774 getCodingComplement().getAlignment().getSequences());
2775 if (!seqMappings.isEmpty())
2781 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2784 * No ungapped mapped sequence in middle column - do nothing
2788 MappingUtils.addSearchResults(sr, sequence,
2789 sequence.findPosition(middleColumn), seqMappings);
2794 * synthesize a column selection if none exists so it covers the given
2795 * selection group. if wholewidth is false, no column selection is made if the
2796 * selection group covers the whole alignment width.
2801 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2804 if (sg != null && (sgs = sg.getStartRes()) >= 0
2805 && sg.getStartRes() <= (sge = sg.getEndRes())
2806 && !this.hasSelectedColumns())
2808 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2815 colSel = new ColumnSelection();
2817 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2819 colSel.addElement(cspos);
2825 * hold status of current selection group - defined on alignment or not.
2827 private boolean selectionIsDefinedGroup = false;
2831 public boolean isSelectionDefinedGroup()
2833 if (selectionGroup == null)
2837 if (isSelectionGroupChanged(true))
2839 selectionIsDefinedGroup = false;
2840 List<SequenceGroup> gps = alignment.getGroups();
2841 if (gps == null || gps.size() == 0)
2843 selectionIsDefinedGroup = false;
2847 selectionIsDefinedGroup = gps.contains(selectionGroup);
2850 return selectionGroup.getContext() == alignment
2851 || selectionIsDefinedGroup;
2855 * null, or currently highlighted results on this view
2857 private SearchResultsI searchResults = null;
2860 public boolean hasSearchResults()
2862 return searchResults != null;
2866 public void setSearchResults(SearchResultsI results)
2868 searchResults = results;
2872 public SearchResultsI getSearchResults()
2874 return searchResults;
2878 public ContactListI getContactList(AlignmentAnnotation _aa, int column)
2880 return alignment.getContactListFor(_aa, column);