# I/O Module

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

<a id="geniml.io.BedSet"></a>

## `BedSet`

```python
class BedSet(region_sets: Union[List[RegionSet], List[str], List[List[Region]], None] = None, file_path: str = None, identifier: str = None)
```

BedSet object

Initialize a BedSet object.

Args:
    region_sets: list of BED file paths, RegionSet, or 2-dimension list of Region. Defaults to None (empty BedSet).
    file_path (str): path to the .txt file with identifier of all BED files in it
    identifier (str): the identifier of the BED set

### Attributes

- <a id="geniml.io.BedSet.region_sets"></a>**`region_sets`**

### Properties

<a id="geniml.io.BedSet.identifier"></a>

#### `identifier`

```python
@property
def identifier -> str
```

### Methods

<a id="geniml.io.BedSet.add"></a>

#### `add`

```python
def add(bedfile: RegionSet) -> NoReturn
```

Add a BED file to the BED set.

Warning: if new bedfile will be added, bedSet identifier will be changed!

Args:
    bedfile (RegionSet): RegionSet instance, that should be added to the bedSet

<a id="geniml.io.BedSet.compute_bedset_identifier"></a>

#### `compute_bedset_identifier`

```python
def compute_bedset_identifier() -> str
```

Return the identifier. If it is not set, compute one.

Returns:
    str: the identifier of BED set

<a id="geniml.io.RegionSet"></a>

## `RegionSet`

```python
class RegionSet(regions: Union[str, List[Region]], backed: bool = False)
```

Instantiate a RegionSet object. This can be backed or not backed. It represents a set of genomic regions.

If you specify `backed` as True, then the bed file will not be loaded into memory. This is useful for large
bed files. You can still iterate over the regions, but you cannot index into them.

Args:
    regions: path, or url to bed file or list of Region objects
    backed (bool): whether to load the bed file into memory or not. Defaults to False.

### Attributes

- <a id="geniml.io.RegionSet.backed"></a>**`backed`**
- <a id="geniml.io.RegionSet.regions"></a>**`regions`** (*List[[Region](#geniml.io.Region)]*)
- <a id="geniml.io.RegionSet.path"></a>**`path`**
- <a id="geniml.io.RegionSet.is_gzipped"></a>**`is_gzipped`**
- <a id="geniml.io.RegionSet.length"></a>**`length`**

### Properties

<a id="geniml.io.RegionSet.identifier"></a>

#### `identifier`

```python
@property
def identifier -> str
```

### Methods

<a id="geniml.io.RegionSet.to_pandas"></a>

#### `to_pandas`

```python
def to_pandas() -> Union[pd.DataFrame, None]
```

<a id="geniml.io.RegionSet.to_granges"></a>

#### `to_granges`

```python
def to_granges()
```

Return GenomicRanges contained in this BED file.

Returns:
    genomicranges.GenomicRanges: GenomicRanges object

<a id="geniml.io.RegionSet.compute_bed_identifier"></a>

#### `compute_bed_identifier`

```python
def compute_bed_identifier() -> str
```

Return bed file identifier. If it is not set, compute one.

Returns:
    str: the identifier of BED file

<a id="geniml.io.Region"></a>

## `Region`

```python
class Region(chr: str, start: int, stop: int)
```

Instantiate a Region object.

Args:
    chr (str): chromosome
    start (int): start position
    stop (int): stop position

### Attributes

- <a id="geniml.io.Region.chr"></a>**`chr`**
- <a id="geniml.io.Region.start"></a>**`start`**
- <a id="geniml.io.Region.end"></a>**`end`**
