From 8fa99ac703f58a721543e86485f733867af5e31a Mon Sep 17 00:00:00 2001 From: Brandon Duane Walker Date: Mon, 3 Jun 2024 14:42:23 -0400 Subject: [PATCH] refactor pdbfixer --- utils/pdbfixer-plugin/Dockerfile | 25 ------- utils/pdbfixer-plugin/tests/test_pdbfixer.py | 67 ------------------- .../pdbfixer-tool}/.bumpversion.cfg | 0 .../pdbfixer-tool}/.dockerignore | 0 .../pdbfixer-tool}/.gitignore | 0 .../pdbfixer-tool}/CHANGELOG.md | 0 .../structure-change/pdbfixer-tool/Dockerfile | 31 +++++++++ .../structure-change/pdbfixer-tool}/README.md | 2 +- .../structure-change/pdbfixer-tool}/VERSION | 0 .../pdbfixer-tool}/environment.yml | 5 +- .../structure-change/pdbfixer-tool}/ict.yml | 5 +- .../pdbfixer-tool/pdb_fixer_0@1@0.cwl} | 2 +- .../pdbfixer-tool}/pyproject.toml | 0 .../src/polus/mm/utils/pdbfixer/__init__.py | 0 .../src/polus/mm/utils/pdbfixer/__main__.py | 0 .../src/polus/mm/utils/pdbfixer/pdbfixer.py | 0 .../pdbfixer-tool}/tests/1msn_protein.pdb | 0 .../pdbfixer-tool}/tests/__init__.py | 0 .../pdbfixer-tool/tests/test_pdbfixer.py | 64 ++++++++++++++++++ 19 files changed, 103 insertions(+), 98 deletions(-) delete mode 100644 utils/pdbfixer-plugin/Dockerfile delete mode 100644 utils/pdbfixer-plugin/tests/test_pdbfixer.py rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/.bumpversion.cfg (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/.dockerignore (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/.gitignore (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/CHANGELOG.md (100%) create mode 100644 utils/pre-process/structure-change/pdbfixer-tool/Dockerfile rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/README.md (92%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/VERSION (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/environment.yml (74%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/ict.yml (86%) rename utils/{pdbfixer-plugin/pdb_fixer.cwl => pre-process/structure-change/pdbfixer-tool/pdb_fixer_0@1@0.cwl} (95%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/pyproject.toml (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/src/polus/mm/utils/pdbfixer/__init__.py (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/src/polus/mm/utils/pdbfixer/__main__.py (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/src/polus/mm/utils/pdbfixer/pdbfixer.py (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/tests/1msn_protein.pdb (100%) rename utils/{pdbfixer-plugin => pre-process/structure-change/pdbfixer-tool}/tests/__init__.py (100%) create mode 100644 utils/pre-process/structure-change/pdbfixer-tool/tests/test_pdbfixer.py diff --git a/utils/pdbfixer-plugin/Dockerfile b/utils/pdbfixer-plugin/Dockerfile deleted file mode 100644 index 7111a1a9..00000000 --- a/utils/pdbfixer-plugin/Dockerfile +++ /dev/null @@ -1,25 +0,0 @@ -# docker build -f Dockerfile -t mrbrandonwalker/pdbfixer . - -FROM condaforge/mambaforge -# pdbfixer not installable with poetry - -ENV EXEC_DIR="/opt/executables" -ENV POLUS_LOG="INFO" -RUN mkdir -p ${EXEC_DIR} - -# Work directory defined in the base container -# WORKDIR ${EXEC_DIR} - -COPY pyproject.toml ${EXEC_DIR} -COPY VERSION ${EXEC_DIR} -COPY README.md ${EXEC_DIR} -COPY CHANGELOG.md ${EXEC_DIR} -COPY src ${EXEC_DIR}/src -WORKDIR ${EXEC_DIR} - -# Install needed packages here -RUN mamba install -c conda-forge pdbfixer - -RUN pip3 install ${EXEC_DIR} --no-cache-dir - -CMD ["--help"] diff --git a/utils/pdbfixer-plugin/tests/test_pdbfixer.py b/utils/pdbfixer-plugin/tests/test_pdbfixer.py deleted file mode 100644 index 2a260bd6..00000000 --- a/utils/pdbfixer-plugin/tests/test_pdbfixer.py +++ /dev/null @@ -1,67 +0,0 @@ -"""Tests for pdbfixer.""" -import sys -from pathlib import Path - -from polus.mm.utils.pdbfixer.pdbfixer import runpdbfixer - -current_dir = Path(__file__).resolve().parent -target_dir = current_dir.parent.parent.parent / "cwl_utils" -sys.path.append(str(target_dir)) - -from cwl_utilities import call_cwltool # noqa: E402 -from cwl_utilities import create_input_yaml # noqa: E402 -from cwl_utilities import parse_cwl_arguments # noqa: E402 - - -def test_pdbfixer() -> None: - """Test pdbfixer.""" - add_atoms = "all" - add_residues = True - pdbid = "" - url = "" - replace_nonstandard = True - keep_heterogens = "all" - input_pdb_path = "1msn_protein.pdb" - input_helper_pdb_path = "1msn_protein.pdb" - input_pdb_path = str(Path(__file__).resolve().parent / Path(input_pdb_path)) - input_helper_pdb_path = str( - Path(__file__).resolve().parent / Path(input_helper_pdb_path), - ) - output_pdb_path = "test.pdb" - output_pdb_path = str(Path(__file__).resolve().parent / Path(output_pdb_path)) - - runpdbfixer( - input_pdb_path, - input_helper_pdb_path, - output_pdb_path, - add_atoms, - add_residues, - pdbid, - url, - replace_nonstandard, - keep_heterogens, - ) - - assert Path(output_pdb_path).exists() - - -def test_cwl_pdb_fixer() -> None: - """Test the pdbfixer function in cwltool.""" - cwl_file = Path("pdb_fixer.cwl") - input_to_props = parse_cwl_arguments(cwl_file) - input_pdb_path = "1msn_protein.pdb" - input_pdb_path = str(Path(__file__).resolve().parent / Path(input_pdb_path)) - input_to_props["input_pdb_path"]["path"] = input_pdb_path - input_to_props["input_pdb_path"]["class"] = "File" - input_helper_pdb_path = "1msn_protein.pdb" - input_helper_pdb_path = str( - Path(__file__).resolve().parent / Path(input_helper_pdb_path), - ) - input_to_props["input_helper_pdb_path"]["path"] = input_helper_pdb_path - input_to_props["input_helper_pdb_path"]["class"] = "File" - input_to_props["output_pdb_path"] = "output.pdb" - input_yaml_path = Path("pdb_fixer.yml") - create_input_yaml(input_to_props, input_yaml_path) - stdout, stderr = call_cwltool(cwl_file, input_yaml_path) - - assert Path("output.pdb").exists() diff --git a/utils/pdbfixer-plugin/.bumpversion.cfg b/utils/pre-process/structure-change/pdbfixer-tool/.bumpversion.cfg similarity index 100% rename from utils/pdbfixer-plugin/.bumpversion.cfg rename to utils/pre-process/structure-change/pdbfixer-tool/.bumpversion.cfg diff --git a/utils/pdbfixer-plugin/.dockerignore b/utils/pre-process/structure-change/pdbfixer-tool/.dockerignore similarity index 100% rename from utils/pdbfixer-plugin/.dockerignore rename to utils/pre-process/structure-change/pdbfixer-tool/.dockerignore diff --git a/utils/pdbfixer-plugin/.gitignore b/utils/pre-process/structure-change/pdbfixer-tool/.gitignore similarity index 100% rename from utils/pdbfixer-plugin/.gitignore rename to utils/pre-process/structure-change/pdbfixer-tool/.gitignore diff --git a/utils/pdbfixer-plugin/CHANGELOG.md b/utils/pre-process/structure-change/pdbfixer-tool/CHANGELOG.md similarity index 100% rename from utils/pdbfixer-plugin/CHANGELOG.md rename to utils/pre-process/structure-change/pdbfixer-tool/CHANGELOG.md diff --git a/utils/pre-process/structure-change/pdbfixer-tool/Dockerfile b/utils/pre-process/structure-change/pdbfixer-tool/Dockerfile new file mode 100644 index 00000000..9b20b9d0 --- /dev/null +++ b/utils/pre-process/structure-change/pdbfixer-tool/Dockerfile @@ -0,0 +1,31 @@ +# docker build -f Dockerfile -t polusai/pdbfixer-tool . + +FROM condaforge/mambaforge + +ENV EXEC_DIR="/opt/executables" +ENV POLUS_LOG="INFO" +RUN mkdir -p ${EXEC_DIR} + + +# Work directory defined in the base container +# WORKDIR ${EXEC_DIR} + +COPY pyproject.toml ${EXEC_DIR} +COPY VERSION ${EXEC_DIR} +COPY README.md ${EXEC_DIR} +COPY CHANGELOG.md ${EXEC_DIR} + +# Install needed packages here +# errors installing pdbfixer from poetry so using conda +COPY environment.yml ${EXEC_DIR} +RUN mamba env create -f ${EXEC_DIR}/environment.yml +RUN echo "source activate project_env" > ~/.bashrc +ENV PATH /opt/conda/envs/env/bin:$PATH + +COPY src ${EXEC_DIR}/src + +ADD Dockerfile . + +RUN conda run -n project_env pip install ${EXEC_DIR} --no-cache-dir + +CMD ["--help"] diff --git a/utils/pdbfixer-plugin/README.md b/utils/pre-process/structure-change/pdbfixer-tool/README.md similarity index 92% rename from utils/pdbfixer-plugin/README.md rename to utils/pre-process/structure-change/pdbfixer-tool/README.md index e9efad65..5277c939 100644 --- a/utils/pdbfixer-plugin/README.md +++ b/utils/pre-process/structure-change/pdbfixer-tool/README.md @@ -12,7 +12,7 @@ This plugin takes 9 input arguments and 1 output argument: | input_helper_pdb_path | Template input PDB path | Input | File | File | | pdbid | PDB id from RCSB? | Input | string | string | | url | URL to retrieve PDB from | Input | string | string | -| output_pdb_path | | Input | string | string | +| output_pdb_path | Output protein file path name | Input | string | string | | add_atoms | What missing atoms to add, all, heavy or none | Input | string | string | | add_residues | If set to True, adds missing residue | Input | boolean | boolean | | replace_nonstandard | Replace nonstandard residues with standard equivalents | Input | boolean | boolean | diff --git a/utils/pdbfixer-plugin/VERSION b/utils/pre-process/structure-change/pdbfixer-tool/VERSION similarity index 100% rename from utils/pdbfixer-plugin/VERSION rename to utils/pre-process/structure-change/pdbfixer-tool/VERSION diff --git a/utils/pdbfixer-plugin/environment.yml b/utils/pre-process/structure-change/pdbfixer-tool/environment.yml similarity index 74% rename from utils/pdbfixer-plugin/environment.yml rename to utils/pre-process/structure-change/pdbfixer-tool/environment.yml index 191f0f5f..0b778e25 100644 --- a/utils/pdbfixer-plugin/environment.yml +++ b/utils/pre-process/structure-change/pdbfixer-tool/environment.yml @@ -7,5 +7,6 @@ dependencies: - pdbfixer==1.9 - ruamel.yaml==0.17.21 - pytest==8.1.1 - - cwltool==3.1.20240404144621 - - cwl-utils==0.33 + - pip + - pip: + - sophios==0.1.1 diff --git a/utils/pdbfixer-plugin/ict.yml b/utils/pre-process/structure-change/pdbfixer-tool/ict.yml similarity index 86% rename from utils/pdbfixer-plugin/ict.yml rename to utils/pre-process/structure-change/pdbfixer-tool/ict.yml index ad7abaef..978b3776 100644 --- a/utils/pdbfixer-plugin/ict.yml +++ b/utils/pre-process/structure-change/pdbfixer-tool/ict.yml @@ -1,11 +1,12 @@ specVersion: 0.1.0 name: labshare/pdbfixer version: 0.1.0 -container: polusai/pdbfixer-plugin:0.1.0 +container: polusai/pdbfixer-tool:0.1.0 entrypoint: "" title: pdbfixer description: Fix pdbfiles. -author: Data Scientist (data.scientist@labshare.org) +author: Brandon Walker, Nazanin Donyapour +contact: brandon.walker@axleinfo.com, nazanin.donyapour@axleinfo.com repository: https://github.com/labshare/mmtools documentation: https://ncats.nih.gov/preclinical/core/informatics citation: diff --git a/utils/pdbfixer-plugin/pdb_fixer.cwl b/utils/pre-process/structure-change/pdbfixer-tool/pdb_fixer_0@1@0.cwl similarity index 95% rename from utils/pdbfixer-plugin/pdb_fixer.cwl rename to utils/pre-process/structure-change/pdbfixer-tool/pdb_fixer_0@1@0.cwl index b71b27e6..9a08c18c 100644 --- a/utils/pdbfixer-plugin/pdb_fixer.cwl +++ b/utils/pre-process/structure-change/pdbfixer-tool/pdb_fixer_0@1@0.cwl @@ -12,7 +12,7 @@ baseCommand: ["python", "-m", "polus.mm.utils.pdbfixer"] hints: DockerRequirement: - dockerPull: mrbrandonwalker/pdbfixer + dockerPull: polusai/pdbfixer-tool@sha256:8c4c7756a3981799da1b7699a471be59684890c365fa4e30c62c96d256eb089f inputs: input_pdb_path: diff --git a/utils/pdbfixer-plugin/pyproject.toml b/utils/pre-process/structure-change/pdbfixer-tool/pyproject.toml similarity index 100% rename from utils/pdbfixer-plugin/pyproject.toml rename to utils/pre-process/structure-change/pdbfixer-tool/pyproject.toml diff --git a/utils/pdbfixer-plugin/src/polus/mm/utils/pdbfixer/__init__.py b/utils/pre-process/structure-change/pdbfixer-tool/src/polus/mm/utils/pdbfixer/__init__.py similarity index 100% rename from utils/pdbfixer-plugin/src/polus/mm/utils/pdbfixer/__init__.py rename to utils/pre-process/structure-change/pdbfixer-tool/src/polus/mm/utils/pdbfixer/__init__.py diff --git a/utils/pdbfixer-plugin/src/polus/mm/utils/pdbfixer/__main__.py b/utils/pre-process/structure-change/pdbfixer-tool/src/polus/mm/utils/pdbfixer/__main__.py similarity index 100% rename from utils/pdbfixer-plugin/src/polus/mm/utils/pdbfixer/__main__.py rename to utils/pre-process/structure-change/pdbfixer-tool/src/polus/mm/utils/pdbfixer/__main__.py diff --git a/utils/pdbfixer-plugin/src/polus/mm/utils/pdbfixer/pdbfixer.py b/utils/pre-process/structure-change/pdbfixer-tool/src/polus/mm/utils/pdbfixer/pdbfixer.py similarity index 100% rename from utils/pdbfixer-plugin/src/polus/mm/utils/pdbfixer/pdbfixer.py rename to utils/pre-process/structure-change/pdbfixer-tool/src/polus/mm/utils/pdbfixer/pdbfixer.py diff --git a/utils/pdbfixer-plugin/tests/1msn_protein.pdb b/utils/pre-process/structure-change/pdbfixer-tool/tests/1msn_protein.pdb similarity index 100% rename from utils/pdbfixer-plugin/tests/1msn_protein.pdb rename to utils/pre-process/structure-change/pdbfixer-tool/tests/1msn_protein.pdb diff --git a/utils/pdbfixer-plugin/tests/__init__.py b/utils/pre-process/structure-change/pdbfixer-tool/tests/__init__.py similarity index 100% rename from utils/pdbfixer-plugin/tests/__init__.py rename to utils/pre-process/structure-change/pdbfixer-tool/tests/__init__.py diff --git a/utils/pre-process/structure-change/pdbfixer-tool/tests/test_pdbfixer.py b/utils/pre-process/structure-change/pdbfixer-tool/tests/test_pdbfixer.py new file mode 100644 index 00000000..ddb2ec06 --- /dev/null +++ b/utils/pre-process/structure-change/pdbfixer-tool/tests/test_pdbfixer.py @@ -0,0 +1,64 @@ +"""Tests for pdbfixer.""" +from pathlib import Path + +from polus.mm.utils.pdbfixer.pdbfixer import runpdbfixer +from sophios.api.pythonapi import Step +from sophios.api.pythonapi import Workflow + + +def test_pdbfixer() -> None: + """Test pdbfixer.""" + add_atoms = "all" + add_residues = True + pdbid = "" + url = "" + replace_nonstandard = True + keep_heterogens = "all" + input_pdb_path = "1msn_protein.pdb" + input_helper_pdb_path = "1msn_protein.pdb" + input_pdb_path = str(Path(__file__).resolve().parent / Path(input_pdb_path)) + input_helper_pdb_path = str( + Path(__file__).resolve().parent / Path(input_helper_pdb_path), + ) + output_pdb_path = "test.pdb" + output_pdb_path = str(Path(__file__).resolve().parent / Path(output_pdb_path)) + + runpdbfixer( + input_pdb_path, + input_helper_pdb_path, + output_pdb_path, + add_atoms, + add_residues, + pdbid, + url, + replace_nonstandard, + keep_heterogens, + ) + + assert Path(output_pdb_path).exists() + + +def test_cwl_pdb_fixer() -> None: + """Test the pdbfixer function in cwltool.""" + cwl_file_str = "pdb_fixer_0@1@0.cwl" + cwl_file = Path(__file__).resolve().parent / Path(cwl_file_str) + # Create a Step instance for pdb_fixer + pdb_fixer = Step(clt_path=cwl_file) + + # Set input properties + pdb_fixer.input_pdb_path = str(Path(__file__).resolve().parent / "1msn_protein.pdb") + pdb_fixer.input_helper_pdb_path = str( + Path(__file__).resolve().parent / "1msn_protein.pdb", + ) + pdb_fixer.output_pdb_path = "output.pdb" + + # Define the workflow + steps = [pdb_fixer] + filename = "pdb_fixer" + workflow = Workflow(steps, filename) + + # Run the workflow + workflow.run() + + # Check if the output file exists + assert Path("output.pdb").exists(), "The file 'output.pdb' does not exist."