CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-pyopenms

Python wrapper for C++ LC-MS library OpenMS for comprehensive mass spectrometry data analysis

Pending
Overview
Eval results
Files

feature-detection.mddocs/

Feature Detection and Quantification

Advanced algorithms for detecting LC-MS features including peak picking, feature finding, and quantitative analysis. These algorithms form the foundation for label-free quantification and comparative proteomics/metabolomics studies.

Capabilities

Peak Picking

High-Resolution Peak Picking

class PeakPickerHiRes:
    def __init__(self) -> None: ...
    
    def pickExperiment(self, input: MSExperiment, output: MSExperiment) -> None:
        """
        Pick peaks in entire MS experiment.
        
        Args:
            input (MSExperiment): Input experiment with profile spectra
            output (MSExperiment): Output experiment with picked peaks
        """
    
    def pick(self, input: MSSpectrum, output: MSSpectrum) -> None:
        """
        Pick peaks in single spectrum.
        
        Args:
            input (MSSpectrum): Input profile spectrum
            output (MSSpectrum): Output picked spectrum
        """
    
    def getParameters(self) -> Param:
        """
        Get algorithm parameters.
        
        Returns:
            Param: Parameter object for configuration
        """
    
    def setParameters(self, param: Param) -> None:
        """
        Set algorithm parameters.
        
        Args:
            param (Param): Parameter configuration
        """

class PeakPickerMaxima:
    def __init__(self) -> None: ...
    
    def pick(self, input: MSSpectrum, output: MSSpectrum) -> None:
        """
        Pick peaks using local maxima method.
        
        Args:
            input (MSSpectrum): Input profile spectrum
            output (MSSpectrum): Output picked spectrum
        """
    
    def getParameters(self) -> Param:
        """Get algorithm parameters."""
    
    def setParameters(self, param: Param) -> None:
        """Set algorithm parameters."""

Feature Detection Algorithms

Centroided Data Feature Detection

class FeatureFinderAlgorithmPicked:
    def __init__(self) -> None: ...
    
    def run(self, input: MSExperiment, features: FeatureMap, 
            params: Param, seeds: FeatureMap) -> None:
        """
        Detect features in picked/centroided MS data.
        
        Args:
            input (MSExperiment): Input experiment with picked peaks
            features (FeatureMap): Output feature map
            params (Param): Algorithm parameters
            seeds (FeatureMap): Feature seeds (optional)
        """
    
    def getParameters(self) -> Param:
        """
        Get default parameters.
        
        Returns:
            Param: Default parameter configuration
        """

class FeatureFinderAlgorithmIsotopeWavelet:
    def __init__(self) -> None: ...
    
    def run(self, input: MSExperiment, features: FeatureMap, 
            params: Param, seeds: FeatureMap) -> None:
        """
        Detect features using isotope wavelet method.
        
        Args:
            input (MSExperiment): Input experiment
            features (FeatureMap): Output feature map
            params (Param): Algorithm parameters
            seeds (FeatureMap): Feature seeds (optional)
        """

Advanced Feature Detection

class FeatureFinderMultiplex:
    def __init__(self) -> None: ...
    
    def run(self, input: MSExperiment, features: FeatureMap, 
            params: Param) -> None:
        """
        Detect multiplex-labeled features.
        
        Args:
            input (MSExperiment): Input experiment
            features (FeatureMap): Output feature map
            params (Param): Algorithm parameters including label information
        """

class FeatureFinderIdentification:
    def __init__(self) -> None: ...
    
    def run(self, input: MSExperiment, peptide_ids: list, 
            features: FeatureMap, params: Param) -> None:
        """
        Extract features based on peptide identifications.
        
        Args:
            input (MSExperiment): Input experiment
            peptide_ids (list[PeptideIdentification]): Peptide identifications
            features (FeatureMap): Output feature map
            params (Param): Algorithm parameters
        """

Feature Data Structures

Feature

Individual detected feature with quantitative information.

class Feature:
    def __init__(self) -> None: ...
    
    def getRT(self) -> float:
        """
        Get retention time of feature centroid.
        
        Returns:
            float: Retention time in seconds
        """
    
    def setRT(self, rt: float) -> None:
        """
        Set retention time.
        
        Args:
            rt (float): Retention time in seconds
        """
    
    def getMZ(self) -> float:
        """
        Get m/z of feature centroid.
        
        Returns:
            float: m/z value
        """
    
    def setMZ(self, mz: float) -> None:
        """
        Set m/z value.
        
        Args:
            mz (float): m/z value
        """
    
    def getIntensity(self) -> float:
        """
        Get feature intensity.
        
        Returns:
            float: Feature intensity
        """
    
    def setIntensity(self, intensity: float) -> None:
        """
        Set feature intensity.
        
        Args:
            intensity (float): Feature intensity
        """
    
    def getOverallQuality(self) -> float:
        """
        Get overall feature quality score.
        
        Returns:
            float: Quality score (0-1)
        """
    
    def setOverallQuality(self, quality: float) -> None:
        """
        Set overall quality score.
        
        Args:
            quality (float): Quality score
        """
    
    def getCharge(self) -> int:
        """
        Get feature charge state.
        
        Returns:
            int: Charge state
        """
    
    def setCharge(self, charge: int) -> None:
        """
        Set charge state.
        
        Args:
            charge (int): Charge state
        """
    
    def getConvexHull(self) -> ConvexHull2D:
        """
        Get feature convex hull boundary.
        
        Returns:
            ConvexHull2D: 2D convex hull in RT/m/z space
        """
    
    def setConvexHull(self, hull: ConvexHull2D) -> None:
        """
        Set convex hull boundary.
        
        Args:
            hull (ConvexHull2D): 2D convex hull
        """
    
    def getSubordinates(self) -> list[Feature]:
        """
        Get subordinate features (isotope peaks, etc.).
        
        Returns:
            list[Feature]: List of subordinate features
        """
    
    def getPeptideIdentifications(self) -> list[PeptideIdentification]:
        """
        Get peptide identifications assigned to feature.
        
        Returns:
            list[PeptideIdentification]: Assigned identifications
        """
    
    def setPeptideIdentifications(self, ids: list[PeptideIdentification]) -> None:
        """
        Set peptide identifications.
        
        Args:
            ids (list[PeptideIdentification]): Identifications to assign
        """
    
    def getUniqueId(self) -> int:
        """
        Get unique feature identifier.
        
        Returns:
            int: Unique ID
        """

FeatureMap

Container for multiple features with metadata.

class FeatureMap:
    def __init__(self) -> None: ...
    
    def size(self) -> int:
        """
        Get number of features.
        
        Returns:
            int: Number of features
        """
    
    def empty(self) -> bool:
        """
        Check if feature map is empty.
        
        Returns:
            bool: True if no features
        """
    
    def push_back(self, feature: Feature) -> None:
        """
        Add feature to map.
        
        Args:
            feature (Feature): Feature to add
        """
    
    def __getitem__(self, index: int) -> Feature:
        """
        Get feature by index.
        
        Args:
            index (int): Feature index
            
        Returns:
            Feature: The feature at given index
        """
    
    def clear(self) -> None:
        """Remove all features."""
    
    def updateRanges(self) -> None:
        """Update RT/m/z ranges from features."""
    
    def getMinRT(self) -> float:
        """Get minimum retention time."""
    
    def getMaxRT(self) -> float:
        """Get maximum retention time."""
    
    def getMinMZ(self) -> float:
        """Get minimum m/z."""
    
    def getMaxMZ(self) -> float:
        """Get maximum m/z."""
    
    def sortByRT(self) -> None:
        """Sort features by retention time."""
    
    def sortByMZ(self) -> None:
        """Sort features by m/z."""
    
    def sortByIntensity(self, reverse: bool = True) -> None:
        """
        Sort features by intensity.
        
        Args:
            reverse (bool): Sort in descending order
        """
    
    def getProteinIdentifications(self) -> list[ProteinIdentification]:
        """
        Get protein identifications.
        
        Returns:
            list[ProteinIdentification]: Protein IDs
        """
    
    def setProteinIdentifications(self, ids: list[ProteinIdentification]) -> None:
        """
        Set protein identifications.
        
        Args:
            ids (list[ProteinIdentification]): Protein IDs
        """
    
    def get_df(self, meta_values: list[str] = None, 
               export_peptide_identifications: bool = True) -> DataFrame:
        """
        Export features to pandas DataFrame.
        
        Args:
            meta_values (list[str]): Meta values to include
            export_peptide_identifications (bool): Include peptide ID info
            
        Returns:
            DataFrame: Feature data in tabular format
        """
    
    def get_assigned_peptide_identifications(self) -> list[PeptideIdentification]:
        """
        Get all peptide identifications assigned to features.
        
        Returns:
            list[PeptideIdentification]: Assigned peptide IDs
        """

Signal Processing

Filtering and Smoothing

class GaussFilter:
    def __init__(self) -> None: ...
    
    def filter(self, input: MSExperiment, output: MSExperiment) -> None:
        """
        Apply Gaussian smoothing to experiment.
        
        Args:
            input (MSExperiment): Input experiment
            output (MSExperiment): Smoothed output experiment
        """
    
    def getParameters(self) -> Param:
        """Get filter parameters."""
    
    def setParameters(self, param: Param) -> None:
        """Set filter parameters."""

class SavitzkyGolayFilter:
    def __init__(self) -> None: ...
    
    def filter(self, input: MSSpectrum, output: MSSpectrum) -> None:
        """
        Apply Savitzky-Golay smoothing to spectrum.
        
        Args:
            input (MSSpectrum): Input spectrum
            output (MSSpectrum): Smoothed spectrum
        """

class LinearResampler:
    def __init__(self) -> None: ...
    
    def rasterize(self, input: MSExperiment, output: MSExperiment, 
                  min_mz: float, max_mz: float, spacing: float) -> None:
        """
        Resample spectra to regular m/z grid.
        
        Args:
            input (MSExperiment): Input experiment
            output (MSExperiment): Resampled experiment
            min_mz (float): Minimum m/z
            max_mz (float): Maximum m/z
            spacing (float): m/z spacing
        """

Quality Assessment

Feature Quality Metrics

class FeatureQuality:
    def __init__(self) -> None: ...
    
    def compute(self, feature: Feature, experiment: MSExperiment) -> None:
        """
        Compute quality metrics for feature.
        
        Args:
            feature (Feature): Feature to assess
            experiment (MSExperiment): Source experiment
        """
    
    def getParameters(self) -> Param:
        """Get quality assessment parameters."""

class QcBase:
    def __init__(self) -> None: ...
    
    def compute(self, feature_map: FeatureMap, experiment: MSExperiment, 
                protein_ids: list, peptide_ids: list) -> None:
        """
        Compute quality control metrics.
        
        Args:
            feature_map (FeatureMap): Detected features
            experiment (MSExperiment): Source experiment
            protein_ids (list[ProteinIdentification]): Protein IDs
            peptide_ids (list[PeptideIdentification]): Peptide IDs
        """

Usage Examples

Complete Feature Detection Workflow

import pyopenms

# Load raw data
exp = pyopenms.MSExperiment()
pyopenms.MzMLFile().load("raw_data.mzML", exp)

# Peak picking
picker = pyopenms.PeakPickerHiRes()
picked_exp = pyopenms.MSExperiment()
picker.pickExperiment(exp, picked_exp)

# Feature detection
features = pyopenms.FeatureMap()
finder = pyopenms.FeatureFinderAlgorithmPicked()

# Configure parameters
params = finder.getParameters()
params.setValue("mass_trace:mz_tolerance", 0.004)
params.setValue("mass_trace:min_spectra", 10)
params.setValue("isotopic_pattern:charge_low", 1)
params.setValue("isotopic_pattern:charge_high", 4)

# Run feature detection
seeds = pyopenms.FeatureMap()  # Empty seed map
finder.run(picked_exp, features, params, seeds)

print(f"Detected {features.size()} features")

# Sort by intensity and show top features
features.sortByIntensity(reverse=True)
for i in range(min(10, features.size())):
    feature = features[i]
    print(f"Feature {i+1}: RT={feature.getRT():.2f}, "
          f"m/z={feature.getMZ():.4f}, "
          f"Intensity={feature.getIntensity():.0f}, "
          f"Charge={feature.getCharge()}")

# Save results
pyopenms.FeatureXMLFile().store("features.featureXML", features)

Feature-Based Quantification

import pyopenms

# Load features from multiple runs
feature_maps = []
file_names = ["run1_features.featureXML", "run2_features.featureXML", "run3_features.featureXML"]

for filename in file_names:
    features = pyopenms.FeatureMap()
    pyopenms.FeatureXMLFile().load(filename, features)
    feature_maps.append(features)

# Convert to DataFrames for analysis
dfs = []
for i, features in enumerate(feature_maps):
    df = features.get_df()
    df['run'] = f'run_{i+1}'
    dfs.append(df)

# Combine all runs
import pandas as pd
combined_df = pd.concat(dfs, ignore_index=True)

# Basic statistics
print("Feature count per run:")
print(combined_df.groupby('run').size())

print("\nIntensity statistics:")
print(combined_df.groupby('run')['intensity'].describe())

Identification-Guided Feature Extraction

import pyopenms

# Load raw data and identifications
exp = pyopenms.MSExperiment()
pyopenms.MzMLFile().load("data.mzML", exp)

protein_ids = []
peptide_ids = []
pyopenms.IdXMLFile().load("identifications.idXML", protein_ids, peptide_ids)

# Use identifications to guide feature detection
finder = pyopenms.FeatureFinderIdentification()
features = pyopenms.FeatureMap()

# Configure parameters for ID-based extraction
params = finder.getParameters()
params.setValue("extract:mz_window", 0.01)
params.setValue("extract:rt_window", 60.0)

# Run ID-guided feature extraction
finder.run(exp, peptide_ids, features, params)

print(f"Extracted {features.size()} features based on {len(peptide_ids)} identifications")

# Export combined feature and identification data
df = features.get_df(export_peptide_identifications=True)
print(df[['RT', 'mz', 'intensity', 'peptide_sequence', 'peptide_score']].head())

Advanced Peak Picking Configuration

import pyopenms

# Configure high-resolution peak picker
picker = pyopenms.PeakPickerHiRes()
params = picker.getParameters()

# Fine-tune parameters for high-resolution data
params.setValue("signal_to_noise", 1.0)
params.setValue("spacing_difference_gap", 4.0)
params.setValue("spacing_difference", 1.5)
params.setValue("missing", 1)
params.setValue("ms_levels", [1, 2])  # Pick both MS1 and MS2

picker.setParameters(params)

# Apply to experiment
exp = pyopenms.MSExperiment()
pyopenms.MzMLFile().load("profile_data.mzML", exp)

picked_exp = pyopenms.MSExperiment()
picker.pickExperiment(exp, picked_exp)

print(f"Input: {sum(s.size() for s in exp)} total peaks")
print(f"Output: {sum(s.size() for s in picked_exp)} picked peaks")

# Save picked data
pyopenms.MzMLFile().store("picked_data.mzML", picked_exp)

Install with Tessl CLI

npx tessl i tessl/pypi-pyopenms

docs

alignment.md

chemistry.md

feature-detection.md

file-io.md

index.md

ms-data.md

peptide-protein.md

targeted-analysis.md

tile.json