looking for GRanges ggply like ddply
1
0
Entering edit mode
Ido M. Tamir ▴ 150
@ido-m-tamir-2778
Last seen 9.6 years ago
Hi, I need to aggregate Granges by metadata I would like to write something like: ggply(granges, .(transcript_id, type), function(tt) { ... }) is this possible? thank you very much, ido
• 1.1k views
ADD COMMENT
0
Entering edit mode
@michael-lawrence-3846
Last seen 2.4 years ago
United States
Not really sure how ddply works (the "." syntax seems a bit weird) but I think you want something like: do.call(c, tapply(gr, list(gr$transcript_id, gr$type), function(tt) { }, simplify=FALSE)) Michael On Fri, Mar 21, 2014 at 8:19 AM, Ido Tamir <tamir@imp.ac.at> wrote: > Hi, > I need to aggregate Granges by metadata I would like to write something > like: > > ggply(granges, .(transcript_id, type), function(tt) { > ... > }) > > is this possible? > > thank you very much, > ido > > _______________________________________________ > Bioconductor mailing list > Bioconductor@r-project.org > https://stat.ethz.ch/mailman/listinfo/bioconductor > Search the archives: > http://news.gmane.org/gmane.science.biology.informatics.conductor > [[alternative HTML version deleted]]
ADD COMMENT
0
Entering edit mode
Howdy, On Fri, Mar 21, 2014 at 9:12 AM, Michael Lawrence <lawrence.michael at="" gene.com=""> wrote: > Not really sure how ddply works (the "." syntax seems a bit weird) but I > think you want something like: > > do.call(c, tapply(gr, list(gr$transcript_id, gr$type), function(tt) { > }, simplify=FALSE)) Clever -- somehow I never realized we had specialized versions of more than just lapply, and mapply ... maybe it's because I've never been a fan of `tapply` (I mean, what does the `t` mean, anyway?) Anyway, the OP's `ggply` function would be neat -- perhaps a `bioplyr` package could interesting/fun for somebody whose got some time for a little yak shaving ... ;-) -steve -- Steve Lianoglou Computational Biologist Genentech
ADD REPLY
0
Entering edit mode
On Fri, Mar 21, 2014 at 11:05 AM, Steve Lianoglou <lianoglou.steve@gene.com>wrote: > Howdy, > > On Fri, Mar 21, 2014 at 9:12 AM, Michael Lawrence > <lawrence.michael@gene.com> wrote: > > Not really sure how ddply works (the "." syntax seems a bit weird) but I > > think you want something like: > > > > do.call(c, tapply(gr, list(gr$transcript_id, gr$type), function(tt) { > > }, simplify=FALSE)) > > Clever -- somehow I never realized we had specialized versions of more > than just lapply, and mapply ... maybe it's because I've never been a > fan of `tapply` (I mean, what does the `t` mean, anyway?) > > I'm pretty sure it originates from its use in generating contingency /t/ables, see example(tapply). > Anyway, the OP's `ggply` function would be neat -- perhaps a `bioplyr` > package could interesting/fun for somebody whose got some time for a > little yak shaving ... ;-) > > I was thinking to achieve something close to the convenience of ddply without moving too far from the R API would be: aggregate(~ transcript_id + type, gr, function(tt) { }) The default aggregate() requires a formula with an LHS, but I can see no reason why it couldn't behave like ddply in the case where the LHS is empty. > -steve > > -- > Steve Lianoglou > Computational Biologist > Genentech > [[alternative HTML version deleted]]
ADD REPLY
0
Entering edit mode
On Fri, Mar 21, 2014 at 11:33 AM, Michael Lawrence <lawrence.michael at="" gene.com=""> wrote: > On Fri, Mar 21, 2014 at 11:05 AM, Steve Lianoglou > <lianoglou.steve at="" gene.com="">wrote: > >> Howdy, >> >> On Fri, Mar 21, 2014 at 9:12 AM, Michael Lawrence >> <lawrence.michael at="" gene.com=""> wrote: >> > Not really sure how ddply works (the "." syntax seems a bit weird) but I >> > think you want something like: >> > >> > do.call(c, tapply(gr, list(gr$transcript_id, gr$type), function(tt) { >> > }, simplify=FALSE)) >> >> Clever -- somehow I never realized we had specialized versions of more >> than just lapply, and mapply ... maybe it's because I've never been a >> fan of `tapply` (I mean, what does the `t` mean, anyway?) >> >> > I'm pretty sure it originates from its use in generating contingency > /t/ables, see example(tapply). > > >> Anyway, the OP's `ggply` function would be neat -- perhaps a `bioplyr` >> package could interesting/fun for somebody whose got some time for a >> little yak shaving ... ;-) >> >> > > I was thinking to achieve something close to the convenience of ddply > without moving too far from the R API would be: > > aggregate(~ transcript_id + type, gr, function(tt) { > }) `aggregate` ... Ack! My eyes! To my detriment (and embarrassment!), my eyes always begin to gloss-over when I try to parse that syntax[1] when it's used for things outside of linear modeling, and have always steered clear (although I am trying to make a more concerted effort of dealing with it in reshap-ing and stuff more recently). I know it's a base R thing ... but ugh ... I guess it should have clicked by now, but I've never given it its due, hence my love of plyr and data.table for (at least) these types of summary tasks. [1] Heaven forbid there be a call to `substitute` or `quote` in close proximity to a strange formula-like looking `aggregate` or `xtabs` call -- I may start seeing dead people. -steve -- Steve Lianoglou Computational Biologist Genentech
ADD REPLY

Login before adding your answer.

Traffic: 561 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6