Skip to content

Commit

Permalink
updating test and data class
Browse files Browse the repository at this point in the history
  • Loading branch information
jykr committed Nov 25, 2023
1 parent 526490f commit 2804ecc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
51 changes: 45 additions & 6 deletions bean/preprocessing/data_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ def __init__(
replicate_column: str = "rep",
**kwargs,
):
self._pre_init(condition_column)
screen = self._pre_init(screen, condition_column, time_column, condition_column)
super().__init__(
screen=screen,
repguide_mask=repguide_mask,
Expand All @@ -942,8 +942,13 @@ def __init__(
)
self._post_init()

def _pre_init(self, time_column: str, condition_column: str):
self.time_column = time_column
def _pre_init(
self,
time_column: str,
condition_column: str,
control_condition: str,
normalized_time_column: str = "_time_normed",
):
if not np.issubdtype(self.screen.samples[time_column].dtype, np.number):
raise ValueError(
f"Invalid timepoint value({self.screen.samples[time_column]}) in screen.samples[{time_column}]: check input."
Expand All @@ -957,6 +962,28 @@ def _pre_init(self, time_column: str, condition_column: str):
f"Not all replicate share same timepoint definition. If you have missing bin data, add the sample and add 'mask' column in 'screen.samples', or run `bean-qc` that automatically handles this. \n{self.screen.samples}"
)

self.screen.samples[normalized_time_column] = (
self.screen.samples[time_column] - self.screen.samples[time_column].min()
) / (
self.screen.samples[time_column].max()
- self.screen.samples[time_column].min()
)
self.screen_selected.samples[normalized_time_column] = (
self.screen_selected.samples[time_column]
- self.screen.samples[time_column].min()
) / (
self.screen.samples[time_column].max()
- self.screen.samples[time_column].min()
)
self.screen_control.samples[normalized_time_column] = (
self.screen_control.samples[time_column]
- self.screen.samples[time_column].min()
) / (
self.screen.samples[time_column].max()
- self.screen.samples[time_column].min()
)
self.time_column = normalized_time_column

def _post_init(
self,
):
Expand Down Expand Up @@ -1212,6 +1239,7 @@ def __init__(
replicate_column="rep",
condition_column="condition",
time_column="time",
control_condition="bulk",
control_can_be_selected=True,
target_col="target",
sample_mask_column="mask",
Expand All @@ -1226,12 +1254,15 @@ def __init__(
sample_mask_column=sample_mask_column,
replicate_column=replicate_column,
condition_column=condition_column,
control_condition=control_condition,
time_column=time_column,
shrink_alpha=shrink_alpha,
control_can_be_selected=control_can_be_selected,
**kwargs,
)
SurvivalScreenData._pre_init(self, time_column, condition_column)
SurvivalScreenData._pre_init(
self, time_column, condition_column, control_condition
)
ScreenData._post_init(self)
SurvivalScreenData._post_init(self)
VariantScreenData._post_init(self, target_col)
Expand Down Expand Up @@ -1282,6 +1313,7 @@ def __init__(
replicate_column="rep",
condition_column="condition",
time_column="time",
control_condition="control",
control_can_be_selected=True,
target_col="target",
sample_mask_column="mask",
Expand All @@ -1299,12 +1331,15 @@ def __init__(
sample_mask_column=sample_mask_column,
replicate_column=replicate_column,
condition_column=condition_column,
control_condition=control_condition,
time_column=time_column,
shrink_alpha=shrink_alpha,
control_can_be_selected=control_can_be_selected,
**kwargs,
)
SurvivalScreenData._pre_init(self, time_column, condition_column)
SurvivalScreenData._pre_init(
self, time_column, condition_column, control_condition
)
ScreenData._post_init(self)
SurvivalScreenData._post_init(self)
VariantScreenData._post_init(self, target_col)
Expand All @@ -1328,6 +1363,7 @@ def __init__(
replicate_column="rep",
condition_column="condition",
time_column="time",
control_condition="control",
control_can_be_selected=True,
sample_mask_column="mask",
use_const_pi: bool = False,
Expand All @@ -1347,12 +1383,15 @@ def __init__(
sample_mask_column=sample_mask_column,
replicate_column=replicate_column,
condition_column=condition_column,
control_condition=control_condition,
time_column=time_column,
shrink_alpha=shrink_alpha,
control_can_be_selected=control_can_be_selected,
**kwargs,
)
SurvivalScreenData._pre_init(self, time_column, condition_column)
SurvivalScreenData._pre_init(
self, time_column, condition_column, control_condition
)
ScreenData._post_init(self)
SurvivalScreenData._post_init(self)
TilingReporterScreenData._post_init(
Expand Down
12 changes: 6 additions & 6 deletions tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@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_chr6.bw -o tests/test_res/var/ --repguide-mask None"
cmd = "bean-run sorting variant tests/data/var_mini_screen_annotated.h5ad --scale-by-acc --acc-bw-path tests/data/accessibility_signal_chr6.bw -o tests/test_res/var/ --repguide-mask None"
try:
subprocess.check_output(
cmd,
Expand All @@ -17,7 +17,7 @@ def test_run_variant_wacc():

@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/ "
cmd = "bean-run sorting variant tests/data/var_mini_screen_annotated.h5ad -o tests/test_res/var/ "
try:
subprocess.check_output(
cmd,
Expand All @@ -30,7 +30,7 @@ def test_run_variant_noacc():

@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 "
cmd = "bean-run sorting variant tests/data/var_mini_screen_annotated.h5ad -o tests/test_res/var/ --uniform-edit "
try:
subprocess.check_output(
cmd,
Expand All @@ -43,7 +43,7 @@ def test_run_variant_wo_negctrl_uniform():

@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"
cmd = "bean-run sorting 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,
Expand All @@ -56,7 +56,7 @@ def test_run_tiling_wo_negctrl():

@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"
cmd = "bean-run sorting 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,
Expand All @@ -69,7 +69,7 @@ def test_run_tiling_with_wo_negctrl_noacc():

@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"
cmd = "bean-run sorting 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,
Expand Down

0 comments on commit 2804ecc

Please sign in to comment.