hic3defdr.util.matrices module¶
-
hic3defdr.util.matrices.
deconvolute
(matrix, bias, invert=False)[source]¶ Applies bias factors to a sparse matrix.
Parameters: - matrix (scipy.sparse.spmatrix) – The matrix to bias. Will be converted to CSR by this function.
- bias (np.ndarray) – The dense bias vector.
- invert (bool) – Whether or not to invert the bias before applying it. By default this function multiplies the matrix by the bias. Infinite bias (1 / 0) will be converted to zero bias to allow rows with infinite bias to be dropped from the resulting sparse matrix.
Returns: The deconvoluted matrix.
Return type: scipy.sparse.csr_matrix
-
hic3defdr.util.matrices.
dilate
(matrix, doublings)[source]¶ Doubles the “resolution” of a matrix using nearest-neighbor interpolation.
Parameters: - matrix (np.ndarray) – Input matrix.
- doublings (int) – The number of times the resolution will be doubled.
Returns: The dilated matrix.
Return type: np.ndarray
-
hic3defdr.util.matrices.
select_matrix
(row_slice, col_slice, row, col, data, symmetrize=True)[source]¶ Slices out a dense matrix from COO-formatted sparse data, filling empty values with
np.nan
.Parameters: - col_slice (row_slice,) – Row and column slice to use, respectively.
- col, data (row,) – COO-format sparse matrix to be sliced.
- symmetrize (bool) – Pass True to fill in lower-triangle points of the matrix.
Returns: Dense matrix.
Return type: np.ndarray
-
hic3defdr.util.matrices.
sparse_intersection
(fnames, bias=None)[source]¶ Computes the intersection set of (row, col) pairs across multiple sparse matrices.
Parameters: - fnames (list of str) – File paths to sparse matrices loadable by
scipy.sparse.load_npz()
. Will be converted to COO by this function. - bias (np.ndarray, optional) – Pass the bias matrix to drop rows and columns with bias factors of zero in any replicate.
Returns: row, col – The intersection set of (row, col) pairs.
Return type: np.ndarray
- fnames (list of str) – File paths to sparse matrices loadable by
-
hic3defdr.util.matrices.
sparse_union
(fnames, dist_thresh=1000, bias=None, size_factors=None, mean_thresh=0.0)[source]¶ Computes the intersection set of (row, col) pairs across multiple sparse matrices.
Parameters: - fnames (list of str) – File paths to sparse matrices loadable by
scipy.sparse.load_npz()
. Will be converted to COO by this function. - dist_thresh (int) – The maximum distance allowed, respectively, in bin units.
- bias (np.ndarray, optional) – Rectangular matrix containing bias factors for each bin (rows) and each replicate (columns).
- size_factors (np.ndarray, optional) – Size factors for each replicate.
- mean_thresh (float) – Minimum mean value (in normalized space) to keep pixels for.
Returns: row, col – The union set of (row, col) pairs.
Return type: np.ndarray
- fnames (list of str) – File paths to sparse matrices loadable by
-
hic3defdr.util.matrices.
wipe_distances
(matrix, min_dist, max_dist)[source]¶ Eliminates entries from a sparse matrix outside of a specified distance range.
Parameters: - matrix (scipy.sparse.spmatrix) – The matrix to wipe. Will be converted to COO by this function.
- max_dist (min_dist,) – The minimum and maximum distance allowed, respectively, in bin units.
Returns: The wiped matrix.
Return type: scipy.sparse.coo_matrix