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 java.awt.Color;
24 import java.beans.PropertyChangeSupport;
25 import java.util.ArrayDeque;
26 import java.util.ArrayList;
27 import java.util.BitSet;
28 import java.util.Deque;
29 import java.util.HashMap;
30 import java.util.Hashtable;
31 import java.util.List;
34 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
35 import jalview.analysis.Conservation;
36 import jalview.api.AlignCalcManagerI;
37 import jalview.api.AlignViewportI;
38 import jalview.api.AlignmentViewPanel;
39 import jalview.api.FeaturesDisplayedI;
40 import jalview.api.ViewStyleI;
41 import jalview.commands.CommandI;
42 import jalview.datamodel.AlignedCodonFrame;
43 import jalview.datamodel.AlignmentAnnotation;
44 import jalview.datamodel.AlignmentI;
45 import jalview.datamodel.AlignmentView;
46 import jalview.datamodel.Annotation;
47 import jalview.datamodel.CigarArray;
48 import jalview.datamodel.ColumnSelection;
49 import jalview.datamodel.HiddenSequences;
50 import jalview.datamodel.ProfilesI;
51 import jalview.datamodel.SearchResultsI;
52 import jalview.datamodel.Sequence;
53 import jalview.datamodel.SequenceCollectionI;
54 import jalview.datamodel.SequenceGroup;
55 import jalview.datamodel.SequenceI;
56 import jalview.renderer.ResidueShader;
57 import jalview.renderer.ResidueShaderI;
58 import jalview.schemes.ColourSchemeI;
59 import jalview.structure.CommandListener;
60 import jalview.structure.StructureSelectionManager;
61 import jalview.structure.VamsasSource;
62 import jalview.util.Comparison;
63 import jalview.util.MapList;
64 import jalview.util.MappingUtils;
65 import jalview.util.MessageManager;
66 import jalview.viewmodel.styles.ViewStyle;
67 import jalview.workers.AlignCalcManager;
68 import jalview.workers.ComplementConsensusThread;
69 import jalview.workers.ConsensusThread;
70 import jalview.workers.StrucConsensusThread;
73 * base class holding visualization and analysis attributes and common logic for
74 * an active alignment view displayed in the GUI
79 public abstract class AlignmentViewport implements AlignViewportI,
80 CommandListener, VamsasSource
82 protected ViewportRanges ranges;
84 protected ViewStyleI viewStyle = new ViewStyle();
87 * A viewport that hosts the cDna view of this (protein), or vice versa (if
90 AlignViewportI codingComplement = null;
92 FeaturesDisplayedI featuresDisplayed = null;
94 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
96 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
100 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
103 public void setFontName(String name)
105 viewStyle.setFontName(name);
110 * @see jalview.api.ViewStyleI#setFontStyle(int)
113 public void setFontStyle(int style)
115 viewStyle.setFontStyle(style);
120 * @see jalview.api.ViewStyleI#setFontSize(int)
123 public void setFontSize(int size)
125 viewStyle.setFontSize(size);
130 * @see jalview.api.ViewStyleI#getFontStyle()
133 public int getFontStyle()
135 return viewStyle.getFontStyle();
140 * @see jalview.api.ViewStyleI#getFontName()
143 public String getFontName()
145 return viewStyle.getFontName();
150 * @see jalview.api.ViewStyleI#getFontSize()
153 public int getFontSize()
155 return viewStyle.getFontSize();
159 * @param upperCasebold
160 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
163 public void setUpperCasebold(boolean upperCasebold)
165 viewStyle.setUpperCasebold(upperCasebold);
170 * @see jalview.api.ViewStyleI#isUpperCasebold()
173 public boolean isUpperCasebold()
175 return viewStyle.isUpperCasebold();
180 * @see jalview.api.ViewStyleI#isSeqNameItalics()
183 public boolean isSeqNameItalics()
185 return viewStyle.isSeqNameItalics();
189 * @param colourByReferenceSeq
190 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
193 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
195 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
200 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
203 public void setColourAppliesToAllGroups(boolean b)
205 viewStyle.setColourAppliesToAllGroups(b);
210 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
213 public boolean getColourAppliesToAllGroups()
215 return viewStyle.getColourAppliesToAllGroups();
220 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
223 public boolean getAbovePIDThreshold()
225 return viewStyle.getAbovePIDThreshold();
230 * @see jalview.api.ViewStyleI#setIncrement(int)
233 public void setIncrement(int inc)
235 viewStyle.setIncrement(inc);
240 * @see jalview.api.ViewStyleI#getIncrement()
243 public int getIncrement()
245 return viewStyle.getIncrement();
250 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
253 public void setConservationSelected(boolean b)
255 viewStyle.setConservationSelected(b);
260 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
263 public void setShowHiddenMarkers(boolean show)
265 viewStyle.setShowHiddenMarkers(show);
270 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
273 public boolean getShowHiddenMarkers()
275 return viewStyle.getShowHiddenMarkers();
280 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
283 public void setScaleRightWrapped(boolean b)
285 viewStyle.setScaleRightWrapped(b);
290 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
293 public void setScaleLeftWrapped(boolean b)
295 viewStyle.setScaleLeftWrapped(b);
300 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
303 public void setScaleAboveWrapped(boolean b)
305 viewStyle.setScaleAboveWrapped(b);
310 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
313 public boolean getScaleLeftWrapped()
315 return viewStyle.getScaleLeftWrapped();
320 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
323 public boolean getScaleAboveWrapped()
325 return viewStyle.getScaleAboveWrapped();
330 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
333 public boolean getScaleRightWrapped()
335 return viewStyle.getScaleRightWrapped();
340 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
343 public void setAbovePIDThreshold(boolean b)
345 viewStyle.setAbovePIDThreshold(b);
350 * @see jalview.api.ViewStyleI#setThreshold(int)
353 public void setThreshold(int thresh)
355 viewStyle.setThreshold(thresh);
360 * @see jalview.api.ViewStyleI#getThreshold()
363 public int getThreshold()
365 return viewStyle.getThreshold();
370 * @see jalview.api.ViewStyleI#getShowJVSuffix()
373 public boolean getShowJVSuffix()
375 return viewStyle.getShowJVSuffix();
380 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
383 public void setShowJVSuffix(boolean b)
385 viewStyle.setShowJVSuffix(b);
390 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
393 public void setWrapAlignment(boolean state)
395 viewStyle.setWrapAlignment(state);
400 * @see jalview.api.ViewStyleI#setShowText(boolean)
403 public void setShowText(boolean state)
405 viewStyle.setShowText(state);
410 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
413 public void setRenderGaps(boolean state)
415 viewStyle.setRenderGaps(state);
420 * @see jalview.api.ViewStyleI#getColourText()
423 public boolean getColourText()
425 return viewStyle.getColourText();
430 * @see jalview.api.ViewStyleI#setColourText(boolean)
433 public void setColourText(boolean state)
435 viewStyle.setColourText(state);
440 * @see jalview.api.ViewStyleI#getWrapAlignment()
443 public boolean getWrapAlignment()
445 return viewStyle.getWrapAlignment();
450 * @see jalview.api.ViewStyleI#getShowText()
453 public boolean getShowText()
455 return viewStyle.getShowText();
460 * @see jalview.api.ViewStyleI#getWrappedWidth()
463 public int getWrappedWidth()
465 return viewStyle.getWrappedWidth();
470 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
473 public void setWrappedWidth(int w)
475 viewStyle.setWrappedWidth(w);
480 * @see jalview.api.ViewStyleI#getCharHeight()
483 public int getCharHeight()
485 return viewStyle.getCharHeight();
490 * @see jalview.api.ViewStyleI#setCharHeight(int)
493 public void setCharHeight(int h)
495 viewStyle.setCharHeight(h);
500 * @see jalview.api.ViewStyleI#getCharWidth()
503 public int getCharWidth()
505 return viewStyle.getCharWidth();
510 * @see jalview.api.ViewStyleI#setCharWidth(int)
513 public void setCharWidth(int w)
515 viewStyle.setCharWidth(w);
520 * @see jalview.api.ViewStyleI#getShowBoxes()
523 public boolean getShowBoxes()
525 return viewStyle.getShowBoxes();
530 * @see jalview.api.ViewStyleI#getShowUnconserved()
533 public boolean getShowUnconserved()
535 return viewStyle.getShowUnconserved();
539 * @param showunconserved
540 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
543 public void setShowUnconserved(boolean showunconserved)
545 viewStyle.setShowUnconserved(showunconserved);
550 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
553 public void setSeqNameItalics(boolean default1)
555 viewStyle.setSeqNameItalics(default1);
559 * alignment displayed in the viewport. Please use get/setter
561 protected AlignmentI alignment;
564 public AlignmentI getAlignment()
570 public char getGapCharacter()
572 return alignment.getGapCharacter();
575 protected String sequenceSetID;
578 * probably unused indicator that view is of a dataset rather than an
581 protected boolean isDataset = false;
583 public void setDataset(boolean b)
588 public boolean isDataset()
593 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
595 protected ColumnSelection colSel = new ColumnSelection();
597 public boolean autoCalculateConsensus = true;
599 protected boolean autoCalculateStrucConsensus = true;
601 protected boolean ignoreGapsInConsensusCalculation = false;
603 protected ResidueShaderI residueShading;
606 public void setGlobalColourScheme(ColourSchemeI cs)
608 // TODO: logic refactored from AlignFrame changeColour -
609 // TODO: autorecalc stuff should be changed to rely on the worker system
610 // check to see if we should implement a changeColour(cs) method rather than
611 // put the logic in here
612 // - means that caller decides if they want to just modify state and defer
613 // calculation till later or to do all calculations in thread.
617 * only instantiate alignment colouring once, thereafter update it;
618 * this means that any conservation or PID threshold settings
619 * persist when the alignment colour scheme is changed
621 if (residueShading == null)
623 residueShading = new ResidueShader(viewStyle);
625 residueShading.setColourScheme(cs);
627 // TODO: do threshold and increment belong in ViewStyle or ResidueShader?
628 // ...problem: groups need these, but do not currently have a ViewStyle
632 if (getConservationSelected())
634 residueShading.setConservation(hconservation);
636 residueShading.alignmentChanged(alignment, hiddenRepSequences);
640 * if 'apply colour to all groups' is selected... do so
641 * (but don't transfer any colour threshold settings to groups)
643 if (getColourAppliesToAllGroups())
645 for (SequenceGroup sg : getAlignment().getGroups())
648 * retain any colour thresholds per group while
649 * changing choice of colour scheme (JAL-2386)
651 sg.setColourScheme(cs);
654 sg.getGroupColourScheme()
655 .alignmentChanged(sg, hiddenRepSequences);
662 public ColourSchemeI getGlobalColourScheme()
664 return residueShading == null ? null : residueShading
669 public ResidueShaderI getResidueShading()
671 return residueShading;
674 protected AlignmentAnnotation consensus;
676 protected AlignmentAnnotation complementConsensus;
678 protected AlignmentAnnotation gapcounts;
680 protected AlignmentAnnotation strucConsensus;
682 protected AlignmentAnnotation conservation;
684 protected AlignmentAnnotation quality;
686 protected AlignmentAnnotation[] groupConsensus;
688 protected AlignmentAnnotation[] groupConservation;
691 * results of alignment consensus analysis for visible portion of view
693 protected ProfilesI hconsensus = null;
696 * results of cDNA complement consensus visible portion of view
698 protected Hashtable[] hcomplementConsensus = null;
701 * results of secondary structure base pair consensus for visible portion of
704 protected Hashtable[] hStrucConsensus = null;
706 protected Conservation hconservation = null;
709 public void setConservation(Conservation cons)
711 hconservation = cons;
715 * percentage gaps allowed in a column before all amino acid properties should
716 * be considered unconserved
718 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
721 public int getConsPercGaps()
727 public void setSequenceConsensusHash(ProfilesI hconsensus)
729 this.hconsensus = hconsensus;
733 public void setComplementConsensusHash(Hashtable[] hconsensus)
735 this.hcomplementConsensus = hconsensus;
739 public ProfilesI getSequenceConsensusHash()
745 public Hashtable[] getComplementConsensusHash()
747 return hcomplementConsensus;
751 public Hashtable[] getRnaStructureConsensusHash()
753 return hStrucConsensus;
757 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
759 this.hStrucConsensus = hStrucConsensus;
764 public AlignmentAnnotation getAlignmentQualityAnnot()
770 public AlignmentAnnotation getAlignmentConservationAnnotation()
776 public AlignmentAnnotation getAlignmentConsensusAnnotation()
782 public AlignmentAnnotation getAlignmentGapAnnotation()
788 public AlignmentAnnotation getComplementConsensusAnnotation()
790 return complementConsensus;
794 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
796 return strucConsensus;
799 protected AlignCalcManagerI calculator = new AlignCalcManager();
802 * trigger update of conservation annotation
804 public void updateConservation(final AlignmentViewPanel ap)
806 // see note in mantis : issue number 8585
807 if (alignment.isNucleotide()
808 || (conservation == null && quality == null)
809 || !autoCalculateConsensus)
814 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
816 calculator.registerWorker(new jalview.workers.ConservationThread(
822 * trigger update of consensus annotation
824 public void updateConsensus(final AlignmentViewPanel ap)
826 // see note in mantis : issue number 8585
827 if (consensus == null || !autoCalculateConsensus)
831 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
833 calculator.registerWorker(new ConsensusThread(this, ap));
837 * A separate thread to compute cDNA consensus for a protein alignment
838 * which has mapping to cDNA
840 final AlignmentI al = this.getAlignment();
841 if (!al.isNucleotide() && al.getCodonFrames() != null
842 && !al.getCodonFrames().isEmpty())
845 * fudge - check first for protein-to-nucleotide mappings
846 * (we don't want to do this for protein-to-protein)
848 boolean doConsensus = false;
849 for (AlignedCodonFrame mapping : al.getCodonFrames())
851 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
852 MapList[] mapLists = mapping.getdnaToProt();
853 // mapLists can be empty if project load has not finished resolving seqs
854 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
863 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
866 .registerWorker(new ComplementConsensusThread(this, ap));
872 // --------START Structure Conservation
873 public void updateStrucConsensus(final AlignmentViewPanel ap)
875 if (autoCalculateStrucConsensus && strucConsensus == null
876 && alignment.isNucleotide() && alignment.hasRNAStructure())
878 // secondary structure has been added - so init the consensus line
882 // see note in mantis : issue number 8585
883 if (strucConsensus == null || !autoCalculateStrucConsensus)
887 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
889 calculator.registerWorker(new StrucConsensusThread(this, ap));
893 public boolean isCalcInProgress()
895 return calculator.isWorking();
899 public boolean isCalculationInProgress(
900 AlignmentAnnotation alignmentAnnotation)
902 if (!alignmentAnnotation.autoCalculated)
906 if (calculator.workingInvolvedWith(alignmentAnnotation))
908 // System.err.println("grey out ("+alignmentAnnotation.label+")");
914 public void setAlignment(AlignmentI align)
916 this.alignment = align;
920 * Clean up references when this viewport is closed
923 public void dispose()
926 * defensively null out references to large objects in case
927 * this object is not garbage collected (as if!)
930 complementConsensus = null;
931 strucConsensus = null;
934 groupConsensus = null;
935 groupConservation = null;
937 hcomplementConsensus = null;
938 // colour scheme may hold reference to consensus
939 residueShading = null;
940 // TODO remove listeners from changeSupport?
941 changeSupport = null;
946 public boolean isClosed()
948 // TODO: check that this isClosed is only true after panel is closed, not
949 // before it is fully constructed.
950 return alignment == null;
954 public AlignCalcManagerI getCalcManager()
960 * should conservation rows be shown for groups
962 protected boolean showGroupConservation = false;
965 * should consensus rows be shown for groups
967 protected boolean showGroupConsensus = false;
970 * should consensus profile be rendered by default
972 protected boolean showSequenceLogo = false;
975 * should consensus profile be rendered normalised to row height
977 protected boolean normaliseSequenceLogo = false;
980 * should consensus histograms be rendered by default
982 protected boolean showConsensusHistogram = true;
985 * @return the showConsensusProfile
988 public boolean isShowSequenceLogo()
990 return showSequenceLogo;
994 * @param showSequenceLogo
997 public void setShowSequenceLogo(boolean showSequenceLogo)
999 if (showSequenceLogo != this.showSequenceLogo)
1001 // TODO: decouple settings setting from calculation when refactoring
1002 // annotation update method from alignframe to viewport
1003 this.showSequenceLogo = showSequenceLogo;
1004 calculator.updateAnnotationFor(ConsensusThread.class);
1005 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1006 calculator.updateAnnotationFor(StrucConsensusThread.class);
1008 this.showSequenceLogo = showSequenceLogo;
1012 * @param showConsensusHistogram
1013 * the showConsensusHistogram to set
1015 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1017 this.showConsensusHistogram = showConsensusHistogram;
1021 * @return the showGroupConservation
1023 public boolean isShowGroupConservation()
1025 return showGroupConservation;
1029 * @param showGroupConservation
1030 * the showGroupConservation to set
1032 public void setShowGroupConservation(boolean showGroupConservation)
1034 this.showGroupConservation = showGroupConservation;
1038 * @return the showGroupConsensus
1040 public boolean isShowGroupConsensus()
1042 return showGroupConsensus;
1046 * @param showGroupConsensus
1047 * the showGroupConsensus to set
1049 public void setShowGroupConsensus(boolean showGroupConsensus)
1051 this.showGroupConsensus = showGroupConsensus;
1056 * @return flag to indicate if the consensus histogram should be rendered by
1060 public boolean isShowConsensusHistogram()
1062 return this.showConsensusHistogram;
1066 * when set, updateAlignment will always ensure sequences are of equal length
1068 private boolean padGaps = false;
1071 * when set, alignment should be reordered according to a newly opened tree
1073 public boolean sortByTree = false;
1078 * @return null or the currently selected sequence region
1081 public SequenceGroup getSelectionGroup()
1083 return selectionGroup;
1087 * Set the selection group for this window. Also sets the current alignment as
1088 * the context for the group, if it does not already have one.
1091 * - group holding references to sequences in this alignment view
1095 public void setSelectionGroup(SequenceGroup sg)
1097 selectionGroup = sg;
1098 if (sg != null && sg.getContext() == null)
1100 sg.setContext(alignment);
1104 public void setHiddenColumns(ColumnSelection colsel)
1106 this.colSel = colsel;
1110 public ColumnSelection getColumnSelection()
1116 public void setColumnSelection(ColumnSelection colSel)
1118 this.colSel = colSel;
1121 updateHiddenColumns();
1123 isColSelChanged(true);
1131 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1133 return hiddenRepSequences;
1137 public void setHiddenRepSequences(
1138 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1140 this.hiddenRepSequences = hiddenRepSequences;
1144 public boolean hasSelectedColumns()
1146 ColumnSelection columnSelection = getColumnSelection();
1147 return columnSelection != null && columnSelection.hasSelectedColumns();
1151 public boolean hasHiddenColumns()
1153 return colSel != null && colSel.hasHiddenColumns();
1156 public void updateHiddenColumns()
1158 // this method doesn't really do anything now. But - it could, since a
1159 // column Selection could be in the process of modification
1160 // hasHiddenColumns = colSel.hasHiddenColumns();
1164 public boolean hasHiddenRows()
1166 return alignment.getHiddenSequences().getSize() > 0;
1169 protected SequenceGroup selectionGroup;
1171 public void setSequenceSetId(String newid)
1173 if (sequenceSetID != null)
1176 .println("Warning - overwriting a sequenceSetId for a viewport!");
1178 sequenceSetID = new String(newid);
1182 public String getSequenceSetId()
1184 if (sequenceSetID == null)
1186 sequenceSetID = alignment.hashCode() + "";
1189 return sequenceSetID;
1193 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1196 protected String viewId = null;
1199 public String getViewId()
1203 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1208 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1210 ignoreGapsInConsensusCalculation = b;
1213 updateConsensus(ap);
1214 if (residueShading != null)
1216 residueShading.setThreshold(residueShading.getThreshold(),
1217 ignoreGapsInConsensusCalculation);
1223 private long sgrouphash = -1, colselhash = -1;
1226 * checks current SelectionGroup against record of last hash value, and
1230 * update the record of last hash value
1232 * @return true if SelectionGroup changed since last call (when b is true)
1234 public boolean isSelectionGroupChanged(boolean b)
1236 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1237 : selectionGroup.hashCode();
1238 if (hc != -1 && hc != sgrouphash)
1250 * checks current colsel against record of last hash value, and optionally
1254 * update the record of last hash value
1255 * @return true if colsel changed since last call (when b is true)
1257 public boolean isColSelChanged(boolean b)
1259 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1260 if (hc != -1 && hc != colselhash)
1272 public boolean isIgnoreGapsConsensus()
1274 return ignoreGapsInConsensusCalculation;
1277 // property change stuff
1278 // JBPNote Prolly only need this in the applet version.
1279 private PropertyChangeSupport changeSupport = new PropertyChangeSupport(
1282 protected boolean showConservation = true;
1284 protected boolean showQuality = true;
1286 protected boolean showConsensus = true;
1288 protected boolean showOccupancy = true;
1290 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1292 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1294 protected boolean showAutocalculatedAbove;
1297 * when set, view will scroll to show the highlighted position
1299 private boolean followHighlight = true;
1302 * Property change listener for changes in alignment
1307 public void addPropertyChangeListener(
1308 java.beans.PropertyChangeListener listener)
1310 changeSupport.addPropertyChangeListener(listener);
1319 public void removePropertyChangeListener(
1320 java.beans.PropertyChangeListener listener)
1322 changeSupport.removePropertyChangeListener(listener);
1326 * Property change listener for changes in alignment
1335 public void firePropertyChange(String prop, Object oldvalue,
1338 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1341 // common hide/show column stuff
1343 public void hideSelectedColumns()
1345 if (colSel.isEmpty())
1350 colSel.hideSelectedColumns();
1351 setSelectionGroup(null);
1352 isColSelChanged(true);
1355 public void hideColumns(int start, int end)
1359 colSel.hideColumns(start);
1363 colSel.hideColumns(start, end);
1365 isColSelChanged(true);
1368 public void showColumn(int col)
1370 colSel.revealHiddenColumns(col);
1371 isColSelChanged(true);
1374 public void showAllHiddenColumns()
1376 colSel.revealAllHiddenColumns();
1377 isColSelChanged(true);
1380 // common hide/show seq stuff
1381 public void showAllHiddenSeqs()
1383 if (alignment.getHiddenSequences().getSize() > 0)
1385 if (selectionGroup == null)
1387 selectionGroup = new SequenceGroup();
1388 selectionGroup.setEndRes(alignment.getWidth() - 1);
1390 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1391 hiddenRepSequences);
1392 for (SequenceI seq : tmp)
1394 selectionGroup.addSequence(seq, false);
1395 setSequenceAnnotationsVisible(seq, true);
1398 hiddenRepSequences = null;
1400 firePropertyChange("alignment", null, alignment.getSequences());
1401 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1407 public void showSequence(int index)
1409 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1410 index, hiddenRepSequences);
1413 if (selectionGroup == null)
1415 selectionGroup = new SequenceGroup();
1416 selectionGroup.setEndRes(alignment.getWidth() - 1);
1419 for (SequenceI seq : tmp)
1421 selectionGroup.addSequence(seq, false);
1422 setSequenceAnnotationsVisible(seq, true);
1424 firePropertyChange("alignment", null, alignment.getSequences());
1429 public void hideAllSelectedSeqs()
1431 if (selectionGroup == null || selectionGroup.getSize() < 1)
1436 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1440 setSelectionGroup(null);
1443 public void hideSequence(SequenceI[] seq)
1447 for (int i = 0; i < seq.length; i++)
1449 alignment.getHiddenSequences().hideSequence(seq[i]);
1450 setSequenceAnnotationsVisible(seq[i], false);
1452 firePropertyChange("alignment", null, alignment.getSequences());
1457 * Hides the specified sequence, or the sequences it represents
1460 * the sequence to hide, or keep as representative
1461 * @param representGroup
1462 * if true, hide the current selection group except for the
1463 * representative sequence
1465 public void hideSequences(SequenceI sequence, boolean representGroup)
1467 if (selectionGroup == null || selectionGroup.getSize() < 1)
1469 hideSequence(new SequenceI[] { sequence });
1475 hideRepSequences(sequence, selectionGroup);
1476 setSelectionGroup(null);
1480 int gsize = selectionGroup.getSize();
1481 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1482 new SequenceI[gsize]);
1484 hideSequence(hseqs);
1485 setSelectionGroup(null);
1490 * Set visibility for any annotations for the given sequence.
1494 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1497 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1500 for (AlignmentAnnotation ann : anns)
1502 if (ann.sequenceRef == sequenceI)
1504 ann.visible = visible;
1510 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1512 int sSize = sg.getSize();
1518 if (hiddenRepSequences == null)
1520 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1523 hiddenRepSequences.put(repSequence, sg);
1525 // Hide all sequences except the repSequence
1526 SequenceI[] seqs = new SequenceI[sSize - 1];
1528 for (int i = 0; i < sSize; i++)
1530 if (sg.getSequenceAt(i) != repSequence)
1532 if (index == sSize - 1)
1537 seqs[index++] = sg.getSequenceAt(i);
1540 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1541 sg.setHidereps(true); // note: not done in 2.7applet
1548 * @return null or the current reference sequence
1550 public SequenceI getReferenceSeq()
1552 return alignment.getSeqrep();
1557 * @return true iff seq is the reference for the alignment
1559 public boolean isReferenceSeq(SequenceI seq)
1561 return alignment.getSeqrep() == seq;
1567 * @return true if there are sequences represented by this sequence that are
1570 public boolean isHiddenRepSequence(SequenceI seq)
1572 return (hiddenRepSequences != null && hiddenRepSequences
1579 * @return null or a sequence group containing the sequences that seq
1582 public SequenceGroup getRepresentedSequences(SequenceI seq)
1584 return (SequenceGroup) (hiddenRepSequences == null ? null
1585 : hiddenRepSequences.get(seq));
1589 public int adjustForHiddenSeqs(int alignmentIndex)
1591 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1596 public void invertColumnSelection()
1598 colSel.invertColumnSelection(0, alignment.getWidth());
1602 public SequenceI[] getSelectionAsNewSequence()
1604 SequenceI[] sequences;
1605 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1606 // this was the only caller in the applet for this method
1607 // JBPNote: in applet, this method returned references to the alignment
1608 // sequences, and it did not honour the presence/absence of annotation
1609 // attached to the alignment (probably!)
1610 if (selectionGroup == null || selectionGroup.getSize() == 0)
1612 sequences = alignment.getSequencesArray();
1613 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1614 for (int i = 0; i < sequences.length; i++)
1616 // construct new sequence with subset of visible annotation
1617 sequences[i] = new Sequence(sequences[i], annots);
1622 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1629 public SequenceI[] getSequenceSelection()
1631 SequenceI[] sequences = null;
1632 if (selectionGroup != null)
1634 sequences = selectionGroup.getSequencesInOrder(alignment);
1636 if (sequences == null)
1638 sequences = alignment.getSequencesArray();
1644 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1646 return new CigarArray(alignment, colSel,
1647 (selectedRegionOnly ? selectionGroup : null));
1651 public jalview.datamodel.AlignmentView getAlignmentView(
1652 boolean selectedOnly)
1654 return getAlignmentView(selectedOnly, false);
1658 public jalview.datamodel.AlignmentView getAlignmentView(
1659 boolean selectedOnly, boolean markGroups)
1661 return new AlignmentView(alignment, colSel, selectionGroup,
1662 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1667 public String[] getViewAsString(boolean selectedRegionOnly)
1669 return getViewAsString(selectedRegionOnly, true);
1673 public String[] getViewAsString(boolean selectedRegionOnly,
1674 boolean exportHiddenSeqs)
1676 String[] selection = null;
1677 SequenceI[] seqs = null;
1679 int start = 0, end = 0;
1680 if (selectedRegionOnly && selectionGroup != null)
1682 iSize = selectionGroup.getSize();
1683 seqs = selectionGroup.getSequencesInOrder(alignment);
1684 start = selectionGroup.getStartRes();
1685 end = selectionGroup.getEndRes() + 1;
1689 if (hasHiddenRows() && exportHiddenSeqs)
1691 AlignmentI fullAlignment = alignment.getHiddenSequences()
1692 .getFullAlignment();
1693 iSize = fullAlignment.getHeight();
1694 seqs = fullAlignment.getSequencesArray();
1695 end = fullAlignment.getWidth();
1699 iSize = alignment.getHeight();
1700 seqs = alignment.getSequencesArray();
1701 end = alignment.getWidth();
1705 selection = new String[iSize];
1706 if (colSel != null && colSel.hasHiddenColumns())
1708 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1712 for (i = 0; i < iSize; i++)
1714 selection[i] = seqs[i].getSequenceAsString(start, end);
1722 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1724 ArrayList<int[]> regions = new ArrayList<int[]>();
1730 if (colSel != null && colSel.hasHiddenColumns())
1734 start = colSel.adjustForHiddenColumns(start);
1737 end = colSel.getHiddenBoundaryRight(start);
1748 regions.add(new int[] { start, end });
1750 if (colSel != null && colSel.hasHiddenColumns())
1752 start = colSel.adjustForHiddenColumns(end);
1753 start = colSel.getHiddenBoundaryLeft(start) + 1;
1755 } while (end < max);
1757 int[][] startEnd = new int[regions.size()][2];
1763 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1764 boolean selectedOnly)
1766 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1767 AlignmentAnnotation[] aa;
1768 if ((aa = alignment.getAlignmentAnnotation()) != null)
1770 for (AlignmentAnnotation annot : aa)
1772 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1773 if (selectedOnly && selectionGroup != null)
1775 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1776 selectionGroup.getEndRes(), clone);
1780 colSel.makeVisibleAnnotation(clone);
1789 public boolean isPadGaps()
1795 public void setPadGaps(boolean padGaps)
1797 this.padGaps = padGaps;
1801 * apply any post-edit constraints and trigger any calculations needed after
1802 * an edit has been performed on the alignment
1807 public void alignmentChanged(AlignmentViewPanel ap)
1811 alignment.padGaps();
1813 if (autoCalculateConsensus)
1815 updateConsensus(ap);
1817 if (hconsensus != null && autoCalculateConsensus)
1819 updateConservation(ap);
1821 if (autoCalculateStrucConsensus)
1823 updateStrucConsensus(ap);
1826 // Reset endRes of groups if beyond alignment width
1827 int alWidth = alignment.getWidth();
1828 List<SequenceGroup> groups = alignment.getGroups();
1831 for (SequenceGroup sg : groups)
1833 if (sg.getEndRes() > alWidth)
1835 sg.setEndRes(alWidth - 1);
1840 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1842 selectionGroup.setEndRes(alWidth - 1);
1845 updateAllColourSchemes();
1846 calculator.restartWorkers();
1847 // alignment.adjustSequenceAnnotations();
1851 * reset scope and do calculations for all applied colourschemes on alignment
1853 void updateAllColourSchemes()
1855 ResidueShaderI rs = residueShading;
1858 rs.alignmentChanged(alignment, hiddenRepSequences);
1860 rs.setConsensus(hconsensus);
1861 if (rs.conservationApplied())
1863 rs.setConservation(Conservation.calculateConservation("All",
1864 alignment.getSequences(), 0, alignment.getWidth(), false,
1865 getConsPercGaps(), false));
1869 for (SequenceGroup sg : alignment.getGroups())
1873 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1875 sg.recalcConservation();
1879 protected void initAutoAnnotation()
1881 // TODO: add menu option action that nulls or creates consensus object
1882 // depending on if the user wants to see the annotation or not in a
1883 // specific alignment
1885 if (hconsensus == null && !isDataset)
1887 if (!alignment.isNucleotide())
1896 consensus = new AlignmentAnnotation("Consensus",
1897 MessageManager.getString("label.consensus_descr"),
1898 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1899 initConsensus(consensus);
1902 initComplementConsensus();
1907 * If this is a protein alignment and there are mappings to cDNA, adds the
1908 * cDNA consensus annotation and returns true, else returns false.
1910 public boolean initComplementConsensus()
1912 if (!alignment.isNucleotide())
1914 final List<AlignedCodonFrame> codonMappings = alignment
1916 if (codonMappings != null && !codonMappings.isEmpty())
1918 boolean doConsensus = false;
1919 for (AlignedCodonFrame mapping : codonMappings)
1921 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1922 MapList[] mapLists = mapping.getdnaToProt();
1923 // mapLists can be empty if project load has not finished resolving
1925 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1933 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1935 .getString("label.complement_consensus_descr"),
1936 new Annotation[1], 0f, 100f,
1937 AlignmentAnnotation.BAR_GRAPH);
1938 initConsensus(complementConsensus);
1946 private void initConsensus(AlignmentAnnotation aa)
1949 aa.autoCalculated = true;
1953 alignment.addAnnotation(aa);
1957 // these should be extracted from the view model - style and settings for
1958 // derived annotation
1959 private void initGapCounts()
1963 gapcounts = new AlignmentAnnotation("Occupancy",
1964 MessageManager.getString("label.occupancy_descr"),
1965 new Annotation[1], 0f,
1966 alignment.getHeight(), AlignmentAnnotation.BAR_GRAPH);
1967 gapcounts.hasText = true;
1968 gapcounts.autoCalculated = true;
1969 gapcounts.scaleColLabel = true;
1970 gapcounts.graph = AlignmentAnnotation.BAR_GRAPH;
1972 alignment.addAnnotation(gapcounts);
1976 private void initConservation()
1978 if (showConservation)
1980 if (conservation == null)
1982 conservation = new AlignmentAnnotation("Conservation",
1983 MessageManager.formatMessage("label.conservation_descr",
1984 getConsPercGaps()), new Annotation[1],
1985 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1986 conservation.hasText = true;
1987 conservation.autoCalculated = true;
1988 alignment.addAnnotation(conservation);
1993 private void initQuality()
1997 if (quality == null)
1999 quality = new AlignmentAnnotation("Quality",
2000 MessageManager.getString("label.quality_descr"),
2001 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
2002 quality.hasText = true;
2003 quality.autoCalculated = true;
2004 alignment.addAnnotation(quality);
2009 private void initRNAStructure()
2011 if (alignment.hasRNAStructure() && strucConsensus == null)
2013 strucConsensus = new AlignmentAnnotation("StrucConsensus",
2014 MessageManager.getString("label.strucconsensus_descr"),
2015 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
2016 strucConsensus.hasText = true;
2017 strucConsensus.autoCalculated = true;
2021 alignment.addAnnotation(strucConsensus);
2029 * @see jalview.api.AlignViewportI#calcPanelHeight()
2032 public int calcPanelHeight()
2034 // setHeight of panels
2035 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2037 int charHeight = getCharHeight();
2040 BitSet graphgrp = new BitSet();
2041 for (AlignmentAnnotation aa : anns)
2045 System.err.println("Null annotation row: ignoring.");
2052 if (aa.graphGroup > -1)
2054 if (graphgrp.get(aa.graphGroup))
2060 graphgrp.set(aa.graphGroup);
2067 aa.height += charHeight;
2077 aa.height += aa.graphHeight;
2085 height += aa.height;
2097 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2098 boolean preserveNewGroupSettings)
2100 boolean updateCalcs = false;
2101 boolean conv = isShowGroupConservation();
2102 boolean cons = isShowGroupConsensus();
2103 boolean showprf = isShowSequenceLogo();
2104 boolean showConsHist = isShowConsensusHistogram();
2105 boolean normLogo = isNormaliseSequenceLogo();
2108 * TODO reorder the annotation rows according to group/sequence ordering on
2111 boolean sortg = true;
2113 // remove old automatic annotation
2114 // add any new annotation
2116 // intersect alignment annotation with alignment groups
2118 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2119 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2122 for (int an = 0; an < aan.length; an++)
2124 if (aan[an].autoCalculated && aan[an].groupRef != null)
2126 oldrfs.add(aan[an].groupRef);
2127 alignment.deleteAnnotation(aan[an], false);
2131 if (alignment.getGroups() != null)
2133 for (SequenceGroup sg : alignment.getGroups())
2135 updateCalcs = false;
2136 if (applyGlobalSettings
2137 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2139 // set defaults for this group's conservation/consensus
2140 sg.setshowSequenceLogo(showprf);
2141 sg.setShowConsensusHistogram(showConsHist);
2142 sg.setNormaliseSequenceLogo(normLogo);
2147 alignment.addAnnotation(sg.getConservationRow(), 0);
2152 alignment.addAnnotation(sg.getConsensus(), 0);
2154 // refresh the annotation rows
2157 sg.recalcConservation();
2165 public boolean isDisplayReferenceSeq()
2167 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2171 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2173 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2177 public boolean isColourByReferenceSeq()
2179 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2183 public Color getSequenceColour(SequenceI seq)
2185 Color sqc = sequenceColours.get(seq);
2186 return (sqc == null ? Color.white : sqc);
2190 public void setSequenceColour(SequenceI seq, Color col)
2194 sequenceColours.remove(seq);
2198 sequenceColours.put(seq, col);
2203 public void updateSequenceIdColours()
2205 for (SequenceGroup sg : alignment.getGroups())
2207 if (sg.idColour != null)
2209 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2211 sequenceColours.put(s, sg.idColour);
2218 public void clearSequenceColours()
2220 sequenceColours.clear();
2224 public AlignViewportI getCodingComplement()
2226 return this.codingComplement;
2230 * Set this as the (cDna/protein) complement of the given viewport. Also
2231 * ensures the reverse relationship is set on the given viewport.
2234 public void setCodingComplement(AlignViewportI av)
2238 System.err.println("Ignoring recursive setCodingComplement request");
2242 this.codingComplement = av;
2243 // avoid infinite recursion!
2244 if (av.getCodingComplement() != this)
2246 av.setCodingComplement(this);
2252 public boolean isNucleotide()
2254 return getAlignment() == null ? false : getAlignment().isNucleotide();
2258 public FeaturesDisplayedI getFeaturesDisplayed()
2260 return featuresDisplayed;
2264 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2266 featuresDisplayed = featuresDisplayedI;
2270 public boolean areFeaturesDisplayed()
2272 return featuresDisplayed != null
2273 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2280 * features are displayed if true
2283 public void setShowSequenceFeatures(boolean b)
2285 viewStyle.setShowSequenceFeatures(b);
2289 public boolean isShowSequenceFeatures()
2291 return viewStyle.isShowSequenceFeatures();
2295 public void setShowSequenceFeaturesHeight(boolean selected)
2297 viewStyle.setShowSequenceFeaturesHeight(selected);
2301 public boolean isShowSequenceFeaturesHeight()
2303 return viewStyle.isShowSequenceFeaturesHeight();
2307 public void setShowAnnotation(boolean b)
2309 viewStyle.setShowAnnotation(b);
2313 public boolean isShowAnnotation()
2315 return viewStyle.isShowAnnotation();
2319 public boolean isRightAlignIds()
2321 return viewStyle.isRightAlignIds();
2325 public void setRightAlignIds(boolean rightAlignIds)
2327 viewStyle.setRightAlignIds(rightAlignIds);
2331 public boolean getConservationSelected()
2333 return viewStyle.getConservationSelected();
2337 public void setShowBoxes(boolean state)
2339 viewStyle.setShowBoxes(state);
2344 * @see jalview.api.ViewStyleI#getTextColour()
2347 public Color getTextColour()
2349 return viewStyle.getTextColour();
2354 * @see jalview.api.ViewStyleI#getTextColour2()
2357 public Color getTextColour2()
2359 return viewStyle.getTextColour2();
2364 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2367 public int getThresholdTextColour()
2369 return viewStyle.getThresholdTextColour();
2374 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2377 public boolean isConservationColourSelected()
2379 return viewStyle.isConservationColourSelected();
2384 * @see jalview.api.ViewStyleI#isRenderGaps()
2387 public boolean isRenderGaps()
2389 return viewStyle.isRenderGaps();
2394 * @see jalview.api.ViewStyleI#isShowColourText()
2397 public boolean isShowColourText()
2399 return viewStyle.isShowColourText();
2403 * @param conservationColourSelected
2404 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2407 public void setConservationColourSelected(
2408 boolean conservationColourSelected)
2410 viewStyle.setConservationColourSelected(conservationColourSelected);
2414 * @param showColourText
2415 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2418 public void setShowColourText(boolean showColourText)
2420 viewStyle.setShowColourText(showColourText);
2425 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2428 public void setTextColour(Color textColour)
2430 viewStyle.setTextColour(textColour);
2434 * @param thresholdTextColour
2435 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2438 public void setThresholdTextColour(int thresholdTextColour)
2440 viewStyle.setThresholdTextColour(thresholdTextColour);
2444 * @param textColour2
2445 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2448 public void setTextColour2(Color textColour2)
2450 viewStyle.setTextColour2(textColour2);
2454 public ViewStyleI getViewStyle()
2456 return new ViewStyle(viewStyle);
2460 public void setViewStyle(ViewStyleI settingsForView)
2462 viewStyle = new ViewStyle(settingsForView);
2463 if (residueShading != null)
2465 residueShading.setConservationApplied(settingsForView
2466 .isConservationColourSelected());
2471 public boolean sameStyle(ViewStyleI them)
2473 return viewStyle.sameStyle(them);
2478 * @see jalview.api.ViewStyleI#getIdWidth()
2481 public int getIdWidth()
2483 return viewStyle.getIdWidth();
2488 * @see jalview.api.ViewStyleI#setIdWidth(int)
2491 public void setIdWidth(int i)
2493 viewStyle.setIdWidth(i);
2498 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2501 public boolean isCentreColumnLabels()
2503 return viewStyle.isCentreColumnLabels();
2507 * @param centreColumnLabels
2508 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2511 public void setCentreColumnLabels(boolean centreColumnLabels)
2513 viewStyle.setCentreColumnLabels(centreColumnLabels);
2518 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2521 public void setShowDBRefs(boolean showdbrefs)
2523 viewStyle.setShowDBRefs(showdbrefs);
2528 * @see jalview.api.ViewStyleI#isShowDBRefs()
2531 public boolean isShowDBRefs()
2533 return viewStyle.isShowDBRefs();
2538 * @see jalview.api.ViewStyleI#isShowNPFeats()
2541 public boolean isShowNPFeats()
2543 return viewStyle.isShowNPFeats();
2547 * @param shownpfeats
2548 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2551 public void setShowNPFeats(boolean shownpfeats)
2553 viewStyle.setShowNPFeats(shownpfeats);
2556 public abstract StructureSelectionManager getStructureSelectionManager();
2559 * Add one command to the command history list.
2563 public void addToHistoryList(CommandI command)
2565 if (this.historyList != null)
2567 this.historyList.push(command);
2568 broadcastCommand(command, false);
2572 protected void broadcastCommand(CommandI command, boolean undo)
2574 getStructureSelectionManager().commandPerformed(command, undo,
2579 * Add one command to the command redo list.
2583 public void addToRedoList(CommandI command)
2585 if (this.redoList != null)
2587 this.redoList.push(command);
2589 broadcastCommand(command, true);
2593 * Clear the command redo list.
2595 public void clearRedoList()
2597 if (this.redoList != null)
2599 this.redoList.clear();
2603 public void setHistoryList(Deque<CommandI> list)
2605 this.historyList = list;
2608 public Deque<CommandI> getHistoryList()
2610 return this.historyList;
2613 public void setRedoList(Deque<CommandI> list)
2615 this.redoList = list;
2618 public Deque<CommandI> getRedoList()
2620 return this.redoList;
2624 public VamsasSource getVamsasSource()
2629 public SequenceAnnotationOrder getSortAnnotationsBy()
2631 return sortAnnotationsBy;
2634 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2636 this.sortAnnotationsBy = sortAnnotationsBy;
2639 public boolean isShowAutocalculatedAbove()
2641 return showAutocalculatedAbove;
2644 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2646 this.showAutocalculatedAbove = showAutocalculatedAbove;
2650 public boolean isScaleProteinAsCdna()
2652 return viewStyle.isScaleProteinAsCdna();
2656 public void setScaleProteinAsCdna(boolean b)
2658 viewStyle.setScaleProteinAsCdna(b);
2662 * @return true if view should scroll to show the highlighted region of a
2667 public final boolean isFollowHighlight()
2669 return followHighlight;
2673 public final void setFollowHighlight(boolean b)
2675 this.followHighlight = b;
2679 public ViewportRanges getRanges()
2685 * Helper method to populate the SearchResults with the location in the
2686 * complementary alignment to scroll to, in order to match this one.
2689 * the SearchResults to add to
2690 * @return the offset (below top of visible region) of the matched sequence
2692 protected int findComplementScrollTarget(SearchResultsI sr)
2694 final AlignViewportI complement = getCodingComplement();
2695 if (complement == null || !complement.isFollowHighlight())
2699 boolean iAmProtein = !getAlignment().isNucleotide();
2700 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2702 if (proteinAlignment == null)
2706 final List<AlignedCodonFrame> mappings = proteinAlignment
2710 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2711 * residue in the middle column of the visible region. Scroll the
2712 * complementary alignment to line up the corresponding residue.
2715 SequenceI sequence = null;
2718 * locate 'middle' column (true middle if an odd number visible, left of
2719 * middle if an even number visible)
2721 int middleColumn = ranges.getStartRes()
2722 + (ranges.getEndRes() - ranges.getStartRes()) / 2;
2723 final HiddenSequences hiddenSequences = getAlignment()
2724 .getHiddenSequences();
2727 * searching to the bottom of the alignment gives smoother scrolling across
2728 * all gapped visible regions
2730 int lastSeq = alignment.getHeight() - 1;
2731 List<AlignedCodonFrame> seqMappings = null;
2732 for (int seqNo = ranges.getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2734 sequence = getAlignment().getSequenceAt(seqNo);
2735 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2739 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2743 seqMappings = MappingUtils
2744 .findMappingsForSequenceAndOthers(sequence, mappings,
2745 getCodingComplement().getAlignment().getSequences());
2746 if (!seqMappings.isEmpty())
2752 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2755 * No ungapped mapped sequence in middle column - do nothing
2759 MappingUtils.addSearchResults(sr, sequence,
2760 sequence.findPosition(middleColumn), seqMappings);
2765 * synthesize a column selection if none exists so it covers the given
2766 * selection group. if wholewidth is false, no column selection is made if the
2767 * selection group covers the whole alignment width.
2772 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2775 if (sg != null && (sgs = sg.getStartRes()) >= 0
2776 && sg.getStartRes() <= (sge = sg.getEndRes())
2777 && !this.hasSelectedColumns())
2779 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2786 colSel = new ColumnSelection();
2788 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2790 colSel.addElement(cspos);
2796 * hold status of current selection group - defined on alignment or not.
2798 private boolean selectionIsDefinedGroup = false;
2801 public boolean isSelectionDefinedGroup()
2803 if (selectionGroup == null)
2807 if (isSelectionGroupChanged(true))
2809 selectionIsDefinedGroup = false;
2810 List<SequenceGroup> gps = alignment.getGroups();
2811 if (gps == null || gps.size() == 0)
2813 selectionIsDefinedGroup = false;
2817 selectionIsDefinedGroup = gps.contains(selectionGroup);
2820 return selectionGroup.getContext() == alignment
2821 || selectionIsDefinedGroup;
2825 * null, or currently highlighted results on this view
2827 private SearchResultsI searchResults = null;
2830 public boolean hasSearchResults()
2832 return searchResults != null;
2836 public void setSearchResults(SearchResultsI results)
2838 searchResults = results;
2842 public SearchResultsI getSearchResults()
2844 return searchResults;