Skip to main content

mfe

Yet another automated mass spectrometry imaging data processing package, but for geological samples.

Prerequisite

Before using the workflow, proprietary mass spectrometry data format (e.g., .D from Bruker) needs to be exported as plain text file (represented as da_exported_txt in the following examples). Only the coordinates and the centroid mass-to-charge ratios along with the peak intensity are needed from each spectrum.

Python >= 3.5 is needed, and the required library is listed in requirements.txt.

This package is OS-independent

Installation

Just run the following command and the package with all dependecies will be installed.

pip install git+https://github.com/weimin-liu/msi_feature_extraction.git

Instruction

Mass calibration

Dataset should be calibrated first if it hasn't been calibrated yet. Currently, a quadratic mass error calibration function (mfe.quadratic_calibration) is available in this package. Just provide the list of calibrants, and a quadratic function will be fitted to calibrate the spectrum.

Bin-wise KDE for reference peak detection and peak alignment

Reference peaks that are used for spectra alignment are detected in the evenly spaced discrete mass bins, with a peak picking threshold value pth.

The following is an example of how to create a feature table from the MSI spectra with ion intensities normalized by the median peak intensity of each individual spectrum.

from mfe.from_txt import msi_from_txt, get_ref_peaks, create_feature_table

# create a msi object from the exported txt file
spectra = msi_from_txt(da_exported_txt)

# get the reference peaks, with a peak picking threshold of pth, and pth is a list
ref = get_ref_peaks(spectra, peak_th=pth)

# create a feature table with the reference peaks
feature_table = create_feature_table(spectra, ref, normalization='median')

A 2D table will be produced in this step, with columns being the name of the reference peaks (m/z ratios), and each row representing one laser spot.

Pick peaks using grey-level co-occurrences matrix (optional)

No peak has been dropped until this step, grey-level co-occurrences matrix (GLCM) are used to detect how structured are those ion images and rank them.

The following is an example of comparing the GLCM features in MSI dataset with those in the X-radiophotograph.

from mfe.peak_picking import GLCMPeakRanking

glcm = GLCMPeakRanking(q_val=8)
glcm.fit(feature_table, [1, 2, 3, 4, 5], [np.pi / 6, 0, -np.pi / 6, np.pi / 2, -np.pi / 2, np.pi / 4, -np.pi / 4])

results = glcm.results
results = pd.DataFrame(results)

Feature extraction using non-negative matrix factorization

from mfe.feature import repeated_nmf

# first detect the appropriate rank for the data, the list of images are used here instead of the feature table, because the images have already been normalized with quantiles removed.

rank_candidates = list(range(2, 20))
summary = {}
for rank in rank_candidates
    summary[rank] = repeated_nmf(ims, rank, 30, init='random', max_iter=3000)

TODO:

  • Add a more sophisticated piecewise function for mass calibration
  • Add an image registration function (Affine transformation already existed in the code)

Credits

Metadata

Release files for mfe 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mfe 0.0.4
File Size Uploaded Provenance Actions
mfe-0.0.4.tar.gz 19.3 kB Without provenance Details for mfe-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mfe 0.0.4
File Interpreter ABI Platform Actions
mfe-0.0.4-py3-none-any.whl Python 3 none any Details for mfe-0.0.4-py3-none-any.whl

Total release size: 39.0 kB

Release files / mfe-0.0.4.tar.gz

Download URL mfe-0.0.4.tar.gz
Size 19.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fd502f462a3a9e27c2061f2c359c4d15c0f2e344066837490cb62990f0b166d4
BLAKE2b-256 checksum
How to use checksums
912abdf87dffb8d715b6407295f0ffb8ee81a8493e7e5e78ef1aaa562958a758
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Release files / mfe-0.0.4-py3-none-any.whl

Download URL mfe-0.0.4-py3-none-any.whl
Size 19.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0cd5e705750a4389d5dff7c2b068682e9a17ac8cdfce762ee5bfa5c60f10865f
BLAKE2b-256 checksum
How to use checksums
a8d62af251754d3e9e309b807e407176a4753fb0de118f75f00f59ea54134fcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.15

Security for mfe 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page