Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

FeatureFinderAlgorithmSH.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Florian Zeller $
00032 // $Authors: Florian Zeller $
00033 // --------------------------------------------------------------------------
00034 
00035 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSH_H
00036 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDERALGORITHMSH_H
00037 
00038 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinderAlgorithmSHCtrl.h>
00039 #include <OpenMS/TRANSFORMATIONS/FEATUREFINDER/FeatureFinderAlgorithm.h>
00040 
00041 #include "boost/shared_ptr.hpp"
00042 
00043 namespace OpenMS
00044 {
00101   template <class PeakType, class FeatureType>
00102   class FeatureFinderAlgorithmSH :
00103     public FeatureFinderAlgorithm<PeakType, FeatureType>,
00104     public FeatureFinderDefs
00105   {
00106 
00107 public:
00108     typedef typename FeatureFinderAlgorithm<PeakType, FeatureType>::MapType MapType; // MSExperiment
00109     typedef typename FeatureFinderAlgorithm<PeakType, FeatureType>::FeatureMapType FeatureMapType;
00110     typedef typename MapType::SpectrumType SpectrumType;
00111 
00112     using FeatureFinderAlgorithm<PeakType, FeatureType>::features_;
00113 
00114     FeatureFinderAlgorithmSH() :
00115       FeatureFinderAlgorithm<PeakType, FeatureType>()
00116     {
00117       // ----------------------------------------------------------------------------------------------------
00118       this->defaults_.setValue("centroiding:active", "false", "MS1 data centroid data");
00119       this->defaults_.setValidStrings("centroiding:active", StringList::create("true,false"));
00120       // ----------------------------------------------------------------------------------------------------
00121       this->defaults_.setValue("ms1:precursor_detection_scan_levels", IntList::create(1), "Precursor detection scan levels");
00122       // ----------------------------------------------------------------------------------------------------
00123       this->defaults_.setValue("ms1:max_inter_scan_distance", 0, "MS1 max inter scan distance");        // was 0.1
00124       this->defaults_.setMinInt("ms1:max_inter_scan_distance", 0);       // Markus needs to clarify this parameter
00125       // ----------------------------------------------------------------------------------------------------
00126       this->defaults_.setValue("ms1:tr_resolution", 0.01, "MS1 LC retention time resolution");         // seems to have no effect
00127       this->defaults_.setMinFloat("ms1:tr_resolution", 0);
00128       // ----------------------------------------------------------------------------------------------------
00129       this->defaults_.setValue("ms1:intensity_threshold", 1000.0, "FT peak detect MS1 intensity min threshold");
00130       this->defaults_.setMinFloat("ms1:intensity_threshold", 0);
00131       // ----------------------------------------------------------------------------------------------------
00132       this->defaults_.setValue("ms1:max_inter_scan_rt_distance", 0.1, "MS1 max inter scan distance");        // seems to have no effect
00133       this->defaults_.setMinFloat("ms1:max_inter_scan_rt_distance", 0);
00134       // ----------------------------------------------------------------------------------------------------
00135       this->defaults_.setValue("ms1:min_nb_cluster_members", 4, "FT peak detect MS1 min nb peak members");
00136       this->defaults_.setMinInt("ms1:min_nb_cluster_members", 0);
00137       // ----------------------------------------------------------------------------------------------------
00138       this->defaults_.setValue("ms1:detectable_isotope_factor", 0.05, "Detectable isotope factor");
00139       this->defaults_.setMinFloat("ms1:detectable_isotope_factor", 0);
00140       // ----------------------------------------------------------------------------------------------------
00141       this->defaults_.setValue("ms1:intensity_cv", 0.9, "IntensityCV");
00142       this->defaults_.setMinFloat("ms1:intensity_cv", 0);
00143       // ----------------------------------------------------------------------------------------------------
00144       this->defaults_.setValue("centroiding:window_width", 5, "Centroid window width");
00145       this->defaults_.setMinInt("centroiding:window_width", 1);
00146       // ----------------------------------------------------------------------------------------------------
00147       this->defaults_.setValue("centroiding:absolute_isotope_mass_precision", 0.01, "Absolute isotope mass precision (Da)");
00148       this->defaults_.setMinFloat("centroiding:absolute_isotope_mass_precision", 0.0);
00149       // ----------------------------------------------------------------------------------------------------
00150       this->defaults_.setValue("centroiding:relative_isotope_mass_precision", 10.0, "Relative isotope mass precision");
00151       this->defaults_.setMinFloat("centroiding:relative_isotope_mass_precision", 0.0);
00152       // ----------------------------------------------------------------------------------------------------
00153       this->defaults_.setValue("centroiding:minimal_peak_height", 0.0, "Minimal peak height");
00154       this->defaults_.setMinFloat("centroiding:minimal_peak_height", 0.0);
00155       // ----------------------------------------------------------------------------------------------------
00156       this->defaults_.setValue("centroiding:min_ms_signal_intensity", 50.0, "Minimal Centroid MS Signal Intensity");
00157       this->defaults_.setMinFloat("centroiding:min_ms_signal_intensity", 0.0);
00158       // ----------------------------------------------------------------------------------------------------
00159       this->defaults_.setValue("ms1:retention_time_tolerance", 0.5, "MS1 retention time tolerance (minutes)");
00160       this->defaults_.setMinFloat("ms1:retention_time_tolerance", 0.0);
00161       // ----------------------------------------------------------------------------------------------------
00162       this->defaults_.setValue("ms1:mz_tolerance", 0.0, "MS1 m/z tolerance (ppm)");
00163       this->defaults_.setMinFloat("ms1:mz_tolerance", 0.0);
00164       // ----------------------------------------------------------------------------------------------------
00165       this->defaults_.setValue("ms1_feature_merger:active", "true", "Activation of MS1 feature merging post processing");
00166       this->defaults_.setValidStrings("ms1_feature_merger:active", StringList::create("true,false"));
00167       // ----------------------------------------------------------------------------------------------------
00168       this->defaults_.setValue("ms1_feature_merger:tr_resolution", 0.01, "MS1 LC retention time resolution");
00169       this->defaults_.setMinFloat("ms1_feature_merger:tr_resolution", 0.0);
00170       // ----------------------------------------------------------------------------------------------------
00171       this->defaults_.setValue("ms1_feature_merger:initial_apex_tr_tolerance", 5.0, "Initial Apex Tr tolerance");
00172       this->defaults_.setMinFloat("ms1_feature_merger:initial_apex_tr_tolerance", 0.0);
00173       // ----------------------------------------------------------------------------------------------------
00174       this->defaults_.setValue("ms1_feature_merger:feature_merging_tr_tolerance", 1.0, "MS1 feature Tr merging tolerance");
00175       this->defaults_.setMinFloat("ms1_feature_merger:feature_merging_tr_tolerance", 0.0);
00176       // ----------------------------------------------------------------------------------------------------
00177       this->defaults_.setValue("ms1_feature_merger:intensity_variation_percentage", 25.0, "Percentage of intensity variation between LC border peaks");
00178       this->defaults_.setMinFloat("ms1_feature_merger:intensity_variation_percentage", 0.0);
00179       this->defaults_.setMaxFloat("ms1_feature_merger:intensity_variation_percentage", 100.0);
00180       // ----------------------------------------------------------------------------------------------------
00181       this->defaults_.setValue("ms1_feature_merger:ppm_tolerance_for_mz_clustering", 10.0, "PPM value for the m/z clustering of merging candidates");
00182       this->defaults_.setMinFloat("ms1_feature_merger:ppm_tolerance_for_mz_clustering", 0.0);
00183       // ----------------------------------------------------------------------------------------------------
00184       // ----------------------------------------------------------------------------------------------------
00185       this->defaults_.setValue("ms1_feature_selection_options:start_elution_window", 0.0, "start elution window (minutes)");
00186       this->defaults_.setMinFloat("ms1_feature_selection_options:start_elution_window", 0.0);
00187       // ----------------------------------------------------------------------------------------------------
00188       this->defaults_.setValue("ms1_feature_selection_options:end_elution_window", 180.0, "end elution window (minutes)");
00189       this->defaults_.setMinFloat("ms1_feature_selection_options:end_elution_window", 0.0);
00190       // ----------------------------------------------------------------------------------------------------
00191       this->defaults_.setValue("ms1_feature_selection_options:mz_range_min", 0.0, "MS1 feature mz range min");
00192       this->defaults_.setMinFloat("ms1_feature_selection_options:mz_range_min", 0.0);
00193       // ----------------------------------------------------------------------------------------------------
00194       this->defaults_.setValue("ms1_feature_selection_options:mz_range_max", 2000.0, "MS1 feature mz range max");
00195       this->defaults_.setMinFloat("ms1_feature_selection_options:mz_range_max", 0.0);
00196       // ----------------------------------------------------------------------------------------------------
00197       this->defaults_.setValue("ms1_feature_selection_options:chrg_range_min", 1, "MS1 feature CHRG range min");
00198       this->defaults_.setMinInt("ms1_feature_selection_options:chrg_range_min", 0);
00199       // ----------------------------------------------------------------------------------------------------
00200       this->defaults_.setValue("ms1_feature_selection_options:chrg_range_max", 5, "MS1 feature CHRG range max");
00201       this->defaults_.setMinInt("ms1_feature_selection_options:chrg_range_max", 0);
00202 
00203       this->check_defaults_ =  false;
00204     }
00205 
00206     unsigned int getNativeScanId(String native_id)
00207     {
00208 
00209       Size start_idx = 0;
00210       while (!isdigit(native_id[start_idx]) && start_idx < native_id.length())
00211       {
00212         ++start_idx;
00213       }
00214       if (start_idx == native_id.length())
00215       {
00216         std::cout << "Native id could not be determined: " << native_id;
00217         throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__, "Cannot convert native id to unsigned integer");
00218       }
00219 
00220       Size end_idx = start_idx;
00221       while (isdigit(native_id[end_idx]))
00222       {
00223         ++end_idx;
00224       }
00225 
00226       return native_id.substr(start_idx, end_idx - start_idx).toInt();
00227     }
00228 
00229     virtual void run()
00230     {
00231       std::cout << "SuperHirn feature extraction...\n";
00232 
00233       map_ = *(FeatureFinderAlgorithm<PeakType, FeatureType>::map_);
00234 
00235       MyMap dummyMap;
00236       Vec datavec;
00237       datavec.resize(map_.size());
00238       unsigned int scanId = 0;
00239 
00240       // Ordering by native IDs order by scan numbers
00241       // To achieve the exact same results as the original
00242       // superhirn does, this is necessary.
00243       // However, its is very experimental and will work
00244       // for all data since its based on string comparison.
00245       bool orderByNativeIds = false;
00246 
00247       // go through map, extract data and store it in a vector of RawData objects
00248       for (unsigned int s = 0; s < map_.size(); s++)
00249       {
00250         const SpectrumType & spectrum = map_[s];
00251         double rt = spectrum.getRT();
00252 
00253         if (orderByNativeIds)
00254         {
00255           scanId = getNativeScanId(spectrum.getNativeID());
00256           if (scanId == 0)
00257           {
00258             std::cout << "Order by native ids not working, turning it off.\n";
00259             orderByNativeIds = false;
00260             scanId = 1;
00261           }
00262         }
00263         else
00264         {
00265           scanId++;
00266         }
00267 
00268         std::vector<double> vmzvals;
00269         std::vector<double> vintvals;
00270 
00271         for (Size p = 0; p < spectrum.size(); ++p)
00272         {
00273           vmzvals.push_back(spectrum[p].getMZ());
00274           vintvals.push_back(spectrum[p].getIntensity());
00275         }
00276 
00277         //RawData* data = new RawData(vmzvals, vintvals);
00278         boost::shared_ptr<RawData> data_ptr(new RawData(vmzvals, vintvals));
00279 
00280         MyMap map_ptr(rt / 60, data_ptr);
00281 //        m[rt/60.0] = data;
00282         unsigned int scanIndex = scanId - 1;
00283         datavec[scanIndex] = map_ptr;
00284       }
00285 
00286       // apply the SuperHirn FeatureFinder algorithm
00287       FeatureFinderAlgorithmSHCtrl ctrl;
00288       ctrl.initParams(this->param_);
00289       std::vector<Feature> thefeatures = ctrl.extractPeaks(datavec);
00290 
00291       for (unsigned int i = 0; i < thefeatures.size(); ++i)
00292         features_->push_back(thefeatures[i]);
00293     }
00294 
00295     static FeatureFinderAlgorithm<Peak1D, Feature> * create()
00296     {
00297       return new FeatureFinderAlgorithmSH();
00298     }
00299 
00300     static const String getProductName()
00301     {
00302       return "superhirn";
00303     }
00304 
00305 protected:
00306     MapType map_;
00307 
00308   };
00309 
00310 }
00311 
00312 #endif

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:39 using doxygen 1.7.1