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

fixed query-api-civic --cancer bug #33 #35

Merged
merged 19 commits into from
Jul 3, 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
2 changes: 1 addition & 1 deletion .github/workflows/lint-code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

# Run editor config check only on files not covered by a linter
- name: Run ECLint check
run: editorconfig-checker -exclude README.md $(git ls-files | grep -v 'test\|.py\|md\|json\|yml\|yaml\|html\|css\|Makefile')
run: editorconfig-checker -exclude README.md $(git ls-files | grep -v 'test\|.py\|md\|json\|yml\|yaml\|html\|css\|Makefile\|.obo')

Prettier:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:

- name: Install python dependencies
run: |
python -m pip install --upgrade pip -r requirements-dev.txt
python -m pip install --upgrade pip -r requirements.txt
pip install -e .

- name: Test with pytest
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
Changelog
============

0.5.1 - Sulfur Io (2024-07-03)
---------------------------------------------

**Added**

**Fixed**

* fixed a severe bug in `query-api-civic` that made the tool unusable, the bug was introduced in v0.5.0.

**Dependencies**

**Deprecated**


0.5.0 - Sulfur Io (2024-06-23)
---------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,3 @@ This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypack

.. _Cookiecutter: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage


386 changes: 386 additions & 0 deletions example_files/cgi_test_out/cgi_test_out.cgi_results/biomarkers.tsv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
internal_id sample gene cna cancer predicted_in_tumors gene_role known_in_tumors driver driver_statement predicted_match known_match
input01_1 test_1 ERBB2 AMP CANCER CESC;ESCA;HNSC;LUAD;PAAD;STAD;UCEC Act BRCA;OV;CANCER;NSCLC;ST;BT;COREAD;BLCA;GEJA;HNC;ED known known in: BRCA;OV;CANCER;NSCLC;ST;BT;COREAD;BLCA;GEJA;HNC;ED known_match known_match
input01_2 test_1 TP53 DEL CANCER S LoF THYM;BCL known known in: THYM;BCL known_match known_match
input01_3 test_1 EGFR AMP CANCER BLCA;CESC;ESCA;LGG;LUAD;LUSC;STAD Act G;NSCLC;ED;HNSC;COREAD known known in: G;NSCLC;ED;HNSC;COREAD known_match known_match
8 changes: 5 additions & 3 deletions querynator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Top-level package for querynator."""

__author__ = """Susanne Jodoin & Mark Polster"""
__email__ = "susanne.jodoin@qbic.uni-tuebingen.de | mark.polster@uni-tuebingen.de"
__version__ = "0.5.0"
__author__ = """Susanne Jodoin, Mark Polster & Niclas Grote"""
__email__ = (
"susanne.jodoin@qbic.uni-tuebingen.de | mark.polster@uni-tuebingen.de | niclas.grote@student.uni-tuebingen.de"
)
__version__ = "0.5.1"
18 changes: 9 additions & 9 deletions querynator/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,13 @@ def query_api_cgi(mutations, cnas, translocations, cancer, genome, token, email,
required=True,
default="GRCh38",
)
@click.option(
"-c",
"--cancer",
help="the cancer DOID (id or name) to be searched.",
default=None,
type=click.STRING,
)
@click.option(
"-f",
"--filter_vep",
Expand All @@ -427,14 +434,7 @@ def query_api_cgi(mutations, cnas, translocations, cancer, genome, token, email,
show_default=True,
default=False,
)
@click.option(
"-c",
"--cancer",
help="the cancer DOID (id or name) to be searched.",
default=None,
type=click.STRING,
)
def query_api_civic(vcf, outdir, genome, cancer_doid, filter_vep):
def query_api_civic(vcf, outdir, genome, cancer, filter_vep):
try:
result_dir = get_unique_querynator_dir(f"{outdir}")
dirname, basename = os.path.split(result_dir)
Expand All @@ -447,7 +447,7 @@ def query_api_civic(vcf, outdir, genome, cancer_doid, filter_vep):

logger.info("Query the Clinical Interpretations of Variants In Cancer (CIViC)")
# run analysis
query_civic(candidate_variants, result_dir, logger, vcf, genome, cancer_doid, filter_vep)
query_civic(candidate_variants, result_dir, logger, vcf, genome, cancer, filter_vep)

else:
logger.info("Query the Clinical Interpretations of Variants In Cancer (CIViC)")
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
]

setup(
author="Susanne Jodoin, Mark Polster",
author_email="susanne.jodoin@qbic.uni-tuebingen.de, mark.polster@uni-tuebingen.de",
author="Susanne Jodoin, Mark Polster, Niclas Grote",
author_email="susanne.jodoin@qbic.uni-tuebingen.de, mark.polster@uni-tuebingen.de, niclas.grote@student.uni-tuebingen.de",
python_requires=">=3.8,<3.11",
classifiers=[
"Development Status :: 2 - Pre-Alpha",
Expand All @@ -46,6 +46,6 @@
test_suite="tests",
tests_require=test_requirements,
url="https://github.com/qbic-pipelines/querynator",
version="0.5.0",
version="0.5.1",
zip_safe=False,
)
216 changes: 193 additions & 23 deletions tests/test_querynator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,220 @@

"""Tests for `querynator` package."""

import os
import shutil
import unittest

from click.testing import CliRunner

import querynator.__main__
from querynator.__main__ import querynator_cli


class testCLI(unittest.TestCase):
class testCliHelp(unittest.TestCase):

def setUp(self):
self.runner = CliRunner()

def test_commandLineInterface(self):
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(querynator.__main__.querynator_cli)
assert result.exit_code == 0
result = self.runner.invoke(querynator_cli)
self.assertEqual(result.exit_code, 0)

def test_helpMessage(self):
"""Test help message"""
help_result = runner.invoke(querynator.__main__.querynator_cli, ["--help"])
assert help_result.exit_code == 0
assert "--help Show this message and exit." in help_result.output
help_result = self.runner.invoke(querynator_cli, ["--help"])
self.assertEqual(help_result.exit_code, 0)
self.assertIn("--help Show this message and exit.", help_result.output)
self.assertNotIn("+++lalelu+++this is not part of the help message+++", help_result.output)

def test_CgiHelp(self):
"""Test CGI help message"""
cgi_help_result = runner.invoke(querynator.__main__.querynator_cli, ["query-api-cgi", "--help"])
assert cgi_help_result.exit_code == 0
assert "--help Show this message and exit." in cgi_help_result.output
cgi_help_result = self.runner.invoke(querynator_cli, ["query-api-cgi", "--help"])
self.assertEqual(cgi_help_result.exit_code, 0)
self.assertIn("--help Show this message and exit.", cgi_help_result.output)

def test_CivicHelp(self):
"""Test CIVIC help message"""
civic_help_result = runner.invoke(querynator.__main__.querynator_cli, ["query-api-civic", "--help"])
assert civic_help_result.exit_code == 0
assert "--help Show this message and exit." in civic_help_result.output
civic_help_result = self.runner.invoke(querynator_cli, ["query-api-civic", "--help"])
self.assertEqual(civic_help_result.exit_code, 0)
self.assertIn("--help Show this message and exit.", civic_help_result.output)

def test_CreatereportHelp(self):
"""Test CREATE-REPORT help message"""
civic_help_result = runner.invoke(querynator.__main__.querynator_cli, ["create-report", "--help"])
assert civic_help_result.exit_code == 0
assert "--help Show this message and exit." in civic_help_result.output
report_help_result = self.runner.invoke(querynator_cli, ["create-report", "--help"])
self.assertEqual(report_help_result.exit_code, 0)
self.assertIn("--help Show this message and exit.", report_help_result.output)

def test_nonExistingSubcommand(self):
"""Test non-existing subcommand"""
result = runner.invoke(querynator.__main__.querynator_cli, ["query-api-clinvar"])
assert result.exit_code == 2
assert "No such command" in result.output
result = self.runner.invoke(querynator_cli, ["query-api-clinvar"])
self.assertEqual(result.exit_code, 2)
self.assertIn("No such command", result.output)

def test_nonExistingOption(self):
"""Test non-existing option"""
result = runner.invoke(querynator.__main__.querynator_cli, ["query-api-cgi", "--baz"])
assert result.exit_code == 2
assert "No such option" in result.output
result = self.runner.invoke(querynator_cli, ["query-api-cgi", "--baz"])
self.assertEqual(result.exit_code, 2)
self.assertIn("No such option", result.output)


class testCliRun(unittest.TestCase):
unittest_dir = f"{os.getcwd()}/example_files/unittest_out"

# helper functions
def assertIsFile(self, path, msg=None):
msg = f"{path} is not a file" if msg is None else msg
self.assertTrue(os.path.isfile(path), msg)

def get_testdir(self):
"""Get the test directory for the current test method."""
method_name = str(self).split()[0]
return f"{self.unittest_dir}/{method_name}"

def clean_testdir(self):
try:
shutil.rmtree(self.get_testdir())
except FileNotFoundError:
pass

# tests
def setUp(self):
self.runner = CliRunner()
self.clean_testdir()

def test_queryApiCivic(self):
"""Test query-api-civic"""
outdir = self.get_testdir()
result = self.runner.invoke(
querynator_cli,
[
"query-api-civic",
"--vcf",
f"{os.getcwd()}/example_files/example.vcf",
"--genome",
"GRCh37",
"--outdir",
outdir,
"--filter_vep",
],
)
self.assertEqual(result.exit_code, 0, "non-zero exit code")
self.assertIsFile(f"{outdir}/{outdir.split('/')[-1]}.civic_results.tsv", "civic_results.tsv not created")

def test_queryApiCivic_Cancer(self):
"""Test query-api-civic"""
outdir = self.get_testdir()

result = self.runner.invoke(
querynator_cli,
[
"query-api-civic",
"--vcf",
"example_files/example.vcf",
"--genome",
"GRCh37",
"--outdir",
outdir,
"--cancer",
"Cholangiocarcinoma",
"--filter_vep",
],
)
self.assertEqual(result.exit_code, 0, "non-zero exit code")
self.assertIsFile(f"{outdir}/{outdir.split('/')[-1]}.civic_results.tsv", "civic_results.tsv not created")

def test_queryApiCgi(self):
"""test querynator query-api-cgi with dummy credentials"""
outdir = self.get_testdir()
result = self.runner.invoke(
querynator_cli,
[
"query-api-cgi",
"--mutations",
f"{os.getcwd()}/example_files/example.vcf",
"--genome",
"GRCh37",
"--outdir",
outdir,
"--email",
"dummy@internet.by",
"--token",
"thisisadummytoken",
"--filter_vep",
],
)
self.assertEqual(result.exit_code, 1)

def test_queryApiCgi_Cancer(self):
"""test querynator query-api-cgi with dummy credentials"""
outdir = self.get_testdir()
result = self.runner.invoke(
querynator_cli,
[
"query-api-cgi",
"--mutations",
f"{os.getcwd()}/example_files/example.vcf",
"--genome",
"GRCh37",
"--outdir",
outdir,
"--cancer",
"Breast adenocarcinoma",
"--email",
"dummy@internet.by",
"--token",
"thisisadummytoken",
"--filter_vep",
],
)
self.assertEqual(result.exit_code, 1)

def test_queryApiCgi_invalidCancer(self):
"""test querynator query-api-cgi with dummy credentials"""
outdir = self.get_testdir()
result = self.runner.invoke(
querynator_cli,
[
"query-api-cgi",
"--mutations",
f"{os.getcwd()}/example_files/example.vcf",
"--genome",
"GRCh37",
"--outdir",
outdir,
"--cancer",
"this is not cancer, 'tis but a flesh wound",
"--email",
"dummy@internet.by",
"--token",
"thisisadummytoken",
"--filter_vep",
],
)
self.assertEqual(result.exit_code, 2)

def test_createReport(self):
"""test querynator create-report on example files"""
outdir = self.get_testdir()
result = self.runner.invoke(
querynator_cli,
[
"create-report",
"--cgi_path",
f"{os.getcwd()}/example_files/cgi_test_out",
"--civic_path",
f"{os.getcwd()}/example_files/civic_test_out",
"--outdir",
outdir,
],
)
self.assertEqual(result.exit_code, 0, "non-zero exit code")
self.assertIsFile(f"{outdir}/combined_files/civic_cgi_vep.tsv", "combined file not created")
self.assertIsFile(f"{outdir}/report/{outdir.split('/')[-1]}_overall_report.html", "report not created")

def tearDown(self):
"""Clean up output directories after tests are run."""
self.clean_testdir()


if __name__ == "__main__":
Expand Down
Loading