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.datamodel.AlignmentAnnotation;
28 import jalview.datamodel.AlignmentI;
29 import jalview.datamodel.AlignmentView;
30 import jalview.datamodel.Annotation;
31 import jalview.datamodel.ColumnSelection;
32 import jalview.datamodel.Sequence;
33 import jalview.datamodel.SequenceCollectionI;
34 import jalview.datamodel.SequenceGroup;
35 import jalview.datamodel.SequenceI;
36 import jalview.schemes.Blosum62ColourScheme;
37 import jalview.schemes.ColourSchemeI;
38 import jalview.schemes.PIDColourScheme;
39 import jalview.schemes.ResidueProperties;
40 import jalview.util.MappingUtils;
41 import jalview.workers.AlignCalcManager;
42 import jalview.workers.ConsensusThread;
43 import jalview.workers.StrucConsensusThread;
45 import java.awt.Color;
46 import java.util.ArrayList;
47 import java.util.BitSet;
48 import java.util.HashMap;
49 import java.util.Hashtable;
50 import java.util.List;
52 import java.util.Vector;
55 * base class holding visualization and analysis attributes and common logic for
56 * an active alignment view displayed in the GUI
61 public abstract class AlignmentViewport implements AlignViewportI
64 * A viewport that hosts the cDna view of this (protein), or vice versa (if
67 AlignViewportI codingComplement = null;
70 * alignment displayed in the viewport. Please use get/setter
72 protected AlignmentI alignment;
74 protected String sequenceSetID;
77 * probably unused indicator that view is of a dataset rather than an
80 protected boolean isDataset = false;
82 private Map<SequenceI, SequenceCollectionI> hiddenRepSequences;
84 protected ColumnSelection colSel = new ColumnSelection();
86 public boolean autoCalculateConsensus = true;
88 protected boolean autoCalculateStrucConsensus = true;
90 protected boolean ignoreGapsInConsensusCalculation = false;
92 protected ColourSchemeI globalColourScheme = null;
95 * gui state - changes to colour scheme propagated to all groups
97 private boolean colourAppliesToAllGroups;
101 * indicating if subsequent colourscheme changes will be propagated
104 public void setColourAppliesToAllGroups(boolean b)
106 colourAppliesToAllGroups = b;
112 * @return flag indicating if colourchanges propagated to all groups
114 public boolean getColourAppliesToAllGroups()
116 return colourAppliesToAllGroups;
119 boolean abovePIDThreshold = false;
124 * @return true if percent identity threshold is applied to shading
126 public boolean getAbovePIDThreshold()
128 return abovePIDThreshold;
136 * indicate if percent identity threshold is applied to shading
138 public void setAbovePIDThreshold(boolean b)
140 abovePIDThreshold = b;
151 public void setThreshold(int thresh)
159 * @return DOCUMENT ME!
161 public int getThreshold()
171 * set the scalar for bleaching colourschemes according to degree of
174 public void setIncrement(int inc)
182 * @return get scalar for bleaching colourschemes by conservation
184 public int getIncrement()
189 boolean conservationColourSelected = false;
194 * @return true if conservation based shading is enabled
196 public boolean getConservationSelected()
198 return conservationColourSelected;
205 * enable conservation based shading
207 public void setConservationSelected(boolean b)
209 conservationColourSelected = b;
213 public void setGlobalColourScheme(ColourSchemeI cs)
215 // TODO: logic refactored from AlignFrame changeColour -
216 // autorecalc stuff should be changed to rely on the worker system
217 // check to see if we should implement a changeColour(cs) method rather than
218 // put th logic in here
219 // - means that caller decides if they want to just modify state and defer
220 // calculation till later or to do all calculations in thread.
222 globalColourScheme = cs;
223 boolean recalc = false;
226 cs.setConservationApplied(recalc = getConservationSelected());
227 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
228 || cs instanceof Blosum62ColourScheme)
231 cs.setThreshold(threshold, ignoreGapsInConsensusCalculation);
235 cs.setThreshold(0, ignoreGapsInConsensusCalculation);
239 cs.setConsensus(hconsensus);
240 cs.setConservation(hconservation);
242 cs.alignmentChanged(alignment, hiddenRepSequences);
244 if (getColourAppliesToAllGroups())
246 for (SequenceGroup sg : getAlignment().getGroups())
253 sg.cs = cs.applyTo(sg, getHiddenRepSequences());
254 sg.setConsPercGaps(ConsPercGaps);
255 if (getAbovePIDThreshold() || cs instanceof PIDColourScheme
256 || cs instanceof Blosum62ColourScheme)
258 sg.cs.setThreshold(threshold, getIgnoreGapsConsensus());
263 sg.cs.setThreshold(0, getIgnoreGapsConsensus());
266 if (getConservationSelected())
268 sg.cs.setConservationApplied(true);
273 sg.cs.setConservation(null);
274 // sg.cs.setThreshold(0, getIgnoreGapsConsensus());
278 sg.recalcConservation();
282 sg.cs.alignmentChanged(sg, hiddenRepSequences);
290 public ColourSchemeI getGlobalColourScheme()
292 return globalColourScheme;
295 protected AlignmentAnnotation consensus;
297 protected AlignmentAnnotation strucConsensus;
299 protected AlignmentAnnotation conservation;
301 protected AlignmentAnnotation quality;
303 protected AlignmentAnnotation[] groupConsensus;
305 protected AlignmentAnnotation[] groupConservation;
308 * results of alignment consensus analysis for visible portion of view
310 protected Hashtable[] hconsensus = null;
313 * results of secondary structure base pair consensus for visible portion of
316 protected Hashtable[] hStrucConsensus = null;
318 protected Conservation hconservation = null;
321 public void setConservation(Conservation cons)
323 hconservation = cons;
327 * percentage gaps allowed in a column before all amino acid properties should
328 * be considered unconserved
330 int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
333 public int getConsPercGaps()
339 public void setSequenceConsensusHash(Hashtable[] hconsensus)
341 this.hconsensus = hconsensus;
346 public Hashtable[] getSequenceConsensusHash()
352 public Hashtable[] getRnaStructureConsensusHash()
354 return hStrucConsensus;
358 public void setRnaStructureConsensusHash(Hashtable[] hStrucConsensus)
360 this.hStrucConsensus = hStrucConsensus;
365 public AlignmentAnnotation getAlignmentQualityAnnot()
371 public AlignmentAnnotation getAlignmentConservationAnnotation()
377 public AlignmentAnnotation getAlignmentConsensusAnnotation()
383 public AlignmentAnnotation getAlignmentStrucConsensusAnnotation()
385 return strucConsensus;
388 protected AlignCalcManagerI calculator = new AlignCalcManager();
391 * trigger update of conservation annotation
393 public void updateConservation(final AlignmentViewPanel ap)
395 // see note in mantis : issue number 8585
396 if (alignment.isNucleotide() || conservation == null
397 || !autoCalculateConsensus)
402 .getRegisteredWorkersOfClass(jalview.workers.ConservationThread.class) == null)
404 calculator.registerWorker(new jalview.workers.ConservationThread(
410 * trigger update of consensus annotation
412 public void updateConsensus(final AlignmentViewPanel ap)
414 // see note in mantis : issue number 8585
415 if (consensus == null || !autoCalculateConsensus)
419 if (calculator.getRegisteredWorkersOfClass(ConsensusThread.class) == null)
421 calculator.registerWorker(new ConsensusThread(this, ap));
425 // --------START Structure Conservation
426 public void updateStrucConsensus(final AlignmentViewPanel ap)
428 if (autoCalculateStrucConsensus && strucConsensus == null
429 && alignment.isNucleotide() && alignment.hasRNAStructure())
431 // secondary structure has been added - so init the consensus line
435 // see note in mantis : issue number 8585
436 if (strucConsensus == null || !autoCalculateStrucConsensus)
440 if (calculator.getRegisteredWorkersOfClass(StrucConsensusThread.class) == null)
442 calculator.registerWorker(new StrucConsensusThread(this, ap));
446 public boolean isCalcInProgress()
448 return calculator.isWorking();
452 public boolean isCalculationInProgress(
453 AlignmentAnnotation alignmentAnnotation)
455 if (!alignmentAnnotation.autoCalculated)
459 if (calculator.workingInvolvedWith(alignmentAnnotation))
461 // System.err.println("grey out ("+alignmentAnnotation.label+")");
468 public boolean isClosed()
470 // TODO: check that this isClosed is only true after panel is closed, not
471 // before it is fully constructed.
472 return alignment == null;
476 public AlignCalcManagerI getCalcManager()
482 * should conservation rows be shown for groups
484 protected boolean showGroupConservation = false;
487 * should consensus rows be shown for groups
489 protected boolean showGroupConsensus = false;
492 * should consensus profile be rendered by default
494 protected boolean showSequenceLogo = false;
497 * should consensus profile be rendered normalised to row height
499 protected boolean normaliseSequenceLogo = false;
502 * should consensus histograms be rendered by default
504 protected boolean showConsensusHistogram = true;
507 * @return the showConsensusProfile
510 public boolean isShowSequenceLogo()
512 return showSequenceLogo;
516 * @param showSequenceLogo
519 public void setShowSequenceLogo(boolean showSequenceLogo)
521 if (showSequenceLogo != this.showSequenceLogo)
523 // TODO: decouple settings setting from calculation when refactoring
524 // annotation update method from alignframe to viewport
525 this.showSequenceLogo = showSequenceLogo;
526 calculator.updateAnnotationFor(ConsensusThread.class);
527 calculator.updateAnnotationFor(StrucConsensusThread.class);
529 this.showSequenceLogo = showSequenceLogo;
533 * @param showConsensusHistogram
534 * the showConsensusHistogram to set
536 public void setShowConsensusHistogram(boolean showConsensusHistogram)
538 this.showConsensusHistogram = showConsensusHistogram;
542 * @return the showGroupConservation
544 public boolean isShowGroupConservation()
546 return showGroupConservation;
550 * @param showGroupConservation
551 * the showGroupConservation to set
553 public void setShowGroupConservation(boolean showGroupConservation)
555 this.showGroupConservation = showGroupConservation;
559 * @return the showGroupConsensus
561 public boolean isShowGroupConsensus()
563 return showGroupConsensus;
567 * @param showGroupConsensus
568 * the showGroupConsensus to set
570 public void setShowGroupConsensus(boolean showGroupConsensus)
572 this.showGroupConsensus = showGroupConsensus;
577 * @return flag to indicate if the consensus histogram should be rendered by
581 public boolean isShowConsensusHistogram()
583 return this.showConsensusHistogram;
587 * show non-conserved residues only
589 protected boolean showUnconserved = false;
592 * when set, updateAlignment will always ensure sequences are of equal length
594 private boolean padGaps = false;
597 * when set, alignment should be reordered according to a newly opened tree
599 public boolean sortByTree = false;
601 public boolean getShowUnconserved()
603 return showUnconserved;
606 public void setShowUnconserved(boolean showunconserved)
608 showUnconserved = showunconserved;
612 * @param showNonconserved
613 * the showUnconserved to set
615 public void setShowunconserved(boolean displayNonconserved)
617 this.showUnconserved = displayNonconserved;
623 * @return null or the currently selected sequence region
626 public SequenceGroup getSelectionGroup()
628 return selectionGroup;
632 * Set the selection group for this window.
635 * - group holding references to sequences in this alignment view
639 public void setSelectionGroup(SequenceGroup sg)
644 public void setHiddenColumns(ColumnSelection colsel)
646 this.colSel = colsel;
647 if (colSel.getHiddenColumns() != null)
649 hasHiddenColumns = true;
654 public ColumnSelection getColumnSelection()
659 public void setColumnSelection(ColumnSelection colSel)
661 this.colSel = colSel;
669 public Map<SequenceI, SequenceCollectionI> getHiddenRepSequences()
671 return hiddenRepSequences;
675 public void setHiddenRepSequences(
676 Map<SequenceI, SequenceCollectionI> hiddenRepSequences)
678 this.hiddenRepSequences = hiddenRepSequences;
681 protected boolean hasHiddenColumns = false;
683 public void updateHiddenColumns()
685 hasHiddenColumns = colSel.getHiddenColumns() != null;
688 protected boolean hasHiddenRows = false;
690 public boolean hasHiddenRows()
692 return hasHiddenRows;
695 protected SequenceGroup selectionGroup;
697 public void setSequenceSetId(String newid)
699 if (sequenceSetID != null)
702 .println("Warning - overwriting a sequenceSetId for a viewport!");
704 sequenceSetID = new String(newid);
707 public String getSequenceSetId()
709 if (sequenceSetID == null)
711 sequenceSetID = alignment.hashCode() + "";
714 return sequenceSetID;
718 * unique viewId for synchronizing state (e.g. with stored Jalview Project)
721 protected String viewId = null;
723 public String getViewId()
727 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
732 public void setIgnoreGapsConsensus(boolean b, AlignmentViewPanel ap)
734 ignoreGapsInConsensusCalculation = b;
738 if (globalColourScheme != null)
740 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
741 ignoreGapsInConsensusCalculation);
747 private long sgrouphash = -1, colselhash = -1;
750 * checks current SelectionGroup against record of last hash value, and
754 * update the record of last hash value
756 * @return true if SelectionGroup changed since last call (when b is true)
758 public boolean isSelectionGroupChanged(boolean b)
760 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
761 : selectionGroup.hashCode();
762 if (hc != -1 && hc != sgrouphash)
774 * checks current colsel against record of last hash value, and optionally
778 * update the record of last hash value
779 * @return true if colsel changed since last call (when b is true)
781 public boolean isColSelChanged(boolean b)
783 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
785 if (hc != -1 && hc != colselhash)
797 public boolean getIgnoreGapsConsensus()
799 return ignoreGapsInConsensusCalculation;
802 // / property change stuff
804 // JBPNote Prolly only need this in the applet version.
805 private final java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
808 protected boolean showConservation = true;
810 protected boolean showQuality = true;
812 protected boolean showConsensus = true;
814 private Map<SequenceI, Color> sequenceColours = new HashMap<SequenceI, Color>();
817 * Property change listener for changes in alignment
822 public void addPropertyChangeListener(
823 java.beans.PropertyChangeListener listener)
825 changeSupport.addPropertyChangeListener(listener);
834 public void removePropertyChangeListener(
835 java.beans.PropertyChangeListener listener)
837 changeSupport.removePropertyChangeListener(listener);
841 * Property change listener for changes in alignment
850 public void firePropertyChange(String prop, Object oldvalue,
853 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
856 // common hide/show column stuff
858 public void hideSelectedColumns()
860 if (colSel.size() < 1)
865 colSel.hideSelectedColumns();
866 setSelectionGroup(null);
868 hasHiddenColumns = true;
871 public void hideColumns(int start, int end)
875 colSel.hideColumns(start);
879 colSel.hideColumns(start, end);
882 hasHiddenColumns = true;
885 public void showColumn(int col)
887 colSel.revealHiddenColumns(col);
888 if (colSel.getHiddenColumns() == null)
890 hasHiddenColumns = false;
894 public void showAllHiddenColumns()
896 colSel.revealAllHiddenColumns();
897 hasHiddenColumns = false;
900 // common hide/show seq stuff
901 public void showAllHiddenSeqs()
903 if (alignment.getHiddenSequences().getSize() > 0)
905 if (selectionGroup == null)
907 selectionGroup = new SequenceGroup();
908 selectionGroup.setEndRes(alignment.getWidth() - 1);
910 List<SequenceI> tmp = alignment.getHiddenSequences().showAll(
912 for (SequenceI seq : tmp)
914 selectionGroup.addSequence(seq, false);
915 setSequenceAnnotationsVisible(seq, true);
918 hasHiddenRows = false;
919 hiddenRepSequences = null;
921 firePropertyChange("alignment", null, alignment.getSequences());
922 // used to set hasHiddenRows/hiddenRepSequences here, after the property
928 public void showSequence(int index)
930 List<SequenceI> tmp = alignment.getHiddenSequences().showSequence(
935 if (selectionGroup == null)
937 selectionGroup = new SequenceGroup();
938 selectionGroup.setEndRes(alignment.getWidth() - 1);
941 for (SequenceI seq : tmp)
943 selectionGroup.addSequence(seq, false);
944 setSequenceAnnotationsVisible(seq, true);
946 // JBPNote: refactor: only update flag if we modified visiblity (used to
947 // do this regardless)
948 if (alignment.getHiddenSequences().getSize() < 1)
950 hasHiddenRows = false;
952 firePropertyChange("alignment", null, alignment.getSequences());
957 public void hideAllSelectedSeqs()
959 if (selectionGroup == null || selectionGroup.getSize() < 1)
964 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
968 AlignViewportI peer = getCodingComplement();
971 SequenceGroup mappedGroup = MappingUtils.mapSequenceGroup(
972 selectionGroup, this, peer);
973 ((AlignmentViewport) peer).hideSequence(mappedGroup
974 .getSequencesInOrder(peer.getAlignment()));
975 peer.setSelectionGroup(null);
979 setSelectionGroup(null);
982 public void hideSequence(SequenceI[] seq)
986 for (int i = 0; i < seq.length; i++)
988 alignment.getHiddenSequences().hideSequence(seq[i]);
989 setSequenceAnnotationsVisible(seq[i], false);
991 hasHiddenRows = true;
992 firePropertyChange("alignment", null, alignment.getSequences());
997 * Set visibility for any annotations for the given sequence.
1001 protected void setSequenceAnnotationsVisible(SequenceI sequenceI,
1004 for (AlignmentAnnotation ann : alignment.getAlignmentAnnotation())
1006 if (ann.sequenceRef == sequenceI)
1008 ann.visible = visible;
1013 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1015 int sSize = sg.getSize();
1021 if (hiddenRepSequences == null)
1023 hiddenRepSequences = new Hashtable();
1026 hiddenRepSequences.put(repSequence, sg);
1028 // Hide all sequences except the repSequence
1029 SequenceI[] seqs = new SequenceI[sSize - 1];
1031 for (int i = 0; i < sSize; i++)
1033 if (sg.getSequenceAt(i) != repSequence)
1035 if (index == sSize - 1)
1040 seqs[index++] = sg.getSequenceAt(i);
1043 sg.setSeqrep(repSequence); // note: not done in 2.7applet
1044 sg.setHidereps(true); // note: not done in 2.7applet
1049 public boolean isHiddenRepSequence(SequenceI seq)
1051 return hiddenRepSequences != null
1052 && hiddenRepSequences.containsKey(seq);
1055 public SequenceGroup getRepresentedSequences(SequenceI seq)
1057 return (SequenceGroup) (hiddenRepSequences == null ? null
1058 : hiddenRepSequences.get(seq));
1061 public int adjustForHiddenSeqs(int alignmentIndex)
1063 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1067 // Selection manipulation
1069 * broadcast selection to any interested parties
1071 public abstract void sendSelection();
1073 public void invertColumnSelection()
1075 colSel.invertColumnSelection(0, alignment.getWidth());
1079 * This method returns an array of new SequenceI objects derived from the
1080 * whole alignment or just the current selection with start and end points
1083 * @note if you need references to the actual SequenceI objects in the
1084 * alignment or currently selected then use getSequenceSelection()
1085 * @return selection as new sequenceI objects
1087 public SequenceI[] getSelectionAsNewSequence()
1089 SequenceI[] sequences;
1090 // JBPNote: Need to test jalviewLite.getSelectedSequencesAsAlignmentFrom -
1091 // this was the only caller in the applet for this method
1092 // JBPNote: in applet, this method returned references to the alignment
1093 // sequences, and it did not honour the presence/absence of annotation
1094 // attached to the alignment (probably!)
1095 if (selectionGroup == null || selectionGroup.getSize() == 0)
1097 sequences = alignment.getSequencesArray();
1098 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1099 for (int i = 0; i < sequences.length; i++)
1101 sequences[i] = new Sequence(sequences[i], annots); // construct new
1103 // subset of visible
1109 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1116 * get the currently selected sequence objects or all the sequences in the
1119 * @return array of references to sequence objects
1122 public SequenceI[] getSequenceSelection()
1124 SequenceI[] sequences = null;
1125 if (selectionGroup != null)
1127 sequences = selectionGroup.getSequencesInOrder(alignment);
1129 if (sequences == null)
1131 sequences = alignment.getSequencesArray();
1137 * This method returns the visible alignment as text, as seen on the GUI, ie
1138 * if columns are hidden they will not be returned in the result. Use this for
1139 * calculating trees, PCA, redundancy etc on views which contain hidden
1145 public jalview.datamodel.CigarArray getViewAsCigars(
1146 boolean selectedRegionOnly)
1148 return new jalview.datamodel.CigarArray(alignment,
1149 (hasHiddenColumns ? colSel : null),
1150 (selectedRegionOnly ? selectionGroup : null));
1154 * return a compact representation of the current alignment selection to pass
1155 * to an analysis function
1157 * @param selectedOnly
1158 * boolean true to just return the selected view
1159 * @return AlignmentView
1162 public jalview.datamodel.AlignmentView getAlignmentView(
1163 boolean selectedOnly)
1165 return getAlignmentView(selectedOnly, false);
1169 * return a compact representation of the current alignment selection to pass
1170 * to an analysis function
1172 * @param selectedOnly
1173 * boolean true to just return the selected view
1175 * boolean true to annotate the alignment view with groups on the
1176 * alignment (and intersecting with selected region if selectedOnly
1178 * @return AlignmentView
1181 public jalview.datamodel.AlignmentView getAlignmentView(
1182 boolean selectedOnly, boolean markGroups)
1184 return new AlignmentView(alignment, colSel, selectionGroup,
1185 hasHiddenColumns, selectedOnly, markGroups);
1189 * This method returns the visible alignment as text, as seen on the GUI, ie
1190 * if columns are hidden they will not be returned in the result. Use this for
1191 * calculating trees, PCA, redundancy etc on views which contain hidden
1197 public String[] getViewAsString(boolean selectedRegionOnly)
1199 String[] selection = null;
1200 SequenceI[] seqs = null;
1202 int start = 0, end = 0;
1203 if (selectedRegionOnly && selectionGroup != null)
1205 iSize = selectionGroup.getSize();
1206 seqs = selectionGroup.getSequencesInOrder(alignment);
1207 start = selectionGroup.getStartRes();
1208 end = selectionGroup.getEndRes() + 1;
1212 iSize = alignment.getHeight();
1213 seqs = alignment.getSequencesArray();
1214 end = alignment.getWidth();
1217 selection = new String[iSize];
1218 if (hasHiddenColumns)
1220 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1224 for (i = 0; i < iSize; i++)
1226 selection[i] = seqs[i].getSequenceAsString(start, end);
1234 * return visible region boundaries within given column range
1237 * first column (inclusive, from 0)
1239 * last column (exclusive)
1240 * @return int[][] range of {start,end} visible positions
1242 public int[][] getVisibleRegionBoundaries(int min, int max)
1244 Vector regions = new Vector();
1250 if (hasHiddenColumns)
1254 start = colSel.adjustForHiddenColumns(start);
1257 end = colSel.getHiddenBoundaryRight(start);
1268 regions.addElement(new int[]
1271 if (hasHiddenColumns)
1273 start = colSel.adjustForHiddenColumns(end);
1274 start = colSel.getHiddenBoundaryLeft(start) + 1;
1276 } while (end < max);
1278 int[][] startEnd = new int[regions.size()][2];
1280 regions.copyInto(startEnd);
1287 public List<AlignmentAnnotation> getVisibleAlignmentAnnotation(boolean selectedOnly)
1289 ArrayList<AlignmentAnnotation> ala = new ArrayList<AlignmentAnnotation>();
1290 AlignmentAnnotation[] aa;
1291 if ((aa=alignment.getAlignmentAnnotation())!=null)
1293 for (AlignmentAnnotation annot:aa)
1295 AlignmentAnnotation clone = new AlignmentAnnotation(annot);
1296 if (selectedOnly && selectionGroup!=null)
1298 colSel.makeVisibleAnnotation(selectionGroup.getStartRes(), selectionGroup.getEndRes(),clone);
1300 colSel.makeVisibleAnnotation(clone);
1309 * @return the padGaps
1311 public boolean isPadGaps()
1318 * the padGaps to set
1320 public void setPadGaps(boolean padGaps)
1322 this.padGaps = padGaps;
1326 * apply any post-edit constraints and trigger any calculations needed after
1327 * an edit has been performed on the alignment
1331 public void alignmentChanged(AlignmentViewPanel ap)
1335 alignment.padGaps();
1337 if (autoCalculateConsensus)
1339 updateConsensus(ap);
1341 if (hconsensus != null && autoCalculateConsensus)
1343 updateConservation(ap);
1345 if (autoCalculateStrucConsensus)
1347 updateStrucConsensus(ap);
1350 // Reset endRes of groups if beyond alignment width
1351 int alWidth = alignment.getWidth();
1352 List<SequenceGroup> groups = alignment.getGroups();
1355 for (SequenceGroup sg : groups)
1357 if (sg.getEndRes() > alWidth)
1359 sg.setEndRes(alWidth - 1);
1364 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1366 selectionGroup.setEndRes(alWidth - 1);
1369 resetAllColourSchemes();
1370 calculator.restartWorkers();
1371 // alignment.adjustSequenceAnnotations();
1375 * reset scope and do calculations for all applied colourschemes on alignment
1377 void resetAllColourSchemes()
1379 ColourSchemeI cs = globalColourScheme;
1382 cs.alignmentChanged(alignment, hiddenRepSequences);
1384 cs.setConsensus(hconsensus);
1385 if (cs.conservationApplied())
1387 cs.setConservation(Conservation.calculateConservation("All",
1388 ResidueProperties.propHash, 3, alignment.getSequences(), 0,
1389 alignment.getWidth(), false, getConsPercGaps(), false));
1393 for (SequenceGroup sg : alignment.getGroups())
1397 sg.cs.alignmentChanged(sg, hiddenRepSequences);
1399 sg.recalcConservation();
1403 protected void initAutoAnnotation()
1405 // TODO: add menu option action that nulls or creates consensus object
1406 // depending on if the user wants to see the annotation or not in a
1407 // specific alignment
1409 if (hconsensus == null && !isDataset)
1411 if (!alignment.isNucleotide())
1424 private void initConsensus()
1427 consensus = new AlignmentAnnotation("Consensus", "PID",
1428 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1429 consensus.hasText = true;
1430 consensus.autoCalculated = true;
1434 alignment.addAnnotation(consensus);
1438 private void initConservation()
1440 if (showConservation)
1442 if (conservation == null)
1444 conservation = new AlignmentAnnotation("Conservation",
1445 "Conservation of total alignment less than "
1446 + getConsPercGaps() + "% gaps", new Annotation[1],
1447 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1448 conservation.hasText = true;
1449 conservation.autoCalculated = true;
1450 alignment.addAnnotation(conservation);
1455 private void initQuality()
1459 if (quality == null)
1461 quality = new AlignmentAnnotation("Quality",
1462 "Alignment Quality based on Blosum62 scores",
1463 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
1464 quality.hasText = true;
1465 quality.autoCalculated = true;
1466 alignment.addAnnotation(quality);
1471 private void initRNAStructure()
1473 if (alignment.hasRNAStructure() && strucConsensus == null)
1475 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
1476 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
1477 strucConsensus.hasText = true;
1478 strucConsensus.autoCalculated = true;
1482 alignment.addAnnotation(strucConsensus);
1490 * @see jalview.api.AlignViewportI#calcPanelHeight()
1492 public int calcPanelHeight()
1494 // setHeight of panels
1495 AlignmentAnnotation[] aa = getAlignment().getAlignmentAnnotation();
1497 int charHeight = getCharHeight();
1500 BitSet graphgrp = new BitSet();
1501 for (int i = 0; i < aa.length; i++)
1505 System.err.println("Null annotation row: ignoring.");
1512 if (aa[i].graphGroup > -1)
1514 if (graphgrp.get(aa[i].graphGroup))
1520 graphgrp.set(aa[i].graphGroup);
1527 aa[i].height += charHeight;
1535 if (aa[i].graph > 0)
1537 aa[i].height += aa[i].graphHeight;
1540 if (aa[i].height == 0)
1545 height += aa[i].height;
1557 public void updateGroupAnnotationSettings(boolean applyGlobalSettings,
1558 boolean preserveNewGroupSettings)
1560 boolean updateCalcs = false;
1561 boolean conv = isShowGroupConservation();
1562 boolean cons = isShowGroupConsensus();
1563 boolean showprf = isShowSequenceLogo();
1564 boolean showConsHist = isShowConsensusHistogram();
1565 boolean normLogo = isNormaliseSequenceLogo();
1568 * TODO reorder the annotation rows according to group/sequence ordering on
1571 boolean sortg = true;
1573 // remove old automatic annotation
1574 // add any new annotation
1576 // intersect alignment annotation with alignment groups
1578 AlignmentAnnotation[] aan = alignment.getAlignmentAnnotation();
1579 List<SequenceGroup> oldrfs = new ArrayList<SequenceGroup>();
1582 for (int an = 0; an < aan.length; an++)
1584 if (aan[an].autoCalculated && aan[an].groupRef != null)
1586 oldrfs.add(aan[an].groupRef);
1587 alignment.deleteAnnotation(aan[an], false);
1591 if (alignment.getGroups() != null)
1593 for (SequenceGroup sg : alignment.getGroups())
1595 updateCalcs = false;
1596 if (applyGlobalSettings
1597 || (!preserveNewGroupSettings && !oldrfs.contains(sg)))
1599 // set defaults for this group's conservation/consensus
1600 sg.setshowSequenceLogo(showprf);
1601 sg.setShowConsensusHistogram(showConsHist);
1602 sg.setNormaliseSequenceLogo(normLogo);
1607 alignment.addAnnotation(sg.getConservationRow(), 0);
1612 alignment.addAnnotation(sg.getConsensus(), 0);
1614 // refresh the annotation rows
1617 sg.recalcConservation();
1625 public Color getSequenceColour(SequenceI seq)
1627 Color sqc = sequenceColours.get(seq);
1628 return (sqc == null ? Color.white : sqc);
1632 public void setSequenceColour(SequenceI seq, Color col)
1636 sequenceColours.remove(seq);
1640 sequenceColours.put(seq, col);
1645 public void updateSequenceIdColours()
1647 for (SequenceGroup sg : alignment.getGroups())
1649 if (sg.idColour != null)
1651 for (SequenceI s : sg.getSequences(getHiddenRepSequences()))
1653 sequenceColours.put(s, sg.idColour);
1660 public void clearSequenceColours()
1662 sequenceColours.clear();
1666 public AlignViewportI getCodingComplement()
1668 return this.codingComplement;
1672 * Set this as the (cDna/protein) complement of the given viewport. Also
1673 * ensures the reverse relationship is set on the given viewport.
1676 public void setCodingComplement(AlignViewportI av)
1680 System.err.println("Ignoring recursive setCodingComplement request");
1684 this.codingComplement = av;
1685 // avoid infinite recursion!
1686 if (av.getCodingComplement() != this)
1688 av.setCodingComplement(this);
1694 public boolean isNucleotide()
1696 return getAlignment() == null ? false : getAlignment().isNucleotide();