Mercurial > repos > dddd > test1
comparison sra_tools-ffdd41766195/sra_fetch.py @ 0:f1de190a2aef draft
Uploaded
| author | dddd |
|---|---|
| date | Thu, 28 Feb 2013 18:10:48 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:f1de190a2aef |
|---|---|
| 1 from ftplib import FTP | |
| 2 import sys | |
| 3 | |
| 4 # Get accession number from argument | |
| 5 accession = sys.argv[1] | |
| 6 outfile = sys.argv[2] | |
| 7 prefix = accession[0:3] | |
| 8 middle = accession[3:6] | |
| 9 suffix = accession[6:9] | |
| 10 | |
| 11 # NCBI SRA FTP site | |
| 12 ftp = FTP('ftp-trace.ncbi.nih.gov') | |
| 13 | |
| 14 # Open file and transfer requested SRA as a file | |
| 15 # Try to change the working directory until it works | |
| 16 sra = open(outfile, 'wb') | |
| 17 ftp.login('ftp') | |
| 18 connected = False | |
| 19 while not connected: | |
| 20 try: | |
| 21 ftp.cwd('/sra/sra-instant/reads/ByRun/sra/' + | |
| 22 prefix + '/' + | |
| 23 prefix + middle + '/' + | |
| 24 prefix + middle + suffix + '/') | |
| 25 connected = True | |
| 26 except: | |
| 27 pass | |
| 28 | |
| 29 ftp.retrbinary('RETR ' + prefix + middle + suffix + '.sra', sra.write) | |
| 30 ftp.quit() |
