使用Signac包進行單細胞ATAC-seq數(shù)據(jù)分析(三):scATAC-seq data integration

在本教程中澜汤,我們將學(xué)習(xí)使用Signac包對多樣本的scATAC-seq數(shù)據(jù)進行整合分析。這里敢艰,我們對來自10x Genomics和sci-ATAC-seq技術(shù)測序的成年小鼠大腦的多個單細胞ATAC-seq數(shù)據(jù)集進行了整合分析诬乞。

其中,10x Genomics平臺產(chǎn)生的原始數(shù)據(jù)可從官網(wǎng)下載:

sci-ATAC-seq技術(shù)產(chǎn)生的數(shù)據(jù)集由Cusanovich和Hill等人生成钠导。原始數(shù)據(jù)可從作者的網(wǎng)站下載:

我們將演示使用Seurat v3中的數(shù)據(jù)整合方法(dataset integration and label transfer)對多個scATAC-seq數(shù)據(jù)集進行整合分析震嫉,以及使用harmony包進行數(shù)據(jù)整合。

安裝并加載所需的R包

if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("rtracklayer")
library(devtools)
install_github("immunogenomics/harmony")

library(Signac)
library(Seurat)
library(patchwork)
set.seed(1234)

加載數(shù)據(jù)集并構(gòu)建Seurat對象

# this object was created following the mouse brain vignette
# 加載10x Genomics的小鼠大腦的scATAC-seq數(shù)據(jù)
tenx <- readRDS(file = "/home/dongwei/scATAC-seq/brain/10x/adult_mouse_brain.rds")
tenx$tech <- '10x'
tenx$celltype <- Idents(tenx)

# 加載sci-ATAC-seq的小鼠大腦數(shù)據(jù)
sci.metadata <- read.table(
  file = "/home/dongwei/scATAC-seq/brain/sci/cell_metadata.txt",
  header = TRUE,
  row.names = 1,
  sep = "\t"
)
# subset to include only the brain data
sci.metadata <- sci.metadata[sci.metadata$tissue == 'PreFrontalCortex', ]
sci.counts <- readRDS(file = "/home/dongwei/scATAC-seq/brain/sci/atac_matrix.binary.qc_filtered.rds")
sci.counts <- sci.counts[, rownames(x = sci.metadata)]

數(shù)據(jù)預(yù)處理

在上述兩個數(shù)據(jù)集中牡属,sci-ATAC-seq數(shù)據(jù)是比對到小鼠mm9參考基因組的票堵,而10x的數(shù)據(jù)是比對到小鼠mm10參考基因組的,因此這兩個數(shù)據(jù)集中peaks的基因組坐標(biāo)信息是不同的逮栅。我們可以使用rtracklayer包將mm9參考基因組的坐標(biāo)信息轉(zhuǎn)換到mm10中悴势,并使用mm10的坐標(biāo)更換sci-ATAC-seq數(shù)據(jù)中peaks的坐標(biāo),其中l(wèi)iftover轉(zhuǎn)換的chain文件可以從UCSC官網(wǎng)進行下載证芭。

# 將peaks坐標(biāo)信息轉(zhuǎn)換成GRanges格式
sci_peaks_mm9 <- StringToGRanges(regions = rownames(sci.counts), sep = c("_", "_"))

# 導(dǎo)入mm9ToMm10.over.chain文件
mm9_mm10 <- rtracklayer::import.chain("/home/dongwei/data/liftover/mm9ToMm10.over.chain")
# 使用rtracklayer包中的liftOver函數(shù)轉(zhuǎn)換坐標(biāo)信息
sci_peaks_mm10 <- rtracklayer::liftOver(x = sci_peaks_mm9, chain = mm9_mm10)
names(sci_peaks_mm10) <- rownames(sci.counts)

# discard any peaks that were mapped to >1 region in mm10
correspondence <- S4Vectors::elementNROWS(sci_peaks_mm10)
sci_peaks_mm10 <- sci_peaks_mm10[correspondence == 1]
sci_peaks_mm10 <- unlist(sci_peaks_mm10)
sci.counts <- sci.counts[names(sci_peaks_mm10), ]

# rename peaks with mm10 coordinates
rownames(sci.counts) <- GRangesToString(grange = sci_peaks_mm10)

# create Seurat object and perform some basic QC filtering
# 構(gòu)建Seurat對象
sci <- CreateSeuratObject(
  counts = sci.counts,
  meta.data = sci.metadata,
  assay = 'peaks',
  project = 'sci'
)
# 數(shù)據(jù)過濾
sci.ds <- sci[, sci$nFeature_peaks > 2000 & sci$nCount_peaks > 5000 & !(sci$cell_label %in% c("Collisions", "Unknown"))]
sci$tech <- 'sciATAC'
# 使用RunTFIDF函數(shù)進行數(shù)據(jù)歸一化
sci <- RunTFIDF(sci)
# 使用FindTopFeatures函數(shù)提取高變異的peaks
sci <- FindTopFeatures(sci, min.cutoff = 50)
# 使用RunSVD函數(shù)進行線性降維
sci <- RunSVD(sci, n = 30, reduction.name = 'lsi', reduction.key = 'LSI_')
# 使用RunUMAP函數(shù)進行非線性降維
sci <- RunUMAP(sci, reduction = 'lsi', dims = 2:30)

現(xiàn)在瞳浦,我們構(gòu)建好了兩個scATAC-seq對象,并且它們都含有基于相同的mm10參考基因組坐標(biāo)系統(tǒng)得到的peaks信息废士。但是叫潦,由于這兩個實驗都單獨進行了peak calling,因此這兩個數(shù)據(jù)集中得到的peaks坐標(biāo)不太可能完全重疊官硝。為了在我們要整合的數(shù)據(jù)集中具有共同的特征矗蕊,我們可以基于10x Genomics數(shù)據(jù)集對sci-ATAC-seq中peaks的reads進行計數(shù)短蜕,并使用這些計數(shù)創(chuàng)建一個新的assay。

# find peaks that intersect in both datasets
# 使用GetIntersectingFeatures函數(shù)提取兩個數(shù)據(jù)集中重疊的peak區(qū)域
intersecting.regions <- GetIntersectingFeatures(
  object.1 = sci,
  object.2 = tenx,
  sep.1 = c("-", "-"),
  sep.2 = c(":", "-")
)

# choose a subset of intersecting peaks
peaks.use <- sample(intersecting.regions[[1]], size = 10000, replace = FALSE)

# count fragments per cell overlapping the set of peaks in the 10x data
# 使用FeatureMatrix函數(shù)對peaks中的reads進行計數(shù)
sci_peaks_tenx <- FeatureMatrix(
  fragments = GetFragments(object = tenx, assay = 'peaks'),
  features = StringToGRanges(peaks.use),
  cells = colnames(tenx)
)

# create a new assay and add it to the 10x dataset
# 使用CreateAssayObject函數(shù)新建一個assay對象
tenx[['sciPeaks']] <- CreateAssayObject(counts = sci_peaks_tenx, min.cells = 1)
# 數(shù)據(jù)歸一化
tenx <- RunTFIDF(object = tenx, assay = 'sciPeaks')

多樣本scATAC-seq數(shù)據(jù)集的整合

在進行數(shù)據(jù)整合之前傻咖,我們最好先檢查下是否存在數(shù)據(jù)集特異的差異朋魔,并將其刪除。如果沒有卿操,我們可以簡單地將多個對象進行合并而不執(zhí)行整合警检。在本示例中,由于使用不同的測序技術(shù)害淤,兩個數(shù)據(jù)集之間存在很大的差異扇雕。我們可以使用Seurat v3中的數(shù)據(jù)整合方法來消除這種影響。

