HelenaLC / muscat

Multi-sample multi-group scRNA-seq analysis tools
166 stars 33 forks source link

`prepSCE`: only replace colData of original SCE #61

Closed milanmlft closed 3 years ago

milanmlft commented 3 years ago

Keep the original SingleCellExperiment object and only replace the colData() and add experiment_info to the metadata(). This ensures that other slots, such as altExps() or prior metadata() are retained.

Other minor additions:

The example using scuttle::mockSCE() shows the effect: the input sce contains an altExp(), which would have been removed before by prepSCE(). Now it remains:

library(muscat)

# generate random counts
ng <- 50
nc <- 200

# generate some cell metadata
gids <- sample(c("groupA", "groupB"), nc, TRUE)
sids <- sample(paste0("sample", seq_len(3)), nc, TRUE)
kids <- sample(paste0("cluster", seq_len(5)), nc, TRUE)
batch <- sample(seq_len(3), nc, TRUE)
cd <- data.frame(group = gids, id = sids, cluster = kids, batch)

# construct SCE
library(scuttle)
sce <- mockSCE(ncells = nc, ngenes = ng)
colData(sce) <- cbind(colData(sce), cd)

# prep. for workflow
sce <- prepSCE(sce, kid = "cluster", sid = "id", gid = "group")
sce
#> class: SingleCellExperiment 
#> dim: 50 200 
#> metadata(1): experiment_info
#> assays(1): counts
#> rownames(50): Gene_0001 Gene_0002 ... Gene_0049 Gene_0050
#> rowData names(0):
#> colnames(200): Cell_001 Cell_002 ... Cell_199 Cell_200
#> colData names(7): cluster_id sample_id ... Treatment batch
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(1): Spikes