YangLabHKUST / SpatialScope

A unified approach for integrating spatial and single-cell transcriptomics data by leveraging deep generative models
https://spatialscope-tutorial.readthedocs.io/en/latest/
GNU General Public License v3.0
43 stars 4 forks source link

TypeError during Nuclei Segmentation with Custom Dataset in SpatialScope #9

Closed ChenJin2020 closed 5 months ago

ChenJin2020 commented 5 months ago

Hi,

Issue Description:

After successfully installing SpatialScope via Docker and running the nuclei segmentation step without any issues on the provided human heart demo dataset, I encountered a TypeError when attempting the same process with my custom dataset. The error arises during the image feature calculation step within the Nuclei Segmentation module.

Detailed Error Log:

2024-02-02 22:48:33,040 : INFO : Reading spatial data: /home/data/ovary/ovary23_adata.h5ad 2024-02-02 22:48:33,126 : INFO : Spatial data shape: (3420, 36601) 2024-02-02 22:48:33,210 : INFO : Spatial data shape after QC: (3332, 36601) 2024-02-02 22:48:33,211 : INFO : Reading image data: /home/data/ovary/ovary23_adata.h5ad utils.py (494): The return type of Dataset.dims will be changed to return a set of dimension names in future, in order to be more consistent with DataArray.dims. To access a mapping from dimension names to lengths, please use Dataset.sizes. 2024-02-02 22:48:34,732 : INFO : Image shape: (17780, 17780) Found model '2D_versatile_he' for 'StarDist2D'. 2024-02-02 22:48:34.812288: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 AVX AVX2 AVX512F FMA To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. Loading network weights from 'weights_best.h5'. Loading thresholds from 'thresholds.json'. Using default values: prob_thresh=0.692478, nms_thresh=0.3. Found model '2D_versatile_he' for 'StarDist2D'. Loading network weights from 'weights_best.h5'. Loading thresholds from 'thresholds.json'. Using default values: prob_thresh=0.692478, nms_thresh=0.3. 2024-02-02 22:48:45.886894: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 40519073792 exceeds 10% of free system memory. 2024-02-02 22:48:47.923680: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 40519073792 exceeds 10% of free system memory. 2024-02-02 22:48:52.320152: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 10129768448 exceeds 10% of free system memory. 2024-02-02 22:49:03.505906: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 10129768448 exceeds 10% of free system memory. 2024-02-02 22:49:04.581739: W tensorflow/core/framework/cpu_allocator_impl.cc:82] Allocation of 10129768448 exceeds 10% of free system memory. 2024-02-02 22:50:33,603 : INFO : Number of segments: 253591 0%| | 0/3332 [00:00<?, ?/s]Traceback (most recent call last): File "/home/SpatialScope/./src/Nuclei_Segmentation.py", line 174, in NS.NucleiSegmentation() File "/home/SpatialScope/./src/Nuclei_Segmentation.py", line 104, in NucleiSegmentation sq.im.calculate_image_features( File "/opt/conda/envs/SpatialScope/lib/python3.9/site-packages/squidpy/im/_feature.py", line 91, in calculate_image_features res = parallelize( File "/opt/conda/envs/SpatialScope/lib/python3.9/site-packages/squidpy/_utils.py", line 168, in wrapper res = jl.Parallel(n_jobs=n_jobs, backend=backend)( File "/opt/conda/envs/SpatialScope/lib/python3.9/site-packages/joblib/parallel.py", line 1863, in call return output if self.return_generator else list(output) File "/opt/conda/envs/SpatialScope/lib/python3.9/site-packages/joblib/parallel.py", line 1792, in _get_sequential_output res = func(*args, *kwargs) File "/opt/conda/envs/SpatialScope/lib/python3.9/site-packages/squidpy/im/_feature.py", line 119, in _calculate_image_features_helper for crop in img.generate_spot_crops( File "/opt/conda/envs/SpatialScope/lib/python3.9/site-packages/squidpy/im/_container.py", line 823, in generate_spot_crops y = int(spatial[i][1] scale) TypeError: can't multiply sequence by non-int of type 'float'

Possible Cause:

I suspect the issue may relate to the version of Spatial Ranger used to prepare the input data. The output from my Spatial Ranger run was named tissue_positions_list.csv, differing from the expected tissue_positions.csv by Scanpy, which reads an older format. To accommodate this, I renamed the file and proceeded to save the spatial transcriptomics (ST) data as an .h5ad file.

Thanks,

Chen

ChenJin2020 commented 5 months ago

This issue can be resolved by removing the header from the tissue_positions.csv file after renaming it