diff --git a/src/toffy/normalize.py b/src/toffy/normalize.py index 7a9c1cc0..2921d116 100644 --- a/src/toffy/normalize.py +++ b/src/toffy/normalize.py @@ -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) ) diff --git a/src/toffy/watcher_callbacks.py b/src/toffy/watcher_callbacks.py index affe6de4..65894efa 100644 --- a/src/toffy/watcher_callbacks.py +++ b/src/toffy/watcher_callbacks.py @@ -1,5 +1,6 @@ import inspect import os +import warnings from dataclasses import dataclass, field from typing import Iterable diff --git a/tests/fov_watcher_test.py b/tests/fov_watcher_test.py index 1cb3298b..9dcad15f 100644 --- a/tests/fov_watcher_test.py +++ b/tests/fov_watcher_test.py @@ -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, @@ -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 @@ -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, ( diff --git a/tests/utils/test_utils.py b/tests/utils/test_utils.py index 97ed4191..0059d47b 100644 --- a/tests/utils/test_utils.py +++ b/tests/utils/test_utils.py @@ -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."""