Exemplo n.º 1
0
def main():

    # register command line arguments
    model = CTDModel(
        name='NameOfThePyTOPPTool',  # required
        version='1.0',  # required
        description=
        'This is an example tool how to write pyTOPP tools compatible with the OpenMS workflow ecosystem.',
        manual='RTF',
        docurl='http://dummy.url/docurl.html',
        category='Example',
        executableName='exampletool',
        executablePath='/path/to/exec/exampletool-1.0/exampletool')

    # Register in / out etc. with CTDModel
    model.add(
        'input',
        required=True,
        type='input-file',
        is_list=False,
        file_formats=['mzML'],  # filename restrictions
        description='Input file')

    model.add(
        'output',
        required=True,
        type='output-file',
        is_list=False,
        file_formats=['mzML'],  # filename restrictions
        description='Output file')

    defaults = pms.PeakPickerHiRes().getDefaults()

    # expose algorithm parameters in command line options
    addParamToCTDopts(defaults, model)

    # parse command line
    # if -write_ini is provided, store model in CTD file, exit with error code 0
    # if -ini is provided, load CTD file into defaults Param object and return new model with paraneters set as defaults
    arg_dict, openms_params = parseCTDCommandLine(sys.argv, model, defaults)

    # data processing
    fh = pms.MzMLFile()
    fh.setLogType(pms.LogType.CMD)
    input_map = pms.MSExperiment()

    fh.load(arg_dict["input"], input_map)

    pp = pms.PeakPickerHiRes()
    pp.setParameters(openms_params)
    out_map = pms.MSExperiment()
    pp.pickExperiment(input_map, out_map)

    out_map = addDataProcessing(
        out_map, openms_params,
        pms.DataProcessing.ProcessingAction.PEAK_PICKING)
    fh = pms.FileHandler()
    fh.storeExperiment(arg_dict["output"], out_map)
Exemplo n.º 2
0
 def __init__(self, **modified_config):
     self.pp = pyopenms.PeakPickerHiRes()
     params = self.pp.getParameters()
     config = self.standardConfig
     config.update(modified_config)
     params.update(config)
     self.pp.setParameters(params)
Exemplo n.º 3
0
def fft_pick(spec, fft_low_cutoff, fft_high_cutoff):
    # filter spec
    filtered_spec = fft_filter_spec(spec, fft_low_cutoff, fft_high_cutoff)
    # apply pyopenms peakpicker on filtered spec
    picker = pyopenms.PeakPickerHiRes()
    newspec_out = pyopenms.MSSpectrum()
    picker.pick(filtered_spec, newspec_out)
    return newspec_out
Exemplo n.º 4
0
def main(options):
    
    # generate fragmentationtype lookup
    lookup = {}
    methods = pyopenms.ActivationMethod()
    for attr in dir(methods):
        value = getattr(methods,attr)
        if isinstance(value,int):
            lookup[value] = attr
    
    print "loading MS Experiment "
    exp = pyopenms.MSExperiment()
    fh = pyopenms.FileHandler()
    fh.loadExperiment(options.infile,exp)
    
    print "checking spectra types:"
    fragmentationTypes = {}
    for s in exp:
        typ = getSpectrumType(s,lookup)
        cont = continousSpectrumCheck(s)
        fragmentationTypes[typ] = fragmentationTypes.get(typ, [] ) + [cont]


    isContinousSpectrum = {}
    for typ in fragmentationTypes:
        check = percentile75(fragmentationTypes[typ])
        isContinousSpectrum[typ] = check
        if check == True:
            print "\t" + typ + " has continous spectra data"
        else:
            print "\t" + typ + " has centroided spectra data"

    print "picking spectra"
    expNew = pyopenms.MSExperiment()
    picker = pyopenms.PeakPickerHiRes()
    for s in exp:
        typ = getSpectrumType(s,lookup)
        if isContinousSpectrum[typ] == True:
            newSpec = pyopenms.MSSpectrum()
            picker.pick(s,newSpec)
            expNew.addSpectrum(newSpec)
        else:
            expNew.addSpectrum(s)
    
    print "saving file to ",options.outfile
    mzFile = pyopenms.MzMLFile()
    fileoptions = mzFile.getOptions()
    fileoptions.setCompression(True)
    mzFile.setOptions(fileoptions)
    mzFile.store(options.outfile,expNew)
    print "finished"
Exemplo n.º 5
0
def run_peak_picker(input_map, params, out_path):

    spec0 = input_map[0]
    if pms.PeakTypeEstimator().estimateType(spec0) == \
        pms.                               SpectrumSettings.SpectrumType.PEAKS:
        logging.warn("input peak map does not look like profile data")

    pp = pms.PeakPickerHiRes()
    pp.setParameters(params)
    out_map = pms.MSExperiment()
    pp.pickExperiment(input_map, out_map)

    out_map = addDataProcessing(out_map, params)
    fh = pms.FileHandler()
    fh.storeExperiment(out_path, out_map)
