Skip to content

scimapToCsv

scimapToCsv

scimapToCsv(
    data,
    layer="raw",
    outputDir=None,
    fileName=None,
    cellId="CellID",
    verbose=True,
    sdataTable=None,
)

Export expression and metadata as one flat table.

Produces one row per cell: a cell id, one column per marker, then every obs column. That is the shape most non-Python tools expect.

Parameters:

Name Type Description Default
data (AnnData | SpatialData | str, required)

The cell table. An AnnData, a path to an .h5ad file, a SpatialData object, or a path to a .zarr SpatialData store.

required
layer str

Which matrix to export. 'raw' uses .raw.X, None uses .X, any other string names a key in .layers.

'raw'
outputDir str

Directory to write the CSV into. With None nothing is written and the DataFrame is only returned.

None
fileName str

Name of the CSV. Defaults to 'scimap_export.csv'.

None
cellId str

Name of the first column, holding obs_names.

'CellID'
verbose bool

Print the path written.

True
sdataTable str

Which SpatialData table to read.

None

Returns:

Name Type Description
result DataFrame

The flattened table, always returned whether or not outputDir was given.

Raises:

Type Description
ValueError

When layer='raw' and the object has no .raw.

Example
sp.pp.scimapToCsv(adata, outputDir="results", fileName="analysis.csv")

# Export the rescaled values rather than the raw ones.
table = sp.pp.scimapToCsv(adata, layer=None)