Skip to content

Commit e055ac3

Browse files
authored
Make direct HTTP requests using clj-http instead of using blend4j (#2)
* Replace blend4j calls with direct API calls with http-kit * Use clj-http instead of http-kit * Update * Changed namespace to org.galaxyproject.clj-blend * Changed namespace to org.galaxyproject.clj-blend * Fix namespaces * Organizing namespaces * Add more users methods * Reorganize histories * update users * Update user namespace * Work on downloading history contents * Added simple test for users namespace * Remove core ns test and append /api/ to GALAXY_URL when constructing client * Remove unused reloaded.repl functions * Remove references to blend4j from README
1 parent 57c3162 commit e055ac3

File tree

16 files changed

+365
-181
lines changed

16 files changed

+365
-181
lines changed

README.md

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
11
# clj-blend
22

3-
Clojure library for interacting with Galaxy, CloudMan, and BioCloudCentral. This
4-
builds on [blend4j][0] with lots of help from [blend][1]. Provides high level
5-
functionality on top of blend4j, with a focus on smooth interaction with Galaxy.
6-
7-
[0]: https://github.com/jmchilton/blend4j
8-
[1]: https://github.com/afgane/blend
3+
Clojure library for interacting with the Galaxy bioinformatics workflow platform.
94

105
## Usage
116

12-
Requires Java 1.6 or better and [Leiningen 2.x][u1].
7+
Requires Java 8 or better and [Leiningen 2.x][u1].
138

149
$ lein repl
15-
> (require '[blend.galaxy.core :as galaxy])
10+
> (require '[org.galaxyproject.clj-blend.galaxy.core :as galaxy])
1611
> (def c (galaxy/get-client "https://main.g2.bx.psu.edu/" "your-api-key"))
17-
> (def ds (galaxy/get-datasets-by-type c :bed))
18-
> (galaxy/download-dataset c (first ds) "/where/to/put/your/file.bed")
19-
> (galaxy/upload-to-history c "http://www.yoursite.com/data" :hg19 :vcf)
20-
12+
> (def user (galaxy/get-user-info c))
2113

2214
[u1]: https://github.com/technomancy/leiningen
2315

project.clj

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
(defproject clj-blend "0.1.1-SNAPSHOT"
2-
:description "Clojure library for interacting with Galaxy, CloudMan, and BioCloudCentral, built on blend4j"
1+
(defproject clj-blend "0.2.0-SNAPSHOT"
2+
:description "Clojure library for interacting with the Galaxy Bioinformatics Workflow Platform"
33
:url "http://github.com/chapmanb/clj-blend"
44
:license {:name "MIT"
55
:url "http://www.opensource.org/licenses/mit-license.html"}
6-
:dependencies [[org.clojure/clojure "1.4.0"]
7-
[fs "1.3.2"]
8-
[com.github.jmchilton.blend4j/blend4j "0.1-alpha-1"]])
6+
:dependencies [[org.clojure/clojure "1.10.0"]
7+
[clj-http "3.9.1"]
8+
[org.clojure/data.json "0.2.6"]
9+
[org.clojure/data.codec "0.1.1"]
10+
[fs "1.3.2"]]
11+
:profiles {:dev {:dependencies [[reloaded.repl "0.2.4"]]}})

src/blend/galaxy/core.clj

-23
This file was deleted.

src/blend/galaxy/histories.clj

-82
This file was deleted.

src/blend/galaxy/tools.clj

-30
This file was deleted.

src/blend/galaxy/users.clj

-13
This file was deleted.
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(ns org.galaxyproject.clj-blend.auth
2+
"Galaxy Authentication."
3+
(:require [clj-http.client :as client]
4+
[clojure.data.json :as json]
5+
[org.galaxyproject.clj-blend.util :as util]))
6+
7+
(defn authenticate
8+
[server user]
9+
(let [b64 (util/b64-encode-str (str (:email user) ":" (:password user)))]
10+
(json/read-str
11+
(:body (client/get (str (:api-root server) "authenticate/baseauth")
12+
{:headers {"Authorization" (str "Basic " b64)}}))
13+
:key-fn util/key-fn)))
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
(ns org.galaxyproject.clj-blend.core
2+
"Top level Galaxy interaction"
3+
(:require [clj-http.client :as client]
4+
[org.galaxyproject.clj-blend.users :as users]
5+
[org.galaxyproject.clj-blend.histories :as histories]
6+
[org.galaxyproject.clj-blend.tools :as tools]))
7+
8+
9+
(defn authenticate
10+
[server user]
11+
(client/get (str (:api-root server) "authenticate/baseauth")
12+
:headers {"Authorization" (str "Basic " )}))
13+
14+
15+
(defn get-client
16+
[galaxy-url api-key]
17+
{:url (str galaxy-url "/api/") :api-key api-key})
18+
19+
(def get-user-info users/get-current-user)
20+
21+
(defn list-histories
22+
[client]
23+
[(histories/get-history-most-recently-used client)])
24+
25+
(def get-history-contents-by-type histories/get-history-contents-by-type)
26+
(def get-history-contents-by-id histories/get-history-contents-by-id)
27+
28+
(def download-history-contents histories/download-history-contents)
29+
(def upload-to-history tools/upload-to-history)
30+
31+
(comment
32+
(def client (get-client "http://localhost:8080" "admin"))
33+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
(ns org.galaxyproject.clj-blend.histories
2+
"Retrieve Galaxy history information."
3+
(:use [clojure.java.io])
4+
(:require [clojure.string :as string]
5+
[clj-http.client :as client]
6+
[clojure.data.json :as json]
7+
[org.galaxyproject.clj-blend.util :as util]
8+
[fs.core :as fs]))
9+
10+
(defn get-histories
11+
[client]
12+
(json/read-str
13+
(:body (client/get (str (client :url) "histories")
14+
{:headers {"x-api-key" (client :api-key)}}))
15+
:key-fn util/key-fn))
16+
17+
(defn get-history-most-recently-used
18+
[client]
19+
(json/read-str
20+
(:body (client/get (str (client :url) "histories/most_recently_used")
21+
{:headers {"x-api-key" (client :api-key)}}))
22+
:key-fn util/key-fn))
23+
24+
(defn get-history-by-id
25+
[client history-id]
26+
(json/read-str
27+
(:body (client/get (str (client :url) "histories/" history-id)
28+
{:headers {"x-api-key" (client :api-key)}}))
29+
:key-fn util/key-fn))
30+
31+
(defn create-history
32+
[client history]
33+
(json/read-str
34+
(:body (client/post (str (client :url) "histories")
35+
{:headers {"x-api-key" (client :api-key)}
36+
:content-type :json
37+
:body (json/write-str history)}))
38+
:key-fn util/key-fn))
39+
40+
(defn delete-history
41+
[client history-id]
42+
(json/read-str
43+
(:body (client/delete (str (client :url) "histories/" history-id)
44+
{:headers {"x-api-key" (client :api-key)}}))
45+
:key-fn util/key-fn))
46+
47+
(defn get-history-contents
48+
"Retrieve history datasets, flattened into Clojure maps."
49+
[client history-id]
50+
(json/read-str
51+
(:body (client/get (str (client :url) "histories/" history-id "/contents")
52+
{:headers {"x-api-key" (client :api-key)}}))
53+
:key-fn util/key-fn))
54+
55+
(defn get-history-contents-by-id
56+
"Retrieve a history dataset converted into a clojure map."
57+
[client history-id content-id]
58+
(json/read-str
59+
(:body (client/get (str (client :url) "histories/" history-id "/contents/" content-id)
60+
{:headers {"x-api-key" (client :api-key)}}))
61+
:key-fn util/key-fn))
62+
63+
(defn get-history-status
64+
[client history-id]
65+
(select-keys (get-history-by-id client history-id) [:state :state-details]))
66+
67+
(defn- is-ftype?
68+
"Check if a dataset is the given filetype, cleanly handling keywords"
69+
[ftype dataset]
70+
(= (keyword ftype)
71+
(keyword (:data-type dataset))))
72+
73+
(defn get-history-contents
74+
[client history-id]
75+
(json/read-str
76+
(:body (client/get (str (client :url) "histories/" history-id "/contents")
77+
{:headers {"x-api-key" (client :api-key)}}))
78+
:key-fn util/key-fn))
79+
80+
(defn get-history-contents-by-id
81+
[client history-id content-id]
82+
(json/read-str
83+
(:body (client/get (str (client :url) "histories/" history-id "/contents/" content-id)
84+
{:headers {"x-api-key" (client :api-key)}}))
85+
:key-fn util/key-fn))
86+
87+
(defn get-history-contents-by-type
88+
"Retrieve datasets from the current active history by filetype."
89+
[client history-id ftype]
90+
(filter (partial is-ftype? ftype)
91+
(get-history-contents client history-id)))
92+
93+
(defn download-history-contents
94+
[client history-id content-id download-path]
95+
(spit download-path
96+
(:body (client/get (str (client :url) "histories/" history-id "/contents/" content-id "/display")
97+
{:headers {"x-api-key" (client :api-key)}}))))
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(ns org.galaxyproject.clj-blend.tools
2+
"Run Galaxy tools through the remote API"
3+
(:require [clj-http.client :as client]
4+
[clojure.data.json :as json]
5+
[clojure.string :as string]
6+
[org.galaxyproject.clj-blend.histories :as histories]
7+
[org.galaxyproject.clj-blend.util :as util]))
8+
9+
(defn list-tools
10+
[client]
11+
(json/read-str
12+
(:body (client/get (str (client :url) "tools")
13+
{:headers {"x-api-key" (client :api-key)}}))
14+
:key-fn util/key-fn))
15+
16+
(defn run-tool
17+
"Run a remote tool on Galaxy server"
18+
[client tool-id params & {:keys [history-id]}]
19+
(json/read-str
20+
(:body (client/post (str (client :url) "tools")
21+
{:headers {"x-api-key" (client :api-key)}}))
22+
:key-fn util/key-fn))
23+
24+
(defn upload-to-history
25+
"Upload a file via URL to a Galaxy history, defaulting to the current."
26+
[client file-url dbkey ftype & {:keys [history-id display-name]}]
27+
(run-tool client "upload1"
28+
{:file-type (name ftype)
29+
:dbkey (name dbkey)
30+
"files_0|url_paste" file-url
31+
"files_0|NAME" (or display-name (last (string/split file-url #"/")))}
32+
:history-id history-id))

0 commit comments

Comments
 (0)