virgil/commit
ADD PRR and CHI-squared apis
author | Michiel Hildebrand |
---|---|
Tue Jul 16 00:17:28 2013 +0200 | |
committer | Michiel Hildebrand |
Tue Jul 16 00:17:28 2013 +0200 | |
commit | af94181e702242940bfcb155e5d286afc51b6831 |
tree | 1cc86adead057364a86735f899a89659158f7a58 |
parent | 6badbab93887d1230e3e76c11397a8633c1d3890 |
Diff style: patch stat
diff --git a/api/reports.pl b/api/reports.pl index cef3e61..505677e 100644 --- a/api/reports.pl +++ b/api/reports.pl @@ -14,6 +14,8 @@ :- http_handler(cliopatria(aers/api/reports), http_reports, []). :- http_handler(cliopatria(aers/api/cc), http_cc, []). :- http_handler(cliopatria(aers/api/table), http_contingency_table, []). +:- http_handler(cliopatria(aers/api/prr), http_prr, []). +:- http_handler(cliopatria(aers/api/chi), http_chi, []). %% http_reports(+Request) @@ -155,6 +157,81 @@ http_contingency_table(Request) :- -> DrugMatch = [word,brand,synonym,corrected] ; DrugMatch = DrugMatch0 ), + contingency_table(Drug, DrugMatch, Reaction, + A,B,C,D,AB,AC,BD,CD,ABCD), + reply_json(json([a=A, + b=B, + c=C, + d=D, + 'a+b'=AB, + 'a+c'=AC, + 'b+d'=BD, + 'c+d'=CD, + 'a+b+c+d'=ABCD + ])). + +http_prr(Request) :- + http_parameters(Request, + [drug(Drug, + [atom + ]), + reaction(Reaction, + [atom + ]), + drugMatch(DrugMatch0, + [list(atom) + ]) + ]), + ( DrugMatch0 = [] + -> DrugMatch = [word,brand,synonym,corrected] + ; DrugMatch = DrugMatch0 + ), + contingency_table(Drug, DrugMatch, Reaction, + A,_,C,_,AB,_,_,_,ABCD), + PRR is (A/C)/(AB/ABCD), + reply_json(json([prr=PRR, + formula='(a/c)/((a+b)/(a+b+c+d))', + a=A, + c=C, + 'a+b'=AB, + 'a+b+c+d'=ABCD + ])). + +http_chi(Request) :- + http_parameters(Request, + [drug(Drug, + [atom + ]), + reaction(Reaction, + [atom + ]), + drugMatch(DrugMatch0, + [list(atom) + ]) + ]), + ( DrugMatch0 = [] + -> DrugMatch = [word,brand,synonym,corrected] + ; DrugMatch = DrugMatch0 + ), + contingency_table(Drug, DrugMatch, Reaction, + A,B,C,D,AB,AC,BD,CD,ABCD), + Chi is (A/C)/(AB/ABCD), + reply_json(json([chi=Chi, + formula='(ad-bc)^2(a+b+c+d)/((a+b)*(c+d)*(b+d)*(a+c))', + a=A, + b=B, + c=C, + d=D, + 'a+b'=AB, + 'a+c'=AC, + 'b+d'=BD, + 'c+d'=CD, + 'a+b+c+d'=ABCD + ])). + + +contingency_table(Drug, DrugMatch, Reaction, + A,B,C,D,AB,AC,BD,CD,ABCD) :- drug_match(Drug, DrugMatch, DrugMentions), drug_reaction_cc(DrugMentions, Reaction, CC_A), drug_reaction_cc(DrugMentions, all, CC_AC), @@ -167,14 +244,5 @@ http_contingency_table(Request) :- C is AC-A, CD is ABCD-AB, BD is ABCD-AC, - D is BD-B, - reply_json(json([a=A, - b=B, - c=C, - d=D, - ab=AB, - ac=AC, - bd=BD, - cd=CD, - abcd=ABCD - ])). + D is BD-B. + diff --git a/config-available/virgil.pl b/config-available/virgil.pl index 0d94073..26f8ecc 100644 --- a/config-available/virgil.pl +++ b/config-available/virgil.pl @@ -16,7 +16,7 @@ :- load_files([ api(drugs), api(reactions), api(reports), - api(measurements), + %api(measurements), library(drug_spell_check), library(aers_report), applications(virgil)