2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.Conservation;
24 import jalview.api.AlignCalcManagerI;
25 import jalview.api.AlignViewportI;
26 import jalview.api.AlignmentViewPanel;
27 import jalview.api.FeaturesDisplayedI;
28 import jalview.api.ViewStyleI;
29 import jalview.commands.CommandI;
30 import jalview.datamodel.AlignmentAnnotation;
31 import jalview.datamodel.AlignmentI;
32 import jalview.datamodel.AlignmentView;
33 import jalview.datamodel.Annotation;
34 import jalview.datamodel.CigarArray;
35 import jalview.datamodel.ColumnSelection;
36 import jalview.datamodel.Sequence;
37 import jalview.datamodel.SequenceCollectionI;
38 import jalview.datamodel.SequenceGroup;
39 import jalview.datamodel.SequenceI;
40 import jalview.schemes.Blosum62ColourScheme;
41 import jalview.schemes.ColourSchemeI;
42 import jalview.schemes.PIDColourScheme;
43 import jalview.schemes.ResidueProperties;
44 import jalview.structure.CommandListener;
45 import jalview.structure.StructureSelectionManager;
46 import jalview.structure.VamsasSource;
47 import jalview.viewmodel.styles.ViewStyle;
48 import jalview.workers.AlignCalcManager;
49 import jalview.workers.ConsensusThread;
50 import jalview.workers.StrucConsensusThread;
52 import java.awt.Color;
53 import java.util.ArrayDeque;
54 import java.util.ArrayList;
55 import java.util.BitSet;
56 import java.util.Deque;
57 import java.util.HashMap;
58 import java.util.Hashtable;
59 import java.util.List;
63 * base class holding visualization and analysis attributes and common logic for
64 * an active alignment view displayed in the GUI
69 public abstract class AlignmentViewport implements AlignViewportI,
70 ViewStyleI, CommandListener, VamsasSource
72 protected ViewStyleI viewStyle = new ViewStyle();
75 * A viewport that hosts the cDna view of this (protein), or vice versa (if
78 AlignViewportI codingComplement = null;
80 FeaturesDisplayedI featuresDisplayed = null;
82 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
84 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
88 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
90 public void setFontName(String name)
92 viewStyle.setFontName(name);
97 * @see jalview.api.ViewStyleI#setFontStyle(int)
99 public void setFontStyle(int style)
101 viewStyle.setFontStyle(style);
106 * @see jalview.api.ViewStyleI#setFontSize(int)
108 public void setFontSize(int size)
110 viewStyle.setFontSize(size);
115 * @see jalview.api.ViewStyleI#getFontStyle()
117 public int getFontStyle()
119 return viewStyle.getFontStyle();
124 * @see jalview.api.ViewStyleI#getFontName()
126 public String getFontName()
128 return viewStyle.getFontName();
133 * @see jalview.api.ViewStyleI#getFontSize()
135 public int getFontSize()
137 return viewStyle.getFontSize();
141 * @param upperCasebold
142 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
144 public void setUpperCasebold(boolean upperCasebold)
146 viewStyle.setUpperCasebold(upperCasebold);
151 * @see jalview.api.ViewStyleI#isUpperCasebold()
153 public boolean isUpperCasebold()
155 return viewStyle.isUpperCasebold();
160 * @see jalview.api.ViewStyleI#isSeqNameItalics()
162 public boolean isSeqNameItalics()
164 return viewStyle.isSeqNameItalics();
168 * @param colourByReferenceSeq
169 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
171 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
173 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
178 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
180 public void setColourAppliesToAllGroups(boolean b)
182 viewStyle.setColourAppliesToAllGroups(b);
187 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
189 public boolean getColourAppliesToAllGroups()
191 return viewStyle.getColourAppliesToAllGroups();
196 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
198 public boolean getAbovePIDThreshold()
200 return viewStyle.getAbovePIDThreshold();
205 * @see jalview.api.ViewStyleI#setIncrement(int)
207 public void setIncrement(int inc)
209 viewStyle.setIncrement(inc);
214 * @see jalview.api.ViewStyleI#getIncrement()
216 public int getIncrement()
218 return viewStyle.getIncrement();
223 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
225 public void setConservationSelected(boolean b)
227 viewStyle.setConservationSelected(b);
232 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
234 public void setShowHiddenMarkers(boolean show)
236 viewStyle.setShowHiddenMarkers(show);
241 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
243 public boolean getShowHiddenMarkers()
245 return viewStyle.getShowHiddenMarkers();
250 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
252 public void setScaleRightWrapped(boolean b)
254 viewStyle.setScaleRightWrapped(b);
259 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
261 public void setScaleLeftWrapped(boolean b)
263 viewStyle.setScaleLeftWrapped(b);
268 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
270 public void setScaleAboveWrapped(boolean b)
272 viewStyle.setScaleAboveWrapped(b);
277 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
279 public boolean getScaleLeftWrapped()
281 return viewStyle.getScaleLeftWrapped();
286 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
288 public boolean getScaleAboveWrapped()
290 return viewStyle.getScaleAboveWrapped();
295 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
297 public boolean getScaleRightWrapped()
299 return viewStyle.getScaleRightWrapped();
304 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
306 public void setAbovePIDThreshold(boolean b)
308 viewStyle.setAbovePIDThreshold(b);
313 * @see jalview.api.ViewStyleI#setThreshold(int)
315 public void setThreshold(int thresh)
317 viewStyle.setThreshold(thresh);
322 * @see jalview.api.ViewStyleI#getThreshold()
324 public int getThreshold()
326 return viewStyle.getThreshold();
331 * @see jalview.api.ViewStyleI#getShowJVSuffix()
333 public boolean getShowJVSuffix()
335 return viewStyle.getShowJVSuffix();
340 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
342 public void setShowJVSuffix(boolean b)
344 viewStyle.setShowJVSuffix(b);
349 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
351 public void setWrapAlignment(boolean state)
353 viewStyle.setWrapAlignment(state);
358 * @see jalview.api.ViewStyleI#setShowText(boolean)
360 public void setShowText(boolean state)
362 viewStyle.setShowText(state);
367 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
369 public void setRenderGaps(boolean state)
371 viewStyle.setRenderGaps(state);
376 * @see jalview.api.ViewStyleI#getColourText()
378 public boolean getColourText()
380 return viewStyle.getColourText();
385 * @see jalview.api.ViewStyleI#setColourText(boolean)
387 public void setColourText(boolean state)
389 viewStyle.setColourText(state);
394 * @see jalview.api.ViewStyleI#getWrapAlignment()
396 public boolean getWrapAlignment()
398 return viewStyle.getWrapAlignment();
403 * @see jalview.api.ViewStyleI#getShowText()
405 public boolean getShowText()
407 return viewStyle.getShowText();
412 * @see jalview.api.ViewStyleI#getWrappedWidth()
414 public int getWrappedWidth()
416 return viewStyle.getWrappedWidth();
421 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
423 public void setWrappedWidth(int w)
425 viewStyle.setWrappedWidth(w);
430 * @see jalview.api.ViewStyleI#getCharHeight()
432 public int getCharHeight()
434 return viewStyle.getCharHeight();
439 * @see jalview.api.ViewStyleI#setCharHeight(int)
441 public void setCharHeight(int h)
443 viewStyle.setCharHeight(h);
448 * @see jalview.api.ViewStyleI#getCharWidth()
450 public int getCharWidth()
452 return viewStyle.getCharWidth();
457 * @see jalview.api.ViewStyleI#setCharWidth(int)
459 public void setCharWidth(int w)
461 viewStyle.setCharWidth(w);
466 * @see jalview.api.ViewStyleI#getShowBoxes()
468 public boolean getShowBoxes()
470 return viewStyle.getShowBoxes();
475 * @see jalview.api.ViewStyleI#getShowUnconserved()
477 public boolean getShowUnconserved()
479 return viewStyle.getShowUnconserved();
483 * @param showunconserved
484 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
486 public void setShowUnconserved(boolean showunconserved)
488 viewStyle.setShowUnconserved(showunconserved);
493 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
495 public void setSeqNameItalics(boolean default1)
497 viewStyle.setSeqNameItalics(default1);
502 * @see jalview.api.ViewStyleI#setShowSeqFeaturesHeight(boolean)
504 public void setShowSeqFeaturesHeight(boolean selected)
506 viewStyle.setShowSeqFeaturesHeight(selected);
510 * alignment displayed in the viewport. Please use get/setter
512 protected AlignmentI alignment;
515 public AlignmentI getAlignment()
521 public char getGapCharacter()
523 return alignment.getGapCharacter();
526 protected String sequenceSetID;
529 * probably unused indicator that view is of a dataset rather than an
532 protected boolean isDataset = false;
534 public void setDataset(boolean b)
539 public boolean isDataset()
545 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
547 protected ColumnSelection colSel = new ColumnSelection();
549 public boolean autoCalculateConsensus = true;
551 protected boolean autoCalculateStrucConsensus = true;
553 protected boolean ignoreGapsInConsensusCalculation = false;
555 protected ColourSchemeI globalColourScheme = null;
559 public void setGlobalColourScheme(ColourSchemeI cs)
561 // TODO: logic refactored from AlignFrame changeColour -
562 // autorecalc stuff should be changed to rely on the worker system
563 // check to see if we should implement a changeColour(cs) method rather than
564 // put th logic in here
565 // - means that caller decides if they want to just modify state and defer
566 // calculation till later or to do all calculations in thread.
568 globalColourScheme = cs;
569 boolean recalc = false;
572 cs.setConservationApplied(recalc = getConservationSelected());
573 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
574 || cs instanceof Blosum62ColourScheme)
577 cs.setThreshold(viewStyle.getThreshold(),
578 ignoreGapsInConsensusCalculation);
582 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
586 cs.setConsensus(hconsensus);
587 cs.setConservation(hconservation);
589 cs.alignmentChanged(alignment, hiddenRepSequences);
591 if (getColourAppliesToAllGroups())
593 for (SequenceGroup sg : getAlignment().getGroups())
600 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
601 sg.setConsPercGaps(ConsPercGaps);
602 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
603 || cs instanceof Blosum62ColourScheme)
605 sg.cs.setThreshold(viewStyle.getThreshold(),
606 isIgnoreGapsConsensus());
611 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
614 if (getConservationSelected())
616 sg.cs.setConservationApplied(true);
621 sg.cs.setConservation(null);
622 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
626 sg.recalcConservation();
630 sg.cs.alignmentChanged(sg, hiddenRepSequences);
638 public ColourSchemeI getGlobalColourScheme()
640 return globalColourScheme;
643 protected AlignmentAnnotation consensus;
645 protected AlignmentAnnotation strucConsensus;
647 protected AlignmentAnnotation conservation;
649 protected AlignmentAnnotation quality;
651 protected AlignmentAnnotation[] groupConsensus;
653 protected AlignmentAnnotation[] groupConservation;
656 * results of alignment consensus analysis for visible portion of view
658 protected Hashtable[] hconsensus = null;
661 * results of secondary structure base pair consensus for visible portion of
664 protected Hashtable[] hStrucConsensus = null;
666 protected Conservation hconservation = null;
669 public void setConservation(Conservation cons)
671 hconservation = cons;
675 * percentage gaps allowed in a column before all amino acid properties should
676 * be considered unconserved
678 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
681 public int getConsPercGaps()
687 public void setSequenceConsensusHash(Hashtable[] hconsensus)
689 this.hconsensus = hconsensus;
694 public Hashtable[] getSequenceConsensusHash()
700 public Hashtable[] getRnaStructureConsensusHash()
702 return hStrucConsensus;
706 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
708 this.hStrucConsensus = hStrucConsensus;
713 public AlignmentAnnotation getAlignmentQualityAnnot()
719 public AlignmentAnnotation getAlignmentConservationAnnotation()
725 public AlignmentAnnotation getAlignmentConsensusAnnotation()
731 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
733 return strucConsensus;
736 protected AlignCalcManagerI calculator = new AlignCalcManager();
739 * trigger update of conservation annotation
741 public void updateConservation(final AlignmentViewPanel ap)
743 // see note in mantis : issue number 8585
744 if (alignment.isNucleotide() || conservation == null
745 || !autoCalculateConsensus)
750 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
752 calculator.registerWorker(new jalview.workers.ConservationThread(
758 * trigger update of consensus annotation
760 public void updateConsensus(final AlignmentViewPanel ap)
762 // see note in mantis : issue number 8585
763 if (consensus == null || !autoCalculateConsensus)
767 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
769 calculator.registerWorker(new ConsensusThread(this, ap));
773 // --------START Structure Conservation
774 public void updateStrucConsensus(final AlignmentViewPanel ap)
776 if (autoCalculateStrucConsensus && strucConsensus == null
777 && alignment.isNucleotide() && alignment.hasRNAStructure())
779 // secondary structure has been added - so init the consensus line
783 // see note in mantis : issue number 8585
784 if (strucConsensus == null || !autoCalculateStrucConsensus)
788 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
790 calculator.registerWorker(new StrucConsensusThread(this, ap));
794 public boolean isCalcInProgress()
796 return calculator.isWorking();
800 public boolean isCalculationInProgress(
801 AlignmentAnnotation alignmentAnnotation)
803 if (!alignmentAnnotation.autoCalculated)
807 if (calculator.workingInvolvedWith(alignmentAnnotation))
809 // System.err.println("grey out ("+alignmentAnnotation.label+")");
816 public boolean isClosed()
818 // TODO: check that this isClosed is only true after panel is closed, not
819 // before it is fully constructed.
820 return alignment == null;
824 public AlignCalcManagerI getCalcManager()
830 * should conservation rows be shown for groups
832 protected boolean showGroupConservation = false;
835 * should consensus rows be shown for groups
837 protected boolean showGroupConsensus = false;
840 * should consensus profile be rendered by default
842 protected boolean showSequenceLogo = false;
845 * should consensus profile be rendered normalised to row height
847 protected boolean normaliseSequenceLogo = false;
850 * should consensus histograms be rendered by default
852 protected boolean showConsensusHistogram = true;
855 * @return the showConsensusProfile
858 public boolean isShowSequenceLogo()
860 return showSequenceLogo;
864 * @param showSequenceLogo
867 public void setShowSequenceLogo(boolean showSequenceLogo)
869 if (showSequenceLogo != this.showSequenceLogo)
871 // TODO: decouple settings setting from calculation when refactoring
872 // annotation update method from alignframe to viewport
873 this.showSequenceLogo = showSequenceLogo;
874 calculator.updateAnnotationFor(ConsensusThread.class);
875 calculator.updateAnnotationFor(StrucConsensusThread.class);
877 this.showSequenceLogo = showSequenceLogo;
881 * @param showConsensusHistogram
882 * the showConsensusHistogram to set
884 public void setShowConsensusHistogram(boolean showConsensusHistogram)
886 this.showConsensusHistogram = showConsensusHistogram;
890 * @return the showGroupConservation
892 public boolean isShowGroupConservation()
894 return showGroupConservation;
898 * @param showGroupConservation
899 * the showGroupConservation to set
901 public void setShowGroupConservation(boolean showGroupConservation)
903 this.showGroupConservation = showGroupConservation;
907 * @return the showGroupConsensus
909 public boolean isShowGroupConsensus()
911 return showGroupConsensus;
915 * @param showGroupConsensus
916 * the showGroupConsensus to set
918 public void setShowGroupConsensus(boolean showGroupConsensus)
920 this.showGroupConsensus = showGroupConsensus;
925 * @return flag to indicate if the consensus histogram should be rendered by
929 public boolean isShowConsensusHistogram()
931 return this.showConsensusHistogram;
935 * when set, updateAlignment will always ensure sequences are of equal length
937 private boolean padGaps = false;
940 * when set, alignment should be reordered according to a newly opened tree
942 public boolean sortByTree = false;
948 * @return null or the currently selected sequence region
951 public SequenceGroup getSelectionGroup()
953 return selectionGroup;
957 * Set the selection group for this window.
960 * - group holding references to sequences in this alignment view
964 public void setSelectionGroup(SequenceGroup sg)
969 public void setHiddenColumns(ColumnSelection colsel)
971 this.colSel = colsel;
975 public ColumnSelection getColumnSelection()
981 public void setColumnSelection(ColumnSelection colSel)
983 this.colSel = colSel;
986 updateHiddenColumns();
995 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
997 return hiddenRepSequences;
1001 public void setHiddenRepSequences(
1002 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1004 this.hiddenRepSequences = hiddenRepSequences;
1008 public boolean hasHiddenColumns()
1010 return colSel != null && colSel.hasHiddenColumns();
1013 public void updateHiddenColumns()
1015 // this method doesn't really do anything now. But - it could, since a
1016 // column Selection could be in the process of modification
1017 // hasHiddenColumns = colSel.hasHiddenColumns();
1020 protected boolean hasHiddenRows = false;
1023 public boolean hasHiddenRows()
1025 return hasHiddenRows;
1028 protected SequenceGroup selectionGroup;
1030 public void setSequenceSetId(String newid)
1032 if (sequenceSetID != null)
1035 .println("Warning - overwriting a sequenceSetId for a viewport!");
1037 sequenceSetID = new String(newid);
1041 public String getSequenceSetId()
1043 if (sequenceSetID == null)
1045 sequenceSetID = alignment.hashCode() + "";
1048 return sequenceSetID;
1052 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1055 protected String viewId = null;
1058 public String getViewId()
1062 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1067 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1069 ignoreGapsInConsensusCalculation = b;
1072 updateConsensus(ap);
1073 if (globalColourScheme != null)
1075 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1076 ignoreGapsInConsensusCalculation);
1082 private long sgrouphash = -1, colselhash = -1;
1085 * checks current SelectionGroup against record of last hash value, and
1089 * update the record of last hash value
1091 * @return true if SelectionGroup changed since last call (when b is true)
1093 public boolean isSelectionGroupChanged(boolean b)
1095 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1096 : selectionGroup.hashCode();
1097 if (hc != -1 && hc != sgrouphash)
1109 * checks current colsel against record of last hash value, and optionally
1113 * update the record of last hash value
1114 * @return true if colsel changed since last call (when b is true)
1116 public boolean isColSelChanged(boolean b)
1118 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
1120 if (hc != -1 && hc != colselhash)
1132 public boolean isIgnoreGapsConsensus()
1134 return ignoreGapsInConsensusCalculation;
1137 // / property change stuff
1139 // JBPNote Prolly only need this in the applet version.
1140 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1143 protected boolean showConservation = true;
1145 protected boolean showQuality = true;
1147 protected boolean showConsensus = true;
1149 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1152 * Property change listener for changes in alignment
1157 public void addPropertyChangeListener(
1158 java.beans.PropertyChangeListener listener)
1160 changeSupport.addPropertyChangeListener(listener);
1169 public void removePropertyChangeListener(
1170 java.beans.PropertyChangeListener listener)
1172 changeSupport.removePropertyChangeListener(listener);
1176 * Property change listener for changes in alignment
1185 public void firePropertyChange(String prop, Object oldvalue,
1188 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1191 // common hide/show column stuff
1193 public void hideSelectedColumns()
1195 if (colSel.size() < 1)
1200 colSel.hideSelectedColumns();
1201 setSelectionGroup(null);
1205 public void hideColumns(int start, int end)
1209 colSel.hideColumns(start);
1213 colSel.hideColumns(start, end);
1217 public void showColumn(int col)
1219 colSel.revealHiddenColumns(col);
1223 public void showAllHiddenColumns()
1225 colSel.revealAllHiddenColumns();
1228 // common hide/show seq stuff
1229 public void showAllHiddenSeqs()
1231 if (alignment.getHiddenSequences().getSize() > 0)
1233 if (selectionGroup == null)
1235 selectionGroup = new SequenceGroup();
1236 selectionGroup.setEndRes(alignment.getWidth() - 1);
1238 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1239 hiddenRepSequences);
1240 for (SequenceI seq : tmp)
1242 selectionGroup.addSequence(seq, false);
1243 setSequenceAnnotationsVisible(seq, true);
1246 hasHiddenRows = false;
1247 hiddenRepSequences = null;
1249 firePropertyChange("alignment", null, alignment.getSequences());
1250 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1256 public void showSequence(int index)
1258 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1260 hiddenRepSequences);
1263 if (selectionGroup == null)
1265 selectionGroup = new SequenceGroup();
1266 selectionGroup.setEndRes(alignment.getWidth() - 1);
1269 for (SequenceI seq : tmp)
1271 selectionGroup.addSequence(seq, false);
1272 setSequenceAnnotationsVisible(seq, true);
1274 // JBPNote: refactor: only update flag if we modified visiblity (used to
1275 // do this regardless)
1276 if (alignment.getHiddenSequences().getSize() < 1)
1278 hasHiddenRows = false;
1280 firePropertyChange("alignment", null, alignment.getSequences());
1285 public void hideAllSelectedSeqs()
1287 if (selectionGroup == null || selectionGroup.getSize() < 1)
1292 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1296 setSelectionGroup(null);
1299 public void hideSequence(SequenceI[] seq)
1303 for (int i = 0; i < seq.length; i++)
1305 alignment.getHiddenSequences().hideSequence(seq[i]);
1306 setSequenceAnnotationsVisible(seq[i], false);
1308 hasHiddenRows = true;
1309 firePropertyChange("alignment", null, alignment.getSequences());
1314 * Set visibility for any annotations for the given sequence.
1318 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1321 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1323 if (ann.sequenceRef == sequenceI)
1325 ann.visible = visible;
1330 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1332 int sSize = sg.getSize();
1338 if (hiddenRepSequences == null)
1340 hiddenRepSequences = new Hashtable();
1343 hiddenRepSequences.put(repSequence, sg);
1345 // Hide all sequences except the repSequence
1346 SequenceI[] seqs = new SequenceI[sSize - 1];
1348 for (int i = 0; i < sSize; i++)
1350 if (sg.getSequenceAt(i) != repSequence)
1352 if (index == sSize - 1)
1357 seqs[index++] = sg.getSequenceAt(i);
1360 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1361 sg.setHidereps(true); // note: not done in 2.7applet
1366 public boolean isHiddenRepSequence(SequenceI seq)
1368 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1369 && hiddenRepSequences.containsKey(seq));
1372 public SequenceGroup getRepresentedSequences(SequenceI seq)
1374 return (SequenceGroup) (hiddenRepSequences == null ? null
1375 : hiddenRepSequences.get(seq));
1379 public int adjustForHiddenSeqs(int alignmentIndex)
1381 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1386 public void invertColumnSelection()
1388 colSel.invertColumnSelection(0, alignment.getWidth());
1393 public SequenceI[] getSelectionAsNewSequence()
1395 SequenceI[] sequences;
1396 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1397 // this was the only caller in the applet for this method
1398 // JBPNote: in applet, this method returned references to the alignment
1399 // sequences, and it did not honour the presence/absence of annotation
1400 // attached to the alignment (probably!)
1401 if (selectionGroup == null || selectionGroup.getSize() == 0)
1403 sequences = alignment.getSequencesArray();
1404 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1405 for (int i = 0; i < sequences.length; i++)
1407 // construct new sequence with subset of visible annotation
1408 sequences[i] = new Sequence(sequences[i], annots);
1413 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1421 public SequenceI[] getSequenceSelection()
1423 SequenceI[] sequences = null;
1424 if (selectionGroup != null)
1426 sequences = selectionGroup.getSequencesInOrder(alignment);
1428 if (sequences == null)
1430 sequences = alignment.getSequencesArray();
1437 public CigarArray getViewAsCigars(
1438 boolean selectedRegionOnly)
1440 return new CigarArray(alignment, colSel,
1441 (selectedRegionOnly ? selectionGroup : null));
1446 public jalview.datamodel.AlignmentView getAlignmentView(
1447 boolean selectedOnly)
1449 return getAlignmentView(selectedOnly, false);
1454 public jalview.datamodel.AlignmentView getAlignmentView(
1455 boolean selectedOnly, boolean markGroups)
1457 return new AlignmentView(alignment, colSel, selectionGroup,
1458 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1464 public String[] getViewAsString(boolean selectedRegionOnly)
1466 String[] selection = null;
1467 SequenceI[] seqs = null;
1469 int start = 0, end = 0;
1470 if (selectedRegionOnly && selectionGroup != null)
1472 iSize = selectionGroup.getSize();
1473 seqs = selectionGroup.getSequencesInOrder(alignment);
1474 start = selectionGroup.getStartRes();
1475 end = selectionGroup.getEndRes() + 1;
1479 iSize = alignment.getHeight();
1480 seqs = alignment.getSequencesArray();
1481 end = alignment.getWidth();
1484 selection = new String[iSize];
1485 if (colSel != null && colSel.hasHiddenColumns())
1487 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1491 for (i = 0; i < iSize; i++)
1493 selection[i] = seqs[i].getSequenceAsString(start, end);
1502 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1504 ArrayList<int[]> regions = new ArrayList<int[]>();
1510 if (colSel != null && colSel.hasHiddenColumns())
1514 start = colSel.adjustForHiddenColumns(start);
1517 end = colSel.getHiddenBoundaryRight(start);
1528 regions.add(new int[]
1531 if (colSel != null && colSel.hasHiddenColumns())
1533 start = colSel.adjustForHiddenColumns(end);
1534 start = colSel.getHiddenBoundaryLeft(start) + 1;
1536 } while (end < max);
1538 int[][] startEnd = new int[regions.size()][2];
1544 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1546 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1547 AlignmentAnnotation[] aa;
1548 if ((aa=alignment.getAlignmentAnnotation())!=null)
1550 for (AlignmentAnnotation annot:aa)
1552 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1553 if (selectedOnly && selectionGroup!=null)
1555 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1557 colSel.makeVisibleAnnotation(clone);
1567 public boolean isPadGaps()
1574 public void setPadGaps(boolean padGaps)
1576 this.padGaps = padGaps;
1580 * apply any post-edit constraints and trigger any calculations needed after
1581 * an edit has been performed on the alignment
1586 public void alignmentChanged(AlignmentViewPanel ap)
1590 alignment.padGaps();
1592 if (autoCalculateConsensus)
1594 updateConsensus(ap);
1596 if (hconsensus != null && autoCalculateConsensus)
1598 updateConservation(ap);
1600 if (autoCalculateStrucConsensus)
1602 updateStrucConsensus(ap);
1605 // Reset endRes of groups if beyond alignment width
1606 int alWidth = alignment.getWidth();
1607 List<SequenceGroup> groups = alignment.getGroups();
1610 for (SequenceGroup sg : groups)
1612 if (sg.getEndRes() > alWidth)
1614 sg.setEndRes(alWidth - 1);
1619 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1621 selectionGroup.setEndRes(alWidth - 1);
1624 resetAllColourSchemes();
1625 calculator.restartWorkers();
1626 // alignment.adjustSequenceAnnotations();
1630 * reset scope and do calculations for all applied colourschemes on alignment
1632 void resetAllColourSchemes()
1634 ColourSchemeI cs = globalColourScheme;
1637 cs.alignmentChanged(alignment, hiddenRepSequences);
1639 cs.setConsensus(hconsensus);
1640 if (cs.conservationApplied())
1642 cs.setConservation(Conservation.calculateConservation("All",
1643 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1644 alignment.getWidth(), false, getConsPercGaps(), false));
1648 for (SequenceGroup sg : alignment.getGroups())
1652 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1654 sg.recalcConservation();
1658 protected void initAutoAnnotation()
1660 // TODO: add menu option action that nulls or creates consensus object
1661 // depending on if the user wants to see the annotation or not in a
1662 // specific alignment
1664 if (hconsensus == null && !isDataset)
1666 if (!alignment.isNucleotide())
1679 private void initConsensus()
1682 consensus = new AlignmentAnnotation("Consensus", "PID",
1683 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1684 consensus.hasText = true;
1685 consensus.autoCalculated = true;
1689 alignment.addAnnotation(consensus);
1693 private void initConservation()
1695 if (showConservation)
1697 if (conservation == null)
1699 conservation = new AlignmentAnnotation("Conservation",
1700 "Conservation of total alignment less than "
1701 + getConsPercGaps() + "% gaps", new Annotation[1],
1702 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1703 conservation.hasText = true;
1704 conservation.autoCalculated = true;
1705 alignment.addAnnotation(conservation);
1710 private void initQuality()
1714 if (quality == null)
1716 quality = new AlignmentAnnotation("Quality",
1717 "Alignment Quality based on Blosum62 scores",
1718 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1719 quality.hasText = true;
1720 quality.autoCalculated = true;
1721 alignment.addAnnotation(quality);
1726 private void initRNAStructure()
1728 if (alignment.hasRNAStructure() && strucConsensus == null)
1730 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1731 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1732 strucConsensus.hasText = true;
1733 strucConsensus.autoCalculated = true;
1737 alignment.addAnnotation(strucConsensus);
1745 * @see jalview.api.AlignViewportI#calcPanelHeight()
1748 public int calcPanelHeight()
1750 // setHeight of panels
1751 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1753 int charHeight = getCharHeight();
1756 BitSet graphgrp = new BitSet();
1757 for (int i = 0; i < aa.length; i++)
1761 System.err.println("Null annotation row: ignoring.");
1768 if (aa[i].graphGroup > -1)
1770 if (graphgrp.get(aa[i].graphGroup))
1776 graphgrp.set(aa[i].graphGroup);
1783 aa[i].height += charHeight;
1791 if (aa[i].graph > 0)
1793 aa[i].height += aa[i].graphHeight;
1796 if (aa[i].height == 0)
1801 height += aa[i].height;
1813 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1814 boolean preserveNewGroupSettings)
1816 boolean updateCalcs = false;
1817 boolean conv = isShowGroupConservation();
1818 boolean cons = isShowGroupConsensus();
1819 boolean showprf = isShowSequenceLogo();
1820 boolean showConsHist = isShowConsensusHistogram();
1821 boolean normLogo = isNormaliseSequenceLogo();
1824 * TODO reorder the annotation rows according to group/sequence ordering on
1827 boolean sortg = true;
1829 // remove old automatic annotation
1830 // add any new annotation
1832 // intersect alignment annotation with alignment groups
1834 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1835 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1838 for (int an = 0; an < aan.length; an++)
1840 if (aan[an].autoCalculated && aan[an].groupRef != null)
1842 oldrfs.add(aan[an].groupRef);
1843 alignment.deleteAnnotation(aan[an], false);
1847 if (alignment.getGroups() != null)
1849 for (SequenceGroup sg : alignment.getGroups())
1851 updateCalcs = false;
1852 if (applyGlobalSettings
1853 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1855 // set defaults for this group's conservation/consensus
1856 sg.setshowSequenceLogo(showprf);
1857 sg.setShowConsensusHistogram(showConsHist);
1858 sg.setNormaliseSequenceLogo(normLogo);
1863 alignment.addAnnotation(sg.getConservationRow(), 0);
1868 alignment.addAnnotation(sg.getConsensus(), 0);
1870 // refresh the annotation rows
1873 sg.recalcConservation();
1880 public boolean isDisplayReferenceSeq()
1882 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1886 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1888 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1892 public boolean isColourByReferenceSeq()
1894 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1898 public Color getSequenceColour(SequenceI seq)
1900 Color sqc = sequenceColours.get(seq);
1901 return (sqc == null ? Color.white : sqc);
1905 public void setSequenceColour(SequenceI seq, Color col)
1909 sequenceColours.remove(seq);
1913 sequenceColours.put(seq, col);
1918 public void updateSequenceIdColours()
1920 for (SequenceGroup sg : alignment.getGroups())
1922 if (sg.idColour != null)
1924 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1926 sequenceColours.put(s, sg.idColour);
1933 public void clearSequenceColours()
1935 sequenceColours.clear();
1939 public AlignViewportI getCodingComplement()
1941 return this.codingComplement;
1945 * Set this as the (cDna/protein) complement of the given viewport. Also
1946 * ensures the reverse relationship is set on the given viewport.
1949 public void setCodingComplement(AlignViewportI av)
1953 System.err.println("Ignoring recursive setCodingComplement request");
1957 this.codingComplement = av;
1958 // avoid infinite recursion!
1959 if (av.getCodingComplement() != this)
1961 av.setCodingComplement(this);
1967 public boolean isNucleotide()
1969 return getAlignment() == null ? false : getAlignment().isNucleotide();
1973 public FeaturesDisplayedI getFeaturesDisplayed()
1975 return featuresDisplayed;
1979 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1981 featuresDisplayed = featuresDisplayedI;
1985 public boolean areFeaturesDisplayed()
1987 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1994 * features are displayed if true
1997 public void setShowSequenceFeatures(boolean b)
1999 viewStyle.setShowSequenceFeatures(b);
2002 public boolean isShowSequenceFeatures()
2004 return viewStyle.isShowSequenceFeatures();
2008 public void setShowSequenceFeaturesHeight(boolean selected)
2010 viewStyle.setShowSeqFeaturesHeight(selected);
2014 public boolean isShowSequenceFeaturesHeight()
2016 return viewStyle.isShowSequenceFeaturesHeight();
2022 public void setShowAnnotation(boolean b)
2024 viewStyle.setShowAnnotation(b);
2028 public boolean isShowAnnotation()
2030 return viewStyle.isShowAnnotation();
2034 public boolean isRightAlignIds()
2036 return viewStyle.isRightAlignIds();
2040 public void setRightAlignIds(boolean rightAlignIds)
2042 viewStyle.setRightAlignIds(rightAlignIds);
2046 public boolean getConservationSelected()
2048 return viewStyle.getConservationSelected();
2052 public void setShowBoxes(boolean state)
2054 viewStyle.setShowBoxes(state);
2059 * @see jalview.api.ViewStyleI#getTextColour()
2061 public Color getTextColour()
2063 return viewStyle.getTextColour();
2068 * @see jalview.api.ViewStyleI#getTextColour2()
2070 public Color getTextColour2()
2072 return viewStyle.getTextColour2();
2077 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2079 public int getThresholdTextColour()
2081 return viewStyle.getThresholdTextColour();
2086 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2088 public boolean isConservationColourSelected()
2090 return viewStyle.isConservationColourSelected();
2095 * @see jalview.api.ViewStyleI#isRenderGaps()
2097 public boolean isRenderGaps()
2099 return viewStyle.isRenderGaps();
2104 * @see jalview.api.ViewStyleI#isShowColourText()
2106 public boolean isShowColourText()
2108 return viewStyle.isShowColourText();
2112 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2114 public boolean isShowSeqFeaturesHeight()
2116 return viewStyle.isShowSeqFeaturesHeight();
2120 * @param conservationColourSelected
2121 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2123 public void setConservationColourSelected(
2124 boolean conservationColourSelected)
2126 viewStyle.setConservationColourSelected(conservationColourSelected);
2130 * @param showColourText
2131 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2133 public void setShowColourText(boolean showColourText)
2135 viewStyle.setShowColourText(showColourText);
2140 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2142 public void setTextColour(Color textColour)
2144 viewStyle.setTextColour(textColour);
2148 * @param thresholdTextColour
2149 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2151 public void setThresholdTextColour(int thresholdTextColour)
2153 viewStyle.setThresholdTextColour(thresholdTextColour);
2157 * @param textColour2
2158 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2160 public void setTextColour2(Color textColour2)
2162 viewStyle.setTextColour2(textColour2);
2166 public ViewStyleI getViewStyle()
2168 return new ViewStyle(viewStyle);
2172 public void setViewStyle(ViewStyleI settingsForView)
2174 viewStyle = new ViewStyle(settingsForView);
2178 public boolean sameStyle(ViewStyleI them)
2180 return viewStyle.sameStyle(them);
2185 * @see jalview.api.ViewStyleI#getIdWidth()
2187 public int getIdWidth()
2189 return viewStyle.getIdWidth();
2194 * @see jalview.api.ViewStyleI#setIdWidth(int)
2196 public void setIdWidth(int i)
2198 viewStyle.setIdWidth(i);
2203 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2205 public boolean isCentreColumnLabels()
2207 return viewStyle.isCentreColumnLabels();
2211 * @param centreColumnLabels
2212 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2214 public void setCentreColumnLabels(boolean centreColumnLabels)
2216 viewStyle.setCentreColumnLabels(centreColumnLabels);
2221 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2223 public void setShowDBRefs(boolean showdbrefs)
2225 viewStyle.setShowDBRefs(showdbrefs);
2230 * @see jalview.api.ViewStyleI#isShowDBRefs()
2232 public boolean isShowDBRefs()
2234 return viewStyle.isShowDBRefs();
2239 * @see jalview.api.ViewStyleI#isShowNPFeats()
2241 public boolean isShowNPFeats()
2243 return viewStyle.isShowNPFeats();
2247 * @param shownpfeats
2248 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2250 public void setShowNPFeats(boolean shownpfeats)
2252 viewStyle.setShowNPFeats(shownpfeats);
2255 public abstract StructureSelectionManager getStructureSelectionManager();
2258 * Add one command to the command history list.
2262 public void addToHistoryList(CommandI command)
2264 if (this.historyList != null)
2266 this.historyList.push(command);
2267 broadcastCommand(command, false);
2271 protected void broadcastCommand(CommandI command, boolean undo)
2273 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
2277 * Add one command to the command redo list.
2281 public void addToRedoList(CommandI command)
2283 if (this.redoList != null)
2285 this.redoList.push(command);
2287 broadcastCommand(command, true);
2291 * Clear the command redo list.
2293 public void clearRedoList()
2295 if (this.redoList != null)
2297 this.redoList.clear();
2301 public void setHistoryList(Deque<CommandI> list)
2303 this.historyList = list;
2306 public Deque<CommandI> getHistoryList()
2308 return this.historyList;
2311 public void setRedoList(Deque<CommandI> list)
2313 this.redoList = list;
2316 public Deque<CommandI> getRedoList()
2318 return this.redoList;
2322 public VamsasSource getVamsasSource()