Skip to content

Commit 7a4d94a

Browse files
committed
lint
1 parent 03a742e commit 7a4d94a

File tree

8 files changed

+93
-40
lines changed

8 files changed

+93
-40
lines changed

docs/notebooks/example.ipynb

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@
644644
],
645645
"source": [
646646
"# Visualize data\n",
647-
"ax = plt.hist2d(ff_t[:,\"CD4\"].X.flatten(), ff_t[:,\"CD8\"].X.flatten(), bins=200, cmin = 1, cmap = \"jet\")\n",
647+
"ax = plt.hist2d(ff_t[:, \"CD4\"].X.flatten(), ff_t[:, \"CD8\"].X.flatten(), bins=200, cmin=1, cmap=\"jet\")\n",
648648
"plt.show()"
649649
]
650650
},
@@ -714,7 +714,7 @@
714714
}
715715
],
716716
"source": [
717-
"fsom = fs.FlowSOM(ff_t, cols_to_use, xdim = 10, ydim = 10, n_clus = 10)\n",
717+
"fsom = fs.FlowSOM(ff_t, cols_to_use, xdim=10, ydim=10, n_clus=10)\n",
718718
"fsom.mudata"
719719
]
720720
},
@@ -749,7 +749,7 @@
749749
}
750750
],
751751
"source": [
752-
"ff_clustered = fs.flowsom_clustering(ff_t, cols_to_use, xdim = 10, ydim = 10, n_clus = 10)\n",
752+
"ff_clustered = fs.flowsom_clustering(ff_t, cols_to_use, xdim=10, ydim=10, n_clus=10)\n",
753753
"ff_clustered"
754754
]
755755
},
@@ -857,7 +857,7 @@
857857
}
858858
],
859859
"source": [
860-
"p = fs.pl.plot_stars(fsom, background_values = fsom.get_cluster_data().obs.metaclustering)\n",
860+
"p = fs.pl.plot_stars(fsom, background_values=fsom.get_cluster_data().obs.metaclustering)\n",
861861
"p.show()"
862862
]
863863
},
@@ -897,7 +897,13 @@
897897
}
898898
],
899899
"source": [
900-
"p = fs.pl.plot_stars(fsom, background_values = fsom.get_cluster_data().obs.metaclustering, view = \"grid\", equal_node_size = True, equal_background_size = True)\n",
900+
"p = fs.pl.plot_stars(\n",
901+
" fsom,\n",
902+
" background_values=fsom.get_cluster_data().obs.metaclustering,\n",
903+
" view=\"grid\",\n",
904+
" equal_node_size=True,\n",
905+
" equal_background_size=True,\n",
906+
")\n",
901907
"p"
902908
]
903909
},
@@ -927,12 +933,12 @@
927933
],
928934
"source": [
929935
"# Read in that data\n",
930-
"file = open(\"../../tests/data/gating_result.csv\", \"r\")\n",
936+
"file = open(\"../../tests/data/gating_result.csv\")\n",
931937
"data = csv.reader(file)\n",
932938
"data = [i[0] for i in data]\n",
933939
"\n",
934940
"# Plot\n",
935-
"p = fs.pl.plot_pies(fsom, data, background_values = fsom.get_cluster_data().obs.metaclustering)"
941+
"p = fs.pl.plot_pies(fsom, data, background_values=fsom.get_cluster_data().obs.metaclustering)"
936942
]
937943
},
938944
{
@@ -962,7 +968,7 @@
962968
}
963969
],
964970
"source": [
965-
"p = fs.pl.plot_numbers(fsom, level = \"clusters\", text_size = 5)"
971+
"p = fs.pl.plot_numbers(fsom, level=\"clusters\", text_size=5)"
966972
]
967973
},
968974
{
@@ -991,7 +997,7 @@
991997
}
992998
],
993999
"source": [
994-
"p = fs.pl.plot_marker(fsom, marker = np.array([\"CD3\"]))"
1000+
"p = fs.pl.plot_marker(fsom, marker=np.array([\"CD3\"]))"
9951001
]
9961002
},
9971003
{
@@ -1028,13 +1034,13 @@
10281034
],
10291035
"source": [
10301036
"p = fs.pl.plot_2D_scatters(\n",
1031-
" fsom,\n",
1032-
" channelpairs=[[\"CD3\", \"CD4\"], [\"CD19\", \"TCRb\"]],\n",
1033-
" clusters=[[1, 2], [3]],\n",
1034-
" metaclusters=[[4], [5, 6]],\n",
1035-
" density=True,\n",
1036-
" centers=True,\n",
1037-
" )\n",
1037+
" fsom,\n",
1038+
" channelpairs=[[\"CD3\", \"CD4\"], [\"CD19\", \"TCRb\"]],\n",
1039+
" clusters=[[1, 2], [3]],\n",
1040+
" metaclusters=[[4], [5, 6]],\n",
1041+
" density=True,\n",
1042+
" centers=True,\n",
1043+
")\n",
10381044
"p.show()"
10391045
]
10401046
},
@@ -1148,7 +1154,12 @@
11481154
}
11491155
],
11501156
"source": [
1151-
"features = fs.tl.get_features(fsom, files=[ff_t[1:1000, :], ff_t[1000:2000, :]], level = [\"clusters\", \"metaclusters\"], type = [\"counts\", \"percentages\"])\n",
1157+
"features = fs.tl.get_features(\n",
1158+
" fsom,\n",
1159+
" files=[ff_t[1:1000, :], ff_t[1000:2000, :]],\n",
1160+
" level=[\"clusters\", \"metaclusters\"],\n",
1161+
" type=[\"counts\", \"percentages\"],\n",
1162+
")\n",
11521163
"features[\"metacluster_percentages\"]"
11531164
]
11541165
},
@@ -1263,7 +1274,7 @@
12631274
}
12641275
],
12651276
"source": [
1266-
"fs.tl.get_counts(fsom, level = \"clusters\")"
1277+
"fs.tl.get_counts(fsom, level=\"clusters\")"
12671278
]
12681279
},
12691280
{
@@ -1433,7 +1444,9 @@
14331444
}
14341445
],
14351446
"source": [
1436-
"fs.pp.aggregate_flowframes(filenames = [\"../../tests/data/not_preprocessed.fcs\", \"../../tests/data/not_preprocessed.fcs\"], c_total = 5000)"
1447+
"fs.pp.aggregate_flowframes(\n",
1448+
" filenames=[\"../../tests/data/not_preprocessed.fcs\", \"../../tests/data/not_preprocessed.fcs\"], c_total=5000\n",
1449+
")"
14371450
]
14381451
},
14391452
{
@@ -1496,7 +1509,7 @@
14961509
],
14971510
"source": [
14981511
"fsom_new = fsom.new_data(ff_t[1:200, :])\n",
1499-
"fs.pl.plot_stars(fsom_new, background_values = fsom_new.get_cluster_data().obs.metaclustering)"
1512+
"fs.pl.plot_stars(fsom_new, background_values=fsom_new.get_cluster_data().obs.metaclustering)"
15001513
]
15011514
},
15021515
{
@@ -1545,7 +1558,7 @@
15451558
],
15461559
"source": [
15471560
"fsom_subset = fsom.subset(fsom.get_cell_data().obs[\"metaclustering\"] == 4)\n",
1548-
"fs.pl.plot_stars(fsom_subset, background_values = fsom_subset.get_cluster_data().obs.metaclustering)"
1561+
"fs.pl.plot_stars(fsom_subset, background_values=fsom_subset.get_cluster_data().obs.metaclustering)"
15491562
]
15501563
}
15511564
],

src/FlowSOM/io/read_fcs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def read_FCS(filepath):
1919
f.var = f.var.sort_values(by="n")
2020
f.uns["meta"]["channels"].index = f.uns["meta"]["channels"].index.astype(int)
2121
f.uns["meta"]["channels"] = f.uns["meta"]["channels"].sort_index()
22-
except:
22+
except ValueError:
2323
f = pm.io.read_fcs(filepath, reindex=False)
2424
markers = {
2525
str(re.sub("S$", "", re.sub("^P", "", string))): f.uns["meta"][string]
@@ -37,6 +37,7 @@ def read_FCS(filepath):
3737

3838

3939
def read_csv(filepath, spillover=None, **kwargs):
40+
"""Reads in a CSV file."""
4041
ff = ad.read_csv(filepath, **kwargs)
4142
ff.var = pd.DataFrame(
4243
{"n": range(ff.shape[1]), "channel": ff.var_names, "marker": ff.var_names}, index=ff.var.index

src/FlowSOM/main.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,19 @@ def metacluster(self, n_clus):
290290
def consensus_hierarchical_clustering(
291291
self, data, n_clus, n_subsamples=100, linkage="average", resample_proportion=0.9
292292
):
293+
"""Perform a consensus hierarchical clustering.
294+
295+
:param data: The data to cluster
296+
:type data: np.array
297+
:param n_clus: The number of metaclusters
298+
:type n_clus: int
299+
:param n_subsamples: The number of subsamples to use for consensus clustering
300+
:type n_subsamples: int
301+
:param linkage: The linkage method to use for clustering
302+
:type linkage: str
303+
:param resample_proportion: The proportion of the data to use for subsampling
304+
:type resample_proportion: float
305+
"""
293306
average = ConsensusCluster(
294307
AgglomerativeClustering, K=n_clus, H=n_subsamples, resample_proportion=resample_proportion, linkage=linkage
295308
)
@@ -439,15 +452,18 @@ def subset(self, ids):
439452
return fsom_subset
440453

441454
def get_cell_data(self):
455+
"""Get the cell data."""
442456
return self.mudata["cell_data"]
443457

444458
def get_cluster_data(self):
459+
"""Get the cluster data."""
445460
return self.mudata["cluster_data"]
446461

447462

448463
def flowsom_clustering(inp, cols_to_use=None, n_clus=10, xdim=10, ydim=10, seed=None, **kwargs):
449-
"""Perform FlowSOM clustering on an anndata object and returns the anndata
450-
object with the FlowSOM clusters and metaclusters added as variable.
464+
"""Perform FlowSOM clustering on an anndata object and returns the anndata object.
465+
466+
The FlowSOM clusters and metaclusters are added as variable.
451467
452468
:param inp: An anndata or filepath to an FCS file
453469
:type inp: ad.AnnData / str

src/FlowSOM/pl/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
from ._plot_helper_functions import *
2-
from .plot_functions import *

src/FlowSOM/pl/plot_functions.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,18 @@
1414

1515
from flowsom.tl import get_channels, get_markers
1616

17-
from ._plot_helper_functions import *
17+
from ._plot_helper_functions import (
18+
FlowSOM_colors,
19+
add_legend,
20+
add_nodes,
21+
add_stars,
22+
add_text,
23+
add_wedges,
24+
gg_color_hue,
25+
plot_FlowSOM,
26+
plot_star_legend,
27+
scale_star_heights,
28+
)
1829

1930

2031
def plot_2D_scatters(
@@ -195,7 +206,8 @@ def plot_labels(fsom, labels, max_node_size=0, text_size=20, text_color="black",
195206

196207

197208
def plot_numbers(fsom, level="clusters", max_node_size=0, **kwargs):
198-
"""Plot cluster ids for each cluster
209+
"""Plot cluster ids for each cluster.
210+
199211
:param fsom: A FlowSOM object
200212
:type fsom: FlowSOM
201213
:param level: Should be either "clusters" (default) or "metaclusters".
@@ -339,8 +351,7 @@ def plot_pies(
339351
title=None,
340352
**kwargs,
341353
):
342-
"""Plot FlowSOM grid or tree, with pies indicating another clustering or
343-
manual gating result.
354+
"""Plot FlowSOM grid or tree, with pies indicating another clustering or manual gating result.
344355
345356
:param fsom: A FlowSOM object
346357
:type fsom: FlowSOM
@@ -467,7 +478,6 @@ def FlowSOMmary(fsom, plot_file="./FlowSOMmary.pdf"):
467478
np.random.choice(range(fsom.get_cell_data().shape[0]), 5000, replace=False),
468479
fsom.get_cell_data().var_names[ref_markers_bool],
469480
]
470-
subset_fsom
471481
neighbors(subset_fsom)
472482
umap(subset_fsom)
473483

src/FlowSOM/pp/fcs_functions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313

1414
def aggregate_flowframes(filenames, c_total, channels=None, keep_order=False):
15-
"""Aggregate multiple FCS files together
15+
"""Aggregate multiple FCS files together.
16+
1617
:param filenames: An array containing full paths to the FCS files
1718
:type filenames: np.array
1819
:param c_total: Total number of cells to write to the output file
@@ -56,6 +57,17 @@ def aggregate_flowframes(filenames, c_total, channels=None, keep_order=False):
5657

5758

5859
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+
"""
5971
assert isinstance(adata, ad.AnnData), "Please provide an AnnData object"
6072
assert isinstance(channels, list), "Please provide a list of channels"
6173
channels = list(get_markers(adata, channels).keys())

src/FlowSOM/tl/_consensus_clustering.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
class ConsensusCluster:
1717
"""
18-
Implementation of Consensus clustering, following the paper
18+
Implementation of Consensus clustering.
19+
20+
This follows the paper
1921
https://link.springer.com/content/pdf/10.1023%2FA%3A1023949509487.pdf
2022
https://github.com/ZigaSajovic/Consensus_Clustering/blob/master/consensusClustering.py
2123
* cluster -> clustering class
@@ -36,7 +38,8 @@ def __init__(self, cluster, K, H, resample_proportion=0.9, linkage="average"):
3638
self.H_ = H
3739

3840
def _internal_resample(self, data, proportion):
39-
"""
41+
"""Resamples the data.
42+
4043
Args:
4144
* data -> (examples,attributes) format
4245
* proportion -> percentage to sample.

tests/test_basic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,19 @@ def test_FlowSOM_class(FlowSOM_res):
120120
var_true_keys_cell = ["pretty_colnames", "cols_used", "markers", "channels"]
121121

122122
# make sure that at least the true keys are in the object
123-
uns_keys_cell = all([key in cell_data.uns.keys() for key in uns_true_keys_cell])
124-
obs_keys_cell = all([key in cell_data.obs.keys() for key in obs_true_keys_cell])
125-
var_keys_cell = all([key in cell_data.var.keys() for key in var_true_keys_cell])
123+
uns_keys_cell = all(key in cell_data.uns.keys() for key in uns_true_keys_cell)
124+
obs_keys_cell = all(key in cell_data.obs.keys() for key in obs_true_keys_cell)
125+
var_keys_cell = all(key in cell_data.var.keys() for key in var_true_keys_cell)
126126

127127
cluster_data = FlowSOM_res.get_cluster_data()
128128
uns_true_keys_cluster = ["outliers", "graph", "xdim", "ydim", "metacluster_MFIs"]
129129
obs_true_keys_cluster = ["percentages", "metaclustering"]
130130
obsm_true_keys_cluster = ["cv_values", "sd_values", "mad_values", "codes", "grid", "layout"]
131131

132132
# make sure that at least the true keys are in the object
133-
uns_keys_cluster = all([key in cluster_data.uns.keys() for key in uns_true_keys_cluster])
134-
obs_keys_cluster = all([key in cluster_data.obs.keys() for key in obs_true_keys_cluster])
135-
obsm_keys_cluster = all([key in cluster_data.obsm.keys() for key in obsm_true_keys_cluster])
133+
uns_keys_cluster = all(key in cluster_data.uns.keys() for key in uns_true_keys_cluster)
134+
obs_keys_cluster = all(key in cluster_data.obs.keys() for key in obs_true_keys_cluster)
135+
obsm_keys_cluster = all(key in cluster_data.obsm.keys() for key in obsm_true_keys_cluster)
136136
assert all(
137137
[
138138
uns_keys_cell,

0 commit comments

Comments
 (0)