gunz_cm package
Subpackages
- gunz_cm.cli package
- gunz_cm.converters package
- gunz_cm.datasets package
- gunz_cm.io package
- gunz_cm.loaders package
- Submodules
- gunz_cm.loaders.cool_loader module
- gunz_cm.loaders.csv_loader module
- gunz_cm.loaders.ginteractions_loader module
- gunz_cm.loaders.hic_loader module
- gunz_cm.loaders.memmap_loader module
- gunz_cm.loaders.narrowpeaks module
- gunz_cm.loaders.pickle_loader module
- gunz_cm.loaders.utils module
- Module contents
- gunz_cm.metrics package
- gunz_cm.pipeline package
- gunz_cm.preprocs package
- Submodules
- gunz_cm.preprocs.band_matrix module
- gunz_cm.preprocs.commons module
- gunz_cm.preprocs.converters module
- gunz_cm.preprocs.count_filters module
- gunz_cm.preprocs.graphs module
- gunz_cm.preprocs.infer_shape module
- gunz_cm.preprocs.linear_scaler module
- gunz_cm.preprocs.log_scaler module
- gunz_cm.preprocs.masks module
- gunz_cm.preprocs.mirrors module
- gunz_cm.preprocs.noises module
- gunz_cm.preprocs.rc_filters module
- gunz_cm.preprocs.rc_filters_common module
- gunz_cm.preprocs.resamples module
- gunz_cm.preprocs.sparse_wish_dist module
- gunz_cm.preprocs.triu_matrix module
- gunz_cm.preprocs.weight_filters module
- Module contents
- gunz_cm.reconstructions package
- gunz_cm.resolution_enhancements package
- gunz_cm.samplers package
- gunz_cm.structs package
- gunz_cm.utils package
Submodules
gunz_cm.consts module
Defines shared constants, enumerations, and data structures for the library.
This module centralizes common values used throughout the application, including DataFrame column names, data types, supported file formats, and standard genomic build information. Using this module ensures consistency and simplifies maintenance.
Examples
- class gunz_cm.consts.Backend(value)[source]
Bases:
BaseStrEnumEnumeration for interaction matrix loader backends.
Examples
- COOLER = 'cooler'
- HICSTRAW = 'hicstraw'
- HICTK = 'hictk'
- STRAW = 'straw'
- class gunz_cm.consts.Balancing(value)[source]
Bases:
BaseStrEnumEnumeration for matrix balancing (normalization) methods.
Examples
- KR = 'KR'
- NONE = 'NONE'
- VC = 'VC'
- VC_SQRT = 'VC_SQRT'
- class gunz_cm.consts.BpFrag(value)[source]
Bases:
BaseStrEnumEnumeration for binning units (Base Pairs vs. Fragments).
Examples
- BP = 'BP'
- FRAG = 'FRAG'
- class gunz_cm.consts.Counts(value)[source]
Bases:
BaseStrEnumEnumeration for different types of interaction counts.
Examples
- EXPECTED = 'expected'
- OBSERVED = 'observed'
- OE = 'oe'
- gunz_cm.consts.DS
alias of
DataStructure
- class gunz_cm.consts.DataStructure(value)[source]
Bases:
BaseStrEnumEnumeration for in-memory data representations.
Examples
- COO = 'coo'
- DF = 'df'
- RC = 'rc'
- RCV = 'rcv'
- class gunz_cm.consts.Format(value)[source]
Bases:
BaseStrEnumEnumeration for supported file formats.
Uses BaseStrEnum for case-insensitivity and aliases.
Examples
- COO = 'coo'
- COOLER = 'cooler'
- CSV = 'csv'
- GINTERACTIONS = 'ginteractions'
- HIC = 'hic'
- MCOO = 'mcoo'
- MCSV = 'mcsv'
- MEMMAP = 'npdat'
- NPY = 'npy'
- PICKLE = 'pickle'
- TSV = 'tsv'
gunz_cm.exceptions module
Custom exception classes for the gunz_cm package.
- exception gunz_cm.exceptions.ConversionFailedError(region: str, message: str = 'Conversion failed')[source]
Bases:
ConverterErrorException raised when a conversion process fails.
- exception gunz_cm.exceptions.ConverterError[source]
Bases:
GunzCMErrorBase class for exceptions in the converters module.
- exception gunz_cm.exceptions.DataResolutionError[source]
Bases:
LoaderErrorException raised when there’s an issue with data resolution.
- exception gunz_cm.exceptions.DatasetError[source]
Bases:
GunzCMErrorBase class for exceptions in the datasets module.
- exception gunz_cm.exceptions.FormatError[source]
Bases:
LoaderErrorException raised for format-related errors.
- exception gunz_cm.exceptions.GunzCMError[source]
Bases:
ExceptionBase class for all custom exceptions in the gunz_cm package.
Examples
>>> try: ... raise GunzCMError("A matrix error occurred") ... except GunzCMError as e: ... print(e) A matrix error occurred
- exception gunz_cm.exceptions.IOError[source]
Bases:
GunzCMErrorBase class for exceptions related to input/output operations.
- exception gunz_cm.exceptions.InvalidRegionFormatError(region: str, message: str = 'Invalid region format')[source]
Bases:
LoaderErrorException raised for errors in the input region format.
- exception gunz_cm.exceptions.LoaderError[source]
Bases:
GunzCMErrorBase class for exceptions in the loaders module.
- exception gunz_cm.exceptions.MetricError[source]
Bases:
GunzCMErrorBase class for exceptions in the metrics module.
- exception gunz_cm.exceptions.PreprocError[source]
Bases:
GunzCMErrorBase class for exceptions in the preprocs module.
- exception gunz_cm.exceptions.ReconstructionError[source]
Bases:
GunzCMErrorBase class for exceptions in the reconstructions module.
- exception gunz_cm.exceptions.UnsupportedLoaderFeatureError(feature: str, loader_name: str)[source]
Bases:
LoaderErrorException raised when a loader does not support a requested feature.
gunz_cm.matrix module
Defines the ContactMatrix data structure.
- class gunz_cm.matrix.ContactMatrix(chromosome1: str, resolution: int, loader_func: Callable, loader_kwargs: Dict[str, ~typing.Any]=<factory>, chromosome2: str | None = None, metadata: Dict[str, ~typing.Any]=<factory>)[source]
Bases:
objectA data container for a contact matrix and its associated metadata.
This class acts as a simple, data-oriented container to group a contact matrix (as a pandas DataFrame or a SciPy sparse matrix) with important metadata like its genomic coordinates and resolution. It supports lazy loading of data via a loader function.
- loader_func
A function or callable that returns the raw data when called.
- Type:
callable
- chromosome2
The name of the second chromosome, if different from the first (for inter-chromosomal matrices). Defaults to chromosome1.
- Type:
str, optional
Examples
>>> from gunz_cm.matrix import ContactMatrix >>> import numpy as np >>> def dummy_loader(n): return np.eye(n) >>> cm = ContactMatrix("chr1", 10000, loader_func=dummy_loader, loader_kwargs={"n": 5}) >>> print(cm.data.shape) (5, 5)
- as_coo() coo_matrix[source]
Returns the contact matrix as a SciPy COO sparse matrix.
- Returns:
The contact matrix data in COO format.
- Return type:
scipy.sparse.coo_matrix
Examples
>>> cm = load_cm_data("sample.cool", "chr1", 10000) >>> coo = cm.as_coo() >>> print(f"Non-zero elements: {coo.nnz}")
- as_csc() csc_matrix[source]
Returns the contact matrix as a SciPy CSC sparse matrix.
- Returns:
The contact matrix data in CSC format.
- Return type:
scipy.sparse.csc_matrix
- as_csr() csr_matrix[source]
Returns the contact matrix as a SciPy CSR sparse matrix.
- Returns:
The contact matrix data in CSR format.
- Return type:
scipy.sparse.csr_matrix
- as_dataframe() DataFrame[source]
Returns the contact matrix as a pandas DataFrame.
- Returns:
The contact matrix data as a DataFrame with bin IDs and counts.
- Return type:
Examples
>>> df = cm.as_dataframe() >>> print(df.columns) Index(['bin1_id', 'bin2_id', 'count'], dtype='object')