Skip to Content
Python APIHicHiCMatrixGenerator

HiCMatrixGenerator

class chr3d.HiCMatrixGenerator( chrom_sizes: str, assembly: str = 'hg38', threads: int = 1, )

Contact matrix generation using cooler.

Creates .cool and multi-resolution .mcool files from pairs.

Parameters

ParameterTypeDescription
chrom_sizesstrPath to chromosome sizes file
assemblystrGenome assembly name (default: 'hg38')
threadsintNumber of threads (default: 1)

Methods

create

def create( self, input_pairs: str, output_cool: str, resolution: int = 1000, ) -> Dict[str, Any]

Create contact matrix from pairs.

Parameters:

ParameterTypeDescription
input_pairsstrPath to filtered pairs file
output_coolstrPath to output .cool file
resolutionintMatrix resolution in bp (default: 1000)

Returns:

Dict[str, Any] with keys:

  • 'output_cool': Path to output .cool file
  • 'cool_size_bytes': Size of cool file
  • 'resolution': Matrix resolution
  • 'num_contacts': Number of contacts

balance

def balance( self, input_cool: str, max_iters: int = 200, cis_only: bool = True, ) -> Dict[str, Any]

Balance contact matrix.

Parameters:

ParameterTypeDescription
input_coolstrPath to .cool file
max_itersintMaximum iterations (default: 200)
cis_onlyboolOnly balance cis contacts (default: True)

zoomify

def zoomify( self, input_cool: str, output_mcool: str, resolutions: List[int] = None, ) -> Dict[str, Any]

Create multi-resolution .mcool file.

Parameters:

ParameterTypeDescription
input_coolstrPath to .cool file
output_mcoolstrPath to output .mcool file
resolutionsList[int]List of resolutions in bp (default: [1000, 5000, 10000, 25000, 50000, 100000])

Example:

import chr3d as c3d matrix = c3d.HiCMatrixGenerator( chrom_sizes="/data/genomes/hg38.chrom.sizes", assembly="hg38", threads=24 ) # Create contact matrix stats = matrix.create( input_pairs="filtered.pairs.gz", output_cool="sample.cool" ) # Create multi-resolution matrix matrix.zoomify( input_cool="sample.cool", output_mcool="sample.mcool", resolutions=[1000, 5000, 10000, 25000, 50000, 100000] )
Last updated on