squidpy
squidpy copied to clipboard
sc.read_visium() and tissue positions
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 ?
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!
hi @wangjiawen2013 , will close this issue as per this conversation https://github.com/scverse/scanpy/pull/2296#issuecomment-1273309536
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 ?"
And this is an related issue: https://github.com/scverse/scanpy/issues/2251
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
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?
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.