catomatic 0.1.3__tar.gz → 0.2.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 (34) hide show
  1. catomatic-0.2.0/PKG-INFO +323 -0
  2. catomatic-0.2.0/README.md +298 -0
  3. catomatic-0.2.0/pyproject.toml +62 -0
  4. catomatic-0.2.0/setup.cfg +4 -0
  5. catomatic-0.2.0/src/catomatic/BinaryCatalogue.py +584 -0
  6. catomatic-0.2.0/src/catomatic/PiezoTools.py +241 -0
  7. catomatic-0.2.0/src/catomatic/RegressionCatalogue.py +858 -0
  8. catomatic-0.2.0/src/catomatic/__init__.py +4 -0
  9. {catomatic-0.1.3 → catomatic-0.2.0}/src/catomatic/__main__.py +1 -11
  10. {catomatic-0.1.3 → catomatic-0.2.0}/src/catomatic/cli.py +55 -119
  11. catomatic-0.2.0/src/catomatic/defence_module.py +376 -0
  12. catomatic-0.2.0/src/catomatic.egg-info/PKG-INFO +323 -0
  13. {catomatic-0.1.3 → catomatic-0.2.0}/src/catomatic.egg-info/SOURCES.txt +4 -3
  14. catomatic-0.2.0/src/catomatic.egg-info/entry_points.txt +2 -0
  15. catomatic-0.2.0/src/catomatic.egg-info/requires.txt +10 -0
  16. {catomatic-0.1.3 → catomatic-0.2.0}/src/catomatic.egg-info/top_level.txt +1 -0
  17. catomatic-0.2.0/src/tests/test_BuildBinaryCatalogue.py +557 -0
  18. catomatic-0.2.0/src/tests/test_BuildRegressionCatalogue.py +595 -0
  19. catomatic-0.1.3/PKG-INFO +0 -119
  20. catomatic-0.1.3/README.md +0 -101
  21. catomatic-0.1.3/pyproject.toml +0 -3
  22. catomatic-0.1.3/setup.cfg +0 -37
  23. catomatic-0.1.3/src/catomatic/BinaryCatalogue.py +0 -511
  24. catomatic-0.1.3/src/catomatic/Ecoff.py +0 -178
  25. catomatic-0.1.3/src/catomatic/PiezoTools.py +0 -202
  26. catomatic-0.1.3/src/catomatic/RegressionCatalogue.py +0 -758
  27. catomatic-0.1.3/src/catomatic/defence_module.py +0 -307
  28. catomatic-0.1.3/src/catomatic.egg-info/PKG-INFO +0 -119
  29. catomatic-0.1.3/src/catomatic.egg-info/entry_points.txt +0 -4
  30. catomatic-0.1.3/src/catomatic.egg-info/requires.txt +0 -4
  31. {catomatic-0.1.3 → catomatic-0.2.0}/LICENSE +0 -0
  32. {catomatic-0.1.3 → catomatic-0.2.0}/src/catomatic.egg-info/dependency_links.txt +0 -0
  33. {catomatic-0.1.3 → catomatic-0.2.0}/src/catomatic.egg-info/not-zip-safe +0 -0
  34. {catomatic-0.1.3/src/catomatic → catomatic-0.2.0/src/tests}/__init__.py +0 -0
