def compare_single_var(result, bedregion, orig_vars, caller_vars, comparator, inputgt, conf): """ Determine a result string for the given result tuple. Not trivial since for NO_MATCH_RESULTS we need to determine if a simple genotype change will produce a match :param result: Result tuple produced by a comparator :param bedregion: Genomic region containing result :param orig_vars: 'original' (truth) variant set :param caller_vars: Variants produced by caller :param comparator: Comparator function :param inputgt: True variant genotype :param conf: Configuration :return: """ result_str = result_from_tuple(result) if result_str == NO_MATCH_RESULT and (inputgt in util.ALL_HET_GTS or inputgt in util.ALL_HOMALT_GTS): try: gt_mod_vars = util.set_genotypes(caller_vars, inputgt, bedregion, conf) bedfile = util.region_to_bedfile(bedregion) gt_mod_result = comparator(orig_vars, gt_mod_vars, bedfile, conf) if result_from_tuple(gt_mod_result) == MATCH_RESULT: if inputgt in util.ALL_HET_GTS: result_str = ZYGOSITY_EXTRA_ALLELE else: result_str = ZYGOSITY_MISSING_ALLELE except util.GTModException as ex: logging.warning('Exception while attempting to modify GTs: ' + str(ex)) return result_str
def test_gtmod(self): orig_vcf = os.path.join(TestUtils.DATA_PATH, TestUtils.COMPLEX_VCF) orig_vars = ["-".join(line.split("\t")[0:5]) for line in open(orig_vcf) if line[0] != "#"] mod_vcf = util.set_genotypes(orig_vcf, "0/1", None, None, compress_result=False) new_vars = ["-".join(line.split("\t")[0:5]) for line in open(mod_vcf) if line[0] != "#"] self.assertListEqual(orig_vars, new_vars) for line in open(mod_vcf): if line[0] == "#": continue else: toks = line.split("\t") alt = toks[4] gt = toks[9].split(":")[0] if alt != util.VCF_MISSING: self.assertTrue(gt == "0/1") else: self.assertTrue(gt == "0") os.remove(mod_vcf)