Skip to content

Commit

Permalink
Populate null values for haploid chromosomes
Browse files Browse the repository at this point in the history
  • Loading branch information
apriha committed Aug 25, 2024
1 parent 9e5e5f7 commit bfe1e90
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/snps/io/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ def _write_vcf(self):
if self._vcf_qc_only or self._vcf_qc_filter
else get_empty_snps_dataframe()
),
"sex": self._snps.determine_sex(),
}
)

Expand Down Expand Up @@ -288,6 +289,7 @@ def _create_vcf_representation(self, task):
snps = task["snps"]
cluster = task["cluster"]
low_quality_snps = task["low_quality_snps"]
sex = task["sex"]

if len(snps.loc[snps["genotype"].notnull()]) == 0:
return {
Expand Down Expand Up @@ -377,6 +379,18 @@ def _create_vcf_representation(self, task):
self._compute_genotype
)(temp["REF"], temp["ALT"], temp["genotype"])

if sex == "Female":
haploid_chroms = ["Y", "MT"]
else:
haploid_chroms = ["X", "Y", "MT"]

# populate null values for haploid chromosomes
df.loc[
(df["SAMPLE"].isnull())
& (df["CHROM"].str.contains("|".join(haploid_chroms))),
"SAMPLE",
] = "."

df.loc[df["SAMPLE"].isnull(), "SAMPLE"] = "./."

del df["genotype"]
Expand Down

0 comments on commit bfe1e90

Please sign in to comment.