From f0668c92b3d13de1401995f744aec098c31977b5 Mon Sep 17 00:00:00 2001 From: joaomcteixeira Date: Tue, 8 Nov 2022 09:14:22 +0100 Subject: [PATCH] invert -strict behavior --- pdbtools/pdb_tidy.py | 7 +++---- tests/test_pdb_tidy.py | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pdbtools/pdb_tidy.py b/pdbtools/pdb_tidy.py index fc39df55..779b1374 100644 --- a/pdbtools/pdb_tidy.py +++ b/pdbtools/pdb_tidy.py @@ -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 @@ -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): @@ -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) diff --git a/tests/test_pdb_tidy.py b/tests/test_pdb_tidy.py index e3cbec2f..1f9156bb 100644 --- a/tests/test_pdb_tidy.py +++ b/tests/test_pdb_tidy.py @@ -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')) @@ -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')) @@ -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')) @@ -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')) @@ -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'))