gkmsvm-lite 0.1.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.
- gkmsvm_lite-0.1.0/LICENSE +21 -0
- gkmsvm_lite-0.1.0/PKG-INFO +180 -0
- gkmsvm_lite-0.1.0/README.md +135 -0
- gkmsvm_lite-0.1.0/pyproject.toml +69 -0
- gkmsvm_lite-0.1.0/setup.cfg +4 -0
- gkmsvm_lite-0.1.0/setup.py +42 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/__init__.py +49 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/_csmo.c +364 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/_threading.py +51 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/backend.py +213 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/cli.py +487 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/codec.py +131 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/deltasvm.py +263 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/explain.py +482 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/fasta.py +162 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/gram.py +110 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/importers/__init__.py +15 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/importers/classic.py +201 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/importers/deltasvm.py +115 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/importers/lsgkm.py +184 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/importers/r_gkmsvm.py +219 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/ism.py +375 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/kernels/__init__.py +17 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/kernels/base.py +91 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/kernels/direct.py +957 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/kernels/esttrunc.py +110 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/kernels/rbf.py +49 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/kernels/weighted.py +227 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/serialization.py +120 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/solver.py +445 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/svm.py +591 -0
- gkmsvm_lite-0.1.0/src/gkmsvm/train.py +607 -0
- gkmsvm_lite-0.1.0/src/gkmsvm_lite.egg-info/PKG-INFO +180 -0
- gkmsvm_lite-0.1.0/src/gkmsvm_lite.egg-info/SOURCES.txt +49 -0
- gkmsvm_lite-0.1.0/src/gkmsvm_lite.egg-info/dependency_links.txt +1 -0
- gkmsvm_lite-0.1.0/src/gkmsvm_lite.egg-info/entry_points.txt +2 -0
- gkmsvm_lite-0.1.0/src/gkmsvm_lite.egg-info/requires.txt +25 -0
- gkmsvm_lite-0.1.0/src/gkmsvm_lite.egg-info/top_level.txt +1 -0
- gkmsvm_lite-0.1.0/tests/test_cli.py +239 -0
- gkmsvm_lite-0.1.0/tests/test_codec.py +149 -0
- gkmsvm_lite-0.1.0/tests/test_deltasvm.py +256 -0
- gkmsvm_lite-0.1.0/tests/test_explain.py +304 -0
- gkmsvm_lite-0.1.0/tests/test_gpu.py +499 -0
- gkmsvm_lite-0.1.0/tests/test_gram.py +92 -0
- gkmsvm_lite-0.1.0/tests/test_ism.py +149 -0
- gkmsvm_lite-0.1.0/tests/test_mlx.py +493 -0
- gkmsvm_lite-0.1.0/tests/test_replication.py +207 -0
- gkmsvm_lite-0.1.0/tests/test_serialization.py +150 -0
- gkmsvm_lite-0.1.0/tests/test_solver.py +386 -0
- gkmsvm_lite-0.1.0/tests/test_svm.py +212 -0
- gkmsvm_lite-0.1.0/tests/test_train.py +247 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Adam Youlin He
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gkmsvm-lite
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Gapped k-mer SVMs for DNA sequence classification and regression
|
|
5
|
+
Author-email: Adam Youlin He <ayhe@stanford.edu>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/adamyhe/gkmsvm-lite
|
|
8
|
+
Project-URL: Repository, https://github.com/adamyhe/gkmsvm-lite
|
|
9
|
+
Project-URL: Issues, https://github.com/adamyhe/gkmsvm-lite/issues
|
|
10
|
+
Project-URL: Documentation, https://github.com/adamyhe/gkmsvm-lite/tree/main/docs
|
|
11
|
+
Keywords: gkm-svm,svm,dna,genomics,bioinformatics,kernel-methods
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: numpy
|
|
24
|
+
Requires-Dist: numba>=0.57
|
|
25
|
+
Requires-Dist: tqdm
|
|
26
|
+
Requires-Dist: scikit-learn>=1.0
|
|
27
|
+
Requires-Dist: pyfaidx
|
|
28
|
+
Requires-Dist: dinuc-shuf>=0.1.0b1
|
|
29
|
+
Provides-Extra: gpu
|
|
30
|
+
Requires-Dist: cupy-cuda12x[ctk]>=12.0; extra == "gpu"
|
|
31
|
+
Provides-Extra: mlx
|
|
32
|
+
Requires-Dist: mlx>=0.10.0; extra == "mlx"
|
|
33
|
+
Provides-Extra: dev
|
|
34
|
+
Requires-Dist: pytest; extra == "dev"
|
|
35
|
+
Requires-Dist: pytest-cov; extra == "dev"
|
|
36
|
+
Provides-Extra: examples
|
|
37
|
+
Requires-Dist: jupyter; extra == "examples"
|
|
38
|
+
Requires-Dist: matplotlib; extra == "examples"
|
|
39
|
+
Requires-Dist: pandas; extra == "examples"
|
|
40
|
+
Requires-Dist: scipy; extra == "examples"
|
|
41
|
+
Requires-Dist: modisco>=2.5; extra == "examples"
|
|
42
|
+
Requires-Dist: h5py; extra == "examples"
|
|
43
|
+
Requires-Dist: openpyxl; extra == "examples"
|
|
44
|
+
Dynamic: license-file
|
|
45
|
+
|
|
46
|
+
# gkmsvm-lite
|
|
47
|
+
|
|
48
|
+
[](https://pypi.org/project/gkmsvm-lite/)
|
|
49
|
+
[](https://github.com/adamyhe/gkmsvm-lite/actions/workflows/ci.yml)
|
|
50
|
+
[](https://pepy.tech/projects/gkmsvm-lite)
|
|
51
|
+
|
|
52
|
+
A pure-Python implementation of gapped k-mer SVMs (gkm-SVMs) for DNA sequence analysis. Supports classification (C-SVC) and regression (epsilon-SVR), all six kernel types, GPU acceleration via CuPy (NVIDIA) and MLX (Apple Silicon), and compatibility with models from LS-GKM, classic gkmSVM, and the R gkmSVM package.
|
|
53
|
+
|
|
54
|
+
## Install
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
pip install gkmsvm-lite # CPU (NumPy + Numba)
|
|
58
|
+
pip install gkmsvm-lite[gpu] # NVIDIA GPU (+ CuPy)
|
|
59
|
+
pip install gkmsvm-lite[mlx] # Apple Silicon GPU (+ MLX)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
For development installation from source, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
63
|
+
|
|
64
|
+
## Quick start
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from gkmsvm import load_lsgkm_model, one_hot_encode, ism, gkmexplain
|
|
68
|
+
|
|
69
|
+
# Load an existing model
|
|
70
|
+
model = load_lsgkm_model("model.txt.gz")
|
|
71
|
+
|
|
72
|
+
# Score a sequence
|
|
73
|
+
x = one_hot_encode("ACGTACGTACGTACGT")[None, ...] # [1, 4, 16]
|
|
74
|
+
score = model(x) # [1, 1]
|
|
75
|
+
|
|
76
|
+
# Variant effect prediction
|
|
77
|
+
ref = one_hot_encode("ACGTACGTACGTACGT")[None, ...]
|
|
78
|
+
alt = one_hot_encode("ACGTACGAACGTACGT")[None, ...]
|
|
79
|
+
delta = model(alt).item() - model(ref).item()
|
|
80
|
+
|
|
81
|
+
# Attribution
|
|
82
|
+
hyp = gkmexplain(model, x, mode=1) # [1, 4, 16] hypothetical importance
|
|
83
|
+
attr = gkmexplain(model, x, mode=0) # [1, 4, 16] importance (= mode 1 × input)
|
|
84
|
+
deltas = ism(model, x) # [1, 4, 16] mutation deltas
|
|
85
|
+
|
|
86
|
+
# GPU acceleration
|
|
87
|
+
model.cuda() # NVIDIA (~6x speedup)
|
|
88
|
+
model.mlx() # Apple Silicon (~2-6x speedup)
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Command-line interface
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
gkmsvm predict -m model.npz -i sequences.fa -o scores.tsv --device cuda
|
|
95
|
+
gkmsvm train -p positive.fa -n negative.fa -o model.npz -l 11 -k 7 -d 3
|
|
96
|
+
gkmsvm explain -m model.npz -i sequences.fa -o attr.npz -s seqs.npz
|
|
97
|
+
gkmsvm ism -m model.npz -i sequences.fa -o ism.npz
|
|
98
|
+
gkmsvm score-variants -m model.npz --ref ref.fa --alt alt.fa -o deltas.tsv
|
|
99
|
+
gkmsvm to-deltasvm -m model.npz -o weights.txt
|
|
100
|
+
gkmsvm import -i model.txt.gz -f lsgkm -o model.npz
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
See [docs/cli.md](docs/cli.md) for full usage.
|
|
104
|
+
|
|
105
|
+
## Train a model
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from gkmsvm import train_gkmsvm, train_gkmsvr
|
|
109
|
+
|
|
110
|
+
# Classification
|
|
111
|
+
model = train_gkmsvm(pos_seqs, neg_seqs, l=11, k=7, d=3, C=1.0)
|
|
112
|
+
|
|
113
|
+
# Regression (e.g., chromatin accessibility)
|
|
114
|
+
model = train_gkmsvr(sequences, labels, l=11, k=7, d=3, epsilon=0.1)
|
|
115
|
+
|
|
116
|
+
model.save("my_model.npz")
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Load models from any gkm-SVM package
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from gkmsvm import (
|
|
123
|
+
load_lsgkm_model, # LS-GKM / kundajelab/lsgkm
|
|
124
|
+
load_classic_model, # C gkmSVM (LIBSVM-style format)
|
|
125
|
+
load_r_gkmsvm_model, # R gkmSVM (Ghandi et al. 2016)
|
|
126
|
+
load_deltasvm_model, # DeltaSVM k-mer weights
|
|
127
|
+
load_model, # auto-detect npz or LS-GKM text
|
|
128
|
+
)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
See [docs/models.md](docs/models.md) for format details, training options, and examples.
|
|
132
|
+
|
|
133
|
+
## Kernel types
|
|
134
|
+
|
|
135
|
+
All six LS-GKM kernel types are supported:
|
|
136
|
+
|
|
137
|
+
| `-t` | Name | Description |
|
|
138
|
+
|------|------|-------------|
|
|
139
|
+
| 0 | gkm | Direct gapped k-mer count |
|
|
140
|
+
| 1 | gkm_estfull | Estimated full l-mer |
|
|
141
|
+
| 2 | gkm_esttrunc | Estimated truncated l-mer (LS-GKM default) |
|
|
142
|
+
| 3 | gkmrbf | RBF-transformed estimated |
|
|
143
|
+
| 4 | wgkm | Center-weighted gapped k-mer |
|
|
144
|
+
| 5 | wgkmrbf | Center-weighted RBF |
|
|
145
|
+
|
|
146
|
+
## Documentation
|
|
147
|
+
|
|
148
|
+
| Guide | Contents |
|
|
149
|
+
|---|---|
|
|
150
|
+
| [CLI reference](docs/cli.md) | All `gkmsvm` subcommands, flags, and usage examples |
|
|
151
|
+
| [Loading and training models](docs/models.md) | Importing from all formats, training SVC/SVR, solver selection, kernel types |
|
|
152
|
+
| [Scoring and variant effects](docs/scoring.md) | Inference, batch scoring, VEP, GPU acceleration, memory management |
|
|
153
|
+
| [Interpretation](docs/interpretation.md) | GkmExplain, ISM, when to use each, why gradients don't work |
|
|
154
|
+
| [Performance](docs/performance.md) | Benchmarks, optimization details, tuning guidance |
|
|
155
|
+
| [Design decisions](docs/design.md) | Architecture, kernel math, format specifications |
|
|
156
|
+
| [Roadmap](docs/roadmap.md) | Completed features and what's next |
|
|
157
|
+
|
|
158
|
+
## Citation
|
|
159
|
+
|
|
160
|
+
If you use gkmsvm-lite, please cite the relevant methods papers:
|
|
161
|
+
|
|
162
|
+
> Ghandi M, Lee D, Mohammad-Noori M, Beer MA. Enhanced regulatory sequence prediction using gapped k-mer features. *PLoS Comput Biol* 10(7):e1003711 (2014).
|
|
163
|
+
|
|
164
|
+
> Ghandi M, Mohammad-Noori M, Ghareghani N, Lee D, Garraway L, Beer MA. gkmSVM: an R package for gapped-kmer SVM. *Bioinformatics* 32(14):2205-2207 (2016).
|
|
165
|
+
|
|
166
|
+
> Lee D. LS-GKM: a new gkm-SVM for large-scale datasets. *Bioinformatics* 32(14):2196-2198 (2016).
|
|
167
|
+
|
|
168
|
+
If you use GkmExplain:
|
|
169
|
+
|
|
170
|
+
> Shrikumar A, Prakash E, Kundaje A. GkmExplain: fast and accurate interpretation of nonlinear gapped k-mer SVMs. *Bioinformatics* 35(14):i173-i182 (2019).
|
|
171
|
+
|
|
172
|
+
If you use DeltaSVM:
|
|
173
|
+
|
|
174
|
+
> Lee D, Gorkin DU, Baker M, Strober BJ, Asoni AL, McCallion AS, Beer MA. A method to predict the impact of regulatory variants from DNA sequence. *Nat Genet* 47(8):955-961 (2015).
|
|
175
|
+
|
|
176
|
+
See [CITATION.cff](CITATION.cff) for machine-readable citation metadata.
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT. LS-GKM C (Dongwon-Lee/lsgkm) is GPL v3 — gkmsvm-lite is a clean-room reimplementation.
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# gkmsvm-lite
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/gkmsvm-lite/)
|
|
4
|
+
[](https://github.com/adamyhe/gkmsvm-lite/actions/workflows/ci.yml)
|
|
5
|
+
[](https://pepy.tech/projects/gkmsvm-lite)
|
|
6
|
+
|
|
7
|
+
A pure-Python implementation of gapped k-mer SVMs (gkm-SVMs) for DNA sequence analysis. Supports classification (C-SVC) and regression (epsilon-SVR), all six kernel types, GPU acceleration via CuPy (NVIDIA) and MLX (Apple Silicon), and compatibility with models from LS-GKM, classic gkmSVM, and the R gkmSVM package.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install gkmsvm-lite # CPU (NumPy + Numba)
|
|
13
|
+
pip install gkmsvm-lite[gpu] # NVIDIA GPU (+ CuPy)
|
|
14
|
+
pip install gkmsvm-lite[mlx] # Apple Silicon GPU (+ MLX)
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
For development installation from source, see [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
18
|
+
|
|
19
|
+
## Quick start
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
from gkmsvm import load_lsgkm_model, one_hot_encode, ism, gkmexplain
|
|
23
|
+
|
|
24
|
+
# Load an existing model
|
|
25
|
+
model = load_lsgkm_model("model.txt.gz")
|
|
26
|
+
|
|
27
|
+
# Score a sequence
|
|
28
|
+
x = one_hot_encode("ACGTACGTACGTACGT")[None, ...] # [1, 4, 16]
|
|
29
|
+
score = model(x) # [1, 1]
|
|
30
|
+
|
|
31
|
+
# Variant effect prediction
|
|
32
|
+
ref = one_hot_encode("ACGTACGTACGTACGT")[None, ...]
|
|
33
|
+
alt = one_hot_encode("ACGTACGAACGTACGT")[None, ...]
|
|
34
|
+
delta = model(alt).item() - model(ref).item()
|
|
35
|
+
|
|
36
|
+
# Attribution
|
|
37
|
+
hyp = gkmexplain(model, x, mode=1) # [1, 4, 16] hypothetical importance
|
|
38
|
+
attr = gkmexplain(model, x, mode=0) # [1, 4, 16] importance (= mode 1 × input)
|
|
39
|
+
deltas = ism(model, x) # [1, 4, 16] mutation deltas
|
|
40
|
+
|
|
41
|
+
# GPU acceleration
|
|
42
|
+
model.cuda() # NVIDIA (~6x speedup)
|
|
43
|
+
model.mlx() # Apple Silicon (~2-6x speedup)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Command-line interface
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
gkmsvm predict -m model.npz -i sequences.fa -o scores.tsv --device cuda
|
|
50
|
+
gkmsvm train -p positive.fa -n negative.fa -o model.npz -l 11 -k 7 -d 3
|
|
51
|
+
gkmsvm explain -m model.npz -i sequences.fa -o attr.npz -s seqs.npz
|
|
52
|
+
gkmsvm ism -m model.npz -i sequences.fa -o ism.npz
|
|
53
|
+
gkmsvm score-variants -m model.npz --ref ref.fa --alt alt.fa -o deltas.tsv
|
|
54
|
+
gkmsvm to-deltasvm -m model.npz -o weights.txt
|
|
55
|
+
gkmsvm import -i model.txt.gz -f lsgkm -o model.npz
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
See [docs/cli.md](docs/cli.md) for full usage.
|
|
59
|
+
|
|
60
|
+
## Train a model
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from gkmsvm import train_gkmsvm, train_gkmsvr
|
|
64
|
+
|
|
65
|
+
# Classification
|
|
66
|
+
model = train_gkmsvm(pos_seqs, neg_seqs, l=11, k=7, d=3, C=1.0)
|
|
67
|
+
|
|
68
|
+
# Regression (e.g., chromatin accessibility)
|
|
69
|
+
model = train_gkmsvr(sequences, labels, l=11, k=7, d=3, epsilon=0.1)
|
|
70
|
+
|
|
71
|
+
model.save("my_model.npz")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Load models from any gkm-SVM package
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from gkmsvm import (
|
|
78
|
+
load_lsgkm_model, # LS-GKM / kundajelab/lsgkm
|
|
79
|
+
load_classic_model, # C gkmSVM (LIBSVM-style format)
|
|
80
|
+
load_r_gkmsvm_model, # R gkmSVM (Ghandi et al. 2016)
|
|
81
|
+
load_deltasvm_model, # DeltaSVM k-mer weights
|
|
82
|
+
load_model, # auto-detect npz or LS-GKM text
|
|
83
|
+
)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
See [docs/models.md](docs/models.md) for format details, training options, and examples.
|
|
87
|
+
|
|
88
|
+
## Kernel types
|
|
89
|
+
|
|
90
|
+
All six LS-GKM kernel types are supported:
|
|
91
|
+
|
|
92
|
+
| `-t` | Name | Description |
|
|
93
|
+
|------|------|-------------|
|
|
94
|
+
| 0 | gkm | Direct gapped k-mer count |
|
|
95
|
+
| 1 | gkm_estfull | Estimated full l-mer |
|
|
96
|
+
| 2 | gkm_esttrunc | Estimated truncated l-mer (LS-GKM default) |
|
|
97
|
+
| 3 | gkmrbf | RBF-transformed estimated |
|
|
98
|
+
| 4 | wgkm | Center-weighted gapped k-mer |
|
|
99
|
+
| 5 | wgkmrbf | Center-weighted RBF |
|
|
100
|
+
|
|
101
|
+
## Documentation
|
|
102
|
+
|
|
103
|
+
| Guide | Contents |
|
|
104
|
+
|---|---|
|
|
105
|
+
| [CLI reference](docs/cli.md) | All `gkmsvm` subcommands, flags, and usage examples |
|
|
106
|
+
| [Loading and training models](docs/models.md) | Importing from all formats, training SVC/SVR, solver selection, kernel types |
|
|
107
|
+
| [Scoring and variant effects](docs/scoring.md) | Inference, batch scoring, VEP, GPU acceleration, memory management |
|
|
108
|
+
| [Interpretation](docs/interpretation.md) | GkmExplain, ISM, when to use each, why gradients don't work |
|
|
109
|
+
| [Performance](docs/performance.md) | Benchmarks, optimization details, tuning guidance |
|
|
110
|
+
| [Design decisions](docs/design.md) | Architecture, kernel math, format specifications |
|
|
111
|
+
| [Roadmap](docs/roadmap.md) | Completed features and what's next |
|
|
112
|
+
|
|
113
|
+
## Citation
|
|
114
|
+
|
|
115
|
+
If you use gkmsvm-lite, please cite the relevant methods papers:
|
|
116
|
+
|
|
117
|
+
> Ghandi M, Lee D, Mohammad-Noori M, Beer MA. Enhanced regulatory sequence prediction using gapped k-mer features. *PLoS Comput Biol* 10(7):e1003711 (2014).
|
|
118
|
+
|
|
119
|
+
> Ghandi M, Mohammad-Noori M, Ghareghani N, Lee D, Garraway L, Beer MA. gkmSVM: an R package for gapped-kmer SVM. *Bioinformatics* 32(14):2205-2207 (2016).
|
|
120
|
+
|
|
121
|
+
> Lee D. LS-GKM: a new gkm-SVM for large-scale datasets. *Bioinformatics* 32(14):2196-2198 (2016).
|
|
122
|
+
|
|
123
|
+
If you use GkmExplain:
|
|
124
|
+
|
|
125
|
+
> Shrikumar A, Prakash E, Kundaje A. GkmExplain: fast and accurate interpretation of nonlinear gapped k-mer SVMs. *Bioinformatics* 35(14):i173-i182 (2019).
|
|
126
|
+
|
|
127
|
+
If you use DeltaSVM:
|
|
128
|
+
|
|
129
|
+
> Lee D, Gorkin DU, Baker M, Strober BJ, Asoni AL, McCallion AS, Beer MA. A method to predict the impact of regulatory variants from DNA sequence. *Nat Genet* 47(8):955-961 (2015).
|
|
130
|
+
|
|
131
|
+
See [CITATION.cff](CITATION.cff) for machine-readable citation metadata.
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT. LS-GKM C (Dongwon-Lee/lsgkm) is GPL v3 — gkmsvm-lite is a clean-room reimplementation.
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "gkmsvm-lite"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Gapped k-mer SVMs for DNA sequence classification and regression"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.10"
|
|
12
|
+
keywords = ["gkm-svm", "svm", "dna", "genomics", "bioinformatics", "kernel-methods"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Intended Audience :: Science/Research",
|
|
16
|
+
"Topic :: Scientific/Engineering :: Bio-Informatics",
|
|
17
|
+
"Programming Language :: Python :: 3.10",
|
|
18
|
+
"Programming Language :: Python :: 3.11",
|
|
19
|
+
"Programming Language :: Python :: 3.12",
|
|
20
|
+
"Programming Language :: Python :: 3.13",
|
|
21
|
+
"Programming Language :: Python :: 3.14",
|
|
22
|
+
]
|
|
23
|
+
authors = [
|
|
24
|
+
{name = "Adam Youlin He", email = "ayhe@stanford.edu"},
|
|
25
|
+
]
|
|
26
|
+
dependencies = [
|
|
27
|
+
"numpy",
|
|
28
|
+
"numba>=0.57",
|
|
29
|
+
"tqdm",
|
|
30
|
+
"scikit-learn>=1.0",
|
|
31
|
+
"pyfaidx",
|
|
32
|
+
"dinuc-shuf>=0.1.0b1",
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
[project.urls]
|
|
36
|
+
Homepage = "https://github.com/adamyhe/gkmsvm-lite"
|
|
37
|
+
Repository = "https://github.com/adamyhe/gkmsvm-lite"
|
|
38
|
+
Issues = "https://github.com/adamyhe/gkmsvm-lite/issues"
|
|
39
|
+
Documentation = "https://github.com/adamyhe/gkmsvm-lite/tree/main/docs"
|
|
40
|
+
|
|
41
|
+
[project.scripts]
|
|
42
|
+
gkmsvm = "gkmsvm.cli:main"
|
|
43
|
+
|
|
44
|
+
[project.optional-dependencies]
|
|
45
|
+
gpu = [
|
|
46
|
+
"cupy-cuda12x[ctk]>=12.0",
|
|
47
|
+
]
|
|
48
|
+
mlx = [
|
|
49
|
+
"mlx>=0.10.0",
|
|
50
|
+
]
|
|
51
|
+
dev = [
|
|
52
|
+
"pytest",
|
|
53
|
+
"pytest-cov",
|
|
54
|
+
]
|
|
55
|
+
examples = [
|
|
56
|
+
"jupyter",
|
|
57
|
+
"matplotlib",
|
|
58
|
+
"pandas",
|
|
59
|
+
"scipy",
|
|
60
|
+
"modisco>=2.5",
|
|
61
|
+
"h5py",
|
|
62
|
+
"openpyxl",
|
|
63
|
+
]
|
|
64
|
+
|
|
65
|
+
[tool.setuptools.packages.find]
|
|
66
|
+
where = ["src"]
|
|
67
|
+
|
|
68
|
+
[tool.pytest.ini_options]
|
|
69
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Build configuration for C extensions."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
from setuptools import Extension, setup
|
|
6
|
+
from setuptools.command.build_ext import build_ext
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class OptionalBuildExt(build_ext):
|
|
10
|
+
"""Allow the build to succeed even if the C extension fails to compile."""
|
|
11
|
+
|
|
12
|
+
def run(self):
|
|
13
|
+
try:
|
|
14
|
+
super().run()
|
|
15
|
+
except Exception:
|
|
16
|
+
self._warn_failed()
|
|
17
|
+
|
|
18
|
+
def build_extension(self, ext):
|
|
19
|
+
try:
|
|
20
|
+
super().build_extension(ext)
|
|
21
|
+
except Exception:
|
|
22
|
+
self._warn_failed(ext.name)
|
|
23
|
+
|
|
24
|
+
@staticmethod
|
|
25
|
+
def _warn_failed(name="C SMO extension"):
|
|
26
|
+
print(
|
|
27
|
+
f"WARNING: Failed to build {name}. "
|
|
28
|
+
"The SMO solver will fall back to the Python implementation.",
|
|
29
|
+
file=sys.stderr,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
setup(
|
|
34
|
+
ext_modules=[
|
|
35
|
+
Extension(
|
|
36
|
+
"gkmsvm._csmo",
|
|
37
|
+
sources=["src/gkmsvm/_csmo.c"],
|
|
38
|
+
extra_compile_args=["-O2"],
|
|
39
|
+
),
|
|
40
|
+
],
|
|
41
|
+
cmdclass={"build_ext": OptionalBuildExt},
|
|
42
|
+
)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from gkmsvm._threading import pin_threading_layer
|
|
2
|
+
|
|
3
|
+
pin_threading_layer()
|
|
4
|
+
|
|
5
|
+
from gkmsvm.codec import (
|
|
6
|
+
encode_batch,
|
|
7
|
+
one_hot_decode,
|
|
8
|
+
one_hot_encode,
|
|
9
|
+
reverse_complement,
|
|
10
|
+
validate,
|
|
11
|
+
)
|
|
12
|
+
from gkmsvm.deltasvm import DeltaSVM
|
|
13
|
+
from gkmsvm.explain import gkmexplain
|
|
14
|
+
from gkmsvm.fasta import extract_loci, read_fasta, write_fasta
|
|
15
|
+
from gkmsvm.importers.classic import load_classic_model
|
|
16
|
+
from gkmsvm.importers.deltasvm import load_deltasvm_model
|
|
17
|
+
from gkmsvm.importers.lsgkm import load_lsgkm_model
|
|
18
|
+
from gkmsvm.importers.r_gkmsvm import load_r_gkmsvm_model
|
|
19
|
+
from gkmsvm.ism import ism
|
|
20
|
+
from gkmsvm.serialization import load_model, load_npz, save_lsgkm, save_npz
|
|
21
|
+
from gkmsvm.svm import KERNEL_ALIASES, GkmSVM, resolve_kernel_type
|
|
22
|
+
from gkmsvm.train import train_gkmsvm, train_gkmsvr
|
|
23
|
+
|
|
24
|
+
__all__ = [
|
|
25
|
+
"one_hot_encode",
|
|
26
|
+
"one_hot_decode",
|
|
27
|
+
"reverse_complement",
|
|
28
|
+
"validate",
|
|
29
|
+
"encode_batch",
|
|
30
|
+
"GkmSVM",
|
|
31
|
+
"KERNEL_ALIASES",
|
|
32
|
+
"resolve_kernel_type",
|
|
33
|
+
"DeltaSVM",
|
|
34
|
+
"load_lsgkm_model",
|
|
35
|
+
"load_classic_model",
|
|
36
|
+
"load_r_gkmsvm_model",
|
|
37
|
+
"load_deltasvm_model",
|
|
38
|
+
"read_fasta",
|
|
39
|
+
"write_fasta",
|
|
40
|
+
"extract_loci",
|
|
41
|
+
"ism",
|
|
42
|
+
"gkmexplain",
|
|
43
|
+
"train_gkmsvm",
|
|
44
|
+
"train_gkmsvr",
|
|
45
|
+
"load_model",
|
|
46
|
+
"load_npz",
|
|
47
|
+
"save_npz",
|
|
48
|
+
"save_lsgkm",
|
|
49
|
+
]
|