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

fixing precursors property #280

Closed liquidcarbon closed 2 years ago

liquidcarbon commented 2 years ago

otherwise error:

site-packages/pymzml/spec.py in precursors(self)
    169             precursor(list): list of precursor ids for this spectrum.
    170         """
--> 171         if self._precursors is None:
    172             precursors = self.element.findall(
    173                 "./{ns}precursorList/{ns}precursor".format(ns=self.ns)

AttributeError: 'Spectrum' object has no attribute '_precursors'
sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

MKoesters commented 2 years ago

Hi @liquidcarbon ,

Thanks for your contribution! I'll have a look at the PR, I might change your fix a little bit.

Please also notice that precursors is deprecated, I suggest you switch to using selected_precursors

Best, Manuel

liquidcarbon commented 2 years ago

Please also notice that precursors is deprecated, I suggest you switch to using selected_precursors

Thanks for looking into it! My impression was precursors gives you MS1 scan ID whereas selected_precursors return mz and intensity (and sometimes charge, if provided in MZML). MS1 scan ID is helpful, would be nice to keep it.

Speaking of charge, do you happen to know why in MZML files sometimes you have charge information, and sometimes don't?

                <selectedIon>
                  <cvParam cvRef="MS" accession="MS:1000744" name="selected ion m/z" value="388.712829589844" unitCvRef="MS" unitAccession="MS:1000040" unitName="m/z"/>
                  <cvParam cvRef="MS" accession="MS:1000041" name="charge state" value="2"/>  # sometimes this line is absent
                  <cvParam cvRef="MS" accession="MS:1000042" name="peak intensity" value="4.435413823438e07" unitCvRef="MS" unitAccession="MS:1000131" unitName="number of detector counts"/>
                </selectedIon>
MKoesters commented 2 years ago

Ups, the spectrum ID was supposed to be already part of selected_precursors, precursors will definitely stay until it moved to selected_precursors

Speaking of charge, do you happen to know why in MZML files sometimes you have charge information, and sometimes don't?

I actually don't know, but I could imagine that the mass spec was simply not able to determine the charge state (maybe due to low resolution for older instruments or missing isotope peaks? @fu @StSchulze Do you have any idea why that happens?