diff --git a/bbconf/__init__.py b/bbconf/__init__.py index e17fb4f..e7ad25b 100644 --- a/bbconf/__init__.py +++ b/bbconf/__init__.py @@ -1,9 +1,6 @@ -import logmuse - from bbconf._version import __version__ from bbconf.bbconf import * from bbconf.const import * __all__ = ["BedBaseConf", "get_bedbase_cfg"] -logmuse.init_logger("bbconf") diff --git a/bbconf/bbconf.py b/bbconf/bbconf.py index 2268974..b8ee8ff 100644 --- a/bbconf/bbconf.py +++ b/bbconf/bbconf.py @@ -43,14 +43,16 @@ from bbconf.exceptions import MissingConfigDataError, BedBaseConfError from bbconf.helpers import raise_missing_key, get_bedbase_cfg -os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # to suppress verbose warnings tensorflow +# os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3" # to suppress verbose warnings tensorflow from geniml.text2bednn import text2bednn from geniml.search import QdrantBackend from sentence_transformers import SentenceTransformer from geniml.region2vec import Region2VecExModel from geniml.io import RegionSet -_LOGGER = getLogger(PKG_NAME) +_LOGGER = getLogger(__name__) + +DRS_ACCESS_URL = "{server_url}/objects/{object_id}/access/{access_id}" class BedBaseConf: @@ -593,3 +595,37 @@ def get_prefixed_uri(self, postfix: str, remote_class: str = "http") -> str: :return: full uri path """ return os.path.join(self.prefix(remote_class), postfix) + + def get_bed_drs_metadata(object_id: str) -> dict: + bed_metadata = self.bed.retrieve(object_id) + drs_dict = { + "id": object_id, + "size": bed_metadata["file_size"], + "created_time": bed_metadata["created_time"], + "checksums": object_id, + "access_methods": [], + } + # add access method for each remote class + for access_id in keys(self.config[CFG_REMOTE_KEY]): + access_dict = { + "type": "https", + "access_id": access_id, + "access_url": DRS_ACCESS_URL.format( + server_url=self.config["access_methods"][access_id]["server_url"], + object_id=object_id, + access_id=access_id, + ), + } + access_dict["region"] = ( + self.config["access_methods"][access_id]["region"] or None + ) + drs_dict["access_methods"].append(access_dict) + return drs_dict + + def get_bed_url(object_id: str, access_id: str) -> str: + access_url = DRS_ACCESS_URL.format( + server_url=self.config["access_methods"][access_id]["server_url"], + object_id=object_id, + access_id=access_id, + ) + return access_url diff --git a/interactive_testing.py b/interactive_testing.py new file mode 100644 index 0000000..d9c3134 --- /dev/null +++ b/interactive_testing.py @@ -0,0 +1,31 @@ +# This provides a short script to explore bbconf interactively +# First you have to set the env vars with something like: +# source ../bedbase.org/environment/production.env + +from bbconf import BedBaseConf + +import logging +import sys + +def set_up_interactive_logger(package=None) -> logging.Logger: + """Set up a logger for interactive testing""" + _LOGGER = logging.getLogger(package) + formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') + stream = logging.StreamHandler(sys.stdout) + stream.setFormatter(formatter) + stream.setLevel(logging.DEBUG) + _LOGGER.addHandler(stream) + _LOGGER.setLevel(logging.DEBUG) + return _LOGGER + +_LOGGER = set_up_interactive_logger() +_LOGGER.debug("Test log message") + + +bbc = BedBaseConf("../bedbase.org/config/bedbase.yaml") + +bbc.bed.retrieve("78c0e4753d04b238fc07e4ebe5a02984") + +bbc.bed.retrieve("78c0e4753d04b238fc07e4ebe5a02984", "bedfile") + +bbc.bed.retrieve("78c0e4753d04b238fc07e4ebe5a02984", result_identifier="bedfile") diff --git a/requirements/requirements-all.txt b/requirements/requirements-all.txt index bdbbb0a..a95ef04 100644 --- a/requirements/requirements-all.txt +++ b/requirements/requirements-all.txt @@ -1,4 +1,3 @@ -logmuse yacman>=0.9.1 pipestat>=0.6.0a2 #pipestat @ git+https://github.com/pepkit/pipestat@dev#egg=pipestat