diff --git a/src/depiction/spectrum/peak_picking/basic_interpolated_peak_picker.py b/src/depiction/spectrum/peak_picking/basic_interpolated_peak_picker.py index 8d51c87..e50ab15 100644 --- a/src/depiction/spectrum/peak_picking/basic_interpolated_peak_picker.py +++ b/src/depiction/spectrum/peak_picking/basic_interpolated_peak_picker.py @@ -93,5 +93,6 @@ def _find_local_maxima_indices(self, mz_arr: NDArray[float], int_arr: NDArray[fl ) return local_maxima_indices + # TODO the interpolation could be much faster, if it were implemented in numba for our specific case of 3 points, # since in general the scipy library will do everything much moe general than is actually required. diff --git a/src/depiction_targeted_preproc/example_compare/run_compare.py b/src/depiction_targeted_preproc/example_compare/run_compare.py index 97f20ef..362a9e0 100644 --- a/src/depiction_targeted_preproc/example_compare/run_compare.py +++ b/src/depiction_targeted_preproc/example_compare/run_compare.py @@ -16,9 +16,11 @@ def prepare_tasks(input_imzml_path: Path, work_dir: Path) -> list[Path]: requested_files = get_all_output_files(folders) combined_dir = work_dir / input_imzml_path.stem - exp_files = [combined_dir / "exp_compare_cluster_stats.pdf", - combined_dir / "exp_plot_compare_peak_density.pdf", - combined_dir / "exp_plot_map_comparison.pdf"] + exp_files = [ + combined_dir / "exp_compare_cluster_stats.pdf", + combined_dir / "exp_plot_compare_peak_density.pdf", + combined_dir / "exp_plot_map_comparison.pdf", + ] return requested_files + exp_files diff --git a/src/depiction_targeted_preproc/workflow/exp/plot_map_comparison.py b/src/depiction_targeted_preproc/workflow/exp/plot_map_comparison.py index 79451b5..5a8b869 100644 --- a/src/depiction_targeted_preproc/workflow/exp/plot_map_comparison.py +++ b/src/depiction_targeted_preproc/workflow/exp/plot_map_comparison.py @@ -22,5 +22,6 @@ def exp_plot_map_comparison( plt.savefig(output_pdf_path, bbox_inches="tight") + if __name__ == "__main__": typer.run(exp_plot_map_comparison) diff --git a/src/depiction_targeted_preproc/workflow/proc/cluster_hdbscan.py b/src/depiction_targeted_preproc/workflow/proc/cluster_hdbscan.py index 6fd606d..bc8b3df 100644 --- a/src/depiction_targeted_preproc/workflow/proc/cluster_hdbscan.py +++ b/src/depiction_targeted_preproc/workflow/proc/cluster_hdbscan.py @@ -5,7 +5,7 @@ import numpy as np import typer import xarray -from hdbscan.flat import (HDBSCAN_flat) +from hdbscan.flat import HDBSCAN_flat from loguru import logger from sklearn.preprocessing import StandardScaler from typer import Option @@ -30,9 +30,8 @@ def cluster_dbscan(input_netcdf_path: Annotated[Path, Option()], output_netcdf_p data_scaled = scaler.transform(reduced_data.values) try: - clusterer = HDBSCAN_flat(data_scaled, - n_clusters=10) - #min_cluster_size=math.ceil(0.02 * data_scaled.shape[0])) + clusterer = HDBSCAN_flat(data_scaled, n_clusters=10) + # min_cluster_size=math.ceil(0.02 * data_scaled.shape[0])) clusters = clusterer.labels_ except IndexError: logger.error("No clusters found") diff --git a/src/depiction_targeted_preproc/workflow/proc/cluster_stats.py b/src/depiction_targeted_preproc/workflow/proc/cluster_stats.py index c764022..d3234bb 100644 --- a/src/depiction_targeted_preproc/workflow/proc/cluster_stats.py +++ b/src/depiction_targeted_preproc/workflow/proc/cluster_stats.py @@ -54,7 +54,7 @@ def compute_metrics(cluster_data: np.ndarray, cluster_coords: np.ndarray) -> dic "PAS": pas, "Silhouette": silhouette, "Davies-Bouldin": davies_bouldin, - "Calinski-Harabasz": calinski_harabasz + "Calinski-Harabasz": calinski_harabasz, } @@ -71,9 +71,7 @@ def cluster_stats(input_netcdf_path: Annotated[Path, Option()], output_csv_path: metrics = compute_metrics(cluster_data, cluster_coords) - metrics_df = pl.DataFrame( - {"metric": list(metrics.keys()), "value": list(metrics.values())} - ) + metrics_df = pl.DataFrame({"metric": list(metrics.keys()), "value": list(metrics.values())}) metrics_df.write_csv(output_csv_path) diff --git a/src/depiction_targeted_preproc/workflow/vis/clustering.py b/src/depiction_targeted_preproc/workflow/vis/clustering.py index 0937f92..ae56287 100644 --- a/src/depiction_targeted_preproc/workflow/vis/clustering.py +++ b/src/depiction_targeted_preproc/workflow/vis/clustering.py @@ -15,7 +15,7 @@ def vis_clustering(input_netcdf_path: Annotated[Path, Option()], output_png_path source_image.plot(cmap="tab10", ax=ax) ax.set_aspect("equal") - #n_classes = len(set(source_image.values.ravel())) + # n_classes = len(set(source_image.values.ravel())) n_classes = len(np.unique(source_image.values)) fig.suptitle(f"Clustering with {n_classes} classes") fig.tight_layout() diff --git a/src/depiction_targeted_preproc/workflow/vis/test_mass_shifts.py b/src/depiction_targeted_preproc/workflow/vis/test_mass_shifts.py index 301b31c..25e8bd8 100644 --- a/src/depiction_targeted_preproc/workflow/vis/test_mass_shifts.py +++ b/src/depiction_targeted_preproc/workflow/vis/test_mass_shifts.py @@ -30,8 +30,9 @@ def vis_test_mass_shifts( # compute the shifts def compute_shifts(coef): - result = calibration.apply_spectrum_model(spectrum_mz_arr=test_masses, spectrum_int_arr=test_masses_int, - model_coef=xr.DataArray(coef, dims=["c"])) + result = calibration.apply_spectrum_model( + spectrum_mz_arr=test_masses, spectrum_int_arr=test_masses_int, model_coef=xr.DataArray(coef, dims=["c"]) + ) return xr.DataArray(result[0] - test_masses, dims=["m"]) shifts = xr.apply_ufunc( diff --git a/tests/unit/calibration/spectrum/test_calibration_method_mcc.py b/tests/unit/calibration/spectrum/test_calibration_method_mcc.py index fc84198..b953424 100644 --- a/tests/unit/calibration/spectrum/test_calibration_method_mcc.py +++ b/tests/unit/calibration/spectrum/test_calibration_method_mcc.py @@ -11,4 +11,4 @@ def test_get_distances_nearest_when_invalid(self) -> None: if __name__ == "__main__": - unittest.main() + unittest.main() diff --git a/tests/unit/spectrum/peak_picking/test_basic_interpolated_peak_picker.py b/tests/unit/spectrum/peak_picking/test_basic_interpolated_peak_picker.py index 509cad2..03fc43e 100644 --- a/tests/unit/spectrum/peak_picking/test_basic_interpolated_peak_picker.py +++ b/tests/unit/spectrum/peak_picking/test_basic_interpolated_peak_picker.py @@ -29,8 +29,8 @@ def test_interpolate_max_mz_and_intensity_when_success_and_exact(self) -> None: """In this very simple case, interpolation should return the same value as the intensity on both sides is symmetric.""" local_max_index = 2 - mz_arr = np.array([1., 2, 3, 4, 5]) - int_arr = np.array([0., 0, 10, 0, 0]) + mz_arr = np.array([1.0, 2, 3, 4, 5]) + int_arr = np.array([0.0, 0, 10, 0, 0]) interpolated_mz, interpolated_int = self.basic_interpolated_peak_picker._interpolate_max_mz_and_intensity( local_max_index, mz_arr, int_arr @@ -41,8 +41,8 @@ def test_interpolate_max_mz_and_intensity_when_success_and_exact(self) -> None: def test_interpolate_max_mz_and_intensity_when_success_and_not_exact(self) -> None: local_max_index = 2 - mz_arr = np.array([1., 2, 3, 4, 5]) - int_arr = np.array([0., 0, 10, 5, 0]) + mz_arr = np.array([1.0, 2, 3, 4, 5]) + int_arr = np.array([0.0, 0, 10, 5, 0]) interpolated_mz, interpolated_int = self.basic_interpolated_peak_picker._interpolate_max_mz_and_intensity( local_max_index, mz_arr, int_arr @@ -53,8 +53,8 @@ def test_interpolate_max_mz_and_intensity_when_success_and_not_exact(self) -> No def test_interpolate_max_mz_and_intensity_when_failure(self) -> None: local_max_index = 2 - mz_arr = np.array([1., 2, 3, 4, 5]) - int_arr = np.array([0., 10, 10, 10, 0]) + mz_arr = np.array([1.0, 2, 3, 4, 5]) + int_arr = np.array([0.0, 10, 10, 10, 0]) with Logot().capturing(capturer=LoguruCapturer) as logot: interpolated_mz, interpolated_int = self.basic_interpolated_peak_picker._interpolate_max_mz_and_intensity(