import sys # Make sure the command line is valid. if (len(sys.argv) != 4): print "USAGE: compute-fdr.py " sys.exit(1) ############################################################################# # Define a function to read values from a file and report how many are above # a given threshold. ############################################################################# def readFileWithThreshold (fileName, threshold): # Counter of values above threshold returnValue = 0 # Read the file line by line. myFile = open(fileName, "r") for line in myFile: if (len(line.split()) != 1): print "Invalid line (%s).\n" % line sys.exit(1) thisValue = float(line) if (thisValue >= threshold): returnValue += 1 myFile.close() return(returnValue) ############################################################################# # MAIN PROCEDURE ############################################################################# # Read the arguments. threshold = float(sys.argv[1]) targetFilename = sys.argv[2] decoyFilename = sys.argv[3] # Parse both files and store the count above threshold. numTargets = readFileWithThreshold(targetFilename, threshold) numDecoys = readFileWithThreshold(decoyFilename, threshold) # Check for divide by zero and print FDR. if (numTargets == 0): print "No targets above threshold. FDR undefined.\n" else: print "%g" % (float(numDecoys) / float(numTargets))