-
-
Save swannodette/331478 to your computer and use it in GitHub Desktop.
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
; Amaturish Clojure version of uniprot mapping function by @sjcockell | |
; Improved a bit by David Nolen | |
; http://blog.fuzzierlogic.com/archives/339 | |
; http://gist.github.com/329730 | |
(ns uniprot | |
(:use [clojure.contrib.duck-streams]) | |
(:require [clojure.contrib.str-utils2 :as s]) | |
(:import java.net.URLEncoder)) | |
(defn- url-encode [param] (URLEncoder/encode param)) | |
(defn- map-to-query [amap] | |
(s/join "&" (map (fn [[k v]] (str (url-encode (name k)) "=" (url-encode v))) amap))) | |
(defn uniprot-mapping | |
[from to query] | |
(slurp* (str "http://www.uniprot.org/mapping?" (map-to-query {:from from :to to :query query :format "tab"})))) | |
(println (uniprot-mapping "ENSEMBL_ID" "ACC" "ENSG00000141510")) |
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
// Groovy version of uniprot mapping function by @sjcockell | |
// http://blog.fuzzierlogic.com/archives/339 | |
// http://gist.github.com/329730 | |
import java.net.URLEncoder as U | |
def uniprot_mapping( fromtype, totype, identifier ) { | |
base = 'http://www.uniprot.org' | |
tool = 'mapping' | |
params = [ from : fromtype, | |
to : totype, | |
format : 'tab', | |
query : identifier ] | |
params = params.collect { "${U.encode(it.key)}=${U.encode(it.value)}" }.join( '&' ) | |
new URL( "$base/$tool?$params" ).text | |
} | |
// For mapping example types, see: | |
// http://www.uniprot.org/faq/28#id_mapping_examples | |
println uniprot_mapping( 'ENSEMBL_ID', 'ACC', 'ENSG00000141510' ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment