-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsra_status.py
76 lines (64 loc) · 2.08 KB
/
sra_status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
"""
Report the status of an SRA run
"""
import os
import sys
import argparse
import requests
import json
def get_status(runids, verbose, url='https://www.ncbi.nlm.nih.gov/Traces/sra/status/srastatrep.fcgi/acc-mirroring?acc='):
"""
Get the status of the run
:param runid: the set of run ids to get
:param verbose: more output
:param url: the base url to append the status to
:return:
"""
req = url + ",".join(runids)
if args.v:
sys.stderr.write("Getting {}\n".format(req))
r = requests.get(req)
if args.v:
sys.stderr.write("Status: {}\n".format(r.status_code))
d = json.loads(r.text)
return d
def print_full(runids, data, verbose):
"""
Print the full output
:param runids: the set of run ids to check
:param data: the json object
:param verbose: more output
:return:
"""
for r in data['rows']:
if r[0] not in runids:
sys.stderr.write("Expected an accession of {} but found {}\n".format(runid))
for i, j in zip(data['column_names'], r):
print("{}\t{}".format(i, j))
def print_status(runids, data, verbose):
"""
Print the status of the run
:param runids: the set of run ids to check
:param data:
:param verbose:
:return:
"""
s = data['column_names'].index('Status')
for r in data['rows']:
if r[0] not in runids:
sys.stderr.write("Expected an accession of {} but found {}\n".format(runid))
print("{}\t{}".format(r[0], r[s]))
if __name__ == '__main__':
parser = argparse.ArgumentParser(description="Return the status of an SRA run")
parser.add_argument('-r', help='SRA Run ID', required=True, action='append')
parser.add_argument('-f', help="full output", action='store_true')
parser.add_argument('-v', help='verbose output', action="store_true")
args = parser.parse_args()
allruns = set()
for r in args.r:
allruns.update(r.split(','))
data = get_status(allruns, args.v)
if args.f:
print_full(allruns, data, args.v)
else:
print_status(allruns, data, args.v)