[Biojava-dev] WeightMatrixAnnotator
Schreiber, Mark
mark.schreiber at agresearch.co.nz
Tue Dec 2 19:34:57 EST 2003
Hi -
These additional methods have been added to CVS. Thanks Tanya.
- Mark
> -----Original Message-----
> From: Tanya Vavouri [mailto:tvavouri at hotmail.com]
> Sent: Wednesday, 3 December 2003 1:04 a.m.
> To: biojava-dev at biojava.org
> Subject: [Biojava-dev] WeightMatrixAnnotator
>
>
> Hi,
>
> I've made some really simple changes to the latest
> WeightMatrixAnnotator
> that have allowed me to annotate sequences with multiple
> weight matrices.
> Basically, I've just added an extra variable the String wmID,
> a constructor
> that initialises with a user specified weight matrix ID and a
> getter/setter
> for the weight matrix ID.
>
> The changes are really simple but below is the code if anyone
> is interested
> to use it or add it to biojava.
>
> Thanks
> Tanya Vavouri
>
> package org.biojava.bio.dp;
>
> import java.io.Serializable;
>
> import org.biojava.bio.BioException;
> import org.biojava.bio.SimpleAnnotation;
> import org.biojava.bio.seq.Feature;
> import org.biojava.bio.seq.Sequence;
> import org.biojava.bio.seq.SequenceAnnotator;
> import org.biojava.bio.seq.impl.ViewSequence;
> import org.biojava.bio.symbol.IllegalAlphabetException;
> import org.biojava.bio.symbol.RangeLocation;
> import org.biojava.utils.ChangeVetoException;
>
> /**
> * Annotates a sequence with hits to a weight-matrix.
> *
> * <p>
> * This SequenceAnnotator implementation returns a new
> * ViewSequence wrapping the underlying Sequence
> * </p>
> *
> * @author Matthew Pocock
> * @author Thomas Down
> */
> public class WeightMatrixAnnotator implements SequenceAnnotator,
> Serializable {
> private WeightMatrix matrix;
> private double threshold;
> private final ScoreType scoreType;
> private String wmID;
>
> public Sequence annotate(Sequence seq)
> throws IllegalAlphabetException, BioException,
> ChangeVetoException
> {
> seq = new ViewSequence(seq);
>
> int cols = matrix.columns();
> Feature.Template template = new Feature.Template();
> template.source = "WeightMatrixAnnotator";
> template.type = wmID;
> for(int offset = 1;
> offset <= seq.length() - cols + 1;
> offset++) {
> double score = DP.scoreWeightMatrix(matrix, seq,
> scoreType, offset);
> double q = Math.exp(score);
> if(q >= threshold) {
> template.location = new RangeLocation(offset,
> offset+cols-1);
> SimpleAnnotation ann = new SimpleAnnotation();
> ann.setProperty("score", new Double(q));
> ann.setProperty("weightMatrix", matrix);
> template.annotation = ann;
> seq.createFeature(template);
> }
> }
> return seq;
> }
>
> /**
> * Create a new annotator that uses the PROBABILITY score
> type and an ID
> for the weight matrix.
> *
> * @param wm the weight matrix
> * @param threshold the threshold
> * @param wmID the weight matrix ID
> */
> public WeightMatrixAnnotator(WeightMatrix wm, ScoreType
> scoreType,
> double threshold, String wmID) {
> this.matrix = wm;
> this.threshold = threshold;
> this.scoreType = ScoreType.PROBABILITY;
> this.wmID = wmID;
> }
>
> /**
> * Create a new annotator that uses PROBABILITY score type.
> *
> * @param wm a <code>WeightMatrix</code> value
> * @param threshold a <code>double</code> value
> */
> public WeightMatrixAnnotator(WeightMatrix wm, double threshold) {
> this(wm, ScoreType.PROBABILITY, threshold, "hit");
> }
>
> /**
> * Create a new annotator that uses a specific score type.
> *
> * @param wm the weigth matrix
> * @param scoreType the score type
> * @param threshold the threshold
> * @since 1.4
> */
> public WeightMatrixAnnotator(WeightMatrix wm, ScoreType
> scoreType,
> double threshold) {
> this.matrix = wm;
> this.scoreType = scoreType;
> this.threshold = threshold;
> this.wmID = "hit";
> }
>
> /**
> * Get the value of the weight matrix id.
> * @return value of the weight matrix id.
> */
> public String getWmID() {
> return wmID;
> }
>
> /**
> * Set the weight matrix id.
> * @param v Value to assign to the weight matrix id.
> */
> public void setWmID(String v) {
> this.wmID = v;
> }
>
>
> }
>
> _________________________________________________________________
> Tired of 56k? Get a FREE BT Broadband connection
> http://www.msn.co.uk/specials/btbroadband
>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at biojava.org
> http://biojava.org/mailman/listinfo/biojava-> dev
>
=======================================================================
Attention: The information contained in this message and/or attachments
from AgResearch Limited is intended only for the persons or entities
to which it is addressed and may contain confidential and/or privileged
material. Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by persons or
entities other than the intended recipients is prohibited by AgResearch
Limited. If you have received this message in error, please notify the
sender immediately.
=======================================================================
More information about the biojava-dev
mailing list