Skip to content

Commit

Permalink
Simplify VCF reader logic
Browse files Browse the repository at this point in the history
Remove distinction between present with missing value, versus missing
  • Loading branch information
jeromekelleher authored and mergify[bot] committed Mar 5, 2024
1 parent ec365f0 commit 6b10a77
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions sgkit/io/vcf/vcf_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit 6b10a77

Please sign in to comment.