currtag 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 DenseCall2 contributors
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,2 @@
1
+ include README.md
2
+ include requirements.txt
currtag-0.2.0/PKG-INFO ADDED
@@ -0,0 +1,216 @@
1
+ Metadata-Version: 2.4
2
+ Name: currtag
3
+ Version: 0.2.0
4
+ Author: linlian
5
+ Author-email: 21620151153308@stu.xmu.edu.cn
6
+ License: MIT
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
12
+ Requires-Python: >=3.10
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENCE.txt
15
+ Requires-Dist: numpy>=1.23
16
+ Requires-Dist: scipy>=1.9
17
+ Requires-Dist: pandas>=1.5
18
+ Requires-Dist: h5py>=3.7
19
+ Requires-Dist: torch>=2.0
20
+ Requires-Dist: tqdm>=4.64
21
+ Requires-Dist: toml>=0.10
22
+ Requires-Dist: scikit-learn>=1.1
23
+ Requires-Dist: matplotlib>=3.6
24
+ Requires-Dist: seaborn>=0.12
25
+ Requires-Dist: biopython>=1.80
26
+ Requires-Dist: numba>=0.57
27
+ Requires-Dist: plotnine>=0.12
28
+ Requires-Dist: ont-fast5-api>=4.1
29
+ Requires-Dist: ont-bonito>=0.7
30
+ Dynamic: author
31
+ Dynamic: author-email
32
+ Dynamic: classifier
33
+ Dynamic: description
34
+ Dynamic: description-content-type
35
+ Dynamic: license
36
+ Dynamic: license-file
37
+ Dynamic: requires-dist
38
+ Dynamic: requires-python
39
+
40
+ <div align="center">
41
+
42
+ # ⚡ **currtag**
43
+
44
+ **Nanopore signal classification** — label every raw read by species, barcode or taxon,
45
+ straight from the current, with no basecalling step.
46
+
47
+ [![PyPI](https://img.shields.io/pypi/v/currtag)](https://pypi.org/project/currtag/)
48
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
49
+ [![License](https://img.shields.io/badge/license-MIT-green)](LICENCE.txt)
50
+
51
+ </div>
52
+
53
+ ---
54
+
55
+ ## 📖 Table of Contents
56
+
57
+ - [Overview](#-overview)
58
+ - [Installation](#-installation)
59
+ - [Quick start](#-quick-start)
60
+ - [Subcommands](#-subcommands)
61
+ - [Training modes](#-training-modes)
62
+ - [Examples](#-examples)
63
+ - [License](#-license)
64
+
65
+ ---
66
+
67
+ ## 🧬 Overview
68
+
69
+ Reads are trimmed to their informative region (adapter/polyA detection for DNA,
70
+ poly(A)-tail trimming for RNA), encoded, and passed through a small 1-D CNN that
71
+ predicts one class per read. Training works either on **real** labelled reads or on
72
+ **signal simulated** from reference genomes, so you can build a classifier without
73
+ per-species reads for every class.
74
+
75
+ The pipeline is a fixed chain of subcommands:
76
+
77
+ ```
78
+ label → split → gendata → train → predict → evaluation
79
+ ```
80
+
81
+ Every step is also importable as a module (`currtag.label`, `currtag.train`, ...), and
82
+ the package depends on nothing outside `requirements.txt`.
83
+
84
+ ---
85
+
86
+ ## 📦 Installation
87
+
88
+ From PyPI:
89
+
90
+ ```bash
91
+ pip install currtag
92
+ ```
93
+
94
+ From source:
95
+
96
+ ```bash
97
+ git clone <this-repo>
98
+ cd currtag
99
+ pip install -e .
100
+ ```
101
+
102
+ `torch` is deliberately unpinned so the resolver picks a build matching your local
103
+ CUDA toolkit. For GPU work, install the CUDA toolkit first and verify `nvcc` is on
104
+ `$PATH`:
105
+
106
+ ```bash
107
+ conda install -c nvidia cuda-toolkit=12.8
108
+ ```
109
+
110
+ ---
111
+
112
+ ## 🚀 Quick start
113
+
114
+ ```bash
115
+ currtag --help # list the subcommands
116
+ currtag label --help # one subcommand, with its own flags
117
+ currtag -v # print the version
118
+ ```
119
+
120
+ ---
121
+
122
+ ## 🎯 Subcommands
123
+
124
+ | Subcommand | Purpose |
125
+ |:--|:--|
126
+ | `label` | Build `label_map.json` / `inverse_label_map.json` from a FASTA whose headers are the class names |
127
+ | `split` | Split a read→label pairs file into train / test sets |
128
+ | `gendata` | Convert POD5/FAST5 + labels into `train.hdf5` / `valid.hdf5` |
129
+ | `train` | Train the classification CNN (real or simulated data) |
130
+ | `predict` | Classify reads with a trained model |
131
+ | `precision` | One-class precision / recall / F1 / ROC evaluation |
132
+ | `evaluation` | Full multiclass panel (confusion matrix, PR/ROC, ...) |
133
+ | `comparison` | Side-by-side comparison of two models |
134
+
135
+ ---
136
+
137
+ ## 🧪 Training modes
138
+
139
+ | Mode | Description |
140
+ |:--|:--|
141
+ | **Real-data** | `gendata` extracts signal chunks from reads already labelled by species, then `train` (no `--simu`) fits the CNN directly. |
142
+ | **Simulation** | `train --simu <refs.fa> --preset <name>` synthesises chunks on the fly from a FASTA of reference genomes. Presets: `dna-r9-min`, `dna-r10-min`, `rna-r9-min`, `rna004-min`, ... |
143
+
144
+ The CNN architecture is set by a small TOML (`dna.toml` with `strides=[2,2,2,2,2]` for
145
+ DNA, `rna.toml` with `strides=[5,2,2,2,2]` for RNA) passed via `-config`. The
146
+ `label_map.json` / `inverse_label_map.json` pair must be produced first with
147
+ `currtag label`.
148
+
149
+ ---
150
+
151
+ ## 🧪 Examples
152
+
153
+ ### Barcode / species classification on real reads
154
+
155
+ ```bash
156
+ # 1. build the label map
157
+ currtag label species.fa
158
+
159
+ # 2. split read→label pairs
160
+ currtag split readid_species.txt --train_file train_labels.txt --test_file test_labels.txt
161
+
162
+ # 3. extract training chunks
163
+ currtag gendata train.pod5 \
164
+ --label_path train_labels.txt --save_path ./ --seqlen 6000 --do-trim
165
+
166
+ # 4. train
167
+ currtag train model_real \
168
+ -config dna.toml --directory ./ --label-map label_map.json \
169
+ --chunksize 6000 -f --new -y
170
+
171
+ # 5. predict
172
+ currtag predict model_real test.pod5 inverse_label_map.json \
173
+ --chunksize 6000 > result_real.txt
174
+
175
+ # 6. evaluate
176
+ currtag evaluation result_real.txt test_labels.txt \
177
+ -m label_map.json -o ./real
178
+ ```
179
+
180
+ ### Simulation-based training (no real per-species data)
181
+
182
+ ```bash
183
+ currtag label species.fa
184
+
185
+ currtag train model_simu \
186
+ -config dna.toml --directory ./ --label-map label_map.json \
187
+ --chunksize 25000 -f --new --simu species.fa --preset dna-r10-min -y
188
+
189
+ currtag predict model_simu reads_dir/ inverse_label_map.json \
190
+ --chunksize 25000 > result_simu.txt
191
+
192
+ currtag precision result_simu.txt test_labels.txt -m label_map.json
193
+ ```
194
+
195
+ ### RNA direct-read classification
196
+
197
+ RNA reads are reverse-complement mapped and sequenced after the poly(A) tail, so
198
+ `gendata` / `predict` take `--rna --tail`, and RNA models use `rna.toml`:
199
+
200
+ ```bash
201
+ currtag gendata train.pod5 \
202
+ --label_path train_labels.txt --save_path ./ --rna --seqlen 50000 --tail
203
+
204
+ currtag train model \
205
+ -config rna.toml --directory ./ --label-map label_map.json \
206
+ -f --new -y --chunksize 50000 --rna
207
+
208
+ currtag predict model test.pod5 inverse_label_map.json \
209
+ --rna --tail --chunksize 50000 > result_real.txt
210
+ ```
211
+
212
+ ---
213
+
214
+ ## 📄 License
215
+
216
+ MIT — see [LICENCE.txt](LICENCE.txt).
@@ -0,0 +1,177 @@
1
+ <div align="center">
2
+
3
+ # ⚡ **currtag**
4
+
5
+ **Nanopore signal classification** — label every raw read by species, barcode or taxon,
6
+ straight from the current, with no basecalling step.
7
+
8
+ [![PyPI](https://img.shields.io/pypi/v/currtag)](https://pypi.org/project/currtag/)
9
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue)](https://www.python.org/)
10
+ [![License](https://img.shields.io/badge/license-MIT-green)](LICENCE.txt)
11
+
12
+ </div>
13
+
14
+ ---
15
+
16
+ ## 📖 Table of Contents
17
+
18
+ - [Overview](#-overview)
19
+ - [Installation](#-installation)
20
+ - [Quick start](#-quick-start)
21
+ - [Subcommands](#-subcommands)
22
+ - [Training modes](#-training-modes)
23
+ - [Examples](#-examples)
24
+ - [License](#-license)
25
+
26
+ ---
27
+
28
+ ## 🧬 Overview
29
+
30
+ Reads are trimmed to their informative region (adapter/polyA detection for DNA,
31
+ poly(A)-tail trimming for RNA), encoded, and passed through a small 1-D CNN that
32
+ predicts one class per read. Training works either on **real** labelled reads or on
33
+ **signal simulated** from reference genomes, so you can build a classifier without
34
+ per-species reads for every class.
35
+
36
+ The pipeline is a fixed chain of subcommands:
37
+
38
+ ```
39
+ label → split → gendata → train → predict → evaluation
40
+ ```
41
+
42
+ Every step is also importable as a module (`currtag.label`, `currtag.train`, ...), and
43
+ the package depends on nothing outside `requirements.txt`.
44
+
45
+ ---
46
+
47
+ ## 📦 Installation
48
+
49
+ From PyPI:
50
+
51
+ ```bash
52
+ pip install currtag
53
+ ```
54
+
55
+ From source:
56
+
57
+ ```bash
58
+ git clone <this-repo>
59
+ cd currtag
60
+ pip install -e .
61
+ ```
62
+
63
+ `torch` is deliberately unpinned so the resolver picks a build matching your local
64
+ CUDA toolkit. For GPU work, install the CUDA toolkit first and verify `nvcc` is on
65
+ `$PATH`:
66
+
67
+ ```bash
68
+ conda install -c nvidia cuda-toolkit=12.8
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 🚀 Quick start
74
+
75
+ ```bash
76
+ currtag --help # list the subcommands
77
+ currtag label --help # one subcommand, with its own flags
78
+ currtag -v # print the version
79
+ ```
80
+
81
+ ---
82
+
83
+ ## 🎯 Subcommands
84
+
85
+ | Subcommand | Purpose |
86
+ |:--|:--|
87
+ | `label` | Build `label_map.json` / `inverse_label_map.json` from a FASTA whose headers are the class names |
88
+ | `split` | Split a read→label pairs file into train / test sets |
89
+ | `gendata` | Convert POD5/FAST5 + labels into `train.hdf5` / `valid.hdf5` |
90
+ | `train` | Train the classification CNN (real or simulated data) |
91
+ | `predict` | Classify reads with a trained model |
92
+ | `precision` | One-class precision / recall / F1 / ROC evaluation |
93
+ | `evaluation` | Full multiclass panel (confusion matrix, PR/ROC, ...) |
94
+ | `comparison` | Side-by-side comparison of two models |
95
+
96
+ ---
97
+
98
+ ## 🧪 Training modes
99
+
100
+ | Mode | Description |
101
+ |:--|:--|
102
+ | **Real-data** | `gendata` extracts signal chunks from reads already labelled by species, then `train` (no `--simu`) fits the CNN directly. |
103
+ | **Simulation** | `train --simu <refs.fa> --preset <name>` synthesises chunks on the fly from a FASTA of reference genomes. Presets: `dna-r9-min`, `dna-r10-min`, `rna-r9-min`, `rna004-min`, ... |
104
+
105
+ The CNN architecture is set by a small TOML (`dna.toml` with `strides=[2,2,2,2,2]` for
106
+ DNA, `rna.toml` with `strides=[5,2,2,2,2]` for RNA) passed via `-config`. The
107
+ `label_map.json` / `inverse_label_map.json` pair must be produced first with
108
+ `currtag label`.
109
+
110
+ ---
111
+
112
+ ## 🧪 Examples
113
+
114
+ ### Barcode / species classification on real reads
115
+
116
+ ```bash
117
+ # 1. build the label map
118
+ currtag label species.fa
119
+
120
+ # 2. split read→label pairs
121
+ currtag split readid_species.txt --train_file train_labels.txt --test_file test_labels.txt
122
+
123
+ # 3. extract training chunks
124
+ currtag gendata train.pod5 \
125
+ --label_path train_labels.txt --save_path ./ --seqlen 6000 --do-trim
126
+
127
+ # 4. train
128
+ currtag train model_real \
129
+ -config dna.toml --directory ./ --label-map label_map.json \
130
+ --chunksize 6000 -f --new -y
131
+
132
+ # 5. predict
133
+ currtag predict model_real test.pod5 inverse_label_map.json \
134
+ --chunksize 6000 > result_real.txt
135
+
136
+ # 6. evaluate
137
+ currtag evaluation result_real.txt test_labels.txt \
138
+ -m label_map.json -o ./real
139
+ ```
140
+
141
+ ### Simulation-based training (no real per-species data)
142
+
143
+ ```bash
144
+ currtag label species.fa
145
+
146
+ currtag train model_simu \
147
+ -config dna.toml --directory ./ --label-map label_map.json \
148
+ --chunksize 25000 -f --new --simu species.fa --preset dna-r10-min -y
149
+
150
+ currtag predict model_simu reads_dir/ inverse_label_map.json \
151
+ --chunksize 25000 > result_simu.txt
152
+
153
+ currtag precision result_simu.txt test_labels.txt -m label_map.json
154
+ ```
155
+
156
+ ### RNA direct-read classification
157
+
158
+ RNA reads are reverse-complement mapped and sequenced after the poly(A) tail, so
159
+ `gendata` / `predict` take `--rna --tail`, and RNA models use `rna.toml`:
160
+
161
+ ```bash
162
+ currtag gendata train.pod5 \
163
+ --label_path train_labels.txt --save_path ./ --rna --seqlen 50000 --tail
164
+
165
+ currtag train model \
166
+ -config rna.toml --directory ./ --label-map label_map.json \
167
+ -f --new -y --chunksize 50000 --rna
168
+
169
+ currtag predict model test.pod5 inverse_label_map.json \
170
+ --rna --tail --chunksize 50000 > result_real.txt
171
+ ```
172
+
173
+ ---
174
+
175
+ ## 📄 License
176
+
177
+ MIT — see [LICENCE.txt](LICENCE.txt).
@@ -0,0 +1,12 @@
1
+ """Signal classification for nanopore reads.
2
+
3
+ Split out of the ``densecall`` basecaller into this standalone package. Nothing
4
+ here imports ``densecall``: the only helper that was shared
5
+ (``convert_base_name``) is vendored in ``base_util.py``.
6
+
7
+ Pipeline: label -> split -> gendata -> train -> predict -> evaluate
8
+ """
9
+
10
+ from currtag.cli import __version__, argparser, main, subcommands
11
+
12
+ __all__ = ['main', 'argparser', 'subcommands', '__version__']
@@ -0,0 +1,4 @@
1
+ from currtag.cli import main
2
+
3
+ if __name__ == '__main__':
4
+ main()
@@ -0,0 +1,41 @@
1
+ """Base-name to IUPAC regular-expression helpers.
2
+
3
+ Vendored from ``densecall.mod_util`` so this package has no dependency on the
4
+ basecaller. Only ``convert_base_name`` was ever used here; the rest of
5
+ ``mod_util`` pulls in remora/mappy, which this package does not need.
6
+ """
7
+
8
+ # IUPAC degenerate codes expanded into character classes.
9
+ _MERGE_BASES = {
10
+ "A": "A",
11
+ "C": "C",
12
+ "G": "G",
13
+ "T": "T",
14
+ "M": "[AC]",
15
+ "V": "[ACG]",
16
+ "R": "[AG]",
17
+ "H": "[ACT]",
18
+ "W": "[AT]",
19
+ "D": "[AGT]",
20
+ "S": "[CG]",
21
+ "B": "[CGT]",
22
+ "Y": "[CT]",
23
+ "N": "[ACGT]",
24
+ "K": "[GT]",
25
+ }
26
+
27
+
28
+ def convert_base_name(base_name):
29
+ """Expand a base string into a regular expression pattern.
30
+
31
+ Args:
32
+ base_name (str): Input base string to be converted, e.g. ``"NAY"``.
33
+
34
+ Returns:
35
+ str: Regular expression pattern equivalent to the input, e.g.
36
+ ``"[ACGT]A[CT]"``.
37
+ """
38
+ pattern = ""
39
+ for base in base_name:
40
+ pattern += _MERGE_BASES.get(base, base)
41
+ return pattern
@@ -0,0 +1,76 @@
1
+ """Command-line namespace for signal classification.
2
+
3
+ ``argparser()`` builds the subcommand tree for introspection and library use;
4
+ ``main()`` is the console entry point. Both share the same leaf registration,
5
+ and ``main`` mirrors DenseCall's two-level layout (leaves hang directly off the
6
+ top parser) so that ``currtag <cmd> --help`` shows the leaf's help.
7
+ """
8
+
9
+ from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
10
+
11
+ __version__ = '0.2.0'
12
+
13
+ subcommands = [
14
+ 'label', 'split', 'gendata', 'train', 'predict',
15
+ 'precision', 'evaluation', 'comparison'
16
+ ]
17
+
18
+ __all__ = ['argparser', 'main', 'subcommands', '__version__']
19
+
20
+ _DESCRIPTION = ('Signal classification: label map -> split -> gendata -> '
21
+ 'train -> predict -> evaluate')
22
+
23
+
24
+ def _leaves():
25
+ """Yield (name, module) for each subcommand."""
26
+ for name in subcommands:
27
+ mod = __import__(f"currtag.{name}", fromlist=['argparser', 'main'])
28
+ yield name, mod
29
+
30
+
31
+ def _add_subparsers(parser):
32
+ """Attach every subcommand to ``parser`` as a real subparser."""
33
+ sub = parser.add_subparsers(
34
+ title='subcommands', description='valid commands',
35
+ help='additional help', dest='subcommand'
36
+ )
37
+ sub.required = True
38
+ for name, mod in _leaves():
39
+ p = sub.add_parser(name, parents=[mod.argparser()])
40
+ p.set_defaults(func=mod.main)
41
+ return sub
42
+
43
+
44
+ def argparser():
45
+ """The subcommand namespace on its own (``add_help=False``, since each leaf
46
+ carries its own ``-h``)."""
47
+ parser = ArgumentParser(
48
+ "currtag",
49
+ formatter_class=ArgumentDefaultsHelpFormatter,
50
+ description=_DESCRIPTION,
51
+ add_help=False,
52
+ )
53
+ parser.add_argument(
54
+ '-v', '--version', action='version',
55
+ version='%(prog)s {}'.format(__version__)
56
+ )
57
+ _add_subparsers(parser)
58
+ return parser
59
+
60
+
61
+ def main(args=None):
62
+ """Console entry point: leaves hang off the top parser so
63
+ ``currtag <cmd> --help`` reaches the leaf."""
64
+ parser = ArgumentParser(
65
+ 'currtag',
66
+ formatter_class=ArgumentDefaultsHelpFormatter,
67
+ description=_DESCRIPTION,
68
+ )
69
+ parser.add_argument(
70
+ '-v', '--version', action='version',
71
+ version='%(prog)s {}'.format(__version__)
72
+ )
73
+ _add_subparsers(parser)
74
+
75
+ parsed = parser.parse_args(args)
76
+ parsed.func(parsed)