def generateNetworkVisualizationFiles(drugsfile, targetsfile, proteinnodesfile): fingerprints = util.readDrugData(drugsfile) [targetSets, ligandSets] = util.readTargetData(targetsfile, fingerprints.keys()) # Unsorted protein nodes data proteinNodes = np.loadtxt(proteinnodesfile, dtype='string', delimiter=',', skiprows=1) # Protein nodes data, sorted alphabetically by protein name sortedProteinNodes = proteinNodes[proteinNodes[:,0].argsort()] # Initialize data structures networkData=[]; nameData=[]; indicationData=[]; networkNodes=set() # Iterate over each node pair to determine if their bootstrap p-value merits an edge connection for i in range(len(sortedProteinNodes)): for j in range(i+1, len(sortedProteinNodes)): proteinA = sortedProteinNodes[i,0] proteinB = sortedProteinNodes[j,0] bootstrapPVal = util.calculateBootstrapPValue(100, 214, fingerprints, ligandSets, proteinA, proteinB) if bootstrapPVal <= 0.05: networkData.append([proteinA, proteinB]) # Create edge between connected nodes networkNodes.update([proteinA, proteinB]) # Update set of nodes in network # Annotate each node with its name and indication for protein in proteinNodes: if protein[0] in networkNodes: nameData.append([protein[0],protein[1]]) indicationData.append([protein[0],protein[2]]) # Output files np.savetxt('network.sif', np.array(networkData), fmt='%s edge %s') np.savetxt('name.nodeAttr', np.array(nameData), fmt='%s = %s', header="name", comments='') np.savetxt('indication.nodeAttr', np.array(indicationData), fmt='%s = %s', header="indication", comments='')
def printBootstrapPValue(): params = initParams() print util.calculateBootstrapPValue(params['n'], params['r'], params['fingerprints'], params['ligandSets'], params['proteinA'], params['proteinB'])