Skip to content

Commit

Permalink
closes 25 add proper error message when input does not overlap with d…
Browse files Browse the repository at this point in the history
…atabase.
  • Loading branch information
SeppeDeWinter committed Oct 2, 2023
1 parent 16d14b9 commit d50c6f4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/pycistarget/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,14 @@ def target_to_query(target: Union[pr.PyRanges, List[str]],
query_pr=query

join_pr = target_pr.join(query_pr, report_overlap = True)
if len(join_pr) == 0:

This comment has been minimized.

Copy link
@ghuls

ghuls Oct 4, 2023

Member

It is probably better to use: if join_pr.empty:

In [18]: a1 = pr.PyRanges(chromosomes="chr1", starts=(1, 5), ends=[3, 149], strands=("+", "-"), int64=True)

In [19]: a2 = pr.PyRanges(chromosomes="chr1", starts=(1001, 1005), ends=[1003, 1149], strands=("+", "-"), int64=True)

In [20]: j = a1.join(a2)

In [21]: j
Out[21]: Empty PyRanges

In [22]: j.empty
Out[22]: True

In [23]: a1.empty
Out[23]: False
raise ValueError(
"""
None of the regions in the bed file overlap with the cistarget database.
Check wether the chromosome names of the input regions are correctly

This comment has been minimized.

Copy link
@casblaauw

casblaauw Oct 6, 2023

Very small typo, but this should be 'whether' ;)

formatted and that you are using the correct database.
"""
)
join_pr.Overlap_query = join_pr.Overlap/(join_pr.End_b - join_pr.Start_b)
join_pr.Overlap_target = join_pr.Overlap/(join_pr.End - join_pr.Start)
join_pr = join_pr[(join_pr.Overlap_query > fraction_overlap) | (join_pr.Overlap_target > fraction_overlap)]
Expand Down

0 comments on commit d50c6f4

Please sign in to comment.