2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
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 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * Jalview - A Sequence Alignment Editor and Viewer
20 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version 2
25 * of the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
42 import jalview.analysis.*;
43 import jalview.api.AlignViewportI;
47 import jalview.datamodel.*;
49 import jalview.schemes.*;
50 import jalview.structure.SelectionSource;
51 import jalview.structure.StructureSelectionManager;
52 import jalview.structure.VamsasSource;
58 * @version $Revision: 1.141 $
60 public class AlignViewport implements SelectionSource, VamsasSource, AlignViewportI
62 private static final int RIGHT_JUSTIFY = 1;
72 boolean showJVSuffix = true;
74 boolean showText = true;
76 boolean showColourText = false;
78 boolean showBoxes = true;
80 boolean wrapAlignment = false;
82 boolean renderGaps = true;
84 boolean showSequenceFeatures = false;
86 boolean showAnnotation = true;
88 boolean colourAppliesToAllGroups = true;
90 ColourSchemeI globalColourScheme = null;
92 boolean conservationColourSelected = false;
94 boolean abovePIDThreshold = false;
96 SequenceGroup selectionGroup;
102 boolean validCharWidth;
108 boolean seqNameItalics;
110 AlignmentI alignment;
112 ColumnSelection colSel = new ColumnSelection();
118 NJTree currentTree = null;
120 boolean scaleAboveWrapped = false;
122 boolean scaleLeftWrapped = true;
124 boolean scaleRightWrapped = true;
126 boolean hasHiddenColumns = false;
128 boolean hasHiddenRows = false;
130 boolean showHiddenMarkers = true;
132 boolean cursorMode = false;
135 * Keys are the feature types which are currently visible. Note: Values are
138 Hashtable featuresDisplayed = null;
141 public Hashtable[] hconsensus;
143 public Hashtable[] hStrucConsensus;
145 AlignmentAnnotation consensus;
147 AlignmentAnnotation strucConsensus;
149 AlignmentAnnotation conservation;
151 AlignmentAnnotation quality;
153 AlignmentAnnotation[] groupConsensus;
155 AlignmentAnnotation[] groupConservation;
157 boolean autoCalculateConsensus = true;
159 boolean autoCalculateStrucConsensus = true;
162 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
164 // JBPNote Prolly only need this in the applet version.
165 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
168 boolean ignoreGapsInConsensusCalculation = false;
170 boolean isDataset = false;
172 boolean antiAlias = false;
174 boolean padGaps = false;
176 Rectangle explodedPosition;
180 String sequenceSetID;
182 boolean gatherViewsHere = false;
184 Stack historyList = new Stack();
186 Stack redoList = new Stack();
188 Hashtable sequenceColours;
190 int thresholdTextColour = 0;
192 Color textColour = Color.black;
194 Color textColour2 = Color.white;
196 boolean rightAlignIds = false;
198 Hashtable hiddenRepSequences;
203 * Creates a new AlignViewport object.
208 public AlignViewport(AlignmentI al)
215 * Create a new AlignViewport object with a specific sequence set ID
219 * (may be null - but potential for ambiguous constructor exception)
221 public AlignViewport(AlignmentI al, String seqsetid)
223 this(al, seqsetid, null);
226 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
228 sequenceSetID = seqsetid;
230 // TODO remove these once 2.4.VAMSAS release finished
231 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
233 Cache.log.debug("Setting viewport's sequence set id : "
236 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
238 Cache.log.debug("Setting viewport's view id : " + viewId);
245 * Create a new AlignViewport with hidden regions
249 * @param hiddenColumns
252 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
255 if (hiddenColumns != null)
257 this.colSel = hiddenColumns;
258 if (hiddenColumns.getHiddenColumns() != null
259 && hiddenColumns.getHiddenColumns().size() > 0)
261 hasHiddenColumns = true;
265 hasHiddenColumns = false;
272 * New viewport with hidden columns and an existing sequence set id
275 * @param hiddenColumns
279 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
282 this(al, hiddenColumns, seqsetid, null);
286 * New viewport with hidden columns and an existing sequence set id and viewid
289 * @param hiddenColumns
295 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
296 String seqsetid, String viewid)
298 sequenceSetID = seqsetid;
300 // TODO remove these once 2.4.VAMSAS release finished
301 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
303 Cache.log.debug("Setting viewport's sequence set id : "
306 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
308 Cache.log.debug("Setting viewport's view id : " + viewId);
311 if (hiddenColumns != null)
313 this.colSel = hiddenColumns;
314 if (hiddenColumns.getHiddenColumns() != null
315 && hiddenColumns.getHiddenColumns().size() > 0)
317 hasHiddenColumns = true;
321 hasHiddenColumns = false;
330 this.endRes = alignment.getWidth() - 1;
332 this.endSeq = alignment.getHeight() - 1;
334 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
336 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
337 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
339 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
340 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
341 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
343 padGaps = Cache.getDefault("PAD_GAPS", true);
344 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
345 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
347 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
348 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
349 String fontSize = Cache.getDefault("FONT_SIZE", "10");
351 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
355 if (fontStyle.equals("bold"))
359 else if (fontStyle.equals("italic"))
364 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
367 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
369 // We must set conservation and consensus before setting colour,
370 // as Blosum and Clustal require this to be done
371 if (hconsensus == null && !isDataset)
373 if (!alignment.isNucleotide())
375 conservation = new AlignmentAnnotation("Conservation",
376 "Conservation of total alignment less than " + ConsPercGaps
377 + "% gaps", new Annotation[1], 0f, 11f,
378 AlignmentAnnotation.BAR_GRAPH);
379 conservation.hasText = true;
380 conservation.autoCalculated = true;
382 if (Cache.getDefault("SHOW_CONSERVATION", true))
384 alignment.addAnnotation(conservation);
387 if (Cache.getDefault("SHOW_QUALITY", true))
389 quality = new AlignmentAnnotation("Quality",
390 "Alignment Quality based on Blosum62 scores",
391 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
392 quality.hasText = true;
393 quality.autoCalculated = true;
395 alignment.addAnnotation(quality);
397 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
404 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
406 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
407 normaliseSequenceLogo = Cache.getDefault("NORMALISE_CONSENSUS_LOGO", false);
408 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
409 // TODO: add menu option action that nulls or creates consensus object
410 // depending on if the user wants to see the annotation or not in a
411 // specific alignment
412 consensus = new AlignmentAnnotation("Consensus", "PID",
413 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
414 consensus.hasText = true;
415 consensus.autoCalculated = true;
417 if (alignment.isNucleotide() && alignment.hasRNAStructure())
419 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
420 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
421 strucConsensus.hasText = true;
422 strucConsensus.autoCalculated = true;
425 if (Cache.getDefault("SHOW_IDENTITY", true))
427 alignment.addAnnotation(consensus);
428 // TODO: Make own if for structure
429 if (alignment.isNucleotide() && alignment.hasRNAStructure())
431 alignment.addAnnotation(strucConsensus);
437 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
439 globalColourScheme = ColourSchemeProperty.getColour(alignment,
440 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
442 if (globalColourScheme instanceof UserColourScheme)
444 globalColourScheme = UserDefinedColours.loadDefaultColours();
445 ((UserColourScheme) globalColourScheme).setThreshold(0,
446 getIgnoreGapsConsensus());
449 if (globalColourScheme != null)
451 globalColourScheme.setConsensus(hconsensus);
455 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
456 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
458 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
459 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
467 * features are displayed if true
469 public void setShowSequenceFeatures(boolean b)
471 showSequenceFeatures = b;
474 public boolean getShowSequenceFeatures()
476 return showSequenceFeatures;
479 ConservationThread conservationThread;
481 ConsensusThread consensusThread;
483 StrucConsensusThread strucConsensusThread;
485 boolean consUpdateNeeded = false;
487 static boolean UPDATING_CONSENSUS = false;
489 static boolean UPDATING_STRUC_CONSENSUS = false;
491 static boolean UPDATING_CONSERVATION = false;
493 boolean updatingConsensus = false;
495 boolean updatingStrucConsensus = false;
497 boolean updatingConservation = false;
500 * centre columnar annotation labels in displayed alignment annotation TODO:
501 * add to jalviewXML and annotation display settings
503 boolean centreColumnLabels = false;
505 private boolean showdbrefs;
507 private boolean shownpfeats;
510 * trigger update of conservation annotation
512 public void updateConservation(final AlignmentPanel ap)
514 // see note in mantis : issue number 8585
515 if (alignment.isNucleotide() || conservation == null
516 || !autoCalculateConsensus)
521 conservationThread = new ConservationThread(this, ap);
522 conservationThread.start();
526 * trigger update of consensus annotation
528 public void updateConsensus(final AlignmentPanel ap)
530 // see note in mantis : issue number 8585
531 if (consensus == null || !autoCalculateConsensus)
535 consensusThread = new ConsensusThread(ap);
536 consensusThread.start();
539 class ConsensusThread extends Thread
543 public ConsensusThread(AlignmentPanel ap)
550 updatingConsensus = true;
551 while (UPDATING_CONSENSUS)
557 ap.paintAlignment(false);
561 } catch (Exception ex)
563 ex.printStackTrace();
567 UPDATING_CONSENSUS = true;
571 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
577 updatingConsensus = false;
578 UPDATING_CONSENSUS = false;
582 consensus.annotations = null;
583 consensus.annotations = new Annotation[aWidth];
585 hconsensus = new Hashtable[aWidth];
586 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
587 .getWidth(), hconsensus, true);
588 updateAnnotation(true);
589 if (globalColourScheme != null)
591 globalColourScheme.setConsensus(hconsensus);
594 } catch (OutOfMemoryError error)
596 alignment.deleteAnnotation(consensus);
600 new OOMWarning("calculating consensus", error);
602 UPDATING_CONSENSUS = false;
603 updatingConsensus = false;
607 ap.paintAlignment(true);
612 * update the consensus annotation from the sequence profile data using
613 * current visualization settings.
615 public void updateAnnotation()
617 updateAnnotation(false);
620 protected void updateAnnotation(boolean immediate)
622 // TODO: make calls thread-safe, so if another thread calls this method,
623 // it will either return or wait until one calculation is finished.
625 || (!updatingConsensus && consensus != null && hconsensus != null))
627 AAFrequency.completeConsensus(consensus, hconsensus, 0,
628 hconsensus.length, ignoreGapsInConsensusCalculation,
634 // --------START Structure Conservation
635 public void updateStrucConsensus(final AlignmentPanel ap)
637 // see note in mantis : issue number 8585
638 if (strucConsensus == null || !autoCalculateStrucConsensus)
642 strucConsensusThread = new StrucConsensusThread(ap);
643 strucConsensusThread.start();
646 class StrucConsensusThread extends Thread
650 public StrucConsensusThread(AlignmentPanel ap)
657 updatingStrucConsensus = true;
658 while (UPDATING_STRUC_CONSENSUS)
664 ap.paintAlignment(false);
668 } catch (Exception ex)
670 ex.printStackTrace();
674 UPDATING_STRUC_CONSENSUS = true;
678 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
684 updatingStrucConsensus = false;
685 UPDATING_STRUC_CONSENSUS = false;
689 strucConsensus.annotations = null;
690 strucConsensus.annotations = new Annotation[aWidth];
692 hStrucConsensus = new Hashtable[aWidth];
694 AlignmentAnnotation[] aa = ap.av.getAlignment()
695 .getAlignmentAnnotation();
696 AlignmentAnnotation rnaStruc = null;
697 for (int i = 0; i < aa.length; i++)
699 if (aa[i].getRNAStruc() != null)
706 AlignmentAnnotation rna = ap.av.getAlignment()
707 .getAlignmentAnnotation()[0];
708 StructureFrequency.calculate(alignment.getSequencesArray(), 0,
709 alignment.getWidth(), hStrucConsensus, true, rnaStruc);
710 // TODO AlignmentAnnotation rnaStruc!!!
711 updateAnnotation(true);
712 if (globalColourScheme != null)
714 globalColourScheme.setConsensus(hStrucConsensus);
717 } catch (OutOfMemoryError error)
719 alignment.deleteAnnotation(strucConsensus);
721 strucConsensus = null;
722 hStrucConsensus = null;
723 new OOMWarning("calculating structure consensus", error);
725 UPDATING_STRUC_CONSENSUS = false;
726 updatingStrucConsensus = false;
730 ap.paintAlignment(true);
735 * update the consensus annotation from the sequence profile data using
736 * current visualization settings.
738 public void updateAnnotation()
740 updateAnnotation(false);
743 protected void updateAnnotation(boolean immediate)
745 // TODO: make calls thread-safe, so if another thread calls this method,
746 // it will either return or wait until one calculation is finished.
748 || (!updatingStrucConsensus && strucConsensus != null && hStrucConsensus != null))
750 StructureFrequency.completeConsensus(strucConsensus,
751 hStrucConsensus, 0, hStrucConsensus.length, false,
757 // --------END Structure Conservation
760 * get the consensus sequence as displayed under the PID consensus annotation
763 * @return consensus sequence as a new sequence object
765 public SequenceI getConsensusSeq()
767 if (consensus == null)
769 updateConsensus(null);
771 if (consensus == null)
775 StringBuffer seqs = new StringBuffer();
776 for (int i = 0; i < consensus.annotations.length; i++)
778 if (consensus.annotations[i] != null)
780 if (consensus.annotations[i].description.charAt(0) == '[')
782 seqs.append(consensus.annotations[i].description.charAt(1));
786 seqs.append(consensus.annotations[i].displayCharacter);
791 SequenceI sq = new Sequence("Consensus", seqs.toString());
792 sq.setDescription("Percentage Identity Consensus "
793 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
800 * @return null or the currently selected sequence region
802 public SequenceGroup getSelectionGroup()
804 return selectionGroup;
808 * Set the selection group for this window.
811 * - group holding references to sequences in this alignment view
814 public void setSelectionGroup(SequenceGroup sg)
822 * @return true if conservation based shading is enabled
824 public boolean getConservationSelected()
826 return conservationColourSelected;
833 * enable conservation based shading
835 public void setConservationSelected(boolean b)
837 conservationColourSelected = b;
843 * @return true if percent identity threshold is applied to shading
845 public boolean getAbovePIDThreshold()
847 return abovePIDThreshold;
855 * indicate if percent identity threshold is applied to shading
857 public void setAbovePIDThreshold(boolean b)
859 abovePIDThreshold = b;
865 * @return DOCUMENT ME!
867 public int getStartRes()
875 * @return DOCUMENT ME!
877 public int getEndRes()
885 * @return DOCUMENT ME!
887 public int getStartSeq()
898 public void setGlobalColourScheme(ColourSchemeI cs)
900 globalColourScheme = cs;
906 * @return DOCUMENT ME!
908 public ColourSchemeI getGlobalColourScheme()
910 return globalColourScheme;
919 public void setStartRes(int res)
930 public void setStartSeq(int seq)
941 public void setEndRes(int res)
943 if (res > (alignment.getWidth() - 1))
945 // log.System.out.println(" Corrected res from " + res + " to maximum " +
946 // (alignment.getWidth()-1));
947 res = alignment.getWidth() - 1;
964 public void setEndSeq(int seq)
966 if (seq > alignment.getHeight())
968 seq = alignment.getHeight();
982 * @return DOCUMENT ME!
984 public int getEndSeq()
995 public void setFont(Font f)
999 Container c = new Container();
1001 java.awt.FontMetrics fm = c.getFontMetrics(font);
1002 setCharHeight(fm.getHeight());
1003 setCharWidth(fm.charWidth('M'));
1004 validCharWidth = true;
1010 * @return DOCUMENT ME!
1012 public Font getFont()
1023 public void setCharWidth(int w)
1031 * @return DOCUMENT ME!
1033 public int getCharWidth()
1044 public void setCharHeight(int h)
1046 this.charHeight = h;
1052 * @return DOCUMENT ME!
1054 public int getCharHeight()
1065 public void setWrappedWidth(int w)
1067 this.wrappedWidth = w;
1073 * @return DOCUMENT ME!
1075 public int getWrappedWidth()
1077 return wrappedWidth;
1083 * @return DOCUMENT ME!
1085 public AlignmentI getAlignment()
1096 public void setAlignment(AlignmentI align)
1098 if (alignment != null && alignment.getCodonFrames() != null)
1100 StructureSelectionManager.getStructureSelectionManager(
1101 Desktop.instance).removeMappings(alignment.getCodonFrames());
1103 this.alignment = align;
1104 if (alignment.getCodonFrames() != null)
1106 StructureSelectionManager.getStructureSelectionManager(
1107 Desktop.instance).addMappings(alignment.getCodonFrames());
1117 public void setWrapAlignment(boolean state)
1119 wrapAlignment = state;
1128 public void setShowText(boolean state)
1139 public void setRenderGaps(boolean state)
1147 * @return DOCUMENT ME!
1149 public boolean getColourText()
1151 return showColourText;
1160 public void setColourText(boolean state)
1162 showColourText = state;
1171 public void setShowBoxes(boolean state)
1179 * @return DOCUMENT ME!
1181 public boolean getWrapAlignment()
1183 return wrapAlignment;
1189 * @return DOCUMENT ME!
1191 public boolean getShowText()
1199 * @return DOCUMENT ME!
1201 public boolean getShowBoxes()
1209 * @return DOCUMENT ME!
1211 public char getGapCharacter()
1213 return getAlignment().getGapCharacter();
1222 public void setGapCharacter(char gap)
1224 if (getAlignment() != null)
1226 getAlignment().setGapCharacter(gap);
1236 public void setThreshold(int thresh)
1244 * @return DOCUMENT ME!
1246 public int getThreshold()
1257 public void setIncrement(int inc)
1265 * @return DOCUMENT ME!
1267 public int getIncrement()
1275 * @return DOCUMENT ME!
1277 public ColumnSelection getColumnSelection()
1288 public void setCurrentTree(NJTree tree)
1296 * @return DOCUMENT ME!
1298 public NJTree getCurrentTree()
1309 public void setColourAppliesToAllGroups(boolean b)
1311 colourAppliesToAllGroups = b;
1317 * @return DOCUMENT ME!
1319 public boolean getColourAppliesToAllGroups()
1321 return colourAppliesToAllGroups;
1327 * @return DOCUMENT ME!
1329 public boolean getShowJVSuffix()
1331 return showJVSuffix;
1340 public void setShowJVSuffix(boolean b)
1348 * @return DOCUMENT ME!
1350 public boolean getShowAnnotation()
1352 return showAnnotation;
1361 public void setShowAnnotation(boolean b)
1369 * @return DOCUMENT ME!
1371 public boolean getScaleAboveWrapped()
1373 return scaleAboveWrapped;
1379 * @return DOCUMENT ME!
1381 public boolean getScaleLeftWrapped()
1383 return scaleLeftWrapped;
1389 * @return DOCUMENT ME!
1391 public boolean getScaleRightWrapped()
1393 return scaleRightWrapped;
1402 public void setScaleAboveWrapped(boolean b)
1404 scaleAboveWrapped = b;
1413 public void setScaleLeftWrapped(boolean b)
1415 scaleLeftWrapped = b;
1424 public void setScaleRightWrapped(boolean b)
1426 scaleRightWrapped = b;
1430 * Property change listener for changes in alignment
1435 public void addPropertyChangeListener(
1436 java.beans.PropertyChangeListener listener)
1438 changeSupport.addPropertyChangeListener(listener);
1447 public void removePropertyChangeListener(
1448 java.beans.PropertyChangeListener listener)
1450 changeSupport.removePropertyChangeListener(listener);
1454 * Property change listener for changes in alignment
1463 public void firePropertyChange(String prop, Object oldvalue,
1466 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1469 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1471 ignoreGapsInConsensusCalculation = b;
1472 updateConsensus(ap);
1473 if (globalColourScheme != null)
1475 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1476 ignoreGapsInConsensusCalculation);
1480 public boolean getIgnoreGapsConsensus()
1482 return ignoreGapsInConsensusCalculation;
1485 public void setDataset(boolean b)
1490 public boolean isDataset()
1495 public void hideSelectedColumns()
1497 if (colSel.size() < 1)
1502 colSel.hideSelectedColumns();
1503 setSelectionGroup(null);
1505 hasHiddenColumns = true;
1508 public void hideColumns(int start, int end)
1512 colSel.hideColumns(start);
1516 colSel.hideColumns(start, end);
1519 hasHiddenColumns = true;
1522 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1524 int sSize = sg.getSize();
1530 if (hiddenRepSequences == null)
1532 hiddenRepSequences = new Hashtable();
1535 hiddenRepSequences.put(repSequence, sg);
1537 // Hide all sequences except the repSequence
1538 SequenceI[] seqs = new SequenceI[sSize - 1];
1540 for (int i = 0; i < sSize; i++)
1542 if (sg.getSequenceAt(i) != repSequence)
1544 if (index == sSize - 1)
1549 seqs[index++] = sg.getSequenceAt(i);
1552 sg.setSeqrep(repSequence);
1553 sg.setHidereps(true);
1558 public void hideAllSelectedSeqs()
1560 if (selectionGroup == null || selectionGroup.getSize() < 1)
1565 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1569 setSelectionGroup(null);
1572 public void hideSequence(SequenceI[] seq)
1576 for (int i = 0; i < seq.length; i++)
1578 alignment.getHiddenSequences().hideSequence(seq[i]);
1580 hasHiddenRows = true;
1581 firePropertyChange("alignment", null, alignment.getSequences());
1585 public void showSequence(int index)
1587 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1588 hiddenRepSequences);
1591 if (selectionGroup == null)
1593 selectionGroup = new SequenceGroup();
1594 selectionGroup.setEndRes(alignment.getWidth() - 1);
1597 for (int t = 0; t < tmp.size(); t++)
1599 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1601 firePropertyChange("alignment", null, alignment.getSequences());
1605 if (alignment.getHiddenSequences().getSize() < 1)
1607 hasHiddenRows = false;
1611 public void showColumn(int col)
1613 colSel.revealHiddenColumns(col);
1614 if (colSel.getHiddenColumns() == null)
1616 hasHiddenColumns = false;
1620 public void showAllHiddenColumns()
1622 colSel.revealAllHiddenColumns();
1623 hasHiddenColumns = false;
1626 public void showAllHiddenSeqs()
1628 if (alignment.getHiddenSequences().getSize() > 0)
1630 if (selectionGroup == null)
1632 selectionGroup = new SequenceGroup();
1633 selectionGroup.setEndRes(alignment.getWidth() - 1);
1635 Vector tmp = alignment.getHiddenSequences().showAll(
1636 hiddenRepSequences);
1637 for (int t = 0; t < tmp.size(); t++)
1639 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1641 firePropertyChange("alignment", null, alignment.getSequences());
1643 hasHiddenRows = false;
1644 hiddenRepSequences = null;
1648 public void invertColumnSelection()
1650 colSel.invertColumnSelection(0, alignment.getWidth());
1653 public int adjustForHiddenSeqs(int alignmentIndex)
1655 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1660 * This method returns an array of new SequenceI objects derived from the
1661 * whole alignment or just the current selection with start and end points
1664 * @note if you need references to the actual SequenceI objects in the
1665 * alignment or currently selected then use getSequenceSelection()
1666 * @return selection as new sequenceI objects
1668 public SequenceI[] getSelectionAsNewSequence()
1670 SequenceI[] sequences;
1672 if (selectionGroup == null)
1674 sequences = alignment.getSequencesArray();
1675 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1676 for (int i = 0; i < sequences.length; i++)
1678 sequences[i] = new Sequence(sequences[i], annots); // construct new
1680 // subset of visible
1686 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1693 * get the currently selected sequence objects or all the sequences in the
1696 * @return array of references to sequence objects
1698 public SequenceI[] getSequenceSelection()
1700 SequenceI[] sequences = null;
1701 if (selectionGroup != null)
1703 sequences = selectionGroup.getSequencesInOrder(alignment);
1705 if (sequences == null)
1707 sequences = alignment.getSequencesArray();
1713 * This method returns the visible alignment as text, as seen on the GUI, ie
1714 * if columns are hidden they will not be returned in the result. Use this for
1715 * calculating trees, PCA, redundancy etc on views which contain hidden
1720 public jalview.datamodel.CigarArray getViewAsCigars(
1721 boolean selectedRegionOnly)
1723 return new jalview.datamodel.CigarArray(alignment,
1724 (hasHiddenColumns ? colSel : null),
1725 (selectedRegionOnly ? selectionGroup : null));
1729 * return a compact representation of the current alignment selection to pass
1730 * to an analysis function
1732 * @param selectedOnly
1733 * boolean true to just return the selected view
1734 * @return AlignmentView
1736 public jalview.datamodel.AlignmentView getAlignmentView(
1737 boolean selectedOnly)
1739 return getAlignmentView(selectedOnly, false);
1743 * return a compact representation of the current alignment selection to pass
1744 * to an analysis function
1746 * @param selectedOnly
1747 * boolean true to just return the selected view
1749 * boolean true to annotate the alignment view with groups on the
1750 * alignment (and intersecting with selected region if selectedOnly
1752 * @return AlignmentView
1754 public jalview.datamodel.AlignmentView getAlignmentView(
1755 boolean selectedOnly, boolean markGroups)
1757 return new AlignmentView(alignment, colSel, selectionGroup,
1758 hasHiddenColumns, selectedOnly, markGroups);
1762 * This method returns the visible alignment as text, as seen on the GUI, ie
1763 * if columns are hidden they will not be returned in the result. Use this for
1764 * calculating trees, PCA, redundancy etc on views which contain hidden
1769 public String[] getViewAsString(boolean selectedRegionOnly)
1771 String[] selection = null;
1772 SequenceI[] seqs = null;
1774 int start = 0, end = 0;
1775 if (selectedRegionOnly && selectionGroup != null)
1777 iSize = selectionGroup.getSize();
1778 seqs = selectionGroup.getSequencesInOrder(alignment);
1779 start = selectionGroup.getStartRes();
1780 end = selectionGroup.getEndRes() + 1;
1784 iSize = alignment.getHeight();
1785 seqs = alignment.getSequencesArray();
1786 end = alignment.getWidth();
1789 selection = new String[iSize];
1790 if (hasHiddenColumns)
1792 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1796 for (i = 0; i < iSize; i++)
1798 selection[i] = seqs[i].getSequenceAsString(start, end);
1805 public int[][] getVisibleRegionBoundaries(int min, int max)
1807 Vector regions = new Vector();
1813 if (hasHiddenColumns)
1817 start = colSel.adjustForHiddenColumns(start);
1820 end = colSel.getHiddenBoundaryRight(start);
1831 regions.addElement(new int[]
1834 if (hasHiddenColumns)
1836 start = colSel.adjustForHiddenColumns(end);
1837 start = colSel.getHiddenBoundaryLeft(start) + 1;
1839 } while (end < max);
1841 int[][] startEnd = new int[regions.size()][2];
1843 regions.copyInto(startEnd);
1849 public boolean getShowHiddenMarkers()
1851 return showHiddenMarkers;
1854 public void setShowHiddenMarkers(boolean show)
1856 showHiddenMarkers = show;
1859 public String getSequenceSetId()
1861 if (sequenceSetID == null)
1863 sequenceSetID = alignment.hashCode() + "";
1866 return sequenceSetID;
1870 * unique viewId for synchronizing state with stored Jalview Project
1873 private String viewId = null;
1875 public String getViewId()
1879 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1884 public void alignmentChanged(AlignmentPanel ap)
1888 alignment.padGaps();
1890 if (hconsensus != null && autoCalculateConsensus)
1892 updateConservation(ap);
1894 if (autoCalculateConsensus)
1896 updateConsensus(ap);
1898 if (autoCalculateStrucConsensus)
1900 updateStrucConsensus(ap);
1903 // Reset endRes of groups if beyond alignment width
1904 int alWidth = alignment.getWidth();
1905 Vector groups = alignment.getGroups();
1908 for (int i = 0; i < groups.size(); i++)
1910 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1911 if (sg.getEndRes() > alWidth)
1913 sg.setEndRes(alWidth - 1);
1918 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1920 selectionGroup.setEndRes(alWidth - 1);
1923 resetAllColourSchemes();
1925 // alignment.adjustSequenceAnnotations();
1928 void resetAllColourSchemes()
1930 ColourSchemeI cs = globalColourScheme;
1933 if (cs instanceof ClustalxColourScheme)
1935 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1936 alignment.getWidth());
1939 cs.setConsensus(hconsensus);
1940 if (cs.conservationApplied())
1942 Alignment al = (Alignment) alignment;
1943 Conservation c = new Conservation("All",
1944 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1947 c.verdict(false, ConsPercGaps);
1949 cs.setConservation(c);
1953 int s, sSize = alignment.getGroups().size();
1954 for (s = 0; s < sSize; s++)
1956 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1957 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1959 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1960 .getSequences(hiddenRepSequences), sg.getWidth());
1962 sg.recalcConservation();
1966 public Color getSequenceColour(SequenceI seq)
1968 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1974 return (Color) sequenceColours.get(seq);
1978 public void setSequenceColour(SequenceI seq, Color col)
1980 if (sequenceColours == null)
1982 sequenceColours = new Hashtable();
1987 sequenceColours.remove(seq);
1991 sequenceColours.put(seq, col);
1996 * returns the visible column regions of the alignment
1998 * @param selectedRegionOnly
1999 * true to just return the contigs intersecting with the selected
2003 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
2005 int[] viscontigs = null;
2006 int start = 0, end = 0;
2007 if (selectedRegionOnly && selectionGroup != null)
2009 start = selectionGroup.getStartRes();
2010 end = selectionGroup.getEndRes() + 1;
2014 end = alignment.getWidth();
2016 viscontigs = colSel.getVisibleContigs(start, end);
2021 * get hash of undo and redo list for the alignment
2023 * @return long[] { historyList.hashCode, redoList.hashCode };
2025 public long[] getUndoRedoHash()
2027 if (historyList == null || redoList == null)
2031 { historyList.hashCode(), this.redoList.hashCode() };
2035 * test if a particular set of hashcodes are different to the hashcodes for
2036 * the undo and redo list.
2039 * the stored set of hashcodes as returned by getUndoRedoHash
2040 * @return true if the hashcodes differ (ie the alignment has been edited) or
2041 * the stored hashcode array differs in size
2043 public boolean isUndoRedoHashModified(long[] undoredo)
2045 if (undoredo == null)
2049 long[] cstate = getUndoRedoHash();
2050 if (cstate.length != undoredo.length)
2055 for (int i = 0; i < cstate.length; i++)
2057 if (cstate[i] != undoredo[i])
2065 public boolean getCentreColumnLabels()
2067 return centreColumnLabels;
2070 public void setCentreColumnLabels(boolean centrecolumnlabels)
2072 centreColumnLabels = centrecolumnlabels;
2075 public void updateSequenceIdColours()
2077 Vector groups = alignment.getGroups();
2078 if (sequenceColours == null)
2080 sequenceColours = new Hashtable();
2082 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
2084 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
2085 if (sg.idColour != null)
2087 Vector sqs = sg.getSequences(hiddenRepSequences);
2088 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2090 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2097 * enable or disable the display of Database Cross References in the sequence
2100 public void setShowDbRefs(boolean show)
2107 * @return true if Database References are to be displayed on tooltips.
2109 public boolean isShowDbRefs()
2116 * @return true if Non-positional features are to be displayed on tooltips.
2118 public boolean isShowNpFeats()
2124 * enable or disable the display of Non-Positional sequence features in the
2125 * sequence ID tooltip
2129 public void setShowNpFeats(boolean show)
2136 * @return true if view has hidden rows
2138 public boolean hasHiddenRows()
2140 return hasHiddenRows;
2145 * @return true if view has hidden columns
2147 public boolean hasHiddenColumns()
2149 return hasHiddenColumns;
2153 * when set, view will scroll to show the highlighted position
2155 public boolean followHighlight = true;
2158 * @return true if view should scroll to show the highlighted region of a
2162 public boolean getFollowHighlight()
2164 return followHighlight;
2167 public boolean followSelection = true;
2170 * @return true if view selection should always follow the selections
2171 * broadcast by other selection sources
2173 public boolean getFollowSelection()
2175 return followSelection;
2178 private long sgrouphash = -1, colselhash = -1;
2180 boolean showSeqFeaturesHeight;
2183 * checks current SelectionGroup against record of last hash value, and
2187 * update the record of last hash value
2189 * @return true if SelectionGroup changed since last call (when b is true)
2191 boolean isSelectionGroupChanged(boolean b)
2193 int hc = (selectionGroup == null || selectionGroup.getSize() == 0) ? -1
2194 : selectionGroup.hashCode();
2195 if (hc != -1 && hc != sgrouphash)
2207 * checks current colsel against record of last hash value, and optionally
2211 * update the record of last hash value
2212 * @return true if colsel changed since last call (when b is true)
2214 boolean isColSelChanged(boolean b)
2216 int hc = (colSel == null || colSel.size() == 0) ? -1 : colSel
2218 if (hc != -1 && hc != colselhash)
2229 public void sendSelection()
2231 jalview.structure.StructureSelectionManager
2232 .getStructureSelectionManager(Desktop.instance).sendSelection(
2233 new SequenceGroup(getSelectionGroup()),
2234 new ColumnSelection(getColumnSelection()), this);
2237 public void setShowSequenceFeaturesHeight(boolean selected)
2239 showSeqFeaturesHeight = selected;
2242 public boolean getShowSequenceFeaturesHeight()
2244 return showSeqFeaturesHeight;
2247 boolean showUnconserved = false;
2249 public boolean getShowUnconserved()
2251 return showUnconserved;
2254 public void setShowUnconserved(boolean showunconserved)
2256 showUnconserved = showunconserved;
2260 * return the alignPanel containing the given viewport. Use this to get the
2261 * components currently handling the given viewport.
2264 * @return null or an alignPanel guaranteed to have non-null alignFrame
2267 public AlignmentPanel getAlignPanel()
2269 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2270 .getSequenceSetId());
2271 AlignmentPanel ap = null;
2272 for (int p = 0; aps != null && p < aps.length; p++)
2274 if (aps[p].av == this)
2282 public boolean getSortByTree()
2287 public void setSortByTree(boolean sort)
2293 * should conservation rows be shown for groups
2295 boolean showGroupConservation = false;
2298 * should consensus rows be shown for groups
2300 boolean showGroupConsensus = false;
2303 * should consensus profile be rendered by default
2305 public boolean showSequenceLogo = false;
2307 * should consensus profile be rendered normalised to row height
2309 public boolean normaliseSequenceLogo = false;
2311 * should consensus histograms be rendered by default
2313 public boolean showConsensusHistogram = true;
2316 * @return the showConsensusProfile
2318 public boolean isShowSequenceLogo()
2320 return showSequenceLogo;
2324 * @param showSequenceLogo
2327 public void setShowSequenceLogo(boolean showSequenceLogo)
2329 if (showSequenceLogo != this.showSequenceLogo)
2331 // TODO: decouple settings setting from calculation when refactoring
2332 // annotation update method from alignframe to viewport
2333 this.showSequenceLogo = showSequenceLogo;
2334 if (consensusThread != null)
2336 consensusThread.updateAnnotation();
2338 if (strucConsensusThread != null)
2340 strucConsensusThread.updateAnnotation();
2343 this.showSequenceLogo = showSequenceLogo;
2347 * @param showConsensusHistogram
2348 * the showConsensusHistogram to set
2350 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2352 this.showConsensusHistogram = showConsensusHistogram;
2356 * @return the showGroupConservation
2358 public boolean isShowGroupConservation()
2360 return showGroupConservation;
2364 * @param showGroupConservation
2365 * the showGroupConservation to set
2367 public void setShowGroupConservation(boolean showGroupConservation)
2369 this.showGroupConservation = showGroupConservation;
2373 * @return the showGroupConsensus
2375 public boolean isShowGroupConsensus()
2377 return showGroupConsensus;
2381 * @param showGroupConsensus
2382 * the showGroupConsensus to set
2384 public void setShowGroupConsensus(boolean showGroupConsensus)
2386 this.showGroupConsensus = showGroupConsensus;
2391 * @return flag to indicate if the consensus histogram should be rendered by
2394 public boolean isShowConsensusHistogram()
2396 return this.showConsensusHistogram;
2400 * synthesize a column selection if none exists so it covers the given
2401 * selection group. if wholewidth is false, no column selection is made if the
2402 * selection group covers the whole alignment width.
2407 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2411 && (sgs = sg.getStartRes()) >= 0
2412 && sg.getStartRes() <= (sge = sg.getEndRes())
2413 && (colSel == null || colSel.getSelected() == null || colSel
2414 .getSelected().size() == 0))
2416 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2423 colSel = new ColumnSelection();
2425 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2427 colSel.addElement(cspos);
2432 public StructureSelectionManager getStructureSelectionManager()
2434 return StructureSelectionManager
2435 .getStructureSelectionManager(Desktop.instance);
2441 * @return a series of SequenceI arrays, one for each PDBEntry, listing which
2442 * sequence in the alignment holds a reference to it
2444 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
2446 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
2447 for (PDBEntry pdb : pdbEntries)
2449 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
2450 for (int i = 0; i < alignment.getHeight(); i++)
2452 Vector pdbs = alignment.getSequenceAt(i).getDatasetSequence()
2457 for (int p = 0; p < pdbs.size(); p++)
2459 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
2460 if (p1.getId().equals(pdb.getId()))
2462 if (!seqs.contains(sq = alignment.getSequenceAt(i)))
2469 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
2471 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);
2475 public boolean isNormaliseSequenceLogo()
2477 return normaliseSequenceLogo;
2480 public void setNormaliseSequenceLogo(boolean state)
2482 normaliseSequenceLogo = state;
2485 public boolean isCalcInProgress()
2487 // TODO generalise to iterate over all calculators associated with av
2488 return updatingConsensus || updatingConservation || updatingStrucConsensus;
2491 public boolean isCalculationInProgress(
2492 AlignmentAnnotation alignmentAnnotation)
2494 if (!alignmentAnnotation.autoCalculated)
2496 if ((updatingConsensus && consensus==alignmentAnnotation)
2497 || (updatingConservation && (conservation==alignmentAnnotation || quality==alignmentAnnotation))
2498 || (updatingStrucConsensus && strucConsensus==alignmentAnnotation)
2508 * @return true if alignment characters should be displayed
2510 public boolean isValidCharWidth()
2512 return validCharWidth;
2516 public Hashtable[] getSequenceConsensusHash()
2522 public Hashtable[] getRnaStructureConsensusHash()
2524 return hStrucConsensus;