# 先簡單的將兩個數(shù)據(jù)集進行合并看一下聚類的效果
# Look at the data without integration first
# 使用MergeWithRegions函數(shù)將兩個數(shù)據(jù)對象進行合并
unintegrated <- MergeWithRegions(
  object.1 = sci,
  object.2 = tenx,
  assay.1 = 'peaks',
  assay.2 = 'sciPeaks',
  sep.1 = c("-", "-"),
  sep.2 = c("-", "-")
)

# 對合并后數(shù)據(jù)進行歸一化窥摄,特征選擇和降維可視化
unintegrated <- RunTFIDF(unintegrated)
unintegrated <- FindTopFeatures(unintegrated, min.cutoff = 50)
unintegrated <- RunSVD(unintegrated, n = 30, reduction.name = 'lsi', reduction.key = 'LSI_')
unintegrated <- RunUMAP(unintegrated, reduction = 'lsi', dims = 2:30)
p1 <- DimPlot(unintegrated, group.by = 'tech', pt.size = 0.1) + ggplot2::ggtitle("Unintegrated")

# 使用Seurat v3的數(shù)據(jù)整合方法進行數(shù)據(jù)集的整合
# find integration anchors between 10x and sci-ATAC
# 使用FindIntegrationAnchors函數(shù)識別共享的整合anchors
anchors <- FindIntegrationAnchors(
  object.list = list(tenx, sci),
  anchor.features = peaks.use,
  assay = c('sciPeaks', 'peaks'),
  k.filter = NA
)

# integrate data and create a new merged object
# 使用IntegrateData函數(shù)根據(jù)識別的anchors進行數(shù)據(jù)整合
integrated <- IntegrateData(
  anchorset = anchors,
  weight.reduction = sci[['lsi']],
  dims = 2:30,
  preserve.order = TRUE
)

# we now have a "corrected" TF-IDF matrix, and can run LSI again on this corrected matrix
# 對整合后的數(shù)據(jù)進行降維可視化
integrated <- RunSVD(
  object = integrated,
  n = 30,
  reduction.name = 'integratedLSI'
)

integrated <- RunUMAP(
  object = integrated,
  dims = 2:30,
  reduction = 'integratedLSI'
)

p2 <- DimPlot(integrated, group.by = 'tech', pt.size = 0.1) + ggplot2::ggtitle("Integrated")
p1 + p2
image

Label transfer

我們還可以使用Seurat v3中的Label transfer方法進行數(shù)據(jù)集的整合镶奉,它將數(shù)據(jù)從一個query數(shù)據(jù)集映射到另一個reference數(shù)據(jù)集中。在這里崭放,我們通過將細胞類型標(biāo)簽從10x Genomics scATAC-seq數(shù)據(jù)映射到到sci-ATAC-seq數(shù)據(jù)中哨苛。

# 使用FindTransferAnchors函數(shù)識別整合的anchors
transfer.anchors <- FindTransferAnchors(
  reference = tenx,
  query = sci,
  reference.assay = 'sciPeaks',
  query.assay = 'peaks',
  reduction = 'cca',
  features = peaks.use,
  k.filter = NA
)

# 使用TransferData函數(shù)基于識別好的anchors進行數(shù)據(jù)映射整合
predicted.id <- TransferData(
  anchorset = transfer.anchors,
  refdata = tenx$celltype,
  weight.reduction = sci[['lsi']],
  dims = 2:30
)

sci <- AddMetaData(
  object = sci,
  metadata = predicted.id
)

sci$predicted.id <- factor(sci$predicted.id, levels = levels(tenx$celltype))  # to make the colors match

# 數(shù)據(jù)可視化
p3 <- DimPlot(tenx, group.by = 'celltype', label = TRUE) + NoLegend() + ggplot2::ggtitle("Celltype labels 10x scATAC-seq")
p4 <- DimPlot(sci, group.by = 'predicted.id', label = TRUE) + NoLegend() + ggplot2::ggtitle("Predicted labels sci-ATAC-seq")
p3 + p4
image

Integration with Harmony使用Harmony包進行數(shù)據(jù)整合

