From da1c1a99572aec8fc7fbfc426a831d1e93c55d16 Mon Sep 17 00:00:00 2001 From: nsheff Date: Thu, 26 Oct 2023 08:07:11 -0400 Subject: [PATCH 1/3] work toward implementing drs --- bbconf/bbconf.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/bbconf/bbconf.py b/bbconf/bbconf.py index f48523c..22ef744 100644 --- a/bbconf/bbconf.py +++ b/bbconf/bbconf.py @@ -52,7 +52,7 @@ _LOGGER = getLogger(PKG_NAME) - +DRS_ACCESS_URL = "{server_url}/objects/{object_id}/access/{access_id}" class BedBaseConf: """ This class standardizes reporting of bedstat and bedbuncher results. @@ -594,3 +594,33 @@ 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 From b6c8a11fe0e77d34ab03a2d39c4d3a607d240b34 Mon Sep 17 00:00:00 2001 From: nsheff Date: Thu, 26 Oct 2023 08:36:23 -0400 Subject: [PATCH 2/3] remove logmuse. See #29 --- bbconf/__init__.py | 3 --- bbconf/bbconf.py | 28 +++++++++++++++++----------- interactive_testing.py | 19 +++++++++++++++++++ requirements/requirements-all.txt | 1 - 4 files changed, 36 insertions(+), 15 deletions(-) create mode 100644 interactive_testing.py 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 22ef744..7a44295 100644 --- a/bbconf/bbconf.py +++ b/bbconf/bbconf.py @@ -53,6 +53,8 @@ _LOGGER = getLogger(PKG_NAME) DRS_ACCESS_URL = "{server_url}/objects/{object_id}/access/{access_id}" + + class BedBaseConf: """ This class standardizes reporting of bedstat and bedbuncher results. @@ -602,25 +604,29 @@ def get_bed_drs_metadata(object_id: str) -> dict: "size": bed_metadata["file_size"], "created_time": bed_metadata["created_time"], "checksums": object_id, - "access_methods": [] + "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 + "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) + access_id=access_id, + ) return access_url diff --git a/interactive_testing.py b/interactive_testing.py new file mode 100644 index 0000000..bbe36e1 --- /dev/null +++ b/interactive_testing.py @@ -0,0 +1,19 @@ +from bbconf import BedBaseConf + +import logging +import sys + +log = logging.getLogger() +log.setLevel(logging.DEBUG) +stream = logging.StreamHandler(sys.stdout) +stream.setLevel(logging.DEBUG) +log.addHandler(stream) +logging.getLogger("bbconf").setLevel(logging.DEBUG) + +bbc = BedBaseConf("bedbase.org/config/bedbase2.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 From 3b2026ba7c30057d8b55375a12015ddeba5a8d79 Mon Sep 17 00:00:00 2001 From: nsheff Date: Thu, 26 Oct 2023 11:40:13 -0400 Subject: [PATCH 3/3] cleanup --- bbconf/bbconf.py | 4 ++-- interactive_testing.py | 26 +++++++++++++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/bbconf/bbconf.py b/bbconf/bbconf.py index 7a44295..f194fb2 100644 --- a/bbconf/bbconf.py +++ b/bbconf/bbconf.py @@ -43,14 +43,14 @@ 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}" diff --git a/interactive_testing.py b/interactive_testing.py index bbe36e1..d9c3134 100644 --- a/interactive_testing.py +++ b/interactive_testing.py @@ -1,16 +1,28 @@ +# 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 -log = logging.getLogger() -log.setLevel(logging.DEBUG) -stream = logging.StreamHandler(sys.stdout) -stream.setLevel(logging.DEBUG) -log.addHandler(stream) -logging.getLogger("bbconf").setLevel(logging.DEBUG) +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/bedbase2.yaml") +bbc = BedBaseConf("../bedbase.org/config/bedbase.yaml") bbc.bed.retrieve("78c0e4753d04b238fc07e4ebe5a02984")