Skip to content

Commit

Permalink
Merge pull request #149 from databio/dev
Browse files Browse the repository at this point in the history
Release 0.8.0
  • Loading branch information
khoroshevskyi authored Nov 7, 2024
2 parents acbb847 + 175b922 commit a6fcb8a
Show file tree
Hide file tree
Showing 22 changed files with 220 additions and 149 deletions.
4 changes: 3 additions & 1 deletion bedhost/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import logmuse
import logging

import logmuse

from .const import PKG_NAME

_LOGGER = logmuse.init_logger(PKG_NAME)
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.7.0"
__version__ = "0.8.0"
3 changes: 2 additions & 1 deletion bedhost/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from ubiquerg import VersionInHelpParser

from . import PKG_NAME
from ._version import __version__
from ubiquerg import VersionInHelpParser


def build_parser():
Expand Down
10 changes: 9 additions & 1 deletion bedhost/data_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum

from fastapi import Path
from pydantic import BaseModel
from enum import Enum

RemoteClassEnum = Enum(
"RemoteClassEnum",
Expand Down Expand Up @@ -69,3 +70,10 @@ class ServiceInfoResponse(BaseModel):
version: str
component_versions: ComponentVersions
embedding_models: EmbeddingModels


class BaseListResponse(BaseModel):
count: int
limit: int
offset: int
results: list
6 changes: 3 additions & 3 deletions bedhost/helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from starlette.responses import FileResponse, RedirectResponse, JSONResponse
import os

from bbconf.bbagent import BedBaseAgent
import os
from starlette.responses import FileResponse, JSONResponse, RedirectResponse

from . import _LOGGER
from .exceptions import BedHostException
Expand Down Expand Up @@ -50,7 +50,7 @@ def attach_routers(app):
_LOGGER.info("Mounting routers...")

# importing routers here avoids circular imports
from .routers import bed_api, bedset_api, objects_api, base_api
from .routers import base_api, bed_api, bedset_api, objects_api

app.include_router(base_api.router)
app.include_router(bed_api.router)
Expand Down
30 changes: 10 additions & 20 deletions bedhost/main.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,24 @@
import os
import sys
import uvicorn

from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse, RedirectResponse

import markdown
from fastapi.templating import Jinja2Templates
import uvicorn
from bbconf.exceptions import (
MissingObjectError,
MissingThumbnailError,
BEDFileNotFoundError,
BedSetNotFoundError,
MissingObjectError,
MissingThumbnailError,
)

from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import HTMLResponse, RedirectResponse
from fastapi.templating import Jinja2Templates

from . import _LOGGER
from .helpers import (
configure,
attach_routers,
drs_response,
)
from .cli import build_parser
from ._version import __version__ as bedhost_version
from .const import (
PKG_NAME,
STATIC_PATH,
)

from .cli import build_parser
from .const import PKG_NAME, STATIC_PATH
from .helpers import attach_routers, configure, drs_response

tags_metadata = [
{
Expand Down
39 changes: 29 additions & 10 deletions bedhost/routers/base_api.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
try:
from typing import Annotated, Dict, Optional, List, Any
from typing import Annotated, Any, Dict, List, Optional
except ImportError:
from typing_extensions import Annotated
from typing import Dict, Optional, List, Any

from fastapi import APIRouter

from bbconf.models.base_models import StatsReturn
from platform import python_version

from bbconf import __version__ as bbconf_version
from bbconf.models.base_models import StatsReturn
from fastapi import APIRouter
from geniml import __version__ as geniml_version

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

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

Expand All @@ -39,6 +40,24 @@ async def get_bedbase_db_stats():
return bbagent.get_stats()


@router.get(
"/genomes",
summary="Get available genomes",
response_model=BaseListResponse,
)
async def get_bedbase_db_stats():
"""
Returns statistics
"""
genomes = bbagent.get_list_genomes()
return BaseListResponse(
count=len(genomes),
limit=100,
offset=0,
results=genomes,
)


@router.get(
"/service-info", summary="GA4GH service info", response_model=ServiceInfoResponse
)
Expand Down
69 changes: 47 additions & 22 deletions bedhost/routers/bed_api.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,41 @@
import subprocess

try:
from typing import Annotated, Dict, Optional, List, Any
from typing import Annotated, Any, Dict, List, Optional
except ImportError:
from typing_extensions import Annotated
from typing import Dict, Optional, List, Any

from fastapi import APIRouter, HTTPException, Query, UploadFile, File
from fastapi.responses import PlainTextResponse

from gtars.tokenizers import RegionSet

import tempfile
import os
import shutil
import tempfile

from bbconf.exceptions import (
BedBaseConfError,
BEDFileNotFoundError,
TokenizeFileNotExistError,
)
from bbconf.models.bed_models import (
BedClassification, # BedPEPHub,
BedEmbeddingResult,
BedFiles,
BedListResult,
BedListSearchResult,
BedMetadataAll,
BedFiles,
BedStatsModel,
BedPlots,
BedClassification,
# BedPEPHub,
BedPEPHubRestrict,
BedListSearchResult,
TokenizedPathResponse,
BedPlots,
BedStatsModel,
TokenizedBedResponse,
BedEmbeddingResult,
TokenizedPathResponse,
)
from bbconf.exceptions import BEDFileNotFoundError, TokenizeFileNotExistError
from fastapi import APIRouter, File, HTTPException, Query, UploadFile
from fastapi.responses import PlainTextResponse
from gtars.tokenizers import RegionSet

from .. import _LOGGER
from ..main import bbagent
from ..data_models import (
BedDigest,
CROM_NUMBERS,
)
from ..const import EXAMPLE_BED
from ..data_models import CROM_NUMBERS, BaseListResponse, BedDigest
from ..main import bbagent

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

Expand All @@ -52,7 +50,7 @@ async def get_example_bed_record():
"""
Get metadata for an example BED record.
"""
result = bbagent.bed.get_ids_list(limit=1, offset=0).results
result = bbagent.bed.get_ids_list(limit=1, offset=0, genome="hg38").results
if result:
return result[0]
raise HTTPException(status_code=404, detail="No records found")
Expand Down Expand Up @@ -238,6 +236,33 @@ async def embed_bed_file(
return embedding.tolist()[0]


@router.get(
"/missing_plots",
summary="Get missing plots for a bed file.",
response_model=BaseListResponse,
)
async def missing_plots(plot_id: str):
"""
Get missing plots for a bed file
example -> plot_id: gccontent
"""

try:
bed_ids = bbagent.bed.get_missing_plots(plot_id, limit=100000, offset=0)
except BedBaseConfError as e:
raise HTTPException(
status_code=404,
detail=f"{e}",
)
return BaseListResponse(
count=len(bed_ids),
limit=100000,
offset=0,
results=bed_ids,
)


@router.get(
"/{bed_id}/regions/{chr_num}",
summary="Get regions from a BED file that overlap a query region.",
Expand Down
11 changes: 5 additions & 6 deletions bedhost/routers/bedset_api.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
from fastapi import APIRouter, HTTPException, Request, Response
import logging

from bbconf.exceptions import BedSetNotFoundError
from bbconf.models.bedset_models import (
BedSetMetadata,
BedSetListResult,
BedSetBedFiles,
BedSetListResult,
BedSetMetadata,
BedSetPlots,
BedSetStats,
)
from bbconf.exceptions import BedSetNotFoundError
from fastapi import APIRouter, HTTPException, Request, Response

from ..const import EXAMPLE_BEDSET, PKG_NAME
from ..main import bbagent
from ..const import PKG_NAME, EXAMPLE_BEDSET
from ..utils import zip_pep


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

_LOGGER = logging.getLogger(PKG_NAME)
Expand Down
11 changes: 5 additions & 6 deletions bedhost/routers/objects_api.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
try:
from typing import Annotated, Dict, Optional, List, Any
from typing import Annotated, Any, Dict, List, Optional
except ImportError:
from typing_extensions import Annotated
from typing import Dict, Optional, List, Any

from fastapi import APIRouter, HTTPException, Request
from urllib.parse import urlparse

from bbconf.models.drs_models import DRSModel
from fastapi import APIRouter, HTTPException, Request

from ..helpers import serve_file
from ..main import bbagent
from ..helpers import (
serve_file,
)
from urllib.parse import urlparse

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

Expand Down
2 changes: 1 addition & 1 deletion deployment/config/api-dev.bedbase.org.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ qdrant:
host: $QDRANT_HOST
port: 6333
api_key: $QDRANT_API_KEY
file_collection: bedbase2
file_collection: bedbase
text_collection: bed_text
server:
host: 0.0.0.0
Expand Down
2 changes: 1 addition & 1 deletion deployment/config/api.bedbase.org.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ qdrant:
host: $QDRANT_HOST
port: 6333
api_key: $QDRANT_API_KEY
file_collection: bedbase2
file_collection: bedbase
text_collection: bed_text
server:
host: 0.0.0.0
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.8.0
# bbconf @ git+https://github.com/databio/bbconf.git@dev#egg=bbconf
bbconf>=0.9.0
fastapi>=0.103.0
logmuse>=0.2.7
markdown
Expand Down
3 changes: 2 additions & 1 deletion tests/test_fastapi/test_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from fastapi.testclient import TestClient
import os

import pytest
from fastapi.testclient import TestClient

# os.environ.setdefault("BEDBASE_CONFIG", os.path.abspath("test_config.yaml"))
# from bedhost.main import app
Expand Down
4 changes: 2 additions & 2 deletions ui/bedbase-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1182,7 +1182,7 @@ export interface components {
* @description Name of species. e.g. Homo sapiens.
* @default
*/
organism: string;
species_name: string;
/**
* Species Id
* @default
Expand Down Expand Up @@ -1234,7 +1234,7 @@ export interface components {
* @description Experimental protocol (e.g. ChIP-seq)
* @default
*/
exp_protocol: string;
assay: string;
/**
* Antibody
* @description Antibody used in the assay
Expand Down
Loading

0 comments on commit a6fcb8a

Please sign in to comment.