Created
July 3, 2015 09:49
-
-
Save chiragmatkar/11721c240dbb56a40e63 to your computer and use it in GitHub Desktop.
Filter Common KEGG Biological Pathways for 2 organisms using a text file containing pathways
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 | |
| d = {} | |
| with open("metabolicpathways.txt") as f: | |
| for line in f: | |
| (key, val) = line.split('\t') | |
| d[key] = val | |
| def intersect(a, b): | |
| return list(set(a) & set(b)) | |
| pathways = requests.get('http://rest.kegg.jp/list/pathway/hsa') | |
| pathways2 = requests.get('http://rest.kegg.jp/list/pathway/bar') | |
| hsa=[] | |
| bar=[] | |
| for line in pathways.content.split('\n'): | |
| pathwayid = line.split('\t')[0].replace('path:', '') | |
| hsa.append(pathwayid[3:]) | |
| print "\n\n\n\n" | |
| for line2 in pathways2.content.split('\n'): | |
| pathwayid2 = line2.split('\t')[0].replace('path:', '') | |
| bar.append(pathwayid2[3:]) | |
| hsa = filter(None, hsa) | |
| bar = filter(None, bar) | |
| common=intersect(hsa,bar) | |
| for j in common: | |
| if j in d.keys(): | |
| print "Common Pathway -->",j," - ",d[j],"\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment