Skip to content

Commit 90de413

Browse files
committed
fix mfi and model copy
1 parent 3363807 commit 90de413

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/flowsom/main.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,19 @@ def _update_derived_values(self):
237237
cluster_mudata.obsm["codes"] = self.model.codes
238238
cluster_mudata.obsm["grid"] = np.array([(x, y) for x in range(self.xdim) for y in range(self.ydim)])
239239
cluster_mudata.uns["outliers"] = self.test_outliers(mad_allowed=self.mad_allowed).reset_index()
240-
# update metacluster values
241240

241+
# update metacluster values
242242
self.mudata.mod["cluster_data"] = cluster_mudata
243-
df = self.mudata["cell_data"].X[self.mudata["cell_data"].X[:, 0].argsort()]
244-
df = np.c_[self.mudata["cell_data"].obs["metaclustering"], df]
245-
metacluster_median_values: pd.DataFrame = pd.DataFrame(df).groupby(0).median()
243+
244+
# Get df with cell data and metaclustering labels
245+
df = self.mudata["cell_data"].to_df()
246+
df["metaclustering"] = self.mudata["cell_data"].obs["metaclustering"]
247+
# Group by metaclustering labels and calculate median values
248+
metacluster_median_values = df.groupby("metaclustering").median()
249+
# Update the metacluster_MFIs in the cluster_data
246250
self.mudata["cluster_data"].uns["metacluster_MFIs"] = metacluster_median_values
251+
252+
# Build the Minimum Spanning Tree (MST)
247253
self.build_MST()
248254

249255
def build_MST(self):
@@ -432,6 +438,8 @@ def copy(self):
432438
-------
433439
FlowSOM: A new instance of FlowSOM with all data copied.
434440
"""
441+
from copy import deepcopy
442+
435443
# Create a new instance without calling __init__
436444
fsom_copy = self.__class__.__new__(self.__class__)
437445

@@ -445,7 +453,7 @@ def copy(self):
445453
fsom_copy.alpha = self.alpha
446454
fsom_copy.seed = self.seed
447455
fsom_copy.n_clusters = self.n_clusters
448-
fsom_copy.model = self.model
456+
fsom_copy.model = deepcopy(self.model)
449457
fsom_copy.mudata = self.mudata.copy()
450458
return fsom_copy
451459

src/flowsom/tl/getter_functions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ def get_features(
302302
if "clusters" in level:
303303
C_MFIs[i,] = fsom_tmp.get_cluster_data().to_df().loc[:, MFI].to_numpy().flatten()
304304
if "metaclusters" in level:
305-
MFI_i = [i for i, x in enumerate(fsom_tmp.get_cluster_data().var_names) if x in MFI]
306-
MC_MFIs[i,] = fsom_tmp.get_cluster_data().uns["metacluster_MFIs"].loc[:, MFI_i].to_numpy().flatten()
305+
# MFI_i = [i for i, x in enumerate(fsom_tmp.get_cluster_data().var_names) if x in MFI]
306+
MC_MFIs[i,] = fsom_tmp.get_cluster_data().uns["metacluster_MFIs"].loc[:, MFI].to_numpy().flatten()
307307

308308
if "percentages_positive" in type:
309309
if "clusters" in level:

0 commit comments

Comments
 (0)