Esempio n. 1
0
    def test_ComplexSpeciesType(self):

        # Test constructor
        complex1 = core.ComplexSpeciesType()

        self.assertEqual(complex1.region, '')
        self.assertEqual(complex1.binding, '')
        self.assertEqual(complex1.complex_type, '')
        self.assertEqual(complex1.composition_in_uniprot, '')
        self.assertEqual(complex1.formation_process, None)
        self.assertEqual(complex1.subunits, [])

        cofactor1 = core.MetaboliteSpeciesType(
            id='cofactor1',
            structure=
            'InChI=1S/C8H7NO3/c10-6-1-4-5(2-7(6)11)9-3-8(4)12/h1-2,8-9,12H,3H2'
        )
        cofactor2 = core.MetaboliteSpeciesType(id='cofactor2',
                                               structure='InChI=1S/Zn/q+2')

        # Test adding subunit composition
        # Add subunit composition: (2) cofactor1 + (3) cofactor2 ==> complex1
        species_type_coeff1 = core.SpeciesTypeCoefficient(
            species_type=cofactor1, coefficient=2)
        species_type_coeff2 = core.SpeciesTypeCoefficient(
            species_type=cofactor2, coefficient=3)
        complex1.subunits = [species_type_coeff1, species_type_coeff2]

        self.assertEqual(complex1.get_charge(), 6)
        self.assertAlmostEqual(
            complex1.get_mol_wt(),
            (2 * cofactor1.get_mol_wt() + 3 * cofactor2.get_mol_wt()))
        self.assertEqual(complex1.get_empirical_formula(),
                         chem.EmpiricalFormula('C16H14N2O6Zn3'))
Esempio n. 2
0
    def test_ComplexSpeciesType(self):

        # Test constructor
        complex1 = core.ComplexSpeciesType()

        # Generate test proteins from  Mycoplasma Genintalium Genome
        dna1 = core.DnaSpeciesType(id='chromosome',
                                   sequence_path='tests/fixtures/seq.fna')

        cell1 = dna1.cell = core.Cell()
        cell1.knowledge_base = core.KnowledgeBase(
            translation_table=4)  # Table 4 is for mycoplasma

        # Protein 1,  MPN001
        gene1 = prokaryote_schema.GeneLocus(id='gene1',
                                            cell=cell1,
                                            polymer=dna1,
                                            start=692,
                                            end=1834)
        tu1 = prokaryote_schema.TranscriptionUnitLocus(id='tu1',
                                                       genes=[gene1],
                                                       polymer=dna1)
        prot1 = prokaryote_schema.ProteinSpeciesType(id='prot1',
                                                     gene=gene1,
                                                     cell=cell1)

        # Protein 2, MPN011
        gene2 = prokaryote_schema.GeneLocus(id='gene2',
                                            cell=cell1,
                                            polymer=dna1,
                                            start=12838,
                                            end=13533,
                                            strand=core.PolymerStrand.negative)
        tu2 = prokaryote_schema.TranscriptionUnitLocus(id='tu2',
                                                       genes=[gene2],
                                                       polymer=dna1)
        prot2 = prokaryote_schema.ProteinSpeciesType(id='prot2',
                                                     gene=gene2,
                                                     cell=cell1)

        # Test adding complexation
        # Add formation reaction: (2) prot1 + (3) prot2 ==> complex1
        species_coeff1 = core.SpeciesTypeCoefficient(species_type=prot1,
                                                     coefficient=2)
        species_coeff2 = core.SpeciesTypeCoefficient(species_type=prot2,
                                                     coefficient=3)
        complex1.subunits = [species_coeff1, species_coeff2]

        self.assertEqual(complex1.get_charge(), 38)
        self.assertAlmostEqual(
            complex1.get_mol_wt(),
            (2 * prot1.get_mol_wt() + 3 * prot2.get_mol_wt()))
        self.assertEqual(complex1.get_empirical_formula(),
                         chem.EmpiricalFormula('C7698H12076N1938O2248S23'))
Esempio n. 3
0
    def test_ComplexSpeciesType(self):

        self.tmp_dirname = tempfile.mkdtemp()
        sequence_path = os.path.join(self.tmp_dirname, 'test_seq.fasta')
        with open(sequence_path, 'w') as f:
            f.write(
                '>dna1\nTTTATGAARGTNCTCATHAAYAARAAYGARCTCTAGTTTATGAARTTYAARTTYCTCCTCACNCCNCTCTAATTT\n'
            )

        dna1 = core.DnaSpeciesType(id='dna1', sequence_path=sequence_path)

        # Protein subunit 1
        gene1 = eukaryote_schema.GeneLocus(polymer=dna1, start=1, end=36)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)
        exon1 = eukaryote_schema.ExonLocus(start=4, end=36)
        transcript1 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon1])
        cds1 = eukaryote_schema.CdsLocus(start=4, end=36)
        prot1 = eukaryote_schema.ProteinSpeciesType(transcript=transcript1,
                                                    coding_region=cds1)

        # Protein subunit 2
        gene2 = eukaryote_schema.GeneLocus(polymer=dna1, start=37, end=75)
        rna2 = eukaryote_schema.PreRnaSpeciesType(gene=gene2)
        exon2 = eukaryote_schema.ExonLocus(start=40, end=72)
        transcript2 = eukaryote_schema.TranscriptSpeciesType(rna=rna2,
                                                             exons=[exon2])
        cds2 = eukaryote_schema.CdsLocus(start=40, end=72)
        prot2 = eukaryote_schema.ProteinSpeciesType(transcript=transcript2,
                                                    coding_region=cds2)

        # Complex formation: (2) prot1 + (3) prot2 ==> complex1
        species_coeff1 = core.SpeciesTypeCoefficient(species_type=prot1,
                                                     coefficient=2)
        species_coeff2 = core.SpeciesTypeCoefficient(species_type=prot2,
                                                     coefficient=3)
        complex1 = core.ComplexSpeciesType(
            subunits=[species_coeff1, species_coeff2])

        self.assertEqual(complex1.get_charge(), 8)
        self.assertAlmostEqual(
            complex1.get_mol_wt(),
            (2 * prot1.get_mol_wt() + 3 * prot2.get_mol_wt()))
        self.assertEqual(complex1.get_empirical_formula(),
                         chem.EmpiricalFormula('C292H492N64O66S5'))

        shutil.rmtree(self.tmp_dirname)
Esempio n. 4
0
    def test_constructor(self):

        met = core.MetaboliteSpeciesType(id='met')
        species_type_coeff = core.SpeciesTypeCoefficient(species_type=met,
                                                         coefficient=3)

        self.assertEqual(species_type_coeff.species_type.id, 'met')
        self.assertEqual(species_type_coeff.coefficient, 3)
Esempio n. 5
0
    def test_serialize(self):

        met = core.MetaboliteSpeciesType(id='met')
        species_type_coeff = core.SpeciesTypeCoefficient(species_type=met,
                                                         coefficient=3)

        self.assertEqual(species_type_coeff.serialize(), '(3) met')
        self.assertEqual(
            core.SpeciesTypeCoefficient._serialize(species_type=met,
                                                   coefficient=3), '(3) met')
        self.assertEqual(
            core.SpeciesTypeCoefficient._serialize(species_type=met,
                                                   coefficient=1), 'met')
        self.assertEqual(
            core.SpeciesTypeCoefficient._serialize(species_type=met,
                                                   coefficient=2000),
            '(2.000000e+03) met')
Esempio n. 6
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')