def test(self): kb = wc_kb.KnowledgeBase() cell = kb.cell = wc_kb.Cell() gen = properties.PropertiesGenerator(kb, options={ 'mean_doubling_time': 3600, }) gen.run() self.assertEqual(cell.properties.get_one(id='mean_doubling_time').value, 3600)
def test_generator(self): kb = wc_kb.KnowledgeBase() cell = kb.cell = wc_kb.Cell() cell.taxon = 9606 cell.parameters.create(id='cell_volume', value=1E-15) cell.parameters.create(id='mean_doubling_time', value=20., units=unit_registry.parse_units('hour')) compartments = {'c': 0.7, 'n': 0.3, 'e': None} for k, v in compartments.items(): cell.compartments.create(id=k, volumetric_fraction=v) test_component_generators = [initialize_model.InitializeModel] gen = core.EukaryoteModelGenerator( kb, component_generators=test_component_generators, options={ 'id': 'h1_test', 'name': 'h1 model', 'version': '2.3.1', 'component': { 'InitializeModel': { 'cell_density': 1100., 'gen_dna': False, 'gen_pre_rnas': False, 'gen_transcripts': False, 'gen_protein': False, 'gen_metabolites': False, 'gen_complexes': False, 'gen_distribution_init_concentrations': False, 'gen_observables': False, 'gen_kb_reactions': False, 'gen_kb_rate_laws': False, } } }) model = gen.run() self.assertEqual(model.id, 'h1_test') self.assertEqual(model.name, 'h1 model') self.assertEqual(model.version, '2.3.1') self.assertEqual( model.parameters.get_one(id='mean_doubling_time').value, 72000) self.assertEqual(model.parameters.get_one(id='density_n').value, 1100) self.assertEqual(model.parameters.get_one(id='density_e').value, 1000) self.assertEqual( model.compartments.get_one(id='n').init_volume.mean, 2.997832792664565e-16) self.assertEqual( model.compartments.get_one(id='e').init_volume.mean, 1.0)
def test_default(self): kb = wc_kb.KnowledgeBase() cell = kb.cell = wc_kb.Cell() gen = compartments.CompartmentsGenerator(kb) gen.run() cytosol = cell.compartments.get_one(id='c') self.assertEqual(cytosol.name, 'cytosol') extra = cell.compartments.get_one(id='e') self.assertEqual(extra.name, 'extracellular space')
def test_run(self): kb = wc_kb.KnowledgeBase() cell = kb.cell = wc_kb.Cell() mean_num_genes = 200 gen = chrs_genes_tus.ChromosomesGenesTusGenerator( kb, options={ 'num_chromosomes': 2, 'mean_gc_frac': 1, 'mean_num_genes': mean_num_genes, 'mean_gene_len': 100, 'mean_coding_frac': 0.75, }) gen.run() self.assertEqual(len(cell.species_types), 2) gc = 0 chr_len = 0 for chr in cell.species_types: gc += chr.seq.count('C') + chr.seq.count('G') chr_len += len(chr.seq) self.assertEqual(gc / chr_len, 1) tus = cell.loci.get(__type=wc_kb.prokaryote.TranscriptionUnitLocus) genes = cell.loci.get(__type=wc_kb.prokaryote.GeneLocus) self.assertAlmostEqual(len(tus), mean_num_genes, delta=5 * numpy.sqrt(mean_num_genes)) self.assertAlmostEqual(len(genes), mean_num_genes, delta=5 * numpy.sqrt(mean_num_genes)) mu = 100 / 0.75 * 0.25 / 2 self.assertAlmostEqual(genes[0].start, mu, delta=5 * numpy.sqrt(mu)) gene_len = 0 gene_pos = 0 for gene in genes: gene_len += gene.get_len() gene_pos += gene.strand == wc_kb.core.PolymerStrand.positive self.assertAlmostEqual(gene_len / len(genes), 100, delta=5 * numpy.sqrt(100 / 100)) self.assertAlmostEqual(gene_pos / len(genes), 0.5, delta=5 * numpy.sqrt((1 - 0.5) * 0.5 / 100)) self.assertAlmostEqual(gene_len / chr_len, 0.75, delta=5 * numpy.sqrt((1 - 0.75) * 0.75 / 100))
def test(self): kb = wc_kb.KnowledgeBase() cell = kb.cell = wc_kb.Cell() cell.properties.create(id='mean_volume', value=1, units=unit_registry.parse_units('L')) cytosol = cell.compartments.get_one(id='c') tus = [] for i_tu in range(1000): tu = cell.loci.create( __type=wc_kb.prokaryote.TranscriptionUnitLocus, id='tu_{}'.format(i_tu + 1), name='Transcription unit {}'.format(i_tu + 1), start=10 + 20 * (i_tu), end=20 + 20 * (i_tu), strand=wc_kb.core.PolymerStrand.positive) tu.genes.create(id='gene_{}'.format(i_tu + 1), type=wc_kb.core.GeneType.mRna) tus.append(tu) gen = kb_gen.rna.RnaGenerator(kb, options={ 'mean_copy_number': 10., 'mean_half_life': 120., }) gen.run() rnas = cell.species_types.get(__type=wc_kb.prokaryote.RnaSpeciesType) self.assertEqual(len(rnas), 1000) self.assertEqual(rnas[0].transcription_units, [tus[0]]) self.assertEqual(rnas[0].name, 'RNA 1') self.assertEqual(rnas[0].type, wc_kb.core.RnaType.mRna) concs = [ rna.species.get_one(compartment=cytosol).concentration.value for rna in rnas ] half_lives = [rna.half_life for rna in rnas] self.assertAlmostEqual(numpy.mean(concs), 10. / scipy.constants.Avogadro / 1., delta=5. * numpy.sqrt(10. / 1000.)) self.assertAlmostEqual(numpy.mean(half_lives), 120., delta=5. * numpy.sqrt(120. / 1000.))
def test_run(self): kb = wc_kb.KnowledgeBase() cell = kb.cell = wc_kb.Cell() gen = compartments.CompartmentsGenerator(kb, options={ 'compartments': [('c', 'cytosol'), ('e', 'extracellular space'), ('t', 'test')] }) gen.run() cytosol = cell.compartments.get_one(id='c') self.assertEqual(cytosol.name, 'cytosol') extra = cell.compartments.get_one(id='e') self.assertEqual(extra.name, 'extracellular space') test = cell.compartments.get_one(id='t') self.assertEqual(test.name, 'test')
def test_validate_exception(self): kb = wc_kb.KnowledgeBase(id='kb', name='KB', version='0.0.1a', wc_kb_version='0.0.1') kb.cell = wc_kb.Cell(id='cell') kb.cell.compartments.create(id='c') kb.cell.compartments.create(id='c') self.assertNotEqual(Validator().run(kb, get_related=True), None) filename_core = path.join(self.tempdir, 'core.xlsx') filename_seq = path.join(self.tempdir, 'seq.fna') io.Writer().run(kb, filename_core, filename_seq, set_repo_metadata_from_path=False) with self.assertRaisesRegex(SystemExit, '^Knowledge base is invalid: '): with __main__.App( argv=['validate', filename_core, filename_seq]) as app: app.run()
def test_run(self): kb = wc_kb.KnowledgeBase() cell = kb.cell = wc_kb.Cell() gen = metabolites.MetabolitesGenerator(kb, options={ 'data_path': self.data_path, }) gen.run() h2o = cell.species_types.get_one( __type=wc_kb.core.MetaboliteSpeciesType, id='h2o') self.assertEqual(h2o.get_empirical_formula(), wc_utils.util.chem.EmpiricalFormula('H2O')) self.assertEqual(h2o.get_charge(), 0) concs = cell.concentrations.get(__type=wc_kb.core.Concentration, value=55.) self.assertEqual(len(concs), 2) c = cell.compartments.get_one(id='c') e = cell.compartments.get_one(id='e') h2o_c = h2o.species.get_one(compartment=c) h2o_e = h2o.species.get_one(compartment=e) self.assertEqual(set([conc.species for conc in concs]), set([h2o_c, h2o_e])) h = cell.species_types.get_one(__type=wc_kb.core.MetaboliteSpeciesType, id='h') self.assertEqual(h.get_empirical_formula(), wc_utils.util.chem.EmpiricalFormula('H')) self.assertEqual(h.get_charge(), 1) self.assertEqual( cell.concentrations.get_one(__type=wc_kb.core.Concentration, value=1e-6).species.species_type, h) self.assertEqual( cell.concentrations.get_one(__type=wc_kb.core.Concentration, value=1e-6).species.compartment, c)
def setUp(self): # Create KB content self.tmp_dirname = tempfile.mkdtemp() self.sequence_path = os.path.join(self.tmp_dirname, 'test_seq.fasta') with open(self.sequence_path, 'w') as f: f.write('>chr1\nGCGTGCGATGAT\n' '>chrM\nNGCGTGCGATGAT\n' '>chrX\nATGtgaGCGtgatga\n') self.kb = wc_kb.KnowledgeBase() cell = self.kb.cell = wc_kb.Cell() chr1 = wc_kb.core.DnaSpeciesType(cell=cell, id='chr1', sequence_path=self.sequence_path) gene1 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene1', polymer=chr1, start=1, end=12) chrM = wc_kb.core.DnaSpeciesType(cell=cell, id='chrM', sequence_path=self.sequence_path) geneM = wc_kb.eukaryote.GeneLocus(cell=cell, id='geneM', polymer=chrM, start=2, end=13) chrX = wc_kb.core.DnaSpeciesType(cell=cell, id='chrX', sequence_path=self.sequence_path) geneX1 = wc_kb.eukaryote.GeneLocus(cell=cell, id='geneX1', polymer=chrX, start=1, end=15) geneX2 = wc_kb.eukaryote.GeneLocus(cell=cell, id='geneX2', polymer=chrX, start=1, end=15) locus1 = wc_kb.eukaryote.GenericLocus(start=1, end=6) transcript1 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=gene1, exons=[locus1]) prot1 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='prot1', name='protein1', transcript=transcript1, coding_regions=[locus1]) prot1_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=prot1, value='40000.0', value_type=wc_ontology['WC:float']) locus2 = wc_kb.eukaryote.GenericLocus(start=4, end=9) transcript2 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=gene1, exons=[locus2]) prot2 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='prot2', name='protein2', transcript=transcript2, coding_regions=[locus2]) prot2_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=prot2, value='40000.0', value_type=wc_ontology['WC:float']) locus3 = wc_kb.eukaryote.GenericLocus(start=7, end=12) transcript3 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=gene1, exons=[locus3]) prot3 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='prot3', name='protein3', transcript=transcript3, coding_regions=[locus3]) prot3_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=prot3, value='25000.0', value_type=wc_ontology['WC:float']) locusM = wc_kb.eukaryote.GenericLocus(start=8, end=13) transcriptM = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=geneM, exons=[locusM]) protM = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='protM', name='proteinM', transcript=transcriptM, coding_regions=[locusM]) protM_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=protM, value='25000.0', value_type=wc_ontology['WC:float']) locusX1 = wc_kb.eukaryote.GenericLocus(start=1, end=15) transcriptX1 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=geneX1, exons=[locusX1]) protX1 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='protX1', name='proteinX1', transcript=transcriptX1, coding_regions=[locusX1]) protX1_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=protX1, value='25000.0', value_type=wc_ontology['WC:float']) locusX2 = wc_kb.eukaryote.GenericLocus(start=1, end=15) transcriptX2 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=geneX2, exons=[locusX2]) protX2 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='protX2', name='proteinX2', transcript=transcriptX2, coding_regions=[locusX2]) protX2_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=protX2, value='25000.0', value_type=wc_ontology['WC:float']) # Create initial model content self.model = model = wc_lang.Model() model.parameters.create( id='Avogadro', value=scipy.constants.Avogadro, units=unit_registry.parse_units('molecule mol^-1')) compartments = { 'n': ('nucleus', 5E-14), 'c': ('cytoplasm', 1E-13), 'm': ('mitochondria', 2.5E-14), 'l': ('lysosome', 1.5E-14), 'c_m': ('membrane', 5E-15) } for k, v in compartments.items(): init_volume = wc_lang.core.InitVolume( distribution=wc_ontology['WC:normal_distribution'], mean=v[1], std=0) c = model.compartments.create(id=k, name=v[0], init_volume=init_volume) c.init_density = model.parameters.create( id='density_' + k, value=1000, units=unit_registry.parse_units('g l^-1')) volume = model.functions.create( id='volume_' + k, units=unit_registry.parse_units('l')) volume.expression, error = wc_lang.FunctionExpression.deserialize( f'{c.id} / {c.init_density.id}', { wc_lang.Compartment: { c.id: c }, wc_lang.Parameter: { c.init_density.id: c.init_density }, }) assert error is None, str(error) proteins = { 'prot1': ['n', 'c'], 'prot2': ['c', 'l'], 'prot3': ['l'], 'protM': ['m', 'c_m'], 'protX1': ['l'], 'protX2': ['l'] } for k, v in proteins.items(): kb_protein = cell.species_types.get_one(id=k) model_species_type = model.species_types.create( id=kb_protein.id, name=kb_protein.name, type=wc_ontology['WC:protein']) for comp in v: model_compartment = model.compartments.get_one(id=comp) model_species = model.species.create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=10, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() model.distribution_init_concentrations.get_one( id='dist-init-conc-protM[m]').mean = 0. complexes = { 'comp_1': ('26S proteasome', ['n', 'c']), 'comp_2': ('lonp1', ['m']), 'comp_3': ('clpp', ['m']), 'comp_4': ('cathepsin B', ['l']), 'comp_5': ('cathepsin D', ['l']) } for k, v in complexes.items(): model_species_type = model.species_types.create( id=k, name=v[0], type=wc_ontology['WC:pseudo_species']) for comp in v[1]: model_compartment = model.compartments.get_one(id=comp) model_species = model.species.create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=2, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() metabolic_participants = [ 'Ala', 'Cys', 'Asp', 'Glu', 'Met', 'Selcys', 'h2o' ] metabolic_compartments = ['l', 'm'] for i in metabolic_participants: for c in metabolic_compartments: model_species_type = model.species_types.get_or_create( id=i, type=wc_ontology['WC:metabolite']) model_compartment = model.compartments.get_one(id=c) model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id()
def setUp(self): # Create KB content self.tmp_dirname = tempfile.mkdtemp() self.sequence_path = os.path.join(self.tmp_dirname, 'test_seq.fasta') with open(self.sequence_path, 'w') as f: f.write('>chr1\nTTTATGACTCTAGTTTAT\n' '>chrM\nTTTatgaCTCTAGTTTAT\n') self.kb = wc_kb.KnowledgeBase() cell = self.kb.cell = wc_kb.Cell() nucleus = cell.compartments.create(id='n') mito = cell.compartments.create(id='m') cytoplasm = cell.compartments.create(id='c') chr1 = wc_kb.core.DnaSpeciesType(cell=cell, id='chr1', sequence_path=self.sequence_path) gene1 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene1', polymer=chr1, start=1, end=18) exon1 = wc_kb.eukaryote.GenericLocus(start=4, end=18) transcript1 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans1', name='transcript1', gene=gene1, exons=[exon1]) transcript1_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript1, value='36000.0', value_type=wc_ontology['WC:float']) transcript1_spec = wc_kb.core.Species(species_type=transcript1, compartment=cytoplasm) transcript1_conc = wc_kb.core.Concentration(cell=cell, species=transcript1_spec, value=10.) chrM = wc_kb.core.DnaSpeciesType(cell=cell, id='chrM', sequence_path=self.sequence_path) gene2 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene2', polymer=chrM, start=1, end=18) exon2 = wc_kb.eukaryote.GenericLocus(start=1, end=10) transcript2 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans2', name='transcript2', gene=gene2, exons=[exon2]) transcript2_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript2, value='15000.0', value_type=wc_ontology['WC:float']) transcript2_spec = wc_kb.core.Species(species_type=transcript2, compartment=mito) transcript2_conc = wc_kb.core.Concentration(cell=cell, species=transcript2_spec, value=10.) transcript3 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans3', name='transcript3', gene=gene2, exons=[exon2]) transcript3_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript3, value='36000.0', value_type=wc_ontology['WC:float']) transcript3_spec = wc_kb.core.Species(species_type=transcript3, compartment=mito) transcript3_conc = wc_kb.core.Concentration(cell=cell, species=transcript3_spec, value=10.) transcript4 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans4', name='transcript4', gene=gene2, exons=[exon2]) transcript4_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript4, value='36000.0', value_type=wc_ontology['WC:float']) transcript4_spec = wc_kb.core.Species(species_type=transcript4, compartment=mito) transcript4_conc = wc_kb.core.Concentration(cell=cell, species=transcript4_spec, value=0.) transcript5 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans5', name='transcript5', gene=gene2) transcript5_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript5, value='36000.0', value_type=wc_ontology['WC:float']) transcript5_spec = wc_kb.core.Species(species_type=transcript5, compartment=mito) transcript5_conc = wc_kb.core.Concentration(cell=cell, species=transcript5_spec, value=0.) # Create initial model content self.model = model = wc_lang.Model() model.parameters.create( id='Avogadro', value=scipy.constants.Avogadro, units=unit_registry.parse_units('molecule mol^-1')) compartments = { 'n': ('nucleus', 5E-14), 'm': ('mitochondria', 2.5E-14), 'c': ('cytoplasm', 9E-14) } for k, v in compartments.items(): init_volume = wc_lang.core.InitVolume( distribution=wc_ontology['WC:normal_distribution'], mean=v[1], std=0) c = model.compartments.create(id=k, name=v[0], init_volume=init_volume) c.init_density = model.parameters.create( id='density_' + k, value=1000, units=unit_registry.parse_units('g l^-1')) volume = model.functions.create( id='volume_' + k, units=unit_registry.parse_units('l')) volume.expression, error = wc_lang.FunctionExpression.deserialize( f'{c.id} / {c.init_density.id}', { wc_lang.Compartment: { c.id: c }, wc_lang.Parameter: { c.init_density.id: c.init_density }, }) assert error is None, str(error) for i in cell.species_types.get( __type=wc_kb.eukaryote.TranscriptSpeciesType): model_species_type = model.species_types.create(id=i.id, name=i.name) model_compartment = model.compartments.get_one( id='m' if 'M' in i.gene.polymer.id else 'c') model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=10., units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() model.distribution_init_concentrations.get_one( id='dist-init-conc-trans4[m]').mean = 0. ribo_site_species_type = model.species_types.create( id='trans2_ribosome_binding_site') mitochondria = model.compartments.get_one(id='m') ribo_site_species = model.species.create( species_type=ribo_site_species_type, compartment=mitochondria) ribo_site_species.id = ribo_site_species.gen_id() conc_ribo_site_species = model.distribution_init_concentrations.create( species=ribo_site_species, mean=20, units=unit_registry.parse_units('molecule')) conc_ribo_site_species.id = conc_ribo_site_species.gen_id() complexes = { 'complex1': ('Exosome', ['c', 'n']), 'complex2': ('Exosome variant', ['c', 'n']), 'complex3': ('Mitochondrial Exosome', ['m']), 'complex4': ('Mitochondrial Exosome variant', ['m']) } for k, v in complexes.items(): model_species_type = model.species_types.get_or_create(id=k, name=v[0]) for comp in v[1]: model_compartment = model.compartments.get_one(id=comp) model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=100., units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() metabolic_participants = ['amp', 'cmp', 'gmp', 'ump', 'h2o', 'h'] for i in metabolic_participants: model_species_type = model.species_types.create(id=i) for c in ['n', 'm', 'c']: model_compartment = model.compartments.get_one(id=c) model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=1500., units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id()
def setUp(self): # Create KB content self.tmp_dirname = tempfile.mkdtemp() self.sequence_path = os.path.join(self.tmp_dirname, 'test_seq.fasta') with open(self.sequence_path, 'w') as f: f.write('>chr1\nGCGTGCGATGATtgatga\n') self.kb = wc_kb.KnowledgeBase() cell = self.kb.cell = wc_kb.Cell() nucleus = cell.compartments.create(id='n') mito = cell.compartments.create(id='m') lysosome = cell.compartments.create(id='l') membrane = cell.compartments.create(id='c_m') chr1 = wc_kb.core.DnaSpeciesType(cell=cell, id='chr1', sequence_path=self.sequence_path) gene1 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene1', polymer=chr1, start=1, end=18) locus1 = wc_kb.eukaryote.GenericLocus(start=1, end=6) transcript1 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=gene1, exons=[locus1]) prot1 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='prot1', name='protein1', transcript=transcript1, coding_regions=[locus1]) prot1_half_life = wc_kb.core.SpeciesTypeProperty(property='half-life', species_type=prot1, value='40000.0', value_type=wc_ontology['WC:float']) prot1_spec = wc_kb.core.Species(species_type=prot1, compartment=nucleus) locus2 = wc_kb.eukaryote.GenericLocus(start=4, end=9) transcript2 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=gene1, exons=[locus2]) prot2 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='prot2', name='protein2', transcript=transcript2, coding_regions=[locus2]) prot2_half_life = wc_kb.core.SpeciesTypeProperty(property='half-life', species_type=prot2, value='20000.0', value_type=wc_ontology['WC:float']) prot2_spec = wc_kb.core.Species(species_type=prot2, compartment=nucleus) locus3 = wc_kb.eukaryote.GenericLocus(start=7, end=12) transcript3 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=gene1, exons=[locus3]) prot3 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='prot3', name='protein3', transcript=transcript3, coding_regions=[locus3]) prot3_half_life = wc_kb.core.SpeciesTypeProperty(property='half-life', species_type=prot3, value='25000.0', value_type=wc_ontology['WC:float']) prot3_spec1 = wc_kb.core.Species(species_type=prot3, compartment=nucleus) prot3_spec2 = wc_kb.core.Species(species_type=prot3, compartment=mito) prot3_spec3 = wc_kb.core.Species(species_type=prot3, compartment=membrane) locus4 = wc_kb.eukaryote.GenericLocus(start=10, end=18) transcript4 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, gene=gene1, exons=[locus4]) prot4 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='prot4', name='protein4', transcript=transcript4, coding_regions=[locus4]) prot4_half_life = wc_kb.core.SpeciesTypeProperty(property='half-life', species_type=prot4, value='40000.0', value_type=wc_ontology['WC:float']) prot4_spec = wc_kb.core.Species(species_type=prot4, compartment=nucleus) met1 = wc_kb.core.MetaboliteSpeciesType(cell=cell, id='met1', name='metabolite1') for i in cell.compartments: met1_species = wc_kb.core.Species(species_type=met1, compartment=i) complex1 = wc_kb.core.ComplexSpeciesType(cell=cell, id='complex_1', subunits=[ wc_kb.core.SpeciesTypeCoefficient(species_type=prot1, coefficient=1), wc_kb.core.SpeciesTypeCoefficient(species_type=prot2, coefficient=2), wc_kb.core.SpeciesTypeCoefficient(species_type=prot3, coefficient=0), ]) complex2 = wc_kb.core.ComplexSpeciesType(cell=cell, id='complex_2', subunits=[ wc_kb.core.SpeciesTypeCoefficient(species_type=prot3, coefficient=2), wc_kb.core.SpeciesTypeCoefficient(species_type=met1, coefficient=2), ]) complex3 = wc_kb.core.ComplexSpeciesType(cell=cell, id='complex_3', subunits=[ wc_kb.core.SpeciesTypeCoefficient(species_type=prot4, coefficient=2), ]) # Create initial model content self.model = model = wc_lang.Model() model.parameters.create(id='Avogadro', value = scipy.constants.Avogadro, units = unit_registry.parse_units('molecule mol^-1')) compartments = {'n': ('nucleus', 5E-14), 'm': ('mitochondria', 2.5E-14), 'l': ('lysosome', 2.5E-14), 'c_m': ('membrane', 5E-15)} for k, v in compartments.items(): init_volume = wc_lang.core.InitVolume(distribution=wc_ontology['WC:normal_distribution'], mean=v[1], std=0) c = model.compartments.create(id=k, name=v[0], init_volume=init_volume) c.init_density = model.parameters.create(id='density_' + k, value=1000, units=unit_registry.parse_units('g l^-1')) volume = model.functions.create(id='volume_' + k, units=unit_registry.parse_units('l')) volume.expression, error = wc_lang.FunctionExpression.deserialize(f'{c.id} / {c.init_density.id}', { wc_lang.Compartment: {c.id: c}, wc_lang.Parameter: {c.init_density.id: c.init_density}, }) assert error is None, str(error) for i in cell.species_types.get(__type=wc_kb.eukaryote.ProteinSpeciesType): model_species_type = model.species_types.get_or_create(id=i.id, name=i.name, type=wc_ontology['WC:protein']) model_compartment = model.compartments.get_one(id='n') model_species = model.species.get_or_create(species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.get_or_create(species=model_species, mean=10, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() model_species_type = model.species_types.get_or_create(id='prot3', name='protein3', type=wc_ontology['WC:protein']) model_mito = model.compartments.get_one(id='m') model_species = model.species.get_or_create(species_type=model_species_type, compartment=model_mito) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create(species=model_species, mean=20, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() model_membrane = model.compartments.get_one(id='c_m') model_species = model.species.get_or_create(species_type=model_species_type, compartment=model_membrane) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create(species=model_species, mean=20, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() model_species_type = model.species_types.get_or_create(id='met1', name='metabolite1', type=wc_ontology['WC:metabolite']) for compartment in model.compartments: model_species = model.species.get_or_create(species_type=model_species_type, compartment=compartment) model_species.id = model_species.gen_id() for compl in [complex1, complex2, complex3]: model_species_type = model.species_types.create(id=compl.id, type=wc_ontology['WC:pseudo_species']) subunit_compartments = [[s.compartment.id for s in sub.species_type.species] for sub in compl.subunits] if len(subunit_compartments) == 1: shared_compartments = set(subunit_compartments[0]) else: shared_compartments = set([]) for i in range(len(subunit_compartments)): shared_compartments = (set(subunit_compartments[i]) if i==0 else shared_compartments).intersection( set(subunit_compartments[i+1]) if i<(len(subunit_compartments)-1) else shared_compartments) compartment_ids = set(list(shared_compartments)) for compartment_id in compartment_ids: model_compartment = model.compartments.get_one(id=compartment_id) model_species = model.species.get_or_create(species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() metabolic_participants = ['Ala', 'Cys', 'Asp', 'Glu', 'Selcys', 'h2o'] metabolic_compartments = ['l', 'm'] for i in metabolic_participants: for c in metabolic_compartments: model_species_type = model.species_types.get_or_create(id=i, type=wc_ontology['WC:metabolite']) model_compartment = model.compartments.get_one(id=c) model_species = model.species.get_or_create(species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id()
def setUp(self): # Create KB content self.tmp_dirname = tempfile.mkdtemp() self.sequence_path = os.path.join(self.tmp_dirname, 'test_seq.fasta') with open(self.sequence_path, 'w') as f: f.write('>chr1\nATGCATGACTCTAGTTTAT\n' '>chrM\nTTTatgaCTCTAGTTTACNNN\n') self.kb = wc_kb.KnowledgeBase() cell = self.kb.cell = wc_kb.Cell() nucleus = cell.compartments.create(id='n') mito = cell.compartments.create(id='m') cytoplasm = cell.compartments.create(id='c') chr1 = wc_kb.core.DnaSpeciesType(cell=cell, id='chr1', sequence_path=self.sequence_path) gene1 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene1', polymer=chr1, start=1, end=19) exon1 = wc_kb.eukaryote.GenericLocus(start=5, end=19) transcript1 = wc_kb.eukaryote.TranscriptSpeciesType( cell=cell, id='trans1', name='transcript1', gene=gene1, exons=[exon1], type=wc_kb.eukaryote.TranscriptType.mRna) transcript1_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript1, value='36000.0', value_type=wc_ontology['WC:float']) transcript1_spec = wc_kb.core.Species(species_type=transcript1, compartment=cytoplasm) transcript1_conc = wc_kb.core.Concentration(cell=cell, species=transcript1_spec, value=10.) chrM = wc_kb.core.DnaSpeciesType(cell=cell, id='chrM', sequence_path=self.sequence_path) gene2 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene2', polymer=chrM, start=1, end=19) exon2 = wc_kb.eukaryote.GenericLocus(start=1, end=10) transcript2 = wc_kb.eukaryote.TranscriptSpeciesType( cell=cell, id='trans2', name='transcript2', gene=gene2, exons=[exon2], type=wc_kb.eukaryote.TranscriptType.mRna) transcript2_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript2, value='15000.0', value_type=wc_ontology['WC:float']) transcript2_spec = wc_kb.core.Species(species_type=transcript2, compartment=mito) transcript2_conc = wc_kb.core.Concentration(cell=cell, species=transcript2_spec, value=10.) gene3 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene3', polymer=chr1, start=1, end=19) exon3 = wc_kb.eukaryote.GenericLocus(start=1, end=15) transcript3 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans3', name='transcript3', gene=gene3, exons=[exon3]) transcript3_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript3, value='36000.0', value_type=wc_ontology['WC:float']) transcript3_spec = wc_kb.core.Species(species_type=transcript3, compartment=cytoplasm) transcript3_conc = wc_kb.core.Concentration(cell=cell, species=transcript3_spec, value=10.) gene4 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene4', polymer=chr1, start=1, end=3) exon4 = wc_kb.eukaryote.GenericLocus(start=1, end=3) transcript4 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans4', name='transcript4', gene=gene4, exons=[exon4]) transcript4_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript4, value='36000.0', value_type=wc_ontology['WC:float']) transcript4_spec = wc_kb.core.Species(species_type=transcript4, compartment=cytoplasm) transcript4_conc = wc_kb.core.Concentration(cell=cell, species=transcript4_spec, value=10.) gene5 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene5', polymer=chr1, start=1, end=3) exon5 = wc_kb.eukaryote.GenericLocus(start=1, end=3) transcript5 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans5', name='transcript5', gene=gene5, exons=[exon5]) transcript5_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript5, value='36000.0', value_type=wc_ontology['WC:float']) transcript5_spec = wc_kb.core.Species(species_type=transcript5, compartment=cytoplasm) transcript5_conc = wc_kb.core.Concentration(cell=cell, species=transcript5_spec, value=0.) gene6 = wc_kb.eukaryote.GeneLocus(cell=cell, id='gene6', polymer=chr1, start=1, end=3) exon6 = wc_kb.eukaryote.GenericLocus(start=1, end=3) transcript6 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans6', name='transcript6', gene=gene6, exons=[exon6]) transcript6_half_life = wc_kb.core.SpeciesTypeProperty( property='half-life', species_type=transcript6, value='36000.0', value_type=wc_ontology['WC:float']) transcript6_spec = wc_kb.core.Species(species_type=transcript6, compartment=cytoplasm) transcript6_conc = wc_kb.core.Concentration(cell=cell, species=transcript6_spec, value=0.) transcript7 = wc_kb.eukaryote.TranscriptSpeciesType( cell=cell, id='trans7', name='transcript7', gene=gene6, type=wc_kb.eukaryote.TranscriptType.mRna) transcript7_spec = wc_kb.core.Species(species_type=transcript7, compartment=cytoplasm) transcript7_conc = wc_kb.core.Concentration(cell=cell, species=transcript7_spec, value=10.) transcript8 = wc_kb.eukaryote.TranscriptSpeciesType(cell=cell, id='trans8', name='transcript8', gene=gene6) activator = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='activator') repressor = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='repressor') gene2_reg1 = gene2.regulatory_modules.create( transcription_factor_regulation=[ wc_kb.eukaryote.TranscriptionFactorRegulation( transcription_factor=activator, direction=wc_kb.eukaryote.RegulatoryDirection.activation) ]) gene2_reg2 = gene2.regulatory_modules.create( transcription_factor_regulation=[ wc_kb.eukaryote.TranscriptionFactorRegulation( transcription_factor=repressor, direction=wc_kb.eukaryote.RegulatoryDirection.repression) ]) activator2 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='activator2') repressor2 = wc_kb.eukaryote.ProteinSpeciesType(cell=cell, id='repressor2') gene6_reg1 = gene6.regulatory_modules.create( transcription_factor_regulation=[ wc_kb.eukaryote.TranscriptionFactorRegulation( transcription_factor=activator2, direction=wc_kb.eukaryote.RegulatoryDirection.activation) ]) gene6_reg2 = gene6.regulatory_modules.create( transcription_factor_regulation=[ wc_kb.eukaryote.TranscriptionFactorRegulation( transcription_factor=repressor2, direction=wc_kb.eukaryote.RegulatoryDirection.repression) ]) # Create initial model content self.model = model = wc_lang.Model() model.parameters.create(id='mean_doubling_time', value=20 * 3600, units=unit_registry.parse_units('s')) model.parameters.create( id='Avogadro', value=scipy.constants.Avogadro, units=unit_registry.parse_units('molecule mol^-1')) compartments = { 'n': ('nucleus', 5E-14), 'm': ('mitochondria', 2.5E-14), 'c': ('cytoplasm', 1E-13) } for k, v in compartments.items(): init_volume = wc_lang.core.InitVolume( distribution=wc_ontology['WC:normal_distribution'], mean=v[1], std=0) c = model.compartments.create(id=k, name=v[0], init_volume=init_volume) c.init_density = model.parameters.create( id='density_' + k, value=1000, units=unit_registry.parse_units('g l^-1')) volume = model.functions.create( id='volume_' + k, units=unit_registry.parse_units('l')) volume.expression, error = wc_lang.FunctionExpression.deserialize( f'{c.id} / {c.init_density.id}', { wc_lang.Compartment: { c.id: c }, wc_lang.Parameter: { c.init_density.id: c.init_density }, }) assert error is None, str(error) for i in cell.species_types.get( __type=wc_kb.eukaryote.TranscriptSpeciesType): model_species_type = model.species_types.create(id=i.id) model_compartment = model.compartments.get_one( id='m' if 'M' in i.gene.polymer.id else 'c') model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=10, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() model.distribution_init_concentrations.get_one( id='dist-init-conc-trans5[c]').mean = 0. complexes = { 'complex1': ('RNA Polymerase I', 'n'), 'complex2': ('RNA Polymerase II', 'n'), 'complex3': ('RNA Polymerase mitochondria', 'm'), 'complex4': ('RNA Polymerase III', 'n') } for k, v in complexes.items(): model_species_type = model.species_types.create( id=k, name=v[0], structure=wc_lang.ChemicalStructure( empirical_formula=EmpiricalFormula('H'), molecular_weight=1.018, charge=1)) model_compartment = model.compartments.get_one(id=v[1]) model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=2500 if k == 'complex2' else 100, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() metabolic_participants = [ 'atp', 'ctp', 'gtp', 'utp', 'ppi', 'amp', 'cmp', 'gmp', 'ump', 'h2o', 'h', 'adp', 'pi' ] for i in metabolic_participants: model_species_type = model.species_types.create(id=i, name=i.upper()) for c in ['n', 'm']: model_compartment = model.compartments.get_one(id=c) model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=1500, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() for i in ['activator', 'repressor']: model_species_type = model.species_types.create(id=i, name=i.upper()) model_compartment = model.compartments.get_one(id='m') model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=3, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() for i in ['activator2', 'repressor2']: model_species_type = model.species_types.create(id=i, name=i.upper()) model_compartment = model.compartments.get_one(id='n') model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=0, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id() factors = [ 'pol1_init_factor1', 'pol1_el_factor1', 'pol2_init_factor1', 'pol2_el_factor1', 'pol2_neg_factor1', 'pol3_init_factor1', 'pol3_el_factor1', 'polm_init_factor1', 'polm_el_factor1' ] for i in factors: model_species_type = model.species_types.create(id=i, name=i.upper()) model_compartment = model.compartments.get_one( id='m' if 'polm' in i else 'n') model_species = model.species.get_or_create( species_type=model_species_type, compartment=model_compartment) model_species.id = model_species.gen_id() conc_model = model.distribution_init_concentrations.create( species=model_species, mean=2, units=unit_registry.parse_units('molecule')) conc_model.id = conc_model.gen_id()