A package to convert mzML files to HDF5 for deep learning.
Project description
mzrt2h5
A Python package to convert mzML files to HDF5 format for deep learning applications.
Installation
After installation, a new command mzrt2h5 will be available in your terminal.
pip install -r requirements.txt
pip install .
CLI Usage
This is the most straightforward way to use the package. After installation, you can call the mzrt2h5 command from your terminal.
Example:
mzrt2h5 process \
/path/to/your/mzml_folder/ \
/path/to/your/output.h5 \
--metadata-csv-path /path/to/your/metadata.csv \
--rt-precision 0.1 \
--mz-precision 0.01
Options:
Use mzrt2h5 --help to see all available options.
Python Usage
from mzrt2h5.processing import save_dataset_as_sparse_h5
from mzrt2h5.dataset import DynamicSparseH5Dataset
from mzrt2h5.visualization import plot_sample_image
# Process mzML files and save to HDF5
save_dataset_as_sparse_h5(
folder="path/to/your/mzML_files",
save_path="output.h5",
rt_precision=0.1,
mz_precision=0.01,
metadata_csv_path="path/to/your/metadata.csv",
)
# Create a PyTorch dataset
dataset = DynamicSparseH5Dataset(
h5_path="output.h5",
target_rt_precision=0.5,
target_mz_precision=0.05,
)
# Create a dataset with on-the-fly augmentation for training
# with a random retention time shift of +/- 30 seconds
# and a random m/z shift of +/- 5 ppm.
train_dataset = DynamicSparseH5Dataset(
h5_path="output.h5",
target_rt_precision=0.5,
target_mz_precision=0.05,
augment=True,
aug_rt_shift_s=30,
aug_mz_shift_ppm=5
)
# Plot a sample image from the HDF5 file
plot_sample_image(
h5_path="output.h5",
sample_id="Sample_A", # Or an integer index like 0
target_rt_precision=0.5,
target_mz_precision=0.05,
output_path="sample_A_plot.png" # Saves to file, remove to display interactively
)
Visualization
To visualize a mass spectrometry image from your HDF5 file, use the mzrt2h5 plot command:
mzrt2h5 plot \
/path/to/your/output.h5 \
"Sample_A" \
--rt-precision 0.5 \
--mz-precision 0.05 \
--output-path sample_A_plot.png
Options:
Use mzrt2h5 plot --help to see all available options for plotting.
Web Interface
This package also includes a simple web interface to perform the conversion.
-
Run the Flask app:
python app/app.py -
Access the web interface: Open your web browser and go to
http://127.0.0.1:5000. -
Use the form: Upload your metadata file, select your mzML files directory, set the parameters, and click "Process and Download H5".
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mzrt2h5-0.1.1.tar.gz.
File metadata
- Download URL: mzrt2h5-0.1.1.tar.gz
- Upload date:
- Size: 12.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7f1baebc487bc1b7319eea2dac765d09d45b7d2a81fc27a22dc6e13cb78c605
|
|
| MD5 |
9bbd11804b50e20fa50e11c2fdd5ac80
|
|
| BLAKE2b-256 |
3ae507d082e5a64f487e7e101cc1a7adac13835605e2c1fe2ed4310acd680feb
|
File details
Details for the file mzrt2h5-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mzrt2h5-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a3c699154431c60aec42295071b18a1b6b9e2fdfe6f895941bfce5b62663b172
|
|
| MD5 |
3fe5303d98d7946951acf8b084017f2b
|
|
| BLAKE2b-256 |
0b54cc2596b306dad3b4c78230fd360c29b9b722916fb59d4ad2739773ca1cb0
|