Harmony需要一個對象作為輸入,因此這里我們使用MergeWithRegions函數(shù)以coordinate-aware的方式將sci-ATAC-seq數(shù)據(jù)集和10x的scATAC-seq數(shù)據(jù)集進行合并币砂,然后對合并后的對象進行LSI線性降維建峭。數(shù)據(jù)降維后,我們可以使用RunHarmony函數(shù)調(diào)用Harmony的方法進行數(shù)據(jù)的整合道伟,并提供用作分組變量的技術(shù)來消除sci-ATAC-seq和10x Genomics scATAC-seq數(shù)據(jù)集之間的批次差異迹缀。這會產(chǎn)生一組“校正”的LSI嵌入,可以進一步用于UMAP或tSNE降維蜜徽,并進行細胞聚類分群祝懂。

# 加載harmony包
library(harmony)

# 使用RunHarmony函數(shù)進行數(shù)據(jù)整合
hm.integrated <- RunHarmony(
  object = unintegrated,
  group.by.vars = 'tech',
  reduction = 'lsi',
  assay.use = 'peaks',
  project.dim = FALSE
)

# re-compute the UMAP using corrected LSI embeddings
# 數(shù)據(jù)降維可視化
hm.integrated <- RunUMAP(hm.integrated, dims = 2:30, reduction = 'harmony')
p5 <- DimPlot(hm.integrated, group.by = 'tech', pt.size = 0.1) + ggplot2::ggtitle("Harmony integration")
p1 + p5
image

參考來源:https://satijalab.org/signac/articles/integration.html

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市拘鞋,隨后出現(xiàn)的幾起案子砚蓬,更是在濱河造成了極大的恐慌,老刑警劉巖盆色,帶你破解...
    沈念sama閱讀 218,682評論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件灰蛙,死亡現(xiàn)場離奇詭異,居然都是意外死亡隔躲,警方通過查閱死者的電腦和手機摩梧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,277評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來宣旱,“玉大人仅父,你說我怎么就攤上這事。” “怎么了笙纤?”我有些...
    開封第一講書人閱讀 165,083評論 0 355
  • 文/不壞的土叔 我叫張陵耗溜,是天一觀的道長。 經(jīng)常有香客問我省容,道長抖拴,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,763評論 1 295
  • 正文 為了忘掉前任腥椒,我火速辦了婚禮阿宅,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘寞酿。我一直安慰自己家夺,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,785評論 6 392
  • 文/花漫 我一把揭開白布伐弹。 她就那樣靜靜地躺著,像睡著了一般榨为。 火紅的嫁衣襯著肌膚如雪惨好。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,624評論 1 305
  • 那天随闺,我揣著相機與錄音日川,去河邊找鬼。 笑死矩乐,一個胖子當(dāng)著我的面吹牛龄句,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播散罕,決...
    沈念sama閱讀 40,358評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼分歇,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了欧漱?” 一聲冷哼從身側(cè)響起职抡,我...
    開封第一講書人閱讀 39,261評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎误甚,沒想到半個月后缚甩,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,722評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡窑邦,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,900評論 3 336
  • 正文 我和宋清朗相戀三年擅威,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片冈钦。...
    茶點故事閱讀 40,030評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡郊丛,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情宾袜,我是刑警寧澤捻艳,帶...
    沈念sama閱讀 35,737評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站庆猫,受9級特大地震影響认轨,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜月培,卻給世界環(huán)境...
    茶點故事閱讀 41,360評論 3 330
  • 文/蒙蒙 一嘁字、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧杉畜,春花似錦纪蜒、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,941評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至灭袁,卻和暖如春猬错,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背茸歧。 一陣腳步聲響...
    開封第一講書人閱讀 33,057評論 1 270
  • 我被黑心中介騙來泰國打工倦炒, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人软瞎。 一個月前我還...
    沈念sama閱讀 48,237評論 3 371
  • 正文 我出身青樓逢唤,卻偏偏與公主長得像,于是被迫代替她去往敵國和親涤浇。 傳聞我的和親對象是個殘疾皇子鳖藕,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,976評論 2 355