Permalink
Browse files

Correctly format contig output lines from writer, making output VCFs …

…compatible with GATK. Fixes #74
  • Loading branch information...
1 parent 95fd749 commit 8acaeb3a151a18385748d82ea1fa7310d0a9da4e @chapmanb chapmanb committed Dec 26, 2012
Showing with 10 additions and 2 deletions.
  1. +5 −1 vcf/parser.py
  2. +5 −1 vcf/test/test_vcf.py
View
@@ -549,12 +549,16 @@ def __init__(self, stream, template, lineterminator="\r\n"):
two = '##{key}=<ID={0},Description="{1}">\n'
four = '##{key}=<ID={0},Number={num},Type={2},Description="{3}">\n'
+ contig_format = '##contig=<ID={ID},length={length},assembly={assembly}>\n'
_num = self._fix_field_count
for (key, vals) in template.metadata.iteritems():
if key in SINGULAR_METADATA:
vals = [vals]
for val in vals:
- stream.write('##{0}={1}\n'.format(key, val))
+ if key == "contig":
+ stream.write(contig_format.format(**val))
+ else:
+ stream.write('##{0}={1}\n'.format(key, val))
for line in template.infos.itervalues():
stream.write(four.format(key="INFO", *line, num=_num(line.num)))
for line in template.formats.itervalues():
@@ -218,7 +218,11 @@ def testWrite(self):
for record in records:
writer.write_record(record)
out.seek(0)
- print (out.getvalue())
+ out_str = out.getvalue()
+ for line in out_str.split("\n"):
+ if line.startswith("##contig"):
+ assert "<ID=" in line, "Found dictionary in contig line: {0}".format(line)
+ print (out_str)
reader2 = vcf.Reader(out)
self.assertEquals(reader.samples, reader2.samples)

0 comments on commit 8acaeb3

Please sign in to comment.