Program to calculate the Node degree to be called as a Hub Protein


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. #!/usr/bin/python
  2.  
  3. # Program to calculate the Node degree to be called as a Hub Protein
  4. # Author: Kumaran Kandasamy
  5.  
  6. class IsHubProtein:
  7. def __init__(self,
  8. PINPath,
  9. percentile = 0.95
  10. ):
  11. # Read the PIN File
  12. inFile = file(PINPath,'r')
  13. mainData = inFile.readlines()
  14. inFile.close()
  15.  
  16. nodeDegree = {};
  17. for line in mainData[1:]:
  18. line = line.strip().split('\t')
  19. n1 = str(line[0]).strip()
  20. if not nodeDegree.has_key(n1):nodeDegree[n1] = 0
  21. nodeDegree[n1] += 1
  22.  
  23. n2 = str(line[1]).strip()
  24. if not nodeDegree.has_key(n2):nodeDegree[n2] = 0
  25. nodeDegree[n2] += 1
  26.  
  27. # Number of Nodes in PIN
  28. x = len(nodeDegree)
  29. # To get to the Specified percentile; If not specified it will be 95%
  30. y = int(percentile * x)
  31.  
  32. degreeBin = {}; degreeUniq = [];
  33. for node,degree in nodeDegree.items():
  34. if not degreeBin.has_key(degree):degreeBin[degree] = 0
  35. degreeBin[degree] += 1
  36. if degree not in degreeUniq:degreeUniq.append(degree)
  37. degreeUniq.sort()
  38.  
  39. n = 0; degreeForHub = None;
  40. for degree in degreeUniq:
  41. n = n + degreeBin[degree]
  42. #print degree, degreeBin[degree], n
  43. if n > y:
  44. degreeForHub = degree
  45. break
  46.  
  47. self.degreeForHub = degreeForHub
  48. self.nodedehree = nodeDegree
  49.  
  50. return None
  51.  
  52. def main():
  53. PINFilePath = '/home/kkandasamy/work/databases/interact-innatedb-human-2011-01-17.txt'
  54. data = IsHubProtein(PINFilePath, 0.95)
  55. print data.degreeForHub
  56. return None
  57.  
  58. if __name__ == '__main__':
  59. main()

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.