BayraktarLab / cell2location

Comprehensive mapping of tissue cell architecture via integrated single cell and spatial transcriptomics (cell2location model)
https://cell2location.readthedocs.io/en/latest/
Apache License 2.0
309 stars 57 forks source link

The kernel appears to have died. It will restart automatically. #171

Closed lifan18 closed 2 years ago

lifan18 commented 2 years ago

Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.

Minimal code sample (that we can run without your data, using public data)

# Your code here
# add modulefiles
module load anaconda3/4.8.2
module load cell2location/0.1

#conda activate cell2loc_env (python 3.9)

jupyter notebook --no-browser --port=8896 --ip "*"  \
# jupyter code following as https://cell2location.readthedocs.io/en/latest/notebooks/cell2location_short_demo.html
# [1]to[9] codes from the TUTORIAL go smoothly.
# bugs happen after run [10] codes
adata_vis_plt = adata_vis.copy()

# Log-transform (log(data + 1))
sc.pp.log1p(adata_vis_plt)

# Find highly variable genes within each sample
adata_vis_plt.var['highly_variable'] = False
for s in adata_vis_plt.obs['sample'].unique():

    adata_vis_plt_1 = adata_vis_plt[adata_vis_plt.obs['sample'].isin([s]), :]
    sc.pp.highly_variable_genes(adata_vis_plt_1, min_mean=0.0125, max_mean=5, min_disp=0.5, n_top_genes=1000)

    hvg_list = list(adata_vis_plt_1.var_names[adata_vis_plt_1.var['highly_variable']])
    adata_vis_plt.var.loc[hvg_list, 'highly_variable'] = True

# Scale the data ( (data - mean) / sd )
sc.pp.scale(adata_vis_plt, max_value=10)
# PCA, KNN construction, UMAP
sc.tl.pca(adata_vis_plt, svd_solver='arpack', n_comps=40, use_highly_variable=True)
sc.pp.neighbors(adata_vis_plt, n_neighbors = 20, n_pcs = 40, metric='cosine')
sc.tl.umap(adata_vis_plt, min_dist = 0.3, spread = 1)

with mpl.rc_context({'figure.figsize': [8, 8],
                     'axes.facecolor': 'white'}):
    sc.pl.umap(adata_vis_plt, color=['sample'], size=30,
               color_map = 'RdPu', ncols = 1, #legend_loc='on data',
               legend_fontsize=10)
[The kernel appears to have died. It will restart [automatically.]]

image

After google, this issue seems from new conda version or python 3.9, I tried the solution as below:

conda install freetype=2.10.4

But, this issue still happens.

When I run [10] separetely, it shows the information as below:

NameError                                 Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 adata_vis_plt = adata_vis.copy()
      3 # Log-transform (log(data + 1))
      4 sc.pp.log1p(adata_vis_plt)

NameError: name 'adata_vis' is not defined

Hope these information can help to understand the issue, I am not sure this issue caused by the matplotlib.

Looking forward your reply ;)

Thank you very much!

vitkl commented 2 years ago

Hi @lifan18

sorry for the delayed response.

  1. Please use the new tutorial https://cell2location.readthedocs.io/en/latest/notebooks/cell2location_tutorial.html - the analysis step the notebook fails in is not necessary and is not present in the most up-to-date tutorial.

  2. Dead kernel is most likely due to running out of RAM. This step densifies data requiring substantial RAM:

# Scale the data ( (data - mean) / sd )
sc.pp.scale(adata_vis_plt, max_value=10)
lifan18 commented 2 years ago

Thank you very much for your response! I am clear now, thx!