Skip to content

Commit

Permalink
rescue size_factor if median is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed May 7, 2024
1 parent 509ad9e commit 255e5f6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 2 additions & 0 deletions bean/preprocessing/data_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def get_size_factor(self, X: np.array):
assert geom_mean_x.shape == (n_guides,)
norm_count = X / geom_mean_x[:, None]
size_factor = np.median(norm_count, axis=0)
if any(size_factor == 0):
size_factor = np.mean(norm_count, axis=0)
assert size_factor.shape == (n_samples,)
return size_factor

Expand Down
3 changes: 0 additions & 3 deletions bean/preprocessing/get_alpha0.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def get_fitted_alpha0(
sample_mask = torch.ones((n_reps, n_condits), device="cpu")
elif (sample_mask.sum(axis=0) == 0).any():
raise ValueError("Some bins have no data.")
print(sample_size_factors)
w = get_w(X + 1, sample_size_factors, sample_mask=sample_mask)
q = get_q(X + 1, sample_size_factors, sample_mask=sample_mask)
n = (
Expand All @@ -107,8 +106,6 @@ def get_fitted_alpha0(
print(
f"Cannot fit log(a0) ~ log(q): data too sparse ({len(y)} valid values)! Using pre-fitted values [b0, b1]={popt}"
)
print(n)
print(a0)
else:
popt, pcov = curve_fit(linear, x, y)
print("Linear fit of log(a0) ~ log(q): [b0, b1]={}, cov={}".format(popt, pcov))
Expand Down

0 comments on commit 255e5f6

Please sign in to comment.