Skip to content

Commit

Permalink
update biolink model to version 4.2.1; added procedure to extract the…
Browse files Browse the repository at this point in the history
… leaf classes from a list of classes
  • Loading branch information
kaiwenho committed May 20, 2024
1 parent f1bc8d1 commit 1c1f5aa
Showing 1 changed file with 30 additions and 17 deletions.
47 changes: 30 additions & 17 deletions medikanren2/neo/neo-reasoning/neo-biolink-reasoning-low-level.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
;;
UMLS-biolink-class-mapper
UMLS-biolink-pred-mapper
;;
find-leaf-classes
get-smallest-nonmixin-class*
)
(require
racket/pretty
Expand All @@ -50,7 +53,8 @@
;; (define BIOLINK_YAML_FILE "../neo-biolink/biolink_3_0_3/biolink-model.yaml")
;; (define BIOLINK_YAML_FILE "../neo-biolink/biolink_3_1_1/biolink-model.yaml")
;;(define BIOLINK_YAML_FILE "../neo-biolink/biolink_3_1_2/biolink-model.yaml")
(define BIOLINK_YAML_FILE "../neo-biolink/biolink_3_5_2/biolink-model.yaml")
;;(define BIOLINK_YAML_FILE "../neo-biolink/biolink_3_5_2/biolink-model.yaml")
(define BIOLINK_YAML_FILE "../neo-biolink/biolink_4_2_1/biolink-model.yaml")

(define-runtime-path path.here ".")
(define bl-path (build-path path.here BIOLINK_YAML_FILE))
Expand Down Expand Up @@ -108,7 +112,6 @@
(lambda (pred)
(hash-ref predicate-deprecated-hash pred #f))))


(define class-deprecated?
(let ((class-deprecated-hash (make-hash)))
(for-each
Expand All @@ -121,7 +124,6 @@
(lambda (class)
(hash-ref class-deprecated-hash class #f))))


(define predicate-mixin?
(let ((predicate-mixin-hash (make-hash)))
(for-each
Expand All @@ -146,8 +148,7 @@
(lambda (pred)
(hash-ref predicate-abstract-hash pred #f))))


(define class-mixin?
(define class-mixin-hash
(let ((class-mixin-hash (make-hash)))
(for-each
(lambda (class-yaml-str)
Expand All @@ -156,8 +157,11 @@
(let ((class-biolink-name (yaml-class-name-to-biolink-name class-yaml-str)))
(hash-set! class-mixin-hash class-biolink-name #t)))))
classes)
class-mixin-hash))

(define class-mixin?
(lambda (class)
(hash-ref class-mixin-hash class #f))))
(hash-ref class-mixin-hash class #f)))

(define class-abstract?
(let ((class-abstract-hash (make-hash)))
Expand All @@ -171,8 +175,6 @@
(lambda (class)
(hash-ref class-abstract-hash class #f))))



(define predicate-symmetric?
(let ((predicate-symmetric-hash (make-hash)))
(for-each
Expand All @@ -185,8 +187,6 @@
(lambda (pred)
(hash-ref predicate-symmetric-hash pred #f))))



(define get-inverse-predicate
(let ((inverse-predicate-hash (make-hash)))
(for-each
Expand All @@ -201,8 +201,6 @@
(lambda (pred)
(hash-ref inverse-predicate-hash pred #f))))



(define get-predicate-children
(let ((predicate-children-hash (make-hash)))
(for-each
Expand All @@ -218,7 +216,6 @@
(lambda (pred)
(hash-ref predicate-children-hash pred (set)))))


(define get-predicate-descendents*
(lambda (preds)
(let loop ((preds preds)
Expand Down Expand Up @@ -266,8 +263,7 @@
(lambda (pred)
(hash-ref predicate-proper-descendents-hash pred (set)))))


(define get-class-children
(define class-children-hash
(let ((class-children-hash (make-hash)))
(for-each
(lambda (child-yaml-str)
Expand All @@ -279,8 +275,25 @@
(hash-set! class-children-hash parent-biolink-name
(set-union (set child-biolink-name) children-set)))))))
classes)
(lambda (class)
(hash-ref class-children-hash class (set)))))
class-children-hash))

(define get-class-children
(lambda (class)
(hash-ref class-children-hash class (set))))

(define (find-leaf-classes class*)
(let ((sub-hierarchy (make-hash)))
(for-each
(lambda (class)
(let* ((child* (set->list (hash-ref class-children-hash class (set))))
(child* (filter (lambda (c) (member c class*)) child*)))
(hash-set! sub-hierarchy class child*)))
class*)
(filter (lambda (class) (null? (hash-ref sub-hierarchy class)))
(hash-keys sub-hierarchy))))

(define (get-smallest-nonmixin-class* class*)
(find-leaf-classes (filter (lambda (c) (not (class-mixin? c))) class*)))

(define get-class-descendents*
(lambda (classes)
Expand Down

0 comments on commit 1c1f5aa

Please sign in to comment.