Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow set random seed for reproducibility in CompositionalAnalysis objects #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions sccoda/model/scCODA_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ class scCODAModel(CompositionalModel):
def __init__(
self,
reference_cell_type: int,
seed: Optional[int] = None,
*args,
**kwargs):
"""
Expand Down Expand Up @@ -708,6 +709,9 @@ def target_log_prob_fn(*argsl):
self.target_log_prob_fn = target_log_prob_fn

# MCMC starting values
if seed is not None:
tf.random.set_seed(seed)

self.init_params = [
tf.ones(sigma_size, name="init_sigma_d", dtype=dtype),
tf.random.normal(beta_nobl_size, 0, 1, name='init_b_offset', dtype=dtype),
Expand Down
4 changes: 4 additions & 0 deletions sccoda/util/comp_ana.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def __new__(
formula: str,
reference_cell_type: Union[str, int] = "automatic",
automatic_reference_absence_threshold: float = 0.05,
seed: Optional[int] = None,
) -> dm.scCODAModel:
"""
Builds count and covariate matrix, returns a CompositionalModel object
Expand Down Expand Up @@ -100,6 +101,7 @@ def __new__(
covariate_names=covariate_names,
reference_cell_type=ref_index,
formula=formula,
seed=seed,
)

# Column name as reference cell type
Expand All @@ -112,6 +114,7 @@ def __new__(
covariate_names=covariate_names,
reference_cell_type=num_index,
formula=formula,
seed=seed,
)

# Numeric reference cell type
Expand All @@ -123,6 +126,7 @@ def __new__(
covariate_names=covariate_names,
reference_cell_type=reference_cell_type,
formula=formula,
seed=seed,
)

# None of the above: Throw error
Expand Down