Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverts -strict behaviour in pdb_tidy #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions pdbtools/pdb_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

Example:
python pdb_tidy.py 1CTF.pdb
python pdb_tidy.py -strict 1CTF.pdb # does not add TER on chain breaks
python pdb_tidy.py -strict 1CTF.pdb # also adds TER on chain breaks

This program is part of the `pdb-tools` suite of utilities and should not be
distributed isolatedly. The `pdb-tools` were created to quickly manipulate PDB
Expand Down Expand Up @@ -117,14 +117,13 @@ def run(fhandle, strict=False):
fhandle : a line-by-line iterator of the original PDB file.

strict : bool
If True, does not add TER statements at intra-chain breaks.
If True, adds TER statements at intra-chain breaks.

Yields
------
str (line-by-line)
The modified (or not) PDB line.
"""
not_strict = not strict
fhandle = iter(fhandle)

def make_TER(prev_line):
Expand Down Expand Up @@ -185,7 +184,7 @@ def make_TER(prev_line):
if line.startswith('ATOM'):

is_gap = (int(line[22:26]) - int(prev_line[22:26])) > 1
if atom_section and (line[21] != prev_line[21] or (not_strict and is_gap)):
if atom_section and (line[21] != prev_line[21] or (strict and is_gap)):
serial_offset += 1 # account for TER statement
yield make_TER(prev_line)

Expand Down
20 changes: 10 additions & 10 deletions tests/test_pdb_tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ def test_default(self):
# Validate results
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
# CONECTs are ignored by issue #72, expected only 205 lines
self.assertEqual(len(self.stdout), 205)
self.assertEqual(len(self.stdout), 204)
self.assertEqual(len(self.stderr), 0) # no errors

# Check if we added TER statements correctly
n_ter = len([r for r in self.stdout if r.startswith('TER')])
self.assertEqual(n_ter, 5)
self.assertEqual(n_ter, 4)

# Check no CONECT in output
c_conect = sum(1 for i in self.stdout if i.startswith('CONECT'))
Expand Down Expand Up @@ -112,10 +112,10 @@ def test_default_in_lib(self):
fin.close()
lines = list(self.module.run(original_lines))

self.assertEqual(len(lines), 205)
self.assertEqual(len(lines), 204)
# Check if we added TER statements correctly
n_ter = len([r for r in lines if r.startswith('TER')])
self.assertEqual(n_ter, 5)
self.assertEqual(n_ter, 4)

# Check no CONECT in output
c_conect = sum(1 for i in lines if i.startswith('CONECT'))
Expand Down Expand Up @@ -151,12 +151,12 @@ def test_default_stdin(self):
# Validate results
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
# CONECTs are ignored by issue #72, expected only 205 lines
self.assertEqual(len(self.stdout), 205)
self.assertEqual(len(self.stdout), 204)
self.assertEqual(len(self.stderr), 0) # no errors

# Check if we added TER statements correctly
n_ter = len([r for r in self.stdout if r.startswith('TER')])
self.assertEqual(n_ter, 5)
self.assertEqual(n_ter, 4)

# Check no CONECT in output
c_conect = sum(1 for i in self.stdout if i.startswith('CONECT'))
Expand All @@ -177,12 +177,12 @@ def test_default_strict(self):
# Validate results
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
# CONECTs are ignored by issue #72, expected only 204 lines
self.assertEqual(len(self.stdout), 204)
self.assertEqual(len(self.stdout), 205)
self.assertEqual(len(self.stderr), 0) # no errors

# Check if we added TER statements correctly
n_ter = len([r for r in self.stdout if r.startswith('TER')])
self.assertEqual(n_ter, 4)
self.assertEqual(n_ter, 5)

# Check no CONECT in output
c_conect = sum(1 for i in self.stdout if i.startswith('CONECT'))
Expand All @@ -204,12 +204,12 @@ def test_default_strict_stdin(self):
# Validate results
self.assertEqual(self.retcode, 0) # ensure the program exited OK.
# CONECTs are ignored by issue #72, expected only 204 lines
self.assertEqual(len(self.stdout), 204)
self.assertEqual(len(self.stdout), 205)
self.assertEqual(len(self.stderr), 0) # no errors

# Check if we added TER statements correctly
n_ter = len([r for r in self.stdout if r.startswith('TER')])
self.assertEqual(n_ter, 4)
self.assertEqual(n_ter, 5)

# Check no CONECT in output
c_conect = sum(1 for i in self.stdout if i.startswith('CONECT'))
Expand Down