Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better insty tests #1944

Merged
merged 9 commits into from
Nov 24, 2024
Binary file added prody/tests/datafiles/3o21_disu.npy
Binary file not shown.
5 changes: 4 additions & 1 deletion prody/tests/datafiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@
},
'2k39_disu': {
'file': '2k39_disu.npy'
},
},
'3o21_disu': {
'file': '3o21_disu.npy'
},
'2k39_all': {
'file': '2k39_all.npy'
},
Expand Down
143 changes: 91 additions & 52 deletions prody/tests/proteins/test_insty.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand All @@ -20,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')
Expand All @@ -31,109 +30,151 @@ 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.ATOMS_3O21 = parseDatafile('3o21') # has disulfides & not traj
self.DISU_INTERACTIONS_3O21 = parseDatafile('3o21_disu')

self.data_sbs = calcSaltBridgesTrajectory(self.ATOMS)
np.save('test_2k39_sbs.npy', np.array(self.data_sbs, dtype=object), allow_pickle=True)
def testAllInteractionsCalc(self):
"""Test for calculating all types of interactions."""

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)

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 testAllInteractions(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.
Last column is compared becasue pairs of residues can be reversed and
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 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')


def testRepulsiveIonicBonding(self):
"""Test for repulsive ionic bonding."""

if prody.PY3K:
data_test = np.load('test_2k39_rib.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.RIB_INTERACTIONS if i]),
data_test = calcRepulsiveIonicBondingTrajectory(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.RIB_INTERACTIONS if len(i) > 0]),
'failed to get correct repulsive ionic bonding')

def testPiStacking(self):
"""Test for pi-stacking interactions."""

if prody.PY3K:
data_test = np.load('test_2k39_PiStack.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.PISTACK_INTERACTIONS if i]),
data_test = calcPiStackingTrajectory(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.PISTACK_INTERACTIONS if len(i) > 0]),
'failed to get correct pi-stacking interactions')

def testPiCation(self):
"""Test for pi-stacking interactions."""

if prody.PY3K:
data_test = np.load('test_2k39_PiCat.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.PICAT_INTERACTIONS if i]),
data_test = calcPiCationTrajectory(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.PICAT_INTERACTIONS if len(i) > 0]),
'failed to get correct pi-cation interactions')


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."""
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 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)
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 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')

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 testImportHpb(self):

try:
Expand All @@ -155,7 +196,5 @@ def testImportHpb(self):
def tearDownClass(cls):
if prody.PY3K:
import os
for filename in ['test_2k39_all.npy', 'test_2k39_hbs.npy', 'test_2k39_sbs.npy',
'test_2k39_rib.npy', 'test_2k39_PiStack.npy', 'test_2k39_PiCat.npy',
'test_2k39_hph.npy', 'test_2k39_disu.npy']:
for filename in ['test_2k39_all.npy', 'test_2k39_sbs.npy', 'test_2k39_disu.npy']:
os.remove(filename)
6 changes: 5 additions & 1 deletion prody/utilities/misctools.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,12 @@ def pystr(a):
return b

def getDataPath(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)
return pkg_resources.resource_filename('prody.utilities', 'datafiles/%s'%filename)

def openData(filename, mode='r'):
return open(getDataPath(filename), mode)
Expand Down
Loading