Skip to content

Commit

Permalink
Merge pull request #28 from databio/drs
Browse files Browse the repository at this point in the history
work toward implementing drs
  • Loading branch information
khoroshevskyi authored Oct 30, 2023
2 parents 52fe569 + 406c360 commit 252e592
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
3 changes: 0 additions & 3 deletions bbconf/__init__.py
Original file line number Diff line number Diff line change
@@ -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")
40 changes: 38 additions & 2 deletions bbconf/bbconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
31 changes: 31 additions & 0 deletions interactive_testing.py
Original file line number Diff line number Diff line change
@@ -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")
1 change: 0 additions & 1 deletion requirements/requirements-all.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
logmuse
yacman>=0.9.1
pipestat>=0.6.0a2
#pipestat @ git+https://github.com/pepkit/pipestat@dev#egg=pipestat
Expand Down

0 comments on commit 252e592

Please sign in to comment.