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

Added max_phase as an option #13

Merged
merged 8 commits into from
Jan 30, 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
6 changes: 4 additions & 2 deletions src/chembl_downloader/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def get_target_sql(
standard_relation: Optional[str] = None,
standard_type: Optional[str] = None,
tax_id: Optional[str] = None,
max_phase: bool = False,
) -> str:
"""Get the SQL for all chemicals inhibiting the target."""
ar = (
Expand All @@ -106,14 +107,15 @@ def get_target_sql(
st = "" if standard_relation is None else f"AND ACTIVITIES.standard_type = '{standard_type}'"
tt = "" if target_type is None else f"AND TARGET_DICTIONARY.target_type = '{target_type}'"
tax = "" if tax_id is None else f"AND TARGET_DICTIONARY.tax_id = '{tax_id}'"
mp = "\n MOLECULE_DICTIONARY.max_phase," if max_phase else ""
return dedent(
f"""\
SELECT
ASSAYS.chembl_id AS assay_chembl_id,
TARGET_DICTIONARY.target_type,
TARGET_DICTIONARY.tax_id,
COMPOUND_STRUCTURES.canonical_smiles,
MOLECULE_DICTIONARY.chembl_id AS molecule_chembl_id,
MOLECULE_DICTIONARY.chembl_id AS molecule_chembl_id,{mp}
ACTIVITIES.standard_type,
ACTIVITIES.pchembl_value
FROM TARGET_DICTIONARY
Expand All @@ -128,7 +130,7 @@ def get_target_sql(
{st}
{tax}
""" # noqa: S608
)
).strip()


DRUG_INDICATIONS_SQL = """\
Expand Down
50 changes: 50 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for the API."""

import unittest
from textwrap import dedent

import chembl_downloader

Expand All @@ -12,3 +13,52 @@ def test_latest_version(self):
"""Test getting the latest version."""
latest_version = chembl_downloader.latest()
self.assertIsInstance(latest_version, str)

def test_get_target_sql(self):
"""Test getting the target sql."""
target = chembl_downloader.queries.get_target_sql("CHEMBL3467")
expected = dedent(
"""\
SELECT
ASSAYS.chembl_id AS assay_chembl_id,
TARGET_DICTIONARY.target_type,
TARGET_DICTIONARY.tax_id,
COMPOUND_STRUCTURES.canonical_smiles,
MOLECULE_DICTIONARY.chembl_id AS molecule_chembl_id,
ACTIVITIES.standard_type,
ACTIVITIES.pchembl_value
FROM TARGET_DICTIONARY
JOIN ASSAYS ON TARGET_DICTIONARY.tid == ASSAYS.tid
JOIN ACTIVITIES ON ASSAYS.assay_id == ACTIVITIES.assay_id
JOIN MOLECULE_DICTIONARY ON MOLECULE_DICTIONARY.molregno == ACTIVITIES.molregno
JOIN COMPOUND_STRUCTURES ON MOLECULE_DICTIONARY.molregno == COMPOUND_STRUCTURES.molregno
WHERE TARGET_DICTIONARY.chembl_id = 'CHEMBL3467'
AND ACTIVITIES.pchembl_value IS NOT NULL
"""
).strip()
self.assertEqual(expected, target)

def test_get_target_with_max_phase(self):
"""Test getting target sql with a max phase."""
target = chembl_downloader.queries.get_target_sql("CHEMBL3467", max_phase=True)
expected = dedent(
"""\
SELECT
ASSAYS.chembl_id AS assay_chembl_id,
TARGET_DICTIONARY.target_type,
TARGET_DICTIONARY.tax_id,
COMPOUND_STRUCTURES.canonical_smiles,
MOLECULE_DICTIONARY.chembl_id AS molecule_chembl_id,
MOLECULE_DICTIONARY.max_phase,
ACTIVITIES.standard_type,
ACTIVITIES.pchembl_value
FROM TARGET_DICTIONARY
JOIN ASSAYS ON TARGET_DICTIONARY.tid == ASSAYS.tid
JOIN ACTIVITIES ON ASSAYS.assay_id == ACTIVITIES.assay_id
JOIN MOLECULE_DICTIONARY ON MOLECULE_DICTIONARY.molregno == ACTIVITIES.molregno
JOIN COMPOUND_STRUCTURES ON MOLECULE_DICTIONARY.molregno == COMPOUND_STRUCTURES.molregno
WHERE TARGET_DICTIONARY.chembl_id = 'CHEMBL3467'
AND ACTIVITIES.pchembl_value IS NOT NULL
"""
).strip()
self.assertEqual(expected, target)
Loading