Mercurial > repos > matt-shirley > sra_tools
view sra_fetch.py @ 0:ffdd41766195 draft
Initial version - still need to test if datatype works correctly, and implement scripted download of SRA binaries.
author | matt-shirley <mdshw5@gmail.com> |
---|---|
date | Tue, 27 Nov 2012 13:44:28 -0500 |
parents | |
children | 45031bbf6b27 |
line wrap: on
line source
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()