接着之前的继续,已经去除了部分不合格的细胞后,提取了子集
Normalizing the data数据标准化-函数 NormalizeData
pbmc <- NormalizeData(pbmc, normalization.method = "LogNormalize", scale.factor = 10000)
#Performing log-normalization
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
NormalizeData
https://satijalab.org/seurat/reference/normalizedata
- normalization.method 对数据标准化的方法
- LogNormalize: Feature Counts/(total counts)*scale.factor, 再使用log1p(log1p = log (x+1) 即ln (x+1))对其进行自然对数转换
- CLR: Applies a centered log ratio transformation
- RC: Relative counts. Feature counts for each cell are divided by the total counts for that cell and multiplied by the scale.factor. No log-transformation is applied. For counts per million (CPM) set scale.factor = 1e6
Identification of highly variable features (feature selection) 对特征基因进行挑选
上一步提取的子集,来计算细胞-细胞之间差异比较大的Feature(i.e,某些细胞中高表达,但是在另外一些细胞中是低表达的)We next calculate a subset of features that exhibit high cell-to-cell variation in the dataset (i.e, they are highly expressed in some cells, and lowly expressed in others). 下游分析中关注这些基因,会在单细胞数据集中集中突出显示生物讯号有重要意义。
使用函数FindVariableFeatures()
Identifies features that are outliers on a 'mean variability plot'. 去识别鉴定“均值差异图”中的离群的特征基因https://satijalab.org/seurat/reference/findvariablefeatures
pbmc <- FindVariableFeatures(pbmc, selection.method = "vst", nfeatures = 2000)
#Calculating gene variances
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
Calculating feature variances of standardized and clipped values
0% 10 20 30 40 50 60 70 80 90 100%
[----|----|----|----|----|----|----|----|----|----|
**************************************************|
- selection.method 挑选top变异的Features方法
- vst 使用局部加权回归(loess)拟合log(variance) 和log(mean)之间的线性关系;对拟合线性关系给出的均值和期望方差进行标准化;当clipping 到最大值时,计算Feature差异值
- mean.var.plot (mvp)
- dispersion (disp)
- nfeatures -number of features 挑选到的top variable的特征基因数量
对挑选到的特征值进行查看,并绘图
# Identify the 10 most highly variable genes
top10 <- head(VariableFeatures(pbmc), 10)
top10
[1] "PPBP" "LYZ" "S100A9" "IGLL5" "GNLY" "FTL" "PF4"
[8] "FTH1" "GNG11" "S100A8"
# plot variable features with and without labels
plot1 <- VariableFeaturePlot(pbmc)
plot2 <- LabelPoints(plot = plot1, points = top10)#把repel参数去掉了
#When using repel, set xnudge and ynudge to 0 for optimal results
plot1 + plot2
对top10基因进行绘图,其中LYZ和S100A9标注重合
Scaling the data
使用函数ScaleData()
- 调整每个基因的表达,以使整体所有细胞的平均表达为0
-
对每个基因的表达量进行缩放,使得每个细胞的差异值为1
-- 这一步的作用是:在下游分析中,每个基因都有相等的权重,所以不会导致高表达的基因占主导地位 - 这一步的结果存放在
pbmc[["RNA"]]@scale.data
all.genes <- rownames(pbmc)
pbmc <- ScaleData(pbmc, features = all.genes)
#Centering and scaling data matrix
|=========================| 100%
ScaleData(object, ...)
Scale and center the data
https://satijalab.org/seurat/reference/scaledata
# S3 method for default
ScaleData(
object,#输入对象
features = NULL,#Vector of features names to scale/center. Default is variable features.
vars.to.regress = NULL,
latent.data = NULL,
split.by = NULL,
model.use = "linear",
use.umi = FALSE,
do.scale = TRUE,#默认进行scale
do.center = TRUE,#默认进行center
scale.max = 10,
block.size = 1000,
min.cells.to.block = 3000,
verbose = TRUE,
...
)
vars.to.regress
Variables to regress out (previously latent.vars in RegressOut). For example, nUMI, or percent.mito.
center每个基因在不同细胞的表达量都减去各自的平均值(x-μ)
scale对进行center后的值/标准差
Centering and scaling data matrix就是一个Z-Score标准化过程,(x-μ)/σ; Z-Score的主要目的就是将不同量级的数据统一转化为同一个量级,统一用计算出的Z-Score值衡量,以保证数据之间的可比性
假设:A班级的平均分是80,标准差是10,A考了90分;B班的平均分是400,标准差是100,B考了600分。A的Z-Score是1((90-80)/10),B的Z-Socre是2((600-400)/100)。因此B的成绩更为优异
Z-Score本身没有实际意义,它的现实意义需要在比较中得以实现
normalization和scale 区别
normalization
主要是消除了测序深度对表达量的影响
scale
主要是讲在不同细胞中,每个基因的表达差异进行缩放,这样得到基因的相对表达值,可以两两比较基因的表达差异了;在每个基因的表达量差异很大的情况下,转化为同一个量级,把它们拉到同一个水平线进行了比较
有个加速步骤,缩短之前Scaling过程所耗时间
pbmc <- ScaleData(pbmc)
Scaling is an essential step in the Seurat workflow, but only on genes that will be used as input to PCA. Therefore, the default in ScaleData() is only to perform scaling on the previously identified variable features (2,000 by default). To do this, omit the features argument in the previous function call, i.e.pbmc <- ScaleData(pbmc)
这一步不会对下游的PCA分析造成影响,但是会对热图绘制有影响,因为热图考虑到了所有的基因,所以这个教程还是把所有的基因都进行了Centering and scaling
Perform linear dimensional reduction
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
查看pca数据
print(pbmc[["pca"]], dims = 1:5, nfeatures = 5)
PC_ 1
Positive: CST3, TYROBP, LST1, AIF1, FTL
Negative: MALAT1, LTB, IL32, IL7R, CD2
PC_ 2
Positive: CD79A, MS4A1, TCL1A, HLA-DQA1, HLA-DQB1
Negative: NKG7, PRF1, CST7, GZMB, GZMA
PC_ 3
Positive: HLA-DQA1, CD79A, CD79B, HLA-DQB1, HLA-DPB1
Negative: PPBP, PF4, SDPR, SPARC, GNG11
PC_ 4
Positive: HLA-DQA1, CD79B, CD79A, MS4A1, HLA-DQB1
Negative: VIM, IL7R, S100A6, IL32, S100A8
PC_ 5
Positive: GZMB, NKG7, S100A8, FGFBP2, GNLY
Negative: LTB, IL7R, CKB, VIM, MS4A7
对结果可视化有3种方法
- 方法1 Visualize top genes associated with reduction components
VizDimLoadings(pbmc, dims = 1:2, reduction = "pca")
dims
Number of dimensions to display
nfeatures
Number of genes to display
reduction
Reduction technique to visualize results for
https://satijalab.org/seurat/reference/vizdimloadings
VizDimLoadings(pbmc, dims = 1:5, reduction = "pca",ncol = 5)
VizDimLoadings-dim 为1:5
- 方法2 Dimensional reduction plot
https://satijalab.org/seurat/reference/dimplot
2D散点图绘制,其中每个点都是一个细胞,并且降维方法决定了细胞的嵌入,从而对其进行定位。 默认情况下,单元格按其标识类进行着色(可以使用group.by参数进行更改)(cell embeddings 意思需要再查,不懂)
DimPlot(pbmc, reduction = "pca")
DimPlot
- 方法3 Dimensional reduction heatmap
https://satijalab.org/seurat/reference/dimheatmap
DimHeatmap(
object,
dims = 1,
nfeatures = 30,#选择的代表基因数目30个
cells = NULL,
reduction = "pca",
disp.min = -2.5,
disp.max = NULL,
balanced = TRUE,#Plot an equal number of genes with both + and - scores.
projected = FALSE,
ncol = NULL,
fast = TRUE,
raster = TRUE,
slot = "scale.data",
assays = NULL,
combine = TRUE
)
对本数据
DimHeatmap(pbmc, dims = 1, cells = 500, balanced = TRUE)
DimHeatmap dims = 1
PCA是一种划分不同数据类型的方法之一;在PCA图中,它的坐标轴是按重要性进行排序的。其中PC1是第一主成分轴,它的重要性要强于PC2;这里是只有PC_1这一个主成分轴;每一个竖线代表的是单个细胞,在这个维度中,其对应的基因表达量情况
DimHeatmap(pbmc, dims = 1:15, cells = 500, balanced = TRUE)
DimHeatmap dims = 1:15
参考下面
https://www.jianshu.com/p/b46b6b6d344f
https://zhuanlan.zhihu.com/p/69074703
https://satijalab.org/seurat/articles/pbmc3k_tutorial.html
https://www.embopress.org/doi/full/10.15252/msb.20209539
网友评论