Mercurial > repos > brad-chapman > bam_to_bigwig
changeset 4:14e5258d1b39
v0.1.1: Add the forgotten --split argument in XML and moves to using the new bedtools. Thanks to David Leader
author | Brad Chapman <chapmanb@50mail.com> |
---|---|
date | Tue, 11 Feb 2014 15:55:22 -0500 |
parents | 294e9dae5a9b |
children | 52bcd04ee0d6 |
files | bam_to_bigwig/README.txt bam_to_bigwig/bam_to_bigwig.py bam_to_bigwig/bam_to_bigwig.xml |
diffstat | 3 files changed, 14 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/bam_to_bigwig/README.txt Wed Sep 05 21:19:42 2012 -0400 +++ b/bam_to_bigwig/README.txt Tue Feb 11 15:55:22 2014 -0500 @@ -7,6 +7,9 @@ History ------- +v0.1.1 passes the forgotten split argument and moves to using the new +sub-command enabled bedtools. Thanks to David Leader. + As of v0.1.0, the Galaxy tools uses a revised bam_to_bigwig.py script using genomeCoverageBed and bedGraphToBigWig - this approach allows gaps/skpis to be excluded from the coverage calculation, which is important for RNA-Seq.
--- a/bam_to_bigwig/bam_to_bigwig.py Wed Sep 05 21:19:42 2012 -0400 +++ b/bam_to_bigwig/bam_to_bigwig.py Tue Feb 11 15:55:22 2014 -0500 @@ -4,22 +4,14 @@ """Convert BAM files to BigWig file format in a specified region. Usage: - bam_to_wiggle.py <BAM file> [<YAML config>] [--outfile=<output file name>] - -The optional config file (not used by the Galaxy interface) is in YAML format -and specifies the location of the binary tools. + bam_to_wiggle.py <BAM file> [--outfile=<output file name>] [--split] -program: - bedtools_genomeCoverageBed: genomeCoverageBed - ucsc_bedGraphToBigWig: bedGraphToBigWig - -If not specified, these will be assumed to be present in the system path. +The --split argument is passed to bedtools genomecov The script requires: pysam (http://code.google.com/p/pysam/) - genomeCoverageBed from BedTools (http://code.google.com/p/bedtools/) + bedtools genomecov (http://code.google.com/p/bedtools/) bedGraphToBigWig from UCSC (http://hgdownload.cse.ucsc.edu/admin/exe/) -If a configuration file is used, then PyYAML is also required (http://pyyaml.org/) """ import os import sys @@ -30,14 +22,9 @@ import pysam -def main(bam_file, config_file=None, outfile=None, split=False): - if config_file: - import yaml - with open(config_file) as in_handle: - config = yaml.load(in_handle) - else: - config = {"program": {"ucsc_bedGraphToBigWig" : "bedGraphToBigWig", - "bedtools_genomeCoverageBed" : "genomeCoverageBed"}} +def main(bam_file, outfile=None, split=False): + config = {"program": {"ucsc_bedGraphToBigWig": ["bedGraphToBigWig"], + "bedtools_genomeCoverageBed": ["bedtools", "genomecov"]}} if outfile is None: outfile = "%s.bigwig" % os.path.splitext(bam_file)[0] if os.path.abspath(bam_file) == os.path.abspath(outfile): @@ -59,7 +46,7 @@ print "Calculating coverage..." convert_to_graph(bam_file, split, config, temp_handle) try: - print "Converting %i MB graph file to bigwig..." % (os.path.getsize(temp_file) // (1024*1024)) + print "Converting %i MB graph file to bigwig..." % (os.path.getsize(temp_file) // (1024 * 1024)) #Can't pipe this as stdin due to converter design, #https://lists.soe.ucsc.edu/pipermail/genome/2011-March/025455.html convert_to_bigwig(temp_file, sizes, config, outfile) @@ -82,7 +69,7 @@ return sizes def convert_to_graph(bam_file, split, config, out_handle): - cl = [config["program"]["bedtools_genomeCoverageBed"], "-ibam", bam_file, "-bg"] + cl = [config["program"]["bedtools_genomeCoverageBed"]] + ["-ibam", bam_file, "-bg"] if split: cl.append("-split") subprocess.check_call(cl, stdout=out_handle) @@ -94,7 +81,7 @@ for chrom, size in chr_sizes: out_handle.write("%s\t%s\n" % (chrom, size)) try: - cl = [config["program"]["ucsc_bedGraphToBigWig"], bedgraph_file, size_file, bw_file] + cl = [config["program"]["ucsc_bedGraphToBigWig"]] + [bedgraph_file, size_file, bw_file] subprocess.check_call(cl) finally: os.remove(size_file)
--- a/bam_to_bigwig/bam_to_bigwig.xml Wed Sep 05 21:19:42 2012 -0400 +++ b/bam_to_bigwig/bam_to_bigwig.xml Tue Feb 11 15:55:22 2014 -0500 @@ -1,6 +1,6 @@ -<tool id="bam_to_bigwig" name="BAM to BigWig" version="0.1.0"> +<tool id="bam_to_bigwig" name="BAM to BigWig" version="0.1.1"> <description>Calculates coverage from a BAM alignment file</description> - <command interpreter="python">bam_to_bigwig.py $align --outfile=$out</command> + <command interpreter="python">bam_to_bigwig.py $align --outfile=$out --split</command> <inputs> <param format="bam" name="align" type="data" label="BAM alignment file"/> </inputs>