Skip to content

Commit d8cb6a5

Browse files
authored
Merge pull request #23 from saeyslab/export_pyflowsom
export pyflowsom
2 parents e13e1d2 + 26b0d85 commit d8cb6a5

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ optional-dependencies.doc = [
6666
"sphinxcontrib-bibtex>=1",
6767
"sphinxext-opengraph",
6868
]
69-
optional-dependencies.test = [ "coverage", "pytest" ]
69+
optional-dependencies.test = [ "coverage", "pyflowsom", "pytest" ]
7070
urls.Documentation = "https://flowsom.readthedocs.io/en/latest/"
7171
urls.Home-page = "https://github.com/saeyslab/FlowSOM_Python"
7272
urls.Source = "https://github.com/saeyslab/FlowSOM_Python"

src/flowsom/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
from .consensus_cluster import ConsensusCluster # isort:skip
66
from .flowsom_estimator import FlowSOMEstimator # isort:skip
77
from .batch_flowsom_estimator import BatchFlowSOMEstimator # isort:skip
8+
from .pyFlowSOM_som_estimator import PyFlowSOM_SOMEstimator # isort:skip
9+
from .pyflowsom_estimator import PyFlowSOMEstimator # isort:skip

src/flowsom/models/pyFlowSOM_som_estimator.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import numpy as np
2-
from pyFlowSOM import map_data_to_nodes, som
32
from sklearn.utils.validation import check_is_fitted
43

54
from . import BaseClusterEstimator
@@ -54,6 +53,8 @@ def fit(
5453
according to importance
5554
:type importance: np.array
5655
"""
56+
from pyFlowSOM import map_data_to_nodes, som
57+
5758
alpha = self.alpha
5859
X = X.astype("double")
5960

@@ -77,7 +78,10 @@ def fit(
7778

7879
def predict(self, X, y=None):
7980
"""Predict labels using the model."""
81+
from pyFlowSOM import map_data_to_nodes
82+
8083
check_is_fitted(self)
84+
8185
X = X.astype("double")
8286
clusters, dists = map_data_to_nodes(self.codes, X)
8387
self.labels_ = clusters.astype(int) - 1

tests/models/test_pyFlowSOM.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import pytest
22
from sklearn.metrics import v_measure_score
33

4-
# optional import if pyFlowSOM is installed, otherwise use regular FlowSOM for type checking
4+
# Skip the entire test file if pyflowsom is not installed
5+
pytest.importorskip("pyFlowSOM", reason="pyflowsom is not installed")
6+
57
try:
68
from flowsom.models.pyflowsom_estimator import PyFlowSOMEstimator
79
except ImportError:
810
from flowsom.models import FlowSOMEstimator as PyFlowSOMEstimator
911

1012

11-
@pytest.importorskip("flowsom.models.pyflowsom_estimator")
1213
def test_clustering(X):
1314
fsom = PyFlowSOMEstimator(n_clusters=10)
1415
y_pred = fsom.fit_predict(X)
1516
assert y_pred.shape == (100,)
1617

1718

18-
@pytest.importorskip("flowsom.models.pyflowsom_estimator")
1919
def test_clustering_v_measure(X_and_y):
2020
som = PyFlowSOMEstimator(n_clusters=10)
2121
X, y_true = X_and_y
@@ -24,7 +24,6 @@ def test_clustering_v_measure(X_and_y):
2424
assert score > 0.7
2525

2626

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

3635

37-
@pytest.importorskip("flowsom.models.pyflowsom_estimator")
3836
def test_reproducibility_seed(X):
3937
fsom_1 = PyFlowSOMEstimator(n_clusters=10, seed=0)
4038
fsom_2 = PyFlowSOMEstimator(n_clusters=10, seed=0)

0 commit comments

Comments
 (0)