Exemplo n.º 1
0
    def setUp(self):
        self._database = DictDatabase()
        self._database.set_reaction('rxn_1', parse_reaction('A[e] => B[e]'))
        self._database.set_reaction('rxn_2', parse_reaction('B[e] => C[e]'))
        self._database.set_reaction('rxn_3', parse_reaction('B[e] => D[e]'))
        self._database.set_reaction('rxn_4', parse_reaction('C[e] => E[e]'))
        self._database.set_reaction('rxn_5', parse_reaction('D[e] => E[e]'))
        self._database.set_reaction('rxn_6', parse_reaction('E[e] =>'))
        self._database.set_reaction('ex_A', parse_reaction('A[e] <=>'))

        self._mm = MetabolicModel.load_model(self._database,
                                             self._database.reactions)
        self._assoc = {
            'rxn_1': boolean.Expression('gene_1'),
            'rxn_2': boolean.Expression('gene_2 or gene_3'),
            'rxn_5': boolean.Expression('gene_3 and gene_4')
        }
        self._obj_reaction = 'rxn_6'

        try:
            self._solver = generic.Solver()
        except generic.RequirementsError:
            self.skipTest('Unable to find an LP solver for tests')

        self._prob = fluxanalysis.FluxBalanceProblem(self._mm, self._solver)
Exemplo n.º 2
0
 def test_flux_balance_object_max_min_l1_multiple(self):
     p = fluxanalysis.FluxBalanceProblem(self.model, self.solver)
     p.max_min_l1({'rxn_3': 1, 'rxn_4': 1, 'rxn_5': 1})
     self.assertAlmostEqual(p.get_flux('rxn_1'), 500)
     self.assertAlmostEqual(p.get_flux('rxn_2'), 0)
     self.assertAlmostEqual(p.get_flux('rxn_3'), 0)
     self.assertAlmostEqual(p.get_flux('rxn_4'), 1000)
     self.assertAlmostEqual(p.get_flux('rxn_5'), 1000)
     self.assertAlmostEqual(p.get_flux('rxn_6'), 1000)
Exemplo n.º 3
0
 def test_flux_balance_object_minimize_l1(self):
     p = fluxanalysis.FluxBalanceProblem(self.model, self.solver)
     p.prob.add_linear_constraints(p.get_flux_var('rxn_6') == 1000)
     p.minimize_l1()
     self.assertAlmostEqual(p.get_flux('rxn_1'), 500)
     self.assertAlmostEqual(p.get_flux('rxn_2'), 0)
     self.assertAlmostEqual(p.get_flux('rxn_3'), 1000)
     self.assertAlmostEqual(p.get_flux('rxn_4'), 0)
     self.assertAlmostEqual(p.get_flux('rxn_5'), 0)
     self.assertAlmostEqual(p.get_flux('rxn_6'), 1000)
Exemplo n.º 4
0
    def test_flux_balance_infeasible(self):
        self.model.limits['rxn_6'].lower = 500
        self.model.limits['rxn_1'].upper = 10
        p = fluxanalysis.FluxBalanceProblem(self.model, self.solver)

        try:
            p.maximize('rxn_6')
        except fluxanalysis.FluxBalanceError as e:
            self.assertFalse(e.result.unbounded)
        else:
            self.fail('FluxBalanceError was not raised!')
Exemplo n.º 5
0
 def test_gimme_model(self):
     f = ['gene\texpression', 'gene_1\t15', 'gene_2\t20',
          'gene_3\t15', 'gene_4\t25', 'gene_5\t10', 'gene_6\t25']
     threshold_dict = gimme.parse_transcriptome_file(f, 20)
     mm_irreversible, reversible_gene_assoc, split_rxns = \
         gimme.make_irreversible(self._mm, self._assoc,
         exclude_list=['ex_A', 'rxn_6'])
     p = fluxanalysis.FluxBalanceProblem(mm_irreversible, generic.Solver())
     final_model, used_exchange, below_threshold_ids, incon_score = \
         gimme.solve_gimme_problem(p, mm_irreversible, 'rxn_6',
         reversible_gene_assoc, split_rxns, threshold_dict, MaybeRelative(20))
     self.assertEqual(incon_score, 100)
     self.assertEqual(final_model, set(['rxn_1', 'rxn_2', 'rxn_4']))
     self.assertEqual(below_threshold_ids, set(['rxn_1', 'rxn_3', 'rxn_5']))
