dataframe-toolkit 0.25.0__tar.gz → 0.26.0__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.
Files changed (65) hide show
  1. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/PKG-INFO +9 -3
  2. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/README.md +8 -2
  3. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/pyproject.toml +1 -1
  4. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/pyproject.toml.orig +1 -1
  5. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/heatmap_cmd.py +4 -0
  6. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/phewas_cmd.py +167 -18
  7. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/skills/dftk/SKILL.md +3 -1
  8. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/__init__.py +0 -0
  9. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/cli.py +0 -0
  10. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/__init__.py +0 -0
  11. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/annotate_cmd.py +0 -0
  12. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/append_cmd.py +0 -0
  13. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/base.py +0 -0
  14. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/binx_cmd.py +0 -0
  15. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/box_cmd.py +0 -0
  16. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/chi_cmd.py +0 -0
  17. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/clean_cmd.py +0 -0
  18. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/cleannames_cmd.py +0 -0
  19. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/concat_cmd.py +0 -0
  20. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/corr_cmd.py +0 -0
  21. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/dataset_cmd.py +0 -0
  22. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/describe_cmd.py +0 -0
  23. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/eval_cmd.py +0 -0
  24. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/explode_cmd.py +0 -0
  25. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/fit_cmd.py +0 -0
  26. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/forest_cmd.py +0 -0
  27. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/func_cmd.py +0 -0
  28. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/help.py +0 -0
  29. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/hist_cmd.py +0 -0
  30. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/implode_cmd.py +0 -0
  31. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/info_cmd.py +0 -0
  32. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/interp_cmd.py +0 -0
  33. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/line_cmd.py +0 -0
  34. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/locus_cmd.py +0 -0
  35. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/manhattan_cmd.py +0 -0
  36. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/melt_cmd.py +0 -0
  37. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/merge_cmd.py +0 -0
  38. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/pairs_cmd.py +0 -0
  39. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/pivot_cmd.py +0 -0
  40. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/print_cmd.py +0 -0
  41. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/qq_cmd.py +0 -0
  42. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/query_cmd.py +0 -0
  43. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/randvar_cmd.py +0 -0
  44. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/sample_cmd.py +0 -0
  45. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/scale_cmd.py +0 -0
  46. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/scat_cmd.py +0 -0
  47. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/segid_cmd.py +0 -0
  48. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/skill_cmd.py +0 -0
  49. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/split_cmd.py +0 -0
  50. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/stat_cmd.py +0 -0
  51. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/test_cmd.py +0 -0
  52. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/transpose_cmd.py +0 -0
  53. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/commands/wstat_cmd.py +0 -0
  54. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/__init__.py +0 -0
  55. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/copula.py +0 -0
  56. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/docformats.py +0 -0
  57. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/evalfuncs.py +0 -0
  58. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/gwas.py +0 -0
  59. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/io.py +0 -0
  60. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/plot.py +0 -0
  61. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/seed.py +0 -0
  62. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/seq.py +0 -0
  63. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/common/stats.py +0 -0
  64. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/io.py +0 -0
  65. {dataframe_toolkit-0.25.0 → dataframe_toolkit-0.26.0}/src/dftk/skills/dftk/references/snakemake.md +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: dataframe-toolkit
3
- Version: 0.25.0
3
+ Version: 0.26.0
4
4
  Summary: A command-line toolkit for DataFrame analysis and manipulation
5
5
  Keywords: dataframe,statistics,data analysis,CLI,TSV,pandas
6
6
  Author: Gunnar Pálsson
@@ -170,7 +170,7 @@ publication-quality output.
170
170
  | `pairs` | Scatter-plot matrix with KDEs (or histograms) on the diagonal; `-g` colours groups, `--upper corr` puts r in the upper triangle |
171
171
  | `qq` | QQ plot of p-values: observed against expected -log10(p), confidence band, genomic inflation λ; `-g` one curve and λ per group |
