comparison bio2srr.py @ 0:02ac32a00e25

planemo upload commit 4aa8338dc8bcd7f6c0fb675044ea9d0c045ee7f3
author jpayne
date Tue, 18 Dec 2018 15:17:42 -0500
parents
children 556cac4fb538
comparison
equal deleted inserted replaced
-1:000000000000 0:02ac32a00e25
1 #! /usr/bin/env python3
2
3 "Grab SRR numbers from BioProjects via the EMBL-ENA REST API's."
4
5 import requests
6 import sys
7
8 sra_exp_query = "http://www.ebi.ac.uk/ebisearch/ws/rest/sra-experiment?query={bioproject}"
9
10 sample = """{
11 "hitCount": 2,
12 "entries": [
13 {
14 "id": "SRX377510",
15 "source": "sra-experiment"
16 },
17 {
18 "id": "SRX583279",
19 "source": "sra-experiment"
20 }
21 ],
22 "facets": []
23 }"""
24
25 sra_run_query = "http://www.ebi.ac.uk/ebisearch/ws/rest/sra-run?query={experiment}"
26
27 sample = """{
28 "hitCount": 1,
29 "entries": [
30 {
31 "id": "SRR1029665",
32 "source": "sra-run"
33 }
34 ],
35 "facets": []
36 }"""
37
38 if __name__ == "__main__":
39 try:
40 bioproject = sys.argv[1]
41 b_result = requests.get(sra_exp_query.format(bioproject=bioproject), headers=dict(Accept="application/json"))
42 b_result.raise_for_status()
43 if b_result.json()['entries']:
44 for experiment in [d['id'] for d in b_result.json()['entries']]:
45 r_result = requests.get(sra_run_query.format(experiment=experiment), headers=dict(Accept="application/json"))
46 r_result.raise_for_status()
47 for run in [d['id'] for d in r_result.json()['entries']]:
48 print(run)
49 else:
50 print(f"No results found for '{bioproject}'.", file=sys.stderr)
51 quit(1)
52 except IndexError:
53 raise ValueError("Please provide an NCBI BioProject, NCBI BioSample, EMBL Project, or EMBL Study accession.")
54 except KeyError as e:
55 raise ValueError() from e
56
57
58