예제 #1
0
def main(options):
    out = options.outfile
    chromat_in = options.infile
    traml_in = options.traml_in
    trafo_in = options.trafo_in

    pp = pyopenms.MRMTransitionGroupPicker()


    metabolomics = False
    # this is an important weight for RT-deviation -- the larger the value, the less importance will be given to exact RT matches
    # for proteomics data it tends to be a good idea to set it to the length of
    # the RT space (e.g. for 100 second RT space, set it to 100)
    rt_normalization_factor = 100.0

    pp_params = pp.getDefaults();
    pp_params.setValue("PeakPickerMRM:remove_overlapping_peaks", options.remove_overlapping_peaks, '')
    pp_params.setValue("PeakPickerMRM:method", options.method, '')
    if (metabolomics):
        # Need to change those for metabolomics and very short peaks!
        pp_params.setValue("PeakPickerMRM:signal_to_noise", 0.01, '')
        pp_params.setValue("PeakPickerMRM:peak_width", 0.1, '')
        pp_params.setValue("PeakPickerMRM:gauss_width", 0.1, '')
        pp_params.setValue("resample_boundary", 0.05, '')
        pp_params.setValue("compute_peak_quality", "true", '')
    pp.setParameters(pp_params)

    scorer = pyopenms.MRMFeatureFinderScoring()
    scoring_params = scorer.getDefaults();
    # Only report the top 5 features
    scoring_params.setValue("stop_report_after_feature", 5, '')
    scoring_params.setValue("rt_normalization_factor", rt_normalization_factor, '')
    scorer.setParameters(scoring_params);

    chromatograms = pyopenms.MSExperiment()
    fh = pyopenms.FileHandler()
    fh.loadExperiment(chromat_in, chromatograms)
    targeted = pyopenms.TargetedExperiment();
    tramlfile = pyopenms.TraMLFile();
    tramlfile.load(traml_in, targeted);

    trafoxml = pyopenms.TransformationXMLFile()
    trafo = pyopenms.TransformationDescription()
    if trafo_in is not None:
        model_params = pyopenms.Param()
        model_params.setValue("symmetric_regression", "false", "", [])
        model_type = "linear"
        trafoxml.load(trafo_in, trafo, True)
        trafo.fitModel(model_type, model_params);


    light_targeted = pyopenms.LightTargetedExperiment();
    pyopenms.OpenSwathDataAccessHelper().convertTargetedExp(targeted, light_targeted)
    output = algorithm(chromatograms, light_targeted, pp, scorer, trafo)

    pyopenms.FeatureXMLFile().store(out, output);
예제 #2
0
파일: test000.py 프로젝트: yachliu/pyOpenMS
def testTransformationXMLFile():
    """
    @tests:
     TransformationXMLFile.__init__
     TransformationXMLFile.load
     TransformationXMLFile.store
    """
    fh = pyopenms.TransformationXMLFile()
    td = pyopenms.TransformationDescription()
    fh.store("test.transformationXML", td)
    fh.load("test.transformationXML", td)
    assert td.getDataPoints() == []
예제 #3
0
def main(options):

    # load chromatograms
    chromatograms = pyopenms.MSExperiment()
    fh = pyopenms.FileHandler()
    fh.loadExperiment(options.infile, chromatograms)

    # load TraML file
    targeted = pyopenms.TargetedExperiment()
    tramlfile = pyopenms.TraMLFile()
    tramlfile.load(options.traml_in, targeted)

    trafo_out = algorithm(chromatograms, targeted)

    pyopenms.TransformationXMLFile().store(options.outfile, trafo_out)
예제 #4
0
def align(in_files, out_files, out_trafos, reference_index, reference_file,
          params):

    in_types = set(pms.FileHandler.getType(in_) for in_ in in_files)

    if in_types <= set((pms.Type.MZML, pms.Type.MZXML, pms.Type.MZDATA)):
        align_features = False
    elif in_types == set((pms.Type.FEATUREXML, )):
        align_features = True
    else:
        raise Exception("different kinds of input files")

    algorithm = pms.MapAlignmentAlgorithmPoseClustering()
    alignment_params = params.copy("algorithm:", True)
    algorithm.setParameters(alignment_params)
    algorithm.setLogType(pms.LogType.CMD)

    plog = pms.ProgressLogger()
    plog.setLogType(pms.LogType.CMD)

    if reference_file:
        file_ = reference_file
    elif reference_index > 0:
        file_ = in_files[reference_index - 1]
    else:
        sizes = []
        if align_features:
            fh = pms.FeatureXMLFile()
            plog.startProgress(0, len(in_files), "Determine Reference map")
            for i, in_f in enumerate(in_files):
                sizes.append((fh.loadSize(in_f), in_f))
                plog.setProgress(i)
        else:
            fh = pms.MzMLFile()
            mse = pms.MSExperiment()
            plog.startProgress(0, len(in_files), "Determine Reference map")
            for i, in_f in enumerate(in_files):
                fh.load(in_f, mse)
                mse.updateRanges()
                sizes.append((mse.getSize(), in_f))
                plog.setProgress(i)
        plog.endProgress()
        __, file_ = max(sizes)

    f_fmxl = pms.FeatureXMLFile()
    if not out_files:
        options = f_fmxl.getOptions()
        options.setLoadConvexHull(False)
        options.setLoadSubordinates(False)
        f_fmxl.setOptions(options)

    if align_features:
        map_ref = pms.FeatureMap()
        f_fxml_tmp = pms.FeatureXMLFile()
        options = f_fmxl.getOptions()
        options.setLoadConvexHull(False)
        options.setLoadSubordinates(False)
        f_fxml_tmp.setOptions(options)
        f_fxml_tmp.load(file_, map_ref)
        algorithm.setReference(map_ref)
    else:
        map_ref = pms.MSExperiment()
        pms.MzMLFile().load(file_, map_ref)
        algorithm.setReference(map_ref)

    plog.startProgress(0, len(in_files), "Align input maps")
    for i, in_file in enumerate(in_files):
        trafo = pms.TransformationDescription()
        if align_features:
            map_ = pms.FeatureMap()
            f_fxml_tmp = pms.FeatureXMLFile()
            f_fxml_tmp.setOptions(f_fmxl.getOptions())
            f_fxml_tmp.load(in_file, map_)
            if in_file == file_:
                trafo.fitModel("identity")
            else:
                algorithm.align(map_, trafo)
            if out_files:
                pms.MapAlignmentTransformer.transformSingleFeatureMap(
                    map_, trafo)
                addDataProcessing(map_, params, pms.ProcessingAction.ALIGNMENT)
                f_fxml_tmp.store(out_files[i], map_)
        else:
            map_ = pms.MSExperiment()
            pms.MzMLFile().load(in_file, map_)
            if in_file == file_:
                trafo.fitModel("identity")
            else:
                algorithm.align(map_, trafo)
            if out_files:
                pms.MapAlignmentTransformer.transformSinglePeakMap(map_, trafo)
                addDataProcessing(map_, params, pms.ProcessingAction.ALIGNMENT)
                pms.MzMLFile().store(out_files[i], map_)
        if out_trafos:
            pms.TransformationXMLFile().store(out_trafos[i], trafo)

        plog.setProgress(i + 1)

    plog.endProgress()
예제 #5
0
def align(in_files, out_files, trafo_out_files, reference_index,
        reference_file, params):

    algo = pms.MapAlignmentAlgorithmPoseClustering()
    algo.setReference(reference_index, reference_file)

    model_params = params.copy("model:", True)
    model_type   = model_params.getValue("type").toString()

    pl = pms.ProgressLogger()
    pl.setLogType(pms.LogType.CMD)

    alignment_param = params.copy("algorithm:", True)

    algo.setParameters(alignment_param)

    transformations = []

    in_types = set(pms.FileHandler.getType(in_file) for in_file in in_files)
    in_maps = []
    if in_types <= set((pms.Type.MZML, pms.Type.MZXML, pms.Type.MZDATA)):
        fh = pms.FileHandler()
        pl.startProgress(0, len(in_files), "loading input files")
        for i, in_file in enumerate(in_files):
            pl.setProgress(i)
            pm = pms.MSExperiment()
            fh.loadExperiment(in_file, pm)
            in_maps.append(pm)
        pl.endProgress()
        algo.alignPeakMaps(in_maps, transformations)
        if model_type != "none":
            algo.fitModel(model_type, model_params, transformations)
        pms.MapAlignmentAlgorithmPoseClustering.transformPeakMaps(in_maps, transformations)
        pl.startProgress(0, len(out_files), "writing output files")
        for i, out_file in enumerate(out_files):
            pl.setProgress(i)
            in_map = addDataProcessing(in_maps[i], params)
            fh.storeExperiment(out_file, in_map)
        pl.endProgress()

    elif in_types == set((pms.Type.FEATUREXML,)):
        fh = pms.FeatureXMLFile()
        pl.startProgress(0, len(in_files), "loading input files")
        for i, in_file in enumerate(in_files):
            pl.setProgress(i)
            pm = pms.FeatureMap()
            fh.load(in_file, pm)
            in_maps.append(pm)
        pl.endProgress()
        algo.alignFeatureMaps(in_maps, transformations)
        if model_type != "none":
            algo.fitModel(model_type, model_params, transformations)
        pms.MapAlignmentAlgorithmPoseClustering.transformFeatureMaps(in_maps, transformations)
        pl.startProgress(0, len(out_files), "writing output files")
        for i, out_file in enumerate(out_files):
            pl.setProgress(i)
            in_map = addDataProcessing(in_maps[i], params)
            fh.store(out_file, in_map)
        pl.endProgress()

    else:
        raise Exception("can not handle input file format")

    if trafo_out_files:
        for name, trafo in zip(trafo_out_files, transformations):
            pms.TransformationXMLFile().store(name, trafo)