Skip to content

Commit

Permalink
Merge pull request #60 from loucerac/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
loucerac authored Jul 10, 2023
2 parents 8320571 + 2695c89 commit b59e1ce
Show file tree
Hide file tree
Showing 18 changed files with 2,030 additions and 2,245 deletions.
70 changes: 36 additions & 34 deletions .github/workflows/docs_pages.yaml
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
name: Docs2Pages
on:
pull_request:
branches:
- master
workflow_run:
workflows: ["CI"]
types:
- completed
permissions:
contents: write
jobs:
build-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: 3.8
- 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: |
mkdir gh-pages
touch gh-pages/.nojekyll
cd docs/
poetry run make html
cp -r build/* ../gh-pages/
cd ../gh-pages/
cp -r html/* .
rm -rf html/
- name: Deploy documentation
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: gh-pages
- name: Checkout
uses: actions/checkout@master
with:
fetch-depth: 0
- uses: actions/setup-python@v2
with:
python-version: 3.8

- uses: pdm-project/setup-pdm@v3
with:
prerelease: false
enable-pep582: false
allow-python-prereleases: false

- name: Install package
run: pdm install

- name: Build documentation
run: |
mkdir gh-pages
touch gh-pages/.nojekyll
cd docs/
pdm run make html
cp -r build/* ../gh-pages/
cd ../gh-pages/
cp -r html/* .
rm -rf html/
- name: Deploy documentation
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: gh-pages
53 changes: 27 additions & 26 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, develop ]
branches: [master, develop]
pull_request:
branches: [ master, develop ]
branches: [master, develop]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -21,29 +21,30 @@ jobs:
timeout-minutes: 60
strategy:
matrix:
python-version: ['3.10']
python-version: ["3.10"]

steps:
- 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@v4
with:
python-version: ${{ matrix.python-version }}

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

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install nox nox-poetry
- run: nox
- 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@v4
with:
python-version: ${{ matrix.python-version }}

- name: Setup PDM
uses: pdm-project/setup-pdm@v3
with:
prerelease: false
enable-pep582: false
allow-python-prereleases: false

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install nox
- run: nox
52 changes: 52 additions & 0 deletions .github/workflows/publish-to-test-pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Publish Python 🐍 distributions 📦 to PyPI and TestPyPI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI and TestPyPI
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- name: Setup PDM
uses: pdm-project/setup-pdm@v3
with:
prerelease: false
enable-pep582: false
allow-python-prereleases: false
# - name: Install pypa/build
# run: >-
# python3 -m
# pip install
# build
# --user
# - name: Build a binary wheel and a source tarball
# run: >-
# python3 -m
# build
# --sdist
# --wheel
# --outdir dist/
# .
- name: Build a binary wheel and a source tarball
run: >-
pdm build
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository-url: https://test.pypi.org/legacy/
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_API_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,5 @@ results_July2021_gpu
scripts/automorf.ipynb
debug.ipynb

dask-worker-space/
dask-worker-space/
.pdm-python
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@

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

Repository for the `drexml` python package: (DRExM³L) Drug REpurposing using eXplainable Machine Learning and Mechanistic Models of signal transduction
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.10
conda run -n drexml pip install git+https://github.com/loucerac/drexml.git@master
conda activate drexml
pip install drexml
```

If a CUDA~11 compatible device is available use:
If a CUDA~10.2/11.x (< 12) 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
conda activate drexml
pip install --no-cache-dir --no-binary=shap drexml
```

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

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

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`):
Expand All @@ -47,6 +47,7 @@ circuits=circuits.tsv.gz
```

The `TSV` file `circuits.tsv` has the following format (tab delimited):

```
index in_disease
P-hsa03320-37 0
Expand All @@ -69,8 +70,9 @@ P-hsa03320-28 1
```

where:
* `index`: Hipathia circuit id
* `in_disease`: (boolean) True/1 if a given circuit is part of the disease

- `index`: Hipathia circuit id
- `in_disease`: (boolean) True/1 if a given circuit is part of the disease

Note that in all cases you can restrict the circuits to the physiological list by setting `use_physio=true` in the `env` file.

Expand All @@ -81,27 +83,30 @@ drexml run --n-gpus 0 --n-cpus 10 $DISEASE_PATH
```

where:
* `--n-gpus` indicates the number of gpu devices to use in parallel (-1 -> all) (0 -> None)
* `--n-cpus` indicates the number of cpu devices to use in parallel (-1 -> all) 8
* `DISEASE_PATH` indicates the path to the disease env file (e.g. `/path/to/disease/folder/disease.env`)

- `--n-gpus` indicates the number of gpu devices to use in parallel (-1 -> all) (0 -> None)
- `--n-cpus` indicates the number of cpu devices to use in parallel (-1 -> all) 8
- `DISEASE_PATH` indicates the path to the disease env file (e.g. `/path/to/disease/folder/disease.env`)

Use the `--debug` option for testing that everything works using a few iterations.

Note that the first time that the full program is run, it will take longer as it downloads the latest versions of each background dataset from Zenodo:

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


## Contribute to development

The recommended setup is:

- setup `pipx`
- setup `miniforge`
- use `pipx` to install `poetry`
- use `pipx` to install `nox` and inject `nox-poetry` into `nox`
- use `pipx` to install `pdm`
- use `pipx` to inject pd-bump into `pdm`
- use `pipx` to install `nox`
- run `make`, if you want to use a CUDA enabled GPU, use `make gpu=1`

## Documentation

The documentation can be found here:

https://loucerac.github.io/drexml/
6 changes: 5 additions & 1 deletion drexml/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ def run_cmd(ctx):
cmd = build_cmd(ctx)
# Unpythonic, update with dasks's LocalCudaCluster (currently unreliable).
print(" ".join(cmd))
output = subprocess.run(cmd, capture_output=True, text=True, check=True)
try:
output = subprocess.run(cmd, capture_output=True, text=True, check=True)
except subprocess.CalledProcessError as err: # pragma: no cover
click.echo("Ping stdout output:\n", err.output)

if ctx["verbosity"]:
click.echo(output.stderr)
click.echo(output.stdout)
Expand Down
1 change: 0 additions & 1 deletion drexml/cli/stab_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
print(f"{add=}")

def runner(model, bkg, new, check_add, use_gpu):

gpu_id = queue.get()
if use_gpu:
explainer = shap.GPUTreeExplainer(model, bkg)
Expand Down
1 change: 1 addition & 0 deletions drexml/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"circuits_zenodo": False,
"genes": None,
"genes_zenodo": False,
"activity_normalizer": "false",
"circuits_column": "in_disease",
"genes_column": "drugbank_approved_targets",
"GTEX_VERSION": "v8",
Expand Down
3 changes: 1 addition & 2 deletions drexml/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,12 @@ def fetch_file(key, env, version="latest"):
try:
zenodo = Zenodo()
path = zenodo.download_latest(RECORD_ID, env[key], force=False)
except (ConnectTimeout) as err:
except ConnectTimeout as err:
print(err)
path = pathlib.Path.home().joinpath(
".data", "zenodo", RECORD_ID, "20230612"
)
else:

path = env[key]

print(key, path)
Expand Down
Loading

0 comments on commit b59e1ce

Please sign in to comment.