waldronlab / MultiAssayExperiment

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

Infer MAE-level colData from sampleMap when the former is not supplied #287

Closed LTLA closed 3 years ago

LTLA commented 3 years ago

A quality-of-life improvement for the MAE constructor would be to infer an appropriate colData= value from sampleMap= if the former is not explicitly supplied. For example:

library(MultiAssayExperiment)

# Making up some data.
mat <- matrix(rpois(10000, 5), nrow=10)
rownames(mat) <- paste0("CD", seq_len(nrow(mat))) # made-up markers
colnames(mat) <- paste0("BARCODE_", seq_len(ncol(mat))) # made-up barcodes

# First building the SE. Assuming that barcodes come from a range of donors.
donor <- rep(LETTERS[1:10], each=100)
se <- SummarizedExperiment(list(counts=mat))
se$Donor <- donor

# Now building the MAE. Each 'column' of the MAE corresponds to a donor;
# this is specified by the sample mapping from donors (primary) to barcodes (colname).
mae <- MultiAssayExperiment(list(markers=se),
    sampleMap=data.frame(assay="markers", primary=se$Donor, colname=colnames(se)),
    colData=DataFrame(row.names=LETTERS[1:10])
)

Basically, I would like to avoid having to set the final colData=, given that the row names for a sensible default could easily be inferred from unique(sampleMap$primary). So basically, I would like to get the same results from the code below:

mae <- MultiAssayExperiment(list(markers=se),
    sampleMap=data.frame(assay="markers", primary=se$Donor, colname=colnames(se))
)

Though right now I get an MAE with all columns stripped:

## harmonizing input:
##   removing 1000 sampleMap rows with 'primary' not in colData
##   removing 1000 colData rownames not in sampleMap 'primary'

causing me to scratch my head for a minute and wonder what I did wrong.

lwaldron commented 3 years ago

Seems like a reasonable request to me, @LiNk-NY?

LiNk-NY commented 3 years ago

Thanks Levi and Aaron, I've included this change in version 1.17.3