pdb-tools 2.5.0__py3-none-any.whl → 2.6.0__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.
Potentially problematic release.
This version of pdb-tools might be problematic. Click here for more details.
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.6.0.dist-info}/METADATA +19 -11
- pdb_tools-2.6.0.dist-info/RECORD +55 -0
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.6.0.dist-info}/WHEEL +1 -1
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.6.0.dist-info}/entry_points.txt +0 -1
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.6.0.dist-info}/top_level.txt +0 -1
- pdbtools/pdb_splitmodel.py +2 -1
- pdbtools/pdb_tidy.py +17 -9
- pdb_tools-2.5.0.dist-info/RECORD +0 -105
- tests/__init__.py +0 -38
- tests/config.py +0 -25
- tests/test_pdb_b.py +0 -161
- tests/test_pdb_chain.py +0 -160
- tests/test_pdb_chainbows.py +0 -140
- tests/test_pdb_chainxseg.py +0 -156
- tests/test_pdb_chkensemble.py +0 -191
- tests/test_pdb_delchain.py +0 -165
- tests/test_pdb_delelem.py +0 -165
- tests/test_pdb_delhetatm.py +0 -115
- tests/test_pdb_delinsertion.py +0 -226
- tests/test_pdb_delres.py +0 -241
- tests/test_pdb_delresname.py +0 -171
- tests/test_pdb_element.py +0 -151
- tests/test_pdb_fixinsert.py +0 -223
- tests/test_pdb_fromcif.py +0 -124
- tests/test_pdb_gap.py +0 -125
- tests/test_pdb_head.py +0 -142
- tests/test_pdb_intersect.py +0 -139
- tests/test_pdb_keepcoord.py +0 -115
- tests/test_pdb_merge.py +0 -106
- tests/test_pdb_mkensemble.py +0 -132
- tests/test_pdb_occ.py +0 -161
- tests/test_pdb_reatom.py +0 -243
- tests/test_pdb_reres.py +0 -281
- tests/test_pdb_rplchain.py +0 -172
- tests/test_pdb_rplresname.py +0 -172
- tests/test_pdb_seg.py +0 -160
- tests/test_pdb_segxchain.py +0 -146
- tests/test_pdb_selaltloc.py +0 -943
- tests/test_pdb_selatom.py +0 -165
- tests/test_pdb_selchain.py +0 -210
- tests/test_pdb_selelem.py +0 -165
- tests/test_pdb_selhetatm.py +0 -116
- tests/test_pdb_selmodel.py +0 -165
- tests/test_pdb_selres.py +0 -257
- tests/test_pdb_selresname.py +0 -171
- tests/test_pdb_selseg.py +0 -165
- tests/test_pdb_shiftres.py +0 -241
- tests/test_pdb_sort.py +0 -254
- tests/test_pdb_splitchain.py +0 -242
- tests/test_pdb_splitmodel.py +0 -235
- tests/test_pdb_splitseg.py +0 -251
- tests/test_pdb_tidy.py +0 -312
- tests/test_pdb_tocif.py +0 -238
- tests/test_pdb_tofasta.py +0 -158
- tests/test_pdb_uniqname.py +0 -156
- tests/test_pdb_validate.py +0 -142
- tests/test_pdb_wc.py +0 -161
- tests/utils.py +0 -56
- {pdb_tools-2.5.0.dist-info → pdb_tools-2.6.0.dist-info/licenses}/LICENSE +0 -0
tests/test_pdb_splitseg.py
DELETED
|
@@ -1,251 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
#
|
|
4
|
-
# Copyright 1118 João Pedro Rodrigues
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
|
|
18
|
-
"""
|
|
19
|
-
Unit Tests for `pdb_splitseg`.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
import os
|
|
23
|
-
import shutil
|
|
24
|
-
import sys
|
|
25
|
-
import tempfile
|
|
26
|
-
import unittest
|
|
27
|
-
|
|
28
|
-
from config import data_dir
|
|
29
|
-
from utils import OutputCapture
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
class TestTool(unittest.TestCase):
|
|
33
|
-
"""
|
|
34
|
-
Generic class for testing tools.
|
|
35
|
-
"""
|
|
36
|
-
|
|
37
|
-
def setUp(self):
|
|
38
|
-
# Dynamically import the module
|
|
39
|
-
name = 'pdbtools.pdb_splitseg'
|
|
40
|
-
self.module = __import__(name, fromlist=[''])
|
|
41
|
-
self.tempdir = tempfile.mkdtemp() # set temp dir
|
|
42
|
-
os.chdir(self.tempdir)
|
|
43
|
-
|
|
44
|
-
def tearDown(self):
|
|
45
|
-
os.chdir(os.path.dirname(os.path.abspath('.'))) # cd ../
|
|
46
|
-
shutil.rmtree(self.tempdir)
|
|
47
|
-
|
|
48
|
-
def exec_module(self):
|
|
49
|
-
"""
|
|
50
|
-
Execs module.
|
|
51
|
-
"""
|
|
52
|
-
|
|
53
|
-
with OutputCapture() as output:
|
|
54
|
-
try:
|
|
55
|
-
self.module.main()
|
|
56
|
-
except SystemExit as e:
|
|
57
|
-
self.retcode = e.code
|
|
58
|
-
|
|
59
|
-
self.stdout = output.stdout
|
|
60
|
-
self.stderr = output.stderr
|
|
61
|
-
|
|
62
|
-
return
|
|
63
|
-
|
|
64
|
-
def test_run_fhandler(self):
|
|
65
|
-
"""pdb_splitseg.run(iterable)"""
|
|
66
|
-
from pdbtools import pdb_splitseg
|
|
67
|
-
|
|
68
|
-
# Copy input file to tempdir
|
|
69
|
-
|
|
70
|
-
# Simulate input
|
|
71
|
-
src = os.path.join(data_dir, 'dummy.pdb')
|
|
72
|
-
dst = os.path.join(self.tempdir, 'dummy.pdb')
|
|
73
|
-
shutil.copy(src, dst)
|
|
74
|
-
|
|
75
|
-
with open(dst, 'r') as fin:
|
|
76
|
-
pdb_splitseg.run(fin)
|
|
77
|
-
|
|
78
|
-
# Read files created by script and then delete
|
|
79
|
-
ofiles = [f for f in os.listdir(self.tempdir) if f.startswith('dummy')]
|
|
80
|
-
self.assertEqual(len(ofiles), 2 + 1) # ori + 2 segments
|
|
81
|
-
|
|
82
|
-
# Make sure each file has the chain it should have
|
|
83
|
-
records = (('ATOM', 'HETATM', 'TER', 'ANISOU'))
|
|
84
|
-
for fpath in ofiles:
|
|
85
|
-
if fpath == 'dummy.pdb':
|
|
86
|
-
continue
|
|
87
|
-
|
|
88
|
-
with open(os.path.join(self.tempdir, fpath), 'r') as handle:
|
|
89
|
-
fname_seg = fpath.split('_')[1][:-4] # xxx_(X).pdb
|
|
90
|
-
pdb_segids = [l[72:76].strip() for l in handle
|
|
91
|
-
if l.startswith(records)]
|
|
92
|
-
|
|
93
|
-
self.assertEqual(fname_seg, list(set(pdb_segids))[0])
|
|
94
|
-
|
|
95
|
-
def test_run_iterable_with_name(self):
|
|
96
|
-
"""pdb_splitseg.run(iterable, outname='newname')"""
|
|
97
|
-
from pdbtools import pdb_splitseg
|
|
98
|
-
|
|
99
|
-
# Copy input file to tempdir
|
|
100
|
-
|
|
101
|
-
# Simulate input
|
|
102
|
-
src = os.path.join(data_dir, 'dummy.pdb')
|
|
103
|
-
dst = os.path.join(self.tempdir, 'dummy.pdb')
|
|
104
|
-
shutil.copy(src, dst)
|
|
105
|
-
|
|
106
|
-
with open(dst, 'r') as fin:
|
|
107
|
-
lines = fin.readlines()
|
|
108
|
-
|
|
109
|
-
pdb_splitseg.run(lines, outname='newname')
|
|
110
|
-
|
|
111
|
-
# Read files created by script and then delete
|
|
112
|
-
ofiles = [f for f in os.listdir(self.tempdir) if f.startswith('newname')]
|
|
113
|
-
self.assertEqual(len(ofiles), 2)
|
|
114
|
-
|
|
115
|
-
# Make sure each file has the chain it should have
|
|
116
|
-
records = (('ATOM', 'HETATM', 'TER', 'ANISOU'))
|
|
117
|
-
for fpath in ofiles:
|
|
118
|
-
with open(os.path.join(self.tempdir, fpath), 'r') as handle:
|
|
119
|
-
fname_seg = fpath.split('_')[1][:-4] # xxx_(X).pdb
|
|
120
|
-
pdb_segids = [l[72:76].strip() for l in handle
|
|
121
|
-
if l.startswith(records)]
|
|
122
|
-
|
|
123
|
-
self.assertEqual(fname_seg, list(set(pdb_segids))[0])
|
|
124
|
-
|
|
125
|
-
def test_run_iterable(self):
|
|
126
|
-
"""pdb_splitseg.run(fhandler)"""
|
|
127
|
-
from pdbtools import pdb_splitseg
|
|
128
|
-
|
|
129
|
-
# Copy input file to tempdir
|
|
130
|
-
|
|
131
|
-
# Simulate input
|
|
132
|
-
src = os.path.join(data_dir, 'dummy.pdb')
|
|
133
|
-
dst = os.path.join(self.tempdir, 'dummy.pdb')
|
|
134
|
-
shutil.copy(src, dst)
|
|
135
|
-
|
|
136
|
-
with open(dst, 'r') as fin:
|
|
137
|
-
lines = fin.readlines()
|
|
138
|
-
|
|
139
|
-
pdb_splitseg.run(lines)
|
|
140
|
-
|
|
141
|
-
# Read files created by script and then delete
|
|
142
|
-
ofiles = [
|
|
143
|
-
f
|
|
144
|
-
for f in os.listdir(self.tempdir)
|
|
145
|
-
if f.startswith('splitsegs')]
|
|
146
|
-
self.assertEqual(len(ofiles), 2)
|
|
147
|
-
|
|
148
|
-
# Make sure each file has the chain it should have
|
|
149
|
-
records = (('ATOM', 'HETATM', 'TER', 'ANISOU'))
|
|
150
|
-
for fpath in ofiles:
|
|
151
|
-
with open(os.path.join(self.tempdir, fpath), 'r') as handle:
|
|
152
|
-
fname_seg = fpath.split('_')[1][:-4] # xxx_(X).pdb
|
|
153
|
-
pdb_segids = [l[72:76].strip() for l in handle
|
|
154
|
-
if l.startswith(records)]
|
|
155
|
-
|
|
156
|
-
self.assertEqual(fname_seg, list(set(pdb_segids))[0])
|
|
157
|
-
|
|
158
|
-
def test_default(self):
|
|
159
|
-
"""$ pdb_splitseg data/dummy.pdb"""
|
|
160
|
-
|
|
161
|
-
# Copy input file to tempdir
|
|
162
|
-
|
|
163
|
-
# Simulate input
|
|
164
|
-
src = os.path.join(data_dir, 'dummy.pdb')
|
|
165
|
-
dst = os.path.join(self.tempdir, 'dummy.pdb')
|
|
166
|
-
shutil.copy(src, dst)
|
|
167
|
-
sys.argv = ['', dst]
|
|
168
|
-
|
|
169
|
-
# Execute the script
|
|
170
|
-
self.exec_module()
|
|
171
|
-
|
|
172
|
-
# Validate results
|
|
173
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
174
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
175
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
176
|
-
|
|
177
|
-
# Read files created by script and then delete
|
|
178
|
-
ofiles = [f for f in os.listdir(self.tempdir) if f.startswith('dummy')]
|
|
179
|
-
self.assertEqual(len(ofiles), 2 + 1) # ori + 2 segments
|
|
180
|
-
|
|
181
|
-
# Make sure each file has the chain it should have
|
|
182
|
-
records = (('ATOM', 'HETATM', 'TER', 'ANISOU'))
|
|
183
|
-
for fpath in ofiles:
|
|
184
|
-
if fpath == 'dummy.pdb':
|
|
185
|
-
continue
|
|
186
|
-
|
|
187
|
-
with open(os.path.join(self.tempdir, fpath), 'r') as handle:
|
|
188
|
-
fname_seg = fpath.split('_')[1][:-4] # xxx_(X).pdb
|
|
189
|
-
pdb_segids = [l[72:76].strip() for l in handle
|
|
190
|
-
if l.startswith(records)]
|
|
191
|
-
|
|
192
|
-
self.assertEqual(fname_seg, list(set(pdb_segids))[0])
|
|
193
|
-
|
|
194
|
-
def test_file_not_found(self):
|
|
195
|
-
"""$ pdb_splitseg not_existing.pdb"""
|
|
196
|
-
|
|
197
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
198
|
-
sys.argv = ['', afile]
|
|
199
|
-
|
|
200
|
-
self.exec_module()
|
|
201
|
-
|
|
202
|
-
self.assertEqual(self.retcode, 1) # exit code is 1 (error)
|
|
203
|
-
self.assertEqual(len(self.stdout), 0) # nothing written to stdout
|
|
204
|
-
self.assertEqual(self.stderr[0][:22],
|
|
205
|
-
"ERROR!! File not found") # proper error message
|
|
206
|
-
|
|
207
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
208
|
-
def test_file_missing(self):
|
|
209
|
-
"""$ pdb_splitseg -10"""
|
|
210
|
-
|
|
211
|
-
sys.argv = ['', '-10']
|
|
212
|
-
|
|
213
|
-
self.exec_module()
|
|
214
|
-
|
|
215
|
-
self.assertEqual(self.retcode, 1)
|
|
216
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
217
|
-
self.assertEqual(self.stderr[0][:38],
|
|
218
|
-
"ERROR!! File not found or not readable")
|
|
219
|
-
|
|
220
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
221
|
-
def test_helptext(self):
|
|
222
|
-
"""$ pdb_splitseg"""
|
|
223
|
-
|
|
224
|
-
sys.argv = ['']
|
|
225
|
-
|
|
226
|
-
self.exec_module()
|
|
227
|
-
|
|
228
|
-
self.assertEqual(self.retcode, 1) # ensure the program exited gracefully.
|
|
229
|
-
self.assertEqual(len(self.stdout), 0) # no output
|
|
230
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
231
|
-
|
|
232
|
-
def test_invalid_option(self):
|
|
233
|
-
"""$ pdb_splitseg -A data/dummy.pdb"""
|
|
234
|
-
|
|
235
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
236
|
-
|
|
237
|
-
self.exec_module()
|
|
238
|
-
|
|
239
|
-
self.assertEqual(self.retcode, 1)
|
|
240
|
-
self.assertEqual(len(self.stdout), 0)
|
|
241
|
-
self.assertEqual(self.stderr[0][:22],
|
|
242
|
-
"ERROR!! Script takes 1") # proper error message
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
if __name__ == '__main__':
|
|
246
|
-
from config import test_dir
|
|
247
|
-
|
|
248
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
249
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
250
|
-
|
|
251
|
-
unittest.main()
|
tests/test_pdb_tidy.py
DELETED
|
@@ -1,312 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python
|
|
2
|
-
# -*- coding: utf-8 -*-
|
|
3
|
-
#
|
|
4
|
-
# Copyright 2018 João Pedro Rodrigues
|
|
5
|
-
#
|
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
# you may not use this file except in compliance with the License.
|
|
8
|
-
# You may obtain a copy of the License at
|
|
9
|
-
#
|
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
#
|
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
# See the License for the specific language governing permissions and
|
|
16
|
-
# limitations under the License.
|
|
17
|
-
|
|
18
|
-
"""
|
|
19
|
-
Unit Tests for `pdb_tidy`.
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
try:
|
|
23
|
-
from StringIO import StringIO # python 2.7
|
|
24
|
-
except ImportError:
|
|
25
|
-
from io import StringIO # python 3.x
|
|
26
|
-
|
|
27
|
-
import os
|
|
28
|
-
import sys
|
|
29
|
-
import unittest
|
|
30
|
-
|
|
31
|
-
from config import data_dir
|
|
32
|
-
from utils import OutputCapture
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class TestTool(unittest.TestCase):
|
|
36
|
-
"""
|
|
37
|
-
Generic class for testing tools.
|
|
38
|
-
"""
|
|
39
|
-
|
|
40
|
-
def setUp(self):
|
|
41
|
-
# Dynamically import the module
|
|
42
|
-
name = 'pdbtools.pdb_tidy'
|
|
43
|
-
self.module = __import__(name, fromlist=[''])
|
|
44
|
-
|
|
45
|
-
def exec_module(self, stdin=None):
|
|
46
|
-
"""
|
|
47
|
-
Execs module.
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
if stdin is not None:
|
|
51
|
-
sys.stdin = StringIO(stdin)
|
|
52
|
-
|
|
53
|
-
with OutputCapture() as output:
|
|
54
|
-
try:
|
|
55
|
-
self.module.main()
|
|
56
|
-
except SystemExit as e:
|
|
57
|
-
self.retcode = e.code
|
|
58
|
-
|
|
59
|
-
self.stdout = output.stdout
|
|
60
|
-
self.stderr = output.stderr
|
|
61
|
-
|
|
62
|
-
sys.stdin = sys.__stdin__ # restore
|
|
63
|
-
|
|
64
|
-
return
|
|
65
|
-
|
|
66
|
-
def test_default(self):
|
|
67
|
-
"""$ pdb_tidy data/dummy.pdb"""
|
|
68
|
-
|
|
69
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
70
|
-
sys.argv = ['', fpath]
|
|
71
|
-
|
|
72
|
-
# Execute the script
|
|
73
|
-
self.exec_module()
|
|
74
|
-
|
|
75
|
-
# Validate results
|
|
76
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
77
|
-
# CONECTs are ignored by issue #72, expected only 205 lines
|
|
78
|
-
self.assertEqual(len(self.stdout), 205)
|
|
79
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
80
|
-
|
|
81
|
-
# Check if we added TER statements correctly
|
|
82
|
-
n_ter = len([r for r in self.stdout if r.startswith('TER')])
|
|
83
|
-
self.assertEqual(n_ter, 5)
|
|
84
|
-
|
|
85
|
-
# Check no CONECT in output
|
|
86
|
-
c_conect = sum(1 for i in self.stdout if i.startswith('CONECT'))
|
|
87
|
-
self.assertEqual(c_conect, 0)
|
|
88
|
-
|
|
89
|
-
# Check if we added END statements correctly
|
|
90
|
-
self.assertTrue(self.stdout[-1].startswith('END'))
|
|
91
|
-
|
|
92
|
-
def test_default_in_lib(self):
|
|
93
|
-
"""
|
|
94
|
-
Test command-line versus lib.
|
|
95
|
-
|
|
96
|
-
$ pdb_tidy data/dummy.pdb
|
|
97
|
-
|
|
98
|
-
>>> original_lines = open('dummy.pdb').readlines()
|
|
99
|
-
>>> lines = list(pdb_tidy.run(original_lines))
|
|
100
|
-
|
|
101
|
-
`lines` and the result from the command-line must be the same.
|
|
102
|
-
"""
|
|
103
|
-
|
|
104
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
105
|
-
sys.argv = ['', fpath]
|
|
106
|
-
|
|
107
|
-
# Execute the script
|
|
108
|
-
self.exec_module()
|
|
109
|
-
|
|
110
|
-
fin = open(os.path.join(data_dir, 'dummy.pdb'))
|
|
111
|
-
original_lines = fin.readlines()
|
|
112
|
-
fin.close()
|
|
113
|
-
lines = list(self.module.run(original_lines))
|
|
114
|
-
|
|
115
|
-
self.assertEqual(len(lines), 205)
|
|
116
|
-
# Check if we added TER statements correctly
|
|
117
|
-
n_ter = len([r for r in lines if r.startswith('TER')])
|
|
118
|
-
self.assertEqual(n_ter, 5)
|
|
119
|
-
|
|
120
|
-
# Check no CONECT in output
|
|
121
|
-
c_conect = sum(1 for i in lines if i.startswith('CONECT'))
|
|
122
|
-
self.assertEqual(c_conect, 0)
|
|
123
|
-
|
|
124
|
-
# Check if we added END statements correctly
|
|
125
|
-
self.assertTrue(lines[-1].startswith('END'))
|
|
126
|
-
|
|
127
|
-
self.assertTrue(lines, self.stdout)
|
|
128
|
-
|
|
129
|
-
def test_tidy_removes_master(self):
|
|
130
|
-
"""Test pdb_tidy removes MASTER lines as well."""
|
|
131
|
-
sys.argv = ['']
|
|
132
|
-
self.exec_module(
|
|
133
|
-
'MASTER 378 0 9 5 3 '
|
|
134
|
-
'0 29 6 847 1 76 7'
|
|
135
|
-
)
|
|
136
|
-
|
|
137
|
-
# Check no MASTER in output
|
|
138
|
-
m_master = sum(1 for i in self.stdout if i.startswith('MASTER'))
|
|
139
|
-
self.assertEqual(m_master, 0)
|
|
140
|
-
|
|
141
|
-
def test_default_stdin(self):
|
|
142
|
-
"""$ cat data/dummy.pdb | pdb_tidy"""
|
|
143
|
-
|
|
144
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
145
|
-
sys.argv = ['']
|
|
146
|
-
|
|
147
|
-
# Execute the script with file as stdin
|
|
148
|
-
with open(fpath) as fp:
|
|
149
|
-
self.exec_module(fp.read())
|
|
150
|
-
|
|
151
|
-
# Validate results
|
|
152
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
153
|
-
# CONECTs are ignored by issue #72, expected only 205 lines
|
|
154
|
-
self.assertEqual(len(self.stdout), 205)
|
|
155
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
156
|
-
|
|
157
|
-
# Check if we added TER statements correctly
|
|
158
|
-
n_ter = len([r for r in self.stdout if r.startswith('TER')])
|
|
159
|
-
self.assertEqual(n_ter, 5)
|
|
160
|
-
|
|
161
|
-
# Check no CONECT in output
|
|
162
|
-
c_conect = sum(1 for i in self.stdout if i.startswith('CONECT'))
|
|
163
|
-
self.assertEqual(c_conect, 0)
|
|
164
|
-
|
|
165
|
-
# Check if we added END statements correctly
|
|
166
|
-
self.assertTrue(self.stdout[-1].startswith('END'))
|
|
167
|
-
|
|
168
|
-
def test_default_strict(self):
|
|
169
|
-
"""$ pdb_tidy -strict data/dummy.pdb"""
|
|
170
|
-
|
|
171
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
172
|
-
sys.argv = ['', '-strict', fpath]
|
|
173
|
-
|
|
174
|
-
# Execute the script
|
|
175
|
-
self.exec_module()
|
|
176
|
-
|
|
177
|
-
# Validate results
|
|
178
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
179
|
-
# CONECTs are ignored by issue #72, expected only 204 lines
|
|
180
|
-
self.assertEqual(len(self.stdout), 204)
|
|
181
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
182
|
-
|
|
183
|
-
# Check if we added TER statements correctly
|
|
184
|
-
n_ter = len([r for r in self.stdout if r.startswith('TER')])
|
|
185
|
-
self.assertEqual(n_ter, 4)
|
|
186
|
-
|
|
187
|
-
# Check no CONECT in output
|
|
188
|
-
c_conect = sum(1 for i in self.stdout if i.startswith('CONECT'))
|
|
189
|
-
self.assertEqual(c_conect, 0)
|
|
190
|
-
|
|
191
|
-
# Check if we added END statements correctly
|
|
192
|
-
self.assertTrue(self.stdout[-1].startswith('END'))
|
|
193
|
-
|
|
194
|
-
def test_default_strict_stdin(self):
|
|
195
|
-
"""$ cat data/dummy.pdb | pdb_tidy -strict"""
|
|
196
|
-
|
|
197
|
-
fpath = os.path.join(data_dir, 'dummy.pdb')
|
|
198
|
-
sys.argv = ['', '-strict']
|
|
199
|
-
|
|
200
|
-
# Execute the script
|
|
201
|
-
with open(fpath) as fp:
|
|
202
|
-
self.exec_module(fp.read())
|
|
203
|
-
|
|
204
|
-
# Validate results
|
|
205
|
-
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
|
|
206
|
-
# CONECTs are ignored by issue #72, expected only 204 lines
|
|
207
|
-
self.assertEqual(len(self.stdout), 204)
|
|
208
|
-
self.assertEqual(len(self.stderr), 0) # no errors
|
|
209
|
-
|
|
210
|
-
# Check if we added TER statements correctly
|
|
211
|
-
n_ter = len([r for r in self.stdout if r.startswith('TER')])
|
|
212
|
-
self.assertEqual(n_ter, 4)
|
|
213
|
-
|
|
214
|
-
# Check no CONECT in output
|
|
215
|
-
c_conect = sum(1 for i in self.stdout if i.startswith('CONECT'))
|
|
216
|
-
self.assertEqual(c_conect, 0)
|
|
217
|
-
|
|
218
|
-
# Check if we added END statements correctly
|
|
219
|
-
self.assertTrue(self.stdout[-1].startswith('END'))
|
|
220
|
-
|
|
221
|
-
def test_corrects_model_format_and_numbers(self):
|
|
222
|
-
"""Correct MODEL lines."""
|
|
223
|
-
fpath = os.path.join(data_dir, 'ensemble_error_MODEL.pdb')
|
|
224
|
-
sys.argv = ['', fpath]
|
|
225
|
-
self.exec_module()
|
|
226
|
-
self.assertEqual(self.retcode, 0)
|
|
227
|
-
self.assertEqual(len(self.stdout), 16)
|
|
228
|
-
self.assertEqual(len(self.stderr), 0)
|
|
229
|
-
self.assertEqual(len(self.stdout[5].strip()), 14)
|
|
230
|
-
self.assertEqual(len(self.stdout[5]), 80)
|
|
231
|
-
self.assertEqual(len(self.stdout[10].strip()), 14)
|
|
232
|
-
self.assertEqual(len(self.stdout[10]), 80)
|
|
233
|
-
self.assertEqual(self.stdout[5].strip(), "MODEL 1")
|
|
234
|
-
self.assertEqual(self.stdout[10].strip(), "MODEL 2")
|
|
235
|
-
|
|
236
|
-
def test_corrects_model_ENDMDL(self):
|
|
237
|
-
"""Correct MODEL lines."""
|
|
238
|
-
fpath = os.path.join(data_dir, 'ensemble_error_4.pdb')
|
|
239
|
-
sys.argv = ['', fpath]
|
|
240
|
-
self.exec_module()
|
|
241
|
-
self.assertEqual(self.retcode, 0)
|
|
242
|
-
self.assertEqual(len(self.stdout), 14)
|
|
243
|
-
self.assertEqual(len(self.stderr), 0)
|
|
244
|
-
|
|
245
|
-
# MODEL lines
|
|
246
|
-
self.assertEqual(len(self.stdout[3].strip()), 14)
|
|
247
|
-
self.assertEqual(len(self.stdout[3]), 80)
|
|
248
|
-
self.assertEqual(len(self.stdout[3].strip()), 14)
|
|
249
|
-
self.assertEqual(len(self.stdout[8]), 80)
|
|
250
|
-
self.assertEqual(self.stdout[3].strip(), "MODEL 1")
|
|
251
|
-
self.assertEqual(self.stdout[8].strip(), "MODEL 2")
|
|
252
|
-
|
|
253
|
-
# ENDMDL LINES
|
|
254
|
-
self.assertEqual(len(self.stdout[7]), 80)
|
|
255
|
-
self.assertEqual(len(self.stdout[12]), 80)
|
|
256
|
-
self.assertEqual(self.stdout[7].strip(), "ENDMDL")
|
|
257
|
-
self.assertEqual(self.stdout[12].strip(), "ENDMDL")
|
|
258
|
-
|
|
259
|
-
# END LINES
|
|
260
|
-
self.assertEqual(self.stdout[-1].strip(), "END")
|
|
261
|
-
self.assertEqual(len(self.stdout[-1]), 80)
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
def test_file_not_found(self):
|
|
265
|
-
"""$ pdb_tidy not_existing.pdb"""
|
|
266
|
-
|
|
267
|
-
# Error (file not found)
|
|
268
|
-
afile = os.path.join(data_dir, 'not_existing.pdb')
|
|
269
|
-
sys.argv = ['', afile]
|
|
270
|
-
|
|
271
|
-
# Execute the script
|
|
272
|
-
self.exec_module()
|
|
273
|
-
|
|
274
|
-
self.assertEqual(self.retcode, 1)
|
|
275
|
-
self.assertEqual(len(self.stdout), 0)
|
|
276
|
-
self.assertEqual(self.stderr[0][:22],
|
|
277
|
-
"ERROR!! File not found")
|
|
278
|
-
|
|
279
|
-
@unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY')
|
|
280
|
-
def test_helptext(self):
|
|
281
|
-
"""$ pdb_tidy"""
|
|
282
|
-
|
|
283
|
-
sys.argv = ['']
|
|
284
|
-
|
|
285
|
-
# Execute the script
|
|
286
|
-
self.exec_module()
|
|
287
|
-
|
|
288
|
-
self.assertEqual(self.retcode, 1)
|
|
289
|
-
self.assertEqual(len(self.stdout), 0)
|
|
290
|
-
self.assertEqual(self.stderr, self.module.__doc__.split("\n")[:-1])
|
|
291
|
-
|
|
292
|
-
def test_invalid_option(self):
|
|
293
|
-
"""$ pdb_tidy -A data/dummy.pdb"""
|
|
294
|
-
|
|
295
|
-
sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')]
|
|
296
|
-
|
|
297
|
-
# Execute the script
|
|
298
|
-
self.exec_module()
|
|
299
|
-
|
|
300
|
-
self.assertEqual(self.retcode, 1)
|
|
301
|
-
self.assertEqual(len(self.stdout), 0)
|
|
302
|
-
self.assertEqual(self.stderr[0][:36],
|
|
303
|
-
"ERROR! First argument is not a valid")
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
if __name__ == '__main__':
|
|
307
|
-
from config import test_dir
|
|
308
|
-
|
|
309
|
-
mpath = os.path.abspath(os.path.join(test_dir, '..'))
|
|
310
|
-
sys.path.insert(0, mpath) # so we load dev files before any installation
|
|
311
|
-
|
|
312
|
-
unittest.main()
|