Mercurial > repos > matt-shirley > sra_fetch
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 |
| 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 |
| 7 | 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 | 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 | |
|
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() |
