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

Remove check on PL values when computing local alleles #285

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
30 changes: 0 additions & 30 deletions bio2zarr/vcf2zarr/icf.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,36 +540,6 @@ def bincount_nonzero(arr, *, minlength):
bincount_nonzero, axis=1, arr=depths, minlength=allele_count
)
allele_counts += depths_allele_counts
if "PL" in variant.FORMAT:
likelihoods = variant.format("PL")
likelihoods.clip(0, None, out=likelihoods)
# n is the indices of the nonzero likelihoods
n = np.tile(np.arange(likelihoods.shape[1]), (likelihoods.shape[0], 1))
assert n.shape == likelihoods.shape
n[likelihoods <= 0] = 0
ploidy = variant.ploidy

if ploidy == 1:
a = n
b = np.zeros_like(a)
elif ploidy == 2:
# We have n = b(b+1) / 2 + a
# We need to compute a and b
b = np.ceil(np.sqrt(2 * n + 9 / 4) - 3 / 2).astype(int)
a = (n - b * (b + 1) / 2).astype(int)
else:
# TODO: Handle all possible ploidy
raise ValueError(f"Cannot handle ploidy = {ploidy}")

a_counts = np.apply_along_axis(
np.bincount, axis=1, arr=a, minlength=allele_count
)
b_counts = np.apply_along_axis(
np.bincount, axis=1, arr=b, minlength=allele_count
)
assert a_counts.shape == b_counts.shape == allele_counts.shape
allele_counts += a_counts
allele_counts += b_counts

allele_counts[:, 0] = 0 # We don't count the reference allele
max_row_length = 1
Expand Down
Loading