The support.bioconductor.org editor has been updated to markdown! Please see more info at: Tutorial: Updated Support Site Editor

Question: Subset SummarizedExperiment Objects by Metadata
1
gravatar for Lucas Schiffer
12 months ago by
CUNY School of Public Health, New York, NY
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 • 258 views
ADD COMMENTlink modified 12 months ago • written 12 months ago by Lucas Schiffer220
Answer: Subset SummarizedExperiment Objects by Metadata
2
gravatar for Martin Morgan
12 months ago by
Martin Morgan ♦♦ 22k
United States
Martin Morgan ♦♦ 22k 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 12 months ago by Martin Morgan ♦♦ 22k
Answer: Subset SummarizedExperiment Objects by Metadata
0
gravatar for Lucas Schiffer
12 months ago by
CUNY School of Public Health, New York, NY
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 10 months ago • written 12 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: 207 users visited in the last hour