Skip to content

Commit

Permalink
Explictly convert genotype store to int8, to preserve -1 (missing) va…
Browse files Browse the repository at this point in the history
…lues
  • Loading branch information
hyanwong authored and mergify[bot] committed Jul 24, 2024
1 parent 599920d commit 0c5d895
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tsinfer/algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ def get_site_genotypes_subset(self, site_id, samples):
g[j] = int((byte & mask) != 0)
else:
for j, u in enumerate(samples):
g[j] = self.genotype_store[start + u]
# NB missing data (-1) is stored as 255 in the genotype_store
g[j] = self.genotype_store[start + u].astype(np.int8)
gp = self.get_site_genotypes(site_id)
np.testing.assert_array_equal(gp[samples], g)
return g
Expand All @@ -129,6 +130,8 @@ def store_site_genotypes(self, site_id, genotypes):
if self.genotype_encoding == constants.GenotypeEncoding.ONE_BIT:
assert np.all(genotypes >= 0) and np.all(genotypes <= 1)
genotypes = np.packbits(genotypes, bitorder="little")
else:
assert np.all(genotypes <= 127)
start = site_id * self.encoded_genotypes_size
stop = start + self.encoded_genotypes_size
self.genotype_store[start:stop] = genotypes
Expand Down

0 comments on commit 0c5d895

Please sign in to comment.