pymzml / pymzML

pymzML - an interface between Python and mzML Mass spectrometry Files
https://pymzml.readthedocs.io/en/latest/
MIT License
158 stars 91 forks source link

ms3 not supported #296

Closed fu closed 2 years ago

fu commented 2 years ago

Describe the bug

                     ms_level = spectrum.ms_level
>                   spectrum.measured_precision = self.ms_precisions[ms_level]
E                   KeyError: 3

../../../.virtualenvs/u2_p/lib/python3.8/site-packages/pymzml/run.py:158: KeyError

To Reproduce Parse a MS3 containing mzML

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

MKoesters commented 2 years ago

How did you initialize the reader?

Supplying the run with MS_precisions should do the trick if you specfiy the key for 1, 2 and 3 Alternatively, setting MS1_Precision and MSn_Precision should also work

def __init__(
        self,
        path_or_file,
        MS_precisions=None,
        obo_version=None,
        build_index_from_scratch=False,
        skip_chromatogram=True,
        index_regex=None,
        resolution_dict=None,
        mz_resolution_reference=200,
        **kwargs,
    ):
        """Initialize and set required attributes."""
        self.index_regex = index_regex
        self.build_index_from_scratch = build_index_from_scratch
        self.skip_chromatogram = skip_chromatogram
        self.mz_resolution_reference = mz_resolution_reference
        if MS_precisions is None:
            MS_precisions = {}
            if "MS1_Precision" in kwargs.keys():
                MS_precisions[1] = kwargs["MS1_Precision"]
            if "MSn_Precision" in kwargs.keys():
                MS_precisions[2] = kwargs["MSn_Precision"]
                MS_precisions[3] = kwargs["MSn_Precision"]

        if resolution_dict is None:
            resolution_dict = {}
        self.resolution_dict = {
            None: 70_000,
            1: 70_000,
            2: 35_000,
        }
        self.resolution_dict.update(resolution_dict)

        # Parameters
        self.ms_precisions = {
            None: 0.0001,  # if spectra does not contain ms_level information
            # e.g. UV-chromatograms (thanks pyeguy) then ms_level is
            # returned as None
            0: 0.0001,
            1: 5e-6,
            2: 20e-6,
            3: 20e-6,
        }
        self.ms_precisions.update(MS_precisions)
fu commented 2 years ago

I had 2.5.0 installed. I see you added the missing ms3 precision with 2.5.1 !

https://github.com/pymzml/pymzML/commit/205e96ca81fa170e1a28192efb5200a3463dce57

Thanks :)

fu commented 2 years ago

Maybe worth adding a safe fall back for MSn in general ? Dunno