def test_lump_coupled_reactions_NV(self):
     N = model2stoichiometric_matrix(self.model, self.s_id2i, self.r_id2i)
     V = get_efm_matrix([{'r1': 10, 'r2': 10, 'r3': 10}, {'r1': 1, 'r3': 1, 'r4': 1, 'r6': 1}], self.r_id2i)
     NV = np.dot(N, V)
     coupled_r_id_groups = get_coupled_reactions(V, self.r_id2i)
     N_new, V_new, new_r_id2i, r_id2lr_id, _ = lump_coupled_reactions(N, V, coupled_r_id_groups, self.r_id2i)
     NV_new = np.dot(N_new, V_new)
     self.assertListEqual(list(NV.flatten()), list(NV_new.flatten()), 'NV should not have changed')
 def test_lump_coupled_reactions_N_2(self):
     N = model2stoichiometric_matrix(self.model, self.s_id2i, self.r_id2i)
     V = get_efm_matrix([{'r1': 10, 'r2': 10, 'r3': 10}, {'r1': 1, 'r3': 1, 'r4': 1, 'r6': 1}], self.r_id2i)
     coupled_r_id_groups = get_coupled_reactions(V, self.r_id2i)
     N_new, V_new, new_r_id2i, r_id2lr_id, _ = lump_coupled_reactions(N, V, coupled_r_id_groups, self.r_id2i)
     lr_id = next(r_id2lr_id.values())
     st = N_new[self.s_id2i['m2_b'], new_r_id2i[lr_id]]
     self.assertEqual(1, st, 'The lumped reaction was supposed to produce 1 m2_b, consumes %g instead' % -st)
 def test_lump_coupled_reactions_V(self):
     N = model2stoichiometric_matrix(self.model, self.s_id2i, self.r_id2i)
     V = get_efm_matrix([{'r1': 10, 'r2': 10, 'r3': 10}, {'r1': 1, 'r3': 1, 'r4': 1, 'r6': 1}], self.r_id2i)
     coupled_r_id_groups = get_coupled_reactions(V, self.r_id2i)
     N_new, V_new, new_r_id2i, r_id2lr_id, _ = lump_coupled_reactions(N, V, coupled_r_id_groups, self.r_id2i)
     lr_id = next(r_id2lr_id.values())
     r_i = V_new[new_r_id2i[lr_id], :]
     self.assertListEqual([10, 1], list(r_i),
                          'The lumped reaction was supposed to participate in EFMs with coefficients [10, 1] not %s'
                          % r_i)
Beispiel #4
0
    def lump_coupled_reactions(self):
        coupled_r_id_groups = get_coupled_reactions(self.V, self.r_id2i)
        lr_i = 0
        for r_ids in coupled_r_id_groups:
            lumped_r_id, lr_i = get_unique_id(self.r_id2i, 'coupled_r', lr_i)
            self.coupled_rs.add(lumped_r_id)
            self.r_id2gr_id.update({r_id: lumped_r_id for r_id in r_ids})
            self.r_id2i[lumped_r_id] = self.V.shape[0]

            sample_r_index = self.r_id2i[r_ids[0]]
            sample_efm_index = np.nonzero(self.V[sample_r_index, :])[0][0]
            sample_efm = self.V[:, sample_efm_index]
            c = abs(sample_efm[sample_r_index]) * 1.0
            sign = coefficient_to_binary(sample_efm[sample_r_index])
            self.gr_id2r_id2c[lumped_r_id] = {r_id: sample_efm[self.r_id2i[r_id]] / c for r_id in r_ids}
            lambdas = np.array([[self.gr_id2r_id2c[lumped_r_id][r_id]] for r_id in r_ids])
            r_new = np.dot(self.N[:, tuple((self.r_id2i[r_id] for r_id in r_ids))], lambdas)
            replace_zeros(r_new)
            self.N = np.concatenate((self.N, r_new), axis=1)
            self.V = np.concatenate((self.V, [self.V[sample_r_index, :] * sign]), axis=0)

            self.r_ids -= set(r_ids)
            self.r_ids.add(lumped_r_id)
 def test_coupled_reactions_content(self):
     V = get_efm_matrix([{'r1': 10, 'r2': 10, 'r3': 10}, {'r1': 10, 'r3': 10, 'r4': 10, 'r6': 10}], self.r_id2i)
     coupled_r_id_groups = get_coupled_reactions(V, self.r_id2i)
     self.assertIn(['r1', 'r3'], coupled_r_id_groups, 'Was supposed to find [r1, r3] coupled reaction group.')
 def test_coupled_reactions_len(self):
     V = get_efm_matrix([{'r1': 10, 'r2': 10, 'r3': 10}, {'r1': 10, 'r3': 10, 'r4': 10, 'r6': 10}], self.r_id2i)
     c_r_id_lists = get_coupled_reactions(V, self.r_id2i)
     self.assertEqual(1, len(c_r_id_lists),
                      'Was supposed to find one coupled reaction group, got %g instead.' % len(c_r_id_lists))