-
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.
Galaxy client connection plus query and download of files from history
- Loading branch information
0 parents
commit 0fad262
Showing
5 changed files
with
114 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/target | ||
/lib | ||
/classes | ||
/checkouts | ||
pom.xml | ||
*.jar | ||
*.class | ||
.lein-deps-sum | ||
.lein-failures | ||
.lein-plugins |
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,28 @@ | ||
# clj-blend | ||
|
||
Clojure library for interacting with Galaxy, CloudMan, and BioCloudCentral. This | ||
builds on [blend4j][0] with lots of help from [blend][1]. Provides high level | ||
functionality on top of blend4j, with a focus on useful functionality utilizing | ||
the Galaxy API. | ||
|
||
[0]: https://github.com/jmchilton/blend4j | ||
[1]: https://github.com/afgane/blend | ||
|
||
## Usage | ||
|
||
Requires Java 1.6 or better and [Leiningen 2.x][u1]. | ||
|
||
$ lein repl | ||
> (require '[blend.galaxy.core :as blend]) | ||
> (def c (blend/get-client "https://main.g2.bx.psu.edu/" "your-api-key")) | ||
> (def ds (blend/get-datasets-by-type c :bed)) | ||
> (blend/download-dataset c (first ds) "/where/to/put/your/file.bed") | ||
|
||
|
||
[u1]: https://github.com/technomancy/leiningen | ||
|
||
## License | ||
|
||
The code is freely available under the [MIT license][l1]. | ||
|
||
[l1]: http://www.opensource.org/licenses/mit-license.html |
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,9 @@ | ||
(defproject clj-blend "0.1.0-SNAPSHOT" | ||
:description "Clojure library for interacting with Galaxy, CloudMan, and BioCloudCentral, built on blend4j" | ||
: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-SNAPSHOT"]] | ||
:repositories {"msi-artifactory" {:url "http://artifactory.msi.umn.edu/libs-snapshot-local"}}) |
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,11 @@ | ||
(ns blend.galaxy.core | ||
"Top level Galaxy interaction" | ||
(:import [com.github.jmchilton.blend4j.galaxy GalaxyInstanceFactory]) | ||
(:require [blend.galaxy.histories :as histories])) | ||
|
||
(defn get-client | ||
[galaxy-url api-key] | ||
(GalaxyInstanceFactory/get galaxy-url api-key)) | ||
|
||
(def get-datasets-by-type histories/get-datasets-by-type) | ||
(def download-dataset histories/download-dataset) |
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,56 @@ | ||
(ns blend.galaxy.histories | ||
"Retrieve Galaxy history information." | ||
(:use [clojure.java.io]) | ||
(:require [clojure.string :as string] | ||
[fs.core :as fs])) | ||
|
||
(defn- get-history-dataset | ||
"Retrieve a history dataset converted into a clojure map." | ||
[hist-client hist hist-contents] | ||
(let [ds (.showDataset hist-client (.getId hist) (.getId hist-contents))] | ||
{:id (.getId ds) | ||
:name (.getName ds) | ||
:data-type (.getDataType ds) | ||
:genome-build (.getGenomeBuild ds) | ||
:file-size (.getFileSize ds) | ||
:deleted (.getDeleted ds) | ||
:visible (.getVisible ds) | ||
:state (.getState ds) | ||
:download-url (.getDownloadUrl ds)})) | ||
|
||
(defn- get-history-datasets | ||
"Retrieve history datasets, flattened into Clojure maps." | ||
[hist-client hist] | ||
(->> (.showHistoryContentsRequest hist-client (.getId hist)) | ||
(filter #(= (.getType %) "file")) | ||
(map (partial get-history-dataset hist-client hist)))) | ||
|
||
(defn- is-ftype? | ||
"Check if a dataset is the given filetype, cleanly handling keywords" | ||
[ftype dataset] | ||
(= (keyword ftype) | ||
(keyword (:data-type dataset)))) | ||
|
||
(defn get-datasets-by-type | ||
"Retrieve datasets from the current active history by filetype." | ||
[client ftype] | ||
(let [hist-client (.getHistoriesClient client)] | ||
(->> (.getHistories hist-client) | ||
first | ||
(get-history-datasets hist-client) | ||
(filter (partial is-ftype? ftype))))) | ||
|
||
(defn download-dataset | ||
"Retrieve remote history dataset to a local file or directory" | ||
[client dataset path] | ||
(let [api-url (-> client .getWebResource .getURI) | ||
query (.getQuery api-url) | ||
base-url (first (string/split (.toString api-url) #"/api")) | ||
fname (if (fs/directory? path) | ||
(str (file path (:name dataset))) | ||
path)] | ||
(when (or (not (fs/exists? fname)) | ||
(not= (fs/size fname) (:file-size dataset))) | ||
(with-open [rdr (reader (str base-url (:download-url dataset)))] | ||
(copy rdr (file fname)))) | ||
fname)) |