Example #1
0
    def test_add_tag_nullInputsProduceNullZScores(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "4"
                                 },
                                 "SB": {
                                     "X": "."
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "."
                                 },
                                 "SB": {
                                     "X": "8"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])
        tag = zscore_caller._ZScoreTag("ZScoreX", "ZScore for X", "X", reader)

        tag.add_tag_values(rec1)
        sampleA_tag_values = rec1.sample_tag_values["SA"]
        self.assertEquals("-1.0", sampleA_tag_values["ZScoreX"])
        sampleB_tag_values = rec1.sample_tag_values["SB"]
        self.assertEquals(".", sampleB_tag_values["ZScoreX"])
Example #2
0
    def test_SomaticTagSS_metaheaders(self):
        vcf_reader = MockVcfReader(
            metaheaders=["##foo", "##MuTect=123", '##FORMAT=<ID=FA,...>'])
        mutect_vcf_reader = mutect._MutectVcfReader(vcf_reader)
        metaheaders = mutect_vcf_reader.metaheaders

        self.assertIn(mutect._SomaticTagSS().metaheader, metaheaders)
Example #3
0
    def test_init_createsAllTags(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "JQ_SUMMARY_AF_RANGE": "4"
                                 },
                                 "SB": {
                                     "JQ_SUMMARY_AF_RANGE": "7"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "JQ_SUMMARY_AF_RANGE": "13"
                                 },
                                 "SB": {
                                     "JQ_SUMMARY_AF_RANGE": "16"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])

        caller = zscore_caller.ZScoreCaller(reader)

        self.assertEquals(2, len(caller._tags))
        tag_ids = [tag.tag_id for tag in caller._tags]
        self.assertIn("JQ_SUMMARY_AF_ZSCORE", tag_ids)
        self.assertIn("JQ_SUMMARY_DP_ZSCORE", tag_ids)
Example #4
0
    def test_add_tag_zeroInputsIncluded(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "4"
                                 },
                                 "SB": {
                                     "X": "0"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "0"
                                 },
                                 "SB": {
                                     "X": "8"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])
        tag = zscore_caller._ZScoreTag("ZScoreX", "ZScore for X", "X", reader)

        tag.add_tag_values(rec1)
        sampleA_tag_values = rec1.sample_tag_values["SA"]
        self.assertEquals("0.3015", sampleA_tag_values["ZScoreX"])
        sampleB_tag_values = rec1.sample_tag_values["SB"]
        self.assertEquals("-0.9045", sampleB_tag_values["ZScoreX"])
Example #5
0
    def test_add_tag_doesNothingIfNoStdev(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "4"
                                 },
                                 "SB": {
                                     "X": "4"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "4"
                                 },
                                 "SB": {
                                     "X": "4"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])
        tag = zscore_caller._ZScoreTag("ZScoreX", "ZScore for X", "X", reader)

        tag.add_tag_values(rec1)

        self.assertEquals(0, tag._stdev)
        self.assertEqual(["X"], sorted(rec1.sample_tag_values["SA"].keys()))
        self.assertEqual(["X"], sorted(rec1.sample_tag_values["SB"].keys()))
Example #6
0
    def test_add_tag(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "JQ_SUMMARY_DP_RANGE": "4"
                                 },
                                 "SB": {
                                     "JQ_SUMMARY_DP_RANGE": "7"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "JQ_SUMMARY_DP_RANGE": "13"
                                 },
                                 "SB": {
                                     "JQ_SUMMARY_DP_RANGE": "16"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])
        tag = zscore_caller._DepthZScoreTag(reader)

        tag.add_tag_values(rec1)
        sampleA_tag_values = rec1.sample_tag_values["SA"]
        self.assertEquals("-1.2649",
                          sampleA_tag_values["JQ_SUMMARY_DP_ZSCORE"])
        sampleB_tag_values = rec1.sample_tag_values["SB"]
        self.assertEquals("-0.6325",
                          sampleB_tag_values["JQ_SUMMARY_DP_ZSCORE"])
Example #7
0
    def test_init_setsPopulationStatistics(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "4"
                                 },
                                 "SB": {
                                     "X": "7"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "13"
                                 },
                                 "SB": {
                                     "X": "16"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])

        tag = zscore_caller._ZScoreTag("ZScoreX", "ZScore for X", "X", reader)

        values = [4, 7, 13, 16]
        self.assertAlmostEquals(mean(values), tag._mean,
                                _ZScoreTag._MAX_PRECISION)
        self.assertAlmostEquals(stdev(values), tag._stdev,
                                _ZScoreTag._MAX_PRECISION)
Example #8
0
    def test_add_tag(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "4"
                                 },
                                 "SB": {
                                     "X": "7"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "13"
                                 },
                                 "SB": {
                                     "X": "16"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])
        tag = zscore_caller._ZScoreTag("ZScoreX", "ZScore for X", "X", reader)

        tag.add_tag_values(rec1)
        sampleA_tag_values = rec1.sample_tag_values["SA"]
        self.assertEquals("-1.2649", sampleA_tag_values["ZScoreX"])
        sampleB_tag_values = rec1.sample_tag_values["SB"]
        self.assertEquals("-0.6325", sampleB_tag_values["ZScoreX"])
Example #9
0
    def test_open_and_close(self):
        vcf_reader = MockVcfReader(metaheaders=["##foo", "##source=strelka"])
        strelka_vcf_reader = strelka._StrelkaVcfReader(vcf_reader)
        strelka_vcf_reader.open()
        strelka_vcf_reader.close()

        self.assertTrue(strelka_vcf_reader.open)
        self.assertTrue(strelka_vcf_reader.close)
Example #10
0
    def test_open_and_close(self):
        vcf_reader = MockVcfReader(metaheaders=["##foo", "##source=VarScan2"])
        varscan_vcf_reader = varscan._VarscanVcfReader(vcf_reader)
        varscan_vcf_reader.open()
        varscan_vcf_reader.close()

        self.assertTrue(varscan_vcf_reader.open)
        self.assertTrue(varscan_vcf_reader.close)
Example #11
0
    def test_add_summarize_tags(self):
        file_writer = MockFileWriter()
        vcf_record = vcf.VcfRecord("chr1", "42", "A", "C")
        vcf_reader = MockVcfReader(records=[vcf_record])
        caller = MockSummarizeCaller()

        summarize._add_tags(caller, vcf_reader, file_writer)

        self.assertTrue(caller.add_tags_called)
Example #12
0
    def test_open_and_close(self):
        vcf_reader = MockVcfReader(
            metaheaders=["##foo", "##MuTect=123", '##FORMAT=<ID=FA,...>'])
        mutect_vcf_reader = mutect._MutectVcfReader(vcf_reader)
        mutect_vcf_reader.open()
        mutect_vcf_reader.close()

        self.assertTrue(mutect_vcf_reader.open)
        self.assertTrue(mutect_vcf_reader.close)
Example #13
0
    def test_SomaticTagFilterMutectCalls_metaheaders(self):
        vcf_reader = MockVcfReader(metaheaders=[
            "##foo", "##MuTect=123", '##FORMAT=<ID=FA,...>',
            "##source=FilterMutectCalls"
        ])
        mutect_vcf_reader = mutect._MutectVcfReader(vcf_reader)
        metaheaders = mutect_vcf_reader.metaheaders

        self.assertIn(mutect._SomaticTagFilterMutectCalls().metaheader,
                      metaheaders)
Example #14
0
    def test_metaheaders(self):
        vcf_reader = MockVcfReader(metaheaders=["##foo", "##source=strelka"])
        strelka_vcf_reader = strelka._StrelkaVcfReader(vcf_reader)
        metaheaders = strelka_vcf_reader.metaheaders

        self.assertIn(strelka._AlleleFreqTag().metaheader, metaheaders)
        self.assertIn(strelka._DepthTag().metaheader, metaheaders)
        self.assertIn(strelka._SomaticTag().metaheader, metaheaders)
        self.assertIn("##foo", metaheaders)
        self.assertIn("##source=strelka", metaheaders)
        self.assertIn("##jacquard.translate.caller=Strelka", metaheaders)
Example #15
0
    def test_metaheaders(self):
        vcf_reader = MockVcfReader(metaheaders=["##foo", "##source=VarScan2"])
        varscan_vcf_reader = varscan._VarscanVcfReader(vcf_reader)
        metaheaders = varscan_vcf_reader.metaheaders

        self.assertIn(varscan._AlleleFreqTag().metaheader, metaheaders)
        self.assertIn(varscan._DepthTag().metaheader, metaheaders)
        self.assertIn(varscan._SomaticTag().metaheader, metaheaders)
        self.assertIn("##foo", metaheaders)
        self.assertIn("##source=VarScan2", metaheaders)
        self.assertIn("##jacquard.translate.caller=VarScan", metaheaders)
