HelenaLC/muscat

Importing seurat object directly to muscat

ps120195 opened this issue · 5 comments

Can we directly import seurat combined objects for differential expression analysis in this tool??

I am not sure what you mean by "directly". Seurat has a as.SingleCellExperiment coercion function, with which you could convert the Seurat object to a SingleCellExperiment. Have you tried using this?

Closing due to inactivity. Feel free to re-open if you have issues with this, and feel free to ask for further support in this thread.

I was looking for a way to directly pass seurat merged object of multiple cell types into muscat . I tried the way suggested by you, but that is not working.

I tried this as follows:
my10x<-as.SingleCellExperiment(allcellsdata)
my10x
assayNames(my10x)
pb<-aggregateData(my10x,assay = "counts",fun ="sum",by = c("ident","orig.ident"))
pb
t(head(assay(pb)))
(pb_mds <- pbMDS(pb))
Here i encountered the below error :
Error in .check_pbs(x, check_by = TRUE) : !is.null(ei <- metadata(pbs)$experiment_info) is not TRUE

Help needed. Thank you

Aha, yes. So, muscat expects an experiment_info slot in the metadata to exist. This should be a data.frame with rows = samples and columns = correspondent metadata such as group_id, patient_id etc. (anything else that could be included in the downstream statistical model for DS analysis). You should be able to easily generate this & add it to the input SCE (in your case, my10x) as follows:

ids <- unique(sce$sample_id)
idx <- match(ids, sce$sample_id)

var <- c("sample_id", "group_id", "patient_id", ...)
md <- data.frame(colData(sce)[idx, var])
metadata(sce)$experiment_info <- md

On a side note, there's also an internal function to do this (muscat:::.make_ei()), however, it expects a sample_id and group_id column to exist in the colData:

.make_ei <- function(x) {
    if (is(x, "SingleCellExperiment"))
        x <- colData(x)
    sids <- unique(x$sample_id)
    m <- match(sids, x$sample_id)
    df <- data.frame(
        stringsAsFactors = FALSE,
        sample_id = sids,
        group_id = x$group_id[m],
        n_cells = as.numeric(table(x$sample_id)[sids]))
    for (i in c("sample_id", "group_id"))
        if (is.factor(x[[i]]))
            df <- mutate_at(df, i, factor, levels = levels(x[[i]]))
    return(df)
}

Finally, to make everything easier, you could simply run prepSCE() to bring my10x into the desired format. Essentially, all of muscat assumes specific slots to exist; and prepSCE() is designed to take care of this.