def filter_cath_id(self, cath_id): """ Returns a new container after filtering to only include entries within a given CATH ID """ if not isinstance(cath_id, CathID): cath_id = CathID(cath_id) depth = cath_id.depth filtered_entries = [ c for c in self.entries if c.cath_id_to_depth(depth) == cath_id] return self.__class__(entries=filtered_entries)
def test_cath_id(self): self.assertEqual(str(CathID("1")), "1") self.assertEqual(str(CathID("1.10.8")), "1.10.8") self.assertEqual(str(CathID("1.10.8.10.1.1.1.2.3")), "1.10.8.10.1.1.1.2.3") self.assertEqual(CathID("1.10.8.10").sfam_id, "1.10.8.10") self.assertEqual(CathID("1.10.8.10.1").sfam_id, "1.10.8.10") with self.assertRaises(OutOfBoundsError) as err: cath_id = CathID("1.10.8").sfam_id self.assertRegex(err.exception, r'require depth', 'sfam_id fails when depth < 4')
def __lt__(self, other): if isinstance(other, str): other = CathID(other) return self._cath_id < other._cath_id
def __init__(self, *, cath_id, **kwargs): super().__init__(**kwargs) self._cath_id = CathID(cath_id)