Exemplo n.º 1
0
    def build_params():
        mtd_params = pyopenms.MassTraceDetection().getDefaults()
        mtd_params.remove("chrom_peak_snr")
        mtd_params.remove("noise_threshold_int")

        epdet_params = pyopenms.ElutionPeakDetection().getDefaults()
        epdet_params.remove("noise_threshold_int")
        epdet_params.remove("chrom_peak_snr")
        epdet_params.remove("chrom_fwhm")

        common_params = pyopenms.Param()
        common_params.setValue(
            "noise_threshold_int", 10.0,
            "Intensity threshold below which peaks are regarded as noise.")
        common_params.setValue(
            "chrom_peak_snr", 3.0,
            "Minimum signal-to-noise a mass trace should have")
        common_params.setValue(
            "chrom_fwhm", 5.0,
            "Expected chromatographic peak width (in seconds).")

        ffm_params = pyopenms.FeatureFindingMetabo().getDefaults()
        ffm_params.remove("chrom_fwhm")

        combined_params = pyopenms.Param()
        combined_params.insert("common_", common_params)
        combined_params.insert("mtd_", mtd_params)
        combined_params.insert("epdet_", epdet_params)
        combined_params.insert("ffm_", ffm_params)

        return combined_params
Exemplo n.º 2
0
def FeatureFindingMetabo1(mzfile):
    exp = pyopenms.MSExperiment()
    pyopenms.MzMLFile().load(mzfile, exp)

    mtd_params = pyopenms.MassTraceDetection().getDefaults()
    mtd = pyopenms.MassTraceDetection()
    mtd.setParameters(mtd_params)
    mass_traces = []
    mtd.run(exp, mass_traces)

    epdet_params = pyopenms.ElutionPeakDetection().getDefaults()
    epdet = pyopenms.ElutionPeakDetection()
    epdet.setParameters(epdet_params)
    splitted_mass_traces = []
    epdet.detectPeaks(mass_traces, splitted_mass_traces)

    ffm_params = pyopenms.FeatureFindingMetabo().getDefaults()
    ffm = pyopenms.FeatureFindingMetabo()
    ffm.setParameters(ffm_params)
    feature_map = pyopenms.FeatureMap()
    ffm.run(splitted_mass_traces, feature_map)
    return feature_map
Exemplo n.º 3
0
def oms_ffmetabo_single_file(filename, max_peaks_per_file=5000):

    feature_map = oms.FeatureMap()
    mass_traces = []
    mass_traces_split = []
    mass_traces_filtered = []
    exp = oms.MSExperiment()
    peak_map = oms.PeakMap()
    options = oms.PeakFileOptions()
    
    options.setMSLevels([1])

    if filename.lower().endswith('.mzxml'):
        fh = oms.MzXMLFile()

    elif filename.lower().endswith('.mzml'):
        fh = oms.MzMLFile()
    else:
        assert False, filename

    fh.setOptions(options)

    # Peak map
    fh.load(filename, exp)

    #for chrom in exp.getChromatograms():
    #    peak_map.addChrom(chrom)

    for spec in exp.getSpectra():
        peak_map.addSpectrum(spec)

    mass_trace_detect = oms.MassTraceDetection()
    mass_trace_detect.run(peak_map, mass_traces, max_peaks_per_file)

    elution_peak_detection = oms.ElutionPeakDetection()
    elution_peak_detection.detectPeaks(mass_traces, mass_traces_split)

    feature_finding_metabo = oms.FeatureFindingMetabo()
    feature_finding_metabo.run(
                mass_traces_split,
                feature_map,
                mass_traces_filtered)

    feature_map.sortByOverallQuality()
    return feature_map
Exemplo n.º 4
0
    def ff_metabo(self):

        self.chromatograms = [[]]

        self.ffm_process = oms.FeatureFindingMetabo()

        self.ffm_params = self.ffm_process.getDefaults()

        self.ffm_params.setValue('charge_lower_bound', 1)
        self.ffm_params.setValue('charge_upper_bound', 1)
        self.ffm_params.setValue('enable_RT_filtering', b'true')
        self.ffm_params.setValue('isotope_filtering_model',
                                 b'metabolites (5% RMS)')
        self.ffm_params.setValue('mz_scoring_13C', b'true')
        self.ffm_params.setValue('report_convex_hulls', b'true')
        self.ffm_params.setValue('remove_single_traces', b'true')

        self.ffm_process.setParameters(self.ffm_params)

        self.ffm_process.run(self.splitted_mt, self.feature_map,
                             self.chromatograms)
Exemplo n.º 5
0
def metaboFeatureFinder(peak_map, config_id=None, ms_level=None, **kw):
    from ..algorithm_configs import metaboFFConfigs

    config_params = dict()

    for key, __, params in metaboFFConfigs:
        if key == config_id:
            config_params = params.copy()
            break
    config_params.update(kw)

    assert isinstance(peak_map, PeakMap)
    import time

    def info(fmtstr, *a):
        msg = fmtstr % a
        print
        print(" " + msg + " ").center(79, "=")
        print

    info("RUN FEATURE FINDER METABO")

    start_at = time.time()

    (mtd_params, epdet_params, ffm_params,
     all_params) = _ParamHandler.update_params(config_params)

    def dump_param(prefix, all_params=all_params):
        sub_params = all_params.copy(prefix)
        for k, v in sorted(sub_params.items()):
            print("%s " % (k, )).ljust(35, "."), v

    print "COMMON PARAMETERS"
    print
    dump_param("common_")
    print
    print "PARAMS MASS TRACE DETECTION:"
    print
    dump_param("mtd_")
    print
    print "PARAMS ELUTION PEAK DETECTION:"
    print
    dump_param("epdet_")
    print
    print "PARAMS FEATURE FINDER METABO:"
    print
    dump_param("ffm_")
    print

    # Sometimes when we run nosetest, the locale settings are set to
    # german. I can not explain why.
    # This causes a problem for the Metabo feature finder from OpenMS,
    # which fails to read some config files conatinng numercial values
    # with a "." decimal point, which is not the decimal point for german
    # noumbers. so we set:
    locale.setlocale(locale.LC_NUMERIC, "C")

    mtd = pyopenms.MassTraceDetection()
    mtd.setParameters(mtd_params)
    mass_traces = []
    if ms_level is None:
        peak_map = peak_map.getDominatingPeakmap()
    else:
        peak_map = peak_map.extract(mslevelmin=ms_level, mslevelmax=ms_level)
        for spec in peak_map.spectra:
            spec.msLevel = 1
    info("%d SPECS OF LEVEL %d", len(peak_map), 1)
    mtd.run(peak_map.toMSExperiment(), mass_traces)
    info("FOUND %d MASS TRACES", len(mass_traces))

    rows = []
    splitted_mass_traces = []
    if mass_traces:

        epdet = pyopenms.ElutionPeakDetection()
        epdet.setParameters(epdet_params)
        splitted_mass_traces = []
        epdet.detectPeaks(mass_traces, splitted_mass_traces)

    if splitted_mass_traces:

        if epdet_params.getValue("width_filtering") == "auto":
            final_mass_traces = []
            epdet.filterByPeakWidth(splitted_mass_traces, final_mass_traces)
        else:
            final_mass_traces = splitted_mass_traces

        info("%d SPLITTED MASS TRACES AFTER ELUTION PEAK DETECTION",
             len(final_mass_traces))

        ffm = pyopenms.FeatureFindingMetabo()
        ffm.setParameters(ffm_params)
        feature_map = pyopenms.FeatureMap()
        ffm.run(final_mass_traces, feature_map)

        info("FOUND %d FEATURES", feature_map.size())

        for i, feature in enumerate(feature_map):
            convex_hulls = feature.getConvexHulls()
            quality = feature.getOverallQuality()
            width = feature.getWidth()
            z = feature.getCharge()
            mz = feature.getMZ()
            rt = feature.getRT()
            I = feature.getIntensity()
            for convex_hull in convex_hulls:
                bb = convex_hull.getBoundingBox()
                rtmin, mzmin = bb.minPosition()
                rtmax, mzmax = bb.maxPosition()
                row = [
                    i, mz, mzmin, mzmax, rt, rtmin, rtmax, I, quality, width, z
                ]
                rows.append(row)

    tab = Table([
        "feature_id", "mz", "mzmin", "mzmax", "rt", "rtmin", "rtmax",
        "intensity", "quality", "fwhm", "z"
    ], [
        int, float, float, float, float, float, float, float, float, float, int
    ], [
        "%d", "%10.5f", "%10.5f", "%10.5f", formatSeconds, formatSeconds,
        formatSeconds, "%.2e", "%.2e", formatSeconds, "%d"
    ], rows)

    tab.addConstantColumn("peakmap", peak_map, PeakMap, None)

    def recalc(table, row, name):
        mzmin = table.getValue(row, "mzmin")
        mzmax = table.getValue(row, "mzmax")
        rtmin = table.getValue(row, "rtmin")
        rtmax = table.getValue(row, "rtmax")
        pm = table.getValue(row, "peakmap")
        mz = pm.representingMzPeak(mzmin, mzmax, rtmin, rtmax)
        return mz if mz is not None else (mzmin + mzmax) / 2.0

    tab.replaceColumn("mz", recalc)

    src = peak_map.meta.get("source", "")
    tab.addConstantColumn("source", src)
    tab.addEnumeration()
    if src:
        tab.title = "metabo features from %s" % os.path.basename(src)
    else:
        tab.title = "metabo features"

    needed = time.time() - start_at

    minutes = int(needed / 60)
    seconds = round(needed - 60 * minutes)

    info("NEEDED %d MINUTES AND %d SECONDS", minutes, seconds)

    return tab
Exemplo n.º 6
0
 def __init__(self, **kwargs):
     
     super(FfmEntity, self).__init__(
         oms.FeatureFindingMetabo(),
         **kwargs,
     )