metabintools 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 (46) hide show
  1. metabintools-0.2.0/LICENSE +21 -0
  2. metabintools-0.2.0/PKG-INFO +276 -0
  3. metabintools-0.2.0/README.md +259 -0
  4. metabintools-0.2.0/pyproject.toml +36 -0
  5. metabintools-0.2.0/pyproject.toml.orig +35 -0
  6. metabintools-0.2.0/src/metabintools/__init__.py +0 -0
  7. metabintools-0.2.0/src/metabintools/bin_utils.py +26 -0
  8. metabintools-0.2.0/src/metabintools/binstatistics.py +68 -0
  9. metabintools-0.2.0/src/metabintools/cli/__init__.py +0 -0
  10. metabintools-0.2.0/src/metabintools/cli/cli.py +40 -0
  11. metabintools-0.2.0/src/metabintools/cli/commands/export/__init__.py +17 -0
  12. metabintools-0.2.0/src/metabintools/cli/commands/export/contig2bin.py +61 -0
  13. metabintools-0.2.0/src/metabintools/cli/commands/export/fasta.py +88 -0
  14. metabintools-0.2.0/src/metabintools/cli/commands/export/gff.py +71 -0
  15. metabintools-0.2.0/src/metabintools/cli/commands/import_data/__init__.py +25 -0
  16. metabintools-0.2.0/src/metabintools/cli/commands/import_data/import_annotation.py +65 -0
  17. metabintools-0.2.0/src/metabintools/cli/commands/import_data/import_asm.py +65 -0
  18. metabintools-0.2.0/src/metabintools/cli/commands/import_data/import_bins.py +92 -0
  19. metabintools-0.2.0/src/metabintools/cli/commands/import_data/import_coverage.py +66 -0
  20. metabintools-0.2.0/src/metabintools/cli/commands/import_data/import_quality.py +72 -0
  21. metabintools-0.2.0/src/metabintools/cli/commands/import_data/import_taxonomy.py +68 -0
  22. metabintools-0.2.0/src/metabintools/cli/commands/merge.py +61 -0
  23. metabintools-0.2.0/src/metabintools/cli/commands/rename.py +79 -0
  24. metabintools-0.2.0/src/metabintools/cli/commands/summarise/__init__.py +17 -0
  25. metabintools-0.2.0/src/metabintools/cli/commands/summarise/bins.py +68 -0
  26. metabintools-0.2.0/src/metabintools/cli/commands/summarise/contigs.py +48 -0
  27. metabintools-0.2.0/src/metabintools/cli/commands/summarise/group.py +51 -0
  28. metabintools-0.2.0/src/metabintools/cli/commands/trim.py +54 -0
  29. metabintools-0.2.0/src/metabintools/cli/commands/view.py +114 -0
  30. metabintools-0.2.0/src/metabintools/dataclasses/annotation.py +77 -0
  31. metabintools-0.2.0/src/metabintools/dataclasses/bin.py +274 -0
  32. metabintools-0.2.0/src/metabintools/dataclasses/binset.py +216 -0
  33. metabintools-0.2.0/src/metabintools/dataclasses/contig.py +69 -0
  34. metabintools-0.2.0/src/metabintools/ena_taxonomy/ena_taxonomy.py +186 -0
  35. metabintools-0.2.0/src/metabintools/enums.py +60 -0
  36. metabintools-0.2.0/src/metabintools/export/binset_exporter.py +252 -0
  37. metabintools-0.2.0/src/metabintools/import_data/annotation.py +100 -0
  38. metabintools-0.2.0/src/metabintools/import_data/assembly.py +56 -0
  39. metabintools-0.2.0/src/metabintools/import_data/binset.py +55 -0
  40. metabintools-0.2.0/src/metabintools/import_data/coverage.py +40 -0
  41. metabintools-0.2.0/src/metabintools/import_data/quality.py +103 -0
  42. metabintools-0.2.0/src/metabintools/import_data/taxonomy.py +59 -0
  43. metabintools-0.2.0/src/metabintools/operations/__init__.py +5 -0
  44. metabintools-0.2.0/src/metabintools/operations/merge.py +45 -0
  45. metabintools-0.2.0/src/metabintools/operations/rename.py +57 -0
  46. metabintools-0.2.0/src/metabintools/query/query_parser.py +211 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Genome Research Ltd.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,276 @@
