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 // TODO private with getters and setters?
1289 public int startRes;
1293 public int startSeq;
1298 * Property change listener for changes in alignment
1303 public void addPropertyChangeListener(
1304 java.beans.PropertyChangeListener listener)
1306 changeSupport.addPropertyChangeListener(listener);
1315 public void removePropertyChangeListener(
1316 java.beans.PropertyChangeListener listener)
1318 changeSupport.removePropertyChangeListener(listener);
1322 * Property change listener for changes in alignment
1331 public void firePropertyChange(String prop, Object oldvalue,
1334 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1337 // common hide/show column stuff
1339 public void hideSelectedColumns()
1341 if (colSel.isEmpty())
1346 colSel.hideSelectedColumns();
1347 setSelectionGroup(null);
1348 isColSelChanged(true);
1351 public void hideColumns(int start, int end)
1355 colSel.hideColumns(start);
1359 colSel.hideColumns(start, end);
1361 isColSelChanged(true);
1364 public void showColumn(int col)
1366 colSel.revealHiddenColumns(col);
1367 isColSelChanged(true);
1370 public void showAllHiddenColumns()
1372 colSel.revealAllHiddenColumns();
1373 isColSelChanged(true);
1376 // common hide/show seq stuff
1377 public void showAllHiddenSeqs()
1379 if (alignment.getHiddenSequences().getSize() > 0)
1381 if (selectionGroup == null)
1383 selectionGroup = new SequenceGroup();
1384 selectionGroup.setEndRes(alignment.getWidth() - 1);
1386 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1387 hiddenRepSequences);
1388 for (SequenceI seq : tmp)
1390 selectionGroup.addSequence(seq, false);
1391 setSequenceAnnotationsVisible(seq, true);
1394 hiddenRepSequences = null;
1396 firePropertyChange("alignment", null, alignment.getSequences());
1397 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1403 public void showSequence(int index)
1405 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1406 index, hiddenRepSequences);
1409 if (selectionGroup == null)
1411 selectionGroup = new SequenceGroup();
1412 selectionGroup.setEndRes(alignment.getWidth() - 1);
1415 for (SequenceI seq : tmp)
1417 selectionGroup.addSequence(seq, false);
1418 setSequenceAnnotationsVisible(seq, true);
1420 firePropertyChange("alignment", null, alignment.getSequences());
1425 public void hideAllSelectedSeqs()
1427 if (selectionGroup == null || selectionGroup.getSize() < 1)
1432 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1436 setSelectionGroup(null);
1439 public void hideSequence(SequenceI[] seq)
1443 for (int i = 0; i < seq.length; i++)
1445 alignment.getHiddenSequences().hideSequence(seq[i]);
1446 setSequenceAnnotationsVisible(seq[i], false);
1448 firePropertyChange("alignment", null, alignment.getSequences());
1453 * Hides the specified sequence, or the sequences it represents
1456 * the sequence to hide, or keep as representative
1457 * @param representGroup
1458 * if true, hide the current selection group except for the
1459 * representative sequence
1461 public void hideSequences(SequenceI sequence, boolean representGroup)
1463 if (selectionGroup == null || selectionGroup.getSize() < 1)
1465 hideSequence(new SequenceI[] { sequence });
1471 hideRepSequences(sequence, selectionGroup);
1472 setSelectionGroup(null);
1476 int gsize = selectionGroup.getSize();
1477 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1478 new SequenceI[gsize]);
1480 hideSequence(hseqs);
1481 setSelectionGroup(null);
1486 * Set visibility for any annotations for the given sequence.
1490 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1493 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1496 for (AlignmentAnnotation ann : anns)
1498 if (ann.sequenceRef == sequenceI)
1500 ann.visible = visible;
1506 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1508 int sSize = sg.getSize();
1514 if (hiddenRepSequences == null)
1516 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1519 hiddenRepSequences.put(repSequence, sg);
1521 // Hide all sequences except the repSequence
1522 SequenceI[] seqs = new SequenceI[sSize - 1];
1524 for (int i = 0; i < sSize; i++)
1526 if (sg.getSequenceAt(i) != repSequence)
1528 if (index == sSize - 1)
1533 seqs[index++] = sg.getSequenceAt(i);
1536 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1537 sg.setHidereps(true); // note: not done in 2.7applet
1544 * @return null or the current reference sequence
1546 public SequenceI getReferenceSeq()
1548 return alignment.getSeqrep();
1553 * @return true iff seq is the reference for the alignment
1555 public boolean isReferenceSeq(SequenceI seq)
1557 return alignment.getSeqrep() == seq;
1563 * @return true if there are sequences represented by this sequence that are
1566 public boolean isHiddenRepSequence(SequenceI seq)
1568 return (hiddenRepSequences != null && hiddenRepSequences
1575 * @return null or a sequence group containing the sequences that seq
1578 public SequenceGroup getRepresentedSequences(SequenceI seq)
1580 return (SequenceGroup) (hiddenRepSequences == null ? null
1581 : hiddenRepSequences.get(seq));
1585 public int adjustForHiddenSeqs(int alignmentIndex)
1587 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1592 public void invertColumnSelection()
1594 colSel.invertColumnSelection(0, alignment.getWidth());
1598 public SequenceI[] getSelectionAsNewSequence()
1600 SequenceI[] sequences;
1601 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1602 // this was the only caller in the applet for this method
1603 // JBPNote: in applet, this method returned references to the alignment
1604 // sequences, and it did not honour the presence/absence of annotation
1605 // attached to the alignment (probably!)
1606 if (selectionGroup == null || selectionGroup.getSize() == 0)
1608 sequences = alignment.getSequencesArray();
1609 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1610 for (int i = 0; i < sequences.length; i++)
1612 // construct new sequence with subset of visible annotation
1613 sequences[i] = new Sequence(sequences[i], annots);
1618 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1625 public SequenceI[] getSequenceSelection()
1627 SequenceI[] sequences = null;
1628 if (selectionGroup != null)
1630 sequences = selectionGroup.getSequencesInOrder(alignment);
1632 if (sequences == null)
1634 sequences = alignment.getSequencesArray();
1640 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1642 return new CigarArray(alignment, colSel,
1643 (selectedRegionOnly ? selectionGroup : null));
1647 public jalview.datamodel.AlignmentView getAlignmentView(
1648 boolean selectedOnly)
1650 return getAlignmentView(selectedOnly, false);
1654 public jalview.datamodel.AlignmentView getAlignmentView(
1655 boolean selectedOnly, boolean markGroups)
1657 return new AlignmentView(alignment, colSel, selectionGroup,
1658 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1663 public String[] getViewAsString(boolean selectedRegionOnly)
1665 return getViewAsString(selectedRegionOnly, true);
1669 public String[] getViewAsString(boolean selectedRegionOnly,
1670 boolean exportHiddenSeqs)
1672 String[] selection = null;
1673 SequenceI[] seqs = null;
1675 int start = 0, end = 0;
1676 if (selectedRegionOnly && selectionGroup != null)
1678 iSize = selectionGroup.getSize();
1679 seqs = selectionGroup.getSequencesInOrder(alignment);
1680 start = selectionGroup.getStartRes();
1681 end = selectionGroup.getEndRes() + 1;
1685 if (hasHiddenRows() && exportHiddenSeqs)
1687 AlignmentI fullAlignment = alignment.getHiddenSequences()
1688 .getFullAlignment();
1689 iSize = fullAlignment.getHeight();
1690 seqs = fullAlignment.getSequencesArray();
1691 end = fullAlignment.getWidth();
1695 iSize = alignment.getHeight();
1696 seqs = alignment.getSequencesArray();
1697 end = alignment.getWidth();
1701 selection = new String[iSize];
1702 if (colSel != null && colSel.hasHiddenColumns())
1704 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1708 for (i = 0; i < iSize; i++)
1710 selection[i] = seqs[i].getSequenceAsString(start, end);
1718 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1720 ArrayList<int[]> regions = new ArrayList<int[]>();
1726 if (colSel != null && colSel.hasHiddenColumns())
1730 start = colSel.adjustForHiddenColumns(start);
1733 end = colSel.getHiddenBoundaryRight(start);
1744 regions.add(new int[] { start, end });
1746 if (colSel != null && colSel.hasHiddenColumns())
1748 start = colSel.adjustForHiddenColumns(end);
1749 start = colSel.getHiddenBoundaryLeft(start) + 1;
1751 } while (end < max);
1753 int[][] startEnd = new int[regions.size()][2];
1759 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1760 boolean selectedOnly)
1762 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1763 AlignmentAnnotation[] aa;
1764 if ((aa = alignment.getAlignmentAnnotation()) != null)
1766 for (AlignmentAnnotation annot : aa)
1768 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1769 if (selectedOnly && selectionGroup != null)
1771 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1772 selectionGroup.getEndRes(), clone);
1776 colSel.makeVisibleAnnotation(clone);
1785 public boolean isPadGaps()
1791 public void setPadGaps(boolean padGaps)
1793 this.padGaps = padGaps;
1797 * apply any post-edit constraints and trigger any calculations needed after
1798 * an edit has been performed on the alignment
1803 public void alignmentChanged(AlignmentViewPanel ap)
1807 alignment.padGaps();
1809 if (autoCalculateConsensus)
1811 updateConsensus(ap);
1813 if (hconsensus != null && autoCalculateConsensus)
1815 updateConservation(ap);
1817 if (autoCalculateStrucConsensus)
1819 updateStrucConsensus(ap);
1822 // Reset endRes of groups if beyond alignment width
1823 int alWidth = alignment.getWidth();
1824 List<SequenceGroup> groups = alignment.getGroups();
1827 for (SequenceGroup sg : groups)
1829 if (sg.getEndRes() > alWidth)
1831 sg.setEndRes(alWidth - 1);
1836 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1838 selectionGroup.setEndRes(alWidth - 1);
1841 updateAllColourSchemes();
1842 calculator.restartWorkers();
1843 // alignment.adjustSequenceAnnotations();
1847 * reset scope and do calculations for all applied colourschemes on alignment
1849 void updateAllColourSchemes()
1851 ResidueShaderI rs = residueShading;
1854 rs.alignmentChanged(alignment, hiddenRepSequences);
1856 rs.setConsensus(hconsensus);
1857 if (rs.conservationApplied())
1859 rs.setConservation(Conservation.calculateConservation("All",
1860 alignment.getSequences(), 0, alignment.getWidth(), false,
1861 getConsPercGaps(), false));
1865 for (SequenceGroup sg : alignment.getGroups())
1869 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1871 sg.recalcConservation();
1875 protected void initAutoAnnotation()
1877 // TODO: add menu option action that nulls or creates consensus object
1878 // depending on if the user wants to see the annotation or not in a
1879 // specific alignment
1881 if (hconsensus == null && !isDataset)
1883 if (!alignment.isNucleotide())
1892 consensus = new AlignmentAnnotation("Consensus", "PID",
1893 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1894 initConsensus(consensus);
1896 initComplementConsensus();
1901 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1902 * consensus annotation.
1904 public void initComplementConsensus()
1906 if (!alignment.isNucleotide())
1908 final List<AlignedCodonFrame> codonMappings = alignment
1910 if (codonMappings != null && !codonMappings.isEmpty())
1912 boolean doConsensus = false;
1913 for (AlignedCodonFrame mapping : codonMappings)
1915 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1916 MapList[] mapLists = mapping.getdnaToProt();
1917 // mapLists can be empty if project load has not finished resolving
1919 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1927 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1928 "PID for cDNA", new Annotation[1], 0f, 100f,
1929 AlignmentAnnotation.BAR_GRAPH);
1930 initConsensus(complementConsensus);
1936 private void initConsensus(AlignmentAnnotation aa)
1939 aa.autoCalculated = true;
1943 alignment.addAnnotation(aa);
1947 private void initConservation()
1949 if (showConservation)
1951 if (conservation == null)
1953 conservation = new AlignmentAnnotation("Conservation",
1954 "Conservation of total alignment less than "
1955 + getConsPercGaps() + "% gaps", new Annotation[1],
1956 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1957 conservation.hasText = true;
1958 conservation.autoCalculated = true;
1959 alignment.addAnnotation(conservation);
1964 private void initQuality()
1968 if (quality == null)
1970 quality = new AlignmentAnnotation("Quality",
1971 "Alignment Quality based on Blosum62 scores",
1972 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1973 quality.hasText = true;
1974 quality.autoCalculated = true;
1975 alignment.addAnnotation(quality);
1980 private void initRNAStructure()
1982 if (alignment.hasRNAStructure() && strucConsensus == null)
1984 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1985 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1986 strucConsensus.hasText = true;
1987 strucConsensus.autoCalculated = true;
1991 alignment.addAnnotation(strucConsensus);
1999 * @see jalview.api.AlignViewportI#calcPanelHeight()
2002 public int calcPanelHeight()
2004 // setHeight of panels
2005 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2007 int charHeight = getCharHeight();
2010 BitSet graphgrp = new BitSet();
2011 for (AlignmentAnnotation aa : anns)
2015 System.err.println("Null annotation row: ignoring.");
2022 if (aa.graphGroup > -1)
2024 if (graphgrp.get(aa.graphGroup))
2030 graphgrp.set(aa.graphGroup);
2037 aa.height += charHeight;
2047 aa.height += aa.graphHeight;
2055 height += aa.height;
2067 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2068 boolean preserveNewGroupSettings)
2070 boolean updateCalcs = false;
2071 boolean conv = isShowGroupConservation();
2072 boolean cons = isShowGroupConsensus();
2073 boolean showprf = isShowSequenceLogo();
2074 boolean showConsHist = isShowConsensusHistogram();
2075 boolean normLogo = isNormaliseSequenceLogo();
2078 * TODO reorder the annotation rows according to group/sequence ordering on
2081 boolean sortg = true;
2083 // remove old automatic annotation
2084 // add any new annotation
2086 // intersect alignment annotation with alignment groups
2088 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2089 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2092 for (int an = 0; an < aan.length; an++)
2094 if (aan[an].autoCalculated && aan[an].groupRef != null)
2096 oldrfs.add(aan[an].groupRef);
2097 alignment.deleteAnnotation(aan[an], false);
2101 if (alignment.getGroups() != null)
2103 for (SequenceGroup sg : alignment.getGroups())
2105 updateCalcs = false;
2106 if (applyGlobalSettings
2107 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2109 // set defaults for this group's conservation/consensus
2110 sg.setshowSequenceLogo(showprf);
2111 sg.setShowConsensusHistogram(showConsHist);
2112 sg.setNormaliseSequenceLogo(normLogo);
2117 alignment.addAnnotation(sg.getConservationRow(), 0);
2122 alignment.addAnnotation(sg.getConsensus(), 0);
2124 // refresh the annotation rows
2127 sg.recalcConservation();
2135 public boolean isDisplayReferenceSeq()
2137 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2141 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2143 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2147 public boolean isColourByReferenceSeq()
2149 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2153 public Color getSequenceColour(SequenceI seq)
2155 Color sqc = sequenceColours.get(seq);
2156 return (sqc == null ? Color.white : sqc);
2160 public void setSequenceColour(SequenceI seq, Color col)
2164 sequenceColours.remove(seq);
2168 sequenceColours.put(seq, col);
2173 public void updateSequenceIdColours()
2175 for (SequenceGroup sg : alignment.getGroups())
2177 if (sg.idColour != null)
2179 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2181 sequenceColours.put(s, sg.idColour);
2188 public void clearSequenceColours()
2190 sequenceColours.clear();
2194 public AlignViewportI getCodingComplement()
2196 return this.codingComplement;
2200 * Set this as the (cDna/protein) complement of the given viewport. Also
2201 * ensures the reverse relationship is set on the given viewport.
2204 public void setCodingComplement(AlignViewportI av)
2208 System.err.println("Ignoring recursive setCodingComplement request");
2212 this.codingComplement = av;
2213 // avoid infinite recursion!
2214 if (av.getCodingComplement() != this)
2216 av.setCodingComplement(this);
2222 public boolean isNucleotide()
2224 return getAlignment() == null ? false : getAlignment().isNucleotide();
2228 public FeaturesDisplayedI getFeaturesDisplayed()
2230 return featuresDisplayed;
2234 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2236 featuresDisplayed = featuresDisplayedI;
2240 public boolean areFeaturesDisplayed()
2242 return featuresDisplayed != null
2243 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2250 * features are displayed if true
2253 public void setShowSequenceFeatures(boolean b)
2255 viewStyle.setShowSequenceFeatures(b);
2259 public boolean isShowSequenceFeatures()
2261 return viewStyle.isShowSequenceFeatures();
2265 public void setShowSequenceFeaturesHeight(boolean selected)
2267 viewStyle.setShowSequenceFeaturesHeight(selected);
2271 public boolean isShowSequenceFeaturesHeight()
2273 return viewStyle.isShowSequenceFeaturesHeight();
2277 public void setShowAnnotation(boolean b)
2279 viewStyle.setShowAnnotation(b);
2283 public boolean isShowAnnotation()
2285 return viewStyle.isShowAnnotation();
2289 public boolean isRightAlignIds()
2291 return viewStyle.isRightAlignIds();
2295 public void setRightAlignIds(boolean rightAlignIds)
2297 viewStyle.setRightAlignIds(rightAlignIds);
2301 public boolean getConservationSelected()
2303 return viewStyle.getConservationSelected();
2307 public void setShowBoxes(boolean state)
2309 viewStyle.setShowBoxes(state);
2314 * @see jalview.api.ViewStyleI#getTextColour()
2317 public Color getTextColour()
2319 return viewStyle.getTextColour();
2324 * @see jalview.api.ViewStyleI#getTextColour2()
2327 public Color getTextColour2()
2329 return viewStyle.getTextColour2();
2334 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2337 public int getThresholdTextColour()
2339 return viewStyle.getThresholdTextColour();
2344 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2347 public boolean isConservationColourSelected()
2349 return viewStyle.isConservationColourSelected();
2354 * @see jalview.api.ViewStyleI#isRenderGaps()
2357 public boolean isRenderGaps()
2359 return viewStyle.isRenderGaps();
2364 * @see jalview.api.ViewStyleI#isShowColourText()
2367 public boolean isShowColourText()
2369 return viewStyle.isShowColourText();
2373 * @param conservationColourSelected
2374 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2377 public void setConservationColourSelected(
2378 boolean conservationColourSelected)
2380 viewStyle.setConservationColourSelected(conservationColourSelected);
2384 * @param showColourText
2385 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2388 public void setShowColourText(boolean showColourText)
2390 viewStyle.setShowColourText(showColourText);
2395 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2398 public void setTextColour(Color textColour)
2400 viewStyle.setTextColour(textColour);
2404 * @param thresholdTextColour
2405 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2408 public void setThresholdTextColour(int thresholdTextColour)
2410 viewStyle.setThresholdTextColour(thresholdTextColour);
2414 * @param textColour2
2415 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2418 public void setTextColour2(Color textColour2)
2420 viewStyle.setTextColour2(textColour2);
2424 public ViewStyleI getViewStyle()
2426 return new ViewStyle(viewStyle);
2430 public void setViewStyle(ViewStyleI settingsForView)
2432 viewStyle = new ViewStyle(settingsForView);
2433 if (residueShading != null)
2435 residueShading.setConservationApplied(settingsForView
2436 .isConservationColourSelected());
2441 public boolean sameStyle(ViewStyleI them)
2443 return viewStyle.sameStyle(them);
2448 * @see jalview.api.ViewStyleI#getIdWidth()
2451 public int getIdWidth()
2453 return viewStyle.getIdWidth();
2458 * @see jalview.api.ViewStyleI#setIdWidth(int)
2461 public void setIdWidth(int i)
2463 viewStyle.setIdWidth(i);
2468 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2471 public boolean isCentreColumnLabels()
2473 return viewStyle.isCentreColumnLabels();
2477 * @param centreColumnLabels
2478 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2481 public void setCentreColumnLabels(boolean centreColumnLabels)
2483 viewStyle.setCentreColumnLabels(centreColumnLabels);
2488 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2491 public void setShowDBRefs(boolean showdbrefs)
2493 viewStyle.setShowDBRefs(showdbrefs);
2498 * @see jalview.api.ViewStyleI#isShowDBRefs()
2501 public boolean isShowDBRefs()
2503 return viewStyle.isShowDBRefs();
2508 * @see jalview.api.ViewStyleI#isShowNPFeats()
2511 public boolean isShowNPFeats()
2513 return viewStyle.isShowNPFeats();
2517 * @param shownpfeats
2518 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2521 public void setShowNPFeats(boolean shownpfeats)
2523 viewStyle.setShowNPFeats(shownpfeats);
2526 public abstract StructureSelectionManager getStructureSelectionManager();
2529 * Add one command to the command history list.
2533 public void addToHistoryList(CommandI command)
2535 if (this.historyList != null)
2537 this.historyList.push(command);
2538 broadcastCommand(command, false);
2542 protected void broadcastCommand(CommandI command, boolean undo)
2544 getStructureSelectionManager().commandPerformed(command, undo,
2549 * Add one command to the command redo list.
2553 public void addToRedoList(CommandI command)
2555 if (this.redoList != null)
2557 this.redoList.push(command);
2559 broadcastCommand(command, true);
2563 * Clear the command redo list.
2565 public void clearRedoList()
2567 if (this.redoList != null)
2569 this.redoList.clear();
2573 public void setHistoryList(Deque<CommandI> list)
2575 this.historyList = list;
2578 public Deque<CommandI> getHistoryList()
2580 return this.historyList;
2583 public void setRedoList(Deque<CommandI> list)
2585 this.redoList = list;
2588 public Deque<CommandI> getRedoList()
2590 return this.redoList;
2594 public VamsasSource getVamsasSource()
2599 public SequenceAnnotationOrder getSortAnnotationsBy()
2601 return sortAnnotationsBy;
2604 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2606 this.sortAnnotationsBy = sortAnnotationsBy;
2609 public boolean isShowAutocalculatedAbove()
2611 return showAutocalculatedAbove;
2614 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2616 this.showAutocalculatedAbove = showAutocalculatedAbove;
2620 public boolean isScaleProteinAsCdna()
2622 return viewStyle.isScaleProteinAsCdna();
2626 public void setScaleProteinAsCdna(boolean b)
2628 viewStyle.setScaleProteinAsCdna(b);
2632 * @return true if view should scroll to show the highlighted region of a
2637 public final boolean isFollowHighlight()
2639 return followHighlight;
2643 public final void setFollowHighlight(boolean b)
2645 this.followHighlight = b;
2648 public int getStartRes()
2654 public int getEndRes()
2659 public int getStartSeq()
2664 public void setStartRes(int res)
2666 this.startRes = res;
2669 public void setStartSeq(int seq)
2671 this.startSeq = seq;
2674 public void setEndRes(int res)
2676 if (res > alignment.getWidth() - 1)
2678 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2679 // (alignment.getWidth()-1));
2680 res = alignment.getWidth() - 1;
2689 public void setEndSeq(int seq)
2691 if (seq > alignment.getHeight())
2693 seq = alignment.getHeight();
2702 public int getEndSeq()
2708 * Helper method to populate the SearchResults with the location in the
2709 * complementary alignment to scroll to, in order to match this one.
2712 * the SearchResults to add to
2713 * @return the offset (below top of visible region) of the matched sequence
2715 protected int findComplementScrollTarget(SearchResultsI sr)
2717 final AlignViewportI complement = getCodingComplement();
2718 if (complement == null || !complement.isFollowHighlight())
2722 boolean iAmProtein = !getAlignment().isNucleotide();
2723 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2725 if (proteinAlignment == null)
2729 final List<AlignedCodonFrame> mappings = proteinAlignment
2733 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2734 * residue in the middle column of the visible region. Scroll the
2735 * complementary alignment to line up the corresponding residue.
2738 SequenceI sequence = null;
2741 * locate 'middle' column (true middle if an odd number visible, left of
2742 * middle if an even number visible)
2744 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2745 final HiddenSequences hiddenSequences = getAlignment()
2746 .getHiddenSequences();
2749 * searching to the bottom of the alignment gives smoother scrolling across
2750 * all gapped visible regions
2752 int lastSeq = alignment.getHeight() - 1;
2753 List<AlignedCodonFrame> seqMappings = null;
2754 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2756 sequence = getAlignment().getSequenceAt(seqNo);
2757 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2761 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2765 seqMappings = MappingUtils
2766 .findMappingsForSequenceAndOthers(sequence, mappings,
2767 getCodingComplement().getAlignment().getSequences());
2768 if (!seqMappings.isEmpty())
2774 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2777 * No ungapped mapped sequence in middle column - do nothing
2781 MappingUtils.addSearchResults(sr, sequence,
2782 sequence.findPosition(middleColumn), seqMappings);
2787 * synthesize a column selection if none exists so it covers the given
2788 * selection group. if wholewidth is false, no column selection is made if the
2789 * selection group covers the whole alignment width.
2794 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2797 if (sg != null && (sgs = sg.getStartRes()) >= 0
2798 && sg.getStartRes() <= (sge = sg.getEndRes())
2799 && !this.hasSelectedColumns())
2801 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2808 colSel = new ColumnSelection();
2810 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2812 colSel.addElement(cspos);
2818 * hold status of current selection group - defined on alignment or not.
2820 private boolean selectionIsDefinedGroup = false;
2824 public boolean isSelectionDefinedGroup()
2826 if (selectionGroup == null)
2830 if (isSelectionGroupChanged(true))
2832 selectionIsDefinedGroup = false;
2833 List<SequenceGroup> gps = alignment.getGroups();
2834 if (gps == null || gps.size() == 0)
2836 selectionIsDefinedGroup = false;
2840 selectionIsDefinedGroup = gps.contains(selectionGroup);
2843 return selectionGroup.getContext() == alignment
2844 || selectionIsDefinedGroup;
2848 * null, or currently highlighted results on this view
2850 private SearchResultsI searchResults = null;
2853 public boolean hasSearchResults()
2855 return searchResults != null;
2859 public void setSearchResults(SearchResultsI results)
2861 searchResults = results;
2865 public SearchResultsI getSearchResults()
2867 return searchResults;