knitr::opts_chunk$set(echo = TRUE)
options(width = 100)

Download data

The count table was downloaded from https://s3.amazonaws.com/czbiohub-tabula-muris/TM_facs_mat.rds, following instructions on https://github.com/czbiohub/tabula-muris-vignettes/tree/master/data (accessed August 26, 2018).

The metadata was obtained from https://github.com/czbiohub/tabula-muris-vignettes/tree/master/data (accessed August 26, 2018).

suppressPackageStartupMessages({
    library(Matrix)
    library(SingleCellExperiment)
    library(readr)
    library(dplyr)
})

counts <- readRDS("TM_facs_mat.rds")
metadata <- readr::read_csv("TM_facs_metadata.csv")

Generate SingleCellExperiment object

stopifnot(all(colnames(counts) == metadata$cell))

smartseq2 <- SingleCellExperiment(
    assay = list(counts = counts),
    colData = DataFrame(metadata %>% dplyr::rename(mouse_id = mouse.id,
                                                   mouse_sex = mouse.sex,
                                                   plate_barcode = plate.barcode,
                                                   FACS_selection = FACS.selection)),
    rowData = DataFrame(ID = rownames(counts),
                        Symbol = rownames(counts))
)

Mark ERCCs

SingleCellExperiment::isSpike(smartseq2, "ERCC") <- 
    grep("^ERCC-", rownames(smartseq2))
dim(smartseq2)
table(isSpike(smartseq2, "ERCC"))

Harmonize annotations with 10x data

smartseq2$mouse_id <- vapply(smartseq2$mouse_id, function(i) {
    tmp <- lapply(strsplit(i, "/")[[1]], function(w) {
        strsplit(w, "_")[[1]]
    })
    paste(unlist(vapply(c(1, 3, 2), function(j) {
        paste(unique(unlist(lapply(tmp, function(x) x[j]))), collapse = "/")
    }, "")), collapse = "-")
}, "")

Save SingleCellExperiment object

smartseq2
head(colData(smartseq2))
saveRDS(smartseq2, file = "TabulaMurisSmartSeq2.rds")

Session info

sessionInfo()


csoneson/TabulaMurisData documentation built on July 15, 2024, 5:13 p.m.