-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from hammerlab/search_over_loci
Search over loci
- Loading branch information
Showing
6 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
""" | ||
Helper functions for searching over collections of PyEnsembl objects | ||
""" | ||
|
||
def find_nearest_locus(start, end, loci): | ||
""" | ||
Finds nearest locus (object with method `distance_to_interval`) to the | ||
interval defined by the given `start` and `end` positions. | ||
Returns the distance to that locus, along with the locus object itself. | ||
""" | ||
best_distance = float("inf") | ||
best_locus = None | ||
for locus in loci: | ||
distance = locus.distance_to_interval(start, end) | ||
|
||
if best_distance > distance: | ||
best_distance = distance | ||
best_locus = locus | ||
|
||
return best_distance, best_locus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from test_common import test_ensembl_releases | ||
from pyensembl import EnsemblRelease, find_nearest_locus | ||
from nose.tools import eq_ | ||
|
||
@test_ensembl_releases | ||
def test_find_nearest_BRAF_exon(ensembl): | ||
braf = ensembl.genes_by_name("BRAF")[0] | ||
braf_transcripts = braf.transcripts | ||
for exon in braf_transcripts[0].exons: | ||
# immediately before exon | ||
result = find_nearest_locus( | ||
start=exon.start-2, | ||
end=exon.end-1, | ||
loci=exons) | ||
eq_(result, (1, exon)) | ||
|
||
# overlapping with exon | ||
result = find_nearest_locus( | ||
start=exon.start-2, | ||
end=exon.start+1, | ||
loci=exons) | ||
eq_(result, (0, exon)) | ||
|
||
# immediately after exon | ||
result = find_nearest_locus( | ||
start=exon.end+1, | ||
end=exon.end+2, | ||
loci=exons) | ||
eq_(result, (1, exon)) | ||
|
||
@test_ensembl_releases | ||
def test_find_nearest_BRAF_transcript(ensembl): | ||
braf = ensembl.genes_by_name("BRAF")[0] | ||
braf_transcripts = braf.transcripts | ||
for transcript in braf_transcripts: | ||
# immediately before transcript | ||
result = find_nearest_locus( | ||
start=transcript.start-2, | ||
end=transcript.end-1, | ||
loci=braf_transcripts) | ||
eq_(result, (1, transcript)) | ||
|
||
# overlapping with transcript | ||
result = find_nearest_locus( | ||
start=transcript.start-2, | ||
end=transcript.start+1, | ||
exons=braf_transcripts) | ||
eq_(result, (0, transcript)) | ||
|
||
# immediately after transcript | ||
result = find_nearest_locus( | ||
start=transcript.end+1, | ||
end=transcript.end+2, | ||
exons=braf_transcripts) | ||
eq_(result, (1, transcript)) |