Skip to content
This repository
Browse code

Merge pull request #76 from seandavi/master

vcf_melt script now deals with missing format fields
  • Loading branch information...
commit 9b9194d95089963f9052b2e566414537db8ce55a 2 parents 5da6932 + 5b86e30
James Casbon authored

Showing 2 changed files with 12 additions and 2 deletions. Show diff stats Hide diff stats

  1. +3 1 scripts/vcf_melt
  2. +9 1 vcf/utils.py
4 scripts/vcf_melt
@@ -39,7 +39,9 @@ for record in reader:
39 39
40 40 for sample in record.samples:
41 41 row = [sample.sample]
42   - row += [flatten(getattr(sample.data, x)) for x in formats]
  42 + # Format fields not present will simply end up "blank"
  43 + # in the output
  44 + row += [flatten(getattr(sample.data, x, None)) for x in formats]
43 45 row += [record.FILTER or '.']
44 46 row += fixed
45 47 row += info_row
10 vcf/utils.py
@@ -10,7 +10,15 @@ def walk_together(*readers):
10 10 inputs are sorted in the same way and use the same reference
11 11 otherwise behaviour is undefined.
12 12 """
13   - nexts = [reader.next() for reader in readers]
  13 + # if one of the VCFs has no records, StopIteration is
  14 + # raised immediately, so we need to check for that and
  15 + # deal appropriately
  16 + nexts = []
  17 + for reader in readers:
  18 + try:
  19 + nexts.append(reader.next())
  20 + except StopIteration:
  21 + nexts.append(None)
14 22
15 23 while True:
16 24 min_next = min([x for x in nexts if x is not None])

0 comments on commit 9b9194d

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