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

Ensure INFO and FORMAT keys are unique ignoring case #4

Merged
merged 1 commit into from
Jul 9, 2024
Merged
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
15 changes: 8 additions & 7 deletions hypothesis_vcf/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ def get_header(self):
"SOMATIC",
"VALIDATED",
"1000G",
# conflicts with 'variant_id' variable; see RESERVED_VARIABLE_NAMES in sgkit
"id",
]

# [Table 2: Reserved genotype keys]
Expand Down Expand Up @@ -101,9 +99,10 @@ def vcf_field_keys(category):
field_key_regex = r"[A-Za-z_][0-9A-Za-z_.]"

def is_reserved_key(key):
return (category == "INFO" and key in RESERVED_INFO_KEYS) or (
category == "FORMAT" and key in RESERVED_FORMAT_KEYS
)
# 'id' is reserved since it conflicts with 'variant_id' variable in VCF Zarr
return (
category == "INFO" and key in RESERVED_INFO_KEYS or key.lower() == "id"
) or (category == "FORMAT" and key in RESERVED_FORMAT_KEYS)

return from_regex(field_key_regex, fullmatch=True).filter(
lambda key: not is_reserved_key(key)
Expand Down Expand Up @@ -275,18 +274,20 @@ def vcf(
-------
A Hypothesis strategy to generate a VCF file, including header, as a string.
"""
# ensure INFO and FORMAT keys are unique ignoring case to avoid macOS filesystem
# case-sensitivity issue for VCF Zarr
info_fields = draw(
lists(
vcf_fields("INFO", max_number=max_number),
max_size=max_info_fields,
unique_by=lambda f: f.vcf_key,
unique_by=lambda f: f.vcf_key.lower(),
)
)
format_fields = draw(
lists(
vcf_fields("FORMAT", max_number=max_number),
max_size=max_format_fields,
unique_by=lambda f: f.vcf_key,
unique_by=lambda f: f.vcf_key.lower(),
)
)
sample_ids = draw(
Expand Down