当前位置: 首页>>代码示例>>Python>>正文


Python DictDatabase.set_reaction方法代码示例

本文整理汇总了Python中psamm.database.DictDatabase.set_reaction方法的典型用法代码示例。如果您正苦于以下问题:Python DictDatabase.set_reaction方法的具体用法?Python DictDatabase.set_reaction怎么用?Python DictDatabase.set_reaction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psamm.database.DictDatabase的用法示例。


在下文中一共展示了DictDatabase.set_reaction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestFastcoreTinyBiomassModel

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestFastcoreTinyBiomassModel(unittest.TestCase):
    """Test fastcore using a model with tiny values in biomass reaction

    This model is consistent mathematically since there is a flux solution
    within the flux bounds. However, the numerical nature of the fastcore
    algorithm requires an epsilon-parameter indicating the minimum flux that
    is considered non-zero. For this reason, some models with reactions where
    tiny stoichiometric values appear can be seen as inconsistent by
    fastcore.

    In this particular model, rxn_2 can take a maximum flux of 1000. At the
    same time rxn_1 will have to take a flux of 1e-4. This is the maximum
    possible flux for rxn_1 so running fastcore with an epsilon larger than
    1e-4 will indicate that the model is not consistent.
    """

    def setUp(self):
        # TODO use mock model instead of actual model
        self.database = DictDatabase()
        self.database.set_reaction("rxn_1", parse_reaction("=> |A|"))
        self.database.set_reaction("rxn_2", parse_reaction("(0.000001) |A| =>"))
        self.model = MetabolicModel.load_model(self.database, self.database.reactions)
        self.solver = cplex.Solver()

    def test_fastcc_is_consistent(self):
        self.assertTrue(fastcore.fastcc_is_consistent(self.model, 0.001, solver=self.solver))

    def test_fastcore_induced_model(self):
        core = {"rxn_2"}
        self.assertEquals(set(fastcore.fastcore(self.model, core, 0.001, solver=self.solver)), {"rxn_1", "rxn_2"})

    def test_fastcore_induced_model_high_epsilon(self):
        core = {"rxn_2"}
        self.assertEquals(set(fastcore.fastcore(self.model, core, 0.1, solver=self.solver)), {"rxn_1", "rxn_2"})
开发者ID:gitter-badger,项目名称:psamm,代码行数:36,代码来源:test_fastcore.py

示例2: TestFluxBalanceThermodynamic

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestFluxBalanceThermodynamic(unittest.TestCase):
    def setUp(self):
        self.database = DictDatabase()
        self.database.set_reaction('ex_A', parse_reaction('|A| <=>'))
        self.database.set_reaction('ex_D', parse_reaction('|D| <=>'))
        self.database.set_reaction('rxn_1', parse_reaction('|A| => |B|'))
        self.database.set_reaction('rxn_2', parse_reaction('|B| <=> |C|'))
        self.database.set_reaction('rxn_3', parse_reaction('|C| <=> |D|'))
        self.database.set_reaction('rxn_4', parse_reaction('|D| <=> |E|'))
        self.database.set_reaction('rxn_5', parse_reaction('|E| => |B|'))

        self.model = MetabolicModel.load_model(
            self.database, self.database.reactions)
        self.model.limits['ex_A'].lower = -10 # Low uptake
        self.model.limits['ex_D'].lower = 0 # No uptake

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

    def test_flux_balance_tfba_exchange_d(self):
        fluxes = dict(fluxanalysis.flux_balance(
            self.model, 'ex_D', tfba=True, solver=self.solver))
        self.assertAlmostEqual(fluxes['ex_A'], -10)
        self.assertAlmostEqual(fluxes['ex_D'], 10)
        self.assertAlmostEqual(fluxes['rxn_2'], 10)
        self.assertAlmostEqual(fluxes['rxn_4'], 0)
        self.assertAlmostEqual(fluxes['rxn_5'], 0)
