From 3ee8555bc713dbd4d60ce786c6658c2dcdfdd659 Mon Sep 17 00:00:00 2001 From: Gabriel Studer <gabriel.studer@unibas.ch> Date: Thu, 9 Mar 2023 09:44:12 +0100 Subject: [PATCH] raise Error when no chain fulfills minimum number of residues in ChainMapper The previous error was a selection statement with no obvious connection to that problem. Default minimum lengths are 10 for peptide chains and 4 for nucleotide chains --- modules/mol/alg/pymod/chain_mapping.py | 7 +++++++ modules/mol/alg/tests/test_chain_mapping.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/modules/mol/alg/pymod/chain_mapping.py b/modules/mol/alg/pymod/chain_mapping.py index 7ee8ff5fc..f5e10d58c 100644 --- a/modules/mol/alg/pymod/chain_mapping.py +++ b/modules/mol/alg/pymod/chain_mapping.py @@ -1499,6 +1499,13 @@ class ChainMapper: else: raise RuntimeError("This shouldnt happen") + if len(polypep_seqs) == 0 and len(polynuc_seqs) == 0: + raise RuntimeError(f"No chain fulfilled minimum length requirement " + f"to be considered in chain mapping " + f"({self.min_pep_length} for peptide chains, " + f"{self.min_nuc_length} for nucleotide chains) " + f"- mapping failed") + # select for chains for which we actually extracted the sequence chain_names = [s.GetAttachedView().chains[0].name for s in polypep_seqs] chain_names += [s.GetAttachedView().chains[0].name for s in polynuc_seqs] diff --git a/modules/mol/alg/tests/test_chain_mapping.py b/modules/mol/alg/tests/test_chain_mapping.py index 36a633b09..8c8846aba 100644 --- a/modules/mol/alg/tests/test_chain_mapping.py +++ b/modules/mol/alg/tests/test_chain_mapping.py @@ -353,6 +353,13 @@ class TestChainMapper(unittest.TestCase): aln.GetSequence(1).GetString()) + def test_misc(self): + + # check for triggered error when no chain fulfills length threshold + ref = _LoadFile("3l1p.1.pdb").Select("cname=A and rnum<8") + self.assertRaises(Exception, ChainMapper, ref) + + if __name__ == "__main__": from ost import testutils if testutils.SetDefaultCompoundLib(): -- GitLab