In [30]:
from pytadbit.parsers.hic_parser import load_hic_data_from_reads
In [43]:
r_enz = 'MboI'
reso = 1000000
In [44]:
hic_data = load_hic_data_from_reads(
'results/fragment/{0}/03_filtering/valid_reads12_{0}.tsv'.format(r_enz),
reso)
For this, very sparse, example dataset we are going to ask for very few interactions per bin.
This can be done either by setting min_perc
asking for each bin to contain a minimum percentage of cells with interaction data. Or but setting min_count
asking that the number of cells with interaction data of each bin is above the defined cutoff.
In [45]:
hic_data.filter_columns(draw_hist=True, min_count=10, by_mean=True)
In [46]:
print len(hic_data)
print len(hic_data.bads)
In [47]:
bins = []
for i in range(len(hic_data)):
bins.append(sum(hic_data[i, j] for j in range(len(hic_data))))
out = open('results/fragment/{1}/04_normalizing/biases_{0}_{1}.tsv'.format(reso, r_enz), 'w')
for val in bins:
out.write(str(val) + '\n')
out.close()
As normalization we use either the ICE normalization (Imakaev et al., 2012) with a "full" normalization until the sum of all columns of the matrix are equal, or something more similar to the vanilla normalization used in (Rao et al., 2014) which is exactly like running the ICE normalization without iterations.
Note: if columns with a lot of zeroes are present the ICE normalization will last very long to converge, and these low-coverage columns will present, at the end of the normalization, few cells with very high values of interaction
In [48]:
hic_data.normalize_hic(iterations=10, max_dev=0.1)
At 100 kb itmakes no sense to view the full matrix (your matrix will have more cells than your screen have pixels).
Try plotting a region of the genome only, with the focus
parameter.
In [49]:
from pytadbit.mapping.analyze import hic_map
hic_map(hic_data, normalized=True, focus='chr18', show=True)
ICE normalization is widely used however other, more convaluted, normalizations (Hu et al., 2012) (Yaffe and Tanay, 2011) can be used outside TADbit and then added as normalized matrices.
In [50]:
from cPickle import dump
In [51]:
! mkdir -p results/fragment/$r_enz/04_normalizing
Save biases to separate file.
In [52]:
out = open('results/fragment/{1}/04_normalizing/biases_{0}_{1}.pick'.format(reso, r_enz), 'w')
dump(hic_data.bias, out)
out.close()
Save "bad" columns to an other file
In [53]:
out = open('results/fragment/{1}/04_normalizing/bad_columns_{0}_{1}.pick'.format(reso, r_enz), 'w')
dump(hic_data.bads, out)
out.close()
This time we do not need to save appart the normalization biases and the list of columns with poor signal.
In [27]:
hic_map(hic_data, by_chrom='intra', normalized=False,
savedata='results/fragment/{1}/04_normalizing/{0}_raw'.format(reso, r_enz))
In [28]:
hic_map(hic_data, by_chrom='intra', normalized=True,
savedata='results/fragment/{1}/04_normalizing/{0}_norm'.format(reso, r_enz))
If the resolution is not to low, we could also save genomic matrices:
In [29]:
if reso >= 300000:
hic_map(hic_data, by_chrom=False, normalized=False,
savedata='results/fragment/{1}/04_normalizing/{0}_raw.mat'.format(reso, r_enz))
hic_map(hic_data, by_chrom=False, normalized=True,
savedata='results/fragment/{1}/04_normalizing/{0}_norm.mat'.format(reso, r_enz))
[^](#ref-1) Imakaev, Maxim V and Fudenberg, Geoffrey and McCord, Rachel Patton and Naumova, Natalia and Goloborodko, Anton and Lajoie, Bryan R and Dekker, Job and Mirny, Leonid A. 2012. Iterative correction of Hi-C data reveals hallmarks of chromosome organization.. URL
[^](#ref-2) Rao, Suhas S P and Huntley, Miriam H and Durand, Neva C and Stamenova, Elena K and Bochkov, Ivan D. and James T. Robinson and Sanborn, Adrian L. and Machol, Ido and Omer, Arina D. and Lander, Eric S. and Lieberman-Aiden, Erez. 2014. A 3D Map of the Human Genome at Kilobase Resolution Reveals Principles of Chromatin Looping. URL
[^](#ref-3) Hu, Ming and Deng, Ke and Selvaraj, Siddarth and Qin, Zhaohui and Ren, Bing and Liu, Jun S. 2012. HiCNorm: removing biases in Hi-C data via Poisson regression.
[^](#ref-4) Yaffe, Eitan and Tanay, Amos. 2011. Probabilistic modeling of Hi-C contact maps eliminates systematic biases to characterize global chromosomal architecture.. URL