Posted By

itskkumaran on 03/03/11


Tagged

Hub Protein


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

itskkumaran


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


 / Published in: Python
 

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

Report this snippet  

You need to login to post a comment.