Skip to content

Commit

Permalink
fix(annotation): Added a catch for no-overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
alsmith151 committed Nov 4, 2023
1 parent 51cb77b commit 25c4844
Showing 1 changed file with 28 additions and 14 deletions.
42 changes: 28 additions & 14 deletions capcruncher/api/annotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ def intersection(self) -> pr.PyRanges:
gr_a = pr.PyRanges(self.a.df.drop(columns="Name").assign(Name=lambda df: df.reset_index().index))

df_overlapping = gr_a.join(self.b, nb_cpu=self.n_cores, report_overlap=True).df
df_non_overlapping = gr_a.df.loc[lambda df: df.Name.isin(df_overlapping.Name.unique()) == False]

if not df_overlapping.empty:
df_non_overlapping = gr_a.df.loc[lambda df: df.Name.isin(df_overlapping.Name.unique()) == False]
else:
raise ValueError("No overlapping regions found")


df_both = pd.concat([df_overlapping, df_non_overlapping]).sort_values("Name")

df_both['Name'] = df_both['Name'].map(name_col)
Expand Down Expand Up @@ -200,19 +206,27 @@ def __init__(
self.n_cores = max_cores if self.b.df.shape[0] > 50_000 else 1

def get_intersection(self, method: Literal["get", "count"] = "get") -> pr.PyRanges:
if self.b.empty:
_intersection = IntersectionFailed(
self.a, self.b, self.name, self.fraction, self.n_cores
).intersection
elif method == "get":
_intersection = IntersectionGet(
self.a, self.b, self.name, self.fraction, self.n_cores
).intersection
elif method == "count":
_intersection = IntersectionCount(
self.a, self.b, self.name, self.fraction, self.n_cores
).intersection
else:

try:

if self.b.empty:
_intersection = IntersectionFailed(
self.a, self.b, self.name, self.fraction, self.n_cores
).intersection
elif method == "get":
_intersection = IntersectionGet(
self.a, self.b, self.name, self.fraction, self.n_cores
).intersection
elif method == "count":
_intersection = IntersectionCount(
self.a, self.b, self.name, self.fraction, self.n_cores
).intersection
else:
_intersection = IntersectionFailed(

Check warning on line 225 in capcruncher/api/annotate.py

View check run for this annotation

Codecov / codecov/patch

capcruncher/api/annotate.py#L225

Added line #L225 was not covered by tests
self.a, self.b, self.name, self.fraction, self.n_cores
).intersection

except (OSError, IndexError, FileNotFoundError, StopIteration, AssertionError, ValueError):
_intersection = IntersectionFailed(
self.a, self.b, self.name, self.fraction, self.n_cores
).intersection
Expand Down

0 comments on commit 25c4844

Please sign in to comment.