lib5c.algorithms.filtering.fragment_fragment_filtering module¶
Module for smoothing fragment-level 5C interaction matrices.
-
lib5c.algorithms.filtering.fragment_fragment_filtering.
find_nearby_fragments
(index, regional_primermap, threshold, midpoint=False)[source]¶ Finds the fragments near a target fragment as specified by an index.
- Parameters
index (int) – The index of the bin to look near.
regional_primermap (List[Dict[str, Any]]) – The list of fragments in this region.
threshold (int) – The threshold for deciding if a fragment is “nearby” or not, as a distance in base pairs.
midpoint (bool) – Pass True to restore legacy behavior when distances to fragments were based on their midpoints. The new behavior (with this kwarg set to False) is to compute distances to fragments based on their closest endpoint.
- Returns
A list of nearby fragments, where each nearby bin is represented as a dict of the following form:
{ 'index': int, 'distance': int }
where ‘index’ is the index of the fragment within the region and ‘distance’ is the distance between this fragment and the target fragment.
- Return type
List[Dict[str, int]]
-
lib5c.algorithms.filtering.fragment_fragment_filtering.
fragment_fragment_filter
(array, filter_function, regional_primermap, threshold, filter_kwargs=None, midpoint=False)[source]¶ Convenience function for filtering a fragment-level matrix to a fragment-level matrix.
- Parameters
array (np.ndarray) – The matrix to filter.
filter_function (Callable[[List[Dict[str, Any]]], float]) –
The filter function to use when filtering. This function should take in a “neighborhood” and return the filtered value given that neighborhood. A neighborhood is represented as a list of “nearby points” where each nearby point is represented as a dict of the following form:
{ 'value': float, 'x_dist': int, 'y_dist': int }
where ‘value’ is the value at the point and ‘x_dist’ and ‘y_dist’ are its distances from the center of the neighborhood along the x- and y-axis, respectively, in base pairs. See
lib5c.algorithms.filtering.filter_functions
for examples of filter functions and how they can be created.regional_primermap (List[Dict[str, Any]]) – The list of fragments in this region.
threshold (int) – The threshold for defining the size of the neighborhood passed to the filter function, in base pairs.
filter_kwargs (Optional[Dict[str, Any]]) – Kwargs to be passed to the
filter_function
.midpoint (bool) – Pass True to restore legacy behavior when distances to fragments were based on their midpoints. The new behavior (with this kwarg set to False) is to compute distances to fragments based on their closest endpoint.
- Returns
The filtered matrix.
- Return type
np.ndarray
-
lib5c.algorithms.filtering.fragment_fragment_filtering.
fragment_fragment_filter_counts
(counts, function, primermap, threshold, function_kwargs=None, midpoint=False)[source]¶ Non-parallel wrapper for
fragment_fragment_filter()
. Deprecated now thatfragment_fragment_filter()
is decorated with@parallelize_regions
.- Parameters
counts (Dict[str, np.ndarray]) – The counts dict to filter.
function (Callable[[List[Dict[str, Any]]], float]) – The filter function to use for filtering. See the description of the
filter_function
arg infragment_fragment_filter()
.primermap (Dict[str, List[Dict[str, Any]]]) – The primermap describing the fragments for
counts
.threshold (int) – The threshold for defining the size of the neighborhood passed to the filter function, in base pairs.
function_kwargs (Optional[Dict[str, Any]]) – Kwargs to be passed to the
function
.midpoint (bool) – Pass True to restore legacy behavior when distances to fragments were based on their midpoints. The new behavior (with this kwarg set to False) is to compute distances to fragments based on their closest endpoint.
- Returns
The dict of filtered counts.
- Return type
Dict[str, np.ndarray]