master
michael 2023-02-04 17:17:48 -08:00
parent bfbf2ff239
commit ea2aea1fc8
6 changed files with 97 additions and 44 deletions

View File

@ -1,18 +1,45 @@
searchQuery = "science[journal]+AND+breast+cancer+AND+2008[pdat]"; let searchQuery = "science[journal]+AND+breast+cancer+AND+2008[pdat]";
let url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils"
function testSearch(query) {
fetch(`https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=${query}`) function testSearchPubmed(query) {
fetch(`${url}/esearch.fcgi?db=pubmed&term=${query}`)
.then((res) => { .then((res) => {
console.log(`Status: ${res.status}`); res.blob().then(val => {
let reader = res.body.getReader(); val.text().then(val => {
// while (!reader.closed) { let xmlParser = (new DOMParser()).parseFromString(val, "text/xml");
reader.read().then(out => { let els = xmlParser.getElementsByTagName("Id");
// console.log(out) let ids = [];
var decoder = new TextDecoder('utf8'); for (let i = 0; i < els.length; i++) {
console.log(decoder.decode(out.value)); ids.push(els[i].innerHTML);
}
console.log(ids);
return ids;
})
})
});
}
function testSearchGene(query) {
fetch(`${url}/esearch.fcgi?db=gene&term=${query}`)
.then((res) => {
res.blob().then(val => {
val.text().then(val => {
console.log(val);
})
})
});
}
function testLookupGeneById(ids) {
fetch(`${url}/esummary.fcgi?db=gene&id=${String(ids)}`)
.then(res => {
res.blob().then(val => {
val.text().then(val => {
console.log(val)
})
}) })
// }
}) })
} }
testSearch(searchQuery); testLookupGeneById(7157);

View File

@ -1,5 +1,7 @@
{ {
"scripts": { "scripts": {
"build": "shadow-cljs compile app",
"dev": "shadow-cljs watch app",
"test": "shadow-cljs compile tests", "test": "shadow-cljs compile tests",
"repl": "shadow-cljs node-repl" "repl": "shadow-cljs node-repl"
}, },

View File

@ -1,7 +1,9 @@
{:source-paths ["src"] {:source-paths ["src"]
:dependencies [[binaryage/devtools "1.0.6"] :dependencies [[binaryage/devtools "1.0.6"]
[nrepl "1.0.0"] [nrepl "1.0.0"]
[reagent "1.1.1"]] [reagent "1.1.1"]
[cljs-http "0.1.46"]]
:builds {:app {:target :browser :builds {:app {:target :browser
:output-dir "public/js" :output-dir "public/js"
:asset-path "/js" :asset-path "/js"
@ -13,6 +15,7 @@
:output-dir "tests-out/output" :output-dir "tests-out/output"
:modules {:app {:entries [reagent-test.core-test :modules {:app {:entries [reagent-test.core-test
reagent-test.ncbi-test]}} reagent-test.ncbi-test]}}
:autorun true}} :autorun true
:devtools {:ignore-warnings true}}}
:dev-http {3000 {:root "public"}}} :dev-http {3000 {:root "public"}}}

View File

@ -1,21 +1,14 @@
(ns reagent-test.core (ns reagent-test.core
(:require (:require [cljs.core.async :refer [<! go]]
[reagent.core :as r] [reagent-test.ncbi :refer [ncbi-search]]
[reagent.dom :as d] [reagent.dom :as d]))
[reagent-test.ncbi :refer [ncbi-search]]))
;; ------------------------- ;; -------------------------
;; Component data (custom) ;; Component data (custom)
(def action-btns [{:text "file" (def action-btns [{:text "tools" :action #(js/console.log "hi")}
:items [{:text "new" :action #(dorun (js/console.log "test") {:text "search" :action #((go (let [res (<! (ncbi-search "pubmed" "science[journal]+AND+breast+cancer+AND+2008[pdat]"))]
(js/console.log "hi"))} (js/console.log res))))}
{:text "new" :action #(js/alert "hi")}
{:text "quit" :action #()}]}
{:text "edit"
:items [{:text "hi" :action #(js/console.log "test2")}
{:text "bye" :action #(js/console.log "bye")}]}
{:text "view" :action #(js/console.log "test3")}
{:text "help" :action #(js/console.log "test4")}]) {:text "help" :action #(js/console.log "test4")}])
;; ------------------------- ;; -------------------------

View File

@ -1,16 +1,33 @@
(ns reagent-test.ncbi (ns reagent-test.ncbi
(:require [clojure.core.async :refer [take!]] (:require [cljs.core.async :refer [<! go]]
[cljs-http.client :as http]
[goog.string :as gstring] [goog.string :as gstring]
[goog.string.format])) [goog.string.format]
[goog.dom.xml :refer [loadXml]]))
(defn ncbi-search (def base-url "https://eutils.ncbi.nlm.nih.gov/entrez/eutils")
"Send search query to NCBI database.
(defn ncbi-db-search
"Send search query to NCBI database, and get back a list of ID strings.
[More info](https://www.ncbi.nlm.nih.gov/books/NBK25500/#_chapter1_Searching_a_Database_) [More info](https://www.ncbi.nlm.nih.gov/books/NBK25500/#_chapter1_Searching_a_Database_)
Example Query: `science[journal]+AND+breast+cancer+AND+2008[pdat]`" Example Query: `science[journal]+AND+breast+cancer+AND+2008[pdat]`"
[query] [db-id query]
(let [res (->> query (go (let [res (<! (http/get (gstring/format
(gstring/format "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=%s") "%s/esearch.fcgi?db=%s&term=%s"
js/fetch base-url db-id query)))
take!)] xml-doc (loadXml res)]
(js/console.log res))) (. xml-doc getElementByTagName "Id"))))
(defn ncbi-db-get-summary
"Get summary by ID.
[More info](https://www.ncbi.nlm.nih.gov/books/NBK25500/#_chapter1_Downloading_Document_Summaries_)"
[db-id id]
(go (let [res (<! (http/get (gstring/format
"%s/esummary.fcgi?db=%s&id=%s"
base-url db-id id)))
xml-doc (loadXml res)]
(js/console.log "hi"))))
(defn ncbi-search-gene [query] (ncbi-db-search "gene" query))
(defn ncbi-id-gene [query] (ncbi-db-search "gene" query))

View File

@ -1,10 +1,21 @@
(ns reagent-test.ncbi-test (ns reagent-test.ncbi-test
(:require [cljs.test :refer [deftest is async?]] (:require [cljs.pprint :refer [pprint]]
[clojure.core.async :refer [<! go]] [cljs.test :refer [deftest]]
[cljs.core.async :refer [<! go]]
[reagent-test.ncbi :refer [ncbi-search]])) [reagent-test.ncbi :refer [ncbi-search]]))
(deftest a-test ;; (deftest test-ncbi-search-pubmed
(dorun ;; (go (let [res (<! (ncbi-search "pubmed" "science[journal]+AND+breast+cancer+AND+2008[pdat]"))
(go ;; status (:status res)
(let [res (<! (ncbi-search "science[journal]+AND+breast+cancer+AND+2008[pdat]"))] ;; buf (:buf res)]
(js/console.log res))))) ;; (assert (not (nil? res)))
;; (assert (not (nil? buf)))
;; (assert (= status 200))
;; (pprint res)
;; (pprint "hi"))))
(deftest test-ncbi-search-pubmed
(let [res (ncbi-search "pubmed" "science[journal]+AND+breast+cancer+AND+2008[pdat]")]
(assert (not (nil? res)))
(pprint res)
(pprint "hi")))