Skip to content

Commit

Permalink
Make SPRAS installable
Browse files Browse the repository at this point in the history
This commit adds the ability to install spras as a python module using pip,
which is something we'll need for running in remote environments such as on
the OSPool. The installation "instructions" used by pip during building are
laid out in `pyproject.toml`. While I chose to use setup-tools as a builder
backend in this first pass, other builder backends with more robust build
features are available and may eventually be switched to (eg flit, poetry).

Several additional files had to be modified to adhere to python packaging
guidelines, the most notable of which was changing `src` to spras, and referencing
the new spras directory instead of src. Several lines of omicsintegrator2.py were
also modified becasue they were dealing with an absolute path, which made the
workflow un-runnable outside of the repo. I verified that all tests and the entirety of
the snakefile still run both in the conda environment from the repo root (which is
how the tool is currently used) and in a separate directory with spras installed where
the input data, snakefile, and config file have been brought along.

For testing, install spras using `pip install .` in the repo root. If the extra
development packages are needed, spras can be installed with the command
`pip install .[dev]`. Spras can also be installed via `pip install -e .` to
make the installation editable. That is, when installed via this command, you
can continue to edit spras in the repo and have those changes reflected anywhere
you run spras on the machine.

Note that several package versions had to be modified (they're noted in
pyproject.toml) to get past a few versioning issues between conda and pypi. To the
extent of my knowledge and testing, these changes didn't affect the way spras runs.
Famous last words?
jhiemstrawisc committed Sep 18, 2023
1 parent 17af0e9 commit 60d7ce8
Showing 30 changed files with 100 additions and 41 deletions.
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
from spras.dataset import Dataset
from spras.util import process_config
from spras.analysis import ml, summary, graphspace

# 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
59 changes: 59 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,56 @@
[project]
name = "SPRAS"
version = "v0.0.1"
description = "Signaling Pathway Reconstruction Analysis Streamliner (SPRAS)"
authors = [
{ name = "Anthony Gitter", email = "[email protected]" },
]
license = { file = "LICENSE" }
readme = "README.md"
classifiers = [
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
]
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", #Version bumped from 1.1-->1.2 to get past compilation errors. No other errors encountered
"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.0.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"
"Bug Tracker" = "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
@@ -16,3 +69,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
@@ -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']

File renamed without changes.
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
@@ -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')

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
@@ -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']

4 changes: 2 additions & 2 deletions src/meo.py → spras/meo.py
Original file line number Diff line number Diff line change
@@ -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']

4 changes: 2 additions & 2 deletions src/mincostflow.py → spras/mincostflow.py
Original file line number Diff line number Diff line change
@@ -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']

4 changes: 2 additions & 2 deletions src/omicsintegrator1.py → spras/omicsintegrator1.py
Original file line number Diff line number Diff line change
@@ -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']

6 changes: 3 additions & 3 deletions src/omicsintegrator2.py → spras/omicsintegrator2.py
Original file line number Diff line number Diff line change
@@ -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.prm import PRM
from spras.util import add_rank_column, prepare_volume, run_container
from spras.dataset import Dataset

__all__ = ['OmicsIntegrator2']

4 changes: 2 additions & 2 deletions src/pathlinker.py → spras/pathlinker.py
Original file line number Diff line number Diff line change
@@ -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']

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):
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
@@ -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/'
2 changes: 1 addition & 1 deletion test/DOMINO/test_domino.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion test/MEO/test_meo.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion test/MinCostFlow/test_mcf.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion test/OmicsIntegrator1/test_oi1.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion test/OmicsIntegrator2/test_oi2.py
Original file line number Diff line number Diff line change
@@ -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'
2 changes: 1 addition & 1 deletion test/PathLinker/test_pathlinker.py
Original file line number Diff line number Diff line change
@@ -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'
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/'

2 changes: 1 addition & 1 deletion test/analysis/test_summary.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion test/ml/test_ml.py
Original file line number Diff line number Diff line change
@@ -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/'
2 changes: 1 addition & 1 deletion test/test_prepare_inputs.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@

import yaml

from src import runner
from spras import runner

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

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

import pytest

from src.util import (
from spras.util import (
convert_docker_path,
hash_params_sha1_base32,
prepare_path_docker,

0 comments on commit 60d7ce8

Please sign in to comment.