STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
180 stars 59 forks source link

the batch qc in ms_data.tl.batch_qc(scope=slice_generator[:],mode='integrate', cluster_res_key='leiden', report_path='./batch_qc', res_key='batch_qc') getting error #230

Closed honghh2018 closed 4 months ago

honghh2018 commented 6 months ago

Hi developer, I follow the document of https://stereopy.readthedocs.io/en/latest/Tutorials%28Multi-sample%29/Batch_QC.html to show the batch qc report, unfortunately, it getting error below code:

python 3.8 stereo 1.0.0 development version

data1=st.io.read_h5ad("/customer_h5ad_preprocess_file/data1.h5ad",flavor="stereopy",bin_size=50)

data2=st.io.read_h5ad("/customer_h5ad_preprocess_file/data2.h5ad",flavor="stereopy",bin_size=50) ms_data = MSData(_relationship='continuous', _var_type='intersect')

ms_data += data1 ms_data += data2

ms_data: {'0': (8872, 27074), '1': (21017, 26232)} num_slice: 2 names: ['0', '1'] obs: [] var: [] relationship: continuous var_type: intersect to 0 mss: []

ms_data.integrate() ms_data

ms_data: {'0': (8872, 27074), '1': (21017, 26232)} num_slice: 2 names: ['0', '1'] obs: ['batch'] var: [] relationship: continuous var_type: intersect to 24946 mss: []

ms_data.tl.cal_qc(scope=slice_generator[:],mode='integrate')

ms_data.tl.raw_checkpoint()

ms_data.tl.normalize_total(scope=slice_generator[:],mode='integrate')

ms_data.tl.log1p(scope=slice_generator[:],mode='integrate')

ms_data.tl.scale(scope=slice_generator[:],mode='integrate', zero_center=True, max_value=10)

embedding

ms_data.tl.pca(scope=slice_generator[:],mode='integrate', use_highly_genes=False, n_pcs=50, res_key='pca') ms_data.tl.neighbors(scope=slice_generator[:],mode='integrate', pca_res_key='pca', res_key='neighbors') ms_data.tl.umap(scope=slice_generator[:],mode='integrate', pca_res_key='pca', neighbors_res_key='neighbors', res_key='umap')

clustering

ms_data.tl.leiden(scope=slice_generator[:],mode='integrate', neighbors_res_key='neighbors', res_key='leiden')

ms_data.tl.batch_qc(scope=slice_generator[:],mode='integrate', cluster_res_key='leiden', report_path='./batch_qc', res_key='batch_qc')

in this line ms_data.tl.batch_qc(scope=slice_generator[:],mode='integrate', cluster_res_key='leiden', report_path='./batch_qc', res_key='batch_qc') it getting error lying below:

[2023-12-29 19:52:07][Stereo][15317][MainThread][47675957766528][ms_pipeline][122][INFO]: register algorithm batch_qc to <class 'stereo.core.stereo_exp_data.StereoExpData'>-47679974355872 [2023-12-29 20:04:41][Stereo][15317][MainThread][47675957766528][classifier][144][INFO]: Model Training Finished! [2023-12-29 20:04:41][Stereo][15317][MainThread][47675957766528][classifier][145][INFO]: Trained checkpoint file has been saved to ./batch_qc


ValueError Traceback (most recent call last) Cell In[66], line 1 ----> 1 ms_data.tl.batch_qc(n_neighbors=1000,mode='integrate', report_path='./batch_qc', res_key='batch_qc')

File ~/miniconda3/envs/stereopy2/lib/python3.8/site-packages/stereo/core/ms_pipeline.py:191, in MSDataPipeLine.getattr..temp(*args, *kwargs) 189 if kwargs["mode"] == "integrate": 190 if self.ms_data.merged_data: --> 191 return self._use_integrate_method(item, args, **kwargs) 192 else: 193 raise Exception( 194 "mode integrate should merge first, using ms_data.integrate" 195 )

File ~/miniconda3/envs/stereopy2/lib/python3.8/site-packages/stereo/core/ms_pipeline.py:97, in MSDataPipeLine._use_integrate_method(self, item, *args, *kwargs) 95 if new_attr: 96 logger.info(f'register algorithm {item} to {type(merged_data)}-{id(merged_data)}') ---> 97 return new_attr(args, **kwargs) 98 else: 99 from stereo.plots.plot_base import PlotBase

File ~/miniconda3/envs/stereopy2/lib/python3.8/site-packages/stereo/algorithm/batch_qc/main.py:35, in BatchQc.main(self, n_neighbors, condition, count_key, cluster_res_key, report_path, gpu, data_loader_num_workers, num_threads, res_key) 32 if data_loader_num_workers <= 0 or data_loader_num_workers > cpu_count(): 33 data_loader_num_workers = cpu_count() ---> 35 self.pipeline_res[res_key] = batchqc_raw( 36 self.stereo_exp_data, 37 n_neighbors=n_neighbors, 38 condition=condition, 39 count_key=count_key, 40 celltype_key=cluster_res_key, 41 report_path=report_path, 42 gpu=gpu, 43 data_loader_num_workers=data_loader_num_workers, 44 num_threads=num_threads 45 )

File ~/miniconda3/envs/stereopy2/lib/python3.8/site-packages/stereo/algorithm/batch_qc/batchqc_raw.py:130, in batchqc_raw(data, n_neighbors, batch_key, condition, count_key, celltype_key, report_path, gpu, data_loader_num_workers, num_threads) 127 output_dict["table"]["f-test"] = F_test_df 128 output_dict["imgs"] = {"box": boxplot_src} --> 130 cdf_src = cdf_plot(merge_data, batch_key=batch_key, use_key=count_key) 131 kernel_src = kernel_plot(merge_data, batch_key=batch_key, test_key=count_key) 132 vm_src = var_mean_plot(merge_data, batch_key=batch_key)

File ~/miniconda3/envs/stereopy2/lib/python3.8/site-packages/stereo/algorithm/batch_qc/test/cdf_plot.py:32, in cdf_plot(merge_data, batch_key, use_key) 30 temp_idx = list(set(dfs[i].index).intersection(dfs[j].index)) 31 diff = np.abs(dfs[i].loc[temp_idx].values - dfs[j].loc[temp_idx].values) ---> 32 idx = np.argmax(diff) 33 plt.errorbar(x=temp_idx[idx], y=(dfs[i].loc[temp_idx[idx]] + dfs[j].loc[temp_idx[idx]]) / 2, 34 yerr=diff[idx] / 2, capsize=5, mew=3) 35 plt.annotate(f"Maximum Difference: {diff[idx] / 2:.4f}", 36 xy=(temp_idx[idx], (dfs[i].loc[temp_idx[idx]] + dfs[j].loc[temp_idx[idx]]) / 2), 37 xytext=(temp_idx[idx], dfs[i].loc[temp_idx[idx]]), 38 fontsize=16, 39 arrowprops=dict(arrowstyle="->", connectionstyle="arc3, rad=-0.3"))

File <__array_function__ internals>:180, in argmax(*args, **kwargs)

File ~/miniconda3/envs/stereopy2/lib/python3.8/site-packages/numpy/core/fromnumeric.py:1216, in argmax(a, axis, out, keepdims) 1129 """ 1130 Returns the indices of the maximum values along an axis. 1131 (...) 1213 (2, 1, 4) 1214 """ 1215 kwds = {'keepdims': keepdims} if keepdims is not np._NoValue else {} -> 1216 return _wrapfunc(a, 'argmax', axis=axis, out=out, **kwds)

File ~/miniconda3/envs/stereopy2/lib/python3.8/site-packages/numpy/core/fromnumeric.py:57, in _wrapfunc(obj, method, *args, kwds) 54 return _wrapit(obj, method, *args, *kwds) 56 try: ---> 57 return bound(args, kwds) 58 except TypeError: 59 # A TypeError occurs if the object does have such a method in its 60 # class, but its signature is not identical to that of NumPy's. This (...) 64 # Call _wrapit from within the except clause to ensure a potential 65 # exception has a traceback chain. 66 return _wrapit(obj, method, *args, **kwds)

ValueError: attempt to get argmax of an empty sequence

how to fix this issue? any advice would be appreciated Best hanhuihong

honghh2018 commented 6 months ago

Had anyone hear this issue?

Zhenbin24 commented 5 months ago

Hello, can you send me your h5 file so that I can verify the problem, or you can compare whether the h5 file we provide is different from the one you provided. It is recommended that you use the data we provide to test first, and then replace it with your own data if there are no problems.

honghh2018 commented 4 months ago

您好!已经收到邮件,祝好!                                    洪汉辉