annotate sra_fetch.py @ 7:d7708f338c82 draft

bug fixes
author Matthew Shirley <mdshw5@gmail.com>
date Wed, 14 Nov 2012 16:55:51 -0500
parents f74bbb22bf62
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
1 from ftplib import FTP
2
be22544bfafa First version of the python script that may work. Whole tool is still not functional.
Matthew Shirley <mdshw5@gmail.com>
parents: 1
diff changeset
2 import sys
1
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
3
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
4 # Get accession number from argument
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
5 accession = sys.argv[1]
5
f74bbb22bf62 Fixed typos in python script.
Matthew Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
6 outfile = sys.argv[2]
3
01dec8611542 Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents: 2
diff changeset
7 prefix = accession[0:3]
01dec8611542 Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents: 2
diff changeset
8 middle = accession[3:6]
01dec8611542 Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents: 2
diff changeset
9 suffix = accession[6:9]
1
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
10
2
be22544bfafa First version of the python script that may work. Whole tool is still not functional.
Matthew Shirley <mdshw5@gmail.com>
parents: 1
diff changeset
11 # NCBI SRA FTP site
3
01dec8611542 Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents: 2
diff changeset
12 ftp = FTP('ftp-trace.ncbi.nih.gov')
1
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
13
5
f74bbb22bf62 Fixed typos in python script.
Matthew Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
14 # Open file and transfer requested SRA as a file
7
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
15 # Try to change the working directory until it works
5
f74bbb22bf62 Fixed typos in python script.
Matthew Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
16 sra = open(outfile, 'wb')
f74bbb22bf62 Fixed typos in python script.
Matthew Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
17 ftp.login('ftp')
7
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
18 connected = False
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
19 while not connected:
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
20 try:
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
21 ftp.cwd('/sra/sra-instant/reads/ByRun/sra/' +
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
22 prefix + '/' +
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
23 prefix + middle + '/' +
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
24 prefix + middle + suffix + '/')
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
25 connected = True
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
26 except:
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
27 pass
d7708f338c82 bug fixes
Matthew Shirley <mdshw5@gmail.com>
parents: 5
diff changeset
28
5
f74bbb22bf62 Fixed typos in python script.
Matthew Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
29 ftp.retrbinary('RETR ' + prefix + middle + suffix + '.sra', sra.write)
2
be22544bfafa First version of the python script that may work. Whole tool is still not functional.
Matthew Shirley <mdshw5@gmail.com>
parents: 1
diff changeset
30 ftp.quit()