From 55ad6618e750b1d0c3461ad92ecbd0d7b9f7a198 Mon Sep 17 00:00:00 2001 From: jjavier-bm Date: Wed, 1 Jun 2022 13:46:21 +0100 Subject: [PATCH 1/4] core.contactmap match and match_naive functions now match_other=True ALWAYS signals FNs in contact_map2 --- conkit/core/contactmap.py | 15 +++---- conkit/core/tests/test_contactmap.py | 60 ++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/conkit/core/contactmap.py b/conkit/core/contactmap.py index db7db3fe..e006d7d6 100644 --- a/conkit/core/contactmap.py +++ b/conkit/core/contactmap.py @@ -738,13 +738,14 @@ def match_naive(self, other, add_false_negatives=False, match_other=False, inpla else: contact.false_positive = True - if not add_false_negatives: + if not add_false_negatives and not match_other: return contact_map1 for contact in contact_map2: if contact.id not in contact_map1_set: contact.false_negative = True - contact_map1.add(contact) + if add_false_negatives: + contact_map1.add(contact) return contact_map1 @@ -876,12 +877,12 @@ def match(self, other, add_false_negatives=False, match_other=False, remove_unma # ================================================================ # 3. Add false negatives # ================================================================ - if add_false_negatives: - for contactid in contact_map2.as_list(): - contactid = tuple(contactid) - if contactid not in contact_map1: + for contactid in contact_map2.as_list(): + contactid = tuple(contactid) + if contactid not in contact_map1: + contact_map2[contactid].false_negative = True + if add_false_negatives: contact = contact_map2[contactid].copy() - contact.false_negative = True contact_map1.add(contact) # ================================================================ diff --git a/conkit/core/tests/test_contactmap.py b/conkit/core/tests/test_contactmap.py index d2e40266..48896f2f 100644 --- a/conkit/core/tests/test_contactmap.py +++ b/conkit/core/tests/test_contactmap.py @@ -535,6 +535,7 @@ def test_match_4(self): contact_map1.match(contact_map2, match_other=True, remove_unmatched=True, inplace=True) self.assertEqual([TP, TP], [c.status for c in contact_map1]) + self.assertEqual([TP, TP, FN], [c.status for c in contact_map2]) self.assertEqual([2, 2, 3], [c.res1_altseq for c in contact_map2]) self.assertEqual([6, 7, 5], [c.res2_altseq for c in contact_map2]) @@ -891,6 +892,27 @@ def test_match_14(self): contact_map2.set_sequence_register() contact_map1.match(contact_map2, add_false_negatives=True, inplace=True, match_other=True) + self.assertEqual([FN, FN, FN, FN], [c.status for c in contact_map1]) + self.assertEqual([FN, FN, FN, FN], [c.status for c in contact_map2]) + self.assertListEqual([[1, 5], [1, 7], [2, 7], [3, 4]], contact_map2.as_list()) + + def test_match_15(self): + contact_map1 = ContactMap("foo") + contact_map1.sequence = Sequence("foo", "AICDEFGH") + contact_map1.set_sequence_register() + + contact_map2 = ContactMap("bar") + for i, params in enumerate([(1, 5, 1.0), (1, 7, 1.0), (2, 7, 1.0), (3, 4, 1.0)]): + contact = Contact(*params) + contact.res1_altseq = params[0] + contact.res2_altseq = params[1] + contact.status = TP + contact_map2.add(contact) + contact_map2.sequence = Sequence("bar", "AICDEFGH") + contact_map2.set_sequence_register() + + contact_map1.match(contact_map2, inplace=True, match_other=True) + self.assertEqual([], [c.status for c in contact_map1]) self.assertEqual([FN, FN, FN, FN], [c.status for c in contact_map2]) self.assertListEqual([[1, 5], [1, 7], [2, 7], [3, 4]], contact_map2.as_list()) @@ -946,9 +968,47 @@ def test_match_naive_3(self): contact_map2.set_sequence_register() contact_map1.match_naive(contact_map2, add_false_negatives=True, inplace=True, match_other=True) + self.assertEqual([FN, FN, FN, FN], [c.status for c in contact_map1]) self.assertEqual([FN, FN, FN, FN], [c.status for c in contact_map2]) self.assertListEqual([[1, 5], [1, 7], [2, 7], [3, 4]], contact_map2.as_list()) + def test_match_naive_4(self): + contact_map1 = ContactMap("foo") + for params in [(1, 5, 1.0), (1, 6, 1.0), (2, 7, 1.0), (3, 5, 1.0), (2, 8, 1.0)]: + contact = Contact(*params) + contact_map1.add(contact) + + contact_map2 = ContactMap("bar") + for i, params in enumerate([(1, 5, 1.0), (1, 7, 1.0), (2, 7, 1.0), (3, 4, 1.0)]): + contact = Contact(*params) + contact.res1_altseq = params[0] + contact.res2_altseq = params[1] + contact.status = TP + contact_map2.add(contact) + + contact_map1.match_naive(contact_map2, inplace=True, match_other=True) + self.assertEqual([TP, FP, TP, FP, FP], [c.status for c in contact_map1]) + self.assertEqual([TP, FN, TP, FN], [c.status for c in contact_map2]) + + def test_match_naive_5(self): + contact_map1 = ContactMap("foo") + contact_map1.sequence = Sequence("foo", "AICDEFGH") + contact_map1.set_sequence_register() + + contact_map2 = ContactMap("bar") + for i, params in enumerate([(1, 5, 1.0), (1, 7, 1.0), (2, 7, 1.0), (3, 4, 1.0)]): + contact = Contact(*params) + contact.res1_altseq = params[0] + contact.res2_altseq = params[1] + contact.status = TP + contact_map2.add(contact) + contact_map2.sequence = Sequence("bar", "AICDEFGH") + contact_map2.set_sequence_register() + + contact_map1.match_naive(contact_map2, inplace=True, match_other=True) + self.assertEqual([], [c.status for c in contact_map1]) + self.assertEqual([FN, FN, FN, FN], [c.status for c in contact_map2]) + def test_remove_neighbors_1(self): contact_map = ContactMap("test") for c in [Contact(1, 5, 1.0), Contact(3, 3, 0.4), Contact(2, 4, 0.1), Contact(5, 1, 0.2)]: From 9b45a33de4b07ecbfae5e4593e620d7b405dbfaf Mon Sep 17 00:00:00 2001 From: jjavier-bm Date: Wed, 1 Jun 2022 13:59:23 +0100 Subject: [PATCH 2/4] minor fix conkit.core.contactmap.ContactMap.match --- conkit/core/contactmap.py | 2 +- conkit/core/tests/.test_contactmap.py.swp | Bin 0 -> 1024 bytes 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 conkit/core/tests/.test_contactmap.py.swp diff --git a/conkit/core/contactmap.py b/conkit/core/contactmap.py index e006d7d6..3b23bd33 100644 --- a/conkit/core/contactmap.py +++ b/conkit/core/contactmap.py @@ -880,7 +880,7 @@ def match(self, other, add_false_negatives=False, match_other=False, remove_unma for contactid in contact_map2.as_list(): contactid = tuple(contactid) if contactid not in contact_map1: - contact_map2[contactid].false_negative = True + contact_map2[contactid].status = ContactMatchState.false_negative if add_false_negatives: contact = contact_map2[contactid].copy() contact_map1.add(contact) diff --git a/conkit/core/tests/.test_contactmap.py.swp b/conkit/core/tests/.test_contactmap.py.swp new file mode 100644 index 0000000000000000000000000000000000000000..1b085876b4a7c5d3b58be247a81a50cdc6eacf56 GIT binary patch literal 1024 zcmYc?$V<%2S1{4DU_b#8qRb3giDj9oMJU2pImwkJ`Nf%esk%m3rQw3f`FYuyCHl$v nMXCBFsl_G5U@{&kT#}evlABndS5OI8Jjxgifzc44c?bXis^1t0 literal 0 HcmV?d00001 From 46bd45e14029b436aca18bd7cc31c0f938dcde84 Mon Sep 17 00:00:00 2001 From: jjavier-bm Date: Wed, 1 Jun 2022 14:42:35 +0100 Subject: [PATCH 3/4] minor fix conkit.core.contactmap.ContactMap.match 2 --- conkit/core/contactmap.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/conkit/core/contactmap.py b/conkit/core/contactmap.py index 3b23bd33..310f884f 100644 --- a/conkit/core/contactmap.py +++ b/conkit/core/contactmap.py @@ -801,15 +801,16 @@ def match(self, other, add_false_negatives=False, match_other=False, remove_unma else: contact_map2 = other._inplace(False) - if contact_map1.empty and add_false_negatives: + if contact_map1.empty: for contact in contact_map2: contact.false_negative = True + if add_false_negatives: + contact_map1.add(contact) + return contact_map1 if contact_map2.empty: for contact in contact_map1: contact.false_positive = True - - if contact_map2.empty or contact_map1.empty: return contact_map1 # ================================================================ From 953f818a6bf9b952bbf0e6d7a3d9c49032aa5c01 Mon Sep 17 00:00:00 2001 From: jjavier-bm Date: Wed, 1 Jun 2022 14:58:25 +0100 Subject: [PATCH 4/4] remove trash backup file --- conkit/core/tests/.test_contactmap.py.swp | Bin 1024 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 conkit/core/tests/.test_contactmap.py.swp diff --git a/conkit/core/tests/.test_contactmap.py.swp b/conkit/core/tests/.test_contactmap.py.swp deleted file mode 100644 index 1b085876b4a7c5d3b58be247a81a50cdc6eacf56..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1024 zcmYc?$V<%2S1{4DU_b#8qRb3giDj9oMJU2pImwkJ`Nf%esk%m3rQw3f`FYuyCHl$v nMXCBFsl_G5U@{&kT#}evlABndS5OI8Jjxgifzc44c?bXis^1t0