-
-
Save cplaisier/eb9695f264103e910562cdf7886e4143 to your computer and use it in GitHub Desktop.
takes an input Entrez ID and outputs a .sif file
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
| # -*- coding: utf-8 -*- | |
| """ | |
| Created on Mon Mar 12 18:16:24 2018 | |
| @author: Fuzzy | |
| """ | |
| import json | |
| with open('tfbsDb_plus_and_minus_5000_entrez.json', 'r') as f: | |
| data = json.load(f) | |
| motif2Id = {} | |
| id2Motif = {} | |
| with open('id_conversion/humanTFs_All.CSV','r') as inFile: | |
| header = inFile.readline().strip().split(',') #get rid of header, strip gets rid of whitespace, split each in element by comma | |
| while 1: | |
| inLine = inFile.readline() | |
| if not inLine: | |
| break | |
| split = inLine.strip().split(',')#create an array with element 0 as key, element 2 as ID | |
| motif2Id[split[0]] = split[2]#store element 0 as key and element 2 as the string | |
| #creating Id to motif, mapping one motif to many Ids, create list inside dictonary | |
| if not split[2] in id2Motif: | |
| id2Motif[split[2]] = [] | |
| id2Motif[split[2]].append(split[0]) | |
| # Starting ID list | |
| tfStartId = ['430', '1052', '1053', '1385', '84699', '9586', '1871', '1874', '144455', '79733', '1960', '1997', '2002', '2004', '80712', '2114', '2115', '2120', '51513', '2551', '2623', '2624', '2625', '9421', '3232', '10320', '3659', '3662', '3670', '91464', '3726', '10661', '11278', '128209', '10365', '9314', '1316', '51176', '9935', '23269', '4602', '4774', '4790', '7025', '9480', '5468', '5914', '5916', '3516', '5971', '864', '6257', '4093', '6659', '6660', '6662', '25803', '347853', '30009', '9496', '6929', '6925', '8463', '7022', '29842', '10155', '6935', '132625', '23051', '85416', '7707', '7764', '23528', '201516'] | |
| # Create a TFreg -> TFtarg dictionary | |
| geneNetwork = {} | |
| for TFreg in tfStartId: | |
| if TFreg in id2Motif: | |
| for motif in id2Motif[TFreg]: | |
| if motif in data: | |
| for geneTarg in data[motif]: | |
| if geneTarg in tfStartId: | |
| if not TFreg in geneNetwork: | |
| geneNetwork[TFreg] = [] | |
| geneNetwork[TFreg].append(geneTarg) | |
| #create .sif file | |
| interact = 'r2t' | |
| writeMe = [] | |
| for key in geneNetwork: | |
| for gene in geneNetwork[key]: | |
| writeMe.append(key+'\t'+interact+'\t'+gene) | |
| with open('gene2GeneNetwork.sif','w') as outFile: | |
| outFile.write('\n'.join(writeMe)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment