2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 * Jalview - A Sequence Alignment Editor and Viewer
21 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
23 * This program is free software; you can redistribute it and/or
24 * modify it under the terms of the GNU General Public License
25 * as published by the Free Software Foundation; either version 2
26 * of the License, or (at your option) any later version.
28 * This program is distributed in the hope that it will be useful,
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 * GNU General Public License for more details.
33 * You should have received a copy of the GNU General Public License
34 * along with this program; if not, write to the Free Software
35 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
43 import jalview.analysis.*;
47 import jalview.datamodel.*;
49 import jalview.schemes.*;
50 import jalview.structure.SelectionSource;
51 import jalview.structure.StructureSelectionManager;
59 public class AlignViewport implements SelectionSource
61 private static final int RIGHT_JUSTIFY = 1;
71 boolean showJVSuffix = true;
73 boolean showText = true;
75 boolean showColourText = false;
77 boolean showBoxes = true;
79 boolean wrapAlignment = false;
81 boolean renderGaps = true;
83 boolean showSequenceFeatures = false;
85 boolean showAnnotation = true;
87 boolean colourAppliesToAllGroups = true;
89 ColourSchemeI globalColourScheme = null;
91 boolean conservationColourSelected = false;
93 boolean abovePIDThreshold = false;
95 SequenceGroup selectionGroup;
101 boolean validCharWidth;
107 boolean seqNameItalics;
109 AlignmentI alignment;
111 ColumnSelection colSel = new ColumnSelection();
117 NJTree currentTree = null;
119 boolean scaleAboveWrapped = false;
121 boolean scaleLeftWrapped = true;
123 boolean scaleRightWrapped = true;
125 boolean hasHiddenColumns = false;
127 boolean hasHiddenRows = false;
129 boolean showHiddenMarkers = true;
131 boolean cursorMode = false;
133 // The following vector holds the features which are
134 // currently visible, in the correct order or rendering
135 Hashtable featuresDisplayed = null;
138 public Hashtable[] hconsensus;
140 AlignmentAnnotation consensus;
142 AlignmentAnnotation conservation;
144 AlignmentAnnotation quality;
146 boolean autoCalculateConsensus = true;
149 public int ConsPercGaps = 25; // JBPNote : This should be a scalable property!
151 // JBPNote Prolly only need this in the applet version.
152 private java.beans.PropertyChangeSupport changeSupport = new java.beans.PropertyChangeSupport(
155 boolean ignoreGapsInConsensusCalculation = false;
157 boolean isDataset = false;
159 boolean antiAlias = false;
161 boolean padGaps = false;
163 Rectangle explodedPosition;
167 String sequenceSetID;
169 boolean gatherViewsHere = false;
171 Stack historyList = new Stack();
173 Stack redoList = new Stack();
175 Hashtable sequenceColours;
177 int thresholdTextColour = 0;
179 Color textColour = Color.black;
181 Color textColour2 = Color.white;
183 boolean rightAlignIds = false;
185 Hashtable hiddenRepSequences;
188 * Creates a new AlignViewport object.
190 * @param al alignment to view
192 public AlignViewport(AlignmentI al)
198 * Create a new AlignViewport object with a specific sequence set ID
200 * @param seqsetid (may be null - but potential for ambiguous constructor exception)
202 public AlignViewport(AlignmentI al, String seqsetid)
204 this(al,seqsetid,null);
206 public AlignViewport(AlignmentI al, String seqsetid, String viewid)
208 sequenceSetID = seqsetid;
210 // TODO remove these once 2.4.VAMSAS release finished
211 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
212 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
218 * Create a new AlignViewport with hidden regions
222 * @param hiddenColumns
225 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns)
228 if (hiddenColumns != null)
230 this.colSel = hiddenColumns;
231 if (hiddenColumns.getHiddenColumns() != null)
233 hasHiddenColumns = true;
239 * New viewport with hidden columns and an existing sequence set id
241 * @param hiddenColumns
242 * @param seqsetid (may be null)
244 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid)
246 this(al,hiddenColumns,seqsetid,null);
249 * New viewport with hidden columns and an existing sequence set id and viewid
251 * @param hiddenColumns
252 * @param seqsetid (may be null)
253 * @param viewid (may be null)
255 public AlignViewport(AlignmentI al, ColumnSelection hiddenColumns, String seqsetid, String viewid)
257 sequenceSetID = seqsetid;
259 // TODO remove these once 2.4.VAMSAS release finished
260 if (Cache.log!=null && Cache.log.isDebugEnabled() && seqsetid!=null) { Cache.log.debug("Setting viewport's sequence set id : "+sequenceSetID); }
261 if (Cache.log!=null && Cache.log.isDebugEnabled() && viewId!=null) { Cache.log.debug("Setting viewport's view id : "+viewId); }
263 if (hiddenColumns != null)
265 this.colSel = hiddenColumns;
266 if (hiddenColumns.getHiddenColumns() != null)
268 hasHiddenColumns = true;
277 this.endRes = alignment.getWidth() - 1;
279 this.endSeq = alignment.getHeight() - 1;
281 antiAlias = Cache.getDefault("ANTI_ALIAS", false);
283 showJVSuffix = Cache.getDefault("SHOW_JVSUFFIX", true);
284 showAnnotation = Cache.getDefault("SHOW_ANNOTATIONS", true);
286 rightAlignIds = Cache.getDefault("RIGHT_ALIGN_IDS", false);
287 centreColumnLabels = Cache.getDefault("CENTRE_COLUMN_LABELS", false);
288 autoCalculateConsensus = Cache.getDefault("AUTO_CALC_CONSENSUS", true);
290 padGaps = Cache.getDefault("PAD_GAPS", true);
291 shownpfeats = Cache.getDefault("SHOW_NPFEATS_TOOLTIP",true);
292 showdbrefs = Cache.getDefault("SHOW_DBREFS_TOOLTIP",true);
294 String fontName = Cache.getDefault("FONT_NAME", "SansSerif");
295 String fontStyle = Cache.getDefault("FONT_STYLE", Font.PLAIN + "");
296 String fontSize = Cache.getDefault("FONT_SIZE", "10");
298 seqNameItalics = Cache.getDefault("ID_ITALICS", true);
302 if (fontStyle.equals("bold"))
306 else if (fontStyle.equals("italic"))
311 setFont(new Font(fontName, style, Integer.parseInt(fontSize)));
314 .setGapCharacter(Cache.getDefault("GAP_SYMBOL", "-").charAt(0));
316 // We must set conservation and consensus before setting colour,
317 // as Blosum and Clustal require this to be done
318 if (hconsensus == null && !isDataset)
320 if (!alignment.isNucleotide())
322 conservation = new AlignmentAnnotation("Conservation",
323 "Conservation of total alignment less than " + ConsPercGaps
324 + "% gaps", new Annotation[1], 0f, 11f,
325 AlignmentAnnotation.BAR_GRAPH);
326 conservation.hasText = true;
327 conservation.autoCalculated = true;
329 if (Cache.getDefault("SHOW_CONSERVATION", true))
331 alignment.addAnnotation(conservation);
334 if (Cache.getDefault("SHOW_QUALITY", true))
336 quality = new AlignmentAnnotation("Quality",
337 "Alignment Quality based on Blosum62 scores",
338 new Annotation[1], 0f, 11f, AlignmentAnnotation.BAR_GRAPH);
339 quality.hasText = true;
340 quality.autoCalculated = true;
342 alignment.addAnnotation(quality);
345 // TODO: add menu option action that nulls or creates consensus object depending on if the user wants to see the annotation or not in a specific alignment
346 consensus = new AlignmentAnnotation("Consensus", "PID",
347 new Annotation[1], 0f, 100f, AlignmentAnnotation.BAR_GRAPH);
348 consensus.hasText = true;
349 consensus.autoCalculated = true;
351 if (Cache.getDefault("SHOW_IDENTITY", true))
353 alignment.addAnnotation(consensus);
357 if (jalview.bin.Cache.getProperty("DEFAULT_COLOUR") != null)
359 globalColourScheme = ColourSchemeProperty.getColour(alignment,
360 jalview.bin.Cache.getProperty("DEFAULT_COLOUR"));
362 if (globalColourScheme instanceof UserColourScheme)
364 globalColourScheme = UserDefinedColours.loadDefaultColours();
365 ((UserColourScheme) globalColourScheme).setThreshold(0,
366 getIgnoreGapsConsensus());
369 if (globalColourScheme != null)
371 globalColourScheme.setConsensus(hconsensus);
375 wrapAlignment = jalview.bin.Cache.getDefault("WRAP_ALIGNMENT", false);
376 showUnconserved = jalview.bin.Cache.getDefault("SHOW_UNCONSERVED", false);
385 public void setShowSequenceFeatures(boolean b)
387 showSequenceFeatures = b;
390 public boolean getShowSequenceFeatures()
392 return showSequenceFeatures;
395 class ConservationThread extends Thread
399 public ConservationThread(AlignmentPanel ap)
408 updatingConservation = true;
410 while (UPDATING_CONSERVATION)
416 ap.paintAlignment(false);
419 } catch (Exception ex)
421 ex.printStackTrace();
425 UPDATING_CONSERVATION = true;
427 int alWidth = alignment.getWidth();
433 Conservation cons = new jalview.analysis.Conservation("All",
434 jalview.schemes.ResidueProperties.propHash, 3, alignment
435 .getSequences(), 0, alWidth - 1);
438 cons.verdict(false, ConsPercGaps);
445 char[] sequence = cons.getConsSequence().getSequence();
457 maxB = 0f - minB; // scalable range for colouring both Conservation and
467 conservation.annotations = new Annotation[alWidth];
471 quality.graphMax = cons.qualityRange[1].floatValue();
472 quality.annotations = new Annotation[alWidth];
473 qmin = cons.qualityRange[0].floatValue();
474 qmax = cons.qualityRange[1].floatValue();
477 for (int i = 0; i < alWidth; i++)
483 if (Character.isDigit(c))
485 value = (int) (c - '0');
496 float vprop = value - min;
498 conservation.annotations[i] = new Annotation(String.valueOf(c),
499 String.valueOf(value), ' ', value, new Color(minR
500 + (maxR * vprop), minG + (maxG * vprop), minB
506 value = ((Double) cons.quality.get(i)).floatValue();
507 vprop = value - qmin;
509 quality.annotations[i] = new Annotation(" ", String
510 .valueOf(value), ' ', value, new Color(minR
511 + (maxR * vprop), minG + (maxG * vprop), minB
515 } catch (OutOfMemoryError error)
517 new OOMWarning("calculating conservation", error);
524 UPDATING_CONSERVATION = false;
525 updatingConservation = false;
529 ap.paintAlignment(true);
535 ConservationThread conservationThread;
537 ConsensusThread consensusThread;
539 boolean consUpdateNeeded = false;
541 static boolean UPDATING_CONSENSUS = false;
543 static boolean UPDATING_CONSERVATION = false;
545 boolean updatingConsensus = false;
547 boolean updatingConservation = false;
550 * centre columnar annotation labels in displayed alignment annotation TODO:
551 * add to jalviewXML and annotation display settings
553 boolean centreColumnLabels = false;
555 private boolean showdbrefs;
557 private boolean shownpfeats;
560 * trigger update of conservation annotation
562 public void updateConservation(final AlignmentPanel ap)
564 // see note in mantis : issue number 8585
565 if (alignment.isNucleotide() || conservation == null || !autoCalculateConsensus)
570 conservationThread = new ConservationThread(ap);
571 conservationThread.start();
575 * trigger update of consensus annotation
577 public void updateConsensus(final AlignmentPanel ap)
579 // see note in mantis : issue number 8585
580 if (consensus == null || !autoCalculateConsensus)
584 consensusThread = new ConsensusThread(ap);
585 consensusThread.start();
588 class ConsensusThread extends Thread
592 public ConsensusThread(AlignmentPanel ap)
599 updatingConsensus = true;
600 while (UPDATING_CONSENSUS)
606 ap.paintAlignment(false);
610 } catch (Exception ex)
612 ex.printStackTrace();
616 UPDATING_CONSENSUS = true;
620 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
629 consensus.annotations = null;
630 consensus.annotations = new Annotation[aWidth];
632 hconsensus = new Hashtable[aWidth];
633 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
634 .getWidth(), hconsensus);
636 for (int i = 0; i < aWidth; i++)
639 if (ignoreGapsInConsensusCalculation)
641 value = ((Float) hconsensus[i].get(AAFrequency.PID_NOGAPS))
646 value = ((Float) hconsensus[i].get(AAFrequency.PID_GAPS))
650 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE)
652 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE)
655 if (maxRes.length() > 1)
657 mouseOver = "[" + maxRes + "] ";
661 mouseOver += ((int) value + "%");
662 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
666 if (globalColourScheme != null)
668 globalColourScheme.setConsensus(hconsensus);
671 } catch (OutOfMemoryError error)
673 alignment.deleteAnnotation(consensus);
677 new OOMWarning("calculating consensus", error);
679 UPDATING_CONSENSUS = false;
680 updatingConsensus = false;
684 ap.paintAlignment(true);
690 * get the consensus sequence as displayed under the PID consensus annotation
693 * @return consensus sequence as a new sequence object
695 public SequenceI getConsensusSeq()
697 if (consensus == null)
699 updateConsensus(null);
701 if (consensus == null)
705 StringBuffer seqs = new StringBuffer();
706 for (int i = 0; i < consensus.annotations.length; i++)
708 if (consensus.annotations[i] != null)
710 if (consensus.annotations[i].description.charAt(0) == '[')
712 seqs.append(consensus.annotations[i].description.charAt(1));
716 seqs.append(consensus.annotations[i].displayCharacter);
721 SequenceI sq = new Sequence("Consensus", seqs.toString());
722 sq.setDescription("Percentage Identity Consensus "
723 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
730 * @return DOCUMENT ME!
732 public SequenceGroup getSelectionGroup()
734 return selectionGroup;
743 public void setSelectionGroup(SequenceGroup sg)
751 * @return DOCUMENT ME!
753 public boolean getConservationSelected()
755 return conservationColourSelected;
764 public void setConservationSelected(boolean b)
766 conservationColourSelected = b;
772 * @return DOCUMENT ME!
774 public boolean getAbovePIDThreshold()
776 return abovePIDThreshold;
785 public void setAbovePIDThreshold(boolean b)
787 abovePIDThreshold = b;
793 * @return DOCUMENT ME!
795 public int getStartRes()
803 * @return DOCUMENT ME!
805 public int getEndRes()
813 * @return DOCUMENT ME!
815 public int getStartSeq()
826 public void setGlobalColourScheme(ColourSchemeI cs)
828 globalColourScheme = cs;
834 * @return DOCUMENT ME!
836 public ColourSchemeI getGlobalColourScheme()
838 return globalColourScheme;
847 public void setStartRes(int res)
858 public void setStartSeq(int seq)
869 public void setEndRes(int res)
871 if (res > (alignment.getWidth() - 1))
873 // log.System.out.println(" Corrected res from " + res + " to maximum " +
874 // (alignment.getWidth()-1));
875 res = alignment.getWidth() - 1;
892 public void setEndSeq(int seq)
894 if (seq > alignment.getHeight())
896 seq = alignment.getHeight();
910 * @return DOCUMENT ME!
912 public int getEndSeq()
923 public void setFont(Font f)
927 Container c = new Container();
929 java.awt.FontMetrics fm = c.getFontMetrics(font);
930 setCharHeight(fm.getHeight());
931 setCharWidth(fm.charWidth('M'));
932 validCharWidth = true;
938 * @return DOCUMENT ME!
940 public Font getFont()
951 public void setCharWidth(int w)
959 * @return DOCUMENT ME!
961 public int getCharWidth()
972 public void setCharHeight(int h)
980 * @return DOCUMENT ME!
982 public int getCharHeight()
993 public void setWrappedWidth(int w)
995 this.wrappedWidth = w;
1001 * @return DOCUMENT ME!
1003 public int getWrappedWidth()
1005 return wrappedWidth;
1011 * @return DOCUMENT ME!
1013 public AlignmentI getAlignment()
1024 public void setAlignment(AlignmentI align)
1026 if (alignment != null && alignment.getCodonFrames() != null)
1028 StructureSelectionManager.getStructureSelectionManager()
1029 .removeMappings(alignment.getCodonFrames());
1031 this.alignment = align;
1032 if (alignment.getCodonFrames() != null)
1034 StructureSelectionManager.getStructureSelectionManager().addMappings(
1035 alignment.getCodonFrames());
1045 public void setWrapAlignment(boolean state)
1047 wrapAlignment = state;
1056 public void setShowText(boolean state)
1067 public void setRenderGaps(boolean state)
1075 * @return DOCUMENT ME!
1077 public boolean getColourText()
1079 return showColourText;
1088 public void setColourText(boolean state)
1090 showColourText = state;
1099 public void setShowBoxes(boolean state)
1107 * @return DOCUMENT ME!
1109 public boolean getWrapAlignment()
1111 return wrapAlignment;
1117 * @return DOCUMENT ME!
1119 public boolean getShowText()
1127 * @return DOCUMENT ME!
1129 public boolean getShowBoxes()
1137 * @return DOCUMENT ME!
1139 public char getGapCharacter()
1141 return getAlignment().getGapCharacter();
1150 public void setGapCharacter(char gap)
1152 if (getAlignment() != null)
1154 getAlignment().setGapCharacter(gap);
1164 public void setThreshold(int thresh)
1172 * @return DOCUMENT ME!
1174 public int getThreshold()
1185 public void setIncrement(int inc)
1193 * @return DOCUMENT ME!
1195 public int getIncrement()
1203 * @return DOCUMENT ME!
1205 public ColumnSelection getColumnSelection()
1216 public void setCurrentTree(NJTree tree)
1224 * @return DOCUMENT ME!
1226 public NJTree getCurrentTree()
1237 public void setColourAppliesToAllGroups(boolean b)
1239 colourAppliesToAllGroups = b;
1245 * @return DOCUMENT ME!
1247 public boolean getColourAppliesToAllGroups()
1249 return colourAppliesToAllGroups;
1255 * @return DOCUMENT ME!
1257 public boolean getShowJVSuffix()
1259 return showJVSuffix;
1268 public void setShowJVSuffix(boolean b)
1276 * @return DOCUMENT ME!
1278 public boolean getShowAnnotation()
1280 return showAnnotation;
1289 public void setShowAnnotation(boolean b)
1297 * @return DOCUMENT ME!
1299 public boolean getScaleAboveWrapped()
1301 return scaleAboveWrapped;
1307 * @return DOCUMENT ME!
1309 public boolean getScaleLeftWrapped()
1311 return scaleLeftWrapped;
1317 * @return DOCUMENT ME!
1319 public boolean getScaleRightWrapped()
1321 return scaleRightWrapped;
1330 public void setScaleAboveWrapped(boolean b)
1332 scaleAboveWrapped = b;
1341 public void setScaleLeftWrapped(boolean b)
1343 scaleLeftWrapped = b;
1352 public void setScaleRightWrapped(boolean b)
1354 scaleRightWrapped = b;
1358 * Property change listener for changes in alignment
1363 public void addPropertyChangeListener(
1364 java.beans.PropertyChangeListener listener)
1366 changeSupport.addPropertyChangeListener(listener);
1375 public void removePropertyChangeListener(
1376 java.beans.PropertyChangeListener listener)
1378 changeSupport.removePropertyChangeListener(listener);
1382 * Property change listener for changes in alignment
1391 public void firePropertyChange(String prop, Object oldvalue,
1394 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1397 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1399 ignoreGapsInConsensusCalculation = b;
1400 updateConsensus(ap);
1401 if (globalColourScheme != null)
1403 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1404 ignoreGapsInConsensusCalculation);
1408 public boolean getIgnoreGapsConsensus()
1410 return ignoreGapsInConsensusCalculation;
1413 public void setDataset(boolean b)
1418 public boolean isDataset()
1423 public void hideSelectedColumns()
1425 if (colSel.size() < 1)
1430 colSel.hideSelectedColumns();
1431 setSelectionGroup(null);
1433 hasHiddenColumns = true;
1436 public void hideColumns(int start, int end)
1440 colSel.hideColumns(start);
1444 colSel.hideColumns(start, end);
1447 hasHiddenColumns = true;
1450 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1452 int sSize = sg.getSize();
1458 if (hiddenRepSequences == null)
1460 hiddenRepSequences = new Hashtable();
1463 hiddenRepSequences.put(repSequence, sg);
1465 // Hide all sequences except the repSequence
1466 SequenceI[] seqs = new SequenceI[sSize - 1];
1468 for (int i = 0; i < sSize; i++)
1470 if (sg.getSequenceAt(i) != repSequence)
1472 if (index == sSize - 1)
1477 seqs[index++] = sg.getSequenceAt(i);
1480 sg.setSeqrep(repSequence);
1481 sg.setHidereps(true);
1486 public void hideAllSelectedSeqs()
1488 if (selectionGroup == null || selectionGroup.getSize() < 1)
1493 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1497 setSelectionGroup(null);
1500 public void hideSequence(SequenceI[] seq)
1504 for (int i = 0; i < seq.length; i++)
1506 alignment.getHiddenSequences().hideSequence(seq[i]);
1508 hasHiddenRows = true;
1509 firePropertyChange("alignment", null, alignment.getSequences());
1513 public void showSequence(int index)
1515 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1516 hiddenRepSequences);
1519 if (selectionGroup == null)
1521 selectionGroup = new SequenceGroup();
1522 selectionGroup.setEndRes(alignment.getWidth() - 1);
1525 for (int t = 0; t < tmp.size(); t++)
1527 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1529 firePropertyChange("alignment", null, alignment.getSequences());
1533 if (alignment.getHiddenSequences().getSize() < 1)
1535 hasHiddenRows = false;
1539 public void showColumn(int col)
1541 colSel.revealHiddenColumns(col);
1542 if (colSel.getHiddenColumns() == null)
1544 hasHiddenColumns = false;
1548 public void showAllHiddenColumns()
1550 colSel.revealAllHiddenColumns();
1551 hasHiddenColumns = false;
1554 public void showAllHiddenSeqs()
1556 if (alignment.getHiddenSequences().getSize() > 0)
1558 if (selectionGroup == null)
1560 selectionGroup = new SequenceGroup();
1561 selectionGroup.setEndRes(alignment.getWidth() - 1);
1563 Vector tmp = alignment.getHiddenSequences().showAll(
1564 hiddenRepSequences);
1565 for (int t = 0; t < tmp.size(); t++)
1567 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1569 firePropertyChange("alignment", null, alignment.getSequences());
1571 hasHiddenRows = false;
1572 hiddenRepSequences = null;
1576 public void invertColumnSelection()
1578 colSel.invertColumnSelection(0, alignment.getWidth());
1581 public int adjustForHiddenSeqs(int alignmentIndex)
1583 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1588 * This method returns an array of new SequenceI objects derived from the
1589 * whole alignment or just the current selection with start and end points
1592 * @note if you need references to the actual SequenceI objects in the
1593 * alignment or currently selected then use getSequenceSelection()
1594 * @return selection as new sequenceI objects
1596 public SequenceI[] getSelectionAsNewSequence()
1598 SequenceI[] sequences;
1600 if (selectionGroup == null)
1602 sequences = alignment.getSequencesArray();
1603 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1604 for (int i = 0; i < sequences.length; i++)
1606 sequences[i] = new Sequence(sequences[i], annots); // construct new
1608 // subset of visible
1614 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1621 * get the currently selected sequence objects or all the sequences in the
1624 * @return array of references to sequence objects
1626 public SequenceI[] getSequenceSelection()
1628 SequenceI[] sequences=null;
1629 if (selectionGroup!=null)
1631 sequences = selectionGroup.getSequencesInOrder(alignment);
1633 if (sequences == null)
1635 sequences = alignment.getSequencesArray();
1641 * This method returns the visible alignment as text, as seen on the GUI, ie
1642 * if columns are hidden they will not be returned in the result. Use this for
1643 * calculating trees, PCA, redundancy etc on views which contain hidden
1648 public jalview.datamodel.CigarArray getViewAsCigars(
1649 boolean selectedRegionOnly)
1651 CigarArray selection = null;
1652 SequenceI[] seqs = null;
1654 int start = 0, end = 0;
1655 if (selectedRegionOnly && selectionGroup != null)
1657 iSize = selectionGroup.getSize();
1658 seqs = selectionGroup.getSequencesInOrder(alignment);
1659 start = selectionGroup.getStartRes();
1660 end = selectionGroup.getEndRes(); // inclusive for start and end in
1661 // SeqCigar constructor
1665 iSize = alignment.getHeight();
1666 seqs = alignment.getSequencesArray();
1667 end = alignment.getWidth() - 1;
1669 SeqCigar[] selseqs = new SeqCigar[iSize];
1670 for (i = 0; i < iSize; i++)
1672 selseqs[i] = new SeqCigar(seqs[i], start, end);
1674 selection = new CigarArray(selseqs);
1675 // now construct the CigarArray operations
1676 if (hasHiddenColumns)
1678 Vector regions = colSel.getHiddenColumns();
1680 int hideStart, hideEnd;
1682 for (int j = 0; last < end & j < regions.size(); j++)
1684 region = (int[]) regions.elementAt(j);
1685 hideStart = region[0];
1686 hideEnd = region[1];
1687 // edit hidden regions to selection range
1688 if (hideStart < last)
1700 if (hideStart > end)
1710 if (hideStart > hideEnd)
1715 * form operations...
1717 if (last < hideStart)
1719 selection.addOperation(CigarArray.M, hideStart - last);
1721 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1724 // Final match if necessary.
1727 selection.addOperation(CigarArray.M, end - last + 1);
1732 selection.addOperation(CigarArray.M, end - start + 1);
1738 * return a compact representation of the current alignment selection to pass
1739 * to an analysis function
1741 * @param selectedOnly
1742 * boolean true to just return the selected view
1743 * @return AlignmentView
1745 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1748 // this is here because the AlignmentView constructor modifies the
1750 // object. Refactoring of Cigar and alignment view representation should
1751 // be done to remove redundancy.
1752 CigarArray aligview = getViewAsCigars(selectedOnly);
1753 if (aligview != null)
1755 return new AlignmentView(aligview,
1756 (selectedOnly && selectionGroup != null) ? selectionGroup
1757 .getStartRes() : 0);
1763 * This method returns the visible alignment as text, as seen on the GUI, ie
1764 * if columns are hidden they will not be returned in the result. Use this for
1765 * calculating trees, PCA, redundancy etc on views which contain hidden
1770 public String[] getViewAsString(boolean selectedRegionOnly)
1772 String[] selection = null;
1773 SequenceI[] seqs = null;
1775 int start = 0, end = 0;
1776 if (selectedRegionOnly && selectionGroup != null)
1778 iSize = selectionGroup.getSize();
1779 seqs = selectionGroup.getSequencesInOrder(alignment);
1780 start = selectionGroup.getStartRes();
1781 end = selectionGroup.getEndRes() + 1;
1785 iSize = alignment.getHeight();
1786 seqs = alignment.getSequencesArray();
1787 end = alignment.getWidth();
1790 selection = new String[iSize];
1791 if (hasHiddenColumns)
1793 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1797 for (i = 0; i < iSize; i++)
1799 selection[i] = seqs[i].getSequenceAsString(start, end);
1806 public int[][] getVisibleRegionBoundaries(int min, int max)
1808 Vector regions = new Vector();
1814 if (hasHiddenColumns)
1818 start = colSel.adjustForHiddenColumns(start);
1821 end = colSel.getHiddenBoundaryRight(start);
1832 regions.addElement(new int[]
1835 if (hasHiddenColumns)
1837 start = colSel.adjustForHiddenColumns(end);
1838 start = colSel.getHiddenBoundaryLeft(start) + 1;
1840 } while (end < max);
1842 int[][] startEnd = new int[regions.size()][2];
1844 regions.copyInto(startEnd);
1850 public boolean getShowHiddenMarkers()
1852 return showHiddenMarkers;
1855 public void setShowHiddenMarkers(boolean show)
1857 showHiddenMarkers = show;
1860 public String getSequenceSetId()
1862 if (sequenceSetID == null)
1864 sequenceSetID = alignment.hashCode() + "";
1867 return sequenceSetID;
1870 * unique viewId for synchronizing state with stored Jalview Project
1873 private String viewId=null;
1876 public String getViewId()
1880 viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1885 public void alignmentChanged(AlignmentPanel ap)
1889 alignment.padGaps();
1891 if (hconsensus != null && autoCalculateConsensus)
1893 updateConservation(ap);
1895 if (autoCalculateConsensus)
1897 updateConsensus(ap);
1900 // Reset endRes of groups if beyond alignment width
1901 int alWidth = alignment.getWidth();
1902 Vector groups = alignment.getGroups();
1905 for (int i = 0; i < groups.size(); i++)
1907 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1908 if (sg.getEndRes() > alWidth)
1910 sg.setEndRes(alWidth - 1);
1915 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1917 selectionGroup.setEndRes(alWidth - 1);
1920 resetAllColourSchemes();
1922 // alignment.adjustSequenceAnnotations();
1925 void resetAllColourSchemes()
1927 ColourSchemeI cs = globalColourScheme;
1930 if (cs instanceof ClustalxColourScheme)
1932 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1933 alignment.getWidth());
1936 cs.setConsensus(hconsensus);
1937 if (cs.conservationApplied())
1939 Alignment al = (Alignment) alignment;
1940 Conservation c = new Conservation("All",
1941 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1944 c.verdict(false, ConsPercGaps);
1946 cs.setConservation(c);
1950 int s, sSize = alignment.getGroups().size();
1951 for (s = 0; s < sSize; s++)
1953 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1954 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1956 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1957 .getSequences(hiddenRepSequences), sg.getWidth());
1959 sg.recalcConservation();
1963 public Color getSequenceColour(SequenceI seq)
1965 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1971 return (Color) sequenceColours.get(seq);
1975 public void setSequenceColour(SequenceI seq, Color col)
1977 if (sequenceColours == null)
1979 sequenceColours = new Hashtable();
1984 sequenceColours.remove(seq);
1988 sequenceColours.put(seq, col);
1993 * returns the visible column regions of the alignment
1995 * @param selectedRegionOnly
1996 * true to just return the contigs intersecting with the
2000 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
2002 int[] viscontigs = null;
2003 int start = 0, end = 0;
2004 if (selectedRegionOnly && selectionGroup != null)
2006 start = selectionGroup.getStartRes();
2007 end = selectionGroup.getEndRes() + 1;
2011 end = alignment.getWidth();
2013 viscontigs = colSel.getVisibleContigs(start, end);
2018 * get hash of undo and redo list for the alignment
2020 * @return long[] { historyList.hashCode, redoList.hashCode };
2022 public long[] getUndoRedoHash()
2024 if (historyList == null || redoList == null)
2028 { historyList.hashCode(), this.redoList.hashCode() };
2032 * test if a particular set of hashcodes are different to the hashcodes for
2033 * the undo and redo list.
2036 * the stored set of hashcodes as returned by getUndoRedoHash
2037 * @return true if the hashcodes differ (ie the alignment has been edited) or
2038 * the stored hashcode array differs in size
2040 public boolean isUndoRedoHashModified(long[] undoredo)
2042 if (undoredo == null)
2046 long[] cstate = getUndoRedoHash();
2047 if (cstate.length != undoredo.length)
2052 for (int i = 0; i < cstate.length; i++)
2054 if (cstate[i] != undoredo[i])
2062 public boolean getCentreColumnLabels()
2064 return centreColumnLabels;
2067 public void setCentreColumnLabels(boolean centrecolumnlabels)
2069 centreColumnLabels = centrecolumnlabels;
2072 public void updateSequenceIdColours()
2074 Vector groups = alignment.getGroups();
2075 if (sequenceColours == null)
2077 sequenceColours = new Hashtable();
2079 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
2081 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
2082 if (sg.idColour != null)
2084 Vector sqs = sg.getSequences(hiddenRepSequences);
2085 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2087 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2094 * enable or disable the display of Database Cross References in the sequence ID tooltip
2096 public void setShowDbRefs(boolean show)
2103 * @return true if Database References are to be displayed on tooltips.
2105 public boolean isShowDbRefs()
2112 * @return true if Non-positional features are to be displayed on tooltips.
2114 public boolean isShowNpFeats()
2119 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
2122 public void setShowNpFeats(boolean show)
2128 * @return true if view has hidden rows
2130 public boolean hasHiddenRows()
2132 return hasHiddenRows;
2136 * @return true if view has hidden columns
2138 public boolean hasHiddenColumns()
2140 return hasHiddenColumns;
2143 * when set, view will scroll to show the highlighted position
2145 public boolean followHighlight=true;
2147 * @return true if view should scroll to show the highlighted region of a sequence
2150 public boolean getFollowHighlight() {
2151 return followHighlight;
2153 public boolean followSelection=true;
2155 * @return true if view selection should always follow the selections broadcast by other selection sources
2157 public boolean getFollowSelection() {
2158 return followSelection;
2160 private long sgrouphash=-1,colselhash=-1;
2162 boolean showSeqFeaturesHeight;
2164 * checks current SelectionGroup against record of last hash value, and updates record.
2165 * @return true if SelectionGroup changed since last call
2167 boolean isSelectionGroupChanged() {
2168 int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2177 * checks current colsel against record of last hash value, and updates record.
2178 * @return true if colsel changed since last call
2180 boolean isColSelChanged() {
2181 int hc=(colSel==null) ? -1 : colSel.hashCode();
2189 public void sendSelection()
2191 jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);
2193 public void setShowSequenceFeaturesHeight(boolean selected)
2195 showSeqFeaturesHeight = selected;
2197 public boolean getShowSequenceFeaturesHeight()
2199 return showSeqFeaturesHeight;
2201 boolean showUnconserved=false;
2202 public boolean getShowUnconserved()
2204 return showUnconserved;
2206 public void setShowUnconserved(boolean showunconserved)
2208 showUnconserved=showunconserved;