@@ -237,13 +237,19 @@ def _update_derived_values(self):
237
237
cluster_mudata .obsm ["codes" ] = self .model .codes
238
238
cluster_mudata .obsm ["grid" ] = np .array ([(x , y ) for x in range (self .xdim ) for y in range (self .ydim )])
239
239
cluster_mudata .uns ["outliers" ] = self .test_outliers (mad_allowed = self .mad_allowed ).reset_index ()
240
- # update metacluster values
241
240
241
+ # update metacluster values
242
242
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
246
250
self .mudata ["cluster_data" ].uns ["metacluster_MFIs" ] = metacluster_median_values
251
+
252
+ # Build the Minimum Spanning Tree (MST)
247
253
self .build_MST ()
248
254
249
255
def build_MST (self ):
@@ -432,6 +438,8 @@ def copy(self):
432
438
-------
433
439
FlowSOM: A new instance of FlowSOM with all data copied.
434
440
"""
441
+ from copy import deepcopy
442
+
435
443
# Create a new instance without calling __init__
436
444
fsom_copy = self .__class__ .__new__ (self .__class__ )
437
445
@@ -445,7 +453,7 @@ def copy(self):
445
453
fsom_copy .alpha = self .alpha
446
454
fsom_copy .seed = self .seed
447
455
fsom_copy .n_clusters = self .n_clusters
448
- fsom_copy .model = self .model
456
+ fsom_copy .model = deepcopy ( self .model )
449
457
fsom_copy .mudata = self .mudata .copy ()
450
458
return fsom_copy
451
459
0 commit comments