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

Question about Xenium Sample Alignment and Integration #92

Open
ymoneych opened this issue Feb 5, 2025 · 5 comments
Open

Question about Xenium Sample Alignment and Integration #92

ymoneych opened this issue Feb 5, 2025 · 5 comments
Assignees

Comments

@ymoneych
Copy link

ymoneych commented Feb 5, 2025

Hi, thank you for your excellent work on developing HEST.

I have two questions regarding the integration of new Xenium samples into HEST:

  1. Alignment Process for New Xenium Samples
    I'm trying to understand the process of aligning new Xenium samples. When using XeniumReader, it requires an 'imagealignment.csv' file. I understand that VALIS is being used for image registration to align the DAPI image with the H&E slide. I've checked Aligning new HE-Xenium data #74, but couldn't find any alignment method within the auto_read or read functions. Could you please provide guidance on how to generate the 'imagealignment.csv' file?

  2. XeniumReader Alignment File Handling
    I've noticed a potential issue in the XeniumReader's read function. While alignment_file_path is marked as an optional parameter, setting it to None causes alignment_matrix to be None.
    This leads to an error in the __xenium_estimate_pixel_size during matrix multiplication between he_to_morph_matrix and two_points.T.

    scaled_points = (he_to_morph_matrix @ two_points.T).T

If I've misunderstood any part of the process, I apologize and would appreciate any corrections.
Any clarification on these points would be greatly appreciated. Thank you!

@pauldoucet pauldoucet self-assigned this Feb 5, 2025
@ekansh09
Copy link

ekansh09 commented Feb 5, 2025

I am experiencing the same issue where the auto_read function is not using VALIS for new samples.

Additionally, when using XeniumReader().auto_read(path), I noticed that this function does not have a return statement. Please correct me if I’m wrong, but shouldn’t it include one?

super().auto_read(path, **read_kwargs)

@pauldoucet
Copy link
Collaborator

Hi @ymoneych,
You can obtain an imagealignment.csv file by manually aligning with the Xenium Explorer provided by 10x Genomics. From experience, the affine alignment provided by the Xenium Explorer isn’t always enough and you might need to use Valis micro-registration to get a very accurate alignment.

I’ve added a simple interface to Valis in the latest version, however note that you might need >20Go RAM for aligning a large number of transcripts/shapes. You can use the following code snippet:

xenium_input_dir = 'FFPE Human Cervical Cancer with 5K Human Pan Tissue and Pathways Panel plus 100 Custom Genes'

st = XeniumReader().auto_read(xenium_input_dir )

# Save image to Generic pyramidal tiff
st.save('processed_sample/', save_img=True)

# Path to the H&E image we just saved
he_path = 'processed_sample/aligned_fullres_HE.tif'
dapi_path = 'path_to_morphology_focus_0000.ome.tif'


# Warning Valis alignment might require a significant amount or RAM based on the number of transcripts, shapes and image size
# Feel free to set align_transcripts, align_cells or align_nuclei to False
st.align_with_valis('.', he_path, dapi_path, align_transcripts=True, align_cells=True, align_nuclei=True)

Let me know if that work :)
Best,

Paul

@pauldoucet
Copy link
Collaborator

pauldoucet commented Feb 8, 2025

@ekansh09 thanks for pointing this out! I've just pushed a quick fix

@ymoneych
Copy link
Author

Hi @pauldoucet,
Thank you so much for your quick and detailed response.

Your solution worked perfectly for me.
The provided code snippet for using Valis was exactly what I needed.

My issue is now completely resolved.

@ymoneych
Copy link
Author

Hi @pauldoucet

I encountered an error when using Valis for registration through the align_with_valis method:

The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

The error occurs in registration.py line 189:

if dapi_transcripts:

The error happens because a Pandas DataFrame is being used directly in a conditional statement.
I believe the conditional statement should be modified to:

if dapi_transcripts is not None:

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants