# HG changeset patch # User Brad Chapman # Date 1392152122 18000 # Node ID 14e5258d1b396a029a43c1f00ef34194133742d1 # Parent 294e9dae5a9b4c326702a838e74e2323db56a94e v0.1.1: Add the forgotten --split argument in XML and moves to using the new bedtools. Thanks to David Leader diff -r 294e9dae5a9b -r 14e5258d1b39 bam_to_bigwig/README.txt --- 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. diff -r 294e9dae5a9b -r 14e5258d1b39 bam_to_bigwig/bam_to_bigwig.py --- 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 [] [--outfile=] - -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 [--outfile=] [--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) diff -r 294e9dae5a9b -r 14e5258d1b39 bam_to_bigwig/bam_to_bigwig.xml --- 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 @@ - + Calculates coverage from a BAM alignment file - bam_to_bigwig.py $align --outfile=$out + bam_to_bigwig.py $align --outfile=$out --split