Mercurial > repos > dpryan79 > bwameth
diff bwameth_wrapper.py @ 3:3e1095e1defa draft
Deleted selected files
author | dpryan79 |
---|---|
date | Tue, 13 Sep 2016 15:59:44 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bwameth_wrapper.py Tue Sep 13 15:59:44 2016 -0400 @@ -0,0 +1,42 @@ +#!/usr/bin/env python +import argparse +import subprocess +import os +import shlex + +def createIndex(fname): + """ + Create an index for a file, return where it is + """ + d = os.mkdir("index_dir") + os.link(fname, "index_dir/genome.fa") + cmd = "{}/bwameth.py index index_dir/genome.fa".format(os.path.dirname(__file__)) + proc = subprocess.Popen(args=shlex.split(cmd)) + returncode = proc.wait() + if returncode != 0: + raise Exception("Error during '%s'" % cmd) + return "index_dir/genome.fa" + + +parser = argparse.ArgumentParser(description="A wrapper around bwameth for Galaxy. There's minimal argument checking done") +parser.add_argument('-p', '--numThreads', type=int, default=4, help="number of threads") +parser.add_argument('--makeIndex', help="Given a fasta file, index it") +parser.add_argument('--premadeIndex', help="If an index already exists, this is the fasta file associated with it (the index files must be in the same directory") +parser.add_argument('--readGroup', help="The read group text, if desired") +parser.add_argument('files', nargs="+", help="Fasta files (possibly gzipped, if the file names end in .gz)") +args = parser.parse_args() + +if "makeIndex" in args: + ifile = createIndex(args.makeIndex) +else: + ifile = args.premadeIndex + +files = " ".join(['{}'.format(x) for x in args.files]) +if "readGroup" in args: + files = "{} --read-group '{}'".format(files, args.readGroup) + +cmd = "{}/bwameth.py -p {} '{}' {} | samtools view -Su - - | samtools sort -@ {} -o output.bam -".format(os.path.dirname(__file__), args.numThreads, ifile, files, args.numThreads) +proc = subprocess.Popen(args=shlex.split(cmd)) +returncode = proc.wait() +if returncode != 0: + raise Exception("Error during '%s'" % cmd)