Seurat -- Perform linear dimensional reduction

brief

  • 什么是线性降维?

    这里是一个很形象的网页演示,其中包括了一个视频链接。
    这里是如何用R 包psych做线性降维的演示,其中也有原理的简述。

  • 为什么要做线性降维?
    因为下一步的聚类分析需要这里的降维结果作为输入。降维做的好,聚类时细胞类群才分得开分的好。

    这里使用的 input是上一步的 select highly variable features对应的scale数据。highly variable features选的不好,降维算法再牛逼也可能拯救不了你的数据结果。

  • Seurat 中的函数RunPCA()默认使用selected highly variable features作为input,你也可以使用features argument指定对应的 input,所以RunPCA()可以是一个反复交互优化的步骤。

实例

  • 第一次运行RunPCA
#  By default, only the previously determined variable features are used as input,
#  but can be defined using features argument if you wish to choose a different subset.

pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))

在这里插入图片描述

下面是主成分得分,教程里说Both cells and features are ordered according to their PCA scores,这里显示的结果貌似还没有进行排序。可能是使用相关数据时才会排序。
在这里插入图片描述

# RunPCA
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc))
# ElbowPlot(pbmc)
# DimHeatmap(pbmc, dims = 1:15, cells = 500, balanced = TRUE)
pbmc <- FindNeighbors(pbmc, dims = 1:10)
pbmc <- FindClusters(pbmc, resolution = 0.5)
pbmc <- RunUMAP(pbmc, dims = 1:10)
DimPlot(pbmc, reduction = "umap",label = T)

在这里插入图片描述

  • 第二次运行RunPCA
# 这次使用高变基因排名前1000作为input
pbmc <- RunPCA(pbmc, features = pbmc@assays$RNA@var.features[1:1000])

在这里插入图片描述
可以看到feature.loading (载荷)已经改变了。
在这里插入图片描述

pbmc <- RunPCA(pbmc, features = pbmc@assays$RNA@var.features[1:1000])
pbmc <- FindNeighbors(pbmc, dims = 1:10)
pbmc <- FindClusters(pbmc, resolution = 0.5)
pbmc <- RunUMAP(pbmc, dims = 1:10)
DimPlot(pbmc, reduction = "umap",label = T)

在这里插入图片描述

  • 尝试确定保留多少个PC
    在其他的程序包里面是需要提前制定保留多少个PC的,这里RunPCA默认设置了50个PC,然后根据
    VizDimReduction(), DimPlot(), and DimHeatmap() ,JackStrawPlot(),ElbowPlot()这些函数的结果确定最终下游分析 使用的PC个数。
# 确定保留多少个主成分
# 一般选取碎石图的拐点对应的PC数
ElbowPlot(pbmc)
# 拐点可以认为是7或者10

在这里插入图片描述

# visualizing both cells and features that define the PCA, 
# including VizDimReduction(), DimPlot(), and DimHeatmap()
DimHeatmap(pbmc, dims = 1:15, cells = 500, balanced = TRUE)
# 第七个 PC之后感觉就分不开数据了

在这里插入图片描述

  • 第三次运行RunPCA
# RunPCA
pbmc <- RunPCA(pbmc, features = VariableFeatures(object = pbmc),npcs = 7)
# ElbowPlot(pbmc)
# DimHeatmap(pbmc, dims = 1:15, cells = 500, balanced = TRUE)
pbmc <- FindNeighbors(pbmc, dims = 1:7)
pbmc <- FindClusters(pbmc, resolution = 0.5)
pbmc <- RunUMAP(pbmc, dims = 1:7)
DimPlot(pbmc, reduction = "umap",label = T)

在这里插入图片描述
这里看到聚类结果又有一些不一样了,有可能是FindClusters中的resolution参数设置不当导致的。
这里主要想说明的是你的RunPCA input不同会影响你 发现新的细胞聚类。
然后你选择多少个PC 也会影响你的细胞聚类结果,我这个演示数据集没体现出来罢了。

