Skip to content

Commit

Permalink
update for the reproducibility of MicroEnvs
Browse files Browse the repository at this point in the history
  • Loading branch information
tanliwei-coder committed Dec 20, 2024
1 parent 9ca26b2 commit 9dae50e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions stereo/algorithm/cell_cell_communication/spatial_scoloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def main(self,
min_num: int = 30,
binsize: float = 2,
eps: float = 1e-20,
output_path: str = None
output_path: str = None,
seed_used: int = 1024
):
"""
Generate the micro-environment file used for the CCC analysis.
Expand Down Expand Up @@ -90,8 +91,9 @@ def main(self,
for col in type_name:
pairwise_kl_df[col] = pairwise_kl_df[col].apply(lambda x: [])
# do bootstrap
np.random.seed(seed_used)
for i in range(n_boot):
random.seed(i)
# random.seed(i)
# Get the bootstrap sample
idx = np.random.choice(range(n_cell), round(n_cell * boot_prop), replace=True)
data_boot = data.iloc[idx,]
Expand Down
5 changes: 4 additions & 1 deletion stereo/algorithm/gen_ccc_micro_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def main(
binsize: float = 2,
eps: float = 1e-20,
show_dividing_by_thresholds: bool = True,
seed_used: int = 1024,
method: str = 'split',
threshold: float = None,
output_path: str = None,
Expand Down Expand Up @@ -80,6 +81,7 @@ def main(
which is then used to construct the microenvironments.
:param eps: fill eps to zero kde to avoid inf KL divergence.
:param show_dividing_by_thresholds: whether to display the result while running the first part of this function.
:param seed_used: the seed used for random number generator, fix it for reproducibility.
:param method: define micro environments using two methods:
1) minimum spanning tree, or
2) pruning the fully connected tree based on a given threshold of KL, then split the graph into multiple strongly connected component.
Expand Down Expand Up @@ -129,7 +131,8 @@ def main(
min_num=min_num,
binsize=binsize,
eps=eps,
output_path=output_path
output_path=output_path,
seed_used=seed_used
)
self.pipeline_res[res_key] = {
'output_path': output_path,
Expand Down

0 comments on commit 9dae50e

Please sign in to comment.