Permalink
Browse files

Merge pull request #76 from seandavi/master

vcf_melt script now deals with missing format fields
  • Loading branch information...
2 parents 5da6932 + 5b86e30 commit 9b9194d95089963f9052b2e566414537db8ce55a James Casbon committed Oct 26, 2012
Showing with 12 additions and 2 deletions.
  1. +3 −1 scripts/vcf_melt
  2. +9 −1 vcf/utils.py
View
@@ -39,7 +39,9 @@ for record in reader:
for sample in record.samples:
row = [sample.sample]
- row += [flatten(getattr(sample.data, x)) for x in formats]
+ # Format fields not present will simply end up "blank"
+ # in the output
+ row += [flatten(getattr(sample.data, x, None)) for x in formats]
row += [record.FILTER or '.']
row += fixed
row += info_row
View
@@ -10,7 +10,15 @@ def walk_together(*readers):
inputs are sorted in the same way and use the same reference
otherwise behaviour is undefined.
"""
- nexts = [reader.next() for reader in readers]
+ # if one of the VCFs has no records, StopIteration is
+ # raised immediately, so we need to check for that and
+ # deal appropriately
+ nexts = []
+ for reader in readers:
+ try:
+ nexts.append(reader.next())
+ except StopIteration:
+ nexts.append(None)
while True:
min_next = min([x for x in nexts if x is not None])

0 comments on commit 9b9194d

Please sign in to comment.