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 sequences[i] = new Sequence(sequences[i], annots); // construct new
1409 // subset of visible
1415 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1423 public SequenceI[] getSequenceSelection()
1425 SequenceI[] sequences = null;
1426 if (selectionGroup != null)
1428 sequences = selectionGroup.getSequencesInOrder(alignment);
1430 if (sequences == null)
1432 sequences = alignment.getSequencesArray();
1439 public CigarArray getViewAsCigars(
1440 boolean selectedRegionOnly)
1442 return new CigarArray(alignment, colSel,
1443 (selectedRegionOnly ? selectionGroup : null));
1448 public jalview.datamodel.AlignmentView getAlignmentView(
1449 boolean selectedOnly)
1451 return getAlignmentView(selectedOnly, false);
1456 public jalview.datamodel.AlignmentView getAlignmentView(
1457 boolean selectedOnly, boolean markGroups)
1459 return new AlignmentView(alignment, colSel, selectionGroup,
1460 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1466 public String[] getViewAsString(boolean selectedRegionOnly)
1468 String[] selection = null;
1469 SequenceI[] seqs = null;
1471 int start = 0, end = 0;
1472 if (selectedRegionOnly && selectionGroup != null)
1474 iSize = selectionGroup.getSize();
1475 seqs = selectionGroup.getSequencesInOrder(alignment);
1476 start = selectionGroup.getStartRes();
1477 end = selectionGroup.getEndRes() + 1;
1481 iSize = alignment.getHeight();
1482 seqs = alignment.getSequencesArray();
1483 end = alignment.getWidth();
1486 selection = new String[iSize];
1487 if (colSel != null && colSel.hasHiddenColumns())
1489 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1493 for (i = 0; i < iSize; i++)
1495 selection[i] = seqs[i].getSequenceAsString(start, end);
1504 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1506 ArrayList<int[]> regions = new ArrayList<int[]>();
1512 if (colSel != null && colSel.hasHiddenColumns())
1516 start = colSel.adjustForHiddenColumns(start);
1519 end = colSel.getHiddenBoundaryRight(start);
1530 regions.add(new int[]
1533 if (colSel != null && colSel.hasHiddenColumns())
1535 start = colSel.adjustForHiddenColumns(end);
1536 start = colSel.getHiddenBoundaryLeft(start) + 1;
1538 } while (end < max);
1540 int[][] startEnd = new int[regions.size()][2];
1546 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1548 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1549 AlignmentAnnotation[] aa;
1550 if ((aa=alignment.getAlignmentAnnotation())!=null)
1552 for (AlignmentAnnotation annot:aa)
1554 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1555 if (selectedOnly && selectionGroup!=null)
1557 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1559 colSel.makeVisibleAnnotation(clone);
1569 public boolean isPadGaps()
1576 public void setPadGaps(boolean padGaps)
1578 this.padGaps = padGaps;
1582 * apply any post-edit constraints and trigger any calculations needed after
1583 * an edit has been performed on the alignment
1588 public void alignmentChanged(AlignmentViewPanel ap)
1592 alignment.padGaps();
1594 if (autoCalculateConsensus)
1596 updateConsensus(ap);
1598 if (hconsensus != null && autoCalculateConsensus)
1600 updateConservation(ap);
1602 if (autoCalculateStrucConsensus)
1604 updateStrucConsensus(ap);
1607 // Reset endRes of groups if beyond alignment width
1608 int alWidth = alignment.getWidth();
1609 List<SequenceGroup> groups = alignment.getGroups();
1612 for (SequenceGroup sg : groups)
1614 if (sg.getEndRes() > alWidth)
1616 sg.setEndRes(alWidth - 1);
1621 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1623 selectionGroup.setEndRes(alWidth - 1);
1626 resetAllColourSchemes();
1627 calculator.restartWorkers();
1628 // alignment.adjustSequenceAnnotations();
1632 * reset scope and do calculations for all applied colourschemes on alignment
1634 void resetAllColourSchemes()
1636 ColourSchemeI cs = globalColourScheme;
1639 cs.alignmentChanged(alignment, hiddenRepSequences);
1641 cs.setConsensus(hconsensus);
1642 if (cs.conservationApplied())
1644 cs.setConservation(Conservation.calculateConservation("All",
1645 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1646 alignment.getWidth(), false, getConsPercGaps(), false));
1650 for (SequenceGroup sg : alignment.getGroups())
1654 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1656 sg.recalcConservation();
1660 protected void initAutoAnnotation()
1662 // TODO: add menu option action that nulls or creates consensus object
1663 // depending on if the user wants to see the annotation or not in a
1664 // specific alignment
1666 if (hconsensus == null && !isDataset)
1668 if (!alignment.isNucleotide())
1681 private void initConsensus()
1684 consensus = new AlignmentAnnotation("Consensus", "PID",
1685 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1686 consensus.hasText = true;
1687 consensus.autoCalculated = true;
1691 alignment.addAnnotation(consensus);
1695 private void initConservation()
1697 if (showConservation)
1699 if (conservation == null)
1701 conservation = new AlignmentAnnotation("Conservation",
1702 "Conservation of total alignment less than "
1703 + getConsPercGaps() + "% gaps", new Annotation[1],
1704 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1705 conservation.hasText = true;
1706 conservation.autoCalculated = true;
1707 alignment.addAnnotation(conservation);
1712 private void initQuality()
1716 if (quality == null)
1718 quality = new AlignmentAnnotation("Quality",
1719 "Alignment Quality based on Blosum62 scores",
1720 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1721 quality.hasText = true;
1722 quality.autoCalculated = true;
1723 alignment.addAnnotation(quality);
1728 private void initRNAStructure()
1730 if (alignment.hasRNAStructure() && strucConsensus == null)
1732 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1733 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1734 strucConsensus.hasText = true;
1735 strucConsensus.autoCalculated = true;
1739 alignment.addAnnotation(strucConsensus);
1747 * @see jalview.api.AlignViewportI#calcPanelHeight()
1750 public int calcPanelHeight()
1752 // setHeight of panels
1753 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1755 int charHeight = getCharHeight();
1758 BitSet graphgrp = new BitSet();
1759 for (int i = 0; i < aa.length; i++)
1763 System.err.println("Null annotation row: ignoring.");
1770 if (aa[i].graphGroup > -1)
1772 if (graphgrp.get(aa[i].graphGroup))
1778 graphgrp.set(aa[i].graphGroup);
1785 aa[i].height += charHeight;
1793 if (aa[i].graph > 0)
1795 aa[i].height += aa[i].graphHeight;
1798 if (aa[i].height == 0)
1803 height += aa[i].height;
1815 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1816 boolean preserveNewGroupSettings)
1818 boolean updateCalcs = false;
1819 boolean conv = isShowGroupConservation();
1820 boolean cons = isShowGroupConsensus();
1821 boolean showprf = isShowSequenceLogo();
1822 boolean showConsHist = isShowConsensusHistogram();
1823 boolean normLogo = isNormaliseSequenceLogo();
1826 * TODO reorder the annotation rows according to group/sequence ordering on
1829 boolean sortg = true;
1831 // remove old automatic annotation
1832 // add any new annotation
1834 // intersect alignment annotation with alignment groups
1836 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1837 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1840 for (int an = 0; an < aan.length; an++)
1842 if (aan[an].autoCalculated && aan[an].groupRef != null)
1844 oldrfs.add(aan[an].groupRef);
1845 alignment.deleteAnnotation(aan[an], false);
1849 if (alignment.getGroups() != null)
1851 for (SequenceGroup sg : alignment.getGroups())
1853 updateCalcs = false;
1854 if (applyGlobalSettings
1855 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1857 // set defaults for this group's conservation/consensus
1858 sg.setshowSequenceLogo(showprf);
1859 sg.setShowConsensusHistogram(showConsHist);
1860 sg.setNormaliseSequenceLogo(normLogo);
1865 alignment.addAnnotation(sg.getConservationRow(), 0);
1870 alignment.addAnnotation(sg.getConsensus(), 0);
1872 // refresh the annotation rows
1875 sg.recalcConservation();
1882 public boolean isDisplayReferenceSeq()
1884 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1888 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1890 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1894 public boolean isColourByReferenceSeq()
1896 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1900 public Color getSequenceColour(SequenceI seq)
1902 Color sqc = sequenceColours.get(seq);
1903 return (sqc == null ? Color.white : sqc);
1907 public void setSequenceColour(SequenceI seq, Color col)
1911 sequenceColours.remove(seq);
1915 sequenceColours.put(seq, col);
1920 public void updateSequenceIdColours()
1922 for (SequenceGroup sg : alignment.getGroups())
1924 if (sg.idColour != null)
1926 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1928 sequenceColours.put(s, sg.idColour);
1935 public void clearSequenceColours()
1937 sequenceColours.clear();
1941 public AlignViewportI getCodingComplement()
1943 return this.codingComplement;
1947 * Set this as the (cDna/protein) complement of the given viewport. Also
1948 * ensures the reverse relationship is set on the given viewport.
1951 public void setCodingComplement(AlignViewportI av)
1955 System.err.println("Ignoring recursive setCodingComplement request");
1959 this.codingComplement = av;
1960 // avoid infinite recursion!
1961 if (av.getCodingComplement() != this)
1963 av.setCodingComplement(this);
1969 public boolean isNucleotide()
1971 return getAlignment() == null ? false : getAlignment().isNucleotide();
1975 public FeaturesDisplayedI getFeaturesDisplayed()
1977 return featuresDisplayed;
1981 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1983 featuresDisplayed = featuresDisplayedI;
1987 public boolean areFeaturesDisplayed()
1989 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1996 * features are displayed if true
1999 public void setShowSequenceFeatures(boolean b)
2001 viewStyle.setShowSequenceFeatures(b);
2004 public boolean isShowSequenceFeatures()
2006 return viewStyle.isShowSequenceFeatures();
2010 public void setShowSequenceFeaturesHeight(boolean selected)
2012 viewStyle.setShowSeqFeaturesHeight(selected);
2016 public boolean isShowSequenceFeaturesHeight()
2018 return viewStyle.isShowSequenceFeaturesHeight();
2024 public void setShowAnnotation(boolean b)
2026 viewStyle.setShowAnnotation(b);
2030 public boolean isShowAnnotation()
2032 return viewStyle.isShowAnnotation();
2036 public boolean isRightAlignIds()
2038 return viewStyle.isRightAlignIds();
2042 public void setRightAlignIds(boolean rightAlignIds)
2044 viewStyle.setRightAlignIds(rightAlignIds);
2048 public boolean getConservationSelected()
2050 return viewStyle.getConservationSelected();
2054 public void setShowBoxes(boolean state)
2056 viewStyle.setShowBoxes(state);
2061 * @see jalview.api.ViewStyleI#getTextColour()
2063 public Color getTextColour()
2065 return viewStyle.getTextColour();
2070 * @see jalview.api.ViewStyleI#getTextColour2()
2072 public Color getTextColour2()
2074 return viewStyle.getTextColour2();
2079 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2081 public int getThresholdTextColour()
2083 return viewStyle.getThresholdTextColour();
2088 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2090 public boolean isConservationColourSelected()
2092 return viewStyle.isConservationColourSelected();
2097 * @see jalview.api.ViewStyleI#isRenderGaps()
2099 public boolean isRenderGaps()
2101 return viewStyle.isRenderGaps();
2106 * @see jalview.api.ViewStyleI#isShowColourText()
2108 public boolean isShowColourText()
2110 return viewStyle.isShowColourText();
2114 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2116 public boolean isShowSeqFeaturesHeight()
2118 return viewStyle.isShowSeqFeaturesHeight();
2122 * @param conservationColourSelected
2123 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2125 public void setConservationColourSelected(
2126 boolean conservationColourSelected)
2128 viewStyle.setConservationColourSelected(conservationColourSelected);
2132 * @param showColourText
2133 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2135 public void setShowColourText(boolean showColourText)
2137 viewStyle.setShowColourText(showColourText);
2142 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2144 public void setTextColour(Color textColour)
2146 viewStyle.setTextColour(textColour);
2150 * @param thresholdTextColour
2151 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2153 public void setThresholdTextColour(int thresholdTextColour)
2155 viewStyle.setThresholdTextColour(thresholdTextColour);
2159 * @param textColour2
2160 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2162 public void setTextColour2(Color textColour2)
2164 viewStyle.setTextColour2(textColour2);
2168 public ViewStyleI getViewStyle()
2170 return new ViewStyle(viewStyle);
2174 public void setViewStyle(ViewStyleI settingsForView)
2176 viewStyle = new ViewStyle(settingsForView);
2180 public boolean sameStyle(ViewStyleI them)
2182 return viewStyle.sameStyle(them);
2187 * @see jalview.api.ViewStyleI#getIdWidth()
2189 public int getIdWidth()
2191 return viewStyle.getIdWidth();
2196 * @see jalview.api.ViewStyleI#setIdWidth(int)
2198 public void setIdWidth(int i)
2200 viewStyle.setIdWidth(i);
2205 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2207 public boolean isCentreColumnLabels()
2209 return viewStyle.isCentreColumnLabels();
2213 * @param centreColumnLabels
2214 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2216 public void setCentreColumnLabels(boolean centreColumnLabels)
2218 viewStyle.setCentreColumnLabels(centreColumnLabels);
2223 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2225 public void setShowDBRefs(boolean showdbrefs)
2227 viewStyle.setShowDBRefs(showdbrefs);
2232 * @see jalview.api.ViewStyleI#isShowDBRefs()
2234 public boolean isShowDBRefs()
2236 return viewStyle.isShowDBRefs();
2241 * @see jalview.api.ViewStyleI#isShowNPFeats()
2243 public boolean isShowNPFeats()
2245 return viewStyle.isShowNPFeats();
2249 * @param shownpfeats
2250 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2252 public void setShowNPFeats(boolean shownpfeats)
2254 viewStyle.setShowNPFeats(shownpfeats);
2257 public abstract StructureSelectionManager getStructureSelectionManager();
2260 * Add one command to the command history list.
2264 public void addToHistoryList(CommandI command)
2266 if (this.historyList != null)
2268 this.historyList.push(command);
2269 broadcastCommand(command, false);
2273 protected void broadcastCommand(CommandI command, boolean undo)
2275 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
2279 * Add one command to the command redo list.
2283 public void addToRedoList(CommandI command)
2285 if (this.redoList != null)
2287 this.redoList.push(command);
2289 broadcastCommand(command, true);
2293 * Clear the command redo list.
2295 public void clearRedoList()
2297 if (this.redoList != null)
2299 this.redoList.clear();
2303 public void setHistoryList(Deque<CommandI> list)
2305 this.historyList = list;
2308 public Deque<CommandI> getHistoryList()
2310 return this.historyList;
2313 public void setRedoList(Deque<CommandI> list)
2315 this.redoList = list;
2318 public Deque<CommandI> getRedoList()
2320 return this.redoList;
2324 public VamsasSource getVamsasSource()