Cooler API

class hictkpy.cooler.SingleCellFile(*args, **kwargs)

Class representing a file handle to a .scool file.

__init__(self, path: str | PathLike) None

Open a single-cell Cooler file (.scool).

__getitem__(self, cell_id: str) File

Open the Cooler file corresponding to the cell ID given as input.

__enter__(self) SingleCellFile
__exit__(
self,
exc_type: object | None = None,
exc_value: object | None = None,
traceback: object | None = None,
) None
attributes(self) dict

Get file attributes as a dictionary.

bins(self) BinTable

Get table of bins.

cells(self) list[str]

Get the list of available cells.

chromosomes(self, include_ALL: bool = False) dict[str, int]

Get the chromosome sizes as a dictionary mapping names to sizes.

close(self) None

Manually close the file handle.

path(self) Path

Get the file path.

resolution(self) int

Get the bin size in bp.

class hictkpy.cooler.FileWriter(*args, **kwargs)

Class representing a file handle to create .cool files.

__init__(
self,
path: str | PathLike,
chromosomes: dict[str, int],
resolution: int,
assembly: str = 'unknown',
tmpdir: str | PathLike = PosixPath('/tmp'),
compression_lvl: int = 6,
) None
__init__(
self,
path: str | PathLike,
bins: BinTable,
assembly: str = 'unknown',
tmpdir: str | PathLike = PosixPath('/tmp'),
compression_lvl: int = 6,
) None

Overloaded function.

  1. __init__(self, path: str | os.PathLike, chromosomes: dict[str, int], resolution: int, assembly: str = 'unknown', tmpdir: str | os.PathLike = PosixPath('/tmp'), compression_lvl: int = 6) -> None

Open a .cool file for writing given a list of chromosomes with their sizes and a resolution.

  1. __init__(self, path: str | os.PathLike, bins: hictkpy._hictkpy.BinTable, assembly: str = 'unknown', tmpdir: str | os.PathLike = PosixPath('/tmp'), compression_lvl: int = 6) -> None

Open a .cool file for writing given a table of bins.

__enter__(self) FileWriter
__exit__(
self,
exc_type: object | None = None,
exc_value: object | None = None,
traceback: object | None = None,
) None
add_pixels(
self,
pixels: DataFrame | Table,
sorted: bool = False,
validate: bool = True,
) None

Add pixels from a pandas.DataFrame or pyarrow.Table containing pixels in COO or BG2 format (i.e. either with columns=[bin1_id, bin2_id, count] or with columns=[chrom1, start1, end1, chrom2, start2, end2, count]). When sorted is True, pixels are assumed to be sorted by their genomic coordinates in ascending order. When validate is True, hictkpy will perform some basic sanity checks on the given pixels before adding them to the Cooler file.

add_pixels_from_dict(
self,
columns: Dict[str, Iterable[str | int | float]],
sorted: bool = False,
validate: bool = True,
) None

Add pixels from a dictionary containing containing columns corresponding to pixels in COO or BG2 format (i.e. either with keys=[bin1_id, bin2_id, count] or with keys=[chrom1, start1, end1, chrom2, start2, end2, count]). When sorted is True, pixels are assumed to be sorted by their genomic coordinates in ascending order. When validate is True, hictkpy will perform some basic sanity checks on the given pixels before adding them to the Cooler file.

bins(self) BinTable

Get table of bins.

chromosomes(self, include_ALL: bool = False) dict[str, int]

Get the chromosome sizes as a dictionary mapping names to sizes.

finalize(
self,
log_lvl: str | None = None,
chunk_size: int = 500000,
update_frequency: int = 10000000,
) File

Write interactions to file.

path(self) Path

Get the file path.

resolution(self) int

Get the resolution in bp.