mossjacob / pyslingshot

Python implementation of the Slingshot pseudotime algorithm
51 stars 7 forks source link

TypeError: can only concatenate str (not "int") to str #15

Closed KeitaSaeki closed 9 months ago

KeitaSaeki commented 10 months ago

I got the error message above when I run the following script.

adata.obs['leiden']=adata.obs['leiden'].cat.as_ordered() slingshot = Slingshot(adata, celltype_key="leiden", obsm_key="X_umap", start_node=3, debug_level='verbose') slingshot.fit(num_epochs=1, debug_axes=axes)

I think it is an issue of Python language but have no idea how to fix it. I would appreciate it if someone let me know the solution.

mossjacob commented 10 months ago

Please print the whole stack trace, otherwise I can't know which line is causing this.

KeitaSaeki commented 10 months ago

Hi mossjacob,

For the Anndata below, I ran the above script. AnnData object with n_obs × n_vars = 2082 × 3018 obs: 'n_genes', 'n_genes_by_counts', 'total_counts', 'total_counts_mt', 'pct_counts_mt', 'leiden', 'dpt_pseudotime' var: 'gene_ids', 'feature_types', 'n_cells', 'mt', 'n_cells_by_counts', 'mean_counts', 'pct_dropout_by_counts', 'total_counts', 'highly_variable', 'means', 'dispersions', 'dispersions_norm', 'mean', 'std' uns: 'hvg', 'pca', 'neighbors', 'umap', 'leiden', 'draw_graph', 'leiden_colors', 'paga', 'leiden_sizes', 'iroot', 'diffmap_evals', 'rank_genes_groups' obsm: 'X_pca', 'X_umap', 'X_draw_graph_fr', 'X_diffmap' varm: 'PCs' obsp: 'distances', 'connectivities'

Then, I got the following message.

TypeError Traceback (most recent call last) Cell In[20], line 2 1 adata.obs['leiden']=adata.obs['leiden'].cat.as_ordered() ----> 2 slingshot = Slingshot(adata, celltype_key="leiden", obsm_key="X_umap", start_node=3, debug_level='v erbose') 3 slingshot.fit(num_epochs=1, debug_axes=axes) File ~/.local/lib/python3.9/site-packages/pyslingshot/slingshot.py:43, in Slingshot.init(self, data, cl uster_labels_onehot, celltype_key, obsm_key, start_node, end_nodes, debug_level) 41 assert celltype_key is not None, "Must provide celltype key if data is an AnnData object" 42 cluster_labels = data.obs[celltype_key] ---> 43 cluster_labels_onehot = np.zeros((cluster_labels.shape[0], cluster_labels.max() + 1)) 44 cluster_labels_onehot[np.arange(cluster_labels.shape[0]), cluster_labels] = 1 46 data = data.obsm[obsm_key] TypeError: can only concatenate str (not "int") to str

Hope it works.

Keita

mossjacob commented 9 months ago

Hi Keita,

I have pushed a fix for this, and published a new version (v0.1.3) which should resolve this issue. Please let me know if it persists

mossjacob commented 9 months ago

Closing as presumed fixed