2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.viewmodel;
23 import jalview.analysis.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.AlignedCodonFrame;
31 import jalview.datamodel.AlignmentAnnotation;
32 import jalview.datamodel.AlignmentI;
33 import jalview.datamodel.AlignmentView;
34 import jalview.datamodel.Annotation;
35 import jalview.datamodel.CigarArray;
36 import jalview.datamodel.ColumnSelection;
37 import jalview.datamodel.Sequence;
38 import jalview.datamodel.SequenceCollectionI;
39 import jalview.datamodel.SequenceGroup;
40 import jalview.datamodel.SequenceI;
41 import jalview.schemes.Blosum62ColourScheme;
42 import jalview.schemes.ColourSchemeI;
43 import jalview.schemes.PIDColourScheme;
44 import jalview.schemes.ResidueProperties;
45 import jalview.structure.CommandListener;
46 import jalview.structure.StructureSelectionManager;
47 import jalview.structure.VamsasSource;
48 import jalview.viewmodel.styles.ViewStyle;
49 import jalview.workers.AlignCalcManager;
50 import jalview.workers.ComplementConsensusThread;
51 import jalview.workers.ConsensusThread;
52 import jalview.workers.StrucConsensusThread;
54 import java.awt.Color;
55 import java.util.ArrayDeque;
56 import java.util.ArrayList;
57 import java.util.BitSet;
58 import java.util.Deque;
59 import java.util.HashMap;
60 import java.util.Hashtable;
61 import java.util.List;
66 * base class holding visualization and analysis attributes and common logic for
67 * an active alignment view displayed in the GUI
72 public abstract class AlignmentViewport implements AlignViewportI,
73 ViewStyleI, CommandListener, VamsasSource
75 protected ViewStyleI viewStyle = new ViewStyle();
78 * A viewport that hosts the cDna view of this (protein), or vice versa (if
81 AlignViewportI codingComplement = null;
83 FeaturesDisplayedI featuresDisplayed = null;
85 protected Deque<CommandI> historyList = new ArrayDeque<CommandI>();
87 protected Deque<CommandI> redoList = new ArrayDeque<CommandI>();
91 * @see jalview.api.ViewStyleI#setFontName(java.lang.String)
93 public void setFontName(String name)
95 viewStyle.setFontName(name);
100 * @see jalview.api.ViewStyleI#setFontStyle(int)
102 public void setFontStyle(int style)
104 viewStyle.setFontStyle(style);
109 * @see jalview.api.ViewStyleI#setFontSize(int)
111 public void setFontSize(int size)
113 viewStyle.setFontSize(size);
118 * @see jalview.api.ViewStyleI#getFontStyle()
120 public int getFontStyle()
122 return viewStyle.getFontStyle();
127 * @see jalview.api.ViewStyleI#getFontName()
129 public String getFontName()
131 return viewStyle.getFontName();
136 * @see jalview.api.ViewStyleI#getFontSize()
138 public int getFontSize()
140 return viewStyle.getFontSize();
144 * @param upperCasebold
145 * @see jalview.api.ViewStyleI#setUpperCasebold(boolean)
147 public void setUpperCasebold(boolean upperCasebold)
149 viewStyle.setUpperCasebold(upperCasebold);
154 * @see jalview.api.ViewStyleI#isUpperCasebold()
156 public boolean isUpperCasebold()
158 return viewStyle.isUpperCasebold();
163 * @see jalview.api.ViewStyleI#isSeqNameItalics()
165 public boolean isSeqNameItalics()
167 return viewStyle.isSeqNameItalics();
171 * @param colourByReferenceSeq
172 * @see jalview.api.ViewStyleI#setColourByReferenceSeq(boolean)
174 public void setColourByReferenceSeq(boolean colourByReferenceSeq)
176 viewStyle.setColourByReferenceSeq(colourByReferenceSeq);
181 * @see jalview.api.ViewStyleI#setColourAppliesToAllGroups(boolean)
183 public void setColourAppliesToAllGroups(boolean b)
185 viewStyle.setColourAppliesToAllGroups(b);
190 * @see jalview.api.ViewStyleI#getColourAppliesToAllGroups()
192 public boolean getColourAppliesToAllGroups()
194 return viewStyle.getColourAppliesToAllGroups();
199 * @see jalview.api.ViewStyleI#getAbovePIDThreshold()
201 public boolean getAbovePIDThreshold()
203 return viewStyle.getAbovePIDThreshold();
208 * @see jalview.api.ViewStyleI#setIncrement(int)
210 public void setIncrement(int inc)
212 viewStyle.setIncrement(inc);
217 * @see jalview.api.ViewStyleI#getIncrement()
219 public int getIncrement()
221 return viewStyle.getIncrement();
226 * @see jalview.api.ViewStyleI#setConservationSelected(boolean)
228 public void setConservationSelected(boolean b)
230 viewStyle.setConservationSelected(b);
235 * @see jalview.api.ViewStyleI#setShowHiddenMarkers(boolean)
237 public void setShowHiddenMarkers(boolean show)
239 viewStyle.setShowHiddenMarkers(show);
244 * @see jalview.api.ViewStyleI#getShowHiddenMarkers()
246 public boolean getShowHiddenMarkers()
248 return viewStyle.getShowHiddenMarkers();
253 * @see jalview.api.ViewStyleI#setScaleRightWrapped(boolean)
255 public void setScaleRightWrapped(boolean b)
257 viewStyle.setScaleRightWrapped(b);
262 * @see jalview.api.ViewStyleI#setScaleLeftWrapped(boolean)
264 public void setScaleLeftWrapped(boolean b)
266 viewStyle.setScaleLeftWrapped(b);
271 * @see jalview.api.ViewStyleI#setScaleAboveWrapped(boolean)
273 public void setScaleAboveWrapped(boolean b)
275 viewStyle.setScaleAboveWrapped(b);
280 * @see jalview.api.ViewStyleI#getScaleLeftWrapped()
282 public boolean getScaleLeftWrapped()
284 return viewStyle.getScaleLeftWrapped();
289 * @see jalview.api.ViewStyleI#getScaleAboveWrapped()
291 public boolean getScaleAboveWrapped()
293 return viewStyle.getScaleAboveWrapped();
298 * @see jalview.api.ViewStyleI#getScaleRightWrapped()
300 public boolean getScaleRightWrapped()
302 return viewStyle.getScaleRightWrapped();
307 * @see jalview.api.ViewStyleI#setAbovePIDThreshold(boolean)
309 public void setAbovePIDThreshold(boolean b)
311 viewStyle.setAbovePIDThreshold(b);
316 * @see jalview.api.ViewStyleI#setThreshold(int)
318 public void setThreshold(int thresh)
320 viewStyle.setThreshold(thresh);
325 * @see jalview.api.ViewStyleI#getThreshold()
327 public int getThreshold()
329 return viewStyle.getThreshold();
334 * @see jalview.api.ViewStyleI#getShowJVSuffix()
336 public boolean getShowJVSuffix()
338 return viewStyle.getShowJVSuffix();
343 * @see jalview.api.ViewStyleI#setShowJVSuffix(boolean)
345 public void setShowJVSuffix(boolean b)
347 viewStyle.setShowJVSuffix(b);
352 * @see jalview.api.ViewStyleI#setWrapAlignment(boolean)
354 public void setWrapAlignment(boolean state)
356 viewStyle.setWrapAlignment(state);
361 * @see jalview.api.ViewStyleI#setShowText(boolean)
363 public void setShowText(boolean state)
365 viewStyle.setShowText(state);
370 * @see jalview.api.ViewStyleI#setRenderGaps(boolean)
372 public void setRenderGaps(boolean state)
374 viewStyle.setRenderGaps(state);
379 * @see jalview.api.ViewStyleI#getColourText()
381 public boolean getColourText()
383 return viewStyle.getColourText();
388 * @see jalview.api.ViewStyleI#setColourText(boolean)
390 public void setColourText(boolean state)
392 viewStyle.setColourText(state);
397 * @see jalview.api.ViewStyleI#getWrapAlignment()
399 public boolean getWrapAlignment()
401 return viewStyle.getWrapAlignment();
406 * @see jalview.api.ViewStyleI#getShowText()
408 public boolean getShowText()
410 return viewStyle.getShowText();
415 * @see jalview.api.ViewStyleI#getWrappedWidth()
417 public int getWrappedWidth()
419 return viewStyle.getWrappedWidth();
424 * @see jalview.api.ViewStyleI#setWrappedWidth(int)
426 public void setWrappedWidth(int w)
428 viewStyle.setWrappedWidth(w);
433 * @see jalview.api.ViewStyleI#getCharHeight()
435 public int getCharHeight()
437 return viewStyle.getCharHeight();
442 * @see jalview.api.ViewStyleI#setCharHeight(int)
444 public void setCharHeight(int h)
446 viewStyle.setCharHeight(h);
451 * @see jalview.api.ViewStyleI#getCharWidth()
453 public int getCharWidth()
455 return viewStyle.getCharWidth();
460 * @see jalview.api.ViewStyleI#setCharWidth(int)
462 public void setCharWidth(int w)
464 viewStyle.setCharWidth(w);
469 * @see jalview.api.ViewStyleI#getShowBoxes()
471 public boolean getShowBoxes()
473 return viewStyle.getShowBoxes();
478 * @see jalview.api.ViewStyleI#getShowUnconserved()
480 public boolean getShowUnconserved()
482 return viewStyle.getShowUnconserved();
486 * @param showunconserved
487 * @see jalview.api.ViewStyleI#setShowUnconserved(boolean)
489 public void setShowUnconserved(boolean showunconserved)
491 viewStyle.setShowUnconserved(showunconserved);
496 * @see jalview.api.ViewStyleI#setSeqNameItalics(boolean)
498 public void setSeqNameItalics(boolean default1)
500 viewStyle.setSeqNameItalics(default1);
505 * @see jalview.api.ViewStyleI#setShowSeqFeaturesHeight(boolean)
507 public void setShowSeqFeaturesHeight(boolean selected)
509 viewStyle.setShowSeqFeaturesHeight(selected);
513 * alignment displayed in the viewport. Please use get/setter
515 protected AlignmentI alignment;
518 public AlignmentI getAlignment()
524 public char getGapCharacter()
526 return alignment.getGapCharacter();
529 protected String sequenceSetID;
532 * probably unused indicator that view is of a dataset rather than an
535 protected boolean isDataset = false;
537 public void setDataset(boolean b)
542 public boolean isDataset()
548 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
550 protected ColumnSelection colSel = new ColumnSelection();
552 public boolean autoCalculateConsensus = true;
554 protected boolean autoCalculateStrucConsensus = true;
556 protected boolean ignoreGapsInConsensusCalculation = false;
558 protected ColourSchemeI globalColourScheme = null;
562 public void setGlobalColourScheme(ColourSchemeI cs)
564 // TODO: logic refactored from AlignFrame changeColour -
565 // autorecalc stuff should be changed to rely on the worker system
566 // check to see if we should implement a changeColour(cs) method rather than
567 // put th logic in here
568 // - means that caller decides if they want to just modify state and defer
569 // calculation till later or to do all calculations in thread.
571 globalColourScheme = cs;
572 boolean recalc = false;
575 cs.setConservationApplied(recalc = getConservationSelected());
576 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
577 || cs instanceof Blosum62ColourScheme)
580 cs.setThreshold(viewStyle.getThreshold(),
581 ignoreGapsInConsensusCalculation);
585 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
589 cs.setConsensus(hconsensus);
590 cs.setConservation(hconservation);
592 cs.alignmentChanged(alignment, hiddenRepSequences);
594 if (getColourAppliesToAllGroups())
596 for (SequenceGroup sg : getAlignment().getGroups())
603 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
604 sg.setConsPercGaps(ConsPercGaps);
605 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
606 || cs instanceof Blosum62ColourScheme)
608 sg.cs.setThreshold(viewStyle.getThreshold(),
609 isIgnoreGapsConsensus());
614 sg.cs.setThreshold(0, isIgnoreGapsConsensus());
617 if (getConservationSelected())
619 sg.cs.setConservationApplied(true);
624 sg.cs.setConservation(null);
625 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
629 sg.recalcConservation();
633 sg.cs.alignmentChanged(sg, hiddenRepSequences);
641 public ColourSchemeI getGlobalColourScheme()
643 return globalColourScheme;
646 protected AlignmentAnnotation consensus;
648 protected AlignmentAnnotation complementConsensus;
650 protected AlignmentAnnotation strucConsensus;
652 protected AlignmentAnnotation conservation;
654 protected AlignmentAnnotation quality;
656 protected AlignmentAnnotation[] groupConsensus;
658 protected AlignmentAnnotation[] groupConservation;
661 * results of alignment consensus analysis for visible portion of view
663 protected Hashtable[] hconsensus = null;
666 * results of cDNA complement consensus visible portion of view
668 protected Hashtable[] hcomplementConsensus = null;
671 * results of secondary structure base pair consensus for visible portion of
674 protected Hashtable[] hStrucConsensus = null;
676 protected Conservation hconservation = null;
679 public void setConservation(Conservation cons)
681 hconservation = cons;
685 * percentage gaps allowed in a column before all amino acid properties should
686 * be considered unconserved
688 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
691 public int getConsPercGaps()
697 public void setSequenceConsensusHash(Hashtable[] hconsensus)
699 this.hconsensus = hconsensus;
703 public void setComplementConsensusHash(Hashtable[] hconsensus)
705 this.hcomplementConsensus = hconsensus;
709 public Hashtable[] getSequenceConsensusHash()
715 public Hashtable[] getComplementConsensusHash()
717 return hcomplementConsensus;
721 public Hashtable[] getRnaStructureConsensusHash()
723 return hStrucConsensus;
727 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
729 this.hStrucConsensus = hStrucConsensus;
734 public AlignmentAnnotation getAlignmentQualityAnnot()
740 public AlignmentAnnotation getAlignmentConservationAnnotation()
746 public AlignmentAnnotation getAlignmentConsensusAnnotation()
752 public AlignmentAnnotation getComplementConsensusAnnotation()
754 return complementConsensus;
758 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
760 return strucConsensus;
763 protected AlignCalcManagerI calculator = new AlignCalcManager();
766 * trigger update of conservation annotation
768 public void updateConservation(final AlignmentViewPanel ap)
770 // see note in mantis : issue number 8585
771 if (alignment.isNucleotide() || conservation == null
772 || !autoCalculateConsensus)
777 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
779 calculator.registerWorker(new jalview.workers.ConservationThread(
785 * trigger update of consensus annotation
787 public void updateConsensus(final AlignmentViewPanel ap)
789 // see note in mantis : issue number 8585
790 if (consensus == null || !autoCalculateConsensus)
794 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
796 calculator.registerWorker(new ConsensusThread(this, ap));
800 * A separate thread to compute cDNA consensus for a protein alignment
802 final AlignmentI al = this.getAlignment();
803 if (!al.isNucleotide() && al.getCodonFrames() != null
804 && !al.getCodonFrames().isEmpty())
807 .getRegisteredWorkersOfClass(ComplementConsensusThread.class) == null)
809 calculator.registerWorker(new ComplementConsensusThread(this, ap));
814 // --------START Structure Conservation
815 public void updateStrucConsensus(final AlignmentViewPanel ap)
817 if (autoCalculateStrucConsensus && strucConsensus == null
818 && alignment.isNucleotide() && alignment.hasRNAStructure())
820 // secondary structure has been added - so init the consensus line
824 // see note in mantis : issue number 8585
825 if (strucConsensus == null || !autoCalculateStrucConsensus)
829 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
831 calculator.registerWorker(new StrucConsensusThread(this, ap));
835 public boolean isCalcInProgress()
837 return calculator.isWorking();
841 public boolean isCalculationInProgress(
842 AlignmentAnnotation alignmentAnnotation)
844 if (!alignmentAnnotation.autoCalculated)
848 if (calculator.workingInvolvedWith(alignmentAnnotation))
850 // System.err.println("grey out ("+alignmentAnnotation.label+")");
857 public boolean isClosed()
859 // TODO: check that this isClosed is only true after panel is closed, not
860 // before it is fully constructed.
861 return alignment == null;
865 public AlignCalcManagerI getCalcManager()
871 * should conservation rows be shown for groups
873 protected boolean showGroupConservation = false;
876 * should consensus rows be shown for groups
878 protected boolean showGroupConsensus = false;
881 * should consensus profile be rendered by default
883 protected boolean showSequenceLogo = false;
886 * should consensus profile be rendered normalised to row height
888 protected boolean normaliseSequenceLogo = false;
891 * should consensus histograms be rendered by default
893 protected boolean showConsensusHistogram = true;
896 * @return the showConsensusProfile
899 public boolean isShowSequenceLogo()
901 return showSequenceLogo;
905 * @param showSequenceLogo
908 public void setShowSequenceLogo(boolean showSequenceLogo)
910 if (showSequenceLogo != this.showSequenceLogo)
912 // TODO: decouple settings setting from calculation when refactoring
913 // annotation update method from alignframe to viewport
914 this.showSequenceLogo = showSequenceLogo;
915 calculator.updateAnnotationFor(ConsensusThread.class);
916 calculator.updateAnnotationFor(ComplementConsensusThread.class);
917 calculator.updateAnnotationFor(StrucConsensusThread.class);
919 this.showSequenceLogo = showSequenceLogo;
923 * @param showConsensusHistogram
924 * the showConsensusHistogram to set
926 public void setShowConsensusHistogram(boolean showConsensusHistogram)
928 this.showConsensusHistogram = showConsensusHistogram;
932 * @return the showGroupConservation
934 public boolean isShowGroupConservation()
936 return showGroupConservation;
940 * @param showGroupConservation
941 * the showGroupConservation to set
943 public void setShowGroupConservation(boolean showGroupConservation)
945 this.showGroupConservation = showGroupConservation;
949 * @return the showGroupConsensus
951 public boolean isShowGroupConsensus()
953 return showGroupConsensus;
957 * @param showGroupConsensus
958 * the showGroupConsensus to set
960 public void setShowGroupConsensus(boolean showGroupConsensus)
962 this.showGroupConsensus = showGroupConsensus;
967 * @return flag to indicate if the consensus histogram should be rendered by
971 public boolean isShowConsensusHistogram()
973 return this.showConsensusHistogram;
977 * when set, updateAlignment will always ensure sequences are of equal length
979 private boolean padGaps = false;
982 * when set, alignment should be reordered according to a newly opened tree
984 public boolean sortByTree = false;
990 * @return null or the currently selected sequence region
993 public SequenceGroup getSelectionGroup()
995 return selectionGroup;
999 * Set the selection group for this window.
1002 * - group holding references to sequences in this alignment view
1006 public void setSelectionGroup(SequenceGroup sg)
1008 selectionGroup = sg;
1011 public void setHiddenColumns(ColumnSelection colsel)
1013 this.colSel = colsel;
1017 public ColumnSelection getColumnSelection()
1023 public void setColumnSelection(ColumnSelection colSel)
1025 this.colSel = colSel;
1028 updateHiddenColumns();
1037 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
1039 return hiddenRepSequences;
1043 public void setHiddenRepSequences(
1044 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
1046 this.hiddenRepSequences = hiddenRepSequences;
1050 public boolean hasHiddenColumns()
1052 return colSel != null && colSel.hasHiddenColumns();
1055 public void updateHiddenColumns()
1057 // this method doesn't really do anything now. But - it could, since a
1058 // column Selection could be in the process of modification
1059 // hasHiddenColumns = colSel.hasHiddenColumns();
1062 protected boolean hasHiddenRows = false;
1065 public boolean hasHiddenRows()
1067 return hasHiddenRows;
1070 protected SequenceGroup selectionGroup;
1072 public void setSequenceSetId(String newid)
1074 if (sequenceSetID != null)
1077 .println("Warning - overwriting a sequenceSetId for a viewport!");
1079 sequenceSetID = new String(newid);
1083 public String getSequenceSetId()
1085 if (sequenceSetID == null)
1087 sequenceSetID = alignment.hashCode() + "";
1090 return sequenceSetID;
1094 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
1097 protected String viewId = null;
1100 public String getViewId()
1104 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1109 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
1111 ignoreGapsInConsensusCalculation = b;
1114 updateConsensus(ap);
1115 if (globalColourScheme != null)
1117 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1118 ignoreGapsInConsensusCalculation);
1124 private long sgrouphash = -1, colselhash = -1;
1127 * checks current SelectionGroup against record of last hash value, and
1131 * update the record of last hash value
1133 * @return true if SelectionGroup changed since last call (when b is true)
1135 public boolean isSelectionGroupChanged(boolean b)
1137 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
1138 : selectionGroup.hashCode();
1139 if (hc != -1 && hc != sgrouphash)
1151 * checks current colsel against record of last hash value, and optionally
1155 * update the record of last hash value
1156 * @return true if colsel changed since last call (when b is true)
1158 public boolean isColSelChanged(boolean b)
1160 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
1162 if (hc != -1 && hc != colselhash)
1174 public boolean isIgnoreGapsConsensus()
1176 return ignoreGapsInConsensusCalculation;
1179 // / property change stuff
1181 // JBPNote Prolly only need this in the applet version.
1182 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
1185 protected boolean showConservation = true;
1187 protected boolean showQuality = true;
1189 protected boolean showConsensus = true;
1191 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
1194 * Property change listener for changes in alignment
1199 public void addPropertyChangeListener(
1200 java.beans.PropertyChangeListener listener)
1202 changeSupport.addPropertyChangeListener(listener);
1211 public void removePropertyChangeListener(
1212 java.beans.PropertyChangeListener listener)
1214 changeSupport.removePropertyChangeListener(listener);
1218 * Property change listener for changes in alignment
1227 public void firePropertyChange(String prop, Object oldvalue,
1230 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1233 // common hide/show column stuff
1235 public void hideSelectedColumns()
1237 if (colSel.size() < 1)
1242 colSel.hideSelectedColumns();
1243 setSelectionGroup(null);
1247 public void hideColumns(int start, int end)
1251 colSel.hideColumns(start);
1255 colSel.hideColumns(start, end);
1259 public void showColumn(int col)
1261 colSel.revealHiddenColumns(col);
1265 public void showAllHiddenColumns()
1267 colSel.revealAllHiddenColumns();
1270 // common hide/show seq stuff
1271 public void showAllHiddenSeqs()
1273 if (alignment.getHiddenSequences().getSize() > 0)
1275 if (selectionGroup == null)
1277 selectionGroup = new SequenceGroup();
1278 selectionGroup.setEndRes(alignment.getWidth() - 1);
1280 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
1281 hiddenRepSequences);
1282 for (SequenceI seq : tmp)
1284 selectionGroup.addSequence(seq, false);
1285 setSequenceAnnotationsVisible(seq, true);
1288 hasHiddenRows = false;
1289 hiddenRepSequences = null;
1291 firePropertyChange("alignment", null, alignment.getSequences());
1292 // used to set hasHiddenRows/hiddenRepSequences here, after the property
1298 public void showSequence(int index)
1300 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
1302 hiddenRepSequences);
1305 if (selectionGroup == null)
1307 selectionGroup = new SequenceGroup();
1308 selectionGroup.setEndRes(alignment.getWidth() - 1);
1311 for (SequenceI seq : tmp)
1313 selectionGroup.addSequence(seq, false);
1314 setSequenceAnnotationsVisible(seq, true);
1316 // JBPNote: refactor: only update flag if we modified visiblity (used to
1317 // do this regardless)
1318 if (alignment.getHiddenSequences().getSize() < 1)
1320 hasHiddenRows = false;
1322 firePropertyChange("alignment", null, alignment.getSequences());
1327 public void hideAllSelectedSeqs()
1329 if (selectionGroup == null || selectionGroup.getSize() < 1)
1334 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1338 setSelectionGroup(null);
1341 public void hideSequence(SequenceI[] seq)
1345 for (int i = 0; i < seq.length; i++)
1347 alignment.getHiddenSequences().hideSequence(seq[i]);
1348 setSequenceAnnotationsVisible(seq[i], false);
1350 hasHiddenRows = true;
1351 firePropertyChange("alignment", null, alignment.getSequences());
1356 * Set visibility for any annotations for the given sequence.
1360 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1363 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1365 if (ann.sequenceRef == sequenceI)
1367 ann.visible = visible;
1372 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1374 int sSize = sg.getSize();
1380 if (hiddenRepSequences == null)
1382 hiddenRepSequences = new Hashtable();
1385 hiddenRepSequences.put(repSequence, sg);
1387 // Hide all sequences except the repSequence
1388 SequenceI[] seqs = new SequenceI[sSize - 1];
1390 for (int i = 0; i < sSize; i++)
1392 if (sg.getSequenceAt(i) != repSequence)
1394 if (index == sSize - 1)
1399 seqs[index++] = sg.getSequenceAt(i);
1402 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1403 sg.setHidereps(true); // note: not done in 2.7applet
1408 public boolean isHiddenRepSequence(SequenceI seq)
1410 return alignment.getSeqrep()==seq || (hiddenRepSequences != null
1411 && hiddenRepSequences.containsKey(seq));
1414 public SequenceGroup getRepresentedSequences(SequenceI seq)
1416 return (SequenceGroup) (hiddenRepSequences == null ? null
1417 : hiddenRepSequences.get(seq));
1421 public int adjustForHiddenSeqs(int alignmentIndex)
1423 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1428 public void invertColumnSelection()
1430 colSel.invertColumnSelection(0, alignment.getWidth());
1435 public SequenceI[] getSelectionAsNewSequence()
1437 SequenceI[] sequences;
1438 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1439 // this was the only caller in the applet for this method
1440 // JBPNote: in applet, this method returned references to the alignment
1441 // sequences, and it did not honour the presence/absence of annotation
1442 // attached to the alignment (probably!)
1443 if (selectionGroup == null || selectionGroup.getSize() == 0)
1445 sequences = alignment.getSequencesArray();
1446 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1447 for (int i = 0; i < sequences.length; i++)
1449 // construct new sequence with subset of visible annotation
1450 sequences[i] = new Sequence(sequences[i], annots);
1455 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1463 public SequenceI[] getSequenceSelection()
1465 SequenceI[] sequences = null;
1466 if (selectionGroup != null)
1468 sequences = selectionGroup.getSequencesInOrder(alignment);
1470 if (sequences == null)
1472 sequences = alignment.getSequencesArray();
1479 public CigarArray getViewAsCigars(
1480 boolean selectedRegionOnly)
1482 return new CigarArray(alignment, colSel,
1483 (selectedRegionOnly ? selectionGroup : null));
1488 public jalview.datamodel.AlignmentView getAlignmentView(
1489 boolean selectedOnly)
1491 return getAlignmentView(selectedOnly, false);
1496 public jalview.datamodel.AlignmentView getAlignmentView(
1497 boolean selectedOnly, boolean markGroups)
1499 return new AlignmentView(alignment, colSel, selectionGroup,
1500 colSel != null && colSel.hasHiddenColumns(), selectedOnly,
1506 public String[] getViewAsString(boolean selectedRegionOnly)
1508 String[] selection = null;
1509 SequenceI[] seqs = null;
1511 int start = 0, end = 0;
1512 if (selectedRegionOnly && selectionGroup != null)
1514 iSize = selectionGroup.getSize();
1515 seqs = selectionGroup.getSequencesInOrder(alignment);
1516 start = selectionGroup.getStartRes();
1517 end = selectionGroup.getEndRes() + 1;
1521 iSize = alignment.getHeight();
1522 seqs = alignment.getSequencesArray();
1523 end = alignment.getWidth();
1526 selection = new String[iSize];
1527 if (colSel != null && colSel.hasHiddenColumns())
1529 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1533 for (i = 0; i < iSize; i++)
1535 selection[i] = seqs[i].getSequenceAsString(start, end);
1544 public List<int[]> getVisibleRegionBoundaries(int min, int max)
1546 ArrayList<int[]> regions = new ArrayList<int[]>();
1552 if (colSel != null && colSel.hasHiddenColumns())
1556 start = colSel.adjustForHiddenColumns(start);
1559 end = colSel.getHiddenBoundaryRight(start);
1570 regions.add(new int[]
1573 if (colSel != null && colSel.hasHiddenColumns())
1575 start = colSel.adjustForHiddenColumns(end);
1576 start = colSel.getHiddenBoundaryLeft(start) + 1;
1578 } while (end < max);
1580 int[][] startEnd = new int[regions.size()][2];
1586 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1588 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1589 AlignmentAnnotation[] aa;
1590 if ((aa=alignment.getAlignmentAnnotation())!=null)
1592 for (AlignmentAnnotation annot:aa)
1594 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1595 if (selectedOnly && selectionGroup!=null)
1597 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1599 colSel.makeVisibleAnnotation(clone);
1609 public boolean isPadGaps()
1616 public void setPadGaps(boolean padGaps)
1618 this.padGaps = padGaps;
1622 * apply any post-edit constraints and trigger any calculations needed after
1623 * an edit has been performed on the alignment
1628 public void alignmentChanged(AlignmentViewPanel ap)
1632 alignment.padGaps();
1634 if (autoCalculateConsensus)
1636 updateConsensus(ap);
1638 if (hconsensus != null && autoCalculateConsensus)
1640 updateConservation(ap);
1642 if (autoCalculateStrucConsensus)
1644 updateStrucConsensus(ap);
1647 // Reset endRes of groups if beyond alignment width
1648 int alWidth = alignment.getWidth();
1649 List<SequenceGroup> groups = alignment.getGroups();
1652 for (SequenceGroup sg : groups)
1654 if (sg.getEndRes() > alWidth)
1656 sg.setEndRes(alWidth - 1);
1661 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1663 selectionGroup.setEndRes(alWidth - 1);
1666 resetAllColourSchemes();
1667 calculator.restartWorkers();
1668 // alignment.adjustSequenceAnnotations();
1672 * reset scope and do calculations for all applied colourschemes on alignment
1674 void resetAllColourSchemes()
1676 ColourSchemeI cs = globalColourScheme;
1679 cs.alignmentChanged(alignment, hiddenRepSequences);
1681 cs.setConsensus(hconsensus);
1682 if (cs.conservationApplied())
1684 cs.setConservation(Conservation.calculateConservation("All",
1685 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1686 alignment.getWidth(), false, getConsPercGaps(), false));
1690 for (SequenceGroup sg : alignment.getGroups())
1694 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1696 sg.recalcConservation();
1700 protected void initAutoAnnotation()
1702 // TODO: add menu option action that nulls or creates consensus object
1703 // depending on if the user wants to see the annotation or not in a
1704 // specific alignment
1706 if (hconsensus == null && !isDataset)
1708 if (!alignment.isNucleotide())
1717 consensus = new AlignmentAnnotation("Consensus", "PID",
1718 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1719 initConsensus(consensus);
1721 if (!alignment.isNucleotide())
1723 final Set<AlignedCodonFrame> codonMappings = alignment
1725 if (codonMappings != null && !codonMappings.isEmpty())
1727 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1728 "PID for cDNA", new Annotation[1], 0f, 100f,
1729 AlignmentAnnotation.BAR_GRAPH);
1730 initConsensus(complementConsensus);
1736 private void initConsensus(AlignmentAnnotation aa)
1739 aa.autoCalculated = true;
1743 alignment.addAnnotation(aa);
1747 private void initConservation()
1749 if (showConservation)
1751 if (conservation == null)
1753 conservation = new AlignmentAnnotation("Conservation",
1754 "Conservation of total alignment less than "
1755 + getConsPercGaps() + "% gaps", new Annotation[1],
1756 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1757 conservation.hasText = true;
1758 conservation.autoCalculated = true;
1759 alignment.addAnnotation(conservation);
1764 private void initQuality()
1768 if (quality == null)
1770 quality = new AlignmentAnnotation("Quality",
1771 "Alignment Quality based on Blosum62 scores",
1772 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1773 quality.hasText = true;
1774 quality.autoCalculated = true;
1775 alignment.addAnnotation(quality);
1780 private void initRNAStructure()
1782 if (alignment.hasRNAStructure() && strucConsensus == null)
1784 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1785 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1786 strucConsensus.hasText = true;
1787 strucConsensus.autoCalculated = true;
1791 alignment.addAnnotation(strucConsensus);
1799 * @see jalview.api.AlignViewportI#calcPanelHeight()
1802 public int calcPanelHeight()
1804 // setHeight of panels
1805 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
1807 int charHeight = getCharHeight();
1810 BitSet graphgrp = new BitSet();
1811 for (AlignmentAnnotation aa : anns)
1815 System.err.println("Null annotation row: ignoring.");
1822 if (aa.graphGroup > -1)
1824 if (graphgrp.get(aa.graphGroup))
1830 graphgrp.set(aa.graphGroup);
1837 aa.height += charHeight;
1847 aa.height += aa.graphHeight;
1855 height += aa.height;
1867 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1868 boolean preserveNewGroupSettings)
1870 boolean updateCalcs = false;
1871 boolean conv = isShowGroupConservation();
1872 boolean cons = isShowGroupConsensus();
1873 boolean showprf = isShowSequenceLogo();
1874 boolean showConsHist = isShowConsensusHistogram();
1875 boolean normLogo = isNormaliseSequenceLogo();
1878 * TODO reorder the annotation rows according to group/sequence ordering on
1881 boolean sortg = true;
1883 // remove old automatic annotation
1884 // add any new annotation
1886 // intersect alignment annotation with alignment groups
1888 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1889 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1892 for (int an = 0; an < aan.length; an++)
1894 if (aan[an].autoCalculated && aan[an].groupRef != null)
1896 oldrfs.add(aan[an].groupRef);
1897 alignment.deleteAnnotation(aan[an], false);
1901 if (alignment.getGroups() != null)
1903 for (SequenceGroup sg : alignment.getGroups())
1905 updateCalcs = false;
1906 if (applyGlobalSettings
1907 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1909 // set defaults for this group's conservation/consensus
1910 sg.setshowSequenceLogo(showprf);
1911 sg.setShowConsensusHistogram(showConsHist);
1912 sg.setNormaliseSequenceLogo(normLogo);
1917 alignment.addAnnotation(sg.getConservationRow(), 0);
1922 alignment.addAnnotation(sg.getConsensus(), 0);
1924 // refresh the annotation rows
1927 sg.recalcConservation();
1934 public boolean isDisplayReferenceSeq()
1936 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1940 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1942 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1946 public boolean isColourByReferenceSeq()
1948 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1952 public Color getSequenceColour(SequenceI seq)
1954 Color sqc = sequenceColours.get(seq);
1955 return (sqc == null ? Color.white : sqc);
1959 public void setSequenceColour(SequenceI seq, Color col)
1963 sequenceColours.remove(seq);
1967 sequenceColours.put(seq, col);
1972 public void updateSequenceIdColours()
1974 for (SequenceGroup sg : alignment.getGroups())
1976 if (sg.idColour != null)
1978 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1980 sequenceColours.put(s, sg.idColour);
1987 public void clearSequenceColours()
1989 sequenceColours.clear();
1993 public AlignViewportI getCodingComplement()
1995 return this.codingComplement;
1999 * Set this as the (cDna/protein) complement of the given viewport. Also
2000 * ensures the reverse relationship is set on the given viewport.
2003 public void setCodingComplement(AlignViewportI av)
2007 System.err.println("Ignoring recursive setCodingComplement request");
2011 this.codingComplement = av;
2012 // avoid infinite recursion!
2013 if (av.getCodingComplement() != this)
2015 av.setCodingComplement(this);
2021 public boolean isNucleotide()
2023 return getAlignment() == null ? false : getAlignment().isNucleotide();
2027 public FeaturesDisplayedI getFeaturesDisplayed()
2029 return featuresDisplayed;
2033 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2035 featuresDisplayed = featuresDisplayedI;
2039 public boolean areFeaturesDisplayed()
2041 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
2048 * features are displayed if true
2051 public void setShowSequenceFeatures(boolean b)
2053 viewStyle.setShowSequenceFeatures(b);
2056 public boolean isShowSequenceFeatures()
2058 return viewStyle.isShowSequenceFeatures();
2062 public void setShowSequenceFeaturesHeight(boolean selected)
2064 viewStyle.setShowSeqFeaturesHeight(selected);
2068 public boolean isShowSequenceFeaturesHeight()
2070 return viewStyle.isShowSequenceFeaturesHeight();
2076 public void setShowAnnotation(boolean b)
2078 viewStyle.setShowAnnotation(b);
2082 public boolean isShowAnnotation()
2084 return viewStyle.isShowAnnotation();
2088 public boolean isRightAlignIds()
2090 return viewStyle.isRightAlignIds();
2094 public void setRightAlignIds(boolean rightAlignIds)
2096 viewStyle.setRightAlignIds(rightAlignIds);
2100 public boolean getConservationSelected()
2102 return viewStyle.getConservationSelected();
2106 public void setShowBoxes(boolean state)
2108 viewStyle.setShowBoxes(state);
2113 * @see jalview.api.ViewStyleI#getTextColour()
2115 public Color getTextColour()
2117 return viewStyle.getTextColour();
2122 * @see jalview.api.ViewStyleI#getTextColour2()
2124 public Color getTextColour2()
2126 return viewStyle.getTextColour2();
2131 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2133 public int getThresholdTextColour()
2135 return viewStyle.getThresholdTextColour();
2140 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2142 public boolean isConservationColourSelected()
2144 return viewStyle.isConservationColourSelected();
2149 * @see jalview.api.ViewStyleI#isRenderGaps()
2151 public boolean isRenderGaps()
2153 return viewStyle.isRenderGaps();
2158 * @see jalview.api.ViewStyleI#isShowColourText()
2160 public boolean isShowColourText()
2162 return viewStyle.isShowColourText();
2166 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2168 public boolean isShowSeqFeaturesHeight()
2170 return viewStyle.isShowSeqFeaturesHeight();
2174 * @param conservationColourSelected
2175 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2177 public void setConservationColourSelected(
2178 boolean conservationColourSelected)
2180 viewStyle.setConservationColourSelected(conservationColourSelected);
2184 * @param showColourText
2185 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2187 public void setShowColourText(boolean showColourText)
2189 viewStyle.setShowColourText(showColourText);
2194 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2196 public void setTextColour(Color textColour)
2198 viewStyle.setTextColour(textColour);
2202 * @param thresholdTextColour
2203 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2205 public void setThresholdTextColour(int thresholdTextColour)
2207 viewStyle.setThresholdTextColour(thresholdTextColour);
2211 * @param textColour2
2212 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2214 public void setTextColour2(Color textColour2)
2216 viewStyle.setTextColour2(textColour2);
2220 public ViewStyleI getViewStyle()
2222 return new ViewStyle(viewStyle);
2226 public void setViewStyle(ViewStyleI settingsForView)
2228 viewStyle = new ViewStyle(settingsForView);
2232 public boolean sameStyle(ViewStyleI them)
2234 return viewStyle.sameStyle(them);
2239 * @see jalview.api.ViewStyleI#getIdWidth()
2241 public int getIdWidth()
2243 return viewStyle.getIdWidth();
2248 * @see jalview.api.ViewStyleI#setIdWidth(int)
2250 public void setIdWidth(int i)
2252 viewStyle.setIdWidth(i);
2257 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2259 public boolean isCentreColumnLabels()
2261 return viewStyle.isCentreColumnLabels();
2265 * @param centreColumnLabels
2266 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2268 public void setCentreColumnLabels(boolean centreColumnLabels)
2270 viewStyle.setCentreColumnLabels(centreColumnLabels);
2275 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2277 public void setShowDBRefs(boolean showdbrefs)
2279 viewStyle.setShowDBRefs(showdbrefs);
2284 * @see jalview.api.ViewStyleI#isShowDBRefs()
2286 public boolean isShowDBRefs()
2288 return viewStyle.isShowDBRefs();
2293 * @see jalview.api.ViewStyleI#isShowNPFeats()
2295 public boolean isShowNPFeats()
2297 return viewStyle.isShowNPFeats();
2301 * @param shownpfeats
2302 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2304 public void setShowNPFeats(boolean shownpfeats)
2306 viewStyle.setShowNPFeats(shownpfeats);
2309 public abstract StructureSelectionManager getStructureSelectionManager();
2312 * Add one command to the command history list.
2316 public void addToHistoryList(CommandI command)
2318 if (this.historyList != null)
2320 this.historyList.push(command);
2321 broadcastCommand(command, false);
2325 protected void broadcastCommand(CommandI command, boolean undo)
2327 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
2331 * Add one command to the command redo list.
2335 public void addToRedoList(CommandI command)
2337 if (this.redoList != null)
2339 this.redoList.push(command);
2341 broadcastCommand(command, true);
2345 * Clear the command redo list.
2347 public void clearRedoList()
2349 if (this.redoList != null)
2351 this.redoList.clear();
2355 public void setHistoryList(Deque<CommandI> list)
2357 this.historyList = list;
2360 public Deque<CommandI> getHistoryList()
2362 return this.historyList;
2365 public void setRedoList(Deque<CommandI> list)
2367 this.redoList = list;
2370 public Deque<CommandI> getRedoList()
2372 return this.redoList;
2376 public VamsasSource getVamsasSource()