Exemplo n.º 6
0
    def run_peak_picker(self):

        self._log('Starting peak picking.')

        if self.peak_picking_iterative:

            self.pp = oms.PeakPickerIterative()

        else:

            self.pp = oms.PeakPickerHiRes()

        self.centroid_out_map = oms.MSExperiment()

        self.pp.pickExperiment(self.profile_map, self.centroid_out_map)

        self.centroid_out_map.updateRanges()
Exemplo n.º 7
0
def run_peak_picker(input_map, params, out_path):

    spec0 = input_map[0]
    if pms.PeakTypeEstimator().estimateType(spec0) == \
        pms.                               SpectrumSettings.SpectrumType.PEAKS:
        logging.warn("input peak map does not look like profile data")

    if any(not s.isSorted() for s in input_map):
        raise Exception("Not all spectra are sorted according to m/z")

    pp = pms.PeakPickerHiRes()
    pp.setParameters(params)
    out_map = pms.MSExperiment()
    pp.pickExperiment(input_map, out_map)

    out_map = addDataProcessing(
        out_map, params, pms.DataProcessing.ProcessingAction.PEAK_PICKING)
    fh = pms.FileHandler()
    fh.storeExperiment(out_path, out_map)
Exemplo n.º 8
0
 def __init__(self, **kwargs):
     
     super(PPEntity, self).__init__(
         oms.PeakPickerHiRes(),
         **kwargs,
     )
Exemplo n.º 9
0
def main():

    parser = argparse.ArgumentParser(description="PeakPickerHiRes")
    parser.add_argument(
        "-in",
        action="store",
        type=str,
        dest="in_",
        metavar="input_file",
    )

    parser.add_argument(
        "-out",
        action="store",
        type=str,
        metavar="output_file",
    )

    parser.add_argument(
        "-ini",
        action="store",
        type=str,
        metavar="ini_file",
    )

    parser.add_argument(
        "-dict_ini",
        action="store",
        type=str,
        metavar="python_dict_ini_file",
    )

    parser.add_argument(
        "-write_ini",
        action="store",
        type=str,
        metavar="ini_file",
    )

    parser.add_argument(
        "-write_dict_ini",
        action="store",
        type=str,
        metavar="python_dict_ini_file",
    )

    args = parser.parse_args()

    run_mode = args.in_ is not None and args.out is not None\
                and (args.ini is not None or args.dict_ini is not None)
    write_mode = args.write_ini is not None or args.write_dict_ini is not None
    ok = run_mode or write_mode
    if not ok:
        parser.error("either specify -in, -out and -(dict)ini for running "
                     "the peakpicker\nor -write(dict)ini for creating std "
                     "ini file")

    defaults = pms.PeakPickerHiRes().getDefaults()
    if args.write_dict_ini or args.write_ini:
        if args.write_dict_ini:
            with open(args.write_dict_ini, "w") as fp:
                pprint.pprint(defaults.asDict(), stream=fp)
        if args.write_ini:
            defaults.store(args.write_ini)

    else:
        if args.ini:
            param = pms.Param()
            param.load(args.ini)
            defaults.update(param, False, False)
        elif args.dict_ini:
            with open(args.dict_ini, "r") as fp:
                try:
                    dd = eval(fp.read())
                except:
                    raise Exception("could not parse %s" % args.dict_ini)
            defaults.updateFrom(dd)

        fh = pms.MzXMLFile()
        fh.setLogType(pms.LogType.CMD)
        input_map = pms.MSExperiment()
        fh.load(args.in_, input_map)

        run_peak_picker(input_map, defaults, args.out)
Exemplo n.º 10
0
def main():

    parser = argparse.ArgumentParser(description="PeakPickerHiRes")
    parser.add_argument(
        "-in",
        action="store",
        type=str,
        dest="in_",
        metavar="input_file",
    )

    parser.add_argument(
        "-out",
        action="store",
        type=str,
        metavar="output_file",
    )

    parser.add_argument(
        "-ini",
        action="store",
        type=str,
        metavar="ini_file",
    )

    parser.add_argument(
        "-dict_ini",
        action="store",
        type=str,
        metavar="python_dict_ini_file",
    )

    parser.add_argument(
        "-write_ini",
        action="store",
        type=str,
        metavar="ini_file",
    )

    parser.add_argument(
        "-write_dict_ini",
        action="store",
        type=str,
        metavar="python_dict_ini_file",
    )

    args = parser.parse_args()

    run_mode = args.in_ is not None and args.out is not None\
                and (args.ini is not None or args.dict_ini is not None)
    write_mode = args.write_ini is not None or args.write_dict_ini is not None
    ok = run_mode or write_mode
    if not ok:
        parser.error("either specify -in, -out and -(dict)ini for running "
                     "the peakpicker\nor -write(dict)ini for creating std "
                     "ini file")

    defaults = pms.PeakPickerHiRes().getDefaults()

    write_requested = writeParamsIfRequested(args, defaults)

    if not write_requested:
        updateDefaults(args, defaults)

        fh = pms.MzMLFile()
        fh.setLogType(pms.LogType.CMD)
        input_map = pms.MSExperiment()
        fh.load(args.in_, input_map)

        run_peak_picker(input_map, defaults, args.out)
