PersonalBPNet 0.7.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. personalbpnet-0.7.0/LICENSE +21 -0
  2. personalbpnet-0.7.0/PKG-INFO +106 -0
  3. personalbpnet-0.7.0/README.md +51 -0
  4. personalbpnet-0.7.0/pyproject.toml +55 -0
  5. personalbpnet-0.7.0/setup.cfg +4 -0
  6. personalbpnet-0.7.0/src/PersonalBPNet.egg-info/PKG-INFO +106 -0
  7. personalbpnet-0.7.0/src/PersonalBPNet.egg-info/SOURCES.txt +26 -0
  8. personalbpnet-0.7.0/src/PersonalBPNet.egg-info/dependency_links.txt +1 -0
  9. personalbpnet-0.7.0/src/PersonalBPNet.egg-info/entry_points.txt +4 -0
  10. personalbpnet-0.7.0/src/PersonalBPNet.egg-info/requires.txt +7 -0
  11. personalbpnet-0.7.0/src/PersonalBPNet.egg-info/top_level.txt +2 -0
  12. personalbpnet-0.7.0/src/cli/__init__.py +1 -0
  13. personalbpnet-0.7.0/src/cli/_common.py +233 -0
  14. personalbpnet-0.7.0/src/cli/clipnet.py +340 -0
  15. personalbpnet-0.7.0/src/cli/pausenet.py +189 -0
  16. personalbpnet-0.7.0/src/cli/tf.py +345 -0
  17. personalbpnet-0.7.0/src/personal_bpnet/__init__.py +20 -0
  18. personalbpnet-0.7.0/src/personal_bpnet/clipnet_pytorch.py +294 -0
  19. personalbpnet-0.7.0/src/personal_bpnet/clipnet_tensorflow.py +357 -0
  20. personalbpnet-0.7.0/src/personal_bpnet/losses.py +117 -0
  21. personalbpnet-0.7.0/src/personal_bpnet/personal_bpnet.py +276 -0
  22. personalbpnet-0.7.0/src/personal_bpnet/procapnet.py +256 -0
  23. personalbpnet-0.7.0/src/personal_bpnet/procapnet_orig.py +83 -0
  24. personalbpnet-0.7.0/src/personal_bpnet/utils.py +390 -0
  25. personalbpnet-0.7.0/tests/test_cli_common.py +74 -0
  26. personalbpnet-0.7.0/tests/test_losses.py +73 -0
  27. personalbpnet-0.7.0/tests/test_models.py +111 -0
  28. personalbpnet-0.7.0/tests/test_utils.py +104 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 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,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: PersonalBPNet
3
+ Version: 0.7.0
4
+ Summary: PyTorch BPNet-family models (CLIPNET, ProCapNet, PauseNet) for base-resolution genomic signal prediction, extending bpnetlite.
5
+ Author-email: Adam He <adamyhe@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Adam Youlin He
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/adamyhe/PersonalBPNet
29
+ Project-URL: Repository, https://github.com/adamyhe/PersonalBPNet
30
+ Project-URL: Issues, https://github.com/adamyhe/PersonalBPNet/issues
31
+ Project-URL: Changelog, https://github.com/adamyhe/PersonalBPNet/blob/main/CHANGELOG.md
32
+ Project-URL: Documentation, https://github.com/adamyhe/PersonalBPNet/tree/main/docs
33
+ Keywords: genomics,deep-learning,pytorch,bpnet,clipnet,pro-cap,regulatory-genomics
34
+ Classifier: Development Status :: 3 - Alpha
35
+ Classifier: Intended Audience :: Science/Research
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.9
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Programming Language :: Python :: 3.13
43
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
44
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
45
+ Requires-Python: >=3.9
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+ Requires-Dist: bpnet-lite>=1.0.0
49
+ Requires-Dist: tangermeme>=1.0.0
50
+ Requires-Dist: pyfaidx
51
+ Requires-Dist: numba
52
+ Provides-Extra: tf
53
+ Requires-Dist: h5py; extra == "tf"
54
+ Dynamic: license-file
55
+
56
+ # PersonalBPNet
57
+
58
+ A PyTorch library of [BPNet](https://github.com/jmschrei/bpnet-lite)-family models for predicting base-resolution genomic signal (e.g., PRO-cap read coverage) from DNA sequence, plus CLI tools for prediction and attribution.
59
+
60
+ - **PersonalBPNet** — `bpnetlite.bpnet.BPNet`, with a `fit()` that validates against a PyTorch `DataLoader` instead of holding the whole validation set in memory.
61
+ - **CLIPNET** — `PersonalBPNet` plus batch normalization; PyTorch port of the original TensorFlow [CLIPNET](https://github.com/Danko-Lab/clipnet).
62
+ - **ProCapNet** — `BPNet` with a masked profile loss, improving attributions (from the [ProCapNet paper](https://www.biorxiv.org/content/10.1101/2024.05.28.596138v2)).
63
+ - **PauseNet** — transfer-learns a base-resolution model to predict a single scalar phenotype per locus.
64
+
65
+ ## Install
66
+
67
+ With [uv](https://docs.astral.sh/uv/):
68
+
69
+ ```sh
70
+ uv add personalbpnet
71
+ ```
72
+
73
+ Or with pip:
74
+
75
+ ```sh
76
+ pip install personalbpnet
77
+ ```
78
+
79
+ To load TensorFlow-trained weights (requires `h5py`), install with the `tf` extra: `uv add "personalbpnet[tf]"` or `pip install "personalbpnet[tf]"`.
80
+
81
+ Installing from source, for local development, is covered in [CONTRIBUTING.md](CONTRIBUTING.md).
82
+
83
+ ## Documentation
84
+
85
+ | | |
86
+ | --- | --- |
87
+ | [docs/clipnet.md](docs/clipnet.md) | `PersonalBPNet` and `CLIPNET`, incl. pretrained weights |
88
+ | [docs/clipnet-tf.md](docs/clipnet-tf.md) | Porting the original TensorFlow CLIPNET weights |
89
+ | [docs/procapnet.md](docs/procapnet.md) | `ProCapNet` |
90
+ | [docs/pausenet.md](docs/pausenet.md) | `PauseNet` |
91
+ | [docs/cli.md](docs/cli.md) | `clipnet`, `pausenet`, and `clipnet_tf` command line tools |
92
+ | [CONTRIBUTING.md](CONTRIBUTING.md) | Installing from source and local development |
93
+
94
+ This package is under active development; APIs may change between releases. See [CHANGELOG.md](CHANGELOG.md).
95
+
96
+ ## Citing
97
+
98
+ If you use `PersonalBPNet`/`CLIPNET`/`ProCapNet`, or the underlying `BPNet` architecture (via the `bpnet-lite` dependency), please cite the corresponding paper (see [CITATION.cff](CITATION.cff)):
99
+
100
+ - Avsec et al. (2021). [Base-resolution models of transcription-factor binding reveal soft motif syntax](https://doi.org/10.1038/s41588-021-00782-6). *Nature Genetics* 53:354–366. — BPNet
101
+ - He & Danko (2024). [Dissection of core promoter syntax through single nucleotide resolution modeling of transcription initiation](https://www.biorxiv.org/content/10.1101/2024.03.13.583868). *bioRxiv*. — CLIPNET
102
+ - Cochran et al. (2024). [Dissecting the cis-regulatory syntax of transcription initiation with deep learning](https://www.biorxiv.org/content/10.1101/2024.05.28.596138). *bioRxiv*. — ProCapNet
103
+
104
+ ## License
105
+
106
+ [MIT](LICENSE)
@@ -0,0 +1,51 @@
1
+ # PersonalBPNet
2
+
3
+ A PyTorch library of [BPNet](https://github.com/jmschrei/bpnet-lite)-family models for predicting base-resolution genomic signal (e.g., PRO-cap read coverage) from DNA sequence, plus CLI tools for prediction and attribution.
4
+
5
+ - **PersonalBPNet** — `bpnetlite.bpnet.BPNet`, with a `fit()` that validates against a PyTorch `DataLoader` instead of holding the whole validation set in memory.
6
+ - **CLIPNET** — `PersonalBPNet` plus batch normalization; PyTorch port of the original TensorFlow [CLIPNET](https://github.com/Danko-Lab/clipnet).
7
+ - **ProCapNet** — `BPNet` with a masked profile loss, improving attributions (from the [ProCapNet paper](https://www.biorxiv.org/content/10.1101/2024.05.28.596138v2)).
8
+ - **PauseNet** — transfer-learns a base-resolution model to predict a single scalar phenotype per locus.
9
+
10
+ ## Install
11
+
12
+ With [uv](https://docs.astral.sh/uv/):
13
+
14
+ ```sh
15
+ uv add personalbpnet
16
+ ```
17
+
18
+ Or with pip:
19
+
20
+ ```sh
21
+ pip install personalbpnet
22
+ ```
23
+
24
+ To load TensorFlow-trained weights (requires `h5py`), install with the `tf` extra: `uv add "personalbpnet[tf]"` or `pip install "personalbpnet[tf]"`.
25
+
26
+ Installing from source, for local development, is covered in [CONTRIBUTING.md](CONTRIBUTING.md).
27
+
28
+ ## Documentation
29
+
30
+ | | |
31
+ | --- | --- |
32
+ | [docs/clipnet.md](docs/clipnet.md) | `PersonalBPNet` and `CLIPNET`, incl. pretrained weights |
33
+ | [docs/clipnet-tf.md](docs/clipnet-tf.md) | Porting the original TensorFlow CLIPNET weights |
34
+ | [docs/procapnet.md](docs/procapnet.md) | `ProCapNet` |
35
+ | [docs/pausenet.md](docs/pausenet.md) | `PauseNet` |
36
+ | [docs/cli.md](docs/cli.md) | `clipnet`, `pausenet`, and `clipnet_tf` command line tools |
37
+ | [CONTRIBUTING.md](CONTRIBUTING.md) | Installing from source and local development |
38
+
39
+ This package is under active development; APIs may change between releases. See [CHANGELOG.md](CHANGELOG.md).
40
+
41
+ ## Citing
42
+
43
+ If you use `PersonalBPNet`/`CLIPNET`/`ProCapNet`, or the underlying `BPNet` architecture (via the `bpnet-lite` dependency), please cite the corresponding paper (see [CITATION.cff](CITATION.cff)):
44
+
45
+ - Avsec et al. (2021). [Base-resolution models of transcription-factor binding reveal soft motif syntax](https://doi.org/10.1038/s41588-021-00782-6). *Nature Genetics* 53:354–366. — BPNet
46
+ - He & Danko (2024). [Dissection of core promoter syntax through single nucleotide resolution modeling of transcription initiation](https://www.biorxiv.org/content/10.1101/2024.03.13.583868). *bioRxiv*. — CLIPNET
47
+ - Cochran et al. (2024). [Dissecting the cis-regulatory syntax of transcription initiation with deep learning](https://www.biorxiv.org/content/10.1101/2024.05.28.596138). *bioRxiv*. — ProCapNet
48
+
49
+ ## License
50
+
51
+ [MIT](LICENSE)
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "PersonalBPNet"
7
+ version = "0.7.0"
8
+ description = "PyTorch BPNet-family models (CLIPNET, ProCapNet, PauseNet) for base-resolution genomic signal prediction, extending bpnetlite."
9
+ readme = "README.md"
10
+ authors = [{ name = "Adam He", email = "adamyhe@gmail.com" }]
11
+ license = { file = "LICENSE" }
12
+ keywords = [
13
+ "genomics",
14
+ "deep-learning",
15
+ "pytorch",
16
+ "bpnet",
17
+ "clipnet",
18
+ "pro-cap",
19
+ "regulatory-genomics",
20
+ ]
21
+ classifiers = [
22
+ "Development Status :: 3 - Alpha",
23
+ "Intended Audience :: Science/Research",
24
+ "License :: OSI Approved :: MIT License",
25
+ "Programming Language :: Python :: 3",
26
+ "Programming Language :: Python :: 3.9",
27
+ "Programming Language :: Python :: 3.10",
28
+ "Programming Language :: Python :: 3.11",
29
+ "Programming Language :: Python :: 3.12",
30
+ "Programming Language :: Python :: 3.13",
31
+ "Topic :: Scientific/Engineering :: Bio-Informatics",
32
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
33
+ ]
34
+ urls = { Homepage = "https://github.com/adamyhe/PersonalBPNet", Repository = "https://github.com/adamyhe/PersonalBPNet", Issues = "https://github.com/adamyhe/PersonalBPNet/issues", Changelog = "https://github.com/adamyhe/PersonalBPNet/blob/main/CHANGELOG.md", Documentation = "https://github.com/adamyhe/PersonalBPNet/tree/main/docs" }
35
+ requires-python = ">= 3.9"
36
+ dependencies = ["bpnet-lite>=1.0.0", "tangermeme>=1.0.0", "pyfaidx", "numba"]
37
+
38
+ [project.optional-dependencies]
39
+ tf = ["h5py"]
40
+
41
+ [tool.setuptools.packages.find]
42
+ where = ["src"]
43
+
44
+ [dependency-groups]
45
+ dev = [
46
+ "pytest>=8.4.2",
47
+ ]
48
+
49
+ [tool.pytest.ini_options]
50
+ testpaths = ["tests"]
51
+
52
+ [project.scripts]
53
+ clipnet = "cli.clipnet:cli"
54
+ pausenet = "cli.pausenet:cli"
55
+ clipnet_tf = "cli.tf:cli"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,106 @@
1
+ Metadata-Version: 2.4
2
+ Name: PersonalBPNet
3
+ Version: 0.7.0
4
+ Summary: PyTorch BPNet-family models (CLIPNET, ProCapNet, PauseNet) for base-resolution genomic signal prediction, extending bpnetlite.
5
+ Author-email: Adam He <adamyhe@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2024 Adam Youlin He
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/adamyhe/PersonalBPNet
29
+ Project-URL: Repository, https://github.com/adamyhe/PersonalBPNet
30
+ Project-URL: Issues, https://github.com/adamyhe/PersonalBPNet/issues
31
+ Project-URL: Changelog, https://github.com/adamyhe/PersonalBPNet/blob/main/CHANGELOG.md
32
+ Project-URL: Documentation, https://github.com/adamyhe/PersonalBPNet/tree/main/docs
33
+ Keywords: genomics,deep-learning,pytorch,bpnet,clipnet,pro-cap,regulatory-genomics
34
+ Classifier: Development Status :: 3 - Alpha
35
+ Classifier: Intended Audience :: Science/Research
36
+ Classifier: License :: OSI Approved :: MIT License
37
+ Classifier: Programming Language :: Python :: 3
38
+ Classifier: Programming Language :: Python :: 3.9
39
+ Classifier: Programming Language :: Python :: 3.10
40
+ Classifier: Programming Language :: Python :: 3.11
41
+ Classifier: Programming Language :: Python :: 3.12
42
+ Classifier: Programming Language :: Python :: 3.13
43
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
44
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
45
+ Requires-Python: >=3.9
46
+ Description-Content-Type: text/markdown
47
+ License-File: LICENSE
48
+ Requires-Dist: bpnet-lite>=1.0.0
49
+ Requires-Dist: tangermeme>=1.0.0
50
+ Requires-Dist: pyfaidx
51
+ Requires-Dist: numba
52
+ Provides-Extra: tf
53
+ Requires-Dist: h5py; extra == "tf"
54
+ Dynamic: license-file
55
+
56
+ # PersonalBPNet
57
+
58
+ A PyTorch library of [BPNet](https://github.com/jmschrei/bpnet-lite)-family models for predicting base-resolution genomic signal (e.g., PRO-cap read coverage) from DNA sequence, plus CLI tools for prediction and attribution.
59
+
60
+ - **PersonalBPNet** — `bpnetlite.bpnet.BPNet`, with a `fit()` that validates against a PyTorch `DataLoader` instead of holding the whole validation set in memory.
61
+ - **CLIPNET** — `PersonalBPNet` plus batch normalization; PyTorch port of the original TensorFlow [CLIPNET](https://github.com/Danko-Lab/clipnet).
62
+ - **ProCapNet** — `BPNet` with a masked profile loss, improving attributions (from the [ProCapNet paper](https://www.biorxiv.org/content/10.1101/2024.05.28.596138v2)).
63
+ - **PauseNet** — transfer-learns a base-resolution model to predict a single scalar phenotype per locus.
64
+
65
+ ## Install
66
+
67
+ With [uv](https://docs.astral.sh/uv/):
68
+
69
+ ```sh
70
+ uv add personalbpnet
71
+ ```
72
+
73
+ Or with pip:
74
+
75
+ ```sh
76
+ pip install personalbpnet
77
+ ```
78
+
79
+ To load TensorFlow-trained weights (requires `h5py`), install with the `tf` extra: `uv add "personalbpnet[tf]"` or `pip install "personalbpnet[tf]"`.
80
+
81
+ Installing from source, for local development, is covered in [CONTRIBUTING.md](CONTRIBUTING.md).
82
+
83
+ ## Documentation
84
+
85
+ | | |
86
+ | --- | --- |
87
+ | [docs/clipnet.md](docs/clipnet.md) | `PersonalBPNet` and `CLIPNET`, incl. pretrained weights |
88
+ | [docs/clipnet-tf.md](docs/clipnet-tf.md) | Porting the original TensorFlow CLIPNET weights |
89
+ | [docs/procapnet.md](docs/procapnet.md) | `ProCapNet` |
90
+ | [docs/pausenet.md](docs/pausenet.md) | `PauseNet` |
91
+ | [docs/cli.md](docs/cli.md) | `clipnet`, `pausenet`, and `clipnet_tf` command line tools |
92
+ | [CONTRIBUTING.md](CONTRIBUTING.md) | Installing from source and local development |
93
+
94
+ This package is under active development; APIs may change between releases. See [CHANGELOG.md](CHANGELOG.md).
95
+
96
+ ## Citing
97
+
98
+ If you use `PersonalBPNet`/`CLIPNET`/`ProCapNet`, or the underlying `BPNet` architecture (via the `bpnet-lite` dependency), please cite the corresponding paper (see [CITATION.cff](CITATION.cff)):
99
+
100
+ - Avsec et al. (2021). [Base-resolution models of transcription-factor binding reveal soft motif syntax](https://doi.org/10.1038/s41588-021-00782-6). *Nature Genetics* 53:354–366. — BPNet
101
+ - He & Danko (2024). [Dissection of core promoter syntax through single nucleotide resolution modeling of transcription initiation](https://www.biorxiv.org/content/10.1101/2024.03.13.583868). *bioRxiv*. — CLIPNET
102
+ - Cochran et al. (2024). [Dissecting the cis-regulatory syntax of transcription initiation with deep learning](https://www.biorxiv.org/content/10.1101/2024.05.28.596138). *bioRxiv*. — ProCapNet
103
+
104
+ ## License
105
+
106
+ [MIT](LICENSE)
@@ -0,0 +1,26 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ src/PersonalBPNet.egg-info/PKG-INFO
5
+ src/PersonalBPNet.egg-info/SOURCES.txt
6
+ src/PersonalBPNet.egg-info/dependency_links.txt
7
+ src/PersonalBPNet.egg-info/entry_points.txt
8
+ src/PersonalBPNet.egg-info/requires.txt
9
+ src/PersonalBPNet.egg-info/top_level.txt
10
+ src/cli/__init__.py
11
+ src/cli/_common.py
12
+ src/cli/clipnet.py
13
+ src/cli/pausenet.py
14
+ src/cli/tf.py
15
+ src/personal_bpnet/__init__.py
16
+ src/personal_bpnet/clipnet_pytorch.py
17
+ src/personal_bpnet/clipnet_tensorflow.py
18
+ src/personal_bpnet/losses.py
19
+ src/personal_bpnet/personal_bpnet.py
20
+ src/personal_bpnet/procapnet.py
21
+ src/personal_bpnet/procapnet_orig.py
22
+ src/personal_bpnet/utils.py
23
+ tests/test_cli_common.py
24
+ tests/test_losses.py
25
+ tests/test_models.py
26
+ tests/test_utils.py
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ clipnet = cli.clipnet:cli
3
+ clipnet_tf = cli.tf:cli
4
+ pausenet = cli.pausenet:cli
@@ -0,0 +1,7 @@
1
+ bpnet-lite>=1.0.0
2
+ tangermeme>=1.0.0
3
+ pyfaidx
4
+ numba
5
+
6
+ [tf]
7
+ h5py
@@ -0,0 +1,2 @@
1
+ cli
2
+ personal_bpnet
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,233 @@
1
+ # _common.py
2
+ # Author: Adam He <adamyhe@gmail.com>
3
+
4
+ """
5
+ Argparse and ensemble-loading helpers shared by the clipnet, pausenet, and
6
+ clipnet_tf CLIs.
7
+ """
8
+
9
+ import argparse
10
+ import os
11
+
12
+ import torch
13
+
14
+
15
+ def build_parent_parser(bed_fname_help=None):
16
+ """The -f/-b/-o/-m/-c/-bs/-v arguments common to every subcommand of every CLI
17
+ in this project. Callers may add further arguments to the returned parser
18
+ before passing it as a `parents=[...]` entry to `subparsers.add_parser`."""
19
+
20
+ parser = argparse.ArgumentParser(add_help=False)
21
+ parser.add_argument(
22
+ "-f",
23
+ "--fa_fname",
24
+ type=str,
25
+ required=True,
26
+ help="Path to uncompressed fasta file.",
27
+ )
28
+ parser.add_argument(
29
+ "-b",
30
+ "--bed_fname",
31
+ type=str,
32
+ required=True,
33
+ help=bed_fname_help
34
+ or "Path to bed file of regions to calculate predictions/attributions for.",
35
+ )
36
+ parser.add_argument(
37
+ "-o", "--out_fname", type=str, required=True, help="Path to output npz file"
38
+ )
39
+ parser.add_argument(
40
+ "-m",
41
+ "--model_fname",
42
+ type=str,
43
+ required=True,
44
+ help="Path to model directory or to specific model file to predict/attribute. "
45
+ "If a directory, loads and calculates average predictions/attributions across "
46
+ "all models in directory. If a specific model file, will only predict/attribute "
47
+ "that model. ",
48
+ )
49
+ parser.add_argument(
50
+ "-c",
51
+ "--chroms",
52
+ type=str,
53
+ nargs="+",
54
+ default=None,
55
+ help="Chromosomes to calculate attributions for. Defaults to all chromosomes.",
56
+ )
57
+ parser.add_argument(
58
+ "-bs",
59
+ "--batch_size",
60
+ type=int,
61
+ default=16,
62
+ help="Batch size to control VRAM usage. Defaults to 16.",
63
+ )
64
+ parser.add_argument(
65
+ "-v", "--verbose", action="store_true", help="Whether to print progress bars."
66
+ )
67
+ return parser
68
+
69
+
70
+ def add_shape_args(parser):
71
+ """The --in_window/--out_window/--n_filters/--n_layers arguments used to
72
+ reconstruct a model from a bare state dict, shared across clipnet/pausenet
73
+ predict/predict_tss/attribute subcommands."""
74
+
75
+ parser.add_argument(
76
+ "--in_window",
77
+ type=int,
78
+ default=2114,
79
+ help="Used to specify model input size. "
80
+ "Should not be needed unless using a custom model.",
81
+ )
82
+ parser.add_argument(
83
+ "--out_window",
84
+ type=int,
85
+ default=1000,
86
+ help="Used to specify model output size. "
87
+ "Should not be needed unless using a custom model.",
88
+ )
89
+ parser.add_argument(
90
+ "--n_filters",
91
+ type=int,
92
+ default=512,
93
+ help="Used to specify model convolutions. "
94
+ "Should not be needed unless using a custom model.",
95
+ )
96
+ parser.add_argument(
97
+ "--n_layers",
98
+ type=int,
99
+ default=8,
100
+ help="Used to specify model layers. "
101
+ "Should not be needed unless using a custom model.",
102
+ )
103
+
104
+
105
+ def add_attribute_args(parser):
106
+ """The -a/-s/-y/-n/-r arguments shared by every CLI's attribute subcommand."""
107
+
108
+ parser.add_argument(
109
+ "-a",
110
+ "--attribute_type",
111
+ type=str,
112
+ default="counts",
113
+ choices={"counts", "profile"},
114
+ help="The type of attribution to calculate.",
115
+ )
116
+ parser.add_argument(
117
+ "-s",
118
+ "--save_ohe",
119
+ type=str,
120
+ default=None,
121
+ help="Where to save OHE of sequences. Defaults to not saving. "
122
+ "Set this & hypothetical if you intend to use these attributions for "
123
+ "tfmodisco-lite.",
124
+ )
125
+ parser.add_argument(
126
+ "-y",
127
+ "--hypothetical",
128
+ action="store_true",
129
+ help="Whether to use hypothetical attributions. Defaults to False. "
130
+ "Set this & save_ohe if you intend to use these attributions for "
131
+ "tfmodisco-lite.",
132
+ )
133
+ parser.add_argument(
134
+ "-n",
135
+ "--n_shuffles",
136
+ type=int,
137
+ default=20,
138
+ help="Number of dinucleotide shuffles for DeepLIFT/SHAP. Defaults to 20.",
139
+ )
140
+ parser.add_argument(
141
+ "-r",
142
+ "--random_state",
143
+ type=int,
144
+ default=47,
145
+ help="Random seed. Defaults to 47.",
146
+ )
147
+
148
+
149
+ def resolve_model_paths(model_fname, pattern="f{i}.torch", n=9):
150
+ """If `model_fname` is a directory, returns the `n` replicate paths matching
151
+ `pattern` (formatted with i=1..n) inside it; otherwise returns `[model_fname]`
152
+ unchanged."""
153
+
154
+ if os.path.isdir(model_fname):
155
+ return [os.path.join(model_fname, pattern.format(i=i)) for i in range(1, n + 1)]
156
+ return [model_fname]
157
+
158
+
159
+ def set_cpu_threads():
160
+ """Use all available CPU cores for inference when no GPU is present, capped by
161
+ SLURM's allocation when running under a SLURM job."""
162
+
163
+ if not torch.cuda.is_available():
164
+ if "SLURM_CPUS_PER_TASK" in os.environ:
165
+ n = min(int(os.environ["SLURM_CPUS_PER_TASK"]), os.cpu_count())
166
+ else:
167
+ n = os.cpu_count()
168
+ torch.set_num_threads(n)
169
+ torch.set_num_interop_threads(n)
170
+
171
+
172
+ def resolve_device():
173
+ return "cuda" if torch.cuda.is_available() else "cpu"
174
+
175
+
176
+ def load_torch_model(path, build_model_fn):
177
+ """Loads a `.torch` file that is either a full serialized module or a bare
178
+ state dict; in the latter case, builds a fresh model via `build_model_fn` and
179
+ loads the state dict into it."""
180
+
181
+ checkpoint = torch.load(path)
182
+ if isinstance(checkpoint, torch.nn.Module):
183
+ return checkpoint
184
+ model = build_model_fn()
185
+ model.load_state_dict(checkpoint)
186
+ return model
187
+
188
+
189
+ def load_ensemble(model_paths, load_fn):
190
+ """Yields one model per path in `model_paths`, loaded via `load_fn(path)`.
191
+ Frees each replicate before loading the next to avoid accumulating VRAM/RAM
192
+ across the ensemble; the caller should fully consume each yielded model
193
+ (e.g. run prediction/attribution on it) before continuing the loop."""
194
+
195
+ for path in model_paths:
196
+ model = load_fn(path)
197
+ yield model
198
+ del model
199
+ torch.cuda.empty_cache()
200
+
201
+
202
+ def average_profile_and_counts(predictions):
203
+ """Ensembles (profile_logits, log_counts) predictions from multiple replicates.
204
+
205
+ Averages the raw profile logits and log-counts across replicates *before*
206
+ applying the softmax/exp nonlinearity, then rescales. Averaging after the
207
+ nonlinearity instead (i.e. averaging already-softmaxed, already-rescaled
208
+ per-replicate tracks) biases the ensembled profile toward uniformity whenever
209
+ replicates disagree, which understates real signal.
210
+
211
+ Parameters
212
+ ----------
213
+ predictions: list of (profile_logits, log_counts) tuples, one per replicate, as
214
+ returned by tangermeme.predict.predict.
215
+
216
+ Returns
217
+ -------
218
+ track: torch.Tensor, shape=profile_logits.shape
219
+ The ensembled, rescaled profile track.
220
+ """
221
+
222
+ profiles, counts = zip(*predictions)
223
+ shape = profiles[0].shape
224
+
225
+ mean_profile = torch.stack(
226
+ [profile.reshape(profile.shape[0], -1) for profile in profiles]
227
+ ).mean(dim=0)
228
+ mean_count = torch.stack(list(counts)).mean(dim=0)
229
+
230
+ track = torch.nn.functional.softmax(mean_profile, dim=-1) * (
231
+ torch.exp(mean_count) - 1
232
+ )
233
+ return track.reshape(*shape)