yunguan-wang/SPROD

np.einsum Error following sprod correction

Closed this issue · 4 comments

Hi @yunguan-wang ,
thank you for creating SPROD!
I run into a problem though running it on Visium Data in single mode.
I prepared the data from viewranger output, for this I had to

  1. comment out the unzip os calls in data_preprocessing.py
  2. change the hires png to tif

It ran without errors and now I do have the folder with Counts.txt, Spot_metadata.csv and tissue_hires_image.tif.

But If I then run SPROD with defaults and specifiying in and output folder I get the following traceback:

00:32:16,INFO:::Cold start, processing from counts and image data.
00:32:16,INFO:::Extracting intensity and texture features from matching HE image
00:32:16,INFO:::Normalizing image...
00:32:18,INFO:::Prossessing ./Denoising_ST_SPROD/PreProcessed/UKF275_PreProc
00:32:18,ERROR:::Traceback (most recent call last):
00:32:18,ERROR:::  File "./Denoising_ST_SPROD/SPROD/sprod.py", line 312, in <module>
00:32:18,ERROR:::_ = extract_img_features(input_path, img_type, input_path)
00:32:18,ERROR:::  File "./Denoising_ST_SPROD/SPROD/sprod/feature_extraction.py", line 120, in extract_img_features
00:32:18,ERROR:::spot_img = np.einsum("ij,ijk->ijk", spot_mask, spot_img)
00:32:18,ERROR:::  File "<__array_function__ internals>", line 6, in einsum
00:32:18,ERROR:::  File "/home/anaconda3/envs/SPROD/lib/python3.7/site-packages/numpy/core/einsumfunc.py", line 1359, in einsum
00:32:18,ERROR:::return c_einsum(*operands, **kwargs)
00:32:18,ERROR:::ValueError
00:32:18,ERROR::::
00:32:18,ERROR:::operands could not be broadcast together with remapped shapes [original->remapped]: (39,39)->(39,39,newaxis) (39,33,3)->(39,33,3)

It is probably my mistake, but could you help me find it ?

All the best!

Hi @junyho486 ,
I believe the issue is caused by the image.
In order to use the Sprod with image, you will have to provide an image file that is of the same dimension as the metadata specifies.
For example, if you data's spot coordinate range is from 0 to 6000 thousand, you must provide the matching high resolution image with 3 channels that is also 6000 by 6000 in dimension.
If you do not have that, you can run the data with pseudo image mode.
Hopefully this makes sense.

Hi @yunguan-wang,
Thank you for coming back to me and clarifying!
Going back to the pseudo image is also an option of course, though I would like to avoid it. Especially since my application is the default one (on Visium spaceranger output).
I could only make sprod use the given image features by bloating the image a bit. For this I converted the .png to .tif approx twice the size of my input barcodes (barcodes 3734, image shape (8000, 7688, 3) and now it finally worked.
Even though this worked I am not sure if it is the way to go since image features might now be out of scale...

Do you have any recommendations on how to handle this ?

Closed issue