def __init__(self, endpoint: str = config.get("api", "")) -> None: """ Initialize Nanopub Args: endpoint (str): BEL.bio API endpoint uri, e.g. https://api.bel.bio/v1, default read from config """ self.endpoint = endpoint
def get_client(host=None, port=None, username=None, password=None, enable_logging=True): """Get arango client and edgestore db handle""" host = utils.first_true( [host, config["bel_api"]["servers"]["arangodb_host"], "localhost"]) port = utils.first_true( [port, config["bel_api"]["servers"]["arangodb_port"], 8529]) username = utils.first_true( [username, config["bel_api"]["servers"]["arangodb_username"], ""]) password = utils.first_true([ password, config.get( "secrets", config["secrets"]["bel_api"]["servers"].get("arangodb_password")), "", ]) client = arango.client.ArangoClient( protocol=config["bel_api"]["servers"]["arangodb_protocol"], host=host, port=port) return client
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
def get_client(host=None, port=None, username=None, password=None, enable_logging=True): """Get arango client and edgestore db handle""" host = utils.first_true([host, config["bel_api"]["servers"]["arangodb_host"], "localhost"]) port = utils.first_true([port, config["bel_api"]["servers"]["arangodb_port"], 8529]) username = utils.first_true([username, config["bel_api"]["servers"]["arangodb_username"], ""]) password = utils.first_true( [ password, config.get("secrets", config["secrets"]["bel_api"]["servers"].get("arangodb_password")), "", ] ) arango_url = f"http://{host}:{port}" try: client = arango.ArangoClient(hosts=arango_url) client.db(verify=True) return client except Exception as e: log.error(f"Cannot access arangodb at {arango_url}") return None
if nanopub["nanopub"]["citation"]["database"]["name"].lower( ) == "pubmed": citation_string = f"PMID:{nanopub['nanopub']['citation']['database']['id']}" else: citation_string = f"{nanopub['nanopub']['citation']['database']['name']}:{nanopub['nanopub']['citation']['database']['id']}" elif nanopub["nanopub"]["citation"].get("reference", False): citation_string = nanopub["nanopub"]["citation"]["reference"] elif nanopub["nanopub"]["citation"].get("uri", False): citation_string = nanopub["nanopub"]["citation"]["uri"] return citation_string def main(): pass if __name__ == "__main__": # Setup logging import logging.config module_fn = os.path.basename(__file__) module_fn = module_fn.replace(".py", "") if config.get("logging", False): logging.config.dictConfig(config.get("logging")) log = logging.getLogger(f"{module_fn}") main()
if nanopub['nanopub']['citation']['database']['name'].lower( ) == 'pubmed': citation_string = f"PMID:{nanopub['nanopub']['citation']['database']['id']}" else: citation_string = f"{nanopub['nanopub']['citation']['database']['name']}:{nanopub['nanopub']['citation']['database']['id']}" elif 'reference' in nanopub['nanopub']['citation'] and isinstance( nanopub['nanopub']['citation']['reference'], str): citation_string = nanopub['nanopub']['citation']['reference'] elif 'uri' in nanopub['nanopub']['citation']: citation_string = nanopub['nanopub']['citation']['uri'] return citation_string def main(): pass if __name__ == '__main__': # Setup logging import logging.config module_fn = os.path.basename(__file__) module_fn = module_fn.replace('.py', '') if config.get('logging', False): logging.config.dictConfig(config.get('logging')) log = logging.getLogger(f'{module_fn}') main()