pk_file = open('tiedie_kernel.pkl', 'wb') pickle.dump(diffuser, pk_file) pk_file.close() # Check to make sure the node universe matches the k_labels = diffuser.getLabels() if len(network_nodes) != len(k_labels) or len( network_nodes.intersection(k_labels)) != len(k_labels): sys.stderr.write( "Error: the universe of gene/node labels in the network file doesn't match the supplied kernel file!\n" ) sys.exit(1) sys.stderr.write("Diffusing Heats...\n") # Separately perform diffusion for each input set up_heats_diffused = diffuser.diffuse(up_heats, reverse=False) down_heats_diffused = diffuser.diffuse(down_heats, reverse=True) # Extract a subnetwork solution from the diffused heats, the set of nodes found, the Relevance score for this network solution # and the heat scores for all linker genes subnet_soln, subnet_soln_nodes, alpha_score, linker_scores = extractSubnetwork( up_heats, down_heats, up_heats_diffused, down_heats_diffused, size_control, opts.alpha) # # Generate linker stats and output # out_degrees = getOutDegrees(subnet_soln) sys.stderr.write("Writing network node stats to " + output_folder + "/node.stats\n") out_file = output_folder + "/node.stats"
# # Diffusion Step: # Load the heat diffusion kernel and perform a kernel-multiply, or alternatively use supplied # page-rank diffused vectors # print "Parsing Network File..." network = parseNet(opts.network) if opts.pagerank: diffuser = PPrDiffuser(network) else: print "Loading Heat Diffusion Kernel.." diffuser = Kernel(opts.kernel) print "Diffusing Heats..." up_heats_diffused = diffuser.diffuse(up_heats, reverse=False) down_heats_diffused = diffuser.diffuse(down_heats, reverse=True) if opts.size_select: # Search a number of network sizes to get a range with the highest significance. # Somewhat slow. search_space = [] start, end = opts.size_select.split(":") start = int(start) end = int(end) for size in range(1, 20): search_space.append(float(size)/20) for size in range(11, 20): search_space.append(float(size)/10) for size in range(1, 15):