Skip to content

Commit

Permalink
bugfixes and doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wshayes committed Jan 7, 2018
1 parent 5e1fdbc commit bce4f77
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 253 deletions.
10 changes: 2 additions & 8 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[bumpversion]
current_version = 0.5.8-dev
current_version = 0.5.8
commit = True
tag = True
parse = (?P<major>\d+)
\.(?P<minor>\d+)
\.(?P<patch>\d+)
\-?(?P<release>[a-z]+)?
serialize =
serialize =
{major}.{minor}.{patch}-{release}
{major}.{minor}.{patch}

Expand All @@ -16,10 +16,4 @@ serialize =

[bumpversion:file:docs/source/conf.py]

[bumpversion:part:release]
optional_value = placeholder
first_value = dev
values =
dev
placeholder

2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.8-dev
0.5.8
7 changes: 7 additions & 0 deletions bel/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,18 @@ def load_configuration():
if belbio_conf_fp:
with open(belbio_conf_fp, 'r') as f:
config = yaml.load(f)
config['source_files'] = {}
config['source_files']['conf'] = belbio_conf_fp

if belbio_secrets_fp:
with open(belbio_secrets_fp, 'r') as f:
secrets = yaml.load(f)
config['secrets'] = copy.deepcopy(secrets)
if 'source_files' in config:
config['source_files']['secrets'] = belbio_secrets_fp
else:
config['source_files'] = {}
config['source_files']['secrets'] = belbio_conf_fp

config = get_versions(config)

Expand Down
2 changes: 1 addition & 1 deletion bel/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.8-dev"
__version__ = "0.5.8"
69 changes: 36 additions & 33 deletions bel/db/arangodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
import logging
log = logging.getLogger(__name__)

edgestore_db_name = 'edgestore'
belns_db_name = 'belns'

edgestore_nodes_name = 'nodes' # edgestore node collection name
edgestore_edges_name = 'edges' # edgestore edge collection name

equiv_nodes_name = 'equivalence_nodes' # equivalence node collection name
equiv_edges_name = 'equivalence_edges' # equivalence edge collection name
ortholog_nodes_name = 'ortholog_nodes' # ortholog node collection name
ortholog_edges_name = 'ortholog_edges' # ortholog edge collection name
belns_definitions_name = 'belns_definitions' # BEL Namespace metadata


def get_client(host=None, port=None, username=None, password=None, enable_logging=True):
"""Get arango client and edgestore db handle"""
Expand Down Expand Up @@ -34,22 +46,15 @@ def get_edgestore_handle(client, username=None, password=None):
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'), '')])

db_name = 'edgestore'
node_name = 'nodes' # node collection name
comp_node_name = 'comp_nodes' # node collection name
edges_name = 'edges' # edge collection name
comp_edges_name = 'comp_edges' # edge collection name

# Create a new database named "edgestore"
try:
edgestore_db = client.create_database(db_name)
edgestore_db = client.create_database(edgestore_db_name)
if username and password:
client.create_user(username, password)
client.grant_user_access(username, db_name)
nodes = edgestore_db.create_collection(node_name, index_bucket_count=64)
comp_nodes = edgestore_db.create_collection(comp_node_name, index_bucket_count=64)
edges = edgestore_db.create_collection(edges_name, edge=True, index_bucket_count=64)
comp_edges = edgestore_db.create_collection(comp_edges_name, edge=True, index_bucket_count=64)
client.grant_user_access(username, edgestore_db_name)
nodes = edgestore_db.create_collection(edgestore_nodes_name, index_bucket_count=64)
edges = edgestore_db.create_collection(edgestore_edges_name, edge=True, index_bucket_count=64)

# Add a hash index to the collection
nodes.add_hash_index(fields=['name'], unique=False)
nodes.add_hash_index(fields=['components'], unique=False) # add subject/object components as node properties
Expand All @@ -61,45 +66,43 @@ def get_edgestore_handle(client, username=None, password=None):
# TODO - add a skiplist index for _from? or _key? to be able to do paging?

except ArangoError as ae:
edgestore_db = client.db(db_name)
edgestore_db = client.db(edgestore_db_name)
except Exception as e:
log.error('Error creating database', e)
log.error(f'Error creating database {edgestore_db_name}', e)

