seqmat 1.5.1__tar.gz → 1.6.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 (48) hide show
  1. {seqmat-1.5.1/seqmat.egg-info → seqmat-1.6.0}/PKG-INFO +64 -56
  2. {seqmat-1.5.1 → seqmat-1.6.0}/README.md +60 -28
  3. {seqmat-1.5.1 → seqmat-1.6.0}/examples/basic_usage.py +7 -7
  4. {seqmat-1.5.1 → seqmat-1.6.0}/examples/data_inspection.py +0 -14
  5. {seqmat-1.5.1 → seqmat-1.6.0}/pyproject.toml +7 -11
  6. seqmat-1.6.0/requirements.txt +6 -0
  7. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/__init__.py +2 -8
  8. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/cli.py +104 -64
  9. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/config.py +64 -40
  10. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/conservation.py +2 -4
  11. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/data_setup.py +14 -54
  12. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/discovery.py +10 -22
  13. seqmat-1.6.0/seqmat/download.py +280 -0
  14. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/gene.py +47 -48
  15. seqmat-1.6.0/seqmat/genes_db.py +230 -0
  16. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/gtf.py +73 -163
  17. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/locator.py +60 -68
  18. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/seqmat.py +287 -252
  19. seqmat-1.6.0/seqmat/sqlite_store.py +62 -0
  20. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/transcript.py +102 -50
  21. {seqmat-1.5.1 → seqmat-1.6.0/seqmat.egg-info}/PKG-INFO +64 -56
  22. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat.egg-info/SOURCES.txt +9 -4
  23. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat.egg-info/requires.txt +1 -6
  24. seqmat-1.6.0/tests/test_download.py +27 -0
  25. {seqmat-1.5.1 → seqmat-1.6.0}/tests/test_gene.py +54 -41
  26. seqmat-1.6.0/tests/test_genes_db.py +46 -0
  27. seqmat-1.6.0/tests/test_gtf.py +86 -0
  28. {seqmat-1.5.1 → seqmat-1.6.0}/tests/test_locator.py +35 -0
  29. seqmat-1.6.0/tests/test_mutation_oracle.py +114 -0
  30. seqmat-1.6.0/tests/test_prebuilt_download.py +96 -0
  31. seqmat-1.6.0/tests/test_protein.py +138 -0
  32. {seqmat-1.5.1 → seqmat-1.6.0}/tests/test_seqmat.py +67 -2
  33. seqmat-1.6.0/tests/test_transcript.py +112 -0
  34. seqmat-1.5.1/requirements.txt +0 -8
  35. seqmat-1.5.1/seqmat/_io.py +0 -34
  36. seqmat-1.5.1/seqmat/download.py +0 -228
  37. seqmat-1.5.1/seqmat/lmdb_store.py +0 -150
  38. seqmat-1.5.1/seqmat/sqlite_store.py +0 -50
  39. seqmat-1.5.1/seqmat/utils.py +0 -169
  40. {seqmat-1.5.1 → seqmat-1.6.0}/LICENSE +0 -0
  41. {seqmat-1.5.1 → seqmat-1.6.0}/MANIFEST.in +0 -0
  42. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat/errors.py +0 -0
  43. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat.egg-info/dependency_links.txt +0 -0
  44. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat.egg-info/entry_points.txt +0 -0
  45. {seqmat-1.5.1 → seqmat-1.6.0}/seqmat.egg-info/top_level.txt +0 -0
  46. {seqmat-1.5.1 → seqmat-1.6.0}/setup.cfg +0 -0
  47. {seqmat-1.5.1 → seqmat-1.6.0}/tests/__init__.py +0 -0
  48. {seqmat-1.5.1 → seqmat-1.6.0}/tests/bench_gene_creation.py +0 -0
@@ -1,29 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: seqmat
3
- Version: 1.5.1
3
+ Version: 1.6.0
4
4
  Summary: Fast, vectorized genomic sequences with first-class mutation tracking.
5
5
  Author-email: Nicolas Lynn Vila <nicolasalynn@gmail.com>
6
- License: MIT License
7
-
8
- Copyright (c) 2024 SeqMat Contributors
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy
11
- of this software and associated documentation files (the "Software"), to deal
12
- in the Software without restriction, including without limitation the rights
13
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
- copies of the Software, and to permit persons to whom the Software is
15
- furnished to do so, subject to the following conditions:
16
-
17
- The above copyright notice and this permission notice shall be included in all
18
- copies or substantial portions of the Software.
19
-
20
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
- SOFTWARE.
6
+ License-Expression: MIT
27
7
  Project-URL: Homepage, https://github.com/nicolasalynn/seqmat
28
8
  Project-URL: Repository, https://github.com/nicolasalynn/seqmat
29
9
  Project-URL: Issues, https://github.com/nicolasalynn/seqmat/issues
@@ -32,24 +12,20 @@ Keywords: bioinformatics,genomics,sequence,mutation,splicing,transcript,hg38,mm3
32
12
  Classifier: Development Status :: 5 - Production/Stable
33
13
  Classifier: Intended Audience :: Science/Research
34
14
  Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
35
- Classifier: License :: OSI Approved :: MIT License
36
15
  Classifier: Programming Language :: Python :: 3
37
16
  Classifier: Programming Language :: Python :: 3.10
38
17
  Classifier: Programming Language :: Python :: 3.11
39
18
  Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
40
20
  Classifier: Operating System :: OS Independent
41
21
  Requires-Python: >=3.10
42
22
  Description-Content-Type: text/markdown
43
23
  License-File: LICENSE
44
24
  Requires-Dist: numpy<3,>=1.20.0
