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

updated read_visium() to read in spaceranger 2.0 files #2424

Merged
merged 7 commits into from
Apr 2, 2023

Conversation

LLehner
Copy link
Member

@LLehner LLehner commented Feb 20, 2023

Can now read in spaceranger 2.0 files where the tissue position file name is different and a header is included. Code adapated from squidpy's read.visium() in response to scverse/squidpy#599 and scverse/scanpy#2296.

@codecov
Copy link

codecov bot commented Feb 20, 2023

Codecov Report

Merging #2424 (e0a7409) into master (9969734) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2424   +/-   ##
=======================================
  Coverage   71.87%   71.87%           
=======================================
  Files          98       98           
  Lines       11496    11496           
=======================================
  Hits         8263     8263           
  Misses       3233     3233           
Impacted Files Coverage Δ
scanpy/readwrite.py 67.58% <100.00%> (ø)

@LLehner
Copy link
Member Author

LLehner commented Feb 20, 2023

10x Visium data from both space ranger 1.0.0 and 2.0.0 can be read in using sc.read_visium() and plotted using squidpy with coordinates in correct order.

space ranger 1.0.0 data from 10x plotted with squidpy's spatial_scatter():

spaceranger_1

space ranger 2.0.0 data from 10x plotted with squidpy's spatial_scatter():

spaceranger_2

@LLehner
Copy link
Member Author

LLehner commented Feb 20, 2023

@giovp

Copy link
Member

@ivirshup ivirshup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giovp feel free to approve and merge. One request first:

Can this get a release note?

@giovp
Copy link
Member

giovp commented Mar 1, 2023

@giovp feel free to approve and merge. One request first:

Can this get a release note?

for sure, @LLehner could you? think he's is on holiday until next week

@LLehner
Copy link
Member Author

LLehner commented Mar 6, 2023

for sure, @LLehner could you? think he's is on holiday until next week

sure, will do

@LLehner LLehner mentioned this pull request Apr 1, 2023
@giovp
Copy link
Member

giovp commented Apr 2, 2023

LGTM thanks @LLehner !

@flying-sheep
Copy link
Member

flying-sheep commented Jun 26, 2023

hi @LLehner, why is this header=1?. Doesn’t that mean “the second line of data”? Shouldn’t it be header=0?

@LLehner
Copy link
Member Author

LLehner commented Jun 26, 2023

hi @flying-sheep, you are right. Header should be 0, otherwise the first row with values (besides the barcode) will be turned into headers and then overwritten. Didn't catch that before, since it didn't cause issues in the plotting examples.

@mortunco
Copy link

mortunco commented Aug 1, 2023

Folks. Forgive my ignorance if I am completely wrong but it seems read_visium still reads it wrong.

https://github.com/scverse/scanpy/blob/edd613026cd5991baf92c8308b5ee2375089adc8/scanpy/readwrite.py#L466C1-L473

another edit:

scanpy/scanpy/readwrite.py

Lines 466 to 482 in 89804c2

positions.columns = [
'in_tissue',
'array_row',
'array_col',
'pxl_col_in_fullres',
'pxl_row_in_fullres',
]
adata.obs = adata.obs.join(positions, how="left")
adata.obsm['spatial'] = adata.obs[
['pxl_row_in_fullres', 'pxl_col_in_fullres']
].to_numpy()
adata.obs.drop(
columns=['pxl_row_in_fullres', 'pxl_col_in_fullres'],
inplace=True,
)

Basically line 476 is fixes the switch and makes the barcode coordinates in (x,y).

I apologise for the confusion.

@grst
Copy link
Contributor

grst commented Jan 25, 2024

With scverse/spatialdata-io#102 we could consider replacing scanpy.read_visium with

def read_visium(*args, **kwargs): 
    import spatialdata_io
    return spatialdata_io.visium(*args, **kwargs).to_legacy_anndata()

and avoid maintaing the annoying spaceranger output parsing in multiple locations.

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

Successfully merging this pull request may close these issues.

6 participants