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

Plotting issues with MuData (layers not available) #1290

Open
dawe opened this issue Jan 3, 2025 · 0 comments
Open

Plotting issues with MuData (layers not available) #1290

dawe opened this issue Jan 3, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@dawe
Copy link

dawe commented Jan 3, 2025

I am working with some mudata object, specifically I am applying cellrank kernels to it (BTW, I wasn't sure if posting this on cellrank's issues, but the error traces back to scvelo, so...). Whenever I try to plot the embedding grid/stream, an error is raised, as scv.pl.velocity_embedding_stream tries to access the layers slot (see below the full error). Unfortunately mudata do not support layers (we can discuss if it would make sense or not, but still). The only workaround here is to work on one modality alone, the problem is I have not complete overlap of cells across modalities, so I have to create a new empty anndata to work with.

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[172], line 1
----> 1 ptk.plot_projection(
      2     color='mofa_level_0',
      3     basis='draw_graph_fa', 
      4                )

File [~/miniforge3/envs/sc03/lib/python3.10/site-packages/cellrank/kernels/_utils.py:184](http://localhost:50008/lab/workspaces/~/miniforge3/envs/sc03/lib/python3.10/site-packages/cellrank/kernels/_utils.py#line=183), in require_tmat(wrapped, instance, args, kwargs)
    182 if instance.transition_matrix is None:
    183     raise RuntimeError("Compute transition matrix first as `.compute_transition_matrix()`.")
--> 184 return wrapped(*args, **kwargs)

File [~/miniforge3/envs/sc03/lib/python3.10/site-packages/cellrank/kernels/_base_kernel.py:295](http://localhost:50008/lab/workspaces/~/miniforge3/envs/sc03/lib/python3.10/site-packages/cellrank/kernels/_base_kernel.py#line=294), in KernelExpression.plot_projection(self, basis, key_added, recompute, stream, connectivities, **kwargs)
    293 proj = TmatProjection(self, basis=basis)
    294 proj.project(key_added=key_added, recompute=recompute, connectivities=connectivities)
--> 295 proj.plot(stream=stream, **kwargs)

File [~/miniforge3/envs/sc03/lib/python3.10/site-packages/cellrank/kernels/utils/_projection.py:139](http://localhost:50008/lab/workspaces/~/miniforge3/envs/sc03/lib/python3.10/site-packages/cellrank/kernels/utils/_projection.py#line=138), in TmatProjection.plot(self, stream, *args, **kwargs)
    122 """Plot projected transition matrix in a embedding.
    123 
    124 Parameters
   (...)
    136 %(just_plots)s
    137 """
    138 if stream:
--> 139     return scv.pl.velocity_embedding_stream(
    140         self._kexpr.adata, *args, basis=self._basis, vkey=self._key, **kwargs
    141     )
    142 return scv.pl.velocity_embedding_grid(self._kexpr.adata, *args, basis=self._basis, vkey=self._key, **kwargs)

File [~/miniforge3/envs/sc03/lib/python3.10/site-packages/scvelo/plotting/velocity_embedding_stream.py:250](http://localhost:50008/lab/workspaces/~/miniforge3/envs/sc03/lib/python3.10/site-packages/scvelo/plotting/velocity_embedding_stream.py#line=249), in velocity_embedding_stream(adata, basis, vkey, density, smooth, min_mass, cutoff_perc, arrow_color, arrow_size, arrow_style, max_length, integration_direction, linewidth, n_neighbors, recompute, color, use_raw, layer, color_map, colorbar, palette, size, alpha, perc, X, V, X_grid, V_grid, sort_order, groups, components, legend_loc, legend_fontsize, legend_fontweight, xlabel, ylabel, title, fontsize, figsize, dpi, frameon, show, save, ax, ncols, **kwargs)
    247 ax.streamplot(X_grid[0], X_grid[1], V_grid[0], V_grid[1], **stream_kwargs)
    249 size = 8 * default_size(adata) if size is None else size
--> 250 ax = scatter(
    251     adata,
    252     layer=layer,
    253     color=color,
    254     size=size,
    255     title=title,
    256     ax=ax,
    257     zorder=0,
    258     **scatter_kwargs,
    259 )
    260 if save is True:
    261     save = "embedding_stream"

File [~/miniforge3/envs/sc03/lib/python3.10/site-packages/scvelo/plotting/scatter.py:189](http://localhost:50008/lab/workspaces/~/miniforge3/envs/sc03/lib/python3.10/site-packages/scvelo/plotting/scatter.py#line=188), in scatter(adata, basis, x, y, vkey, color, use_raw, layer, color_map, colorbar, palette, size, alpha, linewidth, linecolor, perc, groups, sort_order, components, projection, legend_loc, legend_loc_lines, legend_fontsize, legend_fontweight, legend_fontoutline, legend_align_text, xlabel, ylabel, title, fontsize, figsize, xlim, ylim, add_density, add_assignments, add_linfit, add_polyfit, add_rug, add_text, add_text_pos, add_margin, add_outline, outline_width, outline_color, n_convolve, smooth, normalize_data, rescale_color, color_gradients, dpi, frameon, zorder, ncols, nrows, wspace, hspace, show, save, ax, aspect, **kwargs)
    187 color = to_list(color, max_len=None)
    188 layer, components = to_list(layer), to_list(components)
--> 189 x, y, basis = to_list(x), to_list(y), to_valid_bases_list(adata, basis)
    191 # get multikey (with more than one element)
    192 multikeys = eval(f"[{','.join(mkeys)}]")

File [~/miniforge3/envs/sc03/lib/python3.10/site-packages/scvelo/plotting/utils.py:199](http://localhost:50008/lab/workspaces/~/miniforge3/envs/sc03/lib/python3.10/site-packages/scvelo/plotting/utils.py#line=198), in to_valid_bases_list(adata, keys)
    190         keys[i] = key = key[2:]
    191     check_basis(adata, key)
    192 valid_keys = np.hstack(
    193     [
    194         adata.obs.keys(),
    195         adata.var.keys(),
    196         adata.varm.keys(),
    197         adata.obsm.keys(),
    198         [key[2:] for key in adata.obsm.keys()],
--> 199         list(adata.layers.keys()),
    200     ]
    201 )
    202 keys_ = keys
    203 keys = [key for key in keys if key in valid_keys or key in adata.var_names]

AttributeError: 'NoneType' object has no attribute 'keys'
@dawe dawe added the bug Something isn't working label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant