Skip to content

Commit

Permalink
fix FlowSOM labels attr
Browse files Browse the repository at this point in the history
  • Loading branch information
berombau committed May 6, 2024
1 parent f880c25 commit 0f4b36a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/flowsom/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,37 @@ def __init__(
self._update_derived_values()

@property
def labels_(self):
"""Get the labels."""
def cluster_labels(self):
"""Get the cluster labels."""
if "cell_data" in self.mudata.mod.keys():
if "clustering" in self.mudata["cell_data"].obs_keys():
return self.mudata["cell_data"].obs["clustering"]
return None

@labels_.setter
def labels_(self, value):
"""Set the labels."""
@cluster_labels.setter
def cluster_labels(self, value):
"""Set the cluster labels."""
if "cell_data" in self.mudata.mod.keys():
self.mudata["cell_data"].obs["clustering"] = value
else:
raise ValueError("No cell data found in the MuData object.")

@property
def metacluster_labels(self):
"""Get the metacluster labels."""
if "cell_data" in self.mudata.mod.keys():
if "clustering" in self.mudata["cell_data"].obs_keys():
return self.mudata["cell_data"].obs["metaclustering"]
return None

@metacluster_labels.setter
def metacluster_labels(self, value):
"""Set the metacluster labels."""
if "cell_data" in self.mudata.mod.keys():
self.mudata["cell_data"].obs["metaclustering"] = value
else:
raise ValueError("No cell data found in the MuData object.")

def read_input(
self,
inp=None,
Expand Down
10 changes: 10 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import numpy as np

import flowsom as fs


Expand All @@ -18,6 +20,14 @@ def test_FlowSOM_type(FlowSOM_res):
assert isinstance(FlowSOM_res, fs.FlowSOM)


def test_FlowSOM_cluster_labels(FlowSOM_res):
assert len(np.unique(FlowSOM_res.cluster_labels)) == 100


def test_FlowSOM_metacluster_labels(FlowSOM_res):
assert len(np.unique(FlowSOM_res.metacluster_labels)) == 10


def test_plot_stars(FlowSOM_res, tmp_path):
pl = fs.pl.plot_stars(
FlowSOM_res,
Expand Down

0 comments on commit 0f4b36a

Please sign in to comment.