@@ -0,0 +1,323 @@
1
+ Metadata-Version: 2.4
2
+ Name: catomatic
3
+ Version: 0.2.0
4
+ Summary: A tool for automatically building catalogues of antibiotic resistance-associated variants
5
+ Author: Dylan Adlard
6
+ Author-email: Philip W Fowler <philip.fowler@ndm.ox.ac.uk>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/fowler-lab/catomatic
9
+ Keywords: resistance catalogue,tuberculosis,clinical microbiology
10
+ Classifier: Programming Language :: Python :: 3
11
+ Requires-Python: >=3.6
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: piezo
15
+ Requires-Dist: numpy
16
+ Requires-Dist: scipy
17
+ Requires-Dist: pandas
18
+ Requires-Dist: intreg
19
+ Requires-Dist: scikit-learn
20
+ Requires-Dist: pytest
21
+ Requires-Dist: mypy
22
+ Requires-Dist: pandas-stubs
23
+ Requires-Dist: pytest
24
+ Dynamic: license-file
25
+
26
+ [![codecov](https://codecov.io/gh/fowler-lab/catomatic/branch/ecoff/graph/badge.svg?token=8fnOy6rHCd)](https://codecov.io/gh/fowler-lab/catomatic) [![DOI](https://zenodo.org/badge/801462003.svg)](https://doi.org/10.5281/zenodo.14917920)
27
+
28
+ # catomatic
29
+
30
+ catomatic is a Python toolkit for algorithmically constructing antimicrobial resistance (AMR) mutation catalogues directly from variant calls generated by read mapping. Rather than relying on alignment-level pattern matching or predefined resistance motifs, the tool infers resistance associations statistically from observed genotype–phenotype relationships, supporting both binary frequentist and regression-based modelling approaches.
31
+
32
+ This design is particularly well suited to Mycobacterium species, where resistance is primarily driven by chromosomal point mutations, indels, and complex multi-locus interactions, and where horizontal gene transfer is rare. By operating on mapped mutation data rather than alignment outputs, the framework enables transparent evidence tracking, flexible statistical testing, and reproducible catalogue construction tailored to the evolutionary and genomic characteristics of mycobacteria.
33
+
34
+ For aligment-relevant approaches, see AMRverse.
35
+
36
+ ## Introduction
37
+
38
+ This repo contains 2 approaches to build resistance catalogues:
39
+
40
+ 1. **Definite defectives (solo-based approach)**
41
+ 2. **Interval regression**
42
+
43
+ The first is used in [https://doi.org/10.1101/2025.01.30.635633](https://doi.org/10.1101/2025.01.30.635633), and the second is a Python translation of the method used in [https://doi.org/10.1038/s41467-023-44325-5](https://doi.org/10.1038/s41467-023-44325-5).
44
+
45
+ ---
46
+
47
+ ## Binary Builder
48
+
49
+ This method relies on the logic that mutations that do not cause resistance can co-occur with those that do. If a mutation in isolation (solo) does not cause resistance, then it is not contributing to the phenotype when present in a mixture either.
50
+
51
+ Mutations that occur in isolation across specified genes are traversed in sequence, and if their proportion of drug-susceptibility (vs. resistance) passes the specified statistical test, they are characterized as benign (susceptible) and removed from the dataset. This step repeats iteratively until no more solo benign mutations are found.
52
+
53
+ Remaining mutations are classified based on their resistance rates and statistical test results. Those that don’t meet thresholds are labeled as `U`.
54
+
55
+ The classification approach supports:
56
+
57
+ - **No test**: assumes homogeneous susceptibility is sufficient for S
58
+ - **Binomial test**: against a specified background resistance rate
59
+ - **Fisher's test**: using a contingency background
60
+
61
+ ### Optional Interventions
62
+
63
+ 1. **Seeding**: You can pre-seed the catalogue with known neutral mutations.
64
+ 2. **Overrides**: You can override or supplement the final catalogue with manual or rule-based entries.
65
+
66
+ Because the method uses GARC1 grammar, rules like `{rpoB@*_fs:R}` can be supplied post-hoc. These rules can:
67
+
68
+ - Be additive (lower priority than specific entries)
69
+ - Replace matching mutations (requires `replace=True` and `wildcards` supplied)
70
+
71
+ The catalogue can be returned as a dictionary or a Piezo-compatible `pandas.DataFrame`.
72
+
73
+ Contingency tables, proportions, p-values, and Wilson confidence intervals are stored in the `EVIDENCE` field.
74
+
75
+ ### Example Workflow using Fisher's:
76
+
77
+ ![Catalogue Diagram](docs/workflow.png)
78
+
79
+ ---
80
+
81
+ ## Regression Builder
82
+
83
+ The Regression Builder implements a mixed-effect interval regression-based approach for catalogue construction to generate predicted mean MICs. It is suitable when the phenotypes are censored or uncesnored MICs.
84
+
85
+ If whole genome SNPs are provided, agglomerative clustering can compute random effects to control for population structure. Any given number of fixed-effects (such as lineage and lab) can also be defined by supplying additional input columns.
86
+
87
+ Similarly to the BinaryBuilder, catalogues can be exported as json objects or piezo-compatible tables.
88
+
89
+ ---
90
+
91
+ ## Installation
92
+
93
+ ### Installation from source
94
+
95
+ Assuming in project directory (after git cloning)
96
+
97
+ ```bash
98
+ pip install -e .
99
+ ```
100
+
101
+ ### Pypy installation
102
+
103
+ ```bash
104
+ pip install catomatic
105
+ ```
106
+
107
+ ## Running catomatic's Binary Builder
108
+
109
+ You need two input DataFrames:
110
+
111
+ - **Samples**: one row per sample, with 'R' or 'S' phenotypes (`UNIQUEID`, `PHENOTYPE`)
112
+ - **Mutations**: one row per mutation per sample (`UNIQUEID`, `MUTATION`)
113
+
114
+ If exporting to Piezo format (`--to_piezo`):
115
+
116
+ - The `MUTATION` column must follow GARC1 grammar (`gene@mutation`)
117
+ - A path to a `wildcards.json` file (containing mutation rules) must be provided
118
+
119
+ ### Python/Jupyter Example
120
+
121
+ ```python
122
+ from catomatic.BinaryCatalogue import BinaryBuilder
123
+
124
+ # Build catalogue
125
+ catalogue = BinaryBuilder(samples=samples_df, mutations=mutations_df).build()
126
+
127
+ # View dictionary version
128
+ cat_dict = catalogue.return_catalogue()
129
+
130
+ # Convert to Piezo-compatible format
131
+ catalogue_df = catalogue.build_piezo(
132
+ genbank_ref='...',
133
+ catalogue_name='...',
134
+ version='...',
135
+ drug='...',
136
+ wildcards='path/to/wildcards.json'
137
+ )
138
+
139
+ # Optionally export to CSV
140
+ catalogue.to_piezo(
141
+ genbank_ref='...',
142
+ catalogue_name='...',
143
+ version='...',
144
+ drug='...',
145
+ wildcards='path/to/wildcards.json',
146
+ outfile='path/to/output.csv'
147
+ )
148
+ ```
149
+
150
+ ### CLI
151
+
152
+ After installation, the simplest way to run the catomatic catalogue builder is via the command line interface using the `binary` subcommand. You must use either `--to_piezo` or `--to_json` to specify the output format. Additional metadata is required when using `--to_piezo`.
153
+
154
+ #### Export to JSON
155
+
156
+ ```bash
157
+ catomatic binary \
158
+ --samples path/to/samples.csv \
159
+ --mutations path/to/mutations.csv \
160
+ --to_json \
161
+ --outfile path/to/output/catalogue.json
162
+ ```
163
+
164
+ #### Export to Piezo format
165
+
166
+ ```bash
167
+ catomatic binary \
168
+ --samples path/to/samples.csv \
169
+ --mutations path/to/mutations.csv \
170
+ --to_piezo \
171
+ --outfile path/to/output/catalogue.csv \
172
+ --genbank_ref '...' \
173
+ --catalogue_name '...' \
174
+ --version '...' \
175
+ --drug '...' \
176
+ --wildcards path/to/wildcards.json
177
+ ```
178
+
179
+ ### CLI Parameters
180
+
181
+ | Parameter | Type | Description |
182
+ | ------------------ | ------- | ---------------------------------------------------------------------------------------------- |
183
+ | `--samples` | `str` | Path to the samples (phenotypes) file. Required. |
184
+ | `--mutations` | `str` | Path to the mutations file. Required. |
185
+ | `--outfile` | `str` | Output file path for saving the catalogue. Required with `--to_json` or `--to_piezo`. |
186
+ | `--to_json` | `flag` | Export the resulting catalogue in JSON format. Optional. |
187
+ | `--to_piezo` | `flag` | Export the resulting catalogue in Piezo-compatible CSV format. Optional. |
188
+ | `--genbank_ref` | `str` | GenBank reference string for Piezo export. Required with `--to_piezo`. |
189
+ | `--catalogue_name` | `str` | Name of the catalogue. Required with `--to_piezo`. |
190
+ | `--version` | `str` | Catalogue version. Required with `--to_piezo`. |
191
+ | `--drug` | `str` | Name of the drug. Required with `--to_piezo`. |
192
+ | `--wildcards` | `str` | Path to JSON file containing wildcard mutation definitions. Required with `--to_piezo`. |
193
+ | `--test` | `str` | Type of statistical test to apply. One of: `None`, `Binomial`, or `Fisher`. Optional. |
194
+ | `--background` | `float` | Background mutation rate (0–1). Required if `--test Binomial` is used. |
195
+ | `--p` | `float` | P-value threshold for statistical significance. Optional. Defaults to `0.95`. |
196
+ | `--tails` | `str` | Tail type for statistical test. One of: `one`, `two`. Optional. Defaults to `two`. |
197
+ | `--strict_unlock` | `flag` | If set, disables classification of susceptible (`S`) mutations unless statistically confident. |
198
+
199
+ ## Running catomatic's Regression Builder
200
+
201
+ You need two input DataFrames:
202
+
203
+ - **Samples**: one row per sample, with an MIC column (`UNIQUEID`, `MIC`)
204
+ - **Mutations**: one row per mutation per sample (`UNIQUEID`, `MUTATION`)
205
+
206
+ If exporting to Piezo format (`--to_piezo`):
207
+
208
+ - The `MUTATION` column must follow GARC1 grammar (`gene@mutation`)
209
+ - A path to a `wildcards.json` file (containing mutation rules) must be provided
210
+
211
+ ### Python/Jupyter Example
212
+
213
+ ```python
214
+ from catomatic.RegressionCatalogue import RegressionBuilder
215
+
216
+ # fit the model to generate mutation effects
217
+ model, effects = RegressionBuilder(samples=samples_df, mutations=mutations_df).predict_effects()
218
+
219
+ # classify effects and generate a catalogue (requires an ecoff)
220
+ catalogue = RegressionBuilder(samples=samples_df, mutations=mutations_df).build(ecoff=1.0)
221
+
222
+ # View dictionary version
223
+ cat_dict = catalogue.return_catalogue()
224
+
225
+ # Convert to Piezo-compatible format
226
+ catalogue_df = catalogue.build_piezo(
227
+ genbank_ref='...',
228
+ catalogue_name='...',
229
+ version='...',
230
+ drug='...',
231
+ wildcards='path/to/wildcards.json'
232
+ )
233
+
234
+ # Optionally export to CSV
235
+ catalogue.to_piezo(
236
+ genbank_ref='...',
237
+ catalogue_name='...',
238
+ version='...',
239
+ drug='...',
240
+ wildcards='path/to/wildcards.json',
241
+ outfile='path/to/output.csv'
242
+ )
243
+ ```
244
+
245
+ ### CLI
246
+
247
+ Similarly to BinaryBuilder, one can instantiate RegressionBuilder from the command line:
248
+
249
+ #### Export to JSON
250
+
251
+ ```bash
252
+ catomatic regression \
253
+ --samples path/to/samples.csv \
254
+ --mutations path/to/mutations.csv \
255
+ --ecoff 1.0 \
256
+ --to_json \
257
+ --outfile path/to/output/catalogue.json
258
+ ```
259
+
260
+ #### Export to Piezo format
261
+
262
+ ```bash
263
+ catomatic regression \
264
+ --samples path/to/samples.csv \
265
+ --mutations path/to/mutations.csv \
266
+ --ecoff 1.0 \
267
+ --to_piezo \
268
+ --outfile path/to/output/catalogue.csv \
269
+ --genbank_ref '...' \
270
+ --catalogue_name '...' \
271
+ --version '...' \
272
+ --drug '...' \
273
+ --wildcards path/to/wildcards.json
274
+ ```
275
+
276
+ ### CLI Parameters
277
+
278
+ ### CLI Parameters (Regression Builder)
279
+
280
+ | Parameter | Type | Description & default |
281
+ | -------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------- |
282
+ | `--samples` | `str` | Path to the samples file (CSV). **Required**. |
283
+ | `--mutations` | `str` | Path to the mutations file (CSV). **Required**. |
284
+ | `--genes` | `str[]` | List of RAV genes. Required when non-RAV genes appear in the mutations table (e.g. when clustering SNP distances). Default: `[]`. |
285
+ | `--dilution_factor` | `int` | Dilution factor used in processing. Default: `2`. |
286
+ | `--censored` | `flag` | Treat phenotype data as censored. Default: `False`. |
287
+ | `--tail_dilutions` | `int` | Tail dilutions to use for uncensored data. Default: `1`. |
288
+ | `--frs` | `float` | Fraction Read Support threshold. Default: `None`. |
289
+ | `--ecoff` | `float` | Epidemiological cutoff value for classification. If `None`, it will be computed. Default: `None`. |
290
+ | `--b_bounds` | `float,float` | Bounds for beta (fixed-effect) coefficients. Two floats: `(min max)`. Default: `(None, None)`. |
291
+ | `--u_bounds` | `float,float` | Bounds for random-effect coefficients. Two floats: `(min max)`. Default: `(None, None)`. |
292
+ | `--s_bounds` | `float,float` | Bounds for sigma (residual variance). Two floats: `(min max)`. Default: `(None, None)`. |
293
+ | `--p` | `float` | Significance / confidence level. Default: `0.95`. |
294
+ | `--fixed_effects` | `str[]` | Column names to include as fixed effects. Default: `None`. |
295
+ | `--random_effects` | `flag` | Perform SNP clustering and include cluster as a random effect. Default: `False`. |
296
+ | `--cluster_distance` | `float` | Distance threshold for SNP clustering. Default: `1`. |
297
+ | `--outfile` | `str` | Path to save output JSON or Piezo file. Required with `--to_json` or `--to_piezo`. |
298
+ | `--options` | `dict` | Options passed to `scipy.optimize.minimize`. Default: `None`. |
299
+ | `--L2_penalties` | `dict` | Regularisation penalties for fixed and random effects. Default: `None`. |
300
+ | `--to_json` | `flag` | Export the resulting catalogue to JSON format. |
301
+ | `--to_piezo` | `flag` | Export the resulting catalogue to Piezo-compatible CSV format. |
302
+ | `--genbank_ref` | `str` | GenBank reference string for Piezo export. Required with `--to_piezo`. |
303
+ | `--catalogue_name` | `str` | Name of the catalogue. Required with `--to_piezo`. |
304
+ | `--version` | `str` | Catalogue version. Required with `--to_piezo`. |
305
+ | `--drug` | `str` | Drug associated with the mutations. Required with `--to_piezo`. |
306
+ | `--wildcards` | `str` | Path to JSON file containing wildcard mutation rules. Required with `--to_piezo`. |
307
+ | `--grammar` | `str` | Grammar used in the catalogue. Default: `GARC1`. |
308
+ | `--values` | `str` | Values used for predictions in the catalogue. Default: `RUS`. |
309
+ | `--for_piezo` | `flag` | If set, enables Piezo-specific placeholder rows. Omit if not exporting to Piezo. Default: `False`. |
310
+
311
+ ### Notes
312
+
313
+ - When using post-hoc rule updates via .update(), you must provide wildcards and set replace=True if you intend to override existing entries.
314
+ - For Piezo export, placeholder entries are inserted automatically if needed to satisfy parser requirements (R, S, and U must be represented).
315
+ - The EVIDENCE column includes contingency tables, proportions, confidence intervals, and p-values, and may optionally include sample IDs if `record_ids=True`.
316
+ - To build a catalogue with the regression builder, as currently implemented, requires an ecoff as it will compare the predited effected against the background to supply an R/S/U label
317
+ - To only calculate predicted effects, this can be done in Python by calling RegressionBuilder.predict_effects()
318
+
319
+ ## Citation
320
+
321
+ If you use catomatic in your research, please cite:
322
+
323
+ - https://doi.org/10.1099/mgen.0.001429
@@ -0,0 +1,298 @@
1
+ [![codecov](https://codecov.io/gh/fowler-lab/catomatic/branch/ecoff/graph/badge.svg?token=8fnOy6rHCd)](https://codecov.io/gh/fowler-lab/catomatic) [![DOI](https://zenodo.org/badge/801462003.svg)](https://doi.org/10.5281/zenodo.14917920)
2
+
3
+ # catomatic
4
+
5
+ catomatic is a Python toolkit for algorithmically constructing antimicrobial resistance (AMR) mutation catalogues directly from variant calls generated by read mapping. Rather than relying on alignment-level pattern matching or predefined resistance motifs, the tool infers resistance associations statistically from observed genotype–phenotype relationships, supporting both binary frequentist and regression-based modelling approaches.
6
+
7
+ This design is particularly well suited to Mycobacterium species, where resistance is primarily driven by chromosomal point mutations, indels, and complex multi-locus interactions, and where horizontal gene transfer is rare. By operating on mapped mutation data rather than alignment outputs, the framework enables transparent evidence tracking, flexible statistical testing, and reproducible catalogue construction tailored to the evolutionary and genomic characteristics of mycobacteria.
8
+
9
+ For aligment-relevant approaches, see AMRverse.
10
+
11
+ ## Introduction
12
+
13
+ This repo contains 2 approaches to build resistance catalogues:
14
+
15
+ 1. **Definite defectives (solo-based approach)**
16
+ 2. **Interval regression**
17
+
18
+ The first is used in [https://doi.org/10.1101/2025.01.30.635633](https://doi.org/10.1101/2025.01.30.635633), and the second is a Python translation of the method used in [https://doi.org/10.1038/s41467-023-44325-5](https://doi.org/10.1038/s41467-023-44325-5).
19
+
20
+ ---
21
+
22
+ ## Binary Builder
23
+
24
+ This method relies on the logic that mutations that do not cause resistance can co-occur with those that do. If a mutation in isolation (solo) does not cause resistance, then it is not contributing to the phenotype when present in a mixture either.
25
+
26
+ Mutations that occur in isolation across specified genes are traversed in sequence, and if their proportion of drug-susceptibility (vs. resistance) passes the specified statistical test, they are characterized as benign (susceptible) and removed from the dataset. This step repeats iteratively until no more solo benign mutations are found.
27
+
28
+ Remaining mutations are classified based on their resistance rates and statistical test results. Those that don’t meet thresholds are labeled as `U`.
29
+
30
+ The classification approach supports:
31
+
32
+ - **No test**: assumes homogeneous susceptibility is sufficient for S
33
+ - **Binomial test**: against a specified background resistance rate
34
+ - **Fisher's test**: using a contingency background
35
+
36
+ ### Optional Interventions
37
+
38
+ 1. **Seeding**: You can pre-seed the catalogue with known neutral mutations.
39
+ 2. **Overrides**: You can override or supplement the final catalogue with manual or rule-based entries.
40
+
41
+ Because the method uses GARC1 grammar, rules like `{rpoB@*_fs:R}` can be supplied post-hoc. These rules can:
42
+
43
+ - Be additive (lower priority than specific entries)
44
+ - Replace matching mutations (requires `replace=True` and `wildcards` supplied)
45
+
46
+ The catalogue can be returned as a dictionary or a Piezo-compatible `pandas.DataFrame`.
47
+
48
+ Contingency tables, proportions, p-values, and Wilson confidence intervals are stored in the `EVIDENCE` field.
49
+
50
+ ### Example Workflow using Fisher's:
51
+
52
+ ![Catalogue Diagram](docs/workflow.png)
53
+
54
+ ---
55
+
56
+ ## Regression Builder
57
+
58
+ The Regression Builder implements a mixed-effect interval regression-based approach for catalogue construction to generate predicted mean MICs. It is suitable when the phenotypes are censored or uncesnored MICs.
59
+
60
+ If whole genome SNPs are provided, agglomerative clustering can compute random effects to control for population structure. Any given number of fixed-effects (such as lineage and lab) can also be defined by supplying additional input columns.
61
+
62
+ Similarly to the BinaryBuilder, catalogues can be exported as json objects or piezo-compatible tables.
63
+
64
+ ---
65
+
66
+ ## Installation
67
+
68
+ ### Installation from source
69
+
70
+ Assuming in project directory (after git cloning)
71
+
72
+ ```bash
73
+ pip install -e .
74
+ ```
75
+
76
+ ### Pypy installation
77
+
78
+ ```bash
79
+ pip install catomatic
80
+ ```
81
+
82
+ ## Running catomatic's Binary Builder
83
+
84
+ You need two input DataFrames:
85
+
86
+ - **Samples**: one row per sample, with 'R' or 'S' phenotypes (`UNIQUEID`, `PHENOTYPE`)
87
+ - **Mutations**: one row per mutation per sample (`UNIQUEID`, `MUTATION`)
88
+
89
+ If exporting to Piezo format (`--to_piezo`):
90
+
91
+ - The `MUTATION` column must follow GARC1 grammar (`gene@mutation`)
92
+ - A path to a `wildcards.json` file (containing mutation rules) must be provided
93
+
94
+ ### Python/Jupyter Example
95
+
96
+ ```python
97
+ from catomatic.BinaryCatalogue import BinaryBuilder
98
+
99
+ # Build catalogue
100
+ catalogue = BinaryBuilder(samples=samples_df, mutations=mutations_df).build()
101
+
102
+ # View dictionary version
103
+ cat_dict = catalogue.return_catalogue()
104
+
105
+ # Convert to Piezo-compatible format
106
+ catalogue_df = catalogue.build_piezo(
107
+ genbank_ref='...',
108
+ catalogue_name='...',
109
+ version='...',
110
+ drug='...',
111
+ wildcards='path/to/wildcards.json'
112
+ )
113
+
114
+ # Optionally export to CSV
115
+ catalogue.to_piezo(
116
+ genbank_ref='...',
117
+ catalogue_name='...',
118
+ version='...',
119
+ drug='...',
120
+ wildcards='path/to/wildcards.json',
121
+ outfile='path/to/output.csv'
122
+ )
123
+ ```
124
+
125
+ ### CLI
126
+
127
+ After installation, the simplest way to run the catomatic catalogue builder is via the command line interface using the `binary` subcommand. You must use either `--to_piezo` or `--to_json` to specify the output format. Additional metadata is required when using `--to_piezo`.
128
+
129
+ #### Export to JSON
130
+
131
+ ```bash
132
+ catomatic binary \
133
+ --samples path/to/samples.csv \
134
+ --mutations path/to/mutations.csv \
135
+ --to_json \
136
+ --outfile path/to/output/catalogue.json
137
+ ```
138
+
139
+ #### Export to Piezo format
140
+
141
+ ```bash
142
+ catomatic binary \
143
+ --samples path/to/samples.csv \
144
+ --mutations path/to/mutations.csv \
145
+ --to_piezo \
146
+ --outfile path/to/output/catalogue.csv \
147
+ --genbank_ref '...' \
148
+ --catalogue_name '...' \
149
+ --version '...' \
150
+ --drug '...' \
151
+ --wildcards path/to/wildcards.json
152
+ ```
153
+
154
+ ### CLI Parameters
155
+
156
+ | Parameter | Type | Description |
157
+ | ------------------ | ------- | ---------------------------------------------------------------------------------------------- |
158
+ | `--samples` | `str` | Path to the samples (phenotypes) file. Required. |
159
+ | `--mutations` | `str` | Path to the mutations file. Required. |
160
+ | `--outfile` | `str` | Output file path for saving the catalogue. Required with `--to_json` or `--to_piezo`. |
161
+ | `--to_json` | `flag` | Export the resulting catalogue in JSON format. Optional. |
162
+ | `--to_piezo` | `flag` | Export the resulting catalogue in Piezo-compatible CSV format. Optional. |
163
+ | `--genbank_ref` | `str` | GenBank reference string for Piezo export. Required with `--to_piezo`. |
164
+ | `--catalogue_name` | `str` | Name of the catalogue. Required with `--to_piezo`. |
165
+ | `--version` | `str` | Catalogue version. Required with `--to_piezo`. |
166
+ | `--drug` | `str` | Name of the drug. Required with `--to_piezo`. |
167
+ | `--wildcards` | `str` | Path to JSON file containing wildcard mutation definitions. Required with `--to_piezo`. |
168
+ | `--test` | `str` | Type of statistical test to apply. One of: `None`, `Binomial`, or `Fisher`. Optional. |
169
+ | `--background` | `float` | Background mutation rate (0–1). Required if `--test Binomial` is used. |
170
+ | `--p` | `float` | P-value threshold for statistical significance. Optional. Defaults to `0.95`. |
171
+ | `--tails` | `str` | Tail type for statistical test. One of: `one`, `two`. Optional. Defaults to `two`. |
172
+ | `--strict_unlock` | `flag` | If set, disables classification of susceptible (`S`) mutations unless statistically confident. |
173
+
174
+ ## Running catomatic's Regression Builder
175
+
176
+ You need two input DataFrames:
177
+
178
+ - **Samples**: one row per sample, with an MIC column (`UNIQUEID`, `MIC`)
179
+ - **Mutations**: one row per mutation per sample (`UNIQUEID`, `MUTATION`)
180
+
181
+ If exporting to Piezo format (`--to_piezo`):
182
+
183
+ - The `MUTATION` column must follow GARC1 grammar (`gene@mutation`)
184
+ - A path to a `wildcards.json` file (containing mutation rules) must be provided
185
+
186
+ ### Python/Jupyter Example
187
+
188
+ ```python
189
+ from catomatic.RegressionCatalogue import RegressionBuilder
190
+
191
+ # fit the model to generate mutation effects
192
+ model, effects = RegressionBuilder(samples=samples_df, mutations=mutations_df).predict_effects()
193
+
194
+ # classify effects and generate a catalogue (requires an ecoff)
195
+ catalogue = RegressionBuilder(samples=samples_df, mutations=mutations_df).build(ecoff=1.0)
196
+
197
+ # View dictionary version
198
+ cat_dict = catalogue.return_catalogue()
199
+
200
+ # Convert to Piezo-compatible format
201
+ catalogue_df = catalogue.build_piezo(
202
+ genbank_ref='...',
203
+ catalogue_name='...',
204
+ version='...',
205
+ drug='...',
206
+ wildcards='path/to/wildcards.json'
207
+ )
208
+
209
+ # Optionally export to CSV
210
+ catalogue.to_piezo(
211
+ genbank_ref='...',
212
+ catalogue_name='...',
213
+ version='...',
214
+ drug='...',
215
+ wildcards='path/to/wildcards.json',
216
+ outfile='path/to/output.csv'
217
+ )
218
+ ```
219
+
220
+ ### CLI
221
+
222
+ Similarly to BinaryBuilder, one can instantiate RegressionBuilder from the command line:
223
+
224
+ #### Export to JSON
225
+
226
+ ```bash
227
+ catomatic regression \
228
+ --samples path/to/samples.csv \
229
+ --mutations path/to/mutations.csv \
230
+ --ecoff 1.0 \
231
+ --to_json \
232
+ --outfile path/to/output/catalogue.json
233
+ ```
234
+
235
+ #### Export to Piezo format
236
+
237
+ ```bash
238
+ catomatic regression \
239
+ --samples path/to/samples.csv \
240
+ --mutations path/to/mutations.csv \
241
+ --ecoff 1.0 \
242
+ --to_piezo \
243
+ --outfile path/to/output/catalogue.csv \
244
+ --genbank_ref '...' \
245
+ --catalogue_name '...' \
246
+ --version '...' \
247
+ --drug '...' \
248
+ --wildcards path/to/wildcards.json
249
+ ```
250
+
251
+ ### CLI Parameters
252
+
253
+ ### CLI Parameters (Regression Builder)
254
+
255
+ | Parameter | Type | Description & default |
256
+ | -------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------- |
257
+ | `--samples` | `str` | Path to the samples file (CSV). **Required**. |
258
+ | `--mutations` | `str` | Path to the mutations file (CSV). **Required**. |
259
+ | `--genes` | `str[]` | List of RAV genes. Required when non-RAV genes appear in the mutations table (e.g. when clustering SNP distances). Default: `[]`. |
260
+ | `--dilution_factor` | `int` | Dilution factor used in processing. Default: `2`. |
261
+ | `--censored` | `flag` | Treat phenotype data as censored. Default: `False`. |
262
+ | `--tail_dilutions` | `int` | Tail dilutions to use for uncensored data. Default: `1`. |
263
+ | `--frs` | `float` | Fraction Read Support threshold. Default: `None`. |
264
+ | `--ecoff` | `float` | Epidemiological cutoff value for classification. If `None`, it will be computed. Default: `None`. |
265
+ | `--b_bounds` | `float,float` | Bounds for beta (fixed-effect) coefficients. Two floats: `(min max)`. Default: `(None, None)`. |
266
+ | `--u_bounds` | `float,float` | Bounds for random-effect coefficients. Two floats: `(min max)`. Default: `(None, None)`. |
267
+ | `--s_bounds` | `float,float` | Bounds for sigma (residual variance). Two floats: `(min max)`. Default: `(None, None)`. |
268
+ | `--p` | `float` | Significance / confidence level. Default: `0.95`. |
269
+ | `--fixed_effects` | `str[]` | Column names to include as fixed effects. Default: `None`. |
270
+ | `--random_effects` | `flag` | Perform SNP clustering and include cluster as a random effect. Default: `False`. |
271
+ | `--cluster_distance` | `float` | Distance threshold for SNP clustering. Default: `1`. |
272
+ | `--outfile` | `str` | Path to save output JSON or Piezo file. Required with `--to_json` or `--to_piezo`. |
273
+ | `--options` | `dict` | Options passed to `scipy.optimize.minimize`. Default: `None`. |
274
+ | `--L2_penalties` | `dict` | Regularisation penalties for fixed and random effects. Default: `None`. |
275
+ | `--to_json` | `flag` | Export the resulting catalogue to JSON format. |
276
+ | `--to_piezo` | `flag` | Export the resulting catalogue to Piezo-compatible CSV format. |
277
+ | `--genbank_ref` | `str` | GenBank reference string for Piezo export. Required with `--to_piezo`. |
278
+ | `--catalogue_name` | `str` | Name of the catalogue. Required with `--to_piezo`. |
279
+ | `--version` | `str` | Catalogue version. Required with `--to_piezo`. |
280
+ | `--drug` | `str` | Drug associated with the mutations. Required with `--to_piezo`. |
281
+ | `--wildcards` | `str` | Path to JSON file containing wildcard mutation rules. Required with `--to_piezo`. |
282
+ | `--grammar` | `str` | Grammar used in the catalogue. Default: `GARC1`. |
283
+ | `--values` | `str` | Values used for predictions in the catalogue. Default: `RUS`. |
284
+ | `--for_piezo` | `flag` | If set, enables Piezo-specific placeholder rows. Omit if not exporting to Piezo. Default: `False`. |
285
+
286
+ ### Notes
287
+
288
+ - When using post-hoc rule updates via .update(), you must provide wildcards and set replace=True if you intend to override existing entries.
289
+ - For Piezo export, placeholder entries are inserted automatically if needed to satisfy parser requirements (R, S, and U must be represented).
290
+ - The EVIDENCE column includes contingency tables, proportions, confidence intervals, and p-values, and may optionally include sample IDs if `record_ids=True`.
291
+ - To build a catalogue with the regression builder, as currently implemented, requires an ecoff as it will compare the predited effected against the background to supply an R/S/U label
292
+ - To only calculate predicted effects, this can be done in Python by calling RegressionBuilder.predict_effects()
293
+
294
+ ## Citation
295
+
296
+ If you use catomatic in your research, please cite:
297
+
298
+ - https://doi.org/10.1099/mgen.0.001429