当前位置: 首页>>代码示例>>Python>>正文


Python KQMLList.from_string方法代码示例

本文整理汇总了Python中kqml.KQMLList.from_string方法的典型用法代码示例。如果您正苦于以下问题:Python KQMLList.from_string方法的具体用法?Python KQMLList.from_string怎么用?Python KQMLList.from_string使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kqml.KQMLList的用法示例。


在下文中一共展示了KQMLList.from_string方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: respond_find_treatment

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
    def respond_find_treatment(self, content_list):
        '''
        Response content to find-treatment request
        '''
        reply_content = KQMLList()
        #TODO: eliminate code duplication here
        disease_arg = content_list.get_keyword_arg(':disease')
        try:
            disease = self.get_disease(disease_arg)
        except Exception as e:
            logger.error(e)
            msg_str = '(FAILURE :reason INVALID_DISEASE)'
            reply_content = KQMLList.from_string(msg_str)
            return reply_content

        if disease.disease_type != 'cancer':
            reply_content.add('FAILURE :reason DISEASE_NOT_FOUND')
            return reply_content

        logger.debug('Disease: %s' % disease.name)

        try:
            mut_protein, mut_percent = \
                self.dtda.get_top_mutation(disease.name)
        except DiseaseNotFoundException:
            reply_content.add('FAILURE :reason DISEASE_NOT_FOUND')
            return reply_content

        # TODO: get functional effect from actual mutations
        # TODO: add list of actual mutations to response
        # TODO: get fraction not percentage from DTDA
        reply_content.add(KQMLList.from_string(
                '(SUCCESS ' +
                ':protein (:name %s :hgnc %s) ' % (mut_protein, mut_protein) +
                ':prevalence %.2f ' % (mut_percent/100.0) +
                ':functional-effect ACTIVE)'))

        # Try to find a drug
        drug_names, chebi_ids = self.dtda.find_target_drugs(mut_protein)
        drug_list_str = ''
        for dn, ci in zip(drug_names, chebi_ids):
            if ci is None:
                drug_list_str += '(:name %s) ' % dn.encode('ascii', 'ignore')
            else:
                drug_list_str += '(:name %s :chebi_id %s) ' % (dn, ci)
        reply_content.add(KQMLList.from_string(
            '(SUCCESS :drugs (' + drug_list_str + '))'))

        return reply_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:51,代码来源:dtda_module.py

示例2: respond_start

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
 def respond_start(self, arguments):
     '''
     Response content to start message
     '''
     if "CODE" not in arguments:
         response_content = self.response_error(["Missing code"])
     elif "NB_PLOT" not in arguments:
         response_content =\
             self.response_error(["Missing number of plot points"])
     else:
         try:
             parameter = {}
             parameter["nb_plot"] = arguments["NB_PLOT"]
             if "MAX_TIME" in arguments:
                 parameter["max_time"] = float(arguments["MAX_TIME"])
             if "MAX_EVENTS" in arguments:
                 parameter["max_events"] = int(arguments["MAX_EVENTS"])
             request_code = arguments["CODE"]
             request_code = request_code[1:-1]
             request_code = request_code.decode('string_escape')
             parameter["code"] = request_code
             try:
                 logger.debug(parameter)
                 response = self.kappa.start(parameter)
                 response_message = '(SUCCESS :id %d)' % response
                 response_content = KQMLList.from_string(response_message)
             except RuntimeError as e:
                 response_content = self.response_error(e.errors)
         except ValueError as e:
             response_content = self.response_error([str(e)])
     return response_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:33,代码来源:kappa_module.py

示例3: subscribe_request

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
 def subscribe_request(self, req_type):
     msg = KQMLPerformative('subscribe')
     content = KQMLList('request')
     content.append('&key')
     content.set('content', KQMLList.from_string('(%s . *)' % req_type))
     msg.set('content', content)
     self.send(msg)
开发者ID:pagreene,项目名称:pykqml,代码行数:9,代码来源:kqml_module.py

示例4: subscribe_tell

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
 def subscribe_tell(self, tell_type):
     msg = KQMLPerformative('subscribe')
     content = KQMLList('tell')
     content.append('&key')
     content.set('content', KQMLList.from_string('(%s . *)' % tell_type))
     msg.set('content', content)
     self.send(msg)
开发者ID:pagreene,项目名称:pykqml,代码行数:9,代码来源:kqml_module.py

示例5: respond_has_mechanism

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
    def respond_has_mechanism(self, content_list):
        """
        Response content to model-has-mechanism request
        """
        try:
            descr_arg = content_list.get_keyword_arg(":description")
            descr = descr_arg[0].to_string()
            descr = self.decode_description(descr)
        except Exception as e:
            raise InvalidModelDescriptionError(e)
        model_id_arg = content_list.get_keyword_arg(":model-id")
        if model_id_arg is None:
            logger.error("Model ID missing.")
            raise InvalidModelIdError
        try:
            model_id_str = model_id_arg.to_string()
            model_id = int(model_id_str)
        except Exception as e:
            logger.error("Could not get model ID as integer.")
            raise InvalidModelIdError(e)
        if model_id < 1 or model_id > len(self.models):
            logger.error("Model ID does not refer to an existing model.")
            raise InvalidModelIdError

        try:
            has_mechanism = self.mra.has_mechanism(descr, model_id)
        except Exception as e:
            raise InvalidModelDescriptionError
        reply_content = KQMLList.from_string("(SUCCESS :model-id %s :has-mechanism %s)" % (model_id, has_mechanism))
        return reply_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:32,代码来源:mra_module.py

示例6: respond_dont_know

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
 def respond_dont_know(self, msg, content_string):
     resp = '(ONT::TELL :content (ONT::DONT-KNOW :content %s))' %\
         content_string
     resp_list = KQMLList.from_string(resp)
     reply_msg = KQMLPerformative('reply')
     reply_msg.set_parameter(':content', resp_list)
     self.reply(msg, reply_msg)
开发者ID:sorgerlab,项目名称:bioagents,代码行数:9,代码来源:dtda_module.py

示例7: receive_request

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
    def receive_request(self, msg, content):
        """
        If a "request" message is received, decode the task and the content
        and call the appropriate function to prepare the response. A reply
        "tell" message is then sent back.
        """
        if self.tra is None:
            reply_content = KQMLList.from_string("(FAILURE :reason KAPPA_FAILURE)")
            reply_msg = KQMLPerformative("reply")
            reply_msg.set_parameter(":content", reply_content)
            self.reply(msg, reply_msg)
            return

        content_list = content
        task_str = content_list[0].to_string().upper()
        if task_str == "SATISFIES-PATTERN":
            try:
                reply_content = self.respond_satisfies_pattern(content_list)
            except Exception as e:
                self.error_reply(msg, "Error in performing satisfies " + "pattern task.")
                return
        else:
            self.error_reply(msg, "Unknown request task " + task_str)
            return

        reply_msg = KQMLPerformative("reply")
        reply_msg.set_parameter(":content", reply_content)
        self.reply(msg, reply_msg)
开发者ID:sorgerlab,项目名称:bioagents,代码行数:30,代码来源:tra_module.py

示例8: respond_build_model

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
 def respond_build_model(self, content_list):
     """
     Response content to build-model request
     """
     try:
         descr_arg = content_list.get_keyword_arg(":description")
         descr = descr_arg[0].to_string()
         descr = self.decode_description(descr)
         model = self.mra.build_model_from_ekb(descr)
     except Exception as e:
         raise InvalidModelDescriptionError(e)
     if model is None:
         raise InvalidModelDescriptionError
     self.get_context(model)
     self.models.append(model)
     model_id = len(self.models)
     model_enc = self.encode_model(model)
     try:
         model_diagram = self.get_model_diagram(model, model_id)
     except DiagramGenerationError as e:
         logger.error("Could not generate model diagram.")
         logger.error(e)
         model_diagram = ""
     except DiagramConversionError as e:
         logger.error("Could not save model diagram.")
         logger.error(e)
         model_diagram = ""
     reply_content = KQMLList.from_string(
         '(SUCCESS :model-id %s :model "%s" :diagram "%s")' % (model_id, model_enc, model_diagram)
     )
     return reply_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:33,代码来源:mra_module.py

示例9: respond_simulate_model

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
    def respond_simulate_model(self, content_list):
        """
        Response content to simulate-model request
        """
        model_str = content_list.get_keyword_arg(":model")
        try:
            # model_str = model_str.to_string()
            model = self.decode_model(model_str)
        except InvalidModelDescriptionError as e:
            logger.error(e)
            reply_content = KQMLList.from_string("(FAILURE :reason INVALID_MODEL)")
            return reply_content
        except Exception as e:
            logger.error(e)
            reply_content = KQMLList.from_string("(FAILURE :reason INVALID_MODEL)")
            return reply_content

        target_entity = content_list.get_keyword_arg(":target_entity")
        if target_entity is not None:
            target_entity = target_entity.to_string()[1:-1]
        else:
            reply_content = KQMLList.from_string("(FAILURE :reason MISSING_PARAMETER)")
            return reply_content
        target_pattern = content_list.get_keyword_arg(":target_pattern")
        if target_pattern is not None:
            target_pattern = target_pattern.to_string().lower()
        else:
            reply_content = KQMLList.from_string("(FAILURE :reason MISSING_PARAMETER)")
            return reply_content
        condition_entity = content_list.get_keyword_arg(":condition_entity")
        if condition_entity is not None:
            condition_entity = condition_entity.to_string()[1:-1]
        condition_type = content_list.get_keyword_arg(":condition_type")
        if condition_type is not None:
            condition_type = condition_type.to_string().lower()

        self.get_context(model)
        if condition_entity is None:
            target_match = self.mea.check_pattern(model, target_entity, target_pattern)
        else:
            target_match = self.mea.compare_conditions(
                model, target_entity, target_pattern, condition_entity, condition_type
            )
        target_match_str = "TRUE" if target_match else "FALSE"
        reply_content = KQMLList()
        reply_content.add("SUCCESS :content (:target_match %s)" % target_match_str)
        return reply_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:49,代码来源:mea_module.py

示例10: respond_version

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
 def respond_version(self):
     '''
     Response content to version message
     '''
     response = self.kappa.version()
     reply_content = KQMLList.from_string(
                     '(SUCCESS ' +
                          ':VERSION "%s" ' % response['version'] +
                          ':BUILD   "%s")' % response['build'])
     logger.debug(reply_content.to_string())
     return reply_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:13,代码来源:kappa_module.py

示例11: respond_stop

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
 def respond_stop(self, arguments):
     if "ID" not in arguments:
         response_content = self.response_error(["Missing simulation id"])
     else:
         try:
             token = int(arguments["ID"])
             status = self.kappa.stop(token)
             response_content = KQMLList.from_string('(SUCCESS)')
         except RuntimeError as e:
             response_content = self.response_error(e.errors)
     return response_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:13,代码来源:kappa_module.py

示例12: respond_test

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
    def respond_test(self):
        '''
        Response content to version message
        '''
        reply_content = KQMLList()
        version_response = KQMLList.from_string( '' +\
            '(ONT::TELL :content ' +\
            ')')

        reply_content.add(KQMLList(version_response))
        return reply_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:13,代码来源:test_module.py

示例13: receive_request

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
 def receive_request(self, msg, content):
     """
     If a "request" message is received, decode the task and the content
     and call the appropriate function to prepare the response. A reply
     "tell" message is then sent back.
     """
     try:
         task_str = content[0].to_string().upper()
     except Exception as e:
         logger.error("Could not get task string from request.")
         logger.error(e)
         self.error_reply(msg, "Invalid task")
     if task_str == "BUILD-MODEL":
         try:
             reply_content = self.respond_build_model(content)
         except InvalidModelDescriptionError as e:
             logger.error("Invalid model description.")
             logger.error(e)
             fail_msg = "(FAILURE :reason INVALID_DESCRIPTION)"
             reply_content = KQMLList.from_string(fail_msg)
     elif task_str == "EXPAND-MODEL":
         try:
             reply_content = self.respond_expand_model(content)
         except InvalidModelIdError as e:
             logger.error("Invalid model ID.")
             logger.error(e)
             fail_msg = "(FAILURE :reason INVALID_MODEL_ID)"
             reply_content = KQMLList.from_string(fail_msg)
         except InvalidModelDescriptionError as e:
             logger.error("Invalid model description.")
             logger.error(e)
             fail_msg = "(FAILURE :reason INVALID_DESCRIPTION)"
             reply_content = KQMLList.from_string(fail_msg)
     elif task_str == "MODEL-HAS-MECHANISM":
         reply_content = self.respond_has_mechanism(content)
     else:
         self.error_reply(msg, "Unknown task " + task_str)
         return
     reply_msg = KQMLPerformative("reply")
     reply_msg.set_parameter(":content", reply_content)
     self.reply(msg, reply_msg)
开发者ID:sorgerlab,项目名称:bioagents,代码行数:43,代码来源:mra_module.py

示例14: respond_find_disease_targets

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
    def respond_find_disease_targets(self, content_list):
        '''
        Response content to find-disease-targets request
        '''
        disease_arg = content_list.get_keyword_arg(':disease')
        try:
            disease = self.get_disease(disease_arg)
        except Exception as e:
            logger.error(e)
            msg_str = '(FAILURE :reason INVALID_DISEASE)'
            reply_content = KQMLList.from_string(msg_str)
            return reply_content

        if disease.disease_type != 'cancer':
            msg_str = '(FAILURE :reason DISEASE_NOT_FOUND)'
            reply_content = KQMLList.from_string(msg_str)
            return reply_content

        logger.debug('Disease: %s' % disease.name)

        try:
            mut_protein, mut_percent =\
                self.dtda.get_top_mutation(disease.name)
        except DiseaseNotFoundException:
            msg_str = '(FAILURE :reason DISEASE_NOT_FOUND)'
            reply_content = KQMLList.from_string(msg_str)
            return reply_content

        # TODO: get functional effect from actual mutations
        # TODO: add list of actual mutations to response
        # TODO: get fraction not percentage from DTDA
        reply_content =\
            KQMLList.from_string(
                '(SUCCESS ' +
                ':protein (:name %s :hgnc %s) ' % (mut_protein, mut_protein) +
                ':prevalence %.2f ' % (mut_percent/100.0) +
                ':functional-effect ACTIVE)')

        return reply_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:41,代码来源:dtda_module.py

示例15: respond_satisfies_pattern

# 需要导入模块: from kqml import KQMLList [as 别名]
# 或者: from kqml.KQMLList import from_string [as 别名]
    def respond_satisfies_pattern(self, content_list):
        """
        Response content to satisfies-pattern request
        """
        model_token = content_list.get_keyword_arg(":model")
        pattern_lst = content_list.get_keyword_arg(":pattern")
        conditions_lst = content_list.get_keyword_arg(":conditions")

        try:
            model_str = str(model_token)
            model = decode_model(model_str)
        except Exception as e:
            logger.error(e)
            reply_content = KQMLList.from_string("(FAILURE :reason INVALID_MODEL)")
            return reply_content

        try:
            pattern = get_temporal_pattern(pattern_lst)
        except InvalidTimeUnitError as e:
            logger.error(e)
            reply_content = KQMLList.from_string("(FAILURE :reason INVALID_TIME_LIMIT)")
            return reply_content
        except Exception as e:
            logger.error(e)
            reply_content = KQMLList.from_string("(FAILURE :reason INVALID_PATTERN)")
            return reply_content
        if conditions_lst is None:
            conditions = None
        else:
            try:
                conditions = []
                for condition_lst in conditions_lst:
                    condition = get_molecular_condition(condition_lst)
                    conditions.append(condition)
            except Exception as e:
                logger.error(e)
                msg_str = "(FAILURE :reason INVALID_CONDITIONS)"
                reply_content = KQMLList.from_string(msg_str)
                return reply_content

        try:
            sat_rate, num_sim = self.tra.check_property(model, pattern, conditions)
        except SimulatorError as e:
            logger.error(e)
            reply_content = KQMLList.from_string("(FAILURE :reason KAPPA_FAILURE)")
            return reply_content
        except Exception as e:
            logger.error(e)
            reply_content = KQMLList.from_string("(FAILURE :reason INVALID_PATTERN)")
            return reply_content

        reply_content = KQMLList()
        msg_str = "(:satisfies-rate %.1f :num-sim %d)" % (sat_rate, num_sim)
        reply_content.add("SUCCESS :content %s" % msg_str)
        return reply_content
开发者ID:sorgerlab,项目名称:bioagents,代码行数:57,代码来源:tra_module.py


注:本文中的kqml.KQMLList.from_string方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。