Skip to content

Commit

Permalink
test cases updated in response to @biochunan's code adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Simkovic committed Jul 25, 2017
1 parent 3f5a805 commit 32e8afc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 4 additions & 2 deletions conkit/core/contactmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,9 +467,11 @@ def calculate_kernel_density(self, bw_method="amise"):
print("The ContactMap is empty!")
return []

# Compute the ranges between each contact pair and store it
# REM: Bug in Sadowski's algorithm, fix in commented line below but untested/not optimized
# REM: Bug in Sadowski's algorithm, res2 is excluded from list to train KDE
# REM: Remember to change test cases when corrected implementation benchmarked
#x = np.asarray([i for c in self for i in np.arange(c.res1_seq, c.res2_seq + 1)])[:, np.newaxis]

# Compute the ranges between each contact pair and store it
x = np.asarray([i for c in self for i in np.arange(c.res1_seq, c.res2_seq)])[:, np.newaxis]
# Compute per-residue points for density extraction
x_fit = np.arange(x.min(), x.max() + 1)[:, np.newaxis]
Expand Down
13 changes: 10 additions & 3 deletions conkit/core/tests/test_contactmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,21 @@ def test_calculate_jaccard_score_4(self):
jindex = contact_map1.calculate_jaccard_index(contact_map2)
self.assertEqual(1.0, jindex)

# REM: Bug in Sadowski res2(+1) error results in tests to fail.
# REM: For now, code reverted by @biochunan to match Sadowski's implementation
# REM: Corresponding results for tests 1-3 are below when code is reverted to correct implementation
# REM: [0.11944664492151888, 0.20124328187327287, 0.23868489948868032, 0.20124328187327284, 0.11944664492151894]
# REM: [0.10012592274179978, 0.19837169506444377, 0.26841488628499205, 0.23132109484153407, 0.1217899243718511]
# REM: [0.14422964774244934, 0.4134215939843202, 0.41342159398432, 0.14422964774244929]

@skipUnless(SKLEARN)
def test_calculate_kernel_density_1(self):
contact_map1 = ContactMap('foo')
for c in [Contact(1, 5, 1.0), Contact(3, 3, 0.4), Contact(2, 4, 0.1)]:
contact_map1.add(c)
density = contact_map1.calculate_kernel_density()
self.assertEqual(
[0.11944664492151888, 0.20124328187327287, 0.23868489948868032, 0.20124328187327284, 0.11944664492151894],
[0.16474084813765252, 0.24964700349773153, 0.24964700349773153, 0.16474084813765252],
density)

@skipUnless(SKLEARN)
Expand All @@ -245,7 +252,7 @@ def test_calculate_kernel_density_2(self):
contact_map1.add(c)
density = contact_map1.calculate_kernel_density()
self.assertEqual(
[0.10012592274179978, 0.19837169506444377, 0.26841488628499205, 0.23132109484153407, 0.1217899243718511],
[0.14936186609839505, 0.26262219502283973, 0.2868154978059642, 0.1768745614827941],
density)

@skipUnless(SKLEARN)
Expand All @@ -254,7 +261,7 @@ def test_calculate_kernel_density_3(self):
for c in [Contact(3, 5, 0.4), Contact(2, 4, 0.1), Contact(3, 4, 0.4)]:
contact_map1.add(c)
density = contact_map1.calculate_kernel_density()
self.assertEqual([0.14422964774244934, 0.4134215939843202, 0.41342159398432, 0.14422964774244929], density)
self.assertEqual([0.2282135747320191, 0.6337372073257503, 0.2282135747320191], density)

def test_find_1(self):
contact_map1 = ContactMap('1')
Expand Down

0 comments on commit 32e8afc

Please sign in to comment.