diff --git a/bedboss/bedboss.py b/bedboss/bedboss.py index 5aec420..3493441 100644 --- a/bedboss/bedboss.py +++ b/bedboss/bedboss.py @@ -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 @@ -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, @@ -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 @@ -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) @@ -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): @@ -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, @@ -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, ) diff --git a/bedboss/bedbuncher/bedbuncher.py b/bedboss/bedbuncher/bedbuncher.py index 9b03ebc..9b5351d 100644 --- a/bedboss/bedbuncher/bedbuncher.py +++ b/bedboss/bedbuncher/bedbuncher.py @@ -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 @@ -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, @@ -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): diff --git a/bedboss/bedstat/bedstat.py b/bedboss/bedstat/bedstat.py index bf57ef8..d5851d6 100755 --- a/bedboss/bedstat/bedstat.py +++ b/bedboss/bedstat/bedstat.py @@ -1,4 +1,4 @@ -from typing import NoReturn +from typing import Union import json import yaml import os @@ -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, @@ -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. @@ -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]