Mercurial > repos > matt-shirley > sra_tools
changeset 13:45031bbf6b27 draft
better sra_fetch code, compliant (?) datatype, updated dependencies in tool wrappers
author | Matt Shirley <mdshw5@gmail.com> |
---|---|
date | Mon, 17 Jun 2013 16:17:33 -0400 |
parents | b77840618b8f |
children | 082fd6374582 |
files | fastq_dump.xml sam_dump.xml sra_fetch.py sra_fetch.xml |
diffstat | 4 files changed, 41 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/fastq_dump.xml Mon Jun 17 16:05:30 2013 -0400 +++ b/fastq_dump.xml Mon Jun 17 16:17:33 2013 -0400 @@ -1,4 +1,4 @@ -<tool id="fastq_dump" name="Extract fastq" version="1.0.0"> +<tool id="fastq_dump" name="Extract fastq" version="1.0.1"> <description> format reads from NCBI SRA.</description> <command>fastq-dump --log-level fatal --report never --accession '${input.name}' --stdout $split $aligned '$input' > $output </command> <version_string>fastq-dump --version</version_string>
--- a/sam_dump.xml Mon Jun 17 16:05:30 2013 -0400 +++ b/sam_dump.xml Mon Jun 17 16:17:33 2013 -0400 @@ -1,4 +1,4 @@ -<tool id="sam_dump" name="Extract SAM" version="1.0.0"> +<tool id="sam_dump" name="Extract SAM" version="1.0.1"> <description> format reads from NCBI SRA.</description> <command>sam-dump $header $aligned $primary '$input' > $output</command> <version_string>sam-dump --version</version_string>
--- a/sra_fetch.py Mon Jun 17 16:05:30 2013 -0400 +++ b/sra_fetch.py Mon Jun 17 16:17:33 2013 -0400 @@ -1,30 +1,41 @@ +import sys +import os from ftplib import FTP -import sys +import argparse -# Get accession number from argument -accession = sys.argv[1] -outfile = sys.argv[2] -prefix = accession[0:3] -middle = accession[3:6] -suffix = accession[6:9] +def main(args): + """ Get accession number from argument """ + prefix = args.accession[0:3] + middle = args.accession[3:6] + suffix = args.accession[6:9] -# NCBI SRA FTP site -ftp = FTP('ftp-trace.ncbi.nih.gov') + ftp = FTP('ftp-trace.ncbi.nih.gov') -# Open file and transfer requested SRA as a file -# Try to change the working directory until it works -sra = open(outfile, 'wb') -ftp.login('ftp') -connected = False -while not connected: - try: - ftp.cwd('/sra/sra-instant/reads/ByRun/sra/' + - prefix + '/' + - prefix + middle + '/' + - prefix + middle + suffix + '/') - connected = True - except: - pass - -ftp.retrbinary('RETR ' + prefix + middle + suffix + '.sra', sra.write) -ftp.quit() + # Open file and transfer requested SRA as a file + # Try to change the working directory until it works + with open(args.out, 'wb') as sra: + ftpPath = os.path.join('/sra/sra-instant/reads/ByRun/sra/', + prefix, + prefix + middle, + prefix + middle + suffix) + ftp.login('ftp') + connected = False + while not connected: + try: + ftp.cwd(ftpPath) + connected = True + except: + pass + ftp.retrbinary('RETR ' + prefix + middle + suffix + '.sra', sra.write) + ftp.quit() + +def arguments(): + parser = argparse.ArgumentParser(description="Download an SRA from the NCBI SRA FTP") + parser.add_argument('accession', type=str, help="SRA accession ex: SRR000001") + parser.add_argument('-o', '--out', type=str, help="Name for SRA file ") + args = parser.parse_args() + return args + +if __name__ == "__main__": + args = arguments() + main(args)
--- a/sra_fetch.xml Mon Jun 17 16:05:30 2013 -0400 +++ b/sra_fetch.xml Mon Jun 17 16:17:33 2013 -0400 @@ -1,6 +1,6 @@ -<tool id="sra_fetch" name="Fetch SRA" version="1.0.0"> +<tool id="sra_fetch" name="Fetch SRA" version="1.0.1"> <description> by accession from NCBI SRA.</description> - <command interpreter="python">sra_fetch.py '$accession' '$output'</command> + <command interpreter="python">sra_fetch.py '$accession' -o '$output'</command> <inputs> <param name="accession" size="13" type="text" value="SRR000001" label="SRA run accession"/> </inputs>