def test_reader_error_multiple_kbs(self): kb1 = core.KnowledgeBase(id='kb1', name='kb1', version='0.0.1') kb2 = core.KnowledgeBase(id='kb2', name='kb2', version='0.0.1') core_path = os.path.join(self.dir, 'core.xlsx') obj_model.io.WorkbookWriter().run(core_path, [kb1, kb2], 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, ' should define one knowledge base'): io.Reader().run(core_path, seq_path)
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)
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)
def test_set_git_repo_metadata_from_path(self): kb = core.KnowledgeBase() self.assertEqual(kb.url, '') util.set_git_repo_metadata_from_path(kb, path='.') self.assertIn(kb.url, [ 'https://github.com/KarrLab/wc_kb.git', 'ssh://[email protected]/KarrLab/wc_kb.git', '[email protected]:KarrLab/wc_kb.git', ])
def test_set_git_repo_metadata_from_path_error(self): tempdir = tempfile.mkdtemp() kb = core.KnowledgeBase() self.assertEqual(kb.url, '') with self.assertRaisesRegex(ValueError, 'is not a Git repository'): util.set_git_repo_metadata_from_path(kb, path=tempdir) self.assertEqual(kb.url, '') shutil.rmtree(tempdir)
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'))
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)
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)
def test_reader_error_multiple_cells(self): kb = core.KnowledgeBase(id='kb', name='kb1', version='0.0.1') cell1 = core.Cell(id='cell1', name='cell1') cell2 = core.Cell(id='cell2', name='cell2') core_path = os.path.join(self.dir, 'core.xlsx') obj_tables.io.WorkbookWriter().run(core_path, [kb, cell1, cell2], 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 with self.assertRaisesRegex(ValueError, ' should define zero or one cells'): io.Reader().run(core_path, seq_path=seq_path)
def test_constructor(self): kb = core.KnowledgeBase() self.assertEqual(kb.cell, None)