Skip to content

Instantly share code, notes, and snippets.

@RalfG
Last active Jun 30, 2021
Embed
What would you like to do?
ProXI, USI, pyteomics, and spectrum_utils

Directly download and visualize any peptide spectrum in Python

Using HUPO-PSI ProXI, Universal Spectrum Identifier (USI), Pyteomics and spectrum_utils:

from pyteomics.usi import USI, proxi
from pyteomics.mass.unimod import Unimod
import spectrum_utils.spectrum as sus
import spectrum_utils.plot as sup


def reshape_attributes(attributes):
    return {item["name"]: item["value"] for item in attributes}


unimod = Unimod()

# Input
modified_sequence = "IENN[UNIMOD:34]DNKPVTNSR"
unmodified_sequence = "IENNDNKPVTNSR"
modifications = {4: unimod.get(34).monoisotopic_mass}
charge = 2

usi = USI(
    "mzspec",
    "PXD000561",
    "Adult_CD8Tcells_Gel_Elite_44_f12",
    "scan",
    "1770",
    modified_sequence + "/" + str(charge)
)

# Get spectrum through ProXI
proxi_response = proxi(usi)
proxi_attributes = reshape_attributes(proxi_response["attributes"])

# Process spectrum, annotate, and plot
spectrum = (
    sus.MsmsSpectrum(
        identifier=usi,
        precursor_mz=proxi_attributes["isolation window target m/z"],
        precursor_charge=int(proxi_attributes["charge state"]),
        mz=proxi_response["m/z array"],
        intensity=proxi_response["intensity array"],
        peptide=unmodified_sequence,
        modifications=modifications
    )
    .filter_intensity(0.01, 50)
    #.scale_intensity('root')
    .annotate_peptide_fragments(0.5, 'Da', ion_types='aby')
)

spectrum = (
    sup.spectrum(spectrum)
)

spectrum

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment