implement PETrackII for fragment files from scATAC experiments
[MACS.git] / MACS3 / Commands / bdgbroadcall_cmd.py
blobdf3f41e4034c1746e0c7bd865898da9829e752b3
1 # Time-stamp: <2024-10-02 15:55:43 Tao Liu>
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
8 the distribution).
10 """
12 # ------------------------------------
13 # python modules
14 # ------------------------------------
16 import os
17 from MACS3.IO import BedGraphIO
18 # ------------------------------------
19 # constants
20 # ------------------------------------
22 # ------------------------------------
23 # Misc functions
24 # ------------------------------------
25 from MACS3.Utilities.Logger import logging
27 logger = logging.getLogger(__name__)
28 debug = logger.debug
29 info = logger.info
30 error = logger.critical
31 warn = logger.warning
33 # ------------------------------------
34 # Classes
35 # ------------------------------------
37 # ------------------------------------
38 # Main function
39 # ------------------------------------
42 def run(options):
43 info("Read and build bedGraph...")
44 bio = BedGraphIO.bedGraphIO(options.ifile)
45 btrack = bio.read_bedGraph(baseline_value=0)
47 info("Call peaks from bedGraph...")
49 bpeaks = btrack.call_broadpeaks(options.cutoffpeak, options.cutofflink, options.minlen, options.lvl1maxgap, options.lvl2maxgap)
51 info("Write peaks...")
53 if options.ofile:
54 bf = open(os.path.join(options.outdir, options.ofile), "w")
55 options.oprefix = options.ofile
56 else:
57 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")
58 bpeaks.write_to_gappedPeak(bf, name_prefix=(options.oprefix+"_broadRegion").encode(), score_column="score", trackline=options.trackline)
59 info("Done")