Skip to content

Commit 03a742e

Browse files
committed
ruff apply unsafe fixes
1 parent 4e648c6 commit 03a742e

File tree

8 files changed

+36
-39
lines changed

8 files changed

+36
-39
lines changed

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ ignore = [
114114
]
115115
extend-include = ["*.ipynb"]
116116

117-
[tool.ruff.format]
118-
docstring-code-format = true
119-
120117
[tool.ruff.pydocstyle]
121118
convention = "numpy"
122119

src/FlowSOM/io/read_fcs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def read_FCS(filepath):
11-
"""Reads in an FCS file
11+
"""Reads in an FCS file.
1212
1313
:param filepath: An array containing a full path to the FCS file
1414
:type filepath: str

src/FlowSOM/main.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FlowSOM:
2121
"""A class that contains all the FlowSOM data using MuData objects."""
2222

2323
def __init__(self, inp=None, cols_to_use: np.ndarray | None = None, n_clus=10, seed: int | None = None, **kwargs):
24-
"""Initialize the FlowSOM AnnData object
24+
"""Initialize the FlowSOM AnnData object.
2525
2626
:param inp: A file path to an FCS file or a AnnData FCS file to cluster
2727
:type inp: str / ad.AnnData
@@ -42,7 +42,7 @@ def __init__(self, inp=None, cols_to_use: np.ndarray | None = None, n_clus=10, s
4242
self._update_derived_values()
4343

4444
def read_input(self, inp):
45-
"""Converts input to a FlowSOM AnnData object
45+
"""Converts input to a FlowSOM AnnData object.
4646
4747
:param inp: A file path to an FCS file or a AnnData FCS file to cluster
4848
:type inp: str / ad.AnnData
@@ -74,7 +74,7 @@ def read_input(self, inp):
7474
return self.mudata
7575

7676
def build_SOM(self, cols_to_use: np.ndarray | None = None, outlier_MAD=4, **kwargs):
77-
"""Initialize the SOM clustering and update FlowSOM object
77+
"""Initialize the SOM clustering and update FlowSOM object.
7878
7979
:param cols_to_use: An array of the columns to use for clustering
8080
:type cols_to_use: np.array
@@ -112,7 +112,7 @@ def SOM(
112112
importance=None,
113113
seed=None,
114114
):
115-
"""Perform SOM clustering
115+
"""Perform SOM clustering.
116116
117117
:param inp: An array of the columns to use for clustering
118118
:type inp: np.array
@@ -181,7 +181,7 @@ def SOM(
181181
return codes, clusters, dists, xdim, ydim
182182

183183
def _update_derived_values(self):
184-
"""Update the derived values such as median values and CV values"""
184+
"""Update the derived values such as median values and CV values."""
185185
# get dataframe of intensities and cluster labels on cell level
186186
df = self.mudata["cell_data"].to_df() # [self.adata.X[:, 0].argsort()]
187187
df = pd.concat([self.mudata["cell_data"].obs["clustering"], df], axis=1)
@@ -243,7 +243,7 @@ def _update_derived_values(self):
243243
self.mudata["cluster_data"].uns["metacluster_MFIs"] = metacluster_median_values
244244

245245
def build_MST(self):
246-
"""Make a minimum spanning tree"""
246+
"""Make a minimum spanning tree."""
247247
adjacency = cdist(
248248
self.mudata["cluster_data"].obsm["codes"],
249249
self.mudata["cluster_data"].obsm["codes"],
@@ -274,7 +274,7 @@ def _dist_mst(self, codes):
274274
return codes
275275

276276
def metacluster(self, n_clus):
277-
"""Perform a (consensus) hierarchical clustering
277+
"""Perform a (consensus) hierarchical clustering.
278278
279279
:param n_clus: The number of metaclusters
280280
:type n_clus: int
@@ -298,7 +298,7 @@ def consensus_hierarchical_clustering(
298298
return metaclusters
299299

300300
def test_outliers(self, mad_allowed: int = 4, fsom_reference=None, plot_file=None, channels=None):
301-
"""Test if any cells are too far from their cluster centers
301+
"""Test if any cells are too far from their cluster centers.
302302
303303
:param mad_allowed: Number of median absolute deviations allowed. Default = 4.
304304
:type mad_allowed: int
@@ -392,7 +392,7 @@ def test_outliers(self, mad_allowed: int = 4, fsom_reference=None, plot_file=Non
392392
return result
393393

394394
def new_data(self, inp, mad_allowed=4):
395-
"""Map new data to a FlowSOM grid
395+
"""Map new data to a FlowSOM grid.
396396
397397
:param inp: An anndata or filepath to an FCS file
398398
:type inp: ad.AnnData / str
@@ -428,7 +428,7 @@ def new_data(self, inp, mad_allowed=4):
428428
return fsom_new
429429

430430
def subset(self, ids):
431-
"""Take a subset from a FlowSOM object
431+
"""Take a subset from a FlowSOM object.
432432
433433
:param ids: An array of ids to subset
434434
:type ids: np.array
@@ -447,7 +447,7 @@ def get_cluster_data(self):
447447

448448
def flowsom_clustering(inp, cols_to_use=None, n_clus=10, xdim=10, ydim=10, seed=None, **kwargs):
449449
"""Perform FlowSOM clustering on an anndata object and returns the anndata
450-
object with the FlowSOM clusters and metaclusters added as variable
450+
object with the FlowSOM clusters and metaclusters added as variable.
451451
452452
:param inp: An anndata or filepath to an FCS file
453453
:type inp: ad.AnnData / str

src/FlowSOM/pl/_plot_helper_functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def FlowSOM_colors():
14-
"""Colormap of default FlowSOM colors"""
14+
"""Colormap of default FlowSOM colors."""
1515
cmap = matplotlib.colors.LinearSegmentedColormap.from_list(
1616
"FlowSOM_colors",
1717
["#00007F", "#0000E1", "#007FFF", "#00E1E1", "#7FFF7F", "#E1E100", "#FF7F00", "#E10000", "#7F0000"],
@@ -20,7 +20,7 @@ def FlowSOM_colors():
2020

2121

2222
def gg_color_hue():
23-
"""Colormap of default ggplot colors"""
23+
"""Colormap of default ggplot colors."""
2424
cmap = matplotlib.colors.ListedColormap(
2525
["#F8766D", "#D89000", "#A3A500", "#39B600", "#00BF7D", "#00BFC4", "#00B0F6", "#9590FF", "#E76BF3", "#FF62BC"]
2626
)
@@ -67,7 +67,7 @@ def plot_FlowSOM(
6767
ref_node_size: int = None,
6868
equal_node_size: bool = False,
6969
):
70-
"""Plots the base layer of a FlowSOM result
70+
"""Plots the base layer of a FlowSOM result.
7171
7272
:param fsom: A FlowSOM object
7373
:type fsom: A object from the class FlowSOM
@@ -185,7 +185,7 @@ def plot_FlowSOM(
185185

186186

187187
def plot_star_legend(fig, ax, markers, coords=(0, 0), cmap=FlowSOM_colors(), max_star_height=1, star_height=1):
188-
"""Function makes the legend of the FlowSOM star plot
188+
"""Function makes the legend of the FlowSOM star plot.
189189
190190
:param markers:
191191
:type markers:

src/FlowSOM/pl/plot_functions.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def plot_2D_scatters(
3535
plot_file: str = "2DScatterPlots.png",
3636
title=None,
3737
):
38-
"""Function to draw 2D scatter plots of FlowSOM (meta)clusters
38+
"""Function to draw 2D scatter plots of FlowSOM (meta)clusters.
3939
4040
:param fsom: A FlowSOM object
4141
:type fsom: FlowSOM
@@ -165,7 +165,7 @@ def plot_2D_scatters(
165165

166166

167167
def plot_labels(fsom, labels, max_node_size=0, text_size=20, text_color="black", title=None, **kwargs):
168-
"""Plot labels for each cluster
168+
"""Plot labels for each cluster.
169169
170170
:param fsom: A FlowSOM object
171171
:type fsom: FlowSOM
@@ -201,7 +201,7 @@ def plot_numbers(fsom, level="clusters", max_node_size=0, **kwargs):
201201
:param level: Should be either "clusters" (default) or "metaclusters".
202202
:type level: str
203203
:param max_node_size: Determines the maximum node size. Default is 0.
204-
:type max_node_size: float
204+
:type max_node_size: float.
205205
"""
206206
assert level in ["clusters", "metaclusters"], "level should be clusters or metaclusters"
207207
if level == "clusters":
@@ -214,7 +214,7 @@ def plot_numbers(fsom, level="clusters", max_node_size=0, **kwargs):
214214
def plot_variable(
215215
fsom, variable, cmap=FlowSOM_colors(), labels=None, text_size=5, text_color="black", lim=None, title=None, **kwargs
216216
):
217-
"""Plot FlowSOM grid or tree, colored by node values given in variable
217+
"""Plot FlowSOM grid or tree, colored by node values given in variable.
218218
219219
:param fsom: A FlowSOM object
220220
:type fsom: FlowSOM
@@ -258,7 +258,7 @@ def plot_variable(
258258

259259

260260
def plot_marker(fsom, marker, ref_markers=None, lim=None, cmap=FlowSOM_colors(), **kwargs):
261-
"""Plot FlowSOM grid or tree, colored by node values for a specific marker
261+
"""Plot FlowSOM grid or tree, colored by node values for a specific marker.
262262
263263
:param fsom: A FlowSOM object
264264
:type fsom: FlowSOM
@@ -287,7 +287,7 @@ def plot_marker(fsom, marker, ref_markers=None, lim=None, cmap=FlowSOM_colors(),
287287

288288

289289
def plot_stars(fsom, markers=None, cmap=FlowSOM_colors(), title=None, **kwargs):
290-
"""Plot star charts
290+
"""Plot star charts.
291291
292292
:param fsom: A FlowSOM object
293293
:type fsom: FlowSOM
@@ -340,7 +340,7 @@ def plot_pies(
340340
**kwargs,
341341
):
342342
"""Plot FlowSOM grid or tree, with pies indicating another clustering or
343-
manual gating result
343+
manual gating result.
344344
345345
:param fsom: A FlowSOM object
346346
:type fsom: FlowSOM
@@ -395,7 +395,7 @@ def plot_pies(
395395

396396

397397
def FlowSOMmary(fsom, plot_file="./FlowSOMmary.pdf"):
398-
"""Makes a visual FlowSOMmary of a FlowSOM object
398+
"""Makes a visual FlowSOMmary of a FlowSOM object.
399399
400400
:param fsom: A FlowSOM object
401401
:type fsom: FlowSOM

src/FlowSOM/pp/fcs_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def aggregate_flowframes(filenames, c_total, channels=None, keep_order=False):
2525
:type keep_order: boolean
2626
:param silent: If False, prints an update every time it starts processing a
2727
new file. Default = False.
28-
:type silent: boolean
28+
:type silent: boolean.
2929
"""
3030
nFiles = len(filenames)
3131
cFile = int(np.ceil(c_total / nFiles))

src/FlowSOM/tl/_consensus_clustering.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class ConsensusCluster:
2424
* L -> smallest number of clusters to try
2525
* K -> biggest number of clusters to try
2626
* H -> number of resamplings for each cluster number
27-
* resample_proportion -> percentage to sample
27+
* resample_proportion -> percentage to sample.
2828
"""
2929

3030
def __init__(self, cluster, K, H, resample_proportion=0.9, linkage="average"):
@@ -39,14 +39,14 @@ def _internal_resample(self, data, proportion):
3939
"""
4040
Args:
4141
* data -> (examples,attributes) format
42-
* proportion -> percentage to sample
42+
* proportion -> percentage to sample.
4343
"""
4444
resampled_indices = np.random.choice(range(data.shape[0]), size=int(data.shape[0] * proportion), replace=False)
4545
return resampled_indices, data[resampled_indices, :]
4646

4747
def fit(self, data):
4848
"""
49-
Fits a consensus matrix for each number of clusters
49+
Fits a consensus matrix for each number of clusters.
5050
5151
Args:
5252
* data -> (examples,attributes) format
@@ -75,5 +75,5 @@ def fit(self, data):
7575
self.Mk = Mk
7676

7777
def predict(self, n_clus=10):
78-
"""Predicts on the consensus matrix, for best found cluster number"""
78+
"""Predicts on the consensus matrix, for best found cluster number."""
7979
return self.cluster_(n_clusters=n_clus, linkage=self.linkage, metric="precomputed").fit_predict(1 - self.Mk)

src/FlowSOM/tl/getter_functions.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
def get_channels(obj, markers: np.ndarray, exact=True):
11-
"""Gets the channels of the provided markers based on a FlowSOM object or an FCS file
11+
"""Gets the channels of the provided markers based on a FlowSOM object or an FCS file.
1212
1313
:param obj: A FlowSOM object or a FCS AnnData object
1414
:type obj: FlowSOM / AnnData
@@ -55,7 +55,7 @@ def get_channels(obj, markers: np.ndarray, exact=True):
5555

5656

5757
def get_markers(obj, channels, exact=True):
58-
"""Gets the markers of the provided channels based on a FlowSOM object or an FCS file
58+
"""Gets the markers of the provided channels based on a FlowSOM object or an FCS file.
5959
6060
:param obj: A FlowSOM object or a FCS AnnData object
6161
:type obj: FlowSOM / AnnData
@@ -106,7 +106,7 @@ def get_markers(obj, channels, exact=True):
106106

107107

108108
def get_counts(fsom, level="metaclusters"):
109-
"""Get counts of number of cells in clusters or metaclusters
109+
"""Get counts of number of cells in clusters or metaclusters.
110110
111111
:param fsom: A FlowSOM object
112112
:type fsom: FlowSOM
@@ -128,7 +128,7 @@ def get_counts(fsom, level="metaclusters"):
128128

129129

130130
def get_percentages(fsom, level="metaclusters"):
131-
"""Get percentages of number of cells in clusters or metaclusters
131+
"""Get percentages of number of cells in clusters or metaclusters.
132132
133133
:param fsom: A FlowSOM object
134134
:type fsom: FlowSOM
@@ -142,7 +142,7 @@ def get_percentages(fsom, level="metaclusters"):
142142

143143

144144
def get_cluster_percentages_positive(fsom, cutoffs, cols_used=False, pretty_colnames=False):
145-
"""Get percentage-positive values for all clusters
145+
"""Get percentage-positive values for all clusters.
146146
147147
:param fsom: A FlowSOM object
148148
:type fsom: FlowSOM
@@ -183,7 +183,7 @@ def get_cluster_percentages_positive(fsom, cutoffs, cols_used=False, pretty_coln
183183

184184

185185
def get_metacluster_percentages_positive(fsom, cutoffs, cols_used=False, pretty_colnames=False):
186-
"""Get percentage-positive values for all metaclusters
186+
"""Get percentage-positive values for all metaclusters.
187187
188188
:param fsom: A FlowSOM object
189189
:type fsom: FlowSOM
@@ -232,7 +232,7 @@ def get_features(
232232
positive_cutoffs=None,
233233
filenames=None,
234234
):
235-
"""Map FCS files on an existing FlowSOM object
235+
"""Map FCS files on an existing FlowSOM object.
236236
237237
:param fsom: A FlowSOM object
238238
:type fsom: FlowSOM

0 commit comments

Comments
 (0)