Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions bedhost/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from . import PKG_NAME
from ._version import __version__

CFG_ENV_VARS = ["BEDBASE_CONFIG"]


def build_parser():
"""
Expand Down
2 changes: 2 additions & 0 deletions bedhost/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
USAGE_RECORD_DAYS = 30


MAX_BATCH_IDS = 1000

MAX_FILE_SIZE = 1024 * 1024 * 2
MAX_REGION_NUMBER = 5000000
MIN_REGION_WIDTH = 10
8 changes: 8 additions & 0 deletions bedhost/data_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,13 @@ class CreateBEDsetRequest(BaseModel):
registry_path: str


class BatchBedRequest(BaseModel):
ids: list[str]


class CollectionStatsRequest(BaseModel):
ids: list[str]


class ChromLengthUploadModel(BaseModel):
bed_file: Dict[str, int]
7 changes: 6 additions & 1 deletion bedhost/routers/base_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

from platform import python_version

from bbconf import __version__ as bbconf_version
try:
from bbconf import __version__ as bbconf_version
except ImportError:
from importlib.metadata import version

bbconf_version = version("bbconf")
from bbconf.models.base_models import StatsReturn, FileStats, UsageStats
from fastapi import APIRouter, Request
from geniml import __version__ as geniml_version
Expand Down
48 changes: 46 additions & 2 deletions bedhost/routers/bed_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,20 @@
from gtars.models import RegionSet

from .. import _LOGGER
from ..const import EXAMPLE_BED, MAX_FILE_SIZE, MAX_REGION_NUMBER, MIN_REGION_WIDTH
from ..const import (
EXAMPLE_BED,
MAX_BATCH_IDS,
MAX_FILE_SIZE,
MAX_REGION_NUMBER,
MIN_REGION_WIDTH,
)
from ..data_models import (
CROM_NUMBERS,
BaseListResponse,
BatchBedRequest,
BedDigest,
ChromLengthUploadModel,
CollectionStatsRequest,
)
from ..main import bbagent, usage_data, ref_validator
from ..helpers import count_requests, test_query_parameter
Expand Down Expand Up @@ -159,15 +167,51 @@ async def get_bed_files(
)
async def get_bed_stats(
bed_id: str = BedDigest,
distributions: bool = Query(
True,
description="Include distribution arrays in the response. Set to false to exclude the large distributions blob.",
),
):
try:
return bbagent.bed.get_stats(bed_id)
return bbagent.bed.get_stats(bed_id, distributions=distributions)
except BEDFileNotFoundError as _:
raise HTTPException(
status_code=404,
)


@router.post(
"/batch",
summary="Get metadata for multiple BED records",
)
async def get_bed_batch(
request: BatchBedRequest,
):
"""Retrieve metadata for multiple BED files in a single request."""
if len(request.ids) > MAX_BATCH_IDS:
raise HTTPException(
status_code=400,
detail=f"Too many IDs. Maximum is {MAX_BATCH_IDS}.",
)
return bbagent.bed.get_batch(request.ids, full=True, distributions=False)


@router.post(
"/collection/stats",
summary="Compute ad-hoc collection statistics from a list of BED IDs",
)
async def get_collection_stats(
request: CollectionStatsRequest,
):
"""Aggregate distribution statistics across a set of BED files on the fly."""
if len(request.ids) > MAX_BATCH_IDS:
raise HTTPException(
status_code=400,
detail=f"Too many IDs. Maximum is {MAX_BATCH_IDS}.",
)
return bbagent.bed.aggregate_collection(request.ids)


@router.get(
"/{bed_id}/metadata/classification",
summary="Get classification of single BED file",
Expand Down
28 changes: 25 additions & 3 deletions bedhost/routers/bedset_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from bbconf.exceptions import BedSetNotFoundError, BedSetTrackHubLimitError
from bbconf.models.bedset_models import (
BedSetBedFiles,
BedSetDistributions,
BedSetListResult,
BedSetMetadata,
BedSetPlots,
Expand Down Expand Up @@ -109,10 +110,10 @@ async def get_bedset_metadata(
@router.get(
"/{bedset_id}/metadata/stats",
response_model=BedSetStats,
summary="Get stats for a single BEDSET record",
description=f"Example\n bed_id: {EXAMPLE_BEDSET}",
summary="Get scalar stats (mean/sd) for a single BEDSET record",
description=f"Example\n bedset_id: {EXAMPLE_BEDSET}",
)
async def get_bedset_metadata(
async def get_bedset_stats(
bedset_id: str,
):
try:
Expand All @@ -121,6 +122,27 @@ async def get_bedset_metadata(
raise HTTPException(status_code=404, detail="No records found")


@router.get(
"/{bedset_id}/metadata/distributions",
response_model=BedSetDistributions,
summary="Get distribution statistics for a single BEDSET record",
description=f"Example\n bedset_id: {EXAMPLE_BEDSET}",
)
async def get_bedset_distributions(
bedset_id: str,
):
"""Get aggregated distribution statistics from the JSONB column.

Returns full distribution data (histograms, KDEs, partitions, etc.)
computed across all member BED files. Falls back to wrapping old
scalar stats if distribution data is not yet available.
"""
try:
return bbagent.bedset.get_distributions(bedset_id)
except BedSetNotFoundError as _:
raise HTTPException(status_code=404, detail="No records found")


@router.get(
"/{bedset_id}/bedfiles",
response_model=BedSetBedFiles,
Expand Down
4 changes: 3 additions & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"generate-types": "npx openapi-typescript https://api-dev.bedbase.org/openapi.json -o bedbase-types.d.ts",
"generate-types-local": "npx openapi-typescript http://localhost:8000/openapi.json -o bedbase-types.d.ts"
"generate-types-local": "npx openapi-typescript http://localhost:8000/openapi.json -o bedbase-types.d.ts",
"deploy": "npm run build && wrangler deploy",
"deploy:preview": "npm run build && wrangler dev"
},
"dependencies": {
"@databio/gtars": "^0.5.3",
Expand Down
8 changes: 8 additions & 0 deletions ui/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "bedhost-ui",
"compatibility_date": "2026-02-20",
"assets": {
"directory": "./dist",
"not_found_handling": "single-page-application"
}
}
Loading