pflex 1.3__tar.gz → 1.4.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pflex-1.3 → pflex-1.4.1}/PKG-INFO +3 -4
- {pflex-1.3 → pflex-1.4.1}/README.md +1 -1
- {pflex-1.3 → pflex-1.4.1}/docs/getting-started.md +1 -1
- {pflex-1.3 → pflex-1.4.1}/docs/user-guide.md +21 -3
- {pflex-1.3 → pflex-1.4.1}/pyproject.toml +96 -97
- {pflex-1.3 → pflex-1.4.1}/src/pflex/__init__.py +4 -4
- {pflex-1.3 → pflex-1.4.1}/src/pflex/analysis.py +30 -8
- {pflex-1.3 → pflex-1.4.1}/src/pflex/examples/basic_usage.py +1 -1
- pflex-1.4.1/src/pflex/plotting.py +1739 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/preprocessing.py +4 -2
- pflex-1.4.1/src/pflex/style.py +37 -0
- {pflex-1.3 → pflex-1.4.1}/uv.lock +1942 -1960
- pflex-1.3/src/pflex/plotting.py +0 -1974
- pflex-1.3/tests/test_mpr_filters.py +0 -176
- pflex-1.3/tests/test_plotting_labels.py +0 -205
- {pflex-1.3 → pflex-1.4.1}/.gitignore +0 -0
- {pflex-1.3 → pflex-1.4.1}/.python-version +0 -0
- {pflex-1.3 → pflex-1.4.1}/LICENSE +0 -0
- {pflex-1.3 → pflex-1.4.1}/docs/index.md +0 -0
- {pflex-1.3 → pflex-1.4.1}/docs/installation.md +0 -0
- {pflex-1.3 → pflex-1.4.1}/mkdocs.yml +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/__init__.py +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/example_input/__init__.py +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/example_input/skin_cell_lines_corum_genes.parquet +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/example_input/soft_tissue_cell_lines_corum_genes.parquet +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/functional_standard/CORUM.parquet +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/functional_standard/GOBP.parquet +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/functional_standard/PATHWAY.parquet +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/functional_standard/__init__.py +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/functional_standard/corum.csv +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/functional_standard/gobp.csv +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/data/functional_standard/pathway.csv +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/logging_config.py +0 -0
- {pflex-1.3 → pflex-1.4.1}/src/pflex/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: pflex
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.4.1
|
|
4
4
|
Summary: pflex is a benchmarking toolkit for evaluating CRISPR screen results against biological functional standards. The toolkit computes gene-level and module-level performance metrics, helping researchers systematically assess the biological relevance and resolution of their CRISPR screening data.
|
|
5
5
|
Author-email: Yasir Demirtas <tyasird@hotmail.com>
|
|
6
6
|
License-File: LICENSE
|
|
@@ -10,7 +10,6 @@ Classifier: Programming Language :: Python :: 3
|
|
|
10
10
|
Classifier: Programming Language :: Python :: 3.10
|
|
11
11
|
Classifier: Programming Language :: Python :: 3.11
|
|
12
12
|
Requires-Python: >=3.10
|
|
13
|
-
Requires-Dist: adjusttext
|
|
14
13
|
Requires-Dist: art
|
|
15
14
|
Requires-Dist: bitarray
|
|
16
15
|
Requires-Dist: emoji
|
|
@@ -148,7 +147,7 @@ config = {
|
|
|
148
147
|
},
|
|
149
148
|
"plotting": {
|
|
150
149
|
"save_plot": True,
|
|
151
|
-
"output_type": "
|
|
150
|
+
"output_type": "pdf",
|
|
152
151
|
},
|
|
153
152
|
}
|
|
154
153
|
```
|
|
@@ -70,7 +70,7 @@ config = {
|
|
|
70
70
|
},
|
|
71
71
|
"plotting": {
|
|
72
72
|
"save_plot": True,
|
|
73
|
-
"output_type": "
|
|
73
|
+
"output_type": "pdf",
|
|
74
74
|
},
|
|
75
75
|
"logging": {
|
|
76
76
|
"visible_levels": ["DONE", "INFO", "WARNING"],
|
|
@@ -93,6 +93,7 @@ Configuration keys:
|
|
|
93
93
|
- `per_module.n_jobs`: worker count for per-module analysis.
|
|
94
94
|
- `plotting.save_plot`: when `True`, saves figures to `output_folder`.
|
|
95
95
|
- `plotting.output_type`: figure extension, such as `"png"` or `"pdf"`.
|
|
96
|
+
- `plotting.dpi`: resolution of raster output such as PNG (default `300`). Vector formats (`"pdf"`, `"svg"`) keep text editable.
|
|
96
97
|
- `logging.visible_levels`: log levels to print during the run. Available values are `"STARTED"`, `"PROGRESS"`, `"DONE"`, `"INFO"`, `"WARNING"`, and `"ERROR"`. A quiet run can use `["DONE", "WARNING"]`; a more verbose run can use `["STARTED", "PROGRESS", "DONE", "INFO", "WARNING"]`.
|
|
97
98
|
|
|
98
99
|
## Loading
|
|
@@ -179,6 +180,9 @@ flex.save_results_to_csv()
|
|
|
179
180
|
|
|
180
181
|
Plotting functions read cached analysis results from the current run. If `plotting.save_plot` is `True`, figures are written to `output_folder`.
|
|
181
182
|
|
|
183
|
+
All figures are produced at their final print size (about 3 inches wide, a single journal column) with 8 pt Arial text and thin lines, so they can go into a manuscript without rescaling.
|
|
184
|
+
Each plot has a descriptive default title and a small grey caption under it (`title=` / `caption=` to change them, `""` to remove). Precision-recall, mPR and scatter plots use a square plot area whatever the axis range. Dataset legends go into an empty corner of the plot when one exists, otherwise outside on the right. The complex-filter comparisons (`plot_globalpr_filter`, `plot_mpr_filter`) show one small panel per filter, with datasets in their usual colours and solid lines; in `plot_panels` give them two columns: `(flex.plot_globalpr_filter, {}, 2)`.
|
|
185
|
+
|
|
182
186
|
Global plots:
|
|
183
187
|
|
|
184
188
|
- `plot_precision_recall_curve(line_width=2.0, hide_minor_ticks=True)` shows precision against the cumulative number of true-positive gene pairs. This is the main global performance curve; higher precision at the same true-positive count means better ranking.
|
|
@@ -187,14 +191,28 @@ Global plots:
|
|
|
187
191
|
Per-module plots:
|
|
188
192
|
|
|
189
193
|
- `plot_significant_modules()` counts how many functional-standard terms pass AUPRC thresholds `0.1`, `0.2`, `0.3`, `0.4`, and `0.5`. It returns the threshold-by-dataset count table, which helps compare how many terms are strongly recovered in each dataset.
|
|
190
|
-
- `plot_per_module_scatter(n_top=10, ...)` compares per-module AUPRC values between pairs of datasets. Each point is one functional-standard term. Points near the diagonal perform similarly in both datasets; points far from the diagonal are terms that are stronger in one dataset.
|
|
194
|
+
- `plot_per_module_scatter(n_top=10, ...)` compares per-module AUPRC values between pairs of datasets. Each point is one functional-standard term. Points near the diagonal perform similarly in both datasets; points far from the diagonal are terms that are stronger in one dataset. The figure is publication-ready at its final size (3 × 3 in, 8 pt Arial, 0.25 pt borders, editable text in PDF/SVG). Every highlighted term (top `n_top` in either dataset, including terms top in both) is always labelled; `n_labels` is deprecated and ignored. Reference circle sizes (5, 10, 50 genes) are shown under the plot (`size_legend=False` to hide), using their first word (`short_labels=True`); nearby terms with the same short name share one label, and `label_map={"Full name": "Label"}` overrides individual labels. Labels that cannot be placed without overlap are left out with a warning.
|
|
191
195
|
- `plot_per_module_scatter_by_size(n_labels=10, n_top=10, ...)` plots each term's per-module AUPRC against the number of genes used for that term. It helps distinguish compact high-performing terms from broader modules.
|
|
192
196
|
- `plot_module_contributions(min_pairs=10, min_precision_cutoff=0.5, num_module_to_show=10, ...)` shows which terms contribute most to true-positive gene pairs across precision cutoffs. It requires `module_contributions(name)` first and helps identify which biological terms drive the global precision-recall curve.
|
|
193
197
|
|
|
198
|
+
Multi-panel figures:
|
|
199
|
+
|
|
200
|
+
- Every plot function accepts `ax=` and then draws into that axes instead of a new figure (nothing is saved). Functions that make one figure per dataset or pair take `dataset=` / `pair=` to choose which one.
|
|
201
|
+
- `plot_panels(panels, ncols=2, panel_size=(3.4, 3.6))` builds a figure labelled a, b, c, ... from those functions. Each entry is a function or a `(function, kwargs)` tuple; ticks, labels and legends are fitted inside each panel's cell, and the result is saved as `figure_panels.<output_type>` (`outname=` to change).
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
flex.plot_panels([
|
|
205
|
+
flex.plot_precision_recall_curve,
|
|
206
|
+
(flex.plot_per_module_scatter, {"pair": ("Skin", "Soft Tissue")}),
|
|
207
|
+
flex.plot_auc_scores,
|
|
208
|
+
flex.plot_mpr_module_coverage_curve,
|
|
209
|
+
], ncols=2)
|
|
210
|
+
```
|
|
211
|
+
|
|
194
212
|
mPR preparation and plots:
|
|
195
213
|
|
|
196
214
|
- `mpr_prepare(name, tp_th=1, percent_th=0.1)` prepares the single unfiltered module-coverage mPR curve for one dataset.
|
|
197
|
-
- `plot_mpr_module_coverage_curve(dataset_names=None, colors=None, linewidth=1.
|
|
215
|
+
- `plot_mpr_module_coverage_curve(dataset_names=None, colors=None, linewidth=1.0, show_markers="auto")` compares unfiltered mPR curves across datasets.
|
|
198
216
|
- `plot_mpr_summary(...)` creates the unfiltered module-coverage plot and the dataset-level mPR AUC plot. It does not create a global PR plot.
|
|
199
217
|
- `mpr_filter(name, size_th=30, auprc_th=0.4, ...)` lazily computes the three predefined module-coverage filter variants. `plot_mpr_filter()` plots them and returns the variant AUC table alongside the axes.
|
|
200
218
|
- `globalpr_filter(name, size_th=30, auprc_th=0.4, ...)` lazily computes the matching global PR variants. `plot_globalpr_filter()` plots them.
|
|
@@ -1,97 +1,96 @@
|
|
|
1
|
-
[project]
|
|
2
|
-
name = "pflex"
|
|
3
|
-
version = "1.
|
|
4
|
-
description = "pflex is a benchmarking toolkit for evaluating CRISPR screen results against biological functional standards. The toolkit computes gene-level and module-level performance metrics, helping researchers systematically assess the biological relevance and resolution of their CRISPR screening data."
|
|
5
|
-
readme = "README.md"
|
|
6
|
-
authors = [
|
|
7
|
-
{ name = "Yasir Demirtas", email = "tyasird@hotmail.com" }
|
|
8
|
-
]
|
|
9
|
-
requires-python = ">=3.10"
|
|
10
|
-
classifiers = [
|
|
11
|
-
"Programming Language :: Python :: 3",
|
|
12
|
-
"Programming Language :: Python :: 3.10",
|
|
13
|
-
"Programming Language :: Python :: 3.11",
|
|
14
|
-
"License :: OSI Approved :: MIT License",
|
|
15
|
-
"Operating System :: OS Independent",
|
|
16
|
-
]
|
|
17
|
-
|
|
18
|
-
dependencies = [
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
[
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
[
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
[
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
[
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
[
|
|
58
|
-
|
|
59
|
-
".
|
|
60
|
-
".
|
|
61
|
-
"
|
|
62
|
-
"**/.env",
|
|
63
|
-
"**/.
|
|
64
|
-
"**/.
|
|
65
|
-
"**/.
|
|
66
|
-
"**/.
|
|
67
|
-
"**/.
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"**/*.
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"src/pflex/
|
|
78
|
-
"src/pflex/output/*",
|
|
79
|
-
"src/pflex/examples
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
[
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
[
|
|
93
|
-
|
|
94
|
-
"
|
|
95
|
-
"mkdocs",
|
|
96
|
-
|
|
97
|
-
]
|
|
1
|
+
[project]
|
|
2
|
+
name = "pflex"
|
|
3
|
+
version = "1.4.1"
|
|
4
|
+
description = "pflex is a benchmarking toolkit for evaluating CRISPR screen results against biological functional standards. The toolkit computes gene-level and module-level performance metrics, helping researchers systematically assess the biological relevance and resolution of their CRISPR screening data."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Yasir Demirtas", email = "tyasird@hotmail.com" }
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.10"
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Programming Language :: Python :: 3",
|
|
12
|
+
"Programming Language :: Python :: 3.10",
|
|
13
|
+
"Programming Language :: Python :: 3.11",
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
dependencies = [
|
|
19
|
+
"art",
|
|
20
|
+
"bitarray",
|
|
21
|
+
"emoji",
|
|
22
|
+
"ipython",
|
|
23
|
+
"joblib",
|
|
24
|
+
"loguru",
|
|
25
|
+
"matplotlib",
|
|
26
|
+
"numba",
|
|
27
|
+
"numpy",
|
|
28
|
+
"pandas",
|
|
29
|
+
"pyarrow",
|
|
30
|
+
"python-slugify",
|
|
31
|
+
"scikit-learn",
|
|
32
|
+
"scipy",
|
|
33
|
+
"tqdm",
|
|
34
|
+
"importlib-resources",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.scripts]
|
|
38
|
+
pflex = "pflex:main"
|
|
39
|
+
|
|
40
|
+
[build-system]
|
|
41
|
+
requires = ["hatchling"]
|
|
42
|
+
build-backend = "hatchling.build"
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
ignore = ["F541"]
|
|
46
|
+
|
|
47
|
+
[tool.setuptools]
|
|
48
|
+
include-package-data = true
|
|
49
|
+
|
|
50
|
+
[tool.setuptools.packages.find]
|
|
51
|
+
include = ["pflex*"]
|
|
52
|
+
|
|
53
|
+
[tool.setuptools.package-data]
|
|
54
|
+
pflex = ["data/**/*.parquet", "data/**/*.csv", "data/**/*.tsv", "data/**/*.json", "data/**/*.txt", "data/**/*.xlsx", "data/**/*.xls", "data/**/*.h5", "data/**/*.hdf5"]
|
|
55
|
+
|
|
56
|
+
[tool.hatch.build]
|
|
57
|
+
exclude = [
|
|
58
|
+
".git",
|
|
59
|
+
".github",
|
|
60
|
+
".venv",
|
|
61
|
+
"**/.env",
|
|
62
|
+
"**/.env.*",
|
|
63
|
+
"**/.ipynb_checkpoints",
|
|
64
|
+
"**/.mypy_cache",
|
|
65
|
+
"**/.pytest_cache",
|
|
66
|
+
"**/.ruff_cache",
|
|
67
|
+
"**/.tmp",
|
|
68
|
+
"**/__pycache__",
|
|
69
|
+
"**/*.pyc",
|
|
70
|
+
"**/*.pyo",
|
|
71
|
+
"**/result.pkl",
|
|
72
|
+
"build",
|
|
73
|
+
"dist",
|
|
74
|
+
"examples/output",
|
|
75
|
+
"site",
|
|
76
|
+
"src/pflex/input/*",
|
|
77
|
+
"src/pflex/output/*",
|
|
78
|
+
"src/pflex/examples/output/*",
|
|
79
|
+
"src/pflex/examples/.tmp/*",
|
|
80
|
+
"tmp",
|
|
81
|
+
"temp",
|
|
82
|
+
"wheels",
|
|
83
|
+
]
|
|
84
|
+
|
|
85
|
+
[tool.hatch.build.targets.wheel]
|
|
86
|
+
packages = ["src/pflex"]
|
|
87
|
+
|
|
88
|
+
[tool.uv.sources]
|
|
89
|
+
pflex = { workspace = true }
|
|
90
|
+
|
|
91
|
+
[dependency-groups]
|
|
92
|
+
dev = [
|
|
93
|
+
"pflex",
|
|
94
|
+
"mkdocs",
|
|
95
|
+
"mkdocs-material",
|
|
96
|
+
]
|
|
@@ -3,10 +3,10 @@ from .utils import dsave, dload
|
|
|
3
3
|
from .preprocessing import example_input_path, get_example_data_path, load_datasets, get_common_genes, filter_matrix_by_genes, load_functional_standard, filter_duplicate_terms
|
|
4
4
|
from .analysis import initialize, prepare_terms_for_dataset, pra, pra_per_module, fast_corr, perform_corr, is_symmetric, binary, has_mirror_of_first_pair, convert_full_to_half_matrix, drop_mirror_pairs, quick_sort, module_contributions, save_results_to_csv, update_matploblib_config, mpr_prepare, mpr_filter, globalpr_filter
|
|
5
5
|
from .plotting import (
|
|
6
|
-
|
|
6
|
+
plot_precision_recall_curve, plot_aggregated_pra, plot_iqr_pra, plot_all_runs_pra, plot_per_module_scatter,
|
|
7
7
|
plot_per_module_scatter_by_size, plot_module_contributions, plot_significant_modules, plot_auc_scores,
|
|
8
8
|
plot_mpr_module_coverage_curve, plot_mpr_module_auc_scores, plot_mpr_summary,
|
|
9
|
-
plot_mpr_filter, plot_globalpr_filter
|
|
9
|
+
plot_mpr_filter, plot_globalpr_filter, plot_panels
|
|
10
10
|
)
|
|
11
11
|
|
|
12
12
|
def main():
|
|
@@ -35,9 +35,9 @@ __all__ = [ "log", "example_input_path", "get_example_data_path", "fast_corr",
|
|
|
35
35
|
"filter_matrix_by_genes", "load_functional_standard", "filter_duplicate_terms", "pra", "pra_per_module",
|
|
36
36
|
"prepare_terms_for_dataset",
|
|
37
37
|
"perform_corr", "is_symmetric", "binary", "has_mirror_of_first_pair", "convert_full_to_half_matrix",
|
|
38
|
-
"drop_mirror_pairs", "quick_sort", "module_contributions", "
|
|
38
|
+
"drop_mirror_pairs", "quick_sort", "module_contributions", "plot_precision_recall_curve",
|
|
39
39
|
"plot_aggregated_pra", "plot_iqr_pra", "plot_all_runs_pra", "plot_per_module_scatter", "plot_per_module_scatter_by_size", "plot_module_contributions",
|
|
40
40
|
"plot_significant_modules", "plot_auc_scores", "plot_mpr_module_auc_scores", "save_results_to_csv", "update_matploblib_config",
|
|
41
|
-
"mpr_prepare", "mpr_filter", "globalpr_filter", "plot_mpr_filter", "plot_globalpr_filter",
|
|
41
|
+
"mpr_prepare", "mpr_filter", "globalpr_filter", "plot_mpr_filter", "plot_globalpr_filter", "plot_panels",
|
|
42
42
|
"plot_mpr_module_coverage_curve", "plot_mpr_summary", "main"
|
|
43
43
|
]
|
|
@@ -25,6 +25,10 @@ from .preprocessing import (
|
|
|
25
25
|
load_functional_standard,
|
|
26
26
|
)
|
|
27
27
|
from .utils import dsave, dload, _sanitize, normalize_analysis_genes
|
|
28
|
+
from .style import PUBLICATION_RC
|
|
29
|
+
|
|
30
|
+
# numpy 2.0 renamed trapz to trapezoid; numpy 2.5 removed the old name.
|
|
31
|
+
_trapz = getattr(np, "trapezoid", None) or np.trapz
|
|
28
32
|
|
|
29
33
|
import matplotlib as mpl
|
|
30
34
|
|
|
@@ -129,7 +133,7 @@ def initialize(config={}):
|
|
|
129
133
|
def update_matploblib_config(config=None, font_family="Arial", layout="single"):
|
|
130
134
|
"""
|
|
131
135
|
Configure matplotlib settings optimized for Nature journal figures:
|
|
132
|
-
-
|
|
136
|
+
- 8 pt fonts everywhere (style.PUBLICATION_RC), 300 dpi output
|
|
133
137
|
- Thin spines (0.5 pt), ticks out (left/bottom only), no minor ticks
|
|
134
138
|
- No grid, clean minimalist look
|
|
135
139
|
- Colorblind-friendly Tableau 10 color cycle
|
|
@@ -226,6 +230,13 @@ def update_matploblib_config(config=None, font_family="Arial", layout="single"):
|
|
|
226
230
|
"pdf.use14corefonts": False,
|
|
227
231
|
"svg.fonttype": "none",
|
|
228
232
|
})
|
|
233
|
+
# Same 8 pt style as pflex's own plots (style.PUBLICATION_RC), so user
|
|
234
|
+
# figures and pflex figures match.
|
|
235
|
+
mpl.rcParams.update(PUBLICATION_RC)
|
|
236
|
+
mpl.rcParams["font.sans-serif"] = [font_family] + [
|
|
237
|
+
f for f in PUBLICATION_RC["font.sans-serif"] if f != font_family
|
|
238
|
+
]
|
|
239
|
+
mpl.rcParams["savefig.dpi"] = config.get("plotting", {}).get("dpi", 300)
|
|
229
240
|
|
|
230
241
|
|
|
231
242
|
def _sort_ascending_for_dataset(dataset_name):
|
|
@@ -388,7 +399,7 @@ def _corrected_auc(df: pd.DataFrame) -> float:
|
|
|
388
399
|
valid = df[["precision", "recall"]].replace([np.inf, -np.inf], np.nan).dropna()
|
|
389
400
|
if len(valid) < 2:
|
|
390
401
|
return np.nan
|
|
391
|
-
return
|
|
402
|
+
return _trapz(valid["precision"], valid["recall"]) - valid["precision"].iloc[-1]
|
|
392
403
|
|
|
393
404
|
def _build_gene_to_pair_indices(pairwise_df):
|
|
394
405
|
indices = pairwise_df.index.values
|
|
@@ -497,7 +508,7 @@ def _process_chunk(chunk_terms, min_genes, memmap_path, gene_to_pair_indices):
|
|
|
497
508
|
# Compute regular AUC
|
|
498
509
|
local_auc_scores[idx] = metrics.auc(recall, precision)
|
|
499
510
|
# Compute corrected AUC using the same logic as _corrected_auc function
|
|
500
|
-
local_corrected_auc_scores[idx] =
|
|
511
|
+
local_corrected_auc_scores[idx] = _trapz(precision, recall) - precision.iloc[-1]
|
|
501
512
|
|
|
502
513
|
return {'auc': local_auc_scores, 'corrected_auc': local_corrected_auc_scores}
|
|
503
514
|
|
|
@@ -870,7 +881,7 @@ def perform_corr(df, corr_func):
|
|
|
870
881
|
corr = np.ma.corrcoef(M)
|
|
871
882
|
arr = corr.filled(np.nan)
|
|
872
883
|
df_corr = pd.DataFrame(arr, index=df.index, columns=df.index)
|
|
873
|
-
|
|
884
|
+
df_corr = _nan_diagonal(df_corr)
|
|
874
885
|
# check shape is x_axis x x_axis
|
|
875
886
|
if df_corr.shape != (x_axis, x_axis):
|
|
876
887
|
raise ValueError(f"Correlation matrix shape mismatch: expected ({x_axis}, {x_axis}), got {df_corr.shape}")
|
|
@@ -880,7 +891,7 @@ def perform_corr(df, corr_func):
|
|
|
880
891
|
elif corr_func == "numpy_without_mask":
|
|
881
892
|
corr = np.corrcoef(df.values)
|
|
882
893
|
df_corr = pd.DataFrame(corr, index=df.index, columns=df.index)
|
|
883
|
-
|
|
894
|
+
df_corr = _nan_diagonal(df_corr)
|
|
884
895
|
if df_corr.shape != (x_axis, x_axis):
|
|
885
896
|
raise ValueError(f"Correlation matrix shape mismatch: expected ({x_axis}, {x_axis}), got {df_corr.shape}")
|
|
886
897
|
log.done("Correlation.")
|
|
@@ -889,7 +900,7 @@ def perform_corr(df, corr_func):
|
|
|
889
900
|
|
|
890
901
|
elif corr_func == "numba":
|
|
891
902
|
corr = fast_corr(df)
|
|
892
|
-
|
|
903
|
+
corr = _nan_diagonal(corr)
|
|
893
904
|
if corr.shape != (x_axis, x_axis):
|
|
894
905
|
raise ValueError(f"Correlation matrix shape mismatch: expected ({x_axis}, {x_axis}), got {corr.shape}")
|
|
895
906
|
log.done("Correlation using Numba.")
|
|
@@ -898,11 +909,22 @@ def perform_corr(df, corr_func):
|
|
|
898
909
|
else:
|
|
899
910
|
# Compute correlations and modify diagonal in-place
|
|
900
911
|
corr = df.T.corr()
|
|
901
|
-
|
|
912
|
+
corr = _nan_diagonal(corr)
|
|
902
913
|
if corr.shape != (x_axis, x_axis):
|
|
903
914
|
raise ValueError(f"Correlation matrix shape mismatch: expected ({x_axis}, {x_axis}), got {corr.shape}")
|
|
904
915
|
return corr
|
|
905
916
|
|
|
917
|
+
def _nan_diagonal(corr):
|
|
918
|
+
"""Return ``corr`` with NaN on the diagonal (self-correlations).
|
|
919
|
+
|
|
920
|
+
Works on a copy: with pandas >= 3 (copy-on-write) ``DataFrame.values`` is
|
|
921
|
+
read-only, so filling it in place raises.
|
|
922
|
+
"""
|
|
923
|
+
arr = corr.to_numpy(dtype=float, copy=True)
|
|
924
|
+
np.fill_diagonal(arr, np.nan)
|
|
925
|
+
return pd.DataFrame(arr, index=corr.index, columns=corr.columns)
|
|
926
|
+
|
|
927
|
+
|
|
906
928
|
def fast_corr(df):
|
|
907
929
|
@njit(parallel=True)
|
|
908
930
|
def compute_corr(data):
|
|
@@ -1504,7 +1526,7 @@ def _mpr_modules_auc(
|
|
|
1504
1526
|
if x.size < 2:
|
|
1505
1527
|
return 0.0
|
|
1506
1528
|
|
|
1507
|
-
return float(
|
|
1529
|
+
return float(_trapz(y, x))
|
|
1508
1530
|
|
|
1509
1531
|
|
|
1510
1532
|
|