45
- Requires-Dist: pandas<3,>=2.2.0
25
+ Requires-Dist: pandas<4,>=2.2.0
46
26
  Requires-Dist: pyarrow>=15.0.0
47
27
  Requires-Dist: pysam>=0.19.0
48
- Requires-Dist: requests>=2.26.0
49
- Requires-Dist: tqdm>=4.62.0
50
28
  Requires-Dist: platformdirs>=3.0.0
51
- Provides-Extra: lmdb
52
- Requires-Dist: lmdb>=1.4.0; extra == "lmdb"
53
29
  Provides-Extra: dev
54
30
  Requires-Dist: pytest>=6.0; extra == "dev"
55
31
  Requires-Dist: pytest-cov>=2.0; extra == "dev"
@@ -59,19 +35,21 @@ Requires-Dist: pdoc>=14.0; extra == "dev"
59
35
  Dynamic: license-file
60
36
 
61
37
  <p align="center">
62
- <img src="docs/assets/logo.svg" alt="SeqMat" width="540">
38
+ <img src="https://raw.githubusercontent.com/nicolasalynn/seqmat/main/docs/assets/logo.svg" alt="SeqMat" width="540">
63
39
  </p>
64
40
 
65
41
  [![PyPI](https://img.shields.io/pypi/v/seqmat.svg)](https://pypi.org/project/seqmat/)
66
42
  [![Python](https://img.shields.io/pypi/pyversions/seqmat.svg)](https://pypi.org/project/seqmat/)
67
43
  [![Tests](https://github.com/nicolasalynn/seqmat/actions/workflows/test.yml/badge.svg)](https://github.com/nicolasalynn/seqmat/actions/workflows/test.yml)
68
44
  [![codecov](https://codecov.io/gh/nicolasalynn/seqmat/branch/main/graph/badge.svg)](https://codecov.io/gh/nicolasalynn/seqmat)
69
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
45
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/nicolasalynn/seqmat/blob/main/LICENSE)
70
46
  [![Downloads](https://static.pepy.tech/badge/seqmat/month)](https://pepy.tech/project/seqmat)
71
47
 
72
- A Python library for genomic sequences that keeps genomic coordinates and mutation history attached to the bases.
48
+ A small Python library for **variant-effect and splicing workflows** — the kind where keeping a genomic coordinate and the original reference attached to each base is most of the value.
73
49
 
74
- SeqMat stores a DNA sequence as a NumPy structured array — `(nt, ref, index, mut_type, valid)` in parallel columns rather than a byte string. Slicing, mutation, complement, and splicing preserve genomic coordinates and the reference state through every transform, and the mutation history is recorded as a side product. The library also includes a gene/transcript model loaded from a single SQLite file built from Ensembl annotations, and a position → gene lookup over a sidecar index.
50
+ SeqMat is not a replacement for Biopython. Biopython is the right default for sequence I/O, alignments, raw byte operations, and most of bioinformatics. SeqMat fills a narrower slot: when you need to apply a variant at a genomic coordinate, splice introns out, re-translate, and ask *"what was here originally?"* — that bookkeeping lives in the data model instead of in your code.
51
+
52
+ A DNA sequence is stored as a NumPy structured array — `(nt, ref, index, mut_type, valid)` in parallel columns rather than a byte string. Slicing, mutation, complement, and splicing preserve the `index` (genomic coordinates) and the `ref` (original bases) through every transform, and mutation history is recorded as a side product. The library also includes a gene/transcript model loaded from a single SQLite file built from Ensembl annotations, and a position → gene lookup over a sidecar NumPy index.
75
53
 
76
54
  ```python
77
55
  from seqmat import Gene, SeqMat
@@ -91,7 +69,29 @@ seq.apply_mutations([(3, "C", "G"), (6, "-", "AAA"), (10, "TC", "-")])
91
69
  seq.mutations
92
70
  ```
93
71
 
94
- A worked example, end to end: [KRAS G12D — coordinate to protein](examples/kras_g12d_analysis.ipynb).
72
+ Worked examples:
73
+
74
+ - [KRAS G12D — coordinate to protein](https://github.com/nicolasalynn/seqmat/blob/main/examples/kras_g12d_analysis.ipynb): chromosome coordinate → mature mRNA → protein, comparing wild type to the G12D mutant.
75
+ - [SeqMat vs Biopython, side by side](https://github.com/nicolasalynn/seqmat/blob/main/examples/seqmat_vs_biopython.ipynb): the same tasks in both libraries, with timings, calling out where each one wins.
76
+
77
+ ---
78
+
79
+ ## When SeqMat fits — and when it doesn't
80
+
81
+ Reach for SeqMat when:
82
+
83
+ - You have a genomic coordinate and want the gene, transcript, mature mRNA, or protein-level effect of a variant at it.
84
+ - You need to splice introns out of a pre-mRNA while keeping a coordinate map for everything that survives.
85
+ - You want a mutation history attached to the sequence without writing your own side-car dict.
86
+ - You're doing splicing or variant-effect analyses where "what was originally here?" comes up repeatedly.
87
+
88
+ Reach for Biopython (or another tool) when:
89
+
90
+ - You're reading or writing FASTA, GenBank, EMBL, alignments, BLAST output, NCBI fetch, etc. Biopython has decades of format coverage that SeqMat will not match.
91
+ - You need maximum throughput on raw byte operations — reverse-complement on long chromosomes, mass translations, big alignment passes. SeqMat's structured-array overhead is real and `Bio.Seq` will win.
92
+ - You're doing batch interval-set algebra over many feature tables — that's PyRanges' job.
93
+
94
+ The two libraries compose. Many real pipelines load FASTA via Biopython, do byte-level work in `Bio.Seq`, and reach for SeqMat where coordinate tracking and mutation history would otherwise be hand-written. See [examples/seqmat_vs_biopython.ipynb](https://github.com/nicolasalynn/seqmat/blob/main/examples/seqmat_vs_biopython.ipynb) for a head-to-head.
95
95
 
96
96
  ---
97
97
 
@@ -102,7 +102,7 @@ pip install seqmat
102
102
  seqmat setup # one-time: downloads hg38 genes.db + FASTA (~4 GB)
103
103
  ```
104
104
 
105
- `seqmat setup` appends `SEQMAT_DATA_DIR` and `SEQMAT_DEFAULT_ORGANISM` to your shell rc so the data is found automatically next session. Mouse: `seqmat setup --organism mm39`.
105
+ `seqmat setup` records the data paths in `config.json` so the data is found automatically next session. Mouse: `seqmat setup --organism mm39`.
106
106
 
107
107
  If you only want `SeqMat` for in-memory sequence work, you can skip `seqmat setup` — `Gene` and `Transcript` are the only objects that need the gene database.
108
108
 
@@ -152,15 +152,20 @@ Backed by a per-chromosome sorted NumPy index persisted as a sidecar `gene_locat
152
152
  ### Loading from FASTA
153
153
 
154
154
  ```python
155
- seq = SeqMat.from_fasta_file("chr12.fasta", "chr12", start=25398284, end=25398384)
156
- seq.apply_mutations([(25398290, "G", "A")]) # G12D, a common KRAS variant
155
+ seq = SeqMat.from_fasta_file("hg38.fa", "chr12", start=25_245_300, end=25_245_400)
156
+ seq.apply_mutations([(25_245_350, "C", "T")]) # KRAS G12D (c.35G>A; alleles are always + strand)
157
157
  ```
158
158
 
159
159
  ## Performance
160
160
 
161
+ Two short statements first, then the numbers.
162
+
163
+ 1. **For the operations SeqMat is built around** (coordinate-aware gene lookup, splicing-with-coordinate-preservation, mutation-tracked sequence assembly), it's fast enough that performance won't be the bottleneck in your pipeline.
164
+ 2. **For raw byte operations** (reverse-complement, mass translation, simple string mutations without coordinate tracking), Biopython is faster, often substantially. Use it.
165
+
161
166
  Measured on an M-series Mac, hg38, one core, warm caches. Reproducible via the scripts in `benchmarks/`.
162
167
 
163
- ### Headline numbers
168
+ ### Operations SeqMat is built for
164
169
 
165
170
  | Operation | Time |
166
171
  | -------------------------------------------------- | -------: |
@@ -170,11 +175,11 @@ Measured on an M-series Mac, hg38, one core, warm caches. Reproducible via the s
170
175
  | `Gene.from_file("KRAS")` (SQLite + unpickle) | 24 ms |
171
176
  | `Gene.from_position(chrm, pos)` end-to-end | 24 ms |
172
177
 
173
- ### Position → gene
178
+ ### Position → gene, head-to-head
174
179
 
175
- Same 63,241 hg38 gene intervals, same 10,000 random point queries. Different libraries are designed for different access patterns, so we report two workloads. Reproduce with `python benchmarks/bench_position_lookup.py`.
180
+ Same 63,241 hg38 gene intervals, same 10,000 random point queries. PyRanges is the natural comparison; both libraries are good at this, in different idioms. Reproduce with `python benchmarks/bench_position_lookup.py`.
176
181
 
177
- Per-query (one coordinate, one answer, in a loop — the `Gene.from_position` pattern):
182
+ Per-query (one coordinate, one answer, in a loop — `Gene.from_position`'s pattern):
178
183
 
179
184
  | Implementation | Per query |
180
185
  | --------------------------------------- | --------: |
@@ -183,31 +188,30 @@ Per-query (one coordinate, one answer, in a loop — the `Gene.from_position` pa
183
188
  | pandas (`groupby` chrm + boolean mask) | 79 µs |
184
189
  | PyRanges constructed per call | 2.0 ms |
185
190
 
186
- Batched (the whole query set in one call — PyRanges' native idiom):
191
+ Batched (all queries handed in at once — PyRanges' native idiom):
187
192
 
188
193
  | Implementation | Per query |
189
194
  | ----------------------------- | --------: |
190
195
  | PyRanges `.join` | 2.07 µs |
191
196
  | SeqMat (serial loop) | 2.59 µs |
192
197
 
193
- PyRanges and SeqMat are in roughly the same range when each is used the way it was designed for. Constructing a `PyRanges` per call is the slow path and not the PyRanges authors' intent — included here only because it's a common mistake.
198
+ Each library wins its native workload. Constructing a `PyRanges` per call is slow (and not what its authors intend) — listed only because it's a common mistake.
194
199
 
195
- ### Sequence operations vs Biopython
200
+ ### Where Biopython is faster
196
201
 
197
- 50 kb sequence, 1,000 SNPs / 10 introns; 1 Mb reverse-complement. Reproduce with `python benchmarks/bench_sequence_ops.py`.
202
+ For completeness, here are the operations where SeqMat is the wrong choice. The gap is the cost of the structured-array data model, which carries `(nt, ref, index, mut_type, valid)` through every transform.
198
203
 
199
- | Workload | Biopython / native | SeqMat |
200
- | ---------------------------------------------- | ------------------------------: | ------: |
201
- | 1,000 SNPs (no history) | `MutableSeq`: 0.21 ms | — |
202
- | 1,000 SNPs with full mutation history | — | 0.5 ms |
203
- | 10-intron splice (50 kb) | `str.join`: 0.002 ms | 0.8 ms |
204
- | Reverse-complement (1 Mb) | `Seq.reverse_complement`: 0.57 ms | 9.4 ms |
204
+ | Workload | Biopython / native | SeqMat |
205
+ | ------------------------------ | ------------------------------: | ------: |
206
+ | 1,000 SNPs (no history needed) | `MutableSeq`: 0.21 ms | 0.5 ms (with history) |
207
+ | 10-intron splice (50 kb) | `str.join`: 0.002 ms | 0.8 ms (coordinate-preserving) |
208
+ | Reverse-complement (1 Mb) | `Seq.reverse_complement`: 0.57 ms | 9.4 ms |
205
209
 
206
- For raw byte-string throughput, `Bio.Seq` and `bytearray` are faster. SeqMat's structured array adds bookkeeping that those types don't carry — genomic coordinates that survive indels, the reference held alongside the current sequence, and a mutation history list. The trade-off makes sense when you need that bookkeeping anyway (the KRAS G12D walkthrough is a typical case) and doesn't when you don't.
210
+ If your hot path is one of these and you don't need coordinates or history attached to the result, use `Bio.Seq` or `bytearray`. The two libraries compose fine.
207
211
 
208
212
  ### Implementation notes
209
213
 
210
- NumPy structured arrays, LUT-based complement, `np.searchsorted` on sorted exon and gene-start coordinates, FASTA range-scoped reads, copy-on-write `clone()`. See [`seqmat/seqmat.py`](seqmat/seqmat.py) and [`seqmat/locator.py`](seqmat/locator.py).
214
+ NumPy structured arrays, LUT-based complement, `np.searchsorted` on sorted exon and gene-start coordinates, FASTA range-scoped reads, copy-on-write `clone()`. See [`seqmat/seqmat.py`](https://github.com/nicolasalynn/seqmat/blob/main/seqmat/seqmat.py) and [`seqmat/locator.py`](https://github.com/nicolasalynn/seqmat/blob/main/seqmat/locator.py).
211
215
 
212
216
  ## Command-line interface
213
217
 
@@ -222,13 +226,13 @@ seqmat count --organism hg38
222
226
 
223
227
  ## Data setup
224
228
 
225
- By default `seqmat setup` downloads prebuilt `genes.db` and FASTA from the SeqMat S3 bucket. To regenerate `genes.db` from a specific Ensembl release or a custom GTF:
229
+ By default `seqmat setup` downloads prebuilt `genes.db` and a bgzipped FASTA from Hugging Face (`nicolasalynn/shared-assets`, with the old S3 bucket as fallback), verifying sha256 checksums. To regenerate `genes.db` from a specific Ensembl release or a custom GTF:
226
230
 
227
231
  ```bash
228
232
  seqmat setup --organism hg38 --build-from-sources
229
233
  ```
230
234
 
231
- Custom organisms, mirror buckets, ephemeral environments (Docker / Run.ai), shared multi-user installs, and the full configuration system are documented in [docs/SETUP.md](docs/SETUP.md).
235
+ Custom organisms, mirror buckets, ephemeral environments (Docker / Run.ai), shared multi-user installs, and the full configuration system are documented in [docs/SETUP.md](https://github.com/nicolasalynn/seqmat/blob/main/docs/SETUP.md).
232
236
 
233
237
  ## API at a glance
234
238
 
@@ -253,19 +257,23 @@ Full API reference (auto-generated from docstrings): [nicolasalynn.github.io/seq
253
257
 
254
258
  ## Requirements
255
259
 
256
- Python ≥ 3.10. Core deps: `numpy`, `pandas`, `pyarrow`, `pysam`, `requests`, `tqdm`, `platformdirs`. Optional: `lmdb` for faster gene loading on large workloads (`pip install seqmat[lmdb]`).
260
+ Python ≥ 3.10. Core deps: `numpy`, `pandas`, `pyarrow`, `pysam`, `platformdirs`.
257
261
 
258
262
  ## A note on indexing
259
263
 
260
264
  `SeqMat` defaults to 1-based indices to match genomic conventions (UCSC, GenBank). If you'd rather work in 0-based offsets — e.g. for a comparison with `bytearray` or `Bio.Seq` — pass `indices=np.arange(len(seq))` at construction.
261
265
 
266
+ ## Roadmap
267
+
268
+ [ROADMAP.md](https://github.com/nicolasalynn/seqmat/blob/main/ROADMAP.md) — what's coming, what isn't, and why. The headline themes: VCF + per-patient `Patient` / `Cohort` objects with lazy region-scoped variant application, reference-build-aware coordinate conversion, and splicing-impact integration.
269
+
262
270
  ## Contributing
263
271
 
264
272
  PRs welcome. Run the test suite with `pytest tests/`. Comparative benchmarks are under `benchmarks/`.
265
273
 
266
274
  ## License
267
275
 
268
- MIT — see [LICENSE](LICENSE).
276
+ MIT — see [LICENSE](https://github.com/nicolasalynn/seqmat/blob/main/LICENSE).
269
277
 
270
278
  ## Citation
271
279
 
@@ -1,17 +1,19 @@
1
1
  <p align="center">
2
- <img src="docs/assets/logo.svg" alt="SeqMat" width="540">
2
+ <img src="https://raw.githubusercontent.com/nicolasalynn/seqmat/main/docs/assets/logo.svg" alt="SeqMat" width="540">
3
3
  </p>
4
4
 
5
5
  [![PyPI](https://img.shields.io/pypi/v/seqmat.svg)](https://pypi.org/project/seqmat/)
6
6
  [![Python](https://img.shields.io/pypi/pyversions/seqmat.svg)](https://pypi.org/project/seqmat/)
7
7
  [![Tests](https://github.com/nicolasalynn/seqmat/actions/workflows/test.yml/badge.svg)](https://github.com/nicolasalynn/seqmat/actions/workflows/test.yml)
8
8
  [![codecov](https://codecov.io/gh/nicolasalynn/seqmat/branch/main/graph/badge.svg)](https://codecov.io/gh/nicolasalynn/seqmat)
9
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/nicolasalynn/seqmat/blob/main/LICENSE)
10
10
  [![Downloads](https://static.pepy.tech/badge/seqmat/month)](https://pepy.tech/project/seqmat)
11
11
 
12
- A Python library for genomic sequences that keeps genomic coordinates and mutation history attached to the bases.
12
+ A small Python library for **variant-effect and splicing workflows** — the kind where keeping a genomic coordinate and the original reference attached to each base is most of the value.
13
13
 
14
- SeqMat stores a DNA sequence as a NumPy structured array — `(nt, ref, index, mut_type, valid)` in parallel columns rather than a byte string. Slicing, mutation, complement, and splicing preserve genomic coordinates and the reference state through every transform, and the mutation history is recorded as a side product. The library also includes a gene/transcript model loaded from a single SQLite file built from Ensembl annotations, and a position → gene lookup over a sidecar index.
14
+ SeqMat is not a replacement for Biopython. Biopython is the right default for sequence I/O, alignments, raw byte operations, and most of bioinformatics. SeqMat fills a narrower slot: when you need to apply a variant at a genomic coordinate, splice introns out, re-translate, and ask *"what was here originally?"* — that bookkeeping lives in the data model instead of in your code.
15
+
16
+ A DNA sequence is stored as a NumPy structured array — `(nt, ref, index, mut_type, valid)` in parallel columns rather than a byte string. Slicing, mutation, complement, and splicing preserve the `index` (genomic coordinates) and the `ref` (original bases) through every transform, and mutation history is recorded as a side product. The library also includes a gene/transcript model loaded from a single SQLite file built from Ensembl annotations, and a position → gene lookup over a sidecar NumPy index.
15
17
 
16
18
  ```python
17
19
  from seqmat import Gene, SeqMat
@@ -31,7 +33,29 @@ seq.apply_mutations([(3, "C", "G"), (6, "-", "AAA"), (10, "TC", "-")])
31
33
  seq.mutations
32
34
  ```
33
35
 
34
- A worked example, end to end: [KRAS G12D — coordinate to protein](examples/kras_g12d_analysis.ipynb).
36
+ Worked examples:
37
+
38
+ - [KRAS G12D — coordinate to protein](https://github.com/nicolasalynn/seqmat/blob/main/examples/kras_g12d_analysis.ipynb): chromosome coordinate → mature mRNA → protein, comparing wild type to the G12D mutant.
39
+ - [SeqMat vs Biopython, side by side](https://github.com/nicolasalynn/seqmat/blob/main/examples/seqmat_vs_biopython.ipynb): the same tasks in both libraries, with timings, calling out where each one wins.
40
+
41
+ ---
42
+
43
+ ## When SeqMat fits — and when it doesn't
44
+
45
+ Reach for SeqMat when:
46
+
47
+ - You have a genomic coordinate and want the gene, transcript, mature mRNA, or protein-level effect of a variant at it.
48
+ - You need to splice introns out of a pre-mRNA while keeping a coordinate map for everything that survives.
49
+ - You want a mutation history attached to the sequence without writing your own side-car dict.
50
+ - You're doing splicing or variant-effect analyses where "what was originally here?" comes up repeatedly.
51
+
52
+ Reach for Biopython (or another tool) when:
53
+
54
+ - You're reading or writing FASTA, GenBank, EMBL, alignments, BLAST output, NCBI fetch, etc. Biopython has decades of format coverage that SeqMat will not match.
55
+ - You need maximum throughput on raw byte operations — reverse-complement on long chromosomes, mass translations, big alignment passes. SeqMat's structured-array overhead is real and `Bio.Seq` will win.
56
+ - You're doing batch interval-set algebra over many feature tables — that's PyRanges' job.
57
+
58
+ The two libraries compose. Many real pipelines load FASTA via Biopython, do byte-level work in `Bio.Seq`, and reach for SeqMat where coordinate tracking and mutation history would otherwise be hand-written. See [examples/seqmat_vs_biopython.ipynb](https://github.com/nicolasalynn/seqmat/blob/main/examples/seqmat_vs_biopython.ipynb) for a head-to-head.
35
59
 
36
60
  ---
37
61
 
@@ -42,7 +66,7 @@ pip install seqmat
42
66
  seqmat setup # one-time: downloads hg38 genes.db + FASTA (~4 GB)
43
67
  ```
44
68
 
45
- `seqmat setup` appends `SEQMAT_DATA_DIR` and `SEQMAT_DEFAULT_ORGANISM` to your shell rc so the data is found automatically next session. Mouse: `seqmat setup --organism mm39`.
69
+ `seqmat setup` records the data paths in `config.json` so the data is found automatically next session. Mouse: `seqmat setup --organism mm39`.
46
70
 
47
71
  If you only want `SeqMat` for in-memory sequence work, you can skip `seqmat setup` — `Gene` and `Transcript` are the only objects that need the gene database.
48
72
 
@@ -92,15 +116,20 @@ Backed by a per-chromosome sorted NumPy index persisted as a sidecar `gene_locat
92
116
  ### Loading from FASTA
93
117
 
94
118
  ```python
95
- seq = SeqMat.from_fasta_file("chr12.fasta", "chr12", start=25398284, end=25398384)
96
- seq.apply_mutations([(25398290, "G", "A")]) # G12D, a common KRAS variant
119
+ seq = SeqMat.from_fasta_file("hg38.fa", "chr12", start=25_245_300, end=25_245_400)
120
+ seq.apply_mutations([(25_245_350, "C", "T")]) # KRAS G12D (c.35G>A; alleles are always + strand)
97
121
  ```
98
122
 
99
123
  ## Performance
100
124
 
125
+ Two short statements first, then the numbers.
126
+
127
+ 1. **For the operations SeqMat is built around** (coordinate-aware gene lookup, splicing-with-coordinate-preservation, mutation-tracked sequence assembly), it's fast enough that performance won't be the bottleneck in your pipeline.
128
+ 2. **For raw byte operations** (reverse-complement, mass translation, simple string mutations without coordinate tracking), Biopython is faster, often substantially. Use it.
129
+
101
130
  Measured on an M-series Mac, hg38, one core, warm caches. Reproducible via the scripts in `benchmarks/`.
102
131
 
103
- ### Headline numbers
132
+ ### Operations SeqMat is built for
104
133
 
105
134
  | Operation | Time |
106
135
  | -------------------------------------------------- | -------: |
@@ -110,11 +139,11 @@ Measured on an M-series Mac, hg38, one core, warm caches. Reproducible via the s
110
139
  | `Gene.from_file("KRAS")` (SQLite + unpickle) | 24 ms |
111
140
  | `Gene.from_position(chrm, pos)` end-to-end | 24 ms |
112
141
 
113
- ### Position → gene
142
+ ### Position → gene, head-to-head
114
143
 
115
- Same 63,241 hg38 gene intervals, same 10,000 random point queries. Different libraries are designed for different access patterns, so we report two workloads. Reproduce with `python benchmarks/bench_position_lookup.py`.
144
+ Same 63,241 hg38 gene intervals, same 10,000 random point queries. PyRanges is the natural comparison; both libraries are good at this, in different idioms. Reproduce with `python benchmarks/bench_position_lookup.py`.
116
145
 
117
- Per-query (one coordinate, one answer, in a loop — the `Gene.from_position` pattern):
146
+ Per-query (one coordinate, one answer, in a loop — `Gene.from_position`'s pattern):
118
147
 
119
148
  | Implementation | Per query |
120
149
  | --------------------------------------- | --------: |
@@ -123,31 +152,30 @@ Per-query (one coordinate, one answer, in a loop — the `Gene.from_position` pa
123
152
  | pandas (`groupby` chrm + boolean mask) | 79 µs |
124
153
  | PyRanges constructed per call | 2.0 ms |
125
154
 
126
- Batched (the whole query set in one call — PyRanges' native idiom):
155
+ Batched (all queries handed in at once — PyRanges' native idiom):
127
156
 
128
157
  | Implementation | Per query |
129
158
  | ----------------------------- | --------: |
130
159
  | PyRanges `.join` | 2.07 µs |
131
160
  | SeqMat (serial loop) | 2.59 µs |
132
161
 
133
- PyRanges and SeqMat are in roughly the same range when each is used the way it was designed for. Constructing a `PyRanges` per call is the slow path and not the PyRanges authors' intent — included here only because it's a common mistake.
162
+ Each library wins its native workload. Constructing a `PyRanges` per call is slow (and not what its authors intend) — listed only because it's a common mistake.
134
163
 
135
- ### Sequence operations vs Biopython
164
+ ### Where Biopython is faster
136
165
 
137
- 50 kb sequence, 1,000 SNPs / 10 introns; 1 Mb reverse-complement. Reproduce with `python benchmarks/bench_sequence_ops.py`.
166
+ For completeness, here are the operations where SeqMat is the wrong choice. The gap is the cost of the structured-array data model, which carries `(nt, ref, index, mut_type, valid)` through every transform.
138
167
 
139
- | Workload | Biopython / native | SeqMat |
140
- | ---------------------------------------------- | ------------------------------: | ------: |
141
- | 1,000 SNPs (no history) | `MutableSeq`: 0.21 ms | — |
142
- | 1,000 SNPs with full mutation history | — | 0.5 ms |
143
- | 10-intron splice (50 kb) | `str.join`: 0.002 ms | 0.8 ms |
144
- | Reverse-complement (1 Mb) | `Seq.reverse_complement`: 0.57 ms | 9.4 ms |
168
+ | Workload | Biopython / native | SeqMat |
169
+ | ------------------------------ | ------------------------------: | ------: |
170
+ | 1,000 SNPs (no history needed) | `MutableSeq`: 0.21 ms | 0.5 ms (with history) |
171
+ | 10-intron splice (50 kb) | `str.join`: 0.002 ms | 0.8 ms (coordinate-preserving) |
172
+ | Reverse-complement (1 Mb) | `Seq.reverse_complement`: 0.57 ms | 9.4 ms |
145
173
 
146
- For raw byte-string throughput, `Bio.Seq` and `bytearray` are faster. SeqMat's structured array adds bookkeeping that those types don't carry — genomic coordinates that survive indels, the reference held alongside the current sequence, and a mutation history list. The trade-off makes sense when you need that bookkeeping anyway (the KRAS G12D walkthrough is a typical case) and doesn't when you don't.
174
+ If your hot path is one of these and you don't need coordinates or history attached to the result, use `Bio.Seq` or `bytearray`. The two libraries compose fine.
147
175
 
148
176
  ### Implementation notes
149
177
 
150
- NumPy structured arrays, LUT-based complement, `np.searchsorted` on sorted exon and gene-start coordinates, FASTA range-scoped reads, copy-on-write `clone()`. See [`seqmat/seqmat.py`](seqmat/seqmat.py) and [`seqmat/locator.py`](seqmat/locator.py).
178
+ NumPy structured arrays, LUT-based complement, `np.searchsorted` on sorted exon and gene-start coordinates, FASTA range-scoped reads, copy-on-write `clone()`. See [`seqmat/seqmat.py`](https://github.com/nicolasalynn/seqmat/blob/main/seqmat/seqmat.py) and [`seqmat/locator.py`](https://github.com/nicolasalynn/seqmat/blob/main/seqmat/locator.py).
151
179
 
152
180
  ## Command-line interface
153
181
 
@@ -162,13 +190,13 @@ seqmat count --organism hg38
162
190
 
163
191
  ## Data setup
164
192
 
165
- By default `seqmat setup` downloads prebuilt `genes.db` and FASTA from the SeqMat S3 bucket. To regenerate `genes.db` from a specific Ensembl release or a custom GTF:
193
+ By default `seqmat setup` downloads prebuilt `genes.db` and a bgzipped FASTA from Hugging Face (`nicolasalynn/shared-assets`, with the old S3 bucket as fallback), verifying sha256 checksums. To regenerate `genes.db` from a specific Ensembl release or a custom GTF:
166
194
 
167
195
  ```bash
168
196
  seqmat setup --organism hg38 --build-from-sources
169
197
  ```
170
198
 
171
- Custom organisms, mirror buckets, ephemeral environments (Docker / Run.ai), shared multi-user installs, and the full configuration system are documented in [docs/SETUP.md](docs/SETUP.md).
199
+ Custom organisms, mirror buckets, ephemeral environments (Docker / Run.ai), shared multi-user installs, and the full configuration system are documented in [docs/SETUP.md](https://github.com/nicolasalynn/seqmat/blob/main/docs/SETUP.md).
172
200
 
173
201
  ## API at a glance
174
202
 
@@ -193,19 +221,23 @@ Full API reference (auto-generated from docstrings): [nicolasalynn.github.io/seq
193
221
 
194
222
  ## Requirements
195
223
 
196
- Python ≥ 3.10. Core deps: `numpy`, `pandas`, `pyarrow`, `pysam`, `requests`, `tqdm`, `platformdirs`. Optional: `lmdb` for faster gene loading on large workloads (`pip install seqmat[lmdb]`).
224
+ Python ≥ 3.10. Core deps: `numpy`, `pandas`, `pyarrow`, `pysam`, `platformdirs`.
197
225
 
198
226
  ## A note on indexing
199
227
 
200
228
  `SeqMat` defaults to 1-based indices to match genomic conventions (UCSC, GenBank). If you'd rather work in 0-based offsets — e.g. for a comparison with `bytearray` or `Bio.Seq` — pass `indices=np.arange(len(seq))` at construction.
201
229
 
230
+ ## Roadmap
231
+
232
+ [ROADMAP.md](https://github.com/nicolasalynn/seqmat/blob/main/ROADMAP.md) — what's coming, what isn't, and why. The headline themes: VCF + per-patient `Patient` / `Cohort` objects with lazy region-scoped variant application, reference-build-aware coordinate conversion, and splicing-impact integration.
233
+
202
234
  ## Contributing
203
235
 
204
236
  PRs welcome. Run the test suite with `pytest tests/`. Comparative benchmarks are under `benchmarks/`.
205
237
 
206
238
  ## License
207
239
 
208
- MIT — see [LICENSE](LICENSE).
240
+ MIT — see [LICENSE](https://github.com/nicolasalynn/seqmat/blob/main/LICENSE).
209
241
 
210
242
  ## Citation
211
243
 
@@ -33,16 +33,16 @@ def mutation_examples():
33
33
  print(f"Original: {seq.seq}")
34
34
 
35
35
  # Single nucleotide polymorphism
36
- seq.apply_mutations((5, "T", "A"))
37
- print(f"After SNP (T->A at pos 5): {seq.seq}")
36
+ seq.apply_mutations((5, "A", "T"))
37
+ print(f"After SNP (A->T at pos 5): {seq.seq}")
38
38
 
39
39
  # Insertion
40
40
  seq.apply_mutations((8, "-", "GGG"))
41
41
  print(f"After insertion (GGG at pos 8): {seq.seq}")
42
42
 
43
43
  # Deletion
44
- seq.apply_mutations((3, "GA", "-"))
45
- print(f"After deletion (GA at pos 3): {seq.seq}")
44
+ seq.apply_mutations((3, "CG", "-"))
45
+ print(f"After deletion (CG at pos 3-4): {seq.seq}")
46
46
 
47
47
  print(f"Total mutations applied: {len(seq.mutations)}")
48
48
  print(f"Modified positions: {sorted(seq.mutated_positions)}")
@@ -56,7 +56,7 @@ def sequence_transformations():
56
56
  print(f"Original: {seq.seq}")
57
57
 
58
58
  # Complement
59
- comp = seq.complement()
59
+ comp = seq.complement(copy=True) # default is in place!
60
60
  print(f"Complement: {comp.seq}")
61
61
 
62
62
  # Reverse complement
@@ -113,7 +113,7 @@ def advanced_mutations():
113
113
  mutations = [
114
114
  (2, "T", "A"), # SNP
115
115
  (6, "-", "AAA"), # Insertion
116
- (10, "CGA", "-"), # Deletion
116
+ (11, "CGA", "-"), # Deletion (positions 11-13)
117
117
  (14, "TC", "GG") # Complex substitution
118
118
  ]
119
119
 
@@ -140,7 +140,7 @@ def export_operations():
140
140
  print("=== Export Operations ===")
141
141
 
142
142
  seq = SeqMat("ATCGATCGATCG", name="export_demo")
143
- seq.apply_mutations([(5, "T", "A"), (8, "-", "GG")])
143
+ seq.apply_mutations([(5, "A", "T"), (8, "-", "GG")])
144
144
 
145
145
  # Export as FASTA
146
146
  fasta = seq.to_fasta(wrap=40)
@@ -6,7 +6,6 @@ This script demonstrates the new data inspection utilities in SeqMat.
6
6
  """
7
7
 
8
8
  from seqmat import (
9
- list_supported_organisms,
10
9
  list_available_organisms,
11
10
  get_organism_info,
12
11
  list_gene_biotypes,
@@ -21,10 +20,6 @@ def basic_organism_info():
21
20
  """Demonstrate basic organism information retrieval"""
22
21
  print("=== Basic Organism Information ===")
23
22
 
24
- # Check what organisms are supported
25
- supported = list_supported_organisms()
26
- print(f"Supported organisms: {supported}")
27
-
28
23
  # Check what's actually configured
29
24
  available = list_available_organisms()
30
25
  print(f"Configured organisms: {available}")
@@ -76,12 +71,6 @@ def explore_organism_data():
76
71
  percentage = (count / total_genes) * 100
77
72
  print(f" {biotype}: {count:,} genes ({percentage:.1f}%)")
78
73
 
79
- # Show chromosome data
80
- if "chromosomes" in data_avail:
81
- chroms = data_avail["chromosomes"]
82
- print(f"✅ Chromosomes: {len(chroms)} available")
83
- print(f" Available: {', '.join(sorted(chroms)[:10])}{'...' if len(chroms) > 10 else ''}")
84
-
85
74
  print()
86
75
 
87
76
  def gene_exploration_examples():
@@ -179,10 +168,7 @@ def data_exploration_workflow():
179
168
  print("=== Complete Data Exploration Workflow ===")
180
169
 
181
170
  print("Step 1: Check organism support")
182
- supported = list_supported_organisms()
183
171
  available = list_available_organisms()
184
-
185
- print(f" Supported: {supported}")
186
172
  print(f" Configured: {available}")
187
173
 
188
174
  if not available:
@@ -1,13 +1,14 @@
1
1
  [build-system]
2
- requires = ["setuptools>=68", "wheel"]
2
+ requires = ["setuptools>=77"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "seqmat"
7
- version = "1.5.1"
7
+ version = "1.6.0"
8
8
  description = "Fast, vectorized genomic sequences with first-class mutation tracking."
9
9
  readme = "README.md"
10
- license = { file = "LICENSE" }
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
11
12
  requires-python = ">=3.10"
12
13
  authors = [{ name = "Nicolas Lynn Vila", email = "nicolasalynn@gmail.com" }]
13
14
  keywords = [
@@ -24,25 +25,22 @@ classifiers = [
24
25
  "Development Status :: 5 - Production/Stable",
25
26
  "Intended Audience :: Science/Research",
26
27
  "Topic :: Scientific/Engineering :: Bio-Informatics",
27
- "License :: OSI Approved :: MIT License",
28
28
  "Programming Language :: Python :: 3",
29
29
  "Programming Language :: Python :: 3.10",
30
30
  "Programming Language :: Python :: 3.11",
31
31
  "Programming Language :: Python :: 3.12",
32
+ "Programming Language :: Python :: 3.13",
32
33
  "Operating System :: OS Independent",
33
34
  ]
34
35
  dependencies = [
35
36
  "numpy>=1.20.0,<3",
36
- "pandas>=2.2.0,<3",
37
- "pyarrow>=15.0.0",
37
+ "pandas>=2.2.0,<4",
38
+ "pyarrow>=15.0.0", # SeqMat.save_seqmat / read_seqmat (parquet)
38
39
  "pysam>=0.19.0",
39
- "requests>=2.26.0",
40
- "tqdm>=4.62.0",
41
40
  "platformdirs>=3.0.0",
42
41
  ]
43
42
 
44
43
  [project.optional-dependencies]
45
- lmdb = ["lmdb>=1.4.0"]
46
44
  dev = [
47
45
  "pytest>=6.0",
48
46
  "pytest-cov>=2.0",
@@ -65,8 +63,6 @@ seqmat-setup = "seqmat.cli:main" # legacy alias
65
63
  include = ["seqmat*"]
66
64
  exclude = ["tests*", "examples*", "scripts*", "docs*"]
67
65
 
68
- [tool.setuptools.package-data]
69
- seqmat = ["*.json"]
70
66
 
71
67
  [tool.pytest.ini_options]
72
68
  testpaths = ["tests"]
@@ -0,0 +1,6 @@
1
+ # NumPy 2 and pandas 2.x and 3.x supported; pyarrow>=15 works with NumPy 2 (gtfparse removed)
2
+ numpy>=1.20.0,<3
3
+ pandas>=2.2.0,<4
4
+ pyarrow>=15.0.0
5
+ pysam>=0.19.0
6
+ platformdirs>=3.0.0