1 # Time-stamp: <2019-09-25 10:04:48 taoliu>
3 """Description: Fine-tuning script to call broad peaks from a single
4 bedGraph track for scores.
6 This code is free software; you can redistribute it and/or modify it
7 under the terms of the BSD License (see the file LICENSE included with
12 # ------------------------------------
14 # ------------------------------------
19 from MACS2
.IO
import BedGraphIO
20 # ------------------------------------
22 # ------------------------------------
23 logging
.basicConfig(level
=20,
24 format
='%(levelname)-5s @ %(asctime)s: %(message)s ',
25 datefmt
='%a, %d %b %Y %H:%M:%S',
30 # ------------------------------------
32 # ------------------------------------
33 error
= logging
.critical
# function alias
34 warn
= logging
.warning
37 # ------------------------------------
39 # ------------------------------------
41 # ------------------------------------
43 # ------------------------------------
45 info("Read and build bedGraph...")
46 bio
= BedGraphIO
.bedGraphIO(options
.ifile
)
47 btrack
= bio
.build_bdgtrack(baseline_value
=0)
49 info("Call peaks from bedGraph...")
51 bpeaks
= btrack
.call_broadpeaks (lvl1_cutoff
=options
.cutoffpeak
, lvl2_cutoff
=options
.cutofflink
, min_length
=options
.minlen
, lvl1_max_gap
=options
.lvl1maxgap
, lvl2_max_gap
=options
.lvl2maxgap
)
53 info("Write peaks...")
56 bf
= open( os
.path
.join( options
.outdir
, options
.ofile
), "w" )
57 options
.oprefix
= options
.ofile
59 bf
= open ( os
.path
.join( options
.outdir
, "%s_c%.1f_C%.2f_l%d_g%d_G%d_broad.bed12" % (options
.oprefix
,options
.cutoffpeak
,options
.cutofflink
,options
.minlen
,options
.lvl1maxgap
,options
.lvl2maxgap
)), "w" )
60 bpeaks
.write_to_gappedPeak(bf
, name_prefix
=(options
.oprefix
+"_broadRegion").encode(), score_column
="score", trackline
=options
.trackline
)