Skip to content

Latest commit

 

History

History
422 lines (295 loc) · 8.67 KB

python_api.md

File metadata and controls

422 lines (295 loc) · 8.67 KB

PhosphoMojo Python API Reference

This document provides detailed documentation for the PhosphoMojo Python API.

Table of Contents

PhosphoAPI

The main API class for PhosphoMojo analysis.

Initialization

from phosphomojo.api import PhosphoAPI

# Default configuration
api = PhosphoAPI()

# Custom configuration
from phosphomojo.config import PhosphoConfig
config = PhosphoConfig()
config.mass_tolerance = 10.0
config.num_threads = 8
api = PhosphoAPI(config)

Data Loading

load_spectra(file_path: str) -> int

Load mass spectrometry spectra from a file.

Parameters:

  • file_path (str): Path to spectra file (mzML, mzXML, MGF)

Returns:

  • int: Number of spectra loaded

Example:

count = api.load_spectra("experiment.mzML")
print(f"Loaded {count} spectra")

load_database(file_path: str) -> int

Load protein database from a FASTA file.

Parameters:

  • file_path (str): Path to FASTA file

Returns:

  • int: Number of proteins loaded

Example:

count = api.load_database("proteins.fasta")
print(f"Loaded {count} proteins")

load_results(file_path: str) -> int

Load analysis results from MaxQuant or other software.

Parameters:

  • file_path (str): Path to results file

Returns:

  • int: Number of results loaded

Example:

count = api.load_results("MaxQuant/Phospho (STY)Sites.txt")
print(f"Loaded {count} phosphosites")

Analysis

analyze() -> dict

Run the complete analysis pipeline.

Returns:

  • dict: Analysis statistics

Example:

stats = api.analyze()
print(f"Peptides: {stats['peptides']}")
print(f"Phosphosites: {stats['phosphosites']}")

identify_peptides() -> list

Identify peptides from spectra.

Returns:

  • list: List of identified peptides

Example:

peptides = api.identify_peptides()
for peptide in peptides:
    print(f"{peptide.sequence}: score={peptide.score}")

identify_phosphosites() -> list

Identify phosphorylation sites.

Returns:

  • list: List of phosphorylation sites

Example:

sites = api.identify_phosphosites()
for site in sites:
    print(f"{site.protein_accession}_{site.residue}{site.position}")

quantify_sites() -> list

Quantify phosphorylation sites.

Returns:

  • list: List of quantitation results

Example:

results = api.quantify_sites()
for result in results:
    print(f"{result.id}: mean_intensity={result.get_mean_intensity()}")

analyze_differential(group1: list, group2: list) -> list

Perform differential phosphorylation analysis.

Parameters:

  • group1 (list): Sample names in group 1
  • group2 (list): Sample names in group 2

Returns:

  • list: List of statistical results

Example:

control = ["control_1", "control_2", "control_3"]
treatment = ["treatment_1", "treatment_2", "treatment_3"]

results = api.analyze_differential(control, treatment)
for result in results:
    if result.is_significant:
        print(f"{result.id}: FC={result.fold_change}, p={result.p_value}")

analyze_motifs() -> list

Analyze sequence motifs around phosphorylation sites.

Returns:

  • list: List of motif results

Example:

motifs = api.analyze_motifs()
for motif in motifs:
    print(f"{motif.phospho_site}: {motif.best_motif}")

Results

get_peptides() -> list

Get identified peptides.

Returns:

  • list: List of Peptide objects

get_phosphosites() -> list

Get phosphorylation sites.

Returns:

  • list: List of PhosphoSite objects

get_quantitation_results() -> list

Get quantitation results.

Returns:

  • list: List of QuantitationResult objects

get_statistical_results() -> list

Get statistical analysis results.

Returns:

  • list: List of StatisticalResult objects

get_motif_results() -> list

Get motif analysis results.

Returns:

  • list: List of MotifResult objects

get_significant_sites(p_threshold=0.05, fc_threshold=2.0) -> list

Get statistically significant phosphorylation sites.

Parameters:

  • p_threshold (float): P-value threshold (default: 0.05)
  • fc_threshold (float): Fold change threshold (default: 2.0)

Returns:

  • list: List of significant PhosphoSite objects

Example:

significant = api.get_significant_sites(p_threshold=0.01, fc_threshold=3.0)
print(f"Found {len(significant)} significant sites")

Export

export_results(output_dir: str)

Export results to files.

Parameters:

  • output_dir (str): Output directory path

Example:

api.export_results("output/")

get_summary() -> str

Get a summary of the analysis results.

Returns:

  • str: Summary string

Example:

summary = api.get_summary()
print(summary)

Configuration

PhosphoConfig

Configuration class for PhosphoMojo analysis.

from phosphomojo.config import PhosphoConfig

config = PhosphoConfig()

# Mass spectrometry parameters
config.mass_tolerance = 20.0  # ppm
config.fragment_tolerance = 0.5  # Da

# Peptide search parameters
config.enzyme = "trypsin"
config.max_missed_cleavages = 2
config.min_peptide_length = 7
config.max_peptide_length = 30

# Phosphorylation parameters
config.localization_threshold = 0.75
config.phospho_residues = "STY"

# Statistical parameters
config.p_value_threshold = 0.05
config.fold_change_threshold = 2.0
config.multiple_testing_correction = "BH"

# Performance parameters
config.num_threads = 4
config.batch_size = 1000

Data Types

Peptide

Represents an identified peptide.

Attributes:

  • sequence (str): Amino acid sequence
  • charge (int): Precursor charge state
  • mass (float): Monoisotopic mass
  • score (float): Identification score
  • is_phospho (bool): Whether peptide contains phosphorylation
  • modifications (list): List of modifications

PhosphoSite

Represents a phosphorylation site.

Attributes:

  • protein_accession (str): Protein accession number
  • residue (str): Phosphorylated residue (S, T, or Y)
  • position (int): Position in protein (1-indexed)
  • peptide_sequence (str): Peptide sequence
  • localization_probability (float): Localization probability (0-1)
  • intensity (float): Signal intensity
  • fold_change (float): Fold change between conditions
  • p_value (float): Statistical p-value

QuantitationResult

Represents quantitation results.

Attributes:

  • id (str): Feature identifier
  • intensities (dict): Intensity values per sample
  • fold_changes (dict): Fold changes per comparison
  • is_significant (bool): Whether significantly different

StatisticalResult

Represents statistical analysis results.

Attributes:

  • id (str): Feature identifier
  • comparison (str): Comparison name
  • p_value (float): Raw p-value
  • adjusted_p_value (float): Adjusted p-value
  • fold_change (float): Fold change
  • log2_fold_change (float): Log2 fold change
  • is_significant (bool): Whether statistically significant

MotifResult

Represents motif analysis results.

Attributes:

  • id (str): Result identifier
  • phospho_site (str): Phosphosite ID
  • matched_motifs (list): List of matched motifs
  • best_motif (str): Best matching motif
  • kinase_predictions (dict): Predicted kinases

Examples

Basic Analysis

from phosphomojo.api import PhosphoAPI

# Initialize
api = PhosphoAPI()

# Load data
api.load_spectra("experiment.mzML")
api.load_database("proteins.fasta")

# Run analysis
stats = api.analyze()

# Get results
phosphosites = api.get_phosphosites()
print(f"Found {len(phosphosites)} phosphosites")

# Export
api.export_results("output/")

Differential Analysis

from phosphomojo.api import PhosphoAPI

api = PhosphoAPI()
api.load_spectra("experiment.mzML")
api.load_database("proteins.fasta")
api.analyze()

# Define groups
control = ["control_1", "control_2", "control_3"]
treatment = ["treatment_1", "treatment_2", "treatment_3"]

# Differential analysis
results = api.analyze_differential(control, treatment)

# Get significant sites
significant = api.get_significant_sites(p_threshold=0.05)
for site in significant:
    print(f"{site.protein_accession}_{site.residue}{site.position}")

Motif Analysis

from phosphomojo.api import PhosphoAPI

api = PhosphoAPI()
api.load_results("Phospho (STY)Sites.txt")

# Analyze motifs
motifs = api.analyze_motifs()

for motif in motifs:
    print(f"Site: {motif.phospho_site}")
    print(f"Motif: {motif.best_motif}")
    print(f"Kinase: {motif.get_top_kinase()}")