From 86e910a42c7fee714990436fb5028b04aaf1d23f Mon Sep 17 00:00:00 2001 From: jykr Date: Sat, 30 Mar 2024 01:50:24 -0400 Subject: [PATCH] fix key for paramStore writing --- README.md | 10 ++++------ bean/model/readwrite.py | 34 ++++++++++++++++------------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index 945dce5..0dd3ef0 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# crispr-bean +# crispr-bean [![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/) @@ -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. -

+## 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 | @@ -46,7 +47,6 @@ The `bean filter` and `bean run` steps depend on the type of gRNA library design Ex) tiling library design -

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

+ ## Subcommands See the full detail for each subcommand in the documentation. * [`count`, `count-samples`](docs/count.md): Count (reporter) screen data @@ -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. -

- ## 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. diff --git a/bean/model/readwrite.py b/bean/model/readwrite.py index a36493b..76287f3 100755 --- a/bean/model/readwrite.py +++ b/bean/model/readwrite.py @@ -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, @@ -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}"] @@ -185,10 +183,10 @@ 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: @@ -196,7 +194,7 @@ def write_result_table( 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(),