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;
1057 public String getViewId()
1061 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1066 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1068 ignoreGapsInConsensusCalculation = b;
1071 updateConsensus(ap);
1072 if (globalColourScheme != null)
1074 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1075 ignoreGapsInConsensusCalculation);
1081 private long sgrouphash = -1, colselhash = -1;
1084 * checks current SelectionGroup against record of last hash value, and
1088 * update the record of last hash value
1090 * @return true if SelectionGroup changed since last call (when b is true)
1092 public boolean isSelectionGroupChanged(boolean b)
1094 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1095 : selectionGroup.hashCode();
1096 if (hc != -1 && hc != sgrouphash)
1108 * checks current colsel against record of last hash value, and optionally
1112 * update the record of last hash value
1113 * @return true if colsel changed since last call (when b is true)
1115 public boolean isColSelChanged(boolean b)
1117 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
1119 if (hc != -1 && hc != colselhash)
1131 public boolean isIgnoreGapsConsensus()
1133 return ignoreGapsInConsensusCalculation;
1136 // / property change stuff
1138 // JBPNote Prolly only need this in the applet version.
1139 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1142 protected boolean showConservation = true;
1144 protected boolean showQuality = true;
1146 protected boolean showConsensus = true;
1148 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1151 * Property change listener for changes in alignment
1156 public void addPropertyChangeListener(
1157 java.beans.PropertyChangeListener listener)
1159 changeSupport.addPropertyChangeListener(listener);
1168 public void removePropertyChangeListener(
1169 java.beans.PropertyChangeListener listener)
1171 changeSupport.removePropertyChangeListener(listener);
1175 * Property change listener for changes in alignment
1184 public void firePropertyChange(String prop, Object oldvalue,
1187 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1190 // common hide/show column stuff
1192 public void hideSelectedColumns()
1194 if (colSel.size() < 1)
1199 colSel.hideSelectedColumns();
1200 setSelectionGroup(null);
1204 public void hideColumns(int start, int end)
1208 colSel.hideColumns(start);
1212 colSel.hideColumns(start, end);
1216 public void showColumn(int col)
1218 colSel.revealHiddenColumns(col);
1222 public void showAllHiddenColumns()
1224 colSel.revealAllHiddenColumns();
1227 // common hide/show seq stuff
1228 public void showAllHiddenSeqs()
1230 if (alignment.getHiddenSequences().getSize() > 0)
1232 if (selectionGroup == null)
1234 selectionGroup = new SequenceGroup();
1235 selectionGroup.setEndRes(alignment.getWidth() - 1);
1237 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1238 hiddenRepSequences);
1239 for (SequenceI seq : tmp)
1241 selectionGroup.addSequence(seq, false);
1242 setSequenceAnnotationsVisible(seq, true);
1245 hasHiddenRows = false;
1246 hiddenRepSequences = null;
1248 firePropertyChange("alignment", null, alignment.getSequences());
1249 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1255 public void showSequence(int index)
1257 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1259 hiddenRepSequences);
1262 if (selectionGroup == null)
1264 selectionGroup = new SequenceGroup();
1265 selectionGroup.setEndRes(alignment.getWidth() - 1);
1268 for (SequenceI seq : tmp)
1270 selectionGroup.addSequence(seq, false);
1271 setSequenceAnnotationsVisible(seq, true);
1273 // JBPNote: refactor: only update flag if we modified visiblity (used to
1274 // do this regardless)
1275 if (alignment.getHiddenSequences().getSize() < 1)
1277 hasHiddenRows = false;
1279 firePropertyChange("alignment", null, alignment.getSequences());
1284 public void hideAllSelectedSeqs()
1286 if (selectionGroup == null || selectionGroup.getSize() < 1)
1291 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1295 setSelectionGroup(null);
1298 public void hideSequence(SequenceI[] seq)
1302 for (int i = 0; i < seq.length; i++)
1304 alignment.getHiddenSequences().hideSequence(seq[i]);
1305 setSequenceAnnotationsVisible(seq[i], false);
1307 hasHiddenRows = true;
1308 firePropertyChange("alignment", null, alignment.getSequences());
1313 * Set visibility for any annotations for the given sequence.
1317 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1320 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1322 if (ann.sequenceRef == sequenceI)
1324 ann.visible = visible;
1329 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1331 int sSize = sg.getSize();
1337 if (hiddenRepSequences == null)
1339 hiddenRepSequences = new Hashtable();
1342 hiddenRepSequences.put(repSequence, sg);
1344 // Hide all sequences except the repSequence
1345 SequenceI[] seqs = new SequenceI[sSize - 1];
1347 for (int i = 0; i < sSize; i++)
1349 if (sg.getSequenceAt(i) != repSequence)
1351 if (index == sSize - 1)
1356 seqs[index++] = sg.getSequenceAt(i);
1359 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1360 sg.setHidereps(true); // note: not done in 2.7applet
1365 public boolean isHiddenRepSequence(SequenceI seq)
1367 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1368 && hiddenRepSequences.containsKey(seq));
1371 public SequenceGroup getRepresentedSequences(SequenceI seq)
1373 return (SequenceGroup) (hiddenRepSequences == null ? null
1374 : hiddenRepSequences.get(seq));
1378 public int adjustForHiddenSeqs(int alignmentIndex)
1380 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1385 public void invertColumnSelection()
1387 colSel.invertColumnSelection(0, alignment.getWidth());
1392 public SequenceI[] getSelectionAsNewSequence()
1394 SequenceI[] sequences;
1395 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1396 // this was the only caller in the applet for this method
1397 // JBPNote: in applet, this method returned references to the alignment
1398 // sequences, and it did not honour the presence/absence of annotation
1399 // attached to the alignment (probably!)
1400 if (selectionGroup == null || selectionGroup.getSize() == 0)
1402 sequences = alignment.getSequencesArray();
1403 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1404 for (int i = 0; i < sequences.length; i++)
1406 sequences[i] = new Sequence(sequences[i], annots); // construct new
1408 // subset of visible
1414 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1422 public SequenceI[] getSequenceSelection()
1424 SequenceI[] sequences = null;
1425 if (selectionGroup != null)
1427 sequences = selectionGroup.getSequencesInOrder(alignment);
1429 if (sequences == null)
1431 sequences = alignment.getSequencesArray();
1438 public CigarArray getViewAsCigars(
1439 boolean selectedRegionOnly)
1441 return new CigarArray(alignment, colSel,
1442 (selectedRegionOnly ? selectionGroup : null));
1447 public jalview.datamodel.AlignmentView getAlignmentView(
1448 boolean selectedOnly)
1450 return getAlignmentView(selectedOnly, false);
1455 public jalview.datamodel.AlignmentView getAlignmentView(
1456 boolean selectedOnly, boolean markGroups)
1458 return new AlignmentView(alignment, colSel, selectionGroup,
1459 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1465 public String[] getViewAsString(boolean selectedRegionOnly)
1467 String[] selection = null;
1468 SequenceI[] seqs = null;
1470 int start = 0, end = 0;
1471 if (selectedRegionOnly && selectionGroup != null)
1473 iSize = selectionGroup.getSize();
1474 seqs = selectionGroup.getSequencesInOrder(alignment);
1475 start = selectionGroup.getStartRes();
1476 end = selectionGroup.getEndRes() + 1;
1480 iSize = alignment.getHeight();
1481 seqs = alignment.getSequencesArray();
1482 end = alignment.getWidth();
1485 selection = new String[iSize];
1486 if (colSel != null && colSel.hasHiddenColumns())
1488 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1492 for (i = 0; i < iSize; i++)
1494 selection[i] = seqs[i].getSequenceAsString(start, end);
1503 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1505 ArrayList<int[]> regions = new ArrayList<int[]>();
1511 if (colSel != null && colSel.hasHiddenColumns())
1515 start = colSel.adjustForHiddenColumns(start);
1518 end = colSel.getHiddenBoundaryRight(start);
1529 regions.add(new int[]
1532 if (colSel != null && colSel.hasHiddenColumns())
1534 start = colSel.adjustForHiddenColumns(end);
1535 start = colSel.getHiddenBoundaryLeft(start) + 1;
1537 } while (end < max);
1539 int[][] startEnd = new int[regions.size()][2];
1545 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1547 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1548 AlignmentAnnotation[] aa;
1549 if ((aa=alignment.getAlignmentAnnotation())!=null)
1551 for (AlignmentAnnotation annot:aa)
1553 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1554 if (selectedOnly && selectionGroup!=null)
1556 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1558 colSel.makeVisibleAnnotation(clone);
1568 public boolean isPadGaps()
1575 public void setPadGaps(boolean padGaps)
1577 this.padGaps = padGaps;
1581 * apply any post-edit constraints and trigger any calculations needed after
1582 * an edit has been performed on the alignment
1587 public void alignmentChanged(AlignmentViewPanel ap)
1591 alignment.padGaps();
1593 if (autoCalculateConsensus)
1595 updateConsensus(ap);
1597 if (hconsensus != null && autoCalculateConsensus)
1599 updateConservation(ap);
1601 if (autoCalculateStrucConsensus)
1603 updateStrucConsensus(ap);
1606 // Reset endRes of groups if beyond alignment width
1607 int alWidth = alignment.getWidth();
1608 List<SequenceGroup> groups = alignment.getGroups();
1611 for (SequenceGroup sg : groups)
1613 if (sg.getEndRes() > alWidth)
1615 sg.setEndRes(alWidth - 1);
1620 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1622 selectionGroup.setEndRes(alWidth - 1);
1625 resetAllColourSchemes();
1626 calculator.restartWorkers();
1627 // alignment.adjustSequenceAnnotations();
1631 * reset scope and do calculations for all applied colourschemes on alignment
1633 void resetAllColourSchemes()
1635 ColourSchemeI cs = globalColourScheme;
1638 cs.alignmentChanged(alignment, hiddenRepSequences);
1640 cs.setConsensus(hconsensus);
1641 if (cs.conservationApplied())
1643 cs.setConservation(Conservation.calculateConservation("All",
1644 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1645 alignment.getWidth(), false, getConsPercGaps(), false));
1649 for (SequenceGroup sg : alignment.getGroups())
1653 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1655 sg.recalcConservation();
1659 protected void initAutoAnnotation()
1661 // TODO: add menu option action that nulls or creates consensus object
1662 // depending on if the user wants to see the annotation or not in a
1663 // specific alignment
1665 if (hconsensus == null && !isDataset)
1667 if (!alignment.isNucleotide())
1680 private void initConsensus()
1683 consensus = new AlignmentAnnotation("Consensus", "PID",
1684 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1685 consensus.hasText = true;
1686 consensus.autoCalculated = true;
1690 alignment.addAnnotation(consensus);
1694 private void initConservation()
1696 if (showConservation)
1698 if (conservation == null)
1700 conservation = new AlignmentAnnotation("Conservation",
1701 "Conservation of total alignment less than "
1702 + getConsPercGaps() + "% gaps", new Annotation[1],
1703 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1704 conservation.hasText = true;
1705 conservation.autoCalculated = true;
1706 alignment.addAnnotation(conservation);
1711 private void initQuality()
1715 if (quality == null)
1717 quality = new AlignmentAnnotation("Quality",
1718 "Alignment Quality based on Blosum62 scores",
1719 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1720 quality.hasText = true;
1721 quality.autoCalculated = true;
1722 alignment.addAnnotation(quality);
1727 private void initRNAStructure()
1729 if (alignment.hasRNAStructure() && strucConsensus == null)
1731 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1732 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1733 strucConsensus.hasText = true;
1734 strucConsensus.autoCalculated = true;
1738 alignment.addAnnotation(strucConsensus);
1746 * @see jalview.api.AlignViewportI#calcPanelHeight()
1749 public int calcPanelHeight()
1751 // setHeight of panels
1752 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1754 int charHeight = getCharHeight();
1757 BitSet graphgrp = new BitSet();
1758 for (int i = 0; i < aa.length; i++)
1762 System.err.println("Null annotation row: ignoring.");
1769 if (aa[i].graphGroup > -1)
1771 if (graphgrp.get(aa[i].graphGroup))
1777 graphgrp.set(aa[i].graphGroup);
1784 aa[i].height += charHeight;
1792 if (aa[i].graph > 0)
1794 aa[i].height += aa[i].graphHeight;
1797 if (aa[i].height == 0)
1802 height += aa[i].height;
1814 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1815 boolean preserveNewGroupSettings)
1817 boolean updateCalcs = false;
1818 boolean conv = isShowGroupConservation();
1819 boolean cons = isShowGroupConsensus();
1820 boolean showprf = isShowSequenceLogo();
1821 boolean showConsHist = isShowConsensusHistogram();
1822 boolean normLogo = isNormaliseSequenceLogo();
1825 * TODO reorder the annotation rows according to group/sequence ordering on
1828 boolean sortg = true;
1830 // remove old automatic annotation
1831 // add any new annotation
1833 // intersect alignment annotation with alignment groups
1835 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1836 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1839 for (int an = 0; an < aan.length; an++)
1841 if (aan[an].autoCalculated && aan[an].groupRef != null)
1843 oldrfs.add(aan[an].groupRef);
1844 alignment.deleteAnnotation(aan[an], false);
1848 if (alignment.getGroups() != null)
1850 for (SequenceGroup sg : alignment.getGroups())
1852 updateCalcs = false;
1853 if (applyGlobalSettings
1854 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1856 // set defaults for this group's conservation/consensus
1857 sg.setshowSequenceLogo(showprf);
1858 sg.setShowConsensusHistogram(showConsHist);
1859 sg.setNormaliseSequenceLogo(normLogo);
1864 alignment.addAnnotation(sg.getConservationRow(), 0);
1869 alignment.addAnnotation(sg.getConsensus(), 0);
1871 // refresh the annotation rows
1874 sg.recalcConservation();
1881 public boolean isDisplayReferenceSeq()
1883 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1887 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1889 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1893 public boolean isColourByReferenceSeq()
1895 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1899 public Color getSequenceColour(SequenceI seq)
1901 Color sqc = sequenceColours.get(seq);
1902 return (sqc == null ? Color.white : sqc);
1906 public void setSequenceColour(SequenceI seq, Color col)
1910 sequenceColours.remove(seq);
1914 sequenceColours.put(seq, col);
1919 public void updateSequenceIdColours()
1921 for (SequenceGroup sg : alignment.getGroups())
1923 if (sg.idColour != null)
1925 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1927 sequenceColours.put(s, sg.idColour);
1934 public void clearSequenceColours()
1936 sequenceColours.clear();
1940 public AlignViewportI getCodingComplement()
1942 return this.codingComplement;
1946 * Set this as the (cDna/protein) complement of the given viewport. Also
1947 * ensures the reverse relationship is set on the given viewport.
1950 public void setCodingComplement(AlignViewportI av)
1954 System.err.println("Ignoring recursive setCodingComplement request");
1958 this.codingComplement = av;
1959 // avoid infinite recursion!
1960 if (av.getCodingComplement() != this)
1962 av.setCodingComplement(this);
1968 public boolean isNucleotide()
1970 return getAlignment() == null ? false : getAlignment().isNucleotide();
1974 public FeaturesDisplayedI getFeaturesDisplayed()
1976 return featuresDisplayed;
1980 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
1982 featuresDisplayed = featuresDisplayedI;
1986 public boolean areFeaturesDisplayed()
1988 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
1995 * features are displayed if true
1998 public void setShowSequenceFeatures(boolean b)
2000 viewStyle.setShowSequenceFeatures(b);
2003 public boolean isShowSequenceFeatures()
2005 return viewStyle.isShowSequenceFeatures();
2009 public void setShowSequenceFeaturesHeight(boolean selected)
2011 viewStyle.setShowSeqFeaturesHeight(selected);
2015 public boolean isShowSequenceFeaturesHeight()
2017 return viewStyle.isShowSequenceFeaturesHeight();
2023 public void setShowAnnotation(boolean b)
2025 viewStyle.setShowAnnotation(b);
2029 public boolean isShowAnnotation()
2031 return viewStyle.isShowAnnotation();
2035 public boolean isRightAlignIds()
2037 return viewStyle.isRightAlignIds();
2041 public void setRightAlignIds(boolean rightAlignIds)
2043 viewStyle.setRightAlignIds(rightAlignIds);
2047 public boolean getConservationSelected()
2049 return viewStyle.getConservationSelected();
2053 public void setShowBoxes(boolean state)
2055 viewStyle.setShowBoxes(state);
2060 * @see jalview.api.ViewStyleI#getTextColour()
2062 public Color getTextColour()
2064 return viewStyle.getTextColour();
2069 * @see jalview.api.ViewStyleI#getTextColour2()
2071 public Color getTextColour2()
2073 return viewStyle.getTextColour2();
2078 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2080 public int getThresholdTextColour()
2082 return viewStyle.getThresholdTextColour();
2087 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2089 public boolean isConservationColourSelected()
2091 return viewStyle.isConservationColourSelected();
2096 * @see jalview.api.ViewStyleI#isRenderGaps()
2098 public boolean isRenderGaps()
2100 return viewStyle.isRenderGaps();
2105 * @see jalview.api.ViewStyleI#isShowColourText()
2107 public boolean isShowColourText()
2109 return viewStyle.isShowColourText();
2113 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2115 public boolean isShowSeqFeaturesHeight()
2117 return viewStyle.isShowSeqFeaturesHeight();
2121 * @param conservationColourSelected
2122 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2124 public void setConservationColourSelected(
2125 boolean conservationColourSelected)
2127 viewStyle.setConservationColourSelected(conservationColourSelected);
2131 * @param showColourText
2132 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2134 public void setShowColourText(boolean showColourText)
2136 viewStyle.setShowColourText(showColourText);
2141 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2143 public void setTextColour(Color textColour)
2145 viewStyle.setTextColour(textColour);
2149 * @param thresholdTextColour
2150 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2152 public void setThresholdTextColour(int thresholdTextColour)
2154 viewStyle.setThresholdTextColour(thresholdTextColour);
2158 * @param textColour2
2159 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2161 public void setTextColour2(Color textColour2)
2163 viewStyle.setTextColour2(textColour2);
2167 public ViewStyleI getViewStyle()
2169 return new ViewStyle(viewStyle);
2173 public void setViewStyle(ViewStyleI settingsForView)
2175 viewStyle = new ViewStyle(settingsForView);
2179 public boolean sameStyle(ViewStyleI them)
2181 return viewStyle.sameStyle(them);
2186 * @see jalview.api.ViewStyleI#getIdWidth()
2188 public int getIdWidth()
2190 return viewStyle.getIdWidth();
2195 * @see jalview.api.ViewStyleI#setIdWidth(int)
2197 public void setIdWidth(int i)
2199 viewStyle.setIdWidth(i);
2204 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2206 public boolean isCentreColumnLabels()
2208 return viewStyle.isCentreColumnLabels();
2212 * @param centreColumnLabels
2213 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2215 public void setCentreColumnLabels(boolean centreColumnLabels)
2217 viewStyle.setCentreColumnLabels(centreColumnLabels);
2222 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2224 public void setShowDBRefs(boolean showdbrefs)
2226 viewStyle.setShowDBRefs(showdbrefs);
2231 * @see jalview.api.ViewStyleI#isShowDBRefs()
2233 public boolean isShowDBRefs()
2235 return viewStyle.isShowDBRefs();
2240 * @see jalview.api.ViewStyleI#isShowNPFeats()
2242 public boolean isShowNPFeats()
2244 return viewStyle.isShowNPFeats();
2248 * @param shownpfeats
2249 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2251 public void setShowNPFeats(boolean shownpfeats)
2253 viewStyle.setShowNPFeats(shownpfeats);
2256 public abstract StructureSelectionManager getStructureSelectionManager();
2259 * Add one command to the command history list.
2263 public void addToHistoryList(CommandI command)
2265 if (this.historyList != null)
2267 this.historyList.push(command);
2268 broadcastCommand(command, false);
2272 protected void broadcastCommand(CommandI command, boolean undo)
2274 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
2278 * Add one command to the command redo list.
2282 public void addToRedoList(CommandI command)
2284 if (this.redoList != null)
2286 this.redoList.push(command);
2288 broadcastCommand(command, true);
2292 * Clear the command redo list.
2294 public void clearRedoList()
2296 if (this.redoList != null)
2298 this.redoList.clear();
2302 public void setHistoryList(Deque<CommandI> list)
2304 this.historyList = list;
2307 public Deque<CommandI> getHistoryList()
2309 return this.historyList;
2312 public void setRedoList(Deque<CommandI> list)
2314 this.redoList = list;
2317 public Deque<CommandI> getRedoList()
2319 return this.redoList;
2323 public VamsasSource getVamsasSource()