loqusdb 2.7.10__py3-none-any.whl → 2.7.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- loqusdb/__init__.py +1 -1
- loqusdb/build_models/variant.py +9 -4
- loqusdb/commands/export.py +4 -1
- loqusdb/commands/load.py +10 -4
- loqusdb/commands/view.py +1 -2
- loqusdb/plugins/mongo/structural_variant.py +2 -2
- loqusdb/utils/load.py +6 -6
- loqusdb/utils/variant.py +5 -6
- {loqusdb-2.7.10.dist-info → loqusdb-2.7.12.dist-info}/METADATA +3 -2
- loqusdb-2.7.12.dist-info/RECORD +56 -0
- {loqusdb-2.7.10.dist-info → loqusdb-2.7.12.dist-info}/WHEEL +1 -1
- README.md +0 -148
- loqusdb-2.7.10.dist-info/RECORD +0 -97
- tests/build_models/test_build_case.py +0 -150
- tests/build_models/test_build_variant.py +0 -15
- tests/build_models/test_is_greater.py +0 -49
- tests/commands/test_export.py +0 -16
- tests/commands/test_identity.py +0 -22
- tests/commands/test_view.py +0 -17
- tests/conftest.py +0 -438
- tests/fixtures/643594.clinical.SV.vcf +0 -178
- tests/fixtures/643594.clinical.vcf.gz +0 -0
- tests/fixtures/double_variant.vcf +0 -21
- tests/fixtures/funny_trio.ped +0 -4
- tests/fixtures/profile_snv.vcf +0 -47
- tests/fixtures/recessive_trio.ped +0 -4
- tests/fixtures/test.SV.vcf +0 -178
- tests/fixtures/test.vcf +0 -26
- tests/fixtures/test.vcf.gz +0 -0
- tests/fixtures/test.vcf.gz.tbi +0 -0
- tests/fixtures/unsorted.vcf +0 -20
- tests/functional/test_cli.py +0 -213
- tests/plugins/mongo/test_case_operations.py +0 -143
- tests/plugins/mongo/test_connect.py +0 -8
- tests/plugins/mongo/test_flask_extension.py +0 -27
- tests/plugins/mongo/test_get_sv.py +0 -27
- tests/plugins/mongo/test_load_svs.py +0 -74
- tests/plugins/mongo/test_variant_operations.py +0 -278
- tests/utils/test_case.py +0 -34
- tests/utils/test_delete.py +0 -73
- tests/utils/test_delete_family.py +0 -30
- tests/utils/test_delete_variant.py +0 -74
- tests/utils/test_get_family.py +0 -13
- tests/utils/test_load_database.py +0 -52
- tests/utils/test_load_family.py +0 -69
- tests/utils/test_load_variants.py +0 -225
- tests/utils/test_migrate.py +0 -38
- tests/utils/test_profiling.py +0 -68
- tests/vcf_tools/test_check_par.py +0 -67
- tests/vcf_tools/test_check_vcf.py +0 -64
- tests/vcf_tools/test_format_sv_variant.py +0 -102
- tests/vcf_tools/test_format_variant.py +0 -113
- tests/vcf_tools/test_vcf.py +0 -63
- {loqusdb-2.7.10.dist-info → loqusdb-2.7.12.dist-info}/LICENSE +0 -0
- {loqusdb-2.7.10.dist-info → loqusdb-2.7.12.dist-info}/entry_points.txt +0 -0
@@ -1,143 +0,0 @@
|
|
1
|
-
import pytest
|
2
|
-
|
3
|
-
from loqusdb.exceptions import CaseError
|
4
|
-
|
5
|
-
|
6
|
-
class TestDeleteCase:
|
7
|
-
def test_delete_one_case(self, mongo_adapter, case_obj):
|
8
|
-
"""Test to delete one case"""
|
9
|
-
|
10
|
-
db = mongo_adapter.db
|
11
|
-
|
12
|
-
mongo_case = db.case.find_one()
|
13
|
-
|
14
|
-
assert mongo_case == None
|
15
|
-
|
16
|
-
db.case.insert_one(case_obj)
|
17
|
-
|
18
|
-
mongo_case = db.case.find_one()
|
19
|
-
|
20
|
-
assert mongo_case["case_id"] == case_obj["case_id"]
|
21
|
-
assert mongo_case["vcf_path"] == case_obj["vcf_path"]
|
22
|
-
|
23
|
-
mongo_adapter.delete_case(case_obj)
|
24
|
-
|
25
|
-
assert db.case.find_one() == None
|
26
|
-
|
27
|
-
def test_delete_non_existing(self, mongo_adapter, case_obj):
|
28
|
-
"""Test to delete non exsting case"""
|
29
|
-
|
30
|
-
with pytest.raises(CaseError):
|
31
|
-
mongo_adapter.delete_case(case_obj)
|
32
|
-
|
33
|
-
|
34
|
-
class TestInsertCase:
|
35
|
-
def test_insert_one_case(self, mongo_adapter, case_obj):
|
36
|
-
db = mongo_adapter.db
|
37
|
-
|
38
|
-
mongo_adapter.add_case(case_obj)
|
39
|
-
|
40
|
-
mongo_case = db.case.find_one()
|
41
|
-
|
42
|
-
assert mongo_case["case_id"] == case_obj["case_id"]
|
43
|
-
assert mongo_case["vcf_path"] == case_obj["vcf_path"]
|
44
|
-
|
45
|
-
def test_insert_one_case_twice(self, mongo_adapter, case_obj):
|
46
|
-
db = mongo_adapter.db
|
47
|
-
|
48
|
-
mongo_adapter.add_case(case_obj)
|
49
|
-
|
50
|
-
with pytest.raises(CaseError):
|
51
|
-
mongo_adapter.add_case(case_obj)
|
52
|
-
|
53
|
-
|
54
|
-
class TestGetCase:
|
55
|
-
def test_get_case(self, mongo_adapter, case_obj):
|
56
|
-
"""Test to get non existing case"""
|
57
|
-
|
58
|
-
db = mongo_adapter.db
|
59
|
-
db.case.insert_one(case_obj)
|
60
|
-
|
61
|
-
mongo_case = mongo_adapter.case(case_obj)
|
62
|
-
|
63
|
-
assert mongo_case["case_id"] == case_obj["case_id"]
|
64
|
-
assert mongo_case["vcf_path"] == case_obj["vcf_path"]
|
65
|
-
|
66
|
-
def test_get_non_existing(self, mongo_adapter, simple_case):
|
67
|
-
"""Test to get non existing case"""
|
68
|
-
|
69
|
-
db = mongo_adapter.db
|
70
|
-
|
71
|
-
mongo_case = mongo_adapter.case(simple_case)
|
72
|
-
|
73
|
-
assert mongo_case == None
|
74
|
-
|
75
|
-
def test_get_multiple_cases(self, mongo_adapter):
|
76
|
-
"""Test to get non existing case"""
|
77
|
-
|
78
|
-
db = mongo_adapter.db
|
79
|
-
case_1 = {"case_id": "test", "vcf_path": "test.vcf"}
|
80
|
-
|
81
|
-
case_2 = {"case_id": "test2", "vcf_path": "test2.vcf"}
|
82
|
-
|
83
|
-
db.case.insert_one(case_1)
|
84
|
-
db.case.insert_one(case_2)
|
85
|
-
|
86
|
-
mongo_cases = mongo_adapter.cases()
|
87
|
-
|
88
|
-
assert sum(1 for i in mongo_cases) == 2
|
89
|
-
|
90
|
-
def test_nr_cases(self, mongo_adapter):
|
91
|
-
"""Test to get non existing case"""
|
92
|
-
|
93
|
-
db = mongo_adapter.db
|
94
|
-
case_1 = {"case_id": "test", "vcf_path": "test.vcf", "vcf_sv_path": None}
|
95
|
-
|
96
|
-
db.case.insert_one(case_1)
|
97
|
-
|
98
|
-
assert mongo_adapter.nr_cases() == 1
|
99
|
-
assert mongo_adapter.nr_cases(sv_cases=True) == 0
|
100
|
-
assert mongo_adapter.nr_cases(snv_cases=True) == 1
|
101
|
-
assert mongo_adapter.nr_cases(snv_cases=True, sv_cases=True) == 1
|
102
|
-
|
103
|
-
def test_nr_cases_only_snv(self, mongo_adapter):
|
104
|
-
"""Test to get non existing case"""
|
105
|
-
db = mongo_adapter.db
|
106
|
-
case_1 = {"case_id": "test", "vcf_path": "test.vcf"}
|
107
|
-
|
108
|
-
db.case.insert_one(case_1)
|
109
|
-
|
110
|
-
assert mongo_adapter.nr_cases() == 1
|
111
|
-
assert mongo_adapter.nr_cases(sv_cases=True) == 0
|
112
|
-
assert mongo_adapter.nr_cases(snv_cases=True) == 1
|
113
|
-
|
114
|
-
def test_nr_cases_sv(self, mongo_adapter):
|
115
|
-
"""Test to get non existing case"""
|
116
|
-
|
117
|
-
db = mongo_adapter.db
|
118
|
-
case_1 = {"case_id": "test", "vcf_sv_path": "test.vcf"}
|
119
|
-
|
120
|
-
db.case.insert_one(case_1)
|
121
|
-
|
122
|
-
assert mongo_adapter.nr_cases() == 1
|
123
|
-
assert mongo_adapter.nr_cases(sv_cases=True) == 1
|
124
|
-
assert mongo_adapter.nr_cases(snv_cases=True) == 0
|
125
|
-
|
126
|
-
def test_get_multiple_cases(self, mongo_adapter):
|
127
|
-
"""Test to get non existing case"""
|
128
|
-
|
129
|
-
db = mongo_adapter.db
|
130
|
-
case_1 = {"case_id": "test", "vcf_path": "test.vcf", "vcf_sv_path": "test.vcf"}
|
131
|
-
|
132
|
-
case_2 = {"case_id": "test2", "vcf_path": "test2.vcf"}
|
133
|
-
|
134
|
-
case_3 = {"case_id": "test3", "vcf_path": "test3.vcf"}
|
135
|
-
|
136
|
-
db.case.insert_one(case_1)
|
137
|
-
db.case.insert_one(case_2)
|
138
|
-
db.case.insert_one(case_3)
|
139
|
-
|
140
|
-
assert mongo_adapter.nr_cases() == 3
|
141
|
-
assert mongo_adapter.nr_cases(snv_cases=True) == 3
|
142
|
-
assert mongo_adapter.nr_cases(sv_cases=True) == 1
|
143
|
-
assert mongo_adapter.nr_cases(sv_cases=True, snv_cases=True) == 3
|
@@ -1,27 +0,0 @@
|
|
1
|
-
from mongomock import MongoClient
|
2
|
-
|
3
|
-
from loqusdb.plugins.mongo.adapter import MongoAdapter
|
4
|
-
|
5
|
-
|
6
|
-
class MockFlaskApp(object):
|
7
|
-
"""Mock a Flask App"""
|
8
|
-
|
9
|
-
def __init__(self, host="localhost", port=27017, db_name="test"):
|
10
|
-
client = MongoClient()
|
11
|
-
|
12
|
-
self.config = {}
|
13
|
-
self.extensions = {"pymongo": {}}
|
14
|
-
|
15
|
-
self.config["MONGO_DBNAME"] = db_name
|
16
|
-
self.config["MONGO_PORT"] = port
|
17
|
-
self.config["MONGO_HOST"] = host
|
18
|
-
|
19
|
-
# This is how flaskpymongo sets it up:
|
20
|
-
self.extensions["pymongo"]["MONGO"] = [client, client[db_name]]
|
21
|
-
|
22
|
-
|
23
|
-
def test_init_app(mongo_client):
|
24
|
-
app = MockFlaskApp()
|
25
|
-
adapter = MongoAdapter()
|
26
|
-
adapter.init_app(app)
|
27
|
-
assert adapter.db_name == app.config["MONGO_DBNAME"]
|
@@ -1,27 +0,0 @@
|
|
1
|
-
from loqusdb.build_models.variant import build_variant
|
2
|
-
|
3
|
-
|
4
|
-
def test_get_insertion(small_insert_variant, mongo_adapter, case_obj):
|
5
|
-
adapter = mongo_adapter
|
6
|
-
## GIVEN a mongo adapter with a small insertion
|
7
|
-
variant = small_insert_variant
|
8
|
-
case_id = case_obj["case_id"]
|
9
|
-
formated_variant = build_variant(variant=variant, case_obj=case_obj, case_id=case_id)
|
10
|
-
|
11
|
-
adapter.add_case(case_obj)
|
12
|
-
adapter.add_structural_variant(formated_variant)
|
13
|
-
for variant_obj in adapter.db.structural_variant.find():
|
14
|
-
assert variant_obj
|
15
|
-
|
16
|
-
|
17
|
-
def test_get_translocation(translocation_variant, mongo_adapter, case_obj):
|
18
|
-
adapter = mongo_adapter
|
19
|
-
## GIVEN a mongo adapter with a translocation
|
20
|
-
variant = translocation_variant
|
21
|
-
case_id = case_obj["case_id"]
|
22
|
-
formated_variant = build_variant(variant=variant, case_obj=case_obj, case_id=case_id)
|
23
|
-
|
24
|
-
adapter.add_case(case_obj)
|
25
|
-
adapter.add_structural_variant(formated_variant)
|
26
|
-
for variant_obj in adapter.db.structural_variant.find():
|
27
|
-
assert variant_obj
|
@@ -1,74 +0,0 @@
|
|
1
|
-
from loqusdb.build_models.variant import build_variant
|
2
|
-
|
3
|
-
|
4
|
-
def test_load_insertion(small_insert_variant, mongo_adapter, case_obj):
|
5
|
-
adapter = mongo_adapter
|
6
|
-
## GIVEN a mongo adapter with a case
|
7
|
-
variant = small_insert_variant
|
8
|
-
case_id = case_obj["case_id"]
|
9
|
-
adapter.add_case(case_obj)
|
10
|
-
|
11
|
-
## WHEN loading a small insertion
|
12
|
-
formated_variant = build_variant(variant=variant, case_obj=case_obj, case_id=case_id)
|
13
|
-
adapter.add_structural_variant(formated_variant)
|
14
|
-
|
15
|
-
## THEN assert the object returned is correct
|
16
|
-
variant_cluster = adapter.db.structural_variant.find_one()
|
17
|
-
|
18
|
-
assert variant_cluster["families"] == [case_id]
|
19
|
-
|
20
|
-
|
21
|
-
def test_load_same_insertion_twice(small_insert_variant, mongo_adapter, case_obj):
|
22
|
-
adapter = mongo_adapter
|
23
|
-
## GIVEN a mongo adapter with a case
|
24
|
-
variant = small_insert_variant
|
25
|
-
case_id = case_obj["case_id"]
|
26
|
-
adapter.add_case(case_obj)
|
27
|
-
|
28
|
-
## WHEN loading a small insertion
|
29
|
-
formated_variant = build_variant(variant=variant, case_obj=case_obj, case_id=case_id)
|
30
|
-
adapter.add_structural_variant(formated_variant)
|
31
|
-
formated_variant["case_id"] = "2"
|
32
|
-
adapter.add_structural_variant(formated_variant)
|
33
|
-
|
34
|
-
## THEN assert the object returned is correct
|
35
|
-
variant_cluster = adapter.db.structural_variant.find_one()
|
36
|
-
|
37
|
-
assert set(variant_cluster["families"]) == set([case_id, "2"])
|
38
|
-
|
39
|
-
|
40
|
-
def test_load_translocation(translocation_variant, case_obj, mongo_adapter):
|
41
|
-
adapter = mongo_adapter
|
42
|
-
## GIVEN a mongo adapter with a case
|
43
|
-
variant = translocation_variant
|
44
|
-
case_id = case_obj["case_id"]
|
45
|
-
adapter.add_case(case_obj)
|
46
|
-
|
47
|
-
## WHEN loading a small insertion
|
48
|
-
formated_variant = build_variant(variant=variant, case_obj=case_obj, case_id=case_id)
|
49
|
-
adapter.add_structural_variant(formated_variant)
|
50
|
-
|
51
|
-
## THEN assert the object returned is correct
|
52
|
-
variant_cluster = adapter.db.structural_variant.find_one()
|
53
|
-
|
54
|
-
assert variant_cluster["families"] == [case_id]
|
55
|
-
|
56
|
-
|
57
|
-
def test_load_same_translocation_twice(translocation_variant, case_obj, mongo_adapter):
|
58
|
-
adapter = mongo_adapter
|
59
|
-
## GIVEN a mongo adapter with a case
|
60
|
-
variant = translocation_variant
|
61
|
-
case_id = case_obj["case_id"]
|
62
|
-
adapter.add_case(case_obj)
|
63
|
-
|
64
|
-
## WHEN loading a small insertion
|
65
|
-
formated_variant = build_variant(variant=variant, case_obj=case_obj, case_id=case_id)
|
66
|
-
adapter.add_structural_variant(formated_variant)
|
67
|
-
|
68
|
-
formated_variant["case_id"] = "2"
|
69
|
-
adapter.add_structural_variant(formated_variant)
|
70
|
-
|
71
|
-
## THEN assert the object returned is correct
|
72
|
-
variant_cluster = adapter.db.structural_variant.find_one()
|
73
|
-
|
74
|
-
assert set(variant_cluster["families"]) == set([case_id, "2"])
|
@@ -1,278 +0,0 @@
|
|
1
|
-
import copy
|
2
|
-
|
3
|
-
from loqusdb.build_models.variant import build_variant
|
4
|
-
|
5
|
-
|
6
|
-
class TestInsertVariant:
|
7
|
-
def test_insert_one_variant(self, mongo_adapter, simplest_variant):
|
8
|
-
"""Test to insert one variant"""
|
9
|
-
|
10
|
-
mongo_adapter.add_variant(simplest_variant)
|
11
|
-
|
12
|
-
db = mongo_adapter.db
|
13
|
-
|
14
|
-
# Get the variant without the adapter
|
15
|
-
mongo_variant = db.variant.find_one()
|
16
|
-
|
17
|
-
assert mongo_variant["_id"] == "test"
|
18
|
-
assert mongo_variant["observations"] == 1
|
19
|
-
assert mongo_variant["homozygote"] == 0
|
20
|
-
|
21
|
-
def test_insert_one_variant_twice(self, mongo_adapter, simplest_variant):
|
22
|
-
"""Test to insert one variant"""
|
23
|
-
|
24
|
-
mongo_adapter.add_variant(simplest_variant)
|
25
|
-
mongo_adapter.add_variant(simplest_variant)
|
26
|
-
|
27
|
-
db = mongo_adapter.db
|
28
|
-
|
29
|
-
mongo_variant = db.variant.find_one()
|
30
|
-
|
31
|
-
assert mongo_variant["_id"] == "test"
|
32
|
-
assert mongo_variant["observations"] == 2
|
33
|
-
assert mongo_variant.get("homozygote", 0) == 0
|
34
|
-
|
35
|
-
def test_insert_hom_variant(self, real_mongo_adapter, homozygous_variant):
|
36
|
-
"""Test to insert a homozygote variant"""
|
37
|
-
mongo_adapter = real_mongo_adapter
|
38
|
-
mongo_adapter.add_variant(homozygous_variant)
|
39
|
-
|
40
|
-
db = mongo_adapter.db
|
41
|
-
|
42
|
-
mongo_variant = db.variant.find_one()
|
43
|
-
assert mongo_variant["_id"] == "test"
|
44
|
-
assert mongo_variant["observations"] == 1
|
45
|
-
assert mongo_variant.get("homozygote", 0) == 1
|
46
|
-
assert mongo_variant["families"] == ["1"]
|
47
|
-
|
48
|
-
def test_insert_many(self, mongo_adapter, simplest_variant):
|
49
|
-
"""Test to insert a homozygote variant"""
|
50
|
-
|
51
|
-
for _ in range(10000):
|
52
|
-
mongo_adapter.add_variant(simplest_variant)
|
53
|
-
|
54
|
-
db = mongo_adapter.db
|
55
|
-
|
56
|
-
mongo_variant = db.variant.find_one()
|
57
|
-
assert mongo_variant["_id"] == "test"
|
58
|
-
assert mongo_variant["observations"] == 10000
|
59
|
-
assert mongo_variant.get("homozygote", 0) == 0
|
60
|
-
|
61
|
-
|
62
|
-
class TestGetVariant:
|
63
|
-
def test_get_variant(self, mongo_client, mongo_adapter, simplest_variant):
|
64
|
-
"""Test to insert one variant"""
|
65
|
-
|
66
|
-
# Insert without adapter
|
67
|
-
db = mongo_client["test"]
|
68
|
-
db.variant.insert_one(simplest_variant)
|
69
|
-
|
70
|
-
mongo_variant = mongo_adapter.get_variant(simplest_variant)
|
71
|
-
assert mongo_variant["_id"] == "test"
|
72
|
-
|
73
|
-
def test_get_none(self, mongo_adapter, simplest_variant):
|
74
|
-
"""Test to get non existing variant"""
|
75
|
-
|
76
|
-
mongo_variant = mongo_adapter.get_variant(simplest_variant)
|
77
|
-
|
78
|
-
assert mongo_variant is None
|
79
|
-
|
80
|
-
|
81
|
-
class TestBulkOperations:
|
82
|
-
def test_insert_one_variant(self, real_mongo_adapter, simplest_variant):
|
83
|
-
"""Test to insert one variant with bulk insert"""
|
84
|
-
|
85
|
-
mongo_adapter = real_mongo_adapter
|
86
|
-
variants = [simplest_variant]
|
87
|
-
|
88
|
-
mongo_adapter.add_variants(variants)
|
89
|
-
db = mongo_adapter.db
|
90
|
-
mongo_variant = db.variant.find_one()
|
91
|
-
|
92
|
-
assert mongo_variant["_id"] == "test"
|
93
|
-
assert mongo_variant["observations"] == 1
|
94
|
-
assert mongo_variant["homozygote"] == 0
|
95
|
-
|
96
|
-
def test_insert_two_variants(self, real_mongo_adapter):
|
97
|
-
"""Test to insert two variants with bulk"""
|
98
|
-
|
99
|
-
adapter = real_mongo_adapter
|
100
|
-
db = adapter.db
|
101
|
-
|
102
|
-
variants = [
|
103
|
-
{"_id": "test", "homozygote": 0},
|
104
|
-
{"_id": "test_1", "homozygote": 1},
|
105
|
-
]
|
106
|
-
|
107
|
-
adapter.add_variants(variants)
|
108
|
-
|
109
|
-
first_variant = db.variant.find_one({"_id": "test"})
|
110
|
-
second_variant = db.variant.find_one({"_id": "test_1"})
|
111
|
-
|
112
|
-
assert first_variant["_id"] == "test"
|
113
|
-
assert first_variant["observations"] == 1
|
114
|
-
assert first_variant.get("homozygote", 0) == 0
|
115
|
-
|
116
|
-
assert second_variant["_id"] == "test_1"
|
117
|
-
assert second_variant["observations"] == 1
|
118
|
-
assert second_variant.get("homozygote", 0) == 1
|
119
|
-
|
120
|
-
def test_insert_many(self, real_mongo_adapter):
|
121
|
-
adapter = real_mongo_adapter
|
122
|
-
db = adapter.db
|
123
|
-
|
124
|
-
variants = ({"_id": "test", "homozygote": 0} for i in range(20000))
|
125
|
-
|
126
|
-
adapter.add_variants(variants)
|
127
|
-
|
128
|
-
mongo_variant = db.variant.find_one()
|
129
|
-
|
130
|
-
assert mongo_variant["_id"] == "test"
|
131
|
-
assert mongo_variant["observations"] == 20000
|
132
|
-
assert mongo_variant.get("homozygote", 0) == 0
|
133
|
-
|
134
|
-
|
135
|
-
class TestRemoveVariant:
|
136
|
-
def test_remove_one_variant(self, mongo_adapter):
|
137
|
-
"""Test to update one variant"""
|
138
|
-
|
139
|
-
db = mongo_adapter.db
|
140
|
-
|
141
|
-
variant = {"_id": "test", "observations": 1}
|
142
|
-
|
143
|
-
db.variant.insert_one(variant)
|
144
|
-
|
145
|
-
mongo_adapter.delete_variant(variant)
|
146
|
-
|
147
|
-
assert db.variant.find_one() is None
|
148
|
-
|
149
|
-
def test_downcount_one_variant(self, mongo_adapter):
|
150
|
-
"""Test to update one variant"""
|
151
|
-
|
152
|
-
db = mongo_adapter.db
|
153
|
-
|
154
|
-
insert_variant = {"_id": "test", "families": ["1", "2"], "observations": 2}
|
155
|
-
|
156
|
-
db.variant.insert_one(insert_variant)
|
157
|
-
|
158
|
-
variant = {"_id": "test", "case_id": "1"}
|
159
|
-
|
160
|
-
mongo_adapter.delete_variant(variant)
|
161
|
-
|
162
|
-
mongo_variant = db.variant.find_one()
|
163
|
-
|
164
|
-
assert mongo_variant["observations"] == 1
|
165
|
-
assert mongo_variant["families"] == ["2"]
|
166
|
-
|
167
|
-
def test_remove_non_existing(self, mongo_adapter, simplest_variant):
|
168
|
-
db = mongo_adapter.db
|
169
|
-
|
170
|
-
mongo_adapter.delete_variant(simplest_variant)
|
171
|
-
|
172
|
-
assert db.variant.find_one() is None
|
173
|
-
|
174
|
-
|
175
|
-
class TestRemoveSV:
|
176
|
-
def test_remove_one_SV(self, mongo_adapter, del_variant, case_obj):
|
177
|
-
# GIVEN a database poulated with one SV
|
178
|
-
db = mongo_adapter.db
|
179
|
-
formated_variant = build_variant(
|
180
|
-
del_variant, case_obj=case_obj, case_id=case_obj["case_id"]
|
181
|
-
)
|
182
|
-
mongo_adapter.add_structural_variant(formated_variant)
|
183
|
-
mongo_SV = db.structural_variant.find_one()
|
184
|
-
mongo_identity = db.identity.find_one()
|
185
|
-
assert mongo_SV is not None
|
186
|
-
assert mongo_identity is not None
|
187
|
-
# WHEN deleting SV
|
188
|
-
mongo_adapter.delete_structural_variant(formated_variant)
|
189
|
-
|
190
|
-
# THEN there should be no remaining SVs in the database
|
191
|
-
mongo_SV = db.structural_variant.find_one()
|
192
|
-
mongo_identity = db.indentity.find_one()
|
193
|
-
assert mongo_SV is None
|
194
|
-
assert mongo_identity is None
|
195
|
-
|
196
|
-
def test_remove_one_of_two_SV(self, mongo_adapter, duptandem_variant, case_obj):
|
197
|
-
# GIVEN a database poulated with one SV
|
198
|
-
db = mongo_adapter.db
|
199
|
-
formated_variant = build_variant(
|
200
|
-
duptandem_variant, case_obj=case_obj, case_id=case_obj["case_id"]
|
201
|
-
)
|
202
|
-
mongo_adapter.add_structural_variant(formated_variant)
|
203
|
-
|
204
|
-
# Add second of same variant, changing the start and end position slightly
|
205
|
-
formated_variant_ = copy.deepcopy(formated_variant)
|
206
|
-
formated_variant_["pos"] = formated_variant_["pos"] + 2
|
207
|
-
formated_variant_["end"] = formated_variant_["end"] - 1
|
208
|
-
formated_variant_["case_id"] = "case_2"
|
209
|
-
mongo_adapter.add_structural_variant(formated_variant_)
|
210
|
-
|
211
|
-
# This should correspond to one structural variant document
|
212
|
-
mongo_svs = list(db.structural_variant.find())
|
213
|
-
assert len(mongo_svs) == 1
|
214
|
-
mongo_sv = mongo_svs[0]
|
215
|
-
assert mongo_sv["pos_sum"] == formated_variant["pos"] + formated_variant_["pos"]
|
216
|
-
# And two identity documents
|
217
|
-
mongo_identities = list(db.identity.find())
|
218
|
-
assert len(mongo_identities) == 2
|
219
|
-
|
220
|
-
# WHEN deleting the variant from the first case
|
221
|
-
mongo_adapter.delete_structural_variant(formated_variant)
|
222
|
-
|
223
|
-
# THEN the SV document should have the pos_sum equal to the pos of the
|
224
|
-
# SV from the second case
|
225
|
-
mongo_svs = list(db.structural_variant.find())
|
226
|
-
assert len(mongo_svs) == 1
|
227
|
-
mongo_sv = mongo_svs[0]
|
228
|
-
assert mongo_sv["pos_sum"] == formated_variant_["pos"]
|
229
|
-
# And one identity documents
|
230
|
-
mongo_identities = list(db.identity.find())
|
231
|
-
assert len(mongo_identities) == 1
|
232
|
-
|
233
|
-
|
234
|
-
class TestHelperMethods:
|
235
|
-
def test_update_sv_metrics(self, mongo_adapter):
|
236
|
-
# GIVEN a mongo adapter
|
237
|
-
|
238
|
-
# WHEN cluster_len > 10000
|
239
|
-
cluster_len, interval_size = mongo_adapter._update_sv_metrics(
|
240
|
-
sv_type="INV", pos_mean=10000, end_mean=30000, max_window=3000
|
241
|
-
)
|
242
|
-
# THEN interval_size should be the cluster_len divided by 10
|
243
|
-
assert cluster_len == 20000
|
244
|
-
assert interval_size == round(20000 / 10, -2)
|
245
|
-
|
246
|
-
# WHEN cluster_len <10000
|
247
|
-
cluster_len, interval_size = mongo_adapter._update_sv_metrics(
|
248
|
-
sv_type="DUP", pos_mean=10000, end_mean=15000, max_window=3000
|
249
|
-
)
|
250
|
-
|
251
|
-
# THEN interval_size should be cluster_len divided by 5
|
252
|
-
assert cluster_len == 5000
|
253
|
-
assert interval_size == round(5000 / 5, -2)
|
254
|
-
|
255
|
-
# WHEN interval_size < 1000
|
256
|
-
cluster_len, interval_size = mongo_adapter._update_sv_metrics(
|
257
|
-
sv_type="DEL", pos_mean=10000, end_mean=10500, max_window=3000
|
258
|
-
)
|
259
|
-
|
260
|
-
# THEN interval_size should be cluster_len divided by 2
|
261
|
-
assert cluster_len == 500
|
262
|
-
assert interval_size == round(500 / 2, -2)
|
263
|
-
|
264
|
-
# WHEN interval size is > max_window
|
265
|
-
cluster_len, interval_size = mongo_adapter._update_sv_metrics(
|
266
|
-
sv_type="INV", pos_mean=100000, end_mean=200000, max_window=3000
|
267
|
-
)
|
268
|
-
# THEN interval size should be set to max_window
|
269
|
-
assert cluster_len == 100000
|
270
|
-
assert interval_size == 3000
|
271
|
-
|
272
|
-
# WHEN sv_type == BND
|
273
|
-
cluster_len, interval_size = mongo_adapter._update_sv_metrics(
|
274
|
-
sv_type="BND", pos_mean=1000, end_mean=2000, max_window=3000
|
275
|
-
)
|
276
|
-
# THEN cluster_len should be 10e10 and interval_size 2*max window
|
277
|
-
assert cluster_len == 10e10
|
278
|
-
assert interval_size == 2 * 3000
|
tests/utils/test_case.py
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
import pytest
|
2
|
-
from loqusdb.exceptions import CaseError
|
3
|
-
from loqusdb.utils.case import update_case
|
4
|
-
|
5
|
-
|
6
|
-
def test_update_case(case_obj, sv_case_obj):
|
7
|
-
## GIVEN a case with snv info and a case with sv info
|
8
|
-
assert sv_case_obj["vcf_path"] is None
|
9
|
-
assert case_obj["vcf_path"] is not None
|
10
|
-
assert case_obj["vcf_sv_path"] is None
|
11
|
-
assert sv_case_obj["vcf_sv_path"] is not None
|
12
|
-
|
13
|
-
## WHEN updating the case
|
14
|
-
updated_case = update_case(case_obj=sv_case_obj, existing_case=case_obj)
|
15
|
-
|
16
|
-
## THEN assert that the cases have been merged without affecting the original cases
|
17
|
-
assert updated_case["vcf_path"] is not None
|
18
|
-
assert updated_case["vcf_path"] == case_obj["vcf_path"]
|
19
|
-
assert sv_case_obj["vcf_path"] is None
|
20
|
-
|
21
|
-
assert updated_case["vcf_sv_path"] is not None
|
22
|
-
assert updated_case["vcf_sv_path"] == sv_case_obj["vcf_sv_path"]
|
23
|
-
assert case_obj["vcf_sv_path"] is None
|
24
|
-
|
25
|
-
assert updated_case["nr_variants"] == case_obj["nr_variants"]
|
26
|
-
assert updated_case["nr_sv_variants"] == sv_case_obj["nr_sv_variants"]
|
27
|
-
|
28
|
-
|
29
|
-
def test_update_existing_vcf(case_obj):
|
30
|
-
## GIVEN a case object with VCF information
|
31
|
-
## WHEN trying to update existing VCF information
|
32
|
-
## THEN assert that a CaseError is raised
|
33
|
-
with pytest.raises(CaseError):
|
34
|
-
updated_case = update_case(case_obj, case_obj)
|
tests/utils/test_delete.py
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
from loqusdb.utils.delete import delete
|
2
|
-
from loqusdb.utils.load import load_database
|
3
|
-
|
4
|
-
|
5
|
-
def test_delete_case(mongo_adapter, simple_case):
|
6
|
-
## GIVEN a mongoadapter with a inserted case
|
7
|
-
db = mongo_adapter.db
|
8
|
-
db.case.insert_one(simple_case)
|
9
|
-
mongo_case = db.case.find_one()
|
10
|
-
|
11
|
-
assert mongo_case
|
12
|
-
## WHEN deleting the case
|
13
|
-
|
14
|
-
mongo_adapter.delete_case(simple_case)
|
15
|
-
## THEN assert that the case was deleted
|
16
|
-
mongo_case = db.case.find_one()
|
17
|
-
|
18
|
-
mongo_case = db.case.find_one()
|
19
|
-
|
20
|
-
assert mongo_case is None
|
21
|
-
|
22
|
-
|
23
|
-
def test_delete_case_and_variants(vcf_path, ped_path, real_mongo_adapter, case_id, case_obj):
|
24
|
-
mongo_adapter = real_mongo_adapter
|
25
|
-
db = mongo_adapter.db
|
26
|
-
|
27
|
-
load_database(
|
28
|
-
adapter=mongo_adapter,
|
29
|
-
variant_file=vcf_path,
|
30
|
-
family_file=ped_path,
|
31
|
-
family_type="ped",
|
32
|
-
)
|
33
|
-
|
34
|
-
mongo_case = db.case.find_one()
|
35
|
-
|
36
|
-
assert mongo_case["case_id"] == case_id
|
37
|
-
|
38
|
-
delete(
|
39
|
-
adapter=mongo_adapter,
|
40
|
-
case_obj=case_obj,
|
41
|
-
)
|
42
|
-
|
43
|
-
mongo_case = db.case.find_one()
|
44
|
-
|
45
|
-
assert mongo_case is None
|
46
|
-
|
47
|
-
mongo_variant = db.variant.find_one()
|
48
|
-
|
49
|
-
assert mongo_variant is None
|
50
|
-
|
51
|
-
|
52
|
-
def test_delete_structural_variants(vcf_path, ped_path, real_mongo_adapter, case_id, sv_case_obj):
|
53
|
-
# GIVEN a mongo adapter with an inserted case with SVs
|
54
|
-
mongo_adapter = real_mongo_adapter
|
55
|
-
db = mongo_adapter.db
|
56
|
-
|
57
|
-
load_database(
|
58
|
-
adapter=mongo_adapter,
|
59
|
-
variant_file=sv_case_obj["vcf_path"],
|
60
|
-
family_file=ped_path,
|
61
|
-
family_type="ped",
|
62
|
-
sv_file=sv_case_obj["vcf_sv_path"],
|
63
|
-
)
|
64
|
-
|
65
|
-
mongo_svs = db.structural_variant.find()
|
66
|
-
assert len(list(mongo_svs)) == 19
|
67
|
-
|
68
|
-
# WHEN deleteing the case
|
69
|
-
delete(adapter=mongo_adapter, case_obj=sv_case_obj)
|
70
|
-
|
71
|
-
# All structural variants should be deleted.
|
72
|
-
mongo_svs = db.structural_variant.find()
|
73
|
-
assert len(list(mongo_svs)) == 0
|