Skip to content

Commit

Permalink
add a tostring method to easily display gene and basic info
Browse files Browse the repository at this point in the history
  • Loading branch information
ashuaibi7 committed Dec 13, 2024
1 parent 2481916 commit a883c74
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/dialect/models/gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,22 @@ def __init__(self, name, counts, bmr_pmf):
self.bmr_pmf = bmr_pmf
self.pi = None

def __str__(self):
"""
Return a string representation of the Gene object.
"""
bmr_preview = ", ".join(
f"{k}: {v:.3e}" for k, v in itertools.islice(self.bmr_pmf.items(), 3)
) # Format the first three key-value pairs in bmr_pmf
pi_info = f"Pi: {self.pi:.3e}" if self.pi is not None else "Pi: Not estimated"
total_mutations = np.sum(self.counts)
return (
f"Gene: {self.name}\n"
f"Total Mutations: {total_mutations}\n"
f"BMR PMF (preview): {{ {bmr_preview} }}\n"
f"{pi_info}"
)

# ---------------------------------------------------------------------------- #
# DATA VALIDATION AND LOGGING #
# ---------------------------------------------------------------------------- #
Expand Down Expand Up @@ -257,14 +273,11 @@ def estimate_pi_with_em_from_scratch(self, max_iter=1000, tol=1e-6, pi_init=0.5)
self.pi = pi
logging.info(f"Estimated pi for gene {self.name}: {self.pi:.4f}")

# TODO: Implement below to increase speed relative to from-scratch EM
# TODO (LOW PRIORITY): Implement EM w/ Pomegranate for Speed Improvement
def estimate_pi_with_em_using_pomegranate(self):
"""
Estimate the pi parameter using the Expectation-Maximization (EM) algorithm.
Uses the Pomegranate library for the EM algorithm.
"""
logging.info(f"Estimating pi for gene {self.name} using the EM algorithm.")
raise NotImplementedError("EM algorithm not implemented yet.")


# TODO: Create to string method for Gene class

0 comments on commit a883c74

Please sign in to comment.