Readers¶
pg.read_imzml and pg.read_scils_csv turn MSI exports into the AnnData
objects that pg.align takes, and pg.read_h5ad reads .h5ad files.
pgalign.readers.read_imzml
¶
Read an imzML file into an AnnData that pg.align accepts.
In continuous mode every spectrum shares one m/z axis, which is used as it is.
In processed mode each spectrum carries its own m/z values, so increment is
required and every spectrum is put on a common grid with gridding
(Nadaraya-Watson smoothing with bandwidth epsilon), as the manuscript's
simulation study did with increment=0.25. Passing increment grids the
spectra in either mode. Requires pyimzML: pip install "pgalign[imzml]".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
the |
required | |
increment
|
grid spacing in m/z. Required when the spectra do not share one m/z axis. |
None
|
|
mz_range
|
|
None
|
|
epsilon
|
bandwidth of the gridding kernel. Defaults to 0.025. |
0.025
|
Returns:
| Type | Description |
|---|---|
|
an |
Source code in pgalign/readers.py
pgalign.readers.read_scils_csv
¶
Read a SCiLS Lab CSV export into an AnnData that pg.align accepts.
The spectra file holds one row per spot: the spot name in the first column,
then one intensity column per m/z value, with the m/z values as the column
headers. The optional spots file (Region Spots.csv) holds one row per spot,
in the same order, with its index and x and y coordinates; its columns are
copied into obs unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spectra_csv
|
path of the spectra export ( |
required | |
spots_csv
|
path of the spot coordinates ( |
None
|
|
sep
|
the field separator. Defaults to |
';'
|
Returns:
| Type | Description |
|---|---|
|
an |
Source code in pgalign/readers.py
pgalign.readers.read_h5ad
¶
Read an .h5ad file written by :func:write_h5ad or by older anndata.
Restores var["mz"] to var["m/z"] when the file has no m/z column;
files that store m/z itself are read as they are.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
the |
required |
Returns:
| Type | Description |
|---|---|
|
an |
Source code in pgalign/readers.py
Saving¶
Since version 0.13, anndata cannot write a column named m/z, so pg.write_h5ad
stores it as mz and pg.read_h5ad restores it.
pgalign.readers.write_h5ad
¶
Write an AnnData to .h5ad, storing var["m/z"] as var["mz"].
anndata 0.13 refuses to write a column whose name contains a slash, so the m/z
values are stored under mz; :func:read_h5ad restores them. The object
passed in is not modified, and its data are written without being copied.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adata
|
the |
required | |
path
|
the |
required |