From bc5fcb630aa4434bf2c89f10863aeb2c1a09180b Mon Sep 17 00:00:00 2001 From: James Krieger Date: Thu, 22 Aug 2024 20:17:22 +0200 Subject: [PATCH 1/6] better insty tests --- prody/tests/proteins/test_insty.py | 109 +++++++++++++++++------------ 1 file changed, 63 insertions(+), 46 deletions(-) diff --git a/prody/tests/proteins/test_insty.py b/prody/tests/proteins/test_insty.py index 0fd6a47ac..1a2dfa46b 100644 --- a/prody/tests/proteins/test_insty.py +++ b/prody/tests/proteins/test_insty.py @@ -29,44 +29,37 @@ def setUp(self): self.HPH_INTERACTIONS = parseDatafile('2k39_hph') self.HPH_INTERACTIONS2 = parseDatafile('2k39_hph2') self.DISU_INTERACTIONS = parseDatafile('2k39_disu') - - self.INTERACTIONS_ALL = InteractionsTrajectory() - self.data_all = self.INTERACTIONS_ALL.calcProteinInteractionsTrajectory(self.ATOMS) - np.save('test_2k39_all.npy', self.data_all, allow_pickle=True) - - self.data_hbs = calcHydrogenBondsTrajectory(self.ATOMS) - np.save('test_2k39_hbs.npy', np.array(self.data_hbs, dtype=object), allow_pickle=True) - - self.data_sbs = calcSaltBridgesTrajectory(self.ATOMS) - np.save('test_2k39_sbs.npy', np.array(self.data_sbs, dtype=object), allow_pickle=True) - - self.data_rib = calcRepulsiveIonicBondingTrajectory(self.ATOMS) - np.save('test_2k39_rib.npy', np.array(self.data_rib, dtype=object), allow_pickle=True) - - self.data_PiStack = calcPiStackingTrajectory(self.ATOMS) - np.save('test_2k39_PiStack.npy', np.array(self.data_PiStack, dtype=object), allow_pickle=True) - self.data_PiCat = calcPiCationTrajectory(self.ATOMS) - np.save('test_2k39_PiCat.npy', np.array(self.data_PiCat, dtype=object), allow_pickle=True) + def testAllInteractionsCalc(self): + """Test for calculating all types of interactions.""" - self.data_hph = calcHydrophobicTrajectory(self.ATOMS) - np.save('test_2k39_hph.npy', np.array(self.data_hph, dtype=object), allow_pickle=True) + if prody.PY3K: + self.INTERACTIONS_ALL = InteractionsTrajectory() + self.data_all = self.INTERACTIONS_ALL.calcProteinInteractionsTrajectory(self.ATOMS) - self.data_disu = calcDisulfideBondsTrajectory(self.ATOMS) - np.save('test_2k39_disu.npy', np.array(self.data_disu, dtype=object), allow_pickle=True) + try: + assert_equal(self.data_all, self.ALL_INTERACTIONS2, + 'failed to get correct interactions without hpb.so from calculation') + except AssertionError: + assert_equal(self.data_all, self.ALL_INTERACTIONS, + 'failed to get correct interactions with hpb.so from calculation') + + def testAllInteractionsSave(self): + """Test for saving and loading all types of interactions.""" + if prody.PY3K: + self.INTERACTIONS_ALL = InteractionsTrajectory() + self.data_all = self.INTERACTIONS_ALL.calcProteinInteractionsTrajectory(self.ATOMS) - def testAllInsteractions(self): - """Test for all types of interactions.""" + np.save('test_2k39_all.npy', np.array(self.data_all, dtype=object), allow_pickle=True) - if prody.PY3K: data_test = np.load('test_2k39_all.npy', allow_pickle=True) try: assert_equal(data_test, self.ALL_INTERACTIONS2, - 'failed to get correct interactions without hpb.so') - except: + 'failed to get correct interactions without hpb.so from saving and loading') + except AssertionError: assert_equal(data_test, self.ALL_INTERACTIONS, - 'failed to get correct interactions with hpb.so') + 'failed to get correct interactions with hpb.so from saving and loading') def testHydrogenBonds(self): """Test for hydrogen bonds. @@ -74,23 +67,37 @@ def testHydrogenBonds(self): order can be also different in the interactions""" if prody.PY3K: - data_test = np.load('test_2k39_hbs.npy', allow_pickle=True) + data_test = calcHydrogenBondsTrajectory(self.ATOMS) assert_equal(sorted([i[-1][-1] for i in data_test]), sorted([i[-1][-1] for i in self.HBS_INTERACTIONS]), 'failed to get correct hydrogen bonds') - def testSaltBridges(self): - """Test for salt bridges.""" + def testSaltBridgesCalc(self): + """Test for salt bridges without saving and loading.""" if prody.PY3K: + self.data_sbs = calcSaltBridgesTrajectory(self.ATOMS) + assert_equal(sorted([i[-1][-1] for i in self.data_sbs]), sorted([i[-1][-1] for i in self.SBS_INTERACTIONS]), + 'failed to get correct salt bridges') + + + def testSaltBridgesSave(self): + """Test for salt bridges with saving and loading (one type with results).""" + + if prody.PY3K: + self.data_sbs = calcSaltBridgesTrajectory(self.ATOMS) + + np.save('test_2k39_sbs.npy', np.array(self.data_sbs, dtype=object), allow_pickle=True) + data_test = np.load('test_2k39_sbs.npy', allow_pickle=True) - assert_equal(sorted([i[-1][-1] for i in data_test]), sorted([i[-1][-1] for i in self.SBS_INTERACTIONS]), - 'failed to get correct salt bridges') + assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.SBS_INTERACTIONS if i]), + 'failed to get correct salt bridges from saving and loading') + def testRepulsiveIonicBonding(self): """Test for repulsive ionic bonding.""" if prody.PY3K: - data_test = np.load('test_2k39_rib.npy', allow_pickle=True) + data_test = calcRepulsiveIonicBondingTrajectory(self.ATOMS) assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.RIB_INTERACTIONS if i]), 'failed to get correct repulsive ionic bonding') @@ -98,7 +105,7 @@ def testPiStacking(self): """Test for pi-stacking interactions.""" if prody.PY3K: - data_test = np.load('test_2k39_PiStack.npy', allow_pickle=True) + data_test = calcPiStackingTrajectory(self.ATOMS) assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.PISTACK_INTERACTIONS if i]), 'failed to get correct pi-stacking interactions') @@ -106,7 +113,7 @@ def testPiCation(self): """Test for pi-stacking interactions.""" if prody.PY3K: - data_test = np.load('test_2k39_PiCat.npy', allow_pickle=True) + data_test = calcPiCationTrajectory(self.ATOMS) assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.PICAT_INTERACTIONS if i]), 'failed to get correct pi-cation interactions') @@ -115,21 +122,31 @@ def testHydrophobicInteractions(self): """Test for hydrophobic interactions.""" if prody.PY3K: - data_test = np.load('test_2k39_hph.npy', allow_pickle=True) + data_test = calcHydrophobicTrajectory(self.ATOMS) try: assert_equal(sorted([i[-1][-1] for i in data_test]), sorted([i[-1][-1] for i in self.HPH_INTERACTIONS2]), 'failed to get correct hydrophobic interactions without hpb.so') - except: + except AssertionError: assert_equal(sorted([i[-1][-1] for i in data_test]), sorted([i[-1][-1] for i in self.HPH_INTERACTIONS]), 'failed to get correct hydrophobic interactions with hpb.so') - def testDisulfideBonds(self): - """Test for disulfide bonds interactions.""" - - if prody.PY3K: - data_test = np.load('test_2k39_disu.npy', allow_pickle=True) - assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if i]), - 'failed to get correct disulfide bonds') + def testDisulfideBondsCalc(self): + """Test for disulfide bonds interactions without saving and loading.""" + if prody.PY3K: + data_test = calcDisulfideBondsTrajectory(self.ATOMS) + assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if i]), + 'failed to get correct disulfide bonds from calculation') - + def testDisulfideBondsSave(self): + """Test for disulfide bonds interactions with saving and loading (one type of interactions with 0).""" + if prody.PY3K: + data_test = calcDisulfideBondsTrajectory(self.ATOMS) + assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if i]), + 'failed to get correct disulfide bonds from calculation') + + np.save('test_2k39_disu.npy', np.array(data_test, dtype=object), allow_pickle=True) + + data_test = np.load('test_2k39_disu.npy', allow_pickle=True) + assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if i]), + 'failed to get correct disulfide bonds from saving and loading') From f8cca17a7832e8ed93ad502025e7aa64b0a3fa37 Mon Sep 17 00:00:00 2001 From: James Krieger Date: Thu, 22 Aug 2024 20:24:17 +0200 Subject: [PATCH 2/6] remove insty test outputs --- prody/tests/proteins/test_insty.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/prody/tests/proteins/test_insty.py b/prody/tests/proteins/test_insty.py index 1a2dfa46b..5e518badf 100644 --- a/prody/tests/proteins/test_insty.py +++ b/prody/tests/proteins/test_insty.py @@ -150,3 +150,10 @@ def testDisulfideBondsSave(self): data_test = np.load('test_2k39_disu.npy', allow_pickle=True) assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if i]), 'failed to get correct disulfide bonds from saving and loading') + + @classmethod + def tearDownClass(cls): + if prody.PY3K: + import os + for filename in ['test_2k39_all.npy', 'test_2k39_sbs.npy', 'test_2k39_disu.npy']: + os.remove(filename) From 0c6e55e2cb9b99ba7c16612223d887dd84063bd0 Mon Sep 17 00:00:00 2001 From: James Krieger Date: Mon, 30 Sep 2024 15:44:07 +0200 Subject: [PATCH 3/6] update getDataPath to importlib --- prody/utilities/misctools.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/prody/utilities/misctools.py b/prody/utilities/misctools.py index 5dd0c92fc..af7446802 100644 --- a/prody/utilities/misctools.py +++ b/prody/utilities/misctools.py @@ -422,8 +422,9 @@ def pystr(a): return b def getDataPath(filename): - import pkg_resources - return pkg_resources.resource_filename('prody.utilities', 'datafiles/%s'%filename) + import importlib + path = importlib.util.find_spec('prody.utilities.datafiles').submodule_search_locations[0] + return '%s/%s' %(path, filename) def openData(filename, mode='r'): return open(getDataPath(filename), mode) From e0edf04be3ea9db97f88a94a91a7faa5632fee17 Mon Sep 17 00:00:00 2001 From: James Krieger Date: Mon, 30 Sep 2024 15:50:48 +0200 Subject: [PATCH 4/6] more stable test for non empty lists --- prody/tests/proteins/test_insty.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/prody/tests/proteins/test_insty.py b/prody/tests/proteins/test_insty.py index d637fab73..305f69fa6 100644 --- a/prody/tests/proteins/test_insty.py +++ b/prody/tests/proteins/test_insty.py @@ -1,7 +1,6 @@ """This module contains unit tests for :mod:`~prody.proteins.interactions`.""" import numpy as np -from numpy import arange from prody import * from prody.tests import unittest from prody.tests.datafiles import * @@ -91,7 +90,7 @@ def testSaltBridgesSave(self): np.save('test_2k39_sbs.npy', np.array(self.data_sbs, dtype=object), allow_pickle=True) data_test = np.load('test_2k39_sbs.npy', allow_pickle=True) - assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.SBS_INTERACTIONS if i]), + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.SBS_INTERACTIONS if len(i) > 0]), 'failed to get correct salt bridges from saving and loading') @@ -100,7 +99,7 @@ def testRepulsiveIonicBonding(self): if prody.PY3K: data_test = calcRepulsiveIonicBondingTrajectory(self.ATOMS) - assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.RIB_INTERACTIONS if i]), + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.RIB_INTERACTIONS if len(i) > 0]), 'failed to get correct repulsive ionic bonding') def testPiStacking(self): @@ -108,7 +107,7 @@ def testPiStacking(self): if prody.PY3K: data_test = calcPiStackingTrajectory(self.ATOMS) - assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.PISTACK_INTERACTIONS if i]), + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.PISTACK_INTERACTIONS if len(i) > 0]), 'failed to get correct pi-stacking interactions') def testPiCation(self): @@ -116,7 +115,7 @@ def testPiCation(self): if prody.PY3K: data_test = calcPiCationTrajectory(self.ATOMS) - assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.PICAT_INTERACTIONS if i]), + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.PICAT_INTERACTIONS if len(i) > 0]), 'failed to get correct pi-cation interactions') @@ -137,20 +136,20 @@ def testDisulfideBondsCalc(self): """Test for disulfide bonds interactions without saving and loading.""" if prody.PY3K: data_test = calcDisulfideBondsTrajectory(self.ATOMS) - assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if i]), + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if len(i) > 0]), 'failed to get correct disulfide bonds from calculation') def testDisulfideBondsSave(self): """Test for disulfide bonds interactions with saving and loading (one type of interactions with 0).""" if prody.PY3K: data_test = calcDisulfideBondsTrajectory(self.ATOMS) - assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if i]), + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if len(i) > 0]), 'failed to get correct disulfide bonds from calculation') np.save('test_2k39_disu.npy', np.array(data_test, dtype=object), allow_pickle=True) data_test = np.load('test_2k39_disu.npy', allow_pickle=True) - assert_equal(sorted([i[-1][-1] for i in data_test if i]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if i]), + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if len(i) > 0]), 'failed to get correct disulfide bonds from saving and loading') def testImportHpb(self): From c674ed493c5c783dd229734ec647943e26bbdc16 Mon Sep 17 00:00:00 2001 From: James Krieger Date: Mon, 30 Sep 2024 15:52:41 +0200 Subject: [PATCH 5/6] keep python 2 getDataPath --- prody/utilities/misctools.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/prody/utilities/misctools.py b/prody/utilities/misctools.py index af7446802..63a006c85 100644 --- a/prody/utilities/misctools.py +++ b/prody/utilities/misctools.py @@ -422,9 +422,12 @@ def pystr(a): return b def getDataPath(filename): - import importlib - path = importlib.util.find_spec('prody.utilities.datafiles').submodule_search_locations[0] - return '%s/%s' %(path, filename) + if PY3K: + import importlib + path = importlib.util.find_spec('prody.utilities.datafiles').submodule_search_locations[0] + return '%s/%s' %(path, filename) + import pkg_resources + return pkg_resources.resource_filename('prody.utilities', 'datafiles/%s'%filename) def openData(filename, mode='r'): return open(getDataPath(filename), mode) From f4ac2086159af3422cabee13a4bb315ddfd774a9 Mon Sep 17 00:00:00 2001 From: James Krieger Date: Mon, 30 Sep 2024 16:14:29 +0200 Subject: [PATCH 6/6] add 3o21 disu test --- prody/tests/datafiles/3o21_disu.npy | Bin 0 -> 1028 bytes prody/tests/datafiles/__init__.py | 5 ++- prody/tests/proteins/test_insty.py | 49 ++++++++++++++++++++-------- 3 files changed, 40 insertions(+), 14 deletions(-) create mode 100644 prody/tests/datafiles/3o21_disu.npy diff --git a/prody/tests/datafiles/3o21_disu.npy b/prody/tests/datafiles/3o21_disu.npy new file mode 100644 index 0000000000000000000000000000000000000000..3f132d62e88f0a2661a9edbcd11e2ee3fb26296e GIT binary patch literal 1028 zcmbV}T~E_c0ERop$Ee?;h@VUpH*^lRwW9-cgCSMQHaKHiVhriFnwgAkZ&yqRm>7vg zu8p@Q-Wc!v3nX59qsCu=f500r^&DoClO^7GE}EW?JkN95*V#g5am6D%6*dE9vstnN z6aK(fE)enu9@j0~GHR=Jt8B96IiuP%>3XwbG)y`VN+G{867oOu|Nju5drP(TwZ=xc zRJY9V+IrP~Vpx{3A+B0xsa|W^)_TbnA+%13wQ_409!+?Oj(qP> zy8j+6+Zzp2M33Gf2trPQZ}-&>dI`j!=G8rPZ3~C8+3fspIu0IM(#GN9?jsxt>Rog{ zy^@c|a8&Q1?|F4KE+xir>>stwl2J7*5yvYnUm=1M%y*KY&-G2=6!p`UvW4ZRrt1EAmzLjV8( literal 0 HcmV?d00001 diff --git a/prody/tests/datafiles/__init__.py b/prody/tests/datafiles/__init__.py index 54f7c00de..8de8f0955 100644 --- a/prody/tests/datafiles/__init__.py +++ b/prody/tests/datafiles/__init__.py @@ -358,7 +358,10 @@ }, '2k39_disu': { 'file': '2k39_disu.npy' - }, + }, + '3o21_disu': { + 'file': '3o21_disu.npy' + }, '2k39_all': { 'file': '2k39_all.npy' }, diff --git a/prody/tests/proteins/test_insty.py b/prody/tests/proteins/test_insty.py index 305f69fa6..247710413 100644 --- a/prody/tests/proteins/test_insty.py +++ b/prody/tests/proteins/test_insty.py @@ -19,7 +19,7 @@ def setUp(self): """Generating new data to compare it with the existing one""" if prody.PY3K: - self.ATOMS = parseDatafile('2k39_insty') + self.ATOMS = parseDatafile('2k39_insty') # no disulfides self.ALL_INTERACTIONS = parseDatafile('2k39_all') self.ALL_INTERACTIONS2 = parseDatafile('2k39_all2') self.HBS_INTERACTIONS = parseDatafile('2k39_hbs') @@ -31,6 +31,9 @@ def setUp(self): self.HPH_INTERACTIONS2 = parseDatafile('2k39_hph2') self.DISU_INTERACTIONS = parseDatafile('2k39_disu') + self.ATOMS_3O21 = parseDatafile('3o21') # has disulfides & not traj + self.DISU_INTERACTIONS_3O21 = parseDatafile('3o21_disu') + def testAllInteractionsCalc(self): """Test for calculating all types of interactions.""" @@ -132,26 +135,46 @@ def testHydrophobicInteractions(self): 'failed to get correct hydrophobic interactions with hpb.so') - def testDisulfideBondsCalc(self): + def testDisulfideBondsCalcNone(self): """Test for disulfide bonds interactions without saving and loading.""" if prody.PY3K: data_test = calcDisulfideBondsTrajectory(self.ATOMS) - assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if len(i) > 0]), - 'failed to get correct disulfide bonds from calculation') - - def testDisulfideBondsSave(self): + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), + sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if len(i) > 0]), + 'failed to get correct disulfide bonds from 2k39 (None) from calculation') + + def testDisulfideBondsSaveNone(self): """Test for disulfide bonds interactions with saving and loading (one type of interactions with 0).""" if prody.PY3K: data_test = calcDisulfideBondsTrajectory(self.ATOMS) - assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if len(i) > 0]), - 'failed to get correct disulfide bonds from calculation') - - np.save('test_2k39_disu.npy', np.array(data_test, dtype=object), allow_pickle=True) + np.save('test_2k39_disu.npy', np.array(data_test, dtype=object), + allow_pickle=True) data_test = np.load('test_2k39_disu.npy', allow_pickle=True) - assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if len(i) > 0]), - 'failed to get correct disulfide bonds from saving and loading') - + assert_equal(sorted([i[-1][-1] for i in data_test if len(i) > 0]), + sorted([i[-1][-1] for i in self.DISU_INTERACTIONS if len(i) > 0]), + 'failed to get correct disulfide bonds from 2k39 (None) from saving and loading') + + def testDisulfideBondsCalcSomeNotTraj(self): + """Test for disulfide bonds interactions without saving and loading.""" + if prody.PY3K: + data_test = calcDisulfideBonds(self.ATOMS_3O21) + assert_equal(sorted([i[-1] for i in data_test if len(i) > 0]), + sorted([i[-1] for i in self.DISU_INTERACTIONS_3O21 if len(i) > 0]), + 'failed to get correct disulfide bonds from 3o21 from calculation') + + def testDisulfideBondsSaveSomeNotTraj(self): + """Test for disulfide bonds interactions with saving and loading (one type of interactions with 0).""" + if prody.PY3K: + data_test = calcDisulfideBonds(self.ATOMS_3O21) + np.save('test_3o21_disu.npy', np.array(data_test, dtype=object), + allow_pickle=True) + + data_test = np.load('test_3o21_disu.npy', allow_pickle=True) + assert_equal(sorted([i[-1] for i in data_test if len(i) > 0]), + sorted([i[-1] for i in self.DISU_INTERACTIONS_3O21 if len(i) > 0]), + 'failed to get correct disulfide bonds from 3o21 from saving and loading') + def testImportHpb(self): try: