X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FSequenceGroup.java;h=ba17cc95431aed5f2959623123972becdc67c970;hb=ce08afbaee380a375cc5dc2c51892c820371c879;hp=6ded8bd79adac1a57f27893c8d819d0dd496ae19;hpb=942de34caf73a7d61104783c8d278c32eaf6b65d;p=jalview.git
diff --git a/src/jalview/datamodel/SequenceGroup.java b/src/jalview/datamodel/SequenceGroup.java
index 6ded8bd..ba17cc9 100755
--- a/src/jalview/datamodel/SequenceGroup.java
+++ b/src/jalview/datamodel/SequenceGroup.java
@@ -1,20 +1,19 @@
/*
- * Jalview - A Sequence Alignment Editor and Viewer
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
+ * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
*/
package jalview.datamodel;
@@ -27,32 +26,81 @@ import jalview.schemes.*;
/**
* Collects a set contiguous ranges on a set of sequences
+ *
* @author $author$
* @version $Revision$
*/
public class SequenceGroup
{
String groupName;
+
String description;
+
Conservation conserve;
+
Vector aaFrequency;
+
boolean displayBoxes = true;
+
boolean displayText = true;
+
boolean colourText = false;
+
+ /**
+ * after Olivier's non-conserved only character display
+ */
+ boolean showNonconserved = false;
+
+ /**
+ * group members
+ */
private Vector sequences = new Vector();
+
+ /**
+ * representative sequence for this group (if any)
+ */
+ private SequenceI seqrep = null;
+
int width = -1;
- /** DOCUMENT ME!! */
+ /**
+ * Colourscheme applied to group if any
+ */
public ColourSchemeI cs;
+
int startRes = 0;
+
int endRes = 0;
+
public Color outlineColour = Color.black;
- public Color idColour = null;
+
+ public Color idColour = null;
+
public int thresholdTextColour = 0;
+
public Color textColour = Color.black;
+
public Color textColour2 = Color.white;
/**
+ * consensus calculation property
+ */
+ private boolean ignoreGapsInConsensus = true;
+
+ /**
+ * consensus calculation property
+ */
+ private boolean showSequenceLogo = false;
+
+ /**
+ * @return the includeAllConsSymbols
+ */
+ public boolean isShowSequenceLogo()
+ {
+ return showSequenceLogo;
+ }
+
+ /**
* Creates a new SequenceGroup object.
*/
public SequenceGroup()
@@ -62,20 +110,21 @@ public class SequenceGroup
/**
* Creates a new SequenceGroup object.
- *
- * @param sequences
- * @param groupName
- * @param scheme
- * @param displayBoxes
- * @param displayText
- * @param colourText
- * @param start first column of group
- * @param end last column of group
+ *
+ * @param sequences
+ * @param groupName
+ * @param scheme
+ * @param displayBoxes
+ * @param displayText
+ * @param colourText
+ * @param start
+ * first column of group
+ * @param end
+ * last column of group
*/
public SequenceGroup(Vector sequences, String groupName,
- ColourSchemeI scheme, boolean displayBoxes,
- boolean displayText,
- boolean colourText, int start, int end)
+ ColourSchemeI scheme, boolean displayBoxes, boolean displayText,
+ boolean colourText, int start, int end)
{
this.sequences = sequences;
this.groupName = groupName;
@@ -88,18 +137,64 @@ public class SequenceGroup
recalcConservation();
}
+ /**
+ * copy constructor
+ *
+ * @param seqsel
+ */
+ public SequenceGroup(SequenceGroup seqsel)
+ {
+ if (seqsel != null)
+ {
+ sequences = new Vector();
+ Enumeration sq = seqsel.sequences.elements();
+ while (sq.hasMoreElements())
+ {
+ sequences.addElement(sq.nextElement());
+ }
+ ;
+ if (seqsel.groupName != null)
+ {
+ groupName = new String(seqsel.groupName);
+ }
+ displayBoxes = seqsel.displayBoxes;
+ displayText = seqsel.displayText;
+ colourText = seqsel.colourText;
+ startRes = seqsel.startRes;
+ endRes = seqsel.endRes;
+ cs = seqsel.cs;
+ if (seqsel.description != null)
+ description = new String(seqsel.description);
+ hidecols = seqsel.hidecols;
+ hidereps = seqsel.hidereps;
+ idColour = seqsel.idColour;
+ outlineColour = seqsel.outlineColour;
+ seqrep = seqsel.seqrep;
+ textColour = seqsel.textColour;
+ textColour2 = seqsel.textColour2;
+ thresholdTextColour = seqsel.thresholdTextColour;
+ width = seqsel.width;
+ ignoreGapsInConsensus = seqsel.ignoreGapsInConsensus;
+ if (seqsel.conserve != null)
+ {
+ recalcConservation(); // safer than
+ // aaFrequency = (Vector) seqsel.aaFrequency.clone(); // ??
+ }
+ }
+ }
+
public SequenceI[] getSelectionAsNewSequences(AlignmentI align)
{
int iSize = sequences.size();
SequenceI[] seqs = new SequenceI[iSize];
SequenceI[] inorder = getSequencesInOrder(align);
-
- for (int i = 0,ipos=0; i < inorder.length; i++)
+
+ for (int i = 0, ipos = 0; i < inorder.length; i++)
{
SequenceI seq = inorder[i];
- seqs[ipos] = seq.getSubSequence(startRes, endRes+1);
- if (seqs[ipos]!=null)
+ seqs[ipos] = seq.getSubSequence(startRes, endRes + 1);
+ if (seqs[ipos] != null)
{
seqs[ipos].setDescription(seq.getDescription());
seqs[ipos].setDBRef(seq.getDBRef());
@@ -112,26 +207,27 @@ public class SequenceGroup
if (seq.getAnnotation() != null)
{
AlignmentAnnotation[] alann = align.getAlignmentAnnotation();
- // Only copy annotation that is either a score or referenced by the alignment's annotation vector
+ // Only copy annotation that is either a score or referenced by the
+ // alignment's annotation vector
for (int a = 0; a < seq.getAnnotation().length; a++)
{
AlignmentAnnotation tocopy = seq.getAnnotation()[a];
- if (alann!=null)
+ if (alann != null)
{
- boolean found=false;
- for (int pos=0;pos 0)
{
- width = ( (SequenceI) sequences.elementAt(0)).getLength();
+ width = ((SequenceI) sequences.elementAt(0)).getLength();
}
for (int i = 1; i < sequences.size(); i++)
@@ -583,8 +765,9 @@ public class SequenceGroup
/**
* DOCUMENT ME!
- *
- * @param c DOCUMENT ME!
+ *
+ * @param c
+ * DOCUMENT ME!
*/
public void setOutlineColour(Color c)
{
@@ -593,7 +776,7 @@ public class SequenceGroup
/**
* DOCUMENT ME!
- *
+ *
* @return DOCUMENT ME!
*/
public Color getOutlineColour()
@@ -602,28 +785,64 @@ public class SequenceGroup
}
/**
- *
- * returns the sequences in the group ordered by the ordering given by al
- *
- * @param al Alignment
- * @return SequenceI[]
+ *
+ * returns the sequences in the group ordered by the ordering given by al.
+ * this used to return an array with null entries regardless, new behaviour is
+ * below. TODO: verify that this does not affect use in applet or application
+ *
+ * @param al
+ * Alignment
+ * @return SequenceI[] intersection of sequences in group with al, ordered by
+ * al, or null if group does not intersect with al
*/
public SequenceI[] getSequencesInOrder(AlignmentI al)
{
+ return getSequencesInOrder(al, true);
+ }
+
+ /**
+ * return an array representing the intersection of the group with al,
+ * optionally returning an array the size of al.getHeight() where nulls mark
+ * the non-intersected sequences
+ *
+ * @param al
+ * @param trim
+ * @return null or array
+ */
+ public SequenceI[] getSequencesInOrder(AlignmentI al, boolean trim)
+ {
int sSize = sequences.size();
int alHeight = al.getHeight();
- SequenceI[] seqs = new SequenceI[sSize];
+ SequenceI[] seqs = new SequenceI[(trim) ? sSize : alHeight];
int index = 0;
for (int i = 0; i < alHeight && index < sSize; i++)
{
if (sequences.contains(al.getSequenceAt(i)))
{
- seqs[index++] = al.getSequenceAt(i);
+ seqs[(trim) ? index : i] = al.getSequenceAt(i);
+ index++;
+ }
+ }
+ if (index == 0)
+ {
+ return null;
+ }
+ if (!trim)
+ {
+ return seqs;
+ }
+ if (index < seqs.length)
+ {
+ SequenceI[] dummy = seqs;
+ seqs = new SequenceI[index];
+ while (--index >= 0)
+ {
+ seqs[index] = dummy[index];
+ dummy[index] = null;
}
}
-
return seqs;
}
@@ -636,10 +855,316 @@ public class SequenceGroup
}
/**
- * @param idColour the idColour to set
+ * @param idColour
+ * the idColour to set
*/
public void setIdColour(Color idColour)
{
this.idColour = idColour;
}
+
+ /**
+ * @return the representative sequence for this group
+ */
+ public SequenceI getSeqrep()
+ {
+ return seqrep;
+ }
+
+ /**
+ * set the representative sequence for this group. Note - this affects the
+ * interpretation of the Hidereps attribute.
+ *
+ * @param seqrep
+ * the seqrep to set (null means no sequence representative)
+ */
+ public void setSeqrep(SequenceI seqrep)
+ {
+ this.seqrep = seqrep;
+ }
+
+ /**
+ *
+ * @return true if group has a sequence representative
+ */
+ public boolean hasSeqrep()
+ {
+ return seqrep != null;
+ }
+
+ /**
+ * visibility of rows or represented rows covered by group
+ */
+ private boolean hidereps = false;
+
+ /**
+ * set visibility of sequences covered by (if no sequence representative is
+ * defined) or represented by this group.
+ *
+ * @param visibility
+ */
+ public void setHidereps(boolean visibility)
+ {
+ hidereps = visibility;
+ }
+
+ /**
+ *
+ * @return true if sequences represented (or covered) by this group should be
+ * hidden
+ */
+ public boolean isHidereps()
+ {
+ return hidereps;
+ }
+
+ /**
+ * visibility of columns intersecting this group
+ */
+ private boolean hidecols = false;
+
+ /**
+ * set intended visibility of columns covered by this group
+ *
+ * @param visibility
+ */
+ public void setHideCols(boolean visibility)
+ {
+ hidecols = visibility;
+ }
+
+ /**
+ *
+ * @return true if columns covered by group should be hidden
+ */
+ public boolean isHideCols()
+ {
+ return hidecols;
+ }
+
+ /**
+ * create a new sequence group from the intersection of this group with an
+ * alignment Hashtable of hidden representatives
+ *
+ * @param alignment
+ * (may not be null)
+ * @param hashtable
+ * (may be null)
+ * @return new group containing sequences common to this group and alignment
+ */
+ public SequenceGroup intersect(AlignmentI alignment, Hashtable hashtable)
+ {
+ SequenceGroup sgroup = new SequenceGroup(this);
+ SequenceI[] insect = getSequencesInOrder(alignment);
+ sgroup.sequences = new Vector();
+ for (int s = 0; insect != null && s < insect.length; s++)
+ {
+ if (hashtable == null || hashtable.containsKey(insect[s]))
+ {
+ sgroup.sequences.addElement(insect[s]);
+ }
+ }
+ // Enumeration en =getSequences(hashtable).elements();
+ // while (en.hasMoreElements())
+ // {
+ // SequenceI elem = (SequenceI) en.nextElement();
+ // if (alignment.getSequences().contains(elem))
+ // {
+ // sgroup.addSequence(elem, false);
+ // }
+ // }
+ return sgroup;
+ }
+
+ /**
+ * @return the showUnconserved
+ */
+ public boolean getShowNonconserved()
+ {
+ return showNonconserved;
+ }
+
+ /**
+ * @param showNonconserved
+ * the showUnconserved to set
+ */
+ public void setShowNonconserved(boolean displayNonconserved)
+ {
+ this.showNonconserved = displayNonconserved;
+ }
+
+ AlignmentAnnotation consensus = null, conservation = null;
+
+ /**
+ * flag indicating if consensus histogram should be rendered
+ */
+ private boolean showConsensusHistogram;
+
+ /**
+ * set this alignmentAnnotation object as the one used to render consensus
+ * annotation
+ *
+ * @param aan
+ */
+ public void setConsensus(AlignmentAnnotation aan)
+ {
+ if (consensus == null)
+ {
+ consensus = aan;
+ }
+ }
+
+ /**
+ *
+ * @return automatically calculated consensus row
+ */
+ public AlignmentAnnotation getConsensus()
+ {
+ // TODO get or calculate and get consensus annotation row for this group
+ int aWidth = this.getWidth();
+ // pointer
+ // possibility
+ // here.
+ if (aWidth < 0)
+ {
+ return null;
+ }
+ if (consensus == null)
+ {
+ consensus = new AlignmentAnnotation("", "", new Annotation[1], 0f,
+ 100f, AlignmentAnnotation.BAR_GRAPH);
+ }
+ consensus.hasText = true;
+ consensus.autoCalculated = true;
+ consensus.groupRef = this;
+ consensus.label = "Consensus for " + getName();
+ consensus.description = "Percent Identity";
+ return consensus;
+ }
+
+ /**
+ * set this alignmentAnnotation object as the one used to render consensus
+ * annotation
+ *
+ * @param aan
+ */
+ public void setConservationRow(AlignmentAnnotation aan)
+ {
+ if (conservation == null)
+ {
+ conservation = aan;
+ }
+ }
+
+ /**
+ * get the conservation annotation row for this group
+ *
+ * @return autoCalculated annotation row
+ */
+ public AlignmentAnnotation getConservationRow()
+ {
+ if (conservation == null)
+ {
+ conservation = new AlignmentAnnotation("", "", new Annotation[1], 0f,
+ 11f, AlignmentAnnotation.BAR_GRAPH);
+ }
+
+ conservation.hasText = true;
+ conservation.autoCalculated = true;
+ conservation.groupRef = this;
+ conservation.label = "Conservation for " + getName();
+ conservation.description = "Conservation for group " + getName()
+ + " less than " + consPercGaps + "% gaps";
+ return conservation;
+ }
+
+ /**
+ *
+ * @return true if annotation rows have been instantiated for this group
+ */
+ public boolean hasAnnotationRows()
+ {
+ return consensus != null || conservation != null;
+ }
+
+ public SequenceI getConsensusSeq()
+ {
+ getConsensus();
+ StringBuffer seqs = new StringBuffer();
+ for (int i = 0; i < consensus.annotations.length; i++)
+ {
+ if (consensus.annotations[i] != null)
+ {
+ if (consensus.annotations[i].description.charAt(0) == '[')
+ {
+ seqs.append(consensus.annotations[i].description.charAt(1));
+ }
+ else
+ {
+ seqs.append(consensus.annotations[i].displayCharacter);
+ }
+ }
+ }
+
+ SequenceI sq = new Sequence("Group" + getName() + " Consensus",
+ seqs.toString());
+ sq.setDescription("Percentage Identity Consensus "
+ + ((ignoreGapsInConsensus) ? " without gaps" : ""));
+ return sq;
+ }
+
+ public void setIgnoreGapsConsensus(boolean state)
+ {
+ if (this.ignoreGapsInConsensus != state && consensus != null)
+ {
+ ignoreGapsInConsensus = state;
+ recalcConservation();
+ }
+ ignoreGapsInConsensus = state;
+ }
+
+ public boolean getIgnoreGapsConsensus()
+ {
+ return ignoreGapsInConsensus;
+ }
+
+ /**
+ * @param showSequenceLogo
+ * indicates if a sequence logo is shown for consensus annotation
+ */
+ public void setshowSequenceLogo(boolean showSequenceLogo)
+ {
+ // TODO: decouple calculation from settings update
+ if (this.showSequenceLogo != showSequenceLogo && consensus != null)
+ {
+ this.showSequenceLogo = showSequenceLogo;
+ recalcConservation();
+ }
+ this.showSequenceLogo = showSequenceLogo;
+ }
+
+ /**
+ *
+ * @param showConsHist
+ * flag indicating if the consensus histogram for this group should
+ * be rendered
+ */
+ public void setShowConsensusHistogram(boolean showConsHist)
+ {
+
+ if (showConsensusHistogram != showConsHist && consensus != null)
+ {
+ this.showConsensusHistogram = showConsHist;
+ recalcConservation();
+ }
+ this.showConsensusHistogram = showConsHist;
+ }
+
+ /**
+ * @return the showConsensusHistogram
+ */
+ public boolean isShowConsensusHistogram()
+ {
+ return showConsensusHistogram;
+ }
}