Mercurial > repos > matt-shirley > sra_fetch
comparison sra_fetch.py @ 9:cf0980cfd040 draft default tip
Deleted selected files
author | matt-shirley |
---|---|
date | Tue, 27 Nov 2012 13:38:35 -0500 |
parents | 61d634d123c0 |
children |
comparison
equal
deleted
inserted
replaced
8:61d634d123c0 | 9:cf0980cfd040 |
---|---|
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() |