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);
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 if (alignment.isNucleotide() || conservation == null)
568 conservationThread = new ConservationThread(ap);
569 conservationThread.start();
573 * trigger update of consensus annotation
575 public void updateConsensus(final AlignmentPanel ap)
577 consensusThread = new ConsensusThread(ap);
578 consensusThread.start();
581 class ConsensusThread extends Thread
585 public ConsensusThread(AlignmentPanel ap)
592 updatingConsensus = true;
593 while (UPDATING_CONSENSUS)
599 ap.paintAlignment(false);
603 } catch (Exception ex)
605 ex.printStackTrace();
609 UPDATING_CONSENSUS = true;
613 int aWidth = (alignment != null) ? alignment.getWidth() : 0; // null
622 consensus.annotations = null;
623 consensus.annotations = new Annotation[aWidth];
625 hconsensus = new Hashtable[aWidth];
626 AAFrequency.calculate(alignment.getSequencesArray(), 0, alignment
627 .getWidth(), hconsensus);
629 for (int i = 0; i < aWidth; i++)
632 if (ignoreGapsInConsensusCalculation)
634 value = ((Float) hconsensus[i].get(AAFrequency.PID_NOGAPS))
639 value = ((Float) hconsensus[i].get(AAFrequency.PID_GAPS))
643 String maxRes = hconsensus[i].get(AAFrequency.MAXRESIDUE)
645 String mouseOver = hconsensus[i].get(AAFrequency.MAXRESIDUE)
648 if (maxRes.length() > 1)
650 mouseOver = "[" + maxRes + "] ";
654 mouseOver += ((int) value + "%");
655 consensus.annotations[i] = new Annotation(maxRes, mouseOver, ' ',
659 if (globalColourScheme != null)
661 globalColourScheme.setConsensus(hconsensus);
664 } catch (OutOfMemoryError error)
666 alignment.deleteAnnotation(consensus);
670 new OOMWarning("calculating consensus", error);
672 UPDATING_CONSENSUS = false;
673 updatingConsensus = false;
677 ap.paintAlignment(true);
683 * get the consensus sequence as displayed under the PID consensus annotation
686 * @return consensus sequence as a new sequence object
688 public SequenceI getConsensusSeq()
690 if (consensus == null)
692 updateConsensus(null);
694 if (consensus == null)
698 StringBuffer seqs = new StringBuffer();
699 for (int i = 0; i < consensus.annotations.length; i++)
701 if (consensus.annotations[i] != null)
703 if (consensus.annotations[i].description.charAt(0) == '[')
705 seqs.append(consensus.annotations[i].description.charAt(1));
709 seqs.append(consensus.annotations[i].displayCharacter);
714 SequenceI sq = new Sequence("Consensus", seqs.toString());
715 sq.setDescription("Percentage Identity Consensus "
716 + ((ignoreGapsInConsensusCalculation) ? " without gaps" : ""));
723 * @return DOCUMENT ME!
725 public SequenceGroup getSelectionGroup()
727 return selectionGroup;
736 public void setSelectionGroup(SequenceGroup sg)
744 * @return DOCUMENT ME!
746 public boolean getConservationSelected()
748 return conservationColourSelected;
757 public void setConservationSelected(boolean b)
759 conservationColourSelected = b;
765 * @return DOCUMENT ME!
767 public boolean getAbovePIDThreshold()
769 return abovePIDThreshold;
778 public void setAbovePIDThreshold(boolean b)
780 abovePIDThreshold = b;
786 * @return DOCUMENT ME!
788 public int getStartRes()
796 * @return DOCUMENT ME!
798 public int getEndRes()
806 * @return DOCUMENT ME!
808 public int getStartSeq()
819 public void setGlobalColourScheme(ColourSchemeI cs)
821 globalColourScheme = cs;
827 * @return DOCUMENT ME!
829 public ColourSchemeI getGlobalColourScheme()
831 return globalColourScheme;
840 public void setStartRes(int res)
851 public void setStartSeq(int seq)
862 public void setEndRes(int res)
864 if (res > (alignment.getWidth() - 1))
866 // log.System.out.println(" Corrected res from " + res + " to maximum " +
867 // (alignment.getWidth()-1));
868 res = alignment.getWidth() - 1;
885 public void setEndSeq(int seq)
887 if (seq > alignment.getHeight())
889 seq = alignment.getHeight();
903 * @return DOCUMENT ME!
905 public int getEndSeq()
916 public void setFont(Font f)
920 Container c = new Container();
922 java.awt.FontMetrics fm = c.getFontMetrics(font);
923 setCharHeight(fm.getHeight());
924 setCharWidth(fm.charWidth('M'));
925 validCharWidth = true;
931 * @return DOCUMENT ME!
933 public Font getFont()
944 public void setCharWidth(int w)
952 * @return DOCUMENT ME!
954 public int getCharWidth()
965 public void setCharHeight(int h)
973 * @return DOCUMENT ME!
975 public int getCharHeight()
986 public void setWrappedWidth(int w)
988 this.wrappedWidth = w;
994 * @return DOCUMENT ME!
996 public int getWrappedWidth()
1004 * @return DOCUMENT ME!
1006 public AlignmentI getAlignment()
1017 public void setAlignment(AlignmentI align)
1019 if (alignment != null && alignment.getCodonFrames() != null)
1021 StructureSelectionManager.getStructureSelectionManager()
1022 .removeMappings(alignment.getCodonFrames());
1024 this.alignment = align;
1025 if (alignment.getCodonFrames() != null)
1027 StructureSelectionManager.getStructureSelectionManager().addMappings(
1028 alignment.getCodonFrames());
1038 public void setWrapAlignment(boolean state)
1040 wrapAlignment = state;
1049 public void setShowText(boolean state)
1060 public void setRenderGaps(boolean state)
1068 * @return DOCUMENT ME!
1070 public boolean getColourText()
1072 return showColourText;
1081 public void setColourText(boolean state)
1083 showColourText = state;
1092 public void setShowBoxes(boolean state)
1100 * @return DOCUMENT ME!
1102 public boolean getWrapAlignment()
1104 return wrapAlignment;
1110 * @return DOCUMENT ME!
1112 public boolean getShowText()
1120 * @return DOCUMENT ME!
1122 public boolean getShowBoxes()
1130 * @return DOCUMENT ME!
1132 public char getGapCharacter()
1134 return getAlignment().getGapCharacter();
1143 public void setGapCharacter(char gap)
1145 if (getAlignment() != null)
1147 getAlignment().setGapCharacter(gap);
1157 public void setThreshold(int thresh)
1165 * @return DOCUMENT ME!
1167 public int getThreshold()
1178 public void setIncrement(int inc)
1186 * @return DOCUMENT ME!
1188 public int getIncrement()
1196 * @return DOCUMENT ME!
1198 public ColumnSelection getColumnSelection()
1209 public void setCurrentTree(NJTree tree)
1217 * @return DOCUMENT ME!
1219 public NJTree getCurrentTree()
1230 public void setColourAppliesToAllGroups(boolean b)
1232 colourAppliesToAllGroups = b;
1238 * @return DOCUMENT ME!
1240 public boolean getColourAppliesToAllGroups()
1242 return colourAppliesToAllGroups;
1248 * @return DOCUMENT ME!
1250 public boolean getShowJVSuffix()
1252 return showJVSuffix;
1261 public void setShowJVSuffix(boolean b)
1269 * @return DOCUMENT ME!
1271 public boolean getShowAnnotation()
1273 return showAnnotation;
1282 public void setShowAnnotation(boolean b)
1290 * @return DOCUMENT ME!
1292 public boolean getScaleAboveWrapped()
1294 return scaleAboveWrapped;
1300 * @return DOCUMENT ME!
1302 public boolean getScaleLeftWrapped()
1304 return scaleLeftWrapped;
1310 * @return DOCUMENT ME!
1312 public boolean getScaleRightWrapped()
1314 return scaleRightWrapped;
1323 public void setScaleAboveWrapped(boolean b)
1325 scaleAboveWrapped = b;
1334 public void setScaleLeftWrapped(boolean b)
1336 scaleLeftWrapped = b;
1345 public void setScaleRightWrapped(boolean b)
1347 scaleRightWrapped = b;
1351 * Property change listener for changes in alignment
1356 public void addPropertyChangeListener(
1357 java.beans.PropertyChangeListener listener)
1359 changeSupport.addPropertyChangeListener(listener);
1368 public void removePropertyChangeListener(
1369 java.beans.PropertyChangeListener listener)
1371 changeSupport.removePropertyChangeListener(listener);
1375 * Property change listener for changes in alignment
1384 public void firePropertyChange(String prop, Object oldvalue,
1387 changeSupport.firePropertyChange(prop, oldvalue, newvalue);
1390 public void setIgnoreGapsConsensus(boolean b, AlignmentPanel ap)
1392 ignoreGapsInConsensusCalculation = b;
1393 updateConsensus(ap);
1394 if (globalColourScheme != null)
1396 globalColourScheme.setThreshold(globalColourScheme.getThreshold(),
1397 ignoreGapsInConsensusCalculation);
1401 public boolean getIgnoreGapsConsensus()
1403 return ignoreGapsInConsensusCalculation;
1406 public void setDataset(boolean b)
1411 public boolean isDataset()
1416 public void hideSelectedColumns()
1418 if (colSel.size() < 1)
1423 colSel.hideSelectedColumns();
1424 setSelectionGroup(null);
1426 hasHiddenColumns = true;
1429 public void hideColumns(int start, int end)
1433 colSel.hideColumns(start);
1437 colSel.hideColumns(start, end);
1440 hasHiddenColumns = true;
1443 public void hideRepSequences(SequenceI repSequence, SequenceGroup sg)
1445 int sSize = sg.getSize();
1451 if (hiddenRepSequences == null)
1453 hiddenRepSequences = new Hashtable();
1456 hiddenRepSequences.put(repSequence, sg);
1458 // Hide all sequences except the repSequence
1459 SequenceI[] seqs = new SequenceI[sSize - 1];
1461 for (int i = 0; i < sSize; i++)
1463 if (sg.getSequenceAt(i) != repSequence)
1465 if (index == sSize - 1)
1470 seqs[index++] = sg.getSequenceAt(i);
1473 sg.setSeqrep(repSequence);
1474 sg.setHidereps(true);
1479 public void hideAllSelectedSeqs()
1481 if (selectionGroup == null || selectionGroup.getSize() < 1)
1486 SequenceI[] seqs = selectionGroup.getSequencesInOrder(alignment);
1490 setSelectionGroup(null);
1493 public void hideSequence(SequenceI[] seq)
1497 for (int i = 0; i < seq.length; i++)
1499 alignment.getHiddenSequences().hideSequence(seq[i]);
1501 hasHiddenRows = true;
1502 firePropertyChange("alignment", null, alignment.getSequences());
1506 public void showSequence(int index)
1508 Vector tmp = alignment.getHiddenSequences().showSequence(index,
1509 hiddenRepSequences);
1512 if (selectionGroup == null)
1514 selectionGroup = new SequenceGroup();
1515 selectionGroup.setEndRes(alignment.getWidth() - 1);
1518 for (int t = 0; t < tmp.size(); t++)
1520 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1522 firePropertyChange("alignment", null, alignment.getSequences());
1526 if (alignment.getHiddenSequences().getSize() < 1)
1528 hasHiddenRows = false;
1532 public void showColumn(int col)
1534 colSel.revealHiddenColumns(col);
1535 if (colSel.getHiddenColumns() == null)
1537 hasHiddenColumns = false;
1541 public void showAllHiddenColumns()
1543 colSel.revealAllHiddenColumns();
1544 hasHiddenColumns = false;
1547 public void showAllHiddenSeqs()
1549 if (alignment.getHiddenSequences().getSize() > 0)
1551 if (selectionGroup == null)
1553 selectionGroup = new SequenceGroup();
1554 selectionGroup.setEndRes(alignment.getWidth() - 1);
1556 Vector tmp = alignment.getHiddenSequences().showAll(
1557 hiddenRepSequences);
1558 for (int t = 0; t < tmp.size(); t++)
1560 selectionGroup.addSequence((SequenceI) tmp.elementAt(t), false);
1562 firePropertyChange("alignment", null, alignment.getSequences());
1564 hasHiddenRows = false;
1565 hiddenRepSequences = null;
1569 public void invertColumnSelection()
1571 colSel.invertColumnSelection(0, alignment.getWidth());
1574 public int adjustForHiddenSeqs(int alignmentIndex)
1576 return alignment.getHiddenSequences().adjustForHiddenSeqs(
1581 * This method returns an array of new SequenceI objects derived from the
1582 * whole alignment or just the current selection with start and end points
1585 * @note if you need references to the actual SequenceI objects in the
1586 * alignment or currently selected then use getSequenceSelection()
1587 * @return selection as new sequenceI objects
1589 public SequenceI[] getSelectionAsNewSequence()
1591 SequenceI[] sequences;
1593 if (selectionGroup == null)
1595 sequences = alignment.getSequencesArray();
1596 AlignmentAnnotation[] annots = alignment.getAlignmentAnnotation();
1597 for (int i = 0; i < sequences.length; i++)
1599 sequences[i] = new Sequence(sequences[i], annots); // construct new
1601 // subset of visible
1607 sequences = selectionGroup.getSelectionAsNewSequences(alignment);
1614 * get the currently selected sequence objects or all the sequences in the
1617 * @return array of references to sequence objects
1619 public SequenceI[] getSequenceSelection()
1621 SequenceI[] sequences;
1622 if (selectionGroup == null)
1624 sequences = alignment.getSequencesArray();
1628 sequences = selectionGroup.getSequencesInOrder(alignment);
1634 * This method returns the visible alignment as text, as seen on the GUI, ie
1635 * if columns are hidden they will not be returned in the result. Use this for
1636 * calculating trees, PCA, redundancy etc on views which contain hidden
1641 public jalview.datamodel.CigarArray getViewAsCigars(
1642 boolean selectedRegionOnly)
1644 CigarArray selection = null;
1645 SequenceI[] seqs = null;
1647 int start = 0, end = 0;
1648 if (selectedRegionOnly && selectionGroup != null)
1650 iSize = selectionGroup.getSize();
1651 seqs = selectionGroup.getSequencesInOrder(alignment);
1652 start = selectionGroup.getStartRes();
1653 end = selectionGroup.getEndRes(); // inclusive for start and end in
1654 // SeqCigar constructor
1658 iSize = alignment.getHeight();
1659 seqs = alignment.getSequencesArray();
1660 end = alignment.getWidth() - 1;
1662 SeqCigar[] selseqs = new SeqCigar[iSize];
1663 for (i = 0; i < iSize; i++)
1665 selseqs[i] = new SeqCigar(seqs[i], start, end);
1667 selection = new CigarArray(selseqs);
1668 // now construct the CigarArray operations
1669 if (hasHiddenColumns)
1671 Vector regions = colSel.getHiddenColumns();
1673 int hideStart, hideEnd;
1675 for (int j = 0; last < end & j < regions.size(); j++)
1677 region = (int[]) regions.elementAt(j);
1678 hideStart = region[0];
1679 hideEnd = region[1];
1680 // edit hidden regions to selection range
1681 if (hideStart < last)
1693 if (hideStart > end)
1703 if (hideStart > hideEnd)
1708 * form operations...
1710 if (last < hideStart)
1712 selection.addOperation(CigarArray.M, hideStart - last);
1714 selection.addOperation(CigarArray.D, 1 + hideEnd - hideStart);
1717 // Final match if necessary.
1720 selection.addOperation(CigarArray.M, end - last + 1);
1725 selection.addOperation(CigarArray.M, end - start + 1);
1731 * return a compact representation of the current alignment selection to pass
1732 * to an analysis function
1734 * @param selectedOnly
1735 * boolean true to just return the selected view
1736 * @return AlignmentView
1738 jalview.datamodel.AlignmentView getAlignmentView(boolean selectedOnly)
1741 // this is here because the AlignmentView constructor modifies the
1743 // object. Refactoring of Cigar and alignment view representation should
1744 // be done to remove redundancy.
1745 CigarArray aligview = getViewAsCigars(selectedOnly);
1746 if (aligview != null)
1748 return new AlignmentView(aligview,
1749 (selectedOnly && selectionGroup != null) ? selectionGroup
1750 .getStartRes() : 0);
1756 * This method returns the visible alignment as text, as seen on the GUI, ie
1757 * if columns are hidden they will not be returned in the result. Use this for
1758 * calculating trees, PCA, redundancy etc on views which contain hidden
1763 public String[] getViewAsString(boolean selectedRegionOnly)
1765 String[] selection = null;
1766 SequenceI[] seqs = null;
1768 int start = 0, end = 0;
1769 if (selectedRegionOnly && selectionGroup != null)
1771 iSize = selectionGroup.getSize();
1772 seqs = selectionGroup.getSequencesInOrder(alignment);
1773 start = selectionGroup.getStartRes();
1774 end = selectionGroup.getEndRes() + 1;
1778 iSize = alignment.getHeight();
1779 seqs = alignment.getSequencesArray();
1780 end = alignment.getWidth();
1783 selection = new String[iSize];
1784 if (hasHiddenColumns)
1786 selection = colSel.getVisibleSequenceStrings(start, end, seqs);
1790 for (i = 0; i < iSize; i++)
1792 selection[i] = seqs[i].getSequenceAsString(start, end);
1799 public int[][] getVisibleRegionBoundaries(int min, int max)
1801 Vector regions = new Vector();
1807 if (hasHiddenColumns)
1811 start = colSel.adjustForHiddenColumns(start);
1814 end = colSel.getHiddenBoundaryRight(start);
1825 regions.addElement(new int[]
1828 if (hasHiddenColumns)
1830 start = colSel.adjustForHiddenColumns(end);
1831 start = colSel.getHiddenBoundaryLeft(start) + 1;
1833 } while (end < max);
1835 int[][] startEnd = new int[regions.size()][2];
1837 regions.copyInto(startEnd);
1843 public boolean getShowHiddenMarkers()
1845 return showHiddenMarkers;
1848 public void setShowHiddenMarkers(boolean show)
1850 showHiddenMarkers = show;
1853 public String getSequenceSetId()
1855 if (sequenceSetID == null)
1857 sequenceSetID = alignment.hashCode() + "";
1860 return sequenceSetID;
1863 * unique viewId for synchronizing state with stored Jalview Project
1866 private String viewId=null;
1869 public String getViewId()
1873 viewId = this.getSequenceSetId()+"."+this.hashCode()+"";
1878 public void alignmentChanged(AlignmentPanel ap)
1882 alignment.padGaps();
1884 if (hconsensus != null && autoCalculateConsensus)
1886 updateConsensus(ap);
1887 updateConservation(ap);
1890 // Reset endRes of groups if beyond alignment width
1891 int alWidth = alignment.getWidth();
1892 Vector groups = alignment.getGroups();
1895 for (int i = 0; i < groups.size(); i++)
1897 SequenceGroup sg = (SequenceGroup) groups.elementAt(i);
1898 if (sg.getEndRes() > alWidth)
1900 sg.setEndRes(alWidth - 1);
1905 if (selectionGroup != null && selectionGroup.getEndRes() > alWidth)
1907 selectionGroup.setEndRes(alWidth - 1);
1910 resetAllColourSchemes();
1912 // alignment.adjustSequenceAnnotations();
1915 void resetAllColourSchemes()
1917 ColourSchemeI cs = globalColourScheme;
1920 if (cs instanceof ClustalxColourScheme)
1922 ((ClustalxColourScheme) cs).resetClustalX(alignment.getSequences(),
1923 alignment.getWidth());
1926 cs.setConsensus(hconsensus);
1927 if (cs.conservationApplied())
1929 Alignment al = (Alignment) alignment;
1930 Conservation c = new Conservation("All",
1931 ResidueProperties.propHash, 3, al.getSequences(), 0, al
1934 c.verdict(false, ConsPercGaps);
1936 cs.setConservation(c);
1940 int s, sSize = alignment.getGroups().size();
1941 for (s = 0; s < sSize; s++)
1943 SequenceGroup sg = (SequenceGroup) alignment.getGroups().elementAt(s);
1944 if (sg.cs != null && sg.cs instanceof ClustalxColourScheme)
1946 ((ClustalxColourScheme) sg.cs).resetClustalX(sg
1947 .getSequences(hiddenRepSequences), sg.getWidth());
1949 sg.recalcConservation();
1953 public Color getSequenceColour(SequenceI seq)
1955 if (sequenceColours == null || !sequenceColours.containsKey(seq))
1961 return (Color) sequenceColours.get(seq);
1965 public void setSequenceColour(SequenceI seq, Color col)
1967 if (sequenceColours == null)
1969 sequenceColours = new Hashtable();
1974 sequenceColours.remove(seq);
1978 sequenceColours.put(seq, col);
1983 * returns the visible column regions of the alignment
1985 * @param selectedRegionOnly
1986 * true to just return the contigs intersecting with the
1990 public int[] getViewAsVisibleContigs(boolean selectedRegionOnly)
1992 int[] viscontigs = null;
1993 int start = 0, end = 0;
1994 if (selectedRegionOnly && selectionGroup != null)
1996 start = selectionGroup.getStartRes();
1997 end = selectionGroup.getEndRes() + 1;
2001 end = alignment.getWidth();
2003 viscontigs = colSel.getVisibleContigs(start, end);
2008 * get hash of undo and redo list for the alignment
2010 * @return long[] { historyList.hashCode, redoList.hashCode };
2012 public long[] getUndoRedoHash()
2014 if (historyList == null || redoList == null)
2018 { historyList.hashCode(), this.redoList.hashCode() };
2022 * test if a particular set of hashcodes are different to the hashcodes for
2023 * the undo and redo list.
2026 * the stored set of hashcodes as returned by getUndoRedoHash
2027 * @return true if the hashcodes differ (ie the alignment has been edited) or
2028 * the stored hashcode array differs in size
2030 public boolean isUndoRedoHashModified(long[] undoredo)
2032 if (undoredo == null)
2036 long[] cstate = getUndoRedoHash();
2037 if (cstate.length != undoredo.length)
2042 for (int i = 0; i < cstate.length; i++)
2044 if (cstate[i] != undoredo[i])
2052 public boolean getCentreColumnLabels()
2054 return centreColumnLabels;
2057 public void setCentreColumnLabels(boolean centrecolumnlabels)
2059 centreColumnLabels = centrecolumnlabels;
2062 public void updateSequenceIdColours()
2064 Vector groups = alignment.getGroups();
2065 if (sequenceColours == null)
2067 sequenceColours = new Hashtable();
2069 for (int ig = 0, igSize = groups.size(); ig < igSize; ig++)
2071 SequenceGroup sg = (SequenceGroup) groups.elementAt(ig);
2072 if (sg.idColour != null)
2074 Vector sqs = sg.getSequences(hiddenRepSequences);
2075 for (int s = 0, sSize = sqs.size(); s < sSize; s++)
2077 sequenceColours.put(sqs.elementAt(s), sg.idColour);
2084 * enable or disable the display of Database Cross References in the sequence ID tooltip
2086 public void setShowDbRefs(boolean show)
2093 * @return true if Database References are to be displayed on tooltips.
2095 public boolean isShowDbRefs()
2102 * @return true if Non-positional features are to be displayed on tooltips.
2104 public boolean isShowNpFeats()
2109 * enable or disable the display of Non-Positional sequence features in the sequence ID tooltip
2112 public void setShowNpFeats(boolean show)
2118 * @return true if view has hidden rows
2120 public boolean hasHiddenRows()
2122 return hasHiddenRows;
2126 * @return true if view has hidden columns
2128 public boolean hasHiddenColumns()
2130 return hasHiddenColumns;
2133 * when set, view will scroll to show the highlighted position
2135 public boolean followHighlight=true;
2137 * @return true if view should scroll to show the highlighted region of a sequence
2140 public boolean getFollowHighlight() {
2141 return followHighlight;
2143 public boolean followSelection=true;
2145 * @return true if view selection should always follow the selections broadcast by other selection sources
2147 public boolean getFollowSelection() {
2148 return followSelection;
2150 private long sgrouphash=-1,colselhash=-1;
2152 boolean showSeqFeaturesHeight;
2154 * checks current SelectionGroup against record of last hash value, and updates record.
2155 * @return true if SelectionGroup changed since last call
2157 boolean isSelectionGroupChanged() {
2158 int hc=(selectionGroup==null) ? -1 : selectionGroup.hashCode();
2167 * checks current colsel against record of last hash value, and updates record.
2168 * @return true if colsel changed since last call
2170 boolean isColSelChanged() {
2171 int hc=(colSel==null) ? -1 : colSel.hashCode();
2179 public void sendSelection()
2181 jalview.structure.StructureSelectionManager.getStructureSelectionManager().sendSelection(new SequenceGroup(getSelectionGroup()), new ColumnSelection(getColumnSelection()), this);
2183 public void setShowSequenceFeaturesHeight(boolean selected)
2185 showSeqFeaturesHeight = selected;
2187 public boolean getShowSequenceFeaturesHeight()
2189 return showSeqFeaturesHeight;