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

Entry point #29

Merged
merged 4 commits into from
Jan 2, 2024
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
23 changes: 22 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pandas = "^2.1.4"
pyarrow = "^14.0.1"
scipy = "^1.11.4"
jinja2 = "^3.1.2"
typer = "^0.9.0"

[tool.poetry.group.dev.dependencies]
rich = "^13.6.0"
Expand All @@ -28,6 +29,9 @@ enable = true
vcs = "git"
style = "semver"

[tool.poetry.scripts]
deemian = "deemian.deemian:app"

[build-system]
requires = ["poetry-core>=1.0.0", "poetry-dynamic-versioning>=1.0.0,<2.0.0"]
build-backend = "poetry_dynamic_versioning.backend"
Expand Down
32 changes: 32 additions & 0 deletions src/deemian/deemian.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import typer
from rich.console import Console

from deemian.engine.builder import DeemianData
from deemian.engine.processor import parser, InstructionTransformer
from deemian.engine.director import director


console = Console()
app = typer.Typer()


@app.command(short_help="run deemian script")
def run(script_name: str):
console.print(f"[bold magenta]Running {script_name}[/bold magenta]")
with open(script_name) as f:
text = f.read()

command_tree = parser(text)
transformer = InstructionTransformer()
command_tree = transformer.transform(command_tree)

deemian_data = DeemianData()
director(command_tree, deemian_data)


# one command one callback, just a temporary helper command
# delete this when there are multiple commands
# https://typer.tiangolo.com/tutorial/commands/one-or-multiple/
@app.callback()
def callback():
pass
4 changes: 4 additions & 0 deletions src/deemian/writer/templates/01_detailed_conf_first.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ interaction for "{{ pair_name }}":

{%- set subject_1, subject_2 = interacting_subjects[pair_name] -%}
{%- set df = interaction_data.dataframe -%}
{%- if len(df) == 0 %}
No interaction detected
{%- else -%}
{%- set confs = df.conformation.unique() -%}
{%- set groupbyconf = df.groupby('conformation') -%}

Expand Down Expand Up @@ -52,4 +55,5 @@ conf {{ "{}".format(conf).rjust(10) }}
{% endfor -%}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
4 changes: 4 additions & 0 deletions src/deemian/writer/templates/02_detailed_type_first.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ interaction for "{{ pair_name }}":

{%- set subject_1, subject_2 = interacting_subjects[pair_name] -%}
{%- set df = interaction_data.dataframe -%}
{%- if len(df) == 0 %}
No interaction detected
{%- else -%}
{%- set unique_interaction = df.interaction_type.unique() %}
{%- set groupbytype = df.groupby('interaction_type') %}

Expand Down Expand Up @@ -55,4 +58,5 @@ interaction for "{{ pair_name }}":
{% endfor -%}
{% endfor -%}
{%- endif %}
{% endif %}
{% endfor %}
4 changes: 4 additions & 0 deletions src/deemian/writer/templates/03_clustered_conf_first.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ interaction for "{{ pair_name }}":

{%- set subject_1, subject_2 = interacting_subjects[pair_name] -%}
{%- set df = interaction_data.dataframe -%}
{%- if len(df) == 0 %}
No interaction detected
{%- else -%}
{%- set confs = df.conformation.unique() -%}
{%- set groupbyconf = df.groupby('conformation') -%}

Expand Down Expand Up @@ -54,4 +57,5 @@ conf {{ "{}".format(conf).rjust(10) }}
{% endfor -%}
{%- endif %}
{% endfor %}
{% endif %}
{% endfor %}
5 changes: 4 additions & 1 deletion src/deemian/writer/templates/04_clustered_type_first.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ interaction for "{{ pair_name }}":

{%- set subject_1, subject_2 = interacting_subjects[pair_name] -%}
{%- set df = interaction_data.dataframe -%}

{%- if len(df) == 0 %}
No interaction detected
{%- else -%}
{%- set unique_interaction = df.interaction_type.unique() %}
{%- set groupbytype = df.groupby('interaction_type') %}
{%- if 'electrostatic_cation' in unique_interaction %}
Expand Down Expand Up @@ -59,4 +61,5 @@ interaction for "{{ pair_name }}":
{% endfor -%}
{% endfor %}
{%- endif %}
{% endif %}
{% endfor %}
4 changes: 4 additions & 0 deletions src/deemian/writer/templates/05_summarized_conf_first.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ interaction for "{{ pair_name }}":

{%- set subjects = interacting_subjects[pair_name] -%}
{%- set df = interaction_data.dataframe -%}
{%- if len(df) == 0 %}
No interaction detected
{%- else -%}
{%- set confs = df.conformation.unique() -%}
{%- set groupbyconf = df.groupby('conformation') -%}

Expand Down Expand Up @@ -63,4 +66,5 @@ conf {{ "{}".format(conf).rjust(10) }}
{% endfor -%}
{%- endif %}
{% endfor %}
{% endif %}
{% endfor %}
5 changes: 4 additions & 1 deletion src/deemian/writer/templates/06_summarized_type_first.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ interaction for "{{ pair_name }}":

{%- set subjects = interacting_subjects[pair_name] -%}
{%- set df = interaction_data.dataframe -%}

{%- if len(df) == 0 %}
No interaction detected
{%- else -%}
{%- set unique_interaction = df.interaction_type.unique() %}
{%- set groupbytype = df.groupby('interaction_type') %}
{%- if 'electrostatic_cation' in unique_interaction %}
Expand Down Expand Up @@ -69,4 +71,5 @@ interaction for "{{ pair_name }}":
{% endfor -%}
{% endfor -%}
{%- endif %}
{% endif %}
{% endfor %}
15 changes: 14 additions & 1 deletion tests/test_deemian.py
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@
# from deemian import deemian
from unittest.mock import patch

from typer.testing import CliRunner

from deemian.deemian import app


runner = CliRunner()


def test_app():
with patch("deemian.deemian.director"):
result = runner.invoke(app, ["run", "tests/data/n1-oseltamivir-5nzn.txt"])
assert result.exit_code == 0