Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
aron0093 committed Feb 15, 2022
2 parents 7fd7212 + f2de388 commit e4ddcfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 11 additions & 1 deletion cytopath/markov_chain_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def sampling(data, auto_adjust=True, matrix_key = 'T_forward', cluster_key = 'lo
ratio_obtained = 0

count = 0 # Iterate sampling runs
old_step_increment=0
# Resample samples until the number of trajectories for each end point has been reached.
while (min(traj_num) < traj_number) or (ratio_obtained < 0.1):

Expand Down Expand Up @@ -321,7 +322,16 @@ def sampling(data, auto_adjust=True, matrix_key = 'T_forward', cluster_key = 'lo
raise ValueError('Sampling failed. Try lowering min_sim_ratio or increase rounds_limit.')

if min(traj_num) < min_sim_ratio*traj_number:
max_steps = math.ceil(traj_number/(max(max_steps, min(traj_num))+1)) + max_steps

# Break out of klein increments
new_step_increment = math.ceil(traj_number/(max(max_steps, min(traj_num))+1))
if new_step_increment==old_step_increment:
new_step_increment=old_step_increment*3

# Adjust max steps
max_steps = new_step_increment + max_steps

old_step_increment = new_step_increment

glob_all_seq = []
glob_prob_all_seq = []
Expand Down
9 changes: 8 additions & 1 deletion cytopath/trajectory_estimation/cyto_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ def cell_neighborhood_finder(adata, map_state, end_point, neighbors_basis='pca',
# Cluster assignment
if n_neighbors_cluster=='auto':
min_cluster_size = adata.obs[adata.uns['run_info']['cluster_key']].value_counts().min()
n_neighbors_cluster=int(max(min_cluster_size - min_cluster_size*cluster_freq, adata.shape[0]/200))
n_neighbors_cluster = min_cluster_size - min_cluster_size*cluster_freq
if n_neighbors_cluster < 10:
n_neighbors_cluster = 10
if adata.shape[0]/200 > 10:
n_neighbors_cluster = adata.shape[0]/200

adata.uns['run_info']['n_neighbors_cluster'] = n_neighbors_cluster

# Find clusters composing the trajectory
compositional_clusters = []
Expand Down Expand Up @@ -116,6 +122,7 @@ def cell_neighborhood_finder(adata, map_state, end_point, neighbors_basis='pca',
if n_neighbors == 'auto':
n_neighbors = adata.obs.loc[adata.obs[adata.uns['run_info']['cluster_key']].astype(str).isin(adata.uns['trajectories']['compositional_clusters'][end_point]),
adata.uns['run_info']['cluster_key']].value_counts().max()
adata.uns['run_info']['n_neighbors'] = n_neighbors

# Create neighborhood
neighborhood_sequence=[]
Expand Down

0 comments on commit e4ddcfc

Please sign in to comment.