dataframe-toolkit 0.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.
- dataframe_toolkit-0.4.1/PKG-INFO +230 -0
- dataframe_toolkit-0.4.1/README.md +202 -0
- dataframe_toolkit-0.4.1/pyproject.toml +72 -0
- dataframe_toolkit-0.4.1/src/dftk/__init__.py +4 -0
- dataframe_toolkit-0.4.1/src/dftk/cli.py +72 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/__init__.py +100 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/annotate_cmd.py +165 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/base.py +85 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/binx_cmd.py +130 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/clean_cmd.py +51 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/concat_cmd.py +165 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/corr_cmd.py +281 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/dataset_cmd.py +181 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/describe_cmd.py +360 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/eval_cmd.py +657 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/fit_cmd.py +265 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/func_cmd.py +186 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/help.py +63 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/hist_cmd.py +321 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/interp_cmd.py +271 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/line_cmd.py +320 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/melt_cmd.py +78 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/merge_cmd.py +373 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/pivot_cmd.py +438 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/print_cmd.py +36 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/query_cmd.py +230 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/randvar_cmd.py +199 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/sample_cmd.py +126 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/scale_cmd.py +299 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/scat_cmd.py +278 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/split_cmd.py +130 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/stat_cmd.py +289 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/test_cmd.py +235 -0
- dataframe_toolkit-0.4.1/src/dftk/commands/wstat_cmd.py +163 -0
- dataframe_toolkit-0.4.1/src/dftk/common/__init__.py +8 -0
- dataframe_toolkit-0.4.1/src/dftk/common/io.py +690 -0
- dataframe_toolkit-0.4.1/src/dftk/common/plot.py +566 -0
- dataframe_toolkit-0.4.1/src/dftk/common/seed.py +25 -0
- dataframe_toolkit-0.4.1/src/dftk/common/seq.py +150 -0
- dataframe_toolkit-0.4.1/src/dftk/common/stats.py +214 -0
- dataframe_toolkit-0.4.1/src/dftk/io.py +10 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: dataframe-toolkit
|
|
3
|
+
Version: 0.4.1
|
|
4
|
+
Summary: A command-line toolkit for DataFrame analysis and manipulation
|
|
5
|
+
Keywords: dataframe,statistics,data analysis,CLI,TSV,pandas
|
|
6
|
+
Author: Gunnar Pálsson
|
|
7
|
+
Author-email: Gunnar Pálsson <hemingur@gmail.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Science/Research
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Information Analysis
|
|
13
|
+
Classifier: Topic :: Utilities
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Requires-Dist: pandas>=2.1
|
|
16
|
+
Requires-Dist: numpy>=1.24
|
|
17
|
+
Requires-Dist: pyarrow>=12.0
|
|
18
|
+
Requires-Dist: scipy>=1.10
|
|
19
|
+
Requires-Dist: statsmodels>=0.14
|
|
20
|
+
Requires-Dist: duckdb>=0.8
|
|
21
|
+
Requires-Dist: matplotlib>=3.7
|
|
22
|
+
Requires-Dist: seaborn>=0.12
|
|
23
|
+
Requires-Dist: tqdm>=4.65
|
|
24
|
+
Requires-Python: >=3.12
|
|
25
|
+
Project-URL: Homepage, https://github.com/hemingur/dataframe-toolkit
|
|
26
|
+
Project-URL: Repository, https://github.com/hemingur/dataframe-toolkit
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# dftk — DataFrame analysis and manipulation toolkit
|
|
30
|
+
|
|
31
|
+
`dftk` is a command-line toolkit for exploratory data analysis on TSV files.
|
|
32
|
+
Each subcommand reads tabular data, performs one operation, and writes TSV to
|
|
33
|
+
stdout, making it easy to chain commands in pipelines.
|
|
34
|
+
|
|
35
|
+
`dftk` was developed during computational genomics research as a fast,
|
|
36
|
+
composable alternative to writing one-off pandas scripts. It is designed
|
|
37
|
+
for analysts who live in the terminal and want a consistent, pipeable toolkit
|
|
38
|
+
for the full data analysis pipeline — from initial exploration through
|
|
39
|
+
statistical modelling and publication-quality figures.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
uv tool install dataframe-toolkit
|
|
45
|
+
dftk --help
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Or with `pip`:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install dataframe-toolkit
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
To install the latest `main` branch directly from GitHub:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
uv tool install git+https://github.com/hemingur/dataframe-toolkit.git
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
To install from a local clone:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
git clone https://github.com/hemingur/dataframe-toolkit.git
|
|
64
|
+
cd dataframe-toolkit
|
|
65
|
+
uv tool install .
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Quick example
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
dftk stat data.tsv -c height weight -g sex
|
|
72
|
+
dftk stat data.tsv -c value -g group -o \
|
|
73
|
+
| dftk pivot -i group -v value_mean -o \
|
|
74
|
+
| dftk print
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Subcommands
|
|
78
|
+
|
|
79
|
+
### Data transformation
|
|
80
|
+
|
|
81
|
+
| Command | Description |
|
|
82
|
+
|-----------|--------------------------------------------------------------------------------------|
|
|
83
|
+
| `eval` | Add or modify columns: eval expressions, string/path functions, statistical ops |
|
|
84
|
+
| `query` | Filter rows with pandas query expressions or SQL (`--sql` via DuckDB) |
|
|
85
|
+
| `merge` | Join two tables on key columns (inner/left/right/outer) |
|
|
86
|
+
| `concat` | Concatenate two or more tables row-wise |
|
|
87
|
+
| `melt` | Reshape wide-to-long (`pd.melt`) |
|
|
88
|
+
| `pivot` | Reshape long-to-wide with per-cell aggregation |
|
|
89
|
+
| `func` | Column transforms: cumsum, group mean/sum/min/max/count/median/std, rank, qcut:N |
|
|
90
|
+
| `scale` | Normalise: z-score, min-shift, sum/max/mean scaling, Blom rank, regression residuals |
|
|
91
|
+
| `interp` | Interpolate values from a reference curve into a table (1-D lookup) |
|
|
92
|
+
| `binx` | Assign bin indices to a column based on explicit or generated edges |
|
|
93
|
+
|
|
94
|
+
### Statistics
|
|
95
|
+
|
|
96
|
+
| Command | Description |
|
|
97
|
+
|------------|-----------------------------------------------------------------------------------------------------|
|
|
98
|
+
| `stat` | Descriptive statistics (count/mean/std/CI/SEM/skew/kurtosis) with grouping and bootstrap |
|
|
99
|
+
| `wstat` | Weighted descriptive statistics (wmean, wstd, weighted quantile CI) |
|
|
100
|
+
| `fit` | OLS/robust/weighted regression via R-style formulas; tidy table, `--summary`, `--anova` |
|
|
101
|
+
| `test` | P-values between column pairs: t-test, Mann-Whitney, Wilcoxon, KS, correlations, bootstrap; groups |
|
|
102
|
+
| `corr` | Pairwise column correlations (Pearson/Spearman/Kendall) with optional BCa bootstrap CI |
|
|
103
|
+
| `describe` | Quick column-level summary (dtype, n, n_unique, n_null, sample values) |
|
|
104
|
+
| `randvar` | Sample from a distribution and append as a new column (norm, alpha, beta, …) |
|
|
105
|
+
|
|
106
|
+
### Plots
|
|
107
|
+
|
|
108
|
+
All plot commands write a PNG/PDF when `-f FILE` is given, or display
|
|
109
|
+
interactively otherwise. They support `--groupcol` for colour grouping,
|
|
110
|
+
`--subgraphcol` for subplot grids, and figure/font presets for
|
|
111
|
+
publication-quality output.
|
|
112
|
+
|
|
113
|
+
| Command | Description |
|
|
114
|
+
|---------|-------------------------------------------------------------------------------------------------|
|
|
115
|
+
| `scat` | Scatter plot; optional OLS/robust fit overlay, bubble size (`--sizecol`), colour (`--colorcol`) |
|
|
116
|
+
| `line` | Line plot; optional error bars (`--yerr`) or CI bands (`--yci lo,hi`) and fit overlay |
|
|
117
|
+
| `hist` | Histogram or KDE (`--kde`); normalisation, cumulative mode, mean±σ annotation (`--stats`) |
|
|
118
|
+
|
|
119
|
+
### Utilities
|
|
120
|
+
|
|
121
|
+
| Command | Description |
|
|
122
|
+
|------------|--------------------------------------------------------------------------|
|
|
123
|
+
| `dataset` | Load a curated example dataset from seaborn, statsmodels, or pydataset |
|
|
124
|
+
| `sample` | Random row sampling (with or without replacement, by count or fraction) |
|
|
125
|
+
| `split` | Split a dataframe into one file per group |
|
|
126
|
+
| `annotate` | Read and write provenance metadata (genome, source, …) in parquet files |
|
|
127
|
+
| `print` | Read any dftk input (TSV, stdin, `...` parquet pipe) and write TSV |
|
|
128
|
+
| `clean` | Remove leftover temp parquet pipe files from interrupted pipelines |
|
|
129
|
+
| `help` | List all subcommands or show full help for one: `dftk help stat` |
|
|
130
|
+
|
|
131
|
+
## Common patterns
|
|
132
|
+
|
|
133
|
+
### Chaining commands
|
|
134
|
+
|
|
135
|
+
```bash
|
|
136
|
+
# z-score within group, then fit a model
|
|
137
|
+
dftk scale data.tsv -c expr -g condition -o \
|
|
138
|
+
| dftk fit - -f "expr_z ~ time + batch" -g condition
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Group summary then plot
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
dftk stat results.tsv -c value -g group -o \
|
|
145
|
+
| dftk line - -x group -y value_mean --yerr value_sem -f fig.png
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Wide-to-long then plot overlaid histograms
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
dftk melt data.tsv -i sample -d gene -v expression \
|
|
152
|
+
| dftk hist - -x expression -g gene -k -f dist.png
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Interpolation (standard curve lookup)
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
dftk interp samples.tsv --ref stdcurve.tsv \
|
|
159
|
+
-x fluorescence -v concentration -d conc_ng_ul
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Bootstrap confidence intervals
|
|
163
|
+
|
|
164
|
+
```bash
|
|
165
|
+
dftk stat data.tsv -c value -g group --bootstrap 1000 --randomseed 42 -o \
|
|
166
|
+
| dftk pivot -i group -v value_mean -f mean -o \
|
|
167
|
+
| dftk stat - -c group_A group_B
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Input/output
|
|
171
|
+
|
|
172
|
+
All commands accept:
|
|
173
|
+
|
|
174
|
+
- A TSV filename as a positional argument
|
|
175
|
+
- `-` to read TSV from stdin
|
|
176
|
+
- `...` to receive a parquet path from stdin (written by a previous `-o` command)
|
|
177
|
+
- A `.parquet` filename to read a named parquet file directly
|
|
178
|
+
|
|
179
|
+
Standard output options (available on all tabular commands):
|
|
180
|
+
|
|
181
|
+
- `-o` / `--output` — write a temp parquet for the next piped command instead of TSV to stdout
|
|
182
|
+
- `--select col1 col2 …` — keep only these columns
|
|
183
|
+
- `--drop col1 col2 …` — remove these columns
|
|
184
|
+
- `--round N` — round numeric output
|
|
185
|
+
- `--postquery EXPR` — filter output rows after processing
|
|
186
|
+
- `--meta KEY=VALUE` — embed provenance metadata in parquet output (repeatable)
|
|
187
|
+
|
|
188
|
+
### Provenance annotations
|
|
189
|
+
|
|
190
|
+
Metadata embedded with `--meta` is stored in the parquet file schema and propagates
|
|
191
|
+
automatically through the pipe: every subsequent `-o` write re-embeds it alongside
|
|
192
|
+
any new `--meta` values.
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
# Tag a file at creation
|
|
196
|
+
dftk eval raw.tsv -f "z = x + y" -o results.parquet \
|
|
197
|
+
--meta genome=hg38 --meta source=gwas_2024
|
|
198
|
+
|
|
199
|
+
# Inspect annotations
|
|
200
|
+
dftk annotate results.parquet
|
|
201
|
+
# genome hg38
|
|
202
|
+
# source gwas_2024
|
|
203
|
+
|
|
204
|
+
# Add or update an annotation in-place
|
|
205
|
+
dftk annotate results.parquet --set step=qc_filtered
|
|
206
|
+
|
|
207
|
+
# Annotations survive piping
|
|
208
|
+
dftk eval results.parquet -f "z_scaled = z / 2" -o | dftk scale ... -c z -o scaled.parquet
|
|
209
|
+
dftk annotate scaled.parquet # genome and source still present
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## Figure options (plot commands)
|
|
213
|
+
|
|
214
|
+
```text
|
|
215
|
+
--size single|double|full|WxH figure size (single ≈ 3.5", double ≈ 7.2")
|
|
216
|
+
--fontsize screen|publication|presentation
|
|
217
|
+
-f FILE save to file (PNG/PDF/SVG); omit to display
|
|
218
|
+
--groupcol COL colour-code by this column
|
|
219
|
+
--subgraphcol COL split into subplot grid by this column
|
|
220
|
+
--ncols N columns in subplot grid (default: auto)
|
|
221
|
+
--legend TEXT legend label for ungrouped series
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
## Dependencies
|
|
225
|
+
|
|
226
|
+
- `pandas`, `numpy`, `scipy` — core data handling and statistics
|
|
227
|
+
- `statsmodels` — regression (`fit`, `scale --resid`, `wstat`)
|
|
228
|
+
- `duckdb` — SQL queries (`query --sql`)
|
|
229
|
+
- `matplotlib`, `seaborn` — plots
|
|
230
|
+
- `pyarrow` — parquet I/O backend
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
# dftk — DataFrame analysis and manipulation toolkit
|
|
2
|
+
|
|
3
|
+
`dftk` is a command-line toolkit for exploratory data analysis on TSV files.
|
|
4
|
+
Each subcommand reads tabular data, performs one operation, and writes TSV to
|
|
5
|
+
stdout, making it easy to chain commands in pipelines.
|
|
6
|
+
|
|
7
|
+
`dftk` was developed during computational genomics research as a fast,
|
|
8
|
+
composable alternative to writing one-off pandas scripts. It is designed
|
|
9
|
+
for analysts who live in the terminal and want a consistent, pipeable toolkit
|
|
10
|
+
for the full data analysis pipeline — from initial exploration through
|
|
11
|
+
statistical modelling and publication-quality figures.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
uv tool install dataframe-toolkit
|
|
17
|
+
dftk --help
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Or with `pip`:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install dataframe-toolkit
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
To install the latest `main` branch directly from GitHub:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
uv tool install git+https://github.com/hemingur/dataframe-toolkit.git
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To install from a local clone:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
git clone https://github.com/hemingur/dataframe-toolkit.git
|
|
36
|
+
cd dataframe-toolkit
|
|
37
|
+
uv tool install .
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Quick example
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
dftk stat data.tsv -c height weight -g sex
|
|
44
|
+
dftk stat data.tsv -c value -g group -o \
|
|
45
|
+
| dftk pivot -i group -v value_mean -o \
|
|
46
|
+
| dftk print
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Subcommands
|
|
50
|
+
|
|
51
|
+
### Data transformation
|
|
52
|
+
|
|
53
|
+
| Command | Description |
|
|
54
|
+
|-----------|--------------------------------------------------------------------------------------|
|
|
55
|
+
| `eval` | Add or modify columns: eval expressions, string/path functions, statistical ops |
|
|
56
|
+
| `query` | Filter rows with pandas query expressions or SQL (`--sql` via DuckDB) |
|
|
57
|
+
| `merge` | Join two tables on key columns (inner/left/right/outer) |
|
|
58
|
+
| `concat` | Concatenate two or more tables row-wise |
|
|
59
|
+
| `melt` | Reshape wide-to-long (`pd.melt`) |
|
|
60
|
+
| `pivot` | Reshape long-to-wide with per-cell aggregation |
|
|
61
|
+
| `func` | Column transforms: cumsum, group mean/sum/min/max/count/median/std, rank, qcut:N |
|
|
62
|
+
| `scale` | Normalise: z-score, min-shift, sum/max/mean scaling, Blom rank, regression residuals |
|
|
63
|
+
| `interp` | Interpolate values from a reference curve into a table (1-D lookup) |
|
|
64
|
+
| `binx` | Assign bin indices to a column based on explicit or generated edges |
|
|
65
|
+
|
|
66
|
+
### Statistics
|
|
67
|
+
|
|
68
|
+
| Command | Description |
|
|
69
|
+
|------------|-----------------------------------------------------------------------------------------------------|
|
|
70
|
+
| `stat` | Descriptive statistics (count/mean/std/CI/SEM/skew/kurtosis) with grouping and bootstrap |
|
|
71
|
+
| `wstat` | Weighted descriptive statistics (wmean, wstd, weighted quantile CI) |
|
|
72
|
+
| `fit` | OLS/robust/weighted regression via R-style formulas; tidy table, `--summary`, `--anova` |
|
|
73
|
+
| `test` | P-values between column pairs: t-test, Mann-Whitney, Wilcoxon, KS, correlations, bootstrap; groups |
|
|
74
|
+
| `corr` | Pairwise column correlations (Pearson/Spearman/Kendall) with optional BCa bootstrap CI |
|
|
75
|
+
| `describe` | Quick column-level summary (dtype, n, n_unique, n_null, sample values) |
|
|
76
|
+
| `randvar` | Sample from a distribution and append as a new column (norm, alpha, beta, …) |
|
|
77
|
+
|
|
78
|
+
### Plots
|
|
79
|
+
|
|
80
|
+
All plot commands write a PNG/PDF when `-f FILE` is given, or display
|
|
81
|
+
interactively otherwise. They support `--groupcol` for colour grouping,
|
|
82
|
+
`--subgraphcol` for subplot grids, and figure/font presets for
|
|
83
|
+
publication-quality output.
|
|
84
|
+
|
|
85
|
+
| Command | Description |
|
|
86
|
+
|---------|-------------------------------------------------------------------------------------------------|
|
|
87
|
+
| `scat` | Scatter plot; optional OLS/robust fit overlay, bubble size (`--sizecol`), colour (`--colorcol`) |
|
|
88
|
+
| `line` | Line plot; optional error bars (`--yerr`) or CI bands (`--yci lo,hi`) and fit overlay |
|
|
89
|
+
| `hist` | Histogram or KDE (`--kde`); normalisation, cumulative mode, mean±σ annotation (`--stats`) |
|
|
90
|
+
|
|
91
|
+
### Utilities
|
|
92
|
+
|
|
93
|
+
| Command | Description |
|
|
94
|
+
|------------|--------------------------------------------------------------------------|
|
|
95
|
+
| `dataset` | Load a curated example dataset from seaborn, statsmodels, or pydataset |
|
|
96
|
+
| `sample` | Random row sampling (with or without replacement, by count or fraction) |
|
|
97
|
+
| `split` | Split a dataframe into one file per group |
|
|
98
|
+
| `annotate` | Read and write provenance metadata (genome, source, …) in parquet files |
|
|
99
|
+
| `print` | Read any dftk input (TSV, stdin, `...` parquet pipe) and write TSV |
|
|
100
|
+
| `clean` | Remove leftover temp parquet pipe files from interrupted pipelines |
|
|
101
|
+
| `help` | List all subcommands or show full help for one: `dftk help stat` |
|
|
102
|
+
|
|
103
|
+
## Common patterns
|
|
104
|
+
|
|
105
|
+
### Chaining commands
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
# z-score within group, then fit a model
|
|
109
|
+
dftk scale data.tsv -c expr -g condition -o \
|
|
110
|
+
| dftk fit - -f "expr_z ~ time + batch" -g condition
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Group summary then plot
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
dftk stat results.tsv -c value -g group -o \
|
|
117
|
+
| dftk line - -x group -y value_mean --yerr value_sem -f fig.png
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Wide-to-long then plot overlaid histograms
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
dftk melt data.tsv -i sample -d gene -v expression \
|
|
124
|
+
| dftk hist - -x expression -g gene -k -f dist.png
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Interpolation (standard curve lookup)
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
dftk interp samples.tsv --ref stdcurve.tsv \
|
|
131
|
+
-x fluorescence -v concentration -d conc_ng_ul
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Bootstrap confidence intervals
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
dftk stat data.tsv -c value -g group --bootstrap 1000 --randomseed 42 -o \
|
|
138
|
+
| dftk pivot -i group -v value_mean -f mean -o \
|
|
139
|
+
| dftk stat - -c group_A group_B
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Input/output
|
|
143
|
+
|
|
144
|
+
All commands accept:
|
|
145
|
+
|
|
146
|
+
- A TSV filename as a positional argument
|
|
147
|
+
- `-` to read TSV from stdin
|
|
148
|
+
- `...` to receive a parquet path from stdin (written by a previous `-o` command)
|
|
149
|
+
- A `.parquet` filename to read a named parquet file directly
|
|
150
|
+
|
|
151
|
+
Standard output options (available on all tabular commands):
|
|
152
|
+
|
|
153
|
+
- `-o` / `--output` — write a temp parquet for the next piped command instead of TSV to stdout
|
|
154
|
+
- `--select col1 col2 …` — keep only these columns
|
|
155
|
+
- `--drop col1 col2 …` — remove these columns
|
|
156
|
+
- `--round N` — round numeric output
|
|
157
|
+
- `--postquery EXPR` — filter output rows after processing
|
|
158
|
+
- `--meta KEY=VALUE` — embed provenance metadata in parquet output (repeatable)
|
|
159
|
+
|
|
160
|
+
### Provenance annotations
|
|
161
|
+
|
|
162
|
+
Metadata embedded with `--meta` is stored in the parquet file schema and propagates
|
|
163
|
+
automatically through the pipe: every subsequent `-o` write re-embeds it alongside
|
|
164
|
+
any new `--meta` values.
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Tag a file at creation
|
|
168
|
+
dftk eval raw.tsv -f "z = x + y" -o results.parquet \
|
|
169
|
+
--meta genome=hg38 --meta source=gwas_2024
|
|
170
|
+
|
|
171
|
+
# Inspect annotations
|
|
172
|
+
dftk annotate results.parquet
|
|
173
|
+
# genome hg38
|
|
174
|
+
# source gwas_2024
|
|
175
|
+
|
|
176
|
+
# Add or update an annotation in-place
|
|
177
|
+
dftk annotate results.parquet --set step=qc_filtered
|
|
178
|
+
|
|
179
|
+
# Annotations survive piping
|
|
180
|
+
dftk eval results.parquet -f "z_scaled = z / 2" -o | dftk scale ... -c z -o scaled.parquet
|
|
181
|
+
dftk annotate scaled.parquet # genome and source still present
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Figure options (plot commands)
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
--size single|double|full|WxH figure size (single ≈ 3.5", double ≈ 7.2")
|
|
188
|
+
--fontsize screen|publication|presentation
|
|
189
|
+
-f FILE save to file (PNG/PDF/SVG); omit to display
|
|
190
|
+
--groupcol COL colour-code by this column
|
|
191
|
+
--subgraphcol COL split into subplot grid by this column
|
|
192
|
+
--ncols N columns in subplot grid (default: auto)
|
|
193
|
+
--legend TEXT legend label for ungrouped series
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
## Dependencies
|
|
197
|
+
|
|
198
|
+
- `pandas`, `numpy`, `scipy` — core data handling and statistics
|
|
199
|
+
- `statsmodels` — regression (`fit`, `scale --resid`, `wstat`)
|
|
200
|
+
- `duckdb` — SQL queries (`query --sql`)
|
|
201
|
+
- `matplotlib`, `seaborn` — plots
|
|
202
|
+
- `pyarrow` — parquet I/O backend
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "dataframe-toolkit"
|
|
3
|
+
version = "0.4.1"
|
|
4
|
+
description = "A command-line toolkit for DataFrame analysis and manipulation"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Gunnar Pálsson", email = "hemingur@gmail.com" }
|
|
8
|
+
]
|
|
9
|
+
license = { text = "MIT" }
|
|
10
|
+
keywords = ["dataframe", "statistics", "data analysis", "CLI", "TSV", "pandas"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Science/Research",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Topic :: Scientific/Engineering :: Information Analysis",
|
|
16
|
+
"Topic :: Utilities",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
]
|
|
19
|
+
requires-python = ">=3.12"
|
|
20
|
+
dependencies = [
|
|
21
|
+
"pandas>=2.1",
|
|
22
|
+
"numpy>=1.24",
|
|
23
|
+
"pyarrow>=12.0",
|
|
24
|
+
"scipy>=1.10",
|
|
25
|
+
"statsmodels>=0.14",
|
|
26
|
+
"duckdb>=0.8",
|
|
27
|
+
"matplotlib>=3.7",
|
|
28
|
+
"seaborn>=0.12",
|
|
29
|
+
"tqdm>=4.65",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.urls]
|
|
33
|
+
Homepage = "https://github.com/hemingur/dataframe-toolkit"
|
|
34
|
+
Repository = "https://github.com/hemingur/dataframe-toolkit"
|
|
35
|
+
|
|
36
|
+
[project.scripts]
|
|
37
|
+
dftk = "dftk.cli:main"
|
|
38
|
+
|
|
39
|
+
[build-system]
|
|
40
|
+
requires = ["uv_build>=0.10.4,<0.11.0"]
|
|
41
|
+
build-backend = "uv_build"
|
|
42
|
+
|
|
43
|
+
[tool.uv.build-backend]
|
|
44
|
+
module-name = "dftk"
|
|
45
|
+
|
|
46
|
+
[dependency-groups]
|
|
47
|
+
dev = [
|
|
48
|
+
"pre-commit>=4.6.0",
|
|
49
|
+
"pytest>=8.0",
|
|
50
|
+
"pytest-cov>=7.1.0",
|
|
51
|
+
"ruff>=0.15.12",
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
[tool.pytest.ini_options]
|
|
55
|
+
testpaths = ["tests"]
|
|
56
|
+
|
|
57
|
+
[tool.ruff]
|
|
58
|
+
line-length = 88
|
|
59
|
+
target-version = "py312"
|
|
60
|
+
|
|
61
|
+
[tool.ruff.lint]
|
|
62
|
+
select = [
|
|
63
|
+
"E", # pycodestyle errors
|
|
64
|
+
"W", # pycodestyle warnings
|
|
65
|
+
"F", # pyflakes
|
|
66
|
+
"I", # isort
|
|
67
|
+
"UP", # pyupgrade
|
|
68
|
+
"B", # flake8-bugbear
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[tool.ruff.lint.isort]
|
|
72
|
+
known-first-party = ["dftk"]
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""
|
|
2
|
+
dftk.cli — entry point for the ``dftk`` command.
|
|
3
|
+
|
|
4
|
+
All subcommands are discovered through the COMMANDS list in
|
|
5
|
+
dftk/commands/__init__.py. This file contains no command-specific
|
|
6
|
+
logic and never needs to change when a new subcommand is added.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import argparse
|
|
10
|
+
import logging
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
from dftk import __version__
|
|
14
|
+
from dftk.commands import COMMANDS
|
|
15
|
+
from dftk.common.io import DFTK_TMPDIR
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger("dftk")
|
|
18
|
+
logging.basicConfig(format="%(asctime)s %(module)s %(message)s", level=logging.INFO)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def main() -> None:
|
|
22
|
+
parser = argparse.ArgumentParser(
|
|
23
|
+
prog="dftk",
|
|
24
|
+
description="DataFrame analysis and manipulation toolkit.",
|
|
25
|
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
26
|
+
epilog=(
|
|
27
|
+
"Pipe mode — use -o alone to pass data between commands:\n"
|
|
28
|
+
" dftk stat -g grp -s val -o \\\n"
|
|
29
|
+
" | dftk pivot -i grp -v val_mean -o \\\n"
|
|
30
|
+
" | dftk print\n\n"
|
|
31
|
+
f"Temp pipe files are stored in {DFTK_TMPDIR}\n"
|
|
32
|
+
"Run 'dftk clean' to remove any leftover pipe files."
|
|
33
|
+
),
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
parser.add_argument("--version", action="version", version=f"dftk {__version__}")
|
|
37
|
+
|
|
38
|
+
subparsers = parser.add_subparsers(dest="command", metavar="COMMAND")
|
|
39
|
+
subparsers.required = True
|
|
40
|
+
|
|
41
|
+
for cmd in COMMANDS:
|
|
42
|
+
cmd_parser = subparsers.add_parser(cmd.name, help=cmd.help)
|
|
43
|
+
cmd.add_arguments(cmd_parser)
|
|
44
|
+
cmd_parser.set_defaults(command_instance=cmd)
|
|
45
|
+
|
|
46
|
+
args = parser.parse_args()
|
|
47
|
+
|
|
48
|
+
try:
|
|
49
|
+
args.command_instance.execute(args)
|
|
50
|
+
except FileNotFoundError as exc:
|
|
51
|
+
print(f"File error: {exc}", file=sys.stderr)
|
|
52
|
+
sys.exit(1)
|
|
53
|
+
except ValueError as exc:
|
|
54
|
+
print(f"Input error: {exc}", file=sys.stderr)
|
|
55
|
+
sys.exit(1)
|
|
56
|
+
except RuntimeError as exc:
|
|
57
|
+
print(f"Processing error: {exc}", file=sys.stderr)
|
|
58
|
+
sys.exit(1)
|
|
59
|
+
except Exception as exc:
|
|
60
|
+
import traceback
|
|
61
|
+
|
|
62
|
+
print(
|
|
63
|
+
f"Unexpected error ({type(exc).__name__}): {exc}\n"
|
|
64
|
+
"Please report this with the full traceback below.",
|
|
65
|
+
file=sys.stderr,
|
|
66
|
+
)
|
|
67
|
+
traceback.print_exc(file=sys.stderr)
|
|
68
|
+
sys.exit(1)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
if __name__ == "__main__":
|
|
72
|
+
main()
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# dftk.commands — explicit registry of all dftk subcommands.
|
|
2
|
+
#
|
|
3
|
+
# To add a new subcommand:
|
|
4
|
+
# 1. Create src/dftk/commands/<name>.py with a class that inherits
|
|
5
|
+
# from BaseCommand (see base.py for the contract and an example skeleton).
|
|
6
|
+
# 2. Import the class here and add an instance to command_list below.
|
|
7
|
+
# That's it — cli.py discovers commands solely through this COMMANDS list.
|
|
8
|
+
|
|
9
|
+
from dftk.commands.annotate_cmd import AnnotateCommand
|
|
10
|
+
from dftk.commands.binx_cmd import BinxCommand
|
|
11
|
+
from dftk.commands.clean_cmd import CleanCommand
|
|
12
|
+
from dftk.commands.concat_cmd import ConcatCommand
|
|
13
|
+
from dftk.commands.corr_cmd import CorrCommand
|
|
14
|
+
from dftk.commands.dataset_cmd import DatasetCommand
|
|
15
|
+
from dftk.commands.describe_cmd import DescribeCommand
|
|
16
|
+
from dftk.commands.eval_cmd import EvalCommand
|
|
17
|
+
from dftk.commands.fit_cmd import FitCommand
|
|
18
|
+
from dftk.commands.func_cmd import FuncCommand
|
|
19
|
+
from dftk.commands.help import HelpCommand
|
|
20
|
+
from dftk.commands.hist_cmd import HistCommand
|
|
21
|
+
from dftk.commands.interp_cmd import InterpCommand
|
|
22
|
+
from dftk.commands.line_cmd import LineCommand
|
|
23
|
+
from dftk.commands.melt_cmd import MeltCommand
|
|
24
|
+
from dftk.commands.merge_cmd import MergeCommand
|
|
25
|
+
from dftk.commands.pivot_cmd import PivotCommand
|
|
26
|
+
from dftk.commands.print_cmd import PrintCommand
|
|
27
|
+
from dftk.commands.query_cmd import QueryCommand
|
|
28
|
+
from dftk.commands.randvar_cmd import RandvarCommand
|
|
29
|
+
from dftk.commands.sample_cmd import SampleCommand
|
|
30
|
+
from dftk.commands.scale_cmd import ScaleCommand
|
|
31
|
+
from dftk.commands.scat_cmd import ScatCommand
|
|
32
|
+
from dftk.commands.split_cmd import SplitCommand
|
|
33
|
+
from dftk.commands.stat_cmd import StatCommand
|
|
34
|
+
from dftk.commands.test_cmd import TestCommand
|
|
35
|
+
from dftk.commands.wstat_cmd import WstatCommand
|
|
36
|
+
|
|
37
|
+
# Ported subcommands — uncomment as each one is added:
|
|
38
|
+
# from dftk.commands.segid import SegidCommand
|
|
39
|
+
# from dftk.commands.info import InfoCommand
|
|
40
|
+
# from dftk.commands.transpose import TransposeCommand
|
|
41
|
+
# from dftk.commands.color import ColorCommand
|
|
42
|
+
# from dftk.commands.wavelet import WaveletCommand
|
|
43
|
+
# from dftk.commands.fisher import FisherCommand # superseded by eval's
|
|
44
|
+
# # fisher_test/fisher_OR
|
|
45
|
+
|
|
46
|
+
COMMAND_GROUPS: list[tuple[str, list]] = [
|
|
47
|
+
(
|
|
48
|
+
"Data transformation",
|
|
49
|
+
[
|
|
50
|
+
EvalCommand(),
|
|
51
|
+
QueryCommand(),
|
|
52
|
+
MergeCommand(),
|
|
53
|
+
ConcatCommand(),
|
|
54
|
+
MeltCommand(),
|
|
55
|
+
PivotCommand(),
|
|
56
|
+
FuncCommand(),
|
|
57
|
+
ScaleCommand(),
|
|
58
|
+
InterpCommand(),
|
|
59
|
+
BinxCommand(),
|
|
60
|
+
],
|
|
61
|
+
),
|
|
62
|
+
(
|
|
63
|
+
"Statistics",
|
|
64
|
+
[
|
|
65
|
+
StatCommand(),
|
|
66
|
+
WstatCommand(),
|
|
67
|
+
FitCommand(),
|
|
68
|
+
TestCommand(),
|
|
69
|
+
CorrCommand(),
|
|
70
|
+
DescribeCommand(),
|
|
71
|
+
RandvarCommand(),
|
|
72
|
+
],
|
|
73
|
+
),
|
|
74
|
+
(
|
|
75
|
+
"Plots",
|
|
76
|
+
[
|
|
77
|
+
ScatCommand(),
|
|
78
|
+
LineCommand(),
|
|
79
|
+
HistCommand(),
|
|
80
|
+
],
|
|
81
|
+
),
|
|
82
|
+
(
|
|
83
|
+
"Utilities",
|
|
84
|
+
[
|
|
85
|
+
DatasetCommand(),
|
|
86
|
+
SampleCommand(),
|
|
87
|
+
SplitCommand(),
|
|
88
|
+
AnnotateCommand(),
|
|
89
|
+
PrintCommand(),
|
|
90
|
+
CleanCommand(),
|
|
91
|
+
],
|
|
92
|
+
),
|
|
93
|
+
]
|
|
94
|
+
|
|
95
|
+
command_list = [cmd for _, cmds in COMMAND_GROUPS for cmd in cmds]
|
|
96
|
+
|
|
97
|
+
# HelpCommand receives the live list and groups so it can introspect any peer.
|
|
98
|
+
help_command = HelpCommand(command_list, COMMAND_GROUPS)
|
|
99
|
+
|
|
100
|
+
COMMANDS = command_list + [help_command]
|