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.SearchResults;
40 import jalview.datamodel.Sequence;
41 import jalview.datamodel.SequenceCollectionI;
42 import jalview.datamodel.SequenceGroup;
43 import jalview.datamodel.SequenceI;
44 import jalview.schemes.Blosum62ColourScheme;
45 import jalview.schemes.ColourSchemeI;
46 import jalview.schemes.PIDColourScheme;
47 import jalview.schemes.ResidueProperties;
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.util.ArrayDeque;
62 import java.util.ArrayList;
63 import java.util.BitSet;
64 import java.util.Deque;
65 import java.util.HashMap;
66 import java.util.Hashtable;
67 import java.util.List;
71 * base class holding visualization and analysis attributes and common logic for
72 * an active alignment view displayed in the GUI
77 public abstract class AlignmentViewport implements AlignViewportI,
78 CommandListener, VamsasSource
80 protected ViewStyleI viewStyle = new ViewStyle();
83 * A viewport that hosts the cDna view of this (protein), or vice versa (if
86 AlignViewportI codingComplement = null;
88 FeaturesDisplayedI featuresDisplayed = null;
90 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
92 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
96 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
99 public void setFontName(String name)
101 viewStyle.setFontName(name);
106 * @see jalview.api.ViewStyleI#setFontStyle(int)
109 public void setFontStyle(int style)
111 viewStyle.setFontStyle(style);
116 * @see jalview.api.ViewStyleI#setFontSize(int)
119 public void setFontSize(int size)
121 viewStyle.setFontSize(size);
126 * @see jalview.api.ViewStyleI#getFontStyle()
129 public int getFontStyle()
131 return viewStyle.getFontStyle();
136 * @see jalview.api.ViewStyleI#getFontName()
139 public String getFontName()
141 return viewStyle.getFontName();
146 * @see jalview.api.ViewStyleI#getFontSize()
149 public int getFontSize()
151 return viewStyle.getFontSize();
155 * @param upperCasebold
156 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
159 public void setUpperCasebold(boolean upperCasebold)
161 viewStyle.setUpperCasebold(upperCasebold);
166 * @see jalview.api.ViewStyleI#isUpperCasebold()
169 public boolean isUpperCasebold()
171 return viewStyle.isUpperCasebold();
176 * @see jalview.api.ViewStyleI#isSeqNameItalics()
179 public boolean isSeqNameItalics()
181 return viewStyle.isSeqNameItalics();
185 * @param colourByReferenceSeq
186 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
189 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
191 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
196 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
199 public void setColourAppliesToAllGroups(boolean b)
201 viewStyle.setColourAppliesToAllGroups(b);
206 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
209 public boolean getColourAppliesToAllGroups()
211 return viewStyle.getColourAppliesToAllGroups();
216 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
219 public boolean getAbovePIDThreshold()
221 return viewStyle.getAbovePIDThreshold();
226 * @see jalview.api.ViewStyleI#setIncrement(int)
229 public void setIncrement(int inc)
231 viewStyle.setIncrement(inc);
236 * @see jalview.api.ViewStyleI#getIncrement()
239 public int getIncrement()
241 return viewStyle.getIncrement();
246 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
249 public void setConservationSelected(boolean b)
251 viewStyle.setConservationSelected(b);
256 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
259 public void setShowHiddenMarkers(boolean show)
261 viewStyle.setShowHiddenMarkers(show);
266 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
269 public boolean getShowHiddenMarkers()
271 return viewStyle.getShowHiddenMarkers();
276 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
279 public void setScaleRightWrapped(boolean b)
281 viewStyle.setScaleRightWrapped(b);
286 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
289 public void setScaleLeftWrapped(boolean b)
291 viewStyle.setScaleLeftWrapped(b);
296 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
299 public void setScaleAboveWrapped(boolean b)
301 viewStyle.setScaleAboveWrapped(b);
306 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
309 public boolean getScaleLeftWrapped()
311 return viewStyle.getScaleLeftWrapped();
316 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
319 public boolean getScaleAboveWrapped()
321 return viewStyle.getScaleAboveWrapped();
326 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
329 public boolean getScaleRightWrapped()
331 return viewStyle.getScaleRightWrapped();
336 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
339 public void setAbovePIDThreshold(boolean b)
341 viewStyle.setAbovePIDThreshold(b);
346 * @see jalview.api.ViewStyleI#setThreshold(int)
349 public void setThreshold(int thresh)
351 viewStyle.setThreshold(thresh);
356 * @see jalview.api.ViewStyleI#getThreshold()
359 public int getThreshold()
361 return viewStyle.getThreshold();
366 * @see jalview.api.ViewStyleI#getShowJVSuffix()
369 public boolean getShowJVSuffix()
371 return viewStyle.getShowJVSuffix();
376 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
379 public void setShowJVSuffix(boolean b)
381 viewStyle.setShowJVSuffix(b);
386 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
389 public void setWrapAlignment(boolean state)
391 viewStyle.setWrapAlignment(state);
396 * @see jalview.api.ViewStyleI#setShowText(boolean)
399 public void setShowText(boolean state)
401 viewStyle.setShowText(state);
406 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
409 public void setRenderGaps(boolean state)
411 viewStyle.setRenderGaps(state);
416 * @see jalview.api.ViewStyleI#getColourText()
419 public boolean getColourText()
421 return viewStyle.getColourText();
426 * @see jalview.api.ViewStyleI#setColourText(boolean)
429 public void setColourText(boolean state)
431 viewStyle.setColourText(state);
436 * @see jalview.api.ViewStyleI#getWrapAlignment()
439 public boolean getWrapAlignment()
441 return viewStyle.getWrapAlignment();
446 * @see jalview.api.ViewStyleI#getShowText()
449 public boolean getShowText()
451 return viewStyle.getShowText();
456 * @see jalview.api.ViewStyleI#getWrappedWidth()
459 public int getWrappedWidth()
461 return viewStyle.getWrappedWidth();
466 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
469 public void setWrappedWidth(int w)
471 viewStyle.setWrappedWidth(w);
476 * @see jalview.api.ViewStyleI#getCharHeight()
479 public int getCharHeight()
481 return viewStyle.getCharHeight();
486 * @see jalview.api.ViewStyleI#setCharHeight(int)
489 public void setCharHeight(int h)
491 viewStyle.setCharHeight(h);
496 * @see jalview.api.ViewStyleI#getCharWidth()
499 public int getCharWidth()
501 return viewStyle.getCharWidth();
506 * @see jalview.api.ViewStyleI#setCharWidth(int)
509 public void setCharWidth(int w)
511 viewStyle.setCharWidth(w);
516 * @see jalview.api.ViewStyleI#getShowBoxes()
519 public boolean getShowBoxes()
521 return viewStyle.getShowBoxes();
526 * @see jalview.api.ViewStyleI#getShowUnconserved()
529 public boolean getShowUnconserved()
531 return viewStyle.getShowUnconserved();
535 * @param showunconserved
536 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
539 public void setShowUnconserved(boolean showunconserved)
541 viewStyle.setShowUnconserved(showunconserved);
546 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
549 public void setSeqNameItalics(boolean default1)
551 viewStyle.setSeqNameItalics(default1);
555 * alignment displayed in the viewport. Please use get/setter
557 protected AlignmentI alignment;
560 public AlignmentI getAlignment()
566 public char getGapCharacter()
568 return alignment.getGapCharacter();
571 protected String sequenceSetID;
574 * probably unused indicator that view is of a dataset rather than an
577 protected boolean isDataset = false;
579 public void setDataset(boolean b)
584 public boolean isDataset()
589 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
591 protected ColumnSelection colSel = new ColumnSelection();
593 public boolean autoCalculateConsensus = true;
595 protected boolean autoCalculateStrucConsensus = true;
597 protected boolean ignoreGapsInConsensusCalculation = false;
599 protected ColourSchemeI globalColourScheme = null;
602 public void setGlobalColourScheme(ColourSchemeI cs)
604 // TODO: logic refactored from AlignFrame changeColour -
605 // TODO: autorecalc stuff should be changed to rely on the worker system
606 // check to see if we should implement a changeColour(cs) method rather than
607 // put th logic in here
608 // - means that caller decides if they want to just modify state and defer
609 // calculation till later or to do all calculations in thread.
611 globalColourScheme = cs;
612 boolean recalc = false;
615 cs.setConservationApplied(recalc = getConservationSelected());
616 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
617 || cs instanceof Blosum62ColourScheme)
620 cs.setThreshold(viewStyle.getThreshold(),
621 ignoreGapsInConsensusCalculation);
625 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
629 cs.setConsensus(hconsensus);
630 cs.setConservation(hconservation);
632 cs.alignmentChanged(alignment, hiddenRepSequences);
634 if (getColourAppliesToAllGroups())
636 for (SequenceGroup sg : getAlignment().getGroups())
643 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
644 sg.setConsPercGaps(ConsPercGaps);
645 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
646 || cs instanceof Blosum62ColourScheme)
648 sg.cs.setThreshold(viewStyle.getThreshold(),
649 isIgnoreGapsConsensus());
654 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
657 if (getConservationSelected())
659 sg.cs.setConservationApplied(true);
664 sg.cs.setConservation(null);
665 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
669 sg.recalcConservation();
673 sg.cs.alignmentChanged(sg, hiddenRepSequences);
680 public ColourSchemeI getGlobalColourScheme()
682 return globalColourScheme;
685 protected AlignmentAnnotation consensus;
687 protected AlignmentAnnotation complementConsensus;
689 protected AlignmentAnnotation strucConsensus;
691 protected AlignmentAnnotation conservation;
693 protected AlignmentAnnotation quality;
695 protected AlignmentAnnotation[] groupConsensus;
697 protected AlignmentAnnotation[] groupConservation;
700 * results of alignment consensus analysis for visible portion of view
702 protected Hashtable[] hconsensus = null;
705 * results of cDNA complement consensus visible portion of view
707 protected Hashtable[] hcomplementConsensus = null;
710 * results of secondary structure base pair consensus for visible portion of
713 protected Hashtable[] hStrucConsensus = null;
715 protected Conservation hconservation = null;
718 public void setConservation(Conservation cons)
720 hconservation = cons;
724 * percentage gaps allowed in a column before all amino acid properties should
725 * be considered unconserved
727 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
730 public int getConsPercGaps()
736 public void setSequenceConsensusHash(Hashtable[] hconsensus)
738 this.hconsensus = hconsensus;
742 public void setComplementConsensusHash(Hashtable[] hconsensus)
744 this.hcomplementConsensus = hconsensus;
748 public Hashtable[] getSequenceConsensusHash()
754 public Hashtable[] getComplementConsensusHash()
756 return hcomplementConsensus;
760 public Hashtable[] getRnaStructureConsensusHash()
762 return hStrucConsensus;
766 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
768 this.hStrucConsensus = hStrucConsensus;
773 public AlignmentAnnotation getAlignmentQualityAnnot()
779 public AlignmentAnnotation getAlignmentConservationAnnotation()
785 public AlignmentAnnotation getAlignmentConsensusAnnotation()
791 public AlignmentAnnotation getComplementConsensusAnnotation()
793 return complementConsensus;
797 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
799 return strucConsensus;
802 protected AlignCalcManagerI calculator = new AlignCalcManager();
805 * trigger update of conservation annotation
807 public void updateConservation(final AlignmentViewPanel ap)
809 // see note in mantis : issue number 8585
810 if (alignment.isNucleotide() || conservation == null
811 || !autoCalculateConsensus)
816 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
818 calculator.registerWorker(new jalview.workers.ConservationThread(
824 * trigger update of consensus annotation
826 public void updateConsensus(final AlignmentViewPanel ap)
828 // see note in mantis : issue number 8585
829 if (consensus == null || !autoCalculateConsensus)
833 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
835 calculator.registerWorker(new ConsensusThread(this, ap));
839 * A separate thread to compute cDNA consensus for a protein alignment
840 * which has mapping to cDNA
842 final AlignmentI al = this.getAlignment();
843 if (!al.isNucleotide() && al.getCodonFrames() != null
844 && !al.getCodonFrames().isEmpty())
847 * fudge - check first mapping is protein-to-nucleotide
848 * (we don't want to do this for protein-to-protein)
850 AlignedCodonFrame mapping = al.getCodonFrames().iterator().next();
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)
857 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
860 .registerWorker(new ComplementConsensusThread(this, ap));
866 // --------START Structure Conservation
867 public void updateStrucConsensus(final AlignmentViewPanel ap)
869 if (autoCalculateStrucConsensus && strucConsensus == null
870 && alignment.isNucleotide() && alignment.hasRNAStructure())
872 // secondary structure has been added - so init the consensus line
876 // see note in mantis : issue number 8585
877 if (strucConsensus == null || !autoCalculateStrucConsensus)
881 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
883 calculator.registerWorker(new StrucConsensusThread(this, ap));
887 public boolean isCalcInProgress()
889 return calculator.isWorking();
893 public boolean isCalculationInProgress(
894 AlignmentAnnotation alignmentAnnotation)
896 if (!alignmentAnnotation.autoCalculated)
900 if (calculator.workingInvolvedWith(alignmentAnnotation))
902 // System.err.println("grey out ("+alignmentAnnotation.label+")");
909 public boolean isClosed()
911 // TODO: check that this isClosed is only true after panel is closed, not
912 // before it is fully constructed.
913 return alignment == null;
917 public AlignCalcManagerI getCalcManager()
923 * should conservation rows be shown for groups
925 protected boolean showGroupConservation = false;
928 * should consensus rows be shown for groups
930 protected boolean showGroupConsensus = false;
933 * should consensus profile be rendered by default
935 protected boolean showSequenceLogo = false;
938 * should consensus profile be rendered normalised to row height
940 protected boolean normaliseSequenceLogo = false;
943 * should consensus histograms be rendered by default
945 protected boolean showConsensusHistogram = true;
948 * @return the showConsensusProfile
951 public boolean isShowSequenceLogo()
953 return showSequenceLogo;
957 * @param showSequenceLogo
960 public void setShowSequenceLogo(boolean showSequenceLogo)
962 if (showSequenceLogo != this.showSequenceLogo)
964 // TODO: decouple settings setting from calculation when refactoring
965 // annotation update method from alignframe to viewport
966 this.showSequenceLogo = showSequenceLogo;
967 calculator.updateAnnotationFor(ConsensusThread.class);
968 calculator.updateAnnotationFor(ComplementConsensusThread.class);
969 calculator.updateAnnotationFor(StrucConsensusThread.class);
971 this.showSequenceLogo = showSequenceLogo;
975 * @param showConsensusHistogram
976 * the showConsensusHistogram to set
978 public void setShowConsensusHistogram(boolean showConsensusHistogram)
980 this.showConsensusHistogram = showConsensusHistogram;
984 * @return the showGroupConservation
986 public boolean isShowGroupConservation()
988 return showGroupConservation;
992 * @param showGroupConservation
993 * the showGroupConservation to set
995 public void setShowGroupConservation(boolean showGroupConservation)
997 this.showGroupConservation = showGroupConservation;
1001 * @return the showGroupConsensus
1003 public boolean isShowGroupConsensus()
1005 return showGroupConsensus;
1009 * @param showGroupConsensus
1010 * the showGroupConsensus to set
1012 public void setShowGroupConsensus(boolean showGroupConsensus)
1014 this.showGroupConsensus = showGroupConsensus;
1019 * @return flag to indicate if the consensus histogram should be rendered by
1023 public boolean isShowConsensusHistogram()
1025 return this.showConsensusHistogram;
1029 * when set, updateAlignment will always ensure sequences are of equal length
1031 private boolean padGaps = false;
1034 * when set, alignment should be reordered according to a newly opened tree
1036 public boolean sortByTree = false;
1041 * @return null or the currently selected sequence region
1044 public SequenceGroup getSelectionGroup()
1046 return selectionGroup;
1050 * Set the selection group for this window.
1053 * - group holding references to sequences in this alignment view
1057 public void setSelectionGroup(SequenceGroup sg)
1059 selectionGroup = sg;
1062 public void setHiddenColumns(ColumnSelection colsel)
1064 this.colSel = colsel;
1068 public ColumnSelection getColumnSelection()
1074 public void setColumnSelection(ColumnSelection colSel)
1076 this.colSel = colSel;
1079 updateHiddenColumns();
1081 isColSelChanged(true);
1089 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1091 return hiddenRepSequences;
1095 public void setHiddenRepSequences(
1096 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1098 this.hiddenRepSequences = hiddenRepSequences;
1102 public boolean hasHiddenColumns()
1104 return colSel != null && colSel.hasHiddenColumns();
1107 public void updateHiddenColumns()
1109 // this method doesn't really do anything now. But - it could, since a
1110 // column Selection could be in the process of modification
1111 // hasHiddenColumns = colSel.hasHiddenColumns();
1115 public boolean hasHiddenRows()
1117 return alignment.getHiddenSequences().getSize() > 0;
1120 protected SequenceGroup selectionGroup;
1122 public void setSequenceSetId(String newid)
1124 if (sequenceSetID != null)
1127 .println("Warning - overwriting a sequenceSetId for a viewport!");
1129 sequenceSetID = new String(newid);
1133 public String getSequenceSetId()
1135 if (sequenceSetID == null)
1137 sequenceSetID = alignment.hashCode() + "";
1140 return sequenceSetID;
1144 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1147 protected String viewId = null;
1150 public String getViewId()
1154 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1159 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1161 ignoreGapsInConsensusCalculation = b;
1164 updateConsensus(ap);
1165 if (globalColourScheme != null)
1167 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1168 ignoreGapsInConsensusCalculation);
1174 private long sgrouphash = -1, colselhash = -1;
1177 * checks current SelectionGroup against record of last hash value, and
1181 * update the record of last hash value
1183 * @return true if SelectionGroup changed since last call (when b is true)
1185 public boolean isSelectionGroupChanged(boolean b)
1187 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1188 : selectionGroup.hashCode();
1189 if (hc != -1 && hc != sgrouphash)
1201 * checks current colsel against record of last hash value, and optionally
1205 * update the record of last hash value
1206 * @return true if colsel changed since last call (when b is true)
1208 public boolean isColSelChanged(boolean b)
1210 int hc = (colSel == null || colSel.isEmpty()) ? -1 : colSel.hashCode();
1211 if (hc != -1 && hc != colselhash)
1223 public boolean isIgnoreGapsConsensus()
1225 return ignoreGapsInConsensusCalculation;
1228 // / property change stuff
1230 // JBPNote Prolly only need this in the applet version.
1231 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1234 protected boolean showConservation = true;
1236 protected boolean showQuality = true;
1238 protected boolean showConsensus = true;
1240 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1242 protected SequenceAnnotationOrder sortAnnotationsBy = null;
1244 protected boolean showAutocalculatedAbove;
1247 * when set, view will scroll to show the highlighted position
1249 private boolean followHighlight = true;
1251 // TODO private with getters and setters?
1252 public int startRes;
1256 public int startSeq;
1261 * Property change listener for changes in alignment
1266 public void addPropertyChangeListener(
1267 java.beans.PropertyChangeListener listener)
1269 changeSupport.addPropertyChangeListener(listener);
1278 public void removePropertyChangeListener(
1279 java.beans.PropertyChangeListener listener)
1281 changeSupport.removePropertyChangeListener(listener);
1285 * Property change listener for changes in alignment
1294 public void firePropertyChange(String prop, Object oldvalue,
1297 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1300 // common hide/show column stuff
1302 public void hideSelectedColumns()
1304 if (colSel.isEmpty())
1309 colSel.hideSelectedColumns();
1310 setSelectionGroup(null);
1311 isColSelChanged(true);
1314 public void hideColumns(int start, int end)
1318 colSel.hideColumns(start);
1322 colSel.hideColumns(start, end);
1324 isColSelChanged(true);
1327 public void showColumn(int col)
1329 colSel.revealHiddenColumns(col);
1330 isColSelChanged(true);
1333 public void showAllHiddenColumns()
1335 colSel.revealAllHiddenColumns();
1336 isColSelChanged(true);
1339 // common hide/show seq stuff
1340 public void showAllHiddenSeqs()
1342 if (alignment.getHiddenSequences().getSize() > 0)
1344 if (selectionGroup == null)
1346 selectionGroup = new SequenceGroup();
1347 selectionGroup.setEndRes(alignment.getWidth() - 1);
1349 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1350 hiddenRepSequences);
1351 for (SequenceI seq : tmp)
1353 selectionGroup.addSequence(seq, false);
1354 setSequenceAnnotationsVisible(seq, true);
1357 hiddenRepSequences = null;
1359 firePropertyChange("alignment", null, alignment.getSequences());
1360 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1366 public void showSequence(int index)
1368 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1369 index, hiddenRepSequences);
1372 if (selectionGroup == null)
1374 selectionGroup = new SequenceGroup();
1375 selectionGroup.setEndRes(alignment.getWidth() - 1);
1378 for (SequenceI seq : tmp)
1380 selectionGroup.addSequence(seq, false);
1381 setSequenceAnnotationsVisible(seq, true);
1383 firePropertyChange("alignment", null, alignment.getSequences());
1388 public void hideAllSelectedSeqs()
1390 if (selectionGroup == null || selectionGroup.getSize() < 1)
1395 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1399 setSelectionGroup(null);
1402 public void hideSequence(SequenceI[] seq)
1406 for (int i = 0; i < seq.length; i++)
1408 alignment.getHiddenSequences().hideSequence(seq[i]);
1409 setSequenceAnnotationsVisible(seq[i], false);
1411 firePropertyChange("alignment", null, alignment.getSequences());
1416 * Set visibility for any annotations for the given sequence.
1420 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1423 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1425 if (ann.sequenceRef == sequenceI)
1427 ann.visible = visible;
1432 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1434 int sSize = sg.getSize();
1440 if (hiddenRepSequences == null)
1442 hiddenRepSequences = new Hashtable<SequenceI, SequenceCollectionI>();
1445 hiddenRepSequences.put(repSequence, sg);
1447 // Hide all sequences except the repSequence
1448 SequenceI[] seqs = new SequenceI[sSize - 1];
1450 for (int i = 0; i < sSize; i++)
1452 if (sg.getSequenceAt(i) != repSequence)
1454 if (index == sSize - 1)
1459 seqs[index++] = sg.getSequenceAt(i);
1462 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1463 sg.setHidereps(true); // note: not done in 2.7applet
1470 * @return null or the current reference sequence
1472 public SequenceI getReferenceSeq()
1474 return alignment.getSeqrep();
1479 * @return true iff seq is the reference for the alignment
1481 public boolean isReferenceSeq(SequenceI seq)
1483 return alignment.getSeqrep() == seq;
1489 * @return true if there are sequences represented by this sequence that are
1492 public boolean isHiddenRepSequence(SequenceI seq)
1494 return (hiddenRepSequences != null && hiddenRepSequences
1501 * @return null or a sequence group containing the sequences that seq
1504 public SequenceGroup getRepresentedSequences(SequenceI seq)
1506 return (SequenceGroup) (hiddenRepSequences == null ? null
1507 : hiddenRepSequences.get(seq));
1511 public int adjustForHiddenSeqs(int alignmentIndex)
1513 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1518 public void invertColumnSelection()
1520 colSel.invertColumnSelection(0, alignment.getWidth());
1524 public SequenceI[] getSelectionAsNewSequence()
1526 SequenceI[] sequences;
1527 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1528 // this was the only caller in the applet for this method
1529 // JBPNote: in applet, this method returned references to the alignment
1530 // sequences, and it did not honour the presence/absence of annotation
1531 // attached to the alignment (probably!)
1532 if (selectionGroup == null || selectionGroup.getSize() == 0)
1534 sequences = alignment.getSequencesArray();
1535 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1536 for (int i = 0; i < sequences.length; i++)
1538 // construct new sequence with subset of visible annotation
1539 sequences[i] = new Sequence(sequences[i], annots);
1544 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1551 public SequenceI[] getSequenceSelection()
1553 SequenceI[] sequences = null;
1554 if (selectionGroup != null)
1556 sequences = selectionGroup.getSequencesInOrder(alignment);
1558 if (sequences == null)
1560 sequences = alignment.getSequencesArray();
1566 public CigarArray getViewAsCigars(boolean selectedRegionOnly)
1568 return new CigarArray(alignment, colSel,
1569 (selectedRegionOnly ? selectionGroup : null));
1573 public jalview.datamodel.AlignmentView getAlignmentView(
1574 boolean selectedOnly)
1576 return getAlignmentView(selectedOnly, false);
1580 public jalview.datamodel.AlignmentView getAlignmentView(
1581 boolean selectedOnly, boolean markGroups)
1583 return new AlignmentView(alignment, colSel, selectionGroup,
1584 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1589 public String[] getViewAsString(boolean selectedRegionOnly)
1591 String[] selection = null;
1592 SequenceI[] seqs = null;
1594 int start = 0, end = 0;
1595 if (selectedRegionOnly && selectionGroup != null)
1597 iSize = selectionGroup.getSize();
1598 seqs = selectionGroup.getSequencesInOrder(alignment);
1599 start = selectionGroup.getStartRes();
1600 end = selectionGroup.getEndRes() + 1;
1604 if (hasHiddenRows() && isExportHiddenSeqs)
1606 iSize = alignment.getHiddenSequences().getFullAlignment()
1608 seqs = alignment.getHiddenSequences().getFullAlignment()
1609 .getSequencesArray();
1610 end = alignment.getHiddenSequences().getFullAlignment().getWidth();
1614 iSize = alignment.getHeight();
1615 seqs = alignment.getSequencesArray();
1616 end = alignment.getWidth();
1620 selection = new String[iSize];
1621 if (colSel != null && colSel.hasHiddenColumns())
1623 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1627 for (i = 0; i < iSize; i++)
1629 selection[i] = seqs[i].getSequenceAsString(start, end);
1637 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1639 ArrayList<int[]> regions = new ArrayList<int[]>();
1645 if (colSel != null && colSel.hasHiddenColumns())
1649 start = colSel.adjustForHiddenColumns(start);
1652 end = colSel.getHiddenBoundaryRight(start);
1663 regions.add(new int[] { start, end });
1665 if (colSel != null && colSel.hasHiddenColumns())
1667 start = colSel.adjustForHiddenColumns(end);
1668 start = colSel.getHiddenBoundaryLeft(start) + 1;
1670 } while (end < max);
1672 int[][] startEnd = new int[regions.size()][2];
1678 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(
1679 boolean selectedOnly)
1681 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1682 AlignmentAnnotation[] aa;
1683 if ((aa = alignment.getAlignmentAnnotation()) != null)
1685 for (AlignmentAnnotation annot : aa)
1687 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1688 if (selectedOnly && selectionGroup != null)
1690 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(),
1691 selectionGroup.getEndRes(), clone);
1695 colSel.makeVisibleAnnotation(clone);
1704 public boolean isPadGaps()
1710 public void setPadGaps(boolean padGaps)
1712 this.padGaps = padGaps;
1716 * apply any post-edit constraints and trigger any calculations needed after
1717 * an edit has been performed on the alignment
1722 public void alignmentChanged(AlignmentViewPanel ap)
1726 alignment.padGaps();
1728 if (autoCalculateConsensus)
1730 updateConsensus(ap);
1732 if (hconsensus != null && autoCalculateConsensus)
1734 updateConservation(ap);
1736 if (autoCalculateStrucConsensus)
1738 updateStrucConsensus(ap);
1741 // Reset endRes of groups if beyond alignment width
1742 int alWidth = alignment.getWidth();
1743 List<SequenceGroup> groups = alignment.getGroups();
1746 for (SequenceGroup sg : groups)
1748 if (sg.getEndRes() > alWidth)
1750 sg.setEndRes(alWidth - 1);
1755 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1757 selectionGroup.setEndRes(alWidth - 1);
1760 resetAllColourSchemes();
1761 calculator.restartWorkers();
1762 // alignment.adjustSequenceAnnotations();
1766 * reset scope and do calculations for all applied colourschemes on alignment
1768 void resetAllColourSchemes()
1770 ColourSchemeI cs = globalColourScheme;
1773 cs.alignmentChanged(alignment, hiddenRepSequences);
1775 cs.setConsensus(hconsensus);
1776 if (cs.conservationApplied())
1778 cs.setConservation(Conservation.calculateConservation("All",
1779 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1780 alignment.getWidth(), false, getConsPercGaps(), false));
1784 for (SequenceGroup sg : alignment.getGroups())
1788 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1790 sg.recalcConservation();
1794 protected void initAutoAnnotation()
1796 // TODO: add menu option action that nulls or creates consensus object
1797 // depending on if the user wants to see the annotation or not in a
1798 // specific alignment
1800 if (hconsensus == null && !isDataset)
1802 if (!alignment.isNucleotide())
1811 consensus = new AlignmentAnnotation("Consensus", "PID",
1812 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1813 initConsensus(consensus);
1815 initComplementConsensus();
1820 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1821 * consensus annotation.
1823 public void initComplementConsensus()
1825 if (!alignment.isNucleotide())
1827 final List<AlignedCodonFrame> codonMappings = alignment
1829 if (codonMappings != null && !codonMappings.isEmpty())
1831 // fudge: check mappings are not protein-to-protein
1833 AlignedCodonFrame mapping = codonMappings.iterator().next();
1834 MapList[] mapLists = mapping.getdnaToProt();
1835 // mapLists can be empty if project load has not finished resolving seqs
1836 if (mapLists.length > 0 && mapLists[0].getFromRatio() == 3)
1838 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1839 "PID for cDNA", new Annotation[1], 0f, 100f,
1840 AlignmentAnnotation.BAR_GRAPH);
1841 initConsensus(complementConsensus);
1847 private void initConsensus(AlignmentAnnotation aa)
1850 aa.autoCalculated = true;
1854 alignment.addAnnotation(aa);
1858 private void initConservation()
1860 if (showConservation)
1862 if (conservation == null)
1864 conservation = new AlignmentAnnotation("Conservation",
1865 "Conservation of total alignment less than "
1866 + getConsPercGaps() + "% gaps", new Annotation[1],
1867 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1868 conservation.hasText = true;
1869 conservation.autoCalculated = true;
1870 alignment.addAnnotation(conservation);
1875 private void initQuality()
1879 if (quality == null)
1881 quality = new AlignmentAnnotation("Quality",
1882 "Alignment Quality based on Blosum62 scores",
1883 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1884 quality.hasText = true;
1885 quality.autoCalculated = true;
1886 alignment.addAnnotation(quality);
1891 private void initRNAStructure()
1893 if (alignment.hasRNAStructure() && strucConsensus == null)
1895 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1896 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1897 strucConsensus.hasText = true;
1898 strucConsensus.autoCalculated = true;
1902 alignment.addAnnotation(strucConsensus);
1910 * @see jalview.api.AlignViewportI#calcPanelHeight()
1913 public int calcPanelHeight()
1915 // setHeight of panels
1916 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
1918 int charHeight = getCharHeight();
1921 BitSet graphgrp = new BitSet();
1922 for (AlignmentAnnotation aa : anns)
1926 System.err.println("Null annotation row: ignoring.");
1933 if (aa.graphGroup > -1)
1935 if (graphgrp.get(aa.graphGroup))
1941 graphgrp.set(aa.graphGroup);
1948 aa.height += charHeight;
1958 aa.height += aa.graphHeight;
1966 height += aa.height;
1978 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1979 boolean preserveNewGroupSettings)
1981 boolean updateCalcs = false;
1982 boolean conv = isShowGroupConservation();
1983 boolean cons = isShowGroupConsensus();
1984 boolean showprf = isShowSequenceLogo();
1985 boolean showConsHist = isShowConsensusHistogram();
1986 boolean normLogo = isNormaliseSequenceLogo();
1989 * TODO reorder the annotation rows according to group/sequence ordering on
1992 boolean sortg = true;
1994 // remove old automatic annotation
1995 // add any new annotation
1997 // intersect alignment annotation with alignment groups
1999 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
2000 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
2003 for (int an = 0; an < aan.length; an++)
2005 if (aan[an].autoCalculated && aan[an].groupRef != null)
2007 oldrfs.add(aan[an].groupRef);
2008 alignment.deleteAnnotation(aan[an], false);
2012 if (alignment.getGroups() != null)
2014 for (SequenceGroup sg : alignment.getGroups())
2016 updateCalcs = false;
2017 if (applyGlobalSettings
2018 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
2020 // set defaults for this group's conservation/consensus
2021 sg.setshowSequenceLogo(showprf);
2022 sg.setShowConsensusHistogram(showConsHist);
2023 sg.setNormaliseSequenceLogo(normLogo);
2028 alignment.addAnnotation(sg.getConservationRow(), 0);
2033 alignment.addAnnotation(sg.getConsensus(), 0);
2035 // refresh the annotation rows
2038 sg.recalcConservation();
2046 public boolean isDisplayReferenceSeq()
2048 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
2052 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
2054 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
2058 public boolean isColourByReferenceSeq()
2060 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
2064 public Color getSequenceColour(SequenceI seq)
2066 Color sqc = sequenceColours.get(seq);
2067 return (sqc == null ? Color.white : sqc);
2071 public void setSequenceColour(SequenceI seq, Color col)
2075 sequenceColours.remove(seq);
2079 sequenceColours.put(seq, col);
2084 public void updateSequenceIdColours()
2086 for (SequenceGroup sg : alignment.getGroups())
2088 if (sg.idColour != null)
2090 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
2092 sequenceColours.put(s, sg.idColour);
2099 public void clearSequenceColours()
2101 sequenceColours.clear();
2105 public AlignViewportI getCodingComplement()
2107 return this.codingComplement;
2111 * Set this as the (cDna/protein) complement of the given viewport. Also
2112 * ensures the reverse relationship is set on the given viewport.
2115 public void setCodingComplement(AlignViewportI av)
2119 System.err.println("Ignoring recursive setCodingComplement request");
2123 this.codingComplement = av;
2124 // avoid infinite recursion!
2125 if (av.getCodingComplement() != this)
2127 av.setCodingComplement(this);
2133 public boolean isNucleotide()
2135 return getAlignment() == null ? false : getAlignment().isNucleotide();
2139 public FeaturesDisplayedI getFeaturesDisplayed()
2141 return featuresDisplayed;
2145 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2147 featuresDisplayed = featuresDisplayedI;
2151 public boolean areFeaturesDisplayed()
2153 return featuresDisplayed != null
2154 && featuresDisplayed.getRegisteredFeaturesCount() > 0;
2161 * features are displayed if true
2164 public void setShowSequenceFeatures(boolean b)
2166 viewStyle.setShowSequenceFeatures(b);
2170 public boolean isShowSequenceFeatures()
2172 return viewStyle.isShowSequenceFeatures();
2176 public void setShowSequenceFeaturesHeight(boolean selected)
2178 viewStyle.setShowSequenceFeaturesHeight(selected);
2182 public boolean isShowSequenceFeaturesHeight()
2184 return viewStyle.isShowSequenceFeaturesHeight();
2188 public void setShowAnnotation(boolean b)
2190 viewStyle.setShowAnnotation(b);
2194 public boolean isShowAnnotation()
2196 return viewStyle.isShowAnnotation();
2200 public boolean isRightAlignIds()
2202 return viewStyle.isRightAlignIds();
2206 public void setRightAlignIds(boolean rightAlignIds)
2208 viewStyle.setRightAlignIds(rightAlignIds);
2212 public boolean getConservationSelected()
2214 return viewStyle.getConservationSelected();
2218 public void setShowBoxes(boolean state)
2220 viewStyle.setShowBoxes(state);
2225 * @see jalview.api.ViewStyleI#getTextColour()
2228 public Color getTextColour()
2230 return viewStyle.getTextColour();
2235 * @see jalview.api.ViewStyleI#getTextColour2()
2238 public Color getTextColour2()
2240 return viewStyle.getTextColour2();
2245 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2248 public int getThresholdTextColour()
2250 return viewStyle.getThresholdTextColour();
2255 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2258 public boolean isConservationColourSelected()
2260 return viewStyle.isConservationColourSelected();
2265 * @see jalview.api.ViewStyleI#isRenderGaps()
2268 public boolean isRenderGaps()
2270 return viewStyle.isRenderGaps();
2275 * @see jalview.api.ViewStyleI#isShowColourText()
2278 public boolean isShowColourText()
2280 return viewStyle.isShowColourText();
2284 * @param conservationColourSelected
2285 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2288 public void setConservationColourSelected(
2289 boolean conservationColourSelected)
2291 viewStyle.setConservationColourSelected(conservationColourSelected);
2295 * @param showColourText
2296 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2299 public void setShowColourText(boolean showColourText)
2301 viewStyle.setShowColourText(showColourText);
2306 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2309 public void setTextColour(Color textColour)
2311 viewStyle.setTextColour(textColour);
2315 * @param thresholdTextColour
2316 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2319 public void setThresholdTextColour(int thresholdTextColour)
2321 viewStyle.setThresholdTextColour(thresholdTextColour);
2325 * @param textColour2
2326 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2329 public void setTextColour2(Color textColour2)
2331 viewStyle.setTextColour2(textColour2);
2335 public ViewStyleI getViewStyle()
2337 return new ViewStyle(viewStyle);
2341 public void setViewStyle(ViewStyleI settingsForView)
2343 viewStyle = new ViewStyle(settingsForView);
2347 public boolean sameStyle(ViewStyleI them)
2349 return viewStyle.sameStyle(them);
2354 * @see jalview.api.ViewStyleI#getIdWidth()
2357 public int getIdWidth()
2359 return viewStyle.getIdWidth();
2364 * @see jalview.api.ViewStyleI#setIdWidth(int)
2367 public void setIdWidth(int i)
2369 viewStyle.setIdWidth(i);
2374 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2377 public boolean isCentreColumnLabels()
2379 return viewStyle.isCentreColumnLabels();
2383 * @param centreColumnLabels
2384 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2387 public void setCentreColumnLabels(boolean centreColumnLabels)
2389 viewStyle.setCentreColumnLabels(centreColumnLabels);
2394 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2397 public void setShowDBRefs(boolean showdbrefs)
2399 viewStyle.setShowDBRefs(showdbrefs);
2404 * @see jalview.api.ViewStyleI#isShowDBRefs()
2407 public boolean isShowDBRefs()
2409 return viewStyle.isShowDBRefs();
2414 * @see jalview.api.ViewStyleI#isShowNPFeats()
2417 public boolean isShowNPFeats()
2419 return viewStyle.isShowNPFeats();
2423 * @param shownpfeats
2424 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2427 public void setShowNPFeats(boolean shownpfeats)
2429 viewStyle.setShowNPFeats(shownpfeats);
2432 public abstract StructureSelectionManager getStructureSelectionManager();
2435 * Add one command to the command history list.
2439 public void addToHistoryList(CommandI command)
2441 if (this.historyList != null)
2443 this.historyList.push(command);
2444 broadcastCommand(command, false);
2448 protected void broadcastCommand(CommandI command, boolean undo)
2450 getStructureSelectionManager().commandPerformed(command, undo,
2455 * Add one command to the command redo list.
2459 public void addToRedoList(CommandI command)
2461 if (this.redoList != null)
2463 this.redoList.push(command);
2465 broadcastCommand(command, true);
2469 * Clear the command redo list.
2471 public void clearRedoList()
2473 if (this.redoList != null)
2475 this.redoList.clear();
2479 public void setHistoryList(Deque<CommandI> list)
2481 this.historyList = list;
2484 public Deque<CommandI> getHistoryList()
2486 return this.historyList;
2489 public void setRedoList(Deque<CommandI> list)
2491 this.redoList = list;
2494 public Deque<CommandI> getRedoList()
2496 return this.redoList;
2500 public VamsasSource getVamsasSource()
2505 public SequenceAnnotationOrder getSortAnnotationsBy()
2507 return sortAnnotationsBy;
2510 public void setSortAnnotationsBy(SequenceAnnotationOrder sortAnnotationsBy)
2512 this.sortAnnotationsBy = sortAnnotationsBy;
2515 public boolean isShowAutocalculatedAbove()
2517 return showAutocalculatedAbove;
2520 public void setShowAutocalculatedAbove(boolean showAutocalculatedAbove)
2522 this.showAutocalculatedAbove = showAutocalculatedAbove;
2526 public boolean isScaleProteinAsCdna()
2528 return viewStyle.isScaleProteinAsCdna();
2532 public void setScaleProteinAsCdna(boolean b)
2534 viewStyle.setScaleProteinAsCdna(b);
2538 * @return true if view should scroll to show the highlighted region of a
2543 public final boolean isFollowHighlight()
2545 return followHighlight;
2549 public final void setFollowHighlight(boolean b)
2551 this.followHighlight = b;
2554 public int getStartRes()
2560 public int getEndRes()
2565 public int getStartSeq()
2570 public void setStartRes(int res)
2572 this.startRes = res;
2575 public void setStartSeq(int seq)
2577 this.startSeq = seq;
2580 public void setEndRes(int res)
2582 if (res > alignment.getWidth() - 1)
2584 // log.System.out.println(" Corrected res from " + res + " to maximum " +
2585 // (alignment.getWidth()-1));
2586 res = alignment.getWidth() - 1;
2595 public void setEndSeq(int seq)
2597 if (seq > alignment.getHeight())
2599 seq = alignment.getHeight();
2608 public int getEndSeq()
2614 * Helper method to populate the SearchResults with the location in the
2615 * complementary alignment to scroll to, in order to match this one.
2618 * the SearchResults to add to
2619 * @return the offset (below top of visible region) of the matched sequence
2621 protected int findComplementScrollTarget(SearchResults sr)
2623 final AlignViewportI complement = getCodingComplement();
2624 if (complement == null || !complement.isFollowHighlight())
2628 boolean iAmProtein = !getAlignment().isNucleotide();
2629 AlignmentI proteinAlignment = iAmProtein ? getAlignment() : complement
2631 if (proteinAlignment == null)
2635 final List<AlignedCodonFrame> mappings = proteinAlignment
2639 * Heuristic: find the first mapped sequence (if any) with a non-gapped
2640 * residue in the middle column of the visible region. Scroll the
2641 * complementary alignment to line up the corresponding residue.
2644 SequenceI sequence = null;
2647 * locate 'middle' column (true middle if an odd number visible, left of
2648 * middle if an even number visible)
2650 int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
2651 final HiddenSequences hiddenSequences = getAlignment()
2652 .getHiddenSequences();
2655 * searching to the bottom of the alignment gives smoother scrolling across
2656 * all gapped visible regions
2658 int lastSeq = alignment.getHeight() - 1;
2659 for (int seqNo = getStartSeq(); seqNo < lastSeq; seqNo++, seqOffset++)
2661 sequence = getAlignment().getSequenceAt(seqNo);
2662 if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
2666 if (Comparison.isGap(sequence.getCharAt(middleColumn)))
2670 List<AlignedCodonFrame> seqMappings = MappingUtils
2671 .findMappingsForSequence(sequence, mappings);
2672 if (!seqMappings.isEmpty())
2678 if (sequence == null)
2681 * No ungapped mapped sequence in middle column - do nothing
2685 MappingUtils.addSearchResults(sr, sequence,
2686 sequence.findPosition(middleColumn), mappings);
2691 * synthesize a column selection if none exists so it covers the given
2692 * selection group. if wholewidth is false, no column selection is made if the
2693 * selection group covers the whole alignment width.
2698 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2702 && (sgs = sg.getStartRes()) >= 0
2703 && sg.getStartRes() <= (sge = sg.getEndRes())
2704 && (colSel == null || colSel.getSelected() == null || colSel
2705 .getSelected().size() == 0))
2707 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2714 colSel = new ColumnSelection();
2716 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2718 colSel.addElement(cspos);
2723 private boolean isExportHiddenSeqs = true;
2726 public void setExportHiddenSeqs(boolean isExportHiddenSeqs)
2728 this.isExportHiddenSeqs = isExportHiddenSeqs;
2732 public boolean isExportHiddenSeqs()
2734 return isExportHiddenSeqs;