scRNA 批量导入从数据库中下载的scRNA数据
点击查看代码
library(Seurat)
#从数据库里下载并解压的文件路径
path <- './GSE221575_RAW/'
fs = list.files(path,pattern = '^GSM')
samples <- substr(fs,1,10)
lapply(unique(samples), function(x){
y = fs[grepl(x,fs)]
folder = paste0(path,paste(strsplit(y[1],split = '_')[[1]][1],strsplit(y[1],split = '_')[[1]][2],sep = '_'))
#创建文件夹
dir.create(folder,recursive = T)
#重命名子文件夹并移动到相应的文件夹中
file.rename(paste0(path,y[1]),file.path(folder,"barcodes.tsv.gz"))
file.rename(paste0(path,y[2]),file.path(folder,"features.tsv.gz"))
file.rename(paste0(path,y[3]),file.path(folder,"matrix.mtx.gz"))
})
samples <- dir(path = path, pattern="^GSM")
for (i in samples){
assign(i, Read10X(data.dir = paste0(path, i)))
}