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

ConsensusPeak.h (Maintainer: Eva Lange)

Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 // --------------------------------------------------------------------------
00005 //                   OpenMS Mass Spectrometry Framework
00006 // --------------------------------------------------------------------------
00007 //  Copyright (C) 2003-2008 -- Oliver Kohlbacher, Knut Reinert
00008 //
00009 //  This library is free software; you can redistribute it and/or
00010 //  modify it under the terms of the GNU Lesser General Public
00011 //  License as published by the Free Software Foundation; either
00012 //  version 2.1 of the License, or (at your option) any later version.
00013 //
00014 //  This library is distributed in the hope that it will be useful,
00015 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 //  Lesser General Public License for more details.
00018 //
00019 //  You should have received a copy of the GNU Lesser General Public
00020 //  License along with this library; if not, write to the Free Software
00021 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 //
00023 // --------------------------------------------------------------------------
00024 // $Maintainer: Eva Lange $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_KERNEL_CONSENSUSPEAK_H
00028 #define OPENMS_KERNEL_CONSENSUSPEAK_H
00029 
00030 #include <OpenMS/KERNEL/StandardTypes.h>
00031 #include <OpenMS/KERNEL/DPeakArray.h>
00032 #include <OpenMS/DATASTRUCTURES/DRange.h>
00033 #include <OpenMS/ANALYSIS/MAPMATCHING/Group.h>
00034 
00035 namespace OpenMS
00036 {
00037   
00045   template < typename ContainerT = DPeakArray< Peak2D > >
00046   class ConsensusPeak
00047   : public Peak2D,
00048   public Group< ContainerT >
00049   {
00050     public:
00055       typedef Peak2D ElementType;
00056       typedef ContainerT ElementContainerType;
00057       typedef Group< ElementContainerType > Group;
00058       
00059       typedef DPosition < 2 > PositionType;
00060       typedef DoubleReal IntensityType;
00061       typedef IndexTuple< ElementContainerType > IndexTuple;
00062       typedef DRange<2> PositionBoundingBoxType;
00063       typedef DRange<1> IntensityBoundingBoxType;
00065       
00066       
00070 
00071       ConsensusPeak()
00072       : ElementType(),
00073       Group(),
00074       position_range_(),
00075       intensity_range_()
00076       {}
00077       
00079       ConsensusPeak(const PositionType& pos, IntensityType i)
00080       : ElementType(),
00081       Group(),
00082       position_range_(),
00083       intensity_range_()
00084       {
00085         this->setPosition(pos);
00086         this->setIntensity(i);
00087       }
00088       
00090       ConsensusPeak(UInt map_index,  UInt peak_index, const ElementType& peak)
00091       {
00092         try
00093         {
00094           IndexTuple i(map_index, peak_index, peak);
00095           i.setTransformedPosition(peak.getPosition());
00096           this->insert(IndexTuple(map_index, peak_index, peak));
00097         }
00098         catch(Exception::InvalidValue)
00099         {}
00100         
00101         this->getPosition() = peak.getPosition();
00102         this->setIntensity(peak.getIntensity());
00103         
00104         position_range_.setMinMax(peak.getPosition(), peak.getPosition());
00105         intensity_range_.setMinMax(peak.getIntensity(), peak.getIntensity());
00106       }
00107       
00109       ConsensusPeak(UInt map_1_index, UInt peak_index_1, const ElementType& peak_1,
00110       UInt map_2_index, UInt peak_index_2, const ElementType& peak_2)
00111       {
00112         try
00113         {
00114           IndexTuple i1(map_1_index, peak_index_1, peak_1);
00115           i1.setTransformedPosition(peak_1.getPosition());
00116           this->insert(i1);
00117           IndexTuple i2(map_2_index, peak_index_2, peak_2);
00118           i2.setTransformedPosition(peak_2.getPosition());
00119           this->insert(i2);
00120         }
00121         catch(Exception::InvalidValue)
00122         {}
00123         
00124         computeConsensus_();
00125       }
00126       
00128       ConsensusPeak(UInt map_index, UInt peak_index, const ElementType& peak, const ConsensusPeak& c_peak)
00129       {
00130         Group::operator=(c_peak);
00131         IndexTuple i(map_index, peak_index, peak);
00132         i.setTransformedPosition(peak.getPosition());
00133         this->insert(IndexTuple(map_index, peak_index, peak));
00134         
00135         computeConsensus_();
00136       }
00137       
00139       ConsensusPeak(const ConsensusPeak& c_peak_1, const ConsensusPeak& c_peak_2)
00140       {
00141         Group::operator=(c_peak_1);
00142         
00143         for (typename Group::iterator it = c_peak_2.begin(); it != c_peak_2.end(); ++it)
00144         {
00145           try
00146           {
00147             this->insert(*it);
00148           }
00149           catch(Exception::InvalidValue)
00150           {}
00151         }
00152         
00153         computeConsensus_();
00154       }
00155       
00156       
00158       inline ConsensusPeak(const ConsensusPeak& source)
00159       : ElementType(source),
00160       Group(source),
00161       position_range_(source.position_range_),
00162       intensity_range_(source.intensity_range_)
00163       {}
00164       
00166       ConsensusPeak& operator=(const ConsensusPeak& source)
00167       {
00168         if (&source==this)
00169           return *this;
00170         
00171         Group::operator=(source);
00172         ElementType::operator=(source);
00173         position_range_=source.position_range_;
00174         intensity_range_=source.intensity_range_;
00175         
00176         return *this;
00177       }
00178       
00180       virtual ~ConsensusPeak()
00181       {}
00183       
00184       
00185       void insert(const IndexTuple& tuple)
00186       {
00187         Group::insert(tuple);
00188         
00189         computeConsensus_();
00190       }
00191       
00193       inline const PositionBoundingBoxType& getPositionRange() const
00194       {
00195         return position_range_;
00196       }
00198       inline PositionBoundingBoxType& getPositionRange()
00199       {
00200         return position_range_;
00201       }
00203       inline void setPositionRange(const PositionBoundingBoxType& p)
00204       {
00205         position_range_= p;
00206       }
00207       
00209       inline const IntensityBoundingBoxType& getIntensityRange() const
00210       {
00211         return intensity_range_;
00212       }
00214       inline IntensityBoundingBoxType& getIntensityRange()
00215       {
00216         return intensity_range_;
00217       }
00219       inline void setIntensityRange(const IntensityBoundingBoxType& i)
00220       {
00221         intensity_range_ = i;
00222       }
00223       
00225       inline const Group& getPeaks() const
00226       {
00227         return *this;
00228       }
00230       inline Group& getPeaks()
00231       {
00232         return *this;
00233       }
00235       inline void setPeaks(const Group& g)
00236       {
00237         Group::operator=(g);
00238       }
00239       
00240       
00241       protected:
00242         PositionBoundingBoxType position_range_;
00243         IntensityBoundingBoxType intensity_range_;
00244         
00245         // compute the consensus attributes like intensity and position as well as the position and intensity range given by the group elements
00246         void computeConsensus_()
00247         {
00248           unsigned int n = Group::size();
00249           DPosition<2> sum_position;
00250           DPosition<2> pos_min(std::numeric_limits<DoubleReal>::max());
00251           DPosition<2> pos_max(std::numeric_limits<DoubleReal>::min());
00252           DPosition<1> sum_intensities = 0;
00253           DPosition<1> int_min(std::numeric_limits<DoubleReal>::max());
00254           DPosition<1> int_max(std::numeric_limits<DoubleReal>::min());
00255           for (typename Group::const_iterator it = Group::begin(); it != Group::end(); ++it)
00256           {
00257             DPosition<1> act_int = (it->getElement()).getIntensity();
00258             DPosition<2> act_pos = it->getTransformedPosition();
00259             
00260             if (int_min > act_int)
00261             {
00262               int_min = act_int;
00263             }
00264             if (int_max < act_int)
00265             {
00266               int_max = act_int;
00267             }
00268             
00269             for (UInt dim=0; dim < 2; ++dim)
00270             {
00271               if (act_pos[dim] > pos_max[dim])
00272                 pos_max[dim] = act_pos[dim];
00273               if (act_pos[dim] < pos_min[dim])
00274                 pos_min[dim] = act_pos[dim];
00275             }
00276             
00277             sum_intensities += act_int;
00278             sum_position += act_pos;
00279           }
00280           
00281           for (UInt dim = 0; dim< 2 ; ++dim)
00282           {
00283             this->position_[dim] = sum_position[dim] / n;
00284           }
00285           this->intensity_ = sum_intensities[0] / n;
00286           
00287           intensity_range_.setMinMax(int_min, int_max);
00288           position_range_.setMinMax(pos_min, pos_max);
00289         }
00290   };
00291   
00293   template < typename ContainerT >
00294   std::ostream& operator << (std::ostream& os, const ConsensusPeak<ContainerT>& cons)
00295   {
00296     os << "---------- CONSENSUS ELEMENT BEGIN -----------------\n";
00297     os << "Position: " << cons.getPosition()<< std::endl;
00298     os << "Intensity " << cons.getIntensity() << std::endl;
00299     os << "Position range " << cons.getPositionRange() << std::endl;
00300     os << "Intensity range " << cons.getIntensityRange() << std::endl;
00301     os << "Grouped elements: " << std::endl;
00302     
00303     UInt i = 1;
00304     os << "Size " << cons.count() << std::endl;
00305     for (typename ConsensusPeak<ContainerT>::Group::const_iterator it = cons.begin(); it != cons.end(); ++it, ++i)
00306     {
00307       os  << "Element: " << i << '\n'
00308       << "Transformed Position: " << it->getTransformedPosition() << '\n'
00309       << "Original Position: " << it->getElement() << '\n'
00310       << "Element index " << it->getElementIndex() << '\n'
00311       << "Map index " << it->getMapIndex() << std::endl;
00312       
00313     }
00314     os << "---------- CONSENSUS ELEMENT END ----------------- " << std::endl;
00315     
00316     return os;
00317   }
00318   
00319 } // namespace OpenMS
00320 
00321 #endif // OPENMS_KERNEL_CONSENSUSPEAK_H

Generated Tue Apr 1 15:36:33 2008 -- using doxygen 1.5.4 OpenMS / TOPP 1.1