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
7 changes: 4 additions & 3 deletions bedboss/bedboss.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,8 @@ def insert_pep(
# Build the stats backend once for the whole batch. The backend holds
# per-backend resources (persistent R service, gtars reference caches,
# etc.) that should be reused across files.
stat_backend = (
build_backend(bbagent.config.config.analysis.backend) if not lite else None
)
backend_name = bbagent.config.config.analysis.backend
stat_backend = build_backend(backend_name) if not lite else None

for i, pep_sample in enumerate(pep.samples):
is_processed = skipper.is_processed(pep_sample.sample_name)
Expand Down Expand Up @@ -520,6 +519,7 @@ def insert_pep(
force_overwrite=force_overwrite,
annotation=bedset_annotation,
lite=lite,
backend=backend_name,
)
else:
_LOGGER.info(
Expand Down Expand Up @@ -786,4 +786,5 @@ def reprocess_bedset(
)
},
lite=False,
backend=bbagent.config.config.analysis.backend,
)
20 changes: 15 additions & 5 deletions bedboss/bedbuncher/bedbuncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def run_bedbuncher(
no_fail: bool = False,
force_overwrite: bool = False,
lite: bool = False,
backend: str = "r",
) -> None:
"""
Add bedset to the database
Expand All @@ -114,16 +115,17 @@ def run_bedbuncher(
:param description: Bedset description
:param annotation: Bedset annotation (author, source, summary, etc.)
:param heavy: whether to use heavy processing (add all columns to the database).
if False -> R-script won't be executed, only basic statistics will be calculated
if False -> R-script won't be executed, only basic statistics will be calculated.
Ignored when backend is "gtars" (no R plots available).
:param no_fail: whether to raise an error if bedset was not added to the database
:param upload_pephub: whether to create a view in pephub
:param upload_s3: whether to upload files to s3
:param force_overwrite: whether to overwrite the record in the database
:param lite: whether to run the pipeline in lite mode
# TODO: force_overwrite is not working!!! Fix it!
:param backend: analysis backend ("r" or "gtars"). For gtars, heavy is ignored.
:return:
"""
_LOGGER.info(f"Adding bedset { record_id} to the database")
_LOGGER.info(f"Adding bedset {record_id} to the database")

if isinstance(bedbase_config, str):
bbagent = BedBaseAgent(bedbase_config)
Expand All @@ -140,15 +142,21 @@ def run_bedbuncher(
"bedsets",
)

if heavy:
gtars_like = backend == "gtars"
if heavy and not gtars_like:
_LOGGER.info("Heavy processing is True. Calculating plots...")
plot_value = create_plots(
bedset=bed_set,
output_folder=output_folder,
)
plots = BedSetPlots(region_commonality=FileModel(**plot_value))
else:
_LOGGER.info("Heavy processing is False. Plots won't be calculated")
if gtars_like and heavy:
_LOGGER.info(
f"Heavy processing ignored for {backend} backend (no R plots available)"
)
else:
_LOGGER.info("Heavy processing is False. Plots won't be calculated")
plots = None

bbagent.bedset.create(
Expand Down Expand Up @@ -178,6 +186,7 @@ def run_bedbuncher_form_pep(
upload_s3: bool = False,
no_fail: bool = False,
force_overwrite: bool = False,
backend: str = "r",
) -> str:
"""
Create bedset from pep and add it to the database
Expand Down Expand Up @@ -224,6 +233,7 @@ def run_bedbuncher_form_pep(
upload_s3=upload_s3,
no_fail=no_fail,
force_overwrite=force_overwrite,
backend=backend,
)
return bedset_name

Expand Down
15 changes: 11 additions & 4 deletions bedboss/bedstat/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
from bedboss.bedstat.backends.base import StatBackend
from bedboss.bedstat.backends.gtars_backend import GtarsStatBackend
from bedboss.bedstat.backends.r_backend import RStatBackend
from bedboss.const import BACKEND_GTARS, BACKEND_R

__all__ = ["StatBackend", "RStatBackend", "create_backend", "build_backend"]
__all__ = [
"StatBackend",
"RStatBackend",
"GtarsStatBackend",
"create_backend",
"build_backend",
]


def create_backend(name: str, **kwargs) -> StatBackend:
Expand All @@ -12,14 +19,14 @@ def create_backend(name: str, **kwargs) -> StatBackend:
should use :func:`build_backend` instead, which handles backend-specific
prerequisites (e.g. starting an RServiceManager for the R backend).

:param name: Backend name (BACKEND_R or BACKEND_GTARS)
:param name: Backend name ('r' or 'gtars')
:param kwargs: Backend-specific keyword arguments
:return: StatBackend instance
"""
if name == BACKEND_R:
return RStatBackend(**kwargs)
elif name == BACKEND_GTARS:
raise NotImplementedError("gtars backend not yet available. Install via PR 2a.")
return GtarsStatBackend(**kwargs)
else:
raise ValueError(f"Unknown analysis backend: {name!r}. Use 'r' or 'gtars'.")

Expand All @@ -35,7 +42,7 @@ def build_backend(name: str) -> StatBackend:
done to release backend-held resources. See `StatBackend` as a context
manager for automatic cleanup.

:param name: Backend name (BACKEND_R or BACKEND_GTARS)
:param name: Backend name ('r' or 'gtars')
:return: StatBackend instance ready for batch processing
"""
if name == BACKEND_R:
Expand Down
Loading
Loading