Mercurial > repos > dddd > test1
diff sra_tools-ffdd41766195/sra_fetch.py @ 0:f1de190a2aef draft
Uploaded
author | dddd |
---|---|
date | Thu, 28 Feb 2013 18:10:48 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sra_tools-ffdd41766195/sra_fetch.py Thu Feb 28 18:10:48 2013 -0500 @@ -0,0 +1,30 @@ +from ftplib import FTP +import sys + +# 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] + +# NCBI SRA FTP site +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()