forked from webyrd/mediKanren
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-web-server.rkt
76 lines (68 loc) · 2.48 KB
/
test-web-server.rkt
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
#lang racket
(require net/http-client)
(define (read/string s) (with-input-from-string s (lambda () (read))))
(define (write/string datum) (with-output-to-string (lambda () (write datum))))
(define (pretty/string datum)
(with-output-to-string (lambda () (pretty-print datum))))
(define (query sdatum)
(define-values (bstatus headers in)
(http-sendrecv "localhost" "/query"
#:port 8000
#:ssl? #f
#:version "1.1"
#:method "POST"
#:data (write/string sdatum)))
(define status (bytes->string/utf-8 bstatus))
(define response (port->string in))
(close-input-port in)
(cond ((string-suffix? status "200 OK") (read/string response))
(else (printf "~a\n" response)
(error "Query failed:" status (map bytes->string/utf-8 headers)
response))))
(define (decreases? p)
(member (cddr p) '("negatively_regulates"
"prevents"
"treats"
"disrupts"
"increases_degradation_of"
"decreases_activity_of"
"decreases_expression_of")))
(define (increases? p)
(member (cddr p) '("positively_regulates"
"produces"
"causes"
"causes_condition"
"causally_related_to"
"contributes_to"
"gene_associated_with_condition"
"gene_mutations_contribute_to"
"decreases_degradation_of"
"increases_activity_of"
"increases_expression_of")))
(define SP (map (lambda (cp)
(define c (car cp))
(define pS (cadr cp))
(list c (filter decreases? pS) #f))
(take (query '(concept #t #f 0 #f ("imatin"))) 1)))
(define OP (map (lambda (cp)
(define c (car cp))
(define pO (caddr cp))
(list c #f (filter increases? pO)))
(take (query '(concept #f #t 0 #f ("asthma"))) 1)))
(displayln "Imatinib:")
(pretty-print SP)
(newline)
(displayln "Asthma:")
(pretty-print OP)
(define X (query `(X ,SP ,OP)))
(define x-bcr
(car (filter (lambda (x) (equal? (cadddr (car x)) "BCR gene")) X)))
(newline)
(displayln 'X:)
(pretty-print (car x-bcr))
(newline)
(displayln 'S-edges:)
(pretty-print (cadr x-bcr))
(newline)
(displayln 'O-edges:)
(pretty-print (caddr x-bcr))