gReLU 1.0.1__tar.gz → 1.0.2__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.
- {grelu-1.0.1 → grelu-1.0.2}/PKG-INFO +7 -1
- {grelu-1.0.1 → grelu-1.0.2}/README.md +6 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/gReLU.egg-info/PKG-INFO +7 -1
- {grelu-1.0.1 → grelu-1.0.2}/src/gReLU.egg-info/SOURCES.txt +0 -1
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/lightning/__init__.py +19 -5
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/lightning/metrics.py +3 -0
- grelu-1.0.2/src/grelu/resources/__init__.py +253 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/sequence/format.py +5 -2
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_lightning.py +1 -1
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_models.py +3 -4
- grelu-1.0.1/src/grelu/resources/__init__.py +0 -138
- grelu-1.0.1/src/grelu/resources/__pycache__/__init__.cpython-310.pyc +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/.github/workflows/pypi-publish.yml +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/.github/workflows/pypi-test.yml +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/.pre-commit-config.yaml +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/AUTHORS.md +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/CHANGELOG.md +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/CONTRIBUTING.md +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/Dockerfile +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/LICENSE.txt +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/MANIFEST.in +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/Makefile +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/_static/switcher.json +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/authors.rst +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/changelog.rst +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/conf.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/contributing.rst +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/index.md +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/license.rst +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/media/flowchart.jpg +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/readme.rst +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/requirements.txt +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/tutorials/1_inference.ipynb +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/tutorials/2_finetune.ipynb +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/tutorials/3_train.ipynb +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/tutorials/4_design.ipynb +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/tutorials/5_variant.ipynb +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/docs/tutorials/6_model_zoo.ipynb +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/media/flowchart.jpg +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/pyproject.toml +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/setup.cfg +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/setup.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/gReLU.egg-info/dependency_links.txt +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/gReLU.egg-info/not-zip-safe +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/gReLU.egg-info/requires.txt +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/gReLU.egg-info/top_level.txt +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/data/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/data/augment.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/data/dataset.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/data/preprocess.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/data/utils.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/design.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/interpret/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/interpret/motifs.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/interpret/score.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/io/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/io/bed.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/io/bigwig.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/io/fasta.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/io/genome.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/io/meme.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/lightning/losses.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/blocks.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/heads.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/layers.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/models.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/position.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/trunks/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/trunks/borzoi.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/trunks/enformer.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/model/trunks/explainn.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/encode/hg19-blacklist.v2.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/encode/hg38-blacklist.v2.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/encode/mm10-blacklist.v2.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/hg19.full.blacklist.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/hg19_mm10_c.full.blacklist.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/hg38.full.blacklist.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/mm10.full.blacklist.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/mm9.full.blacklist.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/meme/JASPAR2022_CORE_non-redundant_pfms_meme.txt +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/meme/jvierstra_consensus_pwms.meme +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/sequence/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/sequence/metrics.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/sequence/mutate.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/sequence/utils.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/transforms/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/transforms/label_transforms.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/transforms/prediction_transforms.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/transforms/seq_transforms.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/utils.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/variant.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/src/grelu/visualize.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/__init__.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/conftest.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/files/test.bed +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/files/test.bw +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/files/test.fa.gz +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/files/test.meme +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/files/test_variants.txt +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/files/tomtom/neg_patterns.pattern_0.tomtom.tsv +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/files/tomtom/neg_patterns.pattern_1.tomtom.tsv +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_augment.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_blocks.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_data_utils.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_dataset.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_design.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_heads.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_interpret.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_io.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_layers.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_positional.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_preprocess.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_resources.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_sequence.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_transforms.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_utils.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tests/test_variant.py +0 -0
- {grelu-1.0.1 → grelu-1.0.2}/tox.ini +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gReLU
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: gReLU is a python library to train, interpret, and apply deep learning models to DNA sequences
|
|
5
5
|
Home-page: https://code.roche.com/gred-rb-ai-ml-regulatory-genomics/grelu
|
|
6
6
|
Author: lal.avantika,eraslan.gokcen
|
|
@@ -60,6 +60,12 @@ cd gReLU
|
|
|
60
60
|
pip install .
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
To install using pip:
|
|
64
|
+
|
|
65
|
+
```shell
|
|
66
|
+
pip install gReLU
|
|
67
|
+
```
|
|
68
|
+
|
|
63
69
|
## Contributing
|
|
64
70
|
|
|
65
71
|
This project uses [pre-commit](https://pre-commit.com/). Please make sure to install it before making any changes:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: gReLU
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: gReLU is a python library to train, interpret, and apply deep learning models to DNA sequences
|
|
5
5
|
Home-page: https://code.roche.com/gred-rb-ai-ml-regulatory-genomics/grelu
|
|
6
6
|
Author: lal.avantika,eraslan.gokcen
|
|
@@ -60,6 +60,12 @@ cd gReLU
|
|
|
60
60
|
pip install .
|
|
61
61
|
```
|
|
62
62
|
|
|
63
|
+
To install using pip:
|
|
64
|
+
|
|
65
|
+
```shell
|
|
66
|
+
pip install gReLU
|
|
67
|
+
```
|
|
68
|
+
|
|
63
69
|
## Contributing
|
|
64
70
|
|
|
65
71
|
This project uses [pre-commit](https://pre-commit.com/). Please make sure to install it before making any changes:
|
|
@@ -69,7 +69,6 @@ src/grelu/model/trunks/borzoi.py
|
|
|
69
69
|
src/grelu/model/trunks/enformer.py
|
|
70
70
|
src/grelu/model/trunks/explainn.py
|
|
71
71
|
src/grelu/resources/__init__.py
|
|
72
|
-
src/grelu/resources/__pycache__/__init__.cpython-310.pyc
|
|
73
72
|
src/grelu/resources/blacklists/encode/hg19-blacklist.v2.bed
|
|
74
73
|
src/grelu/resources/blacklists/encode/hg38-blacklist.v2.bed
|
|
75
74
|
src/grelu/resources/blacklists/encode/mm10-blacklist.v2.bed
|
|
@@ -346,6 +346,9 @@ class LightningModel(pl.LightningModule):
|
|
|
346
346
|
self.log_dict(mean_val_metrics)
|
|
347
347
|
self.log("val_loss", mean_losses)
|
|
348
348
|
|
|
349
|
+
self.val_metrics.reset()
|
|
350
|
+
self.val_losses = []
|
|
351
|
+
|
|
349
352
|
def test_step(self, batch: Tensor, batch_idx: int) -> Tensor:
|
|
350
353
|
"""
|
|
351
354
|
Calculate metrics after a single test step
|
|
@@ -368,6 +371,9 @@ class LightningModel(pl.LightningModule):
|
|
|
368
371
|
losses = torch.stack(self.test_losses)
|
|
369
372
|
self.log("test_loss", torch.mean(losses))
|
|
370
373
|
|
|
374
|
+
self.test_metrics.reset()
|
|
375
|
+
self.test_losses = []
|
|
376
|
+
|
|
371
377
|
def configure_optimizers(self) -> None:
|
|
372
378
|
"""
|
|
373
379
|
Configure oprimizer for training
|
|
@@ -549,6 +555,7 @@ class LightningModel(pl.LightningModule):
|
|
|
549
555
|
if checkpoint_path is None:
|
|
550
556
|
# First validation pass
|
|
551
557
|
trainer.validate(model=self, dataloaders=val_dataloader)
|
|
558
|
+
self.val_metrics.reset()
|
|
552
559
|
|
|
553
560
|
# Add data parameters
|
|
554
561
|
self.data_params["tasks"] = train_dataset.tasks.reset_index(
|
|
@@ -813,7 +820,7 @@ class LightningModel(pl.LightningModule):
|
|
|
813
820
|
def embed_on_dataset(
|
|
814
821
|
self,
|
|
815
822
|
dataset: Callable,
|
|
816
|
-
|
|
823
|
+
device: Union[str, int] = "cpu",
|
|
817
824
|
num_workers: int = 1,
|
|
818
825
|
batch_size: int = 256,
|
|
819
826
|
):
|
|
@@ -822,7 +829,7 @@ class LightningModel(pl.LightningModule):
|
|
|
822
829
|
|
|
823
830
|
Args:
|
|
824
831
|
dataset: Dataset object that yields one-hot encoded sequences
|
|
825
|
-
|
|
832
|
+
device: Device ID to use
|
|
826
833
|
num_workers: Number of workers for data loader
|
|
827
834
|
batch_size: Batch size for data loader
|
|
828
835
|
|
|
@@ -837,13 +844,20 @@ class LightningModel(pl.LightningModule):
|
|
|
837
844
|
)
|
|
838
845
|
|
|
839
846
|
# Get device
|
|
840
|
-
orig_device = self.device
|
|
841
|
-
device = self.parse_devices(devices)[0]
|
|
842
847
|
if isinstance(device, list):
|
|
843
848
|
device = device[0]
|
|
844
849
|
warnings.warn(
|
|
845
|
-
f"embed_on_dataset currently only uses a single GPU: {device}"
|
|
850
|
+
f"embed_on_dataset currently only uses a single GPU: Using {device}"
|
|
846
851
|
)
|
|
852
|
+
if isinstance(device, str):
|
|
853
|
+
try:
|
|
854
|
+
device = int(device)
|
|
855
|
+
except Exception:
|
|
856
|
+
pass
|
|
857
|
+
device = torch.device(device)
|
|
858
|
+
|
|
859
|
+
# Move model to device
|
|
860
|
+
orig_device = self.device
|
|
847
861
|
self.to(device)
|
|
848
862
|
|
|
849
863
|
# Get embeddings
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import importlib_resources
|
|
3
|
+
from tempfile import TemporaryDirectory
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from typing import Optional, List, Dict, Any, Union
|
|
6
|
+
|
|
7
|
+
import wandb
|
|
8
|
+
from grelu.lightning import LightningModel
|
|
9
|
+
|
|
10
|
+
DEFAULT_WANDB_ENTITY = 'grelu'
|
|
11
|
+
DEFAULT_WANDB_HOST = 'https://api.wandb.ai'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def get_meme_file_path(meme_motif_db: str) -> str:
|
|
15
|
+
"""
|
|
16
|
+
Return the path to a MEME file.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
meme_motif_db: Path to a MEME file or the name of a MEME file included with gReLU.
|
|
20
|
+
Current name options are "jaspar" and "consensus".
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
Path to the specified MEME file.
|
|
24
|
+
"""
|
|
25
|
+
if meme_motif_db == "jaspar":
|
|
26
|
+
meme_motif_db = (
|
|
27
|
+
importlib_resources.files("grelu")
|
|
28
|
+
/ "resources"
|
|
29
|
+
/ "meme"
|
|
30
|
+
/ "JASPAR2022_CORE_non-redundant_pfms_meme.txt"
|
|
31
|
+
)
|
|
32
|
+
elif meme_motif_db == "consensus":
|
|
33
|
+
meme_motif_db = (
|
|
34
|
+
importlib_resources.files("grelu")
|
|
35
|
+
/ "resources"
|
|
36
|
+
/ "meme"
|
|
37
|
+
/ "jvierstra_consensus_pwms.meme"
|
|
38
|
+
)
|
|
39
|
+
if os.path.isfile(meme_motif_db):
|
|
40
|
+
return str(meme_motif_db)
|
|
41
|
+
else:
|
|
42
|
+
raise Exception(f"{meme_motif_db} is not a valid file.")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_blacklist_file(genome: str) -> str:
|
|
46
|
+
"""
|
|
47
|
+
Return the path to a blacklist file
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
genome: Name of a genome whose blacklist file is included with gReLU.
|
|
51
|
+
Current name options are "hg19", "hg38" and "mm10".
|
|
52
|
+
|
|
53
|
+
Returns:
|
|
54
|
+
Path to the specified blacklist file.
|
|
55
|
+
"""
|
|
56
|
+
blacklist = (
|
|
57
|
+
importlib_resources.files("grelu")
|
|
58
|
+
/ "resources"
|
|
59
|
+
/ "blacklists"
|
|
60
|
+
/ "encode"
|
|
61
|
+
/ f"{genome}-blacklist.v2.bed"
|
|
62
|
+
)
|
|
63
|
+
assert blacklist.exists()
|
|
64
|
+
return str(blacklist)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _check_wandb(host:str=DEFAULT_WANDB_HOST) -> None:
|
|
68
|
+
"""
|
|
69
|
+
Check that the user is logged into Weights and Biases
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
host: URL of the Weights & Biases host
|
|
73
|
+
"""
|
|
74
|
+
assert wandb.login(host=host, anonymous="allow"), f'Weights & Biases (wandb) is not configured, see {host}/authorize'
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def projects(host: str=DEFAULT_WANDB_HOST) -> List[str]:
|
|
78
|
+
"""
|
|
79
|
+
List all projects in the model zoo
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
host: URL of the Weights & Biases host
|
|
83
|
+
|
|
84
|
+
Returns:
|
|
85
|
+
List of project names
|
|
86
|
+
"""
|
|
87
|
+
_check_wandb(host=host)
|
|
88
|
+
|
|
89
|
+
api = wandb.Api()
|
|
90
|
+
projects = api.projects(DEFAULT_WANDB_ENTITY)
|
|
91
|
+
return [p.name for p in projects]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def artifacts(project: str, host: str=DEFAULT_WANDB_HOST, type_is: Optional[str]=None, type_contains: Optional[str]=None) -> List[str]:
|
|
95
|
+
"""
|
|
96
|
+
List all artifacts associated with a project in the model zoo
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
project: Name of the project to search
|
|
100
|
+
host: URL of the Weights & Biases host
|
|
101
|
+
type_is: Return only artifacts with this type
|
|
102
|
+
type_contains: Return only artifacts whose type contains this string
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
List of artifact names
|
|
106
|
+
"""
|
|
107
|
+
_check_wandb(host)
|
|
108
|
+
project_path = f'{DEFAULT_WANDB_ENTITY}/{project}'
|
|
109
|
+
|
|
110
|
+
api = wandb.Api()
|
|
111
|
+
if type_is is not None:
|
|
112
|
+
types = [x.name for x in api.artifact_types(project_path) if type_is == x.name]
|
|
113
|
+
elif type_contains is not None:
|
|
114
|
+
types = [x.name for x in api.artifact_types(project_path) if type_contains in x.name]
|
|
115
|
+
else:
|
|
116
|
+
types = [x.name for x in api.artifact_types(project_path)]
|
|
117
|
+
|
|
118
|
+
assert len(types) > 0, 'Artifact not found'
|
|
119
|
+
|
|
120
|
+
coll = [api.artifact_type(art_type, project_path) for art_type in types]
|
|
121
|
+
arts = [art.name for arts in coll for art in arts.collections()]
|
|
122
|
+
return arts
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def models(project:str, host:str=DEFAULT_WANDB_HOST) -> List[str]:
|
|
126
|
+
"""
|
|
127
|
+
List all models associated with a project in the model zoo
|
|
128
|
+
|
|
129
|
+
Args:
|
|
130
|
+
project: Name of the project to search
|
|
131
|
+
host: URL of the Weights & Biases host
|
|
132
|
+
|
|
133
|
+
Returns:
|
|
134
|
+
List of model names
|
|
135
|
+
"""
|
|
136
|
+
return artifacts(project, host=host, type_contains='model')
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
def datasets(project:str, host:str=DEFAULT_WANDB_HOST) -> List[str]:
|
|
140
|
+
"""
|
|
141
|
+
List all datasets associated with a project in the model zoo
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
project: Name of the project to search
|
|
145
|
+
host: URL of the Weights & Biases host
|
|
146
|
+
|
|
147
|
+
Returns:
|
|
148
|
+
List of dataset names
|
|
149
|
+
"""
|
|
150
|
+
return artifacts(project, host=host, type_contains='dataset')
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def runs(project:str, host:str=DEFAULT_WANDB_HOST, field:str='id', filters: Optional[Dict[str, Any]]=None) -> List[str]:
|
|
154
|
+
"""
|
|
155
|
+
List attributes of all runs associated with a project in the model zoo
|
|
156
|
+
|
|
157
|
+
Args:
|
|
158
|
+
project: Name of the project to search
|
|
159
|
+
host: URL of the Weights & Biases host
|
|
160
|
+
field: Field to return from the run metadata
|
|
161
|
+
filters: Dictionary of filters to pass to `api.runs`
|
|
162
|
+
|
|
163
|
+
Returns:
|
|
164
|
+
List of run attributes
|
|
165
|
+
"""
|
|
166
|
+
_check_wandb(host=host)
|
|
167
|
+
project_path = f'{DEFAULT_WANDB_ENTITY}/{project}'
|
|
168
|
+
|
|
169
|
+
api = wandb.Api()
|
|
170
|
+
return [getattr(run, field) for run in api.runs(project_path, filters=filters)]
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def get_artifact(name:str, project:str, host:str=DEFAULT_WANDB_HOST, alias:str='latest'):
|
|
174
|
+
"""
|
|
175
|
+
Retrieve an artifact associated with a project in the model zoo
|
|
176
|
+
|
|
177
|
+
Args:
|
|
178
|
+
name: Name of the artifact
|
|
179
|
+
project: Name of the project containing the artifact
|
|
180
|
+
host: URL of the Weights & Biases host
|
|
181
|
+
alias: Alias of the artifact
|
|
182
|
+
|
|
183
|
+
Returns:
|
|
184
|
+
The specific artifact
|
|
185
|
+
"""
|
|
186
|
+
_check_wandb(host=host)
|
|
187
|
+
project_path = f'{DEFAULT_WANDB_ENTITY}/{project}'
|
|
188
|
+
|
|
189
|
+
api = wandb.Api()
|
|
190
|
+
return api.artifact(f'{project_path}/{name}:{alias}')
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def get_dataset_by_model(model_name:str, project:str, host:str=DEFAULT_WANDB_HOST, alias:str='latest') -> List[str]:
|
|
194
|
+
"""
|
|
195
|
+
List all datasets associated with a model in the model zoo
|
|
196
|
+
|
|
197
|
+
Args:
|
|
198
|
+
model_name: Name of the model
|
|
199
|
+
project: Name of the project containing the model
|
|
200
|
+
host: URL of the Weights & Biases host
|
|
201
|
+
alias: Alias of the model artifact
|
|
202
|
+
|
|
203
|
+
Returns:
|
|
204
|
+
A list containing the names of all datasets linked to the model
|
|
205
|
+
"""
|
|
206
|
+
art = get_artifact(model_name, project, host=host, alias=alias)
|
|
207
|
+
run = art.logged_by()
|
|
208
|
+
return [x.name for x in run.used_artifacts()]
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def get_model_by_dataset(dataset_name:str, project:str, host:str=DEFAULT_WANDB_HOST, alias:str='latest') -> List[str]:
|
|
212
|
+
"""
|
|
213
|
+
List all models associated with a dataset in the model zoo
|
|
214
|
+
|
|
215
|
+
Args:
|
|
216
|
+
dataset_name: Name of the dataset
|
|
217
|
+
project: Name of the project containing the dataset
|
|
218
|
+
host: URL of the Weights & Biases host
|
|
219
|
+
alias: Alias of the dataset artifact
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
A list containing the names of all models linked to the dataset
|
|
223
|
+
"""
|
|
224
|
+
art = get_artifact(dataset_name, project, host=host, alias=alias)
|
|
225
|
+
runs = art.used_by()
|
|
226
|
+
assert len(runs) > 0
|
|
227
|
+
return [x.name for x in runs[0].logged_artifacts()]
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def load_model(
|
|
231
|
+
project:str, model_name:str, device:Union[str, int]='cpu', host:str=DEFAULT_WANDB_HOST, alias:str='latest', checkpoint_file:str='model.ckpt'
|
|
232
|
+
) -> LightningModel:
|
|
233
|
+
"""
|
|
234
|
+
Download and load a model from the model zoo
|
|
235
|
+
|
|
236
|
+
Args:
|
|
237
|
+
project: Name of the project containing the model
|
|
238
|
+
model_name: Name of the model
|
|
239
|
+
device: Device index on which to load the model.
|
|
240
|
+
host: URL of the Weights & Biases host
|
|
241
|
+
alias: Alias of the model artifact
|
|
242
|
+
checkpoint_file: Name of the checkpoint file contained in the model artifact
|
|
243
|
+
|
|
244
|
+
Returns:
|
|
245
|
+
A LightningModel object
|
|
246
|
+
"""
|
|
247
|
+
art = get_artifact(model_name, project, host=host, alias=alias)
|
|
248
|
+
|
|
249
|
+
with TemporaryDirectory() as d:
|
|
250
|
+
art.download(d)
|
|
251
|
+
model = LightningModel.load_from_checkpoint(Path(d) / checkpoint_file, map_location=device)
|
|
252
|
+
|
|
253
|
+
return model
|
|
@@ -252,8 +252,11 @@ def strings_to_indices(
|
|
|
252
252
|
strings
|
|
253
253
|
), "All input sequences must have the same length."
|
|
254
254
|
return np.stack(
|
|
255
|
-
[
|
|
256
|
-
|
|
255
|
+
[
|
|
256
|
+
np.array([BASE_TO_INDEX_HASH[base] for base in string], dtype=np.int8)
|
|
257
|
+
for string in strings
|
|
258
|
+
]
|
|
259
|
+
)
|
|
257
260
|
|
|
258
261
|
|
|
259
262
|
def indices_to_one_hot(indices: np.ndarray) -> Tensor:
|
|
@@ -252,7 +252,7 @@ def test_lightning_model_transform():
|
|
|
252
252
|
|
|
253
253
|
|
|
254
254
|
def test_lightning_model_embed_on_dataset():
|
|
255
|
-
preds = single_task_reg_model.embed_on_dataset(dataset=udataset,
|
|
255
|
+
preds = single_task_reg_model.embed_on_dataset(dataset=udataset, device="cpu")
|
|
256
256
|
assert preds.shape == (2, 1, 3)
|
|
257
257
|
|
|
258
258
|
|
|
@@ -12,17 +12,16 @@ from grelu.model.models import (
|
|
|
12
12
|
EnformerModel,
|
|
13
13
|
EnformerPretrainedModel,
|
|
14
14
|
)
|
|
15
|
+
from grelu.resources import DEFAULT_WANDB_HOST
|
|
15
16
|
from grelu.sequence.format import convert_input_type
|
|
16
17
|
|
|
17
18
|
inputs = convert_input_type(["A" * 128], "one_hot")
|
|
18
19
|
|
|
19
20
|
|
|
20
21
|
try:
|
|
21
|
-
wandb.login(host=
|
|
22
|
+
wandb.login(host=DEFAULT_WANDB_HOST, anonymous="never", timeout=0)
|
|
22
23
|
except wandb.errors.UsageError: # login anonymously if not logged in already
|
|
23
|
-
wandb.login(
|
|
24
|
-
host="https://genentech.wandb.io", relogin=True, anonymous="must", timeout=0
|
|
25
|
-
)
|
|
24
|
+
wandb.login(host=DEFAULT_WANDB_HOST, relogin=True, anonymous="must", timeout=0)
|
|
26
25
|
|
|
27
26
|
|
|
28
27
|
# Test a fully convolutional model with residual connections and autocropping
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import os
|
|
2
|
-
import importlib_resources
|
|
3
|
-
from tempfile import TemporaryDirectory
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
import wandb
|
|
7
|
-
from grelu.lightning import LightningModel
|
|
8
|
-
|
|
9
|
-
DEFAULT_WANDB_ENTITY = 'grelu'
|
|
10
|
-
DEFAULT_WANDB_HOST = 'https://api.wandb.ai'
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def get_meme_file_path(meme_motif_db):
|
|
14
|
-
"""
|
|
15
|
-
Return the path to a MEME file.
|
|
16
|
-
|
|
17
|
-
Args:
|
|
18
|
-
meme_motif_db (str): Path to a MEME file or the name of a MEME file included with gReLU.
|
|
19
|
-
Current name options are "jaspar" and "consensus".
|
|
20
|
-
|
|
21
|
-
Returns:
|
|
22
|
-
(str): Path to the specified MEME file.
|
|
23
|
-
"""
|
|
24
|
-
if meme_motif_db == "jaspar":
|
|
25
|
-
meme_motif_db = (
|
|
26
|
-
importlib_resources.files("grelu")
|
|
27
|
-
/ "resources"
|
|
28
|
-
/ "meme"
|
|
29
|
-
/ "JASPAR2022_CORE_non-redundant_pfms_meme.txt"
|
|
30
|
-
)
|
|
31
|
-
elif meme_motif_db == "consensus":
|
|
32
|
-
meme_motif_db = (
|
|
33
|
-
importlib_resources.files("grelu")
|
|
34
|
-
/ "resources"
|
|
35
|
-
/ "meme"
|
|
36
|
-
/ "jvierstra_consensus_pwms.meme"
|
|
37
|
-
)
|
|
38
|
-
if os.path.isfile(meme_motif_db):
|
|
39
|
-
return str(meme_motif_db)
|
|
40
|
-
else:
|
|
41
|
-
raise Exception(f"{meme_motif_db} is not a valid file.")
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
def get_default_config_file():
|
|
45
|
-
config = importlib_resources.files("grelu") / "resources" / "default_config.yaml"
|
|
46
|
-
assert config.exists()
|
|
47
|
-
return str(config)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
def get_blacklist_file(genome):
|
|
51
|
-
blacklist = (
|
|
52
|
-
importlib_resources.files("grelu")
|
|
53
|
-
/ "resources"
|
|
54
|
-
/ "blacklists"
|
|
55
|
-
/ "encode"
|
|
56
|
-
/ f"{genome}-blacklist.v2.bed"
|
|
57
|
-
)
|
|
58
|
-
assert blacklist.exists()
|
|
59
|
-
return str(blacklist)
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
def _check_wandb(host=DEFAULT_WANDB_HOST):
|
|
63
|
-
assert wandb.login(host=host), f'Weights & Biases (wandb) is not configured, see {DEFAULT_WANDB_HOST}/authorize'
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
def projects(host=DEFAULT_WANDB_HOST):
|
|
67
|
-
_check_wandb(host=host)
|
|
68
|
-
|
|
69
|
-
api = wandb.Api()
|
|
70
|
-
projects = api.projects(DEFAULT_WANDB_ENTITY)
|
|
71
|
-
return [p.name for p in projects]
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
def artifacts(project, host=DEFAULT_WANDB_HOST, type_is=None, type_contains=None):
|
|
75
|
-
_check_wandb(host)
|
|
76
|
-
project_path = f'{DEFAULT_WANDB_ENTITY}/{project}'
|
|
77
|
-
|
|
78
|
-
api = wandb.Api()
|
|
79
|
-
if type_is is not None:
|
|
80
|
-
types = [x.name for x in api.artifact_types(project_path) if type_is == x.name]
|
|
81
|
-
elif type_contains is not None:
|
|
82
|
-
types = [x.name for x in api.artifact_types(project_path) if type_contains in x.name]
|
|
83
|
-
else:
|
|
84
|
-
types = [x.name for x in api.artifact_types(project_path)]
|
|
85
|
-
|
|
86
|
-
assert len(types) > 0, 'Artifact not found'
|
|
87
|
-
|
|
88
|
-
coll = [api.artifact_type(art_type, project_path) for art_type in types]
|
|
89
|
-
arts = [art.name for arts in coll for art in arts.collections()]
|
|
90
|
-
return arts
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
def models(project, host=DEFAULT_WANDB_HOST):
|
|
94
|
-
return artifacts(project, host=host, type_contains='model')
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
def datasets(project, host=DEFAULT_WANDB_HOST):
|
|
98
|
-
return artifacts(project, host=host, type_contains='dataset')
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
def runs(project, host=DEFAULT_WANDB_HOST, field='id', filters=None):
|
|
102
|
-
_check_wandb(host=host)
|
|
103
|
-
project_path = f'{DEFAULT_WANDB_ENTITY}/{project}'
|
|
104
|
-
|
|
105
|
-
api = wandb.Api()
|
|
106
|
-
return [getattr(run, field) for run in api.runs(project_path, filters=filters)]
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
def get_artifact(name, project, alias='latest'):
|
|
110
|
-
_check_wandb()
|
|
111
|
-
project_path = f'{DEFAULT_WANDB_ENTITY}/{project}'
|
|
112
|
-
|
|
113
|
-
api = wandb.Api()
|
|
114
|
-
return api.artifact(f'{project_path}/{name}:{alias}')
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
def get_dataset_by_model(model_name, project, alias='latest'):
|
|
118
|
-
art = get_artifact(model_name, project, alias=alias)
|
|
119
|
-
run = art.logged_by()
|
|
120
|
-
return [x.name for x in run.used_artifacts()]
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
def get_model_by_dataset(dataset_name, project, alias='latest'):
|
|
124
|
-
art = get_artifact(dataset_name, project, alias=alias)
|
|
125
|
-
runs = art.used_by()
|
|
126
|
-
assert len(runs) > 0
|
|
127
|
-
return [x.name for x in runs[0].logged_artifacts()]
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
def load_model(project, model_name, alias='latest', checkpoint_file='model.ckpt'):
|
|
131
|
-
|
|
132
|
-
art = get_artifact(model_name, project, alias=alias)
|
|
133
|
-
|
|
134
|
-
with TemporaryDirectory() as d:
|
|
135
|
-
art.download(d)
|
|
136
|
-
model = LightningModel.load_from_checkpoint(Path(d) / checkpoint_file)
|
|
137
|
-
|
|
138
|
-
return model
|
|
Binary file
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/hg19.full.blacklist.bed
RENAMED
|
File without changes
|
|
File without changes
|
{grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/hg38.full.blacklist.bed
RENAMED
|
File without changes
|
{grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/mm10.full.blacklist.bed
RENAMED
|
File without changes
|
{grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/blacklists/mito_combined/mm9.full.blacklist.bed
RENAMED
|
File without changes
|
{grelu-1.0.1 → grelu-1.0.2}/src/grelu/resources/meme/JASPAR2022_CORE_non-redundant_pfms_meme.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|