Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding few functions for right and left legs collision #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions looplib/.ipynb_checkpoints/looptools-checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import networkx as nx

import collections
from scipy.spatial import distance

#import pyximport; pyximport.install(
# setup_args={"include_dirs":np.get_include()},
Expand Down Expand Up @@ -294,3 +295,40 @@ def calc_percolation(LEF_array, r=1, tol=.01):

return len(clusters[0]) / float(num_LEFs)


def find_nearby_legs(lefs):
"""
Finds pairs of left and right leg sites with a distance of 1 between them.

Parameters:
lefs (ndarray): A 2D array where the first column contains left leg sites
and the second column contains right leg sites.

Returns:
ndarray: A flattened array of site pairs that have a distance of 1.
"""
l_legs=lefs[:,0]
r_legs = lefs[:,1]
l_legs_2d = l_legs[:, np.newaxis]
r_legs_2d = r_legs[:, np.newaxis]

distances = distance.cdist(r_legs_2d, l_legs_2d)
indices = np.argwhere(distances ==1)
result = [(r_legs[i], l_legs[j]) for i, j in indices]
return np.array(result).flatten()

def collision_at_barriers(lefs, ctcf_list):
"""
Filters collision sites that overlap with specific CTCF sites.

Parameters:
lefs (ndarray): A 2D array where the first column contains left leg sites
and the second column contains right leg sites.
ctcf_list (ndarray): A 1D array of CTCF sites to filter against.

Returns:
ndarray: An array of collision sites that match the provided CTCF sites.
"""
col_sites = find_nearby_legs(lefs)
col_at_ctcf = np.intersect1d(col_sites, ctcf_list)
return col_at_ctcf
38 changes: 38 additions & 0 deletions looplib/looptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import networkx as nx

import collections
from scipy.spatial import distance

#import pyximport; pyximport.install(
# setup_args={"include_dirs":np.get_include()},
Expand Down Expand Up @@ -294,3 +295,40 @@ def calc_percolation(LEF_array, r=1, tol=.01):

return len(clusters[0]) / float(num_LEFs)


def find_nearby_legs(lefs):
"""
Finds pairs of left and right leg sites with a distance of 1 between them.

Parameters:
lefs (ndarray): A 2D array where the first column contains left leg sites
and the second column contains right leg sites.

Returns:
ndarray: A flattened array of site pairs that have a distance of 1.
"""
l_legs=lefs[:,0]
r_legs = lefs[:,1]
l_legs_2d = l_legs[:, np.newaxis]
r_legs_2d = r_legs[:, np.newaxis]

distances = distance.cdist(r_legs_2d, l_legs_2d)
indices = np.argwhere(distances ==1)
result = [(r_legs[i], l_legs[j]) for i, j in indices]
return np.array(result).flatten()

def collision_at_barriers(lefs, ctcf_list):
"""
Filters collision sites that overlap with specific CTCF sites.

Parameters:
lefs (ndarray): A 2D array where the first column contains left leg sites
and the second column contains right leg sites.
ctcf_list (ndarray): A 1D array of CTCF sites to filter against.

Returns:
ndarray: An array of collision sites that match the provided CTCF sites.
"""
col_sites = find_nearby_legs(lefs)
col_at_ctcf = np.intersect1d(col_sites, ctcf_list)
return col_at_ctcf