LittleLittleCloud / haCCA

anchor spots pairs and high correlated feature pairs assist multi-module spatial assay integrating
Other
2 stars 0 forks source link

Jupyter Kernel crashed while executing code of manual_gross_alignment #11

Open OMIC-coding opened 1 month ago

OMIC-coding commented 1 month ago

Great package! However, I encountered a bug when executing the manual_gross_alignment, which caused a crash of my jupyter kernel. Could you help me fix it? Thanks a lot~

LittleLittleCloud commented 1 month ago

Sure, can you share the code

OMIC-coding commented 1 month ago

for sample in sample_list:

Anndata object generation for MALDI-MSI

xs, ys, nodefeatlabels, nodefeatlabelsdict, nodefeats = readOrifile(os.path.join('/data/project/data/20240729.BIOINF-2426044.convert.results', samplefiles[sample]))
varindex = pd.DataFrame(index=nodefeatlabels).astype(str)
adata_maldi = genadata(xs, ys, nodefeats, sample, varindex)
adata_maldi.var_names = adata_maldi.var_names.astype(str)
adata_maldi.obs['group'] = group_dict.get(sample)
from scipy.sparse import csr_matrix
adata_maldi.X = csr_matrix(adata_maldi.X)

# make pixel name unique
adata_maldi.obs_names =  sample + '_' + adata_maldi.obs_names

# Normalization
sc.pp.normalize_total(adata_maldi, target_sum=1, inplace=True)
sc.pp.log1p(adata_maldi, base=2)

# Clustering (per slice) and visualization
sc.pp.neighbors(adata_maldi) #use_rep='X
sc.tl.leiden(adata_maldi, resolution=0.20)
sc.tl.umap(adata_maldi)
sc.pl.umap(adata_maldi, color=['leiden']) #,save=f'{sample}.pdf'
sc.pl.spatial(adata_maldi, color=['leiden'], library_id=None, spot_size=2, img_key=None,) # save=f'{sample}.pdf'

# Anndata object generation for 10x Visium
adata_visium = sc.read_visium('/data/project/liziyu/MASLD/data/ST/' + str(sample), count_file='filtered_feature_bc_matrix.h5')
adata_visium.obs_names = sample + '_' + adata_visium.obs_names
adata_visium.obs['group'] = group_dict.get(sample)

# Quality Control
adata_visium.var_names_make_unique()
sc.pp.calculate_qc_metrics(adata_visium, inplace=True)
sc.pp.filter_genes(adata_visium, min_cells=1)
sc.pp.filter_cells(adata_visium, min_genes=200)
sc.pp.filter_cells(adata_visium, min_counts=400)

# Expression Normalization
sc.pp.normalize_total(adata_visium, inplace=True)
sc.pp.log1p(adata_visium)

# Clustering (per slice) and visualization
sc.pp.neighbors(adata_visium)
sc.tl.leiden(adata_visium, resolution=0.70)
sc.tl.umap(adata_visium)
sc.pl.umap(adata_visium, color=['leiden']) #,save=f'{sample}.pdf'
sc.pl.spatial(adata_visium, color=['leiden'], size=1.5, img_key='hires',) # save=f'{sample}.pdf'
# scale spatial data of adata_maldi and adata_visium

adata_visium_spatial = pd.DataFrame(adata_visium.obsm['spatial']) scaledata = center_and_scale(adata_visium_spatial) adata_visium_spatial = pd.DataFrame(scaledata, columns=adata_visium_spatial.columns).to_numpy()

adata_maldi_spatial = pd.DataFrame(adata_maldi.obsm['spatial']) scaledata = center_and_scale(adata_maldi_spatial) adata_maldi_spatial = pd.DataFrame(scaledata, columns=adata_maldi_spatial.columns).to_numpy()

maldi_hacca = Data(X=adata_maldi.X.toarray(), D=adata_maldi_spatial, Label=adata_maldi.obs['leiden'].to_numpy()) visium_hacca = Data(X=adata_visium.X.toarray(), D=adata_visium_spatial, Label=adata_visium.obs['leiden'].to_numpy())

Step2: gross manual alignment

manual_gross_alignment(maldi_hacca, visium_hacca, work_dir=RESULTS_FOLDERNAME)

The Kernel crashed while executing code in the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details.

LittleLittleCloud commented 1 month ago

Does jupyter kernel sends any stacktrace when crashing?

OMIC-coding commented 1 month ago

Unfortunately, not. I am using VScode to remote-control the computer when doing the hacca analysis pipeline. Have you tried it in this way?

LittleLittleCloud commented 1 month ago

It's probably because cv crashes jupyter notebook, adding %matplotlib inline to the top of notebook might mitigate this issue.

source: https://stackoverflow.com/questions/46236180/opencv-imshow-will-cause-jupyter-notebook-crash

OMIC-coding commented 1 month ago

Still doesn't work. Is there any other reasons causing the crash of ipykernel?

LittleLittleCloud commented 1 month ago

@OMIC-coding Without knowing the stacktrace there is little thing I can do to infer the crashing reason. can you share me the os information of your remote server, so I can reproduce this crashing on github devbox and keep investigating

OMIC-coding commented 1 month ago

Thank for your patience, My os is as follows: PRETTY_NAME="Ubuntu 22.04.4 LTS" NAME="Ubuntu" VERSION_ID="22.04" VERSION="22.04.4 LTS (Jammy Jellyfish)" VERSION_CODENAME=jammy ID=ubuntu ID_LIKE=debian HOME_URL="https://www.ubuntu.com/" SUPPORT_URL="https://help.ubuntu.com/" BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/" PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy" UBUNTU_CODENAME=jammy

OMIC-coding commented 1 month ago

Is there any possible way to fix this bug? (sorry to bother again)

LittleLittleCloud commented 1 month ago

@OMIC-coding Sorry got too busy with other projects recently, I will try to investigate a workround sometime next week and feel free to ping me if I forget to report back under this thread.