Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial changes for VCF Character S->U #1208

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions sgkit/io/vcf/vcf_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def _vcf_type_to_numpy(
elif vcf_type == "Float":
return "f4", FLOAT32_MISSING, FLOAT32_FILL
elif vcf_type == "Character":
return "S1", CHAR_MISSING, CHAR_FILL
return "U1", CHAR_MISSING, CHAR_FILL
elif vcf_type == "String":
return "O", STR_MISSING, STR_FILL
raise ValueError(
Expand All @@ -188,7 +188,7 @@ def _vcf_type_to_numpy(

def _is_str_or_char(array: ArrayLike) -> bool:
"""Return True if the array is of string or character type"""
return array.dtype.kind in ("O", "S", "U")
return array.dtype.kind in ("O", "U")


class VcfFieldHandler:
Expand Down
8 changes: 5 additions & 3 deletions sgkit/io/vcf/vcf_writer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
FLOAT32_MISSING_AS_INT32,
INT_FILL,
INT_MISSING,
STR_MISSING,
)

COLON = ord(":")
Expand Down Expand Up @@ -316,7 +317,8 @@ def vcf_values_to_byte_buf_size(a):
elif a.dtype == np.float32:
# values + separators
return a.size * FLOAT32_BUF_SIZE + a.size
elif a.dtype.kind == "S":
elif a.dtype.kind == "U":
# NOTE! Assuming UTF-8 here?
# values + separators
return a.size * a.dtype.itemsize + a.size
else:
Expand Down Expand Up @@ -502,8 +504,8 @@ def create_mask(arr):
return np.all(arr == INT_MISSING, axis=axis)
elif arr.dtype == np.float32:
return np.all(arr.view("i4") == FLOAT32_MISSING_AS_INT32, axis=axis)
elif arr.dtype.kind == "S":
return np.all(arr == STR_MISSING_BYTE, axis=axis)
elif arr.dtype.kind == "U":
return np.all(arr == STR_MISSING, axis=axis)
else:
raise ValueError(f"Unsupported dtype: {arr.dtype}")

Expand Down
Loading