Seurat包其中的FindIntegrationAnchors函数解析

本文解析了Seurat包中FindIntegrationAnchors函数在多样本单细胞数据整合中的参数和用法,重点介绍了如何选择合适的参数如assay、reference、anchor.features等,以及不同降维方法(CCA、rpca)的选择和注意事项。
摘要由CSDN通过智能技术生成

在用Seurat包做多样本整合的时候,我们通常采用两种方式:
(1)merge的方式
(2)FindIntegrationAnchors的方式整合
这里我们来解析一下FindIntegrationAnchors函数里面的参数及用法:
对于要进行多样本整合的数据,通常的做法是:

for (each in samples){
#  ob=paste("ob",each,sep="_")
  pbmc <- readRDS(paste0(path,'/',each,'_QC.rds'))
        if(grep('-1',colnames(pbmc@assays$RNA@counts)[1])){
        colnames(pbmc@assays$RNA@counts) <- str_replace_all(colnames(pbmc@assays$RNA@counts), '-1',paste0('-',numsap))
        }else{
        colnames(pbmc@assays$RNA@counts) <- paste0(colnames(pbmc@assays$RNA@counts),'-',numsap)
        }
        ob <- CreateSeuratObject(counts =pbmc@assays$RNA@counts,project =each,min.cells = min_cells)
        ob$stim <-each
        ob <- NormalizeData(ob)
        ob <- FindVariableFeatures(ob,  selection.method = "vst",nfeatures = Nfeatures)
        numsap=numsap+1
        ob.list[[each]] <- ob
}
anchors <- FindIntegrationAnchors(object.list = ob.list, dims = 1:20)
combined <- IntegrateData(anchorset = anchors, dims = 1:20)

也就是单样本做了均一化后,进行多样本的整合
那这个函数FindIntegrationAnchors就是来帮助我们寻找样本整合的数据点;
看一下这个函数的参数:

Description:
     Find a set of anchors between a list of ‘Seurat’ objects.  These
     anchors can later be used to integrate the objects using the
     ‘IntegrateData’ function.(多个Seurat对象寻找anchors,也就是锚点)

主要参数:
assay: A vector of assay names specifying which assay to use when
          constructing anchors. If NULL, the current default assay for
          each object is used.(这个参数说明我们可以用部分样本进行anchors的寻找)。
reference: A vector specifying the object/s to be used as a reference
          during integration. If NULL (default), all pairwise anchors
          are found (no reference/s). If not NULL, the corresponding
          objects in ‘object.list’ will be used as references. When
          using a set of specified references, anchors are first found
          between each query and each reference. The references are
          then integrated through pairwise integration. Each query is
          then mapped to the integrated reference.(这种方式说明,如果我们有部分样本细胞定义的结果很好,那么这部分样本可以作为reference,然后未知细胞类型的样本与参考集之间查找锚点,然后进行整合,这种方式类似于RCA,scanpy的样本整合方式,区别在于这里不需要事先对细胞进行定义)。
anchor.features: Can be either:

            • A numeric value. This will call
              ‘SelectIntegrationFeatures’ to select the provided number
              of features to be used in anchor finding

            • A vector of features to be used as input to the anchor
              finding process
          (如果在先验知识很强的前提下,我们可以指定基因进行锚点的查找)。
normalization.method: 
          Name of normalization method used: LogNormalize
          or SCT
         (SCT的标准化的方式是SCTransform这个函数,大家可以看一下,推荐这个)
reduction: Dimensional reduction to perform when finding anchors. Can
          be one of:

            • cca(典型相关分析): Canonical correlation analysis(挖掘出数据间的关联关系的算法,原理就是CCA将多维数据利用线性变换投影为1维的数据,然后计算相关系数,进而得到二者的相关性,在这里我们就是两两细胞之间的相关性,
那么我们的投影标准就是:
            投影后,两组数据的相关系数最大。

但是要要注意,CCA投影到一维且寻找最大相关性,所以存在整合过矫正的问题)
            • rpca: Reciprocal PCA
         When determining anchors between any two datasets using reciprocal PCA,    we project each dataset into the other's PCA space and constrain the anchors by the same mutual neighborhood requirement. All downstream integration steps remain the same and we are able to 'correct' (or harmonize) the datasets.
(也就是是说从基因角度寻找锚点变成了主成分)。
For large studies with many datasets, we recommend also combining reciprocal PCA with reference-based integration, or SCTransform normalization (see details on previous tab)。但是要注意,这种整合方式仅用于大样本,因为锚点寻找的方式比CCA“粗糙”,大家要注意这一点。

k.anchor: How many neighbors (k) to use when picking anchors
k.filter: How many neighbors (k) to use when filtering anchors
k.score: How many neighbors (k) to use when scoring anchors
(锚点的确定原则,这个需要深入研究一下)
nn.method: Method for nearest neighbor finding. Options include: rann,
          annoy

其中Seurat中有很多方法值得我们借鉴,但是具体情况要具体分析,千万不要是个方法就拿来用。
请保持愤怒,让王多鱼倾家荡产~~~~

好的,下面是在R语言中使用Seurat进行主成分分析、计算p值以及执行t-SNE分析的示例代码: 1. 主成分分析 ```R library(Seurat) # 假设我们的数据存储在data矩阵中,每一行代表一个样本,每一列代表一个变量 seurat_obj <- CreateSeuratObject(data, project = "my_project") # 创建Seurat对象 seurat_obj <- NormalizeData(seurat_obj) # 标准化数据 seurat_obj <- ScaleData(seurat_obj) # 缩放数据 seurat_obj <- RunPCA(seurat_obj, pcs.compute = 20) # 进行主成分分析,设定计算20个主成分 ``` 2. 计算p值 ```R library(multtest) # 假设我们已经进行了t检验,并将结果存储在t_values中 # 假设我们要计算每个变量的p值 p_values <- mt.rawp2adjp(t_values, n = nrow(data), "BH") # 使用Benjamini-Hochberg方法校正p值 seurat_obj[["pvals"]] <- p_values # 将p值存储在Seurat对象中 ``` 3. t-SNE分析 ```R library(Seurat) # 假设我们要将数据降至20维,并进行t-SNE分析 seurat_obj <- FindNeighbors(seurat_obj, dims = 1:20) # 计算每个样本之间的邻居关系 seurat_obj <- FindClusters(seurat_obj, resolution = 0.5) # 根据邻居关系进行聚类 seurat_obj <- RunTSNE(seurat_obj, dims = 1:20) # 进行t-SNE降维,设定降至20维 ``` 需要注意的是,以上代码仅为示例代码,具体实现需要根据自己的数据和分析需求进行调整和修改。同时,Seurat提供了丰富的可视化函数,可以帮助我们更好地理解和解释分析结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值