Created
March 12, 2010 13:51
-
-
Save timyates/330312 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 | |
; http://blog.fuzzierlogic.com/archives/339 | |
; http://gist.github.com/329730 | |
(ns uniprot | |
(:use clojure.contrib.duck-streams) | |
(:import java.net.URLEncoder)) | |
(defn- url-encode | |
"Passes a String through java.net.URLEncoder.encode" | |
[ param ] (URLEncoder/encode param)) | |
(defn- map-to-query | |
"Convert a map to a query string" | |
[ a-map ] | |
(let [ key-set (keys a-map) ] | |
(reduce | |
(fn [ accum curr-key ] | |
(let [ key (if (keyword? curr-key) (name curr-key) curr-key) val (curr-key a-map) ] | |
(str accum (url-encode key) "=" (url-encode val) (if (= curr-key (last key-set)) "" "&")))) | |
"" key-set))) | |
(defn uniprot-mapping | |
"Call the uniprot webservice and convert the given ID between the given Uniprot types" | |
[ 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