Skip to content

Commit

Permalink
simplified log odds ratio calculation cases and implementation to imp…
Browse files Browse the repository at this point in the history
…rove readability
  • Loading branch information
ashuaibi7 committed Nov 22, 2024
1 parent 62152d0 commit 74d6398
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/dialect/models/gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,12 @@ def compute_log_odds_ratio(self):
"""
if not self.pi:
raise ValueError("Pi has not been esitmated for this gene.")
if self.pi < 0 or self.pi > 1:
logging.warning(f"Invalid pi value: {self.pi}.")
raise ValueError(
"Estimated pi must be between 0 and 1, inclusive."
) # TODO: move this error to EM method
if self.pi == 0:
logging.info(f"Pi for gene {self.name} is 0")
log_odds_ratio = -np.inf
elif self.pi == 1:
logging.info(f"Pi for gene {self.name} is 1")
log_odds_ratio = np.inf
else:
log_odds_ratio = np.log(self.pi / (1 - self.pi))
if not 0 <= self.pi <= 1:
logging.info(f"Pi value out of bounds: {self.pi}")
raise ValueError("Estimated pi is out of bounds.")
if self.pi == 0 or self.pi == 1:
logging.info(f"Pi for gene {self.name} is 0 or 1")
return np.inf if self.pi else -np.inf

log_odds_ratio = np.log(self.pi / (1 - self.pi))
return log_odds_ratio
# raise NotImplementedError("Log odds ratio computation is not yet implemented.")

0 comments on commit 74d6398

Please sign in to comment.