Skip to content

Commit e124676

Browse files
committed
added missing search module
1 parent 606e240 commit e124676

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pyensembl/search.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Helper functions for searching over collections of PyEnsembl objects
3+
"""
4+
5+
def find_nearest_locus(start, end, loci):
6+
"""
7+
Finds nearest locus (object with method `distance_to_interval`) to the
8+
interval defined by the given `start` and `end` positions.
9+
Returns the distance to that locus, along with the locus object itself.
10+
"""
11+
best_distance = float("inf")
12+
best_locus = None
13+
for locus in loci:
14+
distance = locus.distance_to_interval(start, end)
15+
16+
if best_distance > distance:
17+
best_distance = distance
18+
best_locus = locus
19+
20+
return best_distance, best_locus

0 commit comments

Comments
 (0)