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) => {
console.log(`Status: ${res.status}`);
let reader = res.body.getReader();
// while (!reader.closed) {
reader.read().then(out => {
// console.log(out)
var decoder = new TextDecoder('utf8');
console.log(decoder.decode(out.value));
res.blob().then(val => {
val.text().then(val => {
let xmlParser = (new DOMParser()).parseFromString(val, "text/xml");
let els = xmlParser.getElementsByTagName("Id");
let ids = [];
for (let i = 0; i < els.length; i++) {
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": {
"build": "shadow-cljs compile app",
"dev": "shadow-cljs watch app",
"test": "shadow-cljs compile tests",
"repl": "shadow-cljs node-repl"
},

View File

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

View File

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

View File

@ -1,16 +1,33 @@
(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.format]))
[goog.string.format]
[goog.dom.xml :refer [loadXml]]))
(defn ncbi-search
"Send search query to NCBI database.
(def base-url "https://eutils.ncbi.nlm.nih.gov/entrez/eutils")
(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_)
Example Query: `science[journal]+AND+breast+cancer+AND+2008[pdat]`"
[query]
(let [res (->> query
(gstring/format "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term=%s")
js/fetch
take!)]
(js/console.log res)))
[db-id query]
(go (let [res (<! (http/get (gstring/format
"%s/esearch.fcgi?db=%s&term=%s"
base-url db-id query)))
xml-doc (loadXml 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
(:require [cljs.test :refer [deftest is async?]]
[clojure.core.async :refer [<! go]]
(:require [cljs.pprint :refer [pprint]]
[cljs.test :refer [deftest]]
[cljs.core.async :refer [<! go]]
[reagent-test.ncbi :refer [ncbi-search]]))
(deftest a-test
(dorun
(go
(let [res (<! (ncbi-search "science[journal]+AND+breast+cancer+AND+2008[pdat]"))]
(js/console.log res)))))
;; (deftest test-ncbi-search-pubmed
;; (go (let [res (<! (ncbi-search "pubmed" "science[journal]+AND+breast+cancer+AND+2008[pdat]"))
;; status (:status res)
;; buf (:buf 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")))