snplib 1.0.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env python
2
+ # coding: utf-8
3
+ __author__ = "Igor Loschinin (igor.loschinin@gmail.com)"
4
+
5
+ from . import DIR_DATA
6
+ from .. import Verification, isag_verif
7
+
8
+ import pytest
9
+ import pandas as pd
10
+
11
+
12
+ @pytest.fixture
13
+ def data() -> pd.DataFrame:
14
+ return pd.read_csv(DIR_DATA / "parentage_test_verf.csv", sep=" ")
15
+
16
+
17
+ @pytest.fixture
18
+ def obj_verification() -> Verification:
19
+ return Verification(isag_marks=isag_verif().markers)
20
+
21
+
22
+ class TestVerification(object):
23
+
24
+ def test_check_on_successfully(
25
+ self, data: pd.DataFrame, obj_verification: Verification
26
+ ) -> None:
27
+
28
+ assert obj_verification.check_on(
29
+ data=data,
30
+ descendant="BY000041988163",
31
+ parent="EE10512586",
32
+ snp_name_col="SNP_Name"
33
+ ) is None
34
+ assert obj_verification.num_conflicts == 31
35
+ assert obj_verification.status == "Excluded"
36
+
37
+ def test_check_on_1(self, data: pd.DataFrame) -> None:
38
+ """
39
+ The test checks the exception for missing token data for verification.
40
+ """
41
+ obj_verification = Verification()
42
+
43
+ with pytest.raises(
44
+ ValueError, match="Error. No array of snp names to verify"
45
+ ):
46
+ obj_verification.check_on(
47
+ data=data,
48
+ descendant="BY000041988163",
49
+ parent="EE10512586",
50
+ snp_name_col="SNP_Name"
51
+ )
52
+ assert obj_verification.status is None
53
+ assert obj_verification.num_conflicts is None
54
+
55
+ def test_check_on_2(
56
+ self, data: pd.DataFrame, obj_verification: Verification
57
+ ) -> None:
58
+ """
59
+ Exception for low call rate in both animals.
60
+ """
61
+
62
+ with pytest.raises(
63
+ Exception, match="Calf and parent have low call rate"
64
+ ):
65
+ obj_verification.check_on(
66
+ data=data[:-100],
67
+ descendant="BY000041988163",
68
+ parent="EE10512586",
69
+ snp_name_col="SNP_Name"
70
+ )
71
+ assert obj_verification.status is None
72
+ assert obj_verification.num_conflicts is None
73
+
74
+ def test_check_on_3(
75
+ self, data: pd.DataFrame, obj_verification: Verification
76
+ ) -> None:
77
+ """
78
+ Exception when paired call rate is below threshold.
79
+ """
80
+
81
+ data.loc[228:, 'BY000041988163'] = 5
82
+ data.loc[239:, 'EE10512586'] = 5
83
+
84
+ with pytest.raises(
85
+ Exception, match="Pair call rate is low"
86
+ ):
87
+ obj_verification.check_on(
88
+ data=data,
89
+ descendant="BY000041988163",
90
+ parent="EE10512586",
91
+ snp_name_col="SNP_Name"
92
+ )
93
+ assert obj_verification.status is None
94
+ assert obj_verification.num_conflicts is None
95
+
96
+ def test_search_parent_4(
97
+ self, data: pd.DataFrame, obj_verification: Verification
98
+ ) -> None:
99
+ """
100
+ Test if the transmitted animal names are not in the dataframe.
101
+ """
102
+
103
+ # For descendant
104
+ with pytest.raises(KeyError):
105
+ obj_verification.check_on(
106
+ data=data,
107
+ descendant="BY00004198816",
108
+ parent="EE10512586",
109
+ snp_name_col="SNP_Name"
110
+ )
111
+ assert obj_verification.status is None
112
+ assert obj_verification.num_conflicts is None
113
+
114
+ # For parents
115
+ with pytest.raises(KeyError):
116
+ obj_verification.check_on(
117
+ data=data,
118
+ descendant="BY000041988163",
119
+ parent="EE105125864",
120
+ snp_name_col="SNP_Name"
121
+ )
122
+ assert obj_verification.status is None
123
+ assert obj_verification.num_conflicts is None
124
+
125
+ def test_search_parent_5(
126
+ self, data: pd.DataFrame, obj_verification: Verification
127
+ ) -> None:
128
+ """
129
+ Test when all snp data is not read - equal to 5
130
+ """
131
+ data[["BY000041988163", "EE10512586"]] = 5
132
+
133
+ with pytest.raises(
134
+ Exception, match="Calf and parent have low call rate"
135
+ ):
136
+ obj_verification.check_on(
137
+ data=data,
138
+ descendant="BY000041988163",
139
+ parent="EE10512586",
140
+ snp_name_col="SNP_Name"
141
+ )
142
+ assert obj_verification.status is None
143
+ assert obj_verification.num_conflicts is None
144
+
145
+ def test_search_parent_6(
146
+ self, data: pd.DataFrame, obj_verification: Verification
147
+ ) -> None:
148
+ """
149
+ Test when there is a complete match
150
+ """
151
+ data[["BY000041988163", "EE10512586"]] = 2
152
+
153
+ obj_verification.check_on(
154
+ data=data,
155
+ descendant="BY000041988163",
156
+ parent="EE10512586",
157
+ snp_name_col="SNP_Name"
158
+ )
159
+ assert obj_verification.status == "Accept"
160
+ assert obj_verification.num_conflicts == 0