annotate sra_fetch.py @ 5:f74bbb22bf62 draft

Fixed typos in python script.
author Matthew Shirley <mdshw5@gmail.com>
date Wed, 14 Nov 2012 13:35:44 -0500
parents 01dec8611542
children d7708f338c82
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
f74bbb22bf62 Fixed typos in python script.
Matthew Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
15 sra = open(outfile, 'wb')
f74bbb22bf62 Fixed typos in python script.
Matthew Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
16 ftp.login('ftp')
3
01dec8611542 Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents: 2
diff changeset
17 ftp.cwd('/sra/sra-instant/reads/ByRun/sra/' +
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
18 prefix + '/' +
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
19 prefix + middle + '/' +
3
01dec8611542 Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents: 2
diff changeset
20 prefix + middle + suffix + '/')
01dec8611542 Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents: 2
diff changeset
21 ftp.pwd()
5
f74bbb22bf62 Fixed typos in python script.
Matthew Shirley <mdshw5@gmail.com>
parents: 3
diff changeset
22 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
23 ftp.quit()