之前cellranger count以及aggr拿到了三组表达矩阵文件,后续使用seurat等R包进行处理
配置:
Linux/R4.1.0
1.安装BiocManager
> install.packages("BiocManager")
--- Please select a CRAN mirror for use in this session ---
Secure CRAN mirrors
.
21: China (Guangzhou) [https]
.
Selection: 21
* DONE (BiocManager)
The downloaded source packages are in
‘/tmp/Rtmpn99W31/downloaded_packages’
# 安装成功
> library(BiocManager)
Bioconductor version 3.14 (BiocManager 1.30.16), R 4.1.0 (2021-05-18)
2. 安装Seurat等
第一次装,问题真多,小白头疼
> BiocManager::install("Seurat")
.
.
# 疯狂error,查看
> warnings()
Warning messages:
1: In .inet_warning(msg) :
installation of package ‘caTools’ had non-zero exit status
2: In .inet_warning(msg) :
installation of package ‘sitmo’ had non-zero exit status
3: In .inet_warning(msg) :
installation of package ‘openssl’ had non-zero exit status
4: In .inet_warning(msg) :
installation of package ‘htmlwidgets’ had non-zero exit status
5: In .inet_warning(msg) :
installation of package ‘crosstalk’ had non-zero exit status
6: In .inet_warning(msg) :
installation of package ‘RSpectra’ had non-zero exit status
7: In .inet_warning(msg) :
installation of package ‘future’ had non-zero exit status
8: In .inet_warning(msg) :
installation of package ‘miniUI’ had non-zero exit status
9: In .inet_warning(msg) :
installation of package ‘patchwork’ had non-zero exit status
10: In .inet_warning(msg) :
installation of package ‘RcppAnnoy’ had non-zero exit status
11: In .inet_warning(msg) :
installation of package ‘reticulate’ had non-zero exit status
12: In .inet_warning(msg) :
installation of package ‘Rtsne’ had non-zero exit status
13: In .inet_warning(msg) :
installation of package ‘scattermore’ had non-zero exit status
14: In .inet_warning(msg) :
installation of package ‘SeuratObject’ had non-zero exit status
15: In .inet_warning(msg) :
installation of package ‘spatstat.geom’ had non-zero exit status
16: In .inet_warning(msg) :
installation of package ‘gplots’ had non-zero exit status
17: In .inet_warning(msg) :
installation of package ‘dqrng’ had non-zero exit status
18: In .inet_warning(msg) :
installation of package ‘future.apply’ had non-zero exit status
19: In .inet_warning(msg) :
installation of package ‘httr’ had non-zero exit status
20: In .inet_warning(msg) :
installation of package ‘leiden’ had non-zero exit status
21: In .inet_warning(msg) :
installation of package ‘spatstat.core’ had non-zero exit status
22: In .inet_warning(msg) :
installation of package ‘plotly’ had non-zero exit status
23: In .inet_warning(msg) :
installation of package ‘ROCR’ had non-zero exit status
24: In .inet_warning(msg) :
installation of package ‘sctransform’ had non-zero exit status
25: In .inet_warning(msg) :
installation of package ‘uwot’ had non-zero exit status
26: In .inet_warning(msg) :
installation of package ‘Seurat’ had non-zero exit status
太多了,找了个笨办法,直接一个一个装,装了我一个小时终于全装上了
> install.packages("caTools")
# 报错就再install缺失的包
报错package ‘bitops’ was installed before R 4.0.0,就install packages bitops,一直装,装到装上为止
> packageVersion("Seurat")
[1] ‘4.0.5’
这个网址进去有Seurat的详细用法
Seurat package - RDocumentation
https://www.rdocumentation.org/packages/Seurat/versions/4.0.5
3.读取并创建Seurat对象
之前aggr生成三组文件

整个流程
# 将三文件拷贝至新目录方便使用
cp -r /mnt/sra/patient9/patient9/outs/count/filtered_feature_bc_matrix /mnt/scrna/raw9
cp -r /mnt/sra/patient12/patient12/outs/count/filtered_feature_bc_matrix /mnt/scrna/raw12
cp -r /mnt/sra/patient14/patient14/outs/count/filtered_feature_bc_matrix /mnt/scrna/raw14
# 创建Seurat对象
R
> library(Seurat)
Attaching SeuratObject
> samples = list.files("/mnt/scrna/")
> samples
[1] "raw12" "raw14" "raw9"
> scList = lapply(samples,function(pro){
+ folder = file.path("/mnt/scrna/",pro)
+ CreateSeuratObject(counts = Read10X(folder),project = pro)
+ })
> scList
[[1]]
An object of class Seurat
36702 features across 28937 samples within 1 assay
Active assay: RNA (36702 features, 0 variable features)
[[2]]
An object of class Seurat
36702 features across 13686 samples within 1 assay
Active assay: RNA (36702 features, 0 variable features)
[[3]]
An object of class Seurat
36702 features across 32446 samples within 1 assay
Active assay: RNA (36702 features, 0 variable features)
> sc.merge <- merge(scList[[1]],
+ y = c(scList[[2]],scList[[3]]),
+ add.cell.ids = samples,
+ project = "ebv")
> sc.merge
An object of class Seurat
36702 features across 75069 samples within 1 assay
Active assay: RNA (36702 features, 0 variable features)
> table(sc.merge$orig.ident)
raw12 raw14 raw9
28937 13686 32446
# 保存对象
> save(sc.merge,file = 'sc.merge.ebv.Rdata')
4.用到的functions
R语言里各种功能使用说明可以在下面这个网址搜索Home - RDocumentation
https://www.rdocumentation.org/Seurat-methods function - RDocumentation
4.1Read10X
> Read10X(
data.dir,
gene.column = 2,
cell.column = 1,
unique.features = TRUE,
strip.suffix = FALSE
)

4.2创建矩阵对象CreateSeuratObject: Create a Seurat object
CreateSeuratObject(
counts,
project = "CreateSeuratObject",
assay = "RNA",
names.field = 1,
names.delim = "_",
meta.data = NULL,
...
)
# S3 method for default
CreateSeuratObject(
counts,
project = "SeuratProject",
assay = "RNA",
names.field = 1,
names.delim = "_",
meta.data = NULL,
min.cells = 0,
min.features = 0,
row.names = NULL,
...
)
# S3 method for Assay
CreateSeuratObject(
counts,
project = "SeuratProject",
assay = "RNA",
names.field = 1,
names.delim = "_",
meta.data = NULL,
...
)
CreateSeuratObject function - RDocumentation
4.3lapply函数
lapply函数 #可以循环处理列表中的每一个元素
lapply(列表,函数/函数名,其他参数)
lapply(X, FUN, …)
sapply(X, FUN, …, simplify = TRUE, USE.NAMES = TRUE)
vapply(X, FUN, FUN.VALUE, …, USE.NAMES = TRUE)
replicate(n, expr, simplify = "array")
simplify2array(x, higher = TRUE)
lapply function - RDocumentation
4.4save函数
save(…, list = character(),
file = stop("'file' must be specified"),
ascii = FALSE, version = NULL, envir = parent.frame(),
compress = isTRUE(!ascii), compression_level,
eval.promises = TRUE, precheck = TRUE)
save.image(file = ".RData", version = NULL, ascii = FALSE,
compress = !ascii, safe = TRUE)
本文档介绍了在Linux环境下,利用R语言安装BiocManager和Seurat等包,处理cellranger count及aggr得到的表达矩阵文件,创建Seurat对象的详细过程。遇到的问题包括R 4.0.0以上版本对package 'bitops'的安装要求,以及使用Read10X、CreateSeuratObject、lapply和save函数的说明。

2万+

被折叠的 条评论
为什么被折叠?



