Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

handle String INFO fields with multiple values

  • Loading branch information...
commit 4ce6aff3f6930660bcfe52cdf0e08ff53a9ec969 1 parent 53548b6
@alimanfoo alimanfoo authored
View
5 vcf/parser.py
@@ -323,12 +323,13 @@ def _parse_info(self, info_str):
val = True
elif entry_type == 'String':
try:
- val = entry[1]
+ vals = entry[1].split(',') # commas are reserved characters indicating multiple values
+ val = self._map(str, vals)
except IndexError:
val = True
try:
- if self.infos[ID].num == 1 and entry_type not in ( 'String', 'Flag'):
+ if self.infos[ID].num == 1 and entry_type not in ( 'Flag', ):
val = val[0]
except KeyError:
pass
View
7 vcf/test/example-4.1-info-multiple-values.vcf
@@ -0,0 +1,7 @@
+##fileformat=VCFv4.1
+##contig=<ID=Pf3D7_01_v3,length=640851>
+##INFO=<ID=RepeatCopies,Number=.,Type=Float,Description="Number of copies aligned with the consensus pattern">
+##INFO=<ID=RepeatSize,Number=.,Type=Integer,Description="Size of consensus pattern (may differ slightly from the period size)">
+##INFO=<ID=RepeatConsensus,Number=.,Type=String,Description="Repeat consensus sequence">
+#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT
+Pf3D7_01_v3 401 . C T 53.99 PASS RepeatCopies=19.3,47.4,14.0;RepeatSize=42,14,56;RepeatConsensus=TCTTATCTTCTTACTTTTCATTCCTTACTCTTACTTACTTAC,TTACTCTTACTTAC,TTACTCTTACTTACTTACTCTTACTTACTTACTCTTACTTACTTACTCTTATCTTC
View
16 vcf/test/test_vcf.py
@@ -571,6 +571,22 @@ def test_qual(self):
self.assertEqual(expected, qual)
self.assertEqual(type(expected), qtype)
+ def test_info_multiple_values(self):
+ reader = vcf.Reader(fh('example-4.1-info-multiple-values.vcf'))
+ var = reader.next()
+ # check Float type INFO field with multiple values
+ expected = [19.3, 47.4, 14.0]
+ actual = var.INFO['RepeatCopies']
+ self.assertEqual(expected, actual)
+ # check Integer type INFO field with multiple values
+ expected = [42, 14, 56]
+ actual = var.INFO['RepeatSize']
+ self.assertEqual(expected, actual)
+ # check String type INFO field with multiple values
+ expected = ['TCTTATCTTCTTACTTTTCATTCCTTACTCTTACTTACTTAC', 'TTACTCTTACTTAC', 'TTACTCTTACTTACTTACTCTTACTTACTTACTCTTACTTACTTACTCTTATCTTC']
+ actual = var.INFO['RepeatConsensus']
+ self.assertEqual(expected, actual)
+
class TestCall(unittest.TestCase):
Please sign in to comment.
Something went wrong with that request. Please try again.