def test_remove_reaction_duplicates_V_shape(self):
     N = np.array([[1, 2, 0, -1],
                   [0, 0, 1, 0],
                   [-2, -4, -1, 2]])
     V = np.array([[-1, 0],
                   [1, 1],
                   [0, -1],
                   [2, -1]])
     r_id2i = {'r1': 0, 'r2': 1, 'r3': 2, 'r4': 3}
     r_duplicates = get_reaction_duplicates(N, r_id2i)
     N_new, V_new, new_r_id2i, r_id2gr_id, _ = remove_reaction_duplicates(N, V, r_duplicates, r_id2i)
     self.assertTupleEqual((2, 2), V_new.shape,
                           'Was supposed to get 2x2 V, got %s' % [str(it) for it in V_new.shape])
 def test_remove_reaction_duplicates_NV(self):
     N = np.array([[1, 2, 0, -1],
                   [0, 0, 1, 0],
                   [-2, -4, -1, 2]])
     V = np.array([[-1, 0],
                   [1, 1],
                   [0, -1],
                   [2, -1]])
     r_id2i = {'r1': 0, 'r2': 1, 'r3': 2, 'r4': 3}
     r_duplicates = get_reaction_duplicates(N, r_id2i)
     N_new, V_new, new_r_id2i, r_id2gr_id, _ = remove_reaction_duplicates(N, V, r_duplicates, r_id2i)
     NV = np.dot(N, V)
     NV_new = np.dot(N_new, V_new)
     self.assertListEqual(list(NV.flatten()), list(NV_new.flatten()), 'NV was not supposed to change')
 def test_remove_reaction_duplicates_N_content_1(self):
     N = np.array([[1, 2, 0, -1],
                   [0, 0, 1, 0],
                   [-2, -4, -1, 2]])
     V = np.array([[-1, 0],
                   [1, 1],
                   [0, -1],
                   [2, -1]])
     r_id2i = {'r1': 0, 'r2': 1, 'r3': 2, 'r4': 3}
     r_duplicates = get_reaction_duplicates(N, r_id2i)
     N_new, V_new, new_r_id2i, r_id2gr_id, _ = remove_reaction_duplicates(N, V, r_duplicates, r_id2i)
     m2_st = N[1, new_r_id2i[r_id2gr_id['r1']]]
     self.assertEqual(0, m2_st,
                      'Was supposed to find no metabolite m2 in the grouped reaction, found %g' % m2_st)
 def test_remove_reaction_duplicates_N_content_2(self):
     N = np.array([[1, 2, 0, -1],
                   [0, 0, 1, 0],
                   [-2, -4, -1, 2]])
     V = np.array([[-1, 0],
                   [1, 1],
                   [0, -1],
                   [2, -1]])
     r_id2i = {'r1': 0, 'r2': 1, 'r3': 2, 'r4': 3}
     r_duplicates = get_reaction_duplicates(N, r_id2i)
     N_new, V_new, new_r_id2i, r_id2gr_id, _ = remove_reaction_duplicates(N, V, r_duplicates, r_id2i)
     new_r_index = new_r_id2i[r_id2gr_id['r1']]
     m1_st = N[0, new_r_index]
     m3_st = N[2, new_r_index]
     self.assertEqual(-2, m3_st / m1_st,
                      'Was supposed to get -2 as a proportion between m3 and m1 in the new reaction, found %g'
                      % (m3_st / m1_st))
 def test_remove_reaction_duplicates_V_content(self):
     N = np.array([[1, 2, 0, -1],
                   [0, 0, 1, 0],
                   [-2, -4, -1, 2]])
     V = np.array([[-1, 0],
                   [1, 1],
                   [0, -1],
                   [2, -1]])
     r_id2i = {'r1': 0, 'r2': 1, 'r3': 2, 'r4': 3}
     r_duplicates = get_reaction_duplicates(N, r_id2i)
     N_new, V_new, new_r_id2i, r_id2gr_id, _ = remove_reaction_duplicates(N, V, r_duplicates, r_id2i)
     new_r_index = new_r_id2i[r_id2gr_id['r1']]
     efm1_c = V_new[new_r_index, 0]
     efm2_c = V_new[new_r_index, 1]
     ratio = efm2_c / efm1_c
     self.assertEqual(-3, ratio,
                      'Was supposed to get -3 as a ratio between the coefficients of the grouped reaction in EFMs 2 and 1, got %g'
                      % ratio)