Skip to content

Commit

Permalink
Merge pull request #137 from databio/dev
Browse files Browse the repository at this point in the history
Release 0.6.0
  • Loading branch information
khoroshevskyi authored Oct 15, 2024
2 parents fb9266f + d826969 commit c6f3614
Show file tree
Hide file tree
Showing 37 changed files with 2,741 additions and 1,822 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get install -y python3-dev
RUN apt-get install -y build-essential

# Install CPU-only pytorch, eliminating huge nvidia dependencies
RUN pip install torch==2.1.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
RUN pip install torch==2.3.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
RUN pip install https://github.com/pepkit/pipestat/archive/refs/heads/dev.zip

RUN pip install -r requirements/requirements-all.txt --no-cache-dir
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It needs a path to the *bedbase configuration file*, which can be provided eithe
- **API**: <a href="https://api.bedbase.org/" target="_blank">https://api.bedbase.org/</a>
- **DEV API**: <a href="https://dev.bedbase.org/" target="_blank">https://api-dev.bedbase.org/</a>
- **UI**: <a href="https://bedbase.org/" target="_blank">https://bedbase.org/</a>
-**DEV UI**: <a href="https://dev.bedhost.pages.dev/" target="_blank">https://dev.bedhost.pages.dev/</a>
- **DEV UI**: <a href="https://dev.bedbase.org/" target="_blank">https://dev.bedbase.org/</a>
- **Source Code**: <a href="https://github.com/databio/bedhost/" target="_blank">https://github.com/databio/bedhost/</a>

## Developer quick-start
Expand Down
2 changes: 1 addition & 1 deletion bedhost/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.5.0"
__version__ = "0.6.0"
49 changes: 27 additions & 22 deletions bedhost/routers/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,17 @@

from ..main import bbagent, app
from ..helpers import get_openapi_version
from ..data_models import ServiceInfoResponse
from ..data_models import (
ServiceInfoResponse,
Type,
Organization,
ComponentVersions,
EmbeddingModels,
)
from .._version import __version__ as bedhost_version

router = APIRouter(prefix="/v1", tags=["base"])


packages_versions = {}


Expand All @@ -31,7 +36,7 @@ async def get_bedbase_db_stats():
"""
Returns statistics
"""
return bbagent.get_stats
return bbagent.get_stats()


