bittremieux / spectrum_utils

Python package for efficient mass spectrometry data processing and visualization
https://spectrum-utils.readthedocs.io/
Apache License 2.0
138 stars 20 forks source link

'MsmsSpectrumJit' object has no attribute 'annotate_proforma' #51

Closed danyunghsu closed 1 year ago

danyunghsu commented 1 year ago

Hi Wout, This is an amazing tool to visualize annotated spectra, but i have a problem when running the tool with python. The error tells that i have no package containing 'annotate_proforma'. I have installed spectrum_utils using pip, and my python version is 3.11. Below is my python script and the error.

import matplotlib.pyplot as plt
import pyteomics.mgf
import spectrum_utils.spectrum as sus
import spectrum_utils.plot as sup
import numba as nb
import numpy as np

min_peaks = 10
min_mz, max_mz = 100, 1400
fragment_tol_mass, fragment_tol_mode = 0.02, "Da"
min_intensity = 0.05
max_num_peaks = 150

for spec_dict in pyteomics.mgf.read(r"F:\myb_mgf\log\1\LUMOS2_20220414_XP_MSH_4TI_Log_1_R1_HCDIT\LUMOS2_20220414_XP_MSH_4TI_Log_1_R1.26848.26848.3.0.mgf"):
    # Omit invalid spectra.
    peptide="VGCFR[Phospho]PPTVPAGTSR"
    if (
        len(spec_dict["m/z array"]) < min_peaks
        or "charge" not in spec_dict["params"]
    ):
        continue

    spectrum = sus.MsmsSpectrum(
        spec_dict["params"]["title"],
        spec_dict["params"]["pepmass"][0],
        spec_dict["params"]["charge"][0],
        spec_dict["m/z array"],
        spec_dict["intensity array"],
        float(spec_dict["params"]["rtinseconds"]),
    )._inner
    spectrum.annotate_proforma(peptide,fragment_tol_mass=0.5,fragment_tol_mode="Da",ion_types="by",neutral_losses={"H3PO4": -97.9769})

    fig, ax = plt.subplots(figsize=(12, 6))
    sup.spectrum(spectrum, grid=False, ax=ax)
    ax.set_title(peptide, fontdict={"fontsize": "xx-large"})
    ax.spines["right"].set_visible(False)
    ax.spines["top"].set_visible(False)
    plt.savefig("F:\neutral_losses_1.png", dpi=300, bbox_inches="tight", transparent=True)
    plt.close()

屏幕截图 2023-08-17 110503

I'm not good at python and I desperately need your help! Thanks in advance, Danyung

bittremieux commented 1 year ago

Hi Danyung, you should remove the ._inner part in line 30, then it should work. The "inner" is a hidden subclass of an MsmsSpectrum to facilitate just-in-time compilation for computational efficiency, but is not intended to be used directly (and hence not explicitly documented).

danyunghsu commented 1 year ago

Problem solved, Thanks! Danyung