172
172
  | `forest` | Forest plot: one row per estimate with its interval (`--se` or `--ci lo,hi`), `--exp` for odds/hazard ratios on a log axis, `--text`/`--textcol` numbers on the right, `-g` several series per row, `--section` headers |
173
- | `phewas` | PheWAS plot: -log10(p) of each phenotype grouped by category (one colour each), ▲/▼ by the sign of `--betacol`, Bonferroni line, hits labelled |
173
+ | `phewas` | PheWAS plot: -log10(p) of each phenotype grouped by category (one colour each), ▲/▼ by the sign of `--betacol`, Bonferroni line, hits labelled; `--subgraphcol` stacks one panel per model or gene |
174
174
  | `locus` | Regional association plot: -log10(p) in one region coloured by r² with the lead variant (`--ldcol`), lead as a diamond, `--lead`/`--label` by ID or `chr:pos` |
175
175
  | `manhattan` | Genome-wide -log10(p) by position (`Chr`, `pos`, `Pval`, or `--mlogpcol`/`--chi2col`); significance lines, thinning for millions of variants, `-g`/`--subgraphcol` for several scans |
176
176
 
@@ -530,12 +530,18 @@ dftk dataset gwas -o | dftk query -q "Chr == '6' and pos > 31.6e6 and pos < 33.6
530
530
  | dftk locus --ldcol r2 -f locus.png
531
531
  ```
532
532
 
533
- `phewas` draws a phenome-wide scan: -log10(p) of each phenotype, the phenotypes grouped by category along the x axis in one colour per category (columns `category`, `phenotype` and `Pval` unless named with `-c`, `-l` and the p-value options of `manhattan`). With `--betacol beta` the points are triangles pointing up or down with the sign of the effect. The significance line is Bonferroni (0.05 / number of tests) unless `--sig` gives a p-value, and the phenotypes above it are labelled, at most `--label N` (default 10). One row per phenotype: pick one genotype or mask with `query` first.
533
+ `phewas` draws a phenome-wide scan: -log10(p) of each phenotype, the phenotypes grouped by category along the x axis in one colour per category (columns `category`, `phenotype` and `Pval` unless named with `-c`, `-l` and the p-value options of `manhattan`). With `--betacol beta` the points are triangles pointing up or down with the sign of the effect. The significance line is Bonferroni (0.05 / number of tests) unless `--sig` gives a p-value, and the phenotypes above it are labelled, at most `--label N` (default 10). One row per phenotype: pick one genotype or mask with `query` first, or draw one panel each with `--subgraphcol`.
534
534
 
535
535
  ```bash
536
536
  dftk dataset phewas -o | dftk query -q "genotype == 'het'" -o | dftk phewas --betacol beta -f phewas.png
