Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/mpralib/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
pd.options.mode.copy_on_write = True


def _safe_sigmoid(x: float) -> float:
"""Compute sigmoid while safely handling extreme values."""
try:
return math.exp(x) / (1 + math.exp(x))
except OverflowError:
return 1.0 if x > 0 else 0.0


@click.group(help="Command line interface of MPRAlib, a library for MPRA data analysis.")
def cli() -> None:
pass
Expand Down Expand Up @@ -993,7 +1001,7 @@ def get_reporter_variants(
},
inplace=True,
)
df["postProbEffect"] = df["B"].apply(lambda x: math.exp(x) / (1 + math.exp(x)))
df["postProbEffect"] = df["B"].apply(_safe_sigmoid)
df["variant_id"] = df.index

def _extract_allele_or_zero(variant_id, idx):
Expand Down Expand Up @@ -1270,7 +1278,7 @@ def get_reporter_genomic_variants(
},
inplace=True,
)
df["postProbEffect"] = df["B"].apply(lambda x: math.exp(x) / (1 + math.exp(x)))
df["postProbEffect"] = df["B"].apply(_safe_sigmoid)
df["variant_id"] = df.index

def _extract_allele_or_zero(variant_id, idx):
Expand Down
Loading