Esempio n. 1
0
 def precursor_information(self) -> List[PrecursorInformation]:
     out = []
     for _, info in self.extended_index.msn_ids.items():
         mz = info['mz']
         prec_neutral_mass = info['neutral_mass']
         charge = info['charge']
         if charge == 'ChargeNotProvided':
             charge = ChargeNotProvided
         intensity = info['intensity']
         precursor_scan_id = info['precursor_scan_id']
         product_scan_id = info['product_scan_id']
         orphan = info.get('orphan', False)
         coisolation = info.get('coisolation', [])[:]
         defaulted = info.get('defaulted', False)
         pinfo = PrecursorInformation(mz,
                                      intensity,
                                      charge,
                                      precursor_scan_id,
                                      self,
                                      prec_neutral_mass,
                                      charge,
                                      intensity,
                                      product_scan_id=product_scan_id,
                                      orphan=orphan,
                                      coisolation=coisolation,
                                      defaulted=defaulted)
         if prec_neutral_mass is None or charge is None:
             continue
         out.append(pinfo)
     return out
Esempio n. 2
0
 def precursor_information(self):
     out = []
     for key, info in self.extended_index.msn_ids.items():
         mz = info['mz']
         neutral_mass = info['neutral_mass']
         charge = info['charge']
         if charge == 'ChargeNotProvided':
             charge = ChargeNotProvided
         intensity = info['intensity']
         precursor_scan_id = info['precursor_scan_id']
         product_scan_id = info['product_scan_id']
         orphan = info.get('orphan', False)
         defaulted = info.get('defaulted', False)
         pinfo = PrecursorInformation(mz,
                                      intensity,
                                      charge,
                                      precursor_scan_id,
                                      self,
                                      neutral_mass,
                                      charge,
                                      intensity,
                                      product_scan_id=product_scan_id,
                                      orphan=orphan,
                                      defaulted=defaulted)
         out.append(pinfo)
     return out
Esempio n. 3
0
    def get_precursor_information(self, bind=None):
        '''Create a list of :class:`~.PrecursorInformation` objects
        from :attr:`msn_ids`'s records.

        Returns
        -------
        list
        '''
        out = []
        for _, info in self.msn_ids.items():
            mz = info['mz']
            neutral_mass = info['neutral_mass']
            if neutral_mass is None:
                continue
            charge = info['charge']
            if charge == "ChargeNotProvided":
                charge = ChargeNotProvided
            intensity = info['intensity']
            precursor_scan_id = info['precursor_scan_id']
            product_scan_id = info['product_scan_id']
            pinfo = PrecursorInformation(
                mz, intensity, charge, precursor_scan_id,
                bind, neutral_mass, charge, intensity,
                product_scan_id=product_scan_id,
                coisolation=info.get('coisolation'))
            out.append(pinfo)
        return out
 def _precursor_information(self, scan):
     scan_number = scan.scan_number
     filt = self._source.GetFilterForScanNumber(scan_number + 1)
     precursor_mz = filt.GetMass(filt.MSOrder - 2)
     trailers = self._trailer_values(scan)
     charge = int(trailers.get("Charge State", 0))
     if charge == 0:
         charge = ChargeNotProvided
     inten = 0
     precursor_scan_number = None
     if precursor_scan_number is None:
         last_index = self._scan_index(scan) - 1
         current_level = self._ms_level(scan)
         i = 0
         while last_index >= 0 and i < 100:
             prev_scan = self.get_scan_by_index(last_index)
             if prev_scan.ms_level >= current_level:
                 last_index -= 1
             else:
                 precursor_scan_number = prev_scan._data.scan_number
                 break
             i += 1
     if precursor_scan_number is not None:
         precursor_scan_id = self.get_scan_by_index(
             precursor_scan_number).id
     return PrecursorInformation(precursor_mz,
                                 inten,
                                 charge,
                                 precursor_scan_id,
                                 source=self,
                                 product_scan_id=self._scan_id(scan))
Esempio n. 5
0
 def _precursor_information(self, scan):
     if self._ms_level(scan) == 1:
         return None
     scan_number = scan.scan_number
     pinfo_struct = self._source.GetPrecursorInfoFromScanNum(scan_number)
     precursor_scan_number = None
     labels, flags, _ = self._source.GetAllMSOrderData(scan_number)
     if pinfo_struct:
         mz = pinfo_struct.monoIsoMass
         charge = pinfo_struct.chargeState
         intensity = float(labels.intensity[0])
         precursor_scan_number = pinfo_struct.scanNumber
     else:
         mz = labels.mass[0]
         intensity = float(labels.intensity[0])
         charge = labels.charge[0]
     if not charge:
         charge = ChargeNotProvided
     trailer = self._source.GetTrailerExtraForScanNum(scan_number)
     _mz = trailer.get('Monoisotopic M/Z', 0.0)
     if _mz > 0:
         mz = _mz
     _charge = trailer.get('Charge State', 0)
     if _charge != 0:
         charge = _charge
     # Guess which previous scan was the precursor by iterating
     # backwards until a scan is found with a lower MS level
     if precursor_scan_number is None:
         last_index = self._scan_index(scan) - 1
         current_level = self._ms_level(scan)
         i = 0
         while last_index > 0 and i < 100:
             prev_scan = self.get_scan_by_index(last_index)
             if prev_scan.ms_level >= current_level:
                 last_index -= 1
             else:
                 precursor_scan_number = prev_scan._data.scan_number
                 break
             i += 1
     if intensity is None:
         intensity = 0.0
     if mz is None:
         mz = 0.0
     if charge is None or charge == 0:
         charge = ChargeNotProvided
     pinfo = PrecursorInformation(mz,
                                  intensity,
                                  charge,
                                  _make_id(precursor_scan_number),
                                  0,
                                  0,
                                  0,
                                  product_scan_id=_make_id(
                                      scan.scan_number))
     return pinfo
Esempio n. 6
0
 def _precursor_information(self, scan):
     if self._ms_level(scan) < 2:
         return None
     spectrum_obj = self._get_spectrum_obj(scan)
     precursor_scan_id = make_scan_id_string(spectrum_obj.ParentScanId)
     n, ions = spectrum_obj.GetPrecursorIon()
     if n < 1:
         return None
     mz = ions[0]
     charge, _ = spectrum_obj.GetPrecursorCharge()
     intensity, _ = spectrum_obj.GetPrecursorIntensity()
     return PrecursorInformation(mz, intensity, charge, precursor_scan_id, self)
Esempio n. 7
0
    def _precursor_information(self, scan):
        scan_number = scan.scan_number
        filt = self._source.GetFilterForScanNumber(scan_number + 1)
        precursor_mz = filt.GetMass(filt.MSOrder - 2)
        trailers = self._trailer_values(scan)
        _precursor_mz = float(trailers.get("Monoisotopic M/Z", 0))
        if _precursor_mz > 0:
            precursor_mz = _precursor_mz

        # imitate proteowizard's firmware bug correction
        isolation_window = self._isolation_window(scan)
        if (isolation_window.upper + isolation_window.lower) / 2 <= 2.0:
            if (isolation_window.target - 3.0 > precursor_mz) or (
                    isolation_window.target + 2.5 < precursor_mz):
                precursor_mz = isolation_window.target
        elif precursor_mz not in isolation_window:
            precursor_mz = isolation_window.target
        charge = int(trailers.get("Charge State", 0))
        if charge == 0:
            charge = ChargeNotProvided
        inten = 0
        precursor_scan_number = None
        if precursor_scan_number is None:
            last_index = self._scan_index(scan) - 1
            current_level = self._ms_level(scan)
            i = 0
            while last_index >= 0 and i < 100:
                prev_scan = self.get_scan_by_index(last_index)
                if prev_scan.ms_level >= current_level:
                    last_index -= 1
                else:
                    precursor_scan_number = prev_scan._data.scan_number
                    break
                i += 1
        if precursor_scan_number is not None:
            precursor_scan_id = self.get_scan_by_index(
                precursor_scan_number).id
        else:
            import warnings
            warnings.warn("Could not resolve precursor scan for %s" %
                          (self._scan_id(scan), ))
            precursor_scan_id = None
        return PrecursorInformation(precursor_mz,
                                    inten,
                                    charge,
                                    precursor_scan_id,
                                    source=self,
                                    product_scan_id=self._scan_id(scan))
