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.schemes.Blosum62ColourScheme;
46 import jalview.schemes.ColourSchemeI;
47 import jalview.schemes.PIDColourScheme;
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 ColourSchemeI globalColourScheme = null;
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 th 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.
612 globalColourScheme = cs;
613 boolean recalc = false;
616 recalc = getConservationSelected();
617 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
618 || cs instanceof Blosum62ColourScheme)
621 cs.setThreshold(viewStyle.getThreshold(),
622 ignoreGapsInConsensusCalculation);
626 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
630 cs.setConsensus(hconsensus);
631 cs.setConservation(hconservation);
633 cs.setConservationApplied(getConservationSelected());
634 cs.alignmentChanged(alignment, hiddenRepSequences);
636 if (getColourAppliesToAllGroups())
638 for (SequenceGroup sg : getAlignment().getGroups())
645 sg.cs = cs.getInstance(sg, getHiddenRepSequences());
646 sg.setConsPercGaps(ConsPercGaps);
647 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
648 || cs instanceof Blosum62ColourScheme)
650 sg.cs.setThreshold(viewStyle.getThreshold(),
651 isIgnoreGapsConsensus());
656 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
659 if (getConservationSelected())
661 sg.cs.setConservationApplied(true);
666 sg.cs.setConservation(null);
667 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
671 sg.recalcConservation();
675 sg.cs.alignmentChanged(sg, hiddenRepSequences);
682 public ColourSchemeI getGlobalColourScheme()
684 return globalColourScheme;
687 protected AlignmentAnnotation consensus;
689 protected AlignmentAnnotation complementConsensus;
691 protected AlignmentAnnotation strucConsensus;
693 protected AlignmentAnnotation conservation;
695 protected AlignmentAnnotation quality;
697 protected AlignmentAnnotation[] groupConsensus;
699 protected AlignmentAnnotation[] groupConservation;
702 * results of alignment consensus analysis for visible portion of view
704 protected ProfilesI hconsensus = null;
707 * results of cDNA complement consensus visible portion of view
709 protected Hashtable[] hcomplementConsensus = null;
712 * results of secondary structure base pair consensus for visible portion of
715 protected Hashtable[] hStrucConsensus = null;
717 protected Conservation hconservation = null;
720 public void setConservation(Conservation cons)
722 hconservation = cons;
726 * percentage gaps allowed in a column before all amino acid properties should
727 * be considered unconserved
729 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
732 public int getConsPercGaps()
738 public void setSequenceConsensusHash(ProfilesI hconsensus)
740 this.hconsensus = hconsensus;
744 public void setComplementConsensusHash(Hashtable[] hconsensus)
746 this.hcomplementConsensus = hconsensus;
750 public ProfilesI getSequenceConsensusHash()
756 public Hashtable[] getComplementConsensusHash()
758 return hcomplementConsensus;
762 public Hashtable[] getRnaStructureConsensusHash()
764 return hStrucConsensus;
768 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
770 this.hStrucConsensus = hStrucConsensus;
775 public AlignmentAnnotation getAlignmentQualityAnnot()
781 public AlignmentAnnotation getAlignmentConservationAnnotation()
787 public AlignmentAnnotation getAlignmentConsensusAnnotation()
793 public AlignmentAnnotation getComplementConsensusAnnotation()
795 return complementConsensus;
799 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
801 return strucConsensus;
804 protected AlignCalcManagerI calculator = new AlignCalcManager();
807 * trigger update of conservation annotation
809 public void updateConservation(final AlignmentViewPanel ap)
811 // see note in mantis : issue number 8585
812 if (alignment.isNucleotide()
813 || (conservation == null && quality == null)
814 || !autoCalculateConsensus)
819 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
821 calculator.registerWorker(new jalview.workers.ConservationThread(
827 * trigger update of consensus annotation
829 public void updateConsensus(final AlignmentViewPanel ap)
831 // see note in mantis : issue number 8585
832 if (consensus == null || !autoCalculateConsensus)
836 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
838 calculator.registerWorker(new ConsensusThread(this, ap));
842 * A separate thread to compute cDNA consensus for a protein alignment
843 * which has mapping to cDNA
845 final AlignmentI al = this.getAlignment();
846 if (!al.isNucleotide() && al.getCodonFrames() != null
847 && !al.getCodonFrames().isEmpty())
850 * fudge - check first for protein-to-nucleotide mappings
851 * (we don't want to do this for protein-to-protein)
853 boolean doConsensus = false;
854 for (AlignedCodonFrame mapping : al.getCodonFrames())
856 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
857 MapList[] mapLists = mapping.getdnaToProt();
858 // mapLists can be empty if project load has not finished resolving seqs
859 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
868 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
871 .registerWorker(new ComplementConsensusThread(this, ap));
877 // --------START Structure Conservation
878 public void updateStrucConsensus(final AlignmentViewPanel ap)
880 if (autoCalculateStrucConsensus && strucConsensus == null
881 && alignment.isNucleotide() && alignment.hasRNAStructure())
883 // secondary structure has been added - so init the consensus line
887 // see note in mantis : issue number 8585
888 if (strucConsensus == null || !autoCalculateStrucConsensus)
892 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
894 calculator.registerWorker(new StrucConsensusThread(this, ap));
898 public boolean isCalcInProgress()
900 return calculator.isWorking();
904 public boolean isCalculationInProgress(
905 AlignmentAnnotation alignmentAnnotation)
907 if (!alignmentAnnotation.autoCalculated)
911 if (calculator.workingInvolvedWith(alignmentAnnotation))
913 // System.err.println("grey out ("+alignmentAnnotation.label+")");
919 public void setAlignment(AlignmentI align)
921 this.alignment = align;
925 * Clean up references when this viewport is closed
928 public void dispose()
931 * defensively null out references to large objects in case
932 * this object is not garbage collected (as if!)
935 complementConsensus = null;
936 strucConsensus = null;
939 groupConsensus = null;
940 groupConservation = null;
942 hcomplementConsensus = null;
943 // colour scheme may hold reference to consensus
944 globalColourScheme = null;
945 // TODO remove listeners from changeSupport?
946 changeSupport = null;
951 public boolean isClosed()
953 // TODO: check that this isClosed is only true after panel is closed, not
954 // before it is fully constructed.
955 return alignment == null;
959 public AlignCalcManagerI getCalcManager()
965 * should conservation rows be shown for groups
967 protected boolean showGroupConservation = false;
970 * should consensus rows be shown for groups
972 protected boolean showGroupConsensus = false;
975 * should consensus profile be rendered by default
977 protected boolean showSequenceLogo = false;
980 * should consensus profile be rendered normalised to row height
982 protected boolean normaliseSequenceLogo = false;
985 * should consensus histograms be rendered by default
987 protected boolean showConsensusHistogram = true;
990 * @return the showConsensusProfile
993 public boolean isShowSequenceLogo()
995 return showSequenceLogo;
999 * @param showSequenceLogo
1002 public void setShowSequenceLogo(boolean showSequenceLogo)
1004 if (showSequenceLogo != this.showSequenceLogo)
1006 // TODO: decouple settings setting from calculation when refactoring
1007 // annotation update method from alignframe to viewport
1008 this.showSequenceLogo = showSequenceLogo;
1009 calculator.updateAnnotationFor(ConsensusThread.class);
1010 calculator.updateAnnotationFor(ComplementConsensusThread.class);
1011 calculator.updateAnnotationFor(StrucConsensusThread.class);
1013 this.showSequenceLogo = showSequenceLogo;
1017 * @param showConsensusHistogram
1018 * the showConsensusHistogram to set
1020 public void setShowConsensusHistogram(boolean showConsensusHistogram)
1022 this.showConsensusHistogram = showConsensusHistogram;
1026 * @return the showGroupConservation
1028 public boolean isShowGroupConservation()
1030 return showGroupConservation;
1034 * @param showGroupConservation
1035 * the showGroupConservation to set
1037 public void setShowGroupConservation(boolean showGroupConservation)
1039 this.showGroupConservation = showGroupConservation;
1043 * @return the showGroupConsensus
1045 public boolean isShowGroupConsensus()
1047 return showGroupConsensus;
1051 * @param showGroupConsensus
1052 * the showGroupConsensus to set
1054 public void setShowGroupConsensus(boolean showGroupConsensus)
1056 this.showGroupConsensus = showGroupConsensus;
1061 * @return flag to indicate if the consensus histogram should be rendered by
1065 public boolean isShowConsensusHistogram()
1067 return this.showConsensusHistogram;
1071 * when set, updateAlignment will always ensure sequences are of equal length
1073 private boolean padGaps = false;
1076 * when set, alignment should be reordered according to a newly opened tree
1078 public boolean sortByTree = false;
1083 * @return null or the currently selected sequence region
1086 public SequenceGroup getSelectionGroup()
1088 return selectionGroup;
1092 * Set the selection group for this window.
1095 * - group holding references to sequences in this alignment view
1099 public void setSelectionGroup(SequenceGroup sg)
1101 selectionGroup = sg;
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 (globalColourScheme != null)
1216 globalColourScheme.setThreshold(globalColourScheme.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 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1290 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1292 protected boolean showAutocalculatedAbove;
1295 * when set, view will scroll to show the highlighted position
1297 private boolean followHighlight = true;
1299 // TODO private with getters and setters?
1300 public int startRes;
1304 public int startSeq;
1309 * Property change listener for changes in alignment
1314 public void addPropertyChangeListener(
1315 java.beans.PropertyChangeListener listener)
1317 changeSupport.addPropertyChangeListener(listener);
1326 public void removePropertyChangeListener(
1327 java.beans.PropertyChangeListener listener)
1329 changeSupport.removePropertyChangeListener(listener);
1333 * Property change listener for changes in alignment
1342 public void firePropertyChange(String prop, Object oldvalue,
1345 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1348 // common hide/show column stuff
1350 public void hideSelectedColumns()
1352 if (colSel.isEmpty())
1357 colSel.hideSelectedColumns();
1358 setSelectionGroup(null);
1359 isColSelChanged(true);
1362 public void hideColumns(int start, int end)
1366 colSel.hideColumns(start);
1370 colSel.hideColumns(start, end);
1372 isColSelChanged(true);
1375 public void showColumn(int col)
1377 colSel.revealHiddenColumns(col);
1378 isColSelChanged(true);
1381 public void showAllHiddenColumns()
1383 colSel.revealAllHiddenColumns();
1384 isColSelChanged(true);
1387 // common hide/show seq stuff
1388 public void showAllHiddenSeqs()
1390 if (alignment.getHiddenSequences().getSize() > 0)
1392 if (selectionGroup == null)
1394 selectionGroup = new SequenceGroup();
1395 selectionGroup.setEndRes(alignment.getWidth() - 1);
1397 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1398 hiddenRepSequences);
1399 for (SequenceI seq : tmp)
1401 selectionGroup.addSequence(seq, false);
1402 setSequenceAnnotationsVisible(seq, true);
1405 hiddenRepSequences = null;
1407 firePropertyChange("alignment", null, alignment.getSequences());
1408 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1414 public void showSequence(int index)
1416 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1417 index, hiddenRepSequences);
1420 if (selectionGroup == null)
1422 selectionGroup = new SequenceGroup();
1423 selectionGroup.setEndRes(alignment.getWidth() - 1);
1426 for (SequenceI seq : tmp)
1428 selectionGroup.addSequence(seq, false);
1429 setSequenceAnnotationsVisible(seq, true);
1431 firePropertyChange("alignment", null, alignment.getSequences());
1436 public void hideAllSelectedSeqs()
1438 if (selectionGroup == null || selectionGroup.getSize() < 1)
1443 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1447 setSelectionGroup(null);
1450 public void hideSequence(SequenceI[] seq)
1454 for (int i = 0; i < seq.length; i++)
1456 alignment.getHiddenSequences().hideSequence(seq[i]);
1457 setSequenceAnnotationsVisible(seq[i], false);
1459 firePropertyChange("alignment", null, alignment.getSequences());
1464 * Hides the specified sequence, or the sequences it represents
1467 * the sequence to hide, or keep as representative
1468 * @param representGroup
1469 * if true, hide the current selection group except for the
1470 * representative sequence
1472 public void hideSequences(SequenceI sequence, boolean representGroup)
1474 if (selectionGroup == null || selectionGroup.getSize() < 1)
1476 hideSequence(new SequenceI[] { sequence });
1482 hideRepSequences(sequence, selectionGroup);
1483 setSelectionGroup(null);
1487 int gsize = selectionGroup.getSize();
1488 SequenceI[] hseqs = selectionGroup.getSequences().toArray(
1489 new SequenceI[gsize]);
1491 hideSequence(hseqs);
1492 setSelectionGroup(null);
1497 * Set visibility for any annotations for the given sequence.
1501 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1504 AlignmentAnnotation[] anns = alignment.getAlignmentAnnotation();
1507 for (AlignmentAnnotation ann : anns)
1509 if (ann.sequenceRef == sequenceI)
1511 ann.visible = visible;
1517 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1519 int sSize = sg.getSize();
1525 if (hiddenRepSequences == null)
1527 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1530 hiddenRepSequences.put(repSequence, sg);
1532 // Hide all sequences except the repSequence
1533 SequenceI[] seqs = new SequenceI[sSize - 1];
1535 for (int i = 0; i < sSize; i++)
1537 if (sg.getSequenceAt(i) != repSequence)
1539 if (index == sSize - 1)
1544 seqs[index++] = sg.getSequenceAt(i);
1547 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1548 sg.setHidereps(true); // note: not done in 2.7applet
1555 * @return null or the current reference sequence
1557 public SequenceI getReferenceSeq()
1559 return alignment.getSeqrep();
1564 * @return true iff seq is the reference for the alignment
1566 public boolean isReferenceSeq(SequenceI seq)
1568 return alignment.getSeqrep() == seq;
1574 * @return true if there are sequences represented by this sequence that are
1577 public boolean isHiddenRepSequence(SequenceI seq)
1579 return (hiddenRepSequences != null && hiddenRepSequences
1586 * @return null or a sequence group containing the sequences that seq
1589 public SequenceGroup getRepresentedSequences(SequenceI seq)
1591 return (SequenceGroup) (hiddenRepSequences == null ? null
1592 : hiddenRepSequences.get(seq));
1596 public int adjustForHiddenSeqs(int alignmentIndex)
1598 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1603 public void invertColumnSelection()
1605 colSel.invertColumnSelection(0, alignment.getWidth());
1609 public SequenceI[] getSelectionAsNewSequence()
1611 SequenceI[] sequences;
1612 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1613 // this was the only caller in the applet for this method
1614 // JBPNote: in applet, this method returned references to the alignment
1615 // sequences, and it did not honour the presence/absence of annotation
1616 // attached to the alignment (probably!)
1617 if (selectionGroup == null || selectionGroup.getSize() == 0)
1619 sequences = alignment.getSequencesArray();
1620 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1621 for (int i = 0; i < sequences.length; i++)
1623 // construct new sequence with subset of visible annotation
1624 sequences[i] = new Sequence(sequences[i], annots);
1629 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1636 public SequenceI[] getSequenceSelection()
1638 SequenceI[] sequences = null;
1639 if (selectionGroup != null)
1641 sequences = selectionGroup.getSequencesInOrder(alignment);
1643 if (sequences == null)
1645 sequences = alignment.getSequencesArray();
1651 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1653 return new CigarArray(alignment, colSel,
1654 (selectedRegionOnly ? selectionGroup : null));
1658 public jalview.datamodel.AlignmentView getAlignmentView(
1659 boolean selectedOnly)
1661 return getAlignmentView(selectedOnly, false);
1665 public jalview.datamodel.AlignmentView getAlignmentView(
1666 boolean selectedOnly, boolean markGroups)
1668 return new AlignmentView(alignment, colSel, selectionGroup,
1669 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1674 public String[] getViewAsString(boolean selectedRegionOnly)
1676 return getViewAsString(selectedRegionOnly, true);
1680 public String[] getViewAsString(boolean selectedRegionOnly,
1681 boolean exportHiddenSeqs)
1683 String[] selection = null;
1684 SequenceI[] seqs = null;
1686 int start = 0, end = 0;
1687 if (selectedRegionOnly && selectionGroup != null)
1689 iSize = selectionGroup.getSize();
1690 seqs = selectionGroup.getSequencesInOrder(alignment);
1691 start = selectionGroup.getStartRes();
1692 end = selectionGroup.getEndRes() + 1;
1696 if (hasHiddenRows() && exportHiddenSeqs)
1698 AlignmentI fullAlignment = alignment.getHiddenSequences()
1699 .getFullAlignment();
1700 iSize = fullAlignment.getHeight();
1701 seqs = fullAlignment.getSequencesArray();
1702 end = fullAlignment.getWidth();
1706 iSize = alignment.getHeight();
1707 seqs = alignment.getSequencesArray();
1708 end = alignment.getWidth();
1712 selection = new String[iSize];
1713 if (colSel != null && colSel.hasHiddenColumns())
1715 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1719 for (i = 0; i < iSize; i++)
1721 selection[i] = seqs[i].getSequenceAsString(start, end);
1729 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1731 ArrayList<int[]> regions = new ArrayList<int[]>();
1737 if (colSel != null && colSel.hasHiddenColumns())
1741 start = colSel.adjustForHiddenColumns(start);
1744 end = colSel.getHiddenBoundaryRight(start);
1755 regions.add(new int[] { start, end });
1757 if (colSel != null && colSel.hasHiddenColumns())
1759 start = colSel.adjustForHiddenColumns(end);
1760 start = colSel.getHiddenBoundaryLeft(start) + 1;
1762 } while (end < max);
1764 int[][] startEnd = new int[regions.size()][2];
1770 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1771 boolean selectedOnly)
1773 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1774 AlignmentAnnotation[] aa;
1775 if ((aa = alignment.getAlignmentAnnotation()) != null)
1777 for (AlignmentAnnotation annot : aa)
1779 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1780 if (selectedOnly && selectionGroup != null)
1782 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1783 selectionGroup.getEndRes(), clone);
1787 colSel.makeVisibleAnnotation(clone);
1796 public boolean isPadGaps()
1802 public void setPadGaps(boolean padGaps)
1804 this.padGaps = padGaps;
1808 * apply any post-edit constraints and trigger any calculations needed after
1809 * an edit has been performed on the alignment
1814 public void alignmentChanged(AlignmentViewPanel ap)
1818 alignment.padGaps();
1820 if (autoCalculateConsensus)
1822 updateConsensus(ap);
1824 if (hconsensus != null && autoCalculateConsensus)
1826 updateConservation(ap);
1828 if (autoCalculateStrucConsensus)
1830 updateStrucConsensus(ap);
1833 // Reset endRes of groups if beyond alignment width
1834 int alWidth = alignment.getWidth();
1835 List<SequenceGroup> groups = alignment.getGroups();
1838 for (SequenceGroup sg : groups)
1840 if (sg.getEndRes() > alWidth)
1842 sg.setEndRes(alWidth - 1);
1847 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1849 selectionGroup.setEndRes(alWidth - 1);
1852 resetAllColourSchemes();
1853 calculator.restartWorkers();
1854 // alignment.adjustSequenceAnnotations();
1858 * reset scope and do calculations for all applied colourschemes on alignment
1860 void resetAllColourSchemes()
1862 ColourSchemeI cs = globalColourScheme;
1865 cs.alignmentChanged(alignment, hiddenRepSequences);
1867 cs.setConsensus(hconsensus);
1868 if (cs.conservationApplied())
1870 cs.setConservation(Conservation.calculateConservation("All",
1871 alignment.getSequences(), 0, alignment.getWidth(), false,
1872 getConsPercGaps(), false));
1876 for (SequenceGroup sg : alignment.getGroups())
1880 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1882 sg.recalcConservation();
1886 protected void initAutoAnnotation()
1888 // TODO: add menu option action that nulls or creates consensus object
1889 // depending on if the user wants to see the annotation or not in a
1890 // specific alignment
1892 if (hconsensus == null && !isDataset)
1894 if (!alignment.isNucleotide())
1903 consensus = new AlignmentAnnotation("Consensus", "PID",
1904 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1905 initConsensus(consensus);
1907 initComplementConsensus();
1912 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1913 * consensus annotation.
1915 public void initComplementConsensus()
1917 if (!alignment.isNucleotide())
1919 final List<AlignedCodonFrame> codonMappings = alignment
1921 if (codonMappings != null && !codonMappings.isEmpty())
1923 boolean doConsensus = false;
1924 for (AlignedCodonFrame mapping : codonMappings)
1926 // TODO hold mapping type e.g. dna-to-protein in AlignedCodonFrame?
1927 MapList[] mapLists = mapping.getdnaToProt();
1928 // mapLists can be empty if project load has not finished resolving
1930 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1938 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1939 "PID for cDNA", new Annotation[1], 0f, 100f,
1940 AlignmentAnnotation.BAR_GRAPH);
1941 initConsensus(complementConsensus);
1947 private void initConsensus(AlignmentAnnotation aa)
1950 aa.autoCalculated = true;
1954 alignment.addAnnotation(aa);
1958 private void initConservation()
1960 if (showConservation)
1962 if (conservation == null)
1964 conservation = new AlignmentAnnotation("Conservation",
1965 "Conservation of total alignment less than "
1966 + getConsPercGaps() + "% gaps", new Annotation[1],
1967 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1968 conservation.hasText = true;
1969 conservation.autoCalculated = true;
1970 alignment.addAnnotation(conservation);
1975 private void initQuality()
1979 if (quality == null)
1981 quality = new AlignmentAnnotation("Quality",
1982 "Alignment Quality based on Blosum62 scores",
1983 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1984 quality.hasText = true;
1985 quality.autoCalculated = true;
1986 alignment.addAnnotation(quality);
1991 private void initRNAStructure()
1993 if (alignment.hasRNAStructure() && strucConsensus == null)
1995 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1996 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1997 strucConsensus.hasText = true;
1998 strucConsensus.autoCalculated = true;
2002 alignment.addAnnotation(strucConsensus);
2010 * @see jalview.api.AlignViewportI#calcPanelHeight()
2013 public int calcPanelHeight()
2015 // setHeight of panels
2016 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
2018 int charHeight = getCharHeight();
2021 BitSet graphgrp = new BitSet();
2022 for (AlignmentAnnotation aa : anns)
2026 System.err.println("Null annotation row: ignoring.");
2033 if (aa.graphGroup > -1)
2035 if (graphgrp.get(aa.graphGroup))
2041 graphgrp.set(aa.graphGroup);
2048 aa.height += charHeight;
2058 aa.height += aa.graphHeight;
2066 height += aa.height;
2078 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
2079 boolean preserveNewGroupSettings)
2081 boolean updateCalcs = false;
2082 boolean conv = isShowGroupConservation();
2083 boolean cons = isShowGroupConsensus();
2084 boolean showprf = isShowSequenceLogo();
2085 boolean showConsHist = isShowConsensusHistogram();
2086 boolean normLogo = isNormaliseSequenceLogo();
2089 * TODO reorder the annotation rows according to group/sequence ordering on
2092 boolean sortg = true;
2094 // remove old automatic annotation
2095 // add any new annotation
2097 // intersect alignment annotation with alignment groups
2099 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2100 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2103 for (int an = 0; an < aan.length; an++)
2105 if (aan[an].autoCalculated && aan[an].groupRef != null)
2107 oldrfs.add(aan[an].groupRef);
2108 alignment.deleteAnnotation(aan[an], false);
2112 if (alignment.getGroups() != null)
2114 for (SequenceGroup sg : alignment.getGroups())
2116 updateCalcs = false;
2117 if (applyGlobalSettings
2118 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2120 // set defaults for this group's conservation/consensus
2121 sg.setshowSequenceLogo(showprf);
2122 sg.setShowConsensusHistogram(showConsHist);
2123 sg.setNormaliseSequenceLogo(normLogo);
2128 alignment.addAnnotation(sg.getConservationRow(), 0);
2133 alignment.addAnnotation(sg.getConsensus(), 0);
2135 // refresh the annotation rows
2138 sg.recalcConservation();
2146 public boolean isDisplayReferenceSeq()
2148 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2152 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2154 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2158 public boolean isColourByReferenceSeq()
2160 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2164 public Color getSequenceColour(SequenceI seq)
2166 Color sqc = sequenceColours.get(seq);
2167 return (sqc == null ? Color.white : sqc);
2171 public void setSequenceColour(SequenceI seq, Color col)
2175 sequenceColours.remove(seq);
2179 sequenceColours.put(seq, col);
2184 public void updateSequenceIdColours()
2186 for (SequenceGroup sg : alignment.getGroups())
2188 if (sg.idColour != null)
2190 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2192 sequenceColours.put(s, sg.idColour);
2199 public void clearSequenceColours()
2201 sequenceColours.clear();
2205 public AlignViewportI getCodingComplement()
2207 return this.codingComplement;
2211 * Set this as the (cDna/protein) complement of the given viewport. Also
2212 * ensures the reverse relationship is set on the given viewport.
2215 public void setCodingComplement(AlignViewportI av)
2219 System.err.println("Ignoring recursive setCodingComplement request");
2223 this.codingComplement = av;
2224 // avoid infinite recursion!
2225 if (av.getCodingComplement() != this)
2227 av.setCodingComplement(this);
2233 public boolean isNucleotide()
2235 return getAlignment() == null ? false : getAlignment().isNucleotide();
2239 public FeaturesDisplayedI getFeaturesDisplayed()
2241 return featuresDisplayed;
2245 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2247 featuresDisplayed = featuresDisplayedI;
2251 public boolean areFeaturesDisplayed()
2253 return featuresDisplayed != null
2254 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2261 * features are displayed if true
2264 public void setShowSequenceFeatures(boolean b)
2266 viewStyle.setShowSequenceFeatures(b);
2270 public boolean isShowSequenceFeatures()
2272 return viewStyle.isShowSequenceFeatures();
2276 public void setShowSequenceFeaturesHeight(boolean selected)
2278 viewStyle.setShowSequenceFeaturesHeight(selected);
2282 public boolean isShowSequenceFeaturesHeight()
2284 return viewStyle.isShowSequenceFeaturesHeight();
2288 public void setShowAnnotation(boolean b)
2290 viewStyle.setShowAnnotation(b);
2294 public boolean isShowAnnotation()
2296 return viewStyle.isShowAnnotation();
2300 public boolean isRightAlignIds()
2302 return viewStyle.isRightAlignIds();
2306 public void setRightAlignIds(boolean rightAlignIds)
2308 viewStyle.setRightAlignIds(rightAlignIds);
2312 public boolean getConservationSelected()
2314 return viewStyle.getConservationSelected();
2318 public void setShowBoxes(boolean state)
2320 viewStyle.setShowBoxes(state);
2325 * @see jalview.api.ViewStyleI#getTextColour()
2328 public Color getTextColour()
2330 return viewStyle.getTextColour();
2335 * @see jalview.api.ViewStyleI#getTextColour2()
2338 public Color getTextColour2()
2340 return viewStyle.getTextColour2();
2345 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2348 public int getThresholdTextColour()
2350 return viewStyle.getThresholdTextColour();
2355 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2358 public boolean isConservationColourSelected()
2360 return viewStyle.isConservationColourSelected();
2365 * @see jalview.api.ViewStyleI#isRenderGaps()
2368 public boolean isRenderGaps()
2370 return viewStyle.isRenderGaps();
2375 * @see jalview.api.ViewStyleI#isShowColourText()
2378 public boolean isShowColourText()
2380 return viewStyle.isShowColourText();
2384 * @param conservationColourSelected
2385 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2388 public void setConservationColourSelected(
2389 boolean conservationColourSelected)
2391 viewStyle.setConservationColourSelected(conservationColourSelected);
2395 * @param showColourText
2396 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2399 public void setShowColourText(boolean showColourText)
2401 viewStyle.setShowColourText(showColourText);
2406 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2409 public void setTextColour(Color textColour)
2411 viewStyle.setTextColour(textColour);
2415 * @param thresholdTextColour
2416 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2419 public void setThresholdTextColour(int thresholdTextColour)
2421 viewStyle.setThresholdTextColour(thresholdTextColour);
2425 * @param textColour2
2426 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2429 public void setTextColour2(Color textColour2)
2431 viewStyle.setTextColour2(textColour2);
2435 public ViewStyleI getViewStyle()
2437 return new ViewStyle(viewStyle);
2441 public void setViewStyle(ViewStyleI settingsForView)
2443 viewStyle = new ViewStyle(settingsForView);
2447 public boolean sameStyle(ViewStyleI them)
2449 return viewStyle.sameStyle(them);
2454 * @see jalview.api.ViewStyleI#getIdWidth()
2457 public int getIdWidth()
2459 return viewStyle.getIdWidth();
2464 * @see jalview.api.ViewStyleI#setIdWidth(int)
2467 public void setIdWidth(int i)
2469 viewStyle.setIdWidth(i);
2474 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2477 public boolean isCentreColumnLabels()
2479 return viewStyle.isCentreColumnLabels();
2483 * @param centreColumnLabels
2484 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2487 public void setCentreColumnLabels(boolean centreColumnLabels)
2489 viewStyle.setCentreColumnLabels(centreColumnLabels);
2494 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2497 public void setShowDBRefs(boolean showdbrefs)
2499 viewStyle.setShowDBRefs(showdbrefs);
2504 * @see jalview.api.ViewStyleI#isShowDBRefs()
2507 public boolean isShowDBRefs()
2509 return viewStyle.isShowDBRefs();
2514 * @see jalview.api.ViewStyleI#isShowNPFeats()
2517 public boolean isShowNPFeats()
2519 return viewStyle.isShowNPFeats();
2523 * @param shownpfeats
2524 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2527 public void setShowNPFeats(boolean shownpfeats)
2529 viewStyle.setShowNPFeats(shownpfeats);
2532 public abstract StructureSelectionManager getStructureSelectionManager();
2535 * Add one command to the command history list.
2539 public void addToHistoryList(CommandI command)
2541 if (this.historyList != null)
2543 this.historyList.push(command);
2544 broadcastCommand(command, false);
2548 protected void broadcastCommand(CommandI command, boolean undo)
2550 getStructureSelectionManager().commandPerformed(command, undo,
2555 * Add one command to the command redo list.
2559 public void addToRedoList(CommandI command)
2561 if (this.redoList != null)
2563 this.redoList.push(command);
2565 broadcastCommand(command, true);
2569 * Clear the command redo list.
2571 public void clearRedoList()
2573 if (this.redoList != null)
2575 this.redoList.clear();
2579 public void setHistoryList(Deque<CommandI> list)
2581 this.historyList = list;
2584 public Deque<CommandI> getHistoryList()
2586 return this.historyList;
2589 public void setRedoList(Deque<CommandI> list)
2591 this.redoList = list;
2594 public Deque<CommandI> getRedoList()
2596 return this.redoList;
2600 public VamsasSource getVamsasSource()
2605 public SequenceAnnotationOrder getSortAnnotationsBy()
2607 return sortAnnotationsBy;
2610 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2612 this.sortAnnotationsBy = sortAnnotationsBy;
2615 public boolean isShowAutocalculatedAbove()
2617 return showAutocalculatedAbove;
2620 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2622 this.showAutocalculatedAbove = showAutocalculatedAbove;
2626 public boolean isScaleProteinAsCdna()
2628 return viewStyle.isScaleProteinAsCdna();
2632 public void setScaleProteinAsCdna(boolean b)
2634 viewStyle.setScaleProteinAsCdna(b);
2638 * @return true if view should scroll to show the highlighted region of a
2643 public final boolean isFollowHighlight()
2645 return followHighlight;
2649 public final void setFollowHighlight(boolean b)
2651 this.followHighlight = b;
2654 public int getStartRes()
2660 public int getEndRes()
2665 public int getStartSeq()
2670 public void setStartRes(int res)
2672 this.startRes = res;
2675 public void setStartSeq(int seq)
2677 this.startSeq = seq;
2680 public void setEndRes(int res)
2682 if (res > alignment.getWidth() - 1)
2684 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2685 // (alignment.getWidth()-1));
2686 res = alignment.getWidth() - 1;
2695 public void setEndSeq(int seq)
2697 if (seq > alignment.getHeight())
2699 seq = alignment.getHeight();
2708 public int getEndSeq()
2714 * Helper method to populate the SearchResults with the location in the
2715 * complementary alignment to scroll to, in order to match this one.
2718 * the SearchResults to add to
2719 * @return the offset (below top of visible region) of the matched sequence
2721 protected int findComplementScrollTarget(SearchResultsI sr)
2723 final AlignViewportI complement = getCodingComplement();
2724 if (complement == null || !complement.isFollowHighlight())
2728 boolean iAmProtein = !getAlignment().isNucleotide();
2729 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2731 if (proteinAlignment == null)
2735 final List<AlignedCodonFrame> mappings = proteinAlignment
2739 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2740 * residue in the middle column of the visible region. Scroll the
2741 * complementary alignment to line up the corresponding residue.
2744 SequenceI sequence = null;
2747 * locate 'middle' column (true middle if an odd number visible, left of
2748 * middle if an even number visible)
2750 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2751 final HiddenSequences hiddenSequences = getAlignment()
2752 .getHiddenSequences();
2755 * searching to the bottom of the alignment gives smoother scrolling across
2756 * all gapped visible regions
2758 int lastSeq = alignment.getHeight() - 1;
2759 List<AlignedCodonFrame> seqMappings = null;
2760 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2762 sequence = getAlignment().getSequenceAt(seqNo);
2763 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2767 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2771 seqMappings = MappingUtils
2772 .findMappingsForSequenceAndOthers(sequence, mappings,
2773 getCodingComplement().getAlignment().getSequences());
2774 if (!seqMappings.isEmpty())
2780 if (sequence == null || seqMappings == null || seqMappings.isEmpty())
2783 * No ungapped mapped sequence in middle column - do nothing
2787 MappingUtils.addSearchResults(sr, sequence,
2788 sequence.findPosition(middleColumn), seqMappings);
2793 * synthesize a column selection if none exists so it covers the given
2794 * selection group. if wholewidth is false, no column selection is made if the
2795 * selection group covers the whole alignment width.
2800 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2803 if (sg != null && (sgs = sg.getStartRes()) >= 0
2804 && sg.getStartRes() <= (sge = sg.getEndRes())
2805 && !this.hasSelectedColumns())
2807 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2814 colSel = new ColumnSelection();
2816 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2818 colSel.addElement(cspos);
2824 * hold status of current selection group - defined on alignment or not.
2826 private boolean selectionIsDefinedGroup = false;
2830 public boolean isSelectionDefinedGroup()
2832 if (selectionGroup == null)
2836 if (isSelectionGroupChanged(true))
2838 selectionIsDefinedGroup = false;
2839 List<SequenceGroup> gps = alignment.getGroups();
2840 if (gps == null || gps.size() == 0)
2842 selectionIsDefinedGroup = false;
2846 selectionIsDefinedGroup = gps.contains(selectionGroup);
2849 return selectionGroup.getContext() == alignment
2850 || selectionIsDefinedGroup;
2854 * null, or currently highlighted results on this view
2856 private SearchResultsI searchResults = null;
2859 public boolean hasSearchResults()
2861 return searchResults != null;
2865 public void setSearchResults(SearchResultsI results)
2867 searchResults = results;
2871 public SearchResultsI getSearchResults()
2873 return searchResults;