return edgestore_db


def get_belterms_handle(client, username=None, password=None):
"""Get BEL terms arango db handle"""
def get_belns_handle(client, username=None, password=None):
"""Get BEL namespace arango db handle"""

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')), ''])

db_name = 'belterms'
equiv_nodes_name = 'equivalence_nodes' # node collection name
ortholog_nodes_name = 'ortholog_nodes' # node collection name
equiv_edges_name = 'equivalence_edges' # edge collection name
ortholog_edges_name = 'ortholog_edges' # edge collection name

# Create a new database named "belterms"
# Create a new database named "belns"
try:
belterms_db = client.create_database(db_name)
belns_db = client.create_database(belns_db_name)
if username and password:
client.create_user(username, password)
client.grant_user_access(username, db_name)
equiv_nodes = belterms_db.create_collection(equiv_nodes_name, index_bucket_count=64)
ortholog_nodes = belterms_db.create_collection(ortholog_nodes_name, index_bucket_count=64)
equiv_edges = belterms_db.create_collection(equiv_edges_name, edge=True, index_bucket_count=64)
ortholog_edges = belterms_db.create_collection(ortholog_edges_name, edge=True, index_bucket_count=64)
client.grant_user_access(username, belns_db_name)

belns_definitions = belns_db.create_collection(belns_definitions_name)
equiv_nodes = belns_db.create_collection(equiv_nodes_name, index_bucket_count=64)
ortholog_nodes = belns_db.create_collection(ortholog_nodes_name, index_bucket_count=64)
equiv_edges = belns_db.create_collection(equiv_edges_name, edge=True, index_bucket_count=64)
ortholog_edges = belns_db.create_collection(ortholog_edges_name, edge=True, index_bucket_count=64)

# Add a hash index to the collection
equiv_nodes.add_hash_index(fields=['name'], unique=True)
ortholog_nodes.add_hash_index(fields=['name'], unique=True)
return belterms_db

return belns_db

except ArangoError as ae:
belterms_db = client.db(db_name)
return belterms_db
belns_db = client.db(belns_db_name)
return belns_db
except Exception as e:
log.error('Error creating database', e)
log.error(f'Error creating database {belns_db_name}', e)
return None


Expand Down
33 changes: 18 additions & 15 deletions bel/db/elasticsearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,59 +35,62 @@ def index_exists(es, index):
return es.indices.exists(index=index)


def delete_terms_index(es):
def delete_index(es, index_name):
"""Delete the terms index"""

result = es.indices.delete(index=terms_idx_name)
if not index_name:
log.warn('No index name given to delete')
return None

result = es.indices.delete(index=index_name)
return result


def create_terms_index(es):
def create_terms_index(es, index_name):
"""Create terms index"""

log.info(f'Mapping terms fn: {mapping_terms_fn}')
with open(mapping_terms_fn, 'r') as f:
mapping_terms = yaml.load(f)

try:
es.indices.create(index=terms_idx_name, body=mapping_terms)
set_terms_alias(es)
es.indices.create(index=index_name, body=mapping_terms)

except Exception as e:
log.error(f'Could not create elasticsearch terms index: {e}')

return get_client()
set_terms_alias(es)


def get_client(delete: bool = False):
def get_client(delete: bool = False, index_name: str = terms_idx_name):
"""Get elasticsearch client
Will create terms index if not available using mapping in
es_mapping_terms.yml file
Args:
delete (bool): delete index if exists
index_name (str): index to be created or defaults to terms_idx_name
Returns:
es: Elasticsearch client handle
"""

es = Elasticsearch([config['bel_api']['servers']['elasticsearch']], send_get_body_as='POST')
if delete:
if index_exists(es, terms_idx_name):
delete_terms_index(es)
if index_exists(es, index_name):
delete_index(es, index_name)

if not index_exists(es, terms_idx_name):
create_terms_index(es)
if not index_exists(es, index_name):
create_terms_index(es, index_name)

return es


def bulk_load_terms(es, terms, index_name='terms'):
def bulk_load_terms(es, terms):
"""Bulk load terms
Args:
terms: Iterator of term objects
es: elasticsearch handle
terms: Iterator of term objects - includes index_name
"""

