Пример #1
0
    def _make_deconvoluted_peak_solution(self, fit, composition, charge_carrier):
        eid = fit.experimental
        tid = fit.theoretical
        charge = fit.charge
        rep_eid = drop_placeholders(eid)
        total_abundance = sum(
            p.intensity for p in eid if p.intensity > 1)

        monoisotopic_mass = neutral_mass(
            tid.monoisotopic_mz, charge, charge_carrier)
        monoisotopic_mz = tid.monoisotopic_mz

        reference_peak = first_peak(eid)
        peak = DeconvolutedPeakSolution(
            composition, fit,
            monoisotopic_mass, total_abundance, charge,
            signal_to_noise=mean(p.signal_to_noise for p in rep_eid),
            index=reference_peak.index,
            full_width_at_half_max=mean(
                p.full_width_at_half_max for p in rep_eid),
            a_to_a2_ratio=a_to_a2_ratio(tid),
            most_abundant_mass=neutral_mass(
                most_abundant_mz(eid), charge),
            average_mass=neutral_mass(average_mz(eid), charge),
            score=fit.score,
            envelope=[(p.mz, p.intensity) for p in rep_eid],
            mz=monoisotopic_mz, area=sum(e.area for e in eid))
        return peak
Пример #2
0
    def _make_deconvoluted_peak_solution(self, fit, composition, charge_carrier):
        eid = fit.experimental
        tid = fit.theoretical
        charge = fit.charge
        rep_eid = drop_placeholders(eid)
        total_abundance = sum(
            p.intensity for p in eid if p.intensity > 1)

        monoisotopic_mass = neutral_mass(
            tid.monoisotopic_mz, charge, charge_carrier)
        monoisotopic_mz = tid.monoisotopic_mz

        reference_peak = first_peak(eid)
        peak = DeconvolutedPeakSolution(
            composition, fit,
            monoisotopic_mass, total_abundance, charge,
            signal_to_noise=mean(p.signal_to_noise for p in rep_eid),
            index=reference_peak.index,
            full_width_at_half_max=mean(
                p.full_width_at_half_max for p in rep_eid),
            a_to_a2_ratio=a_to_a2_ratio(tid),
            most_abundant_mass=neutral_mass(
                most_abundant_mz(eid), charge),
            average_mass=neutral_mass(average_mz(eid), charge),
            score=fit.score,
            envelope=[(p.mz, p.intensity) for p in rep_eid],
            mz=monoisotopic_mz, area=sum(e.area for e in eid))
        return peak
Пример #3
0
    def _make_deconvoluted_peak(self, fit, charge_carrier):
        score, charge, eid, tid = fit
        rep_eid = drop_placeholders(eid)
        total_abundance = sum(p.intensity for p in rep_eid)
        monoisotopic_mass = neutral_mass(tid.monoisotopic_mz, charge,
                                         charge_carrier)
        reference_peak = first_peak(eid)

        dpeak = DeconvolutedPeak(
            neutral_mass=monoisotopic_mass,
            intensity=total_abundance,
            charge=charge,
            signal_to_noise=mean(p.signal_to_noise for p in rep_eid),
            index=reference_peak.index,
            full_width_at_half_max=mean(p.full_width_at_half_max
                                        for p in rep_eid),
            a_to_a2_ratio=a_to_a2_ratio(tid),
            most_abundant_mass=neutral_mass(most_abundant_mz(eid), charge),
            average_mass=neutral_mass(average_mz(eid), charge),
            score=score,
            envelope=[(p.mz, p.intensity) for p in eid],
            mz=tid.monoisotopic_mz,
            fit=fit,
            area=sum(e.area for e in eid))
        return dpeak
Пример #4
0
    def _make_deconvoluted_peak(self, fit, charge_carrier):
        score, charge, eid, tid = fit
        rep_eid = drop_placeholders(eid)
        total_abundance = sum(p.intensity for p in rep_eid)
        monoisotopic_mass = neutral_mass(
            tid.monoisotopic_mz, charge, charge_carrier)
        reference_peak = first_peak(eid)

        dpeak = DeconvolutedPeak(
            neutral_mass=monoisotopic_mass, intensity=total_abundance, charge=charge,
            signal_to_noise=mean(p.signal_to_noise for p in rep_eid),
            index=reference_peak.index,
            full_width_at_half_max=mean(
                p.full_width_at_half_max for p in rep_eid),
            a_to_a2_ratio=a_to_a2_ratio(tid),
            most_abundant_mass=neutral_mass(
                most_abundant_mz(eid), charge),
            average_mass=neutral_mass(average_mz(eid), charge),
            score=score,
            envelope=[(p.mz, p.intensity) for p in eid],
            mz=tid.monoisotopic_mz, fit=fit,
            area=sum(e.area for e in eid))
        return dpeak
Пример #5
0
    def finalize_fit(self,
                     feature_fit,
                     charge_carrier=PROTON,
                     subtract=True,
                     detection_threshold=0.1,
                     max_missed_peaks=1):
        nodes = []
        start_time, end_time, _segments = find_bounds(feature_fit,
                                                      detection_threshold)
        feat_iter = FeatureSetIterator(feature_fit.features, start_time,
                                       end_time)
        base_tid = feature_fit.theoretical
        charge = feature_fit.charge
        abs_charge = abs(charge)
        for eid in feat_iter:
            cleaned_eid, tid, n_missing = conform_envelopes(
                eid, base_tid.peaklist)
            rep_eid = drop_placeholders(cleaned_eid)
            n_real_peaks = len(rep_eid)
            if n_real_peaks == 0 or (n_real_peaks == 1 and abs_charge > 1) or \
               n_missing > max_missed_peaks:
                continue
            score = self.scorer.evaluate(None, cleaned_eid, tid)
            is_valid = True
            if np.isnan(score) or score < 0:
                is_valid = False
            envelope = [(e.mz, min(e.intensity, t.intensity))
                        for e, t in zip(cleaned_eid, tid)]
            if is_valid:
                total_abundance = sum(p[1] for p in envelope)
                monoisotopic_mass = neutral_mass(base_tid.monoisotopic_mz,
                                                 charge,
                                                 charge_carrier=charge_carrier)
                reference_peak = first_peak(cleaned_eid)

                dpeak = DeconvolutedPeak(
                    neutral_mass=monoisotopic_mass,
                    intensity=total_abundance,
                    charge=charge,
                    signal_to_noise=mean(p.signal_to_noise for p in rep_eid),
                    index=reference_peak.index,
                    full_width_at_half_max=mean(p.full_width_at_half_max
                                                for p in rep_eid),
                    a_to_a2_ratio=a_to_a2_ratio(tid),
                    most_abundant_mass=neutral_mass(
                        most_abundant_mz(cleaned_eid),
                        charge,
                        charge_carrier=charge_carrier),
                    average_mass=neutral_mass(average_mz(cleaned_eid),
                                              charge,
                                              charge_carrier=charge_carrier),
                    score=score,
                    envelope=envelope,
                    mz=base_tid.monoisotopic_mz,
                    area=sum(e.area for e in cleaned_eid))

                time = feat_iter.current_time
                precursor_info_set = []
                for peak in rep_eid:
                    pinfo = self.precursor_map.precursor_for_peak(
                        (time, peak.index))
                    if pinfo is not None:
                        precursor_info_set.append(pinfo)

                node = DeconvolutedLCMSFeatureTreeNode(time, [dpeak],
                                                       precursor_info_set)
                nodes.append(node)
            if subtract:
                for fpeak, tpeak in zip(cleaned_eid, envelope):
                    # If a theoretical peak uses up more than 70%
                    # of the abundance of a single peak, this peak
                    # should not contribute meaninfully to any other
                    # fits from now on. Set it's abundance to 1.0 as
                    # if it were fully used up.
                    ruin = (fpeak.intensity * 0.7) < tpeak[1]
                    if ruin:
                        fpeak.intensity = 1.0
                    else:
                        fpeak.intensity -= tpeak[1]
                    if fpeak.intensity < 0:
                        fpeak.intensity = 1.0
        for feature in feature_fit.features:
            if feature is None or isinstance(feature, EmptyFeature):
                continue
            feature.invalidate()
        if len(nodes) < self.minimum_size:
            return None

        result_feature = DeconvolutedLCMSFeature(
            nodes,
            feature_fit.charge,
            score=feature_fit.score,
            n_features=len(feature_fit),
            supporters=feature_fit.supporters)

        return result_feature
Пример #6
0
    def finalize_fit(self, feature_fit, charge_carrier=PROTON, subtract=True,
                     detection_threshold=0.1, max_missed_peaks=1):
        nodes = []
        start_time, end_time = find_bounds(feature_fit, detection_threshold)
        feat_iter = FeatureSetIterator(
            feature_fit.features, start_time, end_time)
        base_tid = feature_fit.theoretical
        charge = feature_fit.charge
        abs_charge = abs(charge)
        for eid in feat_iter:
            cleaned_eid, tid, n_missing = conform_envelopes(eid, base_tid.truncated_tid)
            rep_eid = drop_placeholders(cleaned_eid)
            n_real_peaks = len(rep_eid)
            if n_real_peaks == 0 or (n_real_peaks == 1 and abs_charge > 1) or \
               n_missing > max_missed_peaks:
                continue
            score = self.scorer.evaluate(None, cleaned_eid, tid)
            is_valid = True
            if np.isnan(score) or score < 0:
                is_valid = False
            envelope = [(e.mz, min(e.intensity, t.intensity)) for e, t in zip(cleaned_eid, tid)]
            if is_valid:
                total_abundance = sum(p[1] for p in envelope)
                monoisotopic_mass = neutral_mass(
                    base_tid.monoisotopic_mz, charge, charge_carrier=charge_carrier)
                reference_peak = first_peak(cleaned_eid)

                dpeak = DeconvolutedPeak(
                    neutral_mass=monoisotopic_mass, intensity=total_abundance,
                    charge=charge,
                    signal_to_noise=mean(p.signal_to_noise for p in rep_eid),
                    index=reference_peak.index,
                    full_width_at_half_max=mean(p.full_width_at_half_max for p in rep_eid),
                    a_to_a2_ratio=a_to_a2_ratio(tid),
                    most_abundant_mass=neutral_mass(
                        most_abundant_mz(cleaned_eid), charge, charge_carrier=charge_carrier),
                    average_mass=neutral_mass(
                        average_mz(cleaned_eid), charge, charge_carrier=charge_carrier),
                    score=score,
                    envelope=envelope,
                    mz=base_tid.monoisotopic_mz,
                    area=sum(e.area for e in cleaned_eid))

                time = feat_iter.current_time
                precursor_info_set = []
                for peak in rep_eid:
                    pinfo = self.precursor_map.precursor_for_peak((time, peak.index))
                    if pinfo is not None:
                        precursor_info_set.append(pinfo)

                node = DeconvolutedLCMSFeatureTreeNode(time, [dpeak], precursor_info_set)
                nodes.append(node)
            if subtract:
                for fpeak, tpeak in zip(cleaned_eid, envelope):
                    # If a theoretical peak uses up more than 70%
                    # of the abundance of a single peak, this peak
                    # should not contribute meaninfully to any other
                    # fits from now on. Set it's abundance to 1.0 as
                    # if it were fully used up.
                    ruin = (fpeak.intensity * 0.7) < tpeak[1]
                    if ruin:
                        fpeak.intensity = 1.0
                    else:
                        fpeak.intensity -= tpeak[1]
                    if fpeak.intensity < 0:
                        fpeak.intensity = 1.0
        for feature in feature_fit.features:
            if feature is None or isinstance(feature, EmptyFeature):
                continue
            feature.invalidate()
        if len(nodes) < self.minimum_size:
            return None

        result_feature = DeconvolutedLCMSFeature(
            nodes, feature_fit.charge,
            score=feature_fit.score, n_features=len(feature_fit),
            supporters=feature_fit.supporters)

        return result_feature