Mercurial > repos > matt-shirley > sra_fetch
annotate sra_fetch.py @ 6:20a054a7e2fd draft
Updated wrapper script.
author | Matthew Shirley <mdshw5@gmail.com> |
---|---|
date | Wed, 14 Nov 2012 13:36:21 -0500 |
parents | f74bbb22bf62 |
children | d7708f338c82 |
rev | line source |
---|---|
1 | 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 | 3 |
4 # Get accession number from argument | |
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 | 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 | 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() |