Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility of ENACT with Visium HD Data in TIF Format #19

Closed
LCGaoZzz opened this issue Dec 21, 2024 · 4 comments
Closed

Compatibility of ENACT with Visium HD Data in TIF Format #19

LCGaoZzz opened this issue Dec 21, 2024 · 4 comments
Labels
bug Something isn't working question Further information is requested

Comments

@LCGaoZzz
Copy link

LCGaoZzz commented Dec 21, 2024

Hello,

I am currently working with Visium HD data from 10x Genomics, specifically the Visium HD CytAssist Gene Expression Libraries of Human Lung Cancer IF. I noticed that the microscope images for some datasets are provided in TIF format instead of BTF.

I attempted to run the ENACT software with this TIF format data, but encountered an error which prevents successful execution. Here is the error message:

pipeline.py (271): 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
pipeline.py (274): 
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
2024-12-21 10:16:03,245 - ENACT - INFO - <load_image> Successfully loaded image!
2024-12-21 10:16:03,245 - ENACT - INFO - <load_image> Successfully loaded image!
INFO:ENACT:<load_image> Successfully loaded image!
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
[<ipython-input-7-2038a903d2ac>](https://localhost:8080/#) in <cell line: 21>()
     19 )
     20 
---> 21 so_hd.run_enact()

7 frames
[/usr/local/lib/python3.10/dist-packages/enact/pipeline.py](https://localhost:8080/#) in run_enact(self)
    996             # Run cell segmentation
    997             if self.segmentation:
--> 998                 wsi_norm = self.normalize_image(
    999                     image=wsi, min_percentile=5, max_percentile=95
   1000                 )

[/usr/local/lib/python3.10/dist-packages/enact/pipeline.py](https://localhost:8080/#) in normalize_image(self, image, min_percentile, max_percentile)
    297         """
    298         # Adjust min_percentile and max_percentile as needed
--> 299         image_norm = normalize(image, min_percentile, max_percentile)
    300         self.logger.info("<normalize_image> Successfully normalized image!")
    301         return image_norm

[/usr/local/lib/python3.10/dist-packages/csbdeep/utils/utils.py](https://localhost:8080/#) in normalize(x, pmin, pmax, axis, clip, eps, dtype)
     50     """Percentile-based image normalization."""
     51 
---> 52     mi = np.percentile(x,pmin,axis=axis,keepdims=True)
     53     ma = np.percentile(x,pmax,axis=axis,keepdims=True)
     54     return normalize_mi_ma(x, mi, ma, clip=clip, eps=eps, dtype=dtype)

[/usr/local/lib/python3.10/dist-packages/numpy/lib/function_base.py](https://localhost:8080/#) in percentile(a, q, axis, out, overwrite_input, method, keepdims, interpolation)
   4281     if not _quantile_is_valid(q):
   4282         raise ValueError("Percentiles must be in the range [0, 100]")
-> 4283     return _quantile_unchecked(
   4284         a, q, axis, out, overwrite_input, method, keepdims)
   4285 

[/usr/local/lib/python3.10/dist-packages/numpy/lib/function_base.py](https://localhost:8080/#) in _quantile_unchecked(a, q, axis, out, overwrite_input, method, keepdims)
   4553                         keepdims=False):
   4554     """Assumes that q is in [0, 1], and is an ndarray"""
-> 4555     return _ureduce(a,
   4556                     func=_quantile_ureduce_func,
   4557                     q=q,

[/usr/local/lib/python3.10/dist-packages/numpy/lib/function_base.py](https://localhost:8080/#) in _ureduce(a, func, keepdims, **kwargs)
   3821                 kwargs['out'] = out[(Ellipsis, ) + index_out]
   3822 
-> 3823     r = func(a, **kwargs)
   3824 
   3825     if out is not None:

[/usr/local/lib/python3.10/dist-packages/numpy/lib/function_base.py](https://localhost:8080/#) in _quantile_ureduce_func(a, q, axis, out, overwrite_input, method)
   4720         else:
   4721             arr = a.copy()
-> 4722     result = _quantile(arr,
   4723                        quantiles=q,
   4724                        axis=axis,

[/usr/local/lib/python3.10/dist-packages/numpy/lib/function_base.py](https://localhost:8080/#) in _quantile(arr, quantiles, axis, method, out)
   4833             slices_having_nans = None
   4834         # --- Get values from indexes
-> 4835         previous = arr[previous_indexes]
   4836         next = arr[next_indexes]
   4837         # --- Linear interpolation

IndexError: index 0 is out of bounds for axis 0 with size 0

Could you please advise if ENACT is compatible with TIF format files from Visium HD datasets, or if there are specific steps I should follow to convert these files into a compatible format? Any guidance on how to resolve this IndexError would also be greatly appreciated.

Thank you for your assistance and for the development of this useful tool.

@LCGaoZzz
Copy link
Author

LCGaoZzz commented Dec 21, 2024

I noticed that while some datasets work fine with the ENACT software, others lead to execution failures irrespective of the file format (no matter the inputs image's format is TIF or BTF).

I made multiple attempts with four different Visium HD datasets:

  1. Working datasets:

  2. Problematic datasets (same error as above):

Request for Assistance

Could you please advise if there are specific steps I should follow or adjustments needed to make ENACT compatible with these datasets? Any guidance on how to resolve the IndexError and DataFrame issues would be highly appreciated.

Thats wired..

@combj
Copy link

combj commented Jan 29, 2025

I also get the same error: IndexError: index 0 is out of bounds for axis 0 with size 0
I was trying to run the pipeline on Human Cancer Visium HD data and provided it with the tissue_highres_image output from spaceranger that I converted to TIFF format.

@AlbertPlaPlanas AlbertPlaPlanas added bug Something isn't working question Further information is requested labels Jan 29, 2025
@Mena-SA-Kamel
Copy link
Contributor

Hello,

The current implementation assumes an H&E image format ((height, width, 3)), but IF images have a different channel ordering: (channels, height, width). This causes an issue in load_image(), where the cropping logic attempts to slice the channel axis instead of the spatial dimensions.

Proposed Fix

In pipeline.py#L290, update:

img_arr = img_arr[y_min:y_max, x_min:x_max, :]
to

img_arr = img_arr[:, y_min:y_max, x_min:x_max]
This ensures the cropping applies to spatial dimensions while preserving the channel axis.

Additional Fix for StarDist Processing

To properly run StarDist on IF images, update the segmentation step in pipeline.py#L355-L365 as follows:

labels, polys = self.stardist_model.predict_instances_big(
    image[2],  # Only segment the DAPI channel
    axes="YX",  # "YX" since the DAPI image has shape (height, width)
    block_size=self.block_size,
    prob_thresh=self.prob_thresh,
    nms_thresh=self.overlap_thresh,
    min_overlap=self.min_overlap,
    context=self.context,
    n_tiles=n_tiles[:2],  # Remove color channel dimension
    normalizer=None
)

Next Steps

ENACT is currently optimized for H&E images, and IF image support will be improved in the next release. These changes should allow segmentation to run correctly on IF images in the meantime.

Let me know if you need further clarification!

@Mena-SA-Kamel
Copy link
Contributor

ENACT version 0.2.2 now enables support for IF images: Please update the following new parameters accordingly:

  • image_type: "if" -> for IF images, "he" for H&E images
  • stardist
    - stardist_modelname: "2D_versatile_fluo" -> for IF images, "2D_versatile_he" for J&E images
    - channels_to_segment: 2 -> Specify the channel in the IF channel to segment (usually the DAPI channel)

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants