Skip to content

Missing colormap values during 3D reconstruction from multiple slices #342

@jasonleongbio

Description

@jasonleongbio

Dear developer team of Spateo,

Thank you so much for developing such an impressive tool for spatial transcriptomics data!

I was trying to follow the official tutorial in Section 5 to reconstruct a 3D plot from aligned multiple slices, but encountered a few errors.

As I used a different set of data for exploring the tool, I am not sure how to deal with the missing color map in the PyVista step.

point_cloud, _ = st.tdr.construct_pc(
    adata = aligned_adata,
    #spatial_key = "spatial_3D",
    spatial_key = "aligned_spatial_3D",
    groupby = cluster_key,
    key_added = "tissue",
    colormap = palette,
)

point_cloud

The point_cloud data looks like this:

Image

Compared to the one in the tutorial, the key tissue_rgba is missing in the object.
This caused an error message during the visualization step

# show the aligned drosophila in 3D
st.pl.three_d_plot(
    model = point_cloud,
    key = "tissue",
    model_style = 'points',
    model_size = 8,
    show_axes = True,
    jupyter = "static",
    window_size = (1200, 1200),
    show_outline = True,
    outline_kwargs = {'show_labels': False, 'outline_width': 3},
    # plotter_filename='./results/Drosophila_8_9_rigid_alignment_reconstruction.html',  # uncomment this for saving the interactive 3D visualization
)

Error message:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[64], line 2
      1 # show the aligned drosophila in 3D
----> 2 st.pl.three_d_plot(
      3     model = point_cloud,
      4     key = "tissue",
      5     model_style = 'points',
      6     model_size = 8,
      7     show_axes = True,
      8     jupyter = "static",
      9     window_size = (1200, 1200),
     10     show_outline = True,
     11     outline_kwargs = {'show_labels': False, 'outline_width': 3},
     12     # plotter_filename='./results/Drosophila_8_9_rigid_alignment_reconstruction.html',  # uncomment this for saving the interactive 3D visualization
     13 )

File <full_path_not_shown_here_due_to_security_concern>/miniforge3/envs/Spateo/lib/python3.9/site-packages/spateo/plotting/static/three_d_plot/three_dims_plots.py:324, in three_d_plot(model, key, filename, jupyter, off_screen, window_size, background, cpo, colormap, ambient, opacity, model_style, model_size, show_legend, legend_kwargs, show_outline, outline_kwargs, text, text_kwargs, view_up, framerate, plotter_filename, show_axes)
    322 # Create a plotting object to display pyvista/vtk model.
    323 p = create_plotter(off_screen=off_screen1, **plotter_kws)
--> 324 wrap_to_plotter(plotter=p, model=model, key=key, cpo=cpo, **model_kwargs)
    325 cpo = p.show(return_cpos=True, jupyter_backend="none", cpos=cpo)
    327 # Create another plotting object to save pyvista/vtk model.

File <full_path_not_shown_here_due_to_security_concern>/miniforge3/envs/Spateo/lib/python3.9/site-packages/spateo/plotting/static/three_d_plot/three_dims_plots.py:115, in wrap_to_plotter(plotter, model, key, background, cpo, colormap, ambient, opacity, model_style, model_size, show_legend, legend_kwargs, show_outline, outline_kwargs, text, text_kwargs)
    112 cbg_rgb = (1 - bg_rgb[0], 1 - bg_rgb[1], 1 - bg_rgb[2])
    114 # Add model(s) to the plotter.
--> 115 add_model(
    116     plotter=plotter,
    117     model=model,
    118     key=key,
    119     colormap=colormap,
    120     ambient=ambient,
    121     opacity=opacity,
    122     model_size=model_size,
    123     model_style=model_style,
    124 )
    126 # Set the camera position of plotter.
    127 plotter.camera_position = cpo

File <full_path_not_shown_here_due_to_security_concern>/miniforge3/envs/Spateo/lib/python3.9/site-packages/spateo/plotting/static/three_d_plot/three_dims_plotter.py:209, in add_model(plotter, model, key, colormap, ambient, opacity, model_style, model_size)
    198         _add_model(
    199             _p=plotter,
    200             _model=sub_model,
   (...)
    206             _opacity=sub_op,
    207         )
    208 else:
--> 209     _add_model(
    210         _p=plotter,
    211         _model=model,
    212         _key=key,
    213         _colormap=colormap,
    214         _style=model_style,
    215         _model_size=model_size,
    216         _ambient=ambient,
    217         _opacity=opacity,
    218     )

File <full_path_not_shown_here_due_to_security_concern>/miniforge3/envs/Spateo/lib/python3.9/site-packages/spateo/plotting/static/three_d_plot/three_dims_plotter.py:173, in add_model.<locals>._add_model(_p, _model, _key, _colormap, _style, _ambient, _opacity, _model_size)
    163     added_kwargs = (
    164         dict(
    165             scalars=_key if _key in _model.array_names else _model.active_scalars_name,
   (...)
    169         else dict(color=_colormap)
    170     )
    172 mesh_kwargs.update(added_kwargs)
--> 173 _p.add_mesh(_model, **mesh_kwargs)

File <full_path_not_shown_here_due_to_security_concern>/miniforge3/envs/Spateo/lib/python3.9/site-packages/pyvista/_deprecate_positional_args.py:245, in _deprecate_positional_args.<locals>._inner_deprecate_positional_args.<locals>.inner_f(*args, **kwargs)
    241             warnings.warn(msg, PyVistaDeprecationWarning, stacklevel=stack_level)
    243         warn_positional_args()
--> 245 return f(*args, **kwargs)

File <full_path_not_shown_here_due_to_security_concern>/miniforge3/envs/Spateo/lib/python3.9/site-packages/pyvista/plotting/plotter.py:3799, in BasePlotter.add_mesh(self, mesh, color, style, scalars, clim, show_edges, edge_color, point_size, line_width, opacity, flip_scalars, lighting, n_colors, interpolate_before_map, cmap, label, reset_camera, scalar_bar_args, show_scalar_bar, multi_colors, name, texture, render_points_as_spheres, render_lines_as_tubes, smooth_shading, split_sharp_edges, ambient, diffuse, specular, specular_power, nan_color, nan_opacity, culling, rgb, categories, silhouette, use_transparency, below_color, above_color, annotations, pickable, preference, log_scale, pbr, metallic, roughness, render, user_matrix, component, emissive, copy_mesh, backface_params, show_vertices, edge_opacity, **kwargs)
   3796     rgb = True
   3798 original_scalar_name = scalars
-> 3799 scalars = get_array(mesh, scalars, preference=preference, err=True)
   3800 scalar_bar_args.setdefault('title', original_scalar_name)
   3801 scalars_name = original_scalar_name

File <full_path_not_shown_here_due_to_security_concern>/miniforge3/envs/Spateo/lib/python3.9/site-packages/pyvista/_deprecate_positional_args.py:245, in _deprecate_positional_args.<locals>._inner_deprecate_positional_args.<locals>.inner_f(*args, **kwargs)
    241             warnings.warn(msg, PyVistaDeprecationWarning, stacklevel=stack_level)
    243         warn_positional_args()
--> 245 return f(*args, **kwargs)

File <full_path_not_shown_here_due_to_security_concern>/miniforge3/envs/Spateo/lib/python3.9/site-packages/pyvista/core/utilities/arrays.py:436, in get_array(mesh, name, preference, err)
    434 elif err:
    435     msg = f'Data array ({name}) not present in this dataset.'
--> 436     raise KeyError(msg)
    437 else:
    438     out = None

KeyError: 'Data array (tissue_rgba) not present in this dataset.'

The aligned aligned_adata looks like:

AnnData object with n_obs × n_vars = 22534 × 27362
    obs: 'orig.ident', 'nCount_RNA', 'nFeature_RNA', 'batch', 'seurat_clusters', ... (not shown) ... 'nGenes', 'nCounts', 'pMito', 'pass_basic_filter', 'Size_Factor', 'initial_cell_size', 'ntr'
    obsm: ... (not shown) ... 'spatial', 'spatial_3D', 'X_pca', 'X_umap', 'align_spatial', 'aligned_spatial_3D'

And the palette object has the following values

{1: (0.12156862745098039, 0.4666666666666667, 0.7058823529411765),
 2: (0.6823529411764706, 0.7803921568627451, 0.9098039215686274),
 3: (1.0, 0.4980392156862745, 0.054901960784313725),
 4: (1.0, 0.7333333333333333, 0.47058823529411764),
 5: (0.17254901960784313, 0.6274509803921569, 0.17254901960784313),
 6: (0.596078431372549, 0.8745098039215686, 0.5411764705882353),
 7: (0.8392156862745098, 0.15294117647058825, 0.1568627450980392),
 8: (1.0, 0.596078431372549, 0.5882352941176471),
 9: (0.5803921568627451, 0.403921568627451, 0.7411764705882353),
 10: (0.7725490196078432, 0.6901960784313725, 0.8352941176470589),
 11: (0.5490196078431373, 0.33725490196078434, 0.29411764705882354),
 12: (0.7686274509803922, 0.611764705882353, 0.5803921568627451),
 13: (0.8901960784313725, 0.4666666666666667, 0.7607843137254902),
 14: (0.9686274509803922, 0.7137254901960784, 0.8235294117647058),
 15: (0.4980392156862745, 0.4980392156862745, 0.4980392156862745),
 16: (0.7803921568627451, 0.7803921568627451, 0.7803921568627451),
 17: (0.7372549019607844, 0.7411764705882353, 0.13333333333333333),
 18: (0.8588235294117647, 0.8588235294117647, 0.5529411764705883),
 19: (0.09019607843137255, 0.7450980392156863, 0.8117647058823529),
 20: (0.6196078431372549, 0.8549019607843137, 0.8980392156862745),
 21: (0.12156862745098039, 0.4666666666666667, 0.7058823529411765),
 22: (0.6823529411764706, 0.7803921568627451, 0.9098039215686274),
 23: (1.0, 0.4980392156862745, 0.054901960784313725),
 24: (1.0, 0.7333333333333333, 0.47058823529411764),
 25: (0.17254901960784313, 0.6274509803921569, 0.17254901960784313)}

It seems that the key tissue_rgba may need to be manually added to the constructed object after the st.tdr.construct_pc() step?
I sincerely appreciate your help or any advice on how this could be solved ^_^

Thank you very much in advance!

< Package versions >

spateo-release 1.1.1
pyvista 0.46.3

Best regards,
Jason Leong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions