Skip to content

Commit

Permalink
Updated initiation of bbconf object (initiaded once for insert option)
Browse files Browse the repository at this point in the history
  • Loading branch information
khoroshevskyi committed Nov 27, 2023
1 parent fb99493 commit 8c4e6bf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
16 changes: 10 additions & 6 deletions bedboss/bedboss.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from eido import validate_project
import pephubclient
from pephubclient.helpers import is_registry_path
import bbconf

from bedboss.bedstat.bedstat import bedstat
from bedboss.bedmaker.bedmaker import BedMaker
Expand Down Expand Up @@ -76,7 +77,7 @@ def run_all(
input_type: str,
outfolder: str,
genome: str,
bedbase_config: str,
bedbase_config: Union[str, bbconf.BedBaseConf],
rfg_config: str = None,
narrowpeak: bool = False,
check_qc: bool = True,
Expand All @@ -103,7 +104,7 @@ def run_all(
:param input_type: Input type [required] options: (bigwig|bedgraph|bed|bigbed|wig)
:param outfolder: Folder, where output should be saved [required]
:param genome: genome_assembly of the sample. [required] options: (hg19, hg38) #TODO: add more
:param bedbase_config: a path to the bedbase configuration file. [required] #TODO: add example
:param bedbase_config: The path to the bedbase configuration file, or bbconf object.
:param open_signal_matrix: a full path to the openSignalMatrix required for the tissue [optional]
:param rfg_config: file path to the genome config file [optional]
:param narrowpeak: whether the regions are narrow
Expand All @@ -126,8 +127,9 @@ def run_all(
"""
_LOGGER.warning(f"Unused arguments: {kwargs}")

if not check_db_connection(bedbase_config=bedbase_config):
raise Exception("Database connection failed. Exiting...")
if isinstance(bedbase_config, str):
if not check_db_connection(bedbase_config=bedbase_config):
raise Exception("Database connection failed. Exiting...")

file_name = extract_file_name(input_file)
genome = standardize_genome_name(genome)
Expand Down Expand Up @@ -235,6 +237,8 @@ def insert_pep(
else:
raise BedBossException("Incorrect pep type. Exiting...")

bbc = bbconf.BedBaseConf(config_path=bedbase_config, database_only=True)

validate_project(pep, BEDBOSS_PEP_SCHEMA_PATH)

for i, pep_sample in enumerate(pep.samples):
Expand All @@ -251,7 +255,7 @@ def insert_pep(
cell_type=pep_sample.get("cell_type"),
treatment=pep_sample.get("treatment"),
outfolder=output_folder,
bedbase_config=bedbase_config,
bedbase_config=bbc,
rfg_config=rfg_config,
check_qc=check_qc,
standard_chrom=standard_chrom,
Expand All @@ -266,7 +270,7 @@ def insert_pep(
if create_bedset:
_LOGGER.info(f"Creating bedset from {pep.name}")
run_bedbuncher(
bedbase_config=bedbase_config,
bedbase_config=bbc,
bedset_pep=pep,
pephub_registry_path=pephub_registry_path,
)
Expand Down
6 changes: 4 additions & 2 deletions bedboss/bedbuncher/bedbuncher.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import bbconf
from geniml.io import BedSet
from bbconf import BedBaseConf
from bbconf.const import CFG_PATH_KEY, CFG_PATH_BEDBUNCHER_DIR_KEY
Expand Down Expand Up @@ -230,7 +231,7 @@ def add_bedset_to_database(


def run_bedbuncher(
bedbase_config: str,
bedbase_config: Union[str, bbconf.BedBaseConf],
bedset_pep: Union[str, peppy.Project],
bedset_name: str = None,
pephub_registry_path: str = None,
Expand All @@ -253,7 +254,8 @@ def run_bedbuncher(
:return: None
"""

bbc = BedBaseConf(bedbase_config)
if isinstance(bedbase_config, str):
bbc = BedBaseConf(bedbase_config)
if isinstance(bedset_pep, peppy.Project):
pep_of_bed = bedset_pep
elif isinstance(bedset_pep, str):
Expand Down
13 changes: 9 additions & 4 deletions bedboss/bedstat/bedstat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import NoReturn
from typing import Union
import json
import yaml
import os
Expand Down Expand Up @@ -34,7 +34,7 @@ def convert_unit(size_in_bytes: int) -> str:

def bedstat(
bedfile: str,
bedbase_config: str,
bedbase_config: Union[str, bbconf.BedBaseConf],
genome: str,
outfolder: str,
ensdb: str = None,
Expand All @@ -59,7 +59,7 @@ def bedstat(
:param str bigbed: the full path to the bigbed file. Defaults to None.
(bigbed won't be created and some producing of some statistics will
be skipped.)
:param str bedbase_config: The path to the bedbase configuration file.
:param str bedbase_config: The path to the bedbase configuration file, or bbconf object
:param str open_signal_matrix: a full path to the openSignalMatrix
required for the tissue specificity plots
:param str outfolder: The folder for storing the pipeline results.
Expand All @@ -86,7 +86,12 @@ def bedstat(
os.makedirs(outfolder_stats)
except FileExistsError:
pass
bbc = bbconf.BedBaseConf(config_path=bedbase_config, database_only=True)

# if bbconf is a string, create a bbconf object
if isinstance(bedbase_config, str):
bbc = bbconf.BedBaseConf(config_path=bedbase_config, database_only=True)
else:
bbc = bedbase_config

bed_digest = RegionSet(bedfile).identifier
bedfile_name = os.path.split(bedfile)[1]
Expand Down

0 comments on commit 8c4e6bf

Please sign in to comment.