Skip to content

Commit

Permalink
get_phenotypes return in same order than ids input
Browse files Browse the repository at this point in the history
  • Loading branch information
BorjaEst committed Feb 8, 2023
1 parent 88081d5 commit aef6b83
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/gevopy/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,9 @@ def get_phenotypes(tx, ids):
"WITH x, e, collect(y.id) as p "
"RETURN x{.*, .score, experiment:e.name, parents:p } "
)
result = tx.run(query, phenotypes_ids=ids)
return [dict(record["x"]) for record in result]
result = [dict(r["x"]) for r in tx.run(query, phenotypes_ids=ids)]
result.sort(key=lambda r: ids.index(r['id']))
return result


@neo4j.unit_of_work(timeout=config['timeout'])
Expand Down
5 changes: 3 additions & 2 deletions tests/test_utilities/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import uuid

from pytest import fixture
from pytest import fixture, mark


@fixture(scope="module", autouse=True)
Expand Down Expand Up @@ -52,8 +52,9 @@ def ids(population):
return [str(ph.id) for ph in population]


@mark.parametrize("db_interface", ["Neo4jInterface"], indirect=True)
def test_rwd_phenotypes(session, phenotypes, ids):
"""Test write, read and delete of phenotypes in db"""
assert ids == session.add_phenotypes(phenotypes)
assert phenotypes == session.get_phenotypes(ids)
assert ids == session.del_phenotypes(ids)
assert all([id in ids for id in session.del_phenotypes(ids)])

0 comments on commit aef6b83

Please sign in to comment.