Example #16
0
    def test_vcf_records_newTagsPresent(self):
        record1 = vcf.VcfRecord(chrom="chr1",
                                pos="21",
                                ref="A",
                                alt="G",
                                sample_tag_values={
                                    "sampleA": {
                                        "DP2": "45"
                                    },
                                    "sampleB": {
                                        "DP2": "67"
                                    }
                                })
        record2 = vcf.VcfRecord(chrom="chr1",
                                pos="22",
                                ref="A",
                                alt="G",
                                sample_tag_values={
                                    "sampleA": {
                                        "TIR": "10,20",
                                        "DP2": "100"
                                    },
                                    "sampleB": {
                                        "TIR": "15,25",
                                        "DP2": "100"
                                    }
                                })
        vcf_reader = MockVcfReader(records=[record1, record2])

        strelka_vcf_reader = strelka._StrelkaVcfReader(vcf_reader)
        vcf_records = [record for record in strelka_vcf_reader.vcf_records()]

        self.assertEquals(2, len(vcf_records))

        self.assertIn("DP2", vcf_records[0].format_tags)
        self.assertIn(strelka.JQ_STRELKA_TAG + "DP",
                      vcf_records[0].format_tags)
        self.assertIn(strelka.JQ_STRELKA_TAG + "HC_SOM",
                      vcf_records[0].format_tags)
        self.assertIn(strelka.JQ_STRELKA_TAG + "CALLER_REPORTED",
                      vcf_records[0].format_tags)
        self.assertIn(strelka.JQ_STRELKA_TAG + "CALLER_PASSED",
                      vcf_records[0].format_tags)

        self.assertIn("TIR", vcf_records[1].format_tags)
        self.assertIn(strelka.JQ_STRELKA_TAG + "AF",
                      vcf_records[1].format_tags)
        self.assertIn(strelka.JQ_STRELKA_TAG + "HC_SOM",
                      vcf_records[1].format_tags)
        self.assertIn(strelka.JQ_STRELKA_TAG + "CALLER_REPORTED",
                      vcf_records[1].format_tags)
        self.assertIn(strelka.JQ_STRELKA_TAG + "CALLER_PASSED",
                      vcf_records[1].format_tags)
Example #17
0
    def test_common_metaheaders(self):
        vcf_reader = MockVcfReader(
            metaheaders=["##foo", "##MuTect=123", '##FORMAT=<ID=FA,...>'])
        mutect_vcf_reader = mutect._MutectVcfReader(vcf_reader)
        metaheaders = mutect_vcf_reader.metaheaders

        self.assertIn(
            mutect._AlleleFreqTag(vcf_reader.metaheaders).metaheader,
            metaheaders)
        self.assertIn(mutect._DepthTag().metaheader, metaheaders)
        self.assertIn("##foo", metaheaders)
        self.assertIn("##MuTect=123", metaheaders)
        self.assertIn("##jacquard.translate.caller=MuTect", metaheaders)
Example #18
0
 def test_write_metaheaders(self):
     file_writer = MockFileWriter()
     vcf_reader = MockVcfReader(column_header="#header")
     caller = MockSummarizeCaller(["##summarize_metaheader"])
     summarize._write_metaheaders(caller,
                                  vcf_reader,
                                  file_writer,
                                  ["##execution_context"])
     expected = ["##execution_context",
                 "##metaheaders",
                 "##summarize_metaheader",
                 "#header"]
     self.assertEquals(expected, file_writer.lines())
