Skip to content
Browse files

Merge pull request #72 from martijnvermaat/missing-gt

Write record without crashing on missing GT
  • Loading branch information...
2 parents 2a728f4 + 8f3c0a9 commit 964c37245e2928a38991535ed3a71a1ce70185a8 James Casbon committed Sep 23, 2012
Showing with 30 additions and 3 deletions.
  1. +1 −1 vcf/parser.py
  2. +29 −2 vcf/test/test_vcf.py
View
2 vcf/parser.py
@@ -591,7 +591,7 @@ def _format_info(self, info):
return ';'.join([self._stringify_pair(x,y) for x, y in info.iteritems()])
def _format_sample(self, fmt, sample):
- if sample.data.GT is None:
+ if getattr(sample.data, 'GT', None) is None:
return "./."
return ':'.join([self._stringify(x) for x in sample.data])
View
31 vcf/test/test_vcf.py
@@ -205,7 +205,7 @@ def test_issue_49(self):
pass
-class TestWriter(unittest.TestCase):
+class TestGatkOutputWriter(unittest.TestCase):
def testWrite(self):
@@ -228,6 +228,31 @@ def testWrite(self):
for l, r in zip(records, reader2):
self.assertEquals(l.samples, r.samples)
+
+class TestBcfToolsOutputWriter(unittest.TestCase):
+
+ def testWrite(self):
+
+ reader = vcf.Reader(fh('bcftools.vcf'))
+ out = StringIO()
+ writer = vcf.Writer(out, reader)
+
+ records = list(reader)
+
+ for record in records:
+ writer.write_record(record)
+ out.seek(0)
+ print (out.getvalue())
+ reader2 = vcf.Reader(out)
+
+ self.assertEquals(reader.samples, reader2.samples)
+ self.assertEquals(reader.formats, reader2.formats)
+ self.assertEquals(reader.infos, reader2.infos)
+
+ for l, r in zip(records, reader2):
+ self.assertEquals(l.samples, r.samples)
+
+
class TestRecord(unittest.TestCase):
def test_num_calls(self):
@@ -757,7 +782,9 @@ def test_trim(self):
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestGatkOutput))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestFreebayesOutput))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestSamtoolsOutput))
-suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestWriter))
+suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestBcfToolsOutput))
+suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestGatkOutputWriter))
+suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestBcfToolsOutputWriter))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestTabix))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestOpenMethods))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestFilter))

0 comments on commit 964c372

Please sign in to comment.
Something went wrong with that request. Please try again.