def Evaluate(network2Pathway, outFileName, fraction, noise, weightedNetworks=False): with open(outFileName, "w") as outFile: npSum = 0 nrSum = 0 epSum = 0 erSum = 0 outFile.write("Steiner forest\tPathway\tTrue prizes\tNoisy prizes\tForest nodes\tPathway nodes\tIntersection nodes\tNode precision\tNode recall\tForest edges\tPathway edges\tIntersection edges\tEdge precision\tEdge recall\n") # The name forestFile assumes the networks to evaluate are Steiner forests, but they can # be any network for forestFile, pathwayFile in network2Pathway: # For each Steiner forest, compute the precision and recall with respect to the original pathway forest = NetworkUtil.LoadNetwork(forestFile, weight=weightedNetworks) # Remove the artificial node if the forest is not empty if "DUMMY" in forest: forest.remove_node("DUMMY") # NetworkUtil.LoadNetwork only works for the simple format used when writing synthetic # pathways. LoadGraphiteNetwork works for the simple format and the graphite edge list. pathway = NetworkUtil.LoadGraphiteNetwork(pathwayFile) intersection = NetworkUtil.Intersection(forest, pathway) if forest.order() == 0: nPrecision = 0 else: nPrecision = float(intersection.order())/forest.order() npSum += nPrecision nRecall = float(intersection.order())/pathway.order() nrSum += nRecall if forest.size() == 0: ePrecision = 0 else: ePrecision = float(intersection.size())/forest.size() epSum += ePrecision eRecall = float(intersection.size())/pathway.size() erSum += eRecall truePrizes = int(math.ceil(fraction*pathway.order())) noisyPrizes = int(math.ceil(noise*truePrizes)) outFile.write("%s\t%s\t%d\t%d\t%d\t%d\t%d\t%f\t%f\t%d\t%d\t%d\t%f\t%f\n" % (os.path.basename(forestFile), os.path.basename(pathwayFile), truePrizes, noisyPrizes, forest.order(), pathway.order(), intersection.order(), nPrecision, nRecall, forest.size(), pathway.size(), intersection.size(), ePrecision, eRecall)) # Write the average node/edge precision/recall outFile.write("Average\t\t\t\t\t\t\t%f\t%f\t\t\t\t%f\t%f\n" % (npSum/len(network2Pathway), nrSum/len(network2Pathway), epSum/len(network2Pathway), erSum/len(network2Pathway)))