Пример #1
0
    def test_serialize(self):
        comp = core.Compartment(id='c')
        met = core.MetaboliteSpeciesType(id='met')

        spec = core.Species(species_type=met, compartment=comp)
        spec_coeff = core.SpeciesCoefficient(species=spec, coefficient=3)

        self.assertEqual(spec_coeff.serialize(), '(3) met[c]')
        self.assertEqual(
            core.SpeciesCoefficient._serialize(species=spec, coefficient=3),
            '(3) met[c]')
        self.assertEqual(
            core.SpeciesCoefficient._serialize(species=spec, coefficient=1),
            'met[c]')
        self.assertEqual(
            core.SpeciesCoefficient._serialize(species=spec, coefficient=2000),
            '(2.000000e+03) met[c]')
        self.assertEqual(
            core.SpeciesCoefficient._serialize(species=spec,
                                               coefficient=3,
                                               show_compartment=False),
            '(3) met')
        self.assertEqual(
            core.SpeciesCoefficient._serialize(species=spec, coefficient=-1),
            '(-1) met[c]')
        self.assertEqual(
            core.SpeciesCoefficient._serialize(species=spec,
                                               coefficient=-1,
                                               show_coefficient_sign=False),
            'met[c]')
Пример #2
0
    def test_observable_coefficient(self):
        cell = core.Cell()
        comp1 = core.Compartment(id='c')
        met1 = core.MetaboliteSpeciesType(id='met1')
        dna1 = core.DnaSpeciesType(id="dna1")

        species1 = core.Species(species_type=met1, compartment=comp1)
        species2 = core.Species(species_type=dna1, compartment=comp1)

        speciesCoefficient1 = core.SpeciesCoefficient(species=species1,
                                                      coefficient=2.5)
        speciesCoefficient2 = core.SpeciesCoefficient(species=species2,
                                                      coefficient=3)

        observable1 = core.Observable(
            id='test',
            cell=cell,
            species=[speciesCoefficient1, speciesCoefficient2])
        observableCoefficient1 = core.ObservableCoefficient(
            observable=observable1, coefficient=2.3)

        self.assertIsInstance(observableCoefficient1,
                              core.ObservableCoefficient)
        self.assertIsInstance(observableCoefficient1.observable,
                              core.Observable)
        self.assertIsInstance(observableCoefficient1.coefficient, float)
        self.assertEqual(observableCoefficient1.observable.id, 'test')
Пример #3
0
    def test_constructor(self):
        comp = core.Compartment(id='c')
        met = core.MetaboliteSpeciesType(id='met')
        spec = core.Species(species_type=met, compartment=comp)

        conc = core.Concentration(species=spec, value=0.2)

        self.assertEqual(conc.serialize(), 'met[c]')
        self.assertEqual(conc.value, 0.2)
        self.assertEqual(conc.units, 2)
Пример #4
0
    def test_constructor(self):
        comp = core.Compartment(id='c')
        met = core.MetaboliteSpeciesType(id='met')

        spec = core.Species(species_type=met, compartment=comp)
        spec_coeff = core.SpeciesCoefficient(species=spec, coefficient=3)

        self.assertEqual(spec_coeff.species.species_type.id, 'met')
        self.assertEqual(spec_coeff.species.compartment.id, 'c')
        self.assertEqual(spec_coeff.coefficient, 3)
Пример #5
0
    def test_SpeciesType(self):
        comp1 = core.Compartment(id='c')
        met1 = core.MetaboliteSpeciesType(id='met1')
        species1 = core.Species(species_type=met1, compartment=comp1)

        self.assertEqual(core.Species.gen_id(met1, comp1), 'met1[c]')
        self.assertEqual(core.Species.gen_id('met1', 'c'), 'met1[c]')
        with self.assertRaisesRegex(ValueError, 'incorrect species type'):
            core.Species.gen_id(None, 'c')
        with self.assertRaisesRegex(ValueError, 'incorrect compartment type'):
            core.Species.gen_id('met1', None)

        self.assertEqual(species1.id(), 'met1[c]')
Пример #6
0
    def test_deserialize(self):
        comp1 = core.Compartment(id='c')
        met1 = core.MetaboliteSpeciesType(id='met1')
        dna1 = core.DnaSpeciesType(id='dna1')

        objects = {
            core.Compartment: {
                'c': comp1,
            },
            core.MetaboliteSpeciesType: {
                'met1': met1,
            },
            core.DnaSpeciesType: {
                'dna1': dna1,
            },
        }

        attr = core.SpeciesCoefficient.species
        result = core.Species.deserialize(attr, 'met1[c]', objects)
        self.assertEqual(result[0].species_type, met1)
        self.assertEqual(result[0].compartment, comp1)
        self.assertEqual(result[1], None)

        result2 = core.Species.deserialize(attr, 'met1[c]', objects)
        self.assertEqual(result2[0], result[0])
        self.assertIn(core.Species, objects)
        self.assertIn('met1[c]', objects[core.Species])

        self.assertNotIn('dna1[c]', objects[core.Species])
        self.assertEqual(
            core.Species.deserialize(attr, 'dna1[c]', objects)[1], None)
        self.assertIn('dna1[c]', objects[core.Species])

        self.assertNotEqual(
            core.Species.deserialize(attr, 'met2[c]', objects)[1], None)
        self.assertNotEqual(
            core.Species.deserialize(attr, 'met1[e]', objects)[1], None)
        self.assertNotEqual(
            core.Species.deserialize(attr, 'met1', objects)[1], None)
Пример #7
0
    def test_observables(self):
        cell = core.Cell()
        comp1 = core.Compartment(id='c')
        met1 = core.MetaboliteSpeciesType(id='met1')
        dna1 = core.DnaSpeciesType(id="dna1")

        species1 = core.Species(species_type=met1, compartment=comp1)
        species2 = core.Species(species_type=dna1, compartment=comp1)

        speciesCoefficient1 = core.SpeciesCoefficient(species=species1,
                                                      coefficient=2)
        speciesCoefficient2 = core.SpeciesCoefficient(species=species2,
                                                      coefficient=3.3)

        observable1 = core.Observable(
            cell=cell, species=[speciesCoefficient1, speciesCoefficient2])
        observableCoefficient1 = core.ObservableCoefficient(
            observable=observable1, coefficient=2)

        observable2 = core.Observable(
            cell=cell,
            species=[speciesCoefficient1, speciesCoefficient2],
            observables=[observableCoefficient1])

        self.assertIsInstance(observable1, core.Observable)
        self.assertIsInstance(observable2, core.Observable)
        with self.assertRaisesRegex(AttributeError, ""):
            observable3 = core.Observable(cell=cell,
                                          species=[species1, species2])
        self.assertIsInstance(observable1.species[0], core.SpeciesCoefficient)
        self.assertIsInstance(observable2.observables[0],
                              core.ObservableCoefficient)
        self.assertIsInstance(observable1.species[0].species, core.Species)
        self.assertEqual(observable1.species[0].species.id(), 'met1[c]')
        self.assertEqual(observable1.species[1].species.species_type.id,
                         'dna1')
        self.assertIsInstance(observable2.observables[0].observable,
                              core.Observable)
Пример #8
0
    def test_ReactionParticipantAttribute(self):
        compart1 = core.Compartment(id='c')
        compart2 = core.Compartment(id='m')

        met1 = core.MetaboliteSpeciesType(id='met1')
        met2 = core.MetaboliteSpeciesType(id='met2')
        complex1 = core.ComplexSpeciesType(id='complex1')

        species1 = core.Species(species_type=met1, compartment=compart1)
        species2 = core.Species(species_type=met2, compartment=compart1)
        species3 = core.Species(species_type=complex1, compartment=compart1)
        species4 = core.Species(species_type=complex1, compartment=compart2)

        species_coeff1 = core.SpeciesCoefficient(species=species1,
                                                 coefficient=-2)
        species_coeff2 = core.SpeciesCoefficient(species=species2,
                                                 coefficient=-3)
        species_coeff3 = core.SpeciesCoefficient(species=species3,
                                                 coefficient=5)
        species_coeff4 = core.SpeciesCoefficient(species=species4,
                                                 coefficient=7)

        self.assertEqual(
            core.ReactionParticipantAttribute().serialize(participants=[]), '')
        self.assertEqual(
            core.ReactionParticipantAttribute().serialize(
                participants=[species_coeff1]), '[c]: (2) met1 ==> ')
        self.assertEqual(
            core.ReactionParticipantAttribute().serialize(
                participants=[species_coeff1, species_coeff2]),
            '[c]: (2) met1 + (3) met2 ==> ')
        self.assertEqual(
            core.ReactionParticipantAttribute().serialize(
                participants=[species_coeff1, species_coeff2, species_coeff3]),
            '[c]: (2) met1 + (3) met2 ==> (5) complex1')
        self.assertEqual(
            core.ReactionParticipantAttribute().serialize(
                participants=[species_coeff1, species_coeff2, species_coeff4]),
            '(2) met1[c] + (3) met2[c] ==> (7) complex1[m]')

        objects = {
            core.DnaSpeciesType: {},
            core.MetaboliteSpeciesType: {
                'met1': met1,
                'met2': met2
            },
            core.ComplexSpeciesType: {
                'complex1': complex1
            },
            core.Compartment: {
                'c': compart1,
                'm': compart2
            },
            core.Species: {
                'met1[c]': species1,
                'met2[c]': species2,
                'complex1[c]': species3,
                'complex[m]': species4
            },
        }

        result = core.ReactionParticipantAttribute().deserialize(
            value='[c]: met1 ==> met2', objects=objects)
        self.assertEqual(result[0][0].species.species_type, met1)
        self.assertEqual(result[0][1].species.species_type, met2)
        self.assertEqual(result[0][0].coefficient, -1)
        self.assertEqual(result[0][1].coefficient, 1)
        self.assertEqual(result[0][0].species.compartment, compart1)
        self.assertEqual(result[0][1].species.compartment, compart1)
        self.assertEqual(result[0][0].species.id(), 'met1[c]')
        self.assertEqual(result[0][1].species.id(), 'met2[c]')
        self.assertEqual(result[1], None)

        result = core.ReactionParticipantAttribute().deserialize(
            value='(2) met1[c] + (3) met2[c] ==> (7) complex1[m]',
            objects=objects)
        self.assertEqual(result[0][0].species.species_type, met1)
        self.assertEqual(result[0][1].species.species_type, met2)
        self.assertEqual(result[0][2].species.species_type, complex1)
        self.assertEqual(result[0][0].coefficient, -2)
        self.assertEqual(result[0][1].coefficient, -3)
        self.assertEqual(result[0][2].coefficient, 7.0)
        self.assertEqual(result[0][0].species.compartment, compart1)
        self.assertEqual(result[0][1].species.compartment, compart1)
        self.assertEqual(result[0][2].species.compartment, compart2)
        self.assertEqual(result[0][0].species.id(), 'met1[c]')
        self.assertEqual(result[0][1].species.id(), 'met2[c]')
        self.assertEqual(result[0][2].species.id(), 'complex1[m]')
        self.assertEqual(result[1], None)

        result = core.ReactionParticipantAttribute().deserialize(
            value='met2[c] ==>', objects=objects)
        self.assertEqual(result[0], None)
        self.assertEqual(result[1].messages[0],
                         'Incorrectly formatted participants: met2[c] ==>')

        result = core.ReactionParticipantAttribute().deserialize(
            value='==> met1[c]', objects=objects)
        self.assertEqual(result[0], None)
        self.assertEqual(result[1].messages[0],
                         'Incorrectly formatted participants: ==> met1[c]')
Пример #9
0
 def test_constructor(self):
     comp = core.Compartment(volumetric_fraction=0.5)
     self.assertEqual(comp.volumetric_fraction, 0.5)
Пример #10
0
    def test_SubunitAttribute(self):
        compart1 = core.Compartment(id='c')

        met1 = core.MetaboliteSpeciesType(id='met1')
        dna1 = core.DnaSpeciesType(id='dna1')
        complex1 = core.ComplexSpeciesType(id='complex1')

        species1 = core.Species(species_type=complex1, compartment=compart1)

        species_type_coeff1 = core.SpeciesTypeCoefficient(species_type=met1,
                                                          coefficient=2)
        species_type_coeff2 = core.SpeciesTypeCoefficient(species_type=dna1,
                                                          coefficient=3)
        species_type_coeff3 = core.SpeciesTypeCoefficient(
            species_type=complex1, coefficient=5)

        self.assertEqual(core.SubunitAttribute().serialize(subunits=[]), '')
        self.assertEqual(
            core.SubunitAttribute().serialize(subunits=[species_type_coeff1]),
            '(2) met1')
        self.assertEqual(
            core.SubunitAttribute().serialize(
                subunits=[species_type_coeff1, species_type_coeff2]),
            '(3) dna1 + (2) met1')
        self.assertEqual(
            core.SubunitAttribute().serialize(subunits=[
                species_type_coeff1, species_type_coeff2, species_type_coeff3
            ]), '(5) complex1 + (3) dna1 + (2) met1')

        objects = {
            core.DnaSpeciesType: {
                'dna1': dna1
            },
            core.MetaboliteSpeciesType: {
                'met1': met1
            },
            core.ComplexSpeciesType: {
                'complex1': complex1
            },
        }

        result = core.SubunitAttribute().deserialize(value='met1 + (2) dna1',
                                                     objects=objects)
        self.assertEqual(result[0][0].species_type, met1)
        self.assertEqual(result[0][1].species_type, dna1)
        self.assertEqual(result[0][0].coefficient, 1)
        self.assertEqual(result[0][1].coefficient, 2)
        self.assertEqual(result[0][0].species_type.id, 'met1')
        self.assertEqual(result[0][1].species_type.id, 'dna1')
        self.assertEqual(result[1], None)

        result = core.SubunitAttribute().deserialize(
            value='(2) met1 + (7) complex1', objects=objects)
        self.assertEqual(result[0][0].species_type, met1)
        self.assertEqual(result[0][1].species_type, complex1)
        self.assertEqual(result[0][0].coefficient, 2)
        self.assertEqual(result[0][1].coefficient, 7)
        self.assertEqual(result[0][0].species_type.id, 'met1')
        self.assertEqual(result[0][1].species_type.id, 'complex1')
        self.assertEqual(result[1], None)

        result = core.SubunitAttribute().deserialize(
            value='[c]met1 + (2) dna1', objects=objects)
        self.assertEqual(result[0], None)
        self.assertEqual(
            result[1].messages[0],
            'Incorrectly formatted participants: [c]met1 + (2) dna1')
Пример #11
0
    def test_deserialize(self):
        comp = core.Compartment(id='c')
        dna = core.DnaSpeciesType(id='dna')
        met = core.MetaboliteSpeciesType(id='met')

        spec = core.Species(species_type=dna, compartment=comp)

        objects = {
            core.Compartment: {
                'c': comp,
            },
            core.DnaSpeciesType: {
                'dna': dna,
            },
            core.MetaboliteSpeciesType: {
                'met': met,
            },
            core.Species: {
                'dna[c]': spec,
            },
        }

        attr = core.Reaction.participants

        result = core.SpeciesCoefficient.deserialize(attr, '(3) dna[c]',
                                                     objects)
        self.assertEqual(result[0].species, spec)
        self.assertEqual(result[0].coefficient, 3)
        self.assertEqual(result[1], None)
        self.assertEqual(len(objects[core.Species]), 1)
        self.assertEqual(len(objects[core.SpeciesCoefficient]), 1)

        result2 = core.SpeciesCoefficient.deserialize(attr, '(3) dna[c]',
                                                      objects)
        self.assertEqual(result2[0], result[0])
        self.assertEqual(result2[1], None)
        self.assertEqual(len(objects[core.Species]), 1)
        self.assertEqual(len(objects[core.SpeciesCoefficient]), 1)

        result = core.SpeciesCoefficient.deserialize(attr, '(-2) dna[c]',
                                                     objects)
        self.assertEqual(result[0].species, spec)
        self.assertEqual(result[0].coefficient, -2)
        self.assertEqual(result[1], None)
        self.assertEqual(len(objects[core.Species]), 1)
        self.assertEqual(len(objects[core.SpeciesCoefficient]), 2)

        result = core.SpeciesCoefficient.deserialize(attr, 'dna[c]', objects)
        self.assertEqual(result[0].species, spec)
        self.assertEqual(result[0].coefficient, 1)
        self.assertEqual(result[1], None)
        self.assertEqual(len(objects[core.Species]), 1)
        self.assertEqual(len(objects[core.SpeciesCoefficient]), 3)

        result = core.SpeciesCoefficient.deserialize(attr, 'met[c]', objects)
        self.assertEqual(result[0].species.species_type, met)
        self.assertEqual(result[0].species.compartment, comp)
        self.assertEqual(result[0].coefficient, 1)
        self.assertEqual(result[1], None)
        self.assertEqual(len(objects[core.Species]), 2)
        self.assertEqual(len(objects[core.SpeciesCoefficient]), 4)

        result = core.SpeciesCoefficient.deserialize(attr, 'dna2[c]', objects)
        self.assertEqual(result[0], None)
        self.assertNotEqual(result[1], None)

        result = core.SpeciesCoefficient.deserialize(attr, 'dna', objects)
        self.assertEqual(result[0], None)
        self.assertNotEqual(result[1], None)

        result = core.SpeciesCoefficient.deserialize(attr,
                                                     'dna',
                                                     objects,
                                                     compartment=comp)
        self.assertEqual(result[0].species.species_type, dna)
        self.assertEqual(result[0].species.compartment, comp)
        self.assertEqual(result[0].coefficient, 1)
        self.assertEqual(result[1], None)

        result = core.SpeciesCoefficient.deserialize(attr,
                                                     '(2) dna',
                                                     objects,
                                                     compartment=comp)
        self.assertEqual(result[0].species.species_type, dna)
        self.assertEqual(result[0].species.compartment, comp)
        self.assertEqual(result[0].coefficient, 2)
        self.assertEqual(result[1], None)

        result = core.SpeciesCoefficient.deserialize(attr,
                                                     '(-3) dna',
                                                     objects,
                                                     compartment=comp)
        self.assertEqual(result[0].species.species_type, dna)
        self.assertEqual(result[0].species.compartment, comp)
        self.assertEqual(result[0].coefficient, -3)
        self.assertEqual(result[1], None)
Пример #12
0
    def test_serialize(self):
        comp1 = core.Compartment(id='c')
        met1 = core.MetaboliteSpeciesType(id='met1')
        species1 = core.Species(species_type=met1, compartment=comp1)

        self.assertEqual(species1.serialize(), 'met1[c]')
Пример #13
0
    def setUp(self):
        self.cell_1 = cell_1 = core.Cell()
        self.compartment_1 = compartment_1 = core.Compartment(cell=cell_1,
                                                              id='c')
        self.species_type_1 = species_type_1 = core.MetaboliteSpeciesType(
            id='species_type_1')
        self.species_type_2 = species_type_2 = core.MetaboliteSpeciesType(
            id='species_type_2')
        self.species_1 = species_1 = core.Species(species_type=species_type_1,
                                                  compartment=compartment_1)
        self.species_2 = species_2 = core.Species(species_type=species_type_2,
                                                  compartment=compartment_1)
        self.participant_1 = participant_1 = core.SpeciesCoefficient(
            species=species_1, coefficient=1)
        self.participant_2 = participant_2 = core.SpeciesCoefficient(
            species=species_2, coefficient=1)

        self.reaction_1 = reaction_1 = core.Reaction(
            id='reaction_1',
            name='test_reaction',
            cell=cell_1,
            participants=[participant_1, participant_2],
            reversible=False)

        self.rate_law_equation_1 = rate_law_equation_1 = core.RateLawEquation(
            expression=species_1.id())

        self.rate_law_1 = rate_law_1 = core.RateLaw(
            reaction=reaction_1,
            direction=core.RateLawDirection.forward,
            k_m=0.1,
            k_cat=0.5,
            equation=rate_law_equation_1)

        self.reaction_2 = reaction_2 = core.Reaction(
            id='reaction_2',
            name='test_reaction2',
            cell=cell_1,
            participants=[participant_1, participant_2],
            reversible=False)

        self.parameter_1 = parameter_1 = core.Parameter(id='p1',
                                                        name='test_parameter1',
                                                        value=0.7,
                                                        error=0.01,
                                                        units='s^-1')

        self.parameter_2 = parameter_2 = core.Parameter(id='p2',
                                                        name='test_parameter2',
                                                        value=2.,
                                                        error=0.1,
                                                        units='M')

        self.parameter_3 = parameter_3 = core.Parameter(id='p3',
                                                        name='test_parameter3',
                                                        value=2.3,
                                                        error=0.15,
                                                        units='M')

        self.rate_law_equation_2 = rate_law_equation_2 = core.RateLawEquation(
            expression=
            'p1*species_type_1[c]*species_type_2[c]/(p2+species_type_2[c]+(species_type_2[c]^2/p3))',
            modifiers=[species_1, species_2],
            parameters=[parameter_1, parameter_2])

        self.rate_law_2 = rate_law_2 = core.RateLaw(
            reaction=reaction_2,
            direction=core.RateLawDirection.backward,
            equation=rate_law_equation_2)

        self.objects = {
            core.Species: {
                species_1.id(): species_1,
                species_2.id(): species_2
            },
            core.Parameter: {
                parameter_1.id: parameter_1,
                parameter_2.id: parameter_2,
                parameter_3.id: parameter_3
            }
        }