@@ -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
0 commit comments