annotate sra_fetch.py @ 2:be22544bfafa draft

First version of the python script that may work. Whole tool is still not functional.
author Matthew Shirley <mdshw5@gmail.com>
date Wed, 14 Nov 2012 12:07:18 -0500
parents aa7ab53c53bf
children 01dec8611542
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]
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
6 prefix = accession[0:2].uppercase()
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
7 middle = accession[3:5]
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
8 suffix = accession[6:8]
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
9
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
10 # NCBI SRA FTP site
1
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
11 ftp = FTP('ftp.ncbi.nlm.nih.gov')
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
12
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
13 # Open stdout and transfer requested SRA as a file
1
aa7ab53c53bf Started working on the python FTP script.
matt-shirley
parents:
diff changeset
14 ftp.login()
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
15 ftp.retrbinary('/sra/sra-instant/reads/ByRun/sra/' +
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
16 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
17 prefix + middle + '/' +
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 + middle + suffix + '/' +
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 + suffix + '.sra', sys.stdout)
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
20 ftp.quit()