Spaces:
Sleeping
Sleeping
File size: 2,527 Bytes
50e583f |
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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
__author__ = "qiao"
"""
Rank the trials given the matching and aggregation results
"""
import json
import sys
eps = 1e-9
def get_matching_score(matching):
# count only the valid ones
included = 0
not_inc = 0
na_inc = 0
no_info_inc = 0
excluded = 0
not_exc = 0
na_exc = 0
no_info_exc = 0
# first count inclusions
for criteria, info in matching["inclusion"].items():
if len(info) != 3:
continue
if info[2] == "included":
included += 1
elif info[2] == "not included":
not_inc += 1
elif info[2] == "not applicable":
na_inc += 1
elif info[2] == "not enough information":
no_info_inc += 1
# then count exclusions
for criteria, info in matching["exclusion"].items():
if len(info) != 3:
continue
if info[2] == "excluded":
excluded += 1
elif info[2] == "not excluded":
not_exc += 1
elif info[2] == "not applicable":
na_exc += 1
elif info[2] == "not enough information":
no_info_exc += 1
# get the matching score
score = 0
score += included / (included + not_inc + no_info_inc + eps)
if not_inc > 0:
score -= 1
if excluded > 0:
score -= 1
return score
def get_agg_score(assessment):
try:
rel_score = float(assessment["relevance_score_R"])
eli_score = float(assessment["eligibility_score_E"])
except:
rel_score = 0
eli_score = 0
score = (rel_score + eli_score) / 100
return score
if __name__ == "__main__":
# args are the results paths
matching_results_path = sys.argv[1]
agg_results_path = sys.argv[2]
# loading the results
matching_results = json.load(open(matching_results_path))
agg_results = json.load(open(agg_results_path))
# loop over the patients
for patient_id, label2trial2results in matching_results.items():
trial2score = {}
for _, trial2results in label2trial2results.items():
for trial_id, results in trial2results.items():
matching_score = get_matching_score(results)
if patient_id not in agg_results or trial_id not in agg_results[patient_id]:
print(f"Patient {patient_id} Trial {trial_id} not in the aggregation results.")
agg_score = 0
else:
agg_score = get_agg_score(agg_results[patient_id][trial_id])
trial_score = matching_score + agg_score
trial2score[trial_id] = trial_score
sorted_trial2score = sorted(trial2score.items(), key=lambda x: -x[1])
print()
print(f"Patient ID: {patient_id}")
print("Clinical trial ranking:")
for trial, score in sorted_trial2score:
print(trial, score)
print("===")
print()
|