countmut 0.0.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.
countmut-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ye Chang
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,183 @@
1
+ Metadata-Version: 2.4
2
+ Name: countmut
3
+ Version: 0.0.1
4
+ Summary: Ultra-fast strand-aware mutation counter
5
+ Author-email: Ye Chang <yech1990@gmail.com>
6
+ License-Expression: MIT
7
+ Keywords: bioinformatics,bam,pileup,mutation,bisulfite,sequencing,genomics
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.14
17
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: pysam>=0.21.0
24
+ Requires-Dist: rich>=13.0.0
25
+ Requires-Dist: click>=8.0.0
26
+ Requires-Dist: rich-click>=1.6.0
27
+ Requires-Dist: numpy>=1.21.0
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
31
+ Requires-Dist: ruff>=0.14.0; extra == "dev"
32
+ Requires-Dist: black>=22.0.0; extra == "dev"
33
+ Provides-Extra: test
34
+ Requires-Dist: pytest>=7.0.0; extra == "test"
35
+ Requires-Dist: pytest-cov>=4.0.0; extra == "test"
36
+ Dynamic: license-file
37
+
38
+ # CountMut 🧬
39
+
40
+ [![CI](https://github.com/y9c/countmut/actions/workflows/ci.yml/badge.svg)](https://github.com/y9c/countmut/actions/workflows/ci.yml)
41
+ [![PyPI version](https://badge.fury.io/py/countmut.svg)](https://badge.fury.io/py/countmut)
42
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
43
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
44
+
45
+ **Ultra-fast strand-aware mutation counter**
46
+
47
+ CountMut counts mutations from bisulfite sequencing / BAM files with parallel processing, quality-based mate overlap deduplication, and optimized file I/O.
48
+
49
+ ## Features
50
+
51
+ - 🚀 **Ultra-Fast**: Direct FASTA index reading, shared file handles, BGZF multi-threading
52
+ - 🧬 **Bisulfite Support**: NS, Zf, Yf tag filtering for conversion analysis
53
+ - 🎯 **Accurate**: Quality-based mate overlap deduplication prevents double-counting
54
+ - ⚡ **Parallel**: Multi-threaded genomic window processing
55
+ - 🔧 **Flexible**: Configurable filtering, strand-specific processing, auto-indexing
56
+
57
+ ## Installation
58
+
59
+ ```bash
60
+ pip install countmut
61
+ ```
62
+
63
+ ## Quick Start
64
+
65
+ ```bash
66
+ # Basic usage - auto-creates indices if needed
67
+ countmut -i input.bam -r reference.fa -o mutations.tsv
68
+
69
+ # Count T→C mutations (common in bisulfite sequencing)
70
+ countmut -i input.bam -r reference.fa -o mutations.tsv --ref-base T --mut-base C
71
+
72
+ # With custom threads and filtering
73
+ countmut -i input.bam -r reference.fa -o mutations.tsv -t 8 --max-unc 5 --min-con 2
74
+ ```
75
+
76
+ ## Key Options
77
+
78
+ ```bash
79
+ Required:
80
+ -i, --input PATH Input BAM file
81
+ -r, --reference PATH Reference FASTA file
82
+
83
+ Output:
84
+ -o, --output PATH Output TSV file (default: stdout)
85
+
86
+ Mutation:
87
+ --ref-base TEXT Reference base [default: A]
88
+ --mut-base TEXT Mutation base [default: G]
89
+ --strand [both|forward|reverse] Strand processing [default: both]
90
+ --region TEXT Specific region (e.g., 'chr1:1000000-2000000')
91
+
92
+ Performance:
93
+ -t, --threads INTEGER Number of threads [default: auto]
94
+ -b, --bin-size INTEGER Genomic bin size [default: 10000]
95
+
96
+ Filtering (Bisulfite):
97
+ --pad INTEGER Motif window padding [default: 15]
98
+ --trim-start INTEGER Trim 5' bases [default: 2]
99
+ --trim-end INTEGER Trim 3' bases [default: 2]
100
+ --max-unc INTEGER Max unconverted (Zf) [default: 3]
101
+ --min-con INTEGER Min converted (Yf) [default: 1]
102
+ --max-sub INTEGER Max substitutions (NS) [default: 1]
103
+ ```
104
+
105
+ **Note**: BAM must have NS, Zf, and Yf tags for bisulfite analysis.
106
+
107
+ ## Output Format
108
+
109
+ TSV file with columns:
110
+ - `chrom`, `pos`, `strand`, `motif` - Position and context
111
+ - `u0`, `d0` - Drop counts (trimmed/unmapped bases)
112
+ - `u1`, `d1` - Clean counts (converted reads)
113
+ - `u2`, `d2` - Unconverted counts
114
+
115
+ ## Performance
116
+
117
+ Real-world test (3 rRNA genes, 17k reads):
118
+ - **Before optimization**: 16.7s
119
+ - **After optimization**: 4.5s (3.7x faster)
120
+ - **Startup**: 0.2s vs 3.2s (16x faster FASTA index loading)
121
+
122
+ ## Python API
123
+
124
+ ```python
125
+ from countmut import count_mutations
126
+
127
+ success = count_mutations(
128
+ samfile="input.bam",
129
+ reffile="reference.fa",
130
+ output_file="mutations.tsv",
131
+ ref_base="T",
132
+ mut_base="C",
133
+ threads=8,
134
+ max_unc=3,
135
+ min_con=1,
136
+ max_sub=1
137
+ )
138
+ ```
139
+
140
+ ## Requirements
141
+
142
+ - Python 3.10+
143
+ - pysam, rich, click, rich-click, numpy
144
+ - BAM files: coordinate-sorted with `.bai` index (auto-created if missing)
145
+ - FASTA files: with `.fai` index (auto-created if missing)
146
+
147
+ ## Development
148
+
149
+ ```bash
150
+ # Clone and install
151
+ git clone https://github.com/y9c/countmut.git
152
+ cd countmut
153
+ uv sync --dev
154
+
155
+ # Run tests
156
+ uv run pytest tests/ -v
157
+
158
+ # Lint
159
+ uv run ruff check .
160
+ ```
161
+
162
+ ## License
163
+
164
+ MIT License - see [LICENSE](LICENSE) file.
165
+
166
+ ## Citation
167
+
168
+ If you use CountMut in your research, please cite:
169
+
170
+ ```
171
+ Ye Chang. (2025). CountMut: Ultra-fast parallel mutation counter for bisulfite sequencing.
172
+ GitHub: https://github.com/y9c/countmut
173
+ ```
174
+
175
+ ## Contact
176
+
177
+ - **Author**: Ye Chang
178
+ - **Email**: yech1990@gmail.com
179
+ - **Issues**: https://github.com/y9c/countmut/issues
180
+
181
+ ---
182
+
183
+ **Version 0.0.1** | **MIT License**
@@ -0,0 +1,146 @@
1
+ # CountMut 🧬
2
+
3
+ [![CI](https://github.com/y9c/countmut/actions/workflows/ci.yml/badge.svg)](https://github.com/y9c/countmut/actions/workflows/ci.yml)
4
+ [![PyPI version](https://badge.fury.io/py/countmut.svg)](https://badge.fury.io/py/countmut)
5
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
7
+
8
+ **Ultra-fast strand-aware mutation counter**
9
+
10
+ CountMut counts mutations from bisulfite sequencing / BAM files with parallel processing, quality-based mate overlap deduplication, and optimized file I/O.
11
+
12
+ ## Features
13
+
14
+ - 🚀 **Ultra-Fast**: Direct FASTA index reading, shared file handles, BGZF multi-threading
15
+ - 🧬 **Bisulfite Support**: NS, Zf, Yf tag filtering for conversion analysis
16
+ - 🎯 **Accurate**: Quality-based mate overlap deduplication prevents double-counting
17
+ - ⚡ **Parallel**: Multi-threaded genomic window processing
18
+ - 🔧 **Flexible**: Configurable filtering, strand-specific processing, auto-indexing
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pip install countmut
24
+ ```
25
+
26
+ ## Quick Start
27
+
28
+ ```bash
29
+ # Basic usage - auto-creates indices if needed
30
+ countmut -i input.bam -r reference.fa -o mutations.tsv
31
+
32
+ # Count T→C mutations (common in bisulfite sequencing)
33
+ countmut -i input.bam -r reference.fa -o mutations.tsv --ref-base T --mut-base C
34
+
35
+ # With custom threads and filtering
36
+ countmut -i input.bam -r reference.fa -o mutations.tsv -t 8 --max-unc 5 --min-con 2
37
+ ```
38
+
39
+ ## Key Options
40
+
41
+ ```bash
42
+ Required:
43
+ -i, --input PATH Input BAM file
44
+ -r, --reference PATH Reference FASTA file
45
+
46
+ Output:
47
+ -o, --output PATH Output TSV file (default: stdout)
48
+
49
+ Mutation:
50
+ --ref-base TEXT Reference base [default: A]
51
+ --mut-base TEXT Mutation base [default: G]
52
+ --strand [both|forward|reverse] Strand processing [default: both]
53
+ --region TEXT Specific region (e.g., 'chr1:1000000-2000000')
54
+
55
+ Performance:
56
+ -t, --threads INTEGER Number of threads [default: auto]
57
+ -b, --bin-size INTEGER Genomic bin size [default: 10000]
58
+
59
+ Filtering (Bisulfite):
60
+ --pad INTEGER Motif window padding [default: 15]
61
+ --trim-start INTEGER Trim 5' bases [default: 2]
62
+ --trim-end INTEGER Trim 3' bases [default: 2]
63
+ --max-unc INTEGER Max unconverted (Zf) [default: 3]
64
+ --min-con INTEGER Min converted (Yf) [default: 1]
65
+ --max-sub INTEGER Max substitutions (NS) [default: 1]
66
+ ```
67
+
68
+ **Note**: BAM must have NS, Zf, and Yf tags for bisulfite analysis.
69
+
70
+ ## Output Format
71
+
72
+ TSV file with columns:
73
+ - `chrom`, `pos`, `strand`, `motif` - Position and context
74
+ - `u0`, `d0` - Drop counts (trimmed/unmapped bases)
75
+ - `u1`, `d1` - Clean counts (converted reads)
76
+ - `u2`, `d2` - Unconverted counts
77
+
78
+ ## Performance
79
+
80
+ Real-world test (3 rRNA genes, 17k reads):
81
+ - **Before optimization**: 16.7s
82
+ - **After optimization**: 4.5s (3.7x faster)
83
+ - **Startup**: 0.2s vs 3.2s (16x faster FASTA index loading)
84
+
85
+ ## Python API
86
+
87
+ ```python
88
+ from countmut import count_mutations
89
+
90
+ success = count_mutations(
91
+ samfile="input.bam",
92
+ reffile="reference.fa",
93
+ output_file="mutations.tsv",
94
+ ref_base="T",
95
+ mut_base="C",
96
+ threads=8,
97
+ max_unc=3,
98
+ min_con=1,
99
+ max_sub=1
100
+ )
101
+ ```
102
+
103
+ ## Requirements
104
+
105
+ - Python 3.10+
106
+ - pysam, rich, click, rich-click, numpy
107
+ - BAM files: coordinate-sorted with `.bai` index (auto-created if missing)
108
+ - FASTA files: with `.fai` index (auto-created if missing)
109
+
110
+ ## Development
111
+
112
+ ```bash
113
+ # Clone and install
114
+ git clone https://github.com/y9c/countmut.git
115
+ cd countmut
116
+ uv sync --dev
117
+
118
+ # Run tests
119
+ uv run pytest tests/ -v
120
+
121
+ # Lint
122
+ uv run ruff check .
123
+ ```
124
+
125
+ ## License
126
+
127
+ MIT License - see [LICENSE](LICENSE) file.
128
+
129
+ ## Citation
130
+
131
+ If you use CountMut in your research, please cite:
132
+
133
+ ```
134
+ Ye Chang. (2025). CountMut: Ultra-fast parallel mutation counter for bisulfite sequencing.
135
+ GitHub: https://github.com/y9c/countmut
136
+ ```
137
+
138
+ ## Contact
139
+
140
+ - **Author**: Ye Chang
141
+ - **Email**: yech1990@gmail.com
142
+ - **Issues**: https://github.com/y9c/countmut/issues
143
+
144
+ ---
145
+
146
+ **Version 0.0.1** | **MIT License**
@@ -0,0 +1,27 @@
1
+ """
2
+ CountMut - Fast, parallel mutation counting from BAM pileup data
3
+
4
+ This package provides efficient mutation counting functionality with:
5
+ - Parallel processing using genomic windows
6
+ - Bisulfite conversion analysis
7
+ - Rich logging and progress tracking
8
+ - Modern CLI interface
9
+
10
+ Author: Ye Chang
11
+ Date: 2025-10-23
12
+ """
13
+
14
+ from .cli import main
15
+ from .core import count_mutations
16
+ from .utils import format_duration, get_output_headers, write_output
17
+
18
+ __author__ = "Ye Chang"
19
+ __email__ = "yech1990@gmail.com"
20
+
21
+ __all__ = [
22
+ "count_mutations",
23
+ "format_duration",
24
+ "get_output_headers",
25
+ "main",
26
+ "write_output",
27
+ ]