dozmorovlab / HiCcompare

Joint normalization of two Hi-C matrices, visualization and detection of differential chromatin interactions. See multiHiCcompare for the analysis of multiple Hi-C matrices
https://dozmorovlab.github.io/HiCcompare/
Other
18 stars 3 forks source link

How to visualize hic.table? #24

Closed zhqu1148980644 closed 3 years ago

zhqu1148980644 commented 3 years ago

Or are there any functions that can convert hic.table into a matrix in text format? I would like to use the simulated HiC matrix returned by hic_simulate.

mdozmorov commented 3 years ago

In short, we don't have a function to extract simulated matrices.

It is possible to reconstruct the square matrix. This code shows:

> sim <- hic_simulate()
> sim$hic.table %>% str
Classes ‘data.table’ and 'data.frame':  4724 obs. of  18 variables:
 $ chr1   : chr  "ChrSim" "ChrSim" "ChrSim" "ChrSim" ...
 $ start1 : num  1 2 3 4 5 6 7 8 9 10 ...
 $ end1   : num  2 3 4 5 6 7 8 9 10 11 ...
 $ chr2   : chr  "ChrSim" "ChrSim" "ChrSim" "ChrSim" ...
 $ start2 : num  1 2 3 4 5 6 7 8 9 10 ...
 $ end2   : num  2 3 4 5 6 7 8 9 10 11 ...
 $ IF1    : num  188763 326767 158618 180323 167058 ...
 $ IF2    : num  119227 212852 261154 210333 262199 ...
 $ D      : num  0 0 0 0 0 0 0 0 0 0 ...
 $ M      : num  -0.663 -0.618 0.719 0.222 0.65 ...
 $ adj.IF1: num  193933 335717 162962 185262 171634 ...
 $ adj.IF2: num  116048 207178 254192 204726 255210 ...

Have you already done it? It'll be a great pull request. If not, I'll try to do it soon.

zhqu1148980644 commented 3 years ago

Not yet,I am new to R lauguage。

mdozmorov commented 3 years ago

Let me ask @jstansfield0 if he can help. Otherwise, I'll get to it over the weekend.

jstansfield0 commented 3 years ago

You should be able to just pull out the necessary columns to get the sparse matrix and then convert to a full matrix with sparse2full().

mdozmorov commented 3 years ago

I tried the following:

library(HiCcompare)
sim <- hic_simulate(nrow = 20, Plot = FALSE)
sim_sparse <- data.frame(start = sim$hic.table$start1,
                         end = sim$hic.table$end1,
                         IF = sim$hic.table$IF1)

sim_full <- sparse2full(sim_sparse)
image(sim_full)
write.table(sim_full, file = "sim_full.txt", quote = FALSE, sep = "\t", row.names = FALSE, col.names = FALSE)

But it gives some strange results, like: image

@jstansfield0, any suggestion? I'll need to dig more.

jstansfield0 commented 3 years ago

You need to use start2 instead of end1 for pulling out the sparse matrix.

sim <- hic_simulate(nrow = 20, Plot = FALSE)
sim_sparse <- data.frame(start1 = sim$hic.table$start1, start2 = sim$hic.table$start2, IF = sim$hic.table$IF1)
sim_full <- sparse2full(sim_sparse)
image(sim_full)
zhqu1148980644 commented 3 years ago

@mdozmorov @jstansfield0 Thanks for your kindly reply and solution, it works. By the way, if TAD information can be added to the simulation process?

mdozmorov commented 3 years ago

This code will show the simulated matrix better:

sim <- hic_simulate(nrow = 100, Plot = FALSE)
sim_sparse <- data.frame(start1 = sim$hic.table$start1, start2 = sim$hic.table$start2, IF = sim$hic.table$IF1)
sim_full <- sparse2full(sim_sparse)
image(log10(sim_full))

But it won't generate TADs. It was used only to introduce controlled changes. Thanks, @jstansfield0 , for your help!

@zhqu1148980644 , you may want to look at the tool below. It should give you what you want. Have a look at their simulated data.

FreeHi-C - Hi-C data simulation based on properties of experimental Hi-C data. Preserves A/B compartments, TADs, the correlation between replicated (HiCRep), significant interactions, improves power to detect differential interactions. Robust to sequencing depth changes. Tested on replicates of GM12878, A549 human cancer cells, malaria P.falciparum. Compared with poorly performing Sim3C. All simulated data are at https://zenodo.org/record/3345896. Python3 implementation https://github.com/keleslab/FreeHiC

Zheng, Ye, and Sündüz Keleş. “FreeHi-C Simulates High-Fidelity Hi-C Data for Benchmarking and Data Augmentation.” Nature Methods 17, no. 1 (January 2020)

Closing it, but please, feel free to ask more.