Example #19
0
    def test_vcf_records_newTagsPresent(self):
        record1 = vcf.VcfRecord(chrom="chr1",
                                pos="21",
                                ref="A",
                                alt="G",
                                sample_tag_values={
                                    "sampleA": {
                                        "DP": "45"
                                    },
                                    "sampleB": {
                                        "DP": "67"
                                    }
                                })
        record2 = vcf.VcfRecord(chrom="chr1",
                                pos="22",
                                ref="A",
                                alt="G",
                                sample_tag_values={
                                    "sampleA": {
                                        "FREQ": "46%"
                                    },
                                    "sampleB": {
                                        "FREQ": "68%"
                                    }
                                })
        vcf_reader = MockVcfReader(records=[record1, record2])

        varscan_vcf_reader = varscan._VarscanVcfReader(vcf_reader)
        vcf_records = [record for record in varscan_vcf_reader.vcf_records()]

        self.assertEquals(2, len(vcf_records))

        self.assertIn("DP", vcf_records[0].format_tags)
        self.assertIn(varscan.JQ_VARSCAN_TAG + "DP",
                      vcf_records[0].format_tags)
        self.assertIn(varscan.JQ_VARSCAN_TAG + "HC_SOM",
                      vcf_records[0].format_tags)
        self.assertIn(varscan.JQ_VARSCAN_TAG + "CALLER_REPORTED",
                      vcf_records[0].format_tags)
        self.assertIn(varscan.JQ_VARSCAN_TAG + "CALLER_PASSED",
                      vcf_records[0].format_tags)

        self.assertIn("FREQ", vcf_records[1].format_tags)
        self.assertIn(varscan.JQ_VARSCAN_TAG + "AF",
                      vcf_records[1].format_tags)
        self.assertIn(varscan.JQ_VARSCAN_TAG + "HC_SOM",
                      vcf_records[1].format_tags)
        self.assertIn(varscan.JQ_VARSCAN_TAG + "CALLER_REPORTED",
                      vcf_records[1].format_tags)
        self.assertIn(varscan.JQ_VARSCAN_TAG + "CALLER_PASSED",
                      vcf_records[1].format_tags)
Example #20
0
    def test_vcf_records_newTagsPresent(self):
        record1 = vcf.VcfRecord(chrom="chr1",
                                pos="21",
                                ref="A",
                                alt="G",
                                sample_tag_values={
                                    "sampleA": {
                                        "DP": "45"
                                    },
                                    "sampleB": {
                                        "DP": "67"
                                    }
                                })
        record2 = vcf.VcfRecord(chrom="chr1",
                                pos="22",
                                ref="A",
                                alt="G",
                                sample_tag_values={
                                    "sampleA": {
                                        "FA": "0.54"
                                    },
                                    "sampleB": {
                                        "FA": "0.76"
                                    }
                                })
        vcf_reader = MockVcfReader(metaheaders=['##FORMAT=<ID=FA,...>'],
                                   records=[record1, record2])

        mutect_vcf_reader = mutect._MutectVcfReader(vcf_reader)
        vcf_records = [record for record in mutect_vcf_reader.vcf_records()]

        self.assertEquals(2, len(vcf_records))

        self.assertIn("DP", vcf_records[0].format_tags)
        self.assertIn(mutect.JQ_MUTECT_TAG + "DP", vcf_records[0].format_tags)
        self.assertIn(mutect.JQ_MUTECT_TAG + "HC_SOM",
                      vcf_records[0].format_tags)
        self.assertIn(mutect.JQ_MUTECT_TAG + "CALLER_REPORTED",
                      vcf_records[0].format_tags)
        self.assertIn(mutect.JQ_MUTECT_TAG + "CALLER_PASSED",
                      vcf_records[0].format_tags)

        self.assertIn("FA", vcf_records[1].format_tags)
        self.assertIn(mutect.JQ_MUTECT_TAG + "AF", vcf_records[1].format_tags)
        self.assertIn(mutect.JQ_MUTECT_TAG + "HC_SOM",
                      vcf_records[1].format_tags)
        self.assertIn(mutect.JQ_MUTECT_TAG + "CALLER_REPORTED",
                      vcf_records[1].format_tags)
        self.assertIn(mutect.JQ_MUTECT_TAG + "CALLER_PASSED",
                      vcf_records[1].format_tags)
Example #21
0
 def test_translate_write_metaheaders_addsExecutionMetaheaders(self):
     writer = MockWriter()
     reader = MockVcfReader(metaheaders=["##mockCallerMetaheader1"],
                            column_header="#CHROM\tPOS\tREF\tALT\tStuff")
     execution_context = ["##foo1=bar", "##foo2=baz"]
     new_tags = [
         MockTag(metaheader="##newTag1"),
         MockTag(metaheader="##newTag2")
     ]
     translate._write_headers(reader, new_tags, execution_context, writer)
     expected_headers = [
         "##foo1=bar", "##foo2=baz", "##mockCallerMetaheader1", "##newTag1",
         "##newTag2", "#CHROM\tPOS\tREF\tALT\tStuff"
     ]
     self.assertEquals(expected_headers, writer._content)
