Question: Subset SummarizedExperiment Objects by Metadata
1
gravatar for Lucas Schiffer
15 months ago by
Boston University, Boston, MA
Lucas Schiffer220 wrote:

After some searching and reading of old post (subsetting SummarizedExperiments - a proposal (or a hack?)) I am wondering if there exist a manner in which SummarizedExperiment objects can be subset by metadata with an explicit method beyond [. To illustrate, I have a small example:

This is possible with the bracket method:

library(HMP16SData)
V13 <- V13()
V13[, V13$hmp_body_subsite == "Stool"]

But I have something in mind like this:

library(HMP16SData)
V13 <- V13()
subset(V13, V13$hmp_body_subsite == "Stool")

I have looked at subset in SummarizedExperiment and FilterRules in S4Vectors but don't yet have a clear idea how this might be accomplished. Any idea would be helpful, thanks!

summarizedexperiment • 294 views
ADD COMMENTlink modified 15 months ago • written 15 months ago by Lucas Schiffer220
Answer: Subset SummarizedExperiment Objects by Metadata
2
gravatar for Martin Morgan
15 months ago by
Martin Morgan ♦♦ 23k
United States
Martin Morgan ♦♦ 23k wrote:

Try

V13 <- as(V13, "RangedSummarizedExperiment")
subset(V13, select = hmb_body_subsite == "Stool")

Actually the coercion seems to be a hack; I'm not sure why there is  no subset,SummarizedExperiment-method; an implementation might be

setMethod("subset", "SummarizedExperiment",
    function(x, subset, select, ...)
{
    i <- S4Vectors:::evalqForSubset(subset, rowData(x), ...)
    j <- S4Vectors:::evalqForSubset(select, colData(x), ...)
    x[i, j]
})

 

ADD COMMENTlink written 15 months ago by Martin Morgan ♦♦ 23k
Answer: Subset SummarizedExperiment Objects by Metadata
0
gravatar for Lucas Schiffer
15 months ago by
Boston University, Boston, MA
Lucas Schiffer220 wrote:

Thank you Martin. Even with subset(V13, select = V13$hmp_body_subsite == "Stool") there is still an error with the coercion but once the method is there then the behavior is as expected. I will add this a pull request against SummarizedExperiment on GitHub.

ADD COMMENTlink modified 12 months ago • written 15 months ago by Lucas Schiffer220
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 112 users visited in the last hour