aristoteleo / spateo-release

Spatiotemporal modeling of spatial transcriptomics
https://spateo-release.readthedocs.io/
BSD 2-Clause "Simplified" License
164 stars 26 forks source link

My Jupyter Kernel core death when running "st.pl.three_d_multi_plot" in my server in cpu mode #273

Open forrwill opened 1 week ago

forrwill commented 1 week ago

I was running the st.pl.three_d_multi_plot in computational node of the server, and the kernel is dead. I want to know if the function can be used in server or in Server kernel

when qsub the task, I got the error:

image

YifanLu2000 commented 1 week ago

Hi, thank you for raising this issue! Spateo's 3D plotting functions are built upon the PyVista package, and there are certain specifications to consider when running PyVista on a remote server. We recommend reviewing their tutorials, particularly for remote Jupyter environments.

To get started, you can try the following simple demo code and see whether pyvista works:

import pyvista as pv
import numpy as np
pv.start_xvfb()
pv.set_jupyter_backend('trame')

pl = pv.Plotter(notebook=True)
rng = np.random.default_rng(seed=0)
points = rng.random((30, 3))
cloud = pv.wrap(points)
pl.add_mesh(cloud, smooth_shading=True, show_edges=True, render_points_as_spheres=True, point_size=50)

pl.show(jupyter_backend='trame')

If everything is set up correctly, you should see an interactive panel like this:

QQ_1728412866759

Once PyVista is properly installed on your remote server, Spateo's 3D plotting functions should work seamlessly. Here's a preview of the output with demo data from Zhang's dataset:

QQ_1728413789528

Reference: Zhang et al., Molecularly defined and spatially resolved cell atlas of the whole mouse brain.

forrwill commented 1 week ago

Thank you for the solutions! I have installed all the required package. But when I run the demo code of pyvista. I met the error,

"2024-10-09 16:03:45.279 ( 10.927s) [ 146CA0600400]vtkXOpenGLRenderWindow.:456 ERR| vtkXOpenGLRenderWindow (0x55b2d01b96a0): bad X server connection. DISPLAY=:99. Aborting.

ERROR:root:bad X server connection. DISPLAY=:99. Aborting."

Is there any experience can share to me? I have be tested almost all the way I know. But I was still not successful...

YifanLu2000 commented 1 week ago

Hi, I encountered the same error when I commented out the following line: pv.start_xvfb() QQ_1728498577060 QQ_1728498597363 Could you try adding this line back and see if it resolves the issue?

Another potential cause might be dependency errors related to libraries in the VTK package. Here's an error I encountered: QQ_1728498743237

This problem can be addressed by running the following command, as suggested in this discussion: conda install -c conda-forge libstdcxx-ng

I recommend trying the pv.start_xvfb() code first. The second solution is just in case you encounter the same dependency issue. Let me know if you need further assistance!

forrwill commented 1 week ago

Thank you for the suggestions, Now, I run the code successfully, and got the output: image

It seems that I need to set the localhost port. '

Another question is about (https://spateo-release.readthedocs.io/en/latest/tutorials/notebooks/7_morphogenesis/1_models_alignment.html)

image

my alignment adata did not contain "latter_models_align", I want to known: which fucntion can generate the. "adata.uns["latter_models_align"]"

my adata is like this:

image

YifanLu2000 commented 1 week ago

Hi, I'm not entirely sure what "latter_models_align" refers to, but based on the code, it seems like it should be a dictionary containing the spatial coordinates of the source and target cells. To proceed, I recommend trying the following code:

correspondences = np.argmax(mapping, axis=0)
sample_idx = np.random.choice(stage2_aligned_pc_v.points.shape[0], 5000)
matches_points_1 = np.array(stage1_aligned_pc_v.points[correspondences[sample_idx],:])
matches_points_2 = np.array(stage2_aligned_pc_v.points[sample_idx,:])
interval = 800
align_lines, _ = st.tdr.construct_align_lines(
    model1_points=matches_points_1,
    model2_points=matches_points_2 + np.asarray([0, 0, - interval]),
    key_added="check_align", label="align_lines", color="gainsboro")

stage2_aligned_pc_v.points[:, 2] = stage2_aligned_pc_v.points[:, 2] - interval
mapping_model = st.tdr.collect_models([align_lines, stage1_aligned_pc_v, stage2_aligned_pc_v])

Here, mapping is obtained from Spateo’s alignment results. For example:

align_models, pis= st.align.morpho_align(...)
mapping = pis[0]

Next, you can visualize the alignment results, with lines connecting the corresponding cells:

st.pl.three_d_plot(
    model=mapping_model,
    key=["check_align", "celltype", "celltype"],
    opacity=[0.01, 1.0, 1.0],
    model_style=["wireframe", "points", "points"],
    model_size=3,
    window_size=(1024, 1024),
    jupyter="static",
    cpo="iso"
)
forrwill commented 1 week ago

Hi, I'm not entirely sure what "latter_models_align" refers to, but based on the code, it seems like it should be a dictionary containing the spatial coordinates of the source and target cells. To proceed, I recommend trying the following code:

correspondences = np.argmax(mapping, axis=0)
sample_idx = np.random.choice(stage2_aligned_pc_v.points.shape[0], 5000)
matches_points_1 = np.array(stage1_aligned_pc_v.points[correspondences[sample_idx],:])
matches_points_2 = np.array(stage2_aligned_pc_v.points[sample_idx,:])
interval = 800
align_lines, _ = st.tdr.construct_align_lines(
    model1_points=matches_points_1,
    model2_points=matches_points_2 + np.asarray([0, 0, - interval]),
    key_added="check_align", label="align_lines", color="gainsboro")

stage2_aligned_pc_v.points[:, 2] = stage2_aligned_pc_v.points[:, 2] - interval
mapping_model = st.tdr.collect_models([align_lines, stage1_aligned_pc_v, stage2_aligned_pc_v])

Here, mapping is obtained from Spateo’s alignment results. For example:

align_models, pis= st.align.morpho_align(...)
mapping = pis[0]

Next, you can visualize the alignment results, with lines connecting the corresponding cells:

st.pl.three_d_plot(
    model=mapping_model,
    key=["check_align", "celltype", "celltype"],
    opacity=[0.01, 1.0, 1.0],
    model_style=["wireframe", "points", "points"],
    model_size=3,
    window_size=(1024, 1024),
    jupyter="static",
    cpo="iso"
)

Thank you very much!