Created
March 11, 2010 22:11
-
-
Save sjcockell/329730 to your computer and use it in GitHub Desktop.
A Python method to map protein IDs via the UniProt mapping service
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
import urllib | |
import urllib2 | |
def uniprot_mapping(fromtype, totype, identifier): | |
"""Takes an identifier, and types of identifier | |
(to and from), and calls the UniProt mapping service""" | |
base = 'http://www.uniprot.org' | |
tool = 'mapping' | |
params = {'from':fromtype, | |
'to':totype, | |
'format':'tab', | |
'query':identifier, | |
} | |
#urllib turns the dictionary params into an encoded url suffix | |
data = urllib.urlencode(params) | |
#construct the UniProt URL | |
url = base+'/'+tool+'?'+data | |
#and grab the mapping | |
response = urllib2.urlopen(url) | |
#response.read() provides tab-delimited output of the mapping | |
return response.read() | |
if __name__ == '__main__': | |
print uniprot_mapping('EMBL_ID', 'ID', 'X02469') | |
#see http://www.uniprot.org/faq/28#id_mapping_examples for from&to codes |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment