Skip to content

BBClient Module

class BBClient(cache_folder: Union[str, os.PathLike] = DEFAULT_CACHE_FOLDER, bedbase_api: str = DEFAULT_BEDBASE_API)

Bases: BedCacheManager

BBClient to deal with download files from bedbase and caching them.

Args: cache_folder (Union[str, os.PathLike]): path to local folder as cache of files from bedbase, if not given it will be the environment variable BBCLIENT_CACHE bedbase_api (str): url to bedbase

  • zarr_cache
  • bedbase_api

def load_bedset(bedset_id: str) -> BedSet

Load a BEDset from cache, or download and add it to the cache with its BED files.

Args: bedset_id (str): unique identifier of a BED set

Returns: BedSet: the BedSet object

def load_bed(bed_id: str) -> RegionSet

Loads a BED file from cache, or downloads and caches it if it doesn't exist.

Args: bed_id (str): unique identifier of a BED file

Returns: RegionSet: the RegionSet object

def add_bedset_to_cache(bedset: BedSet) -> str

Add a BED set to the cache.

Args: bedset (BedSet): the BED set to be added, a BedSet class

Returns: str: the identifier if the BedSet object

def add_bed_to_cache(bedfile: Union[RegionSet, str], force: bool = False) -> RegionSet

Add a BED file to the cache.

Args: bedfile (Union[RegionSet, str]): a RegionSet object or a path or url to the BED file force (bool): whether to overwrite the existing file in cache

Returns: RegionSet: the RegionSet identifier

def add_bed_tokens_to_cache(bed_id: str, universe_id: str) -> None

Add a tokenized BED file to the cache.

Args: bed_id (str): the identifier of the BED file universe_id (str): the identifier of the universe

Returns: str: the identifier of the tokenized BED file

def load_bed_tokens(bed_id: str, universe_id: str) -> Array

Load a tokenized BED file from cache, or download and cache it if it doesn't exist.

Args: bed_id (str): the identifier of the BED file universe_id (str): the identifier of the universe

Returns: Array: the zarr array of tokens

def remove_tokens(bed_id: str, universe_id: str) -> None

Remove all tokenized BED files from cache

def cache_tokens(bed_id: str, universe_id: str, tokens: Union[list, Array]) -> None

Cache tokenized BED file.

Args: bed_id (str): the identifier of the BED file universe_id (str): the identifier of the universe tokens (Union[list, Array]): the list of tokens

def add_bed_to_s3(identifier: str, bucket: str = DEFAULT_BUCKET_NAME, endpoint_url: str = None, aws_access_key_id: str = None, aws_secret_access_key: str = None, s3_path: str = DEFAULT_BUCKET_FOLDER) -> str

Add a cached BED file to S3.

Args: identifier (str): the unique identifier of the BED file bucket (str): the name of the bucket endpoint_url (str): the URL of the S3 endpoint [Default: set up by the environment vars] aws_access_key_id (str): the access key of the AWS account [Default: set up by the environment vars] aws_secret_access_key (str): the secret access key of the AWS account [Default: set up by the environment vars] s3_path (str): the path on S3

Returns: str: full path on S3

def get_bed_from_s3(identifier: str, bucket: str = DEFAULT_BUCKET_NAME, endpoint_url: str = None, aws_access_key_id: str = None, aws_secret_access_key: str = None, s3_path: str = DEFAULT_BUCKET_FOLDER) -> str

Get a cached BED file from S3 and cache it locally.

Args: identifier (str): the unique identifier of the BED file bucket (str): the name of the bucket endpoint_url (str): the URL of the S3 endpoint [Default: set up by the environment vars] aws_access_key_id (str): the access key of the AWS account [Default: set up by the environment vars] aws_secret_access_key (str): the secret access key of the AWS account [Default: set up by the environment vars] s3_path (str): the path on S3

Returns: str: bed file id

Raises: FileNotFoundError: if the identifier does not exist in cache

def seek(identifier: str) -> str

Get local path to BED file or BED set with specific identifier.

Args: identifier (str): the unique identifier

Returns: str: the local path of the file

Raises: FileNotFoundError: if the identifier does not exist in cache

def remove_bedset_from_cache(bedset_id: str, remove_bed_files: bool = False) -> NoReturn

Remove a BED set from cache.

Args: bedset_id (str): the identifier of BED set remove_bed_files (bool): whether also remove BED files in the BED set

Raises: FileNotFoundError: if the BED set does not exist in cache

def list_beds() -> Dict[str, str]

List all BED files in cache.

Returns: Dict[str, str]: the list of identifiers of BED files

def list_bedsets() -> Dict[str, str]

List all BED sets in cache.

Returns: Dict[str, str]: the list of identifiers of BED sets

def remove_bedfile_from_cache(bedfile_id: str) -> NoReturn

Remove a BED file from cache.

Args: bedfile_id (str): the identifier of BED file

Raises: FileNotFoundError: if the BED set does not exist in cache