Skip to content

Instantly share code, notes, and snippets.

@swannodette
Forked from timyates/uniprot.clj
Created March 13, 2010 18:27
Show Gist options
  • Save swannodette/331478 to your computer and use it in GitHub Desktop.
Save swannodette/331478 to your computer and use it in GitHub Desktop.
; 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"))
// 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