Skip to content

Instantly share code, notes, and snippets.

@RalfG
Last active June 30, 2021 22:01
Show Gist options
  • Save RalfG/81f5dff72e5913fde696ec7eb3df6ee7 to your computer and use it in GitHub Desktop.
Save RalfG/81f5dff72e5913fde696ec7eb3df6ee7 to your computer and use it in GitHub Desktop.
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