implement PETrackII for fragment files from scATAC experiments
[MACS.git] / MACS3 / Commands / cmbreps_cmd.py
blobc7cf9fc2548f440e56be2c16acff6c16cae15974
1 # Time-stamp: <2024-10-02 16:42:02 Tao Liu>
3 """Description: combine replicates
5 This code is free software; you can redistribute it and/or modify it
6 under the terms of the BSD License (see the file LICENSE included with
7 the distribution).
8 """
10 import os
12 from MACS3.IO import BedGraphIO
13 from MACS3.Utilities.OptValidator import opt_validate_cmbreps
15 # ------------------------------------
16 # constants
17 # ------------------------------------
19 # ------------------------------------
20 # Misc functions
21 # ------------------------------------
23 # ------------------------------------
24 # Main function
25 # ------------------------------------
28 def run(options):
29 options = opt_validate_cmbreps(options)
30 info = options.info
31 # warn = options.warn
32 # debug = options.debug
33 # error = options.error
35 info("Read and build bedGraph for each replicate...")
36 reps = []
37 i = 1
38 for ifile in options.ifile:
39 info("Read file #%d" % i)
40 reps.append(BedGraphIO.bedGraphIO(ifile).read_bedGraph())
41 i += 1
43 # first two reps
44 info("combining tracks 1-%i with method '%s'" % (i - 1, options.method))
45 cmbtrack = reps[0].overlie([reps[j] for j in range(1, i - 1)], func=options.method)
47 # now output
48 ofile = BedGraphIO.bedGraphIO(os.path.join(options.outdir, options.ofile), data=cmbtrack)
49 info("Write bedGraph of combined scores...")
50 ofile.write_bedGraph(name="%s_combined_scores" % (options.method.upper()), description="Scores calculated by %s" % (options.method.upper()))
51 info("Finished '%s'! Please check '%s'!" % (options.method, ofile.bedGraph_filename))