@@ -398,7 +398,7 @@ def new_data(self, inp, mad_allowed=4):
398398 madAllowed * MAD. Default is 4.
399399 :type mad_allowed: int
400400 """
401- fsom_new = copy . deepcopy ( self )
401+ fsom_new = self . copy ( )
402402 fsom_new .read_input (inp )
403403 fsom_new .mad_allowed = mad_allowed
404404 X = fsom_new .get_cell_data ()[:, self .cols_to_use ].X
@@ -412,7 +412,7 @@ def subset(self, ids):
412412 :param ids: An array of ids to subset
413413 :type ids: np.array
414414 """
415- fsom_subset = copy . deepcopy ( self )
415+ fsom_subset = self . copy ( )
416416 fsom_subset .mudata .mod ["cell_data" ] = fsom_subset .mudata ["cell_data" ][ids , :].copy ()
417417 fsom_subset .model .subset (ids )
418418 fsom_subset ._update_derived_values ()
@@ -425,6 +425,31 @@ def get_cell_data(self):
425425 def get_cluster_data (self ):
426426 """Get the cluster data."""
427427 return self .mudata ["cluster_data" ]
428+
429+ def copy (self ):
430+ """
431+ Returns a copy of the FlowSOM instance, leveraging MuData's built-in copy method.
432+
433+ Returns:
434+ FlowSOM: A new instance of FlowSOM with all data copied.
435+ """
436+ # Create a new instance without calling __init__
437+ fsom_copy = self .__class__ .__new__ (self .__class__ )
438+
439+ # Copy attributes
440+ fsom_copy .cols_to_use = self .cols_to_use
441+ fsom_copy .mad_allowed = self .mad_allowed
442+ fsom_copy .xdim = self .xdim
443+ fsom_copy .ydim = self .ydim
444+ fsom_copy .rlen = self .rlen
445+ fsom_copy .mst = self .mst
446+ fsom_copy .alpha = self .alpha
447+ fsom_copy .seed = self .seed
448+ fsom_copy .n_clusters = self .n_clusters
449+ fsom_copy .model = self .model
450+ fsom_copy .mudata = self .mudata .copy ()
451+ return fsom_copy
452+
428453
429454
430455def flowsom_clustering (inp : ad .AnnData , cols_to_use = None , n_clusters = 10 , xdim = 10 , ydim = 10 , ** kwargs ):
0 commit comments