Пример #1
0
    def test_run(self):
        thisfilter = pyopenms.GaussFilter()
        old_firstspec = self.exp[0]
        thisfilter.filterExperiment(self.exp)

        self.assertNotEqual(self.exp.size(), 0)
        self.assertNotEqual(old_firstspec, self.exp[0])

        # MZ should not change, Intensity should
        self.assertEqual(old_firstspec[10].getMZ(), self.exp[0][10].getMZ())
        self.assertNotEqual(old_firstspec[10].getIntensity(),
                            self.exp[0][10].getIntensity())
Пример #2
0
    def smoothing(self):

        if not self.smooth_profile_data:

            return

        self._log('Smoothing profile data by Gaussian filter.')

        gs = oms.GaussFilter()
        param = gs.getDefaults()
        self._oms_set_param(self.gs_param, param)
        gs.setParameters(param)

        gs.filterExperiment(self.profile_map)

        if self.export_smoothed_profile:

            self.smoothed_profile_mzml = os.path.join(
                self.wd,
                '%s__smoothed.mzML' % self.name,
            )
            self._log('Exporting smoothed profile '
                      'data into `%s`.' % self.smoothed_profile_mzml)
            oms.MzMLFile().store(self.smoothed_profile_mzml, self.profile_map)
Пример #3
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]
Пример #4
0
 def test_init(self):
     thisfilter = pyopenms.GaussFilter()