(require 'asdf) (setq *load-verbose* t) (setq *compile-verbose* t) (push (truename "./jss") asdf::*central-registry*) (push (truename "./owl") asdf::*central-registry*) (push (truename "./bug") asdf::*central-registry*) (push (truename "./patches") asdf::*central-registry*) (push (truename "./server") asdf::*central-registry*) (defparameter *pellet-dir* (namestring (truename "./extlib"))) (eval-when (:compile-toplevel :load-toplevel :execute) (asdf::oos 'asdf::load-op 'jss) (asdf::oos 'asdf::load-op 'owl) (asdf::oos 'asdf::load-op 'bug) ; (asdf::oos 'asdf::load-op 'patches) ) (dolist (m '("(setq *default-kb* (owl-load-combined)); generate and load ijr904+ecocyc compounds owl" "(generate-sames-by-name) ; based on this, generate sameIndividual statements for same named compounds not otherwise mapped" "(setq *default-kb* (owl-load-combined :recreate t)); reload including this mapping" "(describe-entity \"bug:casEntry\"); describe a class" "(length (collect-sames)) ; how many compounds have been mapped from one to the other database" "(do-some-queries) ; show some sparql queries and results" "(load \"biopax/proto/pathways-with-compounds.lisp\") show how to query pathways that a compound participates in")) (princ m) (terpri)) (defun load-combined () (setq *default-kb* (load-kb-jena (concatenate 'string "file://" (namestring (truename "bug:combined.owl")))))) (defun do-some-queries () (let ((*print-case* :downcase)) (loop for (desc query use-reasoner) in *sample-queries* do (format t "~&~a~%---- Query (lisp) ----" desc) (pprint `(sparql ',(eval-uri-reader-macro query) :use-reasoner ,use-reasoner)) (format t "~&~%---- Query (sparql) ----~%") (princ (sparql-stringify query)) (format t "~%~a~%" "---- Result ----") (pprint (sparql query :use-reasoner use-reasoner)) (format t "~%~a~%" "================================================================") ))) (defparameter *sample-queries* '(("What small molecules are associated with KEGG id C00645?" (:select (?mol) () (?mol !bug:classifiedByKEGG ?kegg) (?kegg !bug:hasID "C00645")) t) ("What small molecules have the chemical formula c6h15o9p, and what are their names, cas, kegg ids?" (:select (?name ?cas ?kegg ) (:distinct t) (?formula !bug:hasFormula "c6h15o9p") (?mol !bug:hasChemicalFormula ?formula) (?mol !bug:hasName ?name) (:optional (?mol !bug:definedByCAS ?casf) (?casf !bug:hasID ?cas)) (:optional (?mol !bug:classifiedByKEGG ?keggf) (?keggf !bug:hasID ?kegg)) ) t ) ("Which pairs (only show 10) of molecules have the same name? don't use reasoner here - it has a bug" (:select (?mol1 ?mol2 ?name) (:limit 10) (?mol1 !bug:hasName ?name) (?mol2 !bug:hasName ?name) (:filter (not (equal ?mol1 ?mol2)))) nil) ("What molecules have 3 letter names(only show 10)?" (:select (?mol ?name) (:limit 10) (?mol !bug:hasName ?name) (:filter (regex ?name "^...$"))) t ) ("What molecules have 3 letter names (but only show 1 if something else is sameAs? Exercise: Why does ADP show up twice? Hint: Used the function (describe-entity uri)." (:select (?mol ?name) () (?mol !bug:hasName ?name) (:filter (and (is-canonical ?mol) (regex ?name "^...$")))) t) ("Which pairs of small molecules are considered to be the same?" (:select (?mol1 ?mol2) () (?mol1 !rdf:type !bug:smallMolecule) (?mol2 !owl:sameAs ?mol1) (:filter (and (is-canonical ?mol1) (not (equal ?mol1 ?mol2))))) :jena) ))