Last active
February 9, 2017 19:41
-
-
Save afrendeiro/e20c8981eba328963627 to your computer and use it in GitHub Desktop.
SRA sample to unaligned bam using sra tools and sambamba, job submission through slurm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from argparse import ArgumentParser | |
import sys | |
from pypiper import NGSTk | |
import textwrap | |
global tk | |
tk = NGSTk() | |
def sra2bam(sra_acession, output_bam): | |
# Slurm header | |
cmd = tk.slurm_header("_".join(["sra2bam", sra_acession]), "%s_sra2bam.log" % sra_acession, cpus_per_task=4) | |
# SRA to BAM | |
cmd += "\t\tsam-dump {0} | sambamba view -t 4 -S -f bam /dev/stdin > {0}.bam".format(sra_acession) | |
# Slurm footer | |
cmd += tk.slurm_footer() + "\n" | |
# Write job to file | |
job_file = "/scratch/users/arendeiro/%s_sra2bam.sh" % sra_acession | |
with open(job_file, "w") as handle: | |
handle.write(textwrap.dedent(cmd)) | |
# Submit | |
tk.slurm_submit_job(job_file) | |
if __name__ == "__main__": | |
try: | |
parser = ArgumentParser( | |
description="Makes unaligned bam file from SRA sample acession number", | |
usage="python sra2bam.py <sra_acession> <output_bam>" | |
) | |
# positional arguments | |
parser.add_argument("sra_acession", help="SRA acession number.") | |
parser.add_argument("output_bam", help="Output bam file.") | |
# parse | |
args = parser.parse_args() | |
sra2bam(args.sra_acession, args.output_bam) | |
except KeyboardInterrupt: | |
print("Program canceled by user!") | |
sys.exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment