OpenSpliceai 0.0.4__tar.gz → 0.0.6__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.
- openspliceai-0.0.6/MANIFEST.in +2 -0
- {openspliceai-0.0.4/openspliceai.egg-info → openspliceai-0.0.6}/PKG-INFO +40 -8
- {openspliceai-0.0.4 → openspliceai-0.0.6}/README.md +28 -6
- openspliceai-0.0.6/openspliceai/__init__.py +1 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/calibrate/calibrate.py +15 -6
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/calibrate/temperature_scaling_site_only.py +1 -3
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/create_data/create_datafile.py +22 -2
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/create_data/create_dataset.py +10 -3
- openspliceai-0.0.6/openspliceai/create_data/gff_to_tsv.py +124 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/create_data/paralogs.py +16 -16
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/create_data/utils.py +49 -4
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/create_data/verify_h5_file.py +6 -4
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/header.py +1 -1
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/merge_data/merge_dataset.py +1 -4
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/openspliceai.py +19 -3
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/predict/predict.py +119 -55
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/predict/utils.py +2 -1
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/train/train.py +14 -6
- openspliceai-0.0.6/openspliceai/train_base/openspliceai.py +141 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/train_base/utils.py +57 -10
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/transfer/transfer.py +21 -8
- openspliceai-0.0.6/openspliceai/variant/annotations/grch37.txt +20275 -0
- openspliceai-0.0.6/openspliceai/variant/annotations/grch38.txt +19306 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/variant/utils.py +74 -21
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/variant/variant.py +16 -5
- {openspliceai-0.0.4 → openspliceai-0.0.6/openspliceai.egg-info}/PKG-INFO +40 -8
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai.egg-info/SOURCES.txt +4 -1
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai.egg-info/requires.txt +10 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/setup.py +7 -2
- openspliceai-0.0.4/MANIFEST.in +0 -1
- openspliceai-0.0.4/openspliceai/__init__.py +0 -1
- openspliceai-0.0.4/openspliceai/train_base/openspliceai.py +0 -72
- {openspliceai-0.0.4 → openspliceai-0.0.6}/LICENSE +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/logo/jhu-logo-dark.png +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/logo/logo_black.png +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/logo/logo_white.png +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/calibrate/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/calibrate/calibrate_utils.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/calibrate/model_utils.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/calibrate/temperature_scaling.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/calibrate/visualization.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/constants.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/create_data/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/merge_data/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/predict/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/test/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/test/test.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/train/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/train_base/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/transfer/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/variant/__init__.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/variant/get_anno.py +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai.egg-info/dependency_links.txt +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai.egg-info/entry_points.txt +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai.egg-info/top_level.txt +0 -0
- {openspliceai-0.0.4 → openspliceai-0.0.6}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: openspliceai
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.6
|
|
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
|
|
@@ -24,20 +24,35 @@ Requires-Dist: matplotlib>=3.8.3
|
|
|
24
24
|
Requires-Dist: matplotlib-inline>=0.1.7
|
|
25
25
|
Requires-Dist: psutil>=5.9.2
|
|
26
26
|
Requires-Dist: mappy>=2.28
|
|
27
|
+
Provides-Extra: test
|
|
28
|
+
Requires-Dist: pytest>=7; extra == "test"
|
|
29
|
+
Requires-Dist: pytest-cov>=4; extra == "test"
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
32
|
+
Requires-Dist: pytest-cov>=4; extra == "dev"
|
|
33
|
+
Requires-Dist: ruff>=0.4; extra == "dev"
|
|
34
|
+
Requires-Dist: pre-commit>=3; extra == "dev"
|
|
27
35
|
Dynamic: author
|
|
28
36
|
Dynamic: author-email
|
|
29
37
|
Dynamic: description
|
|
30
38
|
Dynamic: description-content-type
|
|
31
39
|
Dynamic: home-page
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
Dynamic: provides-extra
|
|
32
42
|
Dynamic: requires-dist
|
|
33
43
|
Dynamic: requires-python
|
|
34
44
|
Dynamic: summary
|
|
35
45
|
|
|
36
|
-
<
|
|
46
|
+
<p align="center">
|
|
47
|
+
<picture>
|
|
48
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/Kuanhao-Chao/OpenSpliceAI/main/logo/logo_white.png">
|
|
49
|
+
<img alt="OpenSpliceAI" src="https://raw.githubusercontent.com/Kuanhao-Chao/OpenSpliceAI/main/logo/logo_black.png" width="90%">
|
|
50
|
+
</picture>
|
|
51
|
+
</p>
|
|
37
52
|
|
|
38
53
|
|
|
39
54
|
<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>
|
|
40
|
-
<a class="reference external image-reference" href="https://img.shields.io/badge/version-v.0.0.
|
|
55
|
+
<a class="reference external image-reference" href="https://img.shields.io/badge/version-v.0.0.6-blue"><img alt="https://img.shields.io/badge/version-v.0.0.6-blue" src="https://img.shields.io/badge/version-v.0.0.6-blue"></a>
|
|
41
56
|
<a class="reference external image-reference" href="https://pepy.tech/project/openspliceai"><img alt="https://static.pepy.tech/personalized-badge/openspliceai?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=PyPi%20downloads" src="https://static.pepy.tech/personalized-badge/openspliceai?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=PyPi%20downloads"></a>
|
|
42
57
|
<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&logo=github&label=Download" src="https://img.shields.io/github/downloads/Kuanhao-Chao/OpenSpliceAI/total.svg?style=social&logo=github&label=Download"></a>
|
|
43
58
|
<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>
|
|
@@ -97,11 +112,10 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
|
|
|
97
112
|
<section id="cite-us">
|
|
98
113
|
<h1>Cite Us<a class="headerlink" href="#cite-us" title="Permalink to this heading">#</a></h1>
|
|
99
114
|
<p>If you use OpenSpliceAI in your research, please cite our work as well as the original SpliceAI paper:</p>
|
|
100
|
-
<p>Kuan-Hao Chao, Alan Mao, Anqi Liu, Mihaela Pertea, and Steven L. Salzberg. <i>"OpenSpliceAI
|
|
101
|
-
<a href="https://khchao.com/" target="_blank"> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> </a> </p>
|
|
115
|
+
<p>Kuan-Hao Chao, Alan Mao, Anqi Liu, Mihaela Pertea, and Steven L. Salzberg. <i>"OpenSpliceAI provides an efficient modular implementation of SpliceAI enabling easy retraining across nonhuman species"</i> <a href="https://doi.org/10.7554/eLife.107454.3" target="_blank"><b><i>eLife</i> 14:RP107454</b></a>.
|
|
102
116
|
|
|
103
117
|
<p>Kishore Jaganathan, Sofia Kyriazopoulou Panagiotopoulou, Jeremy F. McRae, Siavash Fazel Darbandi, David Knowles, Yang I. Li, Jack A. Kosmicki, Juan Arbelaez, Wenwu Cui, Grace B. Schwartz, Eric D. Chow, Efstathios Kanterakis, Hong Gao, Amirali Kia, Serafim Batzoglou, Stephan J. Sanders, and Kyle Kai-How Farh. <i>"Predicting splicing from primary sequence with deep learning"</i> <b>Cell</b>.
|
|
104
|
-
|
|
118
|
+
|
|
105
119
|
<div class="line"><br></div>
|
|
106
120
|
</div>
|
|
107
121
|
</section>
|
|
@@ -121,6 +135,22 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
|
|
|
121
135
|
<div class="line"><br></div>
|
|
122
136
|
</div>
|
|
123
137
|
</section>
|
|
138
|
+
<section id="development-testing">
|
|
139
|
+
<h1>Development & Testing<a class="headerlink" href="#development-testing" title="Permalink to this heading">#</a></h1>
|
|
140
|
+
<p>Install the package with its development dependencies (pytest, pytest-cov, ruff, pre-commit) from a clone of the repository:</p>
|
|
141
|
+
<pre><code>pip install -e '.[dev]'</code></pre>
|
|
142
|
+
<p><strong>Tests</strong> live under <code>tests/</code> (<code>unit</code> / <code>integration</code> / <code>regression</code>) and run on CPU only:</p>
|
|
143
|
+
<pre><code>pytest -m "not slow and not integration" # fast inner loop
|
|
144
|
+
pytest # full suite</code></pre>
|
|
145
|
+
<p>Tests are tagged with markers (declared in <code>pytest.ini</code>) — <code>integration</code>, <code>slow</code>, <code>gpu</code>, and <code>keras</code> (auto-skipped when TensorFlow is absent) — selectable with <code>-m</code>, e.g. <code>pytest -m integration</code>.</p>
|
|
146
|
+
<p><strong>Lint and pre-commit hooks</strong> (configured in <code>ruff.toml</code> and <code>.pre-commit-config.yaml</code>):</p>
|
|
147
|
+
<pre><code>ruff check . # lint (add --fix to auto-fix)
|
|
148
|
+
pre-commit install # run ruff + checks on every commit</code></pre>
|
|
149
|
+
<p>See the <a class="reference external" href="https://ccb.jhu.edu/openspliceai/">full documentation</a> for the complete development and testing guide.</p>
|
|
150
|
+
<div class="line-block">
|
|
151
|
+
<div class="line"><br></div>
|
|
152
|
+
</div>
|
|
153
|
+
</section>
|
|
124
154
|
<section id="table-of-contents">
|
|
125
155
|
<h1>Table of Contents<a class="headerlink" href="#table-of-contents" title="Permalink to this heading">#</a></h1>
|
|
126
156
|
<div class="toctree-wrapper compound">
|
|
@@ -239,5 +269,7 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
|
|
|
239
269
|
<div class="line"><br></div>
|
|
240
270
|
<div class="line"><br></div>
|
|
241
271
|
</div>
|
|
242
|
-
<
|
|
272
|
+
<p align="center">
|
|
273
|
+
<img alt="Johns Hopkins University" src="logo/jhu-logo-dark.png" width="40%">
|
|
274
|
+
</p>
|
|
243
275
|
</section>
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
<
|
|
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.
|
|
10
|
+
<a class="reference external image-reference" href="https://img.shields.io/badge/version-v.0.0.6-blue"><img alt="https://img.shields.io/badge/version-v.0.0.6-blue" src="https://img.shields.io/badge/version-v.0.0.6-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&units=abbreviation&left_color=grey&right_color=blue&left_text=PyPi%20downloads" src="https://static.pepy.tech/personalized-badge/openspliceai?period=total&units=abbreviation&left_color=grey&right_color=blue&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&logo=github&label=Download" src="https://img.shields.io/github/downloads/Kuanhao-Chao/OpenSpliceAI/total.svg?style=social&logo=github&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>
|
|
@@ -62,11 +67,10 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
|
|
|
62
67
|
<section id="cite-us">
|
|
63
68
|
<h1>Cite Us<a class="headerlink" href="#cite-us" title="Permalink to this heading">#</a></h1>
|
|
64
69
|
<p>If you use OpenSpliceAI in your research, please cite our work as well as the original SpliceAI paper:</p>
|
|
65
|
-
<p>Kuan-Hao Chao, Alan Mao, Anqi Liu, Mihaela Pertea, and Steven L. Salzberg. <i>"OpenSpliceAI
|
|
66
|
-
<a href="https://khchao.com/" target="_blank"> <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> </a> </p>
|
|
70
|
+
<p>Kuan-Hao Chao, Alan Mao, Anqi Liu, Mihaela Pertea, and Steven L. Salzberg. <i>"OpenSpliceAI provides an efficient modular implementation of SpliceAI enabling easy retraining across nonhuman species"</i> <a href="https://doi.org/10.7554/eLife.107454.3" target="_blank"><b><i>eLife</i> 14:RP107454</b></a>.
|
|
67
71
|
|
|
68
72
|
<p>Kishore Jaganathan, Sofia Kyriazopoulou Panagiotopoulou, Jeremy F. McRae, Siavash Fazel Darbandi, David Knowles, Yang I. Li, Jack A. Kosmicki, Juan Arbelaez, Wenwu Cui, Grace B. Schwartz, Eric D. Chow, Efstathios Kanterakis, Hong Gao, Amirali Kia, Serafim Batzoglou, Stephan J. Sanders, and Kyle Kai-How Farh. <i>"Predicting splicing from primary sequence with deep learning"</i> <b>Cell</b>.
|
|
69
|
-
|
|
73
|
+
|
|
70
74
|
<div class="line"><br></div>
|
|
71
75
|
</div>
|
|
72
76
|
</section>
|
|
@@ -86,6 +90,22 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
|
|
|
86
90
|
<div class="line"><br></div>
|
|
87
91
|
</div>
|
|
88
92
|
</section>
|
|
93
|
+
<section id="development-testing">
|
|
94
|
+
<h1>Development & Testing<a class="headerlink" href="#development-testing" title="Permalink to this heading">#</a></h1>
|
|
95
|
+
<p>Install the package with its development dependencies (pytest, pytest-cov, ruff, pre-commit) from a clone of the repository:</p>
|
|
96
|
+
<pre><code>pip install -e '.[dev]'</code></pre>
|
|
97
|
+
<p><strong>Tests</strong> live under <code>tests/</code> (<code>unit</code> / <code>integration</code> / <code>regression</code>) and run on CPU only:</p>
|
|
98
|
+
<pre><code>pytest -m "not slow and not integration" # fast inner loop
|
|
99
|
+
pytest # full suite</code></pre>
|
|
100
|
+
<p>Tests are tagged with markers (declared in <code>pytest.ini</code>) — <code>integration</code>, <code>slow</code>, <code>gpu</code>, and <code>keras</code> (auto-skipped when TensorFlow is absent) — selectable with <code>-m</code>, e.g. <code>pytest -m integration</code>.</p>
|
|
101
|
+
<p><strong>Lint and pre-commit hooks</strong> (configured in <code>ruff.toml</code> and <code>.pre-commit-config.yaml</code>):</p>
|
|
102
|
+
<pre><code>ruff check . # lint (add --fix to auto-fix)
|
|
103
|
+
pre-commit install # run ruff + checks on every commit</code></pre>
|
|
104
|
+
<p>See the <a class="reference external" href="https://ccb.jhu.edu/openspliceai/">full documentation</a> for the complete development and testing guide.</p>
|
|
105
|
+
<div class="line-block">
|
|
106
|
+
<div class="line"><br></div>
|
|
107
|
+
</div>
|
|
108
|
+
</section>
|
|
89
109
|
<section id="table-of-contents">
|
|
90
110
|
<h1>Table of Contents<a class="headerlink" href="#table-of-contents" title="Permalink to this heading">#</a></h1>
|
|
91
111
|
<div class="toctree-wrapper compound">
|
|
@@ -204,5 +224,7 @@ Annotates VCF files with delta scores and positions to evaluate the impact of ge
|
|
|
204
224
|
<div class="line"><br></div>
|
|
205
225
|
<div class="line"><br></div>
|
|
206
226
|
</div>
|
|
207
|
-
<
|
|
227
|
+
<p align="center">
|
|
228
|
+
<img alt="Johns Hopkins University" src="logo/jhu-logo-dark.png" width="40%">
|
|
229
|
+
</p>
|
|
208
230
|
</section>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = 'v0.0.6'
|
|
@@ -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(
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
{openspliceai-0.0.4 → openspliceai-0.0.6}/openspliceai/calibrate/temperature_scaling_site_only.py
RENAMED
|
@@ -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
|
|
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()
|
|
@@ -157,10 +167,20 @@ def create_datafile(args):
|
|
|
157
167
|
test_data = get_sequences_and_labels(db, args.output_dir, seq_dict, TEST_CHROM_GROUP, 'test', parse_type=args.parse_type, biotype=args.biotype, canonical_only=args.canonical_only, write_fasta=args.write_fasta)
|
|
158
168
|
if args.remove_paralogs:
|
|
159
169
|
# Remove homologous sequences
|
|
160
|
-
print("> Removing homologous sequences...")
|
|
161
|
-
train_data, test_data = paralogs.remove_paralogous_sequences(train_data, test_data, args.min_identity, args.min_coverage, args.output_dir)
|
|
170
|
+
print("> Removing homologous sequences in test...")
|
|
171
|
+
train_data, test_data = paralogs.remove_paralogous_sequences(train_data, test_data, args.min_identity, args.min_coverage, args.output_dir, "test")
|
|
172
|
+
|
|
173
|
+
# Split the training data into training and validation sets (90:10 split)
|
|
174
|
+
print("> Splitting training data into training and validation sets...")
|
|
175
|
+
train_data, val_data = utils.split_train_val(train_data, args.val_split_ratio)
|
|
176
|
+
if args.remove_paralogs:
|
|
177
|
+
# Remove homologous sequences
|
|
178
|
+
print("> Removing homologous sequences in validation...")
|
|
179
|
+
train_data, val_data = paralogs.remove_paralogous_sequences(train_data, val_data, args.min_identity, args.min_coverage, args.output_dir, "validation")
|
|
180
|
+
|
|
162
181
|
# Write the filtered data to h5 files
|
|
163
182
|
paralogs.write_h5_file(args.output_dir, "train", train_data)
|
|
183
|
+
paralogs.write_h5_file(args.output_dir, "validation", val_data)
|
|
164
184
|
paralogs.write_h5_file(args.output_dir, "test", test_data)
|
|
165
185
|
utils.print_motif_counts(donor_motif_counts, acceptor_motif_counts)
|
|
166
186
|
print("--- %s seconds ---" % (time.process_time() - start_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
|
|
|
@@ -24,6 +33,7 @@ def create_dataset(args):
|
|
|
24
33
|
elif args.chr_split == 'train-test':
|
|
25
34
|
dataset_ls.append('test')
|
|
26
35
|
dataset_ls.append('train')
|
|
36
|
+
dataset_ls.append('validation')
|
|
27
37
|
for dataset_type in dataset_ls:
|
|
28
38
|
print(("\tProcessing %s ..." % dataset_type))
|
|
29
39
|
if args.biotype =="non-coding":
|
|
@@ -37,9 +47,6 @@ def create_dataset(args):
|
|
|
37
47
|
with h5py.File(input_file, 'r') as h5f:
|
|
38
48
|
SEQ = h5f['SEQ'][:]
|
|
39
49
|
LABEL = h5f['LABEL'][:]
|
|
40
|
-
STRAND = h5f['STRAND'][:]
|
|
41
|
-
TX_START = h5f['TX_START'][:]
|
|
42
|
-
TX_END = h5f['TX_END'][:]
|
|
43
50
|
|
|
44
51
|
print(f"\tWriting {output_file} ... ")
|
|
45
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()
|
|
@@ -12,7 +12,7 @@ import h5py
|
|
|
12
12
|
import tempfile
|
|
13
13
|
import os
|
|
14
14
|
|
|
15
|
-
def remove_paralogous_sequences(train_data, test_data, min_identity, min_coverage, output_dir):
|
|
15
|
+
def remove_paralogous_sequences(train_data, test_data, min_identity, min_coverage, output_dir, exp):
|
|
16
16
|
"""
|
|
17
17
|
Remove paralogous sequences between train and test datasets using mappy.
|
|
18
18
|
|
|
@@ -22,9 +22,9 @@ 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(
|
|
26
|
-
print(f"
|
|
27
|
-
print(f"
|
|
25
|
+
print("\tStarting paralogy removal process...")
|
|
26
|
+
print(f"\tInitial train set size: {len(train_data[0])}")
|
|
27
|
+
print(f"\tInitial test set size: {len(test_data[0])}")
|
|
28
28
|
train_seqs = train_data[5] # SEQ is at index 5
|
|
29
29
|
# Create a temporary file with training sequences
|
|
30
30
|
with tempfile.NamedTemporaryFile(mode='w', delete=False) as temp_file:
|
|
@@ -32,20 +32,20 @@ def remove_paralogous_sequences(train_data, test_data, min_identity, min_coverag
|
|
|
32
32
|
temp_file.write(f">seq{i}\n{seq}\n")
|
|
33
33
|
temp_filename = temp_file.name
|
|
34
34
|
# Create a mappy index from the training sequences
|
|
35
|
-
print("
|
|
35
|
+
print("\tCreating mappy index from training sequences...")
|
|
36
36
|
try:
|
|
37
37
|
aligner = mp.Aligner(temp_filename, preset="map-ont")
|
|
38
38
|
if not aligner:
|
|
39
|
-
raise Exception("
|
|
39
|
+
raise Exception("\tFailed to load/build index")
|
|
40
40
|
except Exception as e:
|
|
41
|
-
logging.error(f"
|
|
41
|
+
logging.error(f"\tError creating mappy aligner: {str(e)}")
|
|
42
42
|
os.unlink(temp_filename)
|
|
43
43
|
return train_data, test_data
|
|
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"{
|
|
48
|
-
print("
|
|
47
|
+
fw = open(os.path.join(output_dir, f"removed_paralogs_{exp}.txt"), "w")
|
|
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]
|
|
51
51
|
is_paralogous = False
|
|
@@ -55,7 +55,7 @@ def remove_paralogous_sequences(train_data, test_data, min_identity, min_coverag
|
|
|
55
55
|
fw.write(f"{test_data[0][i]}\t{identity}\t{coverage}\n")
|
|
56
56
|
if identity >= min_identity and coverage >= min_coverage:
|
|
57
57
|
# fw.write(f"{test_data[0][i]}\t{identity}\t{coverage}\n")
|
|
58
|
-
print(f"\tParalogs detected: Identity: {identity}, Coverage: {coverage}")
|
|
58
|
+
print(f"\t\tParalogs detected: Identity: {identity}, Coverage: {coverage}")
|
|
59
59
|
is_paralogous = True
|
|
60
60
|
paralogous_count += 1
|
|
61
61
|
break
|
|
@@ -64,11 +64,11 @@ def remove_paralogous_sequences(train_data, test_data, min_identity, min_coverag
|
|
|
64
64
|
filtered_test_data[j].append(test_data[j][i])
|
|
65
65
|
# Log progress every 1000 sequences
|
|
66
66
|
if (i + 1) % 1000 == 0:
|
|
67
|
-
print(f"
|
|
68
|
-
print(
|
|
69
|
-
print(f"
|
|
70
|
-
print(f"
|
|
71
|
-
print(f"
|
|
67
|
+
print(f"\tProcessed {i + 1}/{total_count} sequences...")
|
|
68
|
+
print("\tParalogy removal process completed.")
|
|
69
|
+
print(f"\tNumber of paralogous sequences removed: {paralogous_count}")
|
|
70
|
+
print(f"\tFinal {exp} set size: {len(filtered_test_data[0])}")
|
|
71
|
+
print(f"\tPercentage of {exp} set removed: {(paralogous_count / total_count) * 100:.2f}%")
|
|
72
72
|
fw.close()
|
|
73
73
|
return train_data, filtered_test_data
|
|
74
74
|
|
|
@@ -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
|
|
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
|
-
|
|
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
|
|
|
@@ -203,4 +214,38 @@ def create_datapoints(seq, label):
|
|
|
203
214
|
Xd, Yd = reformat_data(X0, Y0)
|
|
204
215
|
X, Y = one_hot_encode(Xd, Yd)
|
|
205
216
|
|
|
206
|
-
return X, Y
|
|
217
|
+
return X, Y
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def split_train_val(data, val_split_ratio):
|
|
221
|
+
"""
|
|
222
|
+
Split training data into training and validation sets.
|
|
223
|
+
|
|
224
|
+
Args:
|
|
225
|
+
data (list of lists): [NAME, CHROM, STRAND, TX_START, TX_END, SEQ, LABEL]
|
|
226
|
+
val_split_ratio (float): proportion of data to use for validation (e.g., 0.1 for 10%)
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
tuple: (train_data, val_data), each a list of lists with the same structure as input
|
|
230
|
+
"""
|
|
231
|
+
# Transpose data to a list of records
|
|
232
|
+
records = list(zip(*data))
|
|
233
|
+
# Shuffle records in place for random split
|
|
234
|
+
random.shuffle(records)
|
|
235
|
+
total = len(records)
|
|
236
|
+
val_size = int(total * val_split_ratio)
|
|
237
|
+
|
|
238
|
+
# Split into validation and training records
|
|
239
|
+
val_records = records[:val_size]
|
|
240
|
+
train_records = records[val_size:]
|
|
241
|
+
# Handle case where no records
|
|
242
|
+
if not train_records:
|
|
243
|
+
train_data = [[] for _ in data]
|
|
244
|
+
else:
|
|
245
|
+
train_data = [list(field) for field in zip(*train_records)]
|
|
246
|
+
if not val_records:
|
|
247
|
+
val_data = [[] for _ in data]
|
|
248
|
+
else:
|
|
249
|
+
val_data = [list(field) for field in zip(*val_records)]
|
|
250
|
+
print(f"Split data into {len(train_data[0])} training records and {len(val_data[0])} validation records.")
|
|
251
|
+
return train_data, val_data
|
|
@@ -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
|
|
48
|
-
|
|
49
|
-
|
|
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
|