Skip to content

Commit

Permalink
fix key for paramStore writing
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed Mar 30, 2024
1 parent 8314104 commit 86e910a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# <img src="imgs/bean_title.svg" alt="crispr-bean" width="300"/>
# <img src="imgs/bean_title.svg" alt="crispr-bean" height="50"/>

[![PyPI pyversions](https://img.shields.io/pypi/pyversions/crispr-bean)](https://pypi.org/project/crispr-bean/)
[![PyPI version](https://img.shields.io/pypi/v/crispr-bean)](https://pypi.org/project/crispr-bean/)
Expand All @@ -25,7 +25,8 @@
### Screen data is saved as *ReporterScreen* object in the pipeline.
BEAN stores mapped gRNA and allele counts in `ReporterScreen` object which is compatible with [AnnData](https://anndata.readthedocs.io/en/latest/index.html). See [Data Structure](#data-structure) section for more information.

<br/><br/>
## Documentaton
See the [documentation](https://pinellolab.github.io/crispr-bean/) for tutorials and API references.

## Tutorials
| [Library design](#pipeline-run-options-by-library-design) | Selection | Reporter | Tutorial link |
Expand All @@ -46,7 +47,6 @@ The `bean filter` and `bean run` steps depend on the type of gRNA library design
Ex)
<img src="imgs/tiling.png" alt="tiling library design" width="450"/>

<br/><br/>

## Installation
### Full installation
Expand All @@ -62,7 +62,7 @@ pip install crispr-bean
```
This wouldn't have variant effect size quantification (`bean run`) functionality.

<br/><br/>

## Subcommands
See the full detail for each subcommand in the documentation.
* [`count`, `count-samples`](docs/count.md): Count (reporter) screen data
Expand Down Expand Up @@ -94,8 +94,6 @@ cdata = be.read_h5ad("bean_counts_sample.h5ad")
```
Python package `bean` supports multiple data wrangling functionalities for `ReporterScreen` objects. See the [**ReporterScreen API tutorial**](docs/ReporterScreen_api.ipynb) for more detail.

<br></br>

## Run time
* Installation takes 14.4 mins after pytorch installation with pytorch in Dell XPS 13 Ubuntu WSL.
* `bean run` takes 4.6 mins with `--scale-by-acc` tag in Dell XPS 13 Ubuntu WSL for variant screen dataset with 3455 guides and 6 replicates with 4 sorting bins.
Expand Down
34 changes: 16 additions & 18 deletions bean/model/readwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ def write_result_table(
return_result: bool = False,
) -> Union[pd.DataFrame, None]:
"""Combine target information and scores to write result table to a csv file or return it."""
if param_hist_dict["params"]["mu_loc"].dim() == 2:
mu = param_hist_dict["params"]["mu_loc"].detach()[:, 0].cpu().numpy()
mu_sd = param_hist_dict["params"]["mu_scale"].detach()[:, 0].cpu().numpy()
if param_hist_dict["mu_loc"].dim() == 2:
mu = param_hist_dict["mu_loc"].detach()[:, 0].cpu().numpy()
mu_sd = param_hist_dict["mu_scale"].detach()[:, 0].cpu().numpy()
if sd_is_fitted:
sd = param_hist_dict["params"]["sd_loc"].detach().exp()[:, 0].cpu().numpy()
elif param_hist_dict["params"]["mu_loc"].dim() == 1:
mu = param_hist_dict["params"]["mu_loc"].detach().cpu().numpy()
mu_sd = param_hist_dict["params"]["mu_scale"].detach().cpu().numpy()
sd = param_hist_dict["sd_loc"].detach().exp()[:, 0].cpu().numpy()
elif param_hist_dict["mu_loc"].dim() == 1:
mu = param_hist_dict["mu_loc"].detach().cpu().numpy()
mu_sd = param_hist_dict["mu_scale"].detach().cpu().numpy()
if sd_is_fitted:
sd = param_hist_dict["params"]["sd_loc"].detach().exp().cpu().numpy()
sd = param_hist_dict["sd_loc"].detach().exp().cpu().numpy()
else:
raise ValueError(
f'`mu_loc` has invalid shape of {param_hist_dict["params"]["mu_loc"].shape}'
f'`mu_loc` has invalid shape of {param_hist_dict["mu_loc"].shape}'
)
param_dict = {
"mu": mu,
Expand All @@ -85,17 +85,15 @@ def write_result_table(
param_dict["sd"] = sd
if sample_covariates is not None:
assert (
"mu_cov_loc" in param_hist_dict["params"]
and "mu_cov_scale" in param_hist_dict["params"]
), param_hist_dict["params"].keys()
"mu_cov_loc" in param_hist_dict and "mu_cov_scale" in param_hist_dict
), param_hist_dict.keys()
for i, sample_cov in enumerate(sample_covariates):
param_dict[f"mu_{sample_cov}"] = (
mu + param_hist_dict["params"]["mu_cov_loc"].detach().cpu().numpy()[i]
mu + param_hist_dict["mu_cov_loc"].detach().cpu().numpy()[i]
)
param_dict[f"mu_sd_{sample_cov}"] = np.sqrt(
mu_sd**2
+ param_hist_dict["params"]["mu_cov_scale"].detach().cpu().numpy()[i]
** 2
+ param_hist_dict["mu_cov_scale"].detach().cpu().numpy()[i] ** 2
)
param_dict[f"mu_z_{sample_cov}"] = (
param_dict[f"mu_{sample_cov}"] / param_dict[f"mu_sd_{sample_cov}"]
Expand Down Expand Up @@ -185,18 +183,18 @@ def write_result_table(
)

if write_fitted_eff or guide_acc is not None:
if "alpha_pi" not in param_hist_dict["params"].keys():
if "alpha_pi" not in param_hist_dict.keys():
pi = 1.0
else:
a_fitted = param_hist_dict["params"]["alpha_pi"].detach().cpu().numpy()
a_fitted = param_hist_dict["alpha_pi"].detach().cpu().numpy()
pi = a_fitted[..., 1:].sum(axis=1) / a_fitted.sum(axis=1)
sgRNA_df = pd.DataFrame({"edit_eff": pi}, index=guide_index)
if guide_acc is not None:
sgRNA_df["accessibility"] = guide_acc
sgRNA_df["scaled_edit_eff"] = _scale_pi(
pi,
guide_acc,
fitted_noise_logit=param_hist_dict["params"]["noise_scale"]
fitted_noise_logit=param_hist_dict["noise_scale"]
.detach()
.cpu()
.numpy(),
Expand Down

0 comments on commit 86e910a

Please sign in to comment.