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
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
Lipidomics Analysis
"Analyze my lipidomics data" → Identify and quantify lipid species by class and chain composition, then perform differential lipid analysis and pathway interpretation.
CLI: MS-DIAL or LipidSearch for lipid identification
R Workflow with lipidr
library(lipidr)
library(ggplot2)
# Load lipidomics data (LipidSearch or Skyline format)
lipid_data <- read_lipidomes('lipidsearch_export.csv', data_type = 'LipidSearch')
# Or from generic matrix
lipid_data <- as_lipidomics_experiment(
data = intensity_matrix,
sample_info = sample_metadata,
lipid_info = lipid_annotations
)
# Data summary
print(lipid_data)
plot_samples(lipid_data, type = 'tic')
Lipid Annotation
# Parse lipid names to extract class, chain info
lipid_data <- annotate_lipids(lipid_data)
# View lipid classes
table(rowData(lipid_data)$Class)
# Chain length and saturation
plot_chain_distribution(lipid_data)
Normalization
# Normalize by internal standards
lipid_data <- normalize_pqn(lipid_data)
# Or by specific internal standard class
lipid_data <- normalize_istd(lipid_data, istd_class = 'PC')
# Log transform
lipid_data <- log_transform(lipid_data)
# QC plot
plot_samples(lipid_data, type = 'boxplot')
Goal: Identify and classify lipid species from LC-MS data using PyOpenMS and LipidMaps annotation.
Approach: Load mzML data, extract features from XCMS preprocessing, annotate by m/z against LipidMaps, and parse lipid nomenclature for class and chain composition.
import pandas as pd
import numpy as np
from pyopenms import MSExperiment, MzMLFile
# Load mzML
exp = MSExperiment()
MzMLFile().load('lipidomics.mzML', exp)
# Extract lipid features (after XCMS preprocessing)
features = pd.read_csv('xcms_features.csv')
# LipidMaps annotation by m/z
def annotate_lipidmaps(mz, adduct='[M+H]+', tolerance_ppm=10):
'''Query LipidMaps for lipid annotation'''
import requests
url = f'https://www.lipidmaps.org/rest/compound/lm_id/{mz}'
# Note: Use local database for production
return None # Placeholder
# Parse lipid nomenclature
def parse_lipid_name(name):
'''Extract lipid class and chain info from shorthand notation'''
import re
pattern = r'(\w+)\s*\((\d+):(\d+)(?:/(\d+):(\d+))?\)'
match = re.match(pattern, name)
if match:
lipid_class = match.group(1)
chain1_carbon = int(match.group(2))
chain1_unsat = int(match.group(3))
return {
'class': lipid_class,
'total_carbons': chain1_carbon,
'total_unsaturation': chain1_unsat
}
return None
# Example
parse_lipid_name('PC(34:1)') # {'class': 'PC', 'total_carbons': 34, 'total_unsaturation': 1}