@@ -156,3 +156,51 @@ def get_n_leafs(idx, children):
156156 else :
157157 return sum ([get_n_leafs (child , children )
158158 for child in children [idx ]])
159+
160+
161+
162+ def expand_boundary_positions (boundary_positions , offsets = [0 ]):
163+ """
164+ Expand boundary_positions by offsets.
165+
166+ Args:
167+ boundary_positions : np.array
168+ List of boundary locations.
169+ offsets : np.array (optional)
170+ List of window sizes. Defaults to [0], the positon of the boundaries.
171+ For symmetric windows around boundaries, use np.arange(-window_size, (window_size) + 1)
172+
173+ Returns:
174+ np.ndarray: Array containing peak positions.
175+ """
176+ expanded_positions = np .array ([])
177+
178+ for offset in offsets :
179+ inds_to_add = [boundary + offset for boundary in boundary_positions ]
180+ expanded_positions = np .hstack ((expanded_positions , inds_to_add ))
181+
182+ return expanded_positions .astype (int )
183+
184+
185+
186+
187+ def FRiP (number_of_sites , lef_positions , boundary_positions ):
188+ """
189+ Calculate the Fraction of Reads in Peaks (FRiP).
190+
191+ FRiP is calculated as the sum of reads falling into peak positions
192+ divided by the total number of LEF positions.
193+
194+ Args:
195+ number_of_sites (int): The total number of sites.
196+ extruders_positions (list): List of LEF positions.
197+ peak_positions (list): List of peak positions.
198+
199+ Returns:
200+ float: The Fraction of Reads in Peaks (FRiP).
201+ """
202+
203+ hist , bin_edges = np .histogram (lef_positions , np .arange (number_of_sites + 1 ))
204+ return np .sum (hist [boundary_positions ]) / len (lef_positions )
205+
206+
0 commit comments