Skip to content

Instantly share code, notes, and snippets.

@crazyhottommy
Last active October 24, 2018 03:35
Show Gist options
  • Save crazyhottommy/f11e06da0e069cfb76420495d1709f77 to your computer and use it in GitHub Desktop.
Save crazyhottommy/f11e06da0e069cfb76420495d1709f77 to your computer and use it in GitHub Desktop.

load libraries

#install.packages("tidyverse")
#install.packages("Seurat")
# here package is to get rid of absolute path
# see details https://github.com/jennybc/here_here
#install.packages("here")
# interact with file systems https://github.com/r-lib/fs
#install.packages("fs")
library(tidyverse)
library(Seurat)
library(here)
library(fs)
library(purrr)
here()

read in the data as seruat object

and then merge satijalab/seurat#480

input_folders<- dir_ls( path = here("data"), recursive = T) %>% path_dir() %>%
        unique() %>% str_subset(""mm10-1.2.0_premrna")

samples<- str_extract(input_folders, pattern = yourpattern)
names(input_folders)<- samples
seurat_data<- purrr::map(input_folders, Read10X)

#prefix the sample name to the cell name, otherwise merge seurat objects gives error
add_sample_name_to_cell<- function(x, y){
        colnames(x)<- paste(y, colnames(x), sep = "_")
        return(x)
}

seurat_data<- map2(seurat_data, samples, add_sample_name_to_cell)
seurat_objects<- map2(seurat_data, samples, function(x,y) CreateSeuratObject(raw.data = x, project = y))

merge


merged_seurat<- purrr::reduce(seurat_objects, function(x,y) {MergeSeurat(x,y, do.normalize = F)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment