waldronlab / MultiAssayExperiment

Bioconductor package for management of multi-assay data
https://waldronlab.io/MultiAssayExperiment/
70 stars 32 forks source link

subsetting behavior when an assay has no rownames #256

Closed lwaldron closed 5 years ago

lwaldron commented 5 years ago

RaggedExperiment objects from curatedTCGAData have no rownames, causing all row subsetting operations to error. I think a better behavior would be to ignore such assays when row subsetting.

Example:

library(curatedTCGAData)
mae <- curatedTCGAData("ACC", c("Mutation", "RNASeq2GeneNorm"), dry.run = FALSE) 
rn <- rownames(mae)
rn
#> CharacterList of length 2
#> [["ACC_Mutation-20160128"]] character(0)
#> [["ACC_RNASeq2GeneNorm-20160128"]] A1BG A1CF A2BP1 ... ZZZ3 psiTPTE22 tAKR
mae[rn, , ]
#> Error: cannot subset by character when rownames are NULL
subsetByRow(mae, rn)
#> Error: cannot subset by character when rownames are NULL

Perhaps the above really should error, but I expected this to simply maintain the RaggedExperiment untouched:

rn[[1]] <- TRUE
mae[rn, , ]
#> Error: cannot subset by character when rownames are NULL
subsetByRow(mae, rn)
#> Error: cannot subset by character when rownames are NULL

I think the following should also ignore the Mutation assay:

rn[-1]
#> CharacterList of length 1
#> [["ACC_RNASeq2GeneNorm-20160128"]] A1BG A1CF A2BP1 ... ZZZ3 psiTPTE22 tAKR
mae[rn[-1], , ]
#> Error: cannot subset by character when rownames are NULL
LiNk-NY commented 5 years ago

Hi Levi, @lwaldron

This is just due to the bracket subset method for signature = c("List", "list"). By convention, when subsetting by an empty vector, all of the rows or columns are removed. This is the effect that List[list] is going for.

I can change it to only subset experiments when the subset vector is not empty and the row names are not null.

-MR

LiNk-NY commented 5 years ago

As I understand it, a single list input for row subsetting would only subset the particular named assay to satisfy:

identical(mae[rn[-1], , ], mae)
LiNk-NY commented 5 years ago

@lwaldron Should this behavior be expected for columns as well?

lwaldron commented 5 years ago

Yes. Specifically:

mae[, List(assay2=1:3), ]

would select the first three columns of assay2, just like:

mae[List(assay2=1:3), ,]

would select the first three rows of assay2.