Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vcf/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def __repr__(self):
def make_calldata_tuple(fields):
""" Return a namedtuple for a given call format """

class CallData(collections.namedtuple('calldata', fields)):
class CallData(collections.namedtuple('calldata', fields, rename=True)):
__slots__ = ()

_types = []
Expand Down
2 changes: 2 additions & 0 deletions vcf/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,8 @@ def _parse_samples(self, samples, samp_fmt, site):
sampdat = [None] * nfields

for i, vals in enumerate(sample.split(':')):
if i >= nfields:
break

# short circuit the most common
if samp_fmt._fields[i] == 'GT':
Expand Down
7 changes: 7 additions & 0 deletions vcf/test/issue_298.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT sample1
chr1 123123123 . A C . . . . 1:2
chr1 123123123 . A C . . . A 1:2
chr1 123123123 . A C . . . A:B 1:2
chr1 123123123 . A C . . . A:B:C 1:2
chr1 123123123 . A C . . . :: 1:2
chr1 123123123 . A C . . . -invalid!:B:C 1:2
12 changes: 12 additions & 0 deletions vcf/test/test_vcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,17 @@ def test_strelka(self):
n = next(reader)
assert n is not None

class TestIssue298(unittest.TestCase):
def test_issue_298(self):
records = list(vcf.Reader(fh('issue_298.vcf')))
assert len(records) == 6

assert not records[0].samples
assert records[1].samples and tuple(records[1].samples[0].data) == (['1'],), records[1].samples
assert records[2].samples and tuple(records[2].samples[0].data) == (['1'], ['2']), records[2].samples
assert records[3].samples and tuple(records[3].samples[0].data) == (['1'], ['2'], None), records[3].samples
assert records[4].samples and tuple(records[4].samples[0].data) == (['1'], ['2'], None), records[4].samples
assert records[5].samples and tuple(records[5].samples[0].data) == (['1'], ['2'], None), records[5].samples

suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestVcfSpecs))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestGatkOutput))
Expand Down Expand Up @@ -1753,3 +1764,4 @@ def test_strelka(self):
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestUncalledGenotypes))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestStrelka))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestBadInfoFields))
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestIssue298))