Skip to content

Commit fa09653

Browse files
authored
Merge pull request #9 from saeyslab/interop-pytometry
Better interoperability with pytometry 0.1.6.
2 parents 80529c6 + 5a1efd9 commit fa09653

File tree

6 files changed

+305
-309
lines changed

6 files changed

+305
-309
lines changed

docs/api.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ For more background information, see the paper for this software package {cite:p
5050
:toctree: generated
5151
5252
pp.aggregate_flowframes
53-
pp.normalize_estimate_logicle
5453
```
5554

5655
## Models

docs/notebooks/example.ipynb

Lines changed: 283 additions & 271 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ dependencies = [
3131
"pandas",
3232
"scipy",
3333
"readfcs",
34-
"pytometry",
3534
"scikit-learn",
3635
"igraph",
3736
"session-info",
@@ -57,6 +56,8 @@ doc = [
5756
"ipykernel",
5857
"ipython",
5958
"sphinx-copybutton",
59+
# For example notebooks
60+
"pytometry>=0.1.5",
6061
]
6162
test = ["pytest", "coverage"]
6263

src/flowsom/pl/plot_functions.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,16 @@ def plot_numbers(fsom, level="clusters", max_node_size=0, **kwargs):
224224

225225

226226
def plot_variable(
227-
fsom, variable, cmap=FlowSOM_colors(), labels=None, text_size=5, text_color="black", lim=None, title=None, **kwargs
227+
fsom,
228+
variable,
229+
cmap=FlowSOM_colors(),
230+
labels=None,
231+
text_size=5,
232+
text_color="black",
233+
lim=None,
234+
title=None,
235+
categorical=True,
236+
**kwargs,
228237
):
229238
"""Plot FlowSOM grid or tree, colored by node values given in variable.
230239
@@ -260,7 +269,14 @@ def plot_variable(
260269
if labels is not None:
261270
ax = add_text(ax, layout, labels, text_size=text_size, text_color=text_color, ha=["center"], va=["center"])
262271
ax, fig = add_legend(
263-
fig=fig, ax=ax, data=variable, title="Marker", cmap=cmap, location="upper left", bbox_to_anchor=(1.04, 1)
272+
fig=fig,
273+
ax=ax,
274+
data=variable,
275+
title="Marker",
276+
cmap=cmap,
277+
location="upper left",
278+
bbox_to_anchor=(1.04, 1),
279+
categorical=categorical,
264280
)
265281
ax.axis("equal")
266282
if title is not None:
@@ -294,7 +310,7 @@ def plot_marker(fsom, marker, ref_markers=None, lim=None, cmap=FlowSOM_colors(),
294310
lim = (mfis[:, indices_markers].min(), mfis[:, indices_markers].max())
295311
marker = list(get_channels(fsom, marker).keys())[0]
296312
marker_index = np.where(fsom.get_cell_data().var_names == marker)[0][0]
297-
fig = plot_variable(fsom, variable=mfis[:, marker_index], cmap=cmap, lim=lim, **kwargs)
313+
fig = plot_variable(fsom, variable=mfis[:, marker_index], cmap=cmap, lim=lim, categorical=False, **kwargs)
298314
return fig
299315

300316

src/flowsom/pp/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .fcs_functions import aggregate_flowframes, normalize_estimate_logicle
1+
from .fcs_functions import aggregate_flowframes

src/flowsom/pp/fcs_functions.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
import anndata as ad
66
import numpy as np
7-
import pandas as pd
8-
import pytometry as pm
97

108
from flowsom.io import read_FCS
119
from flowsom.tl import get_markers
@@ -54,33 +52,3 @@ def aggregate_flowframes(filenames, c_total, channels=None, keep_order=False):
5452
flow_frame.append(f)
5553
flow_frame = ad.concat(flow_frame, join="outer", uns_merge="first")
5654
return flow_frame
57-
58-
59-
def normalize_estimate_logicle(adata, channels, m=4.5, q=0.05):
60-
"""Normalize and estimate logicle parameters.
61-
62-
:param adata: An AnnData object
63-
:type adata: AnnData
64-
:param channels: Channels/markers to normalize
65-
:type channels: list
66-
:param m: Logicle parameter. Default=4.5
67-
:type m: float
68-
:param q: Quantile to use for negative values. Default=0.05
69-
:type q: float
70-
"""
71-
assert isinstance(adata, ad.AnnData), "Please provide an AnnData object"
72-
assert isinstance(channels, list), "Please provide a list of channels"
73-
channels = list(get_markers(adata, channels).keys())
74-
assert all(i in adata.var_names for i in channels), "Channels should be in the AnnData object"
75-
neg_marker_quantiles = [
76-
np.quantile(adata[:, channel].X[adata[:, channel].X < 0], q) if (adata[:, channel].X < 0).any() else 0.5
77-
for channel in channels
78-
]
79-
neg_marker_quantiles = pd.Series(neg_marker_quantiles, index=channels, dtype=float)
80-
max_range = adata.var["$PnR"][channels].astype(float)
81-
w = (m - np.log10(max_range / np.abs(neg_marker_quantiles))) / 2
82-
for channel in channels:
83-
adata[:, channel].X = pm.tools.normalize_logicle(
84-
adata[:, channel], t=max_range[channel], m=m, a=0, w=w[channel], inplace=False
85-
).X
86-
return adata

0 commit comments

Comments
 (0)