Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions bartab/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,18 @@ def compute_log_ratios(
raise ValueError("No t0 samples found")

log_X = np.log(X) # (n_strains, n_samples)
log_ref = np.log(np.sum(X[ref_mask, :], axis=0, keepdims=True)) # (1, n_samples,)
ref_counts = np.nansum(X[ref_mask, :], axis=0, keepdims=True)
zero_ref_counts = ref_counts == 0.
if zero_ref_counts.all():
raise ValueError(
f"Reference counts in all samples are zero."
)
if zero_ref_counts.any():
raise ValueError(
f"The following samples have zero reference counts:\n{adata.var.loc[zero_ref_counts]}"
)

log_ref = np.log(ref_counts) # (1, n_samples,)
# log(c_i / c_wt) at every sample
log_ratio_to_ref = log_X - log_ref # (n_strains, n_samples)
log_ratio = log_ratio_to_ref.copy()
Expand Down Expand Up @@ -106,8 +116,8 @@ def compute_log_ratios(
growth_t0_mean = growth[t0_idx].mean()
if growth_type == "density":
expansion[:, c_idx] = np.log(growth[c_idx]) - np.log(growth_t0_mean)
else:
expansion[:, c_idx] = growth[c_idx] * np.log(2.)
else: # generations
expansion[:, c_idx] = (growth[c_idx] - growth_t0_mean) * np.log(2.)
expansion = -expansion
else:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "bartab"
version = "0.0.9"
version = "0.0.10"
authors = [
{ name="Eachan Johnson", email="eachan.johnson@crick.ac.uk" },
]
Expand Down
Loading