函数参数及意义

在这里插入图片描述

  • assay
    Name of Assay PCA is being run on

  • npcs
    Total Number of PCs to compute and store (50 by default)

  • rev.pca
    By default computes the PCA on the cell x gene matrix. Setting to true will compute it on gene x cell matrix.

  • weight.by.var
    Weight the cell embeddings by the variance of each PC (weights the gene loadings if rev.pca is TRUE)

  • verbose
    Print the top genes associated with high/low loadings for the PCs

  • ndims.print
    PCs to print genes for

  • nfeatures.print
    Number of genes to print for each PC

  • reduction.key
    dimensional reduction key, specifies the string before the number for the dimension names. PC by default

  • seed.use
    Set a random seed. By default, sets the seed to 42. Setting NULL will not set a seed.

  • approx
    Use truncated singular value decomposition to approximate PCA

  • features
    Features to compute PCA on. If features=NULL, PCA will be run using the variable features for the Assay. Note that the features must be present in the scaled data. Any requested features that are not scaled or have 0 variance will be dropped, and the PCA will be run using the remaining features.

  • reduction.name
    dimensional reduction name, pca by default

### 关于t-SNE在R语言Seurat包中的实现 #### t-SNE简介 t-SNE是一种用于降维和可视化的算法,特别适用于高维数据的低维表示。它通过保持相似样本间的距离关系,在二维或三维空间中呈现复杂的数据结构[^1]。 #### Seurat包中的t-SNE功能 在Seurat包中,`RunTSNE()`函数被用来执行t-SNE分析,并生成相应的嵌入坐标。这些坐标可以进一步通过绘图函数如`DimPlot()`进行可视化[^3]。具体来说: - `RunTSNE()` 是 Seurat 提供的一个核心函数,用于计算基于 t-SNE 的细胞投影。 - 参数设置方面,默认情况下会自动调整参数以适应大多数情况下的需求,但也可以手动指定诸如困惑度(perplexity)这样的重要超参数[^4]。 以下是具体的代码示例以及解释: ```r library(Seurat) # 假设 pbmc 数据已经加载并预处理完成 pbmc <- RunPCA(pbmc, npcs = 20) # 首先运行 PCA 减少维度到前20个主成分 pbmc <- RunTSNE(pbmc, dims = 1:20) # 利用前面得到的20个PCs来进行t-SNE运算 DimPlot(pbmc, reduction = "tsne") # 可视化t-SNE结果 ``` 上述脚本展示了如何利用Seurat框架内的工具链逐步构建起从原始数据至最终图形展示的过程。其中每一步都紧密相连,共同构成了完整的单细胞数据分析流程的一部分。 另外值得注意的是,虽然默认值通常能够满足一般性的应用场合,但在某些特殊场景下可能需要微调一些选项比如最大迭代次数(max_iter),学习率(eta)等来获得更优的结果。 #### 绘制特征表达量图表 除了基本的聚类之外,我们还可以借助其他类型的图表深入探索各个cluster内部的具体特性。例如使用小提琴图(VlnPlot())查看特定基因在不同组别里的分布状况;或者采用点状热力图(DotPlot())综合评估多个指标的表现趋势等等。 ```r VlnPlot(pbmc, features = c("MS4A1", "CD79A")) DotPlot(pbmc, features = c("FTL", "TFRC")) ``` 以上命令分别生成了两幅不同的统计图形,帮助研究人员更加直观地理解目标分子在整个样品集合当中的变化规律及其潜在意义所在。 ### 结论 综上所述,Seurat不仅提供了强大的基础操作接口支持常规任务顺利完成,同时也内置了许多高级定制可能性使得用户可以根据实际研究方向灵活应对各种挑战。对于初学者而言,则建议按照官方文档指南循序渐进掌握各项技能要点后再尝试扩展边界条件测试极限性能表现。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值