Skip to content

Commit

Permalink
add evidence metrics to output
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed Nov 9, 2023
1 parent c0d8ba3 commit d075205
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 0 deletions.
11 changes: 11 additions & 0 deletions bean/preprocessing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,14 @@ def _obtain_effective_edit_rate(ndata, count_thres=10):

def _obtain_n_guides_alleles_per_variant(ndata):
return (ndata.allele_to_edit.sum(axis=1) > 0).sum(axis=0)


def _obtain_n_cooccurring_variants(ndata) -> np.ndarray:
"""Obtain the number of co-occurring variants in any allele produced by any guides."""
allele_to_edit = ndata.allele_to_edit.cpu()
n_coedited_vars_edits = []
for edit_idx in range(allele_to_edit.shape[-1]):
gidx, aidx = torch.where(allele_to_edit[:, :, edit_idx] > 0)
n_coedited_vars = (allele_to_edit[gidx, aidx, :].sum(axis=0) > 0).sum() - 1
n_coedited_vars_edits.append(n_coedited_vars)
return np.array(n_coedited_vars_edits)
2 changes: 2 additions & 0 deletions bin/bean-run
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ from bean.preprocessing.data_class import (
from bean.preprocessing.utils import (
_obtain_effective_edit_rate,
_obtain_n_guides_alleles_per_variant,
_obtain_n_cooccurring_variants,
)

import bean as be
Expand Down Expand Up @@ -196,6 +197,7 @@ def main(args, bdata):
)
target_info_df["effective_edit_rate"] = _obtain_effective_edit_rate(ndata).cpu()
target_info_df["n_guides"] = _obtain_n_guides_alleles_per_variant(ndata).cpu()
target_info_df["n_coocc"] = _obtain_n_cooccurring_variants(ndata)
if args.adjust_confidence_by_negative_control:
adj_negctrl_idx = np.where(target_info_df.ref == target_info_df.alt)[0]
print("syn idx: ", adj_negctrl_idx)
Expand Down
Binary file added tests/data/tiling_mini_screen_annotated.h5ad
Binary file not shown.
Binary file added tests/data/var_mini_screen_annotated.h5ad
Binary file not shown.
80 changes: 80 additions & 0 deletions tests/test_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import pytest
import subprocess


@pytest.mark.order(13)
def test_run_variant_wacc():
cmd = "bean-run variant tests/data/var_mini_screen_annotated.h5ad --scale-by-acc --acc-bw-path tests/data/accessibility_signal_var.bw -o tests/test_res/var/ --repguide-mask None"
try:
subprocess.check_output(
cmd,
shell=True,
universal_newlines=True,
)
except subprocess.CalledProcessError as exc:
raise exc


@pytest.mark.order(14)
def test_run_variant_noacc():
cmd = "bean-run variant tests/data/var_mini_screen_annotated.h5ad -o tests/test_res/var/ "
try:
subprocess.check_output(
cmd,
shell=True,
universal_newlines=True,
)
except subprocess.CalledProcessError as exc:
raise exc


@pytest.mark.order(15)
def test_run_variant_wo_negctrl_uniform():
cmd = "bean-run variant tests/data/var_mini_screen_annotated.h5ad -o tests/test_res/var/ --uniform-edit "
try:
subprocess.check_output(
cmd,
shell=True,
universal_newlines=True,
)
except subprocess.CalledProcessError as exc:
raise exc


@pytest.mark.order(16)
def test_run_tiling_wo_negctrl():
cmd = "bean-run tiling tests/data/tiling_mini_screen_annotated.h5ad --scale-by-acc --acc-bw-path tests/data/accessibility_signal.bw -o tests/test_res/tiling/ --allele-df-key allele_counts_spacer_0_19_A.G_translated_prop0.1_0.3 --control-guide-tag None --repguide-mask None"
try:
subprocess.check_output(
cmd,
shell=True,
universal_newlines=True,
)
except subprocess.CalledProcessError as exc:
raise exc


@pytest.mark.order(17)
def test_run_tiling_with_wo_negctrl_noacc():
cmd = "bean-run tiling tests/data/tiling_mini_screen_annotated.h5ad -o tests/test_res/tiling/ --allele-df-key allele_counts_spacer_0_19_A.G_translated_prop0.1_0.3 --control-guide-tag None --repguide-mask None"
try:
subprocess.check_output(
cmd,
shell=True,
universal_newlines=True,
)
except subprocess.CalledProcessError as exc:
raise exc


@pytest.mark.order(18)
def test_run_tiling_with_wo_negctrl_uniform():
cmd = "bean-run tiling tests/data/tiling_mini_screen_annotated.h5ad -o tests/test_res/tiling/ --uniform-edit --allele-df-key allele_counts_spacer_0_19_A.G_translated_prop0.1_0.3 --control-guide-tag None --repguide-mask None"
try:
subprocess.check_output(
cmd,
shell=True,
universal_newlines=True,
)
except subprocess.CalledProcessError as exc:
raise exc

0 comments on commit d075205

Please sign in to comment.