예제 #1
0
def run_genotype_filters(in_fhand,
                         out_fhand,
                         gt_filters,
                         plots_dir=None,
                         reader_kwargs=None):
    if reader_kwargs is None:
        reader_kwargs = {}

    reader_kwargs['filename'] = 'pyvcf_bug_workaround'
    reader_kwargs['compressed'] = False
    reader = VCFReader(in_fhand, **reader_kwargs)

    templa_reader = VCFReader(StringIO(reader.header))
    writer = VCFWriter(out_fhand, template_reader=templa_reader)

    for snv in reader.parse_snvs():
        for mapper in gt_filters:
            snv = mapper(snv)
        try:
            writer.write_snv(snv)
        except IOError, error:
            # The pipe could be already closed
            if 'Broken pipe' in str(error):
                break
            else:
                raise
예제 #2
0
 def test_vcf_writer(self):
     varscan = open(join(TEST_DATA_DIR, 'vari_filter.vcf'))
     reader = VCFReader(fhand=varscan)
     out_fhand = NamedTemporaryFile()
     writer = VCFWriter(out_fhand, reader)
     for snv in reader.parse_snvs():
         writer.write_snv(snv)
     writer.flush()
     assert 'CUUC00027_TC01' in open(out_fhand.name).read()
     writer.close()
예제 #3
0
    def test_het_unknown(self):
        vcf = '''#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT 1 2 3 4 5 6 7 8
20\t2\t.\tG\tA\t29\tPASS\tNS=3\tGT\t0/0\t0/0\t0/0\t0/0\t1/1\t1/1\t./.\t1/.\t
'''
        vcf = StringIO(VCF_HEADER + vcf)
        reader = VCFReader(vcf)
        snps = list(reader.parse_snvs())
        snp = snps[0]
        expected = [[0, 0], [0, 0], [0, 0], [0, 0], [1, 1], [1, 1], [],
                    [1, None]]
        assert [call.int_alleles for call in snps[0].calls] == expected
        assert snp.num_called == 7
        out_fhand = StringIO()
        writer = VCFWriter(out_fhand, reader)
        for snv in snps:
            writer.write_snv(snv)
        assert '1/1\t./.\t1/.' in out_fhand.getvalue()
예제 #4
0
def run_genotype_filters(in_fhand, out_fhand, gt_filters, plots_dir=None, reader_kwargs=None):
    if reader_kwargs is None:
        reader_kwargs = {}

    reader_kwargs["filename"] = "pyvcf_bug_workaround"
    reader_kwargs["compressed"] = False
    reader = VCFReader(in_fhand, **reader_kwargs)

    templa_reader = VCFReader(StringIO(reader.header))
    writer = VCFWriter(out_fhand, template_reader=templa_reader)

    for snv in reader.parse_snvs():
        for mapper in gt_filters:
            snv = mapper(snv)
        try:
            writer.write_snv(snv)
        except IOError, error:
            # The pipe could be already closed
            if "Broken pipe" in str(error):
                break
            else:
                raise