Skip to content

Commit

Permalink
Add debug diagnostic messages to BiolinkHelper; send all output to ST…
Browse files Browse the repository at this point in the history
…DERR #2093

ARAX_query does not need to call connect on ResponseCache
  • Loading branch information
isbluis committed Aug 11, 2023
1 parent 140cd4b commit f0a4ea1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
3 changes: 1 addition & 2 deletions code/ARAX/ARAXQuery/ARAX_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ def execute_processing_plan(self,input_operations_dict, mode='ARAX'):

#### Connect to the message store just once, even if we won't use it
response.debug(f"Connecting to ResponseCache")
response_cache = ResponseCache()
response_cache.connect()
response_cache = ResponseCache() # also calls connect

#### Create a messenger object for basic message processing
response.debug(f"Creating ARAXMessenger instance")
Expand Down
14 changes: 11 additions & 3 deletions code/ARAX/BiolinkHelper/biolink_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import argparse
import json
import os
import sys
import pathlib
import pickle
from collections import defaultdict
Expand All @@ -15,10 +16,12 @@
import yaml
from treelib import Tree

def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs)

class BiolinkHelper:

def __init__(self, biolink_version: Optional[str] = None, is_test: bool = False):
eprint("DEBUG: In BiolinkHelper init")
self.biolink_version = biolink_version if biolink_version else self.get_current_arax_biolink_version()
self.root_category = "biolink:NamedThing"
self.root_predicate = "biolink:related_to"
Expand Down Expand Up @@ -112,7 +115,7 @@ def get_canonical_predicates(self, predicates: Union[str, List[str], Set[str]])
valid_predicates = input_predicate_set.intersection(self.biolink_lookup_map["predicates"])
invalid_predicates = input_predicate_set.difference(valid_predicates)
if invalid_predicates:
print(f"WARNING: Provided predicate(s) {invalid_predicates} do not exist in Biolink {self.biolink_version}")
eprint(f"WARNING: Provided predicate(s) {invalid_predicates} do not exist in Biolink {self.biolink_version}")
canonical_predicates = {self.biolink_lookup_map["predicates"][predicate]["canonical_predicate"]
for predicate in valid_predicates}
canonical_predicates.update(invalid_predicates) # Go ahead and include those we don't have canonical info for
Expand Down Expand Up @@ -185,7 +188,12 @@ def get_current_arax_biolink_version() -> str:

def _load_biolink_lookup_map(self, is_test: bool = False):
lookup_map_file = pathlib.Path(self.biolink_lookup_map_path)

if is_test or not lookup_map_file.exists():
if is_test:
eprint(f"DEBUG: in test mode")
else:
eprint(f"DEBUG: lookup map not here! {lookup_map_file}")
# Parse the relevant Biolink yaml file and create/save local indexes
return self._create_biolink_lookup_map()
else:
Expand All @@ -195,8 +203,8 @@ def _load_biolink_lookup_map(self, is_test: bool = False):
return biolink_lookup_map

def _create_biolink_lookup_map(self) -> Dict[str, Dict[str, Dict[str, Union[str, List[str], bool]]]]:
print(f"INFO: Building local Biolink {self.biolink_version} ancestor/descendant lookup map because one "
f"doesn't yet exist")
eprint(f"INFO: Building local Biolink {self.biolink_version} ancestor/descendant lookup map because one "
f"doesn't yet exist")
biolink_lookup_map = {"predicates": dict(), "categories": dict(),
"predicate_mixins": dict(), "category_mixins": dict(),
"aspects": dict(), "directions": dict()}
Expand Down

0 comments on commit f0a4ea1

Please sign in to comment.