使用findtransferanchors对样本进行预注释.md 3.6 KB


title: 使用FindTransferAnchors对样本进行预注释 tags: [] id: '2362' categories:

  • - 注释
  • - 预处理 date: 2022-09-29 21:42:04 ---

处理参考样本

ref_sce <- readRDS('~/upload/zl_liu/data/pca.rds')
ref_sce <- subset(ref_sce, group == 'CRPC')
table(ref_sce@meta.data$cell_type_fig3)
g2m_genes <- Seurat::CaseMatch(search=Seurat::cc.genes$g2m.genes, 
                               match=rownames(ref_sce))
s_genes <- Seurat::CaseMatch(search=Seurat::cc.genes$s.genes, 
                             match=rownames(ref_sce))
ref_sce <- Seurat::CellCycleScoring(ref_sce, g2m.features=g2m_genes, s.features=s_genes)
ref_sce$CC.Difference <- ref_sce$S.Score - ref_sce$G2M.Score 
ref_sce[["percent.mt"]] <- Seurat::PercentageFeatureSet(ref_sce, pattern = "^MT-")
ref_sce[["percent.ERCC"]] <- Seurat::PercentageFeatureSet(ref_sce, pattern = "^ERCC-")
ref_sce[["percent.rp"]] <- Seurat::PercentageFeatureSet(ref_sce, pattern = "^RP[SL]")
ref_sce <- Seurat::SplitObject(object = ref_sce, split.by = 'orig.ident')

integration

ref_sce <- lapply(X = ref_sce, FUN = function(x) {
    x <- Seurat::SCTransform(x, vst.flavor = "v2",
                           vars.to.regress = c("CC.Difference", "percent.mt", "percent.rp"),
                           verbose = F)
})
features <- Seurat::SelectIntegrationFeatures(object.list = ref_sce, 
                                              assay = rep('SCT', length(ref_sce)))
ref_sce <- Seurat::PrepSCTIntegration(object.list = ref_sce, 
                                      anchor.features = features, 
                                      assay = rep('SCT', length(ref_sce)))
anchors <- Seurat::FindIntegrationAnchors(object.list = ref_sce, 
                                          normalization.method = "SCT",
                                          anchor.features = features, 
                                          assay = rep('SCT', length(ref_sce)))
combined <- Seurat::IntegrateData(anchorset = anchors,
                                 normalization.method = "SCT")
combined <- Seurat::RunPCA(combined, verbose = FALSE)
combined <- Seurat::RunUMAP(combined, 
                            reduction = "pca", dims = 1:30,
                            verbose = FALSE)
Seurat::DimPlot(combined, reduction = "umap", 
                group.by = "cell_type_fig3",
                repel = T, label = T)

处理预处理完的样本

样本来自此

打个补丁

sce <- readRDS('SRX6887740.rds')
Seurat::DefaultAssay(sce) <- 'RNA'
sce[["percent.rp"]] <- Seurat::PercentageFeatureSet(sce, pattern = "^RP[SL]")
sce <- Seurat::SCTransform(sce, vst.flavor = "v2",
                       vars.to.regress = c("CC.Difference", "percent.mt", "percent.rp"),
                       verbose = F)

FindTransferAnchors

anchors <- Seurat::FindTransferAnchors(reference = combined, query = sce,
                                      normalization.method = "SCT",
                                      reference.assay = 'integrated',
                                      query.assay = 'SCT')

TransferData

predictions <- Seurat::TransferData(anchorset = anchors, 
                            refdata = combined$cell_type_fig3)
sce <- AddMetaData(object = sce, metadata = predictions)

可视化

sce <- Seurat::RunPCA(sce, verbose = FALSE)
sce <- Seurat::RunUMAP(sce, reduction = "pca", 
                       dims = 1:30, 
                       verbose = FALSE)
Seurat::DimPlot(sce, reduction = "umap", 
                group.by = "predicted.id",
                repel = T, label = T)