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.SearchResultsI;
40 import jalview.datamodel.Sequence;
41 import jalview.datamodel.SequenceCollectionI;
42 import jalview.datamodel.SequenceGroup;
43 import jalview.datamodel.SequenceI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.ColourSchemeI;
46 import jalview.schemes.PIDColourScheme;
47 import jalview.structure.CommandListener;
48 import jalview.structure.StructureSelectionManager;
49 import jalview.structure.VamsasSource;
50 import jalview.util.Comparison;
51 import jalview.util.MapList;
52 import jalview.util.MappingUtils;
53 import jalview.viewmodel.styles.ViewStyle;
54 import jalview.workers.AlignCalcManager;
55 import jalview.workers.ComplementConsensusThread;
56 import jalview.workers.ConsensusThread;
57 import jalview.workers.StrucConsensusThread;
59 import java.awt.Color;
60 import java.beans.PropertyChangeSupport;
61 import java.util.ArrayDeque;
62 import java.util.ArrayList;
63 import java.util.BitSet;
64 import java.util.Deque;
65 import java.util.HashMap;
66 import java.util.Hashtable;
67 import java.util.List;
71 * base class holding visualization and analysis attributes and common logic for
72 * an active alignment view displayed in the GUI
77 public abstract class AlignmentViewport implements AlignViewportI,
78 CommandListener, VamsasSource
80 protected ViewStyleI viewStyle = new ViewStyle();
83 * A viewport that hosts the cDna view of this (protein), or vice versa (if
86 AlignViewportI codingComplement = null;
88 FeaturesDisplayedI featuresDisplayed = null;
90 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
92 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
96 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
99 public void setFontName(String name)
101 viewStyle.setFontName(name);
106 * @see jalview.api.ViewStyleI#setFontStyle(int)
109 public void setFontStyle(int style)
111 viewStyle.setFontStyle(style);
116 * @see jalview.api.ViewStyleI#setFontSize(int)
119 public void setFontSize(int size)
121 viewStyle.setFontSize(size);
126 * @see jalview.api.ViewStyleI#getFontStyle()
129 public int getFontStyle()
131 return viewStyle.getFontStyle();
136 * @see jalview.api.ViewStyleI#getFontName()
139 public String getFontName()
141 return viewStyle.getFontName();
146 * @see jalview.api.ViewStyleI#getFontSize()
149 public int getFontSize()
151 return viewStyle.getFontSize();
155 * @param upperCasebold
156 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
159 public void setUpperCasebold(boolean upperCasebold)
161 viewStyle.setUpperCasebold(upperCasebold);
166 * @see jalview.api.ViewStyleI#isUpperCasebold()
169 public boolean isUpperCasebold()
171 return viewStyle.isUpperCasebold();
176 * @see jalview.api.ViewStyleI#isSeqNameItalics()
179 public boolean isSeqNameItalics()
181 return viewStyle.isSeqNameItalics();
185 * @param colourByReferenceSeq
186 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
189 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
191 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
196 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
199 public void setColourAppliesToAllGroups(boolean b)
201 viewStyle.setColourAppliesToAllGroups(b);
206 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
209 public boolean getColourAppliesToAllGroups()
211 return viewStyle.getColourAppliesToAllGroups();
216 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
219 public boolean getAbovePIDThreshold()
221 return viewStyle.getAbovePIDThreshold();
226 * @see jalview.api.ViewStyleI#setIncrement(int)
229 public void setIncrement(int inc)
231 viewStyle.setIncrement(inc);
236 * @see jalview.api.ViewStyleI#getIncrement()
239 public int getIncrement()
241 return viewStyle.getIncrement();
246 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
249 public void setConservationSelected(boolean b)
251 viewStyle.setConservationSelected(b);
256 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
259 public void setShowHiddenMarkers(boolean show)
261 viewStyle.setShowHiddenMarkers(show);
266 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
269 public boolean getShowHiddenMarkers()
271 return viewStyle.getShowHiddenMarkers();
276 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
279 public void setScaleRightWrapped(boolean b)
281 viewStyle.setScaleRightWrapped(b);
286 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
289 public void setScaleLeftWrapped(boolean b)
291 viewStyle.setScaleLeftWrapped(b);
296 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
299 public void setScaleAboveWrapped(boolean b)
301 viewStyle.setScaleAboveWrapped(b);
306 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
309 public boolean getScaleLeftWrapped()
311 return viewStyle.getScaleLeftWrapped();
316 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
319 public boolean getScaleAboveWrapped()
321 return viewStyle.getScaleAboveWrapped();
326 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
329 public boolean getScaleRightWrapped()
331 return viewStyle.getScaleRightWrapped();
336 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
339 public void setAbovePIDThreshold(boolean b)
341 viewStyle.setAbovePIDThreshold(b);
346 * @see jalview.api.ViewStyleI#setThreshold(int)
349 public void setThreshold(int thresh)
351 viewStyle.setThreshold(thresh);
356 * @see jalview.api.ViewStyleI#getThreshold()
359 public int getThreshold()
361 return viewStyle.getThreshold();
366 * @see jalview.api.ViewStyleI#getShowJVSuffix()
369 public boolean getShowJVSuffix()
371 return viewStyle.getShowJVSuffix();
376 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
379 public void setShowJVSuffix(boolean b)
381 viewStyle.setShowJVSuffix(b);
386 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
389 public void setWrapAlignment(boolean state)
391 viewStyle.setWrapAlignment(state);
396 * @see jalview.api.ViewStyleI#setShowText(boolean)
399 public void setShowText(boolean state)
401 viewStyle.setShowText(state);
406 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
409 public void setRenderGaps(boolean state)
411 viewStyle.setRenderGaps(state);
416 * @see jalview.api.ViewStyleI#getColourText()
419 public boolean getColourText()
421 return viewStyle.getColourText();
426 * @see jalview.api.ViewStyleI#setColourText(boolean)
429 public void setColourText(boolean state)
431 viewStyle.setColourText(state);
436 * @see jalview.api.ViewStyleI#getWrapAlignment()
439 public boolean getWrapAlignment()
441 return viewStyle.getWrapAlignment();
446 * @see jalview.api.ViewStyleI#getShowText()
449 public boolean getShowText()
451 return viewStyle.getShowText();
456 * @see jalview.api.ViewStyleI#getWrappedWidth()
459 public int getWrappedWidth()
461 return viewStyle.getWrappedWidth();
466 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
469 public void setWrappedWidth(int w)
471 viewStyle.setWrappedWidth(w);
476 * @see jalview.api.ViewStyleI#getCharHeight()
479 public int getCharHeight()
481 return viewStyle.getCharHeight();
486 * @see jalview.api.ViewStyleI#setCharHeight(int)
489 public void setCharHeight(int h)
491 viewStyle.setCharHeight(h);
496 * @see jalview.api.ViewStyleI#getCharWidth()
499 public int getCharWidth()
501 return viewStyle.getCharWidth();
506 * @see jalview.api.ViewStyleI#setCharWidth(int)
509 public void setCharWidth(int w)
511 viewStyle.setCharWidth(w);
516 * @see jalview.api.ViewStyleI#getShowBoxes()
519 public boolean getShowBoxes()
521 return viewStyle.getShowBoxes();
526 * @see jalview.api.ViewStyleI#getShowUnconserved()
529 public boolean getShowUnconserved()
531 return viewStyle.getShowUnconserved();
535 * @param showunconserved
536 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
539 public void setShowUnconserved(boolean showunconserved)
541 viewStyle.setShowUnconserved(showunconserved);
546 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
549 public void setSeqNameItalics(boolean default1)
551 viewStyle.setSeqNameItalics(default1);
555 * alignment displayed in the viewport. Please use get/setter
557 protected AlignmentI alignment;
560 public AlignmentI getAlignment()
566 public char getGapCharacter()
568 return alignment.getGapCharacter();
571 protected String sequenceSetID;
574 * probably unused indicator that view is of a dataset rather than an
577 protected boolean isDataset = false;
579 public void setDataset(boolean b)
584 public boolean isDataset()
589 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
591 protected ColumnSelection colSel = new ColumnSelection();
593 public boolean autoCalculateConsensus = true;
595 protected boolean autoCalculateStrucConsensus = true;
597 protected boolean ignoreGapsInConsensusCalculation = false;
599 protected ColourSchemeI globalColourScheme = null;
602 public void setGlobalColourScheme(ColourSchemeI cs)
604 // TODO: logic refactored from AlignFrame changeColour -
605 // TODO: autorecalc stuff should be changed to rely on the worker system
606 // check to see if we should implement a changeColour(cs) method rather than
607 // put th logic in here
608 // - means that caller decides if they want to just modify state and defer
609 // calculation till later or to do all calculations in thread.
611 globalColourScheme = cs;
612 boolean recalc = false;
615 recalc = getConservationSelected();
616 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
617 || cs instanceof Blosum62ColourScheme)
620 cs.setThreshold(viewStyle.getThreshold(),
621 ignoreGapsInConsensusCalculation);
625 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
629 cs.setConsensus(hconsensus);
630 cs.setConservation(hconservation);
632 cs.setConservationApplied(getConservationSelected());
633 cs.alignmentChanged(alignment, hiddenRepSequences);
635 if (getColourAppliesToAllGroups())
637 for (SequenceGroup sg : getAlignment().getGroups())
644 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
645 sg.setConsPercGaps(ConsPercGaps);
646 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
647 || cs instanceof Blosum62ColourScheme)
649 sg.cs.setThreshold(viewStyle.getThreshold(),
650 isIgnoreGapsConsensus());
655 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
658 if (getConservationSelected())
660 sg.cs.setConservationApplied(true);
665 sg.cs.setConservation(null);
666 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
670 sg.recalcConservation();
674 sg.cs.alignmentChanged(sg, hiddenRepSequences);
681 public ColourSchemeI getGlobalColourScheme()
683 return globalColourScheme;
686 protected AlignmentAnnotation consensus;
688 protected AlignmentAnnotation complementConsensus;
690 protected AlignmentAnnotation strucConsensus;
692 protected AlignmentAnnotation conservation;
694 protected AlignmentAnnotation quality;
696 protected AlignmentAnnotation[] groupConsensus;
698 protected AlignmentAnnotation[] groupConservation;
701 * results of alignment consensus analysis for visible portion of view
703 protected Hashtable[] hconsensus = null;
706 * results of cDNA complement consensus visible portion of view
708 protected Hashtable[] hcomplementConsensus = null;
711 * results of secondary structure base pair consensus for visible portion of
714 protected Hashtable[] hStrucConsensus = null;
716 protected Conservation hconservation = null;
719 public void setConservation(Conservation cons)
721 hconservation = cons;
725 * percentage gaps allowed in a column before all amino acid properties should
726 * be considered unconserved
728 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
731 public int getConsPercGaps()
737 public void setSequenceConsensusHash(Hashtable[] hconsensus)
739 this.hconsensus = hconsensus;
743 public void setComplementConsensusHash(Hashtable[] hconsensus)
745 this.hcomplementConsensus = hconsensus;
749 public Hashtable[] getSequenceConsensusHash()
755 public Hashtable[] getComplementConsensusHash()
757 return hcomplementConsensus;
761 public Hashtable[] getRnaStructureConsensusHash()
763 return hStrucConsensus;
767 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
769 this.hStrucConsensus = hStrucConsensus;
774 public AlignmentAnnotation getAlignmentQualityAnnot()
780 public AlignmentAnnotation getAlignmentConservationAnnotation()
786 public AlignmentAnnotation getAlignmentConsensusAnnotation()
792 public AlignmentAnnotation getComplementConsensusAnnotation()
794 return complementConsensus;
798 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
800 return strucConsensus;
803 protected AlignCalcManagerI calculator = new AlignCalcManager();
806 * trigger update of conservation annotation
808 public void updateConservation(final AlignmentViewPanel ap)
810 // see note in mantis : issue number 8585
811 if (alignment.isNucleotide()
812 || (conservation == null && quality == null)
813 || !autoCalculateConsensus)
818 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
820 calculator.registerWorker(new jalview.workers.ConservationThread(
826 * trigger update of consensus annotation
828 public void updateConsensus(final AlignmentViewPanel ap)
830 // see note in mantis : issue number 8585
831 if (consensus == null || !autoCalculateConsensus)
835 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
837 calculator.registerWorker(new ConsensusThread(this, ap));
841 * A separate thread to compute cDNA consensus for a protein alignment
842 * which has mapping to cDNA
844 final AlignmentI al = this.getAlignment();
845 if (!al.isNucleotide() && al.getCodonFrames() != null
846 && !al.getCodonFrames().isEmpty())
849 * fudge - check first for protein-to-nucleotide mappings
850 * (we don't want to do this for protein-to-protein)
852 boolean doConsensus = false;
853 for (AlignedCodonFrame mapping : al.getCodonFrames())
855 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
856 MapList[] mapLists = mapping.getdnaToProt();
857 // mapLists can be empty if project load has not finished resolving seqs
858 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
867 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
870 .registerWorker(new ComplementConsensusThread(this, ap));
876 // --------START Structure Conservation
877 public void updateStrucConsensus(final AlignmentViewPanel ap)
879 if (autoCalculateStrucConsensus && strucConsensus == null
880 && alignment.isNucleotide() && alignment.hasRNAStructure())
882 // secondary structure has been added - so init the consensus line
886 // see note in mantis : issue number 8585
887 if (strucConsensus == null || !autoCalculateStrucConsensus)
891 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
893 calculator.registerWorker(new StrucConsensusThread(this, ap));
897 public boolean isCalcInProgress()
899 return calculator.isWorking();
903 public boolean isCalculationInProgress(
904 AlignmentAnnotation alignmentAnnotation)
906 if (!alignmentAnnotation.autoCalculated)
910 if (calculator.workingInvolvedWith(alignmentAnnotation))
912 // System.err.println("grey out ("+alignmentAnnotation.label+")");
918 public void setAlignment(AlignmentI align)
920 this.alignment = align;
924 * Clean up references when this viewport is closed
927 public void dispose()
930 * defensively null out references to large objects in case
931 * this object is not garbage collected (as if!)
934 complementConsensus = null;
935 strucConsensus = null;
938 groupConsensus = null;
939 groupConservation = null;
941 hcomplementConsensus = null;
942 // TODO removed listeners from changeSupport?
943 changeSupport = null;
948 public boolean isClosed()
950 // TODO: check that this isClosed is only true after panel is closed, not
951 // before it is fully constructed.
952 return alignment == null;
956 public AlignCalcManagerI getCalcManager()
962 * should conservation rows be shown for groups
964 protected boolean showGroupConservation = false;
967 * should consensus rows be shown for groups
969 protected boolean showGroupConsensus = false;
972 * should consensus profile be rendered by default
974 protected boolean showSequenceLogo = false;
977 * should consensus profile be rendered normalised to row height
979 protected boolean normaliseSequenceLogo = false;
982 * should consensus histograms be rendered by default
984 protected boolean showConsensusHistogram = true;
987 * @return the showConsensusProfile
990 public boolean isShowSequenceLogo()
992 return showSequenceLogo;
996 * @param showSequenceLogo
999 public void setShowSequenceLogo(boolean showSequenceLogo)
1001 if (showSequenceLogo != this.showSequenceLogo)
1003 // TODO: decouple settings setting from calculation when refactoring
1004 // annotation update method from alignframe to viewport
1005 this.showSequenceLogo = showSequenceLogo;
1006 calculator.updateAnnotationFor(ConsensusThread.class);
1007 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1008 calculator.updateAnnotationFor(StrucConsensusThread.class);
1010 this.showSequenceLogo = showSequenceLogo;
1014 * @param showConsensusHistogram
1015 * the showConsensusHistogram to set
1017 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1019 this.showConsensusHistogram = showConsensusHistogram;
1023 * @return the showGroupConservation
1025 public boolean isShowGroupConservation()
1027 return showGroupConservation;
1031 * @param showGroupConservation
1032 * the showGroupConservation to set
1034 public void setShowGroupConservation(boolean showGroupConservation)
1036 this.showGroupConservation = showGroupConservation;
1040 * @return the showGroupConsensus
1042 public boolean isShowGroupConsensus()
1044 return showGroupConsensus;
1048 * @param showGroupConsensus
1049 * the showGroupConsensus to set
1051 public void setShowGroupConsensus(boolean showGroupConsensus)
1053 this.showGroupConsensus = showGroupConsensus;
1058 * @return flag to indicate if the consensus histogram should be rendered by
1062 public boolean isShowConsensusHistogram()
1064 return this.showConsensusHistogram;
1068 * when set, updateAlignment will always ensure sequences are of equal length
1070 private boolean padGaps = false;
1073 * when set, alignment should be reordered according to a newly opened tree
1075 public boolean sortByTree = false;
1080 * @return null or the currently selected sequence region
1083 public SequenceGroup getSelectionGroup()
1085 return selectionGroup;
1089 * Set the selection group for this window.
1092 * - group holding references to sequences in this alignment view
1096 public void setSelectionGroup(SequenceGroup sg)
1098 selectionGroup = sg;
1101 public void setHiddenColumns(ColumnSelection colsel)
1103 this.colSel = colsel;
1107 public ColumnSelection getColumnSelection()
1113 public void setColumnSelection(ColumnSelection colSel)
1115 this.colSel = colSel;
1118 updateHiddenColumns();
1120 isColSelChanged(true);
1128 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1130 return hiddenRepSequences;
1134 public void setHiddenRepSequences(
1135 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1137 this.hiddenRepSequences = hiddenRepSequences;
1141 public boolean hasSelectedColumns()
1143 ColumnSelection columnSelection = getColumnSelection();
1144 return columnSelection != null && columnSelection.hasSelectedColumns();
1148 public boolean hasHiddenColumns()
1150 return colSel != null && colSel.hasHiddenColumns();
1153 public void updateHiddenColumns()
1155 // this method doesn't really do anything now. But - it could, since a
1156 // column Selection could be in the process of modification
1157 // hasHiddenColumns = colSel.hasHiddenColumns();
1161 public boolean hasHiddenRows()
1163 return alignment.getHiddenSequences().getSize() > 0;
1166 protected SequenceGroup selectionGroup;
1168 public void setSequenceSetId(String newid)
1170 if (sequenceSetID != null)
1173 .println("Warning - overwriting a sequenceSetId for a viewport!");
1175 sequenceSetID = new String(newid);
1179 public String getSequenceSetId()
1181 if (sequenceSetID == null)
1183 sequenceSetID = alignment.hashCode() + "";
1186 return sequenceSetID;
1190 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1193 protected String viewId = null;
1196 public String getViewId()
1200 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1205 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1207 ignoreGapsInConsensusCalculation = b;
1210 updateConsensus(ap);
1211 if (globalColourScheme != null)
1213 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1214 ignoreGapsInConsensusCalculation);
1220 private long sgrouphash = -1, colselhash = -1;
1223 * checks current SelectionGroup against record of last hash value, and
1227 * update the record of last hash value
1229 * @return true if SelectionGroup changed since last call (when b is true)
1231 public boolean isSelectionGroupChanged(boolean b)
1233 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1234 : selectionGroup.hashCode();
1235 if (hc != -1 && hc != sgrouphash)
1247 * checks current colsel against record of last hash value, and optionally
1251 * update the record of last hash value
1252 * @return true if colsel changed since last call (when b is true)
1254 public boolean isColSelChanged(boolean b)
1256 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1257 if (hc != -1 && hc != colselhash)
1269 public boolean isIgnoreGapsConsensus()
1271 return ignoreGapsInConsensusCalculation;
1274 // property change stuff
1275 // JBPNote Prolly only need this in the applet version.
1276 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1279 protected boolean showConservation = true;
1281 protected boolean showQuality = true;
1283 protected boolean showConsensus = true;
1285 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1287 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1289 protected boolean showAutocalculatedAbove;
1292 * when set, view will scroll to show the highlighted position
1294 private boolean followHighlight = true;
1296 // TODO private with getters and setters?
1297 public int startRes;
1301 public int startSeq;
1306 * Property change listener for changes in alignment
1311 public void addPropertyChangeListener(
1312 java.beans.PropertyChangeListener listener)
1314 changeSupport.addPropertyChangeListener(listener);
1323 public void removePropertyChangeListener(
1324 java.beans.PropertyChangeListener listener)
1326 changeSupport.removePropertyChangeListener(listener);
1330 * Property change listener for changes in alignment
1339 public void firePropertyChange(String prop, Object oldvalue,
1342 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1345 // common hide/show column stuff
1347 public void hideSelectedColumns()
1349 if (colSel.isEmpty())
1354 colSel.hideSelectedColumns();
1355 setSelectionGroup(null);
1356 isColSelChanged(true);
1359 public void hideColumns(int start, int end)
1363 colSel.hideColumns(start);
1367 colSel.hideColumns(start, end);
1369 isColSelChanged(true);
1372 public void showColumn(int col)
1374 colSel.revealHiddenColumns(col);
1375 isColSelChanged(true);
1378 public void showAllHiddenColumns()
1380 colSel.revealAllHiddenColumns();
1381 isColSelChanged(true);
1384 // common hide/show seq stuff
1385 public void showAllHiddenSeqs()
1387 if (alignment.getHiddenSequences().getSize() > 0)
1389 if (selectionGroup == null)
1391 selectionGroup = new SequenceGroup();
1392 selectionGroup.setEndRes(alignment.getWidth() - 1);
1394 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1395 hiddenRepSequences);
1396 for (SequenceI seq : tmp)
1398 selectionGroup.addSequence(seq, false);
1399 setSequenceAnnotationsVisible(seq, true);
1402 hiddenRepSequences = null;
1404 firePropertyChange("alignment", null, alignment.getSequences());
1405 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1411 public void showSequence(int index)
1413 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1414 index, hiddenRepSequences);
1417 if (selectionGroup == null)
1419 selectionGroup = new SequenceGroup();
1420 selectionGroup.setEndRes(alignment.getWidth() - 1);
1423 for (SequenceI seq : tmp)
1425 selectionGroup.addSequence(seq, false);
1426 setSequenceAnnotationsVisible(seq, true);
1428 firePropertyChange("alignment", null, alignment.getSequences());
1433 public void hideAllSelectedSeqs()
1435 if (selectionGroup == null || selectionGroup.getSize() < 1)
1440 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1444 setSelectionGroup(null);
1447 public void hideSequence(SequenceI[] seq)
1451 for (int i = 0; i < seq.length; i++)
1453 alignment.getHiddenSequences().hideSequence(seq[i]);
1454 setSequenceAnnotationsVisible(seq[i], false);
1456 firePropertyChange("alignment", null, alignment.getSequences());
1461 * Hides the specified sequence, or the sequences it represents
1464 * the sequence to hide, or keep as representative
1465 * @param representGroup
1466 * if true, hide the current selection group except for the
1467 * representative sequence
1469 public void hideSequences(SequenceI sequence, boolean representGroup)
1471 if (selectionGroup == null || selectionGroup.getSize() < 1)
1473 hideSequence(new SequenceI[] { sequence });
1479 hideRepSequences(sequence, selectionGroup);
1480 setSelectionGroup(null);
1484 int gsize = selectionGroup.getSize();
1485 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1486 new SequenceI[gsize]);
1488 hideSequence(hseqs);
1489 setSelectionGroup(null);
1494 * Set visibility for any annotations for the given sequence.
1498 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1501 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1504 for (AlignmentAnnotation ann : anns)
1506 if (ann.sequenceRef == sequenceI)
1508 ann.visible = visible;
1514 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1516 int sSize = sg.getSize();
1522 if (hiddenRepSequences == null)
1524 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1527 hiddenRepSequences.put(repSequence, sg);
1529 // Hide all sequences except the repSequence
1530 SequenceI[] seqs = new SequenceI[sSize - 1];
1532 for (int i = 0; i < sSize; i++)
1534 if (sg.getSequenceAt(i) != repSequence)
1536 if (index == sSize - 1)
1541 seqs[index++] = sg.getSequenceAt(i);
1544 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1545 sg.setHidereps(true); // note: not done in 2.7applet
1552 * @return null or the current reference sequence
1554 public SequenceI getReferenceSeq()
1556 return alignment.getSeqrep();
1561 * @return true iff seq is the reference for the alignment
1563 public boolean isReferenceSeq(SequenceI seq)
1565 return alignment.getSeqrep() == seq;
1571 * @return true if there are sequences represented by this sequence that are
1574 public boolean isHiddenRepSequence(SequenceI seq)
1576 return (hiddenRepSequences != null && hiddenRepSequences
1583 * @return null or a sequence group containing the sequences that seq
1586 public SequenceGroup getRepresentedSequences(SequenceI seq)
1588 return (SequenceGroup) (hiddenRepSequences == null ? null
1589 : hiddenRepSequences.get(seq));
1593 public int adjustForHiddenSeqs(int alignmentIndex)
1595 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1600 public void invertColumnSelection()
1602 colSel.invertColumnSelection(0, alignment.getWidth());
1606 public SequenceI[] getSelectionAsNewSequence()
1608 SequenceI[] sequences;
1609 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1610 // this was the only caller in the applet for this method
1611 // JBPNote: in applet, this method returned references to the alignment
1612 // sequences, and it did not honour the presence/absence of annotation
1613 // attached to the alignment (probably!)
1614 if (selectionGroup == null || selectionGroup.getSize() == 0)
1616 sequences = alignment.getSequencesArray();
1617 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1618 for (int i = 0; i < sequences.length; i++)
1620 // construct new sequence with subset of visible annotation
1621 sequences[i] = new Sequence(sequences[i], annots);
1626 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1633 public SequenceI[] getSequenceSelection()
1635 SequenceI[] sequences = null;
1636 if (selectionGroup != null)
1638 sequences = selectionGroup.getSequencesInOrder(alignment);
1640 if (sequences == null)
1642 sequences = alignment.getSequencesArray();
1648 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1650 return new CigarArray(alignment, colSel,
1651 (selectedRegionOnly ? selectionGroup : null));
1655 public jalview.datamodel.AlignmentView getAlignmentView(
1656 boolean selectedOnly)
1658 return getAlignmentView(selectedOnly, false);
1662 public jalview.datamodel.AlignmentView getAlignmentView(
1663 boolean selectedOnly, boolean markGroups)
1665 return new AlignmentView(alignment, colSel, selectionGroup,
1666 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1671 public String[] getViewAsString(boolean selectedRegionOnly)
1673 return getViewAsString(selectedRegionOnly, true);
1677 public String[] getViewAsString(boolean selectedRegionOnly,
1678 boolean exportHiddenSeqs)
1680 String[] selection = null;
1681 SequenceI[] seqs = null;
1683 int start = 0, end = 0;
1684 if (selectedRegionOnly && selectionGroup != null)
1686 iSize = selectionGroup.getSize();
1687 seqs = selectionGroup.getSequencesInOrder(alignment);
1688 start = selectionGroup.getStartRes();
1689 end = selectionGroup.getEndRes() + 1;
1693 if (hasHiddenRows() && exportHiddenSeqs)
1695 AlignmentI fullAlignment = alignment.getHiddenSequences()
1696 .getFullAlignment();
1697 iSize = fullAlignment.getHeight();
1698 seqs = fullAlignment.getSequencesArray();
1699 end = fullAlignment.getWidth();
1703 iSize = alignment.getHeight();
1704 seqs = alignment.getSequencesArray();
1705 end = alignment.getWidth();
1709 selection = new String[iSize];
1710 if (colSel != null && colSel.hasHiddenColumns())
1712 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1716 for (i = 0; i < iSize; i++)
1718 selection[i] = seqs[i].getSequenceAsString(start, end);
1726 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1728 ArrayList<int[]> regions = new ArrayList<int[]>();
1734 if (colSel != null && colSel.hasHiddenColumns())
1738 start = colSel.adjustForHiddenColumns(start);
1741 end = colSel.getHiddenBoundaryRight(start);
1752 regions.add(new int[] { start, end });
1754 if (colSel != null && colSel.hasHiddenColumns())
1756 start = colSel.adjustForHiddenColumns(end);
1757 start = colSel.getHiddenBoundaryLeft(start) + 1;
1759 } while (end < max);
1761 int[][] startEnd = new int[regions.size()][2];
1767 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1768 boolean selectedOnly)
1770 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1771 AlignmentAnnotation[] aa;
1772 if ((aa = alignment.getAlignmentAnnotation()) != null)
1774 for (AlignmentAnnotation annot : aa)
1776 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1777 if (selectedOnly && selectionGroup != null)
1779 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1780 selectionGroup.getEndRes(), clone);
1784 colSel.makeVisibleAnnotation(clone);
1793 public boolean isPadGaps()
1799 public void setPadGaps(boolean padGaps)
1801 this.padGaps = padGaps;
1805 * apply any post-edit constraints and trigger any calculations needed after
1806 * an edit has been performed on the alignment
1811 public void alignmentChanged(AlignmentViewPanel ap)
1815 alignment.padGaps();
1817 if (autoCalculateConsensus)
1819 updateConsensus(ap);
1821 if (hconsensus != null && autoCalculateConsensus)
1823 updateConservation(ap);
1825 if (autoCalculateStrucConsensus)
1827 updateStrucConsensus(ap);
1830 // Reset endRes of groups if beyond alignment width
1831 int alWidth = alignment.getWidth();
1832 List<SequenceGroup> groups = alignment.getGroups();
1835 for (SequenceGroup sg : groups)
1837 if (sg.getEndRes() > alWidth)
1839 sg.setEndRes(alWidth - 1);
1844 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1846 selectionGroup.setEndRes(alWidth - 1);
1849 resetAllColourSchemes();
1850 calculator.restartWorkers();
1851 // alignment.adjustSequenceAnnotations();
1855 * reset scope and do calculations for all applied colourschemes on alignment
1857 void resetAllColourSchemes()
1859 ColourSchemeI cs = globalColourScheme;
1862 cs.alignmentChanged(alignment, hiddenRepSequences);
1864 cs.setConsensus(hconsensus);
1865 if (cs.conservationApplied())
1867 cs.setConservation(Conservation.calculateConservation("All", 3,
1868 alignment.getSequences(), 0, alignment.getWidth(), false,
1869 getConsPercGaps(), false));
1873 for (SequenceGroup sg : alignment.getGroups())
1877 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1879 sg.recalcConservation();
1883 protected void initAutoAnnotation()
1885 // TODO: add menu option action that nulls or creates consensus object
1886 // depending on if the user wants to see the annotation or not in a
1887 // specific alignment
1889 if (hconsensus == null && !isDataset)
1891 if (!alignment.isNucleotide())
1900 consensus = new AlignmentAnnotation("Consensus", "PID",
1901 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1902 initConsensus(consensus);
1904 initComplementConsensus();
1909 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1910 * consensus annotation.
1912 public void initComplementConsensus()
1914 if (!alignment.isNucleotide())
1916 final List<AlignedCodonFrame> codonMappings = alignment
1918 if (codonMappings != null && !codonMappings.isEmpty())
1920 boolean doConsensus = false;
1921 for (AlignedCodonFrame mapping : codonMappings)
1923 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1924 MapList[] mapLists = mapping.getdnaToProt();
1925 // mapLists can be empty if project load has not finished resolving
1927 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1935 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1936 "PID for cDNA", new Annotation[1], 0f, 100f,
1937 AlignmentAnnotation.BAR_GRAPH);
1938 initConsensus(complementConsensus);
1944 private void initConsensus(AlignmentAnnotation aa)
1947 aa.autoCalculated = true;
1951 alignment.addAnnotation(aa);
1955 private void initConservation()
1957 if (showConservation)
1959 if (conservation == null)
1961 conservation = new AlignmentAnnotation("Conservation",
1962 "Conservation of total alignment less than "
1963 + getConsPercGaps() + "% gaps", new Annotation[1],
1964 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1965 conservation.hasText = true;
1966 conservation.autoCalculated = true;
1967 alignment.addAnnotation(conservation);
1972 private void initQuality()
1976 if (quality == null)
1978 quality = new AlignmentAnnotation("Quality",
1979 "Alignment Quality based on Blosum62 scores",
1980 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1981 quality.hasText = true;
1982 quality.autoCalculated = true;
1983 alignment.addAnnotation(quality);
1988 private void initRNAStructure()
1990 if (alignment.hasRNAStructure() && strucConsensus == null)
1992 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1993 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1994 strucConsensus.hasText = true;
1995 strucConsensus.autoCalculated = true;
1999 alignment.addAnnotation(strucConsensus);
2007 * @see jalview.api.AlignViewportI#calcPanelHeight()
2010 public int calcPanelHeight()
2012 // setHeight of panels
2013 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2015 int charHeight = getCharHeight();
2018 BitSet graphgrp = new BitSet();
2019 for (AlignmentAnnotation aa : anns)
2023 System.err.println("Null annotation row: ignoring.");
2030 if (aa.graphGroup > -1)
2032 if (graphgrp.get(aa.graphGroup))
2038 graphgrp.set(aa.graphGroup);
2045 aa.height += charHeight;
2055 aa.height += aa.graphHeight;
2063 height += aa.height;
2075 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2076 boolean preserveNewGroupSettings)
2078 boolean updateCalcs = false;
2079 boolean conv = isShowGroupConservation();
2080 boolean cons = isShowGroupConsensus();
2081 boolean showprf = isShowSequenceLogo();
2082 boolean showConsHist = isShowConsensusHistogram();
2083 boolean normLogo = isNormaliseSequenceLogo();
2086 * TODO reorder the annotation rows according to group/sequence ordering on
2089 boolean sortg = true;
2091 // remove old automatic annotation
2092 // add any new annotation
2094 // intersect alignment annotation with alignment groups
2096 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2097 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2100 for (int an = 0; an < aan.length; an++)
2102 if (aan[an].autoCalculated && aan[an].groupRef != null)
2104 oldrfs.add(aan[an].groupRef);
2105 alignment.deleteAnnotation(aan[an], false);
2109 if (alignment.getGroups() != null)
2111 for (SequenceGroup sg : alignment.getGroups())
2113 updateCalcs = false;
2114 if (applyGlobalSettings
2115 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2117 // set defaults for this group's conservation/consensus
2118 sg.setshowSequenceLogo(showprf);
2119 sg.setShowConsensusHistogram(showConsHist);
2120 sg.setNormaliseSequenceLogo(normLogo);
2125 alignment.addAnnotation(sg.getConservationRow(), 0);
2130 alignment.addAnnotation(sg.getConsensus(), 0);
2132 // refresh the annotation rows
2135 sg.recalcConservation();
2143 public boolean isDisplayReferenceSeq()
2145 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2149 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2151 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2155 public boolean isColourByReferenceSeq()
2157 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2161 public Color getSequenceColour(SequenceI seq)
2163 Color sqc = sequenceColours.get(seq);
2164 return (sqc == null ? Color.white : sqc);
2168 public void setSequenceColour(SequenceI seq, Color col)
2172 sequenceColours.remove(seq);
2176 sequenceColours.put(seq, col);
2181 public void updateSequenceIdColours()
2183 for (SequenceGroup sg : alignment.getGroups())
2185 if (sg.idColour != null)
2187 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2189 sequenceColours.put(s, sg.idColour);
2196 public void clearSequenceColours()
2198 sequenceColours.clear();
2202 public AlignViewportI getCodingComplement()
2204 return this.codingComplement;
2208 * Set this as the (cDna/protein) complement of the given viewport. Also
2209 * ensures the reverse relationship is set on the given viewport.
2212 public void setCodingComplement(AlignViewportI av)
2216 System.err.println("Ignoring recursive setCodingComplement request");
2220 this.codingComplement = av;
2221 // avoid infinite recursion!
2222 if (av.getCodingComplement() != this)
2224 av.setCodingComplement(this);
2230 public boolean isNucleotide()
2232 return getAlignment() == null ? false : getAlignment().isNucleotide();
2236 public FeaturesDisplayedI getFeaturesDisplayed()
2238 return featuresDisplayed;
2242 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2244 featuresDisplayed = featuresDisplayedI;
2248 public boolean areFeaturesDisplayed()
2250 return featuresDisplayed != null
2251 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2258 * features are displayed if true
2261 public void setShowSequenceFeatures(boolean b)
2263 viewStyle.setShowSequenceFeatures(b);
2267 public boolean isShowSequenceFeatures()
2269 return viewStyle.isShowSequenceFeatures();
2273 public void setShowSequenceFeaturesHeight(boolean selected)
2275 viewStyle.setShowSequenceFeaturesHeight(selected);
2279 public boolean isShowSequenceFeaturesHeight()
2281 return viewStyle.isShowSequenceFeaturesHeight();
2285 public void setShowAnnotation(boolean b)
2287 viewStyle.setShowAnnotation(b);
2291 public boolean isShowAnnotation()
2293 return viewStyle.isShowAnnotation();
2297 public boolean isRightAlignIds()
2299 return viewStyle.isRightAlignIds();
2303 public void setRightAlignIds(boolean rightAlignIds)
2305 viewStyle.setRightAlignIds(rightAlignIds);
2309 public boolean getConservationSelected()
2311 return viewStyle.getConservationSelected();
2315 public void setShowBoxes(boolean state)
2317 viewStyle.setShowBoxes(state);
2322 * @see jalview.api.ViewStyleI#getTextColour()
2325 public Color getTextColour()
2327 return viewStyle.getTextColour();
2332 * @see jalview.api.ViewStyleI#getTextColour2()
2335 public Color getTextColour2()
2337 return viewStyle.getTextColour2();
2342 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2345 public int getThresholdTextColour()
2347 return viewStyle.getThresholdTextColour();
2352 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2355 public boolean isConservationColourSelected()
2357 return viewStyle.isConservationColourSelected();
2362 * @see jalview.api.ViewStyleI#isRenderGaps()
2365 public boolean isRenderGaps()
2367 return viewStyle.isRenderGaps();
2372 * @see jalview.api.ViewStyleI#isShowColourText()
2375 public boolean isShowColourText()
2377 return viewStyle.isShowColourText();
2381 * @param conservationColourSelected
2382 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2385 public void setConservationColourSelected(
2386 boolean conservationColourSelected)
2388 viewStyle.setConservationColourSelected(conservationColourSelected);
2392 * @param showColourText
2393 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2396 public void setShowColourText(boolean showColourText)
2398 viewStyle.setShowColourText(showColourText);
2403 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2406 public void setTextColour(Color textColour)
2408 viewStyle.setTextColour(textColour);
2412 * @param thresholdTextColour
2413 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2416 public void setThresholdTextColour(int thresholdTextColour)
2418 viewStyle.setThresholdTextColour(thresholdTextColour);
2422 * @param textColour2
2423 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2426 public void setTextColour2(Color textColour2)
2428 viewStyle.setTextColour2(textColour2);
2432 public ViewStyleI getViewStyle()
2434 return new ViewStyle(viewStyle);
2438 public void setViewStyle(ViewStyleI settingsForView)
2440 viewStyle = new ViewStyle(settingsForView);
2444 public boolean sameStyle(ViewStyleI them)
2446 return viewStyle.sameStyle(them);
2451 * @see jalview.api.ViewStyleI#getIdWidth()
2454 public int getIdWidth()
2456 return viewStyle.getIdWidth();
2461 * @see jalview.api.ViewStyleI#setIdWidth(int)
2464 public void setIdWidth(int i)
2466 viewStyle.setIdWidth(i);
2471 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2474 public boolean isCentreColumnLabels()
2476 return viewStyle.isCentreColumnLabels();
2480 * @param centreColumnLabels
2481 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2484 public void setCentreColumnLabels(boolean centreColumnLabels)
2486 viewStyle.setCentreColumnLabels(centreColumnLabels);
2491 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2494 public void setShowDBRefs(boolean showdbrefs)
2496 viewStyle.setShowDBRefs(showdbrefs);
2501 * @see jalview.api.ViewStyleI#isShowDBRefs()
2504 public boolean isShowDBRefs()
2506 return viewStyle.isShowDBRefs();
2511 * @see jalview.api.ViewStyleI#isShowNPFeats()
2514 public boolean isShowNPFeats()
2516 return viewStyle.isShowNPFeats();
2520 * @param shownpfeats
2521 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2524 public void setShowNPFeats(boolean shownpfeats)
2526 viewStyle.setShowNPFeats(shownpfeats);
2529 public abstract StructureSelectionManager getStructureSelectionManager();
2532 * Add one command to the command history list.
2536 public void addToHistoryList(CommandI command)
2538 if (this.historyList != null)
2540 this.historyList.push(command);
2541 broadcastCommand(command, false);
2545 protected void broadcastCommand(CommandI command, boolean undo)
2547 getStructureSelectionManager().commandPerformed(command, undo,
2552 * Add one command to the command redo list.
2556 public void addToRedoList(CommandI command)
2558 if (this.redoList != null)
2560 this.redoList.push(command);
2562 broadcastCommand(command, true);
2566 * Clear the command redo list.
2568 public void clearRedoList()
2570 if (this.redoList != null)
2572 this.redoList.clear();
2576 public void setHistoryList(Deque<CommandI> list)
2578 this.historyList = list;
2581 public Deque<CommandI> getHistoryList()
2583 return this.historyList;
2586 public void setRedoList(Deque<CommandI> list)
2588 this.redoList = list;
2591 public Deque<CommandI> getRedoList()
2593 return this.redoList;
2597 public VamsasSource getVamsasSource()
2602 public SequenceAnnotationOrder getSortAnnotationsBy()
2604 return sortAnnotationsBy;
2607 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2609 this.sortAnnotationsBy = sortAnnotationsBy;
2612 public boolean isShowAutocalculatedAbove()
2614 return showAutocalculatedAbove;
2617 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2619 this.showAutocalculatedAbove = showAutocalculatedAbove;
2623 public boolean isScaleProteinAsCdna()
2625 return viewStyle.isScaleProteinAsCdna();
2629 public void setScaleProteinAsCdna(boolean b)
2631 viewStyle.setScaleProteinAsCdna(b);
2635 * @return true if view should scroll to show the highlighted region of a
2640 public final boolean isFollowHighlight()
2642 return followHighlight;
2646 public final void setFollowHighlight(boolean b)
2648 this.followHighlight = b;
2651 public int getStartRes()
2657 public int getEndRes()
2662 public int getStartSeq()
2667 public void setStartRes(int res)
2669 this.startRes = res;
2672 public void setStartSeq(int seq)
2674 this.startSeq = seq;
2677 public void setEndRes(int res)
2679 if (res > alignment.getWidth() - 1)
2681 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2682 // (alignment.getWidth()-1));
2683 res = alignment.getWidth() - 1;
2692 public void setEndSeq(int seq)
2694 if (seq > alignment.getHeight())
2696 seq = alignment.getHeight();
2705 public int getEndSeq()
2711 * Helper method to populate the SearchResults with the location in the
2712 * complementary alignment to scroll to, in order to match this one.
2715 * the SearchResults to add to
2716 * @return the offset (below top of visible region) of the matched sequence
2718 protected int findComplementScrollTarget(SearchResultsI sr)
2720 final AlignViewportI complement = getCodingComplement();
2721 if (complement == null || !complement.isFollowHighlight())
2725 boolean iAmProtein = !getAlignment().isNucleotide();
2726 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2728 if (proteinAlignment == null)
2732 final List<AlignedCodonFrame> mappings = proteinAlignment
2736 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2737 * residue in the middle column of the visible region. Scroll the
2738 * complementary alignment to line up the corresponding residue.
2741 SequenceI sequence = null;
2744 * locate 'middle' column (true middle if an odd number visible, left of
2745 * middle if an even number visible)
2747 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2748 final HiddenSequences hiddenSequences = getAlignment()
2749 .getHiddenSequences();
2752 * searching to the bottom of the alignment gives smoother scrolling across
2753 * all gapped visible regions
2755 int lastSeq = alignment.getHeight() - 1;
2756 List<AlignedCodonFrame> seqMappings = null;
2757 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2759 sequence = getAlignment().getSequenceAt(seqNo);
2760 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2764 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2768 seqMappings = MappingUtils
2769 .findMappingsForSequenceAndOthers(sequence, mappings,
2770 getCodingComplement().getAlignment().getSequences());
2771 if (!seqMappings.isEmpty())
2777 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2780 * No ungapped mapped sequence in middle column - do nothing
2784 MappingUtils.addSearchResults(sr, sequence,
2785 sequence.findPosition(middleColumn), seqMappings);
2790 * synthesize a column selection if none exists so it covers the given
2791 * selection group. if wholewidth is false, no column selection is made if the
2792 * selection group covers the whole alignment width.
2797 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2800 if (sg != null && (sgs = sg.getStartRes()) >= 0
2801 && sg.getStartRes() <= (sge = sg.getEndRes())
2802 && !this.hasSelectedColumns())
2804 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2811 colSel = new ColumnSelection();
2813 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2815 colSel.addElement(cspos);
2821 * hold status of current selection group - defined on alignment or not.
2823 private boolean selectionIsDefinedGroup = false;
2827 public boolean isSelectionDefinedGroup()
2829 if (selectionGroup == null)
2833 if (isSelectionGroupChanged(true))
2835 selectionIsDefinedGroup = false;
2836 List<SequenceGroup> gps = alignment.getGroups();
2837 if (gps == null || gps.size() == 0)
2839 selectionIsDefinedGroup = false;
2843 selectionIsDefinedGroup = gps.contains(selectionGroup);
2846 return selectionGroup.getContext() == alignment
2847 || selectionIsDefinedGroup;
2851 * null, or currently highlighted results on this view
2853 private SearchResultsI searchResults = null;
2856 public boolean hasSearchResults()
2858 return searchResults != null;
2862 public void setSearchResults(SearchResultsI results)
2864 searchResults = results;
2868 public SearchResultsI getSearchResults()
2870 return searchResults;