Exemple #1
0
 def _process_scan(self):
     self.scan.pick_peaks(signal_to_noise_threshold=1.5)
     if self.scan.ms_level == 1:
         averagine_value = self.ms1_averagine_combobox.get()
         averagine_value = averagine_label_map[averagine_value]
         truncate_to = 0.95
         scorer = ms_deisotope.PenalizedMSDeconVFitter(
             self.ms1_score_threshold, 2.)
     else:
         averagine_value = self.msn_averagine_combobox.get()
         averagine_value = averagine_label_map[averagine_value]
         truncate_to = 0.8
         scorer = ms_deisotope.MSDeconVFitter(10.)
     max_charge_state = self.max_charge_state_var.get()
     min_charge_state = self.min_charge_state_var.get()
     if self.scan.ms_level > 1:
         prec_charge = self.scan.precursor_information.charge
         if prec_charge and prec_charge != ChargeNotProvided:
             max_charge_state = prec_charge
             if prec_charge < 0:
                 min_charge_state = -abs(min_charge_state)
     self.scan.deconvolute(averagine=averagine_value,
                           scorer=scorer,
                           truncate_after=1 - 1e-4,
                           incremental_truncation=truncate_to,
                           charge_range=(min_charge_state,
                                         max_charge_state))
Exemple #2
0
def deIsotope(peaks):
    peaks = [p for p in peaks if p[1] > 0]
    dcPeaks, _ = ms_deisotope.deconvolute_peaks(
        peaks,
        averagine=ms_deisotope.peptide,
        truncate_after=
        0.999,  ##truncate_after is very important, loose a little bit
        scorer=ms_deisotope.MSDeconVFitter(10.),
        incremental_truncation=0.8)
    # for peak in dcPeaks:
    #     print(peak)
    #     break
    mzs = [peak.neutral_mass for peak in dcPeaks]
    intes = [peak.intensity for peak in dcPeaks]
    # mzs = preProcMzs(mzs)

    newMzs = np.insert(mzs, 0,
                       ATOM_MASS['O'] * 1 + ATOM_MASS['H'] * 2)  #worked for y1
    newMzs = np.insert(newMzs, 0, 0)  #worked for b1
    newInt = np.insert(intes, 0, 10000)
    newInt = np.insert(newInt, 0, 10000)

    deltaMzs = newMzs - np.concatenate(([-2], newMzs[0:-1]))
    outmz = [
        newMzs[i] for i in range(len(deltaMzs)) if abs(deltaMzs[i]) > 0.0008
    ]
    outint = [
        newInt[i] for i in range(len(deltaMzs)) if abs(deltaMzs[i]) > 0.0008
    ]
    return np.array(outmz), np.array(outint)
Exemple #3
0
 def __init__(self, *args, **kwargs):
     self.deconvolution_args = kwargs.get('deconvolution_args', {})
     self.deconvolution_args.setdefault("averagine", ms_deisotope.peptide)
     self.deconvolution_args.setdefault("scorer",
                                        ms_deisotope.MSDeconVFitter(0))
     self.deconvolution_args.setdefault("truncate_after", 0.8)
     super(DeconvolutingScanProcessingMixin, self).__init__(*args, **kwargs)
Exemple #4
0
def deIsotope(peaks):
    dcPeaks, _ = ms_deisotope.deconvolute_peaks(
        peaks,
        averagine=ms_deisotope.peptide,
        truncate_after=
        0.999,  ##truncate_after is very important, loose a little bit
        scorer=ms_deisotope.MSDeconVFitter(10.),
        incremental_truncation=0.8)

    mzs = [peak.neutral_mass for peak in dcPeaks]

    mzs = preProcMzs(mzs)

    return mzs
Exemple #5
0
 def _process_scan(self):
     self.scan.pick_peaks(signal_to_noise_threshold=1.5)
     if self.scan.ms_level == 1:
         averagine_value = self.ms1_averagine_combobox.get()
         averagine_value = averagine_label_map[averagine_value]
         truncate_after = 0.95
         scorer = ms_deisotope.PenalizedMSDeconVFitter(20., 2.)
     else:
         averagine_value = self.msn_averagine_combobox.get()
         averagine_value = averagine_label_map[averagine_value]
         truncate_after = 0.8
         scorer = ms_deisotope.MSDeconVFitter(10.)
     self.scan.deconvolute(averagine=averagine_value,
                           scorer=scorer,
                           truncate_after=truncate_after)
def feature_deconvolution(input_path,
                          output_path,
                          lockmass_config,
                          start_time=0,
                          end_time=None,
                          averagine='glycopeptide',
                          minimum_intensity=10.0,
                          lock_mass_function=3,
                          processes: int = 4,
                          isolation_window_width=0.0,
                          denoise=1.0,
                          signal_averaging=2):
    '''Extract features from each IM-MS cycle followed by deisotoping and charge state deconvolution.
    '''
    logging.basicConfig(
        level="INFO",
        format='%(asctime)s %(message)s',
        datefmt='%m/%d/%Y %I:%M:%S %p',
        filemode='w',
        filename="cyclic_deconvolute_%s_%s.log" %
        (os.path.basename(input_path).rsplit(".", 1)[0], start_time))
    logging.getLogger().addHandler(_default_log_handler())
    input_path = str(input_path)

    print(f"Running on PID {os.getpid()}")

    reader = open_mse_file(input_path, lockmass_config=lockmass_config)

    if start_time is not None:
        start_id = reader.get_frame_by_time(start_time).id
    else:
        start_id = None
    if end_time is not None:
        end_id = reader.get_frame_by_time(end_time).id
    else:
        end_id = None

    averagine = averagine_map[averagine]

    task = MSESampleConsumer(input_path,
                             storage_path=output_path,
                             ms1_peak_picking_args={
                                 "error_tolerance": 4e-5,
                                 "minimum_intensity": minimum_intensity / 2,
                                 "denoise": denoise
                             },
                             msn_peak_picking_args={
                                 "average_within": signal_averaging,
                                 "error_tolerance": 4e-5,
                                 "denoise": denoise
                             },
                             ms1_deconvolution_args={
                                 "averagine":
                                 averagine,
                                 "truncate_after":
                                 0.95,
                                 "scorer":
                                 ms_deisotope.PenalizedMSDeconVFitter(5, 1),
                                 "minimum_intensity":
                                 minimum_intensity,
                                 "copy":
                                 False
                             },
                             msn_deconvolution_args={
                                 "averagine": averagine,
                                 "truncate_after": 0.8,
                                 "scorer": ms_deisotope.MSDeconVFitter(1),
                                 "minimum_intensity": minimum_intensity / 2,
                                 "copy": False
                             },
                             ms1_averaging=signal_averaging,
                             reader_options={
                                 "lockmass_config": lockmass_config,
                                 "default_isolation_width":
                                 isolation_window_width
                             },
                             deconvolute=True,
                             n_processes=processes,
                             start_scan_id=start_id,
                             end_scan_id=end_id,
                             start_scan_time=start_time,
                             end_scan_time=end_time,
                             lock_mass_function=lock_mass_function)

    task.start()
Exemple #7
0
def pcMassRefine(pcMz, charge, ms1Spec, scanNo):
    # peptide_averagine = Averagine({"C": 4.9384, "H": 7.7583, "N": 1.3577, "O": 1.4773, "S": 0.0417})

    #  theoPeaks = peptide_averagine.isotopic_cluster(819.19, charge = 4)

    #  theoMzs = []   #directly find the ms1 peaks
    delta = 1 / charge

    ms1Mz = [peak[0] for peak in ms1Spec]
    ms1Int = [peak[1] for peak in ms1Spec]
    # print(ms1Mz, pcMz)
    mzIndex = binarySearch(ms1Mz, 0, len(ms1Mz), pcMz) + 1
    rawMz = ms1Mz[mzIndex]
    leftRawMz = ms1Mz[mzIndex - 1]

    if pcMz - leftRawMz < 0.02 and rawMz - pcMz < 0.02:
        realMz = max(rawMz, leftRawMz)
        if ms1Int[mzIndex] > ms1Int[mzIndex - 1]:
            realMz = rawMz
            realIndex = mzIndex
        else:
            realMz = leftRawMz
            realIndex = mzIndex - 1
    else:
        if pcMz - leftRawMz < 0.02:
            realMz = leftRawMz
            realIndex = mzIndex - 1
        elif rawMz - pcMz < 0.02:
            realMz = rawMz
            realIndex = mzIndex
        else:
            # realMz = rawMz
            # realIndex = mzIndex
            return pcMz * charge - ATOM_MASS['Z'] * charge
            # print('Warning not valid pcmass %d' % scanNo)
    # print('realMz', realMz)
    extraL = []
    extraR = []
    intL = []
    intR = []
    l = 1
    countL = 1
    # print(len(ms1Mz))
    while True:
        # print(realIndex,l)
        if realIndex - l < 0:
            break
        mzL = ms1Mz[realIndex - l]
        if mzL < realMz - 5:
            break

        expectedMz = realMz - countL * delta
        if abs(mzL - expectedMz) < 5e-3:
            extraL.append(mzL)
            intL.append(ms1Int[realIndex - l])
            countL += 1
        l += 1

    r = 1
    countR = 1
    while True:
        # print(len(ms1Mz), realIndex, r)
        if realIndex + r > len(ms1Mz) - 1:
            break
        mzR = ms1Mz[realIndex + r]
        if mzR > realMz + 5:
            break

        expectedMz = realMz + countR * delta
        if abs(mzR - expectedMz) < 5e-3:
            extraR.append(mzR)
            intR.append(ms1Int[realIndex + r])
            countR += 1
        r += 1

    mzs = extraL[::-1] + [realMz] + extraR
    intens = intL[::-1] + [ms1Int[realIndex]] + intR
    # print('mzs',mzs)

    if len(mzs) == 1:
        return mzs[0]

    peaks = [tuple((mzs[i], intens[i])) for i in range(len(mzs))]
    # print(peaks)
    dcPeaks, _ = ms_deisotope.deconvolute_peaks(
        peaks,
        averagine=ms_deisotope.peptide,
        truncate_after=
        0.999,  ##truncate_after is very important, loose a little bit
        scorer=ms_deisotope.MSDeconVFitter(10.),
        incremental_truncation=0.8)

    monoPeaks = [peak.neutral_mass for peak in dcPeaks]
    if len(monoPeaks) == 0:
        return pcMz * charge - ATOM_MASS['Z'] * charge
    monoPcMass = [peak.neutral_mass for peak in dcPeaks][0]
    # print('mono', monoPcMass)
    # for i in dcPeaks:
    #     print(i)
    # print('monoPcMass',monoPcMass)
    return monoPcMass