Exemplo n.º 6
0
    def test_flux_balance_object_max_min_l1(self):
        p = fluxanalysis.FluxBalanceProblem(self.model, self.solver)
        p.max_min_l1('rxn_6')
        self.assertAlmostEqual(p.get_flux('rxn_1'), 500)
        self.assertAlmostEqual(p.get_flux('rxn_2'), 0)
        self.assertAlmostEqual(p.get_flux('rxn_3'), 1000)
        self.assertAlmostEqual(p.get_flux('rxn_4'), 0)
        self.assertAlmostEqual(p.get_flux('rxn_5'), 0)
        self.assertAlmostEqual(p.get_flux('rxn_6'), 1000)

        # The temporary constraint on the reaction rxn_6 should go away. If
        # not, the next maximize will raise a FluxBalanceError.
        p.prob.add_linear_constraints(p.get_flux_var('rxn_1') == 10)
        p.maximize('rxn_6')
        self.assertAlmostEqual(p.get_flux('rxn_6'), 20)
Exemplo n.º 7
0
    def test_flux_balance_unbounded(self):
        unbounded = float('-inf'), float('inf')
        self.model.limits['rxn_1'].bounds = unbounded
        self.model.limits['rxn_3'].bounds = unbounded
        self.model.limits['rxn_6'].bounds = unbounded
        p = fluxanalysis.FluxBalanceProblem(self.model, self.solver)

        if self.solver.properties['name'] == 'qsoptex':
            # QSopt_ex returns status code 100 for this example. It seems that
            # it is unable to determine whether the problem is unbounded.
            self.skipTest('Skipping because of known issue with QSopt_ex')

        try:
            p.maximize('rxn_6')
        except fluxanalysis.FluxBalanceError as e:
            self.assertTrue(e.result.unbounded)
        else:
            self.fail('FluxBalanceError was not raised!')
Exemplo n.º 8
0
def gene_deletion(model, mm, solver):
    genes = {}
    gene_assoc = {}
    for reaction in model.parse_reactions():
        if reaction.genes is None:
            continue
        expr = boolean.Expression(reaction.genes)
        gene_assoc[reaction.id] = expr
        for var in expr.variables:
            genes.setdefault(var.symbol, set()).add(reaction.id)

    p = fluxanalysis.FluxBalanceProblem(mm, solver)
    biomass = model.get_biomass_reaction()

    p.maximize(biomass)
    wt_biomass = p.get_flux(biomass)
    #print('Wildtype biomass: {}'.format(wt_biomass))

    for gene, reactions in iteritems(genes):
        #print('Deleting {}...'.format(gene))

        deleted_reactions = set()
        for reaction in reactions:
            e = gene_assoc[reaction].substitute(lambda v: False
                                                if v.symbol == gene else v)
            if e.has_value() and not e.value:
                deleted_reactions.add(reaction)

        constr = []
        for reaction in deleted_reactions:
            constr.extend(
                p.prob.add_linear_constraints(p.get_flux_var(reaction) == 0))

        try:
            p.maximize(biomass)
            yield gene, p.get_flux(biomass) / wt_biomass
        except fluxanalysis.FluxBalanceError:
            yield gene, 0.0
        finally:
            for c in constr:
                c.delete()
Exemplo n.º 9
0
 def test_flux_balance_object_maximize(self):
     p = fluxanalysis.FluxBalanceProblem(self.model, self.solver)
     p.maximize('rxn_6')
     self.assertAlmostEqual(p.get_flux('rxn_1'), 500)
     self.assertAlmostEqual(p.get_flux('rxn_2'), 0)
     self.assertAlmostEqual(p.get_flux('rxn_6'), 1000)