Mercurial > repos > matt-shirley > sra_fetch
annotate sra_fetch.py @ 3:01dec8611542 draft
Python script successfully returns SRA archive from accession.
author | Matthew Shirley <mdshw5@gmail.com> |
---|---|
date | Wed, 14 Nov 2012 13:05:14 -0500 |
parents | be22544bfafa |
children | f74bbb22bf62 |
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] | |
3
01dec8611542
Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents:
2
diff
changeset
|
6 prefix = accession[0:3] |
01dec8611542
Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents:
2
diff
changeset
|
7 middle = accession[3:6] |
01dec8611542
Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents:
2
diff
changeset
|
8 suffix = accession[6:9] |
1 | 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 |
3
01dec8611542
Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents:
2
diff
changeset
|
11 ftp = FTP('ftp-trace.ncbi.nih.gov') |
1 | 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 | 14 ftp.login() |
3
01dec8611542
Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents:
2
diff
changeset
|
15 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
|
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 + '/' + |
3
01dec8611542
Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents:
2
diff
changeset
|
18 prefix + middle + suffix + '/') |
01dec8611542
Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents:
2
diff
changeset
|
19 ftp.pwd() |
01dec8611542
Python script successfully returns SRA archive from accession.
Matthew Shirley <mdshw5@gmail.com>
parents:
2
diff
changeset
|
20 ftp.retrbinary('RETR ' + prefix + middle + suffix + '.sra', sys.stdout) |
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
|
21 ftp.quit() |