seurat对象处理 找锚点

在找锚点合并之前,需要把每个seurat对象的细胞名改变成唯一
getwd() #改名字

#教程地址
#https://cloud.tencent.com/developer/article/1697249


#https://bioconductor.org/packages/release/data/experiment/vignettes/scRNAseq/inst/doc/scRNAseq.html
#https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzI1Njk4ODE0MQ==&action=getalbum&album_id=1326587538303434752&scene=173&from_msgid=2247484689&from_itemidx=1&count=3&nolastread=1#wechat_redirect
rm(list = ls()) 
Sys.setenv(R_MAX_NUM_DLLS=999)
options(stringsAsFactors = F)

##########三对三的数据
1#准备原始分析数据  先手动下载  去浏览器下载文件到自己的文件夹下,然后解压
#https://www.ncbi.nlm.nih.gov/geo/query/acc.cgi  
# 3个样本,共9个文件。需要分到9个文件夹里,并且重命名
getwd()
path="G:/silicosis/geo/GSE128033_SnRNAseq-idiopathic pulmonary fibrosis/GSE128033" #空间转录组
dir.create(path)
setwd(path)
getwd()
fs=list.files('./','^GSM')  #得到当前目录下所有以GSM开头的文件名称
fs

seurat对象处理 找锚点_第1张图片




# 自行下载GSE164621数据集的GSE164621_RAW压缩包并且解压哦,这样上面的代码就可以运行啦

# 然后获取3个样本信息,因为是批量,所以下面的代码可能不好理解,需要熟练掌握R语言哦
library(stringr)
samples=str_split(fs,'_',simplify = T)[,1] #取出可以分组的样本名 有三个重复GSM5015042  GSM5015043 GSM5015044 得到样本分组
samples

在这里插入图片描述

getwd()
###注意workshop的位置,决定下一个语句是否成功!
setwd("G:/silicosis/geo/GSE128033_SnRNAseq-idiopathic pulmonary fibrosis/")

lapply(unique(samples),function(x){
  #x=unique(samples)[1]
  y=fs[grepl(x,fs)]
  folder=paste0("GSE128033/", str_split(y[1],'_',simplify = T)[,1])
  dir.create(folder,recursive = T)
  #为每个样本创建子文件夹
  
  file.rename(paste0("GSE128033/",y[1]),file.path(folder,"barcodes.tsv.gz"))
  #重命名文件,并移动到相应的子文件夹里
  file.rename(paste0("GSE128033/",y[2]),file.path(folder,"features.tsv.gz"))
  file.rename(paste0("GSE128033/",y[3]),file.path(folder,"matrix.mtx.gz"))
})
getwd()
samples=list.files("GSE128033/")
samples# 是两个文件夹的名字哦

在这里插入图片描述

samples=list.files("GSE128033/") %>% grep(pattern = "gz",invert = TRUE,value = TRUE)
samples# 是两个文件夹的名字哦

2#创建Seurat对

library(Seurat)

#测试用
if(1==1){
  myexam=  CreateSeuratObject(counts = Read10X(folder),
                              project = "pro" ,min.cells = 3,
                              min.features=200)
  myexam=subset(myexam)
}
dim(myexam)
getwd()
# 循环读取两个文件夹下面的10x的的3个文件
sceList = lapply(samples,function(pro){
  #pro="GSM3660641"
  folder=file.path("GSE128033/",pro)
  CreateSeuratObject(counts = Read10X(folder),  #此处一定要加上筛选条件
                     project = pro ,min.cells=3,min.features=200)
  ##print(paste0("进行到第",pro,"个样本")) 不可以打印这一排
})

添加print回发生错误,所有把print语句注释掉
seurat对象处理 找锚点_第2张图片
seurat对象处理 找锚点_第3张图片

for (i in 1:length(sceList)) {#计算线粒体比例
  sceList[[i]][["percent.mt"]]=PercentageFeatureSet(sceList[[i]],pattern = "^MT-")
}
sceList
DefaultAssay(sceList)

getwd()
save(sceList,file = 

你可能感兴趣的:(seurat,r)