Skip to content

Commit cfc4eba

Browse files
authored
Merge pull request #18 from artuurC/main
Solutions for issue #11 #12 #17
2 parents 2e6b68c + 043006a commit cfc4eba

File tree

4 files changed

+41
-16
lines changed

4 files changed

+41
-16
lines changed

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ urls.Documentation = "https://flowsom.readthedocs.io/en/latest/"
2525
urls.Source = "https://github.com/saeyslab/FlowSOM_Python"
2626
urls.Home-page = "https://github.com/saeyslab/FlowSOM_Python"
2727
dependencies = [
28-
"mudata<=0.2.4",
28+
"mudata",
2929
"numpy",
3030
"matplotlib",
3131
"pandas",
3232
"scipy",
33-
"readfcs<2",
33+
"readfcs",
3434
"scikit-learn",
3535
"igraph",
3636
"session-info",
3737
"numba",
3838
"scanpy",
3939
"seaborn",
40-
"anndata<=0.10.8",
40+
"anndata",
4141
"loguru",
4242
]
4343

src/flowsom/io/read_fcs.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ def read_FCS(filepath):
1717
f = readfcs.read(filepath, reindex=True)
1818
f.var.n = f.var.n.astype(int)
1919
f.var = f.var.sort_values(by="n")
20-
f.uns["meta"]["channels"].index = f.uns["meta"]["channels"].index.astype(int)
21-
f.uns["meta"]["channels"] = f.uns["meta"]["channels"].sort_index()
20+
#f.uns["meta"]["channels"].index = f.uns["meta"]["channels"].index.astype(int)
21+
#f.uns["meta"]["channels"] = f.uns["meta"]["channels"].sort_index()
2222
except ValueError:
2323
f = readfcs.read(filepath, reindex=False)
2424
markers = {
2525
str(re.sub("S$", "", re.sub("^P", "", string))): f.uns["meta"][string]
2626
for string in f.uns["meta"].keys()
27-
if re.match("^P[0-9]+S$", string)
27+
if re.match("^p[0-9]+s$", string)
2828
}
2929
fluo_channels = list(markers.keys())
3030
non_fluo_channels = {
31-
i: f.uns["meta"]["channels"]["$PnN"][i] for i in f.uns["meta"]["channels"].index if i not in fluo_channels
31+
i: f.var["channel"][i] for i in f.var.index if i not in fluo_channels
3232
}
3333
index_markers = dict(markers, **non_fluo_channels)
3434
f.var.rename(index=index_markers, inplace=True)
35-
f.uns["meta"]["channels"]["$PnS"] = [index_markers[key] for key in f.uns["meta"]["channels"].index]
35+
#f.uns["meta"]["channels"]["$PnS"] = [index_markers[key] for key in f.uns["meta"]["channels"].index]
3636
return f
3737

3838

src/flowsom/main.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

430455
def flowsom_clustering(inp: ad.AnnData, cols_to_use=None, n_clusters=10, xdim=10, ydim=10, **kwargs):

src/flowsom/tl/getter_functions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def get_channels(obj, markers: np.ndarray, exact=True):
3030
]
3131
)
3232
else:
33-
object_markers = np.asarray(obj.uns["meta"]["channels"]["$PnS"])
34-
object_channels = np.asarray(obj.uns["meta"]["channels"]["$PnN"])
33+
object_markers = np.asarray(obj.var["marker"])
34+
object_channels = np.asarray(obj.var["channel"])
3535

3636
channelnames = {}
3737
for marker in markers:
@@ -78,8 +78,8 @@ def get_markers(obj, channels, exact=True):
7878
]
7979
)
8080
else:
81-
object_markers = np.asarray(obj.uns["meta"]["channels"]["$PnS"])
82-
object_channels = np.asarray(obj.uns["meta"]["channels"]["$PnN"])
81+
object_markers = np.asarray(obj.var["marker"])
82+
object_channels = np.asarray(obj.var["channel"])
8383

8484
markernames = {}
8585
for channel in channels:
@@ -166,7 +166,7 @@ def get_cluster_percentages_positive(fsom, cutoffs, cols_used=False, pretty_coln
166166
channels = {key: value for key, value in channels.items() if key in markers}
167167

168168
perc_pos = np.empty((len(clusters), len(channels)))
169-
perc_pos.fill(np.NaN)
169+
perc_pos.fill(np.nan)
170170
for i, cluster in enumerate(clusters):
171171
data_per_cluster = fsom.get_cell_data().to_df().loc[cl_per_cell == cluster, list(channels.keys())]
172172
if data_per_cluster.shape[0] != 0:
@@ -207,7 +207,7 @@ def get_metacluster_percentages_positive(fsom, cutoffs, cols_used=False, pretty_
207207
channels = {key: value for key, value in channels.items() if key in markers}
208208

209209
perc_pos = np.empty((len(metaclusters), len(channels)))
210-
perc_pos.fill(np.NaN)
210+
perc_pos.fill(np.nan)
211211
for i, cluster in enumerate(metaclusters):
212212
data_per_metacluster = fsom.get_cell_data().to_df().loc[mcl_per_cell == cluster, list(channels.keys())]
213213
if data_per_metacluster.shape[0] != 0:

0 commit comments

Comments
 (0)