Exemplo n.º 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())
Exemplo n.º 2
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)
Exemplo n.º 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'))
Exemplo n.º 4
0
    def test_get_charge(self):

        dna1 = core.DnaSpeciesType(id='dna6', 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_charge(), -2)

        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_charge(), -3)
Exemplo n.º 5
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)
Exemplo n.º 6
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.TranscriptionUnitLocus(
                    id='tu_{}_{}'.format(i_chr + 1, i_trn + 1))
                trn.type = random.choice([
                    'WC:mRNA', 'WC:sRNA', 'WC:tRNA', 'WC:rRNA',
                    'WC:intergenic', 'WC:mixed'
                ])
                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)
Exemplo n.º 7
0
    def test_constructor(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],
                                         type=1)

        # make sure that only TU can be created that have valid length
        # These should throw errors:
        #tu2 = prokaryote.TranscriptionUnitLocus(id='tu1', polymer=dna1, start=1, end=20)
        #tu2 = prokaryote.TranscriptionUnitLocus(id='tu1', polymer=dna1, start=-3, end=20)

        self.assertEqual(rna1.id, 'rna1')
        self.assertEqual(rna1.name, 'rna1')
        self.assertEqual(rna1.transcription_units, [tu1])
        self.assertEqual(rna1.type, 1)
Exemplo n.º 8
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.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(core_path,
                       self.kb,
                       seq_path=seq_path,
                       data_repo_metadata=False)
Exemplo n.º 9
0
    def test_get_mol_wt(self):

        dna1 = core.DnaSpeciesType(id='dna7', 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])
        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.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=3,
                                                end=3)
        rna1 = prokaryote.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.TranscriptionUnitLocus(id='tu1',
                                                polymer=dna1,
                                                start=5,
                                                end=5)
        rna1 = prokaryote.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)

        # Adding cases that have ,multiple nucleotides
        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])
        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='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])
        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)