Skip to content

Commit

Permalink
Merge pull request #3 from misterbrandonwalker/sanitize_ligand
Browse files Browse the repository at this point in the history
sanitize_ligand
  • Loading branch information
Nicholas-Schaub authored Feb 29, 2024
2 parents 7024fdd + 9e61384 commit 4cf5932
Show file tree
Hide file tree
Showing 15 changed files with 461 additions and 0 deletions.
29 changes: 29 additions & 0 deletions utils/sanitize-ligand-plugin/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[bumpversion]
current_version = 0.1.1-dev1
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{dev}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = _
first_value = dev
values =
dev
_

[bumpversion:part:dev]

[bumpversion:file:pyproject.toml]
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:VERSION]

[bumpversion:file:README.md]

[bumpversion:file:plugin.json]

[bumpversion:file:src/polus/mm/utils/__init__.py]
4 changes: 4 additions & 0 deletions utils/sanitize-ligand-plugin/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv
out
tests
__pycache__
5 changes: 5 additions & 0 deletions utils/sanitize-ligand-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG

## 0.1.0

Initial release.
27 changes: 27 additions & 0 deletions utils/sanitize-ligand-plugin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM condaforge/mambaforge

# environment variables defined
ENV EXEC_DIR="/opt/executables"

RUN mkdir -p ${EXEC_DIR}
COPY pyproject.toml ${EXEC_DIR}
COPY VERSION ${EXEC_DIR}
COPY README.md ${EXEC_DIR}
COPY CHANGELOG.md ${EXEC_DIR}

RUN conda install -c conda-forge rdkit --yes

RUN pip install filepattern

RUN conda init bash

RUN mamba clean --all --yes

ADD Dockerfile ${EXEC_DIR}

COPY src ${EXEC_DIR}/src

RUN pip3 install ${EXEC_DIR} --no-cache-dir
# Default command. Additional arguments are provided through the command line
ENTRYPOINT ["python3", "-m", "polus.mm.utils"]
CMD ["--help"]
18 changes: 18 additions & 0 deletions utils/sanitize-ligand-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Sanitize Ligand (0.1.1-dev1)

Handle molecules with rdkit errors gracefully.

## Building

To build the Docker image for the conversion plugin, run `./build-docker.sh`.
of `plugin.json` into the pop-up window and submit.

## Options

This plugin takes 2 input arguments and 1 output argument:

| Name | Description | I/O | Type |
|------------------------|----------------------------------|--------|--------|
| pattern | Filepattern to parse files | Input | string
| indir | Input collection | Input | collection
| outdir | Output collection | Output | collection
1 change: 1 addition & 0 deletions utils/sanitize-ligand-plugin/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.1-dev1
4 changes: 4 additions & 0 deletions utils/sanitize-ligand-plugin/build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

version=$(<VERSION)
docker build . -t mm/sanitize-ligand-plugin:${version}
36 changes: 36 additions & 0 deletions utils/sanitize-ligand-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "Sanitize Ligand",
"version": "0.1.1-dev1",
"title": "Sanitize Ligand",
"description": "Handle molecules with rdkit errors gracefully.",
"author": "Brandon Walker ([email protected])",
"institution": "National Center for Advancing Translational Sciences, National Institutes of Health",
"repository": "https://github.com/labshare/polus-plugins",
"website": "https://ncats.nih.gov/preclinical/core/informatics",
"citation": "",
"containerId": "polusai/sanitize-ligand-plugin:0.1.1-dev1",
"baseCommand": [
"python3",
"-m",
"polus.plugins.sanitize_ligand"
],
"inputs": {
"pattern": {
"type": "string",
"title": "Filepattern to parse files",
"description": "Filepattern to parse sdf files for sanitizing.",
"required": "True"
},
"indir": {
"type": "collection",
"description": "Input collection.",
"required": "True"
}
},
"outputs": {
"outdir": {
"type": "collection",
"description": "Output collection."
}
}
}
30 changes: 30 additions & 0 deletions utils/sanitize-ligand-plugin/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tool.poetry]
name = "mm-polus-sanitize-ligand"
version = "0.1.1-dev1"
description = "Handle molecules with rdkit errors gracefully."
authors = ["Brandon Walker <[email protected]>"]
readme = "README.md"
packages = [{include = "polus", from = "src"}]

[tool.poetry.dependencies]
python = ">=3.8"
typer = "^0.7.0"
rdkit = "*"

[tool.poetry.group.dev.dependencies]
bump2version = "^1.0.1"
pytest = "^7.4"
pytest-sugar = "^0.9.6"
pre-commit = "^3.2.1"
black = "^23.3.0"
mypy = "^1.1.1"
ruff = "^0.0.270"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
pythonpath = [
"."
]
13 changes: 13 additions & 0 deletions utils/sanitize-ligand-plugin/run-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

version=$(<VERSION)

container_input_dir="/inddir"
container_output_dir="/outdir"

docker run -v $tool_mount_path_input:${container_input_dir} \
-v $tool_mount_path_output:${container_output_dir} \
mm/sanitize-ligand-plugin:${version} \
--pattern ${pattern} \
--indir ${container_input_dir} \
--outdir ${container_output_dir}
7 changes: 7 additions & 0 deletions utils/sanitize-ligand-plugin/src/polus/mm/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""sanitize_ligand."""

__version__ = "0.1.1-dev1"

from polus.mm.utils.sanitize_ligand import ( # pylint: disable=unused-import
sanitize_ligand,
)
63 changes: 63 additions & 0 deletions utils/sanitize-ligand-plugin/src/polus/mm/utils/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""Package entrypoint for the sanitize_ligand package."""

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

import filepattern as fp
import typer
from polus.mm.utils.sanitize_ligand import sanitize_ligand

logging.basicConfig(
format="%(asctime)s - %(name)-8s - %(levelname)-8s - %(message)s",
datefmt="%d-%b-%y %H:%M:%S",
)
POLUS_LOG = getattr(logging, environ.get("POLUS_LOG", "INFO"))
logger = logging.getLogger("polus.mm.utils.sanitize_ligand")
logger.setLevel(POLUS_LOG)

app = typer.Typer(help="Sanitize Ligand.")


@app.command()
def main(
pattern: str = typer.Option(
...,
"--pattern",
help="Input filepattern to be processed.",
),
in_dir: Path = typer.Option(
...,
"--indir",
help="Input directory.",
exists=True,
writable=True,
file_okay=False,
resolve_path=True,
),
out_dir: Path = typer.Option(
...,
"--outdir",
help="Output directory.",
exists=True,
writable=True,
file_okay=False,
resolve_path=True,
),
) -> None:
"""Sanitize Ligand."""
logger.info(f"pattern: {pattern}")
logger.info(f"indir: {in_dir}")
logger.info(f"outdir: {out_dir}")
ligand_file_paths = []
ligand_files = fp.FilePattern(in_dir, pattern)
for input_small_mol_ligand in ligand_files():
ligand = input_small_mol_ligand[-1][0]
ligand_file_paths.append(ligand)

sanitize_ligand(ligand_file_paths, out_dir)


if __name__ == "__main__":
app()
Loading

0 comments on commit 4cf5932

Please sign in to comment.