seqmat 1.3.1__tar.gz → 1.5.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 (43) hide show
  1. seqmat-1.5.0/PKG-INFO +225 -0
  2. seqmat-1.5.0/README.md +166 -0
  3. seqmat-1.5.0/pyproject.toml +73 -0
  4. seqmat-1.5.0/seqmat/__init__.py +75 -0
  5. seqmat-1.5.0/seqmat/_io.py +34 -0
  6. seqmat-1.5.0/seqmat/conservation.py +65 -0
  7. seqmat-1.5.0/seqmat/data_setup.py +189 -0
  8. seqmat-1.5.0/seqmat/discovery.py +304 -0
  9. seqmat-1.5.0/seqmat/download.py +228 -0
  10. seqmat-1.5.0/seqmat/errors.py +35 -0
  11. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat/gene.py +38 -7
  12. seqmat-1.5.0/seqmat/gtf.py +387 -0
  13. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat/lmdb_store.py +10 -7
  14. seqmat-1.5.0/seqmat/locator.py +235 -0
  15. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat/seqmat.py +2 -1
  16. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat/sqlite_store.py +3 -2
  17. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat/transcript.py +4 -1
  18. seqmat-1.5.0/seqmat/utils.py +169 -0
  19. seqmat-1.5.0/seqmat.egg-info/PKG-INFO +225 -0
  20. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat.egg-info/SOURCES.txt +10 -1
  21. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat.egg-info/requires.txt +2 -3
  22. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat.egg-info/top_level.txt +0 -1
  23. seqmat-1.5.0/tests/test_locator.py +108 -0
  24. seqmat-1.3.1/PKG-INFO +0 -771
  25. seqmat-1.3.1/README.md +0 -726
  26. seqmat-1.3.1/seqmat/__init__.py +0 -60
  27. seqmat-1.3.1/seqmat/utils.py +0 -1595
  28. seqmat-1.3.1/seqmat.egg-info/PKG-INFO +0 -771
  29. seqmat-1.3.1/setup.py +0 -59
  30. {seqmat-1.3.1 → seqmat-1.5.0}/LICENSE +0 -0
  31. {seqmat-1.3.1 → seqmat-1.5.0}/MANIFEST.in +0 -0
  32. {seqmat-1.3.1 → seqmat-1.5.0}/examples/basic_usage.py +0 -0
  33. {seqmat-1.3.1 → seqmat-1.5.0}/examples/data_inspection.py +0 -0
  34. {seqmat-1.3.1 → seqmat-1.5.0}/requirements.txt +0 -0
  35. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat/cli.py +0 -0
  36. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat/config.py +0 -0
  37. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat.egg-info/dependency_links.txt +0 -0
  38. {seqmat-1.3.1 → seqmat-1.5.0}/seqmat.egg-info/entry_points.txt +0 -0
  39. {seqmat-1.3.1 → seqmat-1.5.0}/setup.cfg +0 -0
  40. {seqmat-1.3.1 → seqmat-1.5.0}/tests/__init__.py +0 -0
  41. {seqmat-1.3.1 → seqmat-1.5.0}/tests/bench_gene_creation.py +0 -0
  42. {seqmat-1.3.1 → seqmat-1.5.0}/tests/test_gene.py +0 -0
  43. {seqmat-1.3.1 → seqmat-1.5.0}/tests/test_seqmat.py +0 -0
seqmat-1.5.0/PKG-INFO ADDED
@@ -0,0 +1,225 @@
1
+ Metadata-Version: 2.4
2
+ Name: seqmat
3
+ Version: 1.5.0
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
+ Dynamic: license-file
59
+
60
+ # SeqMat
61
+
62
+ [![PyPI](https://img.shields.io/pypi/v/seqmat.svg)](https://pypi.org/project/seqmat/)
63
+ [![Python](https://img.shields.io/pypi/pyversions/seqmat.svg)](https://pypi.org/project/seqmat/)
64
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
65
+ [![Downloads](https://static.pepy.tech/badge/seqmat/month)](https://pepy.tech/project/seqmat)
66
+
67
+ **Fast, vectorized genomic sequences with first-class mutation tracking.**
68
+
69
+ SeqMat treats a DNA sequence as a NumPy-backed matrix of (nucleotide, genomic position) — so slicing, mutation, complement, and splicing are all vectorized array operations. It ships with a compact gene/transcript model that loads from a single indexed SQLite file built from Ensembl annotations, plus a position → gene lookup that resolves overlapping genes in microseconds.
70
+
71
+ ```python
72
+ from seqmat import Gene, SeqMat
73
+
74
+ # What gene is at chr12:25,245,350?
75
+ Gene.from_position("12", 25_245_350) # [Gene(KRAS)]
76
+
77
+ # Load it, assemble the mature mRNA, translate.
78
+ kras = Gene.from_file("KRAS")
79
+ tx = kras.transcript()
80
+ tx.generate_mature_mrna() # 0.2 ms
81
+ tx.generate_protein()
82
+
83
+ # Mutate a sequence with full history and conflict detection.
84
+ seq = SeqMat("ATCGATCGATCG")
85
+ seq.apply_mutations([(3, "C", "G"), (6, "-", "AAA"), (10, "TC", "-")])
86
+ seq.mutations # [(SNP, 3, C, G), (INS, 6, -, AAA), (DEL, 10, TC, -)]
87
+ ```
88
+
89
+ ---
90
+
91
+ ## Install
92
+
93
+ ```bash
94
+ pip install seqmat
95
+ seqmat setup # one-time: downloads hg38 genes.db + FASTA (~4 GB)
96
+ ```
97
+
98
+ `seqmat setup` writes a small env block (`SEQMAT_DATA_DIR`, `SEQMAT_DEFAULT_ORGANISM`) to your shell rc so the data is found automatically next session. Mouse: `seqmat setup --organism mm39`. No config file needed.
99
+
100
+ > If you only want `SeqMat` for in-memory sequence work, you can skip `seqmat setup` entirely — `Gene` / `Transcript` are the only things that need the gene database.
101
+
102
+ ## Quick start
103
+
104
+ ### Sequence operations
105
+
106
+ ```python
107
+ from seqmat import SeqMat
108
+ import numpy as np
109
+
110
+ seq = SeqMat("ATCGATCGATCG", indices=np.arange(1000, 1012))
111
+ seq[1005] # base at genomic position 1005
112
+ seq[1003:1008].seq # "GATCG"
113
+ seq.reverse_complement() # in place
114
+ seq.remove_regions([(1003, 1005), (1008, 1009)]) # splice out introns
115
+ ```
116
+
117
+ ### Genes and transcripts
118
+
119
+ ```python
120
+ from seqmat import Gene
121
+
122
+ kras = Gene.from_file("KRAS")
123
+ kras # Gene: KRAS, ID: ENSG00000133703, Chr: 12, Transcripts: 14
124
+
125
+ tx = kras.transcript() # primary transcript
126
+ tx.generate_mature_mrna()
127
+ tx.generate_protein()
128
+ tx.protein[:20] # 'MTEYKLVVVGAGGVGKSALT'
129
+
130
+ acceptors, donors = kras.splice_sites() # Counter across all transcripts
131
+ ```
132
+
133
+ ### Position → gene (new in 1.4.0)
134
+
135
+ ```python
136
+ from seqmat import Gene, gene_names_at_position
137
+
138
+ Gene.from_position("12", 25_245_350) # [Gene(KRAS)] — point query
139
+ Gene.from_position("chr12", (25_200_000, 25_300_000)) # all overlapping genes in a range
140
+ gene_names_at_position("X", 100_000) # names only (no BLOB load) — ~17 us
141
+ ```
142
+
143
+ 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 for free.
144
+
145
+ ### Loading from FASTA
146
+
147
+ ```python
148
+ seq = SeqMat.from_fasta_file("chr12.fasta", "chr12", start=25398284, end=25398384)
149
+ seq.apply_mutations([(25398290, "G", "A")]) # G12D, the most famous KRAS variant
150
+ ```
151
+
152
+ ## Performance
153
+
154
+ Numbers from an M-series Mac on hg38 (one core, warm caches):
155
+
156
+ | Operation | Time |
157
+ | -------------------------------------- | -------: |
158
+ | `gene_names_at_position(chrm, pos)` | **17 µs** |
159
+ | `Gene.from_file("KRAS")` (SQLite + unpickle) | 24 ms |
160
+ | `Gene.from_position(chrm, pos)` end-to-end | 24 ms |
161
+ | KRAS mature mRNA assembly | 0.2 ms |
162
+ | 1,000-SNP batch on 4 kb sequence | 19 ms |
163
+
164
+ The hot paths use NumPy structured arrays, LUT-based complement, `np.searchsorted` on sorted starts, FASTA range-scoped reads, and copy-on-write `clone()`. See `seqmat/seqmat.py` and `seqmat/locator.py`.
165
+
166
+ ## Command-line interface
167
+
168
+ ```bash
169
+ seqmat setup [--organism hg38|mm39] [--path PATH] [--build-from-sources]
170
+ seqmat summary # what's installed
171
+ seqmat info --organism hg38
172
+ seqmat search --organism hg38 --query KRAS
173
+ seqmat list --organism hg38 --biotype protein_coding --limit 20
174
+ seqmat count --organism hg38
175
+ ```
176
+
177
+ ## Data setup
178
+
179
+ By default `seqmat setup` downloads prebuilt `genes.db` and FASTA from the SeqMat S3 bucket — no build step. To regenerate `genes.db` from a specific Ensembl release or custom GTF:
180
+
181
+ ```bash
182
+ seqmat setup --organism hg38 --build-from-sources
183
+ ```
184
+
185
+ For custom organisms, mirroring the prebuilt bucket, ephemeral environments (Docker / Run.ai), shared multi-user installs, and the full configuration system — see **[docs/SETUP.md](docs/SETUP.md)**.
186
+
187
+ ## API at a glance
188
+
189
+ ```python
190
+ from seqmat import (
191
+ SeqMat, # vectorized sequence with mutation tracking
192
+ Gene, Transcript, # gene/transcript model
193
+ gene_names_at_position, # fast name-only positional lookup
194
+ build_location_index, # force-rebuild the position index
195
+ setup_genomics_data, # programmatic setup
196
+ search_genes, available_genes, # discovery helpers
197
+ )
198
+ ```
199
+
200
+ Key classes:
201
+
202
+ - **`SeqMat`** — `apply_mutations`, `clone`, `complement`, `reverse_complement`, `remove_regions`, `from_fasta_file`
203
+ - **`Gene`** — `from_file`, `from_position`, `transcript`, `splice_sites`, `primary_transcript`
204
+ - **`Transcript`** — `generate_pre_mrna`, `generate_mature_mrna`, `generate_protein`, `exons`, `introns`
205
+
206
+ ## Requirements
207
+
208
+ Python ≥ 3.10. Core deps: `numpy`, `pandas`, `pyarrow`, `pysam`, `requests`, `tqdm`, `platformdirs`. Optional: `lmdb` (faster gene loading on large workloads — install with `pip install seqmat[lmdb]`).
209
+
210
+ ## Contributing
211
+
212
+ PRs welcome. Run the test suite with `pytest tests/`. Benchmarks live under `tests/bench_*.py`.
213
+
214
+ ## License
215
+
216
+ MIT — see [LICENSE](LICENSE).
217
+
218
+ ## Citation
219
+
220
+ If SeqMat is useful in your research, please cite:
221
+
222
+ ```
223
+ Lynn Vila, N. (2025). SeqMat: a fast, vectorized genomic sequence library
224
+ with mutation tracking. https://github.com/nicolasalynn/seqmat
225
+ ```
seqmat-1.5.0/README.md ADDED
@@ -0,0 +1,166 @@
1
+ # SeqMat
2
+
3
+ [![PyPI](https://img.shields.io/pypi/v/seqmat.svg)](https://pypi.org/project/seqmat/)
4
+ [![Python](https://img.shields.io/pypi/pyversions/seqmat.svg)](https://pypi.org/project/seqmat/)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
+ [![Downloads](https://static.pepy.tech/badge/seqmat/month)](https://pepy.tech/project/seqmat)
7
+
8
+ **Fast, vectorized genomic sequences with first-class mutation tracking.**
9
+
10
+ SeqMat treats a DNA sequence as a NumPy-backed matrix of (nucleotide, genomic position) — so slicing, mutation, complement, and splicing are all vectorized array operations. It ships with a compact gene/transcript model that loads from a single indexed SQLite file built from Ensembl annotations, plus a position → gene lookup that resolves overlapping genes in microseconds.
11
+
12
+ ```python
13
+ from seqmat import Gene, SeqMat
14
+
15
+ # What gene is at chr12:25,245,350?
16
+ Gene.from_position("12", 25_245_350) # [Gene(KRAS)]
17
+
18
+ # Load it, assemble the mature mRNA, translate.
19
+ kras = Gene.from_file("KRAS")
20
+ tx = kras.transcript()
21
+ tx.generate_mature_mrna() # 0.2 ms
22
+ tx.generate_protein()
23
+
24
+ # Mutate a sequence with full history and conflict detection.
25
+ seq = SeqMat("ATCGATCGATCG")
26
+ seq.apply_mutations([(3, "C", "G"), (6, "-", "AAA"), (10, "TC", "-")])
27
+ seq.mutations # [(SNP, 3, C, G), (INS, 6, -, AAA), (DEL, 10, TC, -)]
28
+ ```
29
+
30
+ ---
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install seqmat
36
+ seqmat setup # one-time: downloads hg38 genes.db + FASTA (~4 GB)
37
+ ```
38
+
39
+ `seqmat setup` writes a small env block (`SEQMAT_DATA_DIR`, `SEQMAT_DEFAULT_ORGANISM`) to your shell rc so the data is found automatically next session. Mouse: `seqmat setup --organism mm39`. No config file needed.
40
+
41
+ > If you only want `SeqMat` for in-memory sequence work, you can skip `seqmat setup` entirely — `Gene` / `Transcript` are the only things that need the gene database.
42
+
43
+ ## Quick start
44
+
45
+ ### Sequence operations
46
+
47
+ ```python
48
+ from seqmat import SeqMat
49
+ import numpy as np
50
+
51
+ seq = SeqMat("ATCGATCGATCG", indices=np.arange(1000, 1012))
52
+ seq[1005] # base at genomic position 1005
53
+ seq[1003:1008].seq # "GATCG"
54
+ seq.reverse_complement() # in place
55
+ seq.remove_regions([(1003, 1005), (1008, 1009)]) # splice out introns
56
+ ```
57
+
58
+ ### Genes and transcripts
59
+
60
+ ```python
61
+ from seqmat import Gene
62
+
63
+ kras = Gene.from_file("KRAS")
64
+ kras # Gene: KRAS, ID: ENSG00000133703, Chr: 12, Transcripts: 14
65
+
66
+ tx = kras.transcript() # primary transcript
67
+ tx.generate_mature_mrna()
68
+ tx.generate_protein()
69
+ tx.protein[:20] # 'MTEYKLVVVGAGGVGKSALT'
70
+
71
+ acceptors, donors = kras.splice_sites() # Counter across all transcripts
72
+ ```
73
+
74
+ ### Position → gene (new in 1.4.0)
75
+
76
+ ```python
77
+ from seqmat import Gene, gene_names_at_position
78
+
79
+ Gene.from_position("12", 25_245_350) # [Gene(KRAS)] — point query
80
+ Gene.from_position("chr12", (25_200_000, 25_300_000)) # all overlapping genes in a range
81
+ gene_names_at_position("X", 100_000) # names only (no BLOB load) — ~17 us
82
+ ```
83
+
84
+ 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 for free.
85
+
86
+ ### Loading from FASTA
87
+
88
+ ```python
89
+ seq = SeqMat.from_fasta_file("chr12.fasta", "chr12", start=25398284, end=25398384)
90
+ seq.apply_mutations([(25398290, "G", "A")]) # G12D, the most famous KRAS variant
91
+ ```
92
+
93
+ ## Performance
94
+
95
+ Numbers from an M-series Mac on hg38 (one core, warm caches):
96
+
97
+ | Operation | Time |
98
+ | -------------------------------------- | -------: |
99
+ | `gene_names_at_position(chrm, pos)` | **17 µs** |
100
+ | `Gene.from_file("KRAS")` (SQLite + unpickle) | 24 ms |
101
+ | `Gene.from_position(chrm, pos)` end-to-end | 24 ms |
102
+ | KRAS mature mRNA assembly | 0.2 ms |
103
+ | 1,000-SNP batch on 4 kb sequence | 19 ms |
104
+
105
+ The hot paths use NumPy structured arrays, LUT-based complement, `np.searchsorted` on sorted starts, FASTA range-scoped reads, and copy-on-write `clone()`. See `seqmat/seqmat.py` and `seqmat/locator.py`.
106
+
107
+ ## Command-line interface
108
+
109
+ ```bash
110
+ seqmat setup [--organism hg38|mm39] [--path PATH] [--build-from-sources]
111
+ seqmat summary # what's installed
112
+ seqmat info --organism hg38
113
+ seqmat search --organism hg38 --query KRAS
114
+ seqmat list --organism hg38 --biotype protein_coding --limit 20
115
+ seqmat count --organism hg38
116
+ ```
117
+
118
+ ## Data setup
119
+
120
+ By default `seqmat setup` downloads prebuilt `genes.db` and FASTA from the SeqMat S3 bucket — no build step. To regenerate `genes.db` from a specific Ensembl release or custom GTF:
121
+
122
+ ```bash
123
+ seqmat setup --organism hg38 --build-from-sources
124
+ ```
125
+
126
+ For custom organisms, mirroring the prebuilt bucket, ephemeral environments (Docker / Run.ai), shared multi-user installs, and the full configuration system — see **[docs/SETUP.md](docs/SETUP.md)**.
127
+
128
+ ## API at a glance
129
+
130
+ ```python
131
+ from seqmat import (
132
+ SeqMat, # vectorized sequence with mutation tracking
133
+ Gene, Transcript, # gene/transcript model
134
+ gene_names_at_position, # fast name-only positional lookup
135
+ build_location_index, # force-rebuild the position index
136
+ setup_genomics_data, # programmatic setup
137
+ search_genes, available_genes, # discovery helpers
138
+ )
139
+ ```
140
+
141
+ Key classes:
142
+
143
+ - **`SeqMat`** — `apply_mutations`, `clone`, `complement`, `reverse_complement`, `remove_regions`, `from_fasta_file`
144
+ - **`Gene`** — `from_file`, `from_position`, `transcript`, `splice_sites`, `primary_transcript`
145
+ - **`Transcript`** — `generate_pre_mrna`, `generate_mature_mrna`, `generate_protein`, `exons`, `introns`
146
+
147
+ ## Requirements
148
+
149
+ Python ≥ 3.10. Core deps: `numpy`, `pandas`, `pyarrow`, `pysam`, `requests`, `tqdm`, `platformdirs`. Optional: `lmdb` (faster gene loading on large workloads — install with `pip install seqmat[lmdb]`).
150
+
151
+ ## Contributing
152
+
153
+ PRs welcome. Run the test suite with `pytest tests/`. Benchmarks live under `tests/bench_*.py`.
154
+
155
+ ## License
156
+
157
+ MIT — see [LICENSE](LICENSE).
158
+
159
+ ## Citation
160
+
161
+ If SeqMat is useful in your research, please cite:
162
+
163
+ ```
164
+ Lynn Vila, N. (2025). SeqMat: a fast, vectorized genomic sequence library
165
+ with mutation tracking. https://github.com/nicolasalynn/seqmat
166
+ ```
@@ -0,0 +1,73 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "seqmat"
7
+ version = "1.5.0"
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
+ ]
52
+
53
+ [project.urls]
54
+ Homepage = "https://github.com/nicolasalynn/seqmat"
55
+ Repository = "https://github.com/nicolasalynn/seqmat"
56
+ Issues = "https://github.com/nicolasalynn/seqmat/issues"
57
+ Changelog = "https://github.com/nicolasalynn/seqmat/blob/main/CHANGELOG.md"
58
+
59
+ [project.scripts]
60
+ seqmat = "seqmat.cli:main"
61
+ seqmat-setup = "seqmat.cli:main" # legacy alias
62
+
63
+ [tool.setuptools.packages.find]
64
+ include = ["seqmat*"]
65
+ exclude = ["tests*", "examples*", "scripts*", "docs*"]
66
+
67
+ [tool.setuptools.package-data]
68
+ seqmat = ["*.json"]
69
+
70
+ [tool.pytest.ini_options]
71
+ testpaths = ["tests"]
72
+ python_files = ["test_*.py"]
73
+ addopts = "-ra -q"
@@ -0,0 +1,75 @@
1
+ """SeqMat — fast, vectorized genomic sequences with first-class mutation tracking."""
2
+
3
+ __version__ = "1.5.0"
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"]
@@ -0,0 +1,65 @@
1
+ """Conservation score storage: load from .pkl/.db and convert between them."""
2
+ from __future__ import annotations
3
+
4
+ import pickle
5
+ import sqlite3
6
+ from pathlib import Path
7
+ from typing import Any, Dict, Optional, Union
8
+
9
+ from ._io import unload_pickle
10
+
11
+
12
+ def load_conservation(path: Union[str, Path]) -> Dict[str, Any]:
13
+ """Load conservation scores from a ``.db`` (SQLite) or ``.pkl`` file.
14
+
15
+ Returns ``dict[transcript_id] -> {"scores": np.ndarray, "seq": str | bytes}``.
16
+ """
17
+ path = Path(path)
18
+ if not path.exists():
19
+ raise FileNotFoundError(path)
20
+ if path.suffix.lower() == ".db":
21
+ conn = sqlite3.connect(str(path))
22
+ conn.row_factory = sqlite3.Row
23
+ try:
24
+ cursor = conn.execute("SELECT transcript_id, data FROM conservation")
25
+ out: Dict[str, Any] = {}
26
+ for row in cursor:
27
+ out[str(row["transcript_id"])] = pickle.loads(row["data"])
28
+ finally:
29
+ conn.close()
30
+ return out
31
+ data = unload_pickle(path)
32
+ if not isinstance(data, dict):
33
+ raise ValueError("Conservation pickle must be a dict[transcript_id] -> {scores, seq}")
34
+ return data
35
+
36
+
37
+ def convert_conservation_pkl_to_db(
38
+ pkl_path: Union[str, Path],
39
+ db_path: Optional[Union[str, Path]] = None,
40
+ ) -> Path:
41
+ """Convert a conservation ``.pkl`` to ``conservation.db`` (SQLite).
42
+
43
+ Returns the path to the written .db file.
44
+ """
45
+ pkl_path = Path(pkl_path)
46
+ db_path = Path(db_path) if db_path is not None else pkl_path.with_suffix(".db")
47
+ if db_path.exists():
48
+ db_path.unlink()
49
+ data = unload_pickle(pkl_path)
50
+ if not isinstance(data, dict):
51
+ raise ValueError("Conservation pickle must be a dict[transcript_id] -> {scores, seq}")
52
+ conn = sqlite3.connect(str(db_path))
53
+ try:
54
+ conn.execute("CREATE TABLE conservation (transcript_id TEXT PRIMARY KEY, data BLOB)")
55
+ conn.executemany(
56
+ "INSERT INTO conservation (transcript_id, data) VALUES (?, ?)",
57
+ ((str(tid), pickle.dumps(blob)) for tid, blob in data.items()),
58
+ )
59
+ conn.commit()
60
+ finally:
61
+ conn.close()
62
+ return db_path
63
+
64
+
65
+ __all__ = ["load_conservation", "convert_conservation_pkl_to_db"]