From a652a0c31a1ddfad71acfa39f509bbe89984f423 Mon Sep 17 00:00:00 2001
From: Jerome Kelleher <jk@well.ox.ac.uk>
Date: Fri, 16 Feb 2024 12:21:17 +0000
Subject: [PATCH] Simplify VCF reader logic

Remove distinction between present with missing value, versus missing
---
 sgkit/io/vcf/vcf_reader.py | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/sgkit/io/vcf/vcf_reader.py b/sgkit/io/vcf/vcf_reader.py
index b1c401335..e9dfc88e9 100644
--- a/sgkit/io/vcf/vcf_reader.py
+++ b/sgkit/io/vcf/vcf_reader.py
@@ -278,17 +278,11 @@ class InfoAndFormatFieldHandler(VcfFieldHandler):
 
     def add_variant(self, i: int, variant: Any) -> None:
         if self.category == "INFO":
-            try:
-                val = variant.INFO[self.key]
-                present = True
-            except KeyError:
-                present, val = False, None
-
-            if present:
+            val = variant.INFO.get(self.key, None)
+            self.array[i] = self.missing_value
+            if val is not None:
                 assert self.array.ndim in (1, 2)
                 if self.array.ndim == 1:
-                    if val is None:
-                        val = self.missing_value
                     self.array[i] = val
                 elif self.array.ndim == 2:
                     self.array[i] = self.fill_value
@@ -300,11 +294,8 @@ def add_variant(self, i: int, variant: Any) -> None:
                                 v if v is not None else self.missing_value
                             )
                     except TypeError:  # val is a scalar
-                        self.array[i, 0] = (
-                            val if val is not None else self.missing_value
-                        )
-            else:
-                self.array[i] = self.missing_value
+                        self.array[i, 0] = val
+
         elif self.category == "FORMAT":
             val = variant.format(self.key)
             if val is not None: