Exemple #1
0
def stmt_validate(ctx, statement, version, api, config_fn):
    """Parse statement and validate """

    if config_fn:
        config = bel.db.Config.merge_config(ctx.config, override_config_fn=config_fn)
    else:
        config = ctx.config

    # Configuration - will return the first truthy result in list else the default option
    api = utils.first_true([api, config["bel_api"]["servers"].get("api_url", None)], None)
    version = utils.first_true(
        [version, config["bel"]["lang"].get("default_bel_version", None)], None
    )

    print("------------------------------")
    print("BEL version: {}".format(version))
    print("API Endpoint: {}".format(api))
    print("------------------------------")

    bo = BEL(version=version, endpoint=api)
    bo.parse(statement)

    if bo.ast is None:
        print(bo.original_bel_stmt)
        print(bo.parse_visualize_error)
        print(bo.validation_messages)
    else:
        print(bo.ast.to_triple())
        if bo.validation_messages:
            print(bo.validation_messages)
        else:
            print("No problems found")
    return
Exemple #2
0
def edges(ctx, statement, rules, species, namespace_targets, version, api, config_fn):
    """Create BEL Edges from BEL Statement"""

    if config_fn:
        config = bel.db.Config.merge_config(ctx.config, override_config_fn=config_fn)
    else:
        config = ctx.config

    # Configuration - will return the first truthy result in list else the default option
    if namespace_targets:
        namespace_targets = json.loads(namespace_targets)
    if rules:
        rules = rules.replace(" ", "").split(",")

    namespace_targets = utils.first_true(
        [namespace_targets, config["bel"]["lang"].get("canonical")], None
    )
    api_url = utils.first_true(
        [api, config["bel_api"]["servers"].get("api_url", None)], None
    )
    version = utils.first_true(
        [version, config["bel"]["lang"].get("default_bel_version", None)], None
    )

    print("------------------------------")
    print("BEL version: {}".format(version))
    print("API Endpoint: {}".format(api))
    print("------------------------------")

    bo = BEL(version=version, endpoint=api_url)
    if species:
        edges = (
            bo.parse(statement)
            .orthologize(species)
            .canonicalize(namespace_targets=namespace_targets)
            .compute_edges(rules=rules)
        )
    else:
        edges = (
            bo.parse(statement)
            .canonicalize(namespace_targets=namespace_targets)
            .compute_edges(rules=rules)
        )

    if edges is None:
        print(bo.original_bel_stmt)
        print(bo.parse_visualize_error)
        print(bo.validation_messages)
    else:
        print(json.dumps(edges, indent=4))

        if bo.validation_messages:
            print(bo.validation_messages)
        else:
            print("No problems found")
    return
Exemple #3
0
def canonicalize(ctx, statement, namespace_targets, version, api, config_fn):
    """Canonicalize statement

    Target namespaces can be provided in the following manner:

        bel stmt canonicalize "<BELStmt>" --namespace_targets '{"HGNC": ["EG", "SP"], "CHEMBL": ["CHEBI"]}'
            the value of target_namespaces must be JSON and embedded in single quotes
            reserving double quotes for the dictionary elements
    """

    if config_fn:
        config = bel.db.Config.merge_config(ctx.config, override_config_fn=config_fn)
    else:
        config = ctx.config

    # Configuration - will return the first truthy result in list else the default option
    if namespace_targets:
        namespace_targets = json.loads(namespace_targets)

    namespace_targets = utils.first_true(
        [namespace_targets, config.get("canonical")], None
    )
    api = utils.first_true([api, config.get("api", None)], None)
    version = utils.first_true([version, config.get("bel_version", None)], None)

    print("------------------------------")
    print("BEL version: {}".format(version))
    print("API Endpoint: {}".format(api))
    print("------------------------------")

    bo = BEL(version=version, endpoint=api)
    bo.parse(statement).canonicalize(namespace_targets=namespace_targets)

    if bo.ast is None:
        print(bo.original_bel_stmt)
        print(bo.parse_visualize_error)
        print(bo.validation_messages)
    else:
        print("ORIGINAL ", bo.original_bel_stmt)
        print("CANONICAL", bo.ast)
        if bo.validation_messages:
            print(bo.validation_messages)
        else:
            print("No problems found")
    return
Exemple #4
0
    def on_get(self, req, resp, version, belstr=''):

        api_url = config['bel_api']['servers']['api_url']
        bel_obj = BEL(version=version, api_url=api_url)

        decanon_belstr = bel_obj.parse(belstr).decanonicalize().to_string()

        resp.media = {'decanonicalized': decanon_belstr, 'original': belstr}
        resp.status = falcon.HTTP_200
Exemple #5
0
    def on_get(self, req, resp, version, belstr=""):

        api_url = config["bel_api"]["servers"]["api_url"]
        bel_obj = BEL(version=version, api_url=api_url)

        decanon_belstr = bel_obj.parse(belstr).decanonicalize().to_string()

        resp.media = {"decanonicalized": decanon_belstr, "original": belstr}
        resp.status = falcon.HTTP_200
Exemple #6
0
def orthologize(ctx, statement, species, version, api, config_fn):
    """Orthologize statement

    species ID needs to be the NCBI Taxonomy ID in this format: TAX:<tax_id_number>
    You can use the following common names for species id: human, mouse, rat
      (basically whatever is supported at the api orthologs endpoint)
    """

    if config_fn:
        config = bel.db.Config.merge_config(ctx.config, override_config_fn=config_fn)
    else:
        config = ctx.config

    # Configuration - will return the first truthy result in list else the default option
    api_url = utils.first_true(
        [api, config["bel_api"]["servers"].get("api_url", None)], None
    )
    version = utils.first_true(
        [version, config["bel"]["lang"].get("default_bel_version", None)], None
    )

    print("------------------------------")
    print("BEL version: {}".format(version))
    print("API Endpoint: {}".format(api))
    print("------------------------------")

    bo = BEL(version=version, endpoint=api_url)
    bo.parse(statement).orthologize(species)

    if bo.ast is None:
        print(bo.original_bel_stmt)
        print(bo.parse_visualize_error)
        print(bo.validation_messages)
    else:
        print("ORIGINAL     ", bo.original_bel_stmt)
        print("ORTHOLOGIZED ", bo.ast)
        if bo.validation_messages:
            print(bo.validation_messages)
        else:
            print("No problems found")
    return
Exemple #7
0
    def on_get(self, req, resp, version, belstr=""):

        namespace_targets = req.get_param("namespace_targets", default=None)
        api_url = config["bel_api"]["servers"]["api_url"]

        log.info(f"Api_url {api_url}")

        bel_obj = BEL(version=version, api_url=api_url)

        canon_belstr = (bel_obj.parse(belstr).canonicalize(
            namespace_targets=namespace_targets).to_string())

        # TODO figure out how to handle naked namespace:val better
        if not canon_belstr:
            canon_belstr = terms.canonicalize(belstr)

        resp.media = {"canonicalized": canon_belstr, "original": belstr}
        resp.status = falcon.HTTP_200
Exemple #8
0
    def on_get(self, req, resp, version, belstr=''):

        namespace_targets = req.get_param('namespace_targets', default=None)
        api_url = config['bel_api']['servers']['api_url']

        log.info(f'Api_url {api_url}')

        bel_obj = BEL(version=version, api_url=api_url)

        canon_belstr = bel_obj.parse(belstr).canonicalize(
            namespace_targets=namespace_targets).to_string()

        # TODO figure out how to handle naked namespace:val better
        log.info(f'Canonicalize BEL string {canon_belstr}')
        if not canon_belstr:
            canon_belstr = terms.canonicalize(belstr)

        resp.media = {'canonicalized': canon_belstr, 'original': belstr}
        resp.status = falcon.HTTP_200