Skip to content

Instantly share code, notes, and snippets.

@usametov
Created June 4, 2023 17:27
Show Gist options
  • Save usametov/c8b33635ce4c96102ea907633e24f7b4 to your computer and use it in GitHub Desktop.
Save usametov/c8b33635ce4c96102ea907633e24f7b4 to your computer and use it in GitHub Desktop.
babashka bio2rdf client
#!/usr/bin/env bb
(require '[babashka.curl :as curl])
(require '[clojure.string :as s])
(require '[cheshire.core :as json])
(defn query-variant-drug-links
[rsid]
(->
(curl/get
"http://localhost:9000/sparql"
{:headers {"Accept" "application/json"}
:query-params {"query",
(str "select ?s1 as ?c1, ?o where
{
?s1 a <http://bio2rdf.org/pharmgkb_vocabulary:variantlocation-drug-Association> .
?s1 rdfs:label ?o .
FILTER CONTAINS(?o, '" rsid "') } group by ( ?s1 ) order by desc ( <LONG::IRI_RANK> ( ?s1 ) ) limit 200 offset 0")}})
:body
(json/parse-string true)
:results :bindings))
(defn run-queries
[args]
(mapcat query-variant-drug-links args))
(comment
(def rsids ["rs10513789" "rs1625579" "rs2195987" "rs6550435" "rs7914558" "rs9607782"
"rs10994415" "rs17183814" "rs2735940" "rs6599388" "rs8005092" "rs9834970" "rs11191580"
"rs17662626" "rs3752246" "rs6733839" "rs8068318" "rs12129573" "rs17826816" "rs4698412"
"rs6825004" "rs9271058" "rs12552" "rs1800469" "rs4702" "rs73223431" "rs9473117" "rs1432639"
"rs2021722" "rs533123" "rs755383" "rs9515201"])
(def variant-drugs (run-queries rsids))
(query-variant-drug-links "rs10513789")
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment