Subset SummarizedExperiment Objects by Metadata
2
1
Entering edit mode
@schifferl
Last seen 7 months ago
New York, NY

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 • 1.5k views
ADD COMMENT
2
Entering edit mode
@martin-morgan-1513
Last seen 4 months ago
United States

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 COMMENT
0
Entering edit mode
@schifferl
Last seen 7 months ago
New York, NY

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 COMMENT

Login before adding your answer.

Traffic: 628 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