Skip to content

export pyflowsom #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ optional-dependencies.doc = [
"sphinxcontrib-bibtex>=1",
"sphinxext-opengraph",
]
optional-dependencies.test = [ "coverage", "pytest" ]
optional-dependencies.test = [ "coverage", "pyflowsom", "pytest" ]
urls.Documentation = "https://flowsom.readthedocs.io/en/latest/"
urls.Home-page = "https://github.com/saeyslab/FlowSOM_Python"
urls.Source = "https://github.com/saeyslab/FlowSOM_Python"
Expand Down
2 changes: 2 additions & 0 deletions src/flowsom/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
from .consensus_cluster import ConsensusCluster # isort:skip
from .flowsom_estimator import FlowSOMEstimator # isort:skip
from .batch_flowsom_estimator import BatchFlowSOMEstimator # isort:skip
from .pyFlowSOM_som_estimator import PyFlowSOM_SOMEstimator # isort:skip
from .pyflowsom_estimator import PyFlowSOMEstimator # isort:skip
6 changes: 5 additions & 1 deletion src/flowsom/models/pyFlowSOM_som_estimator.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import numpy as np
from pyFlowSOM import map_data_to_nodes, som
from sklearn.utils.validation import check_is_fitted

from . import BaseClusterEstimator
Expand Down Expand Up @@ -54,6 +53,8 @@ def fit(
according to importance
:type importance: np.array
"""
from pyFlowSOM import map_data_to_nodes, som

alpha = self.alpha
X = X.astype("double")

Expand All @@ -77,7 +78,10 @@ def fit(

def predict(self, X, y=None):
"""Predict labels using the model."""
from pyFlowSOM import map_data_to_nodes

check_is_fitted(self)

X = X.astype("double")
clusters, dists = map_data_to_nodes(self.codes, X)
self.labels_ = clusters.astype(int) - 1
Expand Down
8 changes: 3 additions & 5 deletions tests/models/test_pyFlowSOM.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import pytest
from sklearn.metrics import v_measure_score

# optional import if pyFlowSOM is installed, otherwise use regular FlowSOM for type checking
# Skip the entire test file if pyflowsom is not installed
pytest.importorskip("pyFlowSOM", reason="pyflowsom is not installed")

try:
from flowsom.models.pyflowsom_estimator import PyFlowSOMEstimator
except ImportError:
from flowsom.models import FlowSOMEstimator as PyFlowSOMEstimator


@pytest.importorskip("flowsom.models.pyflowsom_estimator")
def test_clustering(X):
fsom = PyFlowSOMEstimator(n_clusters=10)
y_pred = fsom.fit_predict(X)
assert y_pred.shape == (100,)


@pytest.importorskip("flowsom.models.pyflowsom_estimator")
def test_clustering_v_measure(X_and_y):
som = PyFlowSOMEstimator(n_clusters=10)
X, y_true = X_and_y
Expand All @@ -24,7 +24,6 @@ def test_clustering_v_measure(X_and_y):
assert score > 0.7


@pytest.importorskip("flowsom.models.pyflowsom_estimator")
def test_reproducibility_no_seed(X):
fsom_1 = PyFlowSOMEstimator(n_clusters=10)
fsom_2 = PyFlowSOMEstimator(n_clusters=10)
Expand All @@ -34,7 +33,6 @@ def test_reproducibility_no_seed(X):
assert not all(y_pred_1 == y_pred_2)


@pytest.importorskip("flowsom.models.pyflowsom_estimator")
def test_reproducibility_seed(X):
fsom_1 = PyFlowSOMEstimator(n_clusters=10, seed=0)
fsom_2 = PyFlowSOMEstimator(n_clusters=10, seed=0)
Expand Down
Loading