@router.get(
Expand All @@ -41,33 +46,33 @@ async def service_info():
"""
Returns information about this service, such as versions, name, etc.
"""
all_versions = {
"bedhost_version": bedhost_version,
"bbconf_version": bbconf_version,
"geniml_version": geniml_version,
"python_version": python_version(),
"openapi_version": get_openapi_version(app),
}
all_versions = ComponentVersions(
bedhost_version=bedhost_version,
bbconf_version=bbconf_version,
geniml_version=geniml_version,
python_version=python_version(),
openapi_version=get_openapi_version(app),
)

return ServiceInfoResponse(
id="org.bedbase.api",
name="BEDbase API",
type={
"group": "org.databio",
"artifact": "bedbase",
"version": bedhost_version,
},
type=Type(
group="org.databio",
artifact="bedbase",
version=bedhost_version,
),
description="An API providing genomic interval data and metadata",
organization={"name": "Databio Lab", "url": "https://databio.org"},
organization=Organization(name="Databio Lab", url="https://databio.org"),
contactUrl="https://github.com/databio/bedbase/issues",
documentationUrl="https://docs.bedbase.org",
updatedAt="2023-10-25T00:00:00Z",
updatedAt="2024-09-26T00:00:00Z",
environment="main",
version=bedhost_version,
component_versions=all_versions,
embedding_models={
"vec2vec": bbagent.config.config.path.vec2vec,
"region2vec": bbagent.config.config.path.region2vec,
"text2vec": bbagent.config.config.path.text2vec,
},
embedding_models=EmbeddingModels(
vec2vec=bbagent.config.config.path.vec2vec,
region2vec=bbagent.config.config.path.region2vec,
text2vec=bbagent.config.config.path.text2vec,
),
)
41 changes: 36 additions & 5 deletions bedhost/routers/bed_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from fastapi import APIRouter, HTTPException, Query, UploadFile, File
from fastapi.responses import PlainTextResponse

from genimtools.tokenizers import RegionSet
from gtars.tokenizers import RegionSet

import tempfile
import os
import shutil

from bbconf.models.bed_models import (
BedListResult,
BedMetadata,
BedMetadataAll,
BedFiles,
BedStatsModel,
BedPlots,
Expand Down Expand Up @@ -45,7 +45,7 @@
@router.get(
"/example",
summary="Get example BED record metadata",
response_model=BedMetadata,
response_model=BedMetadataAll,
)
async def get_example_bed_record():
"""
Expand Down Expand Up @@ -83,7 +83,8 @@ async def list_beds(
@router.get(
"/{bed_id}/metadata",
summary="Get metadata for a single BED record",
response_model=BedMetadata,
response_model=BedMetadataAll,
response_model_by_alias=False,
description=f"Example\n " f"bed_id: {EXAMPLE_BED}",
)
async def get_bed_metadata(
Expand Down Expand Up @@ -158,6 +159,7 @@ async def get_bed_stats(
"/{bed_id}/metadata/classification",
summary="Get classification of single BED file",
response_model=BedClassification,
response_model_by_alias=False,
description=f"Example\n bed_id: {EXAMPLE_BED}",
)
async def get_bed_classification(
Expand All @@ -176,6 +178,7 @@ async def get_bed_classification(
summary="Get raw metadata for a single BED record",
# response_model=BedPEPHub,
response_model=BedPEPHubRestrict,
response_model_by_alias=False,
description=f"Returns raw metadata for a single BED record. "
f"This metadata is stored in PEPHub. And is not verified."
f"Example\n bed_id: {EXAMPLE_BED}",
Expand All @@ -196,7 +199,7 @@ async def get_bed_pephub(
summary="Get embeddings for a single BED record",
response_model=BedEmbeddingResult,
)
def get_bed_embedding(bed_id: str = BedDigest):
async def get_bed_embedding(bed_id: str = BedDigest):
"""
Returns embeddings for a single BED record.
"""
Expand All @@ -208,6 +211,32 @@ def get_bed_embedding(bed_id: str = BedDigest):
)


@router.post(
"/embed",
summary="Get embeddings for a bed file.",
response_model=List[float],
)
async def embed_bed_file(
file: UploadFile = File(None),
):
"""
Create embedding for bed file
"""
_LOGGER.info("Embedding file..")

if file is not None:
with tempfile.TemporaryDirectory() as dirpath:
file_path = os.path.join(dirpath, file.filename)

with open(file_path, "wb") as bed_file:
shutil.copyfileobj(file.file, bed_file)

region_set = RegionSet(file_path)

embedding = bbagent.bed._embed_file(region_set)
return embedding.tolist()[0]


@router.get(
"/{bed_id}/regions/{chr_num}",
summary="Get regions from a BED file that overlap a query region.",
Expand Down Expand Up @@ -272,6 +301,7 @@ def get_regions_for_bedfile(
summary="Search for a BedFile",
tags=["search"],
response_model=BedListSearchResult,
response_model_by_alias=False,
)
async def text_to_bed_search(query, limit: int = 10, offset: int = 0):
"""
Expand All @@ -291,6 +321,7 @@ async def text_to_bed_search(query, limit: int = 10, offset: int = 0):
summary="Search for similar bed files",
tags=["search"],
response_model=BedListSearchResult,
response_model_by_alias=False,
)
async def bed_to_bed_search(
file: UploadFile = File(None), limit: int = 10, offset: int = 0
Expand Down
3 changes: 3 additions & 0 deletions bedhost/routers/bedset_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"/example",
summary="Get metadata for an example BEDset record",
response_model=BedSetMetadata,
response_model_by_alias=False,
)
async def get_example_bedset_record():
result = bbagent.bedset.get_ids_list(limit=1).results
Expand All @@ -49,6 +50,7 @@ async def list_bedsets(query: str = None, limit: int = 1000, offset: int = 0):
response_model=BedSetMetadata,
summary="Get all metadata for a single BEDset record",
description=f"Example\n bed_id: {EXAMPLE_BEDSET}",
response_model_by_alias=False,
)
async def get_bedset_metadata(
bedset_id: str,
Expand Down Expand Up @@ -98,6 +100,7 @@ async def get_bedset_metadata(
"/{bedset_id}/bedfiles",
response_model=BedSetBedFiles,
description=f"Example\n bed_id: {EXAMPLE_BEDSET}",
response_model_by_alias=False,
)
async def get_bedfiles_in_bedset(
bedset_id: str,
Expand Down
2 changes: 1 addition & 1 deletion dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apt-get install -y python3-dev
RUN apt-get install -y build-essential

# Install CPU-only pytorch, eliminating huge nvidia dependencies
RUN pip install torch==2.1.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
RUN pip install torch==2.3.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
RUN pip install https://github.com/pepkit/pipestat/archive/refs/heads/dev.zip

RUN pip install -r requirements/requirements-all.txt --no-cache-dir
Expand Down
4 changes: 2 additions & 2 deletions requirements/requirements-all.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
bbconf @ git+https://github.com/databio/bbconf.git@dev#egg=bbconf
# bbconf>=0.6.0
#bbconf @ git+https://github.com/databio/bbconf.git@dev#egg=bbconf
bbconf>=0.7.1
fastapi>=0.103.0
logmuse>=0.2.7
markdown
Expand Down
Loading

0 comments on commit c6f3614

Please sign in to comment.