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 CollectionColourScheme 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 colour scheme once, thereafter update it
618 if (globalColourScheme == null)
620 globalColourScheme = new CollectionColourScheme();
622 globalColourScheme.setColourScheme(cs);
624 boolean recalc = false;
627 recalc = getConservationSelected();
628 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
629 || cs instanceof Blosum62ColourScheme)
632 globalColourScheme.setThreshold(viewStyle.getThreshold(),
633 ignoreGapsInConsensusCalculation);
638 .setThreshold(0, ignoreGapsInConsensusCalculation);
642 globalColourScheme.setConsensus(hconsensus);
643 globalColourScheme.setConservation(hconservation);
645 globalColourScheme.setConservationApplied(getConservationSelected());
646 globalColourScheme.alignmentChanged(alignment, hiddenRepSequences);
648 if (getColourAppliesToAllGroups())
650 for (SequenceGroup sg : getAlignment().getGroups())
654 sg.setColourScheme(null);
657 CollectionColourScheme groupColour = new CollectionColourScheme(cs.getInstance(sg,
658 getHiddenRepSequences()));
659 sg.setGroupColourScheme(groupColour);
660 sg.setConsPercGaps(ConsPercGaps);
661 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
662 || cs instanceof Blosum62ColourScheme)
664 groupColour.setThreshold(viewStyle.getThreshold(),
665 isIgnoreGapsConsensus());
670 groupColour.setThreshold(0, isIgnoreGapsConsensus());
673 if (getConservationSelected())
675 groupColour.setConservationApplied(true);
680 groupColour.setConservation(null);
681 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
685 sg.recalcConservation();
689 groupColour.alignmentChanged(sg, hiddenRepSequences);
696 public ColourSchemeI getGlobalColourScheme()
698 return globalColourScheme == null ? null : globalColourScheme
703 public CollectionColourSchemeI getViewportColourScheme()
705 return globalColourScheme;
708 protected AlignmentAnnotation consensus;
710 protected AlignmentAnnotation complementConsensus;
712 protected AlignmentAnnotation strucConsensus;
714 protected AlignmentAnnotation conservation;
716 protected AlignmentAnnotation quality;
718 protected AlignmentAnnotation[] groupConsensus;
720 protected AlignmentAnnotation[] groupConservation;
723 * results of alignment consensus analysis for visible portion of view
725 protected ProfilesI hconsensus = null;
728 * results of cDNA complement consensus visible portion of view
730 protected Hashtable[] hcomplementConsensus = null;
733 * results of secondary structure base pair consensus for visible portion of
736 protected Hashtable[] hStrucConsensus = null;
738 protected Conservation hconservation = null;
741 public void setConservation(Conservation cons)
743 hconservation = cons;
747 * percentage gaps allowed in a column before all amino acid properties should
748 * be considered unconserved
750 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
753 public int getConsPercGaps()
759 public void setSequenceConsensusHash(ProfilesI hconsensus)
761 this.hconsensus = hconsensus;
765 public void setComplementConsensusHash(Hashtable[] hconsensus)
767 this.hcomplementConsensus = hconsensus;
771 public ProfilesI getSequenceConsensusHash()
777 public Hashtable[] getComplementConsensusHash()
779 return hcomplementConsensus;
783 public Hashtable[] getRnaStructureConsensusHash()
785 return hStrucConsensus;
789 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
791 this.hStrucConsensus = hStrucConsensus;
796 public AlignmentAnnotation getAlignmentQualityAnnot()
802 public AlignmentAnnotation getAlignmentConservationAnnotation()
808 public AlignmentAnnotation getAlignmentConsensusAnnotation()
814 public AlignmentAnnotation getComplementConsensusAnnotation()
816 return complementConsensus;
820 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
822 return strucConsensus;
825 protected AlignCalcManagerI calculator = new AlignCalcManager();
828 * trigger update of conservation annotation
830 public void updateConservation(final AlignmentViewPanel ap)
832 // see note in mantis : issue number 8585
833 if (alignment.isNucleotide()
834 || (conservation == null && quality == null)
835 || !autoCalculateConsensus)
840 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
842 calculator.registerWorker(new jalview.workers.ConservationThread(
848 * trigger update of consensus annotation
850 public void updateConsensus(final AlignmentViewPanel ap)
852 // see note in mantis : issue number 8585
853 if (consensus == null || !autoCalculateConsensus)
857 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
859 calculator.registerWorker(new ConsensusThread(this, ap));
863 * A separate thread to compute cDNA consensus for a protein alignment
864 * which has mapping to cDNA
866 final AlignmentI al = this.getAlignment();
867 if (!al.isNucleotide() && al.getCodonFrames() != null
868 && !al.getCodonFrames().isEmpty())
871 * fudge - check first for protein-to-nucleotide mappings
872 * (we don't want to do this for protein-to-protein)
874 boolean doConsensus = false;
875 for (AlignedCodonFrame mapping : al.getCodonFrames())
877 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
878 MapList[] mapLists = mapping.getdnaToProt();
879 // mapLists can be empty if project load has not finished resolving seqs
880 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
889 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
892 .registerWorker(new ComplementConsensusThread(this, ap));
898 // --------START Structure Conservation
899 public void updateStrucConsensus(final AlignmentViewPanel ap)
901 if (autoCalculateStrucConsensus && strucConsensus == null
902 && alignment.isNucleotide() && alignment.hasRNAStructure())
904 // secondary structure has been added - so init the consensus line
908 // see note in mantis : issue number 8585
909 if (strucConsensus == null || !autoCalculateStrucConsensus)
913 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
915 calculator.registerWorker(new StrucConsensusThread(this, ap));
919 public boolean isCalcInProgress()
921 return calculator.isWorking();
925 public boolean isCalculationInProgress(
926 AlignmentAnnotation alignmentAnnotation)
928 if (!alignmentAnnotation.autoCalculated)
932 if (calculator.workingInvolvedWith(alignmentAnnotation))
934 // System.err.println("grey out ("+alignmentAnnotation.label+")");
940 public void setAlignment(AlignmentI align)
942 this.alignment = align;
946 * Clean up references when this viewport is closed
949 public void dispose()
952 * defensively null out references to large objects in case
953 * this object is not garbage collected (as if!)
956 complementConsensus = null;
957 strucConsensus = null;
960 groupConsensus = null;
961 groupConservation = null;
963 hcomplementConsensus = null;
964 // colour scheme may hold reference to consensus
965 globalColourScheme = null;
966 // TODO remove listeners from changeSupport?
967 changeSupport = null;
972 public boolean isClosed()
974 // TODO: check that this isClosed is only true after panel is closed, not
975 // before it is fully constructed.
976 return alignment == null;
980 public AlignCalcManagerI getCalcManager()
986 * should conservation rows be shown for groups
988 protected boolean showGroupConservation = false;
991 * should consensus rows be shown for groups
993 protected boolean showGroupConsensus = false;
996 * should consensus profile be rendered by default
998 protected boolean showSequenceLogo = false;
1001 * should consensus profile be rendered normalised to row height
1003 protected boolean normaliseSequenceLogo = false;
1006 * should consensus histograms be rendered by default
1008 protected boolean showConsensusHistogram = true;
1011 * @return the showConsensusProfile
1014 public boolean isShowSequenceLogo()
1016 return showSequenceLogo;
1020 * @param showSequenceLogo
1023 public void setShowSequenceLogo(boolean showSequenceLogo)
1025 if (showSequenceLogo != this.showSequenceLogo)
1027 // TODO: decouple settings setting from calculation when refactoring
1028 // annotation update method from alignframe to viewport
1029 this.showSequenceLogo = showSequenceLogo;
1030 calculator.updateAnnotationFor(ConsensusThread.class);
1031 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1032 calculator.updateAnnotationFor(StrucConsensusThread.class);
1034 this.showSequenceLogo = showSequenceLogo;
1038 * @param showConsensusHistogram
1039 * the showConsensusHistogram to set
1041 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1043 this.showConsensusHistogram = showConsensusHistogram;
1047 * @return the showGroupConservation
1049 public boolean isShowGroupConservation()
1051 return showGroupConservation;
1055 * @param showGroupConservation
1056 * the showGroupConservation to set
1058 public void setShowGroupConservation(boolean showGroupConservation)
1060 this.showGroupConservation = showGroupConservation;
1064 * @return the showGroupConsensus
1066 public boolean isShowGroupConsensus()
1068 return showGroupConsensus;
1072 * @param showGroupConsensus
1073 * the showGroupConsensus to set
1075 public void setShowGroupConsensus(boolean showGroupConsensus)
1077 this.showGroupConsensus = showGroupConsensus;
1082 * @return flag to indicate if the consensus histogram should be rendered by
1086 public boolean isShowConsensusHistogram()
1088 return this.showConsensusHistogram;
1092 * when set, updateAlignment will always ensure sequences are of equal length
1094 private boolean padGaps = false;
1097 * when set, alignment should be reordered according to a newly opened tree
1099 public boolean sortByTree = false;
1104 * @return null or the currently selected sequence region
1107 public SequenceGroup getSelectionGroup()
1109 return selectionGroup;
1113 * Set the selection group for this window.
1116 * - group holding references to sequences in this alignment view
1120 public void setSelectionGroup(SequenceGroup sg)
1122 selectionGroup = sg;
1125 public void setHiddenColumns(ColumnSelection colsel)
1127 this.colSel = colsel;
1131 public ColumnSelection getColumnSelection()
1137 public void setColumnSelection(ColumnSelection colSel)
1139 this.colSel = colSel;
1142 updateHiddenColumns();
1144 isColSelChanged(true);
1152 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1154 return hiddenRepSequences;
1158 public void setHiddenRepSequences(
1159 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1161 this.hiddenRepSequences = hiddenRepSequences;
1165 public boolean hasSelectedColumns()
1167 ColumnSelection columnSelection = getColumnSelection();
1168 return columnSelection != null && columnSelection.hasSelectedColumns();
1172 public boolean hasHiddenColumns()
1174 return colSel != null && colSel.hasHiddenColumns();
1177 public void updateHiddenColumns()
1179 // this method doesn't really do anything now. But - it could, since a
1180 // column Selection could be in the process of modification
1181 // hasHiddenColumns = colSel.hasHiddenColumns();
1185 public boolean hasHiddenRows()
1187 return alignment.getHiddenSequences().getSize() > 0;
1190 protected SequenceGroup selectionGroup;
1192 public void setSequenceSetId(String newid)
1194 if (sequenceSetID != null)
1197 .println("Warning - overwriting a sequenceSetId for a viewport!");
1199 sequenceSetID = new String(newid);
1203 public String getSequenceSetId()
1205 if (sequenceSetID == null)
1207 sequenceSetID = alignment.hashCode() + "";
1210 return sequenceSetID;
1214 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1217 protected String viewId = null;
1220 public String getViewId()
1224 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1229 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1231 ignoreGapsInConsensusCalculation = b;
1234 updateConsensus(ap);
1235 if (globalColourScheme != null)
1237 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1238 ignoreGapsInConsensusCalculation);
1244 private long sgrouphash = -1, colselhash = -1;
1247 * checks current SelectionGroup against record of last hash value, and
1251 * update the record of last hash value
1253 * @return true if SelectionGroup changed since last call (when b is true)
1255 public boolean isSelectionGroupChanged(boolean b)
1257 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1258 : selectionGroup.hashCode();
1259 if (hc != -1 && hc != sgrouphash)
1271 * checks current colsel against record of last hash value, and optionally
1275 * update the record of last hash value
1276 * @return true if colsel changed since last call (when b is true)
1278 public boolean isColSelChanged(boolean b)
1280 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1281 if (hc != -1 && hc != colselhash)
1293 public boolean isIgnoreGapsConsensus()
1295 return ignoreGapsInConsensusCalculation;
1298 // property change stuff
1299 // JBPNote Prolly only need this in the applet version.
1300 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1303 protected boolean showConservation = true;
1305 protected boolean showQuality = true;
1307 protected boolean showConsensus = true;
1309 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1311 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1313 protected boolean showAutocalculatedAbove;
1316 * when set, view will scroll to show the highlighted position
1318 private boolean followHighlight = true;
1320 // TODO private with getters and setters?
1321 public int startRes;
1325 public int startSeq;
1330 * Property change listener for changes in alignment
1335 public void addPropertyChangeListener(
1336 java.beans.PropertyChangeListener listener)
1338 changeSupport.addPropertyChangeListener(listener);
1347 public void removePropertyChangeListener(
1348 java.beans.PropertyChangeListener listener)
1350 changeSupport.removePropertyChangeListener(listener);
1354 * Property change listener for changes in alignment
1363 public void firePropertyChange(String prop, Object oldvalue,
1366 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1369 // common hide/show column stuff
1371 public void hideSelectedColumns()
1373 if (colSel.isEmpty())
1378 colSel.hideSelectedColumns();
1379 setSelectionGroup(null);
1380 isColSelChanged(true);
1383 public void hideColumns(int start, int end)
1387 colSel.hideColumns(start);
1391 colSel.hideColumns(start, end);
1393 isColSelChanged(true);
1396 public void showColumn(int col)
1398 colSel.revealHiddenColumns(col);
1399 isColSelChanged(true);
1402 public void showAllHiddenColumns()
1404 colSel.revealAllHiddenColumns();
1405 isColSelChanged(true);
1408 // common hide/show seq stuff
1409 public void showAllHiddenSeqs()
1411 if (alignment.getHiddenSequences().getSize() > 0)
1413 if (selectionGroup == null)
1415 selectionGroup = new SequenceGroup();
1416 selectionGroup.setEndRes(alignment.getWidth() - 1);
1418 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1419 hiddenRepSequences);
1420 for (SequenceI seq : tmp)
1422 selectionGroup.addSequence(seq, false);
1423 setSequenceAnnotationsVisible(seq, true);
1426 hiddenRepSequences = null;
1428 firePropertyChange("alignment", null, alignment.getSequences());
1429 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1435 public void showSequence(int index)
1437 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1438 index, hiddenRepSequences);
1441 if (selectionGroup == null)
1443 selectionGroup = new SequenceGroup();
1444 selectionGroup.setEndRes(alignment.getWidth() - 1);
1447 for (SequenceI seq : tmp)
1449 selectionGroup.addSequence(seq, false);
1450 setSequenceAnnotationsVisible(seq, true);
1452 firePropertyChange("alignment", null, alignment.getSequences());
1457 public void hideAllSelectedSeqs()
1459 if (selectionGroup == null || selectionGroup.getSize() < 1)
1464 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1468 setSelectionGroup(null);
1471 public void hideSequence(SequenceI[] seq)
1475 for (int i = 0; i < seq.length; i++)
1477 alignment.getHiddenSequences().hideSequence(seq[i]);
1478 setSequenceAnnotationsVisible(seq[i], false);
1480 firePropertyChange("alignment", null, alignment.getSequences());
1485 * Hides the specified sequence, or the sequences it represents
1488 * the sequence to hide, or keep as representative
1489 * @param representGroup
1490 * if true, hide the current selection group except for the
1491 * representative sequence
1493 public void hideSequences(SequenceI sequence, boolean representGroup)
1495 if (selectionGroup == null || selectionGroup.getSize() < 1)
1497 hideSequence(new SequenceI[] { sequence });
1503 hideRepSequences(sequence, selectionGroup);
1504 setSelectionGroup(null);
1508 int gsize = selectionGroup.getSize();
1509 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1510 new SequenceI[gsize]);
1512 hideSequence(hseqs);
1513 setSelectionGroup(null);
1518 * Set visibility for any annotations for the given sequence.
1522 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1525 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1528 for (AlignmentAnnotation ann : anns)
1530 if (ann.sequenceRef == sequenceI)
1532 ann.visible = visible;
1538 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1540 int sSize = sg.getSize();
1546 if (hiddenRepSequences == null)
1548 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1551 hiddenRepSequences.put(repSequence, sg);
1553 // Hide all sequences except the repSequence
1554 SequenceI[] seqs = new SequenceI[sSize - 1];
1556 for (int i = 0; i < sSize; i++)
1558 if (sg.getSequenceAt(i) != repSequence)
1560 if (index == sSize - 1)
1565 seqs[index++] = sg.getSequenceAt(i);
1568 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1569 sg.setHidereps(true); // note: not done in 2.7applet
1576 * @return null or the current reference sequence
1578 public SequenceI getReferenceSeq()
1580 return alignment.getSeqrep();
1585 * @return true iff seq is the reference for the alignment
1587 public boolean isReferenceSeq(SequenceI seq)
1589 return alignment.getSeqrep() == seq;
1595 * @return true if there are sequences represented by this sequence that are
1598 public boolean isHiddenRepSequence(SequenceI seq)
1600 return (hiddenRepSequences != null && hiddenRepSequences
1607 * @return null or a sequence group containing the sequences that seq
1610 public SequenceGroup getRepresentedSequences(SequenceI seq)
1612 return (SequenceGroup) (hiddenRepSequences == null ? null
1613 : hiddenRepSequences.get(seq));
1617 public int adjustForHiddenSeqs(int alignmentIndex)
1619 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1624 public void invertColumnSelection()
1626 colSel.invertColumnSelection(0, alignment.getWidth());
1630 public SequenceI[] getSelectionAsNewSequence()
1632 SequenceI[] sequences;
1633 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1634 // this was the only caller in the applet for this method
1635 // JBPNote: in applet, this method returned references to the alignment
1636 // sequences, and it did not honour the presence/absence of annotation
1637 // attached to the alignment (probably!)
1638 if (selectionGroup == null || selectionGroup.getSize() == 0)
1640 sequences = alignment.getSequencesArray();
1641 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1642 for (int i = 0; i < sequences.length; i++)
1644 // construct new sequence with subset of visible annotation
1645 sequences[i] = new Sequence(sequences[i], annots);
1650 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1657 public SequenceI[] getSequenceSelection()
1659 SequenceI[] sequences = null;
1660 if (selectionGroup != null)
1662 sequences = selectionGroup.getSequencesInOrder(alignment);
1664 if (sequences == null)
1666 sequences = alignment.getSequencesArray();
1672 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1674 return new CigarArray(alignment, colSel,
1675 (selectedRegionOnly ? selectionGroup : null));
1679 public jalview.datamodel.AlignmentView getAlignmentView(
1680 boolean selectedOnly)
1682 return getAlignmentView(selectedOnly, false);
1686 public jalview.datamodel.AlignmentView getAlignmentView(
1687 boolean selectedOnly, boolean markGroups)
1689 return new AlignmentView(alignment, colSel, selectionGroup,
1690 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1695 public String[] getViewAsString(boolean selectedRegionOnly)
1697 return getViewAsString(selectedRegionOnly, true);
1701 public String[] getViewAsString(boolean selectedRegionOnly,
1702 boolean exportHiddenSeqs)
1704 String[] selection = null;
1705 SequenceI[] seqs = null;
1707 int start = 0, end = 0;
1708 if (selectedRegionOnly && selectionGroup != null)
1710 iSize = selectionGroup.getSize();
1711 seqs = selectionGroup.getSequencesInOrder(alignment);
1712 start = selectionGroup.getStartRes();
1713 end = selectionGroup.getEndRes() + 1;
1717 if (hasHiddenRows() && exportHiddenSeqs)
1719 AlignmentI fullAlignment = alignment.getHiddenSequences()
1720 .getFullAlignment();
1721 iSize = fullAlignment.getHeight();
1722 seqs = fullAlignment.getSequencesArray();
1723 end = fullAlignment.getWidth();
1727 iSize = alignment.getHeight();
1728 seqs = alignment.getSequencesArray();
1729 end = alignment.getWidth();
1733 selection = new String[iSize];
1734 if (colSel != null && colSel.hasHiddenColumns())
1736 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1740 for (i = 0; i < iSize; i++)
1742 selection[i] = seqs[i].getSequenceAsString(start, end);
1750 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1752 ArrayList<int[]> regions = new ArrayList<int[]>();
1758 if (colSel != null && colSel.hasHiddenColumns())
1762 start = colSel.adjustForHiddenColumns(start);
1765 end = colSel.getHiddenBoundaryRight(start);
1776 regions.add(new int[] { start, end });
1778 if (colSel != null && colSel.hasHiddenColumns())
1780 start = colSel.adjustForHiddenColumns(end);
1781 start = colSel.getHiddenBoundaryLeft(start) + 1;
1783 } while (end < max);
1785 int[][] startEnd = new int[regions.size()][2];
1791 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1792 boolean selectedOnly)
1794 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1795 AlignmentAnnotation[] aa;
1796 if ((aa = alignment.getAlignmentAnnotation()) != null)
1798 for (AlignmentAnnotation annot : aa)
1800 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1801 if (selectedOnly && selectionGroup != null)
1803 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1804 selectionGroup.getEndRes(), clone);
1808 colSel.makeVisibleAnnotation(clone);
1817 public boolean isPadGaps()
1823 public void setPadGaps(boolean padGaps)
1825 this.padGaps = padGaps;
1829 * apply any post-edit constraints and trigger any calculations needed after
1830 * an edit has been performed on the alignment
1835 public void alignmentChanged(AlignmentViewPanel ap)
1839 alignment.padGaps();
1841 if (autoCalculateConsensus)
1843 updateConsensus(ap);
1845 if (hconsensus != null && autoCalculateConsensus)
1847 updateConservation(ap);
1849 if (autoCalculateStrucConsensus)
1851 updateStrucConsensus(ap);
1854 // Reset endRes of groups if beyond alignment width
1855 int alWidth = alignment.getWidth();
1856 List<SequenceGroup> groups = alignment.getGroups();
1859 for (SequenceGroup sg : groups)
1861 if (sg.getEndRes() > alWidth)
1863 sg.setEndRes(alWidth - 1);
1868 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1870 selectionGroup.setEndRes(alWidth - 1);
1873 resetAllColourSchemes();
1874 calculator.restartWorkers();
1875 // alignment.adjustSequenceAnnotations();
1879 * reset scope and do calculations for all applied colourschemes on alignment
1881 void resetAllColourSchemes()
1883 CollectionColourScheme cs = globalColourScheme;
1886 cs.alignmentChanged(alignment, hiddenRepSequences);
1888 cs.setConsensus(hconsensus);
1889 if (cs.conservationApplied())
1891 cs.setConservation(Conservation.calculateConservation("All",
1892 alignment.getSequences(), 0, alignment.getWidth(), false,
1893 getConsPercGaps(), false));
1897 for (SequenceGroup sg : alignment.getGroups())
1901 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1903 sg.recalcConservation();
1907 protected void initAutoAnnotation()
1909 // TODO: add menu option action that nulls or creates consensus object
1910 // depending on if the user wants to see the annotation or not in a
1911 // specific alignment
1913 if (hconsensus == null && !isDataset)
1915 if (!alignment.isNucleotide())
1924 consensus = new AlignmentAnnotation("Consensus", "PID",
1925 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1926 initConsensus(consensus);
1928 initComplementConsensus();
1933 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1934 * consensus annotation.
1936 public void initComplementConsensus()
1938 if (!alignment.isNucleotide())
1940 final List<AlignedCodonFrame> codonMappings = alignment
1942 if (codonMappings != null && !codonMappings.isEmpty())
1944 boolean doConsensus = false;
1945 for (AlignedCodonFrame mapping : codonMappings)
1947 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1948 MapList[] mapLists = mapping.getdnaToProt();
1949 // mapLists can be empty if project load has not finished resolving
1951 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1959 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1960 "PID for cDNA", new Annotation[1], 0f, 100f,
1961 AlignmentAnnotation.BAR_GRAPH);
1962 initConsensus(complementConsensus);
1968 private void initConsensus(AlignmentAnnotation aa)
1971 aa.autoCalculated = true;
1975 alignment.addAnnotation(aa);
1979 private void initConservation()
1981 if (showConservation)
1983 if (conservation == null)
1985 conservation = new AlignmentAnnotation("Conservation",
1986 "Conservation of total alignment less than "
1987 + getConsPercGaps() + "% gaps", new Annotation[1],
1988 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1989 conservation.hasText = true;
1990 conservation.autoCalculated = true;
1991 alignment.addAnnotation(conservation);
1996 private void initQuality()
2000 if (quality == null)
2002 quality = new AlignmentAnnotation("Quality",
2003 "Alignment Quality based on Blosum62 scores",
2004 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2005 quality.hasText = true;
2006 quality.autoCalculated = true;
2007 alignment.addAnnotation(quality);
2012 private void initRNAStructure()
2014 if (alignment.hasRNAStructure() && strucConsensus == null)
2016 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
2017 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2018 strucConsensus.hasText = true;
2019 strucConsensus.autoCalculated = true;
2023 alignment.addAnnotation(strucConsensus);
2031 * @see jalview.api.AlignViewportI#calcPanelHeight()
2034 public int calcPanelHeight()
2036 // setHeight of panels
2037 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2039 int charHeight = getCharHeight();
2042 BitSet graphgrp = new BitSet();
2043 for (AlignmentAnnotation aa : anns)
2047 System.err.println("Null annotation row: ignoring.");
2054 if (aa.graphGroup > -1)
2056 if (graphgrp.get(aa.graphGroup))
2062 graphgrp.set(aa.graphGroup);
2069 aa.height += charHeight;
2079 aa.height += aa.graphHeight;
2087 height += aa.height;
2099 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2100 boolean preserveNewGroupSettings)
2102 boolean updateCalcs = false;
2103 boolean conv = isShowGroupConservation();
2104 boolean cons = isShowGroupConsensus();
2105 boolean showprf = isShowSequenceLogo();
2106 boolean showConsHist = isShowConsensusHistogram();
2107 boolean normLogo = isNormaliseSequenceLogo();
2110 * TODO reorder the annotation rows according to group/sequence ordering on
2113 boolean sortg = true;
2115 // remove old automatic annotation
2116 // add any new annotation
2118 // intersect alignment annotation with alignment groups
2120 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2121 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2124 for (int an = 0; an < aan.length; an++)
2126 if (aan[an].autoCalculated && aan[an].groupRef != null)
2128 oldrfs.add(aan[an].groupRef);
2129 alignment.deleteAnnotation(aan[an], false);
2133 if (alignment.getGroups() != null)
2135 for (SequenceGroup sg : alignment.getGroups())
2137 updateCalcs = false;
2138 if (applyGlobalSettings
2139 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2141 // set defaults for this group's conservation/consensus
2142 sg.setshowSequenceLogo(showprf);
2143 sg.setShowConsensusHistogram(showConsHist);
2144 sg.setNormaliseSequenceLogo(normLogo);
2149 alignment.addAnnotation(sg.getConservationRow(), 0);
2154 alignment.addAnnotation(sg.getConsensus(), 0);
2156 // refresh the annotation rows
2159 sg.recalcConservation();
2167 public boolean isDisplayReferenceSeq()
2169 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2173 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2175 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2179 public boolean isColourByReferenceSeq()
2181 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2185 public Color getSequenceColour(SequenceI seq)
2187 Color sqc = sequenceColours.get(seq);
2188 return (sqc == null ? Color.white : sqc);
2192 public void setSequenceColour(SequenceI seq, Color col)
2196 sequenceColours.remove(seq);
2200 sequenceColours.put(seq, col);
2205 public void updateSequenceIdColours()
2207 for (SequenceGroup sg : alignment.getGroups())
2209 if (sg.idColour != null)
2211 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2213 sequenceColours.put(s, sg.idColour);
2220 public void clearSequenceColours()
2222 sequenceColours.clear();
2226 public AlignViewportI getCodingComplement()
2228 return this.codingComplement;
2232 * Set this as the (cDna/protein) complement of the given viewport. Also
2233 * ensures the reverse relationship is set on the given viewport.
2236 public void setCodingComplement(AlignViewportI av)
2240 System.err.println("Ignoring recursive setCodingComplement request");
2244 this.codingComplement = av;
2245 // avoid infinite recursion!
2246 if (av.getCodingComplement() != this)
2248 av.setCodingComplement(this);
2254 public boolean isNucleotide()
2256 return getAlignment() == null ? false : getAlignment().isNucleotide();
2260 public FeaturesDisplayedI getFeaturesDisplayed()
2262 return featuresDisplayed;
2266 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2268 featuresDisplayed = featuresDisplayedI;
2272 public boolean areFeaturesDisplayed()
2274 return featuresDisplayed != null
2275 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2282 * features are displayed if true
2285 public void setShowSequenceFeatures(boolean b)
2287 viewStyle.setShowSequenceFeatures(b);
2291 public boolean isShowSequenceFeatures()
2293 return viewStyle.isShowSequenceFeatures();
2297 public void setShowSequenceFeaturesHeight(boolean selected)
2299 viewStyle.setShowSequenceFeaturesHeight(selected);
2303 public boolean isShowSequenceFeaturesHeight()
2305 return viewStyle.isShowSequenceFeaturesHeight();
2309 public void setShowAnnotation(boolean b)
2311 viewStyle.setShowAnnotation(b);
2315 public boolean isShowAnnotation()
2317 return viewStyle.isShowAnnotation();
2321 public boolean isRightAlignIds()
2323 return viewStyle.isRightAlignIds();
2327 public void setRightAlignIds(boolean rightAlignIds)
2329 viewStyle.setRightAlignIds(rightAlignIds);
2333 public boolean getConservationSelected()
2335 return viewStyle.getConservationSelected();
2339 public void setShowBoxes(boolean state)
2341 viewStyle.setShowBoxes(state);
2346 * @see jalview.api.ViewStyleI#getTextColour()
2349 public Color getTextColour()
2351 return viewStyle.getTextColour();
2356 * @see jalview.api.ViewStyleI#getTextColour2()
2359 public Color getTextColour2()
2361 return viewStyle.getTextColour2();
2366 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2369 public int getThresholdTextColour()
2371 return viewStyle.getThresholdTextColour();
2376 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2379 public boolean isConservationColourSelected()
2381 return viewStyle.isConservationColourSelected();
2386 * @see jalview.api.ViewStyleI#isRenderGaps()
2389 public boolean isRenderGaps()
2391 return viewStyle.isRenderGaps();
2396 * @see jalview.api.ViewStyleI#isShowColourText()
2399 public boolean isShowColourText()
2401 return viewStyle.isShowColourText();
2405 * @param conservationColourSelected
2406 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2409 public void setConservationColourSelected(
2410 boolean conservationColourSelected)
2412 viewStyle.setConservationColourSelected(conservationColourSelected);
2416 * @param showColourText
2417 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2420 public void setShowColourText(boolean showColourText)
2422 viewStyle.setShowColourText(showColourText);
2427 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2430 public void setTextColour(Color textColour)
2432 viewStyle.setTextColour(textColour);
2436 * @param thresholdTextColour
2437 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2440 public void setThresholdTextColour(int thresholdTextColour)
2442 viewStyle.setThresholdTextColour(thresholdTextColour);
2446 * @param textColour2
2447 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2450 public void setTextColour2(Color textColour2)
2452 viewStyle.setTextColour2(textColour2);
2456 public ViewStyleI getViewStyle()
2458 return new ViewStyle(viewStyle);
2462 public void setViewStyle(ViewStyleI settingsForView)
2464 viewStyle = new ViewStyle(settingsForView);
2468 public boolean sameStyle(ViewStyleI them)
2470 return viewStyle.sameStyle(them);
2475 * @see jalview.api.ViewStyleI#getIdWidth()
2478 public int getIdWidth()
2480 return viewStyle.getIdWidth();
2485 * @see jalview.api.ViewStyleI#setIdWidth(int)
2488 public void setIdWidth(int i)
2490 viewStyle.setIdWidth(i);
2495 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2498 public boolean isCentreColumnLabels()
2500 return viewStyle.isCentreColumnLabels();
2504 * @param centreColumnLabels
2505 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2508 public void setCentreColumnLabels(boolean centreColumnLabels)
2510 viewStyle.setCentreColumnLabels(centreColumnLabels);
2515 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2518 public void setShowDBRefs(boolean showdbrefs)
2520 viewStyle.setShowDBRefs(showdbrefs);
2525 * @see jalview.api.ViewStyleI#isShowDBRefs()
2528 public boolean isShowDBRefs()
2530 return viewStyle.isShowDBRefs();
2535 * @see jalview.api.ViewStyleI#isShowNPFeats()
2538 public boolean isShowNPFeats()
2540 return viewStyle.isShowNPFeats();
2544 * @param shownpfeats
2545 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2548 public void setShowNPFeats(boolean shownpfeats)
2550 viewStyle.setShowNPFeats(shownpfeats);
2553 public abstract StructureSelectionManager getStructureSelectionManager();
2556 * Add one command to the command history list.
2560 public void addToHistoryList(CommandI command)
2562 if (this.historyList != null)
2564 this.historyList.push(command);
2565 broadcastCommand(command, false);
2569 protected void broadcastCommand(CommandI command, boolean undo)
2571 getStructureSelectionManager().commandPerformed(command, undo,
2576 * Add one command to the command redo list.
2580 public void addToRedoList(CommandI command)
2582 if (this.redoList != null)
2584 this.redoList.push(command);
2586 broadcastCommand(command, true);
2590 * Clear the command redo list.
2592 public void clearRedoList()
2594 if (this.redoList != null)
2596 this.redoList.clear();
2600 public void setHistoryList(Deque<CommandI> list)
2602 this.historyList = list;
2605 public Deque<CommandI> getHistoryList()
2607 return this.historyList;
2610 public void setRedoList(Deque<CommandI> list)
2612 this.redoList = list;
2615 public Deque<CommandI> getRedoList()
2617 return this.redoList;
2621 public VamsasSource getVamsasSource()
2626 public SequenceAnnotationOrder getSortAnnotationsBy()
2628 return sortAnnotationsBy;
2631 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2633 this.sortAnnotationsBy = sortAnnotationsBy;
2636 public boolean isShowAutocalculatedAbove()
2638 return showAutocalculatedAbove;
2641 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2643 this.showAutocalculatedAbove = showAutocalculatedAbove;
2647 public boolean isScaleProteinAsCdna()
2649 return viewStyle.isScaleProteinAsCdna();
2653 public void setScaleProteinAsCdna(boolean b)
2655 viewStyle.setScaleProteinAsCdna(b);
2659 * @return true if view should scroll to show the highlighted region of a
2664 public final boolean isFollowHighlight()
2666 return followHighlight;
2670 public final void setFollowHighlight(boolean b)
2672 this.followHighlight = b;
2675 public int getStartRes()
2681 public int getEndRes()
2686 public int getStartSeq()
2691 public void setStartRes(int res)
2693 this.startRes = res;
2696 public void setStartSeq(int seq)
2698 this.startSeq = seq;
2701 public void setEndRes(int res)
2703 if (res > alignment.getWidth() - 1)
2705 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2706 // (alignment.getWidth()-1));
2707 res = alignment.getWidth() - 1;
2716 public void setEndSeq(int seq)
2718 if (seq > alignment.getHeight())
2720 seq = alignment.getHeight();
2729 public int getEndSeq()
2735 * Helper method to populate the SearchResults with the location in the
2736 * complementary alignment to scroll to, in order to match this one.
2739 * the SearchResults to add to
2740 * @return the offset (below top of visible region) of the matched sequence
2742 protected int findComplementScrollTarget(SearchResultsI sr)
2744 final AlignViewportI complement = getCodingComplement();
2745 if (complement == null || !complement.isFollowHighlight())
2749 boolean iAmProtein = !getAlignment().isNucleotide();
2750 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2752 if (proteinAlignment == null)
2756 final List<AlignedCodonFrame> mappings = proteinAlignment
2760 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2761 * residue in the middle column of the visible region. Scroll the
2762 * complementary alignment to line up the corresponding residue.
2765 SequenceI sequence = null;
2768 * locate 'middle' column (true middle if an odd number visible, left of
2769 * middle if an even number visible)
2771 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2772 final HiddenSequences hiddenSequences = getAlignment()
2773 .getHiddenSequences();
2776 * searching to the bottom of the alignment gives smoother scrolling across
2777 * all gapped visible regions
2779 int lastSeq = alignment.getHeight() - 1;
2780 List<AlignedCodonFrame> seqMappings = null;
2781 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2783 sequence = getAlignment().getSequenceAt(seqNo);
2784 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2788 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2792 seqMappings = MappingUtils
2793 .findMappingsForSequenceAndOthers(sequence, mappings,
2794 getCodingComplement().getAlignment().getSequences());
2795 if (!seqMappings.isEmpty())
2801 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2804 * No ungapped mapped sequence in middle column - do nothing
2808 MappingUtils.addSearchResults(sr, sequence,
2809 sequence.findPosition(middleColumn), seqMappings);
2814 * synthesize a column selection if none exists so it covers the given
2815 * selection group. if wholewidth is false, no column selection is made if the
2816 * selection group covers the whole alignment width.
2821 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2824 if (sg != null && (sgs = sg.getStartRes()) >= 0
2825 && sg.getStartRes() <= (sge = sg.getEndRes())
2826 && !this.hasSelectedColumns())
2828 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2835 colSel = new ColumnSelection();
2837 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2839 colSel.addElement(cspos);
2845 * hold status of current selection group - defined on alignment or not.
2847 private boolean selectionIsDefinedGroup = false;
2851 public boolean isSelectionDefinedGroup()
2853 if (selectionGroup == null)
2857 if (isSelectionGroupChanged(true))
2859 selectionIsDefinedGroup = false;
2860 List<SequenceGroup> gps = alignment.getGroups();
2861 if (gps == null || gps.size() == 0)
2863 selectionIsDefinedGroup = false;
2867 selectionIsDefinedGroup = gps.contains(selectionGroup);
2870 return selectionGroup.getContext() == alignment
2871 || selectionIsDefinedGroup;
2875 * null, or currently highlighted results on this view
2877 private SearchResultsI searchResults = null;
2880 public boolean hasSearchResults()
2882 return searchResults != null;
2886 public void setSearchResults(SearchResultsI results)
2888 searchResults = results;
2892 public SearchResultsI getSearchResults()
2894 return searchResults;