chunk_size = 200
Expand Down
9 changes: 3 additions & 6 deletions bel/lang/bel_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import yaml
import requests
import sys
from typing import Mapping, List, TYPE_CHECKING
from typing import Mapping, List
import functools
import fastcache

Expand All @@ -15,9 +15,6 @@
import logging
log = logging.getLogger(__name__)

if TYPE_CHECKING: # to allow type checking for a module that would be a circular import
import bel.lang.belobj


# TODO - normalize convert_namespaces_{str|ast} - too much duplicate code - not very elegant

Expand Down Expand Up @@ -94,7 +91,7 @@ def convert_namespaces_str(bel_str: str, api_url: str = None, namespace_targets:
return bel_str


def convert_namespaces_ast(ast: 'bel.lang.belobj.BEL', endpoint: str, namespace_targets: Mapping[str, List[str]] = None) -> 'bel.lang.bel.BEL':
def convert_namespaces_ast(ast, endpoint: str, namespace_targets: Mapping[str, List[str]] = None):
"""Convert namespaces of BEL Entities in BEL AST using API endpoint
Canonicalization and decanonicalization is determined by endpoint used and namespace_targets.
Expand Down Expand Up @@ -133,7 +130,7 @@ def convert_namespaces_ast(ast: 'bel.lang.belobj.BEL', endpoint: str, namespace_
return ast


def orthologize(ast, bo: 'bel.lang.belobj.BEL', species_id: str) -> 'bel.lang.bel.BEL':
def orthologize(ast, bo, species_id: str):
"""Orthologize BEL Entities in BEL AST using API endpoint
NOTE: - will take first ortholog returned in BEL.bio API result (which may return more than one ortholog)
Expand Down
21 changes: 9 additions & 12 deletions bel/lang/semantics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Semantic validation code

from typing import Tuple, List, TYPE_CHECKING
from typing import Tuple, List
import requests
import re

Expand All @@ -10,17 +10,14 @@
import logging
log = logging.getLogger(__name__)

if TYPE_CHECKING: # to allow type checking for a module that would be a circular import
import bel.lang.belobj


def validate(bo: 'bel.lang.belobj.BEL') -> Tuple[bool, List[Tuple[str, str]]]:
def validate(bo) -> Tuple[bool, List[Tuple[str, str]]]:
"""Semantically validate BEL AST
Add errors and warnings to bel_obj.validation_messages
Args:
bo (bel.lang.belobj.BEL): main bel object
bo: main BEL language object
Returns:
Tuple[bool, List[Tuple[str, str]]]: (is_valid, messages)
Expand All @@ -32,7 +29,7 @@ def validate(bo: 'bel.lang.belobj.BEL') -> Tuple[bool, List[Tuple[str, str]]]:
return bo


def validate_functions(ast: BELAst, bo: 'bel.lang.belobj.BEL') -> 'bel.lang.belobj.BEL':
def validate_functions(ast: BELAst, bo):
"""Recursively validate function signatures
Determine if function matches one of the available signatures. Also,
Expand All @@ -43,10 +40,10 @@ def validate_functions(ast: BELAst, bo: 'bel.lang.belobj.BEL') -> 'bel.lang.belo
canonicalization, e.g. reactants(A, B, C) )
Args:
bo ('bel.lang.belobj.BEL'): bel object
bo: bel object
Returns:
'bel.lang.belobj.BEL': bel object
bel object
"""

if isinstance(ast, Function):
Expand Down Expand Up @@ -187,7 +184,7 @@ def check_function_args(args, signatures, function_name):
return (valid_function, messages)


def validate_arg_values(ast, bo: 'bel.lang.belobj.BEL') -> 'bel.lang.belobj.BEL':
def validate_arg_values(ast, bo):
"""Recursively validate arg (nsargs and strargs) values
Check that NSArgs are found in BELbio API and match appropriate entity_type.
Expand All @@ -196,10 +193,10 @@ def validate_arg_values(ast, bo: 'bel.lang.belobj.BEL') -> 'bel.lang.belobj.BEL'
Generate a WARNING if not.
Args:
bo ('bel.lang.belobj.BEL'): bel object
bo: bel object
Returns:
'bel.lang.belobj.BEL': bel object
bel object
"""

if not bo.endpoint:
Expand Down

0 comments on commit bce4f77

Please sign in to comment.