Mercurial > repos > matt-shirley > sra_tools
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:ffdd41766195 |
---|---|
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() |