OpenSpliceai 0.0.5__tar.gz → 0.0.7__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 (56) hide show
  1. openspliceai-0.0.7/MANIFEST.in +2 -0
  2. {openspliceai-0.0.5/openspliceai.egg-info → openspliceai-0.0.7}/PKG-INFO +61 -7
  3. {openspliceai-0.0.5 → openspliceai-0.0.7}/README.md +37 -3
  4. openspliceai-0.0.7/openspliceai/__init__.py +1 -0
  5. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/calibrate/calibrate.py +15 -6
  6. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/calibrate/temperature_scaling_site_only.py +1 -3
  7. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/create_data/create_datafile.py +10 -0
  8. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/create_data/create_dataset.py +9 -3
  9. openspliceai-0.0.7/openspliceai/create_data/gff_to_tsv.py +124 -0
  10. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/create_data/paralogs.py +4 -4
  11. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/create_data/utils.py +14 -3
  12. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/create_data/verify_h5_file.py +6 -4
  13. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/header.py +2 -2
  14. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/merge_data/merge_dataset.py +1 -4
  15. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/openspliceai.py +22 -4
  16. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/predict/predict.py +93 -39
  17. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/predict/utils.py +2 -1
  18. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/train/train.py +9 -3
  19. openspliceai-0.0.7/openspliceai/train_base/openspliceai.py +141 -0
  20. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/train_base/utils.py +45 -4
  21. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/transfer/transfer.py +17 -5
  22. openspliceai-0.0.7/openspliceai/variant/annotations/grch37.txt +20275 -0
  23. openspliceai-0.0.7/openspliceai/variant/annotations/grch38.txt +19306 -0
  24. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/variant/utils.py +232 -9
  25. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/variant/variant.py +42 -8
  26. {openspliceai-0.0.5 → openspliceai-0.0.7/openspliceai.egg-info}/PKG-INFO +61 -7
  27. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai.egg-info/SOURCES.txt +4 -1
  28. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai.egg-info/requires.txt +10 -3
  29. {openspliceai-0.0.5 → openspliceai-0.0.7}/setup.py +22 -6
  30. openspliceai-0.0.5/MANIFEST.in +0 -1
  31. openspliceai-0.0.5/openspliceai/__init__.py +0 -1
  32. openspliceai-0.0.5/openspliceai/train_base/openspliceai.py +0 -72
  33. {openspliceai-0.0.5 → openspliceai-0.0.7}/LICENSE +0 -0
  34. {openspliceai-0.0.5 → openspliceai-0.0.7}/logo/jhu-logo-dark.png +0 -0
  35. {openspliceai-0.0.5 → openspliceai-0.0.7}/logo/logo_black.png +0 -0
  36. {openspliceai-0.0.5 → openspliceai-0.0.7}/logo/logo_white.png +0 -0
  37. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/calibrate/__init__.py +0 -0
  38. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/calibrate/calibrate_utils.py +0 -0
  39. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/calibrate/model_utils.py +0 -0
  40. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/calibrate/temperature_scaling.py +0 -0
  41. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/calibrate/visualization.py +0 -0
  42. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/constants.py +0 -0
  43. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/create_data/__init__.py +0 -0
  44. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/merge_data/__init__.py +0 -0
  45. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/predict/__init__.py +0 -0
  46. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/test/__init__.py +0 -0
  47. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/test/test.py +0 -0
  48. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/train/__init__.py +0 -0
  49. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/train_base/__init__.py +0 -0
  50. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/transfer/__init__.py +0 -0
  51. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/variant/__init__.py +0 -0
  52. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai/variant/get_anno.py +0 -0
  53. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai.egg-info/dependency_links.txt +0 -0
  54. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai.egg-info/entry_points.txt +0 -0
  55. {openspliceai-0.0.5 → openspliceai-0.0.7}/openspliceai.egg-info/top_level.txt +0 -0
  56. {openspliceai-0.0.5 → openspliceai-0.0.7}/setup.cfg +0 -0
@@ -0,0 +1,2 @@
1
+ recursive-include logo *
2
+ recursive-include openspliceai/variant/annotations *.txt
@@ -1,10 +1,22 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openspliceai
3
- Version: 0.0.5
3
+ Version: 0.0.7
4
4
  Summary: Deep learning framework that decodes splicing across species
5
5
  Home-page: https://github.com/Kuanhao-Chao/OpenSpliceAI
6
6
  Author: Kuan-Hao Chao
7
7
  Author-email: kh.chao@cs.jhu.edu
8
+ License: GPL-3.0-only
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Science/Research
11
+ Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
12
+ Classifier: Operating System :: POSIX :: Linux
13
+ Classifier: Operating System :: MacOS
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
8
20
  Requires-Python: >=3.9
9
21
  Description-Content-Type: text/markdown
10
22
  License-File: LICENSE
@@ -16,29 +28,42 @@ Requires-Dist: pandas>=1.5.3
16
28
  Requires-Dist: pyfaidx>=0.8.1.1
17
29
  Requires-Dist: tqdm>=4.65.2
18
30
  Requires-Dist: torch>=2.2.1
19
- Requires-Dist: torchaudio>=2.2.1
20
- Requires-Dist: torchvision>=0.17.1
21
31
  Requires-Dist: scikit-learn>=1.4.1.post1
22
32
  Requires-Dist: biopython>=1.83
23
33
  Requires-Dist: matplotlib>=3.8.3
24
- Requires-Dist: matplotlib-inline>=0.1.7
25
34
  Requires-Dist: psutil>=5.9.2
26
35
  Requires-Dist: mappy>=2.28
36
+ Provides-Extra: test
37
+ Requires-Dist: pytest>=7; extra == "test"
38
+ Requires-Dist: pytest-cov>=4; extra == "test"
39
+ Provides-Extra: dev
40
+ Requires-Dist: pytest>=7; extra == "dev"
41
+ Requires-Dist: pytest-cov>=4; extra == "dev"
42
+ Requires-Dist: ruff>=0.4; extra == "dev"
43
+ Requires-Dist: pre-commit>=3; extra == "dev"
27
44
  Dynamic: author
28
45
  Dynamic: author-email
46
+ Dynamic: classifier
29
47
  Dynamic: description
30
48
  Dynamic: description-content-type
31
49
  Dynamic: home-page
50
+ Dynamic: license
32
51
  Dynamic: license-file
52
+ Dynamic: provides-extra
33
53
  Dynamic: requires-dist
34
54
  Dynamic: requires-python
35
55
  Dynamic: summary
36
56
 
37
- <img alt="My Logo" class="logo header-image only-dark align-center" src="https://khchao.com/images/openspliceai_logo_black.png" style="width:90%">
57
+ <p align="center">
58
+ <picture>
59
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Kuanhao-Chao/OpenSpliceAI/main/logo/logo_white.png">
60
+ <img alt="OpenSpliceAI" src="https://raw.githubusercontent.com/Kuanhao-Chao/OpenSpliceAI/main/logo/logo_black.png" width="90%">
61
+ </picture>
62
+ </p>
38
63
 
39
64
 
40
65
  <a class="reference external image-reference" href="https://img.shields.io/badge/License-GPLv3-yellow.svg"><img alt="https://img.shields.io/badge/License-GPLv3-yellow.svg" src="https://img.shields.io/badge/License-GPLv3-yellow.svg"></a>
41
- <a class="reference external image-reference" href="https://img.shields.io/badge/version-v.0.0.4-blue"><img alt="https://img.shields.io/badge/version-v.0.0.4-blue" src="https://img.shields.io/badge/version-v.0.0.4-blue"></a>
66
+ <a class="reference external image-reference" href="https://img.shields.io/badge/version-v.0.0.7-blue"><img alt="https://img.shields.io/badge/version-v.0.0.7-blue" src="https://img.shields.io/badge/version-v.0.0.7-blue"></a>
42
67
  <a class="reference external image-reference" href="https://pepy.tech/project/openspliceai"><img alt="https://static.pepy.tech/personalized-badge/openspliceai?period=total&amp;units=abbreviation&amp;left_color=grey&amp;right_color=blue&amp;left_text=PyPi%20downloads" src="https://static.pepy.tech/personalized-badge/openspliceai?period=total&amp;units=abbreviation&amp;left_color=grey&amp;right_color=blue&amp;left_text=PyPi%20downloads"></a>
43
68
  <a class="reference external image-reference" href="https://github.com/Kuanhao-Chao/OpenSpliceAI/releases"><img alt="https://img.shields.io/github/downloads/Kuanhao-Chao/OpenSpliceAI/total.svg?style=social&amp;logo=github&amp;label=Download" src="https://img.shields.io/github/downloads/Kuanhao-Chao/OpenSpliceAI/total.svg?style=social&amp;logo=github&amp;label=Download"></a>
44
69
  <a class="reference external image-reference" href="https://github.com/Kuanhao-Chao/OpenSpliceAI/releases"><img alt="https://img.shields.io/badge/platform-macOS_/Linux-green.svg" src="https://img.shields.io/badge/platform-macOS_/Linux-green.svg"></a>
@@ -95,6 +120,17 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
95
120
  <div class="line"><br></div>
96
121
  </div>
97
122
  </section>
123
+ <section id="installation">
124
+ <h1>Installation<a class="headerlink" href="#installation" title="Permalink to this heading">#</a></h1>
125
+ <p>Install the latest release from <strong>PyPI</strong>:</p>
126
+ <pre><code>pip install openspliceai</code></pre>
127
+ <p>or from <strong>Bioconda</strong> (make sure the <code>conda-forge</code> and <code>bioconda</code> channels are enabled):</p>
128
+ <pre><code>conda install -c conda-forge -c bioconda openspliceai</code></pre>
129
+ <p>See the <a class="reference external" href="https://ccb.jhu.edu/openspliceai/content/installation.html#installation">Installation Guide</a> for GPU/CUDA setup and other options.</p>
130
+ <div class="line-block">
131
+ <div class="line"><br></div>
132
+ </div>
133
+ </section>
98
134
  <section id="cite-us">
99
135
  <h1>Cite Us<a class="headerlink" href="#cite-us" title="Permalink to this heading">#</a></h1>
100
136
  <p>If you use OpenSpliceAI in your research, please cite our work as well as the original SpliceAI paper:</p>
@@ -121,6 +157,22 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
121
157
  <div class="line"><br></div>
122
158
  </div>
123
159
  </section>
160
+ <section id="development-testing">
161
+ <h1>Development &amp; Testing<a class="headerlink" href="#development-testing" title="Permalink to this heading">#</a></h1>
162
+ <p>Install the package with its development dependencies (pytest, pytest-cov, ruff, pre-commit) from a clone of the repository:</p>
163
+ <pre><code>pip install -e '.[dev]'</code></pre>
164
+ <p><strong>Tests</strong> live under <code>tests/</code> (<code>unit</code> / <code>integration</code> / <code>regression</code>) and run on CPU only:</p>
165
+ <pre><code>pytest -m "not slow and not integration" # fast inner loop
166
+ pytest # full suite</code></pre>
167
+ <p>Tests are tagged with markers (declared in <code>pytest.ini</code>) &mdash; <code>integration</code>, <code>slow</code>, <code>gpu</code>, and <code>keras</code> (auto-skipped when TensorFlow is absent) &mdash; selectable with <code>-m</code>, e.g. <code>pytest -m integration</code>.</p>
168
+ <p><strong>Lint and pre-commit hooks</strong> (configured in <code>ruff.toml</code> and <code>.pre-commit-config.yaml</code>):</p>
169
+ <pre><code>ruff check . # lint (add --fix to auto-fix)
170
+ pre-commit install # run ruff + checks on every commit</code></pre>
171
+ <p>See the <a class="reference external" href="https://ccb.jhu.edu/openspliceai/">full documentation</a> for the complete development and testing guide.</p>
172
+ <div class="line-block">
173
+ <div class="line"><br></div>
174
+ </div>
175
+ </section>
124
176
  <section id="table-of-contents">
125
177
  <h1>Table of Contents<a class="headerlink" href="#table-of-contents" title="Permalink to this heading">#</a></h1>
126
178
  <div class="toctree-wrapper compound">
@@ -239,5 +291,7 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
239
291
  <div class="line"><br></div>
240
292
  <div class="line"><br></div>
241
293
  </div>
242
- <img alt="My Logo" class="logo header-image only-light align-center" src="https://khchao.com/images/jhu-logo-dark.png">
294
+ <p align="center">
295
+ <img alt="Johns Hopkins University" src="https://raw.githubusercontent.com/Kuanhao-Chao/OpenSpliceAI/main/logo/jhu-logo-dark.png" width="40%">
296
+ </p>
243
297
  </section>
@@ -1,8 +1,13 @@
1
- <img alt="My Logo" class="logo header-image only-dark align-center" src="https://khchao.com/images/openspliceai_logo_black.png" style="width:90%">
1
+ <p align="center">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Kuanhao-Chao/OpenSpliceAI/main/logo/logo_white.png">
4
+ <img alt="OpenSpliceAI" src="https://raw.githubusercontent.com/Kuanhao-Chao/OpenSpliceAI/main/logo/logo_black.png" width="90%">
5
+ </picture>
6
+ </p>
2
7
 
3
8
 
4
9
  <a class="reference external image-reference" href="https://img.shields.io/badge/License-GPLv3-yellow.svg"><img alt="https://img.shields.io/badge/License-GPLv3-yellow.svg" src="https://img.shields.io/badge/License-GPLv3-yellow.svg"></a>
5
- <a class="reference external image-reference" href="https://img.shields.io/badge/version-v.0.0.4-blue"><img alt="https://img.shields.io/badge/version-v.0.0.4-blue" src="https://img.shields.io/badge/version-v.0.0.4-blue"></a>
10
+ <a class="reference external image-reference" href="https://img.shields.io/badge/version-v.0.0.7-blue"><img alt="https://img.shields.io/badge/version-v.0.0.7-blue" src="https://img.shields.io/badge/version-v.0.0.7-blue"></a>
6
11
  <a class="reference external image-reference" href="https://pepy.tech/project/openspliceai"><img alt="https://static.pepy.tech/personalized-badge/openspliceai?period=total&amp;units=abbreviation&amp;left_color=grey&amp;right_color=blue&amp;left_text=PyPi%20downloads" src="https://static.pepy.tech/personalized-badge/openspliceai?period=total&amp;units=abbreviation&amp;left_color=grey&amp;right_color=blue&amp;left_text=PyPi%20downloads"></a>
7
12
  <a class="reference external image-reference" href="https://github.com/Kuanhao-Chao/OpenSpliceAI/releases"><img alt="https://img.shields.io/github/downloads/Kuanhao-Chao/OpenSpliceAI/total.svg?style=social&amp;logo=github&amp;label=Download" src="https://img.shields.io/github/downloads/Kuanhao-Chao/OpenSpliceAI/total.svg?style=social&amp;logo=github&amp;label=Download"></a>
8
13
  <a class="reference external image-reference" href="https://github.com/Kuanhao-Chao/OpenSpliceAI/releases"><img alt="https://img.shields.io/badge/platform-macOS_/Linux-green.svg" src="https://img.shields.io/badge/platform-macOS_/Linux-green.svg"></a>
@@ -59,6 +64,17 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
59
64
  <div class="line"><br></div>
60
65
  </div>
61
66
  </section>
67
+ <section id="installation">
68
+ <h1>Installation<a class="headerlink" href="#installation" title="Permalink to this heading">#</a></h1>
69
+ <p>Install the latest release from <strong>PyPI</strong>:</p>
70
+ <pre><code>pip install openspliceai</code></pre>
71
+ <p>or from <strong>Bioconda</strong> (make sure the <code>conda-forge</code> and <code>bioconda</code> channels are enabled):</p>
72
+ <pre><code>conda install -c conda-forge -c bioconda openspliceai</code></pre>
73
+ <p>See the <a class="reference external" href="https://ccb.jhu.edu/openspliceai/content/installation.html#installation">Installation Guide</a> for GPU/CUDA setup and other options.</p>
74
+ <div class="line-block">
75
+ <div class="line"><br></div>
76
+ </div>
77
+ </section>
62
78
  <section id="cite-us">
63
79
  <h1>Cite Us<a class="headerlink" href="#cite-us" title="Permalink to this heading">#</a></h1>
64
80
  <p>If you use OpenSpliceAI in your research, please cite our work as well as the original SpliceAI paper:</p>
@@ -85,6 +101,22 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
85
101
  <div class="line"><br></div>
86
102
  </div>
87
103
  </section>
104
+ <section id="development-testing">
105
+ <h1>Development &amp; Testing<a class="headerlink" href="#development-testing" title="Permalink to this heading">#</a></h1>
106
+ <p>Install the package with its development dependencies (pytest, pytest-cov, ruff, pre-commit) from a clone of the repository:</p>
107
+ <pre><code>pip install -e '.[dev]'</code></pre>
108
+ <p><strong>Tests</strong> live under <code>tests/</code> (<code>unit</code> / <code>integration</code> / <code>regression</code>) and run on CPU only:</p>
109
+ <pre><code>pytest -m "not slow and not integration" # fast inner loop
110
+ pytest # full suite</code></pre>
111
+ <p>Tests are tagged with markers (declared in <code>pytest.ini</code>) &mdash; <code>integration</code>, <code>slow</code>, <code>gpu</code>, and <code>keras</code> (auto-skipped when TensorFlow is absent) &mdash; selectable with <code>-m</code>, e.g. <code>pytest -m integration</code>.</p>
112
+ <p><strong>Lint and pre-commit hooks</strong> (configured in <code>ruff.toml</code> and <code>.pre-commit-config.yaml</code>):</p>
113
+ <pre><code>ruff check . # lint (add --fix to auto-fix)
114
+ pre-commit install # run ruff + checks on every commit</code></pre>
115
+ <p>See the <a class="reference external" href="https://ccb.jhu.edu/openspliceai/">full documentation</a> for the complete development and testing guide.</p>
116
+ <div class="line-block">
117
+ <div class="line"><br></div>
118
+ </div>
119
+ </section>
88
120
  <section id="table-of-contents">
89
121
  <h1>Table of Contents<a class="headerlink" href="#table-of-contents" title="Permalink to this heading">#</a></h1>
90
122
  <div class="toctree-wrapper compound">
@@ -203,5 +235,7 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
203
235
  <div class="line"><br></div>
204
236
  <div class="line"><br></div>
205
237
  </div>
206
- <img alt="My Logo" class="logo header-image only-light align-center" src="https://khchao.com/images/jhu-logo-dark.png">
238
+ <p align="center">
239
+ <img alt="Johns Hopkins University" src="https://raw.githubusercontent.com/Kuanhao-Chao/OpenSpliceAI/main/logo/jhu-logo-dark.png" width="40%">
240
+ </p>
207
241
  </section>
@@ -0,0 +1 @@
1
+ __version__ = 'v0.0.7'
@@ -62,14 +62,14 @@ def evaluate_and_visualize(calibrated_model, data_loader, device, output_base_di
62
62
 
63
63
  original_nll, original_ece = calibrated_model.compute_ece_nll(logits, labels)
64
64
  with open(metric_original_file, 'w') as f:
65
- f.write(f"Original_NLL\tOriginal_ECE\n")
65
+ f.write("Original_NLL\tOriginal_ECE\n")
66
66
  f.write(f"{original_nll:.8f}\t{original_ece:.8f}\n")
67
67
  print(f"Original NLL: {original_nll:.8f}")
68
68
  print(f"Original ECE: {original_ece:.8f}")
69
69
 
70
70
  calibrated_nll, calibrated_ece = calibrated_model.compute_ece_nll(logits_scaled, labels)
71
71
  with open(metric_calibrated_file, 'w') as f:
72
- f.write(f"Calibrated_NLL\tCalibrated_ECE\n")
72
+ f.write("Calibrated_NLL\tCalibrated_ECE\n")
73
73
  f.write(f"{calibrated_nll:.8f}\t{calibrated_ece:.8f}\n")
74
74
  print(f"Calibrated NLL: {calibrated_nll:.8f}")
75
75
  print(f"Calibrated ECE: {calibrated_ece:.8f}")
@@ -110,6 +110,14 @@ def evaluate_and_visualize(calibrated_model, data_loader, device, output_base_di
110
110
 
111
111
 
112
112
  def calibrate(args):
113
+ """Temperature-scale a trained SpliceAI model (entry point for the ``calibrate`` subcommand).
114
+
115
+ Loads ``args.pretrained_model``, wraps it in a ``ModelWithTemperature``, and
116
+ fits a single temperature parameter on the validation set. Reports
117
+ calibration metrics (ECE/NLL/Brier) and writes calibration-curve plots and
118
+ per-dataset metric files, plus ``temperature.pt``/``.txt`` and a full
119
+ ``calibrated_model.pt`` under ``{output_dir}/calibration``. Returns nothing.
120
+ """
113
121
  print("Running OpenSpliceAI with 'calibrate' mode")
114
122
  start_time = time.time()
115
123
 
@@ -121,8 +129,8 @@ def calibrate(args):
121
129
 
122
130
  # Set up the device, datasets, and indices
123
131
  device = setup_environment(args)
124
- train_h5f, test_h5f, batch_num = load_datasets(args)
125
- train_idxs, val_idxs, test_idxs = generate_indices(batch_num, args.random_seed, test_h5f)
132
+ train_h5f, valid_h5f, test_h5f, batch_num = load_datasets(args)
133
+ train_idxs, val_idxs, test_idxs = generate_indices(train_h5f, valid_h5f, test_h5f)
126
134
 
127
135
  # Initialize the model
128
136
  model, model_params = initialize_model_and_optim(device, args.flanking_size, args.pretrained_model)
@@ -138,8 +146,9 @@ def calibrate(args):
138
146
  print("Validation indices count:", len(val_idxs))
139
147
  print("Test indices count:", len(test_idxs))
140
148
 
141
- # Create data loaders for the validation (calibration) and test sets
142
- validation_loader = get_validation_loader(train_h5f, val_idxs, model_params["BATCH_SIZE"])
149
+ # Create data loaders for the validation (calibration) and test sets.
150
+ # val_idxs index the validation file, so the loader must read from valid_h5f.
151
+ validation_loader = get_validation_loader(valid_h5f, val_idxs, model_params["BATCH_SIZE"])
143
152
  test_loader = get_validation_loader(test_h5f, test_idxs, model_params["BATCH_SIZE"])
144
153
 
145
154
  # Load or determine the temperature vector
@@ -5,14 +5,12 @@ Date: 2025-03-20
5
5
  Description: Test script to calibrate the OpenSpliceAI model only on splice sites.
6
6
  """
7
7
 
8
- import os
9
8
  import torch
10
- from torch import nn, optim
9
+ from torch import nn
11
10
  import torch.nn.functional as F
12
11
  import numpy as np
13
12
  from openspliceai.train_base.utils import *
14
13
  from torch.utils.data import TensorDataset, DataLoader
15
- from tqdm import tqdm
16
14
 
17
15
 
18
16
  def load_data_from_shard(h5f, shard_idx):
@@ -131,6 +131,16 @@ def get_sequences_and_labels(db, output_dir, seq_dict, chrom_dict, train_or_test
131
131
 
132
132
 
133
133
  def create_datafile(args):
134
+ """Stage 1 of ``create-data``: extract per-gene sequences and splice labels into ``datafile_*.h5``.
135
+
136
+ Parses the annotation GFF (via gffutils) and genome FASTA, splits
137
+ chromosomes into train/test groups (``--split-method``), and for each gene
138
+ collects the (minus-strand reverse-complemented) sequence and a per-base
139
+ label marking donor=2 / acceptor=1 positions (optionally gated to canonical
140
+ motifs). Optionally removes paralogs between splits and carves a validation
141
+ set out of train. Side effect: writes ``datafile_{train,validation,test}.h5``
142
+ (string datasets SEQ/LABEL/STRAND/TX_START/TX_END) into ``args.output_dir``.
143
+ """
134
144
  print("Running OpenSpliceAI with 'create-data' mode")
135
145
  print("--- Step 1: Creating datafile.h5 ... ---")
136
146
  start_time = time.process_time()
@@ -15,6 +15,15 @@ from openspliceai.create_data.utils import ceil_div, replace_non_acgt_to_n, crea
15
15
  CHUNK_SIZE = 100 # size of chunks to process data in
16
16
 
17
17
  def create_dataset(args):
18
+ """Stage 2 of ``create-data``: one-hot encode and window the datafiles into ``dataset_*.h5``.
19
+
20
+ Reads each ``datafile_{split}.h5`` produced by :func:`create_datafile`,
21
+ one-hot encodes the sequences (4 channels) and labels (3 channels), splits
22
+ them into fixed-length ``SL + CL_max`` windows, and stores them as chunked
23
+ ``X0,X1,...`` / ``Y0,Y1,...`` datasets (100 genes per chunk). Side effect:
24
+ writes ``dataset_{train,validation,test}.h5`` into ``args.output_dir``,
25
+ ready to be streamed by the training loop.
26
+ """
18
27
  print("--- Step 2: Creating dataset.h5 ... ---")
19
28
  start_time = time.process_time()
20
29
 
@@ -38,9 +47,6 @@ def create_dataset(args):
38
47
  with h5py.File(input_file, 'r') as h5f:
39
48
  SEQ = h5f['SEQ'][:]
40
49
  LABEL = h5f['LABEL'][:]
41
- STRAND = h5f['STRAND'][:]
42
- TX_START = h5f['TX_START'][:]
43
- TX_END = h5f['TX_END'][:]
44
50
 
45
51
  print(f"\tWriting {output_file} ... ")
46
52
  with h5py.File(output_file, 'w') as h5f2:
@@ -0,0 +1,124 @@
1
+ import argparse
2
+ import os
3
+ import gffutils
4
+
5
+ # Removed import openspliceai.create_data.utils as utils to avoid sklearn dependency
6
+
7
+ def create_or_load_db(gff_file, db_file='gff.db'):
8
+ """
9
+ Create a gffutils database from a GFF file, or load it if it already exists.
10
+ """
11
+ if not os.path.exists(db_file):
12
+ print("Creating new database...")
13
+ db = gffutils.create_db(gff_file, dbfn=db_file, force=True, keep_order=True, merge_strategy='merge', sort_attribute_values=True)
14
+ else:
15
+ print("Loading existing database...")
16
+ db = gffutils.FeatureDB(db_file)
17
+ return db
18
+
19
+ def get_canonical_transcript(gene, db):
20
+ """
21
+ Select the canonical transcript for a gene (longest transcript).
22
+ """
23
+ # Look for both 'mRNA' and 'transcript' feature types
24
+ transcripts_mRNA = list(db.children(gene, featuretype='mRNA', order_by='start'))
25
+ transcripts_transcript = list(db.children(gene, featuretype='transcript', order_by='start'))
26
+
27
+ transcripts = transcripts_mRNA + transcripts_transcript
28
+
29
+ if not transcripts:
30
+ return None
31
+
32
+ max_trans = transcripts[0]
33
+ max_len = max_trans.end - max_trans.start + 1
34
+ for transcript in transcripts:
35
+ length = transcript.end - transcript.start + 1
36
+ if length > max_len:
37
+ max_trans = transcript
38
+ max_len = length
39
+ return max_trans
40
+
41
+ def main():
42
+ parser = argparse.ArgumentParser(description="Convert GFF3 annotation to TSV format.")
43
+ parser.add_argument("gff_file", help="Path to the input GFF3 file.")
44
+ parser.add_argument("output_file", help="Path to the output TSV file.")
45
+ args = parser.parse_args()
46
+
47
+ print(f"Processing {args.gff_file}...")
48
+ db = create_or_load_db(args.gff_file, db_file=f'{args.gff_file}_db')
49
+
50
+ with open(args.output_file, 'w') as out_f:
51
+ # Write header
52
+ out_f.write("#NAME\tCHROM\tSTRAND\tTX_START\tTX_END\tEXON_START\tEXON_END\n")
53
+
54
+ for gene in db.features_of_type('gene'):
55
+ # Filter for protein_coding genes
56
+ # Check gene_biotype (Standard/Ensembl) or gene_type (MANE/Gencode)
57
+ is_protein_coding = False
58
+ if 'gene_biotype' in gene.attributes and gene.attributes['gene_biotype'][0] == 'protein_coding':
59
+ is_protein_coding = True
60
+ elif 'gene_type' in gene.attributes and gene.attributes['gene_type'][0] == 'protein_coding':
61
+ is_protein_coding = True
62
+
63
+ # If biotype/type is specified but not protein_coding, skip.
64
+ # If neither attribute exists, decision depends on strictness.
65
+ # Given the loop logic "Filter for protein_coding", we should probably skip if we can't confirm it's protein_coding?
66
+ # Or if it's missing, maybe include it?
67
+ # Previous logic was "if biotype exists and != protein_coding then skip".
68
+ # I will preserve that: if we find a type attribute and it says NOT protein_coding, we skip.
69
+ # If we find NO type attribute, we include it (assumed safe or user wants it).
70
+ # BUT, the user's issue was empty output, implying things got filtered out or not found.
71
+ # In MANE GFF, `gene_type=protein_coding` IS present.
72
+ # So I should check:
73
+
74
+ skip = False
75
+ if 'gene_biotype' in gene.attributes:
76
+ if gene.attributes['gene_biotype'][0] != 'protein_coding':
77
+ skip = True
78
+ elif 'gene_type' in gene.attributes:
79
+ if gene.attributes['gene_type'][0] != 'protein_coding':
80
+ skip = True
81
+
82
+ # If we want to strictly enforce protein_coding when the attribute exists.
83
+ # For MANE, we saw gene_type=protein_coding.
84
+
85
+ if skip:
86
+ continue
87
+
88
+ transcript = get_canonical_transcript(gene, db)
89
+ if not transcript:
90
+ continue
91
+
92
+ exons = list(db.children(transcript, featuretype='exon', order_by='start'))
93
+ if not exons:
94
+ continue
95
+
96
+ # Extract coordinates
97
+ # GFF is 1-based, output requires 0-based start, 1-based end.
98
+ tx_start = transcript.start - 1
99
+ tx_end = transcript.end
100
+
101
+ exon_starts = []
102
+ exon_ends = []
103
+
104
+ for exon in exons:
105
+ exon_starts.append(str(exon.start - 1))
106
+ exon_ends.append(str(exon.end))
107
+
108
+ exon_start_str = ",".join(exon_starts) + ","
109
+ exon_end_str = ",".join(exon_ends) + ","
110
+
111
+ # Name
112
+ # Try 'Name', then 'gene_name', then 'ID'
113
+ gene_name = gene.id
114
+ if 'Name' in gene.attributes:
115
+ gene_name = gene.attributes['Name'][0]
116
+ elif 'gene_name' in gene.attributes:
117
+ gene_name = gene.attributes['gene_name'][0]
118
+
119
+ out_f.write(f"{gene_name}\t{gene.seqid}\t{gene.strand}\t{tx_start}\t{tx_end}\t{exon_start_str}\t{exon_end_str}\n")
120
+
121
+ print(f"Done. Output written to {args.output_file}")
122
+
123
+ if __name__ == "__main__":
124
+ main()
@@ -22,7 +22,7 @@ def remove_paralogous_sequences(train_data, test_data, min_identity, min_coverag
22
22
  :param min_coverage: Minimum coverage for sequences to be considered paralogous
23
23
  :return: Tuple of (filtered_train_data, filtered_test_data)
24
24
  """
25
- print(f"\tStarting paralogy removal process...")
25
+ print("\tStarting paralogy removal process...")
26
26
  print(f"\tInitial train set size: {len(train_data[0])}")
27
27
  print(f"\tInitial test set size: {len(test_data[0])}")
28
28
  train_seqs = train_data[5] # SEQ is at index 5
@@ -44,7 +44,7 @@ def remove_paralogous_sequences(train_data, test_data, min_identity, min_coverag
44
44
  filtered_test_data = [[] for _ in range(len(test_data))]
45
45
  paralogous_count = 0
46
46
  total_count = len(test_data[5])
47
- fw = open(f"{output_dir}removed_paralogs_{exp}.txt", "w")
47
+ fw = open(os.path.join(output_dir, f"removed_paralogs_{exp}.txt"), "w")
48
48
  print("\tStarting to process test sequences...")
49
49
  for i in range(total_count): # Iterate over test sequences
50
50
  test_seq = test_data[5][i]
@@ -65,7 +65,7 @@ def remove_paralogous_sequences(train_data, test_data, min_identity, min_coverag
65
65
  # Log progress every 1000 sequences
66
66
  if (i + 1) % 1000 == 0:
67
67
  print(f"\tProcessed {i + 1}/{total_count} sequences...")
68
- print(f"\tParalogy removal process completed.")
68
+ print("\tParalogy removal process completed.")
69
69
  print(f"\tNumber of paralogous sequences removed: {paralogous_count}")
70
70
  print(f"\tFinal {exp} set size: {len(filtered_test_data[0])}")
71
71
  print(f"\tPercentage of {exp} set removed: {(paralogous_count / total_count) * 100:.2f}%")
@@ -77,7 +77,7 @@ def write_h5_file(output_dir, data_type, data):
77
77
  """
78
78
  Write the data to an h5 file.
79
79
  """
80
- h5fname = output_dir + f'datafile_{data_type}.h5'
80
+ h5fname = os.path.join(output_dir, f'datafile_{data_type}.h5')
81
81
  h5f = h5py.File(h5fname, 'w')
82
82
  dt = h5py.string_dtype(encoding='utf-8')
83
83
 
@@ -6,11 +6,11 @@ Description: Functions to process sequences to/from .h5 datasets.
6
6
  """
7
7
 
8
8
  import os
9
+ import warnings
9
10
  import numpy as np
10
11
  from math import ceil
11
12
  import gffutils
12
13
  import random
13
- from sklearn.metrics import average_precision_score
14
14
  from openspliceai.constants import *
15
15
 
16
16
  def check_and_count_motifs(seq, labels, donor_motif_counts, acceptor_motif_counts):
@@ -62,7 +62,6 @@ def split_chromosomes(seq_dict, method='random', split_ratio=0.8):
62
62
  print("Chromosome lengths: ", chromosome_lengths)
63
63
  if method == 'random':
64
64
  total_length = sum(chromosome_lengths.values())
65
- target_train_length = total_length * split_ratio
66
65
  target_test_length = total_length * (1-split_ratio)
67
66
  chromosomes = list(chromosome_lengths.keys())
68
67
  random.shuffle(chromosomes)
@@ -90,7 +89,19 @@ def split_chromosomes(seq_dict, method='random', split_ratio=0.8):
90
89
  test_chroms = {
91
90
  'chr1': 0, 'chr3': 0, 'chr5': 0, 'chr7': 0, 'chr9': 0
92
91
  }
93
- else:
92
+ # Warn loudly if the genome's sequence names don't match the hardcoded UCSC-style
93
+ # human chromosome names -- otherwise every gene is silently skipped downstream,
94
+ # producing an (almost) empty dataset with no error.
95
+ present = set(seq_dict.keys())
96
+ requested = set(train_chroms) | set(test_chroms)
97
+ if present.isdisjoint(requested):
98
+ warnings.warn(
99
+ "split-method 'human' expects UCSC-style chromosome names (chr1, chr2, ...), "
100
+ f"but none were found in the genome (e.g. {sorted(present)[:3]}). All genes "
101
+ "will be skipped -- use --split-method random, or rename the sequences.",
102
+ stacklevel=2,
103
+ )
104
+ else:
94
105
  raise ValueError("Invalid chromosome split method. Use 'random' or 'human'.")
95
106
  return train_chroms, test_chroms
96
107
 
@@ -9,7 +9,6 @@ import h5py
9
9
  import torch
10
10
  import matplotlib.pyplot as plt
11
11
  import time
12
- import h5py
13
12
 
14
13
  def verify_h5(args):
15
14
  """
@@ -44,9 +43,12 @@ def verify_h5(args):
44
43
  Y0_tensor = torch.from_numpy(hf['Y0'][:])
45
44
  print(f"X0 shape: {X0_tensor.shape}, Y0 shape: {Y0_tensor.shape}")
46
45
 
47
- # process a specific dataset ('X3') for visualization
48
- x = torch.from_numpy(hf['X3'][:]).float()
49
- y = torch.from_numpy(hf['Y3'][:])
46
+ # process a representative chunk (the last available) for visualization.
47
+ # The dataset may have only a handful of chunks (X0, X1, ...), so pick the
48
+ # last one that exists rather than a hardcoded index.
49
+ last_idx = max((int(k[1:]) for k in hf.keys() if k.startswith('X')))
50
+ x = torch.from_numpy(hf[f'X{last_idx}'][:]).float()
51
+ y = torch.from_numpy(hf[f'Y{last_idx}'][:])
50
52
  print(f"x[0].shape: {x[0].shape}, y[0].shape: {y[0].shape}")
51
53
 
52
54
  # plot the sum of the last entry in the 'X3' dataset along its rows
@@ -2,10 +2,10 @@ __author__ = "Kuan-Hao Chao"
2
2
  __contact__ = "kuanhao.chao@gmail.com"
3
3
  __copyright__ = "Copyright 2025, Kuan-Hao Chao, Alan Mao"
4
4
  __credits__ = ["Kuan-Hao Chao", "Alan Mao"]
5
- __date__ = "2025/03/21"
5
+ __date__ = "2026/06/23"
6
6
  __deprecated__ = False
7
7
  __email__ = "kuanhao.chao@gmail.com"
8
8
  __license__ = "GPL-3.0"
9
9
  __maintainer__ = "developer"
10
10
  __status__ = "Kuan-Hao Chao"
11
- __version__ = "0.0.5"
11
+ __version__ = "0.0.7"
@@ -6,12 +6,9 @@ Description: Merge dataset.h5 files.
6
6
  """
7
7
 
8
8
  import h5py
9
- import numpy as np
10
- import sys, os
9
+ import os
11
10
  import time
12
11
  # from utils import *
13
- import argparse
14
- import openspliceai.create_data.utils as utils
15
12
 
16
13
  donor_motif_counts = {} # Initialize counts
17
14
  acceptor_motif_counts = {} # Initialize counts