On Wed, Apr 21, 2010 at 6:07 AM, Yvan <yvan.strahm@uni.no> wrote:

> Hello List,
>
> I am confused about  how to loop over a rangedData object.
> I have this rangedData
>
> RangedData with 61 rows and 1 value column across 3 spaces
>         space     ranges |     score
> <character> <IRanges> | <numeric>
> 1   SCAFFOLD_1 [  8,   8] |  -0.09405
>
> and the spaces are
>
> "SCAFFOLD_1"   "SCAFFOLD_10"  "SCAFFOLD_100"
>
> using aggregate it is possible to apply a function to one of the space
>
> aggregate(rd["SCAFFOLD_1"]$score, start =
> 1:(length(rd["SCAFFOLD_1"]$score)-w+1), width = w, FUN = sum)
>
> but how can I apply the aggregate to all space without a for loop ?
>
>
It looks like you're attempting a running window sum of the score vector.
There are more efficient ways of doing this besides aggregate(). If you
convert the score into an Rle, you can use runsum().

Anyway, to do this over each space individually, use lapply().

This would come out to something like:

values(rd)[,"smoothScore"] <- lapply(rd, function(x) runsum(Rle(x$score),
w))

Probably not exactly right, but it gets you in the right direction...

Michael


> And it is possible to add a column sum "on the fly" or should I create a
> vector "sum" containing values for all spaces and the recreate a rangedData
> object with this extra column?
>
>
> Thanks for your help and patience
> yvan
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor@stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>

	[[alternative HTML version deleted]]

