From 1013f4eec9c3bc30f1d30d4cba158cfd15a1ae2e Mon Sep 17 00:00:00 2001 From: James Krieger Date: Tue, 10 Dec 2024 20:39:18 +0000 Subject: [PATCH 1/2] fix filterInteractions single selection to include chain --- prody/proteins/interactions.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/prody/proteins/interactions.py b/prody/proteins/interactions.py index 1b9e26f80..68efa8a02 100644 --- a/prody/proteins/interactions.py +++ b/prody/proteins/interactions.py @@ -148,10 +148,17 @@ def filterInteractions(list_of_interactions, atoms, **kwargs): LOGGER.warn('selection did not work, so no filtering is performed') return list_of_interactions - x = p.select(kwargs['selection']).getResnames() - y = p.select(kwargs['selection']).getResnums() - listOfselection = np.unique(list(map(lambda x, y: x + str(y), x, y))) - final = [i for i in list_of_interactions if i[0] in listOfselection or i[3] in listOfselection] + selection = kwargs['selection'] + x = p.select(selection).getResnames() + y = p.select(selection).getResnums() + c = p.select(selection).getChids() + listOfselection = np.unique(list(map(lambda x, y, c: (c, x + str(y)), + x, y, c)), + axis=0) + listOfselection = [list(x) for x in listOfselection] + final = [i for i in list_of_interactions + if (([i[2], i[0]] in listOfselection) + or ([i[5], i[3]] in listOfselection))] elif 'selection2' in kwargs: LOGGER.warn('selection2 by itself is ignored') else: From 532dba138256c8a4ab439c29aa4892c870f56b18 Mon Sep 17 00:00:00 2001 From: James Krieger Date: Fri, 13 Dec 2024 12:34:00 +0000 Subject: [PATCH 2/2] complete general filterInteractions --- prody/proteins/interactions.py | 59 ++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 24 deletions(-) diff --git a/prody/proteins/interactions.py b/prody/proteins/interactions.py index 68efa8a02..1d743f316 100644 --- a/prody/proteins/interactions.py +++ b/prody/proteins/interactions.py @@ -127,40 +127,51 @@ def get_permutation_from_dic(dictionary, key): def filterInteractions(list_of_interactions, atoms, **kwargs): - """Return interactions based on selection.""" + """Return interactions based on *selection* and *selection2*.""" + if 'selection1' in kwargs: + kwargs['selection'] = kwargs['selection1'] + if 'selection' in kwargs: - if 'selection2' in kwargs: - if not 'chid' in kwargs['selection'] and not 'chain' in kwargs['selection']: - LOGGER.warn('selection does not include chid or chain, so no filtering is performed') - return list_of_interactions + selection = atoms.select(kwargs['selection']) + if selection is None: + LOGGER.warn('selection did not work, so no filtering is performed') + return list_of_interactions + + ch1 = selection.getChids() + x1 = selection.getResnames() + y1 = selection.getResnums() + listOfselection = np.unique(list(map(lambda x1, y1, ch1: (ch1, x1 + str(y1)), + x1, y1, ch1)), + axis=0) + listOfselection = [list(i) for i in listOfselection] # needed for in check to work - if not 'chid' in kwargs['selection2'] and not 'chain' in kwargs['selection2']: - LOGGER.warn('selection2 does not include chid or chain, so no filtering is performed') + if 'selection2' in kwargs: + selection2 = atoms.select(kwargs['selection2']) + if selection2 is None: + LOGGER.warn('selection2 did not work, so no filtering is performed') return list_of_interactions - - ch1 = kwargs['selection'].split()[-1] - ch2 = kwargs['selection2'].split()[-1] - final = [i for i in list_of_interactions if (i[2] == ch1 and i[5] == ch2) or (i[5] == ch1 and i[2] == ch2)] + + ch2 = selection2.getChids() + x2 = selection2.getResnames() + y2 = selection2.getResnums() + listOfselection2 = np.unique(list(map(lambda x2, y2, ch2: (ch2, x2 + str(y2)), + x2, y2, ch2)), + axis=0) + listOfselection2 = [list(i) for i in listOfselection2] # needed for in check to work + + final = [i for i in list_of_interactions if (([i[2], i[0]] in listOfselection) + and ([i[5], i[3]] in listOfselection2) + or ([i[2], i[0]] in listOfselection2) + and ([i[5], i[3]] in listOfselection))] else: - p = atoms.select('same residue as protein within 10 of ('+kwargs['selection']+')') - if p is None: - LOGGER.warn('selection did not work, so no filtering is performed') - return list_of_interactions - - selection = kwargs['selection'] - x = p.select(selection).getResnames() - y = p.select(selection).getResnums() - c = p.select(selection).getChids() - listOfselection = np.unique(list(map(lambda x, y, c: (c, x + str(y)), - x, y, c)), - axis=0) - listOfselection = [list(x) for x in listOfselection] final = [i for i in list_of_interactions if (([i[2], i[0]] in listOfselection) or ([i[5], i[3]] in listOfselection))] + elif 'selection2' in kwargs: LOGGER.warn('selection2 by itself is ignored') + final = list_of_interactions else: final = list_of_interactions return final