Skip to content

Commit

Permalink
refactor pose_cluster_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Duane Walker authored and misterbrandonwalker committed Jul 25, 2024
1 parent 23fb84d commit 202c1d6
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 251 deletions.
5 changes: 5 additions & 0 deletions utils/docking/diffdock/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.pdb filter=lfs diff=lfs merge=lfs -text
*.pdbqt filter=lfs diff=lfs merge=lfs -text
*.mol2 filter=lfs diff=lfs merge=lfs -text
*.xlsx filter=lfs diff=lfs merge=lfs -text
*.sdf filter=lfs diff=lfs merge=lfs -text
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# docker build -f Dockerfile -t mrbrandonwalker/pose_cluster_filter_tool .
# docker build -f Dockerfile -t polusai/pose-cluster-filter-tool .
FROM condaforge/mambaforge

ENV EXEC_DIR="/opt/executables"
Expand All @@ -16,16 +16,11 @@ COPY README.md ${EXEC_DIR}
COPY CHANGELOG.md ${EXEC_DIR}

# Install needed packages here
# errors installing rdkit 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
RUN pip3 install ${EXEC_DIR} --no-cache-dir

CMD ["--help"]
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

version=$(<VERSION)
docker build . -t polusai/pose-cluster-filter-tool:${version}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
specVersion: "0.1.0"
name: pose_cluster_filter
version: 0.1.0
container: pose-cluster-filter-plugin
container: pose-cluster-filter-tool
entrypoint:
title: pose_cluster_filter
description: Cluster poses in protein and take max confident pose for each cluster
author: Data Scientist
contact: [email protected]
author: Brandon Walker, Nazanin Donyapour
contact: [email protected], [email protected]
repository:
documentation:
citation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ label: Cluster poses in protein and take max confident pose for each cluster
doc: |-
Cluster poses in protein and take max confident pose for each cluster

baseCommand: ["conda", "run", "-n", "project_env", "python", "-m", "polus.mm.utils.pose_cluster_filter"]
baseCommand: ["python", "-m", "polus.mm.utils.pose_cluster_filter"]

hints:
DockerRequirement:
dockerPull: mrbrandonwalker/pose_cluster_filter_tool
dockerPull: polusai/pose-cluster-filter-tool@sha256:f30068018bf5e04f6c19ea9fe44349066732720d0307d0a569dabb98d199312e

requirements:
InlineJavascriptRequirement: {}
Expand All @@ -30,8 +30,8 @@ inputs:
type:
type: array
items: File
inputBinding:
prefix: --predicted_poses
inputBinding:
prefix: --predicted_poses
format: edam:format_3814

outputs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ readme = "README.md"
packages = [{include = "polus", from = "src"}]

[tool.poetry.dependencies]
python = ">=3.9,<3.12"
typer = "^0.7.0"
sophios = "0.1.1"
rdkit = "2024.3.3"

[tool.poetry.group.dev.dependencies]
bump2version = "^1.0.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Package entrypoint for the pose_cluster_filter package."""

# Base packages
import argparse
import logging
from os import environ
from pathlib import Path

import typer
from polus.mm.utils.pose_cluster_filter.pose_cluster_filter import pose_cluster_filter

# Set up logging
logging.basicConfig(
format="%(asctime)s - %(name)-8s - %(levelname)-8s - %(message)s",
datefmt="%d-%b-%y %H:%M:%S",
Expand All @@ -16,31 +17,44 @@
logger = logging.getLogger("polus.mm.utils.pose_cluster_filter.")
logger.setLevel(POLUS_LOG)

app = typer.Typer(help="pose_cluster_filter.")

def main() -> None:
"""Parse the arguments and call the function."""
# Create the argument parser
parser = argparse.ArgumentParser(description="pose_cluster_filter.")

@app.command()
def main(
centroid_cutoff: float = typer.Option(
...,
# Add arguments
parser.add_argument(
"--centroid_cutoff",
help="",
),
predicted_poses: list[Path] = typer.Option(
...,
type=float,
required=True,
help="The cutoff distance for the centroid.",
)
parser.add_argument(
"--predicted_poses",
help="",
),
) -> None:
"""pose_cluster_filter."""
type=Path,
nargs="+",
required=True,
help="A list of paths to the predicted poses.",
)

# Parse the arguments
args = parser.parse_args()

# Extract arguments
centroid_cutoff = args.centroid_cutoff
predicted_poses = args.predicted_poses

# Log the arguments
logger.info(f"centroid_cutoff: {centroid_cutoff}")
logger.info(f"predicted_poses: {predicted_poses}")

# Call the function with the arguments
pose_cluster_filter(
centroid_cutoff=centroid_cutoff,
predicted_poses=predicted_poses,
)


if __name__ == "__main__":
app()
main()
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
"""Tests for pose_cluster_filter."""
import sys
from pathlib import Path

from polus.mm.utils.pose_cluster_filter.pose_cluster_filter import pose_cluster_filter

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
from sophios.api.pythonapi import Step
from sophios.api.pythonapi import Workflow


def test_pose_cluster_filter() -> None:
Expand All @@ -35,22 +28,38 @@ def test_pose_cluster_filter() -> None:

def test_pose_cluster_filter_cwl() -> None:
"""Test the pose_cluster_filter CWL."""
cwl_file = Path("pose_cluster_filter.cwl")
input_to_props = parse_cwl_arguments(cwl_file)
cwl_file_str = "pose_cluster_filter_0@[email protected]"
cwl_file = Path(__file__).resolve().parent.parent / Path(cwl_file_str)

predicted_poses = [
"rank2_confidence0.35.sdf",
"rank3_confidence0.34.sdf",
"rank1_confidence0.36.sdf",
]
file_dict = input_to_props["predicted_poses"][0]
input_to_props["predicted_poses"] = []
for pose in predicted_poses:
file_dict_current = file_dict.copy()
path_pose = str(Path(__file__).resolve().parent / Path(pose))
file_dict_current["path"] = path_pose
input_to_props["predicted_poses"].append(file_dict_current)

input_yaml_path = Path("pose_cluster_filter.yml")
create_input_yaml(input_to_props, input_yaml_path)
stdout, stderr = call_cwltool(cwl_file, input_yaml_path)
assert "success" in stderr

pose_cluster_filter = Step(clt_path=cwl_file)
pose_cluster_filter.predicted_poses = [
{
"format": "edam:format_3814",
"class": "File",
"path": str(Path(__file__).resolve().parent / Path(pose)),
}
for pose in predicted_poses
]
pose_cluster_filter.centroid_cutoff = 5

steps = [pose_cluster_filter]
filename = "pose_cluster_filter"
viz = Workflow(steps, filename)

viz.run()

outdir = Path("outdir")

# Use rglob to find all .sdf files
sdf_files = list(outdir.rglob("*.sdf"))

# Check if any .sdf files were found
if not sdf_files:
msg = f"No .sdf files found in '{outdir}'."
raise FileNotFoundError(msg)
4 changes: 0 additions & 4 deletions utils/pose-cluster-filter-plugin/build-docker.sh

This file was deleted.

9 changes: 0 additions & 9 deletions utils/pose-cluster-filter-plugin/environment.yml

This file was deleted.

62 changes: 0 additions & 62 deletions utils/pose-cluster-filter-plugin/tests/rank1_confidence0.36.sdf

This file was deleted.

62 changes: 0 additions & 62 deletions utils/pose-cluster-filter-plugin/tests/rank2_confidence0.35.sdf

This file was deleted.

Loading

0 comments on commit 202c1d6

Please sign in to comment.