Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make SPRAS installable #126

Merged
merged 7 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ After completing this step, try running the Local Neighborhood algorithm through
```bash
snakemake --cores 1 --configfile config/config.yaml
```
Make sure to run the command inside the `spras` conda environment.
Make sure to run the command inside the `spras` conda environment. If installing via `pip` instead of using conda, install with the `-e .[dev]` options (the full command to run from the repo root is `python -m pip install -e .[dev]`) so that Python picks up any changes you make and installs all optional development packages. Omitting the `-e` flag will prevent your changes from being reflected unless you force re-install, and omitting `.[dev]` will prevent pip from installing `pre-commit` and `pytest`.

As a workflow manager, Snakemake will consider the work described in the configuration file to be completed once the necessary output files have been written to the relevant output directory (`output` in the `config/config.yaml` configuration).
That means that if you change your code and rerun the Snakemake command above, nothing may happen if the output files already exist.
Expand Down Expand Up @@ -223,7 +223,7 @@ Example errors include a yaml file that cannot be parsed or a local variable tha
These tests are run automatically on every commit through the GitHub Actions.
However, developers will benefit from setting up their environment to run the same tests locally while they modify the SPRAS source.

The `pre-commit` package is installed as part of the conda environment in `environment.yml`.
The `pre-commit` package is installed as part of the conda environment in `environment.yml`, or when installing SPRAS with `python -m pip install -e .[dev]`.
From there, the pre-commit [quick start](https://pre-commit.com/#quick-start) guide explains two primary ways to use it locally:
- run against all source files with `pre-commit run --all-files` to identify errors and automatically fix them when possible
- configure `git` to run the hooks before every `git commit` so that a commit will only succeed if the tests pass, ensuring new errors are not introduced
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ conda activate spras
to create a conda environment with the required packages and activate that environment.
If you have a different version of Python already, you can install the specified versions of the required packages in your preferred manner instead of using Anaconda.

SPRAS can also be installed with Python's package manager `pip` by running `python -m pip install .` from the repo's root directory. This makes SPRAS more portable by allowing you to run
snakemake anywhere the Snakefile, data, and configuration file can be accessed. However, use caution when pip installing directly to your computer without using some form of virtual
environment as this can alter your system's underlying python modules, which could lead to unexpected behavior.

For developers, SPRAS can be installed via `pip` with the `-e` flag, as in `python -m pip install -e .`. This points Python back to the SPRAS repo so that any changes made to the source
code are reflected in the installed module.

jhiemstrawisc marked this conversation as resolved.
Show resolved Hide resolved
You also need to install [Docker](https://docs.docker.com/get-docker/).
After installing Docker, start Docker before running SPRAS.

Expand All @@ -60,7 +67,7 @@ The files to create these Docker images are in the `docker-wrappers` subdirector
The Docker images are available on [DockerHub](https://hub.docker.com/orgs/reedcompbio).

**Python wrapper for calling algorithms**: Wrapper functions provide an interface between the common file formats for input and output data and the algorithm-specific file formats and reconstruction commands.
These wrappers are in the `src/` subdirectory.
These wrappers are in the `spras/` subdirectory.

**Test code**: Tests for the Docker wrappers and SPRAS code.
The tests require the conda environment in `environment.yml` and Docker.
Expand Down
8 changes: 4 additions & 4 deletions Snakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import os
from src import runner
from spras import runner
import shutil
import yaml
from src.dataset import Dataset
from src.util import process_config
from src.analysis import ml, summary, graphspace, cytoscape
from spras.dataset import Dataset
from spras.util import process_config
from spras.analysis import ml, summary, graphspace, cytoscape

# Snakemake updated the behavior in the 6.5.0 release https://github.com/snakemake/snakemake/pull/1037
# and using the wrong separator prevents Snakemake from matching filenames to the rules that can produce them
Expand Down
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ dependencies:
- python=3.8
- pip=22.1
- requests=2.28
- scikit-learn=1.1
- scikit-learn=1.2
- seaborn=0.12
- spython=0.2
# Only required for GraphSpace
Expand All @@ -25,4 +25,4 @@ dependencies:
- sphinx=5.0
- pip:
- graphspace_python==1.3.1
- sphinx-rtd-theme==1.0.0
- sphinx-rtd-theme==1.2.0
63 changes: 63 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,60 @@
[project]
name = "spras"
version = "0.0.1"
description = "Signaling Pathway Reconstruction Analysis Streamliner"
authors = [
{ name = "Anthony Gitter", email = "[email protected]" },
{ name = "Anna Ritz", email = "[email protected]"},
]
license = { file = "LICENSE" }
readme = "README.md"
classifiers = [
"Development Status :: 3 - Alpha",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
jhiemstrawisc marked this conversation as resolved.
Show resolved Hide resolved
"Programming Language :: Python :: 3",
"Topic :: Scientific/Engineering :: Bio-Informatics",
]
requires-python = ">=3.8"
dependencies = [
"adjusttext==0.7.3",
"snakemake==7.19.1",
"docker==5.0.3", # Switched from docker-py to docker because docker-py is not maintained in pypi. This appears to have no effect
"matplotlib==3.5",
"networkx==2.8",
"pandas==1.4",
"pip==22.1",
"requests==2.28",
"scikit-learn==1.2",
"seaborn==0.12",
"spython==0.2",
# Only required for GraphSpace
"commonmark==0.9",
"docutils==0.18",
"jinja2==3.1",
"mock==4.0",
"recommonmark==0.7",
"sphinx==5.0",
"graphspace_python==1.3.1",
"sphinx-rtd-theme==1.2.0",
]

[project.optional-dependencies]
dev = [
# Only required for development
"pre-commit==2.20",
"pytest==7.1",
]

[project.urls]
"Homepage" = "https://github.com/Reed-CompBio/spras"
"Issues" = "https://github.com/Reed-CompBio/spras/issues"

[build-system]
requires = ["setuptools>=64.0"]
build-backend = "setuptools.build_meta"

[tool.ruff]
target-version = "py38"
# Autofix errors when possible
Expand All @@ -16,3 +73,9 @@ select = [
"I", # isort
"W292", # missing-newline-at-end-of-file
]

[tool.setuptools]
# py-modules tells setuptools which directory is our actual module
py-modules = ["spras"]
# packages tells setuptools what the exported package is called (ie allows import spras)
packages = ["spras", "spras.analysis"]
File renamed without changes.
4 changes: 2 additions & 2 deletions src/allpairs.py → spras/allpairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pandas as pd

from src.prm import PRM
from src.util import prepare_volume, run_container
from spras.prm import PRM
from spras.util import prepare_volume, run_container

__all__ = ['AllPairs']

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/analysis/cytoscape.py → spras/analysis/cytoscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from shutil import rmtree
from typing import List, Union

from src.util import prepare_volume, run_container
from spras.util import prepare_volume, run_container


def run_cytoscape(pathways: List[Union[str, PurePath]], output_file: str, singularity: bool = False) -> None:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/analysis/ml.py → spras/analysis/ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

from src.util import make_required_dirs
from spras.util import make_required_dirs

plt.switch_backend('Agg')

Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/domino.py → spras/domino.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pandas as pd

from src.prm import PRM
from src.util import prepare_volume, run_container
from spras.prm import PRM
from spras.util import prepare_volume, run_container

__all__ = ['DOMINO', 'pre_domino_id_transform', 'post_domino_id_transform']

Expand Down
4 changes: 2 additions & 2 deletions src/meo.py → spras/meo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pandas as pd

from src.prm import PRM
from src.util import prepare_volume, run_container
from spras.prm import PRM
from spras.util import prepare_volume, run_container

__all__ = ['MEO', 'write_properties']

Expand Down
4 changes: 2 additions & 2 deletions src/mincostflow.py → spras/mincostflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pandas as pd

from src.prm import PRM
from src.util import prepare_volume, run_container
from spras.prm import PRM
from spras.util import prepare_volume, run_container

__all__ = ['MinCostFlow']

Expand Down
4 changes: 2 additions & 2 deletions src/omicsintegrator1.py → spras/omicsintegrator1.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import pandas as pd

from src.prm import PRM
from src.util import prepare_volume, run_container
from spras.prm import PRM
from spras.util import prepare_volume, run_container

__all__ = ['OmicsIntegrator1', 'write_conf']

Expand Down
6 changes: 3 additions & 3 deletions src/omicsintegrator2.py → spras/omicsintegrator2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import pandas as pd

from src.dataset import Dataset
from src.prm import PRM
from src.util import add_rank_column, prepare_volume, run_container
from spras.dataset import Dataset
from spras.prm import PRM
from spras.util import add_rank_column, prepare_volume, run_container

__all__ = ['OmicsIntegrator2']

Expand Down
4 changes: 2 additions & 2 deletions src/pathlinker.py → spras/pathlinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import pandas as pd

from src.prm import PRM
from src.util import prepare_volume, run_container
from spras.prm import PRM
from spras.util import prepare_volume, run_container

__all__ = ['PathLinker']

Expand Down
File renamed without changes.
16 changes: 8 additions & 8 deletions src/runner.py → spras/runner.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# supported algorithm imports
from src.allpairs import AllPairs as allpairs
from src.dataset import Dataset
from src.domino import DOMINO as domino
from src.meo import MEO as meo
from src.mincostflow import MinCostFlow as mincostflow
from src.omicsintegrator1 import OmicsIntegrator1 as omicsintegrator1
from src.omicsintegrator2 import OmicsIntegrator2 as omicsintegrator2
from src.pathlinker import PathLinker as pathlinker
from spras.allpairs import AllPairs as allpairs
from spras.dataset import Dataset
from spras.domino import DOMINO as domino
from spras.meo import MEO as meo
from spras.mincostflow import MinCostFlow as mincostflow
from spras.omicsintegrator1 import OmicsIntegrator1 as omicsintegrator1
from spras.omicsintegrator2 import OmicsIntegrator2 as omicsintegrator2
from spras.pathlinker import PathLinker as pathlinker


def run(algorithm, params):
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/AllPairs/test_ap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from src.allpairs import AllPairs
from spras.allpairs import AllPairs

TEST_DIR = 'test/AllPairs/'
OUT_DIR = TEST_DIR+'output/'
Expand Down
2 changes: 1 addition & 1 deletion test/DOMINO/test_domino.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from src.domino import DOMINO, post_domino_id_transform, pre_domino_id_transform
from spras.domino import DOMINO, post_domino_id_transform, pre_domino_id_transform

TEST_DIR = 'test/DOMINO/'
OUT_FILE_DEFAULT = TEST_DIR+'output/domino-output.txt'
Expand Down
2 changes: 1 addition & 1 deletion test/MEO/test_meo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from src.meo import MEO, write_properties
from spras.meo import MEO, write_properties

TEST_DIR = 'test/MEO/'
OUT_FILE = TEST_DIR + 'output/edges.txt'
Expand Down
2 changes: 1 addition & 1 deletion test/MinCostFlow/test_mcf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from src.mincostflow import MinCostFlow
from spras.mincostflow import MinCostFlow

TEST_DIR = 'test/MinCostFlow/'
OUT_FILE = TEST_DIR + 'output/mincostflow-output.txt'
Expand Down
2 changes: 1 addition & 1 deletion test/OmicsIntegrator1/test_oi1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from src.omicsintegrator1 import OmicsIntegrator1, write_conf
from spras.omicsintegrator1 import OmicsIntegrator1, write_conf

TEST_DIR = 'test/OmicsIntegrator1/'
OUT_FILE = TEST_DIR+'output/test_optimalForest.sif'
Expand Down
2 changes: 1 addition & 1 deletion test/OmicsIntegrator2/test_oi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from src.omicsintegrator2 import OmicsIntegrator2
from spras.omicsintegrator2 import OmicsIntegrator2

TEST_DIR = 'test/OmicsIntegrator2/'
EDGE_FILE = TEST_DIR+'input/oi2-edges.txt'
Expand Down
2 changes: 1 addition & 1 deletion test/PathLinker/test_pathlinker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from src.pathlinker import PathLinker
from spras.pathlinker import PathLinker

TEST_DIR = 'test/PathLinker/'
OUT_FILE_DEFAULT = TEST_DIR+'output/pathlinker-ranked-edges.txt'
Expand Down
4 changes: 2 additions & 2 deletions test/analysis/test_analysis.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import src.analysis.graphspace as graphspace
import src.analysis.summary as summary
import spras.analysis.graphspace as graphspace
import spras.analysis.summary as summary

TEST_DIR = 'test/analysis/'

Expand Down
2 changes: 1 addition & 1 deletion test/analysis/test_cytoscape.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest

from src.analysis.cytoscape import run_cytoscape
from spras.analysis.cytoscape import run_cytoscape

INPUT_DIR = 'test/analysis/input/example/'
INPUT_PATHWAYS = [INPUT_DIR + 'data0-meo-params-GKEDDFZ_pathway.txt',
Expand Down
2 changes: 1 addition & 1 deletion test/analysis/test_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pandas as pd

from src.analysis.summary import summarize_networks
from spras.analysis.summary import summarize_networks

# Notes:
# - Column labels are required in the node table
Expand Down
2 changes: 1 addition & 1 deletion test/ml/test_ml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pandas as pd

import src.analysis.ml as ml
import spras.analysis.ml as ml

INPUT_DIR = 'test/ml/input/'
OUT_DIR = 'test/ml/output/'
Expand Down
2 changes: 1 addition & 1 deletion test/test_prepare_inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import yaml

from src import runner
from spras import runner

config_loc = os.path.join("config", "config.yaml")

Expand Down
2 changes: 1 addition & 1 deletion test/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from src.util import (
from spras.util import (
convert_docker_path,
hash_params_sha1_base32,
prepare_path_docker,
Expand Down
Loading