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())
631 residueShading.setConservation(hconservation);
633 residueShading.alignmentChanged(alignment, hiddenRepSequences);
637 * if 'apply colour to all groups' is selected... do so
638 * (but don't transfer any colour threshold settings to groups)
640 if (getColourAppliesToAllGroups())
642 for (SequenceGroup sg : getAlignment().getGroups())
645 * retain any colour thresholds per group while
646 * changing choice of colour scheme (JAL-2386)
648 sg.setColourScheme(cs);
651 sg.getGroupColourScheme()
652 .alignmentChanged(sg, hiddenRepSequences);
659 public ColourSchemeI getGlobalColourScheme()
661 return residueShading == null ? null : residueShading
666 public ResidueShaderI getResidueShading()
668 return residueShading;
671 protected AlignmentAnnotation consensus;
673 protected AlignmentAnnotation complementConsensus;
675 protected AlignmentAnnotation strucConsensus;
677 protected AlignmentAnnotation conservation;
679 protected AlignmentAnnotation quality;
681 protected AlignmentAnnotation[] groupConsensus;
683 protected AlignmentAnnotation[] groupConservation;
686 * results of alignment consensus analysis for visible portion of view
688 protected ProfilesI hconsensus = null;
691 * results of cDNA complement consensus visible portion of view
693 protected Hashtable[] hcomplementConsensus = null;
696 * results of secondary structure base pair consensus for visible portion of
699 protected Hashtable[] hStrucConsensus = null;
701 protected Conservation hconservation = null;
704 public void setConservation(Conservation cons)
706 hconservation = cons;
710 * percentage gaps allowed in a column before all amino acid properties should
711 * be considered unconserved
713 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
716 public int getConsPercGaps()
722 public void setSequenceConsensusHash(ProfilesI hconsensus)
724 this.hconsensus = hconsensus;
728 public void setComplementConsensusHash(Hashtable[] hconsensus)
730 this.hcomplementConsensus = hconsensus;
734 public ProfilesI getSequenceConsensusHash()
740 public Hashtable[] getComplementConsensusHash()
742 return hcomplementConsensus;
746 public Hashtable[] getRnaStructureConsensusHash()
748 return hStrucConsensus;
752 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
754 this.hStrucConsensus = hStrucConsensus;
759 public AlignmentAnnotation getAlignmentQualityAnnot()
765 public AlignmentAnnotation getAlignmentConservationAnnotation()
771 public AlignmentAnnotation getAlignmentConsensusAnnotation()
777 public AlignmentAnnotation getComplementConsensusAnnotation()
779 return complementConsensus;
783 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
785 return strucConsensus;
788 protected AlignCalcManagerI calculator = new AlignCalcManager();
791 * trigger update of conservation annotation
793 public void updateConservation(final AlignmentViewPanel ap)
795 // see note in mantis : issue number 8585
796 if (alignment.isNucleotide()
797 || (conservation == null && quality == null)
798 || !autoCalculateConsensus)
803 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
805 calculator.registerWorker(new jalview.workers.ConservationThread(
811 * trigger update of consensus annotation
813 public void updateConsensus(final AlignmentViewPanel ap)
815 // see note in mantis : issue number 8585
816 if (consensus == null || !autoCalculateConsensus)
820 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
822 calculator.registerWorker(new ConsensusThread(this, ap));
826 * A separate thread to compute cDNA consensus for a protein alignment
827 * which has mapping to cDNA
829 final AlignmentI al = this.getAlignment();
830 if (!al.isNucleotide() && al.getCodonFrames() != null
831 && !al.getCodonFrames().isEmpty())
834 * fudge - check first for protein-to-nucleotide mappings
835 * (we don't want to do this for protein-to-protein)
837 boolean doConsensus = false;
838 for (AlignedCodonFrame mapping : al.getCodonFrames())
840 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
841 MapList[] mapLists = mapping.getdnaToProt();
842 // mapLists can be empty if project load has not finished resolving seqs
843 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
852 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
855 .registerWorker(new ComplementConsensusThread(this, ap));
861 // --------START Structure Conservation
862 public void updateStrucConsensus(final AlignmentViewPanel ap)
864 if (autoCalculateStrucConsensus && strucConsensus == null
865 && alignment.isNucleotide() && alignment.hasRNAStructure())
867 // secondary structure has been added - so init the consensus line
871 // see note in mantis : issue number 8585
872 if (strucConsensus == null || !autoCalculateStrucConsensus)
876 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
878 calculator.registerWorker(new StrucConsensusThread(this, ap));
882 public boolean isCalcInProgress()
884 return calculator.isWorking();
888 public boolean isCalculationInProgress(
889 AlignmentAnnotation alignmentAnnotation)
891 if (!alignmentAnnotation.autoCalculated)
895 if (calculator.workingInvolvedWith(alignmentAnnotation))
897 // System.err.println("grey out ("+alignmentAnnotation.label+")");
903 public void setAlignment(AlignmentI align)
905 this.alignment = align;
909 * Clean up references when this viewport is closed
912 public void dispose()
915 * defensively null out references to large objects in case
916 * this object is not garbage collected (as if!)
919 complementConsensus = null;
920 strucConsensus = null;
923 groupConsensus = null;
924 groupConservation = null;
926 hcomplementConsensus = null;
927 // colour scheme may hold reference to consensus
928 residueShading = null;
929 // TODO remove listeners from changeSupport?
930 changeSupport = null;
935 public boolean isClosed()
937 // TODO: check that this isClosed is only true after panel is closed, not
938 // before it is fully constructed.
939 return alignment == null;
943 public AlignCalcManagerI getCalcManager()
949 * should conservation rows be shown for groups
951 protected boolean showGroupConservation = false;
954 * should consensus rows be shown for groups
956 protected boolean showGroupConsensus = false;
959 * should consensus profile be rendered by default
961 protected boolean showSequenceLogo = false;
964 * should consensus profile be rendered normalised to row height
966 protected boolean normaliseSequenceLogo = false;
969 * should consensus histograms be rendered by default
971 protected boolean showConsensusHistogram = true;
974 * @return the showConsensusProfile
977 public boolean isShowSequenceLogo()
979 return showSequenceLogo;
983 * @param showSequenceLogo
986 public void setShowSequenceLogo(boolean showSequenceLogo)
988 if (showSequenceLogo != this.showSequenceLogo)
990 // TODO: decouple settings setting from calculation when refactoring
991 // annotation update method from alignframe to viewport
992 this.showSequenceLogo = showSequenceLogo;
993 calculator.updateAnnotationFor(ConsensusThread.class);
994 calculator.updateAnnotationFor(ComplementConsensusThread.class);
995 calculator.updateAnnotationFor(StrucConsensusThread.class);
997 this.showSequenceLogo = showSequenceLogo;
1001 * @param showConsensusHistogram
1002 * the showConsensusHistogram to set
1004 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1006 this.showConsensusHistogram = showConsensusHistogram;
1010 * @return the showGroupConservation
1012 public boolean isShowGroupConservation()
1014 return showGroupConservation;
1018 * @param showGroupConservation
1019 * the showGroupConservation to set
1021 public void setShowGroupConservation(boolean showGroupConservation)
1023 this.showGroupConservation = showGroupConservation;
1027 * @return the showGroupConsensus
1029 public boolean isShowGroupConsensus()
1031 return showGroupConsensus;
1035 * @param showGroupConsensus
1036 * the showGroupConsensus to set
1038 public void setShowGroupConsensus(boolean showGroupConsensus)
1040 this.showGroupConsensus = showGroupConsensus;
1045 * @return flag to indicate if the consensus histogram should be rendered by
1049 public boolean isShowConsensusHistogram()
1051 return this.showConsensusHistogram;
1055 * when set, updateAlignment will always ensure sequences are of equal length
1057 private boolean padGaps = false;
1060 * when set, alignment should be reordered according to a newly opened tree
1062 public boolean sortByTree = false;
1067 * @return null or the currently selected sequence region
1070 public SequenceGroup getSelectionGroup()
1072 return selectionGroup;
1076 * Set the selection group for this window. Also sets the current alignment as
1077 * the context for the group, if it does not already have one.
1080 * - group holding references to sequences in this alignment view
1084 public void setSelectionGroup(SequenceGroup sg)
1086 selectionGroup = sg;
1087 if (sg != null && sg.getContext() == null)
1089 sg.setContext(alignment);
1093 public void setHiddenColumns(ColumnSelection colsel)
1095 this.colSel = colsel;
1099 public ColumnSelection getColumnSelection()
1105 public void setColumnSelection(ColumnSelection colSel)
1107 this.colSel = colSel;
1110 updateHiddenColumns();
1112 isColSelChanged(true);
1120 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1122 return hiddenRepSequences;
1126 public void setHiddenRepSequences(
1127 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1129 this.hiddenRepSequences = hiddenRepSequences;
1133 public boolean hasSelectedColumns()
1135 ColumnSelection columnSelection = getColumnSelection();
1136 return columnSelection != null && columnSelection.hasSelectedColumns();
1140 public boolean hasHiddenColumns()
1142 return colSel != null && colSel.hasHiddenColumns();
1145 public void updateHiddenColumns()
1147 // this method doesn't really do anything now. But - it could, since a
1148 // column Selection could be in the process of modification
1149 // hasHiddenColumns = colSel.hasHiddenColumns();
1153 public boolean hasHiddenRows()
1155 return alignment.getHiddenSequences().getSize() > 0;
1158 protected SequenceGroup selectionGroup;
1160 public void setSequenceSetId(String newid)
1162 if (sequenceSetID != null)
1165 .println("Warning - overwriting a sequenceSetId for a viewport!");
1167 sequenceSetID = new String(newid);
1171 public String getSequenceSetId()
1173 if (sequenceSetID == null)
1175 sequenceSetID = alignment.hashCode() + "";
1178 return sequenceSetID;
1182 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1185 protected String viewId = null;
1188 public String getViewId()
1192 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1197 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1199 ignoreGapsInConsensusCalculation = b;
1202 updateConsensus(ap);
1203 if (residueShading != null)
1205 residueShading.setThreshold(residueShading.getThreshold(),
1206 ignoreGapsInConsensusCalculation);
1212 private long sgrouphash = -1, colselhash = -1;
1215 * checks current SelectionGroup against record of last hash value, and
1219 * update the record of last hash value
1221 * @return true if SelectionGroup changed since last call (when b is true)
1223 public boolean isSelectionGroupChanged(boolean b)
1225 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1226 : selectionGroup.hashCode();
1227 if (hc != -1 && hc != sgrouphash)
1239 * checks current colsel against record of last hash value, and optionally
1243 * update the record of last hash value
1244 * @return true if colsel changed since last call (when b is true)
1246 public boolean isColSelChanged(boolean b)
1248 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1249 if (hc != -1 && hc != colselhash)
1261 public boolean isIgnoreGapsConsensus()
1263 return ignoreGapsInConsensusCalculation;
1266 // property change stuff
1267 // JBPNote Prolly only need this in the applet version.
1268 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1271 protected boolean showConservation = true;
1273 protected boolean showQuality = true;
1275 protected boolean showConsensus = true;
1277 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1279 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1281 protected boolean showAutocalculatedAbove;
1284 * when set, view will scroll to show the highlighted position
1286 private boolean followHighlight = true;
1288 private int startRes;
1292 private int startSeq;
1297 * Property change listener for changes in alignment
1302 public void addPropertyChangeListener(
1303 java.beans.PropertyChangeListener listener)
1305 changeSupport.addPropertyChangeListener(listener);
1314 public void removePropertyChangeListener(
1315 java.beans.PropertyChangeListener listener)
1317 changeSupport.removePropertyChangeListener(listener);
1321 * Property change listener for changes in alignment
1330 public void firePropertyChange(String prop, Object oldvalue,
1333 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1336 // common hide/show column stuff
1338 public void hideSelectedColumns()
1340 if (colSel.isEmpty())
1345 colSel.hideSelectedColumns();
1346 setSelectionGroup(null);
1347 isColSelChanged(true);
1350 public void hideColumns(int start, int end)
1354 colSel.hideColumns(start);
1358 colSel.hideColumns(start, end);
1360 isColSelChanged(true);
1363 public void showColumn(int col)
1365 colSel.revealHiddenColumns(col);
1366 isColSelChanged(true);
1369 public void showAllHiddenColumns()
1371 colSel.revealAllHiddenColumns();
1372 isColSelChanged(true);
1375 // common hide/show seq stuff
1376 public void showAllHiddenSeqs()
1378 if (alignment.getHiddenSequences().getSize() > 0)
1380 if (selectionGroup == null)
1382 selectionGroup = new SequenceGroup();
1383 selectionGroup.setEndRes(alignment.getWidth() - 1);
1385 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1386 hiddenRepSequences);
1387 for (SequenceI seq : tmp)
1389 selectionGroup.addSequence(seq, false);
1390 setSequenceAnnotationsVisible(seq, true);
1393 hiddenRepSequences = null;
1395 firePropertyChange("alignment", null, alignment.getSequences());
1396 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1402 public void showSequence(int index)
1404 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1405 index, hiddenRepSequences);
1408 if (selectionGroup == null)
1410 selectionGroup = new SequenceGroup();
1411 selectionGroup.setEndRes(alignment.getWidth() - 1);
1414 for (SequenceI seq : tmp)
1416 selectionGroup.addSequence(seq, false);
1417 setSequenceAnnotationsVisible(seq, true);
1419 firePropertyChange("alignment", null, alignment.getSequences());
1424 public void hideAllSelectedSeqs()
1426 if (selectionGroup == null || selectionGroup.getSize() < 1)
1431 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1435 setSelectionGroup(null);
1438 public void hideSequence(SequenceI[] seq)
1442 for (int i = 0; i < seq.length; i++)
1444 alignment.getHiddenSequences().hideSequence(seq[i]);
1445 setSequenceAnnotationsVisible(seq[i], false);
1447 firePropertyChange("alignment", null, alignment.getSequences());
1452 * Hides the specified sequence, or the sequences it represents
1455 * the sequence to hide, or keep as representative
1456 * @param representGroup
1457 * if true, hide the current selection group except for the
1458 * representative sequence
1460 public void hideSequences(SequenceI sequence, boolean representGroup)
1462 if (selectionGroup == null || selectionGroup.getSize() < 1)
1464 hideSequence(new SequenceI[] { sequence });
1470 hideRepSequences(sequence, selectionGroup);
1471 setSelectionGroup(null);
1475 int gsize = selectionGroup.getSize();
1476 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1477 new SequenceI[gsize]);
1479 hideSequence(hseqs);
1480 setSelectionGroup(null);
1485 * Set visibility for any annotations for the given sequence.
1489 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1492 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1495 for (AlignmentAnnotation ann : anns)
1497 if (ann.sequenceRef == sequenceI)
1499 ann.visible = visible;
1505 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1507 int sSize = sg.getSize();
1513 if (hiddenRepSequences == null)
1515 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1518 hiddenRepSequences.put(repSequence, sg);
1520 // Hide all sequences except the repSequence
1521 SequenceI[] seqs = new SequenceI[sSize - 1];
1523 for (int i = 0; i < sSize; i++)
1525 if (sg.getSequenceAt(i) != repSequence)
1527 if (index == sSize - 1)
1532 seqs[index++] = sg.getSequenceAt(i);
1535 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1536 sg.setHidereps(true); // note: not done in 2.7applet
1543 * @return null or the current reference sequence
1545 public SequenceI getReferenceSeq()
1547 return alignment.getSeqrep();
1552 * @return true iff seq is the reference for the alignment
1554 public boolean isReferenceSeq(SequenceI seq)
1556 return alignment.getSeqrep() == seq;
1562 * @return true if there are sequences represented by this sequence that are
1565 public boolean isHiddenRepSequence(SequenceI seq)
1567 return (hiddenRepSequences != null && hiddenRepSequences
1574 * @return null or a sequence group containing the sequences that seq
1577 public SequenceGroup getRepresentedSequences(SequenceI seq)
1579 return (SequenceGroup) (hiddenRepSequences == null ? null
1580 : hiddenRepSequences.get(seq));
1584 public int adjustForHiddenSeqs(int alignmentIndex)
1586 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1591 public void invertColumnSelection()
1593 colSel.invertColumnSelection(0, alignment.getWidth());
1597 public SequenceI[] getSelectionAsNewSequence()
1599 SequenceI[] sequences;
1600 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1601 // this was the only caller in the applet for this method
1602 // JBPNote: in applet, this method returned references to the alignment
1603 // sequences, and it did not honour the presence/absence of annotation
1604 // attached to the alignment (probably!)
1605 if (selectionGroup == null || selectionGroup.getSize() == 0)
1607 sequences = alignment.getSequencesArray();
1608 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1609 for (int i = 0; i < sequences.length; i++)
1611 // construct new sequence with subset of visible annotation
1612 sequences[i] = new Sequence(sequences[i], annots);
1617 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1624 public SequenceI[] getSequenceSelection()
1626 SequenceI[] sequences = null;
1627 if (selectionGroup != null)
1629 sequences = selectionGroup.getSequencesInOrder(alignment);
1631 if (sequences == null)
1633 sequences = alignment.getSequencesArray();
1639 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1641 return new CigarArray(alignment, colSel,
1642 (selectedRegionOnly ? selectionGroup : null));
1646 public jalview.datamodel.AlignmentView getAlignmentView(
1647 boolean selectedOnly)
1649 return getAlignmentView(selectedOnly, false);
1653 public jalview.datamodel.AlignmentView getAlignmentView(
1654 boolean selectedOnly, boolean markGroups)
1656 return new AlignmentView(alignment, colSel, selectionGroup,
1657 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1662 public String[] getViewAsString(boolean selectedRegionOnly)
1664 return getViewAsString(selectedRegionOnly, true);
1668 public String[] getViewAsString(boolean selectedRegionOnly,
1669 boolean exportHiddenSeqs)
1671 String[] selection = null;
1672 SequenceI[] seqs = null;
1674 int start = 0, end = 0;
1675 if (selectedRegionOnly && selectionGroup != null)
1677 iSize = selectionGroup.getSize();
1678 seqs = selectionGroup.getSequencesInOrder(alignment);
1679 start = selectionGroup.getStartRes();
1680 end = selectionGroup.getEndRes() + 1;
1684 if (hasHiddenRows() && exportHiddenSeqs)
1686 AlignmentI fullAlignment = alignment.getHiddenSequences()
1687 .getFullAlignment();
1688 iSize = fullAlignment.getHeight();
1689 seqs = fullAlignment.getSequencesArray();
1690 end = fullAlignment.getWidth();
1694 iSize = alignment.getHeight();
1695 seqs = alignment.getSequencesArray();
1696 end = alignment.getWidth();
1700 selection = new String[iSize];
1701 if (colSel != null && colSel.hasHiddenColumns())
1703 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1707 for (i = 0; i < iSize; i++)
1709 selection[i] = seqs[i].getSequenceAsString(start, end);
1717 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1719 ArrayList<int[]> regions = new ArrayList<int[]>();
1725 if (colSel != null && colSel.hasHiddenColumns())
1729 start = colSel.adjustForHiddenColumns(start);
1732 end = colSel.getHiddenBoundaryRight(start);
1743 regions.add(new int[] { start, end });
1745 if (colSel != null && colSel.hasHiddenColumns())
1747 start = colSel.adjustForHiddenColumns(end);
1748 start = colSel.getHiddenBoundaryLeft(start) + 1;
1750 } while (end < max);
1752 int[][] startEnd = new int[regions.size()][2];
1758 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1759 boolean selectedOnly)
1761 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1762 AlignmentAnnotation[] aa;
1763 if ((aa = alignment.getAlignmentAnnotation()) != null)
1765 for (AlignmentAnnotation annot : aa)
1767 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1768 if (selectedOnly && selectionGroup != null)
1770 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1771 selectionGroup.getEndRes(), clone);
1775 colSel.makeVisibleAnnotation(clone);
1784 public boolean isPadGaps()
1790 public void setPadGaps(boolean padGaps)
1792 this.padGaps = padGaps;
1796 * apply any post-edit constraints and trigger any calculations needed after
1797 * an edit has been performed on the alignment
1802 public void alignmentChanged(AlignmentViewPanel ap)
1806 alignment.padGaps();
1808 if (autoCalculateConsensus)
1810 updateConsensus(ap);
1812 if (hconsensus != null && autoCalculateConsensus)
1814 updateConservation(ap);
1816 if (autoCalculateStrucConsensus)
1818 updateStrucConsensus(ap);
1821 // Reset endRes of groups if beyond alignment width
1822 int alWidth = alignment.getWidth();
1823 List<SequenceGroup> groups = alignment.getGroups();
1826 for (SequenceGroup sg : groups)
1828 if (sg.getEndRes() > alWidth)
1830 sg.setEndRes(alWidth - 1);
1835 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1837 selectionGroup.setEndRes(alWidth - 1);
1840 updateAllColourSchemes();
1841 calculator.restartWorkers();
1842 // alignment.adjustSequenceAnnotations();
1846 * reset scope and do calculations for all applied colourschemes on alignment
1848 void updateAllColourSchemes()
1850 ResidueShaderI rs = residueShading;
1853 rs.alignmentChanged(alignment, hiddenRepSequences);
1855 rs.setConsensus(hconsensus);
1856 if (rs.conservationApplied())
1858 rs.setConservation(Conservation.calculateConservation("All",
1859 alignment.getSequences(), 0, alignment.getWidth(), false,
1860 getConsPercGaps(), false));
1864 for (SequenceGroup sg : alignment.getGroups())
1868 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1870 sg.recalcConservation();
1874 protected void initAutoAnnotation()
1876 // TODO: add menu option action that nulls or creates consensus object
1877 // depending on if the user wants to see the annotation or not in a
1878 // specific alignment
1880 if (hconsensus == null && !isDataset)
1882 if (!alignment.isNucleotide())
1891 consensus = new AlignmentAnnotation("Consensus", "PID",
1892 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1893 initConsensus(consensus);
1895 initComplementConsensus();
1900 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1901 * consensus annotation.
1903 public void initComplementConsensus()
1905 if (!alignment.isNucleotide())
1907 final List<AlignedCodonFrame> codonMappings = alignment
1909 if (codonMappings != null && !codonMappings.isEmpty())
1911 boolean doConsensus = false;
1912 for (AlignedCodonFrame mapping : codonMappings)
1914 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1915 MapList[] mapLists = mapping.getdnaToProt();
1916 // mapLists can be empty if project load has not finished resolving
1918 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1926 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1927 "PID for cDNA", new Annotation[1], 0f, 100f,
1928 AlignmentAnnotation.BAR_GRAPH);
1929 initConsensus(complementConsensus);
1935 private void initConsensus(AlignmentAnnotation aa)
1938 aa.autoCalculated = true;
1942 alignment.addAnnotation(aa);
1946 private void initConservation()
1948 if (showConservation)
1950 if (conservation == null)
1952 conservation = new AlignmentAnnotation("Conservation",
1953 "Conservation of total alignment less than "
1954 + getConsPercGaps() + "% gaps", new Annotation[1],
1955 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1956 conservation.hasText = true;
1957 conservation.autoCalculated = true;
1958 alignment.addAnnotation(conservation);
1963 private void initQuality()
1967 if (quality == null)
1969 quality = new AlignmentAnnotation("Quality",
1970 "Alignment Quality based on Blosum62 scores",
1971 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1972 quality.hasText = true;
1973 quality.autoCalculated = true;
1974 alignment.addAnnotation(quality);
1979 private void initRNAStructure()
1981 if (alignment.hasRNAStructure() && strucConsensus == null)
1983 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1984 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1985 strucConsensus.hasText = true;
1986 strucConsensus.autoCalculated = true;
1990 alignment.addAnnotation(strucConsensus);
1998 * @see jalview.api.AlignViewportI#calcPanelHeight()
2001 public int calcPanelHeight()
2003 // setHeight of panels
2004 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2006 int charHeight = getCharHeight();
2009 BitSet graphgrp = new BitSet();
2010 for (AlignmentAnnotation aa : anns)
2014 System.err.println("Null annotation row: ignoring.");
2021 if (aa.graphGroup > -1)
2023 if (graphgrp.get(aa.graphGroup))
2029 graphgrp.set(aa.graphGroup);
2036 aa.height += charHeight;
2046 aa.height += aa.graphHeight;
2054 height += aa.height;
2066 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2067 boolean preserveNewGroupSettings)
2069 boolean updateCalcs = false;
2070 boolean conv = isShowGroupConservation();
2071 boolean cons = isShowGroupConsensus();
2072 boolean showprf = isShowSequenceLogo();
2073 boolean showConsHist = isShowConsensusHistogram();
2074 boolean normLogo = isNormaliseSequenceLogo();
2077 * TODO reorder the annotation rows according to group/sequence ordering on
2080 boolean sortg = true;
2082 // remove old automatic annotation
2083 // add any new annotation
2085 // intersect alignment annotation with alignment groups
2087 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2088 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2091 for (int an = 0; an < aan.length; an++)
2093 if (aan[an].autoCalculated && aan[an].groupRef != null)
2095 oldrfs.add(aan[an].groupRef);
2096 alignment.deleteAnnotation(aan[an], false);
2100 if (alignment.getGroups() != null)
2102 for (SequenceGroup sg : alignment.getGroups())
2104 updateCalcs = false;
2105 if (applyGlobalSettings
2106 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2108 // set defaults for this group's conservation/consensus
2109 sg.setshowSequenceLogo(showprf);
2110 sg.setShowConsensusHistogram(showConsHist);
2111 sg.setNormaliseSequenceLogo(normLogo);
2116 alignment.addAnnotation(sg.getConservationRow(), 0);
2121 alignment.addAnnotation(sg.getConsensus(), 0);
2123 // refresh the annotation rows
2126 sg.recalcConservation();
2134 public boolean isDisplayReferenceSeq()
2136 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2140 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2142 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2146 public boolean isColourByReferenceSeq()
2148 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2152 public Color getSequenceColour(SequenceI seq)
2154 Color sqc = sequenceColours.get(seq);
2155 return (sqc == null ? Color.white : sqc);
2159 public void setSequenceColour(SequenceI seq, Color col)
2163 sequenceColours.remove(seq);
2167 sequenceColours.put(seq, col);
2172 public void updateSequenceIdColours()
2174 for (SequenceGroup sg : alignment.getGroups())
2176 if (sg.idColour != null)
2178 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2180 sequenceColours.put(s, sg.idColour);
2187 public void clearSequenceColours()
2189 sequenceColours.clear();
2193 public AlignViewportI getCodingComplement()
2195 return this.codingComplement;
2199 * Set this as the (cDna/protein) complement of the given viewport. Also
2200 * ensures the reverse relationship is set on the given viewport.
2203 public void setCodingComplement(AlignViewportI av)
2207 System.err.println("Ignoring recursive setCodingComplement request");
2211 this.codingComplement = av;
2212 // avoid infinite recursion!
2213 if (av.getCodingComplement() != this)
2215 av.setCodingComplement(this);
2221 public boolean isNucleotide()
2223 return getAlignment() == null ? false : getAlignment().isNucleotide();
2227 public FeaturesDisplayedI getFeaturesDisplayed()
2229 return featuresDisplayed;
2233 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2235 featuresDisplayed = featuresDisplayedI;
2239 public boolean areFeaturesDisplayed()
2241 return featuresDisplayed != null
2242 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2249 * features are displayed if true
2252 public void setShowSequenceFeatures(boolean b)
2254 viewStyle.setShowSequenceFeatures(b);
2258 public boolean isShowSequenceFeatures()
2260 return viewStyle.isShowSequenceFeatures();
2264 public void setShowSequenceFeaturesHeight(boolean selected)
2266 viewStyle.setShowSequenceFeaturesHeight(selected);
2270 public boolean isShowSequenceFeaturesHeight()
2272 return viewStyle.isShowSequenceFeaturesHeight();
2276 public void setShowAnnotation(boolean b)
2278 viewStyle.setShowAnnotation(b);
2282 public boolean isShowAnnotation()
2284 return viewStyle.isShowAnnotation();
2288 public boolean isRightAlignIds()
2290 return viewStyle.isRightAlignIds();
2294 public void setRightAlignIds(boolean rightAlignIds)
2296 viewStyle.setRightAlignIds(rightAlignIds);
2300 public boolean getConservationSelected()
2302 return viewStyle.getConservationSelected();
2306 public void setShowBoxes(boolean state)
2308 viewStyle.setShowBoxes(state);
2313 * @see jalview.api.ViewStyleI#getTextColour()
2316 public Color getTextColour()
2318 return viewStyle.getTextColour();
2323 * @see jalview.api.ViewStyleI#getTextColour2()
2326 public Color getTextColour2()
2328 return viewStyle.getTextColour2();
2333 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2336 public int getThresholdTextColour()
2338 return viewStyle.getThresholdTextColour();
2343 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2346 public boolean isConservationColourSelected()
2348 return viewStyle.isConservationColourSelected();
2353 * @see jalview.api.ViewStyleI#isRenderGaps()
2356 public boolean isRenderGaps()
2358 return viewStyle.isRenderGaps();
2363 * @see jalview.api.ViewStyleI#isShowColourText()
2366 public boolean isShowColourText()
2368 return viewStyle.isShowColourText();
2372 * @param conservationColourSelected
2373 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2376 public void setConservationColourSelected(
2377 boolean conservationColourSelected)
2379 viewStyle.setConservationColourSelected(conservationColourSelected);
2383 * @param showColourText
2384 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2387 public void setShowColourText(boolean showColourText)
2389 viewStyle.setShowColourText(showColourText);
2394 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2397 public void setTextColour(Color textColour)
2399 viewStyle.setTextColour(textColour);
2403 * @param thresholdTextColour
2404 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2407 public void setThresholdTextColour(int thresholdTextColour)
2409 viewStyle.setThresholdTextColour(thresholdTextColour);
2413 * @param textColour2
2414 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2417 public void setTextColour2(Color textColour2)
2419 viewStyle.setTextColour2(textColour2);
2423 public ViewStyleI getViewStyle()
2425 return new ViewStyle(viewStyle);
2429 public void setViewStyle(ViewStyleI settingsForView)
2431 viewStyle = new ViewStyle(settingsForView);
2432 if (residueShading != null)
2434 residueShading.setConservationApplied(settingsForView
2435 .isConservationColourSelected());
2440 public boolean sameStyle(ViewStyleI them)
2442 return viewStyle.sameStyle(them);
2447 * @see jalview.api.ViewStyleI#getIdWidth()
2450 public int getIdWidth()
2452 return viewStyle.getIdWidth();
2457 * @see jalview.api.ViewStyleI#setIdWidth(int)
2460 public void setIdWidth(int i)
2462 viewStyle.setIdWidth(i);
2467 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2470 public boolean isCentreColumnLabels()
2472 return viewStyle.isCentreColumnLabels();
2476 * @param centreColumnLabels
2477 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2480 public void setCentreColumnLabels(boolean centreColumnLabels)
2482 viewStyle.setCentreColumnLabels(centreColumnLabels);
2487 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2490 public void setShowDBRefs(boolean showdbrefs)
2492 viewStyle.setShowDBRefs(showdbrefs);
2497 * @see jalview.api.ViewStyleI#isShowDBRefs()
2500 public boolean isShowDBRefs()
2502 return viewStyle.isShowDBRefs();
2507 * @see jalview.api.ViewStyleI#isShowNPFeats()
2510 public boolean isShowNPFeats()
2512 return viewStyle.isShowNPFeats();
2516 * @param shownpfeats
2517 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2520 public void setShowNPFeats(boolean shownpfeats)
2522 viewStyle.setShowNPFeats(shownpfeats);
2525 public abstract StructureSelectionManager getStructureSelectionManager();
2528 * Add one command to the command history list.
2532 public void addToHistoryList(CommandI command)
2534 if (this.historyList != null)
2536 this.historyList.push(command);
2537 broadcastCommand(command, false);
2541 protected void broadcastCommand(CommandI command, boolean undo)
2543 getStructureSelectionManager().commandPerformed(command, undo,
2548 * Add one command to the command redo list.
2552 public void addToRedoList(CommandI command)
2554 if (this.redoList != null)
2556 this.redoList.push(command);
2558 broadcastCommand(command, true);
2562 * Clear the command redo list.
2564 public void clearRedoList()
2566 if (this.redoList != null)
2568 this.redoList.clear();
2572 public void setHistoryList(Deque<CommandI> list)
2574 this.historyList = list;
2577 public Deque<CommandI> getHistoryList()
2579 return this.historyList;
2582 public void setRedoList(Deque<CommandI> list)
2584 this.redoList = list;
2587 public Deque<CommandI> getRedoList()
2589 return this.redoList;
2593 public VamsasSource getVamsasSource()
2598 public SequenceAnnotationOrder getSortAnnotationsBy()
2600 return sortAnnotationsBy;
2603 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2605 this.sortAnnotationsBy = sortAnnotationsBy;
2608 public boolean isShowAutocalculatedAbove()
2610 return showAutocalculatedAbove;
2613 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2615 this.showAutocalculatedAbove = showAutocalculatedAbove;
2619 public boolean isScaleProteinAsCdna()
2621 return viewStyle.isScaleProteinAsCdna();
2625 public void setScaleProteinAsCdna(boolean b)
2627 viewStyle.setScaleProteinAsCdna(b);
2631 * @return true if view should scroll to show the highlighted region of a
2636 public final boolean isFollowHighlight()
2638 return followHighlight;
2642 public final void setFollowHighlight(boolean b)
2644 this.followHighlight = b;
2648 public int getStartRes()
2654 public int getEndRes()
2660 public int getStartSeq()
2665 public void setStartRes(int res)
2667 this.startRes = res;
2670 public void setStartSeq(int seq)
2672 this.startSeq = seq;
2675 public void setEndRes(int res)
2677 if (res > alignment.getWidth() - 1)
2679 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2680 // (alignment.getWidth()-1));
2681 res = alignment.getWidth() - 1;
2690 public void setEndSeq(int seq)
2692 if (seq > alignment.getHeight())
2694 seq = alignment.getHeight();
2704 public int getEndSeq()
2710 * Helper method to populate the SearchResults with the location in the
2711 * complementary alignment to scroll to, in order to match this one.
2714 * the SearchResults to add to
2715 * @return the offset (below top of visible region) of the matched sequence
2717 protected int findComplementScrollTarget(SearchResultsI sr)
2719 final AlignViewportI complement = getCodingComplement();
2720 if (complement == null || !complement.isFollowHighlight())
2724 boolean iAmProtein = !getAlignment().isNucleotide();
2725 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2727 if (proteinAlignment == null)
2731 final List<AlignedCodonFrame> mappings = proteinAlignment
2735 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2736 * residue in the middle column of the visible region. Scroll the
2737 * complementary alignment to line up the corresponding residue.
2740 SequenceI sequence = null;
2743 * locate 'middle' column (true middle if an odd number visible, left of
2744 * middle if an even number visible)
2746 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2747 final HiddenSequences hiddenSequences = getAlignment()
2748 .getHiddenSequences();
2751 * searching to the bottom of the alignment gives smoother scrolling across
2752 * all gapped visible regions
2754 int lastSeq = alignment.getHeight() - 1;
2755 List<AlignedCodonFrame> seqMappings = null;
2756 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2758 sequence = getAlignment().getSequenceAt(seqNo);
2759 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2763 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2767 seqMappings = MappingUtils
2768 .findMappingsForSequenceAndOthers(sequence, mappings,
2769 getCodingComplement().getAlignment().getSequences());
2770 if (!seqMappings.isEmpty())
2776 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2779 * No ungapped mapped sequence in middle column - do nothing
2783 MappingUtils.addSearchResults(sr, sequence,
2784 sequence.findPosition(middleColumn), seqMappings);
2789 * synthesize a column selection if none exists so it covers the given
2790 * selection group. if wholewidth is false, no column selection is made if the
2791 * selection group covers the whole alignment width.
2796 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2799 if (sg != null && (sgs = sg.getStartRes()) >= 0
2800 && sg.getStartRes() <= (sge = sg.getEndRes())
2801 && !this.hasSelectedColumns())
2803 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2810 colSel = new ColumnSelection();
2812 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2814 colSel.addElement(cspos);
2820 * hold status of current selection group - defined on alignment or not.
2822 private boolean selectionIsDefinedGroup = false;
2826 public boolean isSelectionDefinedGroup()
2828 if (selectionGroup == null)
2832 if (isSelectionGroupChanged(true))
2834 selectionIsDefinedGroup = false;
2835 List<SequenceGroup> gps = alignment.getGroups();
2836 if (gps == null || gps.size() == 0)
2838 selectionIsDefinedGroup = false;
2842 selectionIsDefinedGroup = gps.contains(selectionGroup);
2845 return selectionGroup.getContext() == alignment
2846 || selectionIsDefinedGroup;
2850 * null, or currently highlighted results on this view
2852 private SearchResultsI searchResults = null;
2855 public boolean hasSearchResults()
2857 return searchResults != null;
2861 public void setSearchResults(SearchResultsI results)
2863 searchResults = results;
2867 public SearchResultsI getSearchResults()
2869 return searchResults;