Esempio n. 8
0
 def precursor_information(self):
     out = []
     for key, info in self.extended_index.msn_ids.items():
         mz = info['mz']
         neutral_mass = info['neutral_mass']
         charge = info['charge']
         intensity = info['intensity']
         precursor_scan_id = info['precursor_scan_id']
         product_scan_id = info['product_scan_id']
         pinfo = PrecursorInformation(mz,
                                      intensity,
                                      charge,
                                      precursor_scan_id,
                                      self,
                                      neutral_mass,
                                      charge,
                                      intensity,
                                      product_scan_id=product_scan_id)
         out.append(pinfo)
     return out
Esempio n. 9
0
 def _precursor_information(self, scan):
     if self._ms_level(scan) == 1:
         return None
     set_mass_str = self.info_reader.GetScanItem(
         scan.function, scan.block if scan.block >= 0 else scan.scan,
         MassLynxRawDefs.MassLynxScanItem.SET_MASS.value)
     if set_mass_str:
         set_mass = float(set_mass_str)
     else:
         set_mass = 0.0
     if set_mass == 0:
         lower_bound, upper_bound = self.info_reader.GetAcquisitionMassRange(
             scan.function)
         set_mass = (lower_bound + upper_bound) / 2.
     pinfo = PrecursorInformation(set_mass,
                                  0,
                                  ChargeNotProvided,
                                  source=self,
                                  product_scan_id=scan.id)
     return pinfo
Esempio n. 10
0
 def get_precursor_information(self, bind=None):
     out = []
     for key, info in self.msn_ids.items():
         mz = info['mz']
         neutral_mass = info['neutral_mass']
         charge = info['charge']
         if charge == "ChargeNotProvided":
             charge = ChargeNotProvided
         intensity = info['intensity']
         precursor_scan_id = info['precursor_scan_id']
         product_scan_id = info['product_scan_id']
         pinfo = PrecursorInformation(mz,
                                      intensity,
                                      charge,
                                      precursor_scan_id,
                                      bind,
                                      neutral_mass,
                                      charge,
                                      intensity,
                                      product_scan_id=product_scan_id,
                                      coisolation=info.get('coisolation'))
         out.append(pinfo)
     return out
Esempio n. 11
0
    def _precursor_information(self, scan):
        if self._ms_level(scan) == 1:
            return None
        scan_number = scan.scan_number
        pinfo_struct = self._source.GetPrecursorInfoFromScanNum(scan_number)
        precursor_scan_number = None
        labels, flags, _ = self._source.GetAllMSOrderData(scan_number)
        if pinfo_struct:
            # this struct field is unreliable and may fall outside the
            # isolation window
            mz = pinfo_struct.monoIsoMass
            charge = pinfo_struct.chargeState
            intensity = float(labels.intensity[0])
            # this struct field is unreliable, and simple to infer
            # precursor_scan_number = pinfo_struct.scanNumber + 1
        else:
            mz = labels.mass[0]
            intensity = float(labels.intensity[0])
            charge = labels.charge[0]
        if not charge:
            charge = ChargeNotProvided
        trailer = self._source.GetTrailerExtraForScanNum(scan_number)
        _mz = trailer.get('Monoisotopic M/Z', 0.0)
        # prefer the trailer m/z if available?
        if _mz > 0:
            mz = _mz

        # imitate proteowizard's firmware bug correction
        isolation_window = self._isolation_window(scan)
        if (isolation_window.upper + isolation_window.lower) / 2 <= 2.0:
            if (isolation_window.target - 3.0 > mz) or (isolation_window.target + 2.5 < mz):
                mz = isolation_window.target
        elif mz not in isolation_window:
            mz = isolation_window.target
        _charge = trailer.get('Charge State', 0)
        if _charge != 0:
            charge = _charge
        # Guess which previous scan was the precursor by iterating
        # backwards until a scan is found with a lower MS level
        if precursor_scan_number is None:
            last_index = self._scan_index(scan) - 1
            current_level = self._ms_level(scan)
            i = 0
            while last_index >= 0 and i < 100:
                prev_scan = self.get_scan_by_index(last_index)
                if prev_scan.ms_level >= current_level:
                    last_index -= 1
                else:
                    precursor_scan_number = prev_scan._data.scan_number
                    break
                i += 1
        if intensity is None:
            intensity = 0.0
        if mz is None:
            mz = 0.0
        if charge is None or charge == 0:
            charge = ChargeNotProvided
        pinfo = PrecursorInformation(
            mz, intensity, charge, _make_id(precursor_scan_number),
            source=self,
            product_scan_id=_make_id(scan.scan_number))
        return pinfo
Esempio n. 12
0
    def _precursor_information(self, scan):
        scan_number = scan.scan_number
        filt = self._source.GetFilterForScanNumber(scan_number + 1)
        precursor_mz = filt.GetMass(filt.MSOrder - 2)
        trailers = self._trailer_values(scan)
        _precursor_mz = float(trailers.get("Monoisotopic M/Z", 0))
        if _precursor_mz > 0:
            precursor_mz = _precursor_mz

        # imitate proteowizard's firmware bug correction
        isolation_window = self._isolation_window(scan)
        if (isolation_window.upper + isolation_window.lower) / 2 <= 2.0:
            if (isolation_window.target - 3.0 > precursor_mz) or (
                    isolation_window.target + 2.5 < precursor_mz):
                precursor_mz = isolation_window.target
        elif precursor_mz not in isolation_window:
            precursor_mz = isolation_window.target
        charge = int(trailers.get("Charge State", 0))
        if charge == 0:
            charge = ChargeNotProvided
        inten = 0
        precursor_scan_number = None
        precursor_scan_number = trailers.get('Master Scan Number')
        if precursor_scan_number == 0:
            precursor_scan_number = None
        if precursor_scan_number is not None:
            precursor_scan_number = int(precursor_scan_number) - 1
            if self.get_scan_by_index(
                    precursor_scan_number).ms_level >= self._ms_level(scan):
                precursor_scan_number = None
        if precursor_scan_number is None:
            current_level = self._ms_level(scan)
            # We want to start looking for the most recent spectrum with the next lowest MS
            # level. The expecteation is that we couldn't determine the precursor scan accurately,
            # so we'll probe backwards until the next best candidate.
            current_index = self._scan_index(scan)
            # Use the index of the current scan to check the index of the previous scans at a lower
            # MS level. This may be None, in which case there is no earlier scan recorded.
            lookup = self._get_previous_scan_index_for_ms_level(
                current_index, current_level - 1)
            if lookup is not None:
                last_index = lookup
            else:
                last_index = current_index - 1
            i = 0
            while last_index >= 0 and i < 100:
                prev_scan = self.get_scan_by_index(last_index)
                if prev_scan.ms_level >= current_level:
                    last_index -= 1
                else:
                    precursor_scan_number = prev_scan._data.scan_number
                    break
                i += 1
        if precursor_scan_number is not None:
            precursor_scan_id = self.get_scan_by_index(
                precursor_scan_number).id
        else:
            import warnings
            warnings.warn("Could not resolve precursor scan for %s" %
                          (self._scan_id(scan), ))
            precursor_scan_id = None
        return PrecursorInformation(precursor_mz,
                                    inten,
                                    charge,
                                    precursor_scan_id,
                                    source=self,
                                    product_scan_id=self._scan_id(scan))