这个数据包括了10个单细胞样本,但是他们事先将数据合并了,其实我只需要其中的3个样本,所以我需要拆分一下
1.加载数据
#首先加载数据
library(Seurat) #加载seurat软件
library(stringr)
library(tidyverse)
a=Read10X("./GSE162692/") #读取3个文件
a <- CreateSeuratObject(a) #创建Seurat对象
head(a@meta.data) #查看读取的数据前6行,结果如下展示
orig.ident nCount_RNA nFeature_RNA
AAACCTGAGAAACCAT-1 SeuratProject 41716 5360
AAACCTGAGCGATTCT-1 SeuratProject 7932 2309
AAACCTGCACAAGCCC-1 SeuratProject 14686 3437
AAACCTGCAGATGAGC-1 SeuratProject 21028 3773
AAACCTGGTGCGCTTG-1 SeuratProject 21707 3978
AAACCTGTCACCACCT-1 SeuratProject 58719 6547
2.正式拆分,使用tidyverse函数
library(tidyverse) #加载tidyverse
rownames(a@meta.data) -> a@meta.data$rowLeo #反向赋值,增加了1列
head(a@meta.data) #展示如下
orig.ident nCount_RNA nFeature_RNA rowLeo
AAACCTGAGAAACCAT-1 SeuratProject 41716 5360 AAACCTGAGAAACCAT-1
AAACCTGAGCGATTCT-1 SeuratProject 7932 2309 AAACCTGAGCGATTCT-1
AAACCTGCACAAGCCC-1 SeuratProject 14686 3437 AAACCTGCACAAGCCC-1
AAACCTGCAGATGAGC-1 SeuratProject 21028 3773 AAACCTGCAGATGAGC-1
AAACCTGGTGCGCTTG-1 SeuratProject 21707 3978 AAACCTGGTGCGCTTG-1
AAACCTGTCACCACCT-1 SeuratProject 58719 6547 AAACCTGTCACCACCT-1
str_split(a$rowLeo,"-") #将-作为拆分的字符,拆的结果如下展示
[[998]]
[1] "CCAATCCGTCTTGATG" "1"
[[999]]
[1] "CCAATCCTCCCATTTA" "1"
[[1000]]
[1] "CCACCTAAGAGCTGCA" "1"
#展示前6行
head(str_split(a$rowLeo,"-",simplify=T)) #展示前6行
[,1] [,2]
[1,] "AAACCTGAGAAACCAT" "1"
[2,] "AAACCTGAGCGATTCT" "1"
[3,] "AAACCTGCACAAGCCC" "1"
[4,] "AAACCTGCAGATGAGC" "1"
[5,] "AAACCTGGTGCGCTTG" "1"
[6,] "AAACCTGTCACCACCT" "1"
head(str_split(a$rowLeo,"-",simplify=T) [,2]) #展示第2列的前6行
[1] "1" "1" "1" "1" "1" "1"
str_split(a$rowLeo,"-",simplify=T) [,2] -> a@meta.data$Sample #反向赋值,实现分组
head(a@meta.data)
orig.ident nCount_RNA nFeature_RNA rowLeo Sample
AAACCTGAGAAACCAT-1 SeuratProject 41716 5360 AAACCTGAGAAACCAT-1 1
AAACCTGAGCGATTCT-1 SeuratProject 7932 2309 AAACCTGAGCGATTCT-1 1
AAACCTGCACAAGCCC-1 SeuratProject 14686 3437 AAACCTGCACAAGCCC-1 1
AAACCTGCAGATGAGC-1 SeuratProject 21028 3773 AAACCTGCAGATGAGC-1 1
AAACCTGGTGCGCTTG-1 SeuratProject 21707 3978 AAACCTGGTGCGCTTG-1 1
AAACCTGTCACCACCT-1 SeuratProject 58719 6547 AAACCTGTCACCACCT-1 1
tail(a@meta.data)
orig.ident nCount_RNA nFeature_RNA rowLeo Sample
TTTGCGCAGCGTCAAG-11 SeuratProject 2385 751 TTTGCGCAGCGTCAAG-11 11
TTTGCGCAGGTGCAAC-11 SeuratProject 2202 56 TTTGCGCAGGTGCAAC-11 11
TTTGGTTAGAAGAAGC-11 SeuratProject 3024 402 TTTGGTTAGAAGAAGC-11 11
TTTGGTTCAATGGAGC-11 SeuratProject 23182 3967 TTTGGTTCAATGGAGC-11 11
TTTGTCACAGCTGCTG-11 SeuratProject 9145 221 TTTGTCACAGCTGCTG-11 11
TTTGTCAGTGGTGTAG-11 SeuratProject 6533 215 TTTGTCAGTGGTGTAG-11 11
3.按照样本将数据提取出来
Leo <- SplitObject(a,split.by='Sample')
Leo
$`1`
An object of class Seurat
33694 features across 3001 samples within 1 assay
Active assay: RNA (33694 features, 0 variable features)
$`2`
An object of class Seurat
33694 features across 673 samples within 1 assay
Active assay: RNA (33694 features, 0 variable features)
$`3`
An object of class Seurat
33694 features across 1159 samples within 1 assay
Active assay: RNA (33694 features, 0 variable features)
$`4`
An object of class Seurat
33694 features across 1769 samples within 1 assay
Active assay: RNA (33694 features, 0 variable features)
4.将样本的seurat对象提取出来,并保存
Library IDs and cell barcode suffixes in processed data:
Cultured MSCs (Lonza, Switzerland) JTW01 = -1
BMAC cells JTW03 = -3
BMAC cells JTW05 = -4
BMAC cells JTW06 = -5
BMAC cells JTW07 = -6
BMAC cells JTW08 = -7
BMAC cells JTW10 = -8
BMAC cells MG01 = -9
BMAC cells MG02 = -10
BMAC cells MG03 = -11
Con01=Leo$`3`
Con02=Leo$`4`
Con03=Leo$`5`
Con04=Leo$`6`
Con05=Leo$`7`
Con06=Leo$`8`
Con07=Leo$`9`
Con08=Leo$`10`
Con09=Leo$`11`
#导出rds文件,下次需要的时候直接load进来就好,一个一个导,或者写个循环
saveRDS(Con09, file = "./bm_control/Con09.Rds")
参考了一下用户“璇而微珏”的教程,在此致敬一下