Created
March 14, 2011 20:47
-
-
Save yy/869845 to your computer and use it in GitHub Desktop.
A simple python script to use FuncAssociate 2.0 (http://llama.mshri.on.ca/funcassociate/documentation?page=funcassociate_api.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
#!/usr/bin/env python | |
import sys | |
import json | |
import httplib | |
class FuncAssociate(object): | |
"""Query funcassociate to find out enriched GO terms.""" | |
host = 'llama.mshri.on.ca' | |
query_url = '/cgi/funcassociate/serv' | |
def __init__(self): | |
self.c = httplib.HTTPConnection(self.host) | |
def close_conn(self): | |
self.c.close() | |
def jsonify(self, data): | |
return (json.dumps(data)).encode('utf-8') | |
def request(self, payload): | |
self.c.request('POST', self.query_url, self.jsonify(payload), | |
headers={'Content-type': 'application/json'}) | |
response = self.c.getresponse() | |
if response.status == httplib.OK: | |
return response.read() | |
def available_species(self): | |
payload = {'method': 'available_species', | |
'id': 0, | |
} | |
return self.request(payload) | |
def available_namespaces(self, species=['Homo sapiens']): | |
payload = {'method': 'available_namespaces', | |
'params': species, | |
'id': 123123123 | |
} | |
return self.request(payload) | |
def go_associations(self, | |
params=['Homo sapiens', 'uniprot_id', | |
['EXP', 'IDA', 'IPI', 'IMP', 'IGI', 'IEP'] | |
]): | |
payload = {'method': 'go_associations', | |
'params': params, | |
'id': 1, | |
} | |
return self.request(payload) | |
if __name__ == '__main__': | |
fa = FuncAssociate() | |
print fa.available_species() | |
print fa.available_namespaces() | |
print fa.go_associations() | |
payload = {'id': 1, | |
'method': 'functionate', | |
'params': [ { "query": ["YLR406C", "YCR031C", "YDR471W"], | |
"species":"Saccharomyces cerevisiae", | |
"namespace": "sgd_systematic" | |
}], | |
'jsonrpc': '2.0'} | |
print fa.request(payload=payload) | |
fa.close_conn() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment