Skip to content

Commit

Permalink
remove intersect_posi
Browse files Browse the repository at this point in the history
  • Loading branch information
chaochungkuo committed Feb 20, 2024
1 parent a1c66e5 commit d2ab326
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 49 deletions.
43 changes: 0 additions & 43 deletions genomkit/regions/gregions.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,49 +598,6 @@ def make_array_same_length(array_1, array_2):
name=""))
return res

def intersect_posi(self, target, strandness: bool = False):
def generate_position_array(position_set, merged_list):
boolean_array = [False] * len(merged_list)
# Set elements to True according to pos_1
for i, element in enumerate(merged_list):
if element in position_set:
boolean_array[i] = True
return np.array(boolean_array)

def find_intersects(orientation):
pos_1 = self.get_positions_by_seq(sequence=seq,
orientation=orientation)
pos_2 = target.get_positions_by_seq(sequence=seq,
orientation=orientation)
merged_pos = list(pos_1.union(pos_2))
array_1 = generate_position_array(pos_1, merged_pos)
array_2 = generate_position_array(pos_2, merged_pos)
result_array = array_1 & array_2
# Find the indices where the value changes
indices = np.where(np.diff(result_array))[0] + 1
# Group consecutive indices into tuples
ranges = [(merged_pos[indices[i - 1]],
merged_pos[indices[i]])
for i in range(1, len(indices), 2)]
return ranges

res = GRegions()
list_seq_self = self.get_sequences(unique=True)
list_seq_target = target.get_sequences(unique=True)
common_seq = [seq for seq in list_seq_self if seq in list_seq_target]
for seq in common_seq:
if strandness:
# positive
ranges_pos = find_intersects(orientation="+")
ranges_neg = find_intersects(orientation="-")
ranges = ranges_pos + ranges_neg
else:
ranges = find_intersects(orientation=None)
for pair in ranges:
res.add(GRegion(sequence=seq, start=pair[0], end=pair[1],
name=""))
return res

def overlap_count(self, target):
intersect = self.intersect_python(target, mode="ORIGINAL")
return len(intersect)
Expand Down
6 changes: 0 additions & 6 deletions tests/evaluate/evaluate_intersect.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,11 @@ def time_intersect_python():
def time_intersect_array():
intersect = peaks.intersect_array(genes)

@profile
def time_intersect_posi():
intersect = peaks.intersect_posi(genes)

repeat_num = 2
execution_time = timeit.timeit(time_intersect_python, number=repeat_num)
print('[{:<20}]'.format('intersect_python'), '{:<5.2f}'.format(execution_time), "seconds")
execution_time = timeit.timeit(time_intersect_array, number=repeat_num)
print('[{:<20}]'.format('intersect_array'), '{:<5.2f}'.format(execution_time), "seconds")
execution_time = timeit.timeit(time_intersect_posi, number=repeat_num)
print('[{:<20}]'.format('intersect_posi'), '{:<5.2f}'.format(execution_time), "seconds")
# print(len(intersect))
# intersect.write("intersect_python.bed")
# print(len(intersect))
Expand Down

0 comments on commit d2ab326

Please sign in to comment.