def get(self, request, project_id, model_id, tag=None):

		HasModel.load(self, request, project_id, model_id)

		try:
			if tag is None:
				tagged_models = TaggedLogicalModel.objects.filter(model=self.model)
				tags = [tagged_model.tag for tagged_model in tagged_models]

				return Response(tags)

			else:
				# Restoring model from tag
				tagged_model = TaggedLogicalModel.objects.get(model=self.model, tag=tag)

				# TODO : Which format fo we want ? which format do we have
				copyfile(
					join(settings.MEDIA_ROOT, tagged_model.file.path),
					join(settings.MEDIA_ROOT, self.model.file.path)
				)

				return Response(status=status.HTTP_200_OK)

		except TaggedLogicalModel.DoesNotExist:
			raise NotFound
Exemple #2
0
    def post(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        positions = loads(request.POST["positions"])

        min_x = 0
        max_x = 0
        min_y = 0
        max_y = 0
        new_positions = {}

        for position in positions:
            min_x = min(position['x'], min_x)
            max_x = max(position['x'], max_x)
            min_y = min(position['y'], min_y)
            max_y = max(position['y'], max_y)
            new_positions.update({
                position['name']: {
                    'pos': [position['x'] + 30, position['y'] + 30],
                    'dim': [60.0, 30.0]
                }
            })

        # print(min_x)
        # print(max_x)
        # print(min_y)
        # print(max_y)

        self.setLayout(
            ((60.0 + max_x - min_x, 60 + max_y - min_y), new_positions))

        return Response(status=status.HTTP_200_OK)
    def delete(self, request, project_id, model_id, node, field):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()

        if field in ["rateUp", "rateDown"]:
            return Response(data={'error': 'Cannot remove %s' % field})

        if field == "logic":
            maboss_sim.network[node].logExp = None

        else:
            del maboss_sim.network[node].internal_var[field]

        res = simplify_messages(maboss_sim.check())
        data = {'error': ''}

        if any([
                message == ("invalid use of alias attribute @%s in node %s" %
                            (field, node)) for message in res
        ]):
            if field == "logic":
                data.update({
                    'error':
                    'The logical formula is used elsewhere in the model'
                })
            else:
                data.update(
                    {'error': 'The formula %s is used in the model' % field})

        elif len(res) > 0:
            data.update({'error': res[0]})

        return Response(data=data)
Exemple #4
0
    def delete(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        maboss_model = self.getMaBoSSModel()
        maboss_model.network.remove_node(request.POST['name'])
        res = simplify_messages(maboss_model.check())

        data = {'error': ''}
        if len(res) > 0:
            if any([
                    message.startswith("node")
                    and message.endswith("used but not defined")
                    for message in res
            ]):
                for message in res:
                    if message.startswith("node") and message.endswith(
                            "used but not defined"):
                        data.update({'error': message})
            elif any([
                    message == "Some logic rule had unkown variables"
                    for message in res
            ]):
                data.update({
                    'error':
                    "The node %s is used in the model" % request.POST['name']
                })

            elif len(res) > 0:
                data.update({'error': res[0]})

        else:
            self.saveMaBoSSModel(maboss_model)

        return Response(data=data, status=status.HTTP_200_OK)
Exemple #5
0
    def get(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        serializer = LogicalModelNameSerializer(self.model)

        return Response(serializer.data)
Exemple #6
0
    def get(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        ginsim_model = self.getGINSimModel()
        fig = ginsim._get_image(ginsim_model)

        return HttpResponse(fig, content_type="image/svg+xml")
    def post(self, request, project_id, model_id, name):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()
        maboss_sim.param[name] = request.POST['value']
        self.saveMaBoSSModel(maboss_sim)

        return Response(status=HTTP_200_OK)
    def delete(self, request, project_id, model_id, name):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()
        del maboss_sim.param[name]
        self.saveMaBoSSModel(maboss_sim)

        return Response(status=HTTP_200_OK)
Exemple #9
0
    def post(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        steady_state = loads(request.data['steady_state'])
        ginsim_model = self.getGINSimModel()
        fig = ginsim._get_image(ginsim_model, steady_state)

        return HttpResponse(fig, content_type="image/svg+xml")
Exemple #10
0
    def get(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        maboss_model = self.getMaBoSSModel()

        initial_states = maboss_model.network.get_istate()

        return Response({
            'initial_states': dumpIstates(initial_states),
        })
Exemple #11
0
    def get(self, request, project_id, model_id, name):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()

        if name in maboss_sim.param.keys():
            return Response(data=maboss_sim.param[name])

        else:
            raise NotFound
Exemple #12
0
    def put(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        maboss_model = self.getMaBoSSModel()

        for var, istate in parseIstates(request.POST['initialStates']).items():
            maboss_model.network.set_istate(var, istate)

        self.saveMaBoSSModel(maboss_model)

        return Response(status=HTTP_200_OK)
Exemple #13
0
    def post(self, request, project_id, model_id, node):

        HasModel.load(self, request, project_id, model_id)
        raw_layout = self.getLayout()
        if raw_layout is not None:
            dims, layout = raw_layout
            new_pos = loads(request.POST["position"])

            layout[node].update({"pos": [new_pos["x"], new_pos["y"]]})
            self.updateLayout((dims, layout))

        return Response(status=status.HTTP_200_OK)
Exemple #14
0
    def put(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        maboss_model = self.getMaBoSSModel()

        for node, is_output in json.loads(request.POST['outputs']).items():
            maboss_model.network[node].is_internal = not is_output

        self.saveMaBoSSModel(maboss_model)

        return Response(status=HTTP_200_OK)
Exemple #15
0
    def get(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        cfg_filename = self.getMaBoSSCFGFile()

        if cfg_filename is None:
            return Response(status=status.HTTP_501_NOT_IMPLEMENTED)

        return FileResponse(open(cfg_filename, 'rb'),
                            as_attachment=True,
                            filename=basename(cfg_filename))
	def delete(self, request, project_id, model_id, tag):

		HasModel.load(self, request, project_id, model_id)

		try:
			tagged_model = TaggedLogicalModel.objects.get(model=self.model, tag=tag)
			tagged_model.delete()

		except TaggedLogicalModel.DoesNotExist:
			raise NotFound

		return Response(status=status.HTTP_200_OK)
Exemple #17
0
    def get(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        model_file = self.getZGINMLModelFile()

        if model_file is None:
            return Response(status=status.HTTP_501_NOT_IMPLEMENTED)

        return FileResponse(open(model_file, 'rb'),
                            as_attachment=True,
                            filename=basename(model_file))
Exemple #18
0
    def put(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        maboss_model = self.getMaBoSSModel()

        for name, value in json.loads(request.POST['settings']).items():
            maboss_model.param[name] = float(value)

        self.saveMaBoSSModel(maboss_model)

        return Response(status=HTTP_200_OK)
    def get(self, request, project_id, model_id):

        if request.user.is_anonymous:
            raise PermissionDenied

        HasModel.load(self, request, project_id, model_id)

        simulations = MaBoSSSensitivityAnalysis.objects.filter(
            model=self.model)
        serializer = MaBoSSSensitivityAnalysisSerializer(simulations,
                                                         many=True)
        return Response(serializer.data)
	def get(self, request, project_id, model_id, tag):

		HasModel.load(self, request, project_id, model_id)

		try:
			tagged_version = TaggedLogicalModel.objects.get(model=self.model, tag=tag)

			return FileResponse(
				open(join(settings.MEDIA_ROOT, tagged_version.file.path), 'rb'),
				as_attachment=True, filename=basename(tagged_version.file.path)
			)

		except TaggedLogicalModel.DoesNotExist:
			raise NotFound
Exemple #21
0
    def get(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        maboss_model = self.getMaBoSSModel()
        outputs = {
            label: not node.is_internal
            for label, node in maboss_model.network.items()
        }

        return Response({
            'outputs':
            collections.OrderedDict(sorted(outputs.items())),
        })
Exemple #22
0
    def get(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()

        data = {}

        for parameter, value in maboss_sim.param.items():
            if parameter.startswith("$"):
                data.update({parameter: value})

        return Response(
            data=json.dumps(collections.OrderedDict(sorted(data.items()))))
Exemple #23
0
    def post(self, request, project_id, model_id, node, field):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()

        if field == "logic":
            maboss_sim.network[node].logExp = request.POST['formula']

        elif field == "rateUp":
            maboss_sim.network[node].rt_up = request.POST['formula']

        elif field == "rateDown":
            maboss_sim.network[node].rt_down = request.POST['formula']

        else:
            maboss_sim.network[node].internal_var.update(
                {field: request.POST['formula']})

        res = simplify_messages(maboss_sim.check())

        data = {'error': ''}

        if any([
                message.startswith("BND syntax error at line")
                for message in res
        ]):
            data.update({'error': 'syntax error'})

        elif any([
                message.startswith("node")
                and message.endswith("used but not defined") for message in res
        ]):
            for message in res:
                if message.startswith("node") and message.endswith(
                        "used but not defined"):
                    data.update({'error': message})

        elif any([
                message.startswith(
                    "invalid use of alias attribute @logic in node")
                for message in res
        ]) and field == "logExp":
            data.update({'error': "Syntax error"})

        elif len(res) > 0:
            data.update({'error': res[0]})

        return Response(data=data)
Exemple #24
0
    def post(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        if self.model.format == LogicalModel.MABOSS:
            maboss_model = self.getMaBoSSModel()
            if request.POST['name'] not in maboss_model.network.keys():
                maboss_model.network.add_node(request.POST['name'])

                self.saveMaBoSSModel(maboss_model)
                return Response(status=status.HTTP_200_OK)
            else:
                return Response(status=status.HTTP_409_CONFLICT)
        else:
            return Response(status=status.HTTP_501_NOT_IMPLEMENTED)
Exemple #25
0
    def get(self, request, project_id, model_id):

        HasModel.load(self, request, project_id, model_id)

        maboss_model = self.getMaBoSSModel()

        settings = {
            key: value
            for key, value in maboss_model.param.items()
            if not key.startswith("$")
        }

        return Response({
            'settings': settings,
        })
Exemple #26
0
    def delete(self, request, project_id, model_id, node, field):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()

        if field in ["rateUp", "rateDown"]:
            return Response(
                data={'error': 'Cannot remove %s' % request.POST['field']})

        if field == "logic":
            maboss_sim.network[node].logExp = None

        else:
            del maboss_sim.network[node].internal_var[field]

        self.saveMaBoSSModel(maboss_sim)
        return Response(status=HTTP_200_OK)
Exemple #27
0
    def get(self, request, project_id, model_id, node, field):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()

        node = maboss_sim.network[node]

        node_data = {}
        node_data.update({'rateUp': maboss_sim.network[node].rt_up})
        node_data.update({'rateDown': maboss_sim.network[node].rt_down})

        if node.logExp is not None:
            node_data.update({'logic': node.logExp})

        node_data.update(node.internal_var)

        return Response(data=json.dumps(node_data))
	def get(self, request, project_id, model_id, tag):

		HasModel.load(self, request, project_id, model_id)

		try:
			tagged_version = TaggedLogicalModel.objects.get(model=self.model, tag=tag)

			ginsim_model = ginsim.load(join(settings.MEDIA_ROOT, tagged_version.file.path))

			sbml_filename = join(settings.TMP_ROOT, splitext(basename(tagged_version.file.path))[0] + ".sbml")
			biolqm.save(ginsim_model, sbml_filename, "sbml")

			return FileResponse(
				open(sbml_filename, 'rb'),
				as_attachment=True, filename=basename(sbml_filename)
			)

		except TaggedLogicalModel.DoesNotExist:
			raise NotFound
Exemple #29
0
    def post(self, request, project_id, model_id, name):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()
        maboss_sim.param[name] = request.POST['value']

        res = simplify_messages(maboss_sim.check())

        data = {'error': ''}

        if any([
                message.startswith("configuration syntax error")
                for message in res
        ]):
            data.update({'error': 'Syntax error'})

        elif len(res) > 0:
            data.update({'error': res[0]})

        return Response(data=data)
Exemple #30
0
    def post(self, request, project_id, model_id, node, field):

        HasModel.load(self, request, project_id, model_id)

        maboss_sim = self.getMaBoSSModel()

        if field == "rateUp":
            maboss_sim.network[node].rt_up = request.POST['formula']

        elif field == "rateDown":
            maboss_sim.network[node].rt_down = request.POST['formula']

        elif field == "logic":
            maboss_sim.network[node].logExp = request.POST['formula']

        else:
            maboss_sim.network[node].internal_var.update(
                {field: request.POST['formula']})

        self.saveMaBoSSModel(maboss_sim)
        return Response(status=HTTP_200_OK)