-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.py
executable file
·188 lines (160 loc) · 6.12 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env python3
import shutil
import unittest
import psa
class Test(unittest.TestCase):
def test_is_emboss_installed(self):
self.assertIsNotNone(shutil.which('needle'))
self.assertIsNotNone(shutil.which('water'))
self.assertIsNotNone(shutil.which('stretcher'))
def test_needle_dna(self):
aln = psa.needle(moltype='nucl', qseq='ATGCTAGATA', sseq='ATGCTAGTTA')
self.assertEqual(len(aln.qaln), len(aln.saln))
self.assertEqual(len(aln.qaln), aln.length)
def test_water_dna(self):
aln = psa.water(moltype='nucl', qseq='ATGCTAGTTA', sseq='ATCCT')
self.assertEqual(len(aln.qaln), len(aln.saln))
self.assertEqual(len(aln.qaln), aln.length)
def test_water_stretcher(self):
aln = psa.stretcher(moltype='nucl', qseq='ATGCTAGATA', sseq='ATGCTAGTTA')
self.assertEqual(len(aln.qaln), len(aln.saln))
self.assertEqual(len(aln.qaln), aln.length)
def test_needle_protein(self):
aln = psa.needle(moltype='prot', qseq='MERILIIMTGG', sseq='MEKILILM')
self.assertEqual(len(aln.qaln), len(aln.saln))
self.assertEqual(len(aln.qaln), aln.length)
def test_water_protein(self):
aln = psa.water(moltype='prot', qseq='MERI', sseq='MEKILILM')
self.assertEqual(len(aln.qaln), len(aln.saln))
self.assertEqual(len(aln.qaln), aln.length)
def test_stretcher_protein(self):
aln = psa.stretcher(moltype='prot', qseq='MERILIIMTGG', sseq='MEKILILM')
self.assertEqual(len(aln.qaln), len(aln.saln))
self.assertEqual(len(aln.qaln), aln.length)
def test_needle_dna_qid_sid(self):
qid = 'dna1'
sid = 'dna2'
qseq = 'ATGCTAGATA'
sseq = 'ATGCTAGTTA'
aln = psa.needle(moltype='nucl', qseq=qseq, sseq=sseq, qid=qid, sid=sid)
self.assertEqual(len(aln.qaln), len(aln.saln))
self.assertEqual(len(aln.qaln), aln.length)
self.assertEqual(aln.qid, qid)
self.assertEqual(aln.sid, sid)
class TestPairwiseAlignment(unittest.TestCase):
def setUp(self):
self.aln1 = psa.PairwiseAlignment(
qid='query',
sid='subject',
qseq='MERILIIMTGGTITSIRDDEVTLELLIDYRKRFGDTQRFDIVKLMNIIS',
sseq='MERILIIMTGGTISSIKKENILNVDDEVTLELLIDYRKRFGDSQKFDIVILIIS',
qaln='MERILIIMTGGTITSIR-------DDEVTLELLIDYRKRFGDTQRFDIVKLMNIIS',
saln='MERILIIMTGGTISSIKKENILNVDDEVTLELLIDYRKRFGDSQKFDIVIL--IIS',
qstart=1,
qend=49,
sstart=1,
send=54,
length=56,
score=183.5,
nidentity=42,
nsimilarity=46,
ngaps=9,
moltype='prot',
program='needle',
gapopen=10,
gapextend=0.5,
matrix='EBLOSUM62',
raw=[] # Skipped for code readability.
)
self.aln2 = psa.PairwiseAlignment(
qid='oddly_long_sequence_identifier1',
sid='oddly_long_sequence_identifier2',
qseq='ATGCTAGTAGTTGATTTTTT',
sseq='ATGCTAGTAGATGAT',
qaln='ATGCTAGTAGTTGAT',
saln='ATGCTAGTAGATGAT',
qstart=1,
qend=15,
sstart=1,
send=15,
length=15,
score=66.0,
nidentity=14,
nsimilarity=14,
ngaps=0,
moltype='nucl',
program='water',
gapopen=10,
gapextend=0.5,
matrix='EDNAFULL',
raw=[] # Skipped for code readability.
)
def test_pidentity(self):
self.assertEqual(self.aln1.pidentity, 75.0)
self.assertAlmostEqual(self.aln2.pidentity, 93.3333333)
def test_psimilarity(self):
self.assertAlmostEqual(self.aln1.psimilarity, 82.1428571)
self.assertAlmostEqual(self.aln2.psimilarity, 93.3333333)
def test_pgaps(self):
self.assertAlmostEqual(self.aln1.pgaps, 16.0714286)
self.assertAlmostEqual(self.aln2.pgaps, 0)
def test_query_coverage(self):
self.assertAlmostEqual(self.aln1.query_coverage(), 100.0)
self.assertAlmostEqual(self.aln2.query_coverage(), 75.0)
def test_subject_coverage(self):
self.assertAlmostEqual(self.aln1.subject_coverage(), 100.0)
self.assertAlmostEqual(self.aln2.subject_coverage(), 100.0)
def test_len(self):
self.assertEqual(len(self.aln1), 56)
self.assertEqual(len(self.aln2), 15)
def test_getitem(self):
self.assertEqual(self.aln1[13], ('T', 'S'))
self.assertEqual(self.aln2[1], ('T', 'T'))
def test_iter(self):
self.assertEqual(list(iter(self.aln1))[0], ('M', 'M'))
self.assertEqual(list(iter(self.aln2))[0], ('A', 'A'))
def test_fasta_aln1(self):
fasta = [
'>query 1-49',
'MERILIIMTGGTITSIR-------DDEVTLELLIDYRKRFGDTQRFDIVKLMNIIS',
'>subject 1-54',
'MERILIIMTGGTISSIKKENILNVDDEVTLELLIDYRKRFGDSQKFDIVIL--IIS',
]
self.assertEqual(self.aln1.fasta(), "\n".join(fasta))
def test_fasta_aln2(self):
fasta = [
'>oddly_long_sequence_identifier1 1-15',
'ATGCTAGTAGTTGAT',
'>oddly_long_sequence_identifier2 1-15',
'ATGCTAGTAGATGAT',
]
self.assertEqual(self.aln2.fasta(), "\n".join(fasta))
def test_fasta_aln1_wrap10(self):
fasta = [
'>query 1-49',
'MERILIIMTG',
'GTITSIR---',
'----DDEVTL',
'ELLIDYRKRF',
'GDTQRFDIVK',
'LMNIIS',
'>subject 1-54',
'MERILIIMTG',
'GTISSIKKEN',
'ILNVDDEVTL',
'ELLIDYRKRF',
'GDSQKFDIVI',
'L--IIS',
]
self.assertEqual(self.aln1.fasta(wrap=10), "\n".join(fasta))
def test_fasta_aln2_wrap10(self):
fasta = [
'>oddly_long_sequence_identifier1 1-15',
'ATGCTAGTAG',
'TTGAT',
'>oddly_long_sequence_identifier2 1-15',
'ATGCTAGTAG',
'ATGAT',
]
self.assertEqual(self.aln2.fasta(wrap=10), "\n".join(fasta))
unittest.main()