File size: 3,079 Bytes
fceeb13 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# if (!requireNamespace("BiocManager", quietly = TRUE))
# install.packages("BiocManager")
#
# BiocManager::install("HiCDCPlus")
# BiocManager::install("BSgenome.Hsapiens.UCSC.hg19")
library(HiCDCPlus)
library(BSgenome.Hsapiens.UCSC.hg19)
# outdir <- "data/3D/K562_HiC/"
# hicfile_path <- paste0(outdir, "GSE63525_K562_combined_30.hic")
outdir <- "data/3D/GM12878_HiC/"
hicfile_path <- paste0(outdir, "GSE63525_GM12878_insitu_primary_30.hic")
process_chromosome <- function(chr) {
cat("Processing chromosome:", chr, "\n")
feature_path <- paste0(outdir, "hg19_5kb_GATC_", chr)
construct_features(output_path=feature_path,
gen="Hsapiens",gen_ver="hg19",
sig="GATC",
binsize=5000,
chrs=c(chr),
)
# generated file under hg19_5kb_GATC_bintolen.txt.gz
# generate gi_list instance
feature_output <- paste0(feature_path, "_bintolen.txt.gz")
gi_list<-generate_bintolen_gi_list(bintolen_path=feature_output)
# add .hic counts
gi_list<-add_hic_counts(gi_list,hic_path = hicfile_path)
# expand features for modeling
gi_list<-expand_1D_features(gi_list)
# run HiC-DC+
set.seed(1010) #HiC-DC downsamples rows for modeling
gi_list<-HiCDCPlus_parallel(gi_list,ncore=2)
cat("gi list length:", length(gi_list), "\n")
# select FDR < 0.1
alpha <- 0.1
significant_interactions <- list()
# 遍历 gi_list 中的每个 GInteractions 对象
gi_list_names <- names(gi_list)
for (i in seq_along(gi_list)) {
name <- gi_list_names[i]
# 提取当前 GInteractions 对象
gi <- gi_list[[i]]
metadata_columns <- mcols(gi)
qvalues <- metadata_columns$qvalue
significant_interaction <- gi[qvalues <= alpha, ]
significant_interactions[[i]] <- significant_interaction
names(significant_interactions) <- name
}
# save file
# save_name = paste0(outdir,'GSE63525_K562_HiC30_FDR_1_', chr)
save_name = paste0(outdir,'GSE63525_GM12878_HiC30_FDR_1_', chr)
hicdc2hic(significant_interactions,
hicfile=paste0(save_name, '.hic'),
mode='normcounts',
gen_ver='hg19'
)
gi_list_write(significant_interactions,fname=paste0(save_name, '.txt.gz'))
}
chromosomes <- c("chr1", "chr2", "chr3", "chr4", "chr5", "chr6", "chr7", "chr8", "chr9", "chr10",
"chr11", "chr12", "chr13", "chr14", "chr15", "chr16", "chr17", "chr18", "chr19", "chr20",
"chr21", "chr22", "chrX")
# Process each chromosome
for (chr in chromosomes) {
process_chromosome(chr)
}
# # test
# library(InteractionSet)
#
# # 提取第一个 GInteractions 对象
# gi <- gi_list[[1]]
#
# # 提取元数据列
# metadata_columns <- mcols(gi)
#
# # 查看 qvalue 和 pvalue 列
# qvalues <- metadata_columns$qvalue
# pvalues <- metadata_columns$pvalue
#
# # 检查 qvalue 和 pvalue 列的唯一值
# unique_qvalues <- unique(qvalues)
# unique_pvalues <- unique(pvalues)
#
# num_qvalues_less_than_0.1 <- sum(qvalues < 0.1, na.rm = TRUE)
|