library(DropletUtils)
library(Seurat)

    # set up data/raw folder to host raw 10x data 
    ifelse(!dir.exists(paste(getwd(), "data/raw", sep = "/")), 
           dir.create(paste(getwd(), "data/raw", sep = "/"), showWarnings = FALSE, recursive = TRUE), FALSE)
    raw_path <- paste(getwd(), "data/raw", sep = "/")

    # set up data/proc folder to host seurat/bioc objects 
    ifelse(!dir.exists(paste(getwd(), "data/proc", sep = "/")), 
           dir.create(paste(getwd(), "data/proc", sep = "/"), showWarnings = FALSE, recursive = TRUE), FALSE)
    proc_path <- paste(getwd(), "data/proc", sep = "/")

    # prepare params for bash excution
    sample_name <- params$sample_name
    Sys.setenv(fd_s3 = params$fd_s3) 
    Sys.setenv(raw_path = raw_path)
    Sys.setenv(proc_path = proc_path)

SCE

sync file from s3 to ec2

    system("aws s3 sync $fd_s3 $raw_path --region us-east-2")

unzip and rename files to SingleCellExperiment input format

    gunzip "${raw_path}/barcodes.tsv.gz"
    gunzip "${raw_path}/matrix.mtx.gz"
    gunzip "${raw_path}/features.tsv.gz"
    mv "${raw_path}/features.tsv" "${raw_path}/genes.tsv"

create and save SCE object

# create objects folder under raw folder
    sce_obj <- read10xCounts(raw_path)
    save(sce_obj, file = paste(paste(proc_path, "/", sep = ""), paste(sample_name, "sce_raw.RData", sep="_"), sep = ""))
    rm(sce_obj)

Seurat

sync file from s3 to ec2

    system("aws s3 sync $fd_s3 $raw_path --region us-east-2")

create and save Seurat object

    dat <- Read10X(data.dir = raw_path) 
    rownames(x = dat[["Antibody Capture"]]) <- gsub(pattern = "_TotalSeqC", replacement = "", x = rownames(x = dat[["Antibody Capture"]]))

    se_obj <- CreateSeuratObject(counts = dat[["Gene Expression"]])
    se_obj[["ADT"]] <- CreateAssayObject(counts = dat[["Antibody Capture"]][, colnames(se_obj)])

    save(se_obj, file = paste(paste(proc_path, "/", sep = ""), paste(sample_name, "seurat_raw.RData", sep = "_"), sep = ""))
    rm(dat, se_obj)

clean up raw folder

    rm "${raw_path}"/*


LarsenLab/immuntools documentation built on July 19, 2023, 9:43 a.m.