Exemplo n.º 11
0
    def find_features(self, pp_type: str, peak_radius: int,
                      window_radius: float, pp_mode: str, ff_type: str,
                      dir: str, filter: str,
                      debug: bool) -> List[List[ms.FeatureMap]]:
        """Runs optional peak picking and then an existing feature finder on each IM bin.

        Keyword arguments:
        pp_type: the peak picker to use ('none', 'pphr', or 'custom')
        peak_radius: for the custom peak picker, the minimum peak radius of a peak set
        window_radius: for the custom peak picker, the maximum m/z window radius to consider
        pp_mode: for the custom peak picker, the mode to use ('ltr' or 'int')
        ff_type: the existing feature finder to use ('centroided' or 'multiplex')
        dir: the directory to write the intermediate output files to
        filter: the noise filter to use ('none', 'gauss', or 'sgolay')
        debug: determines if intermediate output files should be written

        Returns: a list of two lists (for the passes), each containing the features for all of
            their bins.
        """
        features = [[], []]
        total_features = [ms.FeatureMap(),
                          ms.FeatureMap()]  # Only used for debug output

        if filter == 'gauss':
            filter_g = ms.GaussFilter()
            params_g = filter_g.getDefaults()
            params_g.setValue(b'ppm_tolerance', 20.0)
            params_g.setValue(b'use_ppm_tolerance', b'true')
            filter_g.setParameters(params_g)

        if filter == 'sgolay':
            filter_s = ms.SavitzkyGolayFilter()
            params_s = filter_s.getDefaults()
            params_s.setValue(b'frame_length', 7)
            params_s.setValue(b'polynomial_order', 3)
            filter_s.setParameters(params_s)

        pick_hr = ms.PeakPickerHiRes()
        pick_im = ppim.PeakPickerIonMobility()

        nb = [self.num_bins, 0 if self.num_bins == 1 else self.num_bins + 1
              ]  # Size of each pass

        for j in range(2):  # Pass index
            for i in range(nb[j]):  # Bin index
                exp, new_exp = ms.MSExperiment(), ms.MSExperiment()
                ms.MzMLFile().load(
                    dir + '/b-' + str(j) + '-' + str(i) + '.mzML', exp)

                # Optional noise filtering
                if filter == 'gauss':
                    filter_g.filterExperiment(exp)
                elif filter == 'sgolay':
                    filter_s.filterExperiment(exp)

                if filter != 'none' and debug:
                    ms.MzMLFile().store(
                        dir + '/pass' + str(j) + '-bin' + str(i) +
                        '-filtered.mzML', exp)

                # Optional peak picking
                if pp_type == 'pphr':
                    pick_hr.pickExperiment(exp, new_exp)
                elif pp_type == 'custom':
                    new_exp = pick_im.pick_experiment(exp,
                                                      peak_radius,
                                                      window_radius,
                                                      pp_mode,
                                                      self.MIN_INTENSITY,
                                                      strict=True)
                else:
                    new_exp = exp

                if pp_type != 'none' and debug:
                    ms.MzMLFile().store(
                        dir + '/pass' + str(j) + '-bin' + str(i) +
                        '-picked.mzML', new_exp)

                # Feature finding
                temp_features = ms.FeatureMap()
                if util.has_peaks(new_exp):
                    temp_features = self.run_ff(new_exp, ff_type)

                temp_features = self.match_features_internal(temp_features)
                temp_features.setUniqueIds()

                if debug:
                    ms.FeatureXMLFile().store(
                        dir + '/pass' + str(j) + '-bin' + str(i) +
                        '.featureXML', temp_features)

                features[j].append(temp_features)
                total_features[j] += temp_features

        if debug:
            for j in range(2):
                total_features[j].setUniqueIds()
                ms.FeatureXMLFile().store(
                    dir + '/pass' + str(j) + '.featureXML', total_features[j])

        return features[0], features[1]
Exemplo n.º 12
0
            print("A spectrum is not sorted")
            quit()

    # Parameters, default [type, constraints, default value]
    signal_to_noise = 0.0 # float, 0+, 0
    ms_levels = [ 1 ]
    win_len = 100.0 # float, 1+, 200
    bin_count = 20 # int, 3+, 30
    min_required_elements = 5 # int, 1+, 10

    # Parameters, advanced (not currently iterating through these)
    spacing_difference_gap = 4.0 # float, 0+, 4
    spacing_difference = 1.5 # float, 0+, 1.5
    missing = 1 # int, 0+, 1

    params = ms.PeakPickerHiRes().getParameters()
    
    params.__setitem__(b'ms_levels', ms_levels)

    params.__setitem__(b'spacing_difference_gap', spacing_difference_gap)
    params.__setitem__(b'spacing_difference', spacing_difference)
    params.__setitem__(b'missing', missing)

    # Iterate through the params, and for each set, run PeakPickerHiRes and
    # FeatureFinderCentroided, and save the param sets for those that find at least the
    # target number of features
    file = open(args.output + "/suitable_params.txt", "w+")

    for stn in np.arange(signal_to_noise, 1.5, 0.25):
        params.__setitem__(b'signal_to_noise', stn)