def setUp(self): self.working_directory = os.path.join(os.path.dirname(__file__), 'viz_tests') if not os.path.isdir(self.working_directory): os.makedirs(self.working_directory) copasi_file = os.path.join(self.working_directory, 'test_model.cps') with model.BuildAntimony(copasi_file) as loader: self.mod = loader.load(""" model negative_feedback compartment cell = 1.0 var A in cell var B in cell var Signal in cell var C in cell vAProd = 0.1 kADeg = 0.2 kBProd = 0.3 kBDeg = 0.4 kCProd = 0.5 kCDeg = 0.6 A = 0 B = 0 C = 0 Signal = 10 AProd: $Signal => A; cell*vAProd*Signal ADeg: A =>; cell*kADeg*A*B; BProd: => B; cell*kBProd*A; BDeg: B => ; cell*kBDeg*B; CProd: => C ; cell*kCProd*B; CDeg: C => ; cell*kCDeg*C end """) ## initialize empty dict to store TimeCourse objects self.TC = tasks.TimeCourse(self.mod, end=10, intervals=10, step_size=1, global_quantities=[], y=['A', 'B', 'C']) tasks ## format the time course data df = utils.format_timecourse_data(self.TC.report_name) ## write data to file df.to_csv(self.TC.report_name, sep='\t', index=False) self.MPE = tasks.MultiParameterEstimation(self.mod, self.TC.report_name, method='genetic_algorithm', population_size=25, number_of_generations=50, run_mode=True) self.MPE.write_config_file() self.MPE.setup() self.MPE.run()
def simulate_data(self): """ simulate some data from model1 :return: """ TC = tasks.TimeCourse(self.mod, end=100, steps=10, intervals=10) utils.format_timecourse_data(TC.report_name) return TC
def setUp(self): working_directory = os.path.dirname(__file__) copasi_file = os.path.join(working_directory, 'quick_start_model.cps') if os.path.isfile(copasi_file): os.remove(copasi_file) kf = 0.01 kb = 0.1 kcat = 0.05 with model.Build(copasi_file) as m: m.name = 'Michaelis-Menten' m.add('compartment', name='Cell') m.add('metabolite', name='P', concentration=0) m.add('metabolite', name='S', concentration=30) m.add('metabolite', name='E', concentration=10) m.add('metabolite', name='ES', concentration=0) m.add('reaction', name='S bind E', expression='S + E -> ES', rate_law='kf*S*E', parameter_values={'kf': kf}) m.add('reaction', name='S unbind E', expression='ES -> S + E', rate_law='kb*ES', parameter_values={'kb': kb}) m.add('reaction', name='ES produce P', expression='ES -> P + E', rate_law='kcat*ES', parameter_values={'kcat': kcat}) michaelis_menten = model.Model(copasi_file) report = 'parameter_estimation_synthetic_data.txt' TC = tasks.TimeCourse( michaelis_menten, start=0, end=100, intervals=10, step_size=10, report_name=report ) misc.correct_copasi_timecourse_headers(TC.report_name) fit1 = tasks.MultiParameterEstimation( michaelis_menten, TC.report_name, copy_number=2, pe_number=2, lower_bound=1e-3, upper_bound=5e3, results_directory='fit1', method='genetic_algorithm_sr', population_size=1, number_of_generations=1, overwrite_config_file=True ) fit1.write_config_file() fit1.setup() fit1.run() self.fit1 = fit1 self.model = michaelis_menten import time time.sleep(5)
def test_sbml_import_works(self): """ Test that time course works after import :return: """ ## create sbml file for import sbml_filename = self.mod.to_sbml() assert os.path.isfile(sbml_filename) ## remove the existing copasi file if os.path.isfile(self.copasi_file1): os.remove(self.copasi_file1) ## import sbml mod = model.ImportSBML(sbml_filename).model TC = tasks.TimeCourse(mod, end=100, intervals=100, step_size=1) plotted_time_course = viz.PlotTimeCourse(TC, savefig=True) self.assertEqual( 2, len( glob.glob( os.path.join(plotted_time_course.results_directory, '*'))))
def setUp(self): ## create model selection directory self.dire = os.path.join(os.path.dirname(__file__), 'ChaserEstimationTests') if not os.path.isdir(self.dire): os.makedirs(self.dire) self.copasi_file = os.path.join(self.dire, 'negative_feedback.cps') with model.BuildAntimony(self.copasi_file) as loader: self.mod = loader.load(""" model model1 compartment cell = 1.0 var A in cell var B in cell vAProd = 0.1 kADeg = 0.2 kBProd = 0.3 kBDeg = 0.4 vBasalAProd = 0.001 A = 0 B = 0 AProd: => A; cell*vAProd*B+vBasalAProd ADeg: A =>; cell*kADeg*A BProd: => B; cell*kBProd*A BDeg: B => ; cell*kBDeg*B end """) self.TC1 = tasks.TimeCourse(self.mod, end=1000, step_size=100, intervals=10, report_name='report1.txt') utils.format_timecourse_data(self.TC1.report_name) ## add some noise data1 = misc.add_noise(self.TC1.report_name) ## remove the data os.remove(self.TC1.report_name) ## rewrite the data with noise data1.to_csv(self.TC1.report_name, sep='\t') self.copy_number = 2 self.pe_number = 3 self.MPE = tasks.MultiParameterEstimation(self.mod, self.TC1.report_name, copy_number=self.copy_number, pe_number=self.pe_number, method='genetic_algorithm', population_size=10, number_of_generations=10, overwrite_config_file=True, results_directory='test_mpe', run_mode=True) self.list_of_tasks = '{http://www.copasi.org/static/schema}ListOfTasks' self.MPE.write_config_file() self.MPE.setup() self.MPE.run()