# BBClient Module

<a id="geniml.bbclient"></a>

<a id="geniml.bbclient.BBClient"></a>

## `BBClient`

```python
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

### Attributes

- <a id="geniml.bbclient.BBClient.zarr_cache"></a>**`zarr_cache`**
- <a id="geniml.bbclient.BBClient.bedbase_api"></a>**`bedbase_api`**

### Methods

<a id="geniml.bbclient.BBClient.load_bedset"></a>

#### `load_bedset`

```python
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

<a id="geniml.bbclient.BBClient.load_bed"></a>

#### `load_bed`

```python
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

<a id="geniml.bbclient.BBClient.add_bedset_to_cache"></a>

#### `add_bedset_to_cache`

```python
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

<a id="geniml.bbclient.BBClient.add_bed_to_cache"></a>

#### `add_bed_to_cache`

```python
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

<a id="geniml.bbclient.BBClient.add_bed_tokens_to_cache"></a>

#### `add_bed_tokens_to_cache`

```python
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

<a id="geniml.bbclient.BBClient.load_bed_tokens"></a>

#### `load_bed_tokens`

```python
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

<a id="geniml.bbclient.BBClient.remove_tokens"></a>

#### `remove_tokens`

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

Remove all tokenized BED files from cache

<a id="geniml.bbclient.BBClient.cache_tokens"></a>

#### `cache_tokens`

```python
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

<a id="geniml.bbclient.BBClient.add_bed_to_s3"></a>

#### `add_bed_to_s3`

```python
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

<a id="geniml.bbclient.BBClient.get_bed_from_s3"></a>

#### `get_bed_from_s3`

```python
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

<a id="geniml.bbclient.BBClient.seek"></a>

#### `seek`

```python
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

<a id="geniml.bbclient.BBClient.remove_bedset_from_cache"></a>

#### `remove_bedset_from_cache`

```python
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

<a id="geniml.bbclient.BBClient.list_beds"></a>

#### `list_beds`

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

List all BED files in cache.

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

<a id="geniml.bbclient.BBClient.list_bedsets"></a>

#### `list_bedsets`

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

List all BED sets in cache.

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

<a id="geniml.bbclient.BBClient.remove_bedfile_from_cache"></a>

#### `remove_bedfile_from_cache`

```python
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
