def test_non_overlap_true11(self): """ If everything works with new overlap parameter off For specified input we expect not to find any overlap :return: """ qclm_data = generate_qclm_input(11) qclm_data.config.non_overlapping_primers = True exp = set() for mut in qclm_data.mutations: exp.update(set(extract_position_from_key(mut))) random.seed(121) result = qclm_solve(qclm_data) print(result) mut_positions, primers_postions = extract_muations(result) # determine overlaps cnt_overlaps = count_overlaps(primers_postions) print("The solution has {} number of overlapping primers".format(cnt_overlaps)) if len(mut_positions) != len(exp): print(len(mut_positions), len(exp)) # we should have 0 overlaps self.assertEqual(cnt_overlaps, 0)
def test_non_overlap_false(self): """ If everything works with new overlap parameter off For specified input we expect to find some overlaps :return: """ qclm_data = generate_qclm_input(11) qclm_data.config.non_overlapping_primers = False exp = set() for mut in qclm_data.mutations: exp.update(set(extract_position_from_key(mut))) random.seed(121) result = qclm_solve(qclm_data) print(result) mut_positions = set() # here we store primers start and enc positions, as a key we use mutations, which the primer is covering primers_postions = {} for res in result["results"]: # we create key from just mutation positions therefore [1:-1] key = "-".join(res["mutations"]) key_pos = "-".join([m[1:-1] for m in res["mutations"]]) print(key, res["primers"]) for primer in res["primers"]: st = int(primer["start"]) end = int(primer["start"]) + int(primer["length"]) # we can have multiple primers for 1 mutaiton set, therefore we store just the minimal start and maximal end if key_pos in primers_postions.keys(): st = min(st, primers_postions[key_pos][0]) end = max(end, primers_postions[key_pos][1]) primers_postions[key_pos] = (st, end) mut_positions.update(set(extract_position_from_key(key))) # determine overlaps cnt_overlaps = 0 for pair in primers_postions.values(): # we look if we have overlap with any other primer if any([other[0] > pair[0] < other[1] for other in primers_postions.values()]): cnt_overlaps += 1 print("The solution has {} number of overlapping primers".format(cnt_overlaps)) if len(mut_positions) != len(exp): print(len(mut_positions), len(exp)) # we should have 0 overlaps self.assertEqual(len(mut_positions), len(exp))
def runTest(self, non_overlap_flag, ind): self.non_overlap_flag = non_overlap_flag self.qclm_data = generate_qclm_input(ind) self.qclm_data.config.non_overlapping_primers = self.non_overlap_flag random.seed(121) self.qclm_result = qclm_solve(self.qclm_data) self.exp = set() for mut in self.qclm_data.mutations: self.exp.update(set(extract_position_from_key(mut))) mut_positions = set() # here we store primers start and enc positions, as a key we use mutations, which the primer is covering primers_postions = {} for res in self.qclm_result["results"]: # we create key from just mutation positions therefore [1:-1] key = "-".join(res["mutations"]) key_pos = "-".join([m[1:-1] for m in res["mutations"]]) print(key, res["primers"]) for primer in res["primers"]: st = int(primer["start"]) end = int(primer["start"]) + int(primer["length"]) # we can have multiple primers for 1 mutaiton set, therefore we store just the minimal start and maximal end if key_pos in primers_postions.keys(): st = min(st, primers_postions[key_pos][0]) end = max(end, primers_postions[key_pos][1]) primers_postions[key_pos] = (st, end) mut_positions.update(set(extract_position_from_key(key))) # determine overlaps cnt_overlaps = 0 for pair in primers_postions.values(): # we look if we have overlap with any other primer if any([other[0] > pair[0] < other[1] for other in primers_postions.values()]): cnt_overlaps += 1 print("The solution has {} number of overlapping primers".format(cnt_overlaps)) if len(mut_positions) != len(self.xp): print(len(mut_positions), len(self.exp)) # we should have 0 overlaps if the flag is on if self.non_overlap_flag: self.assertEqual(cnt_overlaps, 0) if len(mut_positions) != len(self.exp): print("Not full coverage ERROR: {}".format(str(len(mut_positions)/len(self.exp))))