def loadOptimizations(self, request):

        if self.list_of_models is not None and len(self.list_of_models) > 0:
            t_model = SbmlModel.objects.get(project=self.project,
                                            id=self.model_id)
            optimizations = Optimization.objects.filter(project=self.project,
                                                        model=t_model)
            self.listOfOptimizations = []
            for optimization in optimizations:
                t_optim_id = optimization.optimization_id

                optim_path = join(
                    settings.MEDIA_ROOT, str(self.project.folder),
                    "optimizations/optimization_%s/" % str(t_optim_id))

                t_time_of_launch = int(time()) - (int(t_optim_id) / 1000)

                t_model_name = ""
                if isfile(optim_path + "/model.sbml"):
                    try:
                        t_document = SbmlDocument()
                        t_document.readSbmlFromFile(
                            str(optim_path + "/model.sbml"))
                        t_model_name = t_document.model.getName()
                    except ModelException as e:
                        t_model_name = "Unknown"

                self.listOfOptimizations.append(
                    (optimization, t_time_of_launch, t_model_name))
Пример #2
0
	def getListOfObjects(self, request):

		if str(request.POST['model_id']) != "":
			list_of_project_models = [pm for pm in self.getProjectModels(request) if pm.id != self.model_id]

			t_model = list_of_project_models[int(request.POST['model_id'])]
			t_filename = join(settings.MEDIA_ROOT, str(t_model.sbml_file))
			doc = SbmlDocument()
			doc.readSbmlFromFile(t_filename)

			if (
				'submodel_id' in request.POST
				and request.POST['submodel_id'] != ""
				and int(request.POST['submodel_id']) > 1
			):

				submodel = doc.model.listOfSubmodels[int(request.POST['submodel_id'])-1].getModelObject()
				self.listOfObjects = []
				for t_object in doc.model.listOfSbmlObjects:
					if isinstance(t_object, Variable) and not t_object.isStoichiometry():
						self.listOfObjects.append(t_object.getNameOrSbmlId() + (" (%s)" % type(t_object).__name__))

				return self.listOfObjects

			else:
				self.listOfObjects = []
				for t_object in doc.model.listOfSbmlObjects:
					if isinstance(t_object, Variable) and not t_object.isStoichiometry():
						self.listOfObjects.append(t_object.getNameOrSbmlId() + (" (%s)" % type(t_object).__name__))

				return self.listOfObjects
Пример #3
0
	def loadOptimizations(self, request):

		if self.list_of_models is not None and len(self.list_of_models) > 0:
			t_model = SbmlModel.objects.get(project=self.project, id=self.model_id)
			optimizations = Optimization.objects.filter(project=self.project,
										model=t_model)
			self.listOfOptimizations = []
			for optimization in optimizations:
				t_optim_id = optimization.optimization_id

				optim_path = join(settings.MEDIA_ROOT,
								str(self.project.folder),
								"optimizations/optimization_%s/" % str(t_optim_id))


				t_time_of_launch = int(time()) - (int(t_optim_id)/1000)

				t_model_name = ""
				if isfile(optim_path + "/model.sbml"):
					try:
						t_document = SbmlDocument()
						t_document.readSbmlFromFile(str(optim_path + "/model.sbml"))
						t_model_name = t_document.model.getName()
					except ModelException as e:
						t_model_name = "Unknown"

				self.listOfOptimizations.append((optimization, t_time_of_launch, t_model_name))
Пример #4
0
	def __loadModelVariables(self):

		if self.model_id is not None and SbmlModel.objects.filter(id=self.model_id).exists():

			t_model = SbmlModel.objects.get(id=self.model_id)

			if self.isProjectOwner(self.__request) or t_model.project.access == "PU":
				self.model_filename = os.path.join(settings.MEDIA_ROOT, str(t_model.sbml_file))

				t_doc = SbmlDocument()
				t_doc.readSbmlFromFile(self.model_filename)
				self.model = t_doc.model
				self.model_name = self.model.getName()

				self.model_list_of_submodels = self.model.listOfSubmodels
				self.model_list_of_submodels_names = []
				self.model_list_of_submodels_types = []
				for submodel in self.model.listOfSubmodels:
					if submodel.getModelRef() in self.model.parentDoc.listOfModelDefinitions.sbmlIds():
						self.model_list_of_submodels_names.append(self.model.parentDoc.listOfModelDefinitions.getBySbmlId(submodel.getModelRef()).getNameOrSbmlId())
						self.model_list_of_submodels_types.append(0)
					if submodel.getModelRef() in self.model.parentDoc.listOfExternalModelDefinitions.sbmlIds():
						self.model_list_of_submodels_names.append(self.model.parentDoc.listOfExternalModelDefinitions.getBySbmlId(submodel.getModelRef()).getNameOrSbmlId())
						self.model_list_of_submodels_types.append(1)
			else:
				raise PermissionDenied

		else:
			raise Http404("The model doesn't exist !")
Пример #5
0
	def getModelSBMLSubmodels(self, request):
		""" Returning the submodels of a model available within the project
		"""
		if self.isUserLoggedIn(request) and self.project is not None and self.model_id is not None:
			t_filename = os.path.join(settings.MEDIA_ROOT, str(self.model_filename))
			doc = SbmlDocument()
			doc.readSbmlFromFile(t_filename)
			if doc.useCompPackage:
				return (doc.listOfModelDefinitions.getListOfModelDefinitions()
						+ doc.listOfExternalModelDefinitions.getListOfModelDefinitions())
Пример #6
0
def renameSbmlIdInModelDependencies(sbml_model, old_sbml_id, new_sbml_id):

	for model_dependency in ModelsDependency.objects.filter(submodel=sbml_model):

		doc = SbmlDocument()
		doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model_dependency.model.sbml_file)))

		doc.renameSbmlIdInSubstitutions(old_sbml_id, new_sbml_id, model_dependency.submodel_ref)

		doc.writeSbmlToFile(join(settings.MEDIA_ROOT, str(model_dependency.model.sbml_file)))
Пример #7
0
def deleteModelHierarchy(model_filename):

	doc = SbmlDocument()
	doc.readSbmlFromFile(model_filename)
	path = dirname(model_filename)

	if doc.useCompPackage:
		for dependency in doc.getExternalDocumentDependencies():
			deleteModelHierarchy(join(path, dependency))

	remove(model_filename)
Пример #8
0
def deleteModelHierarchy(model_filename):

    doc = SbmlDocument()
    doc.readSbmlFromFile(model_filename)
    path = dirname(model_filename)

    if doc.useCompPackage:
        for dependency in doc.getExternalDocumentDependencies():
            deleteModelHierarchy(join(path, dependency))

    remove(model_filename)
Пример #9
0
def getModelHierarchy(model_filename):

	doc = SbmlDocument()
	doc.readSbmlFromFile(model_filename)
	path = dirname(model_filename)
	deps = []
	if doc.useCompPackage:
		for dependency in doc.getExternalDocumentDependencies():
			deps.append(dependency)
			deps += getModelHierarchy(join(path, dependency))

	return deps
Пример #10
0
def getModelHierarchy(model_filename):

    doc = SbmlDocument()
    doc.readSbmlFromFile(model_filename)
    path = dirname(model_filename)
    deps = []
    if doc.useCompPackage:
        for dependency in doc.getExternalDocumentDependencies():
            deps.append(dependency)
            deps += getModelHierarchy(join(path, dependency))

    return deps
Пример #11
0
	def getModelSubmodels(self, request, model_id):
		""" Returning the submodels of a model available within the project
		"""
		if self.isUserLoggedIn(request) and self.project is not None:
			t_models = [pm for pm in self.getProjectModels(request) if pm.id != self.model_id]
			t_filename = os.path.join(settings.MEDIA_ROOT, str(t_models[model_id].sbml_file))
			doc = SbmlDocument()
			doc.readSbmlFromFile(t_filename)
			if doc.useCompPackage:
				return [doc.model.getSbmlId()] + doc.listOfModelDefinitions.sbmlIds()+doc.listOfExternalModelDefinitions.sbmlIds()
			else:
				return [doc.model.getSbmlId()]
Пример #12
0
def renameSbmlIdInModelDependencies(sbml_model, old_sbml_id, new_sbml_id):

    for model_dependency in ModelsDependency.objects.filter(
            submodel=sbml_model):

        doc = SbmlDocument()
        doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model_dependency.model.sbml_file)))

        doc.renameSbmlIdInSubstitutions(old_sbml_id, new_sbml_id,
                                        model_dependency.submodel_ref)

        doc.writeSbmlToFile(
            join(settings.MEDIA_ROOT, str(model_dependency.model.sbml_file)))
Пример #13
0
    def getModelSBMLSubmodels(self, request):
        """ Returning the submodels of a model available within the project
		"""
        if self.isUserLoggedIn(
                request
        ) and self.project is not None and self.model_id is not None:
            t_filename = os.path.join(settings.MEDIA_ROOT,
                                      str(self.model_filename))
            doc = SbmlDocument()
            doc.readSbmlFromFile(t_filename)
            if doc.useCompPackage:
                return (
                    doc.listOfModelDefinitions.getListOfModelDefinitions() +
                    doc.listOfExternalModelDefinitions.
                    getListOfModelDefinitions())
Пример #14
0
	def duplicateModel(self, request):

		model = SbmlModel.objects.get(id=request.POST['id'])
		t_file = File(open(os.path.join(settings.MEDIA_ROOT, str(model.sbml_file)), 'rb'))

		new_sbml_model = SbmlModel(project=self.project,
										name=("%s (copy)" % str(model.name)),
										sbml_file=t_file)

		new_sbml_model.save()
		t_filename = os.path.join(settings.MEDIA_ROOT, str(new_sbml_model.sbml_file))

		doc = SbmlDocument()
		doc.readSbmlFromFile(t_filename)
		doc.model.setName(str(new_sbml_model.name))
		doc.writeSbmlToFile(t_filename)
Пример #15
0
def copyModelHierarchy(model_filename):

	doc = SbmlDocument()
	doc.readSbmlFromFile(model_filename)
	path = dirname(model_filename)
	master_filename = new_model_filename()

	if doc.useCompPackage:
		deps = doc.getExternalDocumentDependencies()
		new_deps = {}
		for dependency in deps:
			new_deps.update({dependency: copyModelHierarchy(join(path, dependency))})

		doc.renameExternalDocumentDependencies(new_deps)

	doc.writeSbmlToFile(join(path, master_filename))
	return master_filename
Пример #16
0
    def getModelSubmodels(self, request, model_id):
        """ Returning the submodels of a model available within the project
		"""
        if self.isUserLoggedIn(request) and self.project is not None:
            t_models = [
                pm for pm in self.getProjectModels(request)
                if pm.id != self.model_id
            ]
            t_filename = os.path.join(settings.MEDIA_ROOT,
                                      str(t_models[model_id].sbml_file))
            doc = SbmlDocument()
            doc.readSbmlFromFile(t_filename)
            if doc.useCompPackage:
                return [doc.model.getSbmlId()
                        ] + doc.listOfModelDefinitions.sbmlIds(
                        ) + doc.listOfExternalModelDefinitions.sbmlIds()
            else:
                return [doc.model.getSbmlId()]
Пример #17
0
def copyModelHierarchy(model_filename):

    doc = SbmlDocument()
    doc.readSbmlFromFile(model_filename)
    path = dirname(model_filename)
    master_filename = new_model_filename()

    if doc.useCompPackage:
        deps = doc.getExternalDocumentDependencies()
        new_deps = {}
        for dependency in deps:
            new_deps.update(
                {dependency: copyModelHierarchy(join(path, dependency))})

        doc.renameExternalDocumentDependencies(new_deps)

    doc.writeSbmlToFile(join(path, master_filename))
    return master_filename
Пример #18
0
    def loadModel(self, request):

        self.fileUploadForm = DocumentForm(request.POST, request.FILES)
        if self.fileUploadForm.is_valid():

            new_sbml_model = SbmlModel(project=self.project,
                                       sbml_file=request.FILES['docfile'])
            new_sbml_model.save()

            try:
                doc = SbmlDocument()
                doc.readSbmlFromFile(
                    os.path.join(settings.MEDIA_ROOT,
                                 str(new_sbml_model.sbml_file)))

                dependencies = getDetailedModelDependencies(doc)
                if len(dependencies) > 0:

                    for submodel_filename, submodel_ref in dependencies:
                        submodel_filename = join(self.project.folder, "models",
                                                 submodel_filename)
                        submodel = SbmlModel.objects.get(
                            sbml_file=submodel_filename)
                        new_dependency = ModelsDependency(
                            project=self.project,
                            model=new_sbml_model,
                            submodel=submodel,
                            submodel_ref=submodel_ref)
                        new_dependency.save()

                new_sbml_model.name = doc.model.getName()
                new_sbml_model.save()

            except MissingSubmodelException:
                new_sbml_model.delete()
                self.addError(
                    "This model is importing some models which were not found in the project folder. Please import them first"
                )

            # Is triggered where name is None ??
            except ModelException:
                name = os.path.splitext(str(new_sbml_model.sbml_file))[0]
                new_sbml_model.name = name
                new_sbml_model.save()
Пример #19
0
    def duplicateModel(self, request):

        model = SbmlModel.objects.get(id=request.POST['id'])
        t_file = File(
            open(os.path.join(settings.MEDIA_ROOT, str(model.sbml_file)),
                 'rb'))

        new_sbml_model = SbmlModel(project=self.project,
                                   name=("%s (copy)" % str(model.name)),
                                   sbml_file=t_file)

        new_sbml_model.save()
        t_filename = os.path.join(settings.MEDIA_ROOT,
                                  str(new_sbml_model.sbml_file))

        doc = SbmlDocument()
        doc.readSbmlFromFile(t_filename)
        doc.model.setName(str(new_sbml_model.name))
        doc.writeSbmlToFile(t_filename)
Пример #20
0
    def __loadModelVariables(self):

        if self.model_id is not None and SbmlModel.objects.filter(
                id=self.model_id).exists():

            t_model = SbmlModel.objects.get(id=self.model_id)

            if self.isProjectOwner(
                    self.__request) or t_model.project.access == "PU":
                self.model_filename = os.path.join(settings.MEDIA_ROOT,
                                                   str(t_model.sbml_file))

                t_doc = SbmlDocument()
                t_doc.readSbmlFromFile(self.model_filename)
                self.model = t_doc.model
                self.model_name = self.model.getName()

                self.model_list_of_submodels = self.model.listOfSubmodels
                self.model_list_of_submodels_names = []
                self.model_list_of_submodels_types = []
                for submodel in self.model.listOfSubmodels:
                    if submodel.getModelRef(
                    ) in self.model.parentDoc.listOfModelDefinitions.sbmlIds():
                        self.model_list_of_submodels_names.append(
                            self.model.parentDoc.listOfModelDefinitions.
                            getBySbmlId(
                                submodel.getModelRef()).getNameOrSbmlId())
                        self.model_list_of_submodels_types.append(0)
                    if submodel.getModelRef(
                    ) in self.model.parentDoc.listOfExternalModelDefinitions.sbmlIds(
                    ):
                        self.model_list_of_submodels_names.append(
                            self.model.parentDoc.
                            listOfExternalModelDefinitions.getBySbmlId(
                                submodel.getModelRef()).getNameOrSbmlId())
                        self.model_list_of_submodels_types.append(1)
            else:
                raise PermissionDenied

        else:
            raise Http404("The model doesn't exist !")
Пример #21
0
	def loadModel(self, request):

		self.fileUploadForm = DocumentForm(request.POST, request.FILES)
		if self.fileUploadForm.is_valid():

			new_sbml_model = SbmlModel(project=self.project, sbml_file=request.FILES['docfile'])
			new_sbml_model.save()

			try:
				doc = SbmlDocument()
				doc.readSbmlFromFile(os.path.join(settings.MEDIA_ROOT, str(new_sbml_model.sbml_file)))

				dependencies = getDetailedModelDependencies(doc)
				if len(dependencies) > 0:

					for submodel_filename, submodel_ref in dependencies:
						submodel_filename = join(self.project.folder, "models", submodel_filename)
						submodel = SbmlModel.objects.get(sbml_file=submodel_filename)
						new_dependency = ModelsDependency(
							project=self.project,
							model=new_sbml_model,
							submodel=submodel,
							submodel_ref=submodel_ref
						)
						new_dependency.save()

				new_sbml_model.name = doc.model.getName()
				new_sbml_model.save()

			except MissingSubmodelException:
				new_sbml_model.delete()
				self.addError(
					"This model is importing some models which were not found in the project folder. Please import them first")

			# Is triggered where name is None ??
			except ModelException:
				name = os.path.splitext(str(new_sbml_model.sbml_file))[0]
				new_sbml_model.name = name
				new_sbml_model.save()
Пример #22
0
    def getListOfObjects(self, request):

        if str(request.POST['model_id']) != "":
            list_of_project_models = [
                pm for pm in self.getProjectModels(request)
                if pm.id != self.model_id
            ]

            t_model = list_of_project_models[int(request.POST['model_id'])]
            t_filename = join(settings.MEDIA_ROOT, str(t_model.sbml_file))
            doc = SbmlDocument()
            doc.readSbmlFromFile(t_filename)

            if ('submodel_id' in request.POST
                    and request.POST['submodel_id'] != ""
                    and int(request.POST['submodel_id']) > 1):

                submodel = doc.model.listOfSubmodels[
                    int(request.POST['submodel_id']) - 1].getModelObject()
                self.listOfObjects = []
                for t_object in doc.model.listOfSbmlObjects:
                    if isinstance(t_object,
                                  Variable) and not t_object.isStoichiometry():
                        self.listOfObjects.append(t_object.getNameOrSbmlId() +
                                                  (" (%s)" %
                                                   type(t_object).__name__))

                return self.listOfObjects

            else:
                self.listOfObjects = []
                for t_object in doc.model.listOfSbmlObjects:
                    if isinstance(t_object,
                                  Variable) and not t_object.isStoichiometry():
                        self.listOfObjects.append(t_object.getNameOrSbmlId() +
                                                  (" (%s)" %
                                                   type(t_object).__name__))

                return self.listOfObjects
	def loadSimulation(self, request):

		self.fileUploadForm = DocumentForm(request.POST, request.FILES)
		if self.fileUploadForm.is_valid():

			sedml_archive = SEDMLSimulation(project=self.project, sedml_file=request.FILES['docfile'])
			sedml_archive.name = basename(str(request.FILES['docfile'])).split('.')[0]
			sedml_archive.save()

			# Now everything is in the same folder
			sedml_doc = SedmlDocument()
			sedml_doc.readSedmlFromFile(join(settings.MEDIA_ROOT, str(sedml_archive.sedml_file)))
			sedml_doc.listOfModels.removePaths()

			sbml_files = sedml_doc.listOfModels.makeLocalSources()

			for sbml_file in sbml_files:

				if len(SbmlModel.objects.filter(project=self.project, sbml_file=join(join(str(self.project.folder), "models"), basename(sbml_file)))) == 0:

					sbml_model = SbmlModel(project=self.project, sbml_file=File(open(sbml_file, 'rb')))
					sbml_model.save()
					try:
						doc = SbmlDocument()

						doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(sbml_model.sbml_file)))

						sbml_model.name = doc.model.getName()
						sbml_model.save()
					except Exception:
						name = splitext(str(sbml_model.sbml_file))[0]
						sbml_model.name = name
						sbml_model.save()

			sedml_doc.writeSedmlToFile(join(settings.MEDIA_ROOT, str(sedml_archive.sedml_file)))
			self.loadListOfSimulations()
Пример #24
0
	def testRule(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)

		files_folder = join(dirname(__file__), "files")
		model_filename = join(files_folder, "modelqlzB7i.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)

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		listOfRules = sbml_model.listOfRules + sbml_model.listOfInitialAssignments
		listOfVariables = []
		for variable in sbml_model.listOfVariables:
			if ((variable.isParameter() and variable.isGlobal())
				or variable.isSpecies()
				or variable.isCompartment()
				or variable.isStoichiometry()):
				listOfVariables.append(variable)

		rule = listOfRules[0]

		response_get_compartment = c.post('/json/get_rule/', {
			'rule_ind': '0',
		})

		self.assertEqual(response_get_compartment.status_code, 200)
		json_response = loads(response_get_compartment.content.decode('utf-8'))


		self.assertEqual(json_response[u'rule_id'], listOfRules.index(rule))
		self.assertEqual(json_response[u'rule_type'], 1)
		self.assertEqual(json_response[u'variable'], listOfVariables.index(sbml_model.listOfVariables.getBySbmlId('total_ras_gtp')))

		response_choose_project = c.post('/models/', {
			'action': 'choose_project',
			'project_id': 0
		})
		self.assertEqual(response_choose_project.status_code, 200)
		self.assertEqual(response_choose_project.context['project_name'], "Project")

		response_choose_model = c.post('/edit/rules/', {
			'action': 'choose_model',
			'model_id': 0
		})
		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(response_choose_model.context['model_name'], "SOS-Ras-MAPK with n17")

		response_save_rule = c.post('/edit/rules/', {
			'action': 'save',
			'rule_id': listOfRules.index(rule),
			'rule_type': 1,
			'variable_id': listOfVariables.index(sbml_model.listOfVariables.getBySbmlId('total_mapk_activated')),
			'rule_expression': "75*ras_gtp",
		})

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

		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		listOfRules = sbml_model.listOfRules + sbml_model.listOfInitialAssignments
		listOfVariables = []
		for variable in sbml_model.listOfVariables:
			if ((variable.isParameter() and variable.isGlobal())
				or variable.isSpecies()
				or variable.isCompartment()
				or variable.isStoichiometry()):
				listOfVariables.append(variable)

		rule = listOfRules[0]


		self.assertEqual(rule.getType(), 1)
		self.assertEqual(rule.getVariable(), sbml_model.listOfVariables.getBySbmlId('total_mapk_activated'))
		formula = MathFormula(sbml_model)
		formula.setPrettyPrintMathFormula("75*ras_gtp", rawFormula=True)
		self.assertEqual(simplify(rule.getDefinition().getDeveloppedInternalMathFormula()-formula.getDeveloppedInternalMathFormula()), 0)

		response_delete_rule = c.post('/edit/rules/', {
			'action': 'delete',
			'rule_id': 0
		})
		self.assertEqual(response_delete_rule.status_code, 200)
		self.assertEqual(response_delete_rule.context['form'].getErrors(), [])
Пример #25
0
    def testUnits(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)

        files_folder = join(dirname(__file__), "files")
        model_filename = join(files_folder, "modelqlzB7i.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)

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()

        response_choose_project = c.post('/models/', {
            'action': 'choose_project',
            'project_id': 0
        })
        self.assertEqual(response_choose_project.status_code, 200)
        self.assertEqual(response_choose_project.context['project_name'],
                         "Project")

        response_choose_model = c.post('/edit/units/', {
            'action': 'choose_model',
            'model_id': 0
        })
        self.assertEqual(response_choose_model.status_code, 200)
        self.assertEqual(response_choose_model.context['model_name'],
                         "SOS-Ras-MAPK with n17")

        self.assertEqual(response_choose_model.context['unit_definitions'], [
            'Litre', 'Nanomoles', 'Nanomoles per litre', 'Seconds',
            'per Seconds', 'per Nanomoles ', 'Dimensionless',
            'per Nanomoles per Seconds', 'Nanomoles per seconds',
            'Nanomoles per litre per seconds',
            'per Nanomoles per liter per Seconds'
        ])

        response_save_unit = c.post(
            '/edit/units/', {
                'action': 'save',
                'unit_definition_id': '',
                'unit_definition_name': "Nanomolars",
                'unit_definition_identifier': "nanomolars",
                'subunit_id_0': list(Unit.unit_id.values()).index("mole"),
                'subunit_exponent_0': 1,
                'subunit_scale_0': -9,
                'subunit_multiplier_0': 1,
                'subunit_id_1': list(Unit.unit_id.values()).index("litre"),
                'subunit_exponent_1': -1,
                'subunit_scale_1': 1,
                'subunit_multiplier_1': 1,
            })

        self.assertEqual(response_save_unit.status_code, 200)
        self.assertEqual(response_save_unit.context['form'].getErrors(), [])
        self.assertEqual(response_save_unit.context['unit_definitions'], [
            'Litre', 'Nanomoles', 'Nanomoles per litre', 'Seconds',
            'per Seconds', 'per Nanomoles ', 'Dimensionless',
            'per Nanomoles per Seconds', 'Nanomoles per seconds',
            'Nanomoles per litre per seconds',
            'per Nanomoles per liter per Seconds', 'Nanomolars'
        ])

        response_get_unit_definition = c.post(
            '/json/get_unit_definition/', {
                'id':
                response_save_unit.context['unit_definitions'].index(
                    'Nanomolars'),
            })
        self.assertEqual(response_get_unit_definition.status_code, 200)
        json_response = loads(
            response_get_unit_definition.content.decode('utf-8'))

        self.assertEqual(json_response[u'unit_id'], "nanomolars")
        self.assertEqual(json_response[u'name'], "Nanomolars")
        self.assertEqual(json_response[u'desc'], "nmole.litre^-1")
        self.assertEqual(json_response[u'list_of_units'][0],
                         [u'nmole', 20, u'mole', 1, -9, 1.0])
        self.assertEqual(json_response[u'list_of_units'][1],
                         [u'litre^-1', 16, u'litre', -1, 1, 1.0])

        response_delete_unit_definition = c.post(
            '/edit/units/', {
                'action':
                'delete',
                'id':
                response_save_unit.context['unit_definitions'].index(
                    'Nanomolars')
            })

        self.assertEqual(response_delete_unit_definition.status_code, 200)
        self.assertEqual(
            response_delete_unit_definition.context['unit_definitions'], [
                'Litre', 'Nanomoles', 'Nanomoles per litre', 'Seconds',
                'per Seconds', 'per Nanomoles ', 'Dimensionless',
                'per Nanomoles per Seconds', 'Nanomoles per seconds',
                'Nanomoles per litre per seconds',
                'per Nanomoles per liter per Seconds'
            ])
Пример #26
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)
Пример #27
0
    def testReactions(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)

        files_folder = join(dirname(__file__), "files")
        model_filename = join(files_folder, "modelqlzB7i.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)

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        reaction = sbml_model.listOfReactions.getBySbmlId('reaction_4')

        response_choose_project = c.post('/models/', {
            'action': 'choose_project',
            'project_id': 0
        })
        self.assertEqual(response_choose_project.status_code, 200)
        self.assertEqual(response_choose_project.context['project_name'],
                         "Project")

        response_choose_model = c.post('/edit/reactions/', {
            'action': 'choose_model',
            'model_id': 0
        })
        self.assertEqual(response_choose_model.status_code, 200)
        self.assertEqual(response_choose_model.context['model_name'],
                         "SOS-Ras-MAPK with n17")
        self.assertEqual([
            t_reaction.getReactionDescription() for t_reaction in
            response_choose_model.context['list_of_reactions']
        ], [
            t_reaction.getReactionDescription()
            for t_reaction in sbml_model.listOfReactions
        ])

        response_get_reaction = c.post('/json/get_reaction/',
                                       {'sbml_id': 'reaction_4'})

        self.assertEqual(response_get_reaction.status_code, 200)
        json_response = loads(response_get_reaction.content.decode('utf-8'))

        self.assertEqual(json_response[u'id'],
                         sbml_model.listOfReactions.index(reaction))
        self.assertEqual(json_response[u'sbml_id'], reaction.getSbmlId())
        self.assertEqual(json_response[u'name'], reaction.getName())
        self.assertEqual(json_response[u'kinetic_law'],
                         reaction.kineticLaw.getPrettyPrintMathFormula())
        self.assertEqual(json_response[u'reaction_type'],
                         reaction.getReactionType())
        self.assertEqual(json_response[u'reaction_type_name'],
                         KineticLaw.reactionTypes[reaction.getReactionType()])
        self.assertEqual(json_response[u'reversible'], reaction.reversible)

        self.assertEqual(json_response[u'list_of_reactants'], [[
            sbml_model.listOfSpecies.index(reactant.getSpecies()),
            reactant.stoichiometry.getPrettyPrintMathFormula()
        ] for reactant in reaction.listOfReactants])
        self.assertEqual(json_response[u'list_of_modifiers'], [[
            sbml_model.listOfSpecies.index(modifier.getSpecies()),
            modifier.stoichiometry.getPrettyPrintMathFormula()
        ] for modifier in reaction.listOfModifiers])
        self.assertEqual(json_response[u'list_of_products'], [[
            sbml_model.listOfSpecies.index(product.getSpecies()),
            product.stoichiometry.getPrettyPrintMathFormula()
        ] for product in reaction.listOfProducts])

        response_delete_reaction = c.post('/edit/reactions/', {
            'action': 'delete',
            'reaction_id': 2
        })

        self.assertEqual(response_delete_reaction.status_code, 200)

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        self.assertEqual(len(sbml_model.listOfReactions), 21)
        self.assertEqual(sbml_model.listOfReactions.getBySbmlId('reaction_4'),
                         None)
        response_create_creation = c.post(
            '/edit/reactions/', {
                'action': 'save',
                'reaction_id': "",
                'reaction_sbml_id': "reaction_4",
                'reaction_name': "Ras activation by SOS-Ras-GDP",
                'reaction_reactant_0': 1,
                'reaction_reactant_0_stoichiometry': "1",
                'reaction_modifier_0': 3,
                'reaction_modifier_0_stoichiometry': "1",
                'reaction_product_0': 2,
                'reaction_product_0_stoichiometry': "1",
                'reaction_type': 1,
                'reaction_parameter_0': 2,
                'reaction_parameter_1': 3,
                'reaction_sboterm': ""
            })

        self.assertEqual(response_create_creation.status_code, 200)
        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        reaction = sbml_model.listOfReactions.getBySbmlId('reaction_4')
        self.assertEqual(len(sbml_model.listOfReactions), 22)
        self.assertEqual(reaction.getName(), "Ras activation by SOS-Ras-GDP")

        response_modify_creation = c.post(
            '/edit/reactions/', {
                'action': 'save',
                'reaction_id': sbml_model.listOfReactions.index(reaction),
                'reaction_sbml_id': "reaction_4",
                'reaction_name': "Ras activation by SOS-Ras-GDP, modified",
                'reaction_reactant_0': 1,
                'reaction_reactant_0_stoichiometry': "1",
                'reaction_modifier_0': 3,
                'reaction_modifier_0_stoichiometry': "1",
                'reaction_product_0': 2,
                'reaction_product_0_stoichiometry': "1",
                'reaction_type': 1,
                'reaction_parameter_0': 2,
                'reaction_parameter_1': 3,
                'reaction_sboterm': ""
            })

        self.assertEqual(response_modify_creation.status_code, 200)
        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        reaction = sbml_model.listOfReactions.getBySbmlId('reaction_4')
        self.assertEqual(len(sbml_model.listOfReactions), 22)
        self.assertEqual(reaction.getName(),
                         "Ras activation by SOS-Ras-GDP, modified")
Пример #28
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)
Пример #29
0
    def testCompartment(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)

        files_folder = join(dirname(__file__), "files")
        model_filename = join(files_folder, "modelqlzB7i.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)

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        compartment = sbml_model.listOfCompartments.getBySbmlId('cell')

        response_get_compartment = c.post('/json/get_compartment/', {
            'sbml_id': 'cell',
        })

        self.assertEqual(response_get_compartment.status_code, 200)
        json_response = loads(response_get_compartment.content.decode('utf-8'))

        self.assertEqual(json_response[u'id'],
                         sbml_model.listOfCompartments.index(compartment))
        self.assertEqual(json_response[u'sbml_id'], compartment.getSbmlId())
        self.assertEqual(json_response[u'name'], compartment.getName())
        self.assertEqual(json_response[u'value'], compartment.getValue())
        self.assertEqual(json_response[u'constant'],
                         1 if compartment.constant else 0)

        response_choose_project = c.post('/models/', {
            'action': 'choose_project',
            'project_id': 0
        })
        self.assertEqual(response_choose_project.status_code, 200)
        self.assertEqual(response_choose_project.context['project_name'],
                         "Project")

        response_choose_model = c.post('/edit/compartments/', {
            'action': 'choose_model',
            'model_id': 0
        })
        self.assertEqual(response_choose_model.status_code, 200)
        self.assertEqual(response_choose_model.context['model_name'],
                         "SOS-Ras-MAPK with n17")

        response_save_compartment = c.post(
            '/edit/compartments/', {
                'action': 'save',
                'compartment_id':
                sbml_model.listOfCompartments.index(compartment),
                'compartment_name': "New name",
                'compartment_sbml_id': "new_name",
                'compartment_size': 75,
                'compartment_unit': 2,
                'compartment_constant': "on",
                'compartment_sboterm': "",
            })

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

        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        compartment = sbml_model.listOfCompartments.getBySbmlId('new_name')

        self.assertTrue(compartment is not None)
        self.assertEqual(compartment.getName(), "New name")
        self.assertEqual(compartment.getValue(), 75)
        self.assertEqual(compartment.constant, True)
        self.assertEqual(compartment.getUnits(),
                         sbml_model.listOfUnitDefinitions[2])

        response_delete_compartment = c.post(
            '/edit/compartments/', {
                'action': 'delete',
                'compartment_id':
                sbml_model.listOfCompartments.index(compartment)
            })
        self.assertEqual(response_delete_compartment.status_code, 200)
        self.assertEqual(response_delete_compartment.context['getErrors'],
                         ['Compartment contains 25 species'])

        response_save_new_compartment = c.post(
            '/edit/compartments/', {
                'action': 'save',
                'compartment_id': "",
                'compartment_name': "New compartment",
                'compartment_sbml_id': "new_compartment",
                'compartment_size': 75,
                'compartment_unit': "",
                'compartment_constant': "on",
                'compartment_sboterm': "",
            })

        self.assertEqual(response_save_new_compartment.status_code, 200)

        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        compartment = sbml_model.listOfCompartments.getBySbmlId(
            'new_compartment')

        self.assertTrue(compartment != None)
        self.assertEqual(compartment.getName(), "New compartment")
        self.assertEqual(compartment.getValue(), 75)
        self.assertEqual(compartment.getUnits(), None)
        self.assertEqual(compartment.constant, True)

        response_delete_compartment = c.post(
            '/edit/compartments/', {
                'action': 'delete',
                'compartment_id':
                sbml_model.listOfCompartments.index(compartment)
            })
        self.assertEqual(response_delete_compartment.status_code, 200)
        self.assertEqual(response_delete_compartment.context['getErrors'], [])
Пример #30
0
	def testCreateModel(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)

		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('/edit/species/', {
			'action': 'choose_model',
			'model_id': 0
		})
		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(
			[sbml_model.name for sbml_model in response_choose_model.context['sbml_models']],
			[u'SOS', u'Ras', u'MAPK', u'SOS-Ras-MAPK']
		)
		self.assertEqual(
			[submodel for submodel in response_choose_model.context['model_submodels']],
			['Model definition']
		)

		self.assertEqual(
			[species.getNameOrSbmlId() for species in response_choose_model.context['list_of_species']],
			['SOS', 'SOS_inactive', 'FGF2', 'ERK-PP']
		)

		response_choose_model = c.post('/edit/species/', {
			'action': 'choose_model',
			'model_id': 1
		})
		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(
			[sbml_model.name for sbml_model in response_choose_model.context['sbml_models']],
			[u'SOS', u'Ras', u'MAPK', u'SOS-Ras-MAPK']
		)
		self.assertEqual(
			[submodel for submodel in response_choose_model.context['model_submodels']],
			['Model definition']
		)

		self.assertEqual(
			[species.getNameOrSbmlId() for species in response_choose_model.context['list_of_species']],
			[
				'SOS', 'Ras-GDP', 'Ras-GTP', 'SOS-Ras-GDP', 'SOS-Ras-GTP',
				'GAP', 'GEF', 'Ras-N17', 'SOS-Ras-N17', 'GEF-RasN17', 'Total Ras-GTP'
			]
		)

		response_choose_model = c.post('/edit/species/', {
			'action': 'choose_model',
			'model_id': 2
		})

		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(
			[sbml_model.name for sbml_model in response_choose_model.context['sbml_models']],
			[u'SOS', u'Ras', u'MAPK', u'SOS-Ras-MAPK']
		)
		self.assertEqual(
			[submodel for submodel in response_choose_model.context['model_submodels']],
			['Model definition']
		)

		self.assertEqual(
			[species.getNameOrSbmlId() for species in response_choose_model.context['list_of_species']],
			[
				'Ras-GTP', 'Raf', 'Raf-P', 'Mek', 'Mek-P', 'Mek-PP',
				'Mapk', 'Mapk-P', 'Mapk-PP', 'Total MEK activated', 'Total MAPK activated'
			]
		)

		response_choose_model = c.post('/edit/species/', {
			'action': 'choose_model',
			'model_id': 3
		})
		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(
			[sbml_model.name for sbml_model in response_choose_model.context['sbml_models']],
			[u'SOS', u'Ras', u'MAPK', u'SOS-Ras-MAPK']
		)
		self.assertEqual(
			[submodel for submodel in response_choose_model.context['model_submodels']],
			['Model definition', 'Test submodel']
		)

		self.assertEqual(
			[species.getNameOrSbmlId() for species in response_choose_model.context['list_of_species']],
			['SOS', 'Ras-GTP', 'ERK-PP']
		)


		response_choose_submodel = c.post('/edit/species/', {
			'action': 'choose_submodel',
			'submodel_id': 0
		})
		self.assertEqual(response_choose_submodel.status_code, 200)
		self.assertEqual(
			[species.getNameOrSbmlId() for species in response_choose_submodel.context['list_of_species']],
			['SOS', 'Ras-GTP', 'ERK-PP']
		)

		response_choose_submodel = c.post('/edit/species/', {
			'action': 'choose_submodel',
			'submodel_id': 2
		})
		self.assertEqual(response_choose_submodel.status_code, 200)
		self.assertEqual(
			[species.getNameOrSbmlId() for species in response_choose_submodel.context['list_of_species']],
			['SOS', 'Ras-GTP', 'ERK-PP', 'SOS_inactive', 'FGF2', 'Ras-GDP', 'SOS-Ras-GDP', 'SOS-Ras-GTP', 'GAP', 'GEF',
			 'Ras-N17', 'SOS-Ras-N17', 'GEF-RasN17', 'Total Ras-GTP', 'Raf', 'Raf-P', 'Mek', 'Mek-P', 'Mek-PP', 'Mapk',
			 'Mapk-P', 'Total MEK activated', 'Total MAPK activated']
		)

		response_choose_submodel = c.post('/edit/species/', {
			'action': 'choose_submodel',
			'submodel_id': 2
		})

		self.assertEqual(response_choose_submodel.status_code, 200)
		self.assertEqual(
			[species.getNameOrSbmlId() for species in response_choose_submodel.context['list_of_species']],
			['SOS', 'Ras-GTP', 'ERK-PP', 'SOS_inactive', 'FGF2', 'Ras-GDP', 'SOS-Ras-GDP', 'SOS-Ras-GTP', 'GAP', 'GEF',
			 'Ras-N17', 'SOS-Ras-N17', 'GEF-RasN17', 'Total Ras-GTP', 'Raf', 'Raf-P', 'Mek', 'Mek-P', 'Mek-PP', 'Mapk',
			 'Mapk-P', 'Total MEK activated', 'Total MAPK activated']
		)

		response_choose_submodel = c.post('/edit/submodels/', {
			'action': 'choose_submodel',
			'submodel_id': 0
		})
		self.assertEqual(response_choose_submodel.status_code, 200)
		self.assertEqual(response_choose_submodel.context['model_submodels'], ['Model definition', 'Test submodel'])

		response_add_submodel = c.post('/edit/submodels/', {
			'action': 'save',
			'submodel_id': "",
			'submodel_name': "Internal model",
			'submodel_sbml_id': "internal",
			'submodel_type': 0,
			'extent_conversion_factor': "",
			'time_conversion_factor': ""
		})

		self.assertEqual(response_add_submodel.status_code, 200)
		model = SbmlModel.objects.filter(project=project)[3]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.model
		self.assertEqual(sbml_doc.listOfModelDefinitions[1].getName(), "Internal model")
		self.assertEqual(sbml_model.listOfSubmodels[4].getSbmlId(), "internal")
		self.assertEqual(response_add_submodel.context['model_submodels'], ['Model definition', 'Test submodel', 'Internal model'])

		response_add_submodel = c.post('/edit/submodels/', {
			'action': 'save',
			'submodel_id': 4,
			'submodel_name': "Internal model, modified",
			'submodel_sbml_id': "internal_modified",
			'submodel_type': 0,
			'extent_conversion_factor': "",
			'time_conversion_factor': ""
		})

		self.assertEqual(response_add_submodel.status_code, 200)
		model = SbmlModel.objects.filter(project=project)[3]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.model
		self.assertEqual(sbml_doc.listOfModelDefinitions[1].getName(), "Internal model, modified")
		self.assertEqual(sbml_model.listOfSubmodels[4].getSbmlId(), "internal_modified")
		self.assertEqual(response_add_submodel.context['model_submodels'], ['Model definition', 'Test submodel', 'Internal model, modified'])
Пример #31
0
	def testCompartment(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)

		files_folder = join(dirname(__file__), "files")
		model_filename = join(files_folder, "modelqlzB7i.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)

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		compartment = sbml_model.listOfCompartments.getBySbmlId('cell')

		response_get_compartment = c.post('/json/get_compartment/', {
			'sbml_id': 'cell',
		})

		self.assertEqual(response_get_compartment.status_code, 200)
		json_response = loads(response_get_compartment.content.decode('utf-8'))

		self.assertEqual(json_response[u'id'], sbml_model.listOfCompartments.index(compartment))
		self.assertEqual(json_response[u'sbml_id'], compartment.getSbmlId())
		self.assertEqual(json_response[u'name'], compartment.getName())
		self.assertEqual(json_response[u'value'], compartment.getValue())
		self.assertEqual(json_response[u'constant'], 1 if compartment.constant else 0)

		response_choose_project = c.post('/models/', {
			'action': 'choose_project',
			'project_id': 0
		})
		self.assertEqual(response_choose_project.status_code, 200)
		self.assertEqual(response_choose_project.context['project_name'], "Project")

		response_choose_model = c.post('/edit/compartments/', {
			'action': 'choose_model',
			'model_id': 0
		})
		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(response_choose_model.context['model_name'], "SOS-Ras-MAPK with n17")

		response_save_compartment = c.post('/edit/compartments/', {
			'action': 'save',
			'compartment_id': sbml_model.listOfCompartments.index(compartment),
			'compartment_name': "New name",
			'compartment_sbml_id': "new_name",
			'compartment_size': 75,
			'compartment_unit': 2,
			'compartment_constant': "on",
			'compartment_sboterm': "",
		})

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

		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		compartment = sbml_model.listOfCompartments.getBySbmlId('new_name')

		self.assertTrue(compartment is not None)
		self.assertEqual(compartment.getName(), "New name")
		self.assertEqual(compartment.getValue(), 75)
		self.assertEqual(compartment.constant, True)
		self.assertEqual(compartment.getUnits(), sbml_model.listOfUnitDefinitions[2])

		response_delete_compartment = c.post('/edit/compartments/', {
			'action': 'delete',
			'compartment_id': sbml_model.listOfCompartments.index(compartment)
		})
		self.assertEqual(response_delete_compartment.status_code, 200)
		self.assertEqual(response_delete_compartment.context['getErrors'], ['Compartment contains 25 species'])


		response_save_new_compartment = c.post('/edit/compartments/', {
			'action': 'save',
			'compartment_id': "",
			'compartment_name': "New compartment",
			'compartment_sbml_id': "new_compartment",
			'compartment_size': 75,
			'compartment_unit': "",
			'compartment_constant': "on",
			'compartment_sboterm': "",
		})

		self.assertEqual(response_save_new_compartment.status_code, 200)

		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		compartment = sbml_model.listOfCompartments.getBySbmlId('new_compartment')

		self.assertTrue(compartment != None)
		self.assertEqual(compartment.getName(), "New compartment")
		self.assertEqual(compartment.getValue(), 75)
		self.assertEqual(compartment.getUnits(), None)
		self.assertEqual(compartment.constant, True)


		response_delete_compartment = c.post('/edit/compartments/', {
			'action': 'delete',
			'compartment_id': sbml_model.listOfCompartments.index(compartment)
		})
		self.assertEqual(response_delete_compartment.status_code, 200)
		self.assertEqual(response_delete_compartment.context['getErrors'], [])
Пример #32
0
    def testEvents(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)

        files_folder = join(dirname(__file__), "files")
        model_filename = join(files_folder, "modelqlzB7i.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)

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        listOfVariables = []
        for variable in sbml_model.listOfVariables:
            if ((variable.isParameter() and variable.isGlobal())
                    or variable.isSpecies() or variable.isCompartment()
                    or variable.isStoichiometry()):
                listOfVariables.append(variable)

        response_choose_project = c.post('/models/', {
            'action': 'choose_project',
            'project_id': 0
        })
        self.assertEqual(response_choose_project.status_code, 200)
        self.assertEqual(response_choose_project.context['project_name'],
                         "Project")

        response_choose_model = c.post('/edit/events/', {
            'action': 'choose_model',
            'model_id': 0
        })
        self.assertEqual(response_choose_model.status_code, 200)
        self.assertEqual(response_choose_model.context['model_name'],
                         "SOS-Ras-MAPK with n17")

        response_save_event = c.post(
            '/edit/events/', {
                'action':
                'save',
                'event_id':
                '',
                'event_sbmlid':
                'test_event',
                'event_name':
                "Test event",
                'event_trigger':
                "time==0",
                'event_priority':
                "",
                'event_delay':
                "",
                'event_assignment_0_id':
                listOfVariables.index(
                    sbml_model.listOfVariables.getBySbmlId('ras_gtp')),
                'event_assignment_0_expression':
                'ras_gtp*2'
            })

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

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        listOfVariables = []
        for variable in sbml_model.listOfVariables:
            if ((variable.isParameter() and variable.isGlobal())
                    or variable.isSpecies() or variable.isCompartment()
                    or variable.isStoichiometry()):
                listOfVariables.append(variable)

        response_get_event = c.post('/json/get_event/', {
            'event_ind': '0',
        })

        self.assertEqual(response_get_event.status_code, 200)
        json_response = loads(response_get_event.content.decode('utf-8'))

        self.assertEqual(json_response[u'event_ind'], 0)
        self.assertEqual(json_response[u'event_name'], "Test event")

        formula = MathFormula(sbml_model)
        formula.setPrettyPrintMathFormula("time==0", rawFormula=True)

        formula_response = MathFormula(sbml_model)
        formula_response.setPrettyPrintMathFormula(
            json_response[u'event_trigger'], rawFormula=True)

        self.assertEqual(
            simplify(formula.getDeveloppedInternalMathFormula() -
                     formula_response.getDeveloppedInternalMathFormula()), 0)
        self.assertEqual(json_response[u'event_delay'], "")
        self.assertEqual(
            json_response[u'list_of_assignments'][0][0],
            listOfVariables.index(
                sbml_model.listOfVariables.getBySbmlId('ras_gtp')))

        formula = MathFormula(sbml_model)
        formula.setPrettyPrintMathFormula("ras_gtp*2", rawFormula=True)

        formula_response = MathFormula(sbml_model)
        formula_response.setPrettyPrintMathFormula(
            json_response[u'list_of_assignments'][0][2], rawFormula=True)
        self.assertEqual(
            simplify(formula.getDeveloppedInternalMathFormula() -
                     formula_response.getDeveloppedInternalMathFormula()), 0)
        self.assertTrue(u'event_assignment_variable_1' not in json_response)

        # Modifying an event
        response_save_event = c.post(
            '/edit/events/', {
                'action':
                'save',
                'event_id':
                '0',
                'event_sbmlid':
                'test_event',
                'event_name':
                "Test event",
                'event_trigger':
                "time==100",
                'event_priority':
                "",
                'event_delay':
                "",
                'event_assignment_0_id':
                listOfVariables.index(
                    sbml_model.listOfVariables.getBySbmlId('ras_gtp')),
                'event_assignment_0_expression':
                'ras_gtp*2',
                'event_assignment_1_id':
                listOfVariables.index(
                    sbml_model.listOfVariables.getBySbmlId('ras_gdp')),
                'event_assignment_1_expression':
                'ras_gdp/2',
            })
        self.assertEqual(response_save_event.status_code, 200)
        self.assertEqual(response_save_event.context['form'].getErrors(), [])

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        event = sbml_model.listOfEvents[0]
        listOfVariables = []
        for variable in sbml_model.listOfVariables:
            if ((variable.isParameter() and variable.isGlobal())
                    or variable.isSpecies() or variable.isCompartment()
                    or variable.isStoichiometry()):
                listOfVariables.append(variable)

        self.assertEqual(event.getNameOrSbmlId(), "Test event")

        formula = MathFormula(sbml_model)
        formula.setPrettyPrintMathFormula("time==100", rawFormula=True)

        self.assertEqual(
            simplify(formula.getDeveloppedInternalMathFormula() -
                     event.trigger.getDeveloppedInternalMathFormula()), 0)

        self.assertEqual(event.priority, None)
        self.assertEqual(event.delay, None)
        self.assertEqual(event.listOfEventAssignments[0].getVariable(),
                         sbml_model.listOfVariables.getBySbmlId('ras_gtp'))

        formula = MathFormula(sbml_model)
        formula.setPrettyPrintMathFormula("ras_gtp*2")

        self.assertEqual(
            simplify(formula.getDeveloppedInternalMathFormula() -
                     event.listOfEventAssignments[0].getDefinition(
                     ).getDeveloppedInternalMathFormula()), 0)

        self.assertEqual(event.listOfEventAssignments[1].getVariable(),
                         sbml_model.listOfVariables.getBySbmlId('ras_gdp'))

        formula = MathFormula(sbml_model)
        formula.setPrettyPrintMathFormula("ras_gdp/2")

        self.assertEqual(
            simplify(formula.getDeveloppedInternalMathFormula() -
                     event.listOfEventAssignments[1].getDefinition(
                     ).getDeveloppedInternalMathFormula()), 0)

        response_delete_event = c.post('/edit/events/', {
            'action': 'delete',
            'event_id': 0
        })
        self.assertEqual(response_delete_event.status_code, 200)
        self.assertEqual(response_delete_event.context['form'].getErrors(), [])

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        self.assertEqual(len(sbml_model.listOfEvents), 0)
Пример #33
0
	def testReactions(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)

		files_folder = join(dirname(__file__), "files")
		model_filename = join(files_folder, "modelqlzB7i.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)

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		reaction = sbml_model.listOfReactions.getBySbmlId('reaction_4')

		response_choose_project = c.post('/models/', {
			'action': 'choose_project',
			'project_id': 0
		})
		self.assertEqual(response_choose_project.status_code, 200)
		self.assertEqual(response_choose_project.context['project_name'], "Project")

		response_choose_model = c.post('/edit/reactions/', {
			'action': 'choose_model',
			'model_id': 0
		})
		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(response_choose_model.context['model_name'], "SOS-Ras-MAPK with n17")
		self.assertEqual(
			[t_reaction.getReactionDescription() for t_reaction in response_choose_model.context['list_of_reactions']],
			[t_reaction.getReactionDescription() for t_reaction in sbml_model.listOfReactions]
		)


		response_get_reaction = c.post('/json/get_reaction/', {
			'sbml_id': 'reaction_4'
		})

		self.assertEqual(response_get_reaction.status_code, 200)
		json_response = loads(response_get_reaction.content.decode('utf-8'))

		self.assertEqual(json_response[u'id'], sbml_model.listOfReactions.index(reaction))
		self.assertEqual(json_response[u'sbml_id'], reaction.getSbmlId())
		self.assertEqual(json_response[u'name'], reaction.getName())
		self.assertEqual(json_response[u'kinetic_law'], reaction.kineticLaw.getPrettyPrintMathFormula())
		self.assertEqual(json_response[u'reaction_type'], reaction.getReactionType())
		self.assertEqual(json_response[u'reaction_type_name'], KineticLaw.reactionTypes[reaction.getReactionType()])
		self.assertEqual(json_response[u'reversible'], reaction.reversible)

		self.assertEqual(json_response[u'list_of_reactants'], [
			[
				sbml_model.listOfSpecies.index(reactant.getSpecies()),
				reactant.stoichiometry.getPrettyPrintMathFormula()
			]
			for reactant in reaction.listOfReactants
		])
		self.assertEqual(json_response[u'list_of_modifiers'], [
			[
				sbml_model.listOfSpecies.index(modifier.getSpecies()),
				modifier.stoichiometry.getPrettyPrintMathFormula()
			]
			for modifier in reaction.listOfModifiers
		])
		self.assertEqual(json_response[u'list_of_products'], [
			[
				sbml_model.listOfSpecies.index(product.getSpecies()),
				product.stoichiometry.getPrettyPrintMathFormula()
			]
			for product in reaction.listOfProducts
		])

		response_delete_reaction = c.post('/edit/reactions/', {
			'action': 'delete',
			'reaction_id': 2
		})

		self.assertEqual(response_delete_reaction.status_code, 200)

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		self.assertEqual(len(sbml_model.listOfReactions), 21)
		self.assertEqual(sbml_model.listOfReactions.getBySbmlId('reaction_4'), None)
		response_create_creation = c.post('/edit/reactions/', {
			'action': 'save',
			'reaction_id': "",
			'reaction_sbml_id': "reaction_4",
			'reaction_name': "Ras activation by SOS-Ras-GDP",
			'reaction_reactant_0': 1,
			'reaction_reactant_0_stoichiometry': "1",
			'reaction_modifier_0': 3,
			'reaction_modifier_0_stoichiometry': "1",
			'reaction_product_0': 2,
			'reaction_product_0_stoichiometry': "1",
			'reaction_type': 1,
			'reaction_parameter_0': 2,
			'reaction_parameter_1': 3,
			'reaction_sboterm': ""
		})

		self.assertEqual(response_create_creation.status_code, 200)
		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		reaction = sbml_model.listOfReactions.getBySbmlId('reaction_4')
		self.assertEqual(len(sbml_model.listOfReactions), 22)
		self.assertEqual(reaction.getName(), "Ras activation by SOS-Ras-GDP")

		response_modify_creation = c.post('/edit/reactions/', {
			'action': 'save',
			'reaction_id': sbml_model.listOfReactions.index(reaction),
			'reaction_sbml_id': "reaction_4",
			'reaction_name': "Ras activation by SOS-Ras-GDP, modified",
			'reaction_reactant_0': 1,
			'reaction_reactant_0_stoichiometry': "1",
			'reaction_modifier_0': 3,
			'reaction_modifier_0_stoichiometry': "1",
			'reaction_product_0': 2,
			'reaction_product_0_stoichiometry': "1",
			'reaction_type': 1,
			'reaction_parameter_0': 2,
			'reaction_parameter_1': 3,
			'reaction_sboterm': ""
		})

		self.assertEqual(response_modify_creation.status_code, 200)
		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		reaction = sbml_model.listOfReactions.getBySbmlId('reaction_4')
		self.assertEqual(len(sbml_model.listOfReactions), 22)
		self.assertEqual(reaction.getName(), "Ras activation by SOS-Ras-GDP, modified")
Пример #34
0
	def testEvents(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)

		files_folder = join(dirname(__file__), "files")
		model_filename = join(files_folder, "modelqlzB7i.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)

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		listOfVariables = []
		for variable in sbml_model.listOfVariables:
			if ((variable.isParameter() and variable.isGlobal())
				or variable.isSpecies()
				or variable.isCompartment()
				or variable.isStoichiometry()):
				listOfVariables.append(variable)

		response_choose_project = c.post('/models/', {
			'action': 'choose_project',
			'project_id': 0
		})
		self.assertEqual(response_choose_project.status_code, 200)
		self.assertEqual(response_choose_project.context['project_name'], "Project")

		response_choose_model = c.post('/edit/events/', {
			'action': 'choose_model',
			'model_id': 0
		})
		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(response_choose_model.context['model_name'], "SOS-Ras-MAPK with n17")

		response_save_event = c.post('/edit/events/', {
			'action': 'save',
			'event_id': '',
			'event_sbmlid': 'test_event',
			'event_name': "Test event",
			'event_trigger': "time==0",
			'event_priority': "",
			'event_delay': "",
			'event_assignment_0_id': listOfVariables.index(sbml_model.listOfVariables.getBySbmlId('ras_gtp')),
			'event_assignment_0_expression': 'ras_gtp*2'
		})

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

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		listOfVariables = []
		for variable in sbml_model.listOfVariables:
			if ((variable.isParameter() and variable.isGlobal())
				or variable.isSpecies()
				or variable.isCompartment()
				or variable.isStoichiometry()):
				listOfVariables.append(variable)

		response_get_event = c.post('/json/get_event/', {
			'event_ind': '0',
		})

		self.assertEqual(response_get_event.status_code, 200)
		json_response = loads(response_get_event.content.decode('utf-8'))

		self.assertEqual(json_response[u'event_ind'], 0)
		self.assertEqual(json_response[u'event_name'], "Test event")

		formula = MathFormula(sbml_model)
		formula.setPrettyPrintMathFormula("time==0", rawFormula=True)

		formula_response = MathFormula(sbml_model)
		formula_response.setPrettyPrintMathFormula(json_response[u'event_trigger'], rawFormula=True)

		self.assertEqual(simplify(formula.getDeveloppedInternalMathFormula()-formula_response.getDeveloppedInternalMathFormula()), 0)
		self.assertEqual(json_response[u'event_delay'], "")
		self.assertEqual(json_response[u'list_of_assignments'][0][0], listOfVariables.index(sbml_model.listOfVariables.getBySbmlId('ras_gtp')))

		formula = MathFormula(sbml_model)
		formula.setPrettyPrintMathFormula("ras_gtp*2", rawFormula=True)

		formula_response = MathFormula(sbml_model)
		formula_response.setPrettyPrintMathFormula(json_response[u'list_of_assignments'][0][2], rawFormula=True)
		self.assertEqual(simplify(formula.getDeveloppedInternalMathFormula()-formula_response.getDeveloppedInternalMathFormula()), 0)
		self.assertTrue(u'event_assignment_variable_1' not in json_response)

		# Modifying an event
		response_save_event = c.post('/edit/events/', {
			'action': 'save',
			'event_id': '0',
			'event_sbmlid': 'test_event',
			'event_name': "Test event",
			'event_trigger': "time==100",
			'event_priority': "",
			'event_delay': "",
			'event_assignment_0_id': listOfVariables.index(sbml_model.listOfVariables.getBySbmlId('ras_gtp')),
			'event_assignment_0_expression': 'ras_gtp*2',
			'event_assignment_1_id': listOfVariables.index(sbml_model.listOfVariables.getBySbmlId('ras_gdp')),
			'event_assignment_1_expression': 'ras_gdp/2',

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

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		event = sbml_model.listOfEvents[0]
		listOfVariables = []
		for variable in sbml_model.listOfVariables:
			if ((variable.isParameter() and variable.isGlobal())
				or variable.isSpecies()
				or variable.isCompartment()
				or variable.isStoichiometry()):
				listOfVariables.append(variable)

		self.assertEqual(event.getNameOrSbmlId(), "Test event")

		formula = MathFormula(sbml_model)
		formula.setPrettyPrintMathFormula("time==100", rawFormula=True)

		self.assertEqual(
			simplify(formula.getDeveloppedInternalMathFormula() - event.trigger.getDeveloppedInternalMathFormula()),
			0)

		self.assertEqual(event.priority, None)
		self.assertEqual(event.delay, None)
		self.assertEqual(event.listOfEventAssignments[0].getVariable(), sbml_model.listOfVariables.getBySbmlId('ras_gtp'))

		formula = MathFormula(sbml_model)
		formula.setPrettyPrintMathFormula("ras_gtp*2")

		self.assertEqual(
			simplify(formula.getDeveloppedInternalMathFormula() - event.listOfEventAssignments[0].getDefinition().getDeveloppedInternalMathFormula()),
			0)

		self.assertEqual(event.listOfEventAssignments[1].getVariable(), sbml_model.listOfVariables.getBySbmlId('ras_gdp'))

		formula = MathFormula(sbml_model)
		formula.setPrettyPrintMathFormula("ras_gdp/2")

		self.assertEqual(
			simplify(formula.getDeveloppedInternalMathFormula() - event.listOfEventAssignments[1].getDefinition().getDeveloppedInternalMathFormula()),
			0)

		response_delete_event = c.post('/edit/events/', {
			'action': 'delete',
			'event_id': 0
		})
		self.assertEqual(response_delete_event.status_code, 200)
		self.assertEqual(response_delete_event.context['form'].getErrors(), [])

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		self.assertEqual(len(sbml_model.listOfEvents), 0)
Пример #35
0
    def testSpecies(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)

        files_folder = join(dirname(__file__), "files")
        model_filename = join(files_folder, "modelqlzB7i.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)

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        species = sbml_model.listOfSpecies.getBySbmlId('ras_gtp')

        response_get_species = c.post('/json/get_species/',
                                      {'sbml_id': 'ras_gtp'})

        self.assertEqual(response_get_species.status_code, 200)
        json_response = loads(response_get_species.content.decode('utf-8'))
        self.assertEqual(json_response[u'id'],
                         sbml_model.listOfSpecies.index(species))
        self.assertEqual(json_response[u'sbml_id'], species.getSbmlId())
        self.assertEqual(json_response[u'name'], species.getName())
        self.assertEqual(json_response[u'compartment_name'],
                         species.getCompartment().getName())
        self.assertEqual(
            json_response[u'compartment_id'],
            sbml_model.listOfCompartments.index(species.getCompartment()))
        self.assertEqual(json_response[u'value'], species.getValue())
        self.assertEqual(json_response[u'isConcentration'],
                         1 if not species.hasOnlySubstanceUnits else 0)
        self.assertEqual(json_response[u'constant'],
                         1 if species.constant else 0)
        self.assertEqual(json_response[u'boundaryCondition'],
                         1 if species.boundaryCondition else 0)

        response_choose_project = c.post('/models/', {
            'action': 'choose_project',
            'project_id': 0
        })
        self.assertEqual(response_choose_project.status_code, 200)
        self.assertEqual(response_choose_project.context['project_name'],
                         "Project")

        response_choose_model = c.post('/edit/species/', {
            'action': 'choose_model',
            'model_id': 0
        })
        self.assertEqual(response_choose_model.status_code, 200)
        self.assertEqual(response_choose_model.context['model_name'],
                         "SOS-Ras-MAPK with n17")

        response_save_species = c.post(
            '/edit/species/', {
                'action': 'save',
                'species_id': 2,
                'species_name': "New name",
                'species_sbml_id': "new_name",
                'species_value': 75,
                'species_value_type': 0,
                'species_compartment': 0,
                'species_unit': 2,
                'species_constant': "on",
                'species_boundary': "on",
                'species_sboterm': "",
            })

        self.assertEqual(response_save_species.status_code, 200)

        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        species = sbml_model.listOfSpecies.getBySbmlId('new_name')

        self.assertTrue(species is not None)
        self.assertEqual(species.getName(), "New name")
        self.assertEqual(species.getValue(), 75)
        self.assertEqual(species.hasOnlySubstanceUnits, True)
        self.assertEqual(species.constant, True)
        self.assertEqual(species.boundaryCondition, True)

        response_delete_species = c.post(
            '/edit/species/', {
                'action': 'delete',
                'species_id': sbml_model.listOfSpecies.index(species)
            })
        self.assertEqual(response_delete_species.status_code, 200)
        self.assertEqual(response_delete_species.context['getErrors'],
                         ['Species is used in reactions'])

        response_save_new_species = c.post(
            '/edit/species/', {
                'action': 'save',
                'species_id': "",
                'species_name': "New species",
                'species_sbml_id': "new_species",
                'species_value': 2500,
                'species_value_type': 0,
                'species_compartment': 0,
                'species_unit': 2,
                'species_constant': "off",
                'species_boundary': "off",
                'species_sboterm': "",
            })

        self.assertEqual(response_save_new_species.status_code, 200)

        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        species = sbml_model.listOfSpecies.getBySbmlId('new_species')

        self.assertTrue(species != None)
        self.assertEqual(species.getName(), "New species")
        self.assertEqual(species.getValue(), 2500)
        self.assertEqual(species.isConcentration(), False)
        self.assertEqual(species.getCompartment().getName(), "cell")
        self.assertEqual(species.constant, False)
        self.assertEqual(species.boundaryCondition, False)

        response_delete_species = c.post(
            '/edit/species/', {
                'action': 'delete',
                'species_id': sbml_model.listOfSpecies.index(species)
            })
        self.assertEqual(response_delete_species.status_code, 200)

        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()

        species = sbml_model.listOfSpecies.getBySbmlId('new_species')

        self.assertEqual(species, None)
Пример #36
0
	def testSpecies(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)

		files_folder = join(dirname(__file__), "files")
		model_filename = join(files_folder, "modelqlzB7i.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)

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		species = sbml_model.listOfSpecies.getBySbmlId('ras_gtp')

		response_get_species = c.post('/json/get_species/', {
			'sbml_id': 'ras_gtp'
		})

		self.assertEqual(response_get_species.status_code, 200)
		json_response = loads(response_get_species.content.decode('utf-8'))
		self.assertEqual(json_response[u'id'], sbml_model.listOfSpecies.index(species))
		self.assertEqual(json_response[u'sbml_id'], species.getSbmlId())
		self.assertEqual(json_response[u'name'], species.getName())
		self.assertEqual(json_response[u'compartment_name'], species.getCompartment().getName())
		self.assertEqual(json_response[u'compartment_id'], sbml_model.listOfCompartments.index(species.getCompartment()))
		self.assertEqual(json_response[u'value'], species.getValue())
		self.assertEqual(json_response[u'isConcentration'], 1 if not species.hasOnlySubstanceUnits else 0)
		self.assertEqual(json_response[u'constant'], 1 if species.constant else 0)
		self.assertEqual(json_response[u'boundaryCondition'], 1 if species.boundaryCondition else 0)


		response_choose_project = c.post('/models/', {
			'action': 'choose_project',
			'project_id': 0
		})
		self.assertEqual(response_choose_project.status_code, 200)
		self.assertEqual(response_choose_project.context['project_name'], "Project")

		response_choose_model = c.post('/edit/species/', {
			'action': 'choose_model',
			'model_id': 0
		})
		self.assertEqual(response_choose_model.status_code, 200)
		self.assertEqual(response_choose_model.context['model_name'], "SOS-Ras-MAPK with n17")

		response_save_species = c.post('/edit/species/', {
			'action': 'save',
			'species_id': 2,
			'species_name': "New name",
			'species_sbml_id': "new_name",
			'species_value': 75,
			'species_value_type': 0,
			'species_compartment': 0,
			'species_unit': 2,
			'species_constant': "on",
			'species_boundary': "on",
			'species_sboterm': "",
		})

		self.assertEqual(response_save_species.status_code, 200)

		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		species = sbml_model.listOfSpecies.getBySbmlId('new_name')

		self.assertTrue(species is not None)
		self.assertEqual(species.getName(), "New name")
		self.assertEqual(species.getValue(), 75)
		self.assertEqual(species.hasOnlySubstanceUnits, True)
		self.assertEqual(species.constant, True)
		self.assertEqual(species.boundaryCondition, True)

		response_delete_species = c.post('/edit/species/', {
			'action': 'delete',
			'species_id': sbml_model.listOfSpecies.index(species)
		})
		self.assertEqual(response_delete_species.status_code, 200)
		self.assertEqual(response_delete_species.context['getErrors'], ['Species is used in reactions'])

		response_save_new_species = c.post('/edit/species/', {
			'action': 'save',
			'species_id': "",
			'species_name': "New species",
			'species_sbml_id': "new_species",
			'species_value': 2500,
			'species_value_type': 0,
			'species_compartment': 0,
			'species_unit': 2,
			'species_constant': "off",
			'species_boundary': "off",
			'species_sboterm': "",
		})

		self.assertEqual(response_save_new_species.status_code, 200)

		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		species = sbml_model.listOfSpecies.getBySbmlId('new_species')

		self.assertTrue(species != None)
		self.assertEqual(species.getName(), "New species")
		self.assertEqual(species.getValue(), 2500)
		self.assertEqual(species.isConcentration(), False)
		self.assertEqual(species.getCompartment().getName(), "cell")
		self.assertEqual(species.constant, False)
		self.assertEqual(species.boundaryCondition, False)

		response_delete_species = c.post('/edit/species/', {
			'action': 'delete',
			'species_id': sbml_model.listOfSpecies.index(species)
		})
		self.assertEqual(response_delete_species.status_code, 200)

		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()

		species = sbml_model.listOfSpecies.getBySbmlId('new_species')

		self.assertEqual(species, None)
Пример #37
0
def importProject(new_folder, filename):

	new_combine_archive = CombineArchive()
	new_folder.name = basename(filename).split('.')[0]
	new_folder.save()

	try:
		new_combine_archive.readArchive(filename)

		deps = []
		for sbml_file in new_combine_archive.getAllSbmls():
			t_file = File(open(sbml_file, 'rb'))

			sbml_model = SbmlModel(project=new_folder, sbml_file=t_file)
			sbml_model.save()

			try:
				doc = SbmlDocument()

				doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(sbml_model.sbml_file)))

				dependencies = getDetailedModelDependencies(doc)
				if len(dependencies) > 0:
					deps.append((sbml_model, dependencies))

				sbml_model.name = doc.model.getName()
				sbml_model.save()
			except ModelException:
				name = splitext(str(sbml_model.sbml_file))[0]
				sbml_model.name = name
				sbml_model.save()

		for model, submodels in deps:

			for submodel_filename, submodel_ref in submodels:
				submodel_filename = join(new_folder.folder, "models", submodel_filename)
				submodel = SbmlModel.objects.get(sbml_file=submodel_filename)
				new_dependency = ModelsDependency(project=new_folder, model=model, submodel=submodel, submodel_ref=submodel_ref)
				new_dependency.save()

		for sedml_filename in new_combine_archive.getAllSedmls():

			sedml_archive = SEDMLSimulation(project=new_folder, sedml_file=File(open(sedml_filename, 'rb')))
			sedml_archive.name = basename(sedml_filename).split('.')[0]
			sedml_archive.save()

			# Now everything is in the same folder
			sedml_doc = SedmlDocument()
			sedml_doc.readSedmlFromFile(join(settings.MEDIA_ROOT, str(sedml_archive.sedml_file)))
			sedml_doc.listOfModels.removePaths()
			sbml_files = sedml_doc.listOfModels.makeLocalSources()

			for sbml_file in sbml_files:

				if len(SbmlModel.objects.filter(project=new_folder, sbml_file=join(join(str(new_folder.folder), "models"), basename(sbml_file)))) == 0:

					t_file = File(open(sbml_file, 'rb'))
					sbml_model = SbmlModel(project=new_folder, sbml_file=t_file)
					sbml_model.save()
					try:
						doc = SbmlDocument()

						doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(sbml_model.sbml_file)))

						sbml_model.name = doc.model.getName()
						sbml_model.save()
					except ModelException:
						name = splitext(str(sbml_model.sbml_file))[0]
						sbml_model.name = name
						sbml_model.save()

			sedml_doc.writeSedmlToFile(join(settings.MEDIA_ROOT, str(sedml_archive.sedml_file)))


		for numl_file in new_combine_archive.getAllNumls():
			new_experiment = Experiment(project=new_folder)
			new_experiment.save()
			importExperiment(new_experiment, numl_file)

	except CombineException as e:
		print(e.message)
Пример #38
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)
Пример #39
0
    def testRule(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)

        files_folder = join(dirname(__file__), "files")
        model_filename = join(files_folder, "modelqlzB7i.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)

        model = SbmlModel.objects.filter(project=project)[0]
        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        listOfRules = sbml_model.listOfRules + sbml_model.listOfInitialAssignments
        listOfVariables = []
        for variable in sbml_model.listOfVariables:
            if ((variable.isParameter() and variable.isGlobal())
                    or variable.isSpecies() or variable.isCompartment()
                    or variable.isStoichiometry()):
                listOfVariables.append(variable)

        rule = listOfRules[0]

        response_get_compartment = c.post('/json/get_rule/', {
            'rule_ind': '0',
        })

        self.assertEqual(response_get_compartment.status_code, 200)
        json_response = loads(response_get_compartment.content.decode('utf-8'))

        self.assertEqual(json_response[u'rule_id'], listOfRules.index(rule))
        self.assertEqual(json_response[u'rule_type'], 1)
        self.assertEqual(
            json_response[u'variable'],
            listOfVariables.index(
                sbml_model.listOfVariables.getBySbmlId('total_ras_gtp')))

        response_choose_project = c.post('/models/', {
            'action': 'choose_project',
            'project_id': 0
        })
        self.assertEqual(response_choose_project.status_code, 200)
        self.assertEqual(response_choose_project.context['project_name'],
                         "Project")

        response_choose_model = c.post('/edit/rules/', {
            'action': 'choose_model',
            'model_id': 0
        })
        self.assertEqual(response_choose_model.status_code, 200)
        self.assertEqual(response_choose_model.context['model_name'],
                         "SOS-Ras-MAPK with n17")

        response_save_rule = c.post(
            '/edit/rules/', {
                'action':
                'save',
                'rule_id':
                listOfRules.index(rule),
                'rule_type':
                1,
                'variable_id':
                listOfVariables.index(
                    sbml_model.listOfVariables.getBySbmlId(
                        'total_mapk_activated')),
                'rule_expression':
                "75*ras_gtp",
            })

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

        sbml_doc = SbmlDocument()
        sbml_doc.readSbmlFromFile(
            join(settings.MEDIA_ROOT, str(model.sbml_file)))
        sbml_model = sbml_doc.getModelInstance()
        listOfRules = sbml_model.listOfRules + sbml_model.listOfInitialAssignments
        listOfVariables = []
        for variable in sbml_model.listOfVariables:
            if ((variable.isParameter() and variable.isGlobal())
                    or variable.isSpecies() or variable.isCompartment()
                    or variable.isStoichiometry()):
                listOfVariables.append(variable)

        rule = listOfRules[0]

        self.assertEqual(rule.getType(), 1)
        self.assertEqual(
            rule.getVariable(),
            sbml_model.listOfVariables.getBySbmlId('total_mapk_activated'))
        formula = MathFormula(sbml_model)
        formula.setPrettyPrintMathFormula("75*ras_gtp", rawFormula=True)
        self.assertEqual(
            simplify(rule.getDefinition().getDeveloppedInternalMathFormula() -
                     formula.getDeveloppedInternalMathFormula()), 0)

        response_delete_rule = c.post('/edit/rules/', {
            'action': 'delete',
            'rule_id': 0
        })
        self.assertEqual(response_delete_rule.status_code, 200)
        self.assertEqual(response_delete_rule.context['form'].getErrors(), [])
Пример #40
0
	def testLocalParameter(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)

		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)

		files_folder = join(dirname(__file__), "files")
		model_filename = join(files_folder, "modelqlzB7i.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)

		model = SbmlModel.objects.filter(project=project)[0]
		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		parameter = sbml_model.listOfParameters.getBySbmlId('sos_ras_gdp_comp')

		response_get_reaction = c.post('/json/get_reaction/', {
			'sbml_id': 'reaction_2',
		})

		self.assertEqual(response_get_reaction.status_code, 200)
		json_response = loads(response_get_reaction.content.decode('utf-8'))
		self.assertEqual(json_response[u'kinetic_law'], '-1 * sos_ras_gdp * sos_ras_gdp_decomp + ras_gdp * sos * sos_ras_gdp_comp')

		response_get_parameter = c.post('/json/get_parameter/', {
			'sbml_id': 'sos_ras_gdp_comp',
			'reaction': ''
		})

		self.assertEqual(response_get_parameter.status_code, 200)
		json_response = loads(response_get_parameter.content.decode('utf-8'))
		self.assertEqual(json_response[u'id'], sbml_model.listOfParameters.index(parameter))
		self.assertEqual(json_response[u'reaction_id'], "")

		response_to_local_parameter = c.post('/edit/parameters/', {
			'action': 'save',
			'parameter_id': json_response[u'id'],
			'parameter_name': json_response[u'name'],
			'parameter_sbml_id': json_response[u'sbml_id'],
			'parameter_value': json_response[u'value'],
			'parameter_unit': json_response[u'unit_id'],
			'parameter_constant': "on" if json_response[u'constant'] == 1 else "",
			'parameter_scope': 1,
			'parameter_sboterm': "",
		})

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

		response_get_reaction = c.post('/json/get_reaction/', {
			'sbml_id': 'reaction_2',
		})

		self.assertEqual(response_get_reaction.status_code, 200)
		json_response = loads(response_get_reaction.content.decode('utf-8'))
		self.assertEqual(
			json_response[u'kinetic_law'],
			'-1 * sos_ras_gdp * sos_ras_gdp_decomp + sos_ras_gdp_comp * ras_gdp * sos'
		)

		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		reaction = sbml_model.listOfReactions.getBySbmlId('reaction_2')
		self.assertEqual(
			str(reaction.kineticLaw.getDefinition().getInternalMathFormula()),
			"_local_0_sos_ras_gdp_comp*ras_gdp*sos - sos_ras_gdp*sos_ras_gdp_decomp"
		)

		self.assertEqual(sbml_model.listOfParameters.getBySbmlId("sos_ras_gdp_comp"), None)

		response_get_parameter = c.post('/json/get_parameter/', {
			'sbml_id': 'sos_ras_gdp_comp',
			'reaction': '1'
		})

		self.assertEqual(response_get_parameter.status_code, 200)
		json_response = loads(response_get_parameter.content.decode('utf-8'))

		response_list_parameters = c.get('/edit/parameters/')
		self.assertEqual(response_list_parameters.status_code, 200)
		list_of_parameters = [param.getSbmlId() for param in response_list_parameters.context['list_of_parameters']]



		response_to_global_parameter = c.post('/edit/parameters/', {
			'action': 'save',
			'parameter_id': list_of_parameters.index("sos_ras_gdp_comp"),
			'parameter_name': json_response[u'name'],
			'parameter_sbml_id': json_response[u'sbml_id'],
			'parameter_value': json_response[u'value'],
			'parameter_unit': json_response[u'unit_id'],
			'parameter_constant': "on" if json_response[u'constant'] == 1 else "",
			'parameter_scope': 0,
			'parameter_sboterm': "",
		})

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

		response_get_reaction = c.post('/json/get_reaction/', {
			'sbml_id': 'reaction_2',
		})

		self.assertEqual(response_get_reaction.status_code, 200)
		json_response = loads(response_get_reaction.content.decode('utf-8'))
		# print json_response
		self.assertEqual(
			json_response[u'kinetic_law'],
			'-1 * sos_ras_gdp * sos_ras_gdp_decomp + ras_gdp * sos * sos_ras_gdp_comp'
		)

		sbml_doc = SbmlDocument()
		sbml_doc.readSbmlFromFile(join(settings.MEDIA_ROOT, str(model.sbml_file)))
		sbml_model = sbml_doc.getModelInstance()
		reaction = sbml_model.listOfReactions.getBySbmlId('reaction_2')
		self.assertEqual(
			str(reaction.kineticLaw.getDefinition().getInternalMathFormula()),
			"ras_gdp*sos*sos_ras_gdp_comp - sos_ras_gdp*sos_ras_gdp_decomp"
		)

		self.assertEqual(sbml_model.listOfParameters.getBySbmlId("sos_ras_gdp_comp").getSbmlId(), "sos_ras_gdp_comp")