Return to Snippet

Revision: 42299
at March 3, 2011 00:29 by itskkumaran


Initial Code
#!/usr/bin/python

# Program to calculate the Node degree to be called as a Hub Protein
# Author: Kumaran Kandasamy
# Contact: [email protected]

class IsHubProtein:
    def __init__(self,
                 PINPath,
                 percentile = 0.95
                 ):
        # Read the PIN File
        inFile = file(PINPath,'r')
        mainData = inFile.readlines()
        inFile.close()
        
        nodeDegree = {};
        for line in mainData[1:]:
            line = line.strip().split('\t')
            n1 = str(line[0]).strip()
            if not nodeDegree.has_key(n1):nodeDegree[n1] = 0
            nodeDegree[n1] += 1
            
            n2 = str(line[1]).strip()
            if not nodeDegree.has_key(n2):nodeDegree[n2] = 0
            nodeDegree[n2] += 1
            
        # Number of Nodes in PIN
        x = len(nodeDegree)
        # To get to the Specified percentile; If not specified it will be 95%
        y = int(percentile * x)
        
        degreeBin = {}; degreeUniq = [];
        for node,degree in nodeDegree.items():
            if not degreeBin.has_key(degree):degreeBin[degree] = 0
            degreeBin[degree] += 1
            if degree not in degreeUniq:degreeUniq.append(degree)
        degreeUniq.sort()
        
        n = 0; degreeForHub = None;
        for degree in degreeUniq:
            n = n + degreeBin[degree]
            #print degree, degreeBin[degree], n
            if n > y:
                degreeForHub = degree
                break
            
        self.degreeForHub = degreeForHub
        self.nodedehree = nodeDegree
            
        return None
    
def main():
    PINFilePath = '/home/kkandasamy/work/databases/interact-innatedb-human-2011-01-17.txt'
    data = IsHubProtein(PINFilePath, 0.95)
    print data.degreeForHub
    return None

if __name__ == '__main__':
    main()

Initial URL

                                

Initial Description

                                

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

Initial Tags

                                

Initial Language
Python