1
+ Metadata-Version: 2.4
2
+ Name: metabintools
3
+ Version: 0.2.0
4
+ Summary: A toolkit for collating and manipulating metagenome bins.
5
+ Author: Jim Downie
6
+ Author-email: Jim Downie <jd42@sanger.ac.uk>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Dist: click>=8.5.0
10
+ Requires-Dist: loguru>=0.7.3
11
+ Requires-Dist: pydantic>=2.13.5
12
+ Requires-Dist: pyfastx>=2.3.1
13
+ Requires-Dist: requests>=2.34.2
14
+ Requires-Dist: zstandard>=0.25.0
15
+ Requires-Python: >=3.13
16
+ Description-Content-Type: text/markdown
17
+
18
+ # metabintools
19
+
20
+ **metabintools** is a toolkit for managing and manipulating metagenomic binning outputs. It consolidates all bin data, including sequences, annotations, quality metrics, and taxonomy, into a single unified file format for streamlined analysis workflows. This file can be queried, filtered, bins can be renamed using their metadata, and separate files can easily be merged to consolidate bins into a single file.
21
+
22
+ ## Overview
23
+
24
+ Metagenomic binning produces scattered outputs: bin FASTA files, quality assessments, taxonomic classifications, and annotations in separate formats. **metabintools** unifies these into a single `.bins` file (optionally compressed as `.bins.zstd`), enabling easy filtering, merging, and export via composable command-line operations.
25
+
26
+ ## Key Features
27
+
28
+ - **Unified file format**: Store bins, contigs, annotations, quality scores, and taxonomy in one `.bins` file
29
+ - **Composable operations**: Chain commands via Unix pipes for flexible workflows
30
+ - **Powerful filtering**: Query bins by any property (completeness, contamination, taxonomy, etc.)
31
+ - **Compression support**: Optional zstd compression for efficient storage
32
+ - **Multiple input sources**: Import bin metadata from many metagenomics tools (CheckM, GTDB-Tk, etc.)
33
+
34
+ ## Installation
35
+
36
+ ```bash
37
+ pip install metabintools
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ### 1. Create a binfile from your assembly
43
+
44
+ ```bash
45
+ metabintools import asm assembly.fasta -o binset.bins
46
+ ```
47
+
48
+ ### 2. Add annotations to your binfile
49
+
50
+ ```bash
51
+ metabintools import annotations binset.bins annotations.gff -o binset.bins
52
+ ```
53
+
54
+ ### 3. Add bins from your binner
55
+
56
+ ```bash
57
+ metabintools import binset binset.bins bins/ --group "myBinner" -o binset.bins
58
+ ```
59
+
60
+ ### 4. Add quality scores
61
+
62
+ ```bash
63
+ metabintools import quality binset.bins checkm_results.tsv --tool checkm -o binset.bins
64
+ ```
65
+
66
+ ### 5. Add taxonomy
67
+
68
+ ```bash
69
+ metabintools import taxonomy binset.bins gtdbtk.tsv --tool gtdbtk -o binset.bins
70
+ ```
71
+
72
+ ### 6. Filter high-quality bins
73
+
74
+ ```bash
75
+ metabintools view binset.bins 'completeness >= 0.9 and contamination <= 0.05' -o hq.bins
76
+ ```
77
+
78
+ or, if the required data for MiMAG calls is present (completeness, contamination, tRNAs, rRNAs):
79
+
80
+ ```bash
81
+ metabintools view binset.bins 'mimag == "high"' -o hq.bins
82
+ ```
83
+
84
+ ### 7. Export to FASTA
85
+
86
+ ```bash
87
+ metabintools export fasta hq.bins -o output_directory/
88
+ ```
89
+
90
+ ## Composable Workflows
91
+
92
+ The real power of metabintools is composability via piping:
93
+
94
+ ```bash
95
+ # Filter and export in one pipeline
96
+ metabintools view binset.bins 'group == "metabat" and completeness >= 0.8' -z | \
97
+ metabintools export fasta -o filtered_bins/
98
+
99
+ # Merge multiple binsets and filter
100
+ metabintools merge set1.bins.zstd set2.bins.zstd -z | \
101
+ metabintools view - 'contamination <= 0.1' -o merged_hq.bins.zstd
102
+
103
+ # Extract high-quality archaeal bins
104
+ metabintools view binset.bins 'tax_kingdom == "Archaea" and completeness >= 0.85' -o archaea_hq.bins
105
+ ```
106
+
107
+ ## Filter Query Guide
108
+
109
+ The `view` command uses simple Python-like syntax:
110
+
111
+ ```bash
112
+ # Basic comparisons
113
+ metabintools view input.bins 'completeness >= 0.9' -o output.bins
114
+ metabintools view input.bins 'length > 1000000' -o output.bins
115
+
116
+ # Logical operators
117
+ metabintools view input.bins 'completeness >= 0.9 and contamination <= 0.05' -o output.bins
118
+ metabintools view input.bins 'group == "vamb" or group == "metabat"' -o output.bins
119
+
120
+ # Taxonomy filtering
121
+ metabintools view input.bins 'tax_phylum == "Bacteroidetes"' -o output.bins
122
+
123
+ # Complex queries
124
+ metabintools view input.bins 'group == "archaea" and completeness >= 0.8 and contamination <= 0.1' -o output.bins
125
+ ```
126
+
127
+ ### Available Filter Fields
128
+
129
+ List all available fields:
130
+
131
+ ```bash
132
+ metabintools view --list-fields
133
+ ```
134
+
135
+ ## Commands
136
+
137
+ ### import
138
+
139
+ Import data into a binfile with validation and error handling:
140
+
141
+ - **`metabintools import asm`** - Initialize from assembly FASTA
142
+ - Can detect circular contigs from metaMDBG and myloasm
143
+
144
+ - **`metabintools import binset`** - Add contig clusters from binning
145
+ - Optional binsplit separator recovery (SemiBin2, VAMB compatibility)
146
+
147
+ - **`metabintools import annotation`** - Add GFF annotations to contigs
148
+
149
+ - **`metabintools import coverage`** - Add coverage data to contigs
150
+ - Supports multiple coverage tools (e.g., CoverM, custom formats)
151
+
152
+ - **`metabintools import taxonomy`** - Add taxonomic classifications to bins
153
+ - Supports multiple taxonomy tools (GTDB-Tk, gtdb_to_ncbi_majority_vote.py, manual)
154
+
155
+ - **`metabintools import quality`** - Add quality scores (CheckM, CheckM2, BUSCO) to bins
156
+ - Supports multiple quality assessment tools
157
+
158
+ ### view
159
+
160
+ Decompress a bins file, or filter bins by query expression with comprehensive validation:
161
+
162
+ ```bash
163
+ metabintools view input.bins.zstd -o input.bins # decompress
164
+ ```
165
+
166
+ or
167
+
168
+ ```bash
169
+ metabintools view input.bins 'completeness >= 0.9' -o output.bins
170
+ metabintools view input.bins 'completeness >= 0.9' -z -o output.bins.zstd # compressed
171
+ metabintools view --list-fields # Show all available filter fields
172
+ ```
173
+
174
+ ### export
175
+
176
+ Export data from a binfile:
177
+
178
+ - **`metabintools export fasta`** - Export each bin to a FASTA file
179
+ - **`metabintools export gff`** - Export each bin's annotations to a GFF file
180
+ - **`metabintools export contig2bin`** - Export a set of bins to a contig-to-bin mapping (DAS_Tool format)
181
+
182
+ ### merge
183
+
184
+ Combine multiple binfiles with progress tracking and validation:
185
+
186
+ ```bash
187
+ metabintools merge set1.bins set2.bins set3.bins -o merged.bins
188
+ ```
189
+
190
+ ### trim
191
+
192
+ Remove unused contigs from a binfile:
193
+
194
+ ```bash
195
+ metabintools trim input.bins -o trimmed.bins
196
+ ```
197
+
198
+ ### rename
199
+
200
+ Rename bins in a binfile with template support. Field options can be listed with `--list-fields`.
201
+
202
+ ```bash
203
+ metabintools rename input.bins -n "bin_{tax_phylum}" -o output.bins
204
+ # bin1, bin2 > bin_Pseudomonadota_1, bin_Pseudomonadota_2
205
+ ```
206
+
207
+ ### summarise
208
+
209
+ Generate summary reports:
210
+
211
+ - **`metabintools summarise bins`** - Export bin summary to TSV
212
+ - **`metabintools summarise groups`** - Export an aggregated summary of bin groups, showing counts of bins at each MiMAG level, to TSV
213
+ - **`metabintools summarise contigs`** - Export contig summary to TSV
214
+
215
+ ## File Format
216
+
217
+ A `.bins` file is a zstd-compressed (or uncompressed) JSON document containing:
218
+
219
+ ```json
220
+ {
221
+ "contigs": {
222
+ "contig_id": {
223
+ "id": "contig_id",
224
+ "sequence": "ACGTACGT...",
225
+ "sequence_length": 1234,
226
+ "annotations": [...],
227
+ "coverage": 15.5,
228
+ "topology": "circular"
229
+ }
230
+ },
231
+ "bins": [
232
+ {
233
+ "id": "bin.1",
234
+ "group": "metabat",
235
+ "contigs": ["contig_1", "contig_2"],
236
+ "statistics": {
237
+ "completeness": 0.95,
238
+ "contamination": 0.02,
239
+ "length": 2500000
240
+ },
241
+ "taxonomy": {
242
+ "classification": "k__Bacteria;p__Proteobacteria;..."
243
+ }
244
+ }
245
+ ]
246
+ }
247
+ ```
248
+
249
+ ## Examples
250
+
251
+ ### Workflow: Filter and Export High-Quality Bins
252
+
253
+ ```bash
254
+ # Start with assembly
255
+ metabintools import asm metagenome.fasta -o project.bins
256
+
257
+ # Add binning results
258
+ metabintools import binset project.bins bins/ --group "metabat" -o project.bins
259
+
260
+ # Add quality scores
261
+ metabintools import quality project.bins checkm_results.tsv --tool checkm -o project.bins
262
+
263
+ # Add taxonomy
264
+ metabintools import taxonomy project.bins gtdbtk.tsv --tool gtdbtk -o project.bins
265
+
266
+ # Filter to high-quality bins
267
+ metabintools view project.bins 'completeness >= 0.9 and contamination <= 0.05' \
268
+ -o high_quality.bins
269
+
270
+ # Export to FASTA
271
+ metabintools export fasta high_quality.bins -o bins_fasta/
272
+ ```
273
+
274
+ ## License
275
+
276
+ MIT © 2026 Genome Research Ltd
@@ -0,0 +1,259 @@
1
+ # metabintools
2
+
3
+ **metabintools** is a toolkit for managing and manipulating metagenomic binning outputs. It consolidates all bin data, including sequences, annotations, quality metrics, and taxonomy, into a single unified file format for streamlined analysis workflows. This file can be queried, filtered, bins can be renamed using their metadata, and separate files can easily be merged to consolidate bins into a single file.
4
+
5
+ ## Overview
6
+
7
+ Metagenomic binning produces scattered outputs: bin FASTA files, quality assessments, taxonomic classifications, and annotations in separate formats. **metabintools** unifies these into a single `.bins` file (optionally compressed as `.bins.zstd`), enabling easy filtering, merging, and export via composable command-line operations.
8
+
9
+ ## Key Features
10
+
11
+ - **Unified file format**: Store bins, contigs, annotations, quality scores, and taxonomy in one `.bins` file
12
+ - **Composable operations**: Chain commands via Unix pipes for flexible workflows
13
+ - **Powerful filtering**: Query bins by any property (completeness, contamination, taxonomy, etc.)
14
+ - **Compression support**: Optional zstd compression for efficient storage
15
+ - **Multiple input sources**: Import bin metadata from many metagenomics tools (CheckM, GTDB-Tk, etc.)
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install metabintools
21
+ ```
22
+
23
+ ## Quick Start
24
+
25
+ ### 1. Create a binfile from your assembly
26
+
27
+ ```bash
28
+ metabintools import asm assembly.fasta -o binset.bins
29
+ ```
30
+
31
+ ### 2. Add annotations to your binfile
32
+
33
+ ```bash
34
+ metabintools import annotations binset.bins annotations.gff -o binset.bins
35
+ ```
36
+
37
+ ### 3. Add bins from your binner
38
+
39
+ ```bash
40
+ metabintools import binset binset.bins bins/ --group "myBinner" -o binset.bins
41
+ ```
42
+
43
+ ### 4. Add quality scores
44
+
45
+ ```bash
46
+ metabintools import quality binset.bins checkm_results.tsv --tool checkm -o binset.bins
47
+ ```
48
+
49
+ ### 5. Add taxonomy
50
+
51
+ ```bash
52
+ metabintools import taxonomy binset.bins gtdbtk.tsv --tool gtdbtk -o binset.bins
53
+ ```
54
+
55
+ ### 6. Filter high-quality bins
56
+
57
+ ```bash
58
+ metabintools view binset.bins 'completeness >= 0.9 and contamination <= 0.05' -o hq.bins
59
+ ```
60
+
61
+ or, if the required data for MiMAG calls is present (completeness, contamination, tRNAs, rRNAs):
62
+
63
+ ```bash
64
+ metabintools view binset.bins 'mimag == "high"' -o hq.bins
65
+ ```
66
+
67
+ ### 7. Export to FASTA
68
+
69
+ ```bash
70
+ metabintools export fasta hq.bins -o output_directory/
71
+ ```
72
+
73
+ ## Composable Workflows
74
+
75
+ The real power of metabintools is composability via piping:
76
+
77
+ ```bash
78
+ # Filter and export in one pipeline
79
+ metabintools view binset.bins 'group == "metabat" and completeness >= 0.8' -z | \
80
+ metabintools export fasta -o filtered_bins/
81
+
82
+ # Merge multiple binsets and filter
83
+ metabintools merge set1.bins.zstd set2.bins.zstd -z | \
84
+ metabintools view - 'contamination <= 0.1' -o merged_hq.bins.zstd
85
+
86
+ # Extract high-quality archaeal bins
87
+ metabintools view binset.bins 'tax_kingdom == "Archaea" and completeness >= 0.85' -o archaea_hq.bins
88
+ ```
89
+
90
+ ## Filter Query Guide
91
+
92
+ The `view` command uses simple Python-like syntax:
93
+
94
+ ```bash
95
+ # Basic comparisons
96
+ metabintools view input.bins 'completeness >= 0.9' -o output.bins
97
+ metabintools view input.bins 'length > 1000000' -o output.bins
98
+
99
+ # Logical operators
100
+ metabintools view input.bins 'completeness >= 0.9 and contamination <= 0.05' -o output.bins
101
+ metabintools view input.bins 'group == "vamb" or group == "metabat"' -o output.bins
102
+
103
+ # Taxonomy filtering
104
+ metabintools view input.bins 'tax_phylum == "Bacteroidetes"' -o output.bins
105
+
106
+ # Complex queries
107
+ metabintools view input.bins 'group == "archaea" and completeness >= 0.8 and contamination <= 0.1' -o output.bins
108
+ ```
109
+
110
+ ### Available Filter Fields
111
+
112
+ List all available fields:
113
+
114
+ ```bash
115
+ metabintools view --list-fields
116
+ ```
117
+
118
+ ## Commands
119
+
120
+ ### import
121
+
122
+ Import data into a binfile with validation and error handling:
123
+
124
+ - **`metabintools import asm`** - Initialize from assembly FASTA
125
+ - Can detect circular contigs from metaMDBG and myloasm
126
+
127
+ - **`metabintools import binset`** - Add contig clusters from binning
128
+ - Optional binsplit separator recovery (SemiBin2, VAMB compatibility)
129
+
130
+ - **`metabintools import annotation`** - Add GFF annotations to contigs
131
+
132
+ - **`metabintools import coverage`** - Add coverage data to contigs
133
+ - Supports multiple coverage tools (e.g., CoverM, custom formats)
134
+
135
+ - **`metabintools import taxonomy`** - Add taxonomic classifications to bins
136
+ - Supports multiple taxonomy tools (GTDB-Tk, gtdb_to_ncbi_majority_vote.py, manual)
137
+
138
+ - **`metabintools import quality`** - Add quality scores (CheckM, CheckM2, BUSCO) to bins
139
+ - Supports multiple quality assessment tools
140
+
141
+ ### view
142
+
143
+ Decompress a bins file, or filter bins by query expression with comprehensive validation:
144
+
145
+ ```bash
146
+ metabintools view input.bins.zstd -o input.bins # decompress
147
+ ```
148
+
149
+ or
150
+
151
+ ```bash
152
+ metabintools view input.bins 'completeness >= 0.9' -o output.bins
153
+ metabintools view input.bins 'completeness >= 0.9' -z -o output.bins.zstd # compressed
154
+ metabintools view --list-fields # Show all available filter fields
155
+ ```
156
+
157
+ ### export
158
+
159
+ Export data from a binfile:
160
+
161
+ - **`metabintools export fasta`** - Export each bin to a FASTA file
162
+ - **`metabintools export gff`** - Export each bin's annotations to a GFF file
163
+ - **`metabintools export contig2bin`** - Export a set of bins to a contig-to-bin mapping (DAS_Tool format)
164
+
165
+ ### merge
166
+
167
+ Combine multiple binfiles with progress tracking and validation:
168
+
169
+ ```bash
170
+ metabintools merge set1.bins set2.bins set3.bins -o merged.bins
171
+ ```
172
+
173
+ ### trim
174
+
175
+ Remove unused contigs from a binfile:
176
+
177
+ ```bash
178
+ metabintools trim input.bins -o trimmed.bins
179
+ ```
180
+
181
+ ### rename
182
+
183
+ Rename bins in a binfile with template support. Field options can be listed with `--list-fields`.
184
+
185
+ ```bash
186
+ metabintools rename input.bins -n "bin_{tax_phylum}" -o output.bins
187
+ # bin1, bin2 > bin_Pseudomonadota_1, bin_Pseudomonadota_2
188
+ ```
189
+
190
+ ### summarise
191
+
192
+ Generate summary reports:
193
+
194
+ - **`metabintools summarise bins`** - Export bin summary to TSV
195
+ - **`metabintools summarise groups`** - Export an aggregated summary of bin groups, showing counts of bins at each MiMAG level, to TSV
196
+ - **`metabintools summarise contigs`** - Export contig summary to TSV
197
+
198
+ ## File Format
199
+
200
+ A `.bins` file is a zstd-compressed (or uncompressed) JSON document containing:
201
+
202
+ ```json
203
+ {
204
+ "contigs": {
205
+ "contig_id": {
206
+ "id": "contig_id",
207
+ "sequence": "ACGTACGT...",
208
+ "sequence_length": 1234,
209
+ "annotations": [...],
210
+ "coverage": 15.5,
211
+ "topology": "circular"
212
+ }
213
+ },
214
+ "bins": [
215
+ {
216
+ "id": "bin.1",
217
+ "group": "metabat",
218
+ "contigs": ["contig_1", "contig_2"],
219
+ "statistics": {
220
+ "completeness": 0.95,
221
+ "contamination": 0.02,
222
+ "length": 2500000
223
+ },
224
+ "taxonomy": {
225
+ "classification": "k__Bacteria;p__Proteobacteria;..."
226
+ }
227
+ }
228
+ ]
229
+ }
230
+ ```
231
+
232
+ ## Examples
233
+
234
+ ### Workflow: Filter and Export High-Quality Bins
235
+
236
+ ```bash
237
+ # Start with assembly
238
+ metabintools import asm metagenome.fasta -o project.bins
239
+
240
+ # Add binning results
241
+ metabintools import binset project.bins bins/ --group "metabat" -o project.bins
242
+
243
+ # Add quality scores
244
+ metabintools import quality project.bins checkm_results.tsv --tool checkm -o project.bins
245
+
246
+ # Add taxonomy
247
+ metabintools import taxonomy project.bins gtdbtk.tsv --tool gtdbtk -o project.bins
248
+
249
+ # Filter to high-quality bins
250
+ metabintools view project.bins 'completeness >= 0.9 and contamination <= 0.05' \
251
+ -o high_quality.bins
252
+
253
+ # Export to FASTA
254
+ metabintools export fasta high_quality.bins -o bins_fasta/
255
+ ```
256
+
257
+ ## License
258
+
259
+ MIT © 2026 Genome Research Ltd
@@ -0,0 +1,36 @@
1
+ [project]
2
+ name = "metabintools"
3
+ version = "0.2.0"
4
+ description = "A toolkit for collating and manipulating metagenome bins."
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICEN[CS]E*"]
8
+ requires-python = ">=3.13"
9
+ dependencies = [
10
+ "click>=8.5.0",
11
+ "loguru>=0.7.3",
12
+ "pydantic>=2.13.5",
13
+ "pyfastx>=2.3.1",
14
+ "requests>=2.34.2",
15
+ "zstandard>=0.25.0",
16
+ ]
17
+
18
+ [[project.authors]]
19
+ name = "Jim Downie"
20
+ email = "jd42@sanger.ac.uk"
21
+
22
+ [project.scripts]
23
+ bintools = "metabintools.cli.cli:cli"
24
+ metabintools = "metabintools.cli.cli:cli"
25
+
26
+ [build-system]
27
+ requires = ["uv_build>=0.12.14,<0.13.0"]
28
+ build-backend = "uv_build"
29
+
30
+ [dependency-groups]
31
+ dev = [
32
+ "pytest>=9.1.1",
33
+ "sphinx>=9.1.0",
34
+ "sphinx-click>=6.2.0",
35
+ "sphinx-rtd-theme>=3.1.0",
36
+ ]
@@ -0,0 +1,35 @@
1
+ [project]
2
+ name = "metabintools"
3
+ version = "0.2.0"
4
+ description = "A toolkit for collating and manipulating metagenome bins."
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "Jim Downie", email = "jd42@sanger.ac.uk" }
8
+ ]
9
+ license = "MIT"
10
+ license-files = ["LICEN[CS]E*"]
11
+ requires-python = ">=3.13"
12
+ dependencies = [
13
+ "click>=8.5.0",
14
+ "loguru>=0.7.3",
15
+ "pydantic>=2.13.5",
16
+ "pyfastx>=2.3.1",
17
+ "requests>=2.34.2",
18
+ "zstandard>=0.25.0",
19
+ ]
20
+
21
+ [project.scripts]
22
+ bintools = "metabintools.cli.cli:cli"
23
+ metabintools = "metabintools.cli.cli:cli"
24
+
25
+ [build-system]
26
+ requires = ["uv_build>=0.12.14,<0.13.0"]
27
+ build-backend = "uv_build"
28
+
29
+ [dependency-groups]
30
+ dev = [
31
+ "pytest>=9.1.1",
32
+ "sphinx>=9.1.0",
33
+ "sphinx-click>=6.2.0",
34
+ "sphinx-rtd-theme>=3.1.0",
35
+ ]
File without changes
@@ -0,0 +1,26 @@
1
+ from pathlib import Path
2
+
3
+
4
+ def get_extension(file: Path) -> str:
5
+ if file.suffix == ".gz":
6
+ return "".join(file.suffixes[-2:])
7
+ return file.suffix
8
+
9
+
10
+ def get_basename(file: Path | str) -> str:
11
+ if isinstance(file, str):
12
+ file = Path(file)
13
+
14
+ if file.suffix == ".gz":
15
+ return file.name.rsplit(".", 2)[0]
16
+ else:
17
+ return file.name.rsplit(".", 1)[0]
18
+
19
+
20
+ def find_binfiles(directory: Path) -> list[Path]:
21
+ return [
22
+ p
23
+ for p in directory.glob("*")
24
+ if get_extension(p)
25
+ in {".fa", ".fna", ".fasta", ".fa.gz", ".fna.gz", ".fasta.gz"}
26
+ ]