537
537
  ```
538
538
 
539
+ `--subgraphcol COL` stacks one PheWAS per value of a column: burden models of one gene, genes within one model, or genotypes. A phenotype stands at the same x in every panel and the panels share one y axis. The Bonferroni line counts each panel's own tests; `--sig P` draws one line at P in all of them:
540
+
541
+ ```bash
542
+ dftk dataset phewas -o | dftk phewas --betacol beta --subgraphcol genotype -f phewas_by_genotype.png
543
+ ```
544
+
539
545
  `forest` draws one row per estimate: a point with its interval, labels down the left, top to bottom in file order (sort first to order them), and a reference line at 0. Give the interval as two columns (`--ci lo,hi`) or a standard error (`--se se`, ± 1.96 SE, `--level` to change). `--exp` turns log odds ratios (or any log-scale estimate) into ratios on a log axis with the reference at 1; `--text` writes `estimate [lo, hi]` to the right and `--textcol` adds columns such as the p-value or the number of carriers. `-g` puts several series on each row (het and hom carriers, two cohorts), `--section` groups rows under bold headers, `--weighted` sizes the markers by 1/SE². Coefficients from `fit`:
540
546
 
541
547
  `dataset phewas` is a simulated phenome-wide scan of loss-of-function carriers (heterozygous and homozygous rows per phenotype, log odds ratios, five real effects) to try it on:
@@ -140,7 +140,7 @@ publication-quality output.
140
140
  | `pairs` | Scatter-plot matrix with KDEs (or histograms) on the diagonal; `-g` colours groups, `--upper corr` puts r in the upper triangle |
141
141
  | `qq` | QQ plot of p-values: observed against expected -log10(p), confidence band, genomic inflation λ; `-g` one curve and λ per group |
142
142
  | `forest` | Forest plot: one row per estimate with its interval (`--se` or `--ci lo,hi`), `--exp` for odds/hazard ratios on a log axis, `--text`/`--textcol` numbers on the right, `-g` several series per row, `--section` headers |
143
- | `phewas` | PheWAS plot: -log10(p) of each phenotype grouped by category (one colour each), ▲/▼ by the sign of `--betacol`, Bonferroni line, hits labelled |
143
+ | `phewas` | PheWAS plot: -log10(p) of each phenotype grouped by category (one colour each), ▲/▼ by the sign of `--betacol`, Bonferroni line, hits labelled; `--subgraphcol` stacks one panel per model or gene |
144
144
  | `locus` | Regional association plot: -log10(p) in one region coloured by r² with the lead variant (`--ldcol`), lead as a diamond, `--lead`/`--label` by ID or `chr:pos` |
145
145
  | `manhattan` | Genome-wide -log10(p) by position (`Chr`, `pos`, `Pval`, or `--mlogpcol`/`--chi2col`); significance lines, thinning for millions of variants, `-g`/`--subgraphcol` for several scans |
146
146
 
@@ -500,12 +500,18 @@ dftk dataset gwas -o | dftk query -q "Chr == '6' and pos > 31.6e6 and pos < 33.6
500
500
  | dftk locus --ldcol r2 -f locus.png
501
501
  ```
502
502
 
503
- `phewas` draws a phenome-wide scan: -log10(p) of each phenotype, the phenotypes grouped by category along the x axis in one colour per category (columns `category`, `phenotype` and `Pval` unless named with `-c`, `-l` and the p-value options of `manhattan`). With `--betacol beta` the points are triangles pointing up or down with the sign of the effect. The significance line is Bonferroni (0.05 / number of tests) unless `--sig` gives a p-value, and the phenotypes above it are labelled, at most `--label N` (default 10). One row per phenotype: pick one genotype or mask with `query` first.
503
+ `phewas` draws a phenome-wide scan: -log10(p) of each phenotype, the phenotypes grouped by category along the x axis in one colour per category (columns `category`, `phenotype` and `Pval` unless named with `-c`, `-l` and the p-value options of `manhattan`). With `--betacol beta` the points are triangles pointing up or down with the sign of the effect. The significance line is Bonferroni (0.05 / number of tests) unless `--sig` gives a p-value, and the phenotypes above it are labelled, at most `--label N` (default 10). One row per phenotype: pick one genotype or mask with `query` first, or draw one panel each with `--subgraphcol`.
504
504
 
505
505
  ```bash
506
506
  dftk dataset phewas -o | dftk query -q "genotype == 'het'" -o | dftk phewas --betacol beta -f phewas.png
507
507
  ```
508
508
 
509
+ `--subgraphcol COL` stacks one PheWAS per value of a column: burden models of one gene, genes within one model, or genotypes. A phenotype stands at the same x in every panel and the panels share one y axis. The Bonferroni line counts each panel's own tests; `--sig P` draws one line at P in all of them:
510
+
511
+ ```bash
512
+ dftk dataset phewas -o | dftk phewas --betacol beta --subgraphcol genotype -f phewas_by_genotype.png
513
+ ```
514
+
509
515
  `forest` draws one row per estimate: a point with its interval, labels down the left, top to bottom in file order (sort first to order them), and a reference line at 0. Give the interval as two columns (`--ci lo,hi`) or a standard error (`--se se`, ± 1.96 SE, `--level` to change). `--exp` turns log odds ratios (or any log-scale estimate) into ratios on a log axis with the reference at 1; `--text` writes `estimate [lo, hi]` to the right and `--textcol` adds columns such as the p-value or the number of carriers. `-g` puts several series on each row (het and hom carriers, two cohorts), `--section` groups rows under bold headers, `--weighted` sizes the markers by 1/SE². Coefficients from `fit`:
510
516
 
511
517
  `dataset phewas` is a simulated phenome-wide scan of loss-of-function carriers (heterozygous and homozygous rows per phenotype, log odds ratios, five real effects) to try it on:
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dataframe-toolkit"
3
- version = "0.25.0"
3
+ version = "0.26.0"
4
4
  description = "A command-line toolkit for DataFrame analysis and manipulation"
5
5
  readme = "README.md"
6
6
  keywords = [
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dataframe-toolkit"
3
- version = "0.25.0"
3
+ version = "0.26.0"
4
4
  description = "A command-line toolkit for DataFrame analysis and manipulation"
5
5
  readme = "README.md"
6
6
  authors = [
@@ -395,6 +395,10 @@ class HeatmapCommand(BaseCommand):
395
395
  xticklabels=lowest, yticklabels=col == 0,
396
396
  ) # fmt: skip
397
397
  ax.set_title(title)
398
+ if lowest and row < nrows - 1:
399
+ # An empty grid cell below: its labels hang into that space,
400
+ # so the layout needn't widen the gap under the whole row
401
+ ax.xaxis.set_in_layout(False)
398
402
  used.append(ax)
399
403
  for idx in range(len(panels), nrows * ncols):
400
404
  axes[idx // ncols][idx % ncols].set_visible(False)
@@ -30,7 +30,10 @@ from dftk.common.plot import (
30
30
  add_figure_arguments,
31
31
  apply_style,
32
32
  make_figure,
33
+ make_grouplabel,
33
34
  save_or_show,
35
+ subgraph_groups,
36
+ subgraph_layout,
34
37
  )
35
38
 
36
39
  logger = logging.getLogger(__name__)
@@ -71,7 +74,14 @@ of them (default 10; 0 for none); labels that would overlap are moved
71
74
  down.
72
75
 
73
76
  One row per phenotype: several tests of a phenotype (e.g. heterozygous and
74
- homozygous carriers) would stand side by side; pick one with query.
77
+ homozygous carriers) would stand side by side; pick one with query, or
78
+ draw one panel each with --subgraphcol.
79
+
80
+ --subgraphcol COL draws one PheWAS per value of COL (a burden model, a
81
+ gene, a genotype), stacked (--ncols for a grid). A phenotype stands at the
82
+ same x in every panel, a missing one leaves a gap, and the panels share one
83
+ y axis. The Bonferroni line counts each panel's own tests (it is logged
84
+ when the panels differ); --sig P draws one line at P in every panel.
75
85
 
76
86
  EXAMPLES
77
87
  --------
@@ -84,6 +94,11 @@ The simulated scan of heterozygous loss-of-function carriers:
84
94
  dftk dataset phewas -o | dftk query -q "genotype == 'het'" -o \\
85
95
  | dftk phewas --betacol beta -f phewas.png
86
96
 
97
+ Heterozygous and homozygous carriers, one panel each:
98
+
99
+ dftk dataset phewas -o | dftk phewas --betacol beta \\
100
+ --subgraphcol genotype -f phewas_by_genotype.png
101
+
87
102
  Fixed threshold, a suggestive line, more room for the labels:
88
103
 
89
104
  dftk dataset phewas -o | dftk query -q "genotype == 'het'" -o \\
@@ -162,22 +177,58 @@ def layout(data: pd.DataFrame) -> tuple[np.ndarray, list[tuple[str, float, float
162
177
  return x, spans
163
178
 
164
179
 
180
+ def shared_layout(
181
+ panels: list[pd.DataFrame],
182
+ ) -> tuple[list[np.ndarray], list[tuple[str, float, float]]]:
183
+ """x of every row of every panel, and the category spans: one x per
184
+ phenotype (category and label) across all panels, so that a phenotype
185
+ stands at the same place in each; one missing from a panel leaves a gap."""
186
+ keys = pd.concat([p[["_cat", "_label"]] for p in panels]).drop_duplicates()
187
+ x, spans = layout(keys.reset_index(drop=True))
188
+ at = dict(zip(zip(keys["_cat"], keys["_label"], strict=True), x, strict=True))
189
+ xs = [
190
+ np.array([at[k] for k in zip(p["_cat"], p["_label"], strict=True)], dtype=float)
191
+ for p in panels
192
+ ]
193
+ return xs, spans
194
+
195
+
165
196
  def significance(args, n: int) -> float | None:
166
197
  if args.sig == "bonferroni":
167
198
  return 0.05 / n
168
199
  return args.sig
169
200
 
170
201
 
171
- def _draw(ax, data: pd.DataFrame, args) -> None:
172
- x, spans = layout(data)
173
- y = data["_y"].to_numpy()
174
- sign = data["_sign"].to_numpy()
175
- sig = significance(args, len(data))
176
- lines = [-np.log10(p) for p in (sig, args.suggestive) if p is not None]
202
+ def _lines(args, n: int) -> list[float]:
203
+ """-log10 of the significance and suggestive lines for n tests."""
204
+ sig = significance(args, n)
205
+ return [-np.log10(p) for p in (sig, args.suggestive) if p is not None]
206
+
177
207
 
178
- lo, hi = 0.0, max([float(y.max()), *lines, 1.0]) * 1.08
208
+ def _ylim(panels: list[pd.DataFrame], args) -> tuple[float, float]:
209
+ """y limits shared by all panels: room for the highest point or line."""
210
+ top = max(max([float(p["_y"].max()), *_lines(args, len(p))]) for p in panels)
211
+ lo, hi = 0.0, max(top, 1.0) * 1.08
179
212
  if args.ylim is not None:
180
213
  lo, hi = float_or(args.ylim[0], lo), float_or(args.ylim[1], hi)
214
+ return lo, hi
215
+
216
+
217
+ def _draw(
218
+ ax,
219
+ data: pd.DataFrame,
220
+ args,
221
+ x: np.ndarray,
222
+ spans: list[tuple[str, float, float]],
223
+ ylim: tuple[float, float],
224
+ legend: bool = True,
225
+ categories: bool = True,
226
+ ylabel: bool = True,
227
+ ) -> None:
228
+ y = data["_y"].to_numpy()
229
+ sign = data["_sign"].to_numpy()
230
+ sig = significance(args, len(data))
231
+ lo, hi = ylim
181
232
 
182
233
  colour_of = {
183
234
  cat: _CATEGORY_COLOURS[i % len(_CATEGORY_COLOURS)]
@@ -235,7 +286,7 @@ def _draw(ax, data: pd.DataFrame, args) -> None:
235
286
  len(above),
236
287
  )
237
288
 
238
- if args.betacol and (sign != 0).any():
289
+ if legend and args.betacol and (sign != 0).any():
239
290
  from matplotlib.lines import Line2D
240
291
 
241
292
  handles = [
@@ -252,17 +303,23 @@ def _draw(ax, data: pd.DataFrame, args) -> None:
252
303
  )
253
304
 
254
305
  ax.set_xticks([(a + b) / 2 for _, a, b in spans])
255
- ax.set_xticklabels([c for c, _, _ in spans], rotation=45, ha="right")
256
- for label, (cat, _, _) in zip(ax.get_xticklabels(), spans, strict=True):
257
- label.set_color(colour_of[cat])
306
+ if categories:
307
+ ax.set_xticklabels([c for c, _, _ in spans], rotation=45, ha="right")
308
+ for label, (cat, _, _) in zip(ax.get_xticklabels(), spans, strict=True):
309
+ label.set_color(colour_of[cat])
310
+ else:
311
+ ax.set_xticklabels([])
258
312
  ax.tick_params(axis="x", length=0)
259
313
  ax.set_xlim(-_GAP / 2 - 0.5, spans[-1][2] + _GAP / 2 + 0.5)
260
314
  ax.set_ylim(lo, hi)
261
315
  if args.logy is not None:
262
316
  log_yaxis(ax, args.logy, lo, hi)
263
317
  ax.spines[["top", "right"]].set_visible(False)
264
- ax.set_xlabel(args.xlabel if args.xlabel is not None else "")
265
- ax.set_ylabel(args.ylabel if args.ylabel is not None else r"$-\log_{10}(p)$")
318
+ ax.set_xlabel(args.xlabel if args.xlabel is not None and categories else "")
319
+ default_ylabel = r"$-\log_{10}(p)$"
320
+ ax.set_ylabel(
321
+ (args.ylabel if args.ylabel is not None else default_ylabel) if ylabel else ""
322
+ )
266
323
 
267
324
 
268
325
  def spread_labels(fig, ax) -> None:
@@ -280,6 +337,32 @@ def spread_labels(fig, ax) -> None:
280
337
  placed.append(text.get_window_extent(renderer))
281
338
 
282
339
 
340
+ def _panels(data: pd.DataFrame, args) -> tuple[list[str], list[pd.DataFrame]]:
341
+ """Titles and rows of the --subgraphcol panels; logs each panel's
342
+ Bonferroni threshold when they differ."""
343
+ check_cols(data, args.subgraphcol, "--subgraphcol")
344
+ clash = set(args.subgraphcol) & {args.catcol, args.labelcol}
345
+ if clash:
346
+ raise ValueError(f"--subgraphcol {', '.join(sorted(clash))} is also -c or -l")
347
+ groups = subgraph_groups(data, args.subgraphcol, args.subgraphorder)
348
+ if not groups:
349
+ raise ValueError(f"--subgraphcol {' '.join(args.subgraphcol)} has no values")
350
+ titles = [
351
+ make_grouplabel(k, args.subgraphcol, args.subgraphformat) for k, _ in groups
352
+ ]
353
+ panels = [g.reset_index(drop=True) for _, g in groups]
354
+ counts = [len(p) for p in panels]
355
+ if args.sig == "bonferroni" and len(set(counts)) > 1:
356
+ logger.info(
357
+ "Bonferroni line per panel: %s",
358
+ "; ".join(
359
+ f"{t}: 0.05/{n} = {0.05 / n:.2g}"
360
+ for t, n in zip(titles, counts, strict=True)
361
+ ),
362
+ )
363
+ return titles, panels
364
+
365
+
283
366
  class PhewasCommand(BaseCommand):
284
367
  name = "phewas"
285
368
  help = "PheWAS plot: -log10(p) of each phenotype, grouped by category."
@@ -377,6 +460,39 @@ class PhewasCommand(BaseCommand):
377
460
  "(default: best).",
378
461
  )
379
462
 
463
+ s = parser.add_argument_group("panels")
464
+ s.add_argument(
465
+ "--subgraphcol",
466
+ nargs="+",
467
+ default=None,
468
+ metavar="COL",
469
+ help="One PheWAS per value of this column (a burden model, a gene), "
470
+ "stacked, with the phenotypes at the same x and one y axis; the "
471
+ "Bonferroni line counts each panel's own tests.",
472
+ )
473
+ s.add_argument(
474
+ "--subgraphorder",
475
+ nargs="+",
476
+ default=None,
477
+ metavar="VAL",
478
+ help="Panel order for --subgraphcol. Values not listed appear last "
479
+ "in sorted order.",
480
+ )
481
+ s.add_argument(
482
+ "--subgraphformat",
483
+ default=None,
484
+ metavar="TEMPLATE",
485
+ help="Panel title template, with {colname} placeholders, e.g. "
486
+ "'Model: {model}'.",
487
+ )
488
+ s.add_argument(
489
+ "--ncols",
490
+ type=int,
491
+ default=1,
492
+ metavar="N",
493
+ help="Panels per row (default: 1, stacked).",
494
+ )
495
+
380
496
  add_figure_arguments(parser)
381
497
  parser.set_defaults(size="8x4.5")
382
498
 
@@ -401,11 +517,44 @@ class PhewasCommand(BaseCommand):
401
517
  if args.usetex:
402
518
  plt.rc("text", usetex=True)
403
519
  apply_style(args)
404
- fig, axes = make_figure(args)
405
- _draw(axes[0][0], data, args)
406
- axes[0][0].set_title(args.title or "")
520
+ if not args.subgraphcol:
521
+ fig, axes = make_figure(args)
522
+ ax = axes[0][0]
523
+ x, spans = layout(data)
524
+ _draw(ax, data, args, x, spans, _ylim([data], args))
525
+ ax.set_title(args.title or "")
526
+ fig.tight_layout()
527
+ spread_labels(fig, ax)
528
+ save_or_show(fig, args)
529
+ return
530
+
531
+ titles, panels = _panels(data, args)
532
+ xs, spans = shared_layout(panels)
533
+ ylim = _ylim(panels, args)
534
+ nrows, ncols = subgraph_layout(len(panels), args.ncols)
535
+ fig, axes = make_figure(args, nrows=nrows, ncols=ncols)
536
+ used = []
537
+ for idx, (title, panel, x) in enumerate(zip(titles, panels, xs, strict=True)):
538
+ row, col = divmod(idx, ncols)
539
+ ax = axes[row][col]
540
+ # Category names under the lowest panel of each column only
541
+ lowest = idx + ncols >= len(panels)
542
+ _draw(
543
+ ax, panel, args, x, spans, ylim,
544
+ legend=idx == 0, categories=lowest, ylabel=col == 0,
545
+ ) # fmt: skip
546
+ ax.set_title(title)
547
+ if lowest and row < nrows - 1:
548
+ # An empty grid cell below: its labels hang into that space
549
+ ax.xaxis.set_in_layout(False)
550
+ used.append(ax)
551
+ for idx in range(len(panels), nrows * ncols):
552
+ axes[idx // ncols][idx % ncols].set_visible(False)
553
+ if args.title:
554
+ fig.suptitle(args.title)
407
555
  fig.tight_layout()
408
- spread_labels(fig, axes[0][0])
556
+ for ax in used:
557
+ spread_labels(fig, ax)
409
558
  save_or_show(fig, args)
410
559
 
411
560
 
@@ -163,7 +163,9 @@ lambda; same p-value options, `-g` one curve and lambda per group, `--logy`),
163
163
  `locus` (one region, cut out with `query` first: -log10(p) by position, `--ldcol r2`
164
164
  colours by LD with the lead, `--lead`/`--label` take an ID or `chr6:32600000`),
165
165
  `phewas` (-log10(p) per phenotype grouped by `category`, labels from `phenotype`;
166
- `--betacol beta` triangles up/down by sign, Bonferroni line by default, hits labelled),
166
+ `--betacol beta` triangles up/down by sign, Bonferroni line by default, hits labelled;
167
+ `--subgraphcol MODEL` stacks one panel per burden model or gene, same x, one y axis,
168
+ Bonferroni per panel),
167
169
  `forest` (estimates with intervals, one row each, file order top to bottom:
168
170
  `-y LABEL -x EST --se SE` or `--ci LO,HI`; `--exp` for log odds ratios, `--text`
169
171
  `--textcol Pval n` numbers on the right, `-g` series per row, `--section` headers;