# HG changeset patch # User jpayne # Date 1545164262 18000 # Node ID 02ac32a00e2525f1f986c9cc3f336dfe16001eee planemo upload commit 4aa8338dc8bcd7f6c0fb675044ea9d0c045ee7f3 diff -r 000000000000 -r 02ac32a00e25 bio2srr.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bio2srr.py Tue Dec 18 15:17:42 2018 -0500 @@ -0,0 +1,58 @@ +#! /usr/bin/env python3 + +"Grab SRR numbers from BioProjects via the EMBL-ENA REST API's." + +import requests +import sys + +sra_exp_query = "http://www.ebi.ac.uk/ebisearch/ws/rest/sra-experiment?query={bioproject}" + +sample = """{ + "hitCount": 2, + "entries": [ + { + "id": "SRX377510", + "source": "sra-experiment" + }, + { + "id": "SRX583279", + "source": "sra-experiment" + } + ], + "facets": [] +}""" + +sra_run_query = "http://www.ebi.ac.uk/ebisearch/ws/rest/sra-run?query={experiment}" + +sample = """{ + "hitCount": 1, + "entries": [ + { + "id": "SRR1029665", + "source": "sra-run" + } + ], + "facets": [] +}""" + +if __name__ == "__main__": + try: + bioproject = sys.argv[1] + b_result = requests.get(sra_exp_query.format(bioproject=bioproject), headers=dict(Accept="application/json")) + b_result.raise_for_status() + if b_result.json()['entries']: + for experiment in [d['id'] for d in b_result.json()['entries']]: + r_result = requests.get(sra_run_query.format(experiment=experiment), headers=dict(Accept="application/json")) + r_result.raise_for_status() + for run in [d['id'] for d in r_result.json()['entries']]: + print(run) + else: + print(f"No results found for '{bioproject}'.", file=sys.stderr) + quit(1) + except IndexError: + raise ValueError("Please provide an NCBI BioProject, NCBI BioSample, EMBL Project, or EMBL Study accession.") + except KeyError as e: + raise ValueError() from e + + + diff -r 000000000000 -r 02ac32a00e25 bio2srr.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bio2srr.xml Tue Dec 18 15:17:42 2018 -0500 @@ -0,0 +1,26 @@ + + Retrieve SRR accessions from BioProject or BioSample. + + requests + + "$output" + ]]> + + + + + + + + + + + + + + + + \ No newline at end of file diff -r 000000000000 -r 02ac32a00e25 test-data/test.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test-data/test.txt Tue Dec 18 15:17:42 2018 -0500 @@ -0,0 +1,15 @@ +ERR2130609 +ERR2130611 +ERR2130613 +ERR2130497 +ERR2130499 +ERR2130502 +ERR2130503 +ERR2130506 +ERR2130508 +ERR2130510 +ERR2130512 +ERR2130517 +ERR2130520 +ERR2130521 +ERR2130523 \ No newline at end of file