Skip to content

Commit

Permalink
pileup support for FRAG format done
Browse files Browse the repository at this point in the history
  • Loading branch information
taoliu committed Nov 30, 2024
1 parent 7d67449 commit b87b183
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
12 changes: 7 additions & 5 deletions MACS3/Commands/pileup_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
under the terms of the BSD License (see the file LICENSE included with
the distribution).
"""
# Time-stamp: <2024-10-02 16:51:15 Tao Liu>
# Time-stamp: <2024-11-30 00:04:48 Tao Liu>
# ------------------------------------
# python modules
# ------------------------------------
Expand All @@ -16,7 +16,8 @@
# ------------------------------------
# from MACS3.Utilities.Constants import *
from MACS3.Utilities.OptValidator import opt_validate_pileup
from MACS3.Signal.Pileup import pileup_and_write_se, pileup_and_write_pe
from MACS3.Signal.Pileup import pileup_and_write_se
from MACS3.IO.BedGraphIO import bedGraphIO
# ------------------------------------
# Main function
# ------------------------------------
Expand All @@ -35,7 +36,7 @@ def run(o_options):
# error = options.error

# 0 output arguments
options.PE_MODE = options.format in ('BAMPE', 'BEDPE')
options.PE_MODE = options.format in ('BAMPE', 'BEDPE', 'FRAG')

# 0 prepare output file
outfile = os.path.join(options.outdir, options.outputfile).encode()
Expand All @@ -51,8 +52,9 @@ def run(o_options):
t0 = treat.total # total fragments
info("# total fragments/pairs in alignment file: %d" % (t0))
info("# Pileup paired-end alignment file.")
pileup_and_write_pe(treat, outfile)

bdg = treat.pileup_bdg()
bdgio = bedGraphIO(outfile, data=bdg)
bdgio.write_bedGraph(trackline=False)
else:
(tsize, treat) = load_tag_files_options(options)

Expand Down
6 changes: 3 additions & 3 deletions MACS3/IO/BedGraphIO.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cython: language_level=3
# cython: profile=True
# Time-stamp: <2024-10-08 10:07:47 Tao Liu>
# Time-stamp: <2024-11-30 00:04:35 Tao Liu>

"""Module Description: IO Module for bedGraph file
Expand Down Expand Up @@ -56,10 +56,10 @@ class bedGraphIO:
If any of the above two criteria is violated, parsering will fail.
"""
bedGraph_filename = cython.declare(str, visibility='public')
bedGraph_filename = cython.declare(bytes, visibility='public')
data = cython.declare(object, visibility='public')

def __init__(self, bedGraph_filename: str, data=None):
def __init__(self, bedGraph_filename: bytes, data=None):
"""f must be a filename or a file handler.
"""
Expand Down
6 changes: 5 additions & 1 deletion MACS3/IO/Parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# cython: language_level=3
# cython: profile=True
# cython: linetrace=True
# Time-stamp: <2024-10-22 10:25:23 Tao Liu>
# Time-stamp: <2024-11-29 23:30:03 Tao Liu>

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

@cython.ccall
def build_petrack(self):
return self.build_petrack2()

@cython.ccall
def build_petrack2(self):
"""Build PETrackII from all lines.
Expand Down
4 changes: 3 additions & 1 deletion MACS3/Signal/PairedEndTrack.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cython: language_level=3
# cython: profile=True
# Time-stamp: <2024-10-15 15:56:00 Tao Liu>
# Time-stamp: <2024-11-29 23:37:25 Tao Liu>

"""Module for filter duplicate tags from paired-end data
Expand Down Expand Up @@ -749,6 +749,8 @@ def add_loc(self,
self.buf_size[chromosome] += self.buffer_size
self.locations[chromosome].resize((self.buf_size[chromosome]),
refcheck=False)
self.barcodes[chromosome].resize((self.buf_size[chromosome]),
refcheck=False)
self.locations[chromosome][i] = (start, end, count)
self.barcodes[chromosome][i] = bn
self.size[chromosome] = i + 1
Expand Down
5 changes: 3 additions & 2 deletions MACS3/Utilities/OptValidator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Time-stamp: <2024-11-29 22:11:31 Tao Liu>
# Time-stamp: <2024-11-29 23:48:10 Tao Liu>
"""Module Description
This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -104,6 +104,7 @@ def opt_validate_callpeak(options):
# setting it as 'all'
if options.format == 'FRAG' and options.keepduplicates != "all":
logger.warning("Since the format is 'FRAG', `--keep-dup` will be set as 'all'.")
options.keepduplicates = "all"

if options.extsize < 1:
logger.error("--extsize must >= 1!")
Expand Down Expand Up @@ -537,7 +538,7 @@ def opt_validate_pileup(options):
elif options.format == "BEDPE":
options.parser = BEDPEParser
elif options.format == "FRAG":
options.parser = FragParser
options.parser = FragParser
else:
logger.error("Format \"%s\" cannot be recognized!" % (options.format))
sys.exit(1)
Expand Down

0 comments on commit b87b183

Please sign in to comment.