Guest User

Untitled

a guest
Mar 21st, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Mon Mar 12 18:16:24 2018
  4.  
  5. @author: Fuzzy
  6. """
  7.  
  8. import json
  9. with open('tfbsDb_plus_and_minus_5000_entrez.json', 'r') as f:
  10. data = json.load(f)
  11.  
  12. motif2Id = {}
  13. id2Motif = {}
  14.  
  15. with open('id_conversion/humanTFs_All.CSV','r') as inFile:
  16. header = inFile.readline().strip().split(',') #get rid of header, strip gets rid of whitespace, split each in element by comma
  17. while 1:
  18. inLine = inFile.readline()
  19. if not inLine:
  20. break
  21. split = inLine.strip().split(',')#create an array with element 0 as key, element 2 as ID
  22. motif2Id[split[0]] = split[2]#store element 0 as key and element 2 as the string
  23. #creating Id to motif, mapping one motif to many Ids, create list inside dictonary
  24. if not split[2] in id2Motif:
  25. id2Motif[split[2]] = []
  26. id2Motif[split[2]].append(split[0])
  27.  
  28. #attempt to associate a gene Id to many other gene Ids using associated motifs
  29. gene2GeneDB = {}
  30. for i in range(3):#run through unique gene IDs and set them as geneIn
  31.  
  32. geneIn = id2Motif.keys()[i]
  33. motifList = [] #empty list for motif hits
  34. # for loop to search for any hits in humanTFs_All
  35. for x in range(len(id2Motif)):
  36. if geneIn == float(id2Motif.keys()[x]):
  37. motifList = id2Motif[id2Motif.keys()[x]]
  38.  
  39. #nested for loop to search for motifs in json file and appends all genes
  40. geneList = []
  41. for x in range(len(data)):
  42. for y in range(len(motifList)):
  43. if str(motifList[y]) == str(data.keys()[x]):
  44. geneList += data[data.keys()[x]]
  45.  
  46. #nested for loop to search origonal humanTF list for shared gene IDs
  47. #humanGeneList = []
  48. gene2GeneDB[str(geneIn)] = []
  49. for x in range(len(geneList)):
  50. for y in range(len(id2Motif)):
  51. if geneList[x] == id2Motif.keys()[y]:
  52. gene2GeneDB[str(geneIn)].append(str(id2Motif.keys()[y]))
  53. #humanGeneList.append(id2Motif.keys()[y])
  54.  
  55.  
  56. print gene2GeneDB
  57. #print (gene2GeneDB[gene2GeneDB.keys()[0:5]])
Add Comment
Please, Sign In to add comment