1.批量安裝包
首先是設(shè)置鏡像
options("repos"="https://mirrors.ustc.edu.cn/CRAN/")
if(!require("BiocManager")) install.packages("BiocManager",update = F,ask = F)
options(BioC_mirror="https://mirrors.ustc.edu.cn/bioc/")
#來自cran的包放在一個(gè)向量里
cran_packages <- c('tidyverse',
'msigdbr',
'patchwork',
'SeuratObject',
'Seurat'
)
#來自bioconductor的包放在一個(gè)向量里
Biocductor_packages <- c('sva',
'monocle',
'GOplot',
'GSVA',
'plotmo',
'regplot',
'scRNAseq',
'BiocStyle',
'celldex',
'SingleR',
'BiocParallel'
)
#用for循環(huán)批量安裝來自cran的包
for (pkg in cran_packages){
if (! require(pkg,character.only=T,quietly = T) ) {
install.packages(pkg,ask = F,update = F)
require(pkg,character.only=T)
}
}
#用for循環(huán)批量安裝來自bioconductor的包
for (pkg in Biocductor_packages){
if (! require(pkg,character.only=T,quietly = T) ) {
BiocManager::install(pkg,ask = F,update = F)
require(pkg,character.only=T)
}
}
#再次加載所有包,檢查有沒有沒安裝好的
for (pkg in c(Biocductor_packages,cran_packages)){
require(pkg,character.only=T)
}
#查看Seurat的版本
packageVersion("Seurat")
1.1 require和library
區(qū)別:(1)library 會在包沒有安裝時(shí)拋出錯(cuò)誤怯晕,終止執(zhí)行。require 會在包沒有安裝時(shí)返回 FALSE葵擎,允許繼續(xù)執(zhí)行后續(xù)代碼右核。(2)require在需要的時(shí)候可以提供邏輯值销凑。能加載成功的包會返回TRUE丛晌,不能加載成功的包返回FALSE
as.logical(require(limma))
## [1] TRUE
as.logical(require(dplyr))
## Loading required package: dplyr
## [1] FALSE
或加!(逆轉(zhuǎn)邏輯值符號斗幼,!TRUE就是FALSE澎蛛,!FALSE 就是TRUE)
!require(limma)
## [1] FALSE
!require(huahua)
## Loading required package: huahua
## [1] TRUE
1.2 if
if(TRUE)print("Hello")
## [1] "Hello"
if(FALSE)print("Hello")
1.3 require與if語句的結(jié)合
先判斷是否安裝包,沒找到再執(zhí)行安裝
if(!require("BiocManager")) install.packages("BiocManager",update = F,ask = F)
1.4 for循環(huán)
ps = c("tidyr","dplyr","stringr")
for (p in ps) {
print(p)
}
對于每一個(gè)在向量ps里的元素p蜕窿,都執(zhí)行一遍{}里的命令
1.5 循環(huán)時(shí)必須要加的參數(shù)ask谋逻,updat,character.only
for (pkg in cran_packages){
if (! require(pkg,character.only=T,quietly = T) ) {
install.packages(pkg,ask = F,update = F)
require(pkg,character.only=T)
}
}
#character.only = TRUE pkg 是一個(gè)變量名桐经,而不是直接的包名稱字符串毁兆。
#quietly = TRUE 在加載包時(shí)不顯示加載信息。
#ask = FALSE 在安裝過程中不需要用戶確認(rèn)阴挣。
#update = FALSE 不更新已經(jīng)安裝的包气堕。
2.單細(xì)胞的應(yīng)用方向
2.1 數(shù)據(jù)庫
1.Gene Expression Omnibus (GEO)
2.Single Cell Portal: 在線平臺,提供了單細(xì)胞測序數(shù)據(jù)資源和分析工具。https://singlecell.broadinstitute.org/single_cell
3.Human Cell Atlas: 人類細(xì)胞圖譜計(jì)劃茎芭,旨在建立人類所有細(xì)胞類型的細(xì)胞圖譜揖膜,提供了大量的單細(xì)胞 RNA 測序數(shù)據(jù)。
https://www.humancellatlas.org/
4.Single Cell Expression Atlas
https://www.ebi.ac.uk/gxa/sc/home
5.UCSC Cell Browser: 在線平臺梅桩,用于瀏覽和分析單細(xì)胞RNA測序數(shù)據(jù)壹粟。
https://cells.ucsc.edu/
2.2 單細(xì)胞數(shù)據(jù)格式
(1)10X標(biāo)準(zhǔn)文件 (包含barcodes.tsv.gz,features.tsv.gz和matrix.mtx.gz)
(2)表達(dá)矩陣文件(csv宿百,tsv趁仙,txt)
(3)h5格式文件 (.h5)
(4)h5ad格式文件(.h5ad)
具體可見https://mp.weixin.qq.com/s/W7szy-Kg6G1N1ENHNRjGiw