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.renderer.ResidueShader;
46 import jalview.renderer.ResidueShaderI;
47 import jalview.schemes.ColourSchemeI;
48 import jalview.structure.CommandListener;
49 import jalview.structure.StructureSelectionManager;
50 import jalview.structure.VamsasSource;
51 import jalview.util.Comparison;
52 import jalview.util.MapList;
53 import jalview.util.MappingUtils;
54 import jalview.viewmodel.styles.ViewStyle;
55 import jalview.workers.AlignCalcManager;
56 import jalview.workers.ComplementConsensusThread;
57 import jalview.workers.ConsensusThread;
58 import jalview.workers.StrucConsensusThread;
60 import java.awt.Color;
61 import java.beans.PropertyChangeSupport;
62 import java.util.ArrayDeque;
63 import java.util.ArrayList;
64 import java.util.BitSet;
65 import java.util.Deque;
66 import java.util.HashMap;
67 import java.util.Hashtable;
68 import java.util.List;
72 * base class holding visualization and analysis attributes and common logic for
73 * an active alignment view displayed in the GUI
78 public abstract class AlignmentViewport implements AlignViewportI,
79 CommandListener, VamsasSource
81 protected ViewportPositionProps posProps;
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 ResidueShaderI residueShading;
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 the 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 alignment colouring once, thereafter update it;
617 * this means that any conservation or PID threshold settings
618 * persist when the alignment colour scheme is changed
620 if (residueShading == null)
622 residueShading = new ResidueShader(viewStyle);
624 residueShading.setColourScheme(cs);
626 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
627 // ...problem: groups need these, but do not currently have a ViewStyle
631 if (getConservationSelected())
633 residueShading.setConservation(hconservation);
635 residueShading.alignmentChanged(alignment, hiddenRepSequences);
639 * if 'apply colour to all groups' is selected... do so
640 * (but don't transfer any colour threshold settings to groups)
642 if (getColourAppliesToAllGroups())
644 for (SequenceGroup sg : getAlignment().getGroups())
647 * retain any colour thresholds per group while
648 * changing choice of colour scheme (JAL-2386)
650 sg.setColourScheme(cs);
653 sg.getGroupColourScheme()
654 .alignmentChanged(sg, hiddenRepSequences);
661 public ColourSchemeI getGlobalColourScheme()
663 return residueShading == null ? null : residueShading
668 public ResidueShaderI getResidueShading()
670 return residueShading;
673 protected AlignmentAnnotation consensus;
675 protected AlignmentAnnotation complementConsensus;
677 protected AlignmentAnnotation strucConsensus;
679 protected AlignmentAnnotation conservation;
681 protected AlignmentAnnotation quality;
683 protected AlignmentAnnotation[] groupConsensus;
685 protected AlignmentAnnotation[] groupConservation;
688 * results of alignment consensus analysis for visible portion of view
690 protected ProfilesI hconsensus = null;
693 * results of cDNA complement consensus visible portion of view
695 protected Hashtable[] hcomplementConsensus = null;
698 * results of secondary structure base pair consensus for visible portion of
701 protected Hashtable[] hStrucConsensus = null;
703 protected Conservation hconservation = null;
706 public void setConservation(Conservation cons)
708 hconservation = cons;
712 * percentage gaps allowed in a column before all amino acid properties should
713 * be considered unconserved
715 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
718 public int getConsPercGaps()
724 public void setSequenceConsensusHash(ProfilesI hconsensus)
726 this.hconsensus = hconsensus;
730 public void setComplementConsensusHash(Hashtable[] hconsensus)
732 this.hcomplementConsensus = hconsensus;
736 public ProfilesI getSequenceConsensusHash()
742 public Hashtable[] getComplementConsensusHash()
744 return hcomplementConsensus;
748 public Hashtable[] getRnaStructureConsensusHash()
750 return hStrucConsensus;
754 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
756 this.hStrucConsensus = hStrucConsensus;
761 public AlignmentAnnotation getAlignmentQualityAnnot()
767 public AlignmentAnnotation getAlignmentConservationAnnotation()
773 public AlignmentAnnotation getAlignmentConsensusAnnotation()
779 public AlignmentAnnotation getComplementConsensusAnnotation()
781 return complementConsensus;
785 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
787 return strucConsensus;
790 protected AlignCalcManagerI calculator = new AlignCalcManager();
793 * trigger update of conservation annotation
795 public void updateConservation(final AlignmentViewPanel ap)
797 // see note in mantis : issue number 8585
798 if (alignment.isNucleotide()
799 || (conservation == null && quality == null)
800 || !autoCalculateConsensus)
805 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
807 calculator.registerWorker(new jalview.workers.ConservationThread(
813 * trigger update of consensus annotation
815 public void updateConsensus(final AlignmentViewPanel ap)
817 // see note in mantis : issue number 8585
818 if (consensus == null || !autoCalculateConsensus)
822 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
824 calculator.registerWorker(new ConsensusThread(this, ap));
828 * A separate thread to compute cDNA consensus for a protein alignment
829 * which has mapping to cDNA
831 final AlignmentI al = this.getAlignment();
832 if (!al.isNucleotide() && al.getCodonFrames() != null
833 && !al.getCodonFrames().isEmpty())
836 * fudge - check first for protein-to-nucleotide mappings
837 * (we don't want to do this for protein-to-protein)
839 boolean doConsensus = false;
840 for (AlignedCodonFrame mapping : al.getCodonFrames())
842 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
843 MapList[] mapLists = mapping.getdnaToProt();
844 // mapLists can be empty if project load has not finished resolving seqs
845 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
854 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
857 .registerWorker(new ComplementConsensusThread(this, ap));
863 // --------START Structure Conservation
864 public void updateStrucConsensus(final AlignmentViewPanel ap)
866 if (autoCalculateStrucConsensus && strucConsensus == null
867 && alignment.isNucleotide() && alignment.hasRNAStructure())
869 // secondary structure has been added - so init the consensus line
873 // see note in mantis : issue number 8585
874 if (strucConsensus == null || !autoCalculateStrucConsensus)
878 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
880 calculator.registerWorker(new StrucConsensusThread(this, ap));
884 public boolean isCalcInProgress()
886 return calculator.isWorking();
890 public boolean isCalculationInProgress(
891 AlignmentAnnotation alignmentAnnotation)
893 if (!alignmentAnnotation.autoCalculated)
897 if (calculator.workingInvolvedWith(alignmentAnnotation))
899 // System.err.println("grey out ("+alignmentAnnotation.label+")");
905 public void setAlignment(AlignmentI align)
907 this.alignment = align;
911 * Clean up references when this viewport is closed
914 public void dispose()
917 * defensively null out references to large objects in case
918 * this object is not garbage collected (as if!)
921 complementConsensus = null;
922 strucConsensus = null;
925 groupConsensus = null;
926 groupConservation = null;
928 hcomplementConsensus = null;
929 // colour scheme may hold reference to consensus
930 residueShading = null;
931 // TODO remove listeners from changeSupport?
932 changeSupport = null;
937 public boolean isClosed()
939 // TODO: check that this isClosed is only true after panel is closed, not
940 // before it is fully constructed.
941 return alignment == null;
945 public AlignCalcManagerI getCalcManager()
951 * should conservation rows be shown for groups
953 protected boolean showGroupConservation = false;
956 * should consensus rows be shown for groups
958 protected boolean showGroupConsensus = false;
961 * should consensus profile be rendered by default
963 protected boolean showSequenceLogo = false;
966 * should consensus profile be rendered normalised to row height
968 protected boolean normaliseSequenceLogo = false;
971 * should consensus histograms be rendered by default
973 protected boolean showConsensusHistogram = true;
976 * @return the showConsensusProfile
979 public boolean isShowSequenceLogo()
981 return showSequenceLogo;
985 * @param showSequenceLogo
988 public void setShowSequenceLogo(boolean showSequenceLogo)
990 if (showSequenceLogo != this.showSequenceLogo)
992 // TODO: decouple settings setting from calculation when refactoring
993 // annotation update method from alignframe to viewport
994 this.showSequenceLogo = showSequenceLogo;
995 calculator.updateAnnotationFor(ConsensusThread.class);
996 calculator.updateAnnotationFor(ComplementConsensusThread.class);
997 calculator.updateAnnotationFor(StrucConsensusThread.class);
999 this.showSequenceLogo = showSequenceLogo;
1003 * @param showConsensusHistogram
1004 * the showConsensusHistogram to set
1006 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1008 this.showConsensusHistogram = showConsensusHistogram;
1012 * @return the showGroupConservation
1014 public boolean isShowGroupConservation()
1016 return showGroupConservation;
1020 * @param showGroupConservation
1021 * the showGroupConservation to set
1023 public void setShowGroupConservation(boolean showGroupConservation)
1025 this.showGroupConservation = showGroupConservation;
1029 * @return the showGroupConsensus
1031 public boolean isShowGroupConsensus()
1033 return showGroupConsensus;
1037 * @param showGroupConsensus
1038 * the showGroupConsensus to set
1040 public void setShowGroupConsensus(boolean showGroupConsensus)
1042 this.showGroupConsensus = showGroupConsensus;
1047 * @return flag to indicate if the consensus histogram should be rendered by
1051 public boolean isShowConsensusHistogram()
1053 return this.showConsensusHistogram;
1057 * when set, updateAlignment will always ensure sequences are of equal length
1059 private boolean padGaps = false;
1062 * when set, alignment should be reordered according to a newly opened tree
1064 public boolean sortByTree = false;
1069 * @return null or the currently selected sequence region
1072 public SequenceGroup getSelectionGroup()
1074 return selectionGroup;
1078 * Set the selection group for this window. Also sets the current alignment as
1079 * the context for the group, if it does not already have one.
1082 * - group holding references to sequences in this alignment view
1086 public void setSelectionGroup(SequenceGroup sg)
1088 selectionGroup = sg;
1089 if (sg != null && sg.getContext() == null)
1091 sg.setContext(alignment);
1095 public void setHiddenColumns(ColumnSelection colsel)
1097 this.colSel = colsel;
1101 public ColumnSelection getColumnSelection()
1107 public void setColumnSelection(ColumnSelection colSel)
1109 this.colSel = colSel;
1112 updateHiddenColumns();
1114 isColSelChanged(true);
1122 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1124 return hiddenRepSequences;
1128 public void setHiddenRepSequences(
1129 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1131 this.hiddenRepSequences = hiddenRepSequences;
1135 public boolean hasSelectedColumns()
1137 ColumnSelection columnSelection = getColumnSelection();
1138 return columnSelection != null && columnSelection.hasSelectedColumns();
1142 public boolean hasHiddenColumns()
1144 return colSel != null && colSel.hasHiddenColumns();
1147 public void updateHiddenColumns()
1149 // this method doesn't really do anything now. But - it could, since a
1150 // column Selection could be in the process of modification
1151 // hasHiddenColumns = colSel.hasHiddenColumns();
1155 public boolean hasHiddenRows()
1157 return alignment.getHiddenSequences().getSize() > 0;
1160 protected SequenceGroup selectionGroup;
1162 public void setSequenceSetId(String newid)
1164 if (sequenceSetID != null)
1167 .println("Warning - overwriting a sequenceSetId for a viewport!");
1169 sequenceSetID = new String(newid);
1173 public String getSequenceSetId()
1175 if (sequenceSetID == null)
1177 sequenceSetID = alignment.hashCode() + "";
1180 return sequenceSetID;
1184 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1187 protected String viewId = null;
1190 public String getViewId()
1194 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1199 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1201 ignoreGapsInConsensusCalculation = b;
1204 updateConsensus(ap);
1205 if (residueShading != null)
1207 residueShading.setThreshold(residueShading.getThreshold(),
1208 ignoreGapsInConsensusCalculation);
1214 private long sgrouphash = -1, colselhash = -1;
1217 * checks current SelectionGroup against record of last hash value, and
1221 * update the record of last hash value
1223 * @return true if SelectionGroup changed since last call (when b is true)
1225 public boolean isSelectionGroupChanged(boolean b)
1227 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1228 : selectionGroup.hashCode();
1229 if (hc != -1 && hc != sgrouphash)
1241 * checks current colsel against record of last hash value, and optionally
1245 * update the record of last hash value
1246 * @return true if colsel changed since last call (when b is true)
1248 public boolean isColSelChanged(boolean b)
1250 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1251 if (hc != -1 && hc != colselhash)
1263 public boolean isIgnoreGapsConsensus()
1265 return ignoreGapsInConsensusCalculation;
1268 // property change stuff
1269 // JBPNote Prolly only need this in the applet version.
1270 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1273 protected boolean showConservation = true;
1275 protected boolean showQuality = true;
1277 protected boolean showConsensus = true;
1279 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1281 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1283 protected boolean showAutocalculatedAbove;
1286 * when set, view will scroll to show the highlighted position
1288 private boolean followHighlight = true;
1290 /*private int startRes;
1294 private int startSeq;
1296 private int endSeq;*/
1299 * Property change listener for changes in alignment
1304 public void addPropertyChangeListener(
1305 java.beans.PropertyChangeListener listener)
1307 changeSupport.addPropertyChangeListener(listener);
1316 public void removePropertyChangeListener(
1317 java.beans.PropertyChangeListener listener)
1319 changeSupport.removePropertyChangeListener(listener);
1323 * Property change listener for changes in alignment
1332 public void firePropertyChange(String prop, Object oldvalue,
1335 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1338 // common hide/show column stuff
1340 public void hideSelectedColumns()
1342 if (colSel.isEmpty())
1347 colSel.hideSelectedColumns();
1348 setSelectionGroup(null);
1349 isColSelChanged(true);
1352 public void hideColumns(int start, int end)
1356 colSel.hideColumns(start);
1360 colSel.hideColumns(start, end);
1362 isColSelChanged(true);
1365 public void showColumn(int col)
1367 colSel.revealHiddenColumns(col);
1368 isColSelChanged(true);
1371 public void showAllHiddenColumns()
1373 colSel.revealAllHiddenColumns();
1374 isColSelChanged(true);
1377 // common hide/show seq stuff
1378 public void showAllHiddenSeqs()
1380 if (alignment.getHiddenSequences().getSize() > 0)
1382 if (selectionGroup == null)
1384 selectionGroup = new SequenceGroup();
1385 selectionGroup.setEndRes(alignment.getWidth() - 1);
1387 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1388 hiddenRepSequences);
1389 for (SequenceI seq : tmp)
1391 selectionGroup.addSequence(seq, false);
1392 setSequenceAnnotationsVisible(seq, true);
1395 hiddenRepSequences = null;
1397 firePropertyChange("alignment", null, alignment.getSequences());
1398 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1404 public void showSequence(int index)
1406 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1407 index, hiddenRepSequences);
1410 if (selectionGroup == null)
1412 selectionGroup = new SequenceGroup();
1413 selectionGroup.setEndRes(alignment.getWidth() - 1);
1416 for (SequenceI seq : tmp)
1418 selectionGroup.addSequence(seq, false);
1419 setSequenceAnnotationsVisible(seq, true);
1421 firePropertyChange("alignment", null, alignment.getSequences());
1426 public void hideAllSelectedSeqs()
1428 if (selectionGroup == null || selectionGroup.getSize() < 1)
1433 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1437 setSelectionGroup(null);
1440 public void hideSequence(SequenceI[] seq)
1444 for (int i = 0; i < seq.length; i++)
1446 alignment.getHiddenSequences().hideSequence(seq[i]);
1447 setSequenceAnnotationsVisible(seq[i], false);
1449 firePropertyChange("alignment", null, alignment.getSequences());
1454 * Hides the specified sequence, or the sequences it represents
1457 * the sequence to hide, or keep as representative
1458 * @param representGroup
1459 * if true, hide the current selection group except for the
1460 * representative sequence
1462 public void hideSequences(SequenceI sequence, boolean representGroup)
1464 if (selectionGroup == null || selectionGroup.getSize() < 1)
1466 hideSequence(new SequenceI[] { sequence });
1472 hideRepSequences(sequence, selectionGroup);
1473 setSelectionGroup(null);
1477 int gsize = selectionGroup.getSize();
1478 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1479 new SequenceI[gsize]);
1481 hideSequence(hseqs);
1482 setSelectionGroup(null);
1487 * Set visibility for any annotations for the given sequence.
1491 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1494 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1497 for (AlignmentAnnotation ann : anns)
1499 if (ann.sequenceRef == sequenceI)
1501 ann.visible = visible;
1507 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1509 int sSize = sg.getSize();
1515 if (hiddenRepSequences == null)
1517 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1520 hiddenRepSequences.put(repSequence, sg);
1522 // Hide all sequences except the repSequence
1523 SequenceI[] seqs = new SequenceI[sSize - 1];
1525 for (int i = 0; i < sSize; i++)
1527 if (sg.getSequenceAt(i) != repSequence)
1529 if (index == sSize - 1)
1534 seqs[index++] = sg.getSequenceAt(i);
1537 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1538 sg.setHidereps(true); // note: not done in 2.7applet
1545 * @return null or the current reference sequence
1547 public SequenceI getReferenceSeq()
1549 return alignment.getSeqrep();
1554 * @return true iff seq is the reference for the alignment
1556 public boolean isReferenceSeq(SequenceI seq)
1558 return alignment.getSeqrep() == seq;
1564 * @return true if there are sequences represented by this sequence that are
1567 public boolean isHiddenRepSequence(SequenceI seq)
1569 return (hiddenRepSequences != null && hiddenRepSequences
1576 * @return null or a sequence group containing the sequences that seq
1579 public SequenceGroup getRepresentedSequences(SequenceI seq)
1581 return (SequenceGroup) (hiddenRepSequences == null ? null
1582 : hiddenRepSequences.get(seq));
1586 public int adjustForHiddenSeqs(int alignmentIndex)
1588 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1593 public void invertColumnSelection()
1595 colSel.invertColumnSelection(0, alignment.getWidth());
1599 public SequenceI[] getSelectionAsNewSequence()
1601 SequenceI[] sequences;
1602 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1603 // this was the only caller in the applet for this method
1604 // JBPNote: in applet, this method returned references to the alignment
1605 // sequences, and it did not honour the presence/absence of annotation
1606 // attached to the alignment (probably!)
1607 if (selectionGroup == null || selectionGroup.getSize() == 0)
1609 sequences = alignment.getSequencesArray();
1610 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1611 for (int i = 0; i < sequences.length; i++)
1613 // construct new sequence with subset of visible annotation
1614 sequences[i] = new Sequence(sequences[i], annots);
1619 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1626 public SequenceI[] getSequenceSelection()
1628 SequenceI[] sequences = null;
1629 if (selectionGroup != null)
1631 sequences = selectionGroup.getSequencesInOrder(alignment);
1633 if (sequences == null)
1635 sequences = alignment.getSequencesArray();
1641 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1643 return new CigarArray(alignment, colSel,
1644 (selectedRegionOnly ? selectionGroup : null));
1648 public jalview.datamodel.AlignmentView getAlignmentView(
1649 boolean selectedOnly)
1651 return getAlignmentView(selectedOnly, false);
1655 public jalview.datamodel.AlignmentView getAlignmentView(
1656 boolean selectedOnly, boolean markGroups)
1658 return new AlignmentView(alignment, colSel, selectionGroup,
1659 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1664 public String[] getViewAsString(boolean selectedRegionOnly)
1666 return getViewAsString(selectedRegionOnly, true);
1670 public String[] getViewAsString(boolean selectedRegionOnly,
1671 boolean exportHiddenSeqs)
1673 String[] selection = null;
1674 SequenceI[] seqs = null;
1676 int start = 0, end = 0;
1677 if (selectedRegionOnly && selectionGroup != null)
1679 iSize = selectionGroup.getSize();
1680 seqs = selectionGroup.getSequencesInOrder(alignment);
1681 start = selectionGroup.getStartRes();
1682 end = selectionGroup.getEndRes() + 1;
1686 if (hasHiddenRows() && exportHiddenSeqs)
1688 AlignmentI fullAlignment = alignment.getHiddenSequences()
1689 .getFullAlignment();
1690 iSize = fullAlignment.getHeight();
1691 seqs = fullAlignment.getSequencesArray();
1692 end = fullAlignment.getWidth();
1696 iSize = alignment.getHeight();
1697 seqs = alignment.getSequencesArray();
1698 end = alignment.getWidth();
1702 selection = new String[iSize];
1703 if (colSel != null && colSel.hasHiddenColumns())
1705 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1709 for (i = 0; i < iSize; i++)
1711 selection[i] = seqs[i].getSequenceAsString(start, end);
1719 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1721 ArrayList<int[]> regions = new ArrayList<int[]>();
1727 if (colSel != null && colSel.hasHiddenColumns())
1731 start = colSel.adjustForHiddenColumns(start);
1734 end = colSel.getHiddenBoundaryRight(start);
1745 regions.add(new int[] { start, end });
1747 if (colSel != null && colSel.hasHiddenColumns())
1749 start = colSel.adjustForHiddenColumns(end);
1750 start = colSel.getHiddenBoundaryLeft(start) + 1;
1752 } while (end < max);
1754 int[][] startEnd = new int[regions.size()][2];
1760 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1761 boolean selectedOnly)
1763 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1764 AlignmentAnnotation[] aa;
1765 if ((aa = alignment.getAlignmentAnnotation()) != null)
1767 for (AlignmentAnnotation annot : aa)
1769 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1770 if (selectedOnly && selectionGroup != null)
1772 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1773 selectionGroup.getEndRes(), clone);
1777 colSel.makeVisibleAnnotation(clone);
1786 public boolean isPadGaps()
1792 public void setPadGaps(boolean padGaps)
1794 this.padGaps = padGaps;
1798 * apply any post-edit constraints and trigger any calculations needed after
1799 * an edit has been performed on the alignment
1804 public void alignmentChanged(AlignmentViewPanel ap)
1808 alignment.padGaps();
1810 if (autoCalculateConsensus)
1812 updateConsensus(ap);
1814 if (hconsensus != null && autoCalculateConsensus)
1816 updateConservation(ap);
1818 if (autoCalculateStrucConsensus)
1820 updateStrucConsensus(ap);
1823 // Reset endRes of groups if beyond alignment width
1824 int alWidth = alignment.getWidth();
1825 List<SequenceGroup> groups = alignment.getGroups();
1828 for (SequenceGroup sg : groups)
1830 if (sg.getEndRes() > alWidth)
1832 sg.setEndRes(alWidth - 1);
1837 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1839 selectionGroup.setEndRes(alWidth - 1);
1842 updateAllColourSchemes();
1843 calculator.restartWorkers();
1844 // alignment.adjustSequenceAnnotations();
1848 * reset scope and do calculations for all applied colourschemes on alignment
1850 void updateAllColourSchemes()
1852 ResidueShaderI rs = residueShading;
1855 rs.alignmentChanged(alignment, hiddenRepSequences);
1857 rs.setConsensus(hconsensus);
1858 if (rs.conservationApplied())
1860 rs.setConservation(Conservation.calculateConservation("All",
1861 alignment.getSequences(), 0, alignment.getWidth(), false,
1862 getConsPercGaps(), false));
1866 for (SequenceGroup sg : alignment.getGroups())
1870 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1872 sg.recalcConservation();
1876 protected void initAutoAnnotation()
1878 // TODO: add menu option action that nulls or creates consensus object
1879 // depending on if the user wants to see the annotation or not in a
1880 // specific alignment
1882 if (hconsensus == null && !isDataset)
1884 if (!alignment.isNucleotide())
1893 consensus = new AlignmentAnnotation("Consensus", "PID",
1894 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1895 initConsensus(consensus);
1897 initComplementConsensus();
1902 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1903 * consensus annotation.
1905 public void initComplementConsensus()
1907 if (!alignment.isNucleotide())
1909 final List<AlignedCodonFrame> codonMappings = alignment
1911 if (codonMappings != null && !codonMappings.isEmpty())
1913 boolean doConsensus = false;
1914 for (AlignedCodonFrame mapping : codonMappings)
1916 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1917 MapList[] mapLists = mapping.getdnaToProt();
1918 // mapLists can be empty if project load has not finished resolving
1920 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1928 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1929 "PID for cDNA", new Annotation[1], 0f, 100f,
1930 AlignmentAnnotation.BAR_GRAPH);
1931 initConsensus(complementConsensus);
1937 private void initConsensus(AlignmentAnnotation aa)
1940 aa.autoCalculated = true;
1944 alignment.addAnnotation(aa);
1948 private void initConservation()
1950 if (showConservation)
1952 if (conservation == null)
1954 conservation = new AlignmentAnnotation("Conservation",
1955 "Conservation of total alignment less than "
1956 + getConsPercGaps() + "% gaps", new Annotation[1],
1957 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1958 conservation.hasText = true;
1959 conservation.autoCalculated = true;
1960 alignment.addAnnotation(conservation);
1965 private void initQuality()
1969 if (quality == null)
1971 quality = new AlignmentAnnotation("Quality",
1972 "Alignment Quality based on Blosum62 scores",
1973 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1974 quality.hasText = true;
1975 quality.autoCalculated = true;
1976 alignment.addAnnotation(quality);
1981 private void initRNAStructure()
1983 if (alignment.hasRNAStructure() && strucConsensus == null)
1985 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1986 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1987 strucConsensus.hasText = true;
1988 strucConsensus.autoCalculated = true;
1992 alignment.addAnnotation(strucConsensus);
2000 * @see jalview.api.AlignViewportI#calcPanelHeight()
2003 public int calcPanelHeight()
2005 // setHeight of panels
2006 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2008 int charHeight = getCharHeight();
2011 BitSet graphgrp = new BitSet();
2012 for (AlignmentAnnotation aa : anns)
2016 System.err.println("Null annotation row: ignoring.");
2023 if (aa.graphGroup > -1)
2025 if (graphgrp.get(aa.graphGroup))
2031 graphgrp.set(aa.graphGroup);
2038 aa.height += charHeight;
2048 aa.height += aa.graphHeight;
2056 height += aa.height;
2068 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2069 boolean preserveNewGroupSettings)
2071 boolean updateCalcs = false;
2072 boolean conv = isShowGroupConservation();
2073 boolean cons = isShowGroupConsensus();
2074 boolean showprf = isShowSequenceLogo();
2075 boolean showConsHist = isShowConsensusHistogram();
2076 boolean normLogo = isNormaliseSequenceLogo();
2079 * TODO reorder the annotation rows according to group/sequence ordering on
2082 boolean sortg = true;
2084 // remove old automatic annotation
2085 // add any new annotation
2087 // intersect alignment annotation with alignment groups
2089 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2090 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2093 for (int an = 0; an < aan.length; an++)
2095 if (aan[an].autoCalculated && aan[an].groupRef != null)
2097 oldrfs.add(aan[an].groupRef);
2098 alignment.deleteAnnotation(aan[an], false);
2102 if (alignment.getGroups() != null)
2104 for (SequenceGroup sg : alignment.getGroups())
2106 updateCalcs = false;
2107 if (applyGlobalSettings
2108 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2110 // set defaults for this group's conservation/consensus
2111 sg.setshowSequenceLogo(showprf);
2112 sg.setShowConsensusHistogram(showConsHist);
2113 sg.setNormaliseSequenceLogo(normLogo);
2118 alignment.addAnnotation(sg.getConservationRow(), 0);
2123 alignment.addAnnotation(sg.getConsensus(), 0);
2125 // refresh the annotation rows
2128 sg.recalcConservation();
2136 public boolean isDisplayReferenceSeq()
2138 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2142 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2144 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2148 public boolean isColourByReferenceSeq()
2150 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2154 public Color getSequenceColour(SequenceI seq)
2156 Color sqc = sequenceColours.get(seq);
2157 return (sqc == null ? Color.white : sqc);
2161 public void setSequenceColour(SequenceI seq, Color col)
2165 sequenceColours.remove(seq);
2169 sequenceColours.put(seq, col);
2174 public void updateSequenceIdColours()
2176 for (SequenceGroup sg : alignment.getGroups())
2178 if (sg.idColour != null)
2180 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2182 sequenceColours.put(s, sg.idColour);
2189 public void clearSequenceColours()
2191 sequenceColours.clear();
2195 public AlignViewportI getCodingComplement()
2197 return this.codingComplement;
2201 * Set this as the (cDna/protein) complement of the given viewport. Also
2202 * ensures the reverse relationship is set on the given viewport.
2205 public void setCodingComplement(AlignViewportI av)
2209 System.err.println("Ignoring recursive setCodingComplement request");
2213 this.codingComplement = av;
2214 // avoid infinite recursion!
2215 if (av.getCodingComplement() != this)
2217 av.setCodingComplement(this);
2223 public boolean isNucleotide()
2225 return getAlignment() == null ? false : getAlignment().isNucleotide();
2229 public FeaturesDisplayedI getFeaturesDisplayed()
2231 return featuresDisplayed;
2235 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2237 featuresDisplayed = featuresDisplayedI;
2241 public boolean areFeaturesDisplayed()
2243 return featuresDisplayed != null
2244 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2251 * features are displayed if true
2254 public void setShowSequenceFeatures(boolean b)
2256 viewStyle.setShowSequenceFeatures(b);
2260 public boolean isShowSequenceFeatures()
2262 return viewStyle.isShowSequenceFeatures();
2266 public void setShowSequenceFeaturesHeight(boolean selected)
2268 viewStyle.setShowSequenceFeaturesHeight(selected);
2272 public boolean isShowSequenceFeaturesHeight()
2274 return viewStyle.isShowSequenceFeaturesHeight();
2278 public void setShowAnnotation(boolean b)
2280 viewStyle.setShowAnnotation(b);
2284 public boolean isShowAnnotation()
2286 return viewStyle.isShowAnnotation();
2290 public boolean isRightAlignIds()
2292 return viewStyle.isRightAlignIds();
2296 public void setRightAlignIds(boolean rightAlignIds)
2298 viewStyle.setRightAlignIds(rightAlignIds);
2302 public boolean getConservationSelected()
2304 return viewStyle.getConservationSelected();
2308 public void setShowBoxes(boolean state)
2310 viewStyle.setShowBoxes(state);
2315 * @see jalview.api.ViewStyleI#getTextColour()
2318 public Color getTextColour()
2320 return viewStyle.getTextColour();
2325 * @see jalview.api.ViewStyleI#getTextColour2()
2328 public Color getTextColour2()
2330 return viewStyle.getTextColour2();
2335 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2338 public int getThresholdTextColour()
2340 return viewStyle.getThresholdTextColour();
2345 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2348 public boolean isConservationColourSelected()
2350 return viewStyle.isConservationColourSelected();
2355 * @see jalview.api.ViewStyleI#isRenderGaps()
2358 public boolean isRenderGaps()
2360 return viewStyle.isRenderGaps();
2365 * @see jalview.api.ViewStyleI#isShowColourText()
2368 public boolean isShowColourText()
2370 return viewStyle.isShowColourText();
2374 * @param conservationColourSelected
2375 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2378 public void setConservationColourSelected(
2379 boolean conservationColourSelected)
2381 viewStyle.setConservationColourSelected(conservationColourSelected);
2385 * @param showColourText
2386 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2389 public void setShowColourText(boolean showColourText)
2391 viewStyle.setShowColourText(showColourText);
2396 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2399 public void setTextColour(Color textColour)
2401 viewStyle.setTextColour(textColour);
2405 * @param thresholdTextColour
2406 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2409 public void setThresholdTextColour(int thresholdTextColour)
2411 viewStyle.setThresholdTextColour(thresholdTextColour);
2415 * @param textColour2
2416 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2419 public void setTextColour2(Color textColour2)
2421 viewStyle.setTextColour2(textColour2);
2425 public ViewStyleI getViewStyle()
2427 return new ViewStyle(viewStyle);
2431 public void setViewStyle(ViewStyleI settingsForView)
2433 viewStyle = new ViewStyle(settingsForView);
2434 if (residueShading != null)
2436 residueShading.setConservationApplied(settingsForView
2437 .isConservationColourSelected());
2442 public boolean sameStyle(ViewStyleI them)
2444 return viewStyle.sameStyle(them);
2449 * @see jalview.api.ViewStyleI#getIdWidth()
2452 public int getIdWidth()
2454 return viewStyle.getIdWidth();
2459 * @see jalview.api.ViewStyleI#setIdWidth(int)
2462 public void setIdWidth(int i)
2464 viewStyle.setIdWidth(i);
2469 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2472 public boolean isCentreColumnLabels()
2474 return viewStyle.isCentreColumnLabels();
2478 * @param centreColumnLabels
2479 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2482 public void setCentreColumnLabels(boolean centreColumnLabels)
2484 viewStyle.setCentreColumnLabels(centreColumnLabels);
2489 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2492 public void setShowDBRefs(boolean showdbrefs)
2494 viewStyle.setShowDBRefs(showdbrefs);
2499 * @see jalview.api.ViewStyleI#isShowDBRefs()
2502 public boolean isShowDBRefs()
2504 return viewStyle.isShowDBRefs();
2509 * @see jalview.api.ViewStyleI#isShowNPFeats()
2512 public boolean isShowNPFeats()
2514 return viewStyle.isShowNPFeats();
2518 * @param shownpfeats
2519 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2522 public void setShowNPFeats(boolean shownpfeats)
2524 viewStyle.setShowNPFeats(shownpfeats);
2527 public abstract StructureSelectionManager getStructureSelectionManager();
2530 * Add one command to the command history list.
2534 public void addToHistoryList(CommandI command)
2536 if (this.historyList != null)
2538 this.historyList.push(command);
2539 broadcastCommand(command, false);
2543 protected void broadcastCommand(CommandI command, boolean undo)
2545 getStructureSelectionManager().commandPerformed(command, undo,
2550 * Add one command to the command redo list.
2554 public void addToRedoList(CommandI command)
2556 if (this.redoList != null)
2558 this.redoList.push(command);
2560 broadcastCommand(command, true);
2564 * Clear the command redo list.
2566 public void clearRedoList()
2568 if (this.redoList != null)
2570 this.redoList.clear();
2574 public void setHistoryList(Deque<CommandI> list)
2576 this.historyList = list;
2579 public Deque<CommandI> getHistoryList()
2581 return this.historyList;
2584 public void setRedoList(Deque<CommandI> list)
2586 this.redoList = list;
2589 public Deque<CommandI> getRedoList()
2591 return this.redoList;
2595 public VamsasSource getVamsasSource()
2600 public SequenceAnnotationOrder getSortAnnotationsBy()
2602 return sortAnnotationsBy;
2605 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2607 this.sortAnnotationsBy = sortAnnotationsBy;
2610 public boolean isShowAutocalculatedAbove()
2612 return showAutocalculatedAbove;
2615 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2617 this.showAutocalculatedAbove = showAutocalculatedAbove;
2621 public boolean isScaleProteinAsCdna()
2623 return viewStyle.isScaleProteinAsCdna();
2627 public void setScaleProteinAsCdna(boolean b)
2629 viewStyle.setScaleProteinAsCdna(b);
2633 * @return true if view should scroll to show the highlighted region of a
2638 public final boolean isFollowHighlight()
2640 return followHighlight;
2644 public final void setFollowHighlight(boolean b)
2646 this.followHighlight = b;
2650 public ViewportPositionProps getPosProps()
2656 public int getStartRes()
2658 return posProps.getStartRes();
2662 public int getEndRes()
2664 return posProps.getEndRes();
2668 public int getStartSeq()
2670 return posProps.getStartSeq();
2673 public void setStartRes(int res)
2675 posProps.setStartRes(res);
2676 // this.startRes = res;
2679 public void setStartSeq(int seq)
2681 posProps.setStartSeq(seq);
2684 public void setEndRes(int res)
2686 posProps.setEndRes(res);
2689 public void setEndSeq(int seq)
2691 posProps.setEndSeq(seq);
2695 public int getEndSeq()
2697 return posProps.getEndSeq();
2701 * Helper method to populate the SearchResults with the location in the
2702 * complementary alignment to scroll to, in order to match this one.
2705 * the SearchResults to add to
2706 * @return the offset (below top of visible region) of the matched sequence
2708 protected int findComplementScrollTarget(SearchResultsI sr)
2710 final AlignViewportI complement = getCodingComplement();
2711 if (complement == null || !complement.isFollowHighlight())
2715 boolean iAmProtein = !getAlignment().isNucleotide();
2716 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2718 if (proteinAlignment == null)
2722 final List<AlignedCodonFrame> mappings = proteinAlignment
2726 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2727 * residue in the middle column of the visible region. Scroll the
2728 * complementary alignment to line up the corresponding residue.
2731 SequenceI sequence = null;
2734 * locate 'middle' column (true middle if an odd number visible, left of
2735 * middle if an even number visible)
2737 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2738 final HiddenSequences hiddenSequences = getAlignment()
2739 .getHiddenSequences();
2742 * searching to the bottom of the alignment gives smoother scrolling across
2743 * all gapped visible regions
2745 int lastSeq = alignment.getHeight() - 1;
2746 List<AlignedCodonFrame> seqMappings = null;
2747 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2749 sequence = getAlignment().getSequenceAt(seqNo);
2750 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2754 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2758 seqMappings = MappingUtils
2759 .findMappingsForSequenceAndOthers(sequence, mappings,
2760 getCodingComplement().getAlignment().getSequences());
2761 if (!seqMappings.isEmpty())
2767 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2770 * No ungapped mapped sequence in middle column - do nothing
2774 MappingUtils.addSearchResults(sr, sequence,
2775 sequence.findPosition(middleColumn), seqMappings);
2780 * synthesize a column selection if none exists so it covers the given
2781 * selection group. if wholewidth is false, no column selection is made if the
2782 * selection group covers the whole alignment width.
2787 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2790 if (sg != null && (sgs = sg.getStartRes()) >= 0
2791 && sg.getStartRes() <= (sge = sg.getEndRes())
2792 && !this.hasSelectedColumns())
2794 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2801 colSel = new ColumnSelection();
2803 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2805 colSel.addElement(cspos);
2811 * hold status of current selection group - defined on alignment or not.
2813 private boolean selectionIsDefinedGroup = false;
2817 public boolean isSelectionDefinedGroup()
2819 if (selectionGroup == null)
2823 if (isSelectionGroupChanged(true))
2825 selectionIsDefinedGroup = false;
2826 List<SequenceGroup> gps = alignment.getGroups();
2827 if (gps == null || gps.size() == 0)
2829 selectionIsDefinedGroup = false;
2833 selectionIsDefinedGroup = gps.contains(selectionGroup);
2836 return selectionGroup.getContext() == alignment
2837 || selectionIsDefinedGroup;
2841 * null, or currently highlighted results on this view
2843 private SearchResultsI searchResults = null;
2846 public boolean hasSearchResults()
2848 return searchResults != null;
2852 public void setSearchResults(SearchResultsI results)
2854 searchResults = results;
2858 public SearchResultsI getSearchResults()
2860 return searchResults;