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 ViewStyleI viewStyle = new ViewStyle();
84 * A viewport that hosts the cDna view of this (protein), or vice versa (if
87 AlignViewportI codingComplement = null;
89 FeaturesDisplayedI featuresDisplayed = null;
91 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
93 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
97 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
100 public void setFontName(String name)
102 viewStyle.setFontName(name);
107 * @see jalview.api.ViewStyleI#setFontStyle(int)
110 public void setFontStyle(int style)
112 viewStyle.setFontStyle(style);
117 * @see jalview.api.ViewStyleI#setFontSize(int)
120 public void setFontSize(int size)
122 viewStyle.setFontSize(size);
127 * @see jalview.api.ViewStyleI#getFontStyle()
130 public int getFontStyle()
132 return viewStyle.getFontStyle();
137 * @see jalview.api.ViewStyleI#getFontName()
140 public String getFontName()
142 return viewStyle.getFontName();
147 * @see jalview.api.ViewStyleI#getFontSize()
150 public int getFontSize()
152 return viewStyle.getFontSize();
156 * @param upperCasebold
157 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
160 public void setUpperCasebold(boolean upperCasebold)
162 viewStyle.setUpperCasebold(upperCasebold);
167 * @see jalview.api.ViewStyleI#isUpperCasebold()
170 public boolean isUpperCasebold()
172 return viewStyle.isUpperCasebold();
177 * @see jalview.api.ViewStyleI#isSeqNameItalics()
180 public boolean isSeqNameItalics()
182 return viewStyle.isSeqNameItalics();
186 * @param colourByReferenceSeq
187 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
190 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
192 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
197 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
200 public void setColourAppliesToAllGroups(boolean b)
202 viewStyle.setColourAppliesToAllGroups(b);
207 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
210 public boolean getColourAppliesToAllGroups()
212 return viewStyle.getColourAppliesToAllGroups();
217 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
220 public boolean getAbovePIDThreshold()
222 return viewStyle.getAbovePIDThreshold();
227 * @see jalview.api.ViewStyleI#setIncrement(int)
230 public void setIncrement(int inc)
232 viewStyle.setIncrement(inc);
237 * @see jalview.api.ViewStyleI#getIncrement()
240 public int getIncrement()
242 return viewStyle.getIncrement();
247 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
250 public void setConservationSelected(boolean b)
252 viewStyle.setConservationSelected(b);
257 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
260 public void setShowHiddenMarkers(boolean show)
262 viewStyle.setShowHiddenMarkers(show);
267 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
270 public boolean getShowHiddenMarkers()
272 return viewStyle.getShowHiddenMarkers();
277 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
280 public void setScaleRightWrapped(boolean b)
282 viewStyle.setScaleRightWrapped(b);
287 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
290 public void setScaleLeftWrapped(boolean b)
292 viewStyle.setScaleLeftWrapped(b);
297 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
300 public void setScaleAboveWrapped(boolean b)
302 viewStyle.setScaleAboveWrapped(b);
307 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
310 public boolean getScaleLeftWrapped()
312 return viewStyle.getScaleLeftWrapped();
317 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
320 public boolean getScaleAboveWrapped()
322 return viewStyle.getScaleAboveWrapped();
327 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
330 public boolean getScaleRightWrapped()
332 return viewStyle.getScaleRightWrapped();
337 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
340 public void setAbovePIDThreshold(boolean b)
342 viewStyle.setAbovePIDThreshold(b);
347 * @see jalview.api.ViewStyleI#setThreshold(int)
350 public void setThreshold(int thresh)
352 viewStyle.setThreshold(thresh);
357 * @see jalview.api.ViewStyleI#getThreshold()
360 public int getThreshold()
362 return viewStyle.getThreshold();
367 * @see jalview.api.ViewStyleI#getShowJVSuffix()
370 public boolean getShowJVSuffix()
372 return viewStyle.getShowJVSuffix();
377 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
380 public void setShowJVSuffix(boolean b)
382 viewStyle.setShowJVSuffix(b);
387 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
390 public void setWrapAlignment(boolean state)
392 viewStyle.setWrapAlignment(state);
397 * @see jalview.api.ViewStyleI#setShowText(boolean)
400 public void setShowText(boolean state)
402 viewStyle.setShowText(state);
407 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
410 public void setRenderGaps(boolean state)
412 viewStyle.setRenderGaps(state);
417 * @see jalview.api.ViewStyleI#getColourText()
420 public boolean getColourText()
422 return viewStyle.getColourText();
427 * @see jalview.api.ViewStyleI#setColourText(boolean)
430 public void setColourText(boolean state)
432 viewStyle.setColourText(state);
437 * @see jalview.api.ViewStyleI#getWrapAlignment()
440 public boolean getWrapAlignment()
442 return viewStyle.getWrapAlignment();
447 * @see jalview.api.ViewStyleI#getShowText()
450 public boolean getShowText()
452 return viewStyle.getShowText();
457 * @see jalview.api.ViewStyleI#getWrappedWidth()
460 public int getWrappedWidth()
462 return viewStyle.getWrappedWidth();
467 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
470 public void setWrappedWidth(int w)
472 viewStyle.setWrappedWidth(w);
477 * @see jalview.api.ViewStyleI#getCharHeight()
480 public int getCharHeight()
482 return viewStyle.getCharHeight();
487 * @see jalview.api.ViewStyleI#setCharHeight(int)
490 public void setCharHeight(int h)
492 viewStyle.setCharHeight(h);
497 * @see jalview.api.ViewStyleI#getCharWidth()
500 public int getCharWidth()
502 return viewStyle.getCharWidth();
507 * @see jalview.api.ViewStyleI#setCharWidth(int)
510 public void setCharWidth(int w)
512 viewStyle.setCharWidth(w);
517 * @see jalview.api.ViewStyleI#getShowBoxes()
520 public boolean getShowBoxes()
522 return viewStyle.getShowBoxes();
527 * @see jalview.api.ViewStyleI#getShowUnconserved()
530 public boolean getShowUnconserved()
532 return viewStyle.getShowUnconserved();
536 * @param showunconserved
537 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
540 public void setShowUnconserved(boolean showunconserved)
542 viewStyle.setShowUnconserved(showunconserved);
547 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
550 public void setSeqNameItalics(boolean default1)
552 viewStyle.setSeqNameItalics(default1);
556 * alignment displayed in the viewport. Please use get/setter
558 protected AlignmentI alignment;
561 public AlignmentI getAlignment()
567 public char getGapCharacter()
569 return alignment.getGapCharacter();
572 protected String sequenceSetID;
575 * probably unused indicator that view is of a dataset rather than an
578 protected boolean isDataset = false;
580 public void setDataset(boolean b)
585 public boolean isDataset()
590 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
592 protected ColumnSelection colSel = new ColumnSelection();
594 public boolean autoCalculateConsensus = true;
596 protected boolean autoCalculateStrucConsensus = true;
598 protected boolean ignoreGapsInConsensusCalculation = false;
600 protected ResidueShaderI residueShading;
603 public void setGlobalColourScheme(ColourSchemeI cs)
605 // TODO: logic refactored from AlignFrame changeColour -
606 // TODO: autorecalc stuff should be changed to rely on the worker system
607 // check to see if we should implement a changeColour(cs) method rather than
608 // put the logic in here
609 // - means that caller decides if they want to just modify state and defer
610 // calculation till later or to do all calculations in thread.
614 * only instantiate alignment colouring once, thereafter update it;
615 * this means that any conservation or PID threshold settings
616 * persist when the alignment colour scheme is changed
618 if (residueShading == null)
620 residueShading = new ResidueShader(viewStyle);
622 residueShading.setColourScheme(cs);
624 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
625 // ...problem: groups need these, but do not currently have a ViewStyle
629 // if (getConservationSelected() || getAbovePIDThreshold()
630 // || cs instanceof PIDColourScheme
631 // || cs instanceof Blosum62ColourScheme)
632 if (getConservationSelected())
634 residueShading.setConservation(hconservation);
636 residueShading.alignmentChanged(alignment, hiddenRepSequences);
640 * if 'apply colour to all groups' is selected... do so
641 * (but don't transfer any colour threshold settings to groups)
643 if (getColourAppliesToAllGroups())
645 for (SequenceGroup sg : getAlignment().getGroups())
648 * retain any colour thresholds per group while
649 * changing choice of colour scheme (JAL-2386)
651 sg.setColourScheme(cs);
654 sg.getGroupColourScheme()
655 .alignmentChanged(sg, hiddenRepSequences);
662 public ColourSchemeI getGlobalColourScheme()
664 return residueShading == null ? null : residueShading
669 public ResidueShaderI getResidueShading()
671 return residueShading;
674 protected AlignmentAnnotation consensus;
676 protected AlignmentAnnotation complementConsensus;
678 protected AlignmentAnnotation strucConsensus;
680 protected AlignmentAnnotation conservation;
682 protected AlignmentAnnotation quality;
684 protected AlignmentAnnotation[] groupConsensus;
686 protected AlignmentAnnotation[] groupConservation;
689 * results of alignment consensus analysis for visible portion of view
691 protected ProfilesI hconsensus = null;
694 * results of cDNA complement consensus visible portion of view
696 protected Hashtable[] hcomplementConsensus = null;
699 * results of secondary structure base pair consensus for visible portion of
702 protected Hashtable[] hStrucConsensus = null;
704 protected Conservation hconservation = null;
707 public void setConservation(Conservation cons)
709 hconservation = cons;
713 * percentage gaps allowed in a column before all amino acid properties should
714 * be considered unconserved
716 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
719 public int getConsPercGaps()
725 public void setSequenceConsensusHash(ProfilesI hconsensus)
727 this.hconsensus = hconsensus;
731 public void setComplementConsensusHash(Hashtable[] hconsensus)
733 this.hcomplementConsensus = hconsensus;
737 public ProfilesI getSequenceConsensusHash()
743 public Hashtable[] getComplementConsensusHash()
745 return hcomplementConsensus;
749 public Hashtable[] getRnaStructureConsensusHash()
751 return hStrucConsensus;
755 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
757 this.hStrucConsensus = hStrucConsensus;
762 public AlignmentAnnotation getAlignmentQualityAnnot()
768 public AlignmentAnnotation getAlignmentConservationAnnotation()
774 public AlignmentAnnotation getAlignmentConsensusAnnotation()
780 public AlignmentAnnotation getComplementConsensusAnnotation()
782 return complementConsensus;
786 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
788 return strucConsensus;
791 protected AlignCalcManagerI calculator = new AlignCalcManager();
794 * trigger update of conservation annotation
796 public void updateConservation(final AlignmentViewPanel ap)
798 // see note in mantis : issue number 8585
799 if (alignment.isNucleotide()
800 || (conservation == null && quality == null)
801 || !autoCalculateConsensus)
806 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
808 calculator.registerWorker(new jalview.workers.ConservationThread(
814 * trigger update of consensus annotation
816 public void updateConsensus(final AlignmentViewPanel ap)
818 // see note in mantis : issue number 8585
819 if (consensus == null || !autoCalculateConsensus)
823 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
825 calculator.registerWorker(new ConsensusThread(this, ap));
829 * A separate thread to compute cDNA consensus for a protein alignment
830 * which has mapping to cDNA
832 final AlignmentI al = this.getAlignment();
833 if (!al.isNucleotide() && al.getCodonFrames() != null
834 && !al.getCodonFrames().isEmpty())
837 * fudge - check first for protein-to-nucleotide mappings
838 * (we don't want to do this for protein-to-protein)
840 boolean doConsensus = false;
841 for (AlignedCodonFrame mapping : al.getCodonFrames())
843 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
844 MapList[] mapLists = mapping.getdnaToProt();
845 // mapLists can be empty if project load has not finished resolving seqs
846 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
855 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
858 .registerWorker(new ComplementConsensusThread(this, ap));
864 // --------START Structure Conservation
865 public void updateStrucConsensus(final AlignmentViewPanel ap)
867 if (autoCalculateStrucConsensus && strucConsensus == null
868 && alignment.isNucleotide() && alignment.hasRNAStructure())
870 // secondary structure has been added - so init the consensus line
874 // see note in mantis : issue number 8585
875 if (strucConsensus == null || !autoCalculateStrucConsensus)
879 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
881 calculator.registerWorker(new StrucConsensusThread(this, ap));
885 public boolean isCalcInProgress()
887 return calculator.isWorking();
891 public boolean isCalculationInProgress(
892 AlignmentAnnotation alignmentAnnotation)
894 if (!alignmentAnnotation.autoCalculated)
898 if (calculator.workingInvolvedWith(alignmentAnnotation))
900 // System.err.println("grey out ("+alignmentAnnotation.label+")");
906 public void setAlignment(AlignmentI align)
908 this.alignment = align;
912 * Clean up references when this viewport is closed
915 public void dispose()
918 * defensively null out references to large objects in case
919 * this object is not garbage collected (as if!)
922 complementConsensus = null;
923 strucConsensus = null;
926 groupConsensus = null;
927 groupConservation = null;
929 hcomplementConsensus = null;
930 // colour scheme may hold reference to consensus
931 residueShading = null;
932 // TODO remove listeners from changeSupport?
933 changeSupport = null;
938 public boolean isClosed()
940 // TODO: check that this isClosed is only true after panel is closed, not
941 // before it is fully constructed.
942 return alignment == null;
946 public AlignCalcManagerI getCalcManager()
952 * should conservation rows be shown for groups
954 protected boolean showGroupConservation = false;
957 * should consensus rows be shown for groups
959 protected boolean showGroupConsensus = false;
962 * should consensus profile be rendered by default
964 protected boolean showSequenceLogo = false;
967 * should consensus profile be rendered normalised to row height
969 protected boolean normaliseSequenceLogo = false;
972 * should consensus histograms be rendered by default
974 protected boolean showConsensusHistogram = true;
977 * @return the showConsensusProfile
980 public boolean isShowSequenceLogo()
982 return showSequenceLogo;
986 * @param showSequenceLogo
989 public void setShowSequenceLogo(boolean showSequenceLogo)
991 if (showSequenceLogo != this.showSequenceLogo)
993 // TODO: decouple settings setting from calculation when refactoring
994 // annotation update method from alignframe to viewport
995 this.showSequenceLogo = showSequenceLogo;
996 calculator.updateAnnotationFor(ConsensusThread.class);
997 calculator.updateAnnotationFor(ComplementConsensusThread.class);
998 calculator.updateAnnotationFor(StrucConsensusThread.class);
1000 this.showSequenceLogo = showSequenceLogo;
1004 * @param showConsensusHistogram
1005 * the showConsensusHistogram to set
1007 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1009 this.showConsensusHistogram = showConsensusHistogram;
1013 * @return the showGroupConservation
1015 public boolean isShowGroupConservation()
1017 return showGroupConservation;
1021 * @param showGroupConservation
1022 * the showGroupConservation to set
1024 public void setShowGroupConservation(boolean showGroupConservation)
1026 this.showGroupConservation = showGroupConservation;
1030 * @return the showGroupConsensus
1032 public boolean isShowGroupConsensus()
1034 return showGroupConsensus;
1038 * @param showGroupConsensus
1039 * the showGroupConsensus to set
1041 public void setShowGroupConsensus(boolean showGroupConsensus)
1043 this.showGroupConsensus = showGroupConsensus;
1048 * @return flag to indicate if the consensus histogram should be rendered by
1052 public boolean isShowConsensusHistogram()
1054 return this.showConsensusHistogram;
1058 * when set, updateAlignment will always ensure sequences are of equal length
1060 private boolean padGaps = false;
1063 * when set, alignment should be reordered according to a newly opened tree
1065 public boolean sortByTree = false;
1070 * @return null or the currently selected sequence region
1073 public SequenceGroup getSelectionGroup()
1075 return selectionGroup;
1079 * Set the selection group for this window.
1082 * - group holding references to sequences in this alignment view
1086 public void setSelectionGroup(SequenceGroup sg)
1088 selectionGroup = sg;
1091 public void setHiddenColumns(ColumnSelection colsel)
1093 this.colSel = colsel;
1097 public ColumnSelection getColumnSelection()
1103 public void setColumnSelection(ColumnSelection colSel)
1105 this.colSel = colSel;
1108 updateHiddenColumns();
1110 isColSelChanged(true);
1118 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1120 return hiddenRepSequences;
1124 public void setHiddenRepSequences(
1125 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1127 this.hiddenRepSequences = hiddenRepSequences;
1131 public boolean hasSelectedColumns()
1133 ColumnSelection columnSelection = getColumnSelection();
1134 return columnSelection != null && columnSelection.hasSelectedColumns();
1138 public boolean hasHiddenColumns()
1140 return colSel != null && colSel.hasHiddenColumns();
1143 public void updateHiddenColumns()
1145 // this method doesn't really do anything now. But - it could, since a
1146 // column Selection could be in the process of modification
1147 // hasHiddenColumns = colSel.hasHiddenColumns();
1151 public boolean hasHiddenRows()
1153 return alignment.getHiddenSequences().getSize() > 0;
1156 protected SequenceGroup selectionGroup;
1158 public void setSequenceSetId(String newid)
1160 if (sequenceSetID != null)
1163 .println("Warning - overwriting a sequenceSetId for a viewport!");
1165 sequenceSetID = new String(newid);
1169 public String getSequenceSetId()
1171 if (sequenceSetID == null)
1173 sequenceSetID = alignment.hashCode() + "";
1176 return sequenceSetID;
1180 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1183 protected String viewId = null;
1186 public String getViewId()
1190 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1195 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1197 ignoreGapsInConsensusCalculation = b;
1200 updateConsensus(ap);
1201 if (residueShading != null)
1203 residueShading.setThreshold(residueShading.getThreshold(),
1204 ignoreGapsInConsensusCalculation);
1210 private long sgrouphash = -1, colselhash = -1;
1213 * checks current SelectionGroup against record of last hash value, and
1217 * update the record of last hash value
1219 * @return true if SelectionGroup changed since last call (when b is true)
1221 public boolean isSelectionGroupChanged(boolean b)
1223 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1224 : selectionGroup.hashCode();
1225 if (hc != -1 && hc != sgrouphash)
1237 * checks current colsel against record of last hash value, and optionally
1241 * update the record of last hash value
1242 * @return true if colsel changed since last call (when b is true)
1244 public boolean isColSelChanged(boolean b)
1246 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1247 if (hc != -1 && hc != colselhash)
1259 public boolean isIgnoreGapsConsensus()
1261 return ignoreGapsInConsensusCalculation;
1264 // property change stuff
1265 // JBPNote Prolly only need this in the applet version.
1266 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1269 protected boolean showConservation = true;
1271 protected boolean showQuality = true;
1273 protected boolean showConsensus = true;
1275 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1277 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1279 protected boolean showAutocalculatedAbove;
1282 * when set, view will scroll to show the highlighted position
1284 private boolean followHighlight = true;
1286 // TODO private with getters and setters?
1287 public int startRes;
1291 public int startSeq;
1296 * Property change listener for changes in alignment
1301 public void addPropertyChangeListener(
1302 java.beans.PropertyChangeListener listener)
1304 changeSupport.addPropertyChangeListener(listener);
1313 public void removePropertyChangeListener(
1314 java.beans.PropertyChangeListener listener)
1316 changeSupport.removePropertyChangeListener(listener);
1320 * Property change listener for changes in alignment
1329 public void firePropertyChange(String prop, Object oldvalue,
1332 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1335 // common hide/show column stuff
1337 public void hideSelectedColumns()
1339 if (colSel.isEmpty())
1344 colSel.hideSelectedColumns();
1345 setSelectionGroup(null);
1346 isColSelChanged(true);
1349 public void hideColumns(int start, int end)
1353 colSel.hideColumns(start);
1357 colSel.hideColumns(start, end);
1359 isColSelChanged(true);
1362 public void showColumn(int col)
1364 colSel.revealHiddenColumns(col);
1365 isColSelChanged(true);
1368 public void showAllHiddenColumns()
1370 colSel.revealAllHiddenColumns();
1371 isColSelChanged(true);
1374 // common hide/show seq stuff
1375 public void showAllHiddenSeqs()
1377 if (alignment.getHiddenSequences().getSize() > 0)
1379 if (selectionGroup == null)
1381 selectionGroup = new SequenceGroup();
1382 selectionGroup.setEndRes(alignment.getWidth() - 1);
1384 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1385 hiddenRepSequences);
1386 for (SequenceI seq : tmp)
1388 selectionGroup.addSequence(seq, false);
1389 setSequenceAnnotationsVisible(seq, true);
1392 hiddenRepSequences = null;
1394 firePropertyChange("alignment", null, alignment.getSequences());
1395 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1401 public void showSequence(int index)
1403 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1404 index, hiddenRepSequences);
1407 if (selectionGroup == null)
1409 selectionGroup = new SequenceGroup();
1410 selectionGroup.setEndRes(alignment.getWidth() - 1);
1413 for (SequenceI seq : tmp)
1415 selectionGroup.addSequence(seq, false);
1416 setSequenceAnnotationsVisible(seq, true);
1418 firePropertyChange("alignment", null, alignment.getSequences());
1423 public void hideAllSelectedSeqs()
1425 if (selectionGroup == null || selectionGroup.getSize() < 1)
1430 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1434 setSelectionGroup(null);
1437 public void hideSequence(SequenceI[] seq)
1441 for (int i = 0; i < seq.length; i++)
1443 alignment.getHiddenSequences().hideSequence(seq[i]);
1444 setSequenceAnnotationsVisible(seq[i], false);
1446 firePropertyChange("alignment", null, alignment.getSequences());
1451 * Hides the specified sequence, or the sequences it represents
1454 * the sequence to hide, or keep as representative
1455 * @param representGroup
1456 * if true, hide the current selection group except for the
1457 * representative sequence
1459 public void hideSequences(SequenceI sequence, boolean representGroup)
1461 if (selectionGroup == null || selectionGroup.getSize() < 1)
1463 hideSequence(new SequenceI[] { sequence });
1469 hideRepSequences(sequence, selectionGroup);
1470 setSelectionGroup(null);
1474 int gsize = selectionGroup.getSize();
1475 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1476 new SequenceI[gsize]);
1478 hideSequence(hseqs);
1479 setSelectionGroup(null);
1484 * Set visibility for any annotations for the given sequence.
1488 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1491 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1494 for (AlignmentAnnotation ann : anns)
1496 if (ann.sequenceRef == sequenceI)
1498 ann.visible = visible;
1504 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1506 int sSize = sg.getSize();
1512 if (hiddenRepSequences == null)
1514 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1517 hiddenRepSequences.put(repSequence, sg);
1519 // Hide all sequences except the repSequence
1520 SequenceI[] seqs = new SequenceI[sSize - 1];
1522 for (int i = 0; i < sSize; i++)
1524 if (sg.getSequenceAt(i) != repSequence)
1526 if (index == sSize - 1)
1531 seqs[index++] = sg.getSequenceAt(i);
1534 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1535 sg.setHidereps(true); // note: not done in 2.7applet
1542 * @return null or the current reference sequence
1544 public SequenceI getReferenceSeq()
1546 return alignment.getSeqrep();
1551 * @return true iff seq is the reference for the alignment
1553 public boolean isReferenceSeq(SequenceI seq)
1555 return alignment.getSeqrep() == seq;
1561 * @return true if there are sequences represented by this sequence that are
1564 public boolean isHiddenRepSequence(SequenceI seq)
1566 return (hiddenRepSequences != null && hiddenRepSequences
1573 * @return null or a sequence group containing the sequences that seq
1576 public SequenceGroup getRepresentedSequences(SequenceI seq)
1578 return (SequenceGroup) (hiddenRepSequences == null ? null
1579 : hiddenRepSequences.get(seq));
1583 public int adjustForHiddenSeqs(int alignmentIndex)
1585 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1590 public void invertColumnSelection()
1592 colSel.invertColumnSelection(0, alignment.getWidth());
1596 public SequenceI[] getSelectionAsNewSequence()
1598 SequenceI[] sequences;
1599 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1600 // this was the only caller in the applet for this method
1601 // JBPNote: in applet, this method returned references to the alignment
1602 // sequences, and it did not honour the presence/absence of annotation
1603 // attached to the alignment (probably!)
1604 if (selectionGroup == null || selectionGroup.getSize() == 0)
1606 sequences = alignment.getSequencesArray();
1607 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1608 for (int i = 0; i < sequences.length; i++)
1610 // construct new sequence with subset of visible annotation
1611 sequences[i] = new Sequence(sequences[i], annots);
1616 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1623 public SequenceI[] getSequenceSelection()
1625 SequenceI[] sequences = null;
1626 if (selectionGroup != null)
1628 sequences = selectionGroup.getSequencesInOrder(alignment);
1630 if (sequences == null)
1632 sequences = alignment.getSequencesArray();
1638 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1640 return new CigarArray(alignment, colSel,
1641 (selectedRegionOnly ? selectionGroup : null));
1645 public jalview.datamodel.AlignmentView getAlignmentView(
1646 boolean selectedOnly)
1648 return getAlignmentView(selectedOnly, false);
1652 public jalview.datamodel.AlignmentView getAlignmentView(
1653 boolean selectedOnly, boolean markGroups)
1655 return new AlignmentView(alignment, colSel, selectionGroup,
1656 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1661 public String[] getViewAsString(boolean selectedRegionOnly)
1663 return getViewAsString(selectedRegionOnly, true);
1667 public String[] getViewAsString(boolean selectedRegionOnly,
1668 boolean exportHiddenSeqs)
1670 String[] selection = null;
1671 SequenceI[] seqs = null;
1673 int start = 0, end = 0;
1674 if (selectedRegionOnly && selectionGroup != null)
1676 iSize = selectionGroup.getSize();
1677 seqs = selectionGroup.getSequencesInOrder(alignment);
1678 start = selectionGroup.getStartRes();
1679 end = selectionGroup.getEndRes() + 1;
1683 if (hasHiddenRows() && exportHiddenSeqs)
1685 AlignmentI fullAlignment = alignment.getHiddenSequences()
1686 .getFullAlignment();
1687 iSize = fullAlignment.getHeight();
1688 seqs = fullAlignment.getSequencesArray();
1689 end = fullAlignment.getWidth();
1693 iSize = alignment.getHeight();
1694 seqs = alignment.getSequencesArray();
1695 end = alignment.getWidth();
1699 selection = new String[iSize];
1700 if (colSel != null && colSel.hasHiddenColumns())
1702 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1706 for (i = 0; i < iSize; i++)
1708 selection[i] = seqs[i].getSequenceAsString(start, end);
1716 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1718 ArrayList<int[]> regions = new ArrayList<int[]>();
1724 if (colSel != null && colSel.hasHiddenColumns())
1728 start = colSel.adjustForHiddenColumns(start);
1731 end = colSel.getHiddenBoundaryRight(start);
1742 regions.add(new int[] { start, end });
1744 if (colSel != null && colSel.hasHiddenColumns())
1746 start = colSel.adjustForHiddenColumns(end);
1747 start = colSel.getHiddenBoundaryLeft(start) + 1;
1749 } while (end < max);
1751 int[][] startEnd = new int[regions.size()][2];
1757 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1758 boolean selectedOnly)
1760 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1761 AlignmentAnnotation[] aa;
1762 if ((aa = alignment.getAlignmentAnnotation()) != null)
1764 for (AlignmentAnnotation annot : aa)
1766 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1767 if (selectedOnly && selectionGroup != null)
1769 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1770 selectionGroup.getEndRes(), clone);
1774 colSel.makeVisibleAnnotation(clone);
1783 public boolean isPadGaps()
1789 public void setPadGaps(boolean padGaps)
1791 this.padGaps = padGaps;
1795 * apply any post-edit constraints and trigger any calculations needed after
1796 * an edit has been performed on the alignment
1801 public void alignmentChanged(AlignmentViewPanel ap)
1805 alignment.padGaps();
1807 if (autoCalculateConsensus)
1809 updateConsensus(ap);
1811 if (hconsensus != null && autoCalculateConsensus)
1813 updateConservation(ap);
1815 if (autoCalculateStrucConsensus)
1817 updateStrucConsensus(ap);
1820 // Reset endRes of groups if beyond alignment width
1821 int alWidth = alignment.getWidth();
1822 List<SequenceGroup> groups = alignment.getGroups();
1825 for (SequenceGroup sg : groups)
1827 if (sg.getEndRes() > alWidth)
1829 sg.setEndRes(alWidth - 1);
1834 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1836 selectionGroup.setEndRes(alWidth - 1);
1839 updateAllColourSchemes();
1840 calculator.restartWorkers();
1841 // alignment.adjustSequenceAnnotations();
1845 * reset scope and do calculations for all applied colourschemes on alignment
1847 void updateAllColourSchemes()
1849 ResidueShaderI rs = residueShading;
1852 rs.alignmentChanged(alignment, hiddenRepSequences);
1854 rs.setConsensus(hconsensus);
1855 if (rs.conservationApplied())
1857 rs.setConservation(Conservation.calculateConservation("All",
1858 alignment.getSequences(), 0, alignment.getWidth(), false,
1859 getConsPercGaps(), false));
1863 for (SequenceGroup sg : alignment.getGroups())
1867 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1869 sg.recalcConservation();
1873 protected void initAutoAnnotation()
1875 // TODO: add menu option action that nulls or creates consensus object
1876 // depending on if the user wants to see the annotation or not in a
1877 // specific alignment
1879 if (hconsensus == null && !isDataset)
1881 if (!alignment.isNucleotide())
1890 consensus = new AlignmentAnnotation("Consensus", "PID",
1891 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1892 initConsensus(consensus);
1894 initComplementConsensus();
1899 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1900 * consensus annotation.
1902 public void initComplementConsensus()
1904 if (!alignment.isNucleotide())
1906 final List<AlignedCodonFrame> codonMappings = alignment
1908 if (codonMappings != null && !codonMappings.isEmpty())
1910 boolean doConsensus = false;
1911 for (AlignedCodonFrame mapping : codonMappings)
1913 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1914 MapList[] mapLists = mapping.getdnaToProt();
1915 // mapLists can be empty if project load has not finished resolving
1917 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1925 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1926 "PID for cDNA", new Annotation[1], 0f, 100f,
1927 AlignmentAnnotation.BAR_GRAPH);
1928 initConsensus(complementConsensus);
1934 private void initConsensus(AlignmentAnnotation aa)
1937 aa.autoCalculated = true;
1941 alignment.addAnnotation(aa);
1945 private void initConservation()
1947 if (showConservation)
1949 if (conservation == null)
1951 conservation = new AlignmentAnnotation("Conservation",
1952 "Conservation of total alignment less than "
1953 + getConsPercGaps() + "% gaps", new Annotation[1],
1954 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1955 conservation.hasText = true;
1956 conservation.autoCalculated = true;
1957 alignment.addAnnotation(conservation);
1962 private void initQuality()
1966 if (quality == null)
1968 quality = new AlignmentAnnotation("Quality",
1969 "Alignment Quality based on Blosum62 scores",
1970 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1971 quality.hasText = true;
1972 quality.autoCalculated = true;
1973 alignment.addAnnotation(quality);
1978 private void initRNAStructure()
1980 if (alignment.hasRNAStructure() && strucConsensus == null)
1982 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1983 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1984 strucConsensus.hasText = true;
1985 strucConsensus.autoCalculated = true;
1989 alignment.addAnnotation(strucConsensus);
1997 * @see jalview.api.AlignViewportI#calcPanelHeight()
2000 public int calcPanelHeight()
2002 // setHeight of panels
2003 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2005 int charHeight = getCharHeight();
2008 BitSet graphgrp = new BitSet();
2009 for (AlignmentAnnotation aa : anns)
2013 System.err.println("Null annotation row: ignoring.");
2020 if (aa.graphGroup > -1)
2022 if (graphgrp.get(aa.graphGroup))
2028 graphgrp.set(aa.graphGroup);
2035 aa.height += charHeight;
2045 aa.height += aa.graphHeight;
2053 height += aa.height;
2065 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2066 boolean preserveNewGroupSettings)
2068 boolean updateCalcs = false;
2069 boolean conv = isShowGroupConservation();
2070 boolean cons = isShowGroupConsensus();
2071 boolean showprf = isShowSequenceLogo();
2072 boolean showConsHist = isShowConsensusHistogram();
2073 boolean normLogo = isNormaliseSequenceLogo();
2076 * TODO reorder the annotation rows according to group/sequence ordering on
2079 boolean sortg = true;
2081 // remove old automatic annotation
2082 // add any new annotation
2084 // intersect alignment annotation with alignment groups
2086 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2087 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2090 for (int an = 0; an < aan.length; an++)
2092 if (aan[an].autoCalculated && aan[an].groupRef != null)
2094 oldrfs.add(aan[an].groupRef);
2095 alignment.deleteAnnotation(aan[an], false);
2099 if (alignment.getGroups() != null)
2101 for (SequenceGroup sg : alignment.getGroups())
2103 updateCalcs = false;
2104 if (applyGlobalSettings
2105 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2107 // set defaults for this group's conservation/consensus
2108 sg.setshowSequenceLogo(showprf);
2109 sg.setShowConsensusHistogram(showConsHist);
2110 sg.setNormaliseSequenceLogo(normLogo);
2115 alignment.addAnnotation(sg.getConservationRow(), 0);
2120 alignment.addAnnotation(sg.getConsensus(), 0);
2122 // refresh the annotation rows
2125 sg.recalcConservation();
2133 public boolean isDisplayReferenceSeq()
2135 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2139 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2141 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2145 public boolean isColourByReferenceSeq()
2147 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2151 public Color getSequenceColour(SequenceI seq)
2153 Color sqc = sequenceColours.get(seq);
2154 return (sqc == null ? Color.white : sqc);
2158 public void setSequenceColour(SequenceI seq, Color col)
2162 sequenceColours.remove(seq);
2166 sequenceColours.put(seq, col);
2171 public void updateSequenceIdColours()
2173 for (SequenceGroup sg : alignment.getGroups())
2175 if (sg.idColour != null)
2177 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2179 sequenceColours.put(s, sg.idColour);
2186 public void clearSequenceColours()
2188 sequenceColours.clear();
2192 public AlignViewportI getCodingComplement()
2194 return this.codingComplement;
2198 * Set this as the (cDna/protein) complement of the given viewport. Also
2199 * ensures the reverse relationship is set on the given viewport.
2202 public void setCodingComplement(AlignViewportI av)
2206 System.err.println("Ignoring recursive setCodingComplement request");
2210 this.codingComplement = av;
2211 // avoid infinite recursion!
2212 if (av.getCodingComplement() != this)
2214 av.setCodingComplement(this);
2220 public boolean isNucleotide()
2222 return getAlignment() == null ? false : getAlignment().isNucleotide();
2226 public FeaturesDisplayedI getFeaturesDisplayed()
2228 return featuresDisplayed;
2232 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2234 featuresDisplayed = featuresDisplayedI;
2238 public boolean areFeaturesDisplayed()
2240 return featuresDisplayed != null
2241 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2248 * features are displayed if true
2251 public void setShowSequenceFeatures(boolean b)
2253 viewStyle.setShowSequenceFeatures(b);
2257 public boolean isShowSequenceFeatures()
2259 return viewStyle.isShowSequenceFeatures();
2263 public void setShowSequenceFeaturesHeight(boolean selected)
2265 viewStyle.setShowSequenceFeaturesHeight(selected);
2269 public boolean isShowSequenceFeaturesHeight()
2271 return viewStyle.isShowSequenceFeaturesHeight();
2275 public void setShowAnnotation(boolean b)
2277 viewStyle.setShowAnnotation(b);
2281 public boolean isShowAnnotation()
2283 return viewStyle.isShowAnnotation();
2287 public boolean isRightAlignIds()
2289 return viewStyle.isRightAlignIds();
2293 public void setRightAlignIds(boolean rightAlignIds)
2295 viewStyle.setRightAlignIds(rightAlignIds);
2299 public boolean getConservationSelected()
2301 return viewStyle.getConservationSelected();
2305 public void setShowBoxes(boolean state)
2307 viewStyle.setShowBoxes(state);
2312 * @see jalview.api.ViewStyleI#getTextColour()
2315 public Color getTextColour()
2317 return viewStyle.getTextColour();
2322 * @see jalview.api.ViewStyleI#getTextColour2()
2325 public Color getTextColour2()
2327 return viewStyle.getTextColour2();
2332 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2335 public int getThresholdTextColour()
2337 return viewStyle.getThresholdTextColour();
2342 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2345 public boolean isConservationColourSelected()
2347 return viewStyle.isConservationColourSelected();
2352 * @see jalview.api.ViewStyleI#isRenderGaps()
2355 public boolean isRenderGaps()
2357 return viewStyle.isRenderGaps();
2362 * @see jalview.api.ViewStyleI#isShowColourText()
2365 public boolean isShowColourText()
2367 return viewStyle.isShowColourText();
2371 * @param conservationColourSelected
2372 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2375 public void setConservationColourSelected(
2376 boolean conservationColourSelected)
2378 viewStyle.setConservationColourSelected(conservationColourSelected);
2382 * @param showColourText
2383 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2386 public void setShowColourText(boolean showColourText)
2388 viewStyle.setShowColourText(showColourText);
2393 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2396 public void setTextColour(Color textColour)
2398 viewStyle.setTextColour(textColour);
2402 * @param thresholdTextColour
2403 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2406 public void setThresholdTextColour(int thresholdTextColour)
2408 viewStyle.setThresholdTextColour(thresholdTextColour);
2412 * @param textColour2
2413 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2416 public void setTextColour2(Color textColour2)
2418 viewStyle.setTextColour2(textColour2);
2422 public ViewStyleI getViewStyle()
2424 return new ViewStyle(viewStyle);
2428 public void setViewStyle(ViewStyleI settingsForView)
2430 viewStyle = new ViewStyle(settingsForView);
2434 public boolean sameStyle(ViewStyleI them)
2436 return viewStyle.sameStyle(them);
2441 * @see jalview.api.ViewStyleI#getIdWidth()
2444 public int getIdWidth()
2446 return viewStyle.getIdWidth();
2451 * @see jalview.api.ViewStyleI#setIdWidth(int)
2454 public void setIdWidth(int i)
2456 viewStyle.setIdWidth(i);
2461 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2464 public boolean isCentreColumnLabels()
2466 return viewStyle.isCentreColumnLabels();
2470 * @param centreColumnLabels
2471 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2474 public void setCentreColumnLabels(boolean centreColumnLabels)
2476 viewStyle.setCentreColumnLabels(centreColumnLabels);
2481 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2484 public void setShowDBRefs(boolean showdbrefs)
2486 viewStyle.setShowDBRefs(showdbrefs);
2491 * @see jalview.api.ViewStyleI#isShowDBRefs()
2494 public boolean isShowDBRefs()
2496 return viewStyle.isShowDBRefs();
2501 * @see jalview.api.ViewStyleI#isShowNPFeats()
2504 public boolean isShowNPFeats()
2506 return viewStyle.isShowNPFeats();
2510 * @param shownpfeats
2511 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2514 public void setShowNPFeats(boolean shownpfeats)
2516 viewStyle.setShowNPFeats(shownpfeats);
2519 public abstract StructureSelectionManager getStructureSelectionManager();
2522 * Add one command to the command history list.
2526 public void addToHistoryList(CommandI command)
2528 if (this.historyList != null)
2530 this.historyList.push(command);
2531 broadcastCommand(command, false);
2535 protected void broadcastCommand(CommandI command, boolean undo)
2537 getStructureSelectionManager().commandPerformed(command, undo,
2542 * Add one command to the command redo list.
2546 public void addToRedoList(CommandI command)
2548 if (this.redoList != null)
2550 this.redoList.push(command);
2552 broadcastCommand(command, true);
2556 * Clear the command redo list.
2558 public void clearRedoList()
2560 if (this.redoList != null)
2562 this.redoList.clear();
2566 public void setHistoryList(Deque<CommandI> list)
2568 this.historyList = list;
2571 public Deque<CommandI> getHistoryList()
2573 return this.historyList;
2576 public void setRedoList(Deque<CommandI> list)
2578 this.redoList = list;
2581 public Deque<CommandI> getRedoList()
2583 return this.redoList;
2587 public VamsasSource getVamsasSource()
2592 public SequenceAnnotationOrder getSortAnnotationsBy()
2594 return sortAnnotationsBy;
2597 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2599 this.sortAnnotationsBy = sortAnnotationsBy;
2602 public boolean isShowAutocalculatedAbove()
2604 return showAutocalculatedAbove;
2607 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2609 this.showAutocalculatedAbove = showAutocalculatedAbove;
2613 public boolean isScaleProteinAsCdna()
2615 return viewStyle.isScaleProteinAsCdna();
2619 public void setScaleProteinAsCdna(boolean b)
2621 viewStyle.setScaleProteinAsCdna(b);
2625 * @return true if view should scroll to show the highlighted region of a
2630 public final boolean isFollowHighlight()
2632 return followHighlight;
2636 public final void setFollowHighlight(boolean b)
2638 this.followHighlight = b;
2641 public int getStartRes()
2647 public int getEndRes()
2652 public int getStartSeq()
2657 public void setStartRes(int res)
2659 this.startRes = res;
2662 public void setStartSeq(int seq)
2664 this.startSeq = seq;
2667 public void setEndRes(int res)
2669 if (res > alignment.getWidth() - 1)
2671 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2672 // (alignment.getWidth()-1));
2673 res = alignment.getWidth() - 1;
2682 public void setEndSeq(int seq)
2684 if (seq > alignment.getHeight())
2686 seq = alignment.getHeight();
2695 public int 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;