Example #22
0
    def test_column_header_mangleSampleNameMutect2IgnoresHelpFlag(self):
        column_header = self.entab(
            "#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|25714|25715")
        metaheaders = [
            '##GATKCommandLine=<ID=Mutect2,CommandLine="Mutect2  --tumor-sample 25715 --normal-sample 25714 --help false",Date="recent">',
            '##FORMAT=<ID=FA,...>',
        ]
        vcf_reader = MockVcfReader(metaheaders=metaheaders,
                                   column_header=column_header)

        mutect_vcf_reader = mutect._MutectVcfReader(vcf_reader)

        expected_column_header = self.entab(
            "#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|NORMAL|TUMOR")

        self.assertEquals(expected_column_header,
                          mutect_vcf_reader.column_header)
Example #23
0
    def test_column_header_mangleSampleNameMutect1(self):
        column_header = self.entab(
            "#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|25714|25715")
        metaheaders = [
            '##MuTect="123 tumor_sample_name=25715 normal_sample_name=25714"',
            '##FORMAT=<ID=FA,...>',
        ]
        vcf_reader = MockVcfReader(metaheaders=metaheaders,
                                   column_header=column_header)

        mutect_vcf_reader = mutect._MutectVcfReader(vcf_reader)

        expected_column_header = self.entab(
            "#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|NORMAL|TUMOR")

        self.assertEquals(expected_column_header,
                          mutect_vcf_reader.column_header)
Example #24
0
    def test_translate_files(self):
        record = vcf.VcfRecord("chr1",
                               "42",
                               "A",
                               "C",
                               sample_tag_values=OrderedDict(
                                   sorted({
                                       "SA": OrderedDict(),
                                       "SB": OrderedDict()
                                   }.items())))
        reader = MockVcfReader(metaheaders=["##metaheader1", "##metaheader2"],
                               records=[record],
                               sample_names=["SA", "SB"])
        writer = MockWriter()
        execution_context = []
        new_tags = [
            MockTag("TAG1",
                    OrderedDict(sorted({
                        "SA": 42,
                        "SB": 43
                    }.items())),
                    metaheader="##newTag1"),
            MockTag("TAG2",
                    OrderedDict(sorted({
                        "SA": 420,
                        "SB": 430
                    }.items())),
                    metaheader="##newTag2")
        ]
        translate._translate_files(reader, new_tags, execution_context, writer)

        self.assertTrue(reader.opened)
        self.assertTrue(writer.opened)
        expected = [
            '##metaheader1', '##metaheader2', '##newTag1', '##newTag2',
            '#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tNORMAL\tTUMOR'
        ]
        self.assertEquals(expected, writer._content[0:5])
        self.assertRegexpMatches(writer._content[5], "TAG1:TAG2")
        self.assertRegexpMatches(writer._content[5], "42:420")
        self.assertRegexpMatches(writer._content[5], "43:430")

        self.assertTrue(reader.closed)
        self.assertTrue(writer.closed)
Example #25
0
    def test_init_metaheaders(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "JQ_SUMMARY_DP_RANGE": "4"
                                 },
                                 "SB": {
                                     "JQ_SUMMARY_DP_RANGE": "7"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "JQ_SUMMARY_DP_RANGE": "13"
                                 },
                                 "SB": {
                                     "JQ_SUMMARY_DP_RANGE": "16"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])

        tag = zscore_caller._DepthZScoreTag(reader)

        self.assertEquals(3, len(tag.metaheaders))
        it = iter(tag.metaheaders)
        self.assertRegexpMatches(
            next(it),
            '##jacquard.summarize.JQ_SUMMARY_DP_ZSCORE.JQ_SUMMARY_DP_RANGE_mean='
        )
        self.assertRegexpMatches(
            next(it),
            '##jacquard.summarize.JQ_SUMMARY_DP_ZSCORE.JQ_SUMMARY_DP_RANGE_stdev='
        )
        self.assertRegexpMatches(
            next(it),
            '##FORMAT=<ID=JQ_SUMMARY_DP_ZSCORE,Number=1,Type=Float,Description="Concordance of reported depth.*">'
        )
Example #26
0
    def test_init_metaheaders(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "4"
                                 },
                                 "SB": {
                                     "X": "7"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "13"
                                 },
                                 "SB": {
                                     "X": "16"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])

        tag = zscore_caller._ZScoreTag(
            "ZScoreX",
            '##FORMAT=<ID=ZScoreX,Number=1,Type=Float,Description="ZScore for X">',
            "X", reader)

        self.assertEquals(3, len(tag.metaheaders))
        it = iter(tag.metaheaders)
        self.assertEquals(
            next(it), '##jacquard.summarize.ZScoreX.X_mean=' + repr(tag._mean))
        self.assertEquals(
            next(it),
            '##jacquard.summarize.ZScoreX.X_stdev=' + repr(tag._stdev))
        self.assertRegexpMatches(
            next(it),
            '##FORMAT=<ID=ZScoreX,Number=1,Type=Float,Description="ZScore for X">'
        )
