コード例 #1
0
	def testOptimization(self):

		user = User.objects.filter(username='******')[0]
		self.assertEqual(len(Project.objects.filter(user=user)), 1)
		project = Project.objects.filter(user=user)[0]

		if isdir(join(settings.MEDIA_ROOT, project.folder)):
			rmtree(join(settings.MEDIA_ROOT, project.folder))
			mkdir(join(settings.MEDIA_ROOT, project.folder))

		self.assertEqual(len(SbmlModel.objects.filter(project=project)), 0)

		c = Client()
		self.assertTrue(c.login(username='******', password='******'))

		response_choose_project = c.get('/project/%s/' % project.folder)
		self.assertRedirects(response_choose_project, '/models/', status_code=302, target_status_code=200)

		self.assertEqual(len(SbmlModel.objects.filter(project=project)), 0)

		files_folder = join(dirname(__file__), "files")
		model_filename = join(files_folder, "modelx8Ow70.xml")

		response_load_model = c.post('/models/', {
			'action': 'load_model',
			'docfile': open(model_filename, 'rb')
		})

		self.assertEqual(response_load_model.status_code, 200)
		self.assertEqual(len(SbmlModel.objects.filter(project=project)), 1)

		response_create_experiment = c.post('/data/', {
			'action': 'save',
			'experiment_id': "",
			'experiment_name': "Enzymatic reaction",
			'experiment_notes': "Something"
		})

		self.assertEqual(response_create_experiment.status_code, 200)
		self.assertEqual(
			[experiment.name for experiment in response_create_experiment.context['experimental_data']],
			[u'Enzymatic reaction']
		)

		experiment_id = response_create_experiment.context['experimental_data'][0].id
		# Testing conditions

		response_choose_experiment = c.get('/data/%d/' % experiment_id)
		self.assertEqual(response_choose_experiment.status_code, 200)
		self.assertEqual(response_choose_experiment.context['experiment_name'], u'Enzymatic reaction')
		self.assertEqual(
			[condition.name for condition in response_choose_experiment.context['conditions']],
			[]
		)

		response_new_condition = c.post('/data/%d/' % experiment_id, {
			'action': 'save',
			'condition_id': "",
			'condition_name': "Test condition",
			'condition_notes': "Some notes"
		})

		self.assertEqual(response_new_condition.status_code, 200)
		self.assertEqual(
			[condition.name for condition in response_new_condition.context['conditions']],
			[u'Test condition']
		)

		condition_id = response_new_condition.context['conditions'][0].id

		response_choose_experiment = c.get('/data/%d/%d/' % (experiment_id, condition_id))
		self.assertEqual(response_choose_experiment.status_code, 200)
		self.assertEqual(len(response_choose_experiment.context['experiment_initial_data']), 0)

		response_add_treatment = c.post('/data/%d/%d/' % (experiment_id, condition_id), {
			'data_type': 'treatment',
			'action': 'save',
			'id': "",
			'name': 'Substrate',
			'time': 0,
			'value': 15
		})

		self.assertEqual(response_add_treatment.status_code, 200)
		self.assertEqual(len(response_add_treatment.context['experiment_initial_data']), 1)

		self.assertEqual(len(response_add_treatment.context['experiment_data']), 0)

		response_add_observation = c.post('/data/%d/%d/' % (experiment_id, condition_id), {
			'data_type': 'observation',
			'action': 'save',
			'id': "",
			'name': 'Product',
			'time': 0,
			'value': 0,
			'stddev': 0,
			'steady_state': 'off',
			'min_steady_state': "0",
			'max_steady_state': "0"
		})

		self.assertEqual(response_add_observation.status_code, 200)
		self.assertEqual(len(response_add_observation.context['experiment_data']), 1)

		response_add_observation = c.post('/data/%d/%d/' % (experiment_id, condition_id), {
			'data_type': 'observation',
			'action': 'save',
			'id': "",
			'name': 'Product',
			'time': 10,
			'value': 10,
			'stddev': 0,
			'steady_state': 'off',
			'min_steady_state': "0",
			'max_steady_state': "0"
		})

		self.assertEqual(response_add_observation.status_code, 200)
		self.assertEqual(len(response_add_observation.context['experiment_data']), 2)

		response_add_observation = c.post('/data/%d/%d/' % (experiment_id, condition_id), {
			'data_type': 'observation',
			'action': 'save',
			'id': "",
			'name': 'Product',
			'time': 20,
			'value': 15,
			'stddev': 0,
			'steady_state': 'off',
			'min_steady_state': "0",
			'max_steady_state': "0"
		})

		self.assertEqual(response_add_observation.status_code, 200)
		self.assertEqual(len(response_add_observation.context['experiment_data']), 3)

		response_add_observation = c.post('/data/%d/%d/' % (experiment_id, condition_id), {
			'data_type': 'observation',
			'action': 'save',
			'id': "",
			'name': 'Product',
			'time': 50,
			'value': 15,
			'stddev': 0,
			'steady_state': 'off',
			'min_steady_state': "0",
			'max_steady_state': "0"
		})

		self.assertEqual(response_add_observation.status_code, 200)
		self.assertEqual(len(response_add_observation.context['experiment_data']), 4)

		response_get_fit_data = c.get('/fit/data/')
		self.assertEqual(response_get_fit_data.status_code, 200)
		self.assertEqual(
			[dataset for dataset in response_get_fit_data.context['experimental_data_sets']],
			[u'Enzymatic reaction']
		)

		response_list_optimizations = c.get('/fit/list/')
		self.assertEqual(response_list_optimizations.status_code, 200)
		self.assertEqual(len(response_list_optimizations.context['optimizations']), 0)

		response_add_dataset = c.post('/json/add_dataset/', {
			'dataset_ind': 0
		})

		self.assertEqual(response_add_dataset.status_code, 200)
		mapping = loads(response_add_dataset.content.decode('utf-8'))['model_xpaths']

		sbml_filename = str(SbmlModel.objects.filter(project=project)[0].sbml_file)

		doc = SbmlDocument()
		doc.readSbmlFromFile(join(settings.MEDIA_ROOT, sbml_filename))

		self.assertEqual(sorted(list(mapping.keys())), ['Product', 'Substrate'])

		self.assertEqual(doc.model.listOfSpecies.index(doc.getByXPath(mapping['Substrate'])), 0)
		self.assertEqual(doc.model.listOfSpecies.index(doc.getByXPath(mapping['Product'])), 3)

		response_create_optimization = c.post('/fit/data/', {
			'action': 'create',
			'dataset_0': experiment_id,
			'list_dataset_0_data_species_0_value': "Product",
			'list_dataset_0_species_0_value': 3,
			'list_dataset_0_data_species_1_value': "Substrate",
			'list_dataset_0_species_1_value': 0,
			'parameter_0_active': "on",
			'parameter_0_id': 0,
			'parameter_0_name': "Binding rate",
			'parameter_0_value': 1.0,
			'parameter_0_min': 1e-4,
			'parameter_0_max': 1e+4,
			'parameter_0_precision': 7,
			'parameter_1_active': "on",
			'parameter_1_id': 0,
			'parameter_1_name': "Unbinding rate",
			'parameter_1_value': 1.0,
			'parameter_1_min': 1e-4,
			'parameter_1_max': 1e+4,
			'parameter_1_precision': 7,
			'parameter_2_active': "on",
			'parameter_2_id': 0,
			'parameter_2_name': "Catalytic rate",
			'parameter_2_value': 1.0,
			'parameter_2_min': 1e-4,
			'parameter_2_max': 1e+4,
			'parameter_2_precision': 7,

			'nb_cores': 2,
			'lambda': 0.001,
			'score_precision': 0.001,
			'param_precision': 7,
			'initial_temperature': 1,
			'initial_moves': 2000,
			'freeze_count': 100,
			'negative_penalty': 0
		})

		self.assertEqual(response_create_optimization.status_code, 200)
		self.assertEqual(response_create_optimization.context['form'].getErrors(), [])

		sleep(5)

		response_list_optimizations = c.get('/fit/list/')
		self.assertEqual(response_list_optimizations.status_code, 200)
		self.assertEqual(len(response_list_optimizations.context['optimizations']), 1)
		self.assertEqual(response_list_optimizations.context['optimizations'][0][0].status, "Running")

		sleep(10)

		response_get_optimization = c.get('/fit/%s/' % response_list_optimizations.context['optimizations'][0][0].optimization_id)
		self.assertEqual(response_get_optimization.status_code, 200)

		sleep(240)

		response_list_optimizations = c.get('/fit/list/')
		self.assertEqual(response_list_optimizations.status_code, 200)
		self.assertEqual(response_list_optimizations.context['optimizations'][0][0].status, "Finished")

		response_get_optimization = c.get(
			'/fit/%s/' % response_list_optimizations.context['optimizations'][0][0].optimization_id)
		self.assertEqual(response_get_optimization.status_code, 200)

		scores = response_get_optimization.context['score_values']
		self.assertTrue(scores[len(scores)-1] < 0.24)
コード例 #2
0
    def testOptimization(self):

        user = User.objects.filter(username='******')[0]
        self.assertEqual(len(Project.objects.filter(user=user)), 1)
        project = Project.objects.filter(user=user)[0]

        self.assertEqual(len(SbmlModel.objects.filter(project=project)), 0)

        if isdir(join(settings.MEDIA_ROOT, project.folder)):
            rmtree(join(settings.MEDIA_ROOT, project.folder))
            mkdir(join(settings.MEDIA_ROOT, project.folder))

        c = Client()
        self.assertTrue(c.login(username='******', password='******'))

        response_choose_project = c.get('/project/%s/' % project.folder)
        self.assertRedirects(response_choose_project,
                             '/models/',
                             status_code=302,
                             target_status_code=200)

        response_choose_project = c.post('/models/', {
            'action': 'choose_project',
            'project_id': 0
        })
        self.assertEqual(response_choose_project.status_code, 200)

        files_folder = join(dirname(__file__), "files")
        comp_files_folder = join(files_folder, "comp_model")

        model_filename = join(comp_files_folder, "modelcEvRcX.xml")
        response_load_submodel_1 = c.post('/models/', {
            'action': 'load_model',
            'docfile': open(model_filename, 'rb')
        })

        self.assertEqual(response_load_submodel_1.status_code, 200)
        self.assertEqual(len(SbmlModel.objects.filter(project=project)), 1)

        model_filename = join(comp_files_folder, "modelEHfev9.xml")
        response_load_submodel_2 = c.post('/models/', {
            'action': 'load_model',
            'docfile': open(model_filename, 'rb')
        })

        self.assertEqual(response_load_submodel_2.status_code, 200)
        self.assertEqual(len(SbmlModel.objects.filter(project=project)), 2)

        model_filename = join(comp_files_folder, "modelI1vrys.xml")
        response_load_submodel_3 = c.post('/models/', {
            'action': 'load_model',
            'docfile': open(model_filename, 'rb')
        })

        self.assertEqual(response_load_submodel_3.status_code, 200)
        self.assertEqual(len(SbmlModel.objects.filter(project=project)), 3)

        model_filename = join(comp_files_folder, "modelz9xdww.xml")

        response_load_model = c.post('/models/', {
            'action': 'load_model',
            'docfile': open(model_filename, 'rb')
        })

        self.assertEqual(response_load_model.status_code, 200)
        self.assertEqual(len(SbmlModel.objects.filter(project=project)), 4)

        response_choose_model = c.post('/fit/data/', {
            'action': 'choose_model',
            'model_id': 3
        })
        self.assertEqual(response_choose_model.status_code, 200)
        experiment_filename = join(files_folder, "ras_data.xml")

        response_import_data = c.post(
            '/data/', {
                'action': 'import',
                'docfile': open(experiment_filename, 'rb')
            })

        self.assertEqual(response_import_data.status_code, 200)
        self.assertEqual([
            experiment.name
            for experiment in response_import_data.context['experimental_data']
        ], [u'Ras-GTP quantifications'])
        experiment_id = response_import_data.context['experimental_data'][0].id

        response_get_fit_data = c.get('/fit/data/')
        self.assertEqual(response_get_fit_data.status_code, 200)
        self.assertEqual([
            dataset for dataset in
            response_get_fit_data.context['experimental_data_sets']
        ], [u'Ras-GTP quantifications'])

        response_list_optimizations = c.get('/fit/list/')
        self.assertEqual(response_list_optimizations.status_code, 200)
        self.assertEqual(
            len(response_list_optimizations.context['optimizations']), 0)

        response_add_dataset = c.post('/json/add_dataset/', {'dataset_ind': 0})

        self.assertEqual(response_add_dataset.status_code, 200)
        mapping = loads(
            response_add_dataset.content.decode('utf-8'))['model_xpaths']

        sbml_filename = str(
            SbmlModel.objects.filter(project=project)[3].sbml_file)

        doc = SbmlDocument()
        doc.readSbmlFromFile(join(settings.MEDIA_ROOT, sbml_filename))

        self.assertEqual(sorted(list(mapping.keys())),
                         ['FGF2', 'Total Ras-GTP'])

        self.assertEqual(
            doc.getModelInstance().listOfSpecies.index(
                doc.getByXPath(mapping['FGF2'], instance=True)), 4)
        self.assertEqual(
            doc.getModelInstance().listOfSpecies.index(
                doc.getByXPath(mapping['Total Ras-GTP'], instance=True)), 13)

        response_create_optimization = c.post(
            '/fit/data/',
            {
                'action': 'create',
                'dataset_0':
                experiment_id,  #response_get_fit_data.context['experimental_data_sets'][0].id,
                'list_dataset_0_data_species_0_value': "FGF2",
                'list_dataset_0_species_0_value': 4,
                'list_dataset_0_data_species_1_value': "Total Ras-GTP",
                'list_dataset_0_species_1_value': 13,
                'parameter_0_id': 1,
                'parameter_0_name': "SOS activation by FGF2",
                'parameter_0_value': 1.0,
                'parameter_0_min': 1e-4,
                'parameter_0_max': 1e+4,
                'parameter_0_precision': 7,
                'parameter_1_active': "on",
                'parameter_1_id': 1,
                'parameter_1_name':
                "SOS inactivation by Mapk catalytic constant",
                'parameter_1_value': 1.0,
                'parameter_1_min': 1e-6,
                'parameter_1_max': 1e+6,
                'parameter_1_precision': 7,
                'nb_cores': 2,
                'lambda': 0.02,
                'score_precision': 0.001,
                'param_precision': 7,
                'initial_temperature': 1,
                'initial_moves': 200,
                'freeze_count': 1,
                'negative_penalty': 0
            })

        self.assertEqual(response_create_optimization.status_code, 200)
        self.assertEqual(
            response_create_optimization.context['form'].getErrors(), [])
        sleep(10)

        response_list_optimizations = c.get('/fit/list/')
        self.assertEqual(response_list_optimizations.status_code, 200)
        self.assertEqual(
            len(response_list_optimizations.context['optimizations']), 1)
        self.assertEqual(
            response_list_optimizations.context['optimizations'][0][0].status,
            "Running")

        sleep(10)

        optimization_id = response_list_optimizations.context['optimizations'][
            0][0].optimization_id
        response_get_optimization = c.get('/fit/%s/' % optimization_id)
        self.assertEqual(response_get_optimization.status_code, 200)

        max_time = 360
        sleep(360)
        response_list_optimizations = c.get('/fit/list/')
        self.assertEqual(response_list_optimizations.status_code, 200)
        self.assertEqual(
            response_list_optimizations.context['optimizations'][0][0].status,
            "Finished")

        response_get_optimization = c.get('/fit/%s/' % optimization_id)
        self.assertEqual(response_get_optimization.status_code, 200)

        scores = response_get_optimization.context['score_values']
        self.assertTrue(scores[len(scores) - 1] < 1.01)
コード例 #3
0
	def testOptimization(self):

		user = User.objects.filter(username='******')[0]
		self.assertEqual(len(Project.objects.filter(user=user)), 1)
		project = Project.objects.filter(user=user)[0]

		self.assertEqual(len(SbmlModel.objects.filter(project=project)), 0)

		if isdir(join(settings.MEDIA_ROOT, project.folder)):
			rmtree(join(settings.MEDIA_ROOT, project.folder))
			mkdir(join(settings.MEDIA_ROOT, project.folder))

		c = Client()
		self.assertTrue(c.login(username='******', password='******'))

		response_choose_project = c.get('/project/%s/' % project.folder)
		self.assertRedirects(response_choose_project, '/models/', status_code=302, target_status_code=200)

		response_choose_project = c.post('/models/', {
			'action': 'choose_project',
			'project_id': 0
		})
		self.assertEqual(response_choose_project.status_code, 200)

		files_folder = join(dirname(__file__), "files")
		comp_files_folder = join(files_folder, "comp_model")

		model_filename = join(comp_files_folder, "modelcEvRcX.xml")
		response_load_submodel_1 = c.post('/models/', {
			'action': 'load_model',
			'docfile': open(model_filename, 'rb')
		})

		self.assertEqual(response_load_submodel_1.status_code, 200)
		self.assertEqual(len(SbmlModel.objects.filter(project=project)), 1)

		model_filename = join(comp_files_folder, "modelEHfev9.xml")
		response_load_submodel_2 = c.post('/models/', {
			'action': 'load_model',
			'docfile': open(model_filename, 'rb')
		})

		self.assertEqual(response_load_submodel_2.status_code, 200)
		self.assertEqual(len(SbmlModel.objects.filter(project=project)), 2)

		model_filename = join(comp_files_folder, "modelI1vrys.xml")
		response_load_submodel_3 = c.post('/models/', {
			'action': 'load_model',
			'docfile': open(model_filename, 'rb')
		})

		self.assertEqual(response_load_submodel_3.status_code, 200)
		self.assertEqual(len(SbmlModel.objects.filter(project=project)), 3)

		model_filename = join(comp_files_folder, "modelz9xdww.xml")

		response_load_model = c.post('/models/', {
			'action': 'load_model',
			'docfile': open(model_filename, 'rb')
		})

		self.assertEqual(response_load_model.status_code, 200)
		self.assertEqual(len(SbmlModel.objects.filter(project=project)), 4)

		response_choose_model = c.post('/fit/data/', {
			'action': 'choose_model',
			'model_id': 3
		})
		self.assertEqual(response_choose_model.status_code, 200)
		experiment_filename = join(files_folder, "ras_data.xml")

		response_import_data = c.post('/data/', {
			'action': 'import',
			'docfile': open(experiment_filename, 'rb')
		})

		self.assertEqual(response_import_data.status_code, 200)
		self.assertEqual(
			[experiment.name for experiment in response_import_data.context['experimental_data']],
			[u'Ras-GTP quantifications']
		)
		experiment_id = response_import_data.context['experimental_data'][0].id

		response_get_fit_data = c.get('/fit/data/')
		self.assertEqual(response_get_fit_data.status_code, 200)
		self.assertEqual(
			[dataset for dataset in response_get_fit_data.context['experimental_data_sets']],
			[u'Ras-GTP quantifications']
		)

		response_list_optimizations = c.get('/fit/list/')
		self.assertEqual(response_list_optimizations.status_code, 200)
		self.assertEqual(len(response_list_optimizations.context['optimizations']), 0)

		response_add_dataset = c.post('/json/add_dataset/', {
			'dataset_ind': 0
		})

		self.assertEqual(response_add_dataset.status_code, 200)
		mapping = loads(response_add_dataset.content.decode('utf-8'))['model_xpaths']

		sbml_filename = str(SbmlModel.objects.filter(project=project)[3].sbml_file)

		doc = SbmlDocument()
		doc.readSbmlFromFile(join(settings.MEDIA_ROOT, sbml_filename))

		self.assertEqual(sorted(list(mapping.keys())), ['FGF2', 'Total Ras-GTP'])

		self.assertEqual(doc.getModelInstance().listOfSpecies.index(doc.getByXPath(mapping['FGF2'], instance=True)), 4)
		self.assertEqual(doc.getModelInstance().listOfSpecies.index(doc.getByXPath(mapping['Total Ras-GTP'], instance=True)), 13)

		response_create_optimization = c.post('/fit/data/', {
			'action': 'create',
			'dataset_0': experiment_id, #response_get_fit_data.context['experimental_data_sets'][0].id,

			'list_dataset_0_data_species_0_value': "FGF2",
			'list_dataset_0_species_0_value': 4,
			'list_dataset_0_data_species_1_value': "Total Ras-GTP",
			'list_dataset_0_species_1_value': 13,

			'parameter_0_id': 1,
			'parameter_0_name': "SOS activation by FGF2",
			'parameter_0_value': 1.0,
			'parameter_0_min': 1e-4,
			'parameter_0_max': 1e+4,
			'parameter_0_precision': 7,

			'parameter_1_active': "on",
			'parameter_1_id': 1,
			'parameter_1_name': "SOS inactivation by Mapk catalytic constant",
			'parameter_1_value': 1.0,
			'parameter_1_min': 1e-6,
			'parameter_1_max': 1e+6,
			'parameter_1_precision': 7,

			'nb_cores': 2,
			'lambda': 0.02,
			'score_precision': 0.001,
			'param_precision': 7,
			'initial_temperature': 1,
			'initial_moves': 200,
			'freeze_count': 1,
			'negative_penalty': 0
		})

		self.assertEqual(response_create_optimization.status_code, 200)
		self.assertEqual(response_create_optimization.context['form'].getErrors(), [])
		sleep(10)

		response_list_optimizations = c.get('/fit/list/')
		self.assertEqual(response_list_optimizations.status_code, 200)
		self.assertEqual(len(response_list_optimizations.context['optimizations']), 1)
		self.assertEqual(response_list_optimizations.context['optimizations'][0][0].status, "Running")

		sleep(10)

		optimization_id = response_list_optimizations.context['optimizations'][0][0].optimization_id
		response_get_optimization = c.get('/fit/%s/' % optimization_id)
		self.assertEqual(response_get_optimization.status_code, 200)

		max_time = 360
		sleep(360)
		response_list_optimizations = c.get('/fit/list/')
		self.assertEqual(response_list_optimizations.status_code, 200)
		self.assertEqual(response_list_optimizations.context['optimizations'][0][0].status, "Finished")

		response_get_optimization = c.get('/fit/%s/' % optimization_id)
		self.assertEqual(response_get_optimization.status_code, 200)

		scores = response_get_optimization.context['score_values']
		self.assertTrue(scores[len(scores)-1] < 1.01)