Created
December 7, 2013 00:42
-
-
Save kozo2/7835738 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 requests | |
from sets import Set | |
import more_itertools | |
pathways = requests.get('http://rest.kegg.jp/list/pathway') | |
compounds = [] | |
for line in pathways.content.split('\n'): | |
mapid = line.split('\t')[0].replace('path:', '') | |
cpds = requests.get('http://rest.kegg.jp/link/cpd/' + mapid) | |
for cpd in cpds.content.split('\n'): | |
if len(cpd.split('cpd:')) > 1: | |
compounds.append(cpd.split('cpd:')[1]) | |
cpdids = list(Set(compounds)) | |
cpdids.sort() | |
output = open('compoundNames.txt', 'w') | |
for ids in more_itertools.chunked(cpdids, 100): | |
names = requests.get('http://rest.kegg.jp/list/' + '+'.join(ids)) | |
output.write(names.content) | |
output.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment