Usage

class MSIDataset(path: str)[source]

The class for a raw MSI dataset

Parameters:

path (str) – path of the .d directory

ccs_calibrator()[source]

Generate a CCS calibrater, mapping 1/K_0 -> CCS, using Calibrants(not Mason-Shamp equation)

Returns:

calibrator

Return type:

CCS_calibration

tic() Series[source]

TIC

Returns:

_description_

Return type:

pd.Series

slice_image(mz: slice = None, mobility: slice = None) ndarray[source]

Get slice image data, used for ion images. Example: slice_image(mz=slice(499, 500), mobility=slice(1.0, 1.1))

Parameters:
  • mz (slice, optional) – mz range in slice, defaults to None

  • mobility (slice, optional) – mobility range in slice, defaults to None

Returns:

an intensity array

Return type:

np.ndarray

mean_spectrum(frame_indices: ndarray = None, sampling_ratio: float = 1.0, intensity_threshold: float = 0.05, as_frame=False, seed=42)[source]

compute mean spectra over the whole dataset

Parameters:
  • as_frame (bool, optional) – if True, return a pd.DataFrame, otherwise an Frame, defaults to False

  • intensity_threshold (float, optional) – Filter out intensities that appear in little fraction of pixels, defaults to 0.05

Returns:

_description_

Return type:

_type_

process(sampling_ratio=0.1, intensity_threshold=0.05, roi=None, visualize=False, ccs_calibration=False, **kwargs) Dict[source]

Process the dataset to peak picked and aligned data cube

Parameters:
  • sampling_ratio (float, optional) – ratio for computing the mean spectrum, defaults to 0.1

  • intensity_threshold (float, optional) – intensity threshold relative to lowest intensity in a single frame for filtering the mean spectrum, defaults to 0.05

Returns:

a dictionary with intensity array, peak list and coordinates

Return type:

Dict

image(mz: slice = None, mobility: slice = None)[source]

Show slice image of a dataset, TIC image by default

Parameters:
  • mz (slice, optional) – mz range, defaults to None

  • mobility (slice, optional) – mobility range, defaults to None

class Frame(data: DataFrame | Series, mz_domain: ndarray | None = None, mobility_domain: ndarray | None = None, coords: List[int] = None)[source]

The class for a frame.

Parameters:
  • data (pd.DataFrame | pd.Series) – 3 columns for 3 dimensions: mz, mobility, intensity

  • mz_domain (np.ndarray | None, optional) – a sorted list of all possible mz values, defaults to None

  • mobility_domain (np.ndarray | None, optional) – a sorted list of all possible 1/K0 values, defaults to None

Raises:

TypeError – domains are missing

as_series(use_index=False, sort=True) Series[source]

Represent the frame as a multiindexed pd.Series

Parameters:
  • use_index (bool, optional) – if True the multiindex uses integer indices, otherwise uses values, defaults to False

  • sort (bool, optional) – sort the Series by multiindex levels, defaults to True

Returns:

A pd.Series of intensities, with (mz, mobility) multiindex

Return type:

pd.Series

peakPick(tolerance: Iterable[int | float] | int | float | None = 2, metric: Literal['euclidean', 'chebyshev'] = 'euclidean', window_size: Iterable[int] = [17, 7], adaptive_window=False, subdivide=True, count_thrshold=5, sort=False, return_labels=False, return_extents=False, return_apex=False) DataFrame[source]

2D peak-picking on a frame First group intensities based on approximity in (mz, mobility) space, then detect local maxima in each group

Parameters:
  • tolerance (Iterable[int | float] | int | float | None, optional) – tolerance to determine neighbors, in integer indices, defaults to [2,2]

  • metric (Literal["euclidean", "chebyshev"], optional) – distance metric, defaults to “euclidean”

  • window_size (Iterable[int], optional) – window size of the maximum filter, defaults to [17, 7]

  • count_thrshold (int, optional) – minimum intensity count of a peak, defaults to 5

  • sort (bool, optional) – if True, sort peaks by descending total intensity, defaults to False

  • return_labels (bool, optional) – if True, return group labels, defaults to False

  • return_extents (bool, optional) – if True, return extents in each dimension of groups, defaults to False

Returns:

peak information

Return type:

pd.DataFrame

export_imzML(dataset: MSIDataset, path: str, peaks: Dict = None, mode: Literal['centroid', 'profile'] = 'centroid', imzml_mode: Literal['continuous', 'processed'] = 'continuous')[source]

Export processed data as imzML format with ion mobility

Parameters:
  • dataset (MSIDataset) – the original dataset, contains necessary metadata

  • path (str) – path of the output

  • peaks (Dict, optional) – processing results from MSIDataset.process(), defaults to None

  • mode (Literal["centroid", "profile"], optional) – , defaults to “centroid”

  • imzml_mode (Literal["continuous", "processed"], optional) – mode of arrays in the imzML file, defaults to “continuous”

image(dataset: MSIDataset, mz: slice = None, mobility: slice = None, normalization: Literal['TIC', 'RMS', 'none'] = 'none') Tuple[figure, ColumnDataSource][source]

Visualize images of a dataset. By default it is the TIC image. If mz and mobility provided, all intensities within the slices would be aggregated across pixels

Parameters:
  • dataset (MSIDataset) – the dataset to visualize

  • mz (slice, optional) – the m/z slice to subset the data, defaults to None

  • mobility (slice, optional) – the mobility slice to subset the data, defaults to None

  • normalization (Literal["TIC", "RMS", "none"], optional) – normalize pixel intensities, defaults to “TIC”

Returns:

the image and its data source

Return type:

Tuple[figure, ColumnDataSource]

scatterplot(frame: Frame) Tuple[figure, ColumnDataSource][source]

Visualize a 2D spectogram in scatter plot, with better performance compared with heatmap

Parameters:

frame (Frame) – the frame to visualize

Returns:

the 2D spectogram and its datasource

Return type:

figure

heatmap(frame: Frame) Tuple[figure, ColumnDataSource][source]

Visualize a 2D spectogram

Parameters:

frame (Frame) – the frame to visualize

Returns:

the 2D spectogram and its data source

Return type:

figure

mobilogram(data: DataFrame, transposed: bool = False) Tuple[figure, ColumnDataSource][source]

Visualize a mobilogram using line plot

Parameters:
  • data (pd.DataFrame) – the data to visualize, with “mobility_values” column and “intensity_values” column

  • transposed (bool, optional) – swap x and y axis to set the mobilogram as y-marginal, defaults to False

Returns:

the mobilogram and its data source

Return type:

Tuple[figure, ColumnDataSource]