2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, 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.StructureSelectionManagerProvider;
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
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;
163 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
165 // JBPNote Prolly only need this in the applet version.
166 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
169 boolean ignoreGapsInConsensusCalculation = false;
171 boolean isDataset = false;
173 boolean antiAlias = false;
175 boolean padGaps = false;
177 Rectangle explodedPosition;
181 String sequenceSetID;
183 boolean gatherViewsHere = false;
185 Stack historyList = new Stack();
187 Stack redoList = new Stack();
189 Hashtable sequenceColours;
191 int thresholdTextColour = 0;
193 Color textColour = Color.black;
195 Color textColour2 = Color.white;
197 boolean rightAlignIds = false;
199 Hashtable hiddenRepSequences;
204 * Creates a new AlignViewport object.
209 public AlignViewport(AlignmentI al)
216 * Create a new AlignViewport object with a specific sequence set ID
220 * (may be null - but potential for ambiguous constructor exception)
222 public AlignViewport(AlignmentI al, String seqsetid)
224 this(al, seqsetid, null);
227 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
229 sequenceSetID = seqsetid;
231 // TODO remove these once 2.4.VAMSAS release finished
232 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
234 Cache.log.debug("Setting viewport's sequence set id : "
237 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
239 Cache.log.debug("Setting viewport's view id : " + viewId);
246 * Create a new AlignViewport with hidden regions
250 * @param hiddenColumns
253 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
256 if (hiddenColumns != null)
258 this.colSel = hiddenColumns;
259 if (hiddenColumns.getHiddenColumns() != null
260 && hiddenColumns.getHiddenColumns().size() > 0)
262 hasHiddenColumns = true;
266 hasHiddenColumns = false;
273 * New viewport with hidden columns and an existing sequence set id
276 * @param hiddenColumns
280 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
283 this(al, hiddenColumns, seqsetid, null);
287 * New viewport with hidden columns and an existing sequence set id and viewid
290 * @param hiddenColumns
296 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
297 String seqsetid, String viewid)
299 sequenceSetID = seqsetid;
301 // TODO remove these once 2.4.VAMSAS release finished
302 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
304 Cache.log.debug("Setting viewport's sequence set id : "
307 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
309 Cache.log.debug("Setting viewport's view id : " + viewId);
312 if (hiddenColumns != null)
314 this.colSel = hiddenColumns;
315 if (hiddenColumns.getHiddenColumns() != null
316 && hiddenColumns.getHiddenColumns().size() > 0)
318 hasHiddenColumns = true;
322 hasHiddenColumns = false;
331 this.endRes = alignment.getWidth() - 1;
333 this.endSeq = alignment.getHeight() - 1;
335 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
337 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
338 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
340 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
341 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
342 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
344 padGaps = Cache.getDefault("PAD_GAPS", true);
345 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
346 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
348 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
349 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
350 String fontSize = Cache.getDefault("FONT_SIZE", "10");
352 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
356 if (fontStyle.equals("bold"))
360 else if (fontStyle.equals("italic"))
365 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
368 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
370 // We must set conservation and consensus before setting colour,
371 // as Blosum and Clustal require this to be done
372 if (hconsensus == null && !isDataset)
374 if (!alignment.isNucleotide())
376 conservation = new AlignmentAnnotation("Conservation",
377 "Conservation of total alignment less than " + ConsPercGaps
378 + "% gaps", new Annotation[1], 0f, 11f,
379 AlignmentAnnotation.BAR_GRAPH);
380 conservation.hasText = true;
381 conservation.autoCalculated = true;
383 if (Cache.getDefault("SHOW_CONSERVATION", true))
385 alignment.addAnnotation(conservation);
388 if (Cache.getDefault("SHOW_QUALITY", true))
390 quality = new AlignmentAnnotation("Quality",
391 "Alignment Quality based on Blosum62 scores",
392 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
393 quality.hasText = true;
394 quality.autoCalculated = true;
396 alignment.addAnnotation(quality);
398 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
405 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
407 showSequenceLogo = Cache.getDefault("SHOW_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 //TODO check if this can done accordingly
418 strucConsensus = new AlignmentAnnotation("StrucConsensus", "PID",
419 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
420 strucConsensus.hasText = true;
421 strucConsensus.autoCalculated = true;
423 if (Cache.getDefault("SHOW_IDENTITY", true))
425 alignment.addAnnotation(consensus);
426 //TODO: Make own if for structure
427 alignment.addAnnotation(strucConsensus);
432 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
434 globalColourScheme = ColourSchemeProperty.getColour(alignment,
435 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
437 if (globalColourScheme instanceof UserColourScheme)
439 globalColourScheme = UserDefinedColours.loadDefaultColours();
440 ((UserColourScheme) globalColourScheme).setThreshold(0,
441 getIgnoreGapsConsensus());
444 if (globalColourScheme != null)
446 globalColourScheme.setConsensus(hconsensus);
450 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
451 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
453 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
454 followSelection = jalview.bin.Cache.getDefault("FOLLOW_SELECTIONS",
462 * features are displayed if true
464 public void setShowSequenceFeatures(boolean b)
466 showSequenceFeatures = b;
469 public boolean getShowSequenceFeatures()
471 return showSequenceFeatures;
474 ConservationThread conservationThread;
476 ConsensusThread consensusThread;
478 StrucConsensusThread strucConsensusThread;
480 boolean consUpdateNeeded = false;
482 static boolean UPDATING_CONSENSUS = false;
484 static boolean UPDATING_STRUC_CONSENSUS = false;
486 static boolean UPDATING_CONSERVATION = false;
488 boolean updatingConsensus = false;
490 boolean updatingStrucConsensus = false;
492 boolean updatingConservation = false;
495 * centre columnar annotation labels in displayed alignment annotation TODO:
496 * add to jalviewXML and annotation display settings
498 boolean centreColumnLabels = false;
500 private boolean showdbrefs;
502 private boolean shownpfeats;
505 * trigger update of conservation annotation
507 public void updateConservation(final AlignmentPanel ap)
509 // see note in mantis : issue number 8585
510 if (alignment.isNucleotide() || conservation == null
511 || !autoCalculateConsensus)
516 conservationThread = new ConservationThread(this, ap);
517 conservationThread.start();
521 * trigger update of consensus annotation
523 public void updateConsensus(final AlignmentPanel ap)
525 // see note in mantis : issue number 8585
526 if (consensus == null || !autoCalculateConsensus)
530 consensusThread = new ConsensusThread(ap);
531 consensusThread.start();
534 class ConsensusThread extends Thread
538 public ConsensusThread(AlignmentPanel ap)
545 updatingConsensus = true;
546 while (UPDATING_CONSENSUS)
552 ap.paintAlignment(false);
556 } catch (Exception ex)
558 ex.printStackTrace();
562 UPDATING_CONSENSUS = true;
566 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
572 updatingConsensus = false;
573 UPDATING_CONSENSUS = false;
577 consensus.annotations = null;
578 consensus.annotations = new Annotation[aWidth];
580 hconsensus = new Hashtable[aWidth];
581 AAFrequency.calculate(alignment.getSequencesArray(), 0,
582 alignment.getWidth(), hconsensus, true);
583 updateAnnotation(true);
584 if (globalColourScheme != null)
586 globalColourScheme.setConsensus(hconsensus);
589 } catch (OutOfMemoryError error)
591 alignment.deleteAnnotation(consensus);
595 new OOMWarning("calculating consensus", error);
597 UPDATING_CONSENSUS = false;
598 updatingConsensus = false;
602 ap.paintAlignment(true);
607 * update the consensus annotation from the sequence profile data using
608 * current visualization settings.
610 public void updateAnnotation()
612 updateAnnotation(false);
615 protected void updateAnnotation(boolean immediate)
617 // TODO: make calls thread-safe, so if another thread calls this method,
618 // it will either return or wait until one calculation is finished.
620 || (!updatingConsensus && consensus != null && hconsensus != null))
622 AAFrequency.completeConsensus(consensus, hconsensus, 0,
623 hconsensus.length, ignoreGapsInConsensusCalculation,
629 //--------START Structure Conservation
630 public void updateStrucConsensus(final AlignmentPanel ap)
632 // see note in mantis : issue number 8585
633 if (strucConsensus == null || !autoCalculateStrucConsensus)
637 strucConsensusThread = new StrucConsensusThread(ap);
638 strucConsensusThread.start();
641 class StrucConsensusThread extends Thread
645 public StrucConsensusThread(AlignmentPanel ap)
652 updatingStrucConsensus = true;
653 while (UPDATING_STRUC_CONSENSUS)
659 ap.paintAlignment(false);
663 } catch (Exception ex)
665 ex.printStackTrace();
669 UPDATING_STRUC_CONSENSUS = true;
673 int aWidth = (alignment != null) ? alignment.getWidth() : -1; // null
679 updatingStrucConsensus = false;
680 UPDATING_STRUC_CONSENSUS = false;
684 strucConsensus.annotations = null;
685 strucConsensus.annotations = new Annotation[aWidth];
687 hStrucConsensus = new Hashtable[aWidth];
689 AlignmentAnnotation[] aa = ap.av.getAlignment().getAlignmentAnnotation();
690 AlignmentAnnotation rnaStruc = null;
691 for(int i=0; i<aa.length;i++){
692 if(aa[i].getRNAStruc() != null){
698 AlignmentAnnotation rna = ap.av.getAlignment().getAlignmentAnnotation()[0];
699 StructureFrequency.calculate(alignment.getSequencesArray(), 0,
700 alignment.getWidth(), hStrucConsensus, true, rnaStruc);
701 //TODO AlignmentAnnotation rnaStruc!!!
702 updateAnnotation(true);
703 if (globalColourScheme != null)
705 globalColourScheme.setConsensus(hStrucConsensus);
708 } catch (OutOfMemoryError error)
710 alignment.deleteAnnotation(strucConsensus);
712 strucConsensus = null;
713 hStrucConsensus = null;
714 new OOMWarning("calculating structure consensus", error);
716 UPDATING_STRUC_CONSENSUS = false;
717 updatingStrucConsensus = false;
721 ap.paintAlignment(true);
726 * update the consensus annotation from the sequence profile data using
727 * current visualization settings.
729 public void updateAnnotation()
731 updateAnnotation(false);
734 protected void updateAnnotation(boolean immediate)
736 // TODO: make calls thread-safe, so if another thread calls this method,
737 // it will either return or wait until one calculation is finished.
739 || (!updatingStrucConsensus && strucConsensus != null && hStrucConsensus != null))
741 StructureFrequency.completeConsensus(strucConsensus, hStrucConsensus, 0,
742 hStrucConsensus.length, false,
747 //--------END Structure Conservation
750 * get the consensus sequence as displayed under the PID consensus annotation
753 * @return consensus sequence as a new sequence object
755 public SequenceI getConsensusSeq()
757 if (consensus == null)
759 updateConsensus(null);
761 if (consensus == null)
765 StringBuffer seqs = new StringBuffer();
766 for (int i = 0; i < consensus.annotations.length; i++)
768 if (consensus.annotations[i] != null)
770 if (consensus.annotations[i].description.charAt(0) == '[')
772 seqs.append(consensus.annotations[i].description.charAt(1));
776 seqs.append(consensus.annotations[i].displayCharacter);
781 SequenceI sq = new Sequence("Consensus", seqs.toString());
782 sq.setDescription("Percentage Identity Consensus "
783 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
790 * @return null or the currently selected sequence region
792 public SequenceGroup getSelectionGroup()
794 return selectionGroup;
798 * Set the selection group for this window.
800 * @param sg - group holding references to sequences in this alignment view
803 public void setSelectionGroup(SequenceGroup sg)
810 * @return true if conservation based shading is enabled
812 public boolean getConservationSelected()
814 return conservationColourSelected;
820 * enable conservation based shading
822 public void setConservationSelected(boolean b)
824 conservationColourSelected = b;
829 * @return true if percent identity threshold is applied to shading
831 public boolean getAbovePIDThreshold()
833 return abovePIDThreshold;
840 * @param b indicate if percent identity threshold is applied to shading
842 public void setAbovePIDThreshold(boolean b)
844 abovePIDThreshold = b;
850 * @return DOCUMENT ME!
852 public int getStartRes()
860 * @return DOCUMENT ME!
862 public int getEndRes()
870 * @return DOCUMENT ME!
872 public int getStartSeq()
883 public void setGlobalColourScheme(ColourSchemeI cs)
885 globalColourScheme = cs;
891 * @return DOCUMENT ME!
893 public ColourSchemeI getGlobalColourScheme()
895 return globalColourScheme;
904 public void setStartRes(int res)
915 public void setStartSeq(int seq)
926 public void setEndRes(int res)
928 if (res > (alignment.getWidth() - 1))
930 // log.System.out.println(" Corrected res from " + res + " to maximum " +
931 // (alignment.getWidth()-1));
932 res = alignment.getWidth() - 1;
949 public void setEndSeq(int seq)
951 if (seq > alignment.getHeight())
953 seq = alignment.getHeight();
967 * @return DOCUMENT ME!
969 public int getEndSeq()
980 public void setFont(Font f)
984 Container c = new Container();
986 java.awt.FontMetrics fm = c.getFontMetrics(font);
987 setCharHeight(fm.getHeight());
988 setCharWidth(fm.charWidth('M'));
989 validCharWidth = true;
995 * @return DOCUMENT ME!
997 public Font getFont()
1008 public void setCharWidth(int w)
1016 * @return DOCUMENT ME!
1018 public int getCharWidth()
1029 public void setCharHeight(int h)
1031 this.charHeight = h;
1037 * @return DOCUMENT ME!
1039 public int getCharHeight()
1050 public void setWrappedWidth(int w)
1052 this.wrappedWidth = w;
1058 * @return DOCUMENT ME!
1060 public int getWrappedWidth()
1062 return wrappedWidth;
1068 * @return DOCUMENT ME!
1070 public AlignmentI getAlignment()
1081 public void setAlignment(AlignmentI align)
1083 if (alignment != null && alignment.getCodonFrames() != null)
1085 StructureSelectionManager.getStructureSelectionManager(Desktop.instance)
1086 .removeMappings(alignment.getCodonFrames());
1088 this.alignment = align;
1089 if (alignment.getCodonFrames() != null)
1091 StructureSelectionManager.getStructureSelectionManager(Desktop.instance).addMappings(
1092 alignment.getCodonFrames());
1102 public void setWrapAlignment(boolean state)
1104 wrapAlignment = state;
1113 public void setShowText(boolean state)
1124 public void setRenderGaps(boolean state)
1132 * @return DOCUMENT ME!
1134 public boolean getColourText()
1136 return showColourText;
1145 public void setColourText(boolean state)
1147 showColourText = state;
1156 public void setShowBoxes(boolean state)
1164 * @return DOCUMENT ME!
1166 public boolean getWrapAlignment()
1168 return wrapAlignment;
1174 * @return DOCUMENT ME!
1176 public boolean getShowText()
1184 * @return DOCUMENT ME!
1186 public boolean getShowBoxes()
1194 * @return DOCUMENT ME!
1196 public char getGapCharacter()
1198 return getAlignment().getGapCharacter();
1207 public void setGapCharacter(char gap)
1209 if (getAlignment() != null)
1211 getAlignment().setGapCharacter(gap);
1221 public void setThreshold(int thresh)
1229 * @return DOCUMENT ME!
1231 public int getThreshold()
1242 public void setIncrement(int inc)
1250 * @return DOCUMENT ME!
1252 public int getIncrement()
1260 * @return DOCUMENT ME!
1262 public ColumnSelection getColumnSelection()
1273 public void setCurrentTree(NJTree tree)
1281 * @return DOCUMENT ME!
1283 public NJTree getCurrentTree()
1294 public void setColourAppliesToAllGroups(boolean b)
1296 colourAppliesToAllGroups = b;
1302 * @return DOCUMENT ME!
1304 public boolean getColourAppliesToAllGroups()
1306 return colourAppliesToAllGroups;
1312 * @return DOCUMENT ME!
1314 public boolean getShowJVSuffix()
1316 return showJVSuffix;
1325 public void setShowJVSuffix(boolean b)
1333 * @return DOCUMENT ME!
1335 public boolean getShowAnnotation()
1337 return showAnnotation;
1346 public void setShowAnnotation(boolean b)
1354 * @return DOCUMENT ME!
1356 public boolean getScaleAboveWrapped()
1358 return scaleAboveWrapped;
1364 * @return DOCUMENT ME!
1366 public boolean getScaleLeftWrapped()
1368 return scaleLeftWrapped;
1374 * @return DOCUMENT ME!
1376 public boolean getScaleRightWrapped()
1378 return scaleRightWrapped;
1387 public void setScaleAboveWrapped(boolean b)
1389 scaleAboveWrapped = b;
1398 public void setScaleLeftWrapped(boolean b)
1400 scaleLeftWrapped = b;
1409 public void setScaleRightWrapped(boolean b)
1411 scaleRightWrapped = b;
1415 * Property change listener for changes in alignment
1420 public void addPropertyChangeListener(
1421 java.beans.PropertyChangeListener listener)
1423 changeSupport.addPropertyChangeListener(listener);
1432 public void removePropertyChangeListener(
1433 java.beans.PropertyChangeListener listener)
1435 changeSupport.removePropertyChangeListener(listener);
1439 * Property change listener for changes in alignment
1448 public void firePropertyChange(String prop, Object oldvalue,
1451 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1454 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1456 ignoreGapsInConsensusCalculation = b;
1457 updateConsensus(ap);
1458 if (globalColourScheme != null)
1460 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1461 ignoreGapsInConsensusCalculation);
1465 public boolean getIgnoreGapsConsensus()
1467 return ignoreGapsInConsensusCalculation;
1470 public void setDataset(boolean b)
1475 public boolean isDataset()
1480 public void hideSelectedColumns()
1482 if (colSel.size() < 1)
1487 colSel.hideSelectedColumns();
1488 setSelectionGroup(null);
1490 hasHiddenColumns = true;
1493 public void hideColumns(int start, int end)
1497 colSel.hideColumns(start);
1501 colSel.hideColumns(start, end);
1504 hasHiddenColumns = true;
1507 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1509 int sSize = sg.getSize();
1515 if (hiddenRepSequences == null)
1517 hiddenRepSequences = new Hashtable();
1520 hiddenRepSequences.put(repSequence, sg);
1522 // Hide all sequences except the repSequence
1523 SequenceI[] seqs = new SequenceI[sSize - 1];
1525 for (int i = 0; i < sSize; i++)
1527 if (sg.getSequenceAt(i) != repSequence)
1529 if (index == sSize - 1)
1534 seqs[index++] = sg.getSequenceAt(i);
1537 sg.setSeqrep(repSequence);
1538 sg.setHidereps(true);
1543 public void hideAllSelectedSeqs()
1545 if (selectionGroup == null || selectionGroup.getSize() < 1)
1550 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1554 setSelectionGroup(null);
1557 public void hideSequence(SequenceI[] seq)
1561 for (int i = 0; i < seq.length; i++)
1563 alignment.getHiddenSequences().hideSequence(seq[i]);
1565 hasHiddenRows = true;
1566 firePropertyChange("alignment", null, alignment.getSequences());
1570 public void showSequence(int index)
1572 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1573 hiddenRepSequences);
1576 if (selectionGroup == null)
1578 selectionGroup = new SequenceGroup();
1579 selectionGroup.setEndRes(alignment.getWidth() - 1);
1582 for (int t = 0; t < tmp.size(); t++)
1584 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1586 firePropertyChange("alignment", null, alignment.getSequences());
1590 if (alignment.getHiddenSequences().getSize() < 1)
1592 hasHiddenRows = false;
1596 public void showColumn(int col)
1598 colSel.revealHiddenColumns(col);
1599 if (colSel.getHiddenColumns() == null)
1601 hasHiddenColumns = false;
1605 public void showAllHiddenColumns()
1607 colSel.revealAllHiddenColumns();
1608 hasHiddenColumns = false;
1611 public void showAllHiddenSeqs()
1613 if (alignment.getHiddenSequences().getSize() > 0)
1615 if (selectionGroup == null)
1617 selectionGroup = new SequenceGroup();
1618 selectionGroup.setEndRes(alignment.getWidth() - 1);
1620 Vector tmp = alignment.getHiddenSequences().showAll(
1621 hiddenRepSequences);
1622 for (int t = 0; t < tmp.size(); t++)
1624 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1626 firePropertyChange("alignment", null, alignment.getSequences());
1628 hasHiddenRows = false;
1629 hiddenRepSequences = null;
1633 public void invertColumnSelection()
1635 colSel.invertColumnSelection(0, alignment.getWidth());
1638 public int adjustForHiddenSeqs(int alignmentIndex)
1640 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1645 * This method returns an array of new SequenceI objects derived from the
1646 * whole alignment or just the current selection with start and end points
1649 * @note if you need references to the actual SequenceI objects in the
1650 * alignment or currently selected then use getSequenceSelection()
1651 * @return selection as new sequenceI objects
1653 public SequenceI[] getSelectionAsNewSequence()
1655 SequenceI[] sequences;
1657 if (selectionGroup == null)
1659 sequences = alignment.getSequencesArray();
1660 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1661 for (int i = 0; i < sequences.length; i++)
1663 sequences[i] = new Sequence(sequences[i], annots); // construct new
1665 // subset of visible
1671 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1678 * get the currently selected sequence objects or all the sequences in the
1681 * @return array of references to sequence objects
1683 public SequenceI[] getSequenceSelection()
1685 SequenceI[] sequences = null;
1686 if (selectionGroup != null)
1688 sequences = selectionGroup.getSequencesInOrder(alignment);
1690 if (sequences == null)
1692 sequences = alignment.getSequencesArray();
1698 * This method returns the visible alignment as text, as seen on the GUI, ie
1699 * if columns are hidden they will not be returned in the result. Use this for
1700 * calculating trees, PCA, redundancy etc on views which contain hidden
1705 public jalview.datamodel.CigarArray getViewAsCigars(
1706 boolean selectedRegionOnly)
1708 return new jalview.datamodel.CigarArray(alignment, (hasHiddenColumns ? colSel : null), (selectedRegionOnly ? selectionGroup : null));
1712 * return a compact representation of the current alignment selection to pass
1713 * to an analysis function
1715 * @param selectedOnly
1716 * boolean true to just return the selected view
1717 * @return AlignmentView
1719 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1721 return getAlignmentView(selectedOnly, false);
1725 * return a compact representation of the current alignment selection to pass
1726 * to an analysis function
1728 * @param selectedOnly
1729 * boolean true to just return the selected view
1731 * boolean true to annotate the alignment view with groups on the alignment (and intersecting with selected region if selectedOnly is true)
1732 * @return AlignmentView
1734 public jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly, boolean markGroups)
1736 return new AlignmentView(alignment, colSel, selectionGroup, hasHiddenColumns, selectedOnly, markGroups);
1740 * This method returns the visible alignment as text, as seen on the GUI, ie
1741 * if columns are hidden they will not be returned in the result. Use this for
1742 * calculating trees, PCA, redundancy etc on views which contain hidden
1747 public String[] getViewAsString(boolean selectedRegionOnly)
1749 String[] selection = null;
1750 SequenceI[] seqs = null;
1752 int start = 0, end = 0;
1753 if (selectedRegionOnly && selectionGroup != null)
1755 iSize = selectionGroup.getSize();
1756 seqs = selectionGroup.getSequencesInOrder(alignment);
1757 start = selectionGroup.getStartRes();
1758 end = selectionGroup.getEndRes() + 1;
1762 iSize = alignment.getHeight();
1763 seqs = alignment.getSequencesArray();
1764 end = alignment.getWidth();
1767 selection = new String[iSize];
1768 if (hasHiddenColumns)
1770 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1774 for (i = 0; i < iSize; i++)
1776 selection[i] = seqs[i].getSequenceAsString(start, end);
1783 public int[][] getVisibleRegionBoundaries(int min, int max)
1785 Vector regions = new Vector();
1791 if (hasHiddenColumns)
1795 start = colSel.adjustForHiddenColumns(start);
1798 end = colSel.getHiddenBoundaryRight(start);
1809 regions.addElement(new int[]
1812 if (hasHiddenColumns)
1814 start = colSel.adjustForHiddenColumns(end);
1815 start = colSel.getHiddenBoundaryLeft(start) + 1;
1817 } while (end < max);
1819 int[][] startEnd = new int[regions.size()][2];
1821 regions.copyInto(startEnd);
1827 public boolean getShowHiddenMarkers()
1829 return showHiddenMarkers;
1832 public void setShowHiddenMarkers(boolean show)
1834 showHiddenMarkers = show;
1837 public String getSequenceSetId()
1839 if (sequenceSetID == null)
1841 sequenceSetID = alignment.hashCode() + "";
1844 return sequenceSetID;
1848 * unique viewId for synchronizing state with stored Jalview Project
1851 private String viewId = null;
1853 public String getViewId()
1857 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1862 public void alignmentChanged(AlignmentPanel ap)
1866 alignment.padGaps();
1868 if (hconsensus != null && autoCalculateConsensus)
1870 updateConservation(ap);
1872 if (autoCalculateConsensus)
1874 updateConsensus(ap);
1876 if(autoCalculateStrucConsensus)
1878 updateStrucConsensus(ap);
1881 // Reset endRes of groups if beyond alignment width
1882 int alWidth = alignment.getWidth();
1883 Vector groups = alignment.getGroups();
1886 for (int i = 0; i < groups.size(); i++)
1888 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1889 if (sg.getEndRes() > alWidth)
1891 sg.setEndRes(alWidth - 1);
1896 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1898 selectionGroup.setEndRes(alWidth - 1);
1901 resetAllColourSchemes();
1903 // alignment.adjustSequenceAnnotations();
1906 void resetAllColourSchemes()
1908 ColourSchemeI cs = globalColourScheme;
1911 if (cs instanceof ClustalxColourScheme)
1913 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1914 alignment.getWidth());
1917 cs.setConsensus(hconsensus);
1918 if (cs.conservationApplied())
1920 Alignment al = (Alignment) alignment;
1921 Conservation c = new Conservation("All",
1922 ResidueProperties.propHash, 3, al.getSequences(), 0,
1925 c.verdict(false, ConsPercGaps);
1927 cs.setConservation(c);
1931 int s, sSize = alignment.getGroups().size();
1932 for (s = 0; s < sSize; s++)
1934 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1935 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1937 ((ClustalxColourScheme) sg.cs).resetClustalX(
1938 sg.getSequences(hiddenRepSequences), sg.getWidth());
1940 sg.recalcConservation();
1944 public Color getSequenceColour(SequenceI seq)
1946 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1952 return (Color) sequenceColours.get(seq);
1956 public void setSequenceColour(SequenceI seq, Color col)
1958 if (sequenceColours == null)
1960 sequenceColours = new Hashtable();
1965 sequenceColours.remove(seq);
1969 sequenceColours.put(seq, col);
1974 * returns the visible column regions of the alignment
1976 * @param selectedRegionOnly
1977 * true to just return the contigs intersecting with the selected
1981 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1983 int[] viscontigs = null;
1984 int start = 0, end = 0;
1985 if (selectedRegionOnly && selectionGroup != null)
1987 start = selectionGroup.getStartRes();
1988 end = selectionGroup.getEndRes() + 1;
1992 end = alignment.getWidth();
1994 viscontigs = colSel.getVisibleContigs(start, end);
1999 * get hash of undo and redo list for the alignment
2001 * @return long[] { historyList.hashCode, redoList.hashCode };
2003 public long[] getUndoRedoHash()
2005 if (historyList == null || redoList == null)
2009 { historyList.hashCode(), this.redoList.hashCode() };
2013 * test if a particular set of hashcodes are different to the hashcodes for
2014 * the undo and redo list.
2017 * the stored set of hashcodes as returned by getUndoRedoHash
2018 * @return true if the hashcodes differ (ie the alignment has been edited) or
2019 * the stored hashcode array differs in size
2021 public boolean isUndoRedoHashModified(long[] undoredo)
2023 if (undoredo == null)
2027 long[] cstate = getUndoRedoHash();
2028 if (cstate.length != undoredo.length)
2033 for (int i = 0; i < cstate.length; i++)
2035 if (cstate[i] != undoredo[i])
2043 public boolean getCentreColumnLabels()
2045 return centreColumnLabels;
2048 public void setCentreColumnLabels(boolean centrecolumnlabels)
2050 centreColumnLabels = centrecolumnlabels;
2053 public void updateSequenceIdColours()
2055 Vector groups = alignment.getGroups();
2056 if (sequenceColours == null)
2058 sequenceColours = new Hashtable();
2060 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
2062 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
2063 if (sg.idColour != null)
2065 Vector sqs = sg.getSequences(hiddenRepSequences);
2066 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2068 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2075 * enable or disable the display of Database Cross References in the sequence
2078 public void setShowDbRefs(boolean show)
2085 * @return true if Database References are to be displayed on tooltips.
2087 public boolean isShowDbRefs()
2094 * @return true if Non-positional features are to be displayed on tooltips.
2096 public boolean isShowNpFeats()
2102 * enable or disable the display of Non-Positional sequence features in the
2103 * sequence ID tooltip
2107 public void setShowNpFeats(boolean show)
2114 * @return true if view has hidden rows
2116 public boolean hasHiddenRows()
2118 return hasHiddenRows;
2123 * @return true if view has hidden columns
2125 public boolean hasHiddenColumns()
2127 return hasHiddenColumns;
2131 * when set, view will scroll to show the highlighted position
2133 public boolean followHighlight = true;
2136 * @return true if view should scroll to show the highlighted region of a
2140 public boolean getFollowHighlight()
2142 return followHighlight;
2145 public boolean followSelection = true;
2148 * @return true if view selection should always follow the selections
2149 * broadcast by other selection sources
2151 public boolean getFollowSelection()
2153 return followSelection;
2156 private long sgrouphash = -1, colselhash = -1;
2158 boolean showSeqFeaturesHeight;
2161 * checks current SelectionGroup against record of last hash value, and
2163 * @param b update the record of last hash value
2165 * @return true if SelectionGroup changed since last call (when b is true)
2167 boolean isSelectionGroupChanged(boolean b)
2169 int hc = (selectionGroup == null || selectionGroup.getSize()==0) ? -1 : selectionGroup.hashCode();
2170 if (hc!=-1 && hc != sgrouphash)
2172 if (b) {sgrouphash = hc;}
2179 * checks current colsel against record of last hash value, and optionally updates
2182 * @param b update the record of last hash value
2183 * @return true if colsel changed since last call (when b is true)
2185 boolean isColSelChanged(boolean b)
2187 int hc = (colSel == null || colSel.size()==0) ? -1 : colSel.hashCode();
2188 if (hc!=-1 && hc != colselhash)
2190 if (b) {colselhash = hc;}
2196 public void sendSelection()
2198 jalview.structure.StructureSelectionManager
2199 .getStructureSelectionManager(Desktop.instance).sendSelection(
2200 new SequenceGroup(getSelectionGroup()),
2201 new ColumnSelection(getColumnSelection()), this);
2204 public void setShowSequenceFeaturesHeight(boolean selected)
2206 showSeqFeaturesHeight = selected;
2209 public boolean getShowSequenceFeaturesHeight()
2211 return showSeqFeaturesHeight;
2214 boolean showUnconserved = false;
2216 public boolean getShowUnconserved()
2218 return showUnconserved;
2221 public void setShowUnconserved(boolean showunconserved)
2223 showUnconserved = showunconserved;
2227 * return the alignPanel containing the given viewport. Use this to get the
2228 * components currently handling the given viewport.
2231 * @return null or an alignPanel guaranteed to have non-null alignFrame
2234 public AlignmentPanel getAlignPanel()
2236 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2237 .getSequenceSetId());
2238 AlignmentPanel ap = null;
2239 for (int p = 0; aps != null && p < aps.length; p++)
2241 if (aps[p].av == this)
2249 public boolean getSortByTree()
2254 public void setSortByTree(boolean sort)
2260 * should conservation rows be shown for groups
2262 boolean showGroupConservation = false;
2265 * should consensus rows be shown for groups
2267 boolean showGroupConsensus = false;
2270 * should consensus profile be rendered by default
2272 public boolean showSequenceLogo = false;
2275 * should consensus histograms be rendered by default
2277 public boolean showConsensusHistogram = true;
2280 * @return the showConsensusProfile
2282 public boolean isShowSequenceLogo()
2284 return showSequenceLogo;
2288 * @param showSequenceLogo
2291 public void setShowSequenceLogo(boolean showSequenceLogo)
2293 if (showSequenceLogo != this.showSequenceLogo)
2295 // TODO: decouple settings setting from calculation when refactoring
2296 // annotation update method from alignframe to viewport
2297 this.showSequenceLogo = showSequenceLogo;
2298 if (consensusThread != null)
2300 consensusThread.updateAnnotation();
2303 this.showSequenceLogo = showSequenceLogo;
2307 * @param showConsensusHistogram
2308 * the showConsensusHistogram to set
2310 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2312 this.showConsensusHistogram = showConsensusHistogram;
2316 * @return the showGroupConservation
2318 public boolean isShowGroupConservation()
2320 return showGroupConservation;
2324 * @param showGroupConservation
2325 * the showGroupConservation to set
2327 public void setShowGroupConservation(boolean showGroupConservation)
2329 this.showGroupConservation = showGroupConservation;
2333 * @return the showGroupConsensus
2335 public boolean isShowGroupConsensus()
2337 return showGroupConsensus;
2341 * @param showGroupConsensus
2342 * the showGroupConsensus to set
2344 public void setShowGroupConsensus(boolean showGroupConsensus)
2346 this.showGroupConsensus = showGroupConsensus;
2351 * @return flag to indicate if the consensus histogram should be rendered by
2354 public boolean isShowConsensusHistogram()
2356 return this.showConsensusHistogram;
2360 * synthesize a column selection if none exists so it covers the given
2361 * selection group. if wholewidth is false, no column selection is made if the
2362 * selection group covers the whole alignment width.
2367 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2371 && (sgs = sg.getStartRes()) >= 0
2372 && sg.getStartRes() <= (sge = sg.getEndRes())
2373 && (colSel == null || colSel.getSelected() == null || colSel
2374 .getSelected().size() == 0))
2376 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2383 colSel = new ColumnSelection();
2385 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2387 colSel.addElement(cspos);
2392 public StructureSelectionManager getStructureSelectionManager()
2394 return StructureSelectionManager.getStructureSelectionManager(Desktop.instance);
2400 * @return a series of SequenceI arrays, one for each PDBEntry, listing which sequence in the alignment holds a reference to it
2402 public SequenceI[][] collateForPDB(PDBEntry[] pdbEntries)
2404 ArrayList<SequenceI[]> seqvectors = new ArrayList<SequenceI[]>();
2405 for (PDBEntry pdb: pdbEntries) {
2406 ArrayList<SequenceI> seqs = new ArrayList<SequenceI>();
2407 for (int i = 0; i < alignment.getHeight(); i++)
2409 Vector pdbs = alignment.getSequenceAt(i)
2410 .getDatasetSequence().getPDBId();
2414 for (int p = 0; p < pdbs.size(); p++)
2416 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
2417 if (p1.getId().equals(pdb.getId()))
2419 if (!seqs.contains(sq=alignment.getSequenceAt(i)))
2426 seqvectors.add(seqs.toArray(new SequenceI[seqs.size()]));
2428 return seqvectors.toArray(new SequenceI[seqvectors.size()][]);