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.
1079 * - group holding references to sequences in this alignment view
1083 public void setSelectionGroup(SequenceGroup sg)
1085 selectionGroup = sg;
1088 public void setHiddenColumns(ColumnSelection colsel)
1090 this.colSel = colsel;
1094 public ColumnSelection getColumnSelection()
1100 public void setColumnSelection(ColumnSelection colSel)
1102 this.colSel = colSel;
1105 updateHiddenColumns();
1107 isColSelChanged(true);
1115 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1117 return hiddenRepSequences;
1121 public void setHiddenRepSequences(
1122 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1124 this.hiddenRepSequences = hiddenRepSequences;
1128 public boolean hasSelectedColumns()
1130 ColumnSelection columnSelection = getColumnSelection();
1131 return columnSelection != null && columnSelection.hasSelectedColumns();
1135 public boolean hasHiddenColumns()
1137 return colSel != null && colSel.hasHiddenColumns();
1140 public void updateHiddenColumns()
1142 // this method doesn't really do anything now. But - it could, since a
1143 // column Selection could be in the process of modification
1144 // hasHiddenColumns = colSel.hasHiddenColumns();
1148 public boolean hasHiddenRows()
1150 return alignment.getHiddenSequences().getSize() > 0;
1153 protected SequenceGroup selectionGroup;
1155 public void setSequenceSetId(String newid)
1157 if (sequenceSetID != null)
1160 .println("Warning - overwriting a sequenceSetId for a viewport!");
1162 sequenceSetID = new String(newid);
1166 public String getSequenceSetId()
1168 if (sequenceSetID == null)
1170 sequenceSetID = alignment.hashCode() + "";
1173 return sequenceSetID;
1177 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1180 protected String viewId = null;
1183 public String getViewId()
1187 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1192 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1194 ignoreGapsInConsensusCalculation = b;
1197 updateConsensus(ap);
1198 if (residueShading != null)
1200 residueShading.setThreshold(residueShading.getThreshold(),
1201 ignoreGapsInConsensusCalculation);
1207 private long sgrouphash = -1, colselhash = -1;
1210 * checks current SelectionGroup against record of last hash value, and
1214 * update the record of last hash value
1216 * @return true if SelectionGroup changed since last call (when b is true)
1218 public boolean isSelectionGroupChanged(boolean b)
1220 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1221 : selectionGroup.hashCode();
1222 if (hc != -1 && hc != sgrouphash)
1234 * checks current colsel against record of last hash value, and optionally
1238 * update the record of last hash value
1239 * @return true if colsel changed since last call (when b is true)
1241 public boolean isColSelChanged(boolean b)
1243 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1244 if (hc != -1 && hc != colselhash)
1256 public boolean isIgnoreGapsConsensus()
1258 return ignoreGapsInConsensusCalculation;
1261 // property change stuff
1262 // JBPNote Prolly only need this in the applet version.
1263 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1266 protected boolean showConservation = true;
1268 protected boolean showQuality = true;
1270 protected boolean showConsensus = true;
1272 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1274 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1276 protected boolean showAutocalculatedAbove;
1279 * when set, view will scroll to show the highlighted position
1281 private boolean followHighlight = true;
1283 // TODO private with getters and setters?
1284 public int startRes;
1288 public int startSeq;
1293 * Property change listener for changes in alignment
1298 public void addPropertyChangeListener(
1299 java.beans.PropertyChangeListener listener)
1301 changeSupport.addPropertyChangeListener(listener);
1310 public void removePropertyChangeListener(
1311 java.beans.PropertyChangeListener listener)
1313 changeSupport.removePropertyChangeListener(listener);
1317 * Property change listener for changes in alignment
1326 public void firePropertyChange(String prop, Object oldvalue,
1329 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1332 // common hide/show column stuff
1334 public void hideSelectedColumns()
1336 if (colSel.isEmpty())
1341 colSel.hideSelectedColumns();
1342 setSelectionGroup(null);
1343 isColSelChanged(true);
1346 public void hideColumns(int start, int end)
1350 colSel.hideColumns(start);
1354 colSel.hideColumns(start, end);
1356 isColSelChanged(true);
1359 public void showColumn(int col)
1361 colSel.revealHiddenColumns(col);
1362 isColSelChanged(true);
1365 public void showAllHiddenColumns()
1367 colSel.revealAllHiddenColumns();
1368 isColSelChanged(true);
1371 // common hide/show seq stuff
1372 public void showAllHiddenSeqs()
1374 if (alignment.getHiddenSequences().getSize() > 0)
1376 if (selectionGroup == null)
1378 selectionGroup = new SequenceGroup();
1379 selectionGroup.setEndRes(alignment.getWidth() - 1);
1381 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1382 hiddenRepSequences);
1383 for (SequenceI seq : tmp)
1385 selectionGroup.addSequence(seq, false);
1386 setSequenceAnnotationsVisible(seq, true);
1389 hiddenRepSequences = null;
1391 firePropertyChange("alignment", null, alignment.getSequences());
1392 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1398 public void showSequence(int index)
1400 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1401 index, hiddenRepSequences);
1404 if (selectionGroup == null)
1406 selectionGroup = new SequenceGroup();
1407 selectionGroup.setEndRes(alignment.getWidth() - 1);
1410 for (SequenceI seq : tmp)
1412 selectionGroup.addSequence(seq, false);
1413 setSequenceAnnotationsVisible(seq, true);
1415 firePropertyChange("alignment", null, alignment.getSequences());
1420 public void hideAllSelectedSeqs()
1422 if (selectionGroup == null || selectionGroup.getSize() < 1)
1427 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1431 setSelectionGroup(null);
1434 public void hideSequence(SequenceI[] seq)
1438 for (int i = 0; i < seq.length; i++)
1440 alignment.getHiddenSequences().hideSequence(seq[i]);
1441 setSequenceAnnotationsVisible(seq[i], false);
1443 firePropertyChange("alignment", null, alignment.getSequences());
1448 * Hides the specified sequence, or the sequences it represents
1451 * the sequence to hide, or keep as representative
1452 * @param representGroup
1453 * if true, hide the current selection group except for the
1454 * representative sequence
1456 public void hideSequences(SequenceI sequence, boolean representGroup)
1458 if (selectionGroup == null || selectionGroup.getSize() < 1)
1460 hideSequence(new SequenceI[] { sequence });
1466 hideRepSequences(sequence, selectionGroup);
1467 setSelectionGroup(null);
1471 int gsize = selectionGroup.getSize();
1472 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1473 new SequenceI[gsize]);
1475 hideSequence(hseqs);
1476 setSelectionGroup(null);
1481 * Set visibility for any annotations for the given sequence.
1485 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1488 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1491 for (AlignmentAnnotation ann : anns)
1493 if (ann.sequenceRef == sequenceI)
1495 ann.visible = visible;
1501 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1503 int sSize = sg.getSize();
1509 if (hiddenRepSequences == null)
1511 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1514 hiddenRepSequences.put(repSequence, sg);
1516 // Hide all sequences except the repSequence
1517 SequenceI[] seqs = new SequenceI[sSize - 1];
1519 for (int i = 0; i < sSize; i++)
1521 if (sg.getSequenceAt(i) != repSequence)
1523 if (index == sSize - 1)
1528 seqs[index++] = sg.getSequenceAt(i);
1531 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1532 sg.setHidereps(true); // note: not done in 2.7applet
1539 * @return null or the current reference sequence
1541 public SequenceI getReferenceSeq()
1543 return alignment.getSeqrep();
1548 * @return true iff seq is the reference for the alignment
1550 public boolean isReferenceSeq(SequenceI seq)
1552 return alignment.getSeqrep() == seq;
1558 * @return true if there are sequences represented by this sequence that are
1561 public boolean isHiddenRepSequence(SequenceI seq)
1563 return (hiddenRepSequences != null && hiddenRepSequences
1570 * @return null or a sequence group containing the sequences that seq
1573 public SequenceGroup getRepresentedSequences(SequenceI seq)
1575 return (SequenceGroup) (hiddenRepSequences == null ? null
1576 : hiddenRepSequences.get(seq));
1580 public int adjustForHiddenSeqs(int alignmentIndex)
1582 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1587 public void invertColumnSelection()
1589 colSel.invertColumnSelection(0, alignment.getWidth());
1593 public SequenceI[] getSelectionAsNewSequence()
1595 SequenceI[] sequences;
1596 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1597 // this was the only caller in the applet for this method
1598 // JBPNote: in applet, this method returned references to the alignment
1599 // sequences, and it did not honour the presence/absence of annotation
1600 // attached to the alignment (probably!)
1601 if (selectionGroup == null || selectionGroup.getSize() == 0)
1603 sequences = alignment.getSequencesArray();
1604 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1605 for (int i = 0; i < sequences.length; i++)
1607 // construct new sequence with subset of visible annotation
1608 sequences[i] = new Sequence(sequences[i], annots);
1613 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1620 public SequenceI[] getSequenceSelection()
1622 SequenceI[] sequences = null;
1623 if (selectionGroup != null)
1625 sequences = selectionGroup.getSequencesInOrder(alignment);
1627 if (sequences == null)
1629 sequences = alignment.getSequencesArray();
1635 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1637 return new CigarArray(alignment, colSel,
1638 (selectedRegionOnly ? selectionGroup : null));
1642 public jalview.datamodel.AlignmentView getAlignmentView(
1643 boolean selectedOnly)
1645 return getAlignmentView(selectedOnly, false);
1649 public jalview.datamodel.AlignmentView getAlignmentView(
1650 boolean selectedOnly, boolean markGroups)
1652 return new AlignmentView(alignment, colSel, selectionGroup,
1653 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1658 public String[] getViewAsString(boolean selectedRegionOnly)
1660 return getViewAsString(selectedRegionOnly, true);
1664 public String[] getViewAsString(boolean selectedRegionOnly,
1665 boolean exportHiddenSeqs)
1667 String[] selection = null;
1668 SequenceI[] seqs = null;
1670 int start = 0, end = 0;
1671 if (selectedRegionOnly && selectionGroup != null)
1673 iSize = selectionGroup.getSize();
1674 seqs = selectionGroup.getSequencesInOrder(alignment);
1675 start = selectionGroup.getStartRes();
1676 end = selectionGroup.getEndRes() + 1;
1680 if (hasHiddenRows() && exportHiddenSeqs)
1682 AlignmentI fullAlignment = alignment.getHiddenSequences()
1683 .getFullAlignment();
1684 iSize = fullAlignment.getHeight();
1685 seqs = fullAlignment.getSequencesArray();
1686 end = fullAlignment.getWidth();
1690 iSize = alignment.getHeight();
1691 seqs = alignment.getSequencesArray();
1692 end = alignment.getWidth();
1696 selection = new String[iSize];
1697 if (colSel != null && colSel.hasHiddenColumns())
1699 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1703 for (i = 0; i < iSize; i++)
1705 selection[i] = seqs[i].getSequenceAsString(start, end);
1713 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1715 ArrayList<int[]> regions = new ArrayList<int[]>();
1721 if (colSel != null && colSel.hasHiddenColumns())
1725 start = colSel.adjustForHiddenColumns(start);
1728 end = colSel.getHiddenBoundaryRight(start);
1739 regions.add(new int[] { start, end });
1741 if (colSel != null && colSel.hasHiddenColumns())
1743 start = colSel.adjustForHiddenColumns(end);
1744 start = colSel.getHiddenBoundaryLeft(start) + 1;
1746 } while (end < max);
1748 int[][] startEnd = new int[regions.size()][2];
1754 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1755 boolean selectedOnly)
1757 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1758 AlignmentAnnotation[] aa;
1759 if ((aa = alignment.getAlignmentAnnotation()) != null)
1761 for (AlignmentAnnotation annot : aa)
1763 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1764 if (selectedOnly && selectionGroup != null)
1766 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1767 selectionGroup.getEndRes(), clone);
1771 colSel.makeVisibleAnnotation(clone);
1780 public boolean isPadGaps()
1786 public void setPadGaps(boolean padGaps)
1788 this.padGaps = padGaps;
1792 * apply any post-edit constraints and trigger any calculations needed after
1793 * an edit has been performed on the alignment
1798 public void alignmentChanged(AlignmentViewPanel ap)
1802 alignment.padGaps();
1804 if (autoCalculateConsensus)
1806 updateConsensus(ap);
1808 if (hconsensus != null && autoCalculateConsensus)
1810 updateConservation(ap);
1812 if (autoCalculateStrucConsensus)
1814 updateStrucConsensus(ap);
1817 // Reset endRes of groups if beyond alignment width
1818 int alWidth = alignment.getWidth();
1819 List<SequenceGroup> groups = alignment.getGroups();
1822 for (SequenceGroup sg : groups)
1824 if (sg.getEndRes() > alWidth)
1826 sg.setEndRes(alWidth - 1);
1831 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1833 selectionGroup.setEndRes(alWidth - 1);
1836 updateAllColourSchemes();
1837 calculator.restartWorkers();
1838 // alignment.adjustSequenceAnnotations();
1842 * reset scope and do calculations for all applied colourschemes on alignment
1844 void updateAllColourSchemes()
1846 ResidueShaderI rs = residueShading;
1849 rs.alignmentChanged(alignment, hiddenRepSequences);
1851 rs.setConsensus(hconsensus);
1852 if (rs.conservationApplied())
1854 rs.setConservation(Conservation.calculateConservation("All",
1855 alignment.getSequences(), 0, alignment.getWidth(), false,
1856 getConsPercGaps(), false));
1860 for (SequenceGroup sg : alignment.getGroups())
1864 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1866 sg.recalcConservation();
1870 protected void initAutoAnnotation()
1872 // TODO: add menu option action that nulls or creates consensus object
1873 // depending on if the user wants to see the annotation or not in a
1874 // specific alignment
1876 if (hconsensus == null && !isDataset)
1878 if (!alignment.isNucleotide())
1887 consensus = new AlignmentAnnotation("Consensus", "PID",
1888 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1889 initConsensus(consensus);
1891 initComplementConsensus();
1896 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1897 * consensus annotation.
1899 public void initComplementConsensus()
1901 if (!alignment.isNucleotide())
1903 final List<AlignedCodonFrame> codonMappings = alignment
1905 if (codonMappings != null && !codonMappings.isEmpty())
1907 boolean doConsensus = false;
1908 for (AlignedCodonFrame mapping : codonMappings)
1910 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1911 MapList[] mapLists = mapping.getdnaToProt();
1912 // mapLists can be empty if project load has not finished resolving
1914 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1922 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1923 "PID for cDNA", new Annotation[1], 0f, 100f,
1924 AlignmentAnnotation.BAR_GRAPH);
1925 initConsensus(complementConsensus);
1931 private void initConsensus(AlignmentAnnotation aa)
1934 aa.autoCalculated = true;
1938 alignment.addAnnotation(aa);
1942 private void initConservation()
1944 if (showConservation)
1946 if (conservation == null)
1948 conservation = new AlignmentAnnotation("Conservation",
1949 "Conservation of total alignment less than "
1950 + getConsPercGaps() + "% gaps", new Annotation[1],
1951 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1952 conservation.hasText = true;
1953 conservation.autoCalculated = true;
1954 alignment.addAnnotation(conservation);
1959 private void initQuality()
1963 if (quality == null)
1965 quality = new AlignmentAnnotation("Quality",
1966 "Alignment Quality based on Blosum62 scores",
1967 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1968 quality.hasText = true;
1969 quality.autoCalculated = true;
1970 alignment.addAnnotation(quality);
1975 private void initRNAStructure()
1977 if (alignment.hasRNAStructure() && strucConsensus == null)
1979 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1980 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1981 strucConsensus.hasText = true;
1982 strucConsensus.autoCalculated = true;
1986 alignment.addAnnotation(strucConsensus);
1994 * @see jalview.api.AlignViewportI#calcPanelHeight()
1997 public int calcPanelHeight()
1999 // setHeight of panels
2000 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2002 int charHeight = getCharHeight();
2005 BitSet graphgrp = new BitSet();
2006 for (AlignmentAnnotation aa : anns)
2010 System.err.println("Null annotation row: ignoring.");
2017 if (aa.graphGroup > -1)
2019 if (graphgrp.get(aa.graphGroup))
2025 graphgrp.set(aa.graphGroup);
2032 aa.height += charHeight;
2042 aa.height += aa.graphHeight;
2050 height += aa.height;
2062 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2063 boolean preserveNewGroupSettings)
2065 boolean updateCalcs = false;
2066 boolean conv = isShowGroupConservation();
2067 boolean cons = isShowGroupConsensus();
2068 boolean showprf = isShowSequenceLogo();
2069 boolean showConsHist = isShowConsensusHistogram();
2070 boolean normLogo = isNormaliseSequenceLogo();
2073 * TODO reorder the annotation rows according to group/sequence ordering on
2076 boolean sortg = true;
2078 // remove old automatic annotation
2079 // add any new annotation
2081 // intersect alignment annotation with alignment groups
2083 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2084 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2087 for (int an = 0; an < aan.length; an++)
2089 if (aan[an].autoCalculated && aan[an].groupRef != null)
2091 oldrfs.add(aan[an].groupRef);
2092 alignment.deleteAnnotation(aan[an], false);
2096 if (alignment.getGroups() != null)
2098 for (SequenceGroup sg : alignment.getGroups())
2100 updateCalcs = false;
2101 if (applyGlobalSettings
2102 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2104 // set defaults for this group's conservation/consensus
2105 sg.setshowSequenceLogo(showprf);
2106 sg.setShowConsensusHistogram(showConsHist);
2107 sg.setNormaliseSequenceLogo(normLogo);
2112 alignment.addAnnotation(sg.getConservationRow(), 0);
2117 alignment.addAnnotation(sg.getConsensus(), 0);
2119 // refresh the annotation rows
2122 sg.recalcConservation();
2130 public boolean isDisplayReferenceSeq()
2132 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2136 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2138 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2142 public boolean isColourByReferenceSeq()
2144 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2148 public Color getSequenceColour(SequenceI seq)
2150 Color sqc = sequenceColours.get(seq);
2151 return (sqc == null ? Color.white : sqc);
2155 public void setSequenceColour(SequenceI seq, Color col)
2159 sequenceColours.remove(seq);
2163 sequenceColours.put(seq, col);
2168 public void updateSequenceIdColours()
2170 for (SequenceGroup sg : alignment.getGroups())
2172 if (sg.idColour != null)
2174 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2176 sequenceColours.put(s, sg.idColour);
2183 public void clearSequenceColours()
2185 sequenceColours.clear();
2189 public AlignViewportI getCodingComplement()
2191 return this.codingComplement;
2195 * Set this as the (cDna/protein) complement of the given viewport. Also
2196 * ensures the reverse relationship is set on the given viewport.
2199 public void setCodingComplement(AlignViewportI av)
2203 System.err.println("Ignoring recursive setCodingComplement request");
2207 this.codingComplement = av;
2208 // avoid infinite recursion!
2209 if (av.getCodingComplement() != this)
2211 av.setCodingComplement(this);
2217 public boolean isNucleotide()
2219 return getAlignment() == null ? false : getAlignment().isNucleotide();
2223 public FeaturesDisplayedI getFeaturesDisplayed()
2225 return featuresDisplayed;
2229 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2231 featuresDisplayed = featuresDisplayedI;
2235 public boolean areFeaturesDisplayed()
2237 return featuresDisplayed != null
2238 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2245 * features are displayed if true
2248 public void setShowSequenceFeatures(boolean b)
2250 viewStyle.setShowSequenceFeatures(b);
2254 public boolean isShowSequenceFeatures()
2256 return viewStyle.isShowSequenceFeatures();
2260 public void setShowSequenceFeaturesHeight(boolean selected)
2262 viewStyle.setShowSequenceFeaturesHeight(selected);
2266 public boolean isShowSequenceFeaturesHeight()
2268 return viewStyle.isShowSequenceFeaturesHeight();
2272 public void setShowAnnotation(boolean b)
2274 viewStyle.setShowAnnotation(b);
2278 public boolean isShowAnnotation()
2280 return viewStyle.isShowAnnotation();
2284 public boolean isRightAlignIds()
2286 return viewStyle.isRightAlignIds();
2290 public void setRightAlignIds(boolean rightAlignIds)
2292 viewStyle.setRightAlignIds(rightAlignIds);
2296 public boolean getConservationSelected()
2298 return viewStyle.getConservationSelected();
2302 public void setShowBoxes(boolean state)
2304 viewStyle.setShowBoxes(state);
2309 * @see jalview.api.ViewStyleI#getTextColour()
2312 public Color getTextColour()
2314 return viewStyle.getTextColour();
2319 * @see jalview.api.ViewStyleI#getTextColour2()
2322 public Color getTextColour2()
2324 return viewStyle.getTextColour2();
2329 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2332 public int getThresholdTextColour()
2334 return viewStyle.getThresholdTextColour();
2339 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2342 public boolean isConservationColourSelected()
2344 return viewStyle.isConservationColourSelected();
2349 * @see jalview.api.ViewStyleI#isRenderGaps()
2352 public boolean isRenderGaps()
2354 return viewStyle.isRenderGaps();
2359 * @see jalview.api.ViewStyleI#isShowColourText()
2362 public boolean isShowColourText()
2364 return viewStyle.isShowColourText();
2368 * @param conservationColourSelected
2369 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2372 public void setConservationColourSelected(
2373 boolean conservationColourSelected)
2375 viewStyle.setConservationColourSelected(conservationColourSelected);
2379 * @param showColourText
2380 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2383 public void setShowColourText(boolean showColourText)
2385 viewStyle.setShowColourText(showColourText);
2390 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2393 public void setTextColour(Color textColour)
2395 viewStyle.setTextColour(textColour);
2399 * @param thresholdTextColour
2400 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2403 public void setThresholdTextColour(int thresholdTextColour)
2405 viewStyle.setThresholdTextColour(thresholdTextColour);
2409 * @param textColour2
2410 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2413 public void setTextColour2(Color textColour2)
2415 viewStyle.setTextColour2(textColour2);
2419 public ViewStyleI getViewStyle()
2421 return new ViewStyle(viewStyle);
2425 public void setViewStyle(ViewStyleI settingsForView)
2427 viewStyle = new ViewStyle(settingsForView);
2431 public boolean sameStyle(ViewStyleI them)
2433 return viewStyle.sameStyle(them);
2438 * @see jalview.api.ViewStyleI#getIdWidth()
2441 public int getIdWidth()
2443 return viewStyle.getIdWidth();
2448 * @see jalview.api.ViewStyleI#setIdWidth(int)
2451 public void setIdWidth(int i)
2453 viewStyle.setIdWidth(i);
2458 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2461 public boolean isCentreColumnLabels()
2463 return viewStyle.isCentreColumnLabels();
2467 * @param centreColumnLabels
2468 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2471 public void setCentreColumnLabels(boolean centreColumnLabels)
2473 viewStyle.setCentreColumnLabels(centreColumnLabels);
2478 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2481 public void setShowDBRefs(boolean showdbrefs)
2483 viewStyle.setShowDBRefs(showdbrefs);
2488 * @see jalview.api.ViewStyleI#isShowDBRefs()
2491 public boolean isShowDBRefs()
2493 return viewStyle.isShowDBRefs();
2498 * @see jalview.api.ViewStyleI#isShowNPFeats()
2501 public boolean isShowNPFeats()
2503 return viewStyle.isShowNPFeats();
2507 * @param shownpfeats
2508 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2511 public void setShowNPFeats(boolean shownpfeats)
2513 viewStyle.setShowNPFeats(shownpfeats);
2516 public abstract StructureSelectionManager getStructureSelectionManager();
2519 * Add one command to the command history list.
2523 public void addToHistoryList(CommandI command)
2525 if (this.historyList != null)
2527 this.historyList.push(command);
2528 broadcastCommand(command, false);
2532 protected void broadcastCommand(CommandI command, boolean undo)
2534 getStructureSelectionManager().commandPerformed(command, undo,
2539 * Add one command to the command redo list.
2543 public void addToRedoList(CommandI command)
2545 if (this.redoList != null)
2547 this.redoList.push(command);
2549 broadcastCommand(command, true);
2553 * Clear the command redo list.
2555 public void clearRedoList()
2557 if (this.redoList != null)
2559 this.redoList.clear();
2563 public void setHistoryList(Deque<CommandI> list)
2565 this.historyList = list;
2568 public Deque<CommandI> getHistoryList()
2570 return this.historyList;
2573 public void setRedoList(Deque<CommandI> list)
2575 this.redoList = list;
2578 public Deque<CommandI> getRedoList()
2580 return this.redoList;
2584 public VamsasSource getVamsasSource()
2589 public SequenceAnnotationOrder getSortAnnotationsBy()
2591 return sortAnnotationsBy;
2594 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2596 this.sortAnnotationsBy = sortAnnotationsBy;
2599 public boolean isShowAutocalculatedAbove()
2601 return showAutocalculatedAbove;
2604 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2606 this.showAutocalculatedAbove = showAutocalculatedAbove;
2610 public boolean isScaleProteinAsCdna()
2612 return viewStyle.isScaleProteinAsCdna();
2616 public void setScaleProteinAsCdna(boolean b)
2618 viewStyle.setScaleProteinAsCdna(b);
2622 * @return true if view should scroll to show the highlighted region of a
2627 public final boolean isFollowHighlight()
2629 return followHighlight;
2633 public final void setFollowHighlight(boolean b)
2635 this.followHighlight = b;
2638 public int getStartRes()
2644 public int getEndRes()
2649 public int getStartSeq()
2654 public void setStartRes(int res)
2656 this.startRes = res;
2659 public void setStartSeq(int seq)
2661 this.startSeq = seq;
2664 public void setEndRes(int res)
2666 if (res > alignment.getWidth() - 1)
2668 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2669 // (alignment.getWidth()-1));
2670 res = alignment.getWidth() - 1;
2679 public void setEndSeq(int seq)
2681 if (seq > alignment.getHeight())
2683 seq = alignment.getHeight();
2692 public int getEndSeq()
2698 * Helper method to populate the SearchResults with the location in the
2699 * complementary alignment to scroll to, in order to match this one.
2702 * the SearchResults to add to
2703 * @return the offset (below top of visible region) of the matched sequence
2705 protected int findComplementScrollTarget(SearchResultsI sr)
2707 final AlignViewportI complement = getCodingComplement();
2708 if (complement == null || !complement.isFollowHighlight())
2712 boolean iAmProtein = !getAlignment().isNucleotide();
2713 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2715 if (proteinAlignment == null)
2719 final List<AlignedCodonFrame> mappings = proteinAlignment
2723 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2724 * residue in the middle column of the visible region. Scroll the
2725 * complementary alignment to line up the corresponding residue.
2728 SequenceI sequence = null;
2731 * locate 'middle' column (true middle if an odd number visible, left of
2732 * middle if an even number visible)
2734 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2735 final HiddenSequences hiddenSequences = getAlignment()
2736 .getHiddenSequences();
2739 * searching to the bottom of the alignment gives smoother scrolling across
2740 * all gapped visible regions
2742 int lastSeq = alignment.getHeight() - 1;
2743 List<AlignedCodonFrame> seqMappings = null;
2744 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2746 sequence = getAlignment().getSequenceAt(seqNo);
2747 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2751 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2755 seqMappings = MappingUtils
2756 .findMappingsForSequenceAndOthers(sequence, mappings,
2757 getCodingComplement().getAlignment().getSequences());
2758 if (!seqMappings.isEmpty())
2764 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2767 * No ungapped mapped sequence in middle column - do nothing
2771 MappingUtils.addSearchResults(sr, sequence,
2772 sequence.findPosition(middleColumn), seqMappings);
2777 * synthesize a column selection if none exists so it covers the given
2778 * selection group. if wholewidth is false, no column selection is made if the
2779 * selection group covers the whole alignment width.
2784 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2787 if (sg != null && (sgs = sg.getStartRes()) >= 0
2788 && sg.getStartRes() <= (sge = sg.getEndRes())
2789 && !this.hasSelectedColumns())
2791 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2798 colSel = new ColumnSelection();
2800 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2802 colSel.addElement(cspos);
2808 * hold status of current selection group - defined on alignment or not.
2810 private boolean selectionIsDefinedGroup = false;
2814 public boolean isSelectionDefinedGroup()
2816 if (selectionGroup == null)
2820 if (isSelectionGroupChanged(true))
2822 selectionIsDefinedGroup = false;
2823 List<SequenceGroup> gps = alignment.getGroups();
2824 if (gps == null || gps.size() == 0)
2826 selectionIsDefinedGroup = false;
2830 selectionIsDefinedGroup = gps.contains(selectionGroup);
2833 return selectionGroup.getContext() == alignment
2834 || selectionIsDefinedGroup;
2838 * null, or currently highlighted results on this view
2840 private SearchResultsI searchResults = null;
2843 public boolean hasSearchResults()
2845 return searchResults != null;
2849 public void setSearchResults(SearchResultsI results)
2851 searchResults = results;
2855 public SearchResultsI getSearchResults()
2857 return searchResults;