generated from Sage-Bionetworks-Challenges/model-to-data-challenge-workflow
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconvert_score.cwl
80 lines (67 loc) · 2.4 KB
/
convert_score.cwl
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
79
80
#!/usr/bin/env cwl-runner
#
# Convert annotated notes to annotation store annotations
#
cwlVersion: v1.0
class: CommandLineTool
baseCommand: python
hints:
DockerRequirement:
dockerPull: python:3.7
inputs:
- id: score_json
type: File
- id: annotator_type
type: string
arguments:
- valueFrom: convert_score.py
- valueFrom: $(inputs.score_json)
prefix: -s
- valueFrom: results.json
prefix: -r
- valueFrom: $(inputs.annotator_type)
prefix: -a
requirements:
- class: InlineJavascriptRequirement
- class: InitialWorkDirRequirement
listing:
- entryname: convert_score.py
entry: |
#!/usr/bin/env python
import argparse
import json
import math
parser = argparse.ArgumentParser()
parser.add_argument("-s", "--score_json", required=True, help="Score json file")
parser.add_argument("-r", "--results", required=True, help="Results file")
parser.add_argument("-a", "--annotator_type", required=True, help="Annotator type")
args = parser.parse_args()
with open(args.score_json, "r") as score_f:
scores = json.load(score_f)
api_url_map = {
'nlpsandbox:date-annotator': "date",
'nlpsandbox:person-name-annotator': "person",
'nlpsandbox:location-annotator': "location",
'nlpsandbox:id-annotator': "id",
'nlpsandbox:contact-annotator': "contact",
'nlpsandbox:covid-symptom-annotator': "covid"
}
annotator_type = api_url_map[args.annotator_type]
key = f"{annotator_type}_location"
new_scores_dict = {"location_{metric}_{type}_{mode}".format(
metric=location['metric'],
type=location['type'], mode=location['mode']
): location['value']
for location in scores[key]}
key = f"{annotator_type}_type"
for types in scores[key]:
if not math.isnan(types['value']):
new_scores_dict[f"type_{types['metric']}"] = types['value']
new_scores_dict['submission_status'] = 'SCORED'
with open(args.results, "w") as results_f:
json.dump(new_scores_dict, results_f)
outputs:
- id: results
type: File
outputBinding:
glob: results.json