Skip to content

Commit

Permalink
Merge pull request #52 from loucerac/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
loucerac authored May 29, 2023
2 parents 24e9a33 + 458954e commit ba30cfe
Show file tree
Hide file tree
Showing 46 changed files with 2,138 additions and 2,974 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/docs_pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@ jobs:
- uses: actions/setup-python@v2
with:
python-version: 3.8
- uses: abatilo/[email protected]
- name: install
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: latest
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install package
run: poetry install
- name: Build documentation
run: |
Expand Down
29 changes: 17 additions & 12 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ name: CI
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
branches: [ master, develop ]
pull_request:
branches: [ master ]
branches: [ master, develop ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -18,27 +18,32 @@ on:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 30
timeout-minutes: 60
strategy:
matrix:
python-version: ['3.8', '3.9', '3.10']
python-version: ['3.10']

steps:
- uses: actions/checkout@v1
- uses: conda-incubator/setup-miniconda@v2
with:
auto-activate-base: true
activate-environment: ""

- uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.1.10
virtualenvs-create: true
virtualenvs-in-project: true
version: latest
installer-parallel: true

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox tox-gh-actions tox-poetry
- name: Test with tox
run: tox
python -m pip install nox nox-poetry
- run: nox
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
.nox/

# Translations
*.mo
Expand Down
7 changes: 5 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,9 @@ valid-metaclass-classmethod-first-arg=cls
[DESIGN]

# Maximum number of arguments for function / method.
max-args=5
max-args=10
max-function-args=10


# Maximum number of attributes for a class (see R0902).
max-attributes=7
Expand Down Expand Up @@ -506,4 +508,5 @@ known-third-party=enchant
# Exceptions that will emit a warning when being caught. Defaults to
# "BaseException, Exception".
overgeneral-exceptions=BaseException,
Exception
Exception

3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@
"files.watcherExclude": {
"**/venvs": true,
"**/.venv": true,
"**/__pycache__": true,
"**/data": true
},
"files.exclude": {
"**/venvs": true,
"**/.venv": true,
"**/__pycache__": true,
"**/data": true
},
"search.exclude": {
"**/venvs": true,
"**/.venv": true,
"**/__pycache__": true,
"**/data": true
},
"python.testing.pytestArgs": [
Expand Down
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) [year] [fullname]

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 48 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
[![DOI](https://zenodo.org/badge/362395439.svg)](https://zenodo.org/badge/latestdoi/362395439)

# Drug REpurposing using Mechanistic Models of signal transduction and -eXplainable Machine Learning
# Drug REpurposing using eXplainable Machine Learning and Mechanistic Models of signal transduction

Repository for the `drexml` python package: (DRExM³L) Drug REpurposing using Mechanistic Models of signal transduction and eXplainable Machine Learning
Repository for the `drexml` python package: (DRExM³L) Drug REpurposing using eXplainable Machine Learning and Mechanistic Models of signal transduction

## Setup

To install the `drexml` package use the following:

```
conda create -n drexml python=3.8
conda run -n drexml pip install git+ssh://git@github.com:loucerac/drexml.git
conda create -n drexml python=3.10
conda run -n drexml pip install git+https://github.com/loucerac/drexml.git@master
```

If a CUDA~11 compatible device is available use:

```
conda create -n drexml --override-channels -c "nvidia/label/cuda-11.8.0" -c conda-forge cuda cuda-nvcc cuda-toolkit gxx=11.2 python=3.10
conda run -n drexml pip install git+https://github.com/loucerac/drexml.git@master
```

To install `drexml` in an existing environment, activate it and use:

```
pip install git+https://github.com/loucerac/drexml.git@master
```

Note that by default the `setup` will try to compile the `CUDA` modules, if not possible it will use the `CPU` modules.

To install the development version use `@develop` instead of `@master`.

## Run

To run the program for a disease map that uses circuits from the preprocessed `KEGG` pathways and the `KDT` standard list, construct an environment file (e.g. `disease.env`) using the following template:
Expand All @@ -26,26 +43,26 @@ genes=$default$
genes_column=approved_targets
```

Where `circuits.tsv` has the following format (tab delimited):
The `TSV` file `circuits.tsv` has the following format (tab delimited):
```
index in_disease
P-hsa03320-37 False
P-hsa03320-61 False
P-hsa03320-46 False
P-hsa03320-57 False
P-hsa03320-64 False
P-hsa03320-47 False
P-hsa03320-65 False
P-hsa03320-55 False
P-hsa03320-56 False
P-hsa03320-33 False
P-hsa03320-58 False
P-hsa03320-59 False
P-hsa03320-63 False
P-hsa03320-44 False
P-hsa03320-36 False
P-hsa03320-30 False
P-hsa03320-28 True
P-hsa03320-37 0
P-hsa03320-61 0
P-hsa03320-46 0
P-hsa03320-57 0
P-hsa03320-64 0
P-hsa03320-47 0
P-hsa03320-65 0
P-hsa03320-55 0
P-hsa03320-56 0
P-hsa03320-33 0
P-hsa03320-58 0
P-hsa03320-59 0
P-hsa03320-63 0
P-hsa03320-44 0
P-hsa03320-36 0
P-hsa03320-30 0
P-hsa03320-28 1
```

where:
Expand All @@ -67,6 +84,15 @@ Note that the first time that the full program is run, it will take longer as it

https://doi.org/10.5281/zenodo.6020480

## Contribute to development

The recommended setup is:
- setup `pipx`
- setup `miniconda`
- use `pipx` to install `poetry`
- use `pipx` to install `nox` and inject `nox-poetry` into `nox`
- run `make`, if you want to use a CUDA enabled GPU, use `make gpu=1`

## Documentation
The documentation can be found here:

Expand Down
5 changes: 5 additions & 0 deletions docs/source/api_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ explain
utils
----------
.. automodule:: drexml.utils
:members:

plotting
----------
.. automodule:: drexml.plotting
:members:
73 changes: 69 additions & 4 deletions drexml/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,29 @@
import shutil
import subprocess
import sys
import warnings

import click
import joblib
from numba.core.errors import NumbaDeprecationWarning, NumbaPendingDeprecationWarning

from drexml.utils import get_data, get_number_cuda_devices, get_out_path, get_version
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", module="shap", message="IPython could not be loaded!"
)
warnings.filterwarnings("ignore", module="shap", category=NumbaDeprecationWarning)
warnings.filterwarnings(
"ignore", module="shap", category=NumbaPendingDeprecationWarning
)

from drexml.plotting import plot_metrics
from drexml.utils import (
get_data,
get_number_cuda_devices,
get_out_path,
get_version,
rename_results,
)

FNAME_DICT = {
"train": "stab_trainer.py",
Expand Down Expand Up @@ -80,6 +98,25 @@
]


_check_add_option = [
click.option(
"--add/--no-add",
is_flag=True,
default=True,
help="Check the additivity when computing the SHAP values.",
)
]

_verb_option = [
click.option(
"--verbosity/--no-verbosity",
is_flag=True,
default=False,
help="Verbosity level.",
)
]


def copy_files(ctx, fnames):
"""Copy files from tmp to ml folder."""
for fname in fnames:
Expand Down Expand Up @@ -148,6 +185,7 @@ def build_cmd(ctx):
str(int(ctx["n_gpus"])),
str(ctx["n_cpus"]),
str(int(ctx["debug"])),
str(int(ctx["add"])),
ctx["mode"],
]

Expand All @@ -160,19 +198,21 @@ def run_cmd(ctx):
# Unpythonic, update with dasks's LocalCudaCluster (currently unreliable).
print(" ".join(cmd))
output = subprocess.run(cmd, capture_output=True, text=True, check=True)
click.echo(output.stderr)
click.echo(output.stdout)
if ctx["verbosity"]:
click.echo(output.stderr)
click.echo(output.stdout)


@click.group()
@click.version_option(get_version())
def main():
"""drexml CLI entry point."""
print(f"running drexml orchestrate v {get_version()}")
print(f"running drexml v{get_version()}")


@main.command()
@add_options(_debug_option)
@add_options(_verb_option)
@click.argument("disease-path", type=click.Path(exists=True))
@click.version_option(get_version())
def orchestrate(**kwargs):
Expand All @@ -193,6 +233,7 @@ def orchestrate(**kwargs):
type=click.Choice(["train", "explain", "score"], case_sensitive=False),
)
@add_options(_debug_option)
@add_options(_verb_option)
@add_options(_n_iters_option)
@add_options(_n_gpus_option)
@add_options(_n_cpus_option)
Expand Down Expand Up @@ -223,6 +264,8 @@ def stability(**kwargs):

@main.command()
@add_options(_debug_option)
@add_options(_verb_option)
@add_options(_check_add_option)
@add_options(_n_iters_option)
@add_options(_n_gpus_option)
@add_options(_n_cpus_option)
Expand All @@ -240,6 +283,8 @@ def explain(**kwargs):

@main.command()
@add_options(_debug_option)
@add_options(_verb_option)
@add_options(_check_add_option)
@add_options(_n_iters_option)
@add_options(_n_gpus_option)
@add_options(_n_cpus_option)
Expand All @@ -257,5 +302,25 @@ def run(ctx, **kwargs):
ctx.forward(explain)


@main.command()
@click.argument("stab-path", type=click.Path(exists=True))
@click.version_option(get_version())
@click.pass_context
def plot(ctx, stab_path):
"""Plot the stability results"""

plot_metrics(stab_path)


@main.command()
@click.argument("results-folder", type=click.Path(exists=True))
@click.version_option(get_version())
@click.pass_context
def rename(ctx, results_folder):
"""Plot the stability results"""

rename_results(results_folder)


if __name__ == "__main__":
main()
Loading

0 comments on commit ba30cfe

Please sign in to comment.