Example #27
0
    def test_add_tags(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "X": "4"
                                 },
                                 "SB": {
                                     "X": "7"
                                 }
                             })
        reader = MockVcfReader(records=[rec1])

        caller = zscore_caller.ZScoreCaller(reader)
        caller._tags = [MockTag("Y", {"SA": "A42", "SB": "B42"})]
        caller.add_tags(rec1)

        self.assertEquals({"X": "4", "Y": "A42"}, rec1.sample_tag_values["SA"])
Example #28
0
    def test_create_potential_column_list_preservesSampleOrdering(self):
        metaheaders = ['##FORMAT=<ID=B,Number=1>', '##FORMAT=<ID=A,Number=1>']
        sample_names = ["sample1", "sample2", "sample10"]
        column_header = self.entab("#chrom|pos|id|ref|alt|"
                                   "qual|filter|info|format|"
                                   "sample1|sample2|sample10")

        mock_vcf_reader = MockVcfReader(metaheaders=metaheaders,
                                        column_header=column_header,
                                        sample_names=sample_names)

        actual_cols = expand._create_potential_column_list(mock_vcf_reader)
        actual_format_sample_names = list(actual_cols.keys())[8:]

        expected_format_sample_names = [
            "A|sample1", "A|sample2", "A|sample10", "B|sample1", "B|sample2",
            "B|sample10"
        ]
        self.assertEquals(expected_format_sample_names,
                          actual_format_sample_names)
Example #29
0
    def test_init_createsAllMetaheaders(self):
        rec1 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "JQ_SUMMARY_AF_RANGE": "4"
                                 },
                                 "SB": {
                                     "JQ_SUMMARY_AF_RANGE": "7"
                                 }
                             })
        rec2 = vcf.VcfRecord("1",
                             "42",
                             "A",
                             "C",
                             sample_tag_values={
                                 "SA": {
                                     "JQ_SUMMARY_AF_RANGE": "13"
                                 },
                                 "SB": {
                                     "JQ_SUMMARY_AF_RANGE": "16"
                                 }
                             })
        reader = MockVcfReader(records=[rec1, rec2])

        caller = zscore_caller.ZScoreCaller(reader)

        self.assertEquals(6, len(caller.metaheaders))
        it = iter(caller.metaheaders)
        self.assertRegexpMatches(
            next(it), "JQ_SUMMARY_AF_ZSCORE.JQ_SUMMARY_AF_RANGE_mean")
        self.assertRegexpMatches(
            next(it), "JQ_SUMMARY_AF_ZSCORE.JQ_SUMMARY_AF_RANGE_stdev")
        self.assertRegexpMatches(next(it), "FORMAT=<ID=JQ_SUMMARY_AF_ZSCORE")
        self.assertRegexpMatches(
            next(it), "JQ_SUMMARY_DP_ZSCORE.JQ_SUMMARY_DP_RANGE_mean")
        self.assertRegexpMatches(
            next(it), "JQ_SUMMARY_DP_ZSCORE.JQ_SUMMARY_DP_RANGE_stdev")
        self.assertRegexpMatches(next(it), "FORMAT=<ID=JQ_SUMMARY_DP_ZSCORE")
Example #30
0
    def test_column_header_mangleSampleNameMutect2UsesSampleMetalinesIfAvailable(
            self):
        column_header = self.entab(
            "#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|25714|25715")
        meta_header = '''
##GATKCommandLine=<ID=Mutect2,CommandLine="Mutect2  --tumor-sample A --normal-sample B",Date="recent">'
##FORMAT=<ID=FA,...>
##foo=42
##SAMPLE=<ID=NORMAL,SampleName=25714,File=foo.bam>
##SAMPLE=<ID=TUMOR,SampleName=25715,File=bar.bam>
##baz=42
'''
        vcf_reader = MockVcfReader(metaheaders=meta_header.strip().split('\n'),
                                   column_header=column_header)
        mutect_vcf_reader = mutect._MutectVcfReader(vcf_reader)

        expected_column_header = self.entab(
            "#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|NORMAL|TUMOR")

        self.assertEquals(expected_column_header,
                          mutect_vcf_reader.column_header)