-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (59 loc) · 2.71 KB
/
main.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
77
78
#!/usr/bin/env python
import argparse
import numpy as np
from src.utils import *
def parsing():
# Initiating parser
parser = argparse.ArgumentParser(description=
"A tool to fetch the association score data from the Open Targets REST API for a given disease id or target.")
# Main optional arguments inside a mutually exclusive group
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument("-t", dest="target", type=str, help="The ID of the target for which you want to do the analysis.")
group.add_argument("-d", dest="disease", type=str, help="The ID of the disease for which you want to do the analysis.")
# Optional arguments
parser.add_argument("-e", dest="export", type=str, help="JSON filename from the exported query result.")
parser.add_argument("-m", dest="minimum", type=float, help="Minimum score value to filter associations with lower quality data points.")
args = parser.parse_args()
return args
def main():
'''
Prints to stdout the result of the query and returns relevant association score values.
Returns:
mean: Average of every overall association score values.
maximum: Highest overall association score value.
minimum: Lowest overall association score value.
standard deviation: Standar deviation of every overall association score values.
'''
args = parsing()
# "type" defines the query parameter to differentiate between disease and target ID
if args.disease:
type = "disease"
data = query(type, args.disease, scorevalue_min=args.minimum)
elif args.target:
type = "target"
data = query(type, args.target, scorevalue_min=args.minimum)
assert len(data), "A problem ocurred with the query. Please check that the ID provided is correct."
# stdout prints for every association
for record in data.values():
print(record)
# overall metrics
scores = [record["association_score.overall"] for record in data.values()]
mean = np.mean(scores)
highest = np.max(scores)
lowest = np.min(scores)
stdev = np.std(scores)
print("-------------------------------------")
print(f"{len(scores)} associations have been found for this {type} ID.\n")
print(f"""Association score values:
Average score: {mean}
Maximum score: {highest}
Minimum score: {lowest}
Standard Deviation: {stdev}""")
print("-------------------------------------")
if args.export:
export(data, args.export)
return mean, highest, lowest, stdev
if __name__ == "__main__":
print("-----------------------------------------------")
print("Welcome! Here's how to fetch associations from the Open Targets Platform.")
main()