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 initComplementConsensus();
1726 * If this is a protein alignment and there are mappings to cDNA, add the cDNA
1727 * consensus annotation.
1729 protected void initComplementConsensus()
1731 if (!alignment.isNucleotide())
1733 final Set<AlignedCodonFrame> codonMappings = alignment
1735 if (codonMappings != null && !codonMappings.isEmpty())
1737 complementConsensus = new AlignmentAnnotation("cDNA Consensus",
1738 "PID for cDNA", new Annotation[1], 0f, 100f,
1739 AlignmentAnnotation.BAR_GRAPH);
1740 initConsensus(complementConsensus);
1745 private void initConsensus(AlignmentAnnotation aa)
1748 aa.autoCalculated = true;
1752 alignment.addAnnotation(aa);
1756 private void initConservation()
1758 if (showConservation)
1760 if (conservation == null)
1762 conservation = new AlignmentAnnotation("Conservation",
1763 "Conservation of total alignment less than "
1764 + getConsPercGaps() + "% gaps", new Annotation[1],
1765 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1766 conservation.hasText = true;
1767 conservation.autoCalculated = true;
1768 alignment.addAnnotation(conservation);
1773 private void initQuality()
1777 if (quality == null)
1779 quality = new AlignmentAnnotation("Quality",
1780 "Alignment Quality based on Blosum62 scores",
1781 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1782 quality.hasText = true;
1783 quality.autoCalculated = true;
1784 alignment.addAnnotation(quality);
1789 private void initRNAStructure()
1791 if (alignment.hasRNAStructure() && strucConsensus == null)
1793 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1794 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1795 strucConsensus.hasText = true;
1796 strucConsensus.autoCalculated = true;
1800 alignment.addAnnotation(strucConsensus);
1808 * @see jalview.api.AlignViewportI#calcPanelHeight()
1811 public int calcPanelHeight()
1813 // setHeight of panels
1814 AlignmentAnnotation[] anns = getAlignment().getAlignmentAnnotation();
1816 int charHeight = getCharHeight();
1819 BitSet graphgrp = new BitSet();
1820 for (AlignmentAnnotation aa : anns)
1824 System.err.println("Null annotation row: ignoring.");
1831 if (aa.graphGroup > -1)
1833 if (graphgrp.get(aa.graphGroup))
1839 graphgrp.set(aa.graphGroup);
1846 aa.height += charHeight;
1856 aa.height += aa.graphHeight;
1864 height += aa.height;
1876 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1877 boolean preserveNewGroupSettings)
1879 boolean updateCalcs = false;
1880 boolean conv = isShowGroupConservation();
1881 boolean cons = isShowGroupConsensus();
1882 boolean showprf = isShowSequenceLogo();
1883 boolean showConsHist = isShowConsensusHistogram();
1884 boolean normLogo = isNormaliseSequenceLogo();
1887 * TODO reorder the annotation rows according to group/sequence ordering on
1890 boolean sortg = true;
1892 // remove old automatic annotation
1893 // add any new annotation
1895 // intersect alignment annotation with alignment groups
1897 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1898 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1901 for (int an = 0; an < aan.length; an++)
1903 if (aan[an].autoCalculated && aan[an].groupRef != null)
1905 oldrfs.add(aan[an].groupRef);
1906 alignment.deleteAnnotation(aan[an], false);
1910 if (alignment.getGroups() != null)
1912 for (SequenceGroup sg : alignment.getGroups())
1914 updateCalcs = false;
1915 if (applyGlobalSettings
1916 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1918 // set defaults for this group's conservation/consensus
1919 sg.setshowSequenceLogo(showprf);
1920 sg.setShowConsensusHistogram(showConsHist);
1921 sg.setNormaliseSequenceLogo(normLogo);
1926 alignment.addAnnotation(sg.getConservationRow(), 0);
1931 alignment.addAnnotation(sg.getConsensus(), 0);
1933 // refresh the annotation rows
1936 sg.recalcConservation();
1943 public boolean isDisplayReferenceSeq()
1945 return alignment.hasSeqrep() && viewStyle.isDisplayReferenceSeq();
1949 public void setDisplayReferenceSeq(boolean displayReferenceSeq)
1951 viewStyle.setDisplayReferenceSeq(displayReferenceSeq);
1955 public boolean isColourByReferenceSeq()
1957 return alignment.hasSeqrep() && viewStyle.isColourByReferenceSeq();
1961 public Color getSequenceColour(SequenceI seq)
1963 Color sqc = sequenceColours.get(seq);
1964 return (sqc == null ? Color.white : sqc);
1968 public void setSequenceColour(SequenceI seq, Color col)
1972 sequenceColours.remove(seq);
1976 sequenceColours.put(seq, col);
1981 public void updateSequenceIdColours()
1983 for (SequenceGroup sg : alignment.getGroups())
1985 if (sg.idColour != null)
1987 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1989 sequenceColours.put(s, sg.idColour);
1996 public void clearSequenceColours()
1998 sequenceColours.clear();
2002 public AlignViewportI getCodingComplement()
2004 return this.codingComplement;
2008 * Set this as the (cDna/protein) complement of the given viewport. Also
2009 * ensures the reverse relationship is set on the given viewport.
2012 public void setCodingComplement(AlignViewportI av)
2016 System.err.println("Ignoring recursive setCodingComplement request");
2020 this.codingComplement = av;
2021 // avoid infinite recursion!
2022 if (av.getCodingComplement() != this)
2024 av.setCodingComplement(this);
2030 public boolean isNucleotide()
2032 return getAlignment() == null ? false : getAlignment().isNucleotide();
2036 public FeaturesDisplayedI getFeaturesDisplayed()
2038 return featuresDisplayed;
2042 public void setFeaturesDisplayed(FeaturesDisplayedI featuresDisplayedI)
2044 featuresDisplayed = featuresDisplayedI;
2048 public boolean areFeaturesDisplayed()
2050 return featuresDisplayed != null && featuresDisplayed.getRegisterdFeaturesCount()>0;
2057 * features are displayed if true
2060 public void setShowSequenceFeatures(boolean b)
2062 viewStyle.setShowSequenceFeatures(b);
2065 public boolean isShowSequenceFeatures()
2067 return viewStyle.isShowSequenceFeatures();
2071 public void setShowSequenceFeaturesHeight(boolean selected)
2073 viewStyle.setShowSeqFeaturesHeight(selected);
2077 public boolean isShowSequenceFeaturesHeight()
2079 return viewStyle.isShowSequenceFeaturesHeight();
2085 public void setShowAnnotation(boolean b)
2087 viewStyle.setShowAnnotation(b);
2091 public boolean isShowAnnotation()
2093 return viewStyle.isShowAnnotation();
2097 public boolean isRightAlignIds()
2099 return viewStyle.isRightAlignIds();
2103 public void setRightAlignIds(boolean rightAlignIds)
2105 viewStyle.setRightAlignIds(rightAlignIds);
2109 public boolean getConservationSelected()
2111 return viewStyle.getConservationSelected();
2115 public void setShowBoxes(boolean state)
2117 viewStyle.setShowBoxes(state);
2122 * @see jalview.api.ViewStyleI#getTextColour()
2124 public Color getTextColour()
2126 return viewStyle.getTextColour();
2131 * @see jalview.api.ViewStyleI#getTextColour2()
2133 public Color getTextColour2()
2135 return viewStyle.getTextColour2();
2140 * @see jalview.api.ViewStyleI#getThresholdTextColour()
2142 public int getThresholdTextColour()
2144 return viewStyle.getThresholdTextColour();
2149 * @see jalview.api.ViewStyleI#isConservationColourSelected()
2151 public boolean isConservationColourSelected()
2153 return viewStyle.isConservationColourSelected();
2158 * @see jalview.api.ViewStyleI#isRenderGaps()
2160 public boolean isRenderGaps()
2162 return viewStyle.isRenderGaps();
2167 * @see jalview.api.ViewStyleI#isShowColourText()
2169 public boolean isShowColourText()
2171 return viewStyle.isShowColourText();
2175 * @see jalview.api.ViewStyleI#isShowSeqFeaturesHeight()
2177 public boolean isShowSeqFeaturesHeight()
2179 return viewStyle.isShowSeqFeaturesHeight();
2183 * @param conservationColourSelected
2184 * @see jalview.api.ViewStyleI#setConservationColourSelected(boolean)
2186 public void setConservationColourSelected(
2187 boolean conservationColourSelected)
2189 viewStyle.setConservationColourSelected(conservationColourSelected);
2193 * @param showColourText
2194 * @see jalview.api.ViewStyleI#setShowColourText(boolean)
2196 public void setShowColourText(boolean showColourText)
2198 viewStyle.setShowColourText(showColourText);
2203 * @see jalview.api.ViewStyleI#setTextColour(java.awt.Color)
2205 public void setTextColour(Color textColour)
2207 viewStyle.setTextColour(textColour);
2211 * @param thresholdTextColour
2212 * @see jalview.api.ViewStyleI#setThresholdTextColour(int)
2214 public void setThresholdTextColour(int thresholdTextColour)
2216 viewStyle.setThresholdTextColour(thresholdTextColour);
2220 * @param textColour2
2221 * @see jalview.api.ViewStyleI#setTextColour2(java.awt.Color)
2223 public void setTextColour2(Color textColour2)
2225 viewStyle.setTextColour2(textColour2);
2229 public ViewStyleI getViewStyle()
2231 return new ViewStyle(viewStyle);
2235 public void setViewStyle(ViewStyleI settingsForView)
2237 viewStyle = new ViewStyle(settingsForView);
2241 public boolean sameStyle(ViewStyleI them)
2243 return viewStyle.sameStyle(them);
2248 * @see jalview.api.ViewStyleI#getIdWidth()
2250 public int getIdWidth()
2252 return viewStyle.getIdWidth();
2257 * @see jalview.api.ViewStyleI#setIdWidth(int)
2259 public void setIdWidth(int i)
2261 viewStyle.setIdWidth(i);
2266 * @see jalview.api.ViewStyleI#isCentreColumnLabels()
2268 public boolean isCentreColumnLabels()
2270 return viewStyle.isCentreColumnLabels();
2274 * @param centreColumnLabels
2275 * @see jalview.api.ViewStyleI#setCentreColumnLabels(boolean)
2277 public void setCentreColumnLabels(boolean centreColumnLabels)
2279 viewStyle.setCentreColumnLabels(centreColumnLabels);
2284 * @see jalview.api.ViewStyleI#setShowDBRefs(boolean)
2286 public void setShowDBRefs(boolean showdbrefs)
2288 viewStyle.setShowDBRefs(showdbrefs);
2293 * @see jalview.api.ViewStyleI#isShowDBRefs()
2295 public boolean isShowDBRefs()
2297 return viewStyle.isShowDBRefs();
2302 * @see jalview.api.ViewStyleI#isShowNPFeats()
2304 public boolean isShowNPFeats()
2306 return viewStyle.isShowNPFeats();
2310 * @param shownpfeats
2311 * @see jalview.api.ViewStyleI#setShowNPFeats(boolean)
2313 public void setShowNPFeats(boolean shownpfeats)
2315 viewStyle.setShowNPFeats(shownpfeats);
2318 public abstract StructureSelectionManager getStructureSelectionManager();
2321 * Add one command to the command history list.
2325 public void addToHistoryList(CommandI command)
2327 if (this.historyList != null)
2329 this.historyList.push(command);
2330 broadcastCommand(command, false);
2334 protected void broadcastCommand(CommandI command, boolean undo)
2336 getStructureSelectionManager().commandPerformed(command, undo, getVamsasSource());
2340 * Add one command to the command redo list.
2344 public void addToRedoList(CommandI command)
2346 if (this.redoList != null)
2348 this.redoList.push(command);
2350 broadcastCommand(command, true);
2354 * Clear the command redo list.
2356 public void clearRedoList()
2358 if (this.redoList != null)
2360 this.redoList.clear();
2364 public void setHistoryList(Deque<CommandI> list)
2366 this.historyList = list;
2369 public Deque<CommandI> getHistoryList()
2371 return this.historyList;
2374 public void setRedoList(Deque<CommandI> list)
2376 this.redoList = list;
2379 public Deque<CommandI> getRedoList()
2381 return this.redoList;
2385 public VamsasSource getVamsasSource()