开发者ID:ForkBackups,项目名称:psamm,代码行数:31,代码来源:test_fluxanalysis.py

示例3: TestMassConsistencyZeroMass

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestMassConsistencyZeroMass(unittest.TestCase):
    """Test mass consistency using a model with zero-mass compound"""

    def setUp(self):
        self.database = DictDatabase()
        self.database.set_reaction('rxn_1', parse_reaction(
            '|A| + |B| => |C|'))
        self.database.set_reaction('rxn_2', parse_reaction(
            '|C| + |Z| => |A| + |B|'))
        self.model = MetabolicModel.load_model(
            self.database, self.database.reactions)

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

    def test_is_consistent_with_zeromass(self):
        consistent = massconsistency.is_consistent(
            self.model, solver=self.solver, zeromass={Compound('Z')})
        self.assertTrue(consistent)

    def test_compound_consistency_with_zeromass(self):
        compounds = dict(massconsistency.check_compound_consistency(
            self.model, solver=self.solver, zeromass={Compound('Z')}))
        for c, value in iteritems(compounds):
            self.assertGreaterEqual(value, 1)

    def test_reaction_consistency_with_zeromass(self):
        reactions, _ = massconsistency.check_reaction_consistency(
            self.model, solver=self.solver, zeromass={Compound('Z')})
        reactions = dict(reactions)

        for r, value in iteritems(reactions):
            self.assertAlmostEqual(value, 0)
开发者ID:keitht547,项目名称:psamm,代码行数:37,代码来源:test_massconsistency.py

示例4: TestFluxBalanceThermodynamic

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestFluxBalanceThermodynamic(unittest.TestCase):
    def setUp(self):
        self.database = DictDatabase()
        self.database.set_reaction('ex_A', parse_reaction('|A| <=>'))
        self.database.set_reaction('ex_D', parse_reaction('|D| <=>'))
        self.database.set_reaction('rxn_1', parse_reaction('|A| => |B|'))
        self.database.set_reaction('rxn_2', parse_reaction('|B| <=> |C|'))
        self.database.set_reaction('rxn_3', parse_reaction('|C| <=> |D|'))
        self.database.set_reaction('rxn_4', parse_reaction('|D| <=> |E|'))
        self.database.set_reaction('rxn_5', parse_reaction('|E| => |B|'))

        self.model = MetabolicModel.load_model(
            self.database, self.database.reactions)
        self.model.limits['ex_A'].lower = -10 # Low uptake
        self.model.limits['ex_D'].lower = 0 # No uptake

        self.solver = cplex.Solver()

    def test_flux_balance_tfba_exchange_d(self):
        fluxes = dict(fluxanalysis.flux_balance(
            self.model, 'ex_D', tfba=True, solver=self.solver))
        self.assertEquals(fluxes['ex_A'], -10)
        self.assertEquals(fluxes['ex_D'], 10)
        self.assertEquals(fluxes['rxn_2'], 10)
        self.assertEquals(fluxes['rxn_4'], 0)
        self.assertEquals(fluxes['rxn_5'], 0)
开发者ID:gitter-badger,项目名称:psamm,代码行数:28,代码来源:test_fluxanalysis.py

示例5: TestMassConsistencyZeroMass

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestMassConsistencyZeroMass(unittest.TestCase):
    """Test mass consistency using a model with zero-mass compound"""

    def setUp(self):
        # TODO use mock model instead of actual model
        self.database = DictDatabase()
        self.database.set_reaction('rxn_1', parse_reaction(
            '|A| + |B| => |C|'))
        self.database.set_reaction('rxn_2', parse_reaction(
            '|C| + |Z| => |A| + |B|'))
        self.model = MetabolicModel.load_model(
            self.database, self.database.reactions)

        self.solver = cplex.Solver()

    def test_is_consistent_with_zeromass(self):
        consistent = massconsistency.is_consistent(
            self.model, solver=self.solver, zeromass={'Z'})
        self.assertTrue(consistent)

    def test_compound_consistency_with_zeromass(self):
        compounds = dict(massconsistency.check_compound_consistency(
            self.model, solver=self.solver, zeromass={'Z'}))
        self.assertEquals(compounds[Compound('Z')], 0)
        for c, value in compounds.iteritems():
            if c.name != 'Z':
                self.assertGreaterEqual(value, 1)

    def test_reaction_consistency_with_zeromass(self):
        reactions, _ = massconsistency.check_reaction_consistency(
            self.model, solver=self.solver, zeromass={'Z'})
        reactions = dict(reactions)

        for r, value in reactions.iteritems():
            self.assertEqual(value, 0)
开发者ID:gitter-badger,项目名称:psamm,代码行数:37,代码来源:test_massconsistency.py

示例6: test_load_model_with_reaction_subset

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
    def test_load_model_with_reaction_subset(self):
        database = DictDatabase()
        database.set_reaction('rxn_1', parse_reaction('|A| => |B|'))
        database.set_reaction('rxn_2', parse_reaction('|B| => |C|'))
        database.set_reaction('rxn_3', parse_reaction('|C| => |D|'))
        model = MetabolicModel.load_model(database, {'rxn_1'})

        self.assertEqual(set(model.reactions), {'rxn_1'})
开发者ID:amenge,项目名称:psamm,代码行数:10,代码来源:test_metabolicmodel.py

示例7: TestLinearMOMA

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestLinearMOMA(unittest.TestCase):
    def setUp(self):
        self.database = DictDatabase()
        self.database.set_reaction('rxn_1', parse_reaction('=> (2) |A|'))
        self.database.set_reaction('rxn_2', parse_reaction('|A| <=> |B|'))
        self.database.set_reaction('rxn_3', parse_reaction('|A| => |D|'))
        self.database.set_reaction('rxn_4', parse_reaction('|A| => |C|'))
        self.database.set_reaction('rxn_5', parse_reaction('|C| => |D|'))
        self.database.set_reaction('rxn_6', parse_reaction('|D| =>'))
        self.model = MetabolicModel.load_model(
            self.database, self.database.reactions)

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

    def test_moma_fba(self):
        p = moma.MOMAProblem(self.model, self.solver)
        fluxes = p.get_fba_flux('rxn_6')
        self.assertAlmostEqual(fluxes['rxn_1'], 500)
        self.assertAlmostEqual(fluxes['rxn_2'], 0)
        self.assertAlmostEqual(fluxes['rxn_6'], 1000)

    def test_moma_minimal_fba(self):
        p = moma.MOMAProblem(self.model, self.solver)
        fluxes = p.get_minimal_fba_flux('rxn_6')
        self.assertAlmostEqual(fluxes['rxn_1'], 500)
        self.assertAlmostEqual(fluxes['rxn_2'], 0)
        self.assertAlmostEqual(fluxes['rxn_3'], 1000)
        self.assertAlmostEqual(fluxes['rxn_6'], 1000)

    def test_linear_moma(self):
        p = moma.MOMAProblem(self.model, self.solver)
        with p.constraints(p.get_flux_var('rxn_3') == 0):
            p.lin_moma({
                'rxn_3': 1000,
                'rxn_4': 0,
                'rxn_5': 0,
            })

        # The closest solution when these are constrained is for
        # rxn_6 to take on a flux of zero.
        self.assertAlmostEqual(p.get_flux('rxn_6'), 0)

    def test_linear_moma2(self):
        p = moma.MOMAProblem(self.model, self.solver)
        with p.constraints(p.get_flux_var('rxn_3') == 0):
            p.lin_moma2('rxn_6', 1000)

        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)
开发者ID:keitht547,项目名称:psamm,代码行数:58,代码来源:test_moma.py

示例8: TestFastcoreTinyBiomassModel

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestFastcoreTinyBiomassModel(unittest.TestCase):
    """Test fastcore using a model with tiny values in biomass reaction

    This model is consistent mathematically since there is a flux solution
    within the flux bounds. However, the numerical nature of the fastcore
    algorithm requires an epsilon-parameter indicating the minimum flux that
    is considered non-zero. For this reason, some models with reactions where
    tiny stoichiometric values appear can be seen as inconsistent by
    fastcore.

    In this particular model, rxn_2 can take a maximum flux of 1000. At the
    same time rxn_1 will have to take a flux of 1e-3. This is the maximum
    possible flux for rxn_1 so running fastcore with an epsilon larger than
    1e-3 will indicate that the model is not consistent.
    """

    def setUp(self):
        # TODO use mock model instead of actual model
        self.database = DictDatabase()
        self.database.set_reaction('rxn_1', parse_reaction('=> |A|'))
        self.database.set_reaction('rxn_2',
            parse_reaction('(0.000001) |A| =>'))
        self.model = MetabolicModel.load_model(
            self.database, self.database.reactions)

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

        # Skip these tests with GLPK because of issue #61.
        if self.solver.properties['name'] == 'glpk':
            self.skipTest('Test has known issue with GLPK')

    def test_fastcc_is_consistent(self):
        self.assertTrue(fastcore.fastcc_is_consistent(
            self.model, 0.0001, solver=self.solver))

    def test_fastcc_is_consistent_high_epsilon(self):
        self.assertFalse(fastcore.fastcc_is_consistent(
            self.model, 0.1, solver=self.solver))

    def test_fastcore_induced_model(self):
        core = {'rxn_2'}
        self.assertEqual(
            set(fastcore.fastcore(
                self.model, core, 0.0001, scaling=1e7, solver=self.solver)),
            {'rxn_1', 'rxn_2'})

    def test_fastcore_induced_model_high_epsilon(self):
        core = {'rxn_2'}
        self.assertEqual(
            set(fastcore.fastcore(
                self.model, core, 0.1, scaling=1e7, solver=self.solver)),
            {'rxn_1', 'rxn_2'})
开发者ID:ForkBackups,项目名称:psamm,代码行数:57,代码来源:test_fastcore.py

示例9: TestRandomSparse

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestRandomSparse(unittest.TestCase):
    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)

    def test_random_sparse_reaction_strategy(self):
        expected = [
            ({'rxn_1', 'rxn_6', 'ex_A', 'rxn_2', 'rxn_4'}, {'rxn_3', 'rxn_5'}),
            ({'rxn_1', 'rxn_6', 'ex_A', 'rxn_3', 'rxn_5'}, {'rxn_2', 'rxn_4'})
        ]

        strategy = randomsparse.ReactionDeletionStrategy(self._mm)
        essential, deleted = randomsparse.random_sparse(
            strategy,
            self._prob,
            self._obj_reaction,
            flux_threshold=100)

        self.assertTrue((essential, deleted) in expected)

    def test_random_sparse_gene_strategy(self):
        expected = [
            ({'gene_1', 'gene_2'}, {'gene_3', 'gene_4'}),
            ({'gene_1', 'gene_3'}, {'gene_2', 'gene_4'})
        ]
        strategy = randomsparse.GeneDeletionStrategy(
            self._mm, self._assoc)
        essential, deleted = randomsparse.random_sparse(
            strategy,
            self._prob,
            self._obj_reaction,
            flux_threshold=100)

        self.assertTrue((essential, deleted) in expected)
开发者ID:spikeliu,项目名称:psamm,代码行数:58,代码来源:test_randomsparse.py

示例10: TestMetabolicModelFlipableView

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestMetabolicModelFlipableView(unittest.TestCase):
    def setUp(self):
        # TODO use mock database instead of actual database
        self.database = DictDatabase()
        self.database.set_reaction('rxn_1', parse_reaction('=> (2) |A|'))
        self.database.set_reaction('rxn_2', parse_reaction('|A| <=> |B|'))
        self.database.set_reaction('rxn_3', parse_reaction('|A| => |D|'))
        self.database.set_reaction('rxn_4', parse_reaction('|A| => |C|'))
        self.database.set_reaction('rxn_5', parse_reaction('|C| => |D|'))
        self.database.set_reaction('rxn_6', parse_reaction('|D| =>'))

        model = MetabolicModel.load_model(self.database, self.database.reactions)
        self.model = FlipableModelView(model)

    def test_flipable_model_view_matrix_get_item_after_flip(self):
        self.model.flip({ 'rxn_4' })
        self.assertEqual(self.model.matrix[Compound('A'), 'rxn_1'], 2)
        self.assertEqual(self.model.matrix[Compound('A'), 'rxn_2'], -1)
        self.assertEqual(self.model.matrix[Compound('A'), 'rxn_4'], 1)
        self.assertEqual(self.model.matrix[Compound('C'), 'rxn_4'], -1)

    def test_flipable_model_view_matrix_get_item_after_double_flip(self):
        self.model.flip({ 'rxn_4', 'rxn_5' })
        self.model.flip({ 'rxn_1', 'rxn_4', 'rxn_2' })
        self.assertEqual(self.model.matrix[Compound('A'), 'rxn_1'], -2)
        self.assertEqual(self.model.matrix[Compound('A'), 'rxn_2'], 1)
        self.assertEqual(self.model.matrix[Compound('B'), 'rxn_2'], -1)
        self.assertEqual(self.model.matrix[Compound('A'), 'rxn_4'], -1)
        self.assertEqual(self.model.matrix[Compound('C'), 'rxn_4'], 1)
        self.assertEqual(self.model.matrix[Compound('C'), 'rxn_5'], 1)
        self.assertEqual(self.model.matrix[Compound('D'), 'rxn_5'], -1)

    def test_flipable_model_view_limits_get_item_after_flip(self):
        self.model.flip({ 'rxn_1', 'rxn_2' })
        self.assertEqual(self.model.limits['rxn_1'].bounds, (-1000, 0))
        self.assertEqual(self.model.limits['rxn_2'].bounds, (-1000, 1000))
        self.assertEqual(self.model.limits['rxn_3'].bounds, (0, 1000))

    def test_flipable_model_view_limits_set_item_after_flip(self):
        self.model.flip({ 'rxn_1' })
        self.model.limits['rxn_1'].bounds = -20, 500
        self.assertEqual(self.model.limits['rxn_1'].bounds, (-20, 500))

        self.model.flip({ 'rxn_1' })
        self.assertEqual(self.model.limits['rxn_1'].bounds, (-500, 20))
开发者ID:amenge,项目名称:psamm,代码行数:47,代码来源:test_metabolicmodel.py

示例11: TestMetabolicModelFlipableView

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestMetabolicModelFlipableView(unittest.TestCase):
    def setUp(self):
        # TODO use mock database instead of actual database
        self.database = DictDatabase()
        self.database.set_reaction("rxn_1", parse_reaction("=> (2) |A|"))
        self.database.set_reaction("rxn_2", parse_reaction("|A| <=> |B|"))
        self.database.set_reaction("rxn_3", parse_reaction("|A| => |D|"))
        self.database.set_reaction("rxn_4", parse_reaction("|A| => |C|"))
        self.database.set_reaction("rxn_5", parse_reaction("|C| => |D|"))
        self.database.set_reaction("rxn_6", parse_reaction("|D| =>"))

        model = MetabolicModel.load_model(self.database, self.database.reactions)
        self.model = FlipableModelView(model)

    def test_flipable_model_view_matrix_get_item_after_flip(self):
        self.model.flip({"rxn_4"})
        self.assertEqual(self.model.matrix[Compound("A"), "rxn_1"], 2)
        self.assertEqual(self.model.matrix[Compound("A"), "rxn_2"], -1)
        self.assertEqual(self.model.matrix[Compound("A"), "rxn_4"], 1)
        self.assertEqual(self.model.matrix[Compound("C"), "rxn_4"], -1)

    def test_flipable_model_view_matrix_get_item_after_double_flip(self):
        self.model.flip({"rxn_4", "rxn_5"})
        self.model.flip({"rxn_1", "rxn_4", "rxn_2"})
        self.assertEqual(self.model.matrix[Compound("A"), "rxn_1"], -2)
        self.assertEqual(self.model.matrix[Compound("A"), "rxn_2"], 1)
        self.assertEqual(self.model.matrix[Compound("B"), "rxn_2"], -1)
        self.assertEqual(self.model.matrix[Compound("A"), "rxn_4"], -1)
        self.assertEqual(self.model.matrix[Compound("C"), "rxn_4"], 1)
        self.assertEqual(self.model.matrix[Compound("C"), "rxn_5"], 1)
        self.assertEqual(self.model.matrix[Compound("D"), "rxn_5"], -1)

    def test_flipable_model_view_limits_get_item_after_flip(self):
        self.model.flip({"rxn_1", "rxn_2"})
        self.assertEqual(self.model.limits["rxn_1"].bounds, (-1000, 0))
        self.assertEqual(self.model.limits["rxn_2"].bounds, (-1000, 1000))
        self.assertEqual(self.model.limits["rxn_3"].bounds, (0, 1000))

    def test_flipable_model_view_limits_set_item_after_flip(self):
        self.model.flip({"rxn_1"})
        self.model.limits["rxn_1"].bounds = -20, 500
        self.assertEqual(self.model.limits["rxn_1"].bounds, (-20, 500))

        self.model.flip({"rxn_1"})
        self.assertEqual(self.model.limits["rxn_1"].bounds, (-500, 20))
开发者ID:gitter-badger,项目名称:psamm,代码行数:47,代码来源:test_metabolicmodel.py

示例12: TestGeneDeletionStrategy

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestGeneDeletionStrategy(unittest.TestCase):
    def setUp(self):
        self._database = DictDatabase()
        self._database.set_reaction('rxn_1', parse_reaction('|A| <=>'))
        self._database.set_reaction('rxn_2', parse_reaction('|A| <=> |B|'))
        self._database.set_reaction('rxn_3', parse_reaction('|C| <=> |B|'))
        self._database.set_reaction('rxn_4', parse_reaction('|C| <=>'))
        self._mm = MetabolicModel.load_model(
            self._database, self._database.reactions)
        self._assoc = {'rxn_2': boolean.Expression('gene_1 or gene_2')}

        self._strategy = randomsparse.GeneDeletionStrategy(
            self._mm, self._assoc)

    def test_method_get_all(self):
        expected_total = {'gene_1', 'gene_2'}
        self.assertEqual(set(self._strategy.entities), expected_total)

    def test_method_tests_and_delete(self):
        expected_genes = {'gene_1', 'gene_2'}
        expected_reaction_set = {'rxn_2'}
        test_dict = {}

        for i, (gene, deleted_reac) in enumerate(self._strategy.iter_tests()):
            self._strategy.delete(gene, deleted_reac)
            if i == 0:
                self.assertEqual(deleted_reac, set())
            else:
                self.assertEqual(deleted_reac, {'rxn_2'})
            test_dict[gene] = deleted_reac

        self.assertTrue(all(x in test_dict for x in expected_genes))
        self.assertTrue(expected_reaction_set in test_dict.values())
开发者ID:spikeliu,项目名称:psamm,代码行数:35,代码来源:test_randomsparse.py

示例13: TestFastGapFill

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestFastGapFill(unittest.TestCase):
    def setUp(self):
        self._database = DictDatabase()
        self._database.set_reaction('rxn_1', parse_reaction('|A| <=>'))
        self._database.set_reaction('rxn_2', parse_reaction('|A| <=> |B|'))
        self._database.set_reaction('rxn_3', parse_reaction('|C| <=> |B|'))
        self._database.set_reaction('rxn_4', parse_reaction('|C| <=>'))
        self._mm = MetabolicModel.load_model(
            self._database, self._database.reactions)

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

    def test_fastgapfill(self):
        core = {'rxn_2', 'rxn_3'}
        induced = fastgapfill.fastgapfill(
            self._mm,
            core,
            epsilon=0.001,
            solver=self._solver)

        self.assertEqual(
            set(induced),
            {'rxn_1', 'rxn_2', 'rxn_3', 'rxn_4'})
开发者ID:keitht547,项目名称:psamm,代码行数:28,代码来源:test_fastgapfill.py

示例14: TestFluxBalance

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestFluxBalance(unittest.TestCase):
    def setUp(self):
        self.database = DictDatabase()
        self.database.set_reaction('rxn_1', parse_reaction('=> (2) |A|'))
        self.database.set_reaction('rxn_2', parse_reaction('|A| <=> |B|'))
        self.database.set_reaction('rxn_3', parse_reaction('|A| => |D|'))
        self.database.set_reaction('rxn_4', parse_reaction('|A| => |C|'))
        self.database.set_reaction('rxn_5', parse_reaction('|C| => |D|'))
        self.database.set_reaction('rxn_6', parse_reaction('|D| =>'))
        self.model = MetabolicModel.load_model(
            self.database, self.database.reactions)
        self.solver = cplex.Solver()

    def test_flux_balance_rxn_1(self):
        fluxes = dict(fluxanalysis.flux_balance(
            self.model, 'rxn_1', tfba=False, solver=self.solver))
        self.assertEqual(fluxes['rxn_1'], 500)
        self.assertEqual(fluxes['rxn_2'], 0)
        self.assertEqual(fluxes['rxn_6'], 1000)

    def test_flux_balance_rxn_2(self):
        fluxes = dict(fluxanalysis.flux_balance(
            self.model, 'rxn_2', tfba=False, solver=self.solver))
        self.assertEqual(fluxes['rxn_2'], 0)

    def test_flux_balance_rxn_3(self):
        fluxes = dict(fluxanalysis.flux_balance(
            self.model, 'rxn_3', tfba=False, solver=self.solver))
        self.assertEqual(fluxes['rxn_1'], 500)
        self.assertEqual(fluxes['rxn_2'], 0)
        self.assertEqual(fluxes['rxn_3'], 1000)
        self.assertEqual(fluxes['rxn_6'], 1000)

    def test_flux_balance_rxn_6(self):
        fluxes = dict(fluxanalysis.flux_balance(
            self.model, 'rxn_6', tfba=False, solver=self.solver))
        self.assertEqual(fluxes['rxn_1'], 500)
        self.assertEqual(fluxes['rxn_2'], 0)
        self.assertEqual(fluxes['rxn_6'], 1000)
开发者ID:gitter-badger,项目名称:psamm,代码行数:41,代码来源:test_fluxanalysis.py

示例15: TestGetExchangeReactions

# 需要导入模块: from psamm.database import DictDatabase [as 别名]
# 或者: from psamm.database.DictDatabase import set_reaction [as 别名]
class TestGetExchangeReactions(unittest.TestCase):
    def setUp(self):
        self._database = DictDatabase()
        self._database.set_reaction('rxn_1', parse_reaction('|A| <=>'))
        self._database.set_reaction('rxn_2', parse_reaction('|A| <=> |B|'))
        self._database.set_reaction('rxn_3', parse_reaction('|C| <=> |B|'))
        self._database.set_reaction('rxn_4', parse_reaction('|C| <=>'))
        self._mm = MetabolicModel.load_model(
            self._database, self._database.reactions)

    def test_get_exchange_reactions(self):
        expected_reactions = {'rxn_1', 'rxn_4'}
        self.assertEqual(
            set(randomsparse.get_exchange_reactions(self._mm)),
            expected_reactions)
开发者ID:spikeliu,项目名称:psamm,代码行数:17,代码来源:test_randomsparse.py


注:本文中的psamm.database.DictDatabase.set_reaction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。