Skip to content

Commit

Permalink
added --split-intervals option, fixes #189
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasHeger committed Jun 9, 2015
1 parent d1662a5 commit baf0a13
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
19 changes: 17 additions & 2 deletions scripts/bam_vs_bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
Type::
cgat bam_vs_bed BAM BED [OPTIONS]
cgat bam_vs_bed BAM BED [OPTIONS]
cgat bam_vs_bed --bam-file=BAM --bed-file=BED [OPTIONS]
where BAM is either a bam or bed file and BED is a bed file.
Expand Down Expand Up @@ -102,11 +102,20 @@ def main(argv=None):
"processing. By default the file is assumed to be sorted "
"[%default]")

parser.add_option(
"--split-intervals", dest="split_intervals",
action="store_true",
help="treat split BAM intervals, for example spliced intervals, "
"as separate intervals. Note that a single alignment might be "
"counted several times as a result. "
"[%default]")

parser.set_defaults(
min_overlap=0.5,
filename_bam=None,
filename_bed=None,
sort_bed=False,
split_intervals=False,
)

# add common options (-h/--help, ...) and parse command line
Expand Down Expand Up @@ -199,10 +208,16 @@ def main(argv=None):
else:
bedcmd = filename_bed

if options.split_intervals:
split = "-split"
else:
split = ""

# IMS: newer versions of intersectBed have a very high memory
# requirement unless passed sorted bed files.
statement = """intersectBed %(format)s %(filename_bam)s
statement = """bedtools intersect %(format)s %(filename_bam)s
-b %(bedcmd)s
%(split)s
-sorted -bed -wo -f %(min_overlap)f""" % locals()

E.info("starting counting process: %s" % statement)
Expand Down
6 changes: 6 additions & 0 deletions tests/bam_vs_bed.py/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@ paired_unsorted:
references: [paired.tsv]
options: --sort-bed <DIR>/paired.bam <DIR>/context.paired_unsorted.bed.gz

paired_split:
stdin: null
outputs: [stdout]
references: [paired.tsv]
options: --split-intervals <DIR>/paired.bam <DIR>/context.paired.bed.gz



1 change: 1 addition & 0 deletions tests/option_list.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,7 @@ split-at-tag ok scripts/farm.py,scripts/nofarm.py
split-exons ok scripts/align_transcripts.py
split-fasta-identifier ok scripts/fasta2table.py
split-fields ok scripts/table2table.py
split-intervals ok scripts/bam_vs_bed.py
spp-srange-max ok scripts/runSPP.py
spp-srange-min ok scripts/runSPP.py
spp-z-threshold ok scripts/runSPP.py
Expand Down

0 comments on commit baf0a13

Please sign in to comment.