from pytadbit.mapping.analyze import plot_genomic_distribution

plot_genomic_distribution("results/HindIII/03_filtering/reads12.tsv", resolution=500000, show=True)

"""
Explanation: the orange slope is the most important and you expect a slope of around -1 unless you work with cells badly synchronized or with weird karyotype
resolution= size of bins
End of explanation
"""


from pytadbit.mapping.analyze import hic_map

hic_map("results/HindIII/03_filtering/reads12.tsv", resolution=1000000, show=True)

from pytadbit.mapping.analyze import insert_sizes

insert_sizes("results/HindIII/03_filtering/reads12.tsv", show=True, nreads=100000)

from pytadbit.mapping.filter import filter_reads

filter_reads("results/HindIII/03_filtering/reads12.tsv", max_molecule_length=750, min_dist_to_re=500)

masked = {1: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_self-circle.tsv',
  'name': 'self-circle',
  'reads': 37383},
 2: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_dangling-end.tsv',
  'name': 'dangling-end',
  'reads': 660146},
 3: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_error.tsv',
  'name': 'error',
  'reads': 37395},
 4: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_extra_dangling-end.tsv',
  'name': 'extra dangling-end',
  'reads': 3773498},
 5: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_too_close_from_RES.tsv',
  'name': 'too close from RES',
  'reads': 3277369},
 6: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_too_short.tsv',
  'name': 'too short',
  'reads': 296853},
 7: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_too_large.tsv',
  'name': 'too large',
  'reads': 1843},
 8: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_over-represented.tsv',
  'name': 'over-represented',
  'reads': 411157},
 9: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_duplicated.tsv',
  'name': 'duplicated',
  'reads': 324490},
 10: {'fnam': 'results/HindIII/03_filtering/reads12.tsv_random_breaks.tsv',
  'name': 'random breaks',
  'reads': 968492}}

from pytadbit.mapping.filter import apply_filter

apply_filter ("results/HindIII/03_filtering/reads12.tsv", 
              "results/HindIII/03_filtering/reads12_valid.tsv", 
              masked, filters=[1, 2, 3, 4, 9, 10])

"""
Explanation: In Y we have number of reads per 500kb bins
It reflects different number of copies, for example in chromosome 2 the last part of the chromosome has less copies than the rest, therefore the lower number of reads. 
Big peaks correspond to PCR duplicates
End of explanation
"""


