Skip to content

Commit b87b183

Browse files
committed
pileup support for FRAG format done
1 parent 7d67449 commit b87b183

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

MACS3/Commands/pileup_cmd.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
under the terms of the BSD License (see the file LICENSE included with
55
the distribution).
66
"""
7-
# Time-stamp: <2024-10-02 16:51:15 Tao Liu>
7+
# Time-stamp: <2024-11-30 00:04:48 Tao Liu>
88
# ------------------------------------
99
# python modules
1010
# ------------------------------------
@@ -16,7 +16,8 @@
1616
# ------------------------------------
1717
# from MACS3.Utilities.Constants import *
1818
from MACS3.Utilities.OptValidator import opt_validate_pileup
19-
from MACS3.Signal.Pileup import pileup_and_write_se, pileup_and_write_pe
19+
from MACS3.Signal.Pileup import pileup_and_write_se
20+
from MACS3.IO.BedGraphIO import bedGraphIO
2021
# ------------------------------------
2122
# Main function
2223
# ------------------------------------
@@ -35,7 +36,7 @@ def run(o_options):
3536
# error = options.error
3637

3738
# 0 output arguments
38-
options.PE_MODE = options.format in ('BAMPE', 'BEDPE')
39+
options.PE_MODE = options.format in ('BAMPE', 'BEDPE', 'FRAG')
3940

4041
# 0 prepare output file
4142
outfile = os.path.join(options.outdir, options.outputfile).encode()
@@ -51,8 +52,9 @@ def run(o_options):
5152
t0 = treat.total # total fragments
5253
info("# total fragments/pairs in alignment file: %d" % (t0))
5354
info("# Pileup paired-end alignment file.")
54-
pileup_and_write_pe(treat, outfile)
55-
55+
bdg = treat.pileup_bdg()
56+
bdgio = bedGraphIO(outfile, data=bdg)
57+
bdgio.write_bedGraph(trackline=False)
5658
else:
5759
(tsize, treat) = load_tag_files_options(options)
5860

MACS3/IO/BedGraphIO.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# cython: language_level=3
22
# cython: profile=True
3-
# Time-stamp: <2024-10-08 10:07:47 Tao Liu>
3+
# Time-stamp: <2024-11-30 00:04:35 Tao Liu>
44

55
"""Module Description: IO Module for bedGraph file
66
@@ -56,10 +56,10 @@ class bedGraphIO:
5656
5757
If any of the above two criteria is violated, parsering will fail.
5858
"""
59-
bedGraph_filename = cython.declare(str, visibility='public')
59+
bedGraph_filename = cython.declare(bytes, visibility='public')
6060
data = cython.declare(object, visibility='public')
6161

62-
def __init__(self, bedGraph_filename: str, data=None):
62+
def __init__(self, bedGraph_filename: bytes, data=None):
6363
"""f must be a filename or a file handler.
6464
6565
"""

MACS3/IO/Parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# cython: language_level=3
22
# cython: profile=True
33
# cython: linetrace=True
4-
# Time-stamp: <2024-10-22 10:25:23 Tao Liu>
4+
# Time-stamp: <2024-11-29 23:30:03 Tao Liu>
55

66
"""Module for all MACS Parser classes for input. Please note that the
77
parsers are for reading the alignment files ONLY.
@@ -1528,6 +1528,10 @@ def pe_parse_line(self, thisline: bytes):
15281528
raise Exception("Less than 5 columns found at this line: %s\n" %
15291529
thisline)
15301530

1531+
@cython.ccall
1532+
def build_petrack(self):
1533+
return self.build_petrack2()
1534+
15311535
@cython.ccall
15321536
def build_petrack2(self):
15331537
"""Build PETrackII from all lines.

MACS3/Signal/PairedEndTrack.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# cython: language_level=3
22
# cython: profile=True
3-
# Time-stamp: <2024-10-15 15:56:00 Tao Liu>
3+
# Time-stamp: <2024-11-29 23:37:25 Tao Liu>
44

55
"""Module for filter duplicate tags from paired-end data
66
@@ -749,6 +749,8 @@ def add_loc(self,
749749
self.buf_size[chromosome] += self.buffer_size
750750
self.locations[chromosome].resize((self.buf_size[chromosome]),
751751
refcheck=False)
752+
self.barcodes[chromosome].resize((self.buf_size[chromosome]),
753+
refcheck=False)
752754
self.locations[chromosome][i] = (start, end, count)
753755
self.barcodes[chromosome][i] = bn
754756
self.size[chromosome] = i + 1

MACS3/Utilities/OptValidator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Time-stamp: <2024-11-29 22:11:31 Tao Liu>
1+
# Time-stamp: <2024-11-29 23:48:10 Tao Liu>
22
"""Module Description
33
44
This code is free software; you can redistribute it and/or modify it
@@ -104,6 +104,7 @@ def opt_validate_callpeak(options):
104104
# setting it as 'all'
105105
if options.format == 'FRAG' and options.keepduplicates != "all":
106106
logger.warning("Since the format is 'FRAG', `--keep-dup` will be set as 'all'.")
107+
options.keepduplicates = "all"
107108

108109
if options.extsize < 1:
109110
logger.error("--extsize must >= 1!")
@@ -537,7 +538,7 @@ def opt_validate_pileup(options):
537538
elif options.format == "BEDPE":
538539
options.parser = BEDPEParser
539540
elif options.format == "FRAG":
540-
options.parser = FragParser
541+
options.parser = FragParser
541542
else:
542543
logger.error("Format \"%s\" cannot be recognized!" % (options.format))
543544
sys.exit(1)

0 commit comments

Comments
 (0)