Skip to content

Commit

Permalink
Merge a67a983 into f9c24c2
Browse files Browse the repository at this point in the history
  • Loading branch information
northwestwitch committed Oct 27, 2023
2 parents f9c24c2 + a67a983 commit 47c762d
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
python-version: [3.9]
mongodb-version: ["4.4", "5.0"]
mongodb-version: ["5", "7"]

steps:
# Check out Scout code
Expand Down
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@ This project adheres to [Semantic Versioning](http://semver.org/).

About changelog [here](https://keepachangelog.com/en/1.0.0/)

## [unreleased]
## [2.8]
### Added
- Basic cli tests touching fixed deprecated code
### Changed
- Unfreezed PyMongo in requirements.txt
- Replaced deprecated pymongo `.count()` function with `count_documents()` in code.

## [2.7.2]
### Fixed
- `Deprecated config in setup.cfg` error when installing the package

Expand Down
7 changes: 3 additions & 4 deletions loqusdb/commands/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def export(ctx, outfile, variant_type, freq):
version = ctx.obj["version"]

LOG.info("Export the variants from {0}".format(adapter))
nr_cases = 0

is_sv = variant_type == "sv"
existing_chromosomes = set(adapter.get_chromosomes(sv=is_sv))
Expand All @@ -52,8 +51,8 @@ def export(ctx, outfile, variant_type, freq):
for chrom in existing_chromosomes:
ordered_chromosomes.append(chrom)

nr_cases = adapter.cases().count()
LOG.info("Found {0} cases in database".format(nr_cases))
nr_cases = adapter.case_count()
LOG.info(f"Found {nr_cases} cases in database")

head = HeaderParser()
head.add_fileformat("VCFv4.3")
Expand Down Expand Up @@ -85,7 +84,7 @@ def export(ctx, outfile, variant_type, freq):
else:
LOG.info("Collecting all SV variants")
variants = adapter.get_sv_variants(chromosome=chrom)
LOG.info("{} variants found".format(variants.count()))
LOG.info(f"{adapter.nr_variants(chromosome=chrom)} variants found")
for variant in variants:
variant_line = format_variant(
variant, variant_type=variant_type, nr_cases=nr_cases, add_freq=freq
Expand Down
5 changes: 2 additions & 3 deletions loqusdb/commands/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ def identity(ctx, variant_id):
ctx.abort()

adapter = ctx.obj["adapter"]
version = ctx.obj["version"]

LOG.info("Search variants {0}".format(adapter))

result = adapter.get_clusters(variant_id)
if result.count() == 0:
variant_count: int = adapter.db.identity.count_documents({"variant_id": variant_id})
if variant_count == 0:
LOG.info("No hits for variant %s", variant_id)
return

Expand Down
6 changes: 4 additions & 2 deletions loqusdb/commands/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ def cases(ctx, case_id, to_json, count, case_type):
case_obj["_id"] = str(case_obj["_id"])
cases.append(case_obj)
else:
cases = adapter.cases()
if cases.count() == 0:

nr_cases = adapter.case_count()
if nr_cases == 0:
LOG.info("No cases found in database")
ctx.abort()
cases = adapter.cases()

if to_json:
click.echo(json.dumps(cases))
Expand Down
13 changes: 3 additions & 10 deletions loqusdb/plugins/mongo/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,6 @@ def delete_case(self, case):
LOG.info("Removing case {0} from database".format(mongo_case.get("case_id")))
self.db.case.delete_one({"_id": mongo_case["_id"]})

def case_count(self):
"""Returns the total number of cases in the database
returns:
nr_of_cases (int): Total number of cases in database
"""
nr_of_cases = 0
res = self.cases

return res.count()
def case_count(self) -> int:
"""Returns the total number of cases in the database."""
return self.db.case.count_documents({})
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
pytest==5.4.3
cyvcf2==0.30.12
mongomock==3.18.0
mongomock
click==7.1.2
pymongo==3.7.1
pymongo
numpy==1.21.4
coloredlogs==14.0
pyyaml>=5.4.1
vcftoolbox==1.5
pip==23.1.2
setuptools==65.5.1
mongo_adapter>=0.3.3
mongo_adapter
ped_parser
16 changes: 16 additions & 0 deletions tests/commands/test_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from click.testing import CliRunner

from loqusdb.commands.cli import cli as base_command

def test_export_base(real_db_name):
"""Test the base command that exports variants."""

runner = CliRunner()

# WHEN the base command to export cases is run
command = ["--database", real_db_name, "export"]

## THEN it should return success
result = runner.invoke(base_command, command)
assert result.exit_code == 0

22 changes: 22 additions & 0 deletions tests/commands/test_identity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from click.testing import CliRunner

from loqusdb.commands.cli import cli as base_command

def test_identity(real_db_name):
"""Test the SV identity base command."""

runner = CliRunner()

# WHEN the base identity command is run on an empty database
command = ["--database", real_db_name, "identity", "-v", "1_7890024_TGA_GGG"]

# THEN the command should return success
result = runner.invoke(base_command, command)
assert result.exit_code == 0

# AND no variant found message
assert "No hits for variant" in result.output




17 changes: 17 additions & 0 deletions tests/commands/test_view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from click.testing import CliRunner

from loqusdb.commands.cli import cli as base_command

def test_view_cases_base(real_mongo_adapter, real_db_name):
"""Test the base command that returns database cases."""

## GIVEN an empty database
assert sum([1 for _ in real_mongo_adapter.cases()]) == 0

runner = CliRunner()

# THEN the case command should return No cases found error
command = ["--database", real_db_name, "cases" ]
result = runner.invoke(base_command, command)
assert result.exit_code == 1
assert "No cases found in database" in result.output

0 comments on commit 47c762d

Please sign in to comment.