2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
24 import jalview.analysis.Conservation;
25 import jalview.api.AlignCalcManagerI;
26 import jalview.api.AlignViewportI;
27 import jalview.api.AlignmentViewPanel;
28 import jalview.api.FeaturesDisplayedI;
29 import jalview.api.ViewStyleI;
30 import jalview.commands.CommandI;
31 import jalview.datamodel.AlignedCodonFrame;
32 import jalview.datamodel.AlignmentAnnotation;
33 import jalview.datamodel.AlignmentI;
34 import jalview.datamodel.AlignmentView;
35 import jalview.datamodel.Annotation;
36 import jalview.datamodel.CigarArray;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.HiddenSequences;
39 import jalview.datamodel.ProfilesI;
40 import jalview.datamodel.SearchResultsI;
41 import jalview.datamodel.Sequence;
42 import jalview.datamodel.SequenceCollectionI;
43 import jalview.datamodel.SequenceGroup;
44 import jalview.datamodel.SequenceI;
45 import jalview.schemes.Blosum62ColourScheme;
46 import jalview.schemes.CollectionColourScheme;
47 import jalview.schemes.CollectionColourSchemeI;
48 import jalview.schemes.ColourSchemeI;
49 import jalview.schemes.PIDColourScheme;
50 import jalview.structure.CommandListener;
51 import jalview.structure.StructureSelectionManager;
52 import jalview.structure.VamsasSource;
53 import jalview.util.Comparison;
54 import jalview.util.MapList;
55 import jalview.util.MappingUtils;
56 import jalview.viewmodel.styles.ViewStyle;
57 import jalview.workers.AlignCalcManager;
58 import jalview.workers.ComplementConsensusThread;
59 import jalview.workers.ConsensusThread;
60 import jalview.workers.StrucConsensusThread;
62 import java.awt.Color;
63 import java.beans.PropertyChangeSupport;
64 import java.util.ArrayDeque;
65 import java.util.ArrayList;
66 import java.util.BitSet;
67 import java.util.Deque;
68 import java.util.HashMap;
69 import java.util.Hashtable;
70 import java.util.List;
74 * base class holding visualization and analysis attributes and common logic for
75 * an active alignment view displayed in the GUI
80 public abstract class AlignmentViewport implements AlignViewportI,
81 CommandListener, VamsasSource
83 protected ViewStyleI viewStyle = new ViewStyle();
86 * A viewport that hosts the cDna view of this (protein), or vice versa (if
89 AlignViewportI codingComplement = null;
91 FeaturesDisplayedI featuresDisplayed = null;
93 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
95 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
99 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
102 public void setFontName(String name)
104 viewStyle.setFontName(name);
109 * @see jalview.api.ViewStyleI#setFontStyle(int)
112 public void setFontStyle(int style)
114 viewStyle.setFontStyle(style);
119 * @see jalview.api.ViewStyleI#setFontSize(int)
122 public void setFontSize(int size)
124 viewStyle.setFontSize(size);
129 * @see jalview.api.ViewStyleI#getFontStyle()
132 public int getFontStyle()
134 return viewStyle.getFontStyle();
139 * @see jalview.api.ViewStyleI#getFontName()
142 public String getFontName()
144 return viewStyle.getFontName();
149 * @see jalview.api.ViewStyleI#getFontSize()
152 public int getFontSize()
154 return viewStyle.getFontSize();
158 * @param upperCasebold
159 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
162 public void setUpperCasebold(boolean upperCasebold)
164 viewStyle.setUpperCasebold(upperCasebold);
169 * @see jalview.api.ViewStyleI#isUpperCasebold()
172 public boolean isUpperCasebold()
174 return viewStyle.isUpperCasebold();
179 * @see jalview.api.ViewStyleI#isSeqNameItalics()
182 public boolean isSeqNameItalics()
184 return viewStyle.isSeqNameItalics();
188 * @param colourByReferenceSeq
189 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
192 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
194 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
199 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
202 public void setColourAppliesToAllGroups(boolean b)
204 viewStyle.setColourAppliesToAllGroups(b);
209 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
212 public boolean getColourAppliesToAllGroups()
214 return viewStyle.getColourAppliesToAllGroups();
219 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
222 public boolean getAbovePIDThreshold()
224 return viewStyle.getAbovePIDThreshold();
229 * @see jalview.api.ViewStyleI#setIncrement(int)
232 public void setIncrement(int inc)
234 viewStyle.setIncrement(inc);
239 * @see jalview.api.ViewStyleI#getIncrement()
242 public int getIncrement()
244 return viewStyle.getIncrement();
249 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
252 public void setConservationSelected(boolean b)
254 viewStyle.setConservationSelected(b);
259 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
262 public void setShowHiddenMarkers(boolean show)
264 viewStyle.setShowHiddenMarkers(show);
269 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
272 public boolean getShowHiddenMarkers()
274 return viewStyle.getShowHiddenMarkers();
279 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
282 public void setScaleRightWrapped(boolean b)
284 viewStyle.setScaleRightWrapped(b);
289 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
292 public void setScaleLeftWrapped(boolean b)
294 viewStyle.setScaleLeftWrapped(b);
299 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
302 public void setScaleAboveWrapped(boolean b)
304 viewStyle.setScaleAboveWrapped(b);
309 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
312 public boolean getScaleLeftWrapped()
314 return viewStyle.getScaleLeftWrapped();
319 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
322 public boolean getScaleAboveWrapped()
324 return viewStyle.getScaleAboveWrapped();
329 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
332 public boolean getScaleRightWrapped()
334 return viewStyle.getScaleRightWrapped();
339 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
342 public void setAbovePIDThreshold(boolean b)
344 viewStyle.setAbovePIDThreshold(b);
349 * @see jalview.api.ViewStyleI#setThreshold(int)
352 public void setThreshold(int thresh)
354 viewStyle.setThreshold(thresh);
359 * @see jalview.api.ViewStyleI#getThreshold()
362 public int getThreshold()
364 return viewStyle.getThreshold();
369 * @see jalview.api.ViewStyleI#getShowJVSuffix()
372 public boolean getShowJVSuffix()
374 return viewStyle.getShowJVSuffix();
379 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
382 public void setShowJVSuffix(boolean b)
384 viewStyle.setShowJVSuffix(b);
389 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
392 public void setWrapAlignment(boolean state)
394 viewStyle.setWrapAlignment(state);
399 * @see jalview.api.ViewStyleI#setShowText(boolean)
402 public void setShowText(boolean state)
404 viewStyle.setShowText(state);
409 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
412 public void setRenderGaps(boolean state)
414 viewStyle.setRenderGaps(state);
419 * @see jalview.api.ViewStyleI#getColourText()
422 public boolean getColourText()
424 return viewStyle.getColourText();
429 * @see jalview.api.ViewStyleI#setColourText(boolean)
432 public void setColourText(boolean state)
434 viewStyle.setColourText(state);
439 * @see jalview.api.ViewStyleI#getWrapAlignment()
442 public boolean getWrapAlignment()
444 return viewStyle.getWrapAlignment();
449 * @see jalview.api.ViewStyleI#getShowText()
452 public boolean getShowText()
454 return viewStyle.getShowText();
459 * @see jalview.api.ViewStyleI#getWrappedWidth()
462 public int getWrappedWidth()
464 return viewStyle.getWrappedWidth();
469 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
472 public void setWrappedWidth(int w)
474 viewStyle.setWrappedWidth(w);
479 * @see jalview.api.ViewStyleI#getCharHeight()
482 public int getCharHeight()
484 return viewStyle.getCharHeight();
489 * @see jalview.api.ViewStyleI#setCharHeight(int)
492 public void setCharHeight(int h)
494 viewStyle.setCharHeight(h);
499 * @see jalview.api.ViewStyleI#getCharWidth()
502 public int getCharWidth()
504 return viewStyle.getCharWidth();
509 * @see jalview.api.ViewStyleI#setCharWidth(int)
512 public void setCharWidth(int w)
514 viewStyle.setCharWidth(w);
519 * @see jalview.api.ViewStyleI#getShowBoxes()
522 public boolean getShowBoxes()
524 return viewStyle.getShowBoxes();
529 * @see jalview.api.ViewStyleI#getShowUnconserved()
532 public boolean getShowUnconserved()
534 return viewStyle.getShowUnconserved();
538 * @param showunconserved
539 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
542 public void setShowUnconserved(boolean showunconserved)
544 viewStyle.setShowUnconserved(showunconserved);
549 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
552 public void setSeqNameItalics(boolean default1)
554 viewStyle.setSeqNameItalics(default1);
558 * alignment displayed in the viewport. Please use get/setter
560 protected AlignmentI alignment;
563 public AlignmentI getAlignment()
569 public char getGapCharacter()
571 return alignment.getGapCharacter();
574 protected String sequenceSetID;
577 * probably unused indicator that view is of a dataset rather than an
580 protected boolean isDataset = false;
582 public void setDataset(boolean b)
587 public boolean isDataset()
592 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
594 protected ColumnSelection colSel = new ColumnSelection();
596 public boolean autoCalculateConsensus = true;
598 protected boolean autoCalculateStrucConsensus = true;
600 protected boolean ignoreGapsInConsensusCalculation = false;
602 protected CollectionColourSchemeI globalColourScheme;
605 public void setGlobalColourScheme(ColourSchemeI cs)
607 // TODO: logic refactored from AlignFrame changeColour -
608 // TODO: autorecalc stuff should be changed to rely on the worker system
609 // check to see if we should implement a changeColour(cs) method rather than
610 // put th logic in here
611 // - means that caller decides if they want to just modify state and defer
612 // calculation till later or to do all calculations in thread.
616 * only instantiate collection colour scheme once, thereafter update it
617 * this means that any conservation or PID threshold settings
618 * persist when the alignment colour scheme is changed
620 if (globalColourScheme == null)
622 globalColourScheme = new CollectionColourScheme();
624 globalColourScheme.setColourScheme(cs);
626 // boolean recalc = false;
627 // TODO: do threshold and increment belong in ViewStyle or colour scheme?
628 // problem: groups need this but do not currently have a ViewStyle
632 if (getConservationSelected() || getAbovePIDThreshold()
633 || cs instanceof PIDColourScheme
634 || cs instanceof Blosum62ColourScheme)
636 globalColourScheme.setConservation(hconservation);
638 .setConservationApplied(getConservationSelected());
640 globalColourScheme.alignmentChanged(alignment, hiddenRepSequences);
644 * if 'apply colour to all groups' is selected... do so
645 * (but don't transfer any colour threshold settings to groups)
647 if (getColourAppliesToAllGroups())
649 for (SequenceGroup sg : getAlignment().getGroups())
652 * retain any colour thresholds per group while
653 * changing choice of colour scheme (JAL-2386)
655 sg.setColourScheme(cs);
658 sg.getGroupColourScheme()
659 .alignmentChanged(sg, hiddenRepSequences);
666 public ColourSchemeI getGlobalColourScheme()
668 return globalColourScheme == null ? null : globalColourScheme
673 public CollectionColourSchemeI getViewportColourScheme()
675 return globalColourScheme;
678 protected AlignmentAnnotation consensus;
680 protected AlignmentAnnotation complementConsensus;
682 protected AlignmentAnnotation strucConsensus;
684 protected AlignmentAnnotation conservation;
686 protected AlignmentAnnotation quality;
688 protected AlignmentAnnotation[] groupConsensus;
690 protected AlignmentAnnotation[] groupConservation;
693 * results of alignment consensus analysis for visible portion of view
695 protected ProfilesI hconsensus = null;
698 * results of cDNA complement consensus visible portion of view
700 protected Hashtable[] hcomplementConsensus = null;
703 * results of secondary structure base pair consensus for visible portion of
706 protected Hashtable[] hStrucConsensus = null;
708 protected Conservation hconservation = null;
711 public void setConservation(Conservation cons)
713 hconservation = cons;
717 * percentage gaps allowed in a column before all amino acid properties should
718 * be considered unconserved
720 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
723 public int getConsPercGaps()
729 public void setSequenceConsensusHash(ProfilesI hconsensus)
731 this.hconsensus = hconsensus;
735 public void setComplementConsensusHash(Hashtable[] hconsensus)
737 this.hcomplementConsensus = hconsensus;
741 public ProfilesI getSequenceConsensusHash()
747 public Hashtable[] getComplementConsensusHash()
749 return hcomplementConsensus;
753 public Hashtable[] getRnaStructureConsensusHash()
755 return hStrucConsensus;
759 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
761 this.hStrucConsensus = hStrucConsensus;
766 public AlignmentAnnotation getAlignmentQualityAnnot()
772 public AlignmentAnnotation getAlignmentConservationAnnotation()
778 public AlignmentAnnotation getAlignmentConsensusAnnotation()
784 public AlignmentAnnotation getComplementConsensusAnnotation()
786 return complementConsensus;
790 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
792 return strucConsensus;
795 protected AlignCalcManagerI calculator = new AlignCalcManager();
798 * trigger update of conservation annotation
800 public void updateConservation(final AlignmentViewPanel ap)
802 // see note in mantis : issue number 8585
803 if (alignment.isNucleotide()
804 || (conservation == null && quality == null)
805 || !autoCalculateConsensus)
810 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
812 calculator.registerWorker(new jalview.workers.ConservationThread(
818 * trigger update of consensus annotation
820 public void updateConsensus(final AlignmentViewPanel ap)
822 // see note in mantis : issue number 8585
823 if (consensus == null || !autoCalculateConsensus)
827 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
829 calculator.registerWorker(new ConsensusThread(this, ap));
833 * A separate thread to compute cDNA consensus for a protein alignment
834 * which has mapping to cDNA
836 final AlignmentI al = this.getAlignment();
837 if (!al.isNucleotide() && al.getCodonFrames() != null
838 && !al.getCodonFrames().isEmpty())
841 * fudge - check first for protein-to-nucleotide mappings
842 * (we don't want to do this for protein-to-protein)
844 boolean doConsensus = false;
845 for (AlignedCodonFrame mapping : al.getCodonFrames())
847 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
848 MapList[] mapLists = mapping.getdnaToProt();
849 // mapLists can be empty if project load has not finished resolving seqs
850 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
859 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
862 .registerWorker(new ComplementConsensusThread(this, ap));
868 // --------START Structure Conservation
869 public void updateStrucConsensus(final AlignmentViewPanel ap)
871 if (autoCalculateStrucConsensus && strucConsensus == null
872 && alignment.isNucleotide() && alignment.hasRNAStructure())
874 // secondary structure has been added - so init the consensus line
878 // see note in mantis : issue number 8585
879 if (strucConsensus == null || !autoCalculateStrucConsensus)
883 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
885 calculator.registerWorker(new StrucConsensusThread(this, ap));
889 public boolean isCalcInProgress()
891 return calculator.isWorking();
895 public boolean isCalculationInProgress(
896 AlignmentAnnotation alignmentAnnotation)
898 if (!alignmentAnnotation.autoCalculated)
902 if (calculator.workingInvolvedWith(alignmentAnnotation))
904 // System.err.println("grey out ("+alignmentAnnotation.label+")");
910 public void setAlignment(AlignmentI align)
912 this.alignment = align;
916 * Clean up references when this viewport is closed
919 public void dispose()
922 * defensively null out references to large objects in case
923 * this object is not garbage collected (as if!)
926 complementConsensus = null;
927 strucConsensus = null;
930 groupConsensus = null;
931 groupConservation = null;
933 hcomplementConsensus = null;
934 // colour scheme may hold reference to consensus
935 globalColourScheme = null;
936 // TODO remove listeners from changeSupport?
937 changeSupport = null;
942 public boolean isClosed()
944 // TODO: check that this isClosed is only true after panel is closed, not
945 // before it is fully constructed.
946 return alignment == null;
950 public AlignCalcManagerI getCalcManager()
956 * should conservation rows be shown for groups
958 protected boolean showGroupConservation = false;
961 * should consensus rows be shown for groups
963 protected boolean showGroupConsensus = false;
966 * should consensus profile be rendered by default
968 protected boolean showSequenceLogo = false;
971 * should consensus profile be rendered normalised to row height
973 protected boolean normaliseSequenceLogo = false;
976 * should consensus histograms be rendered by default
978 protected boolean showConsensusHistogram = true;
981 * @return the showConsensusProfile
984 public boolean isShowSequenceLogo()
986 return showSequenceLogo;
990 * @param showSequenceLogo
993 public void setShowSequenceLogo(boolean showSequenceLogo)
995 if (showSequenceLogo != this.showSequenceLogo)
997 // TODO: decouple settings setting from calculation when refactoring
998 // annotation update method from alignframe to viewport
999 this.showSequenceLogo = showSequenceLogo;
1000 calculator.updateAnnotationFor(ConsensusThread.class);
1001 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1002 calculator.updateAnnotationFor(StrucConsensusThread.class);
1004 this.showSequenceLogo = showSequenceLogo;
1008 * @param showConsensusHistogram
1009 * the showConsensusHistogram to set
1011 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1013 this.showConsensusHistogram = showConsensusHistogram;
1017 * @return the showGroupConservation
1019 public boolean isShowGroupConservation()
1021 return showGroupConservation;
1025 * @param showGroupConservation
1026 * the showGroupConservation to set
1028 public void setShowGroupConservation(boolean showGroupConservation)
1030 this.showGroupConservation = showGroupConservation;
1034 * @return the showGroupConsensus
1036 public boolean isShowGroupConsensus()
1038 return showGroupConsensus;
1042 * @param showGroupConsensus
1043 * the showGroupConsensus to set
1045 public void setShowGroupConsensus(boolean showGroupConsensus)
1047 this.showGroupConsensus = showGroupConsensus;
1052 * @return flag to indicate if the consensus histogram should be rendered by
1056 public boolean isShowConsensusHistogram()
1058 return this.showConsensusHistogram;
1062 * when set, updateAlignment will always ensure sequences are of equal length
1064 private boolean padGaps = false;
1067 * when set, alignment should be reordered according to a newly opened tree
1069 public boolean sortByTree = false;
1074 * @return null or the currently selected sequence region
1077 public SequenceGroup getSelectionGroup()
1079 return selectionGroup;
1083 * Set the selection group for this window.
1086 * - group holding references to sequences in this alignment view
1090 public void setSelectionGroup(SequenceGroup sg)
1092 selectionGroup = sg;
1095 public void setHiddenColumns(ColumnSelection colsel)
1097 this.colSel = colsel;
1101 public ColumnSelection getColumnSelection()
1107 public void setColumnSelection(ColumnSelection colSel)
1109 this.colSel = colSel;
1112 updateHiddenColumns();
1114 isColSelChanged(true);
1122 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1124 return hiddenRepSequences;
1128 public void setHiddenRepSequences(
1129 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1131 this.hiddenRepSequences = hiddenRepSequences;
1135 public boolean hasSelectedColumns()
1137 ColumnSelection columnSelection = getColumnSelection();
1138 return columnSelection != null && columnSelection.hasSelectedColumns();
1142 public boolean hasHiddenColumns()
1144 return colSel != null && colSel.hasHiddenColumns();
1147 public void updateHiddenColumns()
1149 // this method doesn't really do anything now. But - it could, since a
1150 // column Selection could be in the process of modification
1151 // hasHiddenColumns = colSel.hasHiddenColumns();
1155 public boolean hasHiddenRows()
1157 return alignment.getHiddenSequences().getSize() > 0;
1160 protected SequenceGroup selectionGroup;
1162 public void setSequenceSetId(String newid)
1164 if (sequenceSetID != null)
1167 .println("Warning - overwriting a sequenceSetId for a viewport!");
1169 sequenceSetID = new String(newid);
1173 public String getSequenceSetId()
1175 if (sequenceSetID == null)
1177 sequenceSetID = alignment.hashCode() + "";
1180 return sequenceSetID;
1184 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1187 protected String viewId = null;
1190 public String getViewId()
1194 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1199 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1201 ignoreGapsInConsensusCalculation = b;
1204 updateConsensus(ap);
1205 if (globalColourScheme != null)
1207 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1208 ignoreGapsInConsensusCalculation);
1214 private long sgrouphash = -1, colselhash = -1;
1217 * checks current SelectionGroup against record of last hash value, and
1221 * update the record of last hash value
1223 * @return true if SelectionGroup changed since last call (when b is true)
1225 public boolean isSelectionGroupChanged(boolean b)
1227 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1228 : selectionGroup.hashCode();
1229 if (hc != -1 && hc != sgrouphash)
1241 * checks current colsel against record of last hash value, and optionally
1245 * update the record of last hash value
1246 * @return true if colsel changed since last call (when b is true)
1248 public boolean isColSelChanged(boolean b)
1250 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1251 if (hc != -1 && hc != colselhash)
1263 public boolean isIgnoreGapsConsensus()
1265 return ignoreGapsInConsensusCalculation;
1268 // property change stuff
1269 // JBPNote Prolly only need this in the applet version.
1270 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1273 protected boolean showConservation = true;
1275 protected boolean showQuality = true;
1277 protected boolean showConsensus = true;
1279 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1281 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1283 protected boolean showAutocalculatedAbove;
1286 * when set, view will scroll to show the highlighted position
1288 private boolean followHighlight = true;
1290 // TODO private with getters and setters?
1291 public int startRes;
1295 public int startSeq;
1300 * Property change listener for changes in alignment
1305 public void addPropertyChangeListener(
1306 java.beans.PropertyChangeListener listener)
1308 changeSupport.addPropertyChangeListener(listener);
1317 public void removePropertyChangeListener(
1318 java.beans.PropertyChangeListener listener)
1320 changeSupport.removePropertyChangeListener(listener);
1324 * Property change listener for changes in alignment
1333 public void firePropertyChange(String prop, Object oldvalue,
1336 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1339 // common hide/show column stuff
1341 public void hideSelectedColumns()
1343 if (colSel.isEmpty())
1348 colSel.hideSelectedColumns();
1349 setSelectionGroup(null);
1350 isColSelChanged(true);
1353 public void hideColumns(int start, int end)
1357 colSel.hideColumns(start);
1361 colSel.hideColumns(start, end);
1363 isColSelChanged(true);
1366 public void showColumn(int col)
1368 colSel.revealHiddenColumns(col);
1369 isColSelChanged(true);
1372 public void showAllHiddenColumns()
1374 colSel.revealAllHiddenColumns();
1375 isColSelChanged(true);
1378 // common hide/show seq stuff
1379 public void showAllHiddenSeqs()
1381 if (alignment.getHiddenSequences().getSize() > 0)
1383 if (selectionGroup == null)
1385 selectionGroup = new SequenceGroup();
1386 selectionGroup.setEndRes(alignment.getWidth() - 1);
1388 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1389 hiddenRepSequences);
1390 for (SequenceI seq : tmp)
1392 selectionGroup.addSequence(seq, false);
1393 setSequenceAnnotationsVisible(seq, true);
1396 hiddenRepSequences = null;
1398 firePropertyChange("alignment", null, alignment.getSequences());
1399 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1405 public void showSequence(int index)
1407 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1408 index, hiddenRepSequences);
1411 if (selectionGroup == null)
1413 selectionGroup = new SequenceGroup();
1414 selectionGroup.setEndRes(alignment.getWidth() - 1);
1417 for (SequenceI seq : tmp)
1419 selectionGroup.addSequence(seq, false);
1420 setSequenceAnnotationsVisible(seq, true);
1422 firePropertyChange("alignment", null, alignment.getSequences());
1427 public void hideAllSelectedSeqs()
1429 if (selectionGroup == null || selectionGroup.getSize() < 1)
1434 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1438 setSelectionGroup(null);
1441 public void hideSequence(SequenceI[] seq)
1445 for (int i = 0; i < seq.length; i++)
1447 alignment.getHiddenSequences().hideSequence(seq[i]);
1448 setSequenceAnnotationsVisible(seq[i], false);
1450 firePropertyChange("alignment", null, alignment.getSequences());
1455 * Hides the specified sequence, or the sequences it represents
1458 * the sequence to hide, or keep as representative
1459 * @param representGroup
1460 * if true, hide the current selection group except for the
1461 * representative sequence
1463 public void hideSequences(SequenceI sequence, boolean representGroup)
1465 if (selectionGroup == null || selectionGroup.getSize() < 1)
1467 hideSequence(new SequenceI[] { sequence });
1473 hideRepSequences(sequence, selectionGroup);
1474 setSelectionGroup(null);
1478 int gsize = selectionGroup.getSize();
1479 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1480 new SequenceI[gsize]);
1482 hideSequence(hseqs);
1483 setSelectionGroup(null);
1488 * Set visibility for any annotations for the given sequence.
1492 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1495 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1498 for (AlignmentAnnotation ann : anns)
1500 if (ann.sequenceRef == sequenceI)
1502 ann.visible = visible;
1508 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1510 int sSize = sg.getSize();
1516 if (hiddenRepSequences == null)
1518 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1521 hiddenRepSequences.put(repSequence, sg);
1523 // Hide all sequences except the repSequence
1524 SequenceI[] seqs = new SequenceI[sSize - 1];
1526 for (int i = 0; i < sSize; i++)
1528 if (sg.getSequenceAt(i) != repSequence)
1530 if (index == sSize - 1)
1535 seqs[index++] = sg.getSequenceAt(i);
1538 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1539 sg.setHidereps(true); // note: not done in 2.7applet
1546 * @return null or the current reference sequence
1548 public SequenceI getReferenceSeq()
1550 return alignment.getSeqrep();
1555 * @return true iff seq is the reference for the alignment
1557 public boolean isReferenceSeq(SequenceI seq)
1559 return alignment.getSeqrep() == seq;
1565 * @return true if there are sequences represented by this sequence that are
1568 public boolean isHiddenRepSequence(SequenceI seq)
1570 return (hiddenRepSequences != null && hiddenRepSequences
1577 * @return null or a sequence group containing the sequences that seq
1580 public SequenceGroup getRepresentedSequences(SequenceI seq)
1582 return (SequenceGroup) (hiddenRepSequences == null ? null
1583 : hiddenRepSequences.get(seq));
1587 public int adjustForHiddenSeqs(int alignmentIndex)
1589 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1594 public void invertColumnSelection()
1596 colSel.invertColumnSelection(0, alignment.getWidth());
1600 public SequenceI[] getSelectionAsNewSequence()
1602 SequenceI[] sequences;
1603 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1604 // this was the only caller in the applet for this method
1605 // JBPNote: in applet, this method returned references to the alignment
1606 // sequences, and it did not honour the presence/absence of annotation
1607 // attached to the alignment (probably!)
1608 if (selectionGroup == null || selectionGroup.getSize() == 0)
1610 sequences = alignment.getSequencesArray();
1611 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1612 for (int i = 0; i < sequences.length; i++)
1614 // construct new sequence with subset of visible annotation
1615 sequences[i] = new Sequence(sequences[i], annots);
1620 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1627 public SequenceI[] getSequenceSelection()
1629 SequenceI[] sequences = null;
1630 if (selectionGroup != null)
1632 sequences = selectionGroup.getSequencesInOrder(alignment);
1634 if (sequences == null)
1636 sequences = alignment.getSequencesArray();
1642 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1644 return new CigarArray(alignment, colSel,
1645 (selectedRegionOnly ? selectionGroup : null));
1649 public jalview.datamodel.AlignmentView getAlignmentView(
1650 boolean selectedOnly)
1652 return getAlignmentView(selectedOnly, false);
1656 public jalview.datamodel.AlignmentView getAlignmentView(
1657 boolean selectedOnly, boolean markGroups)
1659 return new AlignmentView(alignment, colSel, selectionGroup,
1660 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1665 public String[] getViewAsString(boolean selectedRegionOnly)
1667 return getViewAsString(selectedRegionOnly, true);
1671 public String[] getViewAsString(boolean selectedRegionOnly,
1672 boolean exportHiddenSeqs)
1674 String[] selection = null;
1675 SequenceI[] seqs = null;
1677 int start = 0, end = 0;
1678 if (selectedRegionOnly && selectionGroup != null)
1680 iSize = selectionGroup.getSize();
1681 seqs = selectionGroup.getSequencesInOrder(alignment);
1682 start = selectionGroup.getStartRes();
1683 end = selectionGroup.getEndRes() + 1;
1687 if (hasHiddenRows() && exportHiddenSeqs)
1689 AlignmentI fullAlignment = alignment.getHiddenSequences()
1690 .getFullAlignment();
1691 iSize = fullAlignment.getHeight();
1692 seqs = fullAlignment.getSequencesArray();
1693 end = fullAlignment.getWidth();
1697 iSize = alignment.getHeight();
1698 seqs = alignment.getSequencesArray();
1699 end = alignment.getWidth();
1703 selection = new String[iSize];
1704 if (colSel != null && colSel.hasHiddenColumns())
1706 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1710 for (i = 0; i < iSize; i++)
1712 selection[i] = seqs[i].getSequenceAsString(start, end);
1720 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1722 ArrayList<int[]> regions = new ArrayList<int[]>();
1728 if (colSel != null && colSel.hasHiddenColumns())
1732 start = colSel.adjustForHiddenColumns(start);
1735 end = colSel.getHiddenBoundaryRight(start);
1746 regions.add(new int[] { start, end });
1748 if (colSel != null && colSel.hasHiddenColumns())
1750 start = colSel.adjustForHiddenColumns(end);
1751 start = colSel.getHiddenBoundaryLeft(start) + 1;
1753 } while (end < max);
1755 int[][] startEnd = new int[regions.size()][2];
1761 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1762 boolean selectedOnly)
1764 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1765 AlignmentAnnotation[] aa;
1766 if ((aa = alignment.getAlignmentAnnotation()) != null)
1768 for (AlignmentAnnotation annot : aa)
1770 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1771 if (selectedOnly && selectionGroup != null)
1773 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1774 selectionGroup.getEndRes(), clone);
1778 colSel.makeVisibleAnnotation(clone);
1787 public boolean isPadGaps()
1793 public void setPadGaps(boolean padGaps)
1795 this.padGaps = padGaps;
1799 * apply any post-edit constraints and trigger any calculations needed after
1800 * an edit has been performed on the alignment
1805 public void alignmentChanged(AlignmentViewPanel ap)
1809 alignment.padGaps();
1811 if (autoCalculateConsensus)
1813 updateConsensus(ap);
1815 if (hconsensus != null && autoCalculateConsensus)
1817 updateConservation(ap);
1819 if (autoCalculateStrucConsensus)
1821 updateStrucConsensus(ap);
1824 // Reset endRes of groups if beyond alignment width
1825 int alWidth = alignment.getWidth();
1826 List<SequenceGroup> groups = alignment.getGroups();
1829 for (SequenceGroup sg : groups)
1831 if (sg.getEndRes() > alWidth)
1833 sg.setEndRes(alWidth - 1);
1838 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1840 selectionGroup.setEndRes(alWidth - 1);
1843 resetAllColourSchemes();
1844 calculator.restartWorkers();
1845 // alignment.adjustSequenceAnnotations();
1849 * reset scope and do calculations for all applied colourschemes on alignment
1851 void resetAllColourSchemes()
1853 CollectionColourSchemeI cs = globalColourScheme;
1856 cs.alignmentChanged(alignment, hiddenRepSequences);
1858 cs.setConsensus(hconsensus);
1859 if (cs.conservationApplied())
1861 cs.setConservation(Conservation.calculateConservation("All",
1862 alignment.getSequences(), 0, alignment.getWidth(), false,
1863 getConsPercGaps(), false));
1867 for (SequenceGroup sg : alignment.getGroups())
1871 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1873 sg.recalcConservation();
1877 protected void initAutoAnnotation()
1879 // TODO: add menu option action that nulls or creates consensus object
1880 // depending on if the user wants to see the annotation or not in a
1881 // specific alignment
1883 if (hconsensus == null && !isDataset)
1885 if (!alignment.isNucleotide())
1894 consensus = new AlignmentAnnotation("Consensus", "PID",
1895 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1896 initConsensus(consensus);
1898 initComplementConsensus();
1903 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1904 * consensus annotation.
1906 public void initComplementConsensus()
1908 if (!alignment.isNucleotide())
1910 final List<AlignedCodonFrame> codonMappings = alignment
1912 if (codonMappings != null && !codonMappings.isEmpty())
1914 boolean doConsensus = false;
1915 for (AlignedCodonFrame mapping : codonMappings)
1917 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1918 MapList[] mapLists = mapping.getdnaToProt();
1919 // mapLists can be empty if project load has not finished resolving
1921 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1929 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1930 "PID for cDNA", new Annotation[1], 0f, 100f,
1931 AlignmentAnnotation.BAR_GRAPH);
1932 initConsensus(complementConsensus);
1938 private void initConsensus(AlignmentAnnotation aa)
1941 aa.autoCalculated = true;
1945 alignment.addAnnotation(aa);
1949 private void initConservation()
1951 if (showConservation)
1953 if (conservation == null)
1955 conservation = new AlignmentAnnotation("Conservation",
1956 "Conservation of total alignment less than "
1957 + getConsPercGaps() + "% gaps", new Annotation[1],
1958 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1959 conservation.hasText = true;
1960 conservation.autoCalculated = true;
1961 alignment.addAnnotation(conservation);
1966 private void initQuality()
1970 if (quality == null)
1972 quality = new AlignmentAnnotation("Quality",
1973 "Alignment Quality based on Blosum62 scores",
1974 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1975 quality.hasText = true;
1976 quality.autoCalculated = true;
1977 alignment.addAnnotation(quality);
1982 private void initRNAStructure()
1984 if (alignment.hasRNAStructure() && strucConsensus == null)
1986 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1987 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1988 strucConsensus.hasText = true;
1989 strucConsensus.autoCalculated = true;
1993 alignment.addAnnotation(strucConsensus);
2001 * @see jalview.api.AlignViewportI#calcPanelHeight()
2004 public int calcPanelHeight()
2006 // setHeight of panels
2007 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2009 int charHeight = getCharHeight();
2012 BitSet graphgrp = new BitSet();
2013 for (AlignmentAnnotation aa : anns)
2017 System.err.println("Null annotation row: ignoring.");
2024 if (aa.graphGroup > -1)
2026 if (graphgrp.get(aa.graphGroup))
2032 graphgrp.set(aa.graphGroup);
2039 aa.height += charHeight;
2049 aa.height += aa.graphHeight;
2057 height += aa.height;
2069 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2070 boolean preserveNewGroupSettings)
2072 boolean updateCalcs = false;
2073 boolean conv = isShowGroupConservation();
2074 boolean cons = isShowGroupConsensus();
2075 boolean showprf = isShowSequenceLogo();
2076 boolean showConsHist = isShowConsensusHistogram();
2077 boolean normLogo = isNormaliseSequenceLogo();
2080 * TODO reorder the annotation rows according to group/sequence ordering on
2083 boolean sortg = true;
2085 // remove old automatic annotation
2086 // add any new annotation
2088 // intersect alignment annotation with alignment groups
2090 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2091 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2094 for (int an = 0; an < aan.length; an++)
2096 if (aan[an].autoCalculated && aan[an].groupRef != null)
2098 oldrfs.add(aan[an].groupRef);
2099 alignment.deleteAnnotation(aan[an], false);
2103 if (alignment.getGroups() != null)
2105 for (SequenceGroup sg : alignment.getGroups())
2107 updateCalcs = false;
2108 if (applyGlobalSettings
2109 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2111 // set defaults for this group's conservation/consensus
2112 sg.setshowSequenceLogo(showprf);
2113 sg.setShowConsensusHistogram(showConsHist);
2114 sg.setNormaliseSequenceLogo(normLogo);
2119 alignment.addAnnotation(sg.getConservationRow(), 0);
2124 alignment.addAnnotation(sg.getConsensus(), 0);
2126 // refresh the annotation rows
2129 sg.recalcConservation();
2137 public boolean isDisplayReferenceSeq()
2139 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2143 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2145 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2149 public boolean isColourByReferenceSeq()
2151 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2155 public Color getSequenceColour(SequenceI seq)
2157 Color sqc = sequenceColours.get(seq);
2158 return (sqc == null ? Color.white : sqc);
2162 public void setSequenceColour(SequenceI seq, Color col)
2166 sequenceColours.remove(seq);
2170 sequenceColours.put(seq, col);
2175 public void updateSequenceIdColours()
2177 for (SequenceGroup sg : alignment.getGroups())
2179 if (sg.idColour != null)
2181 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2183 sequenceColours.put(s, sg.idColour);
2190 public void clearSequenceColours()
2192 sequenceColours.clear();
2196 public AlignViewportI getCodingComplement()
2198 return this.codingComplement;
2202 * Set this as the (cDna/protein) complement of the given viewport. Also
2203 * ensures the reverse relationship is set on the given viewport.
2206 public void setCodingComplement(AlignViewportI av)
2210 System.err.println("Ignoring recursive setCodingComplement request");
2214 this.codingComplement = av;
2215 // avoid infinite recursion!
2216 if (av.getCodingComplement() != this)
2218 av.setCodingComplement(this);
2224 public boolean isNucleotide()
2226 return getAlignment() == null ? false : getAlignment().isNucleotide();
2230 public FeaturesDisplayedI getFeaturesDisplayed()
2232 return featuresDisplayed;
2236 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2238 featuresDisplayed = featuresDisplayedI;
2242 public boolean areFeaturesDisplayed()
2244 return featuresDisplayed != null
2245 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2252 * features are displayed if true
2255 public void setShowSequenceFeatures(boolean b)
2257 viewStyle.setShowSequenceFeatures(b);
2261 public boolean isShowSequenceFeatures()
2263 return viewStyle.isShowSequenceFeatures();
2267 public void setShowSequenceFeaturesHeight(boolean selected)
2269 viewStyle.setShowSequenceFeaturesHeight(selected);
2273 public boolean isShowSequenceFeaturesHeight()
2275 return viewStyle.isShowSequenceFeaturesHeight();
2279 public void setShowAnnotation(boolean b)
2281 viewStyle.setShowAnnotation(b);
2285 public boolean isShowAnnotation()
2287 return viewStyle.isShowAnnotation();
2291 public boolean isRightAlignIds()
2293 return viewStyle.isRightAlignIds();
2297 public void setRightAlignIds(boolean rightAlignIds)
2299 viewStyle.setRightAlignIds(rightAlignIds);
2303 public boolean getConservationSelected()
2305 return viewStyle.getConservationSelected();
2309 public void setShowBoxes(boolean state)
2311 viewStyle.setShowBoxes(state);
2316 * @see jalview.api.ViewStyleI#getTextColour()
2319 public Color getTextColour()
2321 return viewStyle.getTextColour();
2326 * @see jalview.api.ViewStyleI#getTextColour2()
2329 public Color getTextColour2()
2331 return viewStyle.getTextColour2();
2336 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2339 public int getThresholdTextColour()
2341 return viewStyle.getThresholdTextColour();
2346 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2349 public boolean isConservationColourSelected()
2351 return viewStyle.isConservationColourSelected();
2356 * @see jalview.api.ViewStyleI#isRenderGaps()
2359 public boolean isRenderGaps()
2361 return viewStyle.isRenderGaps();
2366 * @see jalview.api.ViewStyleI#isShowColourText()
2369 public boolean isShowColourText()
2371 return viewStyle.isShowColourText();
2375 * @param conservationColourSelected
2376 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2379 public void setConservationColourSelected(
2380 boolean conservationColourSelected)
2382 viewStyle.setConservationColourSelected(conservationColourSelected);
2386 * @param showColourText
2387 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2390 public void setShowColourText(boolean showColourText)
2392 viewStyle.setShowColourText(showColourText);
2397 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2400 public void setTextColour(Color textColour)
2402 viewStyle.setTextColour(textColour);
2406 * @param thresholdTextColour
2407 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2410 public void setThresholdTextColour(int thresholdTextColour)
2412 viewStyle.setThresholdTextColour(thresholdTextColour);
2416 * @param textColour2
2417 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2420 public void setTextColour2(Color textColour2)
2422 viewStyle.setTextColour2(textColour2);
2426 public ViewStyleI getViewStyle()
2428 return new ViewStyle(viewStyle);
2432 public void setViewStyle(ViewStyleI settingsForView)
2434 viewStyle = new ViewStyle(settingsForView);
2438 public boolean sameStyle(ViewStyleI them)
2440 return viewStyle.sameStyle(them);
2445 * @see jalview.api.ViewStyleI#getIdWidth()
2448 public int getIdWidth()
2450 return viewStyle.getIdWidth();
2455 * @see jalview.api.ViewStyleI#setIdWidth(int)
2458 public void setIdWidth(int i)
2460 viewStyle.setIdWidth(i);
2465 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2468 public boolean isCentreColumnLabels()
2470 return viewStyle.isCentreColumnLabels();
2474 * @param centreColumnLabels
2475 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2478 public void setCentreColumnLabels(boolean centreColumnLabels)
2480 viewStyle.setCentreColumnLabels(centreColumnLabels);
2485 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2488 public void setShowDBRefs(boolean showdbrefs)
2490 viewStyle.setShowDBRefs(showdbrefs);
2495 * @see jalview.api.ViewStyleI#isShowDBRefs()
2498 public boolean isShowDBRefs()
2500 return viewStyle.isShowDBRefs();
2505 * @see jalview.api.ViewStyleI#isShowNPFeats()
2508 public boolean isShowNPFeats()
2510 return viewStyle.isShowNPFeats();
2514 * @param shownpfeats
2515 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2518 public void setShowNPFeats(boolean shownpfeats)
2520 viewStyle.setShowNPFeats(shownpfeats);
2523 public abstract StructureSelectionManager getStructureSelectionManager();
2526 * Add one command to the command history list.
2530 public void addToHistoryList(CommandI command)
2532 if (this.historyList != null)
2534 this.historyList.push(command);
2535 broadcastCommand(command, false);
2539 protected void broadcastCommand(CommandI command, boolean undo)
2541 getStructureSelectionManager().commandPerformed(command, undo,
2546 * Add one command to the command redo list.
2550 public void addToRedoList(CommandI command)
2552 if (this.redoList != null)
2554 this.redoList.push(command);
2556 broadcastCommand(command, true);
2560 * Clear the command redo list.
2562 public void clearRedoList()
2564 if (this.redoList != null)
2566 this.redoList.clear();
2570 public void setHistoryList(Deque<CommandI> list)
2572 this.historyList = list;
2575 public Deque<CommandI> getHistoryList()
2577 return this.historyList;
2580 public void setRedoList(Deque<CommandI> list)
2582 this.redoList = list;
2585 public Deque<CommandI> getRedoList()
2587 return this.redoList;
2591 public VamsasSource getVamsasSource()
2596 public SequenceAnnotationOrder getSortAnnotationsBy()
2598 return sortAnnotationsBy;
2601 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2603 this.sortAnnotationsBy = sortAnnotationsBy;
2606 public boolean isShowAutocalculatedAbove()
2608 return showAutocalculatedAbove;
2611 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2613 this.showAutocalculatedAbove = showAutocalculatedAbove;
2617 public boolean isScaleProteinAsCdna()
2619 return viewStyle.isScaleProteinAsCdna();
2623 public void setScaleProteinAsCdna(boolean b)
2625 viewStyle.setScaleProteinAsCdna(b);
2629 * @return true if view should scroll to show the highlighted region of a
2634 public final boolean isFollowHighlight()
2636 return followHighlight;
2640 public final void setFollowHighlight(boolean b)
2642 this.followHighlight = b;
2645 public int getStartRes()
2651 public int getEndRes()
2656 public int getStartSeq()
2661 public void setStartRes(int res)
2663 this.startRes = res;
2666 public void setStartSeq(int seq)
2668 this.startSeq = seq;
2671 public void setEndRes(int res)
2673 if (res > alignment.getWidth() - 1)
2675 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2676 // (alignment.getWidth()-1));
2677 res = alignment.getWidth() - 1;
2686 public void setEndSeq(int seq)
2688 if (seq > alignment.getHeight())
2690 seq = alignment.getHeight();
2699 public int getEndSeq()
2705 * Helper method to populate the SearchResults with the location in the
2706 * complementary alignment to scroll to, in order to match this one.
2709 * the SearchResults to add to
2710 * @return the offset (below top of visible region) of the matched sequence
2712 protected int findComplementScrollTarget(SearchResultsI sr)
2714 final AlignViewportI complement = getCodingComplement();
2715 if (complement == null || !complement.isFollowHighlight())
2719 boolean iAmProtein = !getAlignment().isNucleotide();
2720 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2722 if (proteinAlignment == null)
2726 final List<AlignedCodonFrame> mappings = proteinAlignment
2730 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2731 * residue in the middle column of the visible region. Scroll the
2732 * complementary alignment to line up the corresponding residue.
2735 SequenceI sequence = null;
2738 * locate 'middle' column (true middle if an odd number visible, left of
2739 * middle if an even number visible)
2741 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2742 final HiddenSequences hiddenSequences = getAlignment()
2743 .getHiddenSequences();
2746 * searching to the bottom of the alignment gives smoother scrolling across
2747 * all gapped visible regions
2749 int lastSeq = alignment.getHeight() - 1;
2750 List<AlignedCodonFrame> seqMappings = null;
2751 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2753 sequence = getAlignment().getSequenceAt(seqNo);
2754 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2758 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2762 seqMappings = MappingUtils
2763 .findMappingsForSequenceAndOthers(sequence, mappings,
2764 getCodingComplement().getAlignment().getSequences());
2765 if (!seqMappings.isEmpty())
2771 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2774 * No ungapped mapped sequence in middle column - do nothing
2778 MappingUtils.addSearchResults(sr, sequence,
2779 sequence.findPosition(middleColumn), seqMappings);
2784 * synthesize a column selection if none exists so it covers the given
2785 * selection group. if wholewidth is false, no column selection is made if the
2786 * selection group covers the whole alignment width.
2791 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2794 if (sg != null && (sgs = sg.getStartRes()) >= 0
2795 && sg.getStartRes() <= (sge = sg.getEndRes())
2796 && !this.hasSelectedColumns())
2798 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2805 colSel = new ColumnSelection();
2807 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2809 colSel.addElement(cspos);
2815 * hold status of current selection group - defined on alignment or not.
2817 private boolean selectionIsDefinedGroup = false;
2821 public boolean isSelectionDefinedGroup()
2823 if (selectionGroup == null)
2827 if (isSelectionGroupChanged(true))
2829 selectionIsDefinedGroup = false;
2830 List<SequenceGroup> gps = alignment.getGroups();
2831 if (gps == null || gps.size() == 0)
2833 selectionIsDefinedGroup = false;
2837 selectionIsDefinedGroup = gps.contains(selectionGroup);
2840 return selectionGroup.getContext() == alignment
2841 || selectionIsDefinedGroup;
2845 * null, or currently highlighted results on this view
2847 private SearchResultsI searchResults = null;
2850 public boolean hasSearchResults()
2852 return searchResults != null;
2856 public void setSearchResults(SearchResultsI results)
2858 searchResults = results;
2862 public SearchResultsI getSearchResults()
2864 return searchResults;