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

FeatureMap.h (Maintainer: Ole Schulz-Trieglaff)

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: Ole Schulz-Trieglaff $
00025 // --------------------------------------------------------------------------
00026 
00027 #ifndef OPENMS_KERNEL_FEATUREMAP_H
00028 #define OPENMS_KERNEL_FEATUREMAP_H
00029 
00030 #include <OpenMS/config.h>
00031 #include <OpenMS/KERNEL/Feature.h>
00032 #include <OpenMS/METADATA/ExperimentalSettings.h>
00033 #include <OpenMS/KERNEL/RangeManager.h>
00034 
00035 #include <algorithm>
00036 #include <vector>
00037 
00038 namespace OpenMS
00039 {
00040 
00053   template <typename FeatureT = Feature >
00054   class FeatureMap
00055     : public std::vector<FeatureT>,
00056       public RangeManager<2>,
00057       public ExperimentalSettings
00058   {
00059    public:
00064       typedef FeatureT FeatureType;
00065       typedef RangeManager<2> RangeManagerType;
00066       typedef std::vector<FeatureType> Base;
00067       typedef typename Base::iterator Iterator;
00068       typedef typename Base::const_iterator ConstIterator;
00069       typedef typename Base::reverse_iterator ReverseIterator;
00070       typedef typename Base::const_reverse_iterator ConstReverseIterator;
00071       typedef FeatureType& Reference;
00072       typedef const FeatureType& ConstReference;
00073   
00075 
00079       
00081       FeatureMap()
00082         : Base(),
00083           RangeManagerType(),
00084           ExperimentalSettings()
00085       {
00086         
00087       }
00088       
00090       FeatureMap(const FeatureMap& map) 
00091         : Base(map),
00092           RangeManagerType(map),
00093           ExperimentalSettings(map)
00094       {
00095       
00096       }
00097       
00099       virtual ~FeatureMap()
00100       {
00101         
00102       }
00103       
00105         
00107       FeatureMap& operator = (const FeatureMap& rhs)
00108       {
00109         if (&rhs==this) return *this;
00110           
00111         Base::operator=(rhs);
00112         RangeManagerType::operator=(rhs);
00113         ExperimentalSettings::operator=(rhs);
00114         
00115         return *this;
00116       }
00117   
00119       bool operator == (const FeatureMap& rhs) const
00120       {
00121         return
00122           std::operator==(*this, rhs) &&
00123           RangeManagerType::operator==(rhs) &&
00124           ExperimentalSettings::operator==(rhs) 
00125           ;       
00126       }
00127         
00129       bool operator != (const FeatureMap& rhs) const
00130       {
00131         return !(operator==(rhs));
00132       }
00133         
00135       void sortByIntensity() 
00136       { 
00137         typename FeatureMap::iterator beg = this->begin();
00138         typename FeatureMap::iterator ed  = this->end();
00139         std::sort(beg, ed, typename FeatureType::IntensityLess() ); 
00140       }
00141         
00146       void sortByPosition() 
00147       { 
00148         std::sort(this->begin(), this->end(), typename FeatureType::PositionLess() );
00149       }
00150       
00155       void sortByNthPosition(UInt i) throw (Exception::NotImplemented);
00156         
00157       void sortByOverallQuality()
00158       {
00159         typename FeatureMap::iterator beg = this->begin();
00160         typename FeatureMap::iterator ed  = this->end();
00161         std::sort(beg, ed, typename FeatureType::OverallQualityLess() ); 
00162       }
00163       
00164       // Docu in base class
00165       void updateRanges()
00166       {
00167         this->clearRanges();
00168         updateRanges_(this->begin(),this->end());
00169       }
00170   };
00171   
00173   template <typename FeatureType >
00174   std::ostream& operator << (std::ostream& os, const FeatureMap<FeatureType>& map)
00175   {
00176     os << "# -- DFEATUREMAP BEGIN --"<< std::endl;
00177     os << "# POSITION \tINTENSITY\tOVERALLQUALITY\tCHARGE" << std::endl; 
00178     for (typename FeatureMap<FeatureType>::const_iterator iter = map.begin(); iter!=map.end(); iter++)
00179     {
00180       os << iter->getPosition() << '\t'
00181          << iter->getIntensity() << '\t'
00182          << iter->getOverallQuality() << '\t'
00183          << iter->getCharge()
00184          << std::endl;
00185     }
00186     os << "# -- DFEATUREMAP END --"<< std::endl;
00187     return os;
00188   }
00189   
00190   template <typename FeatureType > 
00191   void FeatureMap<FeatureType>::sortByNthPosition(UInt i) throw (Exception::NotImplemented)
00192   { 
00193     if (i==0)
00194     {
00195       std::sort(Base::begin(), Base::end(), typename FeatureType::template NthPositionLess<0>() );
00196     }
00197     else if (i==1)
00198     {
00199       std::sort(Base::begin(), Base::end(), typename FeatureType::template NthPositionLess<1>() );
00200     }
00201     else
00202     {
00203       throw Exception::NotImplemented(__FILE__,__LINE__,__FUNCTION__);
00204     }
00205   }
00206   
00207 } // namespace OpenMS
00208 
00209 #endif // OPENMS_KERNEL_DFEATUREMAP_H

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