loqusdb 2.7.3__py3-none-any.whl → 2.7.8__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.
Files changed (55) hide show
  1. README.md +148 -0
  2. loqusdb/__init__.py +5 -3
  3. loqusdb/__main__.py +0 -0
  4. loqusdb/build_models/variant.py +12 -4
  5. loqusdb/resources/loqusdb.20181005.gz +0 -0
  6. loqusdb/resources/maf_50_sites_GRCh37.vcf.gz +0 -0
  7. loqusdb/resources/maf_50_sites_GRCh38.vcf.gz +0 -0
  8. {loqusdb-2.7.3.dist-info → loqusdb-2.7.8.dist-info}/METADATA +27 -42
  9. loqusdb-2.7.8.dist-info/RECORD +97 -0
  10. {loqusdb-2.7.3.dist-info → loqusdb-2.7.8.dist-info}/WHEEL +1 -2
  11. loqusdb-2.7.8.dist-info/entry_points.txt +3 -0
  12. tests/build_models/test_build_case.py +150 -0
  13. tests/build_models/test_build_variant.py +15 -0
  14. tests/build_models/test_is_greater.py +49 -0
  15. tests/commands/test_export.py +16 -0
  16. tests/commands/test_identity.py +22 -0
  17. tests/commands/test_view.py +17 -0
  18. tests/conftest.py +438 -0
  19. tests/fixtures/643594.clinical.SV.vcf +178 -0
  20. tests/fixtures/643594.clinical.vcf.gz +0 -0
  21. tests/fixtures/double_variant.vcf +21 -0
  22. tests/fixtures/funny_trio.ped +4 -0
  23. tests/fixtures/profile_snv.vcf +47 -0
  24. tests/fixtures/recessive_trio.ped +4 -0
  25. tests/fixtures/test.SV.vcf +178 -0
  26. tests/fixtures/test.vcf +26 -0
  27. tests/fixtures/test.vcf.gz +0 -0
  28. tests/fixtures/test.vcf.gz.tbi +0 -0
  29. tests/fixtures/unsorted.vcf +20 -0
  30. tests/functional/test_cli.py +213 -0
  31. tests/plugins/mongo/test_case_operations.py +143 -0
  32. tests/plugins/mongo/test_connect.py +8 -0
  33. tests/plugins/mongo/test_flask_extension.py +27 -0
  34. tests/plugins/mongo/test_get_sv.py +27 -0
  35. tests/plugins/mongo/test_load_svs.py +74 -0
  36. tests/plugins/mongo/test_variant_operations.py +278 -0
  37. tests/utils/test_case.py +34 -0
  38. tests/utils/test_delete.py +73 -0
  39. tests/utils/test_delete_family.py +30 -0
  40. tests/utils/test_delete_variant.py +74 -0
  41. tests/utils/test_get_family.py +13 -0
  42. tests/utils/test_load_database.py +52 -0
  43. tests/utils/test_load_family.py +69 -0
  44. tests/utils/test_load_variants.py +225 -0
  45. tests/utils/test_migrate.py +38 -0
  46. tests/utils/test_profiling.py +68 -0
  47. tests/vcf_tools/test_check_par.py +67 -0
  48. tests/vcf_tools/test_check_vcf.py +64 -0
  49. tests/vcf_tools/test_format_sv_variant.py +102 -0
  50. tests/vcf_tools/test_format_variant.py +113 -0
  51. tests/vcf_tools/test_vcf.py +63 -0
  52. loqusdb-2.7.3.dist-info/RECORD +0 -54
  53. loqusdb-2.7.3.dist-info/entry_points.txt +0 -3
  54. loqusdb-2.7.3.dist-info/top_level.txt +0 -1
  55. {loqusdb-2.7.3.dist-info → loqusdb-2.7.8.dist-info}/LICENSE +0 -0
@@ -0,0 +1,30 @@
1
+ import pytest
2
+ from loqusdb.exceptions import CaseError
3
+
4
+
5
+ def test_delete_family(mongo_adapter):
6
+ ## GIVEN a mongo adapter with a case
7
+ db = mongo_adapter.db
8
+ case = {"case_id": "1", "vcf_path": "path_to_vcf"}
9
+
10
+ db.case.insert_one(case)
11
+ mongo_case = db.case.find_one()
12
+ assert mongo_case["case_id"] == case["case_id"]
13
+
14
+ ## WHEN deleting the case
15
+ mongo_adapter.delete_case(case)
16
+
17
+ ## THEN assert that the case was deleted
18
+ mongo_case = db.case.find_one()
19
+
20
+ assert mongo_case is None
21
+
22
+
23
+ def test_delete_non_existing_family(mongo_adapter):
24
+ ## WHEN deleting a non existing case
25
+ with pytest.raises(CaseError):
26
+ ## GIVEN a mongo adapter and a empty database
27
+ case = {"case_id": "1", "vcf_path": "path_to_vcf"}
28
+
29
+ ## THEN assert a CaseError is raised
30
+ mongo_adapter.delete_case(case)
@@ -0,0 +1,74 @@
1
+ from loqusdb.build_models.variant import get_variant_id
2
+ from loqusdb.utils.delete import delete_variants
3
+
4
+
5
+ def test_delete_variants(real_mongo_adapter, het_variant, case_obj):
6
+ ## GIVEN a database with one variant
7
+ db = real_mongo_adapter.db
8
+ case_id = case_obj["case_id"]
9
+
10
+ db.variant.insert_one(
11
+ {
12
+ "_id": get_variant_id(het_variant),
13
+ "families": [case_id],
14
+ "observations": 1,
15
+ }
16
+ )
17
+
18
+ mongo_variant = db.variant.find_one()
19
+ assert mongo_variant["families"] == [case_id]
20
+
21
+ ## WHEN deleting the variant
22
+ delete_variants(adapter=real_mongo_adapter, vcf_obj=[het_variant], case_obj=case_obj)
23
+
24
+ mongo_variant = db.variant.find_one()
25
+
26
+ ## THEN assert that the variant was not found
27
+ assert mongo_variant is None
28
+
29
+
30
+ def test_delete_variant(real_mongo_adapter, het_variant, case_obj):
31
+ ## GIVEN a database with one variant that is observed twice
32
+ db = real_mongo_adapter.db
33
+ case_id = case_obj["case_id"]
34
+
35
+ db.variant.insert_one(
36
+ {
37
+ "_id": get_variant_id(het_variant),
38
+ "families": [case_id, "2"],
39
+ "observations": 2,
40
+ }
41
+ )
42
+
43
+ mongo_variant = db.variant.find_one()
44
+ assert mongo_variant["observations"] == 2
45
+
46
+ ## WHEN deleting the variant for one case
47
+ delete_variants(
48
+ adapter=real_mongo_adapter,
49
+ vcf_obj=[het_variant],
50
+ case_obj=case_obj,
51
+ case_id="2",
52
+ )
53
+
54
+ mongo_variant = db.variant.find_one()
55
+
56
+ ## THEN assert that one case has been removed from 'families'
57
+ assert mongo_variant["families"] == [case_id]
58
+ ## THEN assert that the observation count is decreased
59
+ assert mongo_variant["observations"] == 1
60
+
61
+
62
+ def test_delete_non_existing_variant(mongo_adapter, het_variant, case_obj):
63
+ """docstring for test_load_variants"""
64
+ ## GIVEN a mongo adapter to an empty database
65
+ db = mongo_adapter.db
66
+ case_id = case_obj["case_id"]
67
+
68
+ ## WHEN deleting the variants
69
+ delete_variants(adapter=mongo_adapter, vcf_obj=[het_variant], case_obj=case_obj)
70
+
71
+ # THEN assert nothing happens
72
+ mongo_variant = db.variant.find_one()
73
+
74
+ assert mongo_variant == None
@@ -0,0 +1,13 @@
1
+ import pytest
2
+ from loqusdb.exceptions import CaseError
3
+ from loqusdb.utils.case import get_case
4
+
5
+
6
+ def test_get_family(case_lines):
7
+ family = get_case(case_lines)
8
+ assert family.family_id == "recessive_trio"
9
+
10
+
11
+ def test_get_multiple_families(two_cases):
12
+ with pytest.raises(CaseError):
13
+ family = get_case(two_cases)
@@ -0,0 +1,52 @@
1
+ import pytest
2
+ from loqusdb.exceptions import CaseError
3
+ from loqusdb.utils.load import load_database
4
+
5
+
6
+ def test_load_database(vcf_path, ped_path, real_mongo_adapter, case_id):
7
+ mongo_adapter = real_mongo_adapter
8
+ db = mongo_adapter.db
9
+
10
+ load_database(
11
+ adapter=mongo_adapter,
12
+ variant_file=vcf_path,
13
+ family_file=ped_path,
14
+ family_type="ped",
15
+ )
16
+
17
+ mongo_case = db.case.find_one()
18
+
19
+ assert mongo_case["case_id"] == case_id
20
+
21
+
22
+ def test_load_database_alternative_ped(vcf_path, ped_path, real_mongo_adapter, case_id):
23
+ mongo_adapter = real_mongo_adapter
24
+ db = mongo_adapter.db
25
+
26
+ load_database(
27
+ adapter=mongo_adapter,
28
+ variant_file=vcf_path,
29
+ family_file=ped_path,
30
+ family_type="ped",
31
+ case_id="alternative",
32
+ )
33
+
34
+ mongo_case = db.case.find_one()
35
+ mongo_variant = db.variant.find_one()
36
+
37
+ assert mongo_case["case_id"] == "alternative"
38
+ assert mongo_variant["families"] == ["alternative"]
39
+
40
+
41
+ def test_load_database_wrong_ped(vcf_path, funny_ped_path, real_mongo_adapter):
42
+ mongo_adapter = real_mongo_adapter
43
+ ## GIVEN a vcf and ped file with wrong individuals
44
+ ## WHEN loading the information
45
+ ## THEN Error should be raised since individuals is not in vcf
46
+ with pytest.raises(CaseError):
47
+ load_database(
48
+ adapter=mongo_adapter,
49
+ variant_file=vcf_path,
50
+ family_file=funny_ped_path,
51
+ family_type="ped",
52
+ )
@@ -0,0 +1,69 @@
1
+ import pytest
2
+ from loqusdb.exceptions import CaseError
3
+
4
+ from loqusdb.utils.load import update_case, load_case
5
+
6
+
7
+ def test_load_family(mongo_adapter, simple_case):
8
+ ## GIVEN a adapter to an empty database
9
+ db = mongo_adapter.db
10
+
11
+ ## WHEN loading a family to the database
12
+ mongo_adapter.add_case(simple_case)
13
+
14
+ ## THEN assert that the case was loaded
15
+ mongo_case = db.case.find_one()
16
+ assert mongo_case["case_id"] == simple_case["case_id"]
17
+
18
+
19
+ def test_load_same_family_twice(mongo_adapter, simple_case):
20
+ ## GIVEN a adapter to an empty database
21
+ db = mongo_adapter.db
22
+
23
+ ## WHEN loading a family to the database twice
24
+ mongo_adapter.add_case(simple_case)
25
+
26
+ ## THEN assert that a CaseError is raised
27
+ with pytest.raises(CaseError):
28
+ mongo_adapter.add_case(simple_case)
29
+
30
+
31
+ def test_update_case(case_obj, sv_case_obj):
32
+ ## GIVEN an existing case and a case with new info
33
+
34
+ ## WHEN merging the two case objs
35
+ updated_case = update_case(sv_case_obj, case_obj)
36
+
37
+ ## THEN assert that the updated case includes information from both cases
38
+ assert updated_case["sv_individuals"] == sv_case_obj["sv_individuals"]
39
+ assert updated_case["sv_individuals"] != case_obj["sv_individuals"]
40
+
41
+ assert updated_case["_sv_inds"] == sv_case_obj["_sv_inds"]
42
+ assert updated_case["_sv_inds"] != case_obj["_sv_inds"]
43
+
44
+ assert updated_case["nr_variants"] == case_obj["nr_variants"]
45
+ assert updated_case["nr_sv_variants"] == sv_case_obj["nr_sv_variants"]
46
+
47
+
48
+ def test_update_case_same_vcf(case_obj, sv_case_obj):
49
+ ## GIVEN an existing case and a case with new info
50
+ sv_case_obj["vcf_path"] = case_obj["vcf_path"]
51
+ ## WHEN merging the two case objs
52
+ ## THEN assert that a CaseError is raised since we are trying to modify existing VCF
53
+ with pytest.raises(CaseError):
54
+ updated_case = update_case(sv_case_obj, case_obj)
55
+
56
+
57
+ def test_load_complete_case(mongo_adapter, complete_case_obj):
58
+ ## GIVEN a case that includes both svs and snvs
59
+ db = mongo_adapter.db
60
+
61
+ ## WHEN loading the case
62
+ case_obj = load_case(mongo_adapter, complete_case_obj)
63
+ ## THEN assert that all info is added
64
+ loaded_case = db.case.find_one()
65
+
66
+ assert len(loaded_case["individuals"]) == 3
67
+ assert len(loaded_case["sv_individuals"]) == 3
68
+ assert loaded_case["nr_variants"] > 0
69
+ assert loaded_case["nr_sv_variants"] > 0
@@ -0,0 +1,225 @@
1
+ from cyvcf2 import VCF
2
+
3
+ from loqusdb.utils.load import load_variants
4
+
5
+
6
+ def test_load_variants(real_mongo_adapter, het_variant, case_obj):
7
+ mongo_adapter = real_mongo_adapter
8
+ ## GIVEN an adapter and a vcf with one heterozygote variant
9
+ db = mongo_adapter.db
10
+
11
+ vcf = []
12
+ vcf.append(het_variant)
13
+ mongo_variant = db.variant.find_one()
14
+
15
+ assert mongo_variant == None
16
+
17
+ ## WHEN loading the variant into the database
18
+ load_variants(
19
+ adapter=mongo_adapter,
20
+ vcf_obj=vcf,
21
+ case_obj=case_obj,
22
+ )
23
+
24
+ mongo_variant = db.variant.find_one()
25
+
26
+ ## THEN assert that the variant is loaded correct
27
+ assert mongo_variant["families"] == [case_obj["case_id"]]
28
+ assert mongo_variant["observations"] == 1
29
+ assert mongo_variant["homozygote"] == 0
30
+ assert mongo_variant["hemizygote"] == 0
31
+
32
+
33
+ def test_load_homozygote(real_mongo_adapter, hom_variant, case_obj):
34
+ mongo_adapter = real_mongo_adapter
35
+ ## GIVEN an adapter and a vcf with one homozygote variant
36
+ db = mongo_adapter.db
37
+
38
+ vcf = []
39
+ vcf.append(hom_variant)
40
+ assert db.variant.find_one() == None
41
+
42
+ ## WHEN loading the variant into the database
43
+ load_variants(
44
+ adapter=mongo_adapter,
45
+ vcf_obj=vcf,
46
+ case_obj=case_obj,
47
+ )
48
+ mongo_variant = db.variant.find_one()
49
+
50
+ ## THEN assert that the variant is loaded correct
51
+ assert mongo_variant["families"] == [case_obj["case_id"]]
52
+ assert mongo_variant["observations"] == 1
53
+ assert mongo_variant["homozygote"] == 1
54
+ assert mongo_variant["hemizygote"] == 0
55
+
56
+
57
+ def test_load_hemizygote(real_mongo_adapter, hem_variant, case_obj):
58
+ mongo_adapter = real_mongo_adapter
59
+ ## GIVEN an adapter and a vcf with one hemizygote variant
60
+ db = mongo_adapter.db
61
+
62
+ vcf = []
63
+ vcf.append(hem_variant)
64
+
65
+ assert db.variant.find_one() == None
66
+
67
+ ## WHEN loading the variant into the database
68
+ load_variants(
69
+ adapter=mongo_adapter,
70
+ vcf_obj=vcf,
71
+ case_obj=case_obj,
72
+ )
73
+ mongo_variant = db.variant.find_one()
74
+
75
+ ## THEN assert that the variant is loaded correct
76
+ assert mongo_variant["families"] == [case_obj["case_id"]]
77
+ assert mongo_variant["observations"] == 1
78
+ assert mongo_variant["homozygote"] == 0
79
+ assert mongo_variant["hemizygote"] == 1
80
+
81
+
82
+ def test_load_par_variant(real_mongo_adapter, par_variant, case_obj):
83
+ mongo_adapter = real_mongo_adapter
84
+
85
+ ## GIVEN an adapter and a vcf with one PAR variant
86
+ db = mongo_adapter.db
87
+
88
+ vcf = []
89
+ vcf.append(par_variant)
90
+
91
+ assert db.variant.find_one() == None
92
+
93
+ ## WHEN loading the variant into the database
94
+ load_variants(
95
+ adapter=mongo_adapter,
96
+ vcf_obj=vcf,
97
+ case_obj=case_obj,
98
+ )
99
+ mongo_variant = db.variant.find_one()
100
+
101
+ ## THEN assert that the variant is loaded correct
102
+ assert mongo_variant["families"] == [case_obj["case_id"]]
103
+ assert mongo_variant["observations"] == 1
104
+ assert mongo_variant["homozygote"] == 0
105
+ assert mongo_variant["hemizygote"] == 0
106
+
107
+
108
+ def test_load_two_variants(real_mongo_adapter, het_variant, case_obj):
109
+ mongo_adapter = real_mongo_adapter
110
+ ## GIVEN an adapter and a vcf with tho heterygote variants
111
+ db = mongo_adapter.db
112
+
113
+ vcf = []
114
+ vcf.append(het_variant)
115
+ vcf.append(het_variant)
116
+
117
+ ## WHEN loading the variants into the database
118
+ load_variants(
119
+ adapter=mongo_adapter,
120
+ vcf_obj=vcf,
121
+ case_obj=case_obj,
122
+ )
123
+
124
+ ## THEN assert that the variant is loaded correct
125
+ mongo_variant = db.variant.find_one()
126
+
127
+ assert mongo_variant["observations"] == 2
128
+
129
+
130
+ def test_load_variants_skip_case_id(real_mongo_adapter, het_variant, case_obj):
131
+ mongo_adapter = real_mongo_adapter
132
+ ## GIVEN an adapter and a vcf with tho heterygote variants
133
+ db = mongo_adapter.db
134
+
135
+ vcf = []
136
+ vcf.append(het_variant)
137
+
138
+ ## WHEN loading the variants into the database
139
+ load_variants(
140
+ adapter=mongo_adapter,
141
+ vcf_obj=vcf,
142
+ case_obj=case_obj,
143
+ skip_case_id=True,
144
+ )
145
+
146
+ mongo_variant = db.variant.find_one()
147
+
148
+ ## THEN assert that the variant is loaded correct
149
+ assert mongo_variant.get("families") == None
150
+
151
+
152
+ def test_load_same_variant_different_case(real_mongo_adapter, het_variant, case_obj):
153
+ mongo_adapter = real_mongo_adapter
154
+ ## GIVEN an adapter and a vcf
155
+ db = mongo_adapter.db
156
+
157
+ vcf = []
158
+ vcf.append(het_variant)
159
+
160
+ ## WHEN loading the variant into the database
161
+ load_variants(
162
+ adapter=mongo_adapter,
163
+ vcf_obj=vcf,
164
+ case_obj=case_obj,
165
+ )
166
+
167
+ case_id = case_obj["case_id"]
168
+ case_id2 = "2"
169
+ case_obj["case_id"] = case_id2
170
+
171
+ load_variants(
172
+ adapter=mongo_adapter,
173
+ vcf_obj=vcf,
174
+ case_obj=case_obj,
175
+ )
176
+
177
+ mongo_variant = db.variant.find_one()
178
+
179
+ assert mongo_variant["observations"] == 2
180
+ assert mongo_variant["families"] == [case_id, case_id2]
181
+
182
+
183
+ def test_load_case_variants(real_mongo_adapter, case_obj):
184
+ mongo_adapter = real_mongo_adapter
185
+
186
+ db = mongo_adapter.db
187
+ ## GIVEN a mongo adatper with snv variant file
188
+ vcf_obj = VCF(case_obj["vcf_path"])
189
+ ## WHEN loading the variants
190
+ nr_variants = load_variants(
191
+ adapter=mongo_adapter,
192
+ vcf_obj=vcf_obj,
193
+ case_obj=case_obj,
194
+ )
195
+
196
+ nr_loaded = 0
197
+ for nr_loaded, variant in enumerate(db.variant.find(), 1):
198
+ pass
199
+ ## THEN assert that the correct number of variants was loaded
200
+ assert nr_loaded > 0
201
+ assert nr_loaded == case_obj["nr_variants"]
202
+
203
+
204
+ def test_load_sv_case_variants(mongo_adapter, sv_case_obj):
205
+ db = mongo_adapter.db
206
+ ## GIVEN a mongo adatper with snv variant file
207
+ vcf_obj = VCF(sv_case_obj["vcf_sv_path"])
208
+ ## WHEN loading the variants
209
+ nr_variants = load_variants(
210
+ adapter=mongo_adapter,
211
+ vcf_obj=vcf_obj,
212
+ case_obj=sv_case_obj,
213
+ variant_type="sv",
214
+ )
215
+
216
+ nr_loaded_svs = 0
217
+ for nr_loaded_svs, variant in enumerate(db.structural_variant.find(), 1):
218
+ pass
219
+ nr_loaded_snvs = 0
220
+ for nr_loaded_snvs, variant in enumerate(db.variant.find(), 1):
221
+ pass
222
+ ## THEN assert that the correct number of variants was loaded
223
+ assert nr_loaded_svs > 0
224
+ assert nr_loaded_snvs == 0
225
+ assert nr_loaded_svs == sv_case_obj["nr_sv_variants"]
@@ -0,0 +1,38 @@
1
+ from loqusdb.utils.migrate import migrate_database
2
+
3
+
4
+ def test_migrate_one_variant(mongo_adapter):
5
+ ##GIVEN a adapter to an empty old database
6
+ adapter = mongo_adapter
7
+ assert sum(1 for i in adapter.get_variants()) == 0
8
+
9
+ ##WHEN inserting a old style variant and updating the database
10
+ chrom = "1"
11
+ pos = 880086
12
+ ref = "T"
13
+ alt = "C"
14
+ hom = hem = 0
15
+ obs = 3
16
+ families = ["recessive_trio", "1", "2"]
17
+ variant = {
18
+ "_id": "_".join([chrom, str(pos), ref, alt]),
19
+ "homozygote": hom,
20
+ "hemizygote": hem,
21
+ "observations": obs,
22
+ "families": families,
23
+ }
24
+ adapter.db.variant.insert_one(variant)
25
+ ##THEN assert that the variant was updated correct
26
+
27
+ nr_updated = migrate_database(adapter)
28
+ assert nr_updated == 1
29
+
30
+ migrated_variant = adapter.db.variant.find_one()
31
+
32
+ assert migrated_variant["chrom"] == chrom
33
+ assert migrated_variant["start"] == pos
34
+ assert migrated_variant["end"] == pos
35
+ assert migrated_variant["homozygote"] == hom
36
+ assert migrated_variant["hemizygote"] == hem
37
+ assert migrated_variant["observations"] == obs
38
+ assert migrated_variant["families"] == families
@@ -0,0 +1,68 @@
1
+ import pytest
2
+ from loqusdb.exceptions import ProfileError
3
+ from loqusdb.utils.load import load_profile_variants, load_case
4
+ from loqusdb.utils.profiling import get_profiles, profile_match, compare_profiles, check_duplicates
5
+ from loqusdb.utils.vcf import check_vcf
6
+
7
+
8
+ def test_get_profiles(real_mongo_adapter, profile_vcf_path, zipped_vcf_path):
9
+ # Load profile variants
10
+ load_profile_variants(real_mongo_adapter, profile_vcf_path)
11
+
12
+ vcf_info = check_vcf(zipped_vcf_path)
13
+
14
+ # Get profiles from vcf
15
+ profiles = get_profiles(real_mongo_adapter, zipped_vcf_path)
16
+
17
+ # Assert that all individuals are included
18
+ assert list(profiles.keys()) == vcf_info["individuals"]
19
+
20
+ # Assert that profile strings are of same lengths
21
+ for i, individual in enumerate(profiles.keys()):
22
+ if i == 0:
23
+ length = len(profiles[individual])
24
+ assert len(profiles[individual]) == length
25
+
26
+
27
+ def test_profile_match(real_mongo_adapter, profile_vcf_path, profile_list, case_obj):
28
+ # Load profile variants
29
+ load_profile_variants(real_mongo_adapter, profile_vcf_path)
30
+
31
+ # Load case having profiles profile_list
32
+ load_case(real_mongo_adapter, case_obj)
33
+
34
+ # Get profiles from vcf
35
+ profiles = {"test_individual": profile_list}
36
+
37
+ # Assert that error is raised
38
+ with pytest.raises(ProfileError) as error:
39
+ profile_match(real_mongo_adapter, profiles)
40
+
41
+
42
+ def test_check_duplicates(real_mongo_adapter, profile_vcf_path, profile_list, case_obj):
43
+ # Load profile variants
44
+ load_profile_variants(real_mongo_adapter, profile_vcf_path)
45
+ # Load case having profiles profile_list
46
+ load_case(real_mongo_adapter, case_obj)
47
+ # Create profiles dictionary
48
+ profiles = {"test_individual": profile_list}
49
+ # match profiles to the profiles in the database
50
+ match = check_duplicates(real_mongo_adapter, profiles, hard_threshold=0.95)
51
+ # This should match with the sample in the database
52
+ assert match["profile"] == profile_list
53
+
54
+ # Change last genotype, now no matches should be found
55
+ profiles = {"test_individual": profile_list[:-1] + ["NN"]}
56
+ match = check_duplicates(real_mongo_adapter, profiles, hard_threshold=0.80)
57
+ assert match is None
58
+
59
+ # Lower threshold. Now match should be found
60
+ match = check_duplicates(real_mongo_adapter, profiles, hard_threshold=0.75)
61
+ assert match["profile"] == profile_list
62
+
63
+
64
+ def test_compare_profiles():
65
+ assert compare_profiles(["AA", "CC"], ["AA", "CC"]) == 1.0
66
+ assert compare_profiles(["AA", "CC"], ["GG", "CC"]) == 0.5
67
+ assert compare_profiles(["AC", "CG"], ["TC", "CG"]) == 0.5
68
+ assert compare_profiles(["AC", "GT"], ["AA", "GG"]) == 0.0
@@ -0,0 +1,67 @@
1
+ """
2
+ tests/vcf_tools/check_par.py
3
+
4
+ Test if variants are in the Pseudo Autosomal Recessive region.
5
+ """
6
+
7
+ from loqusdb.build_models.variant import check_par
8
+
9
+
10
+ def test_par_region_X_lower():
11
+ chrom = "X"
12
+ pos = 60001
13
+ assert check_par(chrom, pos)
14
+
15
+
16
+ def test_par_region_X_middle():
17
+ chrom = "X"
18
+ pos = 1000000
19
+ assert check_par(chrom, pos)
20
+
21
+
22
+ def test_par_region_X_upper():
23
+ chrom = "X"
24
+ pos = 2649520
25
+ assert check_par(chrom, pos)
26
+
27
+
28
+ def test_par_region_X_second():
29
+ chrom = "X"
30
+ pos = 154931044
31
+ assert check_par(chrom, pos)
32
+
33
+
34
+ def test_non_par_X_region():
35
+ chrom = "X"
36
+ pos = 60000
37
+ assert not check_par(chrom, pos)
38
+
39
+
40
+ def test_par_wrong_chrom():
41
+ chrom = "1"
42
+ pos = 60000
43
+ assert not check_par(chrom, pos)
44
+
45
+
46
+ def test_par_region_Y_lower():
47
+ chrom = "Y"
48
+ pos = 10001
49
+ assert check_par(chrom, pos)
50
+
51
+
52
+ def test_par_region_Y_middle():
53
+ chrom = "Y"
54
+ pos = 1000000
55
+ assert check_par(chrom, pos)
56
+
57
+
58
+ def test_par_region_Y_upper():
59
+ chrom = "Y"
60
+ pos = 2649520
61
+ assert check_par(chrom, pos)
62
+
63
+
64
+ def test_par_region_Y_second():
65
+ chrom = "Y"
66
+ pos = 59034050
67
+ assert check_par(chrom, pos)