seqmat 1.4.0__tar.gz → 1.5.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.
Files changed (43) hide show
  1. seqmat-1.5.1/PKG-INFO +278 -0
  2. seqmat-1.5.1/README.md +218 -0
  3. seqmat-1.5.1/pyproject.toml +74 -0
  4. seqmat-1.5.1/seqmat/__init__.py +75 -0
  5. seqmat-1.5.1/seqmat/_io.py +34 -0
  6. seqmat-1.5.1/seqmat/conservation.py +65 -0
  7. seqmat-1.5.1/seqmat/data_setup.py +189 -0
  8. seqmat-1.5.1/seqmat/discovery.py +304 -0
  9. seqmat-1.5.1/seqmat/download.py +228 -0
  10. seqmat-1.5.1/seqmat/errors.py +35 -0
  11. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat/gene.py +57 -48
  12. seqmat-1.5.1/seqmat/gtf.py +387 -0
  13. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat/lmdb_store.py +10 -7
  14. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat/seqmat.py +193 -91
  15. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat/transcript.py +4 -1
  16. seqmat-1.5.1/seqmat/utils.py +169 -0
  17. seqmat-1.5.1/seqmat.egg-info/PKG-INFO +278 -0
  18. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat.egg-info/SOURCES.txt +8 -1
  19. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat.egg-info/requires.txt +3 -3
  20. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat.egg-info/top_level.txt +0 -1
  21. {seqmat-1.4.0 → seqmat-1.5.1}/tests/test_gene.py +27 -3
  22. {seqmat-1.4.0 → seqmat-1.5.1}/tests/test_seqmat.py +31 -0
  23. seqmat-1.4.0/PKG-INFO +0 -771
  24. seqmat-1.4.0/README.md +0 -726
  25. seqmat-1.4.0/seqmat/__init__.py +0 -63
  26. seqmat-1.4.0/seqmat/utils.py +0 -1604
  27. seqmat-1.4.0/seqmat.egg-info/PKG-INFO +0 -771
  28. seqmat-1.4.0/setup.py +0 -59
  29. {seqmat-1.4.0 → seqmat-1.5.1}/LICENSE +0 -0
  30. {seqmat-1.4.0 → seqmat-1.5.1}/MANIFEST.in +0 -0
  31. {seqmat-1.4.0 → seqmat-1.5.1}/examples/basic_usage.py +0 -0
  32. {seqmat-1.4.0 → seqmat-1.5.1}/examples/data_inspection.py +0 -0
  33. {seqmat-1.4.0 → seqmat-1.5.1}/requirements.txt +0 -0
  34. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat/cli.py +0 -0
  35. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat/config.py +0 -0
  36. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat/locator.py +0 -0
  37. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat/sqlite_store.py +0 -0
  38. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat.egg-info/dependency_links.txt +0 -0
  39. {seqmat-1.4.0 → seqmat-1.5.1}/seqmat.egg-info/entry_points.txt +0 -0
  40. {seqmat-1.4.0 → seqmat-1.5.1}/setup.cfg +0 -0
  41. {seqmat-1.4.0 → seqmat-1.5.1}/tests/__init__.py +0 -0
  42. {seqmat-1.4.0 → seqmat-1.5.1}/tests/bench_gene_creation.py +0 -0
  43. {seqmat-1.4.0 → seqmat-1.5.1}/tests/test_locator.py +0 -0
seqmat-1.5.1/PKG-INFO ADDED
@@ -0,0 +1,278 @@
1
+ Metadata-Version: 2.4
2
+ Name: seqmat
3
+ Version: 1.5.1
4
+ Summary: Fast, vectorized genomic sequences with first-class mutation tracking.
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.
27
+ Project-URL: Homepage, https://github.com/nicolasalynn/seqmat
28
+ Project-URL: Repository, https://github.com/nicolasalynn/seqmat
29
+ Project-URL: Issues, https://github.com/nicolasalynn/seqmat/issues
30
+ Project-URL: Changelog, https://github.com/nicolasalynn/seqmat/blob/main/CHANGELOG.md
31
+ Keywords: bioinformatics,genomics,sequence,mutation,splicing,transcript,hg38,mm39
32
+ Classifier: Development Status :: 5 - Production/Stable
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
35
+ Classifier: License :: OSI Approved :: MIT License
36
+ Classifier: Programming Language :: Python :: 3
37
+ Classifier: Programming Language :: Python :: 3.10
38
+ Classifier: Programming Language :: Python :: 3.11
39
+ Classifier: Programming Language :: Python :: 3.12
40
+ Classifier: Operating System :: OS Independent
41
+ Requires-Python: >=3.10
42
+ Description-Content-Type: text/markdown
43
+ License-File: LICENSE
44
+ Requires-Dist: numpy<3,>=1.20.0
45
+ Requires-Dist: pandas<3,>=2.2.0
46
+ Requires-Dist: pyarrow>=15.0.0
47
+ Requires-Dist: pysam>=0.19.0
48
+ Requires-Dist: requests>=2.26.0
49
+ Requires-Dist: tqdm>=4.62.0
50
+ Requires-Dist: platformdirs>=3.0.0
51
+ Provides-Extra: lmdb
52
+ Requires-Dist: lmdb>=1.4.0; extra == "lmdb"
53
+ Provides-Extra: dev
54
+ Requires-Dist: pytest>=6.0; extra == "dev"
55
+ Requires-Dist: pytest-cov>=2.0; extra == "dev"
56
+ Requires-Dist: build>=1.0; extra == "dev"
57
+ Requires-Dist: twine>=4.0; extra == "dev"
58
+ Requires-Dist: pdoc>=14.0; extra == "dev"
59
+ Dynamic: license-file
60
+
61
+ <p align="center">
62
+ <img src="docs/assets/logo.svg" alt="SeqMat" width="540">
63
+ </p>
64
+
65
+ [![PyPI](https://img.shields.io/pypi/v/seqmat.svg)](https://pypi.org/project/seqmat/)
66
+ [![Python](https://img.shields.io/pypi/pyversions/seqmat.svg)](https://pypi.org/project/seqmat/)
67
+ [![Tests](https://github.com/nicolasalynn/seqmat/actions/workflows/test.yml/badge.svg)](https://github.com/nicolasalynn/seqmat/actions/workflows/test.yml)
68
+ [![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)
70
+ [![Downloads](https://static.pepy.tech/badge/seqmat/month)](https://pepy.tech/project/seqmat)
71
+
72
+ A Python library for genomic sequences that keeps genomic coordinates and mutation history attached to the bases.
73
+
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.
75
+
76
+ ```python
77
+ from seqmat import Gene, SeqMat
78
+
79
+ # What gene is at chr12:25,245,350?
80
+ Gene.from_position("12", 25_245_350) # [Gene(KRAS)]
81
+
82
+ # Load it, assemble the mature mRNA, translate.
83
+ kras = Gene.from_file("KRAS")
84
+ tx = kras.transcript()
85
+ tx.generate_mature_mrna()
86
+ tx.generate_protein()
87
+
88
+ # Apply mutations; history is kept on the SeqMat.
89
+ seq = SeqMat("ATCGATCGATCG")
90
+ seq.apply_mutations([(3, "C", "G"), (6, "-", "AAA"), (10, "TC", "-")])
91
+ seq.mutations
92
+ ```
93
+
94
+ A worked example, end to end: [KRAS G12D — coordinate to protein](examples/kras_g12d_analysis.ipynb).
95
+
96
+ ---
97
+
98
+ ## Install
99
+
100
+ ```bash
101
+ pip install seqmat
102
+ seqmat setup # one-time: downloads hg38 genes.db + FASTA (~4 GB)
103
+ ```
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`.
106
+
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
+
109
+ ## Quick start
110
+
111
+ ### Sequence operations
112
+
113
+ ```python
114
+ from seqmat import SeqMat
115
+ import numpy as np
116
+
117
+ seq = SeqMat("ATCGATCGATCG", indices=np.arange(1000, 1012))
118
+ seq[1005] # base at genomic position 1005
119
+ seq[1003:1008].seq # "GATCG"
120
+ seq.reverse_complement() # in place
121
+ seq.remove_regions([(1003, 1005), (1008, 1009)]) # splice out introns
122
+ ```
123
+
124
+ ### Genes and transcripts
125
+
126
+ ```python
127
+ from seqmat import Gene
128
+
129
+ kras = Gene.from_file("KRAS")
130
+ kras # Gene: KRAS, ID: ENSG00000133703, Chr: 12, Transcripts: 14
131
+
132
+ tx = kras.transcript() # primary transcript
133
+ tx.generate_mature_mrna()
134
+ tx.generate_protein()
135
+ tx.protein[:20] # 'MTEYKLVVVGAGGVGKSALT'
136
+
137
+ acceptors, donors = kras.splice_sites() # Counter across all transcripts
138
+ ```
139
+
140
+ ### Position → gene (added in 1.4.0)
141
+
142
+ ```python
143
+ from seqmat import Gene, gene_names_at_position
144
+
145
+ Gene.from_position("12", 25_245_350) # [Gene(KRAS)] — point query
146
+ Gene.from_position("chr12", (25_200_000, 25_300_000)) # all overlapping genes in a range
147
+ gene_names_at_position("X", 100_000) # names only (no BLOB load)
148
+ ```
149
+
150
+ Backed by a per-chromosome sorted NumPy index persisted as a sidecar `gene_locations.npz` next to `genes.db`. Built lazily on first call; fresh `seqmat setup` builds also emit it.
151
+
152
+ ### Loading from FASTA
153
+
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
157
+ ```
158
+
159
+ ## Performance
160
+
161
+ Measured on an M-series Mac, hg38, one core, warm caches. Reproducible via the scripts in `benchmarks/`.
162
+
163
+ ### Headline numbers
164
+
165
+ | Operation | Time |
166
+ | -------------------------------------------------- | -------: |
167
+ | `gene_names_at_position(chrm, pos)` | 2.5 µs |
168
+ | KRAS mature mRNA assembly (splice + translate) | 0.2 ms |
169
+ | 1,000-SNP batch on 45 kb sequence (with history) | 0.5 ms |
170
+ | `Gene.from_file("KRAS")` (SQLite + unpickle) | 24 ms |
171
+ | `Gene.from_position(chrm, pos)` end-to-end | 24 ms |
172
+
173
+ ### Position → gene
174
+
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`.
176
+
177
+ Per-query (one coordinate, one answer, in a loop — the `Gene.from_position` pattern):
178
+
179
+ | Implementation | Per query |
180
+ | --------------------------------------- | --------: |
181
+ | SeqMat (locator) | 2.5 µs |
182
+ | Python `dict` + `bisect` | 21 µs |
183
+ | pandas (`groupby` chrm + boolean mask) | 79 µs |
184
+ | PyRanges constructed per call | 2.0 ms |
185
+
186
+ Batched (the whole query set in one call — PyRanges' native idiom):
187
+
188
+ | Implementation | Per query |
189
+ | ----------------------------- | --------: |
190
+ | PyRanges `.join` | 2.07 µs |
191
+ | SeqMat (serial loop) | 2.59 µs |
192
+
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.
194
+
195
+ ### Sequence operations vs Biopython
196
+
197
+ 50 kb sequence, 1,000 SNPs / 10 introns; 1 Mb reverse-complement. Reproduce with `python benchmarks/bench_sequence_ops.py`.
198
+
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 |
205
+
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.
207
+
208
+ ### Implementation notes
209
+
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).
211
+
212
+ ## Command-line interface
213
+
214
+ ```bash
215
+ seqmat setup [--organism hg38|mm39] [--path PATH] [--build-from-sources]
216
+ seqmat summary
217
+ seqmat info --organism hg38
218
+ seqmat search --organism hg38 --query KRAS
219
+ seqmat list --organism hg38 --biotype protein_coding --limit 20
220
+ seqmat count --organism hg38
221
+ ```
222
+
223
+ ## Data setup
224
+
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:
226
+
227
+ ```bash
228
+ seqmat setup --organism hg38 --build-from-sources
229
+ ```
230
+
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).
232
+
233
+ ## API at a glance
234
+
235
+ ```python
236
+ from seqmat import (
237
+ SeqMat, # coordinate-tracked sequence with mutation history
238
+ Gene, Transcript, # gene/transcript model
239
+ gene_names_at_position, # name-only positional lookup
240
+ build_location_index, # force-rebuild the position index
241
+ setup_genomics_data, # programmatic setup
242
+ search_genes, available_genes, # discovery helpers
243
+ )
244
+ ```
245
+
246
+ Key classes:
247
+
248
+ - `SeqMat` — `apply_mutations`, `clone`, `complement`, `reverse_complement`, `remove_regions`, `from_fasta_file`
249
+ - `Gene` — `from_file`, `from_position`, `get`, `transcript`, `splice_sites`, `primary_transcript`
250
+ - `Transcript` — `generate_pre_mrna`, `generate_mature_mrna`, `generate_protein`, `exons`, `introns`
251
+
252
+ Full API reference (auto-generated from docstrings): [nicolasalynn.github.io/seqmat](https://nicolasalynn.github.io/seqmat/seqmat.html).
253
+
254
+ ## Requirements
255
+
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]`).
257
+
258
+ ## A note on indexing
259
+
260
+ `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
+
262
+ ## Contributing
263
+
264
+ PRs welcome. Run the test suite with `pytest tests/`. Comparative benchmarks are under `benchmarks/`.
265
+
266
+ ## License
267
+
268
+ MIT — see [LICENSE](LICENSE).
269
+
270
+ ## Citation
271
+
272
+ If SeqMat is useful in your research:
273
+
274
+ ```
275
+ Lynn Vila, N. (2025). SeqMat: a genomic sequence library with
276
+ coordinate tracking and mutation history.
277
+ https://github.com/nicolasalynn/seqmat
278
+ ```
seqmat-1.5.1/README.md ADDED
@@ -0,0 +1,218 @@
1
+ <p align="center">
2
+ <img src="docs/assets/logo.svg" alt="SeqMat" width="540">
3
+ </p>
4
+
5
+ [![PyPI](https://img.shields.io/pypi/v/seqmat.svg)](https://pypi.org/project/seqmat/)
6
+ [![Python](https://img.shields.io/pypi/pyversions/seqmat.svg)](https://pypi.org/project/seqmat/)
7
+ [![Tests](https://github.com/nicolasalynn/seqmat/actions/workflows/test.yml/badge.svg)](https://github.com/nicolasalynn/seqmat/actions/workflows/test.yml)
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)
10
+ [![Downloads](https://static.pepy.tech/badge/seqmat/month)](https://pepy.tech/project/seqmat)
11
+
12
+ A Python library for genomic sequences that keeps genomic coordinates and mutation history attached to the bases.
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.
15
+
16
+ ```python
17
+ from seqmat import Gene, SeqMat
18
+
19
+ # What gene is at chr12:25,245,350?
20
+ Gene.from_position("12", 25_245_350) # [Gene(KRAS)]
21
+
22
+ # Load it, assemble the mature mRNA, translate.
23
+ kras = Gene.from_file("KRAS")
24
+ tx = kras.transcript()
25
+ tx.generate_mature_mrna()
26
+ tx.generate_protein()
27
+
28
+ # Apply mutations; history is kept on the SeqMat.
29
+ seq = SeqMat("ATCGATCGATCG")
30
+ seq.apply_mutations([(3, "C", "G"), (6, "-", "AAA"), (10, "TC", "-")])
31
+ seq.mutations
32
+ ```
33
+
34
+ A worked example, end to end: [KRAS G12D — coordinate to protein](examples/kras_g12d_analysis.ipynb).
35
+
36
+ ---
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ pip install seqmat
42
+ seqmat setup # one-time: downloads hg38 genes.db + FASTA (~4 GB)
43
+ ```
44
+
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`.
46
+
47
+ 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
+
49
+ ## Quick start
50
+
51
+ ### Sequence operations
52
+
53
+ ```python
54
+ from seqmat import SeqMat
55
+ import numpy as np
56
+
57
+ seq = SeqMat("ATCGATCGATCG", indices=np.arange(1000, 1012))
58
+ seq[1005] # base at genomic position 1005
59
+ seq[1003:1008].seq # "GATCG"
60
+ seq.reverse_complement() # in place
61
+ seq.remove_regions([(1003, 1005), (1008, 1009)]) # splice out introns
62
+ ```
63
+
64
+ ### Genes and transcripts
65
+
66
+ ```python
67
+ from seqmat import Gene
68
+
69
+ kras = Gene.from_file("KRAS")
70
+ kras # Gene: KRAS, ID: ENSG00000133703, Chr: 12, Transcripts: 14
71
+
72
+ tx = kras.transcript() # primary transcript
73
+ tx.generate_mature_mrna()
74
+ tx.generate_protein()
75
+ tx.protein[:20] # 'MTEYKLVVVGAGGVGKSALT'
76
+
77
+ acceptors, donors = kras.splice_sites() # Counter across all transcripts
78
+ ```
79
+
80
+ ### Position → gene (added in 1.4.0)
81
+
82
+ ```python
83
+ from seqmat import Gene, gene_names_at_position
84
+
85
+ Gene.from_position("12", 25_245_350) # [Gene(KRAS)] — point query
86
+ Gene.from_position("chr12", (25_200_000, 25_300_000)) # all overlapping genes in a range
87
+ gene_names_at_position("X", 100_000) # names only (no BLOB load)
88
+ ```
89
+
90
+ Backed by a per-chromosome sorted NumPy index persisted as a sidecar `gene_locations.npz` next to `genes.db`. Built lazily on first call; fresh `seqmat setup` builds also emit it.
91
+
92
+ ### Loading from FASTA
93
+
94
+ ```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
97
+ ```
98
+
99
+ ## Performance
100
+
101
+ Measured on an M-series Mac, hg38, one core, warm caches. Reproducible via the scripts in `benchmarks/`.
102
+
103
+ ### Headline numbers
104
+
105
+ | Operation | Time |
106
+ | -------------------------------------------------- | -------: |
107
+ | `gene_names_at_position(chrm, pos)` | 2.5 µs |
108
+ | KRAS mature mRNA assembly (splice + translate) | 0.2 ms |
109
+ | 1,000-SNP batch on 45 kb sequence (with history) | 0.5 ms |
110
+ | `Gene.from_file("KRAS")` (SQLite + unpickle) | 24 ms |
111
+ | `Gene.from_position(chrm, pos)` end-to-end | 24 ms |
112
+
113
+ ### Position → gene
114
+
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`.
116
+
117
+ Per-query (one coordinate, one answer, in a loop — the `Gene.from_position` pattern):
118
+
119
+ | Implementation | Per query |
120
+ | --------------------------------------- | --------: |
121
+ | SeqMat (locator) | 2.5 µs |
122
+ | Python `dict` + `bisect` | 21 µs |
123
+ | pandas (`groupby` chrm + boolean mask) | 79 µs |
124
+ | PyRanges constructed per call | 2.0 ms |
125
+
126
+ Batched (the whole query set in one call — PyRanges' native idiom):
127
+
128
+ | Implementation | Per query |
129
+ | ----------------------------- | --------: |
130
+ | PyRanges `.join` | 2.07 µs |
131
+ | SeqMat (serial loop) | 2.59 µs |
132
+
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.
134
+
135
+ ### Sequence operations vs Biopython
136
+
137
+ 50 kb sequence, 1,000 SNPs / 10 introns; 1 Mb reverse-complement. Reproduce with `python benchmarks/bench_sequence_ops.py`.
138
+
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 |
145
+
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.
147
+
148
+ ### Implementation notes
149
+
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).
151
+
152
+ ## Command-line interface
153
+
154
+ ```bash
155
+ seqmat setup [--organism hg38|mm39] [--path PATH] [--build-from-sources]
156
+ seqmat summary
157
+ seqmat info --organism hg38
158
+ seqmat search --organism hg38 --query KRAS
159
+ seqmat list --organism hg38 --biotype protein_coding --limit 20
160
+ seqmat count --organism hg38
161
+ ```
162
+
163
+ ## Data setup
164
+
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:
166
+
167
+ ```bash
168
+ seqmat setup --organism hg38 --build-from-sources
169
+ ```
170
+
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).
172
+
173
+ ## API at a glance
174
+
175
+ ```python
176
+ from seqmat import (
177
+ SeqMat, # coordinate-tracked sequence with mutation history
178
+ Gene, Transcript, # gene/transcript model
179
+ gene_names_at_position, # name-only positional lookup
180
+ build_location_index, # force-rebuild the position index
181
+ setup_genomics_data, # programmatic setup
182
+ search_genes, available_genes, # discovery helpers
183
+ )
184
+ ```
185
+
186
+ Key classes:
187
+
188
+ - `SeqMat` — `apply_mutations`, `clone`, `complement`, `reverse_complement`, `remove_regions`, `from_fasta_file`
189
+ - `Gene` — `from_file`, `from_position`, `get`, `transcript`, `splice_sites`, `primary_transcript`
190
+ - `Transcript` — `generate_pre_mrna`, `generate_mature_mrna`, `generate_protein`, `exons`, `introns`
191
+
192
+ Full API reference (auto-generated from docstrings): [nicolasalynn.github.io/seqmat](https://nicolasalynn.github.io/seqmat/seqmat.html).
193
+
194
+ ## Requirements
195
+
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]`).
197
+
198
+ ## A note on indexing
199
+
200
+ `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
+
202
+ ## Contributing
203
+
204
+ PRs welcome. Run the test suite with `pytest tests/`. Comparative benchmarks are under `benchmarks/`.
205
+
206
+ ## License
207
+
208
+ MIT — see [LICENSE](LICENSE).
209
+
210
+ ## Citation
211
+
212
+ If SeqMat is useful in your research:
213
+
214
+ ```
215
+ Lynn Vila, N. (2025). SeqMat: a genomic sequence library with
216
+ coordinate tracking and mutation history.
217
+ https://github.com/nicolasalynn/seqmat
218
+ ```
@@ -0,0 +1,74 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "seqmat"
7
+ version = "1.5.1"
8
+ description = "Fast, vectorized genomic sequences with first-class mutation tracking."
9
+ readme = "README.md"
10
+ license = { file = "LICENSE" }
11
+ requires-python = ">=3.10"
12
+ authors = [{ name = "Nicolas Lynn Vila", email = "nicolasalynn@gmail.com" }]
13
+ keywords = [
14
+ "bioinformatics",
15
+ "genomics",
16
+ "sequence",
17
+ "mutation",
18
+ "splicing",
19
+ "transcript",
20
+ "hg38",
21
+ "mm39",
22
+ ]
23
+ classifiers = [
24
+ "Development Status :: 5 - Production/Stable",
25
+ "Intended Audience :: Science/Research",
26
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
27
+ "License :: OSI Approved :: MIT License",
28
+ "Programming Language :: Python :: 3",
29
+ "Programming Language :: Python :: 3.10",
30
+ "Programming Language :: Python :: 3.11",
31
+ "Programming Language :: Python :: 3.12",
32
+ "Operating System :: OS Independent",
33
+ ]
34
+ dependencies = [
35
+ "numpy>=1.20.0,<3",
36
+ "pandas>=2.2.0,<3",
37
+ "pyarrow>=15.0.0",
38
+ "pysam>=0.19.0",
39
+ "requests>=2.26.0",
40
+ "tqdm>=4.62.0",
41
+ "platformdirs>=3.0.0",
42
+ ]
43
+
44
+ [project.optional-dependencies]
45
+ lmdb = ["lmdb>=1.4.0"]
46
+ dev = [
47
+ "pytest>=6.0",
48
+ "pytest-cov>=2.0",
49
+ "build>=1.0",
50
+ "twine>=4.0",
51
+ "pdoc>=14.0",
52
+ ]
53
+
54
+ [project.urls]
55
+ Homepage = "https://github.com/nicolasalynn/seqmat"
56
+ Repository = "https://github.com/nicolasalynn/seqmat"
57
+ Issues = "https://github.com/nicolasalynn/seqmat/issues"
58
+ Changelog = "https://github.com/nicolasalynn/seqmat/blob/main/CHANGELOG.md"
59
+
60
+ [project.scripts]
61
+ seqmat = "seqmat.cli:main"
62
+ seqmat-setup = "seqmat.cli:main" # legacy alias
63
+
64
+ [tool.setuptools.packages.find]
65
+ include = ["seqmat*"]
66
+ exclude = ["tests*", "examples*", "scripts*", "docs*"]
67
+
68
+ [tool.setuptools.package-data]
69
+ seqmat = ["*.json"]
70
+
71
+ [tool.pytest.ini_options]
72
+ testpaths = ["tests"]
73
+ python_files = ["test_*.py"]
74
+ addopts = "-ra -q"
@@ -0,0 +1,75 @@
1
+ """SeqMat — fast, vectorized genomic sequences with first-class mutation tracking."""
2
+
3
+ __version__ = "1.5.1"
4
+ __author__ = "Nicolas Lynn Vila"
5
+ __email__ = "nicolasalynn@gmail.com"
6
+
7
+ # Core classes
8
+ from .seqmat import SeqMat
9
+ from .gene import Gene
10
+ from .transcript import Transcript
11
+
12
+ # Config / paths
13
+ from .config import (
14
+ get_config_dir,
15
+ get_config_file,
16
+ get_data_base,
17
+ get_data_dir,
18
+ get_default_organism,
19
+ load_config,
20
+ save_config,
21
+ )
22
+
23
+ # Optional LMDB backend
24
+ from .lmdb_store import build_lmdb
25
+
26
+ # Position → gene lookup
27
+ from .locator import build_location_index, gene_names_at_position
28
+
29
+ # Data setup
30
+ from .data_setup import set_fasta_path, setup_genomics_data
31
+
32
+ # Discovery
33
+ from .discovery import (
34
+ available_genes,
35
+ count_genes,
36
+ data_summary,
37
+ get_all_genes,
38
+ get_gene_list,
39
+ get_organism_info,
40
+ list_available_organisms,
41
+ list_gene_biotypes,
42
+ list_supported_organisms,
43
+ print_data_summary,
44
+ search_genes,
45
+ )
46
+
47
+ # Errors
48
+ from .errors import (
49
+ DataUnavailableError,
50
+ GeneNotFoundError,
51
+ OrganismNotConfiguredError,
52
+ PrebuiltDataUnavailableError,
53
+ SeqMatError,
54
+ )
55
+
56
+ __all__ = [
57
+ # Core
58
+ "SeqMat", "Gene", "Transcript",
59
+ # Config / paths
60
+ "get_default_organism", "get_data_dir", "get_config_dir",
61
+ "get_config_file", "get_data_base", "load_config", "save_config",
62
+ # Setup
63
+ "setup_genomics_data", "set_fasta_path",
64
+ # Discovery
65
+ "list_available_organisms", "list_supported_organisms", "get_organism_info",
66
+ "list_gene_biotypes", "count_genes", "get_gene_list", "get_all_genes",
67
+ "data_summary", "print_data_summary", "search_genes", "available_genes",
68
+ # Position lookup
69
+ "gene_names_at_position", "build_location_index",
70
+ # LMDB
71
+ "build_lmdb",
72
+ # Errors
73
+ "SeqMatError", "GeneNotFoundError", "OrganismNotConfiguredError",
74
+ "DataUnavailableError", "PrebuiltDataUnavailableError",
75
+ ]
@@ -0,0 +1,34 @@
1
+ """File I/O helpers: pickle and JSON."""
2
+ from __future__ import annotations
3
+
4
+ import json
5
+ import pickle
6
+ from pathlib import Path
7
+ from typing import Any, Union
8
+
9
+
10
+ def dump_pickle(path: Union[str, Path], data: Any) -> None:
11
+ """Save data to a pickle file."""
12
+ with open(path, "wb") as f:
13
+ pickle.dump(data, f)
14
+
15
+
16
+ def unload_pickle(path: Union[str, Path]) -> Any:
17
+ """Load data from a pickle file."""
18
+ with open(path, "rb") as f:
19
+ return pickle.load(f)
20
+
21
+
22
+ def dump_json(path: Union[str, Path], data: Any) -> None:
23
+ """Save data to a JSON file (indent=2)."""
24
+ with open(path, "w") as f:
25
+ json.dump(data, f, indent=2)
26
+
27
+
28
+ def unload_json(path: Union[str, Path]) -> Any:
29
+ """Load data from a JSON file."""
30
+ with open(path, "r") as f:
31
+ return json.load(f)
32
+
33
+
34
+ __all__ = ["dump_pickle", "unload_pickle", "dump_json", "unload_json"]