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);
384 public void setShowSequenceFeatures(boolean b)
386 showSequenceFeatures = b;
389 public boolean getShowSequenceFeatures()
391 return showSequenceFeatures;
394 class ConservationThread extends Thread
398 public ConservationThread(AlignmentPanel ap)
407 updatingConservation = true;
409 while (UPDATING_CONSERVATION)
415 ap.paintAlignment(false);
418 } catch (Exception ex)
420 ex.printStackTrace();
424 UPDATING_CONSERVATION = true;
426 int alWidth = alignment.getWidth();
432 Conservation cons = new jalview.analysis.Conservation("All",
433 jalview.schemes.ResidueProperties.propHash, 3, alignment
434 .getSequences(), 0, alWidth - 1);
437 cons.verdict(false, ConsPercGaps);
444 char[] sequence = cons.getConsSequence().getSequence();
456 maxB = 0f - minB; // scalable range for colouring both Conservation and
466 conservation.annotations = new Annotation[alWidth];
470 quality.graphMax = cons.qualityRange[1].floatValue();
471 quality.annotations = new Annotation[alWidth];
472 qmin = cons.qualityRange[0].floatValue();
473 qmax = cons.qualityRange[1].floatValue();
476 for (int i = 0; i < alWidth; i++)
482 if (Character.isDigit(c))
484 value = (int) (c - '0');
495 float vprop = value - min;
497 conservation.annotations[i] = new Annotation(String.valueOf(c),
498 String.valueOf(value), ' ', value, new Color(minR
499 + (maxR * vprop), minG + (maxG * vprop), minB
505 value = ((Double) cons.quality.get(i)).floatValue();
506 vprop = value - qmin;
508 quality.annotations[i] = new Annotation(" ", String
509 .valueOf(value), ' ', value, new Color(minR
510 + (maxR * vprop), minG + (maxG * vprop), minB
514 } catch (OutOfMemoryError error)
516 new OOMWarning("calculating conservation", error);
523 UPDATING_CONSERVATION = false;
524 updatingConservation = false;
528 ap.paintAlignment(true);
534 ConservationThread conservationThread;
536 ConsensusThread consensusThread;
538 boolean consUpdateNeeded = false;
540 static boolean UPDATING_CONSENSUS = false;
542 static boolean UPDATING_CONSERVATION = false;
544 boolean updatingConsensus = false;
546 boolean updatingConservation = false;
549 * centre columnar annotation labels in displayed alignment annotation TODO:
550 * add to jalviewXML and annotation display settings
552 boolean centreColumnLabels = false;
554 private boolean showdbrefs;
556 private boolean shownpfeats;
559 * trigger update of conservation annotation
561 public void updateConservation(final AlignmentPanel ap)
563 // see note in mantis : issue number 8585
564 if (alignment.isNucleotide() || conservation == null || !autoCalculateConsensus)
569 conservationThread = new ConservationThread(ap);
570 conservationThread.start();
574 * trigger update of consensus annotation
576 public void updateConsensus(final AlignmentPanel ap)
578 // see note in mantis : issue number 8585
579 if (consensus == null || !autoCalculateConsensus)
583 consensusThread = new ConsensusThread(ap);
584 consensusThread.start();
587 class ConsensusThread extends Thread
591 public ConsensusThread(AlignmentPanel ap)
598 updatingConsensus = true;
599 while (UPDATING_CONSENSUS)
605 ap.paintAlignment(false);
609 } catch (Exception ex)
611 ex.printStackTrace();
615 UPDATING_CONSENSUS = true;
619 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
628 consensus.annotations = null;
629 consensus.annotations = new Annotation[aWidth];
631 hconsensus = new Hashtable[aWidth];
632 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
633 .getWidth(), hconsensus);
635 for (int i = 0; i < aWidth; i++)
638 if (ignoreGapsInConsensusCalculation)
640 value = ((Float) hconsensus[i].get(AAFrequency.PID_NOGAPS))
645 value = ((Float) hconsensus[i].get(AAFrequency.PID_GAPS))
649 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE)
651 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE)
654 if (maxRes.length() > 1)
656 mouseOver = "[" + maxRes + "] ";
660 mouseOver += ((int) value + "%");
661 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
665 if (globalColourScheme != null)
667 globalColourScheme.setConsensus(hconsensus);
670 } catch (OutOfMemoryError error)
672 alignment.deleteAnnotation(consensus);
676 new OOMWarning("calculating consensus", error);
678 UPDATING_CONSENSUS = false;
679 updatingConsensus = false;
683 ap.paintAlignment(true);
689 * get the consensus sequence as displayed under the PID consensus annotation
692 * @return consensus sequence as a new sequence object
694 public SequenceI getConsensusSeq()
696 if (consensus == null)
698 updateConsensus(null);
700 if (consensus == null)
704 StringBuffer seqs = new StringBuffer();
705 for (int i = 0; i < consensus.annotations.length; i++)
707 if (consensus.annotations[i] != null)
709 if (consensus.annotations[i].description.charAt(0) == '[')
711 seqs.append(consensus.annotations[i].description.charAt(1));
715 seqs.append(consensus.annotations[i].displayCharacter);
720 SequenceI sq = new Sequence("Consensus", seqs.toString());
721 sq.setDescription("Percentage Identity Consensus "
722 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
729 * @return DOCUMENT ME!
731 public SequenceGroup getSelectionGroup()
733 return selectionGroup;
742 public void setSelectionGroup(SequenceGroup sg)
750 * @return DOCUMENT ME!
752 public boolean getConservationSelected()
754 return conservationColourSelected;
763 public void setConservationSelected(boolean b)
765 conservationColourSelected = b;
771 * @return DOCUMENT ME!
773 public boolean getAbovePIDThreshold()
775 return abovePIDThreshold;
784 public void setAbovePIDThreshold(boolean b)
786 abovePIDThreshold = b;
792 * @return DOCUMENT ME!
794 public int getStartRes()
802 * @return DOCUMENT ME!
804 public int getEndRes()
812 * @return DOCUMENT ME!
814 public int getStartSeq()
825 public void setGlobalColourScheme(ColourSchemeI cs)
827 globalColourScheme = cs;
833 * @return DOCUMENT ME!
835 public ColourSchemeI getGlobalColourScheme()
837 return globalColourScheme;
846 public void setStartRes(int res)
857 public void setStartSeq(int seq)
868 public void setEndRes(int res)
870 if (res > (alignment.getWidth() - 1))
872 // log.System.out.println(" Corrected res from " + res + " to maximum " +
873 // (alignment.getWidth()-1));
874 res = alignment.getWidth() - 1;
891 public void setEndSeq(int seq)
893 if (seq > alignment.getHeight())
895 seq = alignment.getHeight();
909 * @return DOCUMENT ME!
911 public int getEndSeq()
922 public void setFont(Font f)
926 Container c = new Container();
928 java.awt.FontMetrics fm = c.getFontMetrics(font);
929 setCharHeight(fm.getHeight());
930 setCharWidth(fm.charWidth('M'));
931 validCharWidth = true;
937 * @return DOCUMENT ME!
939 public Font getFont()
950 public void setCharWidth(int w)
958 * @return DOCUMENT ME!
960 public int getCharWidth()
971 public void setCharHeight(int h)
979 * @return DOCUMENT ME!
981 public int getCharHeight()
992 public void setWrappedWidth(int w)
994 this.wrappedWidth = w;
1000 * @return DOCUMENT ME!
1002 public int getWrappedWidth()
1004 return wrappedWidth;
1010 * @return DOCUMENT ME!
1012 public AlignmentI getAlignment()
1023 public void setAlignment(AlignmentI align)
1025 if (alignment != null && alignment.getCodonFrames() != null)
1027 StructureSelectionManager.getStructureSelectionManager()
1028 .removeMappings(alignment.getCodonFrames());
1030 this.alignment = align;
1031 if (alignment.getCodonFrames() != null)
1033 StructureSelectionManager.getStructureSelectionManager().addMappings(
1034 alignment.getCodonFrames());
1044 public void setWrapAlignment(boolean state)
1046 wrapAlignment = state;
1055 public void setShowText(boolean state)
1066 public void setRenderGaps(boolean state)
1074 * @return DOCUMENT ME!
1076 public boolean getColourText()
1078 return showColourText;
1087 public void setColourText(boolean state)
1089 showColourText = state;
1098 public void setShowBoxes(boolean state)
1106 * @return DOCUMENT ME!
1108 public boolean getWrapAlignment()
1110 return wrapAlignment;
1116 * @return DOCUMENT ME!
1118 public boolean getShowText()
1126 * @return DOCUMENT ME!
1128 public boolean getShowBoxes()
1136 * @return DOCUMENT ME!
1138 public char getGapCharacter()
1140 return getAlignment().getGapCharacter();
1149 public void setGapCharacter(char gap)
1151 if (getAlignment() != null)
1153 getAlignment().setGapCharacter(gap);
1163 public void setThreshold(int thresh)
1171 * @return DOCUMENT ME!
1173 public int getThreshold()
1184 public void setIncrement(int inc)
1192 * @return DOCUMENT ME!
1194 public int getIncrement()
1202 * @return DOCUMENT ME!
1204 public ColumnSelection getColumnSelection()
1215 public void setCurrentTree(NJTree tree)
1223 * @return DOCUMENT ME!
1225 public NJTree getCurrentTree()
1236 public void setColourAppliesToAllGroups(boolean b)
1238 colourAppliesToAllGroups = b;
1244 * @return DOCUMENT ME!
1246 public boolean getColourAppliesToAllGroups()
1248 return colourAppliesToAllGroups;
1254 * @return DOCUMENT ME!
1256 public boolean getShowJVSuffix()
1258 return showJVSuffix;
1267 public void setShowJVSuffix(boolean b)
1275 * @return DOCUMENT ME!
1277 public boolean getShowAnnotation()
1279 return showAnnotation;
1288 public void setShowAnnotation(boolean b)
1296 * @return DOCUMENT ME!
1298 public boolean getScaleAboveWrapped()
1300 return scaleAboveWrapped;
1306 * @return DOCUMENT ME!
1308 public boolean getScaleLeftWrapped()
1310 return scaleLeftWrapped;
1316 * @return DOCUMENT ME!
1318 public boolean getScaleRightWrapped()
1320 return scaleRightWrapped;
1329 public void setScaleAboveWrapped(boolean b)
1331 scaleAboveWrapped = b;
1340 public void setScaleLeftWrapped(boolean b)
1342 scaleLeftWrapped = b;
1351 public void setScaleRightWrapped(boolean b)
1353 scaleRightWrapped = b;
1357 * Property change listener for changes in alignment
1362 public void addPropertyChangeListener(
1363 java.beans.PropertyChangeListener listener)
1365 changeSupport.addPropertyChangeListener(listener);
1374 public void removePropertyChangeListener(
1375 java.beans.PropertyChangeListener listener)
1377 changeSupport.removePropertyChangeListener(listener);
1381 * Property change listener for changes in alignment
1390 public void firePropertyChange(String prop, Object oldvalue,
1393 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1396 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1398 ignoreGapsInConsensusCalculation = b;
1399 updateConsensus(ap);
1400 if (globalColourScheme != null)
1402 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1403 ignoreGapsInConsensusCalculation);
1407 public boolean getIgnoreGapsConsensus()
1409 return ignoreGapsInConsensusCalculation;
1412 public void setDataset(boolean b)
1417 public boolean isDataset()
1422 public void hideSelectedColumns()
1424 if (colSel.size() < 1)
1429 colSel.hideSelectedColumns();
1430 setSelectionGroup(null);
1432 hasHiddenColumns = true;
1435 public void hideColumns(int start, int end)
1439 colSel.hideColumns(start);
1443 colSel.hideColumns(start, end);
1446 hasHiddenColumns = true;
1449 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1451 int sSize = sg.getSize();
1457 if (hiddenRepSequences == null)
1459 hiddenRepSequences = new Hashtable();
1462 hiddenRepSequences.put(repSequence, sg);
1464 // Hide all sequences except the repSequence
1465 SequenceI[] seqs = new SequenceI[sSize - 1];
1467 for (int i = 0; i < sSize; i++)
1469 if (sg.getSequenceAt(i) != repSequence)
1471 if (index == sSize - 1)
1476 seqs[index++] = sg.getSequenceAt(i);
1479 sg.setSeqrep(repSequence);
1480 sg.setHidereps(true);
1485 public void hideAllSelectedSeqs()
1487 if (selectionGroup == null || selectionGroup.getSize() < 1)
1492 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1496 setSelectionGroup(null);
1499 public void hideSequence(SequenceI[] seq)
1503 for (int i = 0; i < seq.length; i++)
1505 alignment.getHiddenSequences().hideSequence(seq[i]);
1507 hasHiddenRows = true;
1508 firePropertyChange("alignment", null, alignment.getSequences());
1512 public void showSequence(int index)
1514 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1515 hiddenRepSequences);
1518 if (selectionGroup == null)
1520 selectionGroup = new SequenceGroup();
1521 selectionGroup.setEndRes(alignment.getWidth() - 1);
1524 for (int t = 0; t < tmp.size(); t++)
1526 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1528 firePropertyChange("alignment", null, alignment.getSequences());
1532 if (alignment.getHiddenSequences().getSize() < 1)
1534 hasHiddenRows = false;
1538 public void showColumn(int col)
1540 colSel.revealHiddenColumns(col);
1541 if (colSel.getHiddenColumns() == null)
1543 hasHiddenColumns = false;
1547 public void showAllHiddenColumns()
1549 colSel.revealAllHiddenColumns();
1550 hasHiddenColumns = false;
1553 public void showAllHiddenSeqs()
1555 if (alignment.getHiddenSequences().getSize() > 0)
1557 if (selectionGroup == null)
1559 selectionGroup = new SequenceGroup();
1560 selectionGroup.setEndRes(alignment.getWidth() - 1);
1562 Vector tmp = alignment.getHiddenSequences().showAll(
1563 hiddenRepSequences);
1564 for (int t = 0; t < tmp.size(); t++)
1566 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1568 firePropertyChange("alignment", null, alignment.getSequences());
1570 hasHiddenRows = false;
1571 hiddenRepSequences = null;
1575 public void invertColumnSelection()
1577 colSel.invertColumnSelection(0, alignment.getWidth());
1580 public int adjustForHiddenSeqs(int alignmentIndex)
1582 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1587 * This method returns an array of new SequenceI objects derived from the
1588 * whole alignment or just the current selection with start and end points
1591 * @note if you need references to the actual SequenceI objects in the
1592 * alignment or currently selected then use getSequenceSelection()
1593 * @return selection as new sequenceI objects
1595 public SequenceI[] getSelectionAsNewSequence()
1597 SequenceI[] sequences;
1599 if (selectionGroup == null)
1601 sequences = alignment.getSequencesArray();
1602 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1603 for (int i = 0; i < sequences.length; i++)
1605 sequences[i] = new Sequence(sequences[i], annots); // construct new
1607 // subset of visible
1613 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1620 * get the currently selected sequence objects or all the sequences in the
1623 * @return array of references to sequence objects
1625 public SequenceI[] getSequenceSelection()
1627 SequenceI[] sequences;
1628 if (selectionGroup == null)
1630 sequences = alignment.getSequencesArray();
1634 sequences = selectionGroup.getSequencesInOrder(alignment);
1640 * This method returns the visible alignment as text, as seen on the GUI, ie
1641 * if columns are hidden they will not be returned in the result. Use this for
1642 * calculating trees, PCA, redundancy etc on views which contain hidden
1647 public jalview.datamodel.CigarArray getViewAsCigars(
1648 boolean selectedRegionOnly)
1650 CigarArray selection = null;
1651 SequenceI[] seqs = null;
1653 int start = 0, end = 0;
1654 if (selectedRegionOnly && selectionGroup != null)
1656 iSize = selectionGroup.getSize();
1657 seqs = selectionGroup.getSequencesInOrder(alignment);
1658 start = selectionGroup.getStartRes();
1659 end = selectionGroup.getEndRes(); // inclusive for start and end in
1660 // SeqCigar constructor
1664 iSize = alignment.getHeight();
1665 seqs = alignment.getSequencesArray();
1666 end = alignment.getWidth() - 1;
1668 SeqCigar[] selseqs = new SeqCigar[iSize];
1669 for (i = 0; i < iSize; i++)
1671 selseqs[i] = new SeqCigar(seqs[i], start, end);
1673 selection = new CigarArray(selseqs);
1674 // now construct the CigarArray operations
1675 if (hasHiddenColumns)
1677 Vector regions = colSel.getHiddenColumns();
1679 int hideStart, hideEnd;
1681 for (int j = 0; last < end & j < regions.size(); j++)
1683 region = (int[]) regions.elementAt(j);
1684 hideStart = region[0];
1685 hideEnd = region[1];
1686 // edit hidden regions to selection range
1687 if (hideStart < last)
1699 if (hideStart > end)
1709 if (hideStart > hideEnd)
1714 * form operations...
1716 if (last < hideStart)
1718 selection.addOperation(CigarArray.M, hideStart - last);
1720 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1723 // Final match if necessary.
1726 selection.addOperation(CigarArray.M, end - last + 1);
1731 selection.addOperation(CigarArray.M, end - start + 1);
1737 * return a compact representation of the current alignment selection to pass
1738 * to an analysis function
1740 * @param selectedOnly
1741 * boolean true to just return the selected view
1742 * @return AlignmentView
1744 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1747 // this is here because the AlignmentView constructor modifies the
1749 // object. Refactoring of Cigar and alignment view representation should
1750 // be done to remove redundancy.
1751 CigarArray aligview = getViewAsCigars(selectedOnly);
1752 if (aligview != null)
1754 return new AlignmentView(aligview,
1755 (selectedOnly && selectionGroup != null) ? selectionGroup
1756 .getStartRes() : 0);
1762 * This method returns the visible alignment as text, as seen on the GUI, ie
1763 * if columns are hidden they will not be returned in the result. Use this for
1764 * calculating trees, PCA, redundancy etc on views which contain hidden
1769 public String[] getViewAsString(boolean selectedRegionOnly)
1771 String[] selection = null;
1772 SequenceI[] seqs = null;
1774 int start = 0, end = 0;
1775 if (selectedRegionOnly && selectionGroup != null)
1777 iSize = selectionGroup.getSize();
1778 seqs = selectionGroup.getSequencesInOrder(alignment);
1779 start = selectionGroup.getStartRes();
1780 end = selectionGroup.getEndRes() + 1;
1784 iSize = alignment.getHeight();
1785 seqs = alignment.getSequencesArray();
1786 end = alignment.getWidth();
1789 selection = new String[iSize];
1790 if (hasHiddenColumns)
1792 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1796 for (i = 0; i < iSize; i++)
1798 selection[i] = seqs[i].getSequenceAsString(start, end);
1805 public int[][] getVisibleRegionBoundaries(int min, int max)
1807 Vector regions = new Vector();
1813 if (hasHiddenColumns)
1817 start = colSel.adjustForHiddenColumns(start);
1820 end = colSel.getHiddenBoundaryRight(start);
1831 regions.addElement(new int[]
1834 if (hasHiddenColumns)
1836 start = colSel.adjustForHiddenColumns(end);
1837 start = colSel.getHiddenBoundaryLeft(start) + 1;
1839 } while (end < max);
1841 int[][] startEnd = new int[regions.size()][2];
1843 regions.copyInto(startEnd);
1849 public boolean getShowHiddenMarkers()
1851 return showHiddenMarkers;
1854 public void setShowHiddenMarkers(boolean show)
1856 showHiddenMarkers = show;
1859 public String getSequenceSetId()
1861 if (sequenceSetID == null)
1863 sequenceSetID = alignment.hashCode() + "";
1866 return sequenceSetID;
1869 * unique viewId for synchronizing state with stored Jalview Project
1872 private String viewId=null;
1875 public String getViewId()
1879 viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1884 public void alignmentChanged(AlignmentPanel ap)
1888 alignment.padGaps();
1890 if (hconsensus != null && autoCalculateConsensus)
1892 updateConservation(ap);
1894 if (autoCalculateConsensus)
1896 updateConsensus(ap);
1899 // Reset endRes of groups if beyond alignment width
1900 int alWidth = alignment.getWidth();
1901 Vector groups = alignment.getGroups();
1904 for (int i = 0; i < groups.size(); i++)
1906 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1907 if (sg.getEndRes() > alWidth)
1909 sg.setEndRes(alWidth - 1);
1914 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1916 selectionGroup.setEndRes(alWidth - 1);
1919 resetAllColourSchemes();
1921 // alignment.adjustSequenceAnnotations();
1924 void resetAllColourSchemes()
1926 ColourSchemeI cs = globalColourScheme;
1929 if (cs instanceof ClustalxColourScheme)
1931 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1932 alignment.getWidth());
1935 cs.setConsensus(hconsensus);
1936 if (cs.conservationApplied())
1938 Alignment al = (Alignment) alignment;
1939 Conservation c = new Conservation("All",
1940 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1943 c.verdict(false, ConsPercGaps);
1945 cs.setConservation(c);
1949 int s, sSize = alignment.getGroups().size();
1950 for (s = 0; s < sSize; s++)
1952 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1953 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1955 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1956 .getSequences(hiddenRepSequences), sg.getWidth());
1958 sg.recalcConservation();
1962 public Color getSequenceColour(SequenceI seq)
1964 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1970 return (Color) sequenceColours.get(seq);
1974 public void setSequenceColour(SequenceI seq, Color col)
1976 if (sequenceColours == null)
1978 sequenceColours = new Hashtable();
1983 sequenceColours.remove(seq);
1987 sequenceColours.put(seq, col);
1992 * returns the visible column regions of the alignment
1994 * @param selectedRegionOnly
1995 * true to just return the contigs intersecting with the
1999 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
2001 int[] viscontigs = null;
2002 int start = 0, end = 0;
2003 if (selectedRegionOnly && selectionGroup != null)
2005 start = selectionGroup.getStartRes();
2006 end = selectionGroup.getEndRes() + 1;
2010 end = alignment.getWidth();
2012 viscontigs = colSel.getVisibleContigs(start, end);
2017 * get hash of undo and redo list for the alignment
2019 * @return long[] { historyList.hashCode, redoList.hashCode };
2021 public long[] getUndoRedoHash()
2023 if (historyList == null || redoList == null)
2027 { historyList.hashCode(), this.redoList.hashCode() };
2031 * test if a particular set of hashcodes are different to the hashcodes for
2032 * the undo and redo list.
2035 * the stored set of hashcodes as returned by getUndoRedoHash
2036 * @return true if the hashcodes differ (ie the alignment has been edited) or
2037 * the stored hashcode array differs in size
2039 public boolean isUndoRedoHashModified(long[] undoredo)
2041 if (undoredo == null)
2045 long[] cstate = getUndoRedoHash();
2046 if (cstate.length != undoredo.length)
2051 for (int i = 0; i < cstate.length; i++)
2053 if (cstate[i] != undoredo[i])
2061 public boolean getCentreColumnLabels()
2063 return centreColumnLabels;
2066 public void setCentreColumnLabels(boolean centrecolumnlabels)
2068 centreColumnLabels = centrecolumnlabels;
2071 public void updateSequenceIdColours()
2073 Vector groups = alignment.getGroups();
2074 if (sequenceColours == null)
2076 sequenceColours = new Hashtable();
2078 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
2080 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
2081 if (sg.idColour != null)
2083 Vector sqs = sg.getSequences(hiddenRepSequences);
2084 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2086 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2093 * enable or disable the display of Database Cross References in the sequence ID tooltip
2095 public void setShowDbRefs(boolean show)
2102 * @return true if Database References are to be displayed on tooltips.
2104 public boolean isShowDbRefs()
2111 * @return true if Non-positional features are to be displayed on tooltips.
2113 public boolean isShowNpFeats()
2118 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
2121 public void setShowNpFeats(boolean show)
2127 * @return true if view has hidden rows
2129 public boolean hasHiddenRows()
2131 return hasHiddenRows;
2135 * @return true if view has hidden columns
2137 public boolean hasHiddenColumns()
2139 return hasHiddenColumns;
2142 * when set, view will scroll to show the highlighted position
2144 public boolean followHighlight=true;
2146 * @return true if view should scroll to show the highlighted region of a sequence
2149 public boolean getFollowHighlight() {
2150 return followHighlight;
2152 public boolean followSelection=true;
2154 * @return true if view selection should always follow the selections broadcast by other selection sources
2156 public boolean getFollowSelection() {
2157 return followSelection;
2159 private long sgrouphash=-1,colselhash=-1;
2161 boolean showSeqFeaturesHeight;
2163 * checks current SelectionGroup against record of last hash value, and updates record.
2164 * @return true if SelectionGroup changed since last call
2166 boolean isSelectionGroupChanged() {
2167 int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2176 * checks current colsel against record of last hash value, and updates record.
2177 * @return true if colsel changed since last call
2179 boolean isColSelChanged() {
2180 int hc=(colSel==null) ? -1 : colSel.hashCode();
2188 public void sendSelection()
2190 jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);
2192 public void setShowSequenceFeaturesHeight(boolean selected)
2194 showSeqFeaturesHeight = selected;
2196 public boolean getShowSequenceFeaturesHeight()
2198 return showSeqFeaturesHeight;