2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
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.*;
46 import jalview.datamodel.*;
48 import jalview.schemes.*;
49 import jalview.structure.SelectionSource;
50 import jalview.structure.StructureSelectionManager;
58 public class AlignViewport implements SelectionSource
60 private static final int RIGHT_JUSTIFY = 1;
70 boolean showJVSuffix = true;
72 boolean showText = true;
74 boolean showColourText = false;
76 boolean showBoxes = true;
78 boolean wrapAlignment = false;
80 boolean renderGaps = true;
82 boolean showSequenceFeatures = false;
84 boolean showAnnotation = true;
86 boolean colourAppliesToAllGroups = true;
88 ColourSchemeI globalColourScheme = null;
90 boolean conservationColourSelected = false;
92 boolean abovePIDThreshold = false;
94 SequenceGroup selectionGroup;
100 boolean validCharWidth;
106 boolean seqNameItalics;
108 AlignmentI alignment;
110 ColumnSelection colSel = new ColumnSelection();
116 NJTree currentTree = null;
118 boolean scaleAboveWrapped = false;
120 boolean scaleLeftWrapped = true;
122 boolean scaleRightWrapped = true;
124 boolean hasHiddenColumns = false;
126 boolean hasHiddenRows = false;
128 boolean showHiddenMarkers = true;
130 boolean cursorMode = false;
133 * Keys are the feature types which are currently visible. Note: Values are
136 Hashtable featuresDisplayed = null;
139 public Hashtable[] hconsensus;
141 AlignmentAnnotation consensus;
143 AlignmentAnnotation conservation;
145 AlignmentAnnotation quality;
147 AlignmentAnnotation[] groupConsensus;
149 AlignmentAnnotation[] groupConservation;
151 boolean autoCalculateConsensus = true;
154 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
156 // JBPNote Prolly only need this in the applet version.
157 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
160 boolean ignoreGapsInConsensusCalculation = false;
162 boolean isDataset = false;
164 boolean antiAlias = false;
166 boolean padGaps = false;
168 Rectangle explodedPosition;
172 String sequenceSetID;
174 boolean gatherViewsHere = false;
176 Stack historyList = new Stack();
178 Stack redoList = new Stack();
180 Hashtable sequenceColours;
182 int thresholdTextColour = 0;
184 Color textColour = Color.black;
186 Color textColour2 = Color.white;
188 boolean rightAlignIds = false;
190 Hashtable hiddenRepSequences;
195 * Creates a new AlignViewport object.
200 public AlignViewport(AlignmentI al)
207 * Create a new AlignViewport object with a specific sequence set ID
211 * (may be null - but potential for ambiguous constructor exception)
213 public AlignViewport(AlignmentI al, String seqsetid)
215 this(al, seqsetid, null);
218 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
220 sequenceSetID = seqsetid;
222 // TODO remove these once 2.4.VAMSAS release finished
223 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
225 Cache.log.debug("Setting viewport's sequence set id : "
228 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
230 Cache.log.debug("Setting viewport's view id : " + viewId);
237 * Create a new AlignViewport with hidden regions
241 * @param hiddenColumns
244 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
247 if (hiddenColumns != null)
249 this.colSel = hiddenColumns;
250 if (hiddenColumns.getHiddenColumns() != null
251 && hiddenColumns.getHiddenColumns().size() > 0)
253 hasHiddenColumns = true;
257 hasHiddenColumns = false;
264 * New viewport with hidden columns and an existing sequence set id
267 * @param hiddenColumns
271 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
274 this(al, hiddenColumns, seqsetid, null);
278 * New viewport with hidden columns and an existing sequence set id and viewid
281 * @param hiddenColumns
287 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns,
288 String seqsetid, String viewid)
290 sequenceSetID = seqsetid;
292 // TODO remove these once 2.4.VAMSAS release finished
293 if (Cache.log != null && Cache.log.isDebugEnabled() && seqsetid != null)
295 Cache.log.debug("Setting viewport's sequence set id : "
298 if (Cache.log != null && Cache.log.isDebugEnabled() && viewId != null)
300 Cache.log.debug("Setting viewport's view id : " + viewId);
303 if (hiddenColumns != null)
305 this.colSel = hiddenColumns;
306 if (hiddenColumns.getHiddenColumns() != null
307 && hiddenColumns.getHiddenColumns().size() > 0)
309 hasHiddenColumns = true;
313 hasHiddenColumns = false;
322 this.endRes = alignment.getWidth() - 1;
324 this.endSeq = alignment.getHeight() - 1;
326 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
328 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
329 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
331 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
332 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
333 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
335 padGaps = Cache.getDefault("PAD_GAPS", true);
336 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP", true);
337 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP", true);
339 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
340 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
341 String fontSize = Cache.getDefault("FONT_SIZE", "10");
343 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
347 if (fontStyle.equals("bold"))
351 else if (fontStyle.equals("italic"))
356 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
359 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
361 // We must set conservation and consensus before setting colour,
362 // as Blosum and Clustal require this to be done
363 if (hconsensus == null && !isDataset)
365 if (!alignment.isNucleotide())
367 conservation = new AlignmentAnnotation("Conservation",
368 "Conservation of total alignment less than " + ConsPercGaps
369 + "% gaps", new Annotation[1], 0f, 11f,
370 AlignmentAnnotation.BAR_GRAPH);
371 conservation.hasText = true;
372 conservation.autoCalculated = true;
374 if (Cache.getDefault("SHOW_CONSERVATION", true))
376 alignment.addAnnotation(conservation);
379 if (Cache.getDefault("SHOW_QUALITY", true))
381 quality = new AlignmentAnnotation("Quality",
382 "Alignment Quality based on Blosum62 scores",
383 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
384 quality.hasText = true;
385 quality.autoCalculated = true;
387 alignment.addAnnotation(quality);
389 showGroupConservation = Cache.getDefault("SHOW_GROUP_CONSERVATION",
396 showConsensusHistogram = Cache.getDefault("SHOW_CONSENSUS_HISTOGRAM",
398 showSequenceLogo = Cache.getDefault("SHOW_CONSENSUS_LOGO", false);
399 showGroupConsensus = Cache.getDefault("SHOW_GROUP_CONSENSUS", false);
400 // TODO: add menu option action that nulls or creates consensus object
401 // depending on if the user wants to see the annotation or not in a
402 // specific alignment
403 consensus = new AlignmentAnnotation("Consensus", "PID",
404 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
405 consensus.hasText = true;
406 consensus.autoCalculated = true;
408 if (Cache.getDefault("SHOW_IDENTITY", true))
410 alignment.addAnnotation(consensus);
414 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
416 globalColourScheme = ColourSchemeProperty.getColour(alignment,
417 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
419 if (globalColourScheme instanceof UserColourScheme)
421 globalColourScheme = UserDefinedColours.loadDefaultColours();
422 ((UserColourScheme) globalColourScheme).setThreshold(0,
423 getIgnoreGapsConsensus());
426 if (globalColourScheme != null)
428 globalColourScheme.setConsensus(hconsensus);
432 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
433 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED",
435 sortByTree = jalview.bin.Cache.getDefault("SORT_BY_TREE", false);
442 * features are displayed if true
444 public void setShowSequenceFeatures(boolean b)
446 showSequenceFeatures = b;
449 public boolean getShowSequenceFeatures()
451 return showSequenceFeatures;
454 ConservationThread conservationThread;
456 ConsensusThread consensusThread;
458 boolean consUpdateNeeded = false;
460 static boolean UPDATING_CONSENSUS = false;
462 static boolean UPDATING_CONSERVATION = false;
464 boolean updatingConsensus = false;
466 boolean updatingConservation = false;
469 * centre columnar annotation labels in displayed alignment annotation TODO:
470 * add to jalviewXML and annotation display settings
472 boolean centreColumnLabels = false;
474 private boolean showdbrefs;
476 private boolean shownpfeats;
479 * consensus annotation includes all percentage for all symbols in column
481 private boolean includeAllConsensusSymbols = true;
484 * trigger update of conservation annotation
486 public void updateConservation(final AlignmentPanel ap)
488 // see note in mantis : issue number 8585
489 if (alignment.isNucleotide() || conservation == null
490 || !autoCalculateConsensus)
495 conservationThread = new ConservationThread(this, ap);
496 conservationThread.start();
500 * trigger update of consensus annotation
502 public void updateConsensus(final AlignmentPanel ap)
504 // see note in mantis : issue number 8585
505 if (consensus == null || !autoCalculateConsensus)
509 consensusThread = new ConsensusThread(ap);
510 consensusThread.start();
513 class ConsensusThread extends Thread
517 public ConsensusThread(AlignmentPanel ap)
524 updatingConsensus = true;
525 while (UPDATING_CONSENSUS)
531 ap.paintAlignment(false);
535 } catch (Exception ex)
537 ex.printStackTrace();
541 UPDATING_CONSENSUS = true;
545 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
554 consensus.annotations = null;
555 consensus.annotations = new Annotation[aWidth];
557 hconsensus = new Hashtable[aWidth];
558 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
559 .getWidth(), hconsensus, includeAllConsensusSymbols);
560 AAFrequency.completeConsensus(consensus, hconsensus, 0, aWidth,
561 ignoreGapsInConsensusCalculation,
562 includeAllConsensusSymbols);
564 if (globalColourScheme != null)
566 globalColourScheme.setConsensus(hconsensus);
569 } catch (OutOfMemoryError error)
571 alignment.deleteAnnotation(consensus);
575 new OOMWarning("calculating consensus", error);
577 UPDATING_CONSENSUS = false;
578 updatingConsensus = false;
582 ap.paintAlignment(true);
588 * get the consensus sequence as displayed under the PID consensus annotation
591 * @return consensus sequence as a new sequence object
593 public SequenceI getConsensusSeq()
595 if (consensus == null)
597 updateConsensus(null);
599 if (consensus == null)
603 StringBuffer seqs = new StringBuffer();
604 for (int i = 0; i < consensus.annotations.length; i++)
606 if (consensus.annotations[i] != null)
608 if (consensus.annotations[i].description.charAt(0) == '[')
610 seqs.append(consensus.annotations[i].description.charAt(1));
614 seqs.append(consensus.annotations[i].displayCharacter);
619 SequenceI sq = new Sequence("Consensus", seqs.toString());
620 sq.setDescription("Percentage Identity Consensus "
621 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
628 * @return DOCUMENT ME!
630 public SequenceGroup getSelectionGroup()
632 return selectionGroup;
641 public void setSelectionGroup(SequenceGroup sg)
649 * @return DOCUMENT ME!
651 public boolean getConservationSelected()
653 return conservationColourSelected;
662 public void setConservationSelected(boolean b)
664 conservationColourSelected = b;
670 * @return DOCUMENT ME!
672 public boolean getAbovePIDThreshold()
674 return abovePIDThreshold;
683 public void setAbovePIDThreshold(boolean b)
685 abovePIDThreshold = b;
691 * @return DOCUMENT ME!
693 public int getStartRes()
701 * @return DOCUMENT ME!
703 public int getEndRes()
711 * @return DOCUMENT ME!
713 public int getStartSeq()
724 public void setGlobalColourScheme(ColourSchemeI cs)
726 globalColourScheme = cs;
732 * @return DOCUMENT ME!
734 public ColourSchemeI getGlobalColourScheme()
736 return globalColourScheme;
745 public void setStartRes(int res)
756 public void setStartSeq(int seq)
767 public void setEndRes(int res)
769 if (res > (alignment.getWidth() - 1))
771 // log.System.out.println(" Corrected res from " + res + " to maximum " +
772 // (alignment.getWidth()-1));
773 res = alignment.getWidth() - 1;
790 public void setEndSeq(int seq)
792 if (seq > alignment.getHeight())
794 seq = alignment.getHeight();
808 * @return DOCUMENT ME!
810 public int getEndSeq()
821 public void setFont(Font f)
825 Container c = new Container();
827 java.awt.FontMetrics fm = c.getFontMetrics(font);
828 setCharHeight(fm.getHeight());
829 setCharWidth(fm.charWidth('M'));
830 validCharWidth = true;
836 * @return DOCUMENT ME!
838 public Font getFont()
849 public void setCharWidth(int w)
857 * @return DOCUMENT ME!
859 public int getCharWidth()
870 public void setCharHeight(int h)
878 * @return DOCUMENT ME!
880 public int getCharHeight()
891 public void setWrappedWidth(int w)
893 this.wrappedWidth = w;
899 * @return DOCUMENT ME!
901 public int getWrappedWidth()
909 * @return DOCUMENT ME!
911 public AlignmentI getAlignment()
922 public void setAlignment(AlignmentI align)
924 if (alignment != null && alignment.getCodonFrames() != null)
926 StructureSelectionManager.getStructureSelectionManager()
927 .removeMappings(alignment.getCodonFrames());
929 this.alignment = align;
930 if (alignment.getCodonFrames() != null)
932 StructureSelectionManager.getStructureSelectionManager().addMappings(
933 alignment.getCodonFrames());
943 public void setWrapAlignment(boolean state)
945 wrapAlignment = state;
954 public void setShowText(boolean state)
965 public void setRenderGaps(boolean state)
973 * @return DOCUMENT ME!
975 public boolean getColourText()
977 return showColourText;
986 public void setColourText(boolean state)
988 showColourText = state;
997 public void setShowBoxes(boolean state)
1005 * @return DOCUMENT ME!
1007 public boolean getWrapAlignment()
1009 return wrapAlignment;
1015 * @return DOCUMENT ME!
1017 public boolean getShowText()
1025 * @return DOCUMENT ME!
1027 public boolean getShowBoxes()
1035 * @return DOCUMENT ME!
1037 public char getGapCharacter()
1039 return getAlignment().getGapCharacter();
1048 public void setGapCharacter(char gap)
1050 if (getAlignment() != null)
1052 getAlignment().setGapCharacter(gap);
1062 public void setThreshold(int thresh)
1070 * @return DOCUMENT ME!
1072 public int getThreshold()
1083 public void setIncrement(int inc)
1091 * @return DOCUMENT ME!
1093 public int getIncrement()
1101 * @return DOCUMENT ME!
1103 public ColumnSelection getColumnSelection()
1114 public void setCurrentTree(NJTree tree)
1122 * @return DOCUMENT ME!
1124 public NJTree getCurrentTree()
1135 public void setColourAppliesToAllGroups(boolean b)
1137 colourAppliesToAllGroups = b;
1143 * @return DOCUMENT ME!
1145 public boolean getColourAppliesToAllGroups()
1147 return colourAppliesToAllGroups;
1153 * @return DOCUMENT ME!
1155 public boolean getShowJVSuffix()
1157 return showJVSuffix;
1166 public void setShowJVSuffix(boolean b)
1174 * @return DOCUMENT ME!
1176 public boolean getShowAnnotation()
1178 return showAnnotation;
1187 public void setShowAnnotation(boolean b)
1195 * @return DOCUMENT ME!
1197 public boolean getScaleAboveWrapped()
1199 return scaleAboveWrapped;
1205 * @return DOCUMENT ME!
1207 public boolean getScaleLeftWrapped()
1209 return scaleLeftWrapped;
1215 * @return DOCUMENT ME!
1217 public boolean getScaleRightWrapped()
1219 return scaleRightWrapped;
1228 public void setScaleAboveWrapped(boolean b)
1230 scaleAboveWrapped = b;
1239 public void setScaleLeftWrapped(boolean b)
1241 scaleLeftWrapped = b;
1250 public void setScaleRightWrapped(boolean b)
1252 scaleRightWrapped = b;
1256 * Property change listener for changes in alignment
1261 public void addPropertyChangeListener(
1262 java.beans.PropertyChangeListener listener)
1264 changeSupport.addPropertyChangeListener(listener);
1273 public void removePropertyChangeListener(
1274 java.beans.PropertyChangeListener listener)
1276 changeSupport.removePropertyChangeListener(listener);
1280 * Property change listener for changes in alignment
1289 public void firePropertyChange(String prop, Object oldvalue,
1292 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1295 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1297 ignoreGapsInConsensusCalculation = b;
1298 updateConsensus(ap);
1299 if (globalColourScheme != null)
1301 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1302 ignoreGapsInConsensusCalculation);
1306 public boolean getIgnoreGapsConsensus()
1308 return ignoreGapsInConsensusCalculation;
1311 public void setDataset(boolean b)
1316 public boolean isDataset()
1321 public void hideSelectedColumns()
1323 if (colSel.size() < 1)
1328 colSel.hideSelectedColumns();
1329 setSelectionGroup(null);
1331 hasHiddenColumns = true;
1334 public void hideColumns(int start, int end)
1338 colSel.hideColumns(start);
1342 colSel.hideColumns(start, end);
1345 hasHiddenColumns = true;
1348 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1350 int sSize = sg.getSize();
1356 if (hiddenRepSequences == null)
1358 hiddenRepSequences = new Hashtable();
1361 hiddenRepSequences.put(repSequence, sg);
1363 // Hide all sequences except the repSequence
1364 SequenceI[] seqs = new SequenceI[sSize - 1];
1366 for (int i = 0; i < sSize; i++)
1368 if (sg.getSequenceAt(i) != repSequence)
1370 if (index == sSize - 1)
1375 seqs[index++] = sg.getSequenceAt(i);
1378 sg.setSeqrep(repSequence);
1379 sg.setHidereps(true);
1384 public void hideAllSelectedSeqs()
1386 if (selectionGroup == null || selectionGroup.getSize() < 1)
1391 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1395 setSelectionGroup(null);
1398 public void hideSequence(SequenceI[] seq)
1402 for (int i = 0; i < seq.length; i++)
1404 alignment.getHiddenSequences().hideSequence(seq[i]);
1406 hasHiddenRows = true;
1407 firePropertyChange("alignment", null, alignment.getSequences());
1411 public void showSequence(int index)
1413 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1414 hiddenRepSequences);
1417 if (selectionGroup == null)
1419 selectionGroup = new SequenceGroup();
1420 selectionGroup.setEndRes(alignment.getWidth() - 1);
1423 for (int t = 0; t < tmp.size(); t++)
1425 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1427 firePropertyChange("alignment", null, alignment.getSequences());
1431 if (alignment.getHiddenSequences().getSize() < 1)
1433 hasHiddenRows = false;
1437 public void showColumn(int col)
1439 colSel.revealHiddenColumns(col);
1440 if (colSel.getHiddenColumns() == null)
1442 hasHiddenColumns = false;
1446 public void showAllHiddenColumns()
1448 colSel.revealAllHiddenColumns();
1449 hasHiddenColumns = false;
1452 public void showAllHiddenSeqs()
1454 if (alignment.getHiddenSequences().getSize() > 0)
1456 if (selectionGroup == null)
1458 selectionGroup = new SequenceGroup();
1459 selectionGroup.setEndRes(alignment.getWidth() - 1);
1461 Vector tmp = alignment.getHiddenSequences().showAll(
1462 hiddenRepSequences);
1463 for (int t = 0; t < tmp.size(); t++)
1465 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1467 firePropertyChange("alignment", null, alignment.getSequences());
1469 hasHiddenRows = false;
1470 hiddenRepSequences = null;
1474 public void invertColumnSelection()
1476 colSel.invertColumnSelection(0, alignment.getWidth());
1479 public int adjustForHiddenSeqs(int alignmentIndex)
1481 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1486 * This method returns an array of new SequenceI objects derived from the
1487 * whole alignment or just the current selection with start and end points
1490 * @note if you need references to the actual SequenceI objects in the
1491 * alignment or currently selected then use getSequenceSelection()
1492 * @return selection as new sequenceI objects
1494 public SequenceI[] getSelectionAsNewSequence()
1496 SequenceI[] sequences;
1498 if (selectionGroup == null)
1500 sequences = alignment.getSequencesArray();
1501 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1502 for (int i = 0; i < sequences.length; i++)
1504 sequences[i] = new Sequence(sequences[i], annots); // construct new
1506 // subset of visible
1512 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1519 * get the currently selected sequence objects or all the sequences in the
1522 * @return array of references to sequence objects
1524 public SequenceI[] getSequenceSelection()
1526 SequenceI[] sequences = null;
1527 if (selectionGroup != null)
1529 sequences = selectionGroup.getSequencesInOrder(alignment);
1531 if (sequences == null)
1533 sequences = alignment.getSequencesArray();
1539 * This method returns the visible alignment as text, as seen on the GUI, ie
1540 * if columns are hidden they will not be returned in the result. Use this for
1541 * calculating trees, PCA, redundancy etc on views which contain hidden
1546 public jalview.datamodel.CigarArray getViewAsCigars(
1547 boolean selectedRegionOnly)
1549 CigarArray selection = null;
1550 SequenceI[] seqs = null;
1552 int start = 0, end = 0;
1553 if (selectedRegionOnly && selectionGroup != null)
1555 iSize = selectionGroup.getSize();
1556 seqs = selectionGroup.getSequencesInOrder(alignment);
1557 start = selectionGroup.getStartRes();
1558 end = selectionGroup.getEndRes(); // inclusive for start and end in
1559 // SeqCigar constructor
1563 iSize = alignment.getHeight();
1564 seqs = alignment.getSequencesArray();
1565 end = alignment.getWidth() - 1;
1567 SeqCigar[] selseqs = new SeqCigar[iSize];
1568 for (i = 0; i < iSize; i++)
1570 selseqs[i] = new SeqCigar(seqs[i], start, end);
1572 selection = new CigarArray(selseqs);
1573 // now construct the CigarArray operations
1574 if (hasHiddenColumns)
1576 Vector regions = colSel.getHiddenColumns();
1578 int hideStart, hideEnd;
1580 for (int j = 0; last < end & j < regions.size(); j++)
1582 region = (int[]) regions.elementAt(j);
1583 hideStart = region[0];
1584 hideEnd = region[1];
1585 // edit hidden regions to selection range
1586 if (hideStart < last)
1598 if (hideStart > end)
1608 if (hideStart > hideEnd)
1613 * form operations...
1615 if (last < hideStart)
1617 selection.addOperation(CigarArray.M, hideStart - last);
1619 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1622 // Final match if necessary.
1625 selection.addOperation(CigarArray.M, end - last + 1);
1630 selection.addOperation(CigarArray.M, end - start + 1);
1636 * return a compact representation of the current alignment selection to pass
1637 * to an analysis function
1639 * @param selectedOnly
1640 * boolean true to just return the selected view
1641 * @return AlignmentView
1643 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1646 // this is here because the AlignmentView constructor modifies the
1648 // object. Refactoring of Cigar and alignment view representation should
1649 // be done to remove redundancy.
1650 CigarArray aligview = getViewAsCigars(selectedOnly);
1651 if (aligview != null)
1653 return new AlignmentView(aligview,
1654 (selectedOnly && selectionGroup != null) ? selectionGroup
1655 .getStartRes() : 0);
1661 * This method returns the visible alignment as text, as seen on the GUI, ie
1662 * if columns are hidden they will not be returned in the result. Use this for
1663 * calculating trees, PCA, redundancy etc on views which contain hidden
1668 public String[] getViewAsString(boolean selectedRegionOnly)
1670 String[] selection = null;
1671 SequenceI[] seqs = null;
1673 int start = 0, end = 0;
1674 if (selectedRegionOnly && selectionGroup != null)
1676 iSize = selectionGroup.getSize();
1677 seqs = selectionGroup.getSequencesInOrder(alignment);
1678 start = selectionGroup.getStartRes();
1679 end = selectionGroup.getEndRes() + 1;
1683 iSize = alignment.getHeight();
1684 seqs = alignment.getSequencesArray();
1685 end = alignment.getWidth();
1688 selection = new String[iSize];
1689 if (hasHiddenColumns)
1691 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1695 for (i = 0; i < iSize; i++)
1697 selection[i] = seqs[i].getSequenceAsString(start, end);
1704 public int[][] getVisibleRegionBoundaries(int min, int max)
1706 Vector regions = new Vector();
1712 if (hasHiddenColumns)
1716 start = colSel.adjustForHiddenColumns(start);
1719 end = colSel.getHiddenBoundaryRight(start);
1730 regions.addElement(new int[]
1733 if (hasHiddenColumns)
1735 start = colSel.adjustForHiddenColumns(end);
1736 start = colSel.getHiddenBoundaryLeft(start) + 1;
1738 } while (end < max);
1740 int[][] startEnd = new int[regions.size()][2];
1742 regions.copyInto(startEnd);
1748 public boolean getShowHiddenMarkers()
1750 return showHiddenMarkers;
1753 public void setShowHiddenMarkers(boolean show)
1755 showHiddenMarkers = show;
1758 public String getSequenceSetId()
1760 if (sequenceSetID == null)
1762 sequenceSetID = alignment.hashCode() + "";
1765 return sequenceSetID;
1769 * unique viewId for synchronizing state with stored Jalview Project
1772 private String viewId = null;
1774 public String getViewId()
1778 viewId = this.getSequenceSetId() + "." + this.hashCode() + "";
1783 public void alignmentChanged(AlignmentPanel ap)
1787 alignment.padGaps();
1789 if (hconsensus != null && autoCalculateConsensus)
1791 updateConservation(ap);
1793 if (autoCalculateConsensus)
1795 updateConsensus(ap);
1798 // Reset endRes of groups if beyond alignment width
1799 int alWidth = alignment.getWidth();
1800 Vector groups = alignment.getGroups();
1803 for (int i = 0; i < groups.size(); i++)
1805 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1806 if (sg.getEndRes() > alWidth)
1808 sg.setEndRes(alWidth - 1);
1813 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1815 selectionGroup.setEndRes(alWidth - 1);
1818 resetAllColourSchemes();
1820 // alignment.adjustSequenceAnnotations();
1823 void resetAllColourSchemes()
1825 ColourSchemeI cs = globalColourScheme;
1828 if (cs instanceof ClustalxColourScheme)
1830 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1831 alignment.getWidth());
1834 cs.setConsensus(hconsensus);
1835 if (cs.conservationApplied())
1837 Alignment al = (Alignment) alignment;
1838 Conservation c = new Conservation("All",
1839 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1842 c.verdict(false, ConsPercGaps);
1844 cs.setConservation(c);
1848 int s, sSize = alignment.getGroups().size();
1849 for (s = 0; s < sSize; s++)
1851 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1852 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1854 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1855 .getSequences(hiddenRepSequences), sg.getWidth());
1857 sg.recalcConservation();
1861 public Color getSequenceColour(SequenceI seq)
1863 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1869 return (Color) sequenceColours.get(seq);
1873 public void setSequenceColour(SequenceI seq, Color col)
1875 if (sequenceColours == null)
1877 sequenceColours = new Hashtable();
1882 sequenceColours.remove(seq);
1886 sequenceColours.put(seq, col);
1891 * returns the visible column regions of the alignment
1893 * @param selectedRegionOnly
1894 * true to just return the contigs intersecting with the selected
1898 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1900 int[] viscontigs = null;
1901 int start = 0, end = 0;
1902 if (selectedRegionOnly && selectionGroup != null)
1904 start = selectionGroup.getStartRes();
1905 end = selectionGroup.getEndRes() + 1;
1909 end = alignment.getWidth();
1911 viscontigs = colSel.getVisibleContigs(start, end);
1916 * get hash of undo and redo list for the alignment
1918 * @return long[] { historyList.hashCode, redoList.hashCode };
1920 public long[] getUndoRedoHash()
1922 if (historyList == null || redoList == null)
1926 { historyList.hashCode(), this.redoList.hashCode() };
1930 * test if a particular set of hashcodes are different to the hashcodes for
1931 * the undo and redo list.
1934 * the stored set of hashcodes as returned by getUndoRedoHash
1935 * @return true if the hashcodes differ (ie the alignment has been edited) or
1936 * the stored hashcode array differs in size
1938 public boolean isUndoRedoHashModified(long[] undoredo)
1940 if (undoredo == null)
1944 long[] cstate = getUndoRedoHash();
1945 if (cstate.length != undoredo.length)
1950 for (int i = 0; i < cstate.length; i++)
1952 if (cstate[i] != undoredo[i])
1960 public boolean getCentreColumnLabels()
1962 return centreColumnLabels;
1965 public void setCentreColumnLabels(boolean centrecolumnlabels)
1967 centreColumnLabels = centrecolumnlabels;
1970 public void updateSequenceIdColours()
1972 Vector groups = alignment.getGroups();
1973 if (sequenceColours == null)
1975 sequenceColours = new Hashtable();
1977 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
1979 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
1980 if (sg.idColour != null)
1982 Vector sqs = sg.getSequences(hiddenRepSequences);
1983 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
1985 sequenceColours.put(sqs.elementAt(s), sg.idColour);
1992 * enable or disable the display of Database Cross References in the sequence
1995 public void setShowDbRefs(boolean show)
2002 * @return true if Database References are to be displayed on tooltips.
2004 public boolean isShowDbRefs()
2011 * @return true if Non-positional features are to be displayed on tooltips.
2013 public boolean isShowNpFeats()
2019 * enable or disable the display of Non-Positional sequence features in the
2020 * sequence ID tooltip
2024 public void setShowNpFeats(boolean show)
2031 * @return true if view has hidden rows
2033 public boolean hasHiddenRows()
2035 return hasHiddenRows;
2040 * @return true if view has hidden columns
2042 public boolean hasHiddenColumns()
2044 return hasHiddenColumns;
2048 * when set, view will scroll to show the highlighted position
2050 public boolean followHighlight = true;
2053 * @return true if view should scroll to show the highlighted region of a
2057 public boolean getFollowHighlight()
2059 return followHighlight;
2062 public boolean followSelection = true;
2065 * @return true if view selection should always follow the selections
2066 * broadcast by other selection sources
2068 public boolean getFollowSelection()
2070 return followSelection;
2073 private long sgrouphash = -1, colselhash = -1;
2075 boolean showSeqFeaturesHeight;
2078 * checks current SelectionGroup against record of last hash value, and
2081 * @return true if SelectionGroup changed since last call
2083 boolean isSelectionGroupChanged()
2085 int hc = (selectionGroup == null) ? -1 : selectionGroup.hashCode();
2086 if (hc != sgrouphash)
2095 * checks current colsel against record of last hash value, and updates
2098 * @return true if colsel changed since last call
2100 boolean isColSelChanged()
2102 int hc = (colSel == null) ? -1 : colSel.hashCode();
2103 if (hc != colselhash)
2111 public void sendSelection()
2113 jalview.structure.StructureSelectionManager
2114 .getStructureSelectionManager().sendSelection(
2115 new SequenceGroup(getSelectionGroup()),
2116 new ColumnSelection(getColumnSelection()), this);
2119 public void setShowSequenceFeaturesHeight(boolean selected)
2121 showSeqFeaturesHeight = selected;
2124 public boolean getShowSequenceFeaturesHeight()
2126 return showSeqFeaturesHeight;
2129 boolean showUnconserved = false;
2131 public boolean getShowUnconserved()
2133 return showUnconserved;
2136 public void setShowUnconserved(boolean showunconserved)
2138 showUnconserved = showunconserved;
2142 * return the alignPanel containing the given viewport. Use this to get the
2143 * components currently handling the given viewport.
2146 * @return null or an alignPanel guaranteed to have non-null alignFrame
2149 public AlignmentPanel getAlignPanel()
2151 AlignmentPanel[] aps = PaintRefresher.getAssociatedPanels(this
2152 .getSequenceSetId());
2153 AlignmentPanel ap = null;
2154 for (int p = 0; aps != null && p < aps.length; p++)
2156 if (aps[p].av == this)
2164 public boolean getSortByTree()
2169 public void setSortByTree(boolean sort)
2175 * should conservation rows be shown for groups
2177 boolean showGroupConservation = false;
2180 * should consensus rows be shown for groups
2182 boolean showGroupConsensus = false;
2185 * should consensus profile be rendered by default
2187 public boolean showSequenceLogo = false;
2190 * should consensus histograms be rendered by default
2192 public boolean showConsensusHistogram = true;
2195 * @return the showConsensusProfile
2197 public boolean isShowSequenceLogo()
2199 return showSequenceLogo;
2203 * @param showSequenceLogo
2206 public void setShowSequenceLogo(boolean showSequenceLogo)
2208 this.showSequenceLogo = showSequenceLogo;
2212 * @param showConsensusHistogram
2213 * the showConsensusHistogram to set
2215 public void setShowConsensusHistogram(boolean showConsensusHistogram)
2217 this.showConsensusHistogram = showConsensusHistogram;
2221 * @return the showGroupConservation
2223 public boolean isShowGroupConservation()
2225 return showGroupConservation;
2229 * @param showGroupConservation
2230 * the showGroupConservation to set
2232 public void setShowGroupConservation(boolean showGroupConservation)
2234 this.showGroupConservation = showGroupConservation;
2238 * @return the showGroupConsensus
2240 public boolean isShowGroupConsensus()
2242 return showGroupConsensus;
2246 * @param showGroupConsensus
2247 * the showGroupConsensus to set
2249 public void setShowGroupConsensus(boolean showGroupConsensus)
2251 this.showGroupConsensus = showGroupConsensus;
2255 * @return the includeAllConsensusSymbols
2257 public boolean isIncludeAllConsensusSymbols()
2259 return includeAllConsensusSymbols;
2263 * @param includeAllConsensusSymbols
2264 * the includeAllConsensusSymbols to set
2266 public void setIncludeAllConsensusSymbols(
2267 boolean includeAllConsensusSymbols)
2269 this.includeAllConsensusSymbols = includeAllConsensusSymbols;
2274 * @return flag to indicate if the consensus histogram should be rendered by
2277 public boolean isShowConsensusHistogram()
2279 return this.showConsensusHistogram;
2283 * synthesize a column selection if none exists so it covers the given
2284 * selection group. if wholewidth is false, no column selection is made if the
2285 * selection group covers the whole alignment width.
2290 public void expandColSelection(SequenceGroup sg, boolean wholewidth)
2294 && (sgs = sg.getStartRes()) >= 0
2295 && sg.getStartRes() <= (sge = sg.getEndRes())
2296 && (colSel == null || colSel.getSelected() == null || colSel
2297 .getSelected().size() == 0))
2299 if (!wholewidth && alignment.getWidth() == (1 + sge - sgs))
2306 colSel = new ColumnSelection();
2308 for (int cspos = sg.getStartRes(); cspos <= sg.getEndRes(); cspos++)
2310 colSel.addElement(cspos);