squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

sc.read_visium() and tissue positions

Open wangjiawen2013 opened this issue 2 years ago • 1 comments

Hi, The sc.read_visium() function needs to be updated. Because 10x genomics changed the position files (https://support.10xgenomics.com/spatial-gene-expression/software/pipelines/latest/output/spatial): tissue_positions.csv: This text file contains a table with rows that correspond to spots. From Space Ranger v2.0 onwards this file, which was previously named tissue_positions_list.csv, is renamed and includes a header column. Excluding the header column, the file has 4,992 rows for Visium slides with a 6.5 mm Capture Area and 14,336 rows for Visium slides with 11 mm Capture Area which is the number of spots in the spatial array. Columns correspond to the following fields:

barcode: The sequence of the barcode associated to the spot. in_tissue: Binary, indicating if the spot falls inside (1) or outside (0) of tissue. array_row: For Visium slide (6.5 mm Capture Area), the row coordinate of the spot in the array from 0 to 77. The array has 78 rows. For Visium slides (11 mm Capture Area), the row coordinate of the spot range from 0 to 127 as the array has 128 rows. array_col: The column coordinate of the spot in the array. In order to express the "orange crate" arrangement of the spots, for Visium slides (6.5 mm Capture Area) this column index uses even numbers from 0 to 126 for even rows, and odd numbers from 1 to 127 for odd rows with each row (even or odd) resulting in 64 spots. For Visium slides (11 mm Capture Area) this column index uses even numbers from 0 to 222 for even rows, and odd numbers from 1 to 223 for odd rows with each row (even or odd) resulting in 111 spots. pxl_row_in_fullres: The row pixel coordinate of the center of the spot in the full resolution image. pxl_col_in_fullres: The column pixel coordinate of the center of the spot in the full resolution image.

Besides, I looked into the code of sc.read_visium, and find that the row and col are transposed and different from the tissue_positives.csv, the row in sc.read_visium() is in col in positons.csv, and the col in sc.read_visium() is row in positions.csv. Is it a typo or you transpose it on purpose ?

企业微信截图_1661503149662

企业微信截图_16615036993586

wangjiawen2013 avatar Aug 26 '22 08:08 wangjiawen2013

hi @wangjiawen2013 thank you so much for the very detailed issue, this is tremendously useful!

I've just pushed a quick fix here: https://github.com/scverse/squidpy/pull/600 would you be able to give it a try with your data to confirm that it fixes your issue? Thanks a lot!

giovp avatar Sep 16 '22 17:09 giovp

hi @wangjiawen2013 , will close this issue as per this conversation https://github.com/scverse/scanpy/pull/2296#issuecomment-1273309536

giovp avatar Oct 11 '22 12:10 giovp

Hi, @giovp I tried the fix and find the image was weired. It's was shown correctly for spaceranger v1. Please refer to the first question: "Besides, I looked into the code of sc.read_visium, and find that the row and col are transposed and different from the tissue_positives.csv, the row in sc.read_visium() is in col in positons.csv, and the col in sc.read_visium() is row in positions.csv. Is it a typo or you transpose it on purpose ?" image

wangjiawen2013 avatar Nov 10 '22 05:11 wangjiawen2013

And this is an related issue: https://github.com/scverse/scanpy/issues/2251

wangjiawen2013 avatar Nov 10 '22 05:11 wangjiawen2013

And header should be header=0, header=1 is a bug and will cause some weired haviors (for example sq.gr.co_occurrence will break sometimes.) @giovp

wangjiawen2013 avatar Jan 13 '23 07:01 wangjiawen2013

Hi @wangjiawen2013, when using squidpy's read.visium() it should already be possible to read in both spaceranger 1.0 and 2.0 files and plot the data correctly. Scanpy's read_visium() is now also updated here. Does the issue still persist on your side?

LLehner avatar Feb 21 '23 15:02 LLehner

Closing this now, because sq.read.visium() works and there is also the option to read visium files using spatialdata-io with spatialdata_io.visium(). For the spatialdata-io method description see here.

LLehner avatar Jul 19 '23 11:07 LLehner