Пример #1
0
    def test_get_seq(self):

        dna1 = core.DnaSpeciesType(id='dna1', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=1,
                                                end=15)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(rna1.get_seq(), dna1.get_seq().transcribe())

        dna1 = core.DnaSpeciesType(id='dna2', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=1,
                                                end=1)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(rna1.get_seq(), dna1.get_seq().transcribe())

        dna1 = core.DnaSpeciesType(id='dna7', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=1,
                                                end=8)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(rna1.get_seq(), dna1.get_seq().transcribe())
Пример #2
0
    def test_get_empirical_formula(self):
        dna1 = core.DnaSpeciesType(id='dna2', sequence_path=self.sequence_path)

        gene1 = eukaryote_schema.GeneLocus(polymer=dna1, start=1, end=1)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)
        self.assertEqual(rna1.get_empirical_formula(),
                         chem.EmpiricalFormula('C10H12N5O7P'))

        gene2 = eukaryote_schema.GeneLocus(polymer=dna1, start=2, end=2)
        rna2 = eukaryote_schema.PreRnaSpeciesType(gene=gene2)
        self.assertEqual(rna2.get_empirical_formula(),
                         chem.EmpiricalFormula('C9H12N3O8P'))

        gene3 = eukaryote_schema.GeneLocus(polymer=dna1, start=3, end=3)
        rna3 = eukaryote_schema.PreRnaSpeciesType(gene=gene3)
        self.assertEqual(rna3.get_empirical_formula(),
                         chem.EmpiricalFormula('C10H12N5O8P'))

        gene4 = eukaryote_schema.GeneLocus(polymer=dna1, start=4, end=4)
        rna4 = eukaryote_schema.PreRnaSpeciesType(gene=gene4)
        self.assertEqual(rna4.get_empirical_formula(),
                         chem.EmpiricalFormula('C9H11N2O9P'))

        dna2 = core.DnaSpeciesType(id='dna3', sequence_path=self.sequence_path)
        gene5 = eukaryote_schema.GeneLocus(polymer=dna2, start=1, end=2)
        rna5 = eukaryote_schema.PreRnaSpeciesType(gene=gene5)
        self.assertEqual(rna5.get_empirical_formula(),
                         chem.EmpiricalFormula('C20H23N10O13P2'))
Пример #3
0
    def test_get_empirical_formula(self):

        dna1 = core.DnaSpeciesType(id='dna2', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=1,
                                                end=1)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(rna1.get_empirical_formula(),
                         chem.EmpiricalFormula('C10H12N5O7P'))

        dna1 = core.DnaSpeciesType(id='dna3', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=1,
                                                end=1)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(rna1.get_empirical_formula(),
                         chem.EmpiricalFormula('C9H12N3O8P'))

        dna1 = core.DnaSpeciesType(id='dna4', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=1,
                                                end=1)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(rna1.get_empirical_formula(),
                         chem.EmpiricalFormula('C10H12N5O8P'))

        dna1 = core.DnaSpeciesType(id='dna5', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=1,
                                                end=1)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(rna1.get_empirical_formula(),
                         chem.EmpiricalFormula('C9H11N2O9P'))

        dna1 = core.DnaSpeciesType(id='dna6', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=1,
                                                end=2)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(rna1.get_empirical_formula(),
                         chem.EmpiricalFormula('C20H23N10O13P2'))
Пример #4
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')
Пример #5
0
    def test_constructor(self):
        dna1 = core.DnaSpeciesType(circular=False, double_stranded=False)

        gene1 = eukaryote.GeneLocus(polymer=dna1, start=9, end=15)
        gene2 = eukaryote.GeneLocus(polymer=dna1, start=17, end=18)

        promoter1 = 'ENSR00000172399'
        promoter2 = 'ENSR00000309980'

        tf1 = eukaryote.ProteinSpeciesType(id='tf1')
        tf2 = eukaryote.ProteinSpeciesType(id='tf2')

        reg_module1 = eukaryote.RegulatoryModule(
            gene=gene1,
            promoter=promoter1,
            activity=eukaryote.ActivityLevel.active,
            type=eukaryote.RegulationType.proximal,
            transcription_factor_regulation=[
                eukaryote.TranscriptionFactorRegulation(
                    transcription_factor=tf1,
                    direction=eukaryote.RegulatoryDirection.activation),
                eukaryote.TranscriptionFactorRegulation(
                    transcription_factor=tf2,
                    direction=eukaryote.RegulatoryDirection.repression)
            ]) 

        reg_module2 = eukaryote.RegulatoryModule(
            gene=gene1,
            promoter=promoter1,
            activity=eukaryote.ActivityLevel.active,
            type=eukaryote.RegulationType.distal,
            transcription_factor_regulation=[eukaryote.TranscriptionFactorRegulation(
                transcription_factor=tf1,
                direction=eukaryote.RegulatoryDirection.repression)]) 

        reg_module3 = eukaryote.RegulatoryModule(
            id='rm3',
            name='reg_module3',
            activity=eukaryote.ActivityLevel.inactive,
            gene=gene2,
            promoter=promoter2)

        self.assertEqual(reg_module1.gene, gene1)
        self.assertEqual(reg_module1.promoter, promoter1)
        self.assertEqual(reg_module1.activity.name, 'active')
        self.assertEqual(reg_module1.type.value, 1)
        self.assertEqual(sorted([i.transcription_factor.id for i in reg_module1.transcription_factor_regulation]), 
            ['tf1', 'tf2'])
        self.assertEqual(sorted([i.direction.name for i in reg_module1.transcription_factor_regulation]), 
            ['activation', 'repression'])
        self.assertEqual(reg_module2.gene, gene1)
        self.assertEqual(reg_module2.promoter, promoter1)
        self.assertEqual(reg_module2.activity.name, 'active')
        self.assertEqual(reg_module2.type.value, 2)
        self.assertEqual(reg_module2.transcription_factor_regulation[0].transcription_factor, tf1)
        self.assertEqual(reg_module2.transcription_factor_regulation[0].direction.name, 'repression')
        self.assertEqual(reg_module3.id, 'rm3')
        self.assertEqual(reg_module3.activity.name, 'inactive')
        self.assertEqual(reg_module3.name, 'reg_module3')
        self.assertEqual(reg_module3.promoter, promoter2)
Пример #6
0
    def test_constructor(self):
        dna1 = core.DnaSpeciesType(id='dna1', sequence_path=self.sequence_path)
        gene1 = eukaryote.GeneLocus(polymer=dna1, start=1, end=15)

        transcript1 = eukaryote.TranscriptSpeciesType(
            id='t1',
            name='transcript1',
            gene=gene1,
            type=eukaryote.TranscriptType.mRna)

        self.assertEqual(transcript1.id, 't1')
        self.assertEqual(transcript1.name, 'transcript1')
        self.assertEqual(transcript1.gene, gene1)
        self.assertEqual(transcript1.type.name, 'mRna')
        self.assertEqual(transcript1.exons, [])
        self.assertEqual(transcript1.comments, '')
        self.assertEqual(transcript1.references, [])
        self.assertEqual(transcript1.identifiers, [])

        exon1 = eukaryote.GenericLocus(start=1, end=1)
        exon2 = eukaryote.GenericLocus(start=2, end=2)
        transcript1.exons = [exon1, exon2]
        transcript2 = eukaryote.TranscriptSpeciesType(id='t2',
                                                      name='transcript2',
                                                      gene=gene1,
                                                      exons=[exon2])

        self.assertEqual(transcript1.exons, [exon1, exon2])
        self.assertEqual(transcript2.exons, [exon2])
Пример #7
0
    def setUp(self):
        # Mycoplasma Genintalium Genome
        dna1 = core.DnaSpeciesType(
            id='chromosome', sequence_path='tests/fixtures/prokaryote_seq.fna')

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

        # MPN001
        self.prot1 = prokaryote.ProteinSpeciesType(id='prot1', cell=cell1)
        gene1 = prokaryote.GeneLocus(id='gene1',
                                     cell=cell1,
                                     proteins=self.prot1,
                                     polymer=dna1,
                                     start=692,
                                     end=1834)
        tu1 = prokaryote.TranscriptionUnitLocus(id='tu1',
                                                genes=[gene1],
                                                polymer=dna1)

        # MPN011
        self.prot2 = prokaryote.ProteinSpeciesType(id='prot2', cell=cell1)
        gene2 = prokaryote.GeneLocus(id='gene2',
                                     cell=cell1,
                                     proteins=self.prot2,
                                     polymer=dna1,
                                     start=12838,
                                     end=13533,
                                     strand=core.PolymerStrand.negative)
        tu2 = prokaryote.TranscriptionUnitLocus(id='tu2',
                                                genes=[gene2],
                                                polymer=dna1)
Пример #8
0
    def test_constructor(self):
        dna1 = core.DnaSpeciesType(id='dna1', sequence_path=self.sequence_path)
        gene1 = eukaryote_schema.GeneLocus(polymer=dna1, start=1, end=15)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)

        transcript1 = eukaryote_schema.TranscriptSpeciesType(
            id='t1', name='transcript1', rna=rna1, half_life=2)

        self.assertEqual(transcript1.id, 't1')
        self.assertEqual(transcript1.name, 'transcript1')
        self.assertEqual(transcript1.rna, rna1)
        self.assertEqual(transcript1.half_life, 2)
        self.assertEqual(transcript1.exons, [])
        self.assertEqual(transcript1.comments, '')
        self.assertEqual(transcript1.references, [])
        self.assertEqual(transcript1.database_references, [])

        exon1 = eukaryote_schema.ExonLocus(start=1, end=1)
        exon2 = eukaryote_schema.ExonLocus(start=2, end=2)
        transcript1.exons = [exon1, exon2]
        transcript2 = eukaryote_schema.TranscriptSpeciesType(
            id='t2', name='transcript2', rna=rna1, exons=[exon2])

        self.assertEqual(transcript1.exons, [exon1, exon2])
        self.assertEqual(transcript2.exons, [exon2])
Пример #9
0
    def setUp(self):
        self.dir = tempfile.mkdtemp()
        self.seq_path = os.path.join(self.dir, 'seq.fna')

        self.kb = kb = core.KnowledgeBase(id='genus_species', name='Genus species', version='0.0.1')

        cell = kb.cell = core.Cell(id='genus_species_cell')

        dna_seqs = []
        for i_chr in range(5):
            dna = core.DnaSpeciesType(id='chr_{}'.format(i_chr + 1), sequence_path=self.seq_path)
            cell.species_types.append(dna)
                
            seq_len = random.randint(100, 200)
            bases = 'ACGT'
            seq = ''
            for i_nt in range(seq_len):
                seq += bases[random.randint(0, 3)]
            dna_seqs.append(Bio.SeqRecord.SeqRecord(
                    Bio.Seq.Seq(seq), dna.id))              
                
            for i_trn in range(5):
                trn = prokaryote_schema.TranscriptionUnitLocus(id='tu_{}_{}'.format(i_chr + 1, i_trn + 1))
                trn.cell = cell
                dna.loci.append(trn)
                trn.start = random.randint(100, 200)
                trn.end = ((trn.start + random.randint(1, 200) - 1) % seq_len) + 1
                trn.strand = core.PolymerStrand.positive

        with open(self.seq_path, 'w') as file:
            writer = Bio.SeqIO.FastaIO.FastaWriter(
                    file, wrap=70, record2title=lambda record: record.id)
            writer.write_file(dna_seqs)            
Пример #10
0
    def test_get_mol_wt(self):
        dna1 = core.DnaSpeciesType(id='dna6', sequence_path=self.sequence_path)
        gene1 = eukaryote_schema.GeneLocus(polymer=dna1, start=1, end=6)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)

        exon1 = eukaryote_schema.ExonLocus(start=1, end=1)
        transcript1 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon1])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(transcript1.get_seq()) \
            - (transcript1.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(transcript1.get_mol_wt(), exp_mol_wt, places=1)

        exon2 = eukaryote_schema.ExonLocus(start=3, end=3)
        transcript2 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon2])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(transcript2.get_seq()) \
            - (transcript2.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(transcript2.get_mol_wt(), exp_mol_wt, places=1)

        exon3 = eukaryote_schema.ExonLocus(start=5, end=5)
        transcript3 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon3])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(transcript3.get_seq()) \
            - (transcript3.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(transcript3.get_mol_wt(), exp_mol_wt, places=1)
Пример #11
0
    def test_get_mol_wt(self):
        dna1 = core.DnaSpeciesType(id='dna6', sequence_path=self.sequence_path)
        gene1 = eukaryote.GeneLocus(polymer=dna1, start=1, end=6)

        exon1 = eukaryote.GenericLocus(start=1, end=1)
        transcript1 = eukaryote.TranscriptSpeciesType(gene=gene1, exons=[exon1])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(transcript1.get_seq()) \
            - (transcript1.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(transcript1.get_mol_wt(), exp_mol_wt, places=1)

        exon2 = eukaryote.GenericLocus(start=3, end=3)
        transcript2 = eukaryote.TranscriptSpeciesType(gene=gene1, exons=[exon2])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(transcript2.get_seq()) \
            - (transcript2.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(transcript2.get_mol_wt(), exp_mol_wt, places=1)

        exon3 = eukaryote.GenericLocus(start=5, end=5)
        transcript3 = eukaryote.TranscriptSpeciesType(gene=gene1, exons=[exon3])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(transcript3.get_seq()) \
            - (transcript3.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(transcript3.get_mol_wt(), exp_mol_wt, places=1)

        # Test using input sequence
        test_trans = eukaryote.TranscriptSpeciesType()
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(transcript1.get_seq()) \
            - (transcript1.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(test_trans.get_mol_wt(seq_input=Bio.Seq.Seq('A')), exp_mol_wt, places=1)
Пример #12
0
    def test_get_seq(self):
        dna1 = core.DnaSpeciesType(id='dna2', sequence_path=self.sequence_path)

        gene1 = eukaryote_schema.GeneLocus(polymer=dna1,
                                           start=1,
                                           end=15,
                                           strand=core.PolymerStrand.positive)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)

        exon1 = eukaryote_schema.ExonLocus(start=1, end=4)
        exon2 = eukaryote_schema.ExonLocus(start=7, end=8)
        transcript1 = eukaryote_schema.TranscriptSpeciesType(
            rna=rna1, exons=[exon1, exon2])

        gene2 = eukaryote_schema.GeneLocus(polymer=dna1,
                                           start=4,
                                           end=18,
                                           strand=core.PolymerStrand.negative)
        rna2 = eukaryote_schema.PreRnaSpeciesType(gene=gene2)
        exon1 = eukaryote_schema.ExonLocus(start=4, end=10)
        exon2 = eukaryote_schema.ExonLocus(start=14, end=16)
        transcript2 = eukaryote_schema.TranscriptSpeciesType(
            rna=rna2, exons=[exon1, exon2])

        self.assertEqual(transcript1.get_seq(), 'ACUGUU')
        self.assertEqual(transcript2.get_seq(), 'ACGGUAACUC')
Пример #13
0
    def test_get_charge(self):
        dna1 = core.DnaSpeciesType(id='dna3', sequence_path=self.sequence_path)

        gene1 = eukaryote_schema.GeneLocus(polymer=dna1, start=1, end=1)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)
        self.assertEqual(rna1.get_charge(), -2)

        gene2 = eukaryote_schema.GeneLocus(polymer=dna1, start=2, end=3)
        rna2 = eukaryote_schema.PreRnaSpeciesType(gene=gene2)
        self.assertEqual(rna2.get_charge(), -3)
Пример #14
0
    def test_get_empirical_formula(self):
        dna1 = core.DnaSpeciesType(id='dna3', sequence_path=self.sequence_path)
        gene1 = eukaryote.GeneLocus(polymer=dna1, start=1, end=4)

        exon1 = eukaryote.GenericLocus(start=1, end=1)
        transcript1 = eukaryote.TranscriptSpeciesType(gene=gene1,
                                                      exons=[exon1])
        self.assertEqual(transcript1.get_empirical_formula(),
                         chem.EmpiricalFormula('C10H12N5O7P'))

        exon2 = eukaryote.GenericLocus(start=2, end=2)
        transcript2 = eukaryote.TranscriptSpeciesType(gene=gene1,
                                                      exons=[exon2])
        self.assertEqual(transcript2.get_empirical_formula(),
                         chem.EmpiricalFormula('C9H12N3O8P'))

        exon3 = eukaryote.GenericLocus(start=3, end=3)
        transcript3 = eukaryote.TranscriptSpeciesType(gene=gene1,
                                                      exons=[exon3])
        self.assertEqual(transcript3.get_empirical_formula(),
                         chem.EmpiricalFormula('C10H12N5O8P'))

        exon4 = eukaryote.GenericLocus(start=4, end=4)
        transcript4 = eukaryote.TranscriptSpeciesType(gene=gene1,
                                                      exons=[exon4])
        self.assertEqual(transcript4.get_empirical_formula(),
                         chem.EmpiricalFormula('C9H11N2O9P'))

        dna2 = core.DnaSpeciesType(id='dna4', sequence_path=self.sequence_path)
        gene2 = eukaryote.GeneLocus(polymer=dna2, start=1, end=4)
        exon5_1 = eukaryote.GenericLocus(start=1, end=1)
        exon5_2 = eukaryote.GenericLocus(start=3, end=3)
        transcript5 = eukaryote.TranscriptSpeciesType(gene=gene2,
                                                      exons=[exon5_1, exon5_2])
        self.assertEqual(transcript5.get_empirical_formula(),
                         chem.EmpiricalFormula('C20H23N10O13P2'))

        # Test using input sequence
        test_trans = eukaryote.TranscriptSpeciesType()
        self.assertEqual(
            test_trans.get_empirical_formula(seq_input=Bio.Seq.Seq('AA')),
            chem.EmpiricalFormula('C20H23N10O13P2'))
Пример #15
0
    def test_get_charge(self):
        dna1 = core.DnaSpeciesType(id='dna6', sequence_path=self.sequence_path)
        tu1 = prokaryote_schema.TranscriptionUnitLocus(id='tu1',
                                                       polymer=dna1,
                                                       start=1,
                                                       end=1)
        rna1 = prokaryote_schema.RnaSpeciesType(id='rna1',
                                                name='rna1',
                                                transcription_units=[tu1])
        self.assertEqual(rna1.get_charge(), -2)

        dna1 = core.DnaSpeciesType(id='dna6', sequence_path=self.sequence_path)
        tu1 = prokaryote_schema.TranscriptionUnitLocus(id='tu1',
                                                       polymer=dna1,
                                                       start=1,
                                                       end=2)
        rna1 = prokaryote_schema.RnaSpeciesType(id='rna1',
                                                name='rna1',
                                                transcription_units=[tu1])
        self.assertEqual(rna1.get_charge(), -3)
Пример #16
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'))
Пример #17
0
    def test_reader_error_no_cell(self):
        kb = core.KnowledgeBase(id='kb', name='kb1', version='0.0.1')
        dna = core.DnaSpeciesType(id='chr')

        core_path = os.path.join(self.dir, 'core.xlsx')
        obj_model.io.WorkbookWriter().run(core_path, [kb, dna], io.PROKARYOTE_MODEL_ORDER, include_all_attributes=False)

        seq_path = os.path.join(self.dir, 'test_seq.fna')
        with open(seq_path, 'w') as file:
            pass

        with self.assertRaisesRegex(ValueError, 'cannot contain instances'):
            io.Reader().run(core_path, seq_path)
Пример #18
0
    def test_get_mol_wt(self):
        dna1 = core.DnaSpeciesType(id='dna7', sequence_path=self.sequence_path)
        tu1 = prokaryote_schema.TranscriptionUnitLocus(id='tu1',
                                                       polymer=dna1,
                                                       start=1,
                                                       end=1)
        rna1 = prokaryote_schema.RnaSpeciesType(id='rna1',
                                                name='rna1',
                                                transcription_units=[tu1])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(rna1.get_seq()) \
            - (rna1.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(rna1.get_mol_wt(), exp_mol_wt, places=1)

        dna1 = core.DnaSpeciesType(id='dna7', sequence_path=self.sequence_path)
        tu1 = prokaryote_schema.TranscriptionUnitLocus(id='tu1',
                                                       polymer=dna1,
                                                       start=3,
                                                       end=3)
        rna1 = prokaryote_schema.RnaSpeciesType(id='rna1',
                                                name='rna1',
                                                transcription_units=[tu1])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(rna1.get_seq()) \
            - (rna1.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(rna1.get_mol_wt(), exp_mol_wt, places=1)

        dna1 = core.DnaSpeciesType(id='dna7', sequence_path=self.sequence_path)
        tu1 = prokaryote_schema.TranscriptionUnitLocus(id='tu1',
                                                       polymer=dna1,
                                                       start=5,
                                                       end=5)
        rna1 = prokaryote_schema.RnaSpeciesType(id='rna1',
                                                name='rna1',
                                                transcription_units=[tu1])
        exp_mol_wt = \
            + Bio.SeqUtils.molecular_weight(rna1.get_seq()) \
            - (rna1.get_len() + 1) * mendeleev.element('H').atomic_weight
        self.assertAlmostEqual(rna1.get_mol_wt(), exp_mol_wt, places=1)
Пример #19
0
    def test_get_empirical_formula(self):
        dna1 = core.DnaSpeciesType(id='dna3', sequence_path=self.sequence_path)
        gene1 = eukaryote_schema.GeneLocus(polymer=dna1, start=1, end=4)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)

        exon1 = eukaryote_schema.ExonLocus(start=1, end=1)
        transcript1 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon1])
        self.assertEqual(transcript1.get_empirical_formula(),
                         chem.EmpiricalFormula('C10H12N5O7P'))

        exon2 = eukaryote_schema.ExonLocus(start=2, end=2)
        transcript2 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon2])
        self.assertEqual(transcript2.get_empirical_formula(),
                         chem.EmpiricalFormula('C9H12N3O8P'))

        exon3 = eukaryote_schema.ExonLocus(start=3, end=3)
        transcript3 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon3])
        self.assertEqual(transcript3.get_empirical_formula(),
                         chem.EmpiricalFormula('C10H12N5O8P'))

        exon4 = eukaryote_schema.ExonLocus(start=4, end=4)
        transcript4 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon4])
        self.assertEqual(transcript4.get_empirical_formula(),
                         chem.EmpiricalFormula('C9H11N2O9P'))

        dna2 = core.DnaSpeciesType(id='dna4', sequence_path=self.sequence_path)
        gene2 = eukaryote_schema.GeneLocus(polymer=dna2, start=1, end=4)
        rna2 = eukaryote_schema.PreRnaSpeciesType(gene=gene2)
        exon5_1 = eukaryote_schema.ExonLocus(start=1, end=1)
        exon5_2 = eukaryote_schema.ExonLocus(start=3, end=3)
        transcript5 = eukaryote_schema.TranscriptSpeciesType(
            rna=rna2, exons=[exon5_1, exon5_2])
        self.assertEqual(transcript5.get_empirical_formula(),
                         chem.EmpiricalFormula('C20H23N10O13P2'))
Пример #20
0
    def test_reader_no_cell(self):
        kb = core.KnowledgeBase(id='kb', name='kb1', version='0.0.1')
        dna = core.DnaSpeciesType(id='chr')

        core_path = os.path.join(self.dir, 'core.xlsx')
        obj_tables.io.WorkbookWriter().run(core_path, [kb, dna],
                                           models=io.PROKARYOTE_MODELS,
                                           include_all_attributes=False)

        seq_path = os.path.join(self.dir, 'test_seq.fna')
        with open(seq_path, 'w') as file:
            pass

        io.Reader().run(core_path, seq_path=seq_path)
Пример #21
0
    def test_get_5_prime(self):
        dna1 = core.DnaSpeciesType(id='dna1', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(
            id='tu1',
            polymer=dna1,
            start=1,
            end=15,
            strand=core.PolymerStrand.positive)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(tu1.get_5_prime(), 1)

        dna1 = core.DnaSpeciesType(id='dna1', sequence_path=self.sequence_path)
        tu1 = prokaryote.TranscriptionUnitLocus(
            id='tu1',
            polymer=dna1,
            start=1,
            end=15,
            strand=core.PolymerStrand.negative)
        rna1 = prokaryote.RnaSpeciesType(id='rna1',
                                         name='rna1',
                                         transcription_units=[tu1])
        self.assertEqual(tu1.get_5_prime(), 15)
Пример #22
0
    def test_get_seq(self):
        dna1 = core.DnaSpeciesType(id='dna1', sequence_path=self.sequence_path)
        gene1 = eukaryote_schema.GeneLocus(polymer=dna1,
                                           start=1,
                                           end=15,
                                           strand=core.PolymerStrand.positive)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)

        gene2 = eukaryote_schema.GeneLocus(polymer=dna1,
                                           start=4,
                                           end=18,
                                           strand=core.PolymerStrand.negative)
        rna2 = eukaryote_schema.PreRnaSpeciesType(gene=gene2)

        self.assertEqual(rna1.get_seq(), 'ACUGAGUUACGUACG')
        self.assertEqual(rna2.get_seq(), 'AAACGUACGUAACUC')
Пример #23
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)
Пример #24
0
    def test_get_charge(self):
        dna1 = core.DnaSpeciesType(id='dna5', sequence_path=self.sequence_path)

        gene1 = eukaryote.GeneLocus(polymer=dna1, start=1, end=1)
        exon1 = eukaryote.GenericLocus(start=1, end=1)
        transcript1 = eukaryote.TranscriptSpeciesType(gene=gene1, exons=[exon1])
        self.assertEqual(transcript1.get_charge(), -2)

        gene2 = eukaryote.GeneLocus(polymer=dna1, start=2, end=4)
        exon2_1 = eukaryote.GenericLocus(start=2, end=2)
        exon2_2 = eukaryote.GenericLocus(start=4, end=4)
        transcript2 = eukaryote.TranscriptSpeciesType(gene=gene2, exons=[exon2_1, exon2_2])
        self.assertEqual(transcript2.get_charge(), -3)

        # Test using input sequence
        test_trans = eukaryote.TranscriptSpeciesType()
        self.assertEqual(test_trans.get_charge(seq_input=Bio.Seq.Seq('CG')), -3)
Пример #25
0
    def test_write_without_cell_relationships(self):
        core_path = os.path.join(self.dir, 'core.xlsx')
        seq_path = os.path.join(self.dir, 'test_seq.fna')

        with open(seq_path, 'w') as file:
            file.write('>chr_x\nACGT\n')

        dna = core.DnaSpeciesType(id='chr_x', sequence_path=seq_path)
        self.kb.cell.species_types.append(dna)

        trn = prokaryote_schema.TranscriptionUnitLocus(id='tu_x_0')
        dna.loci.append(trn)
        trn.cell = None

        writer = io.Writer()
        with self.assertRaisesRegex(ValueError, 'must be set to the instance of `Cell`'):
            writer.run(self.kb, core_path, seq_path, set_repo_metadata_from_path=False)
Пример #26
0
    def test_constructor(self):
        dna1 = core.DnaSpeciesType(id='dna1')
        gene1 = eukaryote_schema.GeneLocus(polymer=dna1, start=1, end=15)
        rna1 = eukaryote_schema.PreRnaSpeciesType(id='rna1',
                                                  name='rna1',
                                                  gene=gene1,
                                                  type=1,
                                                  half_life=2)

        self.assertEqual(rna1.id, 'rna1')
        self.assertEqual(rna1.name, 'rna1')
        self.assertEqual(rna1.gene, gene1)
        self.assertEqual(rna1.type, 1)
        self.assertEqual(rna1.half_life, 2)
        self.assertEqual(rna1.comments, '')
        self.assertEqual(rna1.references, [])
        self.assertEqual(rna1.database_references, [])
Пример #27
0
    def setUp(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\nTTTATGAARGTNCTCATHAAYAARAAYGARCTCTAGTTTTTACAGTTYCGGGGTCAGCAGAAATTTTTTCATTTT\n'
            )

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

        cell1 = dna1.cell = core.Cell()

        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(id='cds1', start=4, end=36)
        self.prot1 = eukaryote_schema.ProteinSpeciesType(
            id='prot1',
            name='protein1',
            uniprot='Q12X34',
            transcript=transcript1,
            coding_region=cds1,
            half_life=0.35)

        gene2 = eukaryote_schema.GeneLocus(polymer=dna1,
                                           start=30,
                                           end=75,
                                           strand=core.PolymerStrand.negative)
        rna2 = eukaryote_schema.PreRnaSpeciesType(gene=gene2)
        exon2_1 = eukaryote_schema.ExonLocus(start=32, end=35)
        exon2_2 = eukaryote_schema.ExonLocus(start=38, end=45)
        exon2_3 = eukaryote_schema.ExonLocus(start=49, end=54)
        exon2_4 = eukaryote_schema.ExonLocus(start=55, end=72)
        exon2_5 = eukaryote_schema.ExonLocus(start=73, end=74)
        transcript2 = eukaryote_schema.TranscriptSpeciesType(
            rna=rna2, exons=[exon2_1, exon2_2, exon2_3, exon2_4, exon2_5])
        cds2 = eukaryote_schema.CdsLocus(id='cds2', start=40, end=72)
        self.prot2 = eukaryote_schema.ProteinSpeciesType(
            id='prot2',
            name='protein2',
            uniprot='P12345',
            cell=cell1,
            transcript=transcript2,
            coding_region=cds2)
Пример #28
0
    def test_get_charge(self):
        dna1 = core.DnaSpeciesType(id='dna5', sequence_path=self.sequence_path)

        gene1 = eukaryote_schema.GeneLocus(polymer=dna1, start=1, end=1)
        rna1 = eukaryote_schema.PreRnaSpeciesType(gene=gene1)
        exon1 = eukaryote_schema.ExonLocus(start=1, end=1)
        transcript1 = eukaryote_schema.TranscriptSpeciesType(rna=rna1,
                                                             exons=[exon1])
        self.assertEqual(transcript1.get_charge(), -2)

        gene2 = eukaryote_schema.GeneLocus(polymer=dna1, start=2, end=4)
        rna2 = eukaryote_schema.PreRnaSpeciesType(gene=gene2)
        exon2_1 = eukaryote_schema.ExonLocus(start=2, end=2)
        exon2_2 = eukaryote_schema.ExonLocus(start=4, end=4)
        transcript2 = eukaryote_schema.TranscriptSpeciesType(
            rna=rna2, exons=[exon2_1, exon2_2])
        self.assertEqual(transcript2.get_charge(), -3)
Пример #29
0
    def test_constructor(self):
        dna1 = core.DnaSpeciesType(id='dna1', sequence_path=self.sequence_path)
        tu1 = prokaryote_schema.TranscriptionUnitLocus(id='tu1',
                                                       polymer=dna1,
                                                       start=1,
                                                       end=15)
        rna1 = prokaryote_schema.RnaSpeciesType(id='rna1',
                                                name='rna1',
                                                transcription_units=[tu1],
                                                type=1,
                                                half_life=2)

        self.assertEqual(rna1.id, 'rna1')
        self.assertEqual(rna1.name, 'rna1')
        self.assertEqual(rna1.transcription_units, [tu1])
        self.assertEqual(rna1.type, 1)
        self.assertEqual(rna1.half_life, 2)
Пример #30
0
    def setUp(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)

        cell1 = dna1.cell = core.Cell()

        gene1 = eukaryote.GeneLocus(polymer=dna1, start=1, end=36)
        exon1 = eukaryote.GenericLocus(start=4, end=36)
        transcript1 = eukaryote.TranscriptSpeciesType(gene=gene1,
                                                      exons=[exon1])
        cds1 = eukaryote.GenericLocus(start=4, end=36)
        self.prot1 = eukaryote.ProteinSpeciesType(id='prot1',
                                                  name='protein1',
                                                  uniprot='Q12X34',
                                                  transcript=transcript1,
                                                  coding_regions=[cds1])

        gene2 = eukaryote.GeneLocus(polymer=dna1,
                                    start=30,
                                    end=75,
                                    strand=core.PolymerStrand.positive)
        exon2_1 = eukaryote.GenericLocus(start=32, end=35)
        exon2_2 = eukaryote.GenericLocus(start=38, end=45)
        exon2_3 = eukaryote.GenericLocus(start=49, end=54)
        exon2_4 = eukaryote.GenericLocus(start=55, end=72)
        exon2_5 = eukaryote.GenericLocus(start=73, end=74)
        transcript2 = eukaryote.TranscriptSpeciesType(
            gene=gene2, exons=[exon2_1, exon2_2, exon2_3, exon2_4, exon2_5])
        cds2_2 = eukaryote.GenericLocus(start=40, end=45)
        cds2_3 = eukaryote.GenericLocus(start=49, end=54)
        cds2_4 = eukaryote.GenericLocus(start=55, end=72)
        self.prot2 = eukaryote.ProteinSpeciesType(
            id='prot2',
            name='protein2',
            uniprot='P12345',
            cell=cell1,
            transcript=transcript2,
            coding_regions=[cds2_4, cds2_2, cds2_3])