MS-DIAL-based metabolomics preprocessing as alternative to XCMS. Covers peak detection, alignment, annotation, and export for downstream analysis. Use when processing MS-DIAL output files for R/Python analysis or when preferring GUI-based preprocessing.
MS-DIAL-based metabolomics preprocessing as alternative to XCMS. Covers peak detection, alignment, annotation, and export for downstream analysis. Use when processing MS-DIAL output files for R/Python analysis or when preferring GUI-based preprocessing.
Before using code patterns, verify installed versions match. If versions differ:
Python: pip show <package> then help(module.function) to check signatures
R: packageVersion('<pkg>') then ?function_name to verify parameters
CLI: <tool> --version then <tool> --help to confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
MS-DIAL Preprocessing
"Process my LC-MS data with MS-DIAL" → Detect chromatographic peaks, align across samples, annotate metabolites, and export a feature table for statistical analysis.
CLI: MS-DIAL GUI or console mode for peak picking and alignment
MS-DIAL GUI Workflow
MS-DIAL provides a user-friendly GUI for complete metabolomics preprocessing:
Project Setup - Create new project, select data type
# Filter by annotation confidence# MS-DIAL Annotation tags: Lipid, Metabolite, Unknown, etc.
annotated <- feature_info$`Annotation tag` !='Unknown'# Filter by fill percentage (presence across samples)
fill_threshold <- 50 # Present in at least 50% of samples
good_fill <- feature_info$`Fill %` >= fill_threshold
# Filter by MS/MS match
has_msms <- feature_info$`MS/MS assigned` ==TRUE# Apply filters
filtered_idx <- which(good_fill)# Minimum filter
filtered_matrix <- intensity_matrix[filtered_idx,]
filtered_info <- feature_info[filtered_idx,]
cat('After filtering:', nrow(filtered_matrix),'features\n')
MS-DIAL Data to XCMS-Like Format
library(SummarizedExperiment)# Create SummarizedExperiment for compatibility with other tools
se <- SummarizedExperiment(
assays =list(raw = filtered_matrix),
rowData = filtered_info,
colData = data.frame(
sample = colnames(filtered_matrix),
row.names = colnames(filtered_matrix)))# Add sample metadata
sample_metadata <- read.csv('sample_metadata.csv')
colData(se)<- merge(colData(se), sample_metadata, by.x ='sample', by.y ='sample_id')
MS-DIAL Batch Processing (Console Mode)
# MS-DIAL console application for batch processing# Available on Windows# Create parameter file (msdial_param.txt)# See MS-DIAL documentation for all parameters# Run MS-DIAL console
MsdialConsoleApp.exe lcmsdda -i input_folder -o output_folder -m msdial_param.txt
Parameter File Example
# MS-DIAL Parameter File for LC-MS DDA
# Data collection
Data type=Centroid
Ion mode=Positive
MS1 data type=Centroid
MS2 data type=Centroid
# Peak detection
Smoothing method=LinearWeightedMovingAverage
Smoothing level=3
Minimum peak width=5
Minimum peak height=1000
Mass slice width=0.1
# Alignment
Retention time tolerance=0.1
MS1 tolerance=0.01
Retention time factor=0.5
MS1 factor=0.5
# Identification
MSP file path=MassBank-GNPS.msp
Retention time tolerance for identification=0.5
Accurate mass tolerance (MS1)=0.01
Accurate mass tolerance (MS2)=0.05
Identification score cut off=80
Python Processing of MS-DIAL Output
Goal: Convert MS-DIAL alignment results into a clean, filtered, log-transformed feature matrix for downstream statistical analysis.
Approach: Parse MS-DIAL CSV export to separate feature metadata from intensity values, filter by fill percentage, log2-transform, and export as a tidy matrix.
import pandas as pd
import numpy as np
# Load MS-DIAL alignment results
df = pd.read_csv('msdial_alignment_result.csv')
# Identify sample columns
sample_cols = [c for c in df.columns if'Area'in c or c.startswith('Sample')]
meta_cols = [c for c in df.columns if c notin sample_cols]
# Create feature info and intensity matrix
feature_info = df[meta_cols].copy()
intensities = df[sample_cols].values
# Clean column names (remove 'Area' suffix)
sample_names = [c.replace(' Area', '').strip() for c in sample_cols]
# Filter by fill percentage
fill_pct = df['Fill %'].values
good_features = fill_pct >= 50
intensities_filtered = intensities[good_features]
feature_info_filtered = feature_info[good_features].reset_index(drop=True)
print(f'Filtered: {sum(good_features)} / {len(good_features)} features')
# Log transform
intensities_log = np.log2(intensities_filtered + 1)
# Export for downstream analysis
result_df = pd.DataFrame(
intensities_log,
columns=sample_names,
index=feature_info_filtered['Alignment ID']
)
result_df.to_csv('msdial_processed.csv')
MS-DIAL Annotation Levels
# MS-DIAL uses different annotation confidence levels
annotation_levels <- data.frame(
level =c('Lipid','Metabolite','SuggestedLipid','SuggestedMetabolite','Unknown'),
confidence =c('High','High','Medium','Medium','None'),
description =c('MS/MS match to lipid database','MS/MS match to metabolite database','Mass match to lipid (no MS/MS)','Mass match to metabolite (no MS/MS)','No database match'))# Count by annotation level
table(feature_info$`Annotation tag`)