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

Error about group parameter in dyn. tl. dynamics #670

Open
mingjianPeng opened this issue Mar 4, 2024 · 4 comments
Open

Error about group parameter in dyn. tl. dynamics #670

mingjianPeng opened this issue Mar 4, 2024 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@mingjianPeng
Copy link

Dear Xiaojie,
My data is pulse-chase data from scNT-seq, three temperatures were used for processing, but an error occurs when running dyn. tl. dynamics(adata, group = 'temp'), here's my run code:
Integrate AnnData list and filter

def add_lable_filter(ad_dict,mito_perc):
    adata = dyn.pp.integrate(list(ad_dict.values()), batch_key='batch', fill_value=0)
    adata=ov.pp.qc(adata,
              tresh={'mito_perc': mito_perc, 'nUMIs': 500, 'detected_genes': 400},mt_startswith='mt-',)
    adata.layers['total'] = adata.X
    adata.layers['new'] = adata.layers['X_l_TC']
    adata.layers.pop('X_l_TC', None)
    adata.layers.pop('X_n_TC', None)
    adata.obs['label_time'] = 24 # this is the labeling time
    tkey = 'label_time'
    adata.obs['time'] = adata.obs['time']/60
    return(adata)
adata_merge = add_lable_filter(merge_dict,0.15)

log:

|-----> Running monocle preprocessing pipeline...
|-----------> filtered out 0 outlier cells
|-----------> filtered out 14130 outlier genes
|-----> PCA dimension reduction
|-----> <insert> X_pca to obsm in AnnData Object.
|-----> computing cell phase...
|-----? 
Dynamo is not able to perform cell cycle staging for you automatically. 
Since dyn.pl.phase_diagram in dynamo by default colors cells by its cell-cycle stage, 
you need to set color argument accordingly if confronting errors related to this.
|-----> [Preprocessor-monocle] completed [38.2824s]

run preproces and dynamics

adata_dyn = adata_merge.copy()
preprocessor = dyn.pp.Preprocessor(cell_cycle_score_enable=True)
preprocessor.config_monocle_recipe(adata_dyn)
preprocessor.filter_cells_by_outliers_kwargs["keep_filtered"] = True
preprocessor.preprocess_adata_monocle(adata_dyn, tkey='label_time', experiment_type='one-shot')
dyn.tl.dynamics(adata_dyn,group = 'temp')

An error occurred:

ValueError                                Traceback (most recent call last)
Cell In[155], line 1
----> 1 dyn.tl.dynamics(adata_dyn,group = 'temp')

File ~/miniconda3/envs/dynamo1.3/lib/python3.8/site-packages/dynamo/tools/dynamics.py:700, in dynamics(adata, filter_gene_mode, use_smoothed, assumption_mRNA, assumption_protein, model, est_method, NTR_vel, group, protein_names, concat_data, log_unnormalized, one_shot_method, fraction_for_deg, re_smooth, sanity_check, del_2nd_moments, cores, tkey, **est_kwargs)
    684     vel_P = vel.vel_p(S, P)
    686     adata = set_velocity(
    687         adata,
    688         vel_U,
   (...)
    697         ind_for_proteins,
    698     )
--> 700     adata = set_param_ss(
    701         adata,
    702         est,
    703         alpha,
    704         beta,
    705         gamma,
    706         eta,
    707         delta,
    708         experiment_type,
    709         _group,
    710         cur_grp,
    711         kin_param_pre,
    712         valid_bools_,
    713         ind_for_proteins,
    714     )
    716 elif assumption_mRNA.lower() == "kinetic":
    717     return_ntr = True if fraction_for_deg and experiment_type.lower() == "deg" else False

File ~/miniconda3/envs/dynamo1.3/lib/python3.8/site-packages/dynamo/tools/utils.py:1428, in set_param_ss(adata, est, alpha, beta, gamma, eta, delta, experiment_type, _group, cur_grp, kin_param_pre, valid_ind, ind_for_proteins)
   1422     if cur_grp == _group[0]:
   1423         adata.varm[kin_param_pre + "alpha"] = (
   1424             sp.csr_matrix(np.zeros(adata.shape[::-1]))
   1425             if sp.issparse(alpha)
   1426             else np.zeros(adata.shape[::-1])
   1427         )  #
-> 1428     adata.varm[kin_param_pre + "alpha"][valid_ind, :] = alpha  #
   1429     adata.var.loc[valid_ind, kin_param_pre + "alpha"] = alpha.mean(1)
   1430 elif len(alpha.shape) == 1:

File ~/.local/lib/python3.8/site-packages/scipy/sparse/_index.py:132, in IndexMixin.__setitem__(self, key, x)
    129 broadcast_col = x.shape[1] == 1 and i.shape[1] != 1
    130 if not ((broadcast_row or x.shape[0] == i.shape[0]) and
    131         (broadcast_col or x.shape[1] == i.shape[1])):
--> 132     raise ValueError('shape mismatch in assignment')
    133 if x.shape[0] == 0 or x.shape[1] == 0:
    134     return

ValueError: shape mismatch in assignment

I want to know whether it is feasible to analyze different samples simultaneously in an AnnData ? Is it where I got it wrong when I was analyzing ?
Best regard.

@mingjianPeng mingjianPeng added the help wanted Extra attention is needed label Mar 4, 2024
@mingjianPeng
Copy link
Author

@Xiaojieqiu I'd appreciate it if you'd take the time to look at it for me.

@Sichao25
Copy link
Collaborator

Sichao25 commented Mar 4, 2024

Hi, thank you for raising this issue. This looks like a bug when setting the alpha back to the original data. I will take a look at it. But I do suggest you analyze those samples separately for now since they may have different velocity parameters.

@mingjianPeng
Copy link
Author

Thanks so much for your reply.Then I'll try to analyze it separately first.

Copy link

github-actions bot commented Jun 4, 2024

This issue is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 14 days

@github-actions github-actions bot added the Stale label Jun 4, 2024
@Sichao25 Sichao25 removed the Stale label Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants