Example #1
0
    def test_vcf_records_raisesStopIterationWhenExhausted(self):
        file_contents = [
            "##metaheader1\n",
            self.entab("#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|SampleNormal|SampleTumor\n"),
            self.entab("chr1|1|.|A|C|.|.|INFO|FORMAT|NORMAL|TUMOR\n"),
        ]
        mock_reader = MockFileReader("my_dir/my_file.txt", file_contents)
        reader = VcfReader(mock_reader)

        reader.open()
        record_iter = reader.vcf_records()
        next(record_iter)
        self.assertRaises(StopIteration, next, record_iter)
Example #2
0
    def test_vcf_records_raisesStopIterationWhenExhausted(self):
        file_contents = [
            "##metaheader1\n",
            self.entab(
                "#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|SampleNormal|SampleTumor\n"
            ),
            self.entab("chr1|1|.|A|C|.|.|INFO|FORMAT|NORMAL|TUMOR\n")
        ]
        mock_reader = MockFileReader("my_dir/my_file.txt", file_contents)
        reader = VcfReader(mock_reader)

        reader.open()
        record_iter = reader.vcf_records()
        next(record_iter)
        self.assertRaises(StopIteration, next, record_iter)
Example #3
0
    def test_vcf_records(self):
        file_contents = [
            "##metaheader1\n",
            "##metaheader2\n",
            self.entab("#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|SampleNormal|SampleTumor\n"),
            self.entab("chr1|1|.|A|C|.|.|INFO|FORMAT|NORMAL|TUMOR\n"),
            self.entab("chr2|1|.|A|C|.|.|INFO|FORMAT|NORMAL|TUMOR"),
        ]
        mock_reader = MockFileReader("my_dir/my_file.txt", file_contents)
        reader = VcfReader(mock_reader)

        actual_vcf_records = []
        reader.open()
        for vcf_record in reader.vcf_records():
            actual_vcf_records.append(vcf_record)
        reader.close()

        self.assertEquals(2, len(actual_vcf_records))
        self.assertEquals("chr1", actual_vcf_records[0].chrom)
        self.assertEquals("chr2", actual_vcf_records[1].chrom)
        self.assertTrue(mock_reader.open_was_called)
        self.assertTrue(mock_reader.close_was_called)
Example #4
0
    def test_vcf_records(self):
        file_contents = [
            "##metaheader1\n", "##metaheader2\n",
            self.entab(
                "#CHROM|POS|ID|REF|ALT|QUAL|FILTER|INFO|FORMAT|SampleNormal|SampleTumor\n"
            ),
            self.entab("chr1|1|.|A|C|.|.|INFO|FORMAT|NORMAL|TUMOR\n"),
            self.entab("chr2|1|.|A|C|.|.|INFO|FORMAT|NORMAL|TUMOR")
        ]
        mock_reader = MockFileReader("my_dir/my_file.txt", file_contents)
        reader = VcfReader(mock_reader)

        actual_vcf_records = []
        reader.open()
        for vcf_record in reader.vcf_records():
            actual_vcf_records.append(vcf_record)
        reader.close()

        self.assertEquals(2, len(actual_vcf_records))
        self.assertEquals('chr1', actual_vcf_records[0].chrom)
        self.assertEquals('chr2', actual_vcf_records[1].chrom)
        self.assertTrue(mock_reader.open_was_called)
        self.assertTrue(mock_reader.close_was_called)