def validate_sensor_make_cases(): # [ Recog, Stem1, Stem2, binding_ratio, maxunknownpercent, numfoldrange, maxenergy, expected ] tests = [ ["ATTA", "CGA", "TCC", (0.9, 1.1), 0.2, (2, 4), -1.3, False], ["ATTA", "CCC", "CGC", (0.9, 1.1), 0.2, (2, 4), -10, False], ["ATTA", "CCC", "CGC", (0.6, 0.7), 0.2, (2, 4), None, True], ["ATTA", "GCG", "CCC", (0.9, 1.1), 0.2, None, None, False], ["ATTA", "TCA", "CC", (0.2, 0.8), 0.2, None, 0, True], ["ATTAGC", "TCCA", "CCCC", (0.9, 1.1), 0.2, None, None, False], ] for test in tests: sensor = util.Sensor(test[0]) sensor.SetStem1(test[1]) sensor.SetStem2(test[2]) test_file = test_dir + "validate_sensor/" + str(sensor) tosave = open(test_file, "w") folds = unafold.parse_ct(unafold.run_hybrid_ss_min(sensor)) scores = unafold.score_sensor(sensor, folds) pickle.dump((sensor, scores, folds, test[3], test[4], test[5], test[6], test[7]), tosave) print ("validate_sensor_make_cases(): storing folds and scores for %s" % str(sensor)) tosave.close()
def find_stems_make_case(seq, foldnum, comment): foldings = unafold.parse_ct(unafold.run_hybrid_ss_min(seq)) tosave_filename = "tests/find_stems/" + seq + "_%d" % (foldnum - 1) tosave = open(tosave_filename, "w") test_case = [foldings[foldnum - 1], unafold.find_stems(foldings[foldnum - 1]), comment] pickle.dump(test_case, tosave) print ("find_stems_make_case(%s, %d, %s): pickling %s" % (seq, foldnum, comment, test_case)) tosave.close()
def run_hybrid_ss_min_make_case(seq): """given a sequence string, pickle the output to tests/run_hybrid_ss_min""" test_file = "tests/run_hybrid_ss_min/" + seq tosave = open(test_file, "w") pickle.dump(unafold.run_hybrid_ss_min(seq), tosave) tosave.close()
def score_sensor_make_case(sensor): folds = unafold.parse_ct(unafold.run_hybrid_ss_min(sensor, True)) scores = unafold.score_sensor(sensor, folds) tosave_filename = test_dir + "score_sensor/" + str(sensor) tosave = open(tosave_filename, "w") pickle.dump((sensor, folds, scores), tosave) print ("score_sensor_make_case(%s): pickling %s" % (sensor, (folds, scores))) tosave.close()
def main(): args = process_command_line(sys.argv[1:]) if args.validate_sensor: validate_sensor_make_cases() return True for line in sys.stdin: line = line.strip() sys.stderr.write("Processing case %s\n" % line) if args.binding: # Assumes that run_hybrid_ss_min produces valid # foldings # Takes a CSV file with the following format # Recognition, Generated Sequence, quencher, fold number, type, comment # # Where fold number is is the 1 based index as returned # from UNAfold, and type binding_on/nonbinding_off/badbind/badnonbind elements = line.split(",") foldings = unafold.parse_ct(unafold.run_hybrid_ss_min(elements[1])) try: comment = elements[5] except IndexError: comment = "" fold_type_make_case( elements[3], elements[1], foldings[int(elements[3]) - 1], elements[0], int(elements[2]), elements[4], comment, ) if args.score_sensor: elements = line.split(",") sensor = util.Sensor(elements[0]) sensor.SetStem1(elements[1]) sensor.SetStem2(elements[2]) score_sensor_make_case(sensor) if args.run_hybrid_ss_min: run_hybrid_ss_min_make_case(line) if args.find_stems: # Reads in STDIN to make regression test cases to test find_stems() # Assumes that run_hybrid_ss_min() and parse_ct() are working correctly # File format # # sequence, foldnum, comment elements = line.split(",") try: comment = elements[2] except IndexError: comment = "" find_stems_make_case(elements[0], int(elements[1]), comment)
def _run_hybrid_ss_min(seq, expected): results = unafold.run_hybrid_ss_min(seq, True) assert results == expected