最近在比較樣本間TAD的差異,看到有個(gè)R包TADCompare可以做,學(xué)了一下,這個(gè)R包功能比較齊全,可以比較,還能直接出圖,很方便。接受很多格式的輸入。
用法官網(wǎng)
安裝
# 方法1:conda安裝
conda install bioconductor-tadcompare -c bioconda -c conda-forge
# 方法2:在R中安裝
if (!requireNamespace("BiocManager", quietly=TRUE))
install.packages("BiocManager")
BiocManager::install("TADCompare")
library(TADCompare)
使用
導(dǎo)入需要的庫,沒有的安裝一下
library(dplyr)
library(SpectralTAD)
library(TADCompare)
輸入格式,我們這里接HiC-Pro的結(jié)果
# Read in both files
mat1 <- read.table("sample1_100000.matrix")
bed1 <- read.table("sample1_100000_abs.bed")
# Matrix 2
mat2 <- read.table("sample2_100000.matrix")
bed2 <- read.table("sample2_100000_abs.bed")
# Convert to modified bed format
sparse_mats1 <- HiCcompare::hicpro2bedpe(mat1,bed1)
sparse_mats2 <- HiCcompare::hicpro2bedpe(mat2,bed2)
# Remove empty matrices if necessary
# sparse_mats$cis = sparse_mats$cis[sapply(sparse_mats, nrow) != 0]
# Go through all pairwise chromosomes and run TADCompare
sparse_tads = lapply(1:length(sparse_mats1$cis), function(z) {
x <- sparse_mats1$cis[[z]]
y <- sparse_mats2$cis[[z]]
#Pull out chromosome
chr <- x[, 1][1]
#Subset to make three column matrix
x <- x[, c(2, 5, 7)]
y <- y[, c(2, 5, 7)]
#Run SpectralTAD
comp <- TADCompare(x, y, resolution = 100000)
return(list(comp, chr))
})
# Pull out differential TAD results
diff_res <- lapply(sparse_tads, function(x) x$comp)
# Pull out chromosomes
chr <- lapply(sparse_tads, function(x) x$chr)
# Name list by corresponding chr
names(diff_res) <- chr