Skip to content

Commit

Permalink
Do not fail if metadata cannot be read from VCF file
Browse files Browse the repository at this point in the history
For example after merging multiple VCF files with Plink
  • Loading branch information
HippocampusGirl committed Jan 25, 2024
1 parent 0dc1876 commit e2b68cc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/gwas/src/gwas/vcf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ def from_metadata_columns(
info[token] = value

is_imputed = "IMPUTED" in info_tokens
alternate_allele_frequency = float(info["AF"])
minor_allele_frequency = float(info["MAF"])
alternate_allele_frequency = float(info.get("AF", np.nan))
minor_allele_frequency = float(info.get("MAF", np.nan))

if is_imputed:
r_squared = float(info["R2"])
r_squared = float(info.get("R2", np.nan))
else:
r_squared = float(info["ER2"])
r_squared = float(info.get("ER2", np.nan))

return cls(
chromosome_to_int(chromosome),
Expand Down Expand Up @@ -205,7 +205,7 @@ def set_variants_from_cutoffs(
):
def greater_or_close(series: pd.Series, cutoff: float) -> npt.NDArray[np.bool_]:
value = np.asanyarray(series.values)
return (value >= cutoff) | np.isclose(value, cutoff)
return (value >= cutoff) | np.isclose(value, cutoff) | np.isnan(value)

allele_frequency_frame = self.vcf_variants[self.allele_frequency_columns].copy()
is_major = allele_frequency_frame.values > 0.5
Expand Down

0 comments on commit e2b68cc

Please sign in to comment.