示例#1
0
    def test_growth_transcription(self):

        # Construct model
        env = EnvironmentVarGuard()
        env.set('CONFIG__DOT__wc_kb__DOT__io__DOT__strict', '0')
        with env:
            self.kb = wc_kb.io.Reader().run(
                'tests/fixtures/min_model_kb.xlsx',
                'tests/fixtures/min_model_kb_seq.fna',
            )[wc_kb.KnowledgeBase][0]

        self.model = prokaryote.ProkaryoteModelGenerator(
            knowledge_base=self.kb,
            component_generators=[
                prokaryote.InitalizeModel,
                prokaryote.TranscriptionSubmodelGenerator,
                prokaryote.RnaDegradationSubmodelGenerator,
                prokaryote.MetabolismSubmodelGenerator
            ],
            options={
                'component': {
                    'TranscriptionSubmodelGenerator': {
                        'beta': 1.
                    },
                    'RnaDegradationSubmodelGenerator': {
                        'beta': 1.
                    }
                }
            }).run()

        # Simulate model
        checkpoint_period = 10
        end_time = 100
        simulation = Simulation(self.model)
        results = simulation.run(end_time, self.dir, checkpoint_period)
        self.assertIsInstance(results, tuple)

        # Check results
        num_events = results[0]
        run_results_dir = results[1]
        run_results = RunResults(run_results_dir)
        df = run_results.get('populations')

        cytosol = self.model.compartments.get_one(id='c')
        rna_ids = []
        for rna in self.model.species_types.get(
                type=wc_ontology['WC:RNA']):  # RNA
            rna_ids.append(rna.species.get_one(compartment=cytosol).id)

        avg_init_rna_cn = np.mean(df.loc[0.0, rna_ids].values)
        avg_final_rna_cn = np.mean(df.loc[100.0, rna_ids].values)

        print(simulation.provide_event_counts())
        print('\n INIT AVG RNA COPY NUMBERS:', avg_init_rna_cn)
        print('\n FINAL AVG RNA COPY NUMBERS:', avg_final_rna_cn)

        self.assertGreater(avg_final_rna_cn,
                           2 * avg_init_rna_cn - avg_init_rna_cn * 0.15)
        self.assertLess(avg_final_rna_cn,
                        2 * avg_init_rna_cn + avg_init_rna_cn * 0.15)
    def setUpClass(cls):
        env = EnvironmentVarGuard()
        env.set('CONFIG__DOT__wc_kb__DOT__io__DOT__strict', '0')
        with env:
            cls.kb = wc_kb.io.Reader().run('tests/fixtures/min_model_kb.xlsx',
                                           'tests/fixtures/min_model_seq.fna',
                                            )[wc_kb.KnowledgeBase][0]

        cls.model = prokaryote.ProkaryoteModelGenerator(knowledge_base = cls.kb,
                        component_generators=[prokaryote.InitalizeModel]).run()
示例#3
0
    def test_generate_read_write(self):
        env = EnvironmentVarGuard()
        env.set('CONFIG__DOT__wc_kb__DOT__io__DOT__strict', '0')
        with env:
            kb = wc_kb.io.Reader().run(
                'tests/fixtures/min_model_kb.xlsx',
                'tests/fixtures/min_model_seq.fna',
            )[wc_kb.KnowledgeBase][0]
        """ Generate and write models from KBs """
        model = prokaryote.ProkaryoteModelGenerator(knowledge_base=kb).run()
        wc_lang.io.Writer().run(os.path.join(self.dir, 'model.xlsx'),
                                model,
                                data_repo_metadata=False)
        """ Read back KBs from disk """
        model_read = wc_lang.io.Reader().run(
            os.path.join(self.dir, 'model.xlsx'))[wc_lang.Model][0]

        self.assertTrue(model.is_equal(model_read, tol=1e-4))
    def test_submodels(self):
        env = EnvironmentVarGuard()
        env.set('CONFIG__DOT__wc_kb__DOT__io__DOT__strict', '0')
        with env:
            cls.kb = wc_kb.io.Reader().run(
                'tests/fixtures/min_model_kb.xlsx',
                'tests/fixtures/min_model_seq.fna',
            )[wc_kb.KnowledgeBase][0]

        cls.model = prokaryote.ProkaryoteModelGenerator(
            knowledge_base=cls.kb).run()
        cytosol = self.model.compartments.get_one(id='c')
        extracellular_space = self.model.compartments.get_one(id='e')
        mean_doubling_time = self.model.parameters.get_one(
            id='mean_doubling_time')

        errors = obj_tables.Validator().run(self.model, get_related=True)
        self.assertEqual(errors,
                         None,
                         msg=wc_utils.util.string.indent_forest(errors))
        self.assertEqual(5, len(self.model.submodels))