-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
16 changed files
with
365 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,11 @@ | ||
(defproject clj-blend "0.1.1-SNAPSHOT" | ||
:description "Clojure library for interacting with Galaxy, CloudMan, and BioCloudCentral, built on blend4j" | ||
(defproject clj-blend "0.2.0-SNAPSHOT" | ||
:description "Clojure library for interacting with the Galaxy Bioinformatics Workflow Platform" | ||
:url "http://github.com/chapmanb/clj-blend" | ||
:license {:name "MIT" | ||
:url "http://www.opensource.org/licenses/mit-license.html"} | ||
:dependencies [[org.clojure/clojure "1.4.0"] | ||
[fs "1.3.2"] | ||
[com.github.jmchilton.blend4j/blend4j "0.1-alpha-1"]]) | ||
:dependencies [[org.clojure/clojure "1.10.0"] | ||
[clj-http "3.9.1"] | ||
[org.clojure/data.json "0.2.6"] | ||
[org.clojure/data.codec "0.1.1"] | ||
[fs "1.3.2"]] | ||
:profiles {:dev {:dependencies [[reloaded.repl "0.2.4"]]}}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
(ns org.galaxyproject.clj-blend.auth | ||
"Galaxy Authentication." | ||
(:require [clj-http.client :as client] | ||
[clojure.data.json :as json] | ||
[org.galaxyproject.clj-blend.util :as util])) | ||
|
||
(defn authenticate | ||
[server user] | ||
(let [b64 (util/b64-encode-str (str (:email user) ":" (:password user)))] | ||
(json/read-str | ||
(:body (client/get (str (:api-root server) "authenticate/baseauth") | ||
{:headers {"Authorization" (str "Basic " b64)}})) | ||
:key-fn util/key-fn))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(ns org.galaxyproject.clj-blend.core | ||
"Top level Galaxy interaction" | ||
(:require [clj-http.client :as client] | ||
[org.galaxyproject.clj-blend.users :as users] | ||
[org.galaxyproject.clj-blend.histories :as histories] | ||
[org.galaxyproject.clj-blend.tools :as tools])) | ||
|
||
|
||
(defn authenticate | ||
[server user] | ||
(client/get (str (:api-root server) "authenticate/baseauth") | ||
:headers {"Authorization" (str "Basic " )})) | ||
|
||
|
||
(defn get-client | ||
[galaxy-url api-key] | ||
{:url (str galaxy-url "/api/") :api-key api-key}) | ||
|
||
(def get-user-info users/get-current-user) | ||
|
||
(defn list-histories | ||
[client] | ||
[(histories/get-history-most-recently-used client)]) | ||
|
||
(def get-history-contents-by-type histories/get-history-contents-by-type) | ||
(def get-history-contents-by-id histories/get-history-contents-by-id) | ||
|
||
(def download-history-contents histories/download-history-contents) | ||
(def upload-to-history tools/upload-to-history) | ||
|
||
(comment | ||
(def client (get-client "http://localhost:8080" "admin")) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
(ns org.galaxyproject.clj-blend.histories | ||
"Retrieve Galaxy history information." | ||
(:use [clojure.java.io]) | ||
(:require [clojure.string :as string] | ||
[clj-http.client :as client] | ||
[clojure.data.json :as json] | ||
[org.galaxyproject.clj-blend.util :as util] | ||
[fs.core :as fs])) | ||
|
||
(defn get-histories | ||
[client] | ||
(json/read-str | ||
(:body (client/get (str (client :url) "histories") | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn get-history-most-recently-used | ||
[client] | ||
(json/read-str | ||
(:body (client/get (str (client :url) "histories/most_recently_used") | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn get-history-by-id | ||
[client history-id] | ||
(json/read-str | ||
(:body (client/get (str (client :url) "histories/" history-id) | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn create-history | ||
[client history] | ||
(json/read-str | ||
(:body (client/post (str (client :url) "histories") | ||
{:headers {"x-api-key" (client :api-key)} | ||
:content-type :json | ||
:body (json/write-str history)})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn delete-history | ||
[client history-id] | ||
(json/read-str | ||
(:body (client/delete (str (client :url) "histories/" history-id) | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn get-history-contents | ||
"Retrieve history datasets, flattened into Clojure maps." | ||
[client history-id] | ||
(json/read-str | ||
(:body (client/get (str (client :url) "histories/" history-id "/contents") | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn get-history-contents-by-id | ||
"Retrieve a history dataset converted into a clojure map." | ||
[client history-id content-id] | ||
(json/read-str | ||
(:body (client/get (str (client :url) "histories/" history-id "/contents/" content-id) | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn get-history-status | ||
[client history-id] | ||
(select-keys (get-history-by-id client history-id) [:state :state-details])) | ||
|
||
(defn- is-ftype? | ||
"Check if a dataset is the given filetype, cleanly handling keywords" | ||
[ftype dataset] | ||
(= (keyword ftype) | ||
(keyword (:data-type dataset)))) | ||
|
||
(defn get-history-contents | ||
[client history-id] | ||
(json/read-str | ||
(:body (client/get (str (client :url) "histories/" history-id "/contents") | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn get-history-contents-by-id | ||
[client history-id content-id] | ||
(json/read-str | ||
(:body (client/get (str (client :url) "histories/" history-id "/contents/" content-id) | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn get-history-contents-by-type | ||
"Retrieve datasets from the current active history by filetype." | ||
[client history-id ftype] | ||
(filter (partial is-ftype? ftype) | ||
(get-history-contents client history-id))) | ||
|
||
(defn download-history-contents | ||
[client history-id content-id download-path] | ||
(spit download-path | ||
(:body (client/get (str (client :url) "histories/" history-id "/contents/" content-id "/display") | ||
{:headers {"x-api-key" (client :api-key)}})))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
(ns org.galaxyproject.clj-blend.tools | ||
"Run Galaxy tools through the remote API" | ||
(:require [clj-http.client :as client] | ||
[clojure.data.json :as json] | ||
[clojure.string :as string] | ||
[org.galaxyproject.clj-blend.histories :as histories] | ||
[org.galaxyproject.clj-blend.util :as util])) | ||
|
||
(defn list-tools | ||
[client] | ||
(json/read-str | ||
(:body (client/get (str (client :url) "tools") | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn run-tool | ||
"Run a remote tool on Galaxy server" | ||
[client tool-id params & {:keys [history-id]}] | ||
(json/read-str | ||
(:body (client/post (str (client :url) "tools") | ||
{:headers {"x-api-key" (client :api-key)}})) | ||
:key-fn util/key-fn)) | ||
|
||
(defn upload-to-history | ||
"Upload a file via URL to a Galaxy history, defaulting to the current." | ||
[client file-url dbkey ftype & {:keys [history-id display-name]}] | ||
(run-tool client "upload1" | ||
{:file-type (name ftype) | ||
:dbkey (name dbkey) | ||
"files_0|url_paste" file-url | ||
"files_0|NAME" (or display-name (last (string/split file-url #"/")))} | ||
:history-id history-id)) |
Oops, something went wrong.