forked from pydna-group/pydna
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_module_contig.py
executable file
·152 lines (114 loc) · 4.38 KB
/
test_module_contig.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
import pytest
def test_contig(monkeypatch):
monkeypatch.setenv("pydna_cached_funcs", "")
from pydna import contig
from pydna.assembly import Assembly
from pydna.dseqrecord import Dseqrecord
a = Dseqrecord("acgatgctatactgCCCCCtgtgctgtgctcta", name="one")
b = Dseqrecord("tgtgctgtgctctaTTTTTtattctggctgtatc", name="two")
c = Dseqrecord("tattctggctgtatcGGGGGtacgatgctatactg", name="three")
asm = Assembly((a,b,c), limit=14)
cnt = asm.circular_products[0]
assert repr(cnt) == "Contig(o59)"
assert cnt.detailed_figure() == str( "||||||||||||||\n"
"acgatgctatactgCCCCCtgtgctgtgctcta\n"
" TGTGCTGTGCTCTA\n"
" tgtgctgtgctctaTTTTTtattctggctgtatc\n"
" TATTCTGGCTGTATC\n"
" tattctggctgtatcGGGGGtacgatgctatactg\n"
" ACGATGCTATACTG\n")
from textwrap import indent
fig = """ -|one|14
| \\/
| /\\
| 14|two|15
| \\/
| /\\
| 15|three|14
| \\/
| /\\
| 14-
| |
-------------------------"""
assert fig == cnt.small_fig()
cnt2 = asm.linear_products[0]
fig = ('one|14\n'
' \\/\n'
' /\\\n'
' 14|two|15\n'
' \\/\n'
' /\\\n'
' 15|three')
assert fig == cnt2.small_fig() == cnt2.figure() == cnt2.small_figure()
assert repr(cnt2) == 'Contig(-73)'
#print(repr(cnt2._repr_html_()))
assert cnt2._repr_html_() == '<pre>one|14\n \\/\n /\\\n 14|two|15\n \\/\n /\\\n 15|three</pre>'
from unittest.mock import MagicMock
pp = MagicMock()
cnt2._repr_pretty_(pp, None)
pp.text.assert_called_with('Contig(-73)')
def test_reverse_complement(monkeypatch):
from pydna._pretty import pretty_str
from pydna.assembly import Assembly
from pydna.dseqrecord import Dseqrecord
a = Dseqrecord("acgatgctatactgtgCCNCCtgtgctgtgctcta")
b = Dseqrecord("tgtgctgtgctctaTTTTTTTtattctggctgtatc")
c = Dseqrecord("tattctggctgtatcGGGGGtacgatgctatactgtg")
a.name="aaa"
b.name="bbb"
c.name="ccc"
x = Assembly((a,b,c), limit=14)
y = x.circular[0]
yfig = '''
-|aaa|14
| \\/
| /\\
| 14|bbb|15
| \\/
| /\\
| 15|ccc|16
| \\/
| /\\
| 16-
| |
-----------------------
'''[1:].rstrip()
ydfig= pretty_str('''
||||||||||||||||
acgatgctatactgtgCCNCCtgtgctgtgctcta
TGTGCTGTGCTCTA
tgtgctgtgctctaTTTTTTTtattctggctgtatc
TATTCTGGCTGTATC
tattctggctgtatcGGGGGtacgatgctatactgtg
ACGATGCTATACTGTG
'''[1:].rstrip()+"\n")
assert y.figure() == yfig
assert y.detailed_figure() == ydfig
z=y.rc()
zfig = '''
-|ccc_rc|15
| \\/
| /\\
| 15|bbb_rc|14
| \\/
| /\\
| 14|aaa_rc|16
| \\/
| /\\
| 16-
| |
--------------------------------
'''[1:].rstrip()
zdfig= '''
||||||||||||||||
cacagtatagcatcgtaCCCCCgatacagccagaata
GATACAGCCAGAATA
gatacagccagaataAAAAAAAtagagcacagcaca
TAGAGCACAGCACA
tagagcacagcacaGGNGGcacagtatagcatcgt
CACAGTATAGCATCGT
'''[1:].rstrip()+"\n"
assert z.figure() == zfig
assert z.detailed_figure() == zdfig
if __name__ == '__main__':
pytest.main([__file__, "-vv", "-s","--cov=pydna","--cov-report=html"])