Skip to content

Commit

Permalink
Make sure test cases create the dummy data correctly for existing_data
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-l-kong committed Jul 24, 2023
1 parent 5dfb0bc commit af6b06d
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/toffy/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ def combine_run_metrics(run_dir, substring, warn_overwrite=True):

if substring + "_combined.csv" in files:
if warn_overwrite:
print("Warning of overwriting!")
warnings.warn(
"Removing previously generated combined {} file in {}".format(substring, run_dir)
)
Expand Down
1 change: 1 addition & 0 deletions src/toffy/watcher_callbacks.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import inspect
import os
import warnings
from dataclasses import dataclass, field
from typing import Iterable

Expand Down
36 changes: 29 additions & 7 deletions tests/fov_watcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,19 @@
from pathlib import Path
from unittest.mock import patch

import numpy as np
import pandas as pd
import pytest
from alpineer import io_utils
from pytest_cases import parametrize_with_cases

from toffy.fov_watcher import start_watcher
from toffy.json_utils import write_json_file
from toffy.settings import QC_COLUMNS, QC_SUFFIXES
from toffy.watcher_callbacks import build_callbacks

from .utils.test_utils import (
TEST_CHANNELS,
RunStructureCases,
RunStructureTestContext,
WatcherCases,
Expand Down Expand Up @@ -161,12 +165,30 @@ def test_watcher(

# if existing_data set to True, test case where a FOV has already been extracted
if existing_data:
os.makedirs(os.path.join(tiff_out_dir, RUN_DIR_NAME, "fov-1-scan-1"))
Path(os.path.join(qc_out_dir, "fov-1-scan-1_nonzero_mean_stats.csv")).touch()
Path(os.path.join(qc_out_dir, "fov-1-scan-1_total_intensity_stats.csv")).touch()
Path(os.path.join(qc_out_dir, "fov-1-scan-1_percentile_99_9_stats.csv")).touch()
Path(os.path.join(mph_out_dir, "fov-1-scan-1-mph_pulse.csv")).touch()
Path(os.path.join(pulse_out_dir, "fov-1-scan-1-pulse_heights.csv")).touch()
os.makedirs(os.path.join(tiff_out_dir, "fov-2-scan-1"))

os.makedirs(qc_out_dir)
for qcs, qcc in zip(QC_SUFFIXES, QC_COLUMNS):
df_qc = pd.DataFrame(
np.random.rand(len(TEST_CHANNELS), 3), columns=["fov", "channel", qcc]
)
df_qc["fov"] = "fov-2-scan-1"
df_qc["channel"] = TEST_CHANNELS
df_qc.to_csv(os.path.join(qc_out_dir, f"fov-2-scan-1_{qcs}.csv"), index=False)

os.makedirs(mph_out_dir)
df_mph = pd.DataFrame(
np.random.rand(1, 4), columns=["fov", "MPH", "total_count", "time"]
)
df_mph["fov"] = "fov-2-scan-1"
df_mph.to_csv(os.path.join(mph_out_dir, "fov-2-scan-1-mph_pulse.csv"), index=False)

os.makedirs(pulse_out_dir)
df_ph = pd.DataFrame(np.random.rand(10, 3), columns=["mass", "fov", "pulse_height"])
df_ph["fov"] = "fov-2-scan-1"
df_ph.to_csv(
os.path.join(pulse_out_dir, "fov-2-scan-1-pulse_heights.csv"), index=False
)

# `_slow_copy_sample_tissue_data` mimics the instrument computer uploading data to the
# client access computer. `start_watcher` is made async here since these processes
Expand All @@ -183,7 +205,7 @@ def test_watcher(
# watcher completion is checked every second
# zero-size files are halted for 1 second or until they have non zero-size
if existing_data:
with pytest.warns(UserWarning, match="already extracted for FOV fov-1-scan-1"):
with pytest.warns(UserWarning, match="already extracted for FOV fov-2-scan-1"):
res_scan = pool.apply_async(
start_watcher,
(
Expand Down
42 changes: 42 additions & 0 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,48 @@
from toffy.json_utils import write_json_file
from toffy.settings import QC_COLUMNS, QC_SUFFIXES

TEST_CHANNELS = [
"Calprotectin",
"Chymase",
"SMA",
"Vimentin",
"LAG3",
"CD4",
"CD69",
"FAP",
"FOXP3",
"PD1",
"CD31",
"Biotin",
"Ecadherin",
"CD56",
"CD38",
"TCF1 TCF7",
"TBET",
"CD45RB",
"CD68",
"CD11c",
"CD8",
"CD3e",
"IDO1",
"CD45RO",
"TIM-3",
"CD163",
"CD20",
"FN1",
"Glut1",
"HLADR",
"CD14",
"CD45",
"Cytokeratin17",
"COL1A1",
"H3K27me3",
"CD57",
"H3K9ac",
"Ki67",
"HLA1 class ABC",
]


def make_run_file(tmp_dir, prefixes=[], include_nontiled=False):
"""Create a run subir and run json in the provided dir and return the path to this new dir."""
Expand Down

0 comments on commit af6b06d

Please sign in to comment.