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

BasePairwiseMapMatcher.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 
00028 #ifndef OPENMS_ANALYSIS_MAPMATCHING_BASEPAIRWISEMAPMATCHER_H
00029 #define OPENMS_ANALYSIS_MAPMATCHING_BASEPAIRWISEMAPMATCHER_H
00030 
00031 #include <OpenMS/ANALYSIS/MAPMATCHING/ElementPair.h>
00032 #include <OpenMS/ANALYSIS/MAPMATCHING/Grid.h>
00033 #include <OpenMS/KERNEL/FeatureMap.h>
00034 #include <OpenMS/DATASTRUCTURES/DBoundingBox.h>
00035 #include <OpenMS/CONCEPT/FactoryProduct.h>
00036 
00037 #include <utility>
00038 #include <fstream>
00039 
00040 namespace OpenMS
00041 {
00042 
00063   template < typename MapT = FeatureMap< > >
00064   class BasePairwiseMapMatcher 
00065     : public FactoryProduct
00066   {
00067   public:
00069     typedef MapT PointMapType;
00070 
00072     typedef typename PointMapType::value_type ElementType;
00073 
00075     typedef ElementPair < ElementType > ElementPairType;
00076 
00078     typedef std::vector < ElementPairType > ElementPairVectorType;
00079 
00081     typedef DPosition < 2 > PositionType;
00082 
00084     typedef DBoundingBox< 2>  PositionBoundingBoxType;
00085 
00087     typedef DoubleReal CoordinateType;
00088 
00089 
00091     BasePairwiseMapMatcher()
00092         : FactoryProduct("BasePairWiseMapMatcher")
00093     {
00094       element_map_[0] = 0;
00095       element_map_[1] = 0;
00096       defaults_.setValue("number_buckets:RT",1, "To obtain a piecewise defined warping function the retention time dimension can be divided into a number of buckets.",true);
00097       defaults_.setValue("number_buckets:MZ",1, "To obtain a piecewise defined warping function the m/z dimension can be divided into a number of buckets.",true);
00098       
00099       // no need to call defaultsToParam_() as it is called in the non-abstract children 
00100     }
00101 
00102    
00104     virtual ~BasePairwiseMapMatcher()
00105     {
00106     }
00107     
00109     void setElementMap(UInt const index, const PointMapType& element_map)
00110     {
00111       element_map_[index] = &element_map;
00112     }
00113 
00115     const PointMapType& getElementMap(UInt index) const
00116     {
00117       return *element_map_[index];
00118     }
00119 
00121     const ElementPairVectorType& getElementPairs() const
00122     {
00123       return all_element_pairs_;
00124     }
00125 
00127     const Grid& getGrid() const
00128     {
00129       return grid_;
00130     }
00131 
00133     void setNumberBuckets(UInt dim, UInt number)
00134     {
00135       number_buckets_[dim] = number;
00136       param_.setValue(String("number_buckets:") + RawDataPoint2D::shortDimensionName(dim), number);
00137     }
00138 
00140     UInt getNumberBuckets(UInt index) const
00141     {
00142       return number_buckets_[index];
00143     }
00144 
00146     static void registerChildren();
00147 
00149     virtual void run() = 0;
00150 
00152     void initGridTransformation(const PointMapType& scene_map)
00153     {
00154       grid_.clear();
00155       bounding_box_scene_map_.clear();
00156       
00157       // compute the minimal and maximal positions of the second map (the map, which should be transformed)
00158       for ( typename PointMapType::const_iterator fm_iter = scene_map.begin();
00159             fm_iter != scene_map.end();
00160             ++fm_iter
00161           )
00162       {
00163         bounding_box_scene_map_.enlarge(fm_iter->getPosition());
00164       }
00165 
00166       // compute the grid sizes in each dimension
00167       // ???? I added the "-0.01" adjustment because otherwise this will almost certainly crash when the right margin point comes by!!  Clemens
00168       // TODO: find a better way that does not use such a magic constant. As is, the bounding box reported in the output is incorrect!
00169       for (UInt i = 0; i < 2; ++i)
00170       {
00171         box_size_[i] =
00172           (bounding_box_scene_map_.max()[i] - bounding_box_scene_map_.min()[i]) /
00173           ( number_buckets_[i] - 0.01 /* <- magic constant */);
00174       }
00175 
00176       // initialize the grid cells of the grid_
00177       for (UInt x_index = 0; x_index < number_buckets_[RawDataPoint2D::RT]; ++x_index)
00178       {
00179         for (UInt y_index = 0; y_index < number_buckets_[RawDataPoint2D::MZ]; ++y_index)
00180         {
00181           CoordinateType x_min = (bounding_box_scene_map_.min())[RawDataPoint2D::RT] + box_size_[RawDataPoint2D::RT]*x_index;
00182           CoordinateType x_max = (bounding_box_scene_map_.min())[RawDataPoint2D::RT] + box_size_[RawDataPoint2D::RT]*(x_index+1);
00183           CoordinateType y_min = (bounding_box_scene_map_.min())[RawDataPoint2D::MZ] + box_size_[RawDataPoint2D::MZ]*y_index;
00184           CoordinateType y_max = (bounding_box_scene_map_.min())[RawDataPoint2D::MZ] + box_size_[RawDataPoint2D::MZ]*(y_index+1);
00185 
00186           grid_.push_back(GridCell(x_min, y_min, x_max, y_max));
00187         }
00188       }
00189     } // initGridTransformation_
00190 
00191 
00192 
00193     //  int dumpElementPairs(const String& filename); // code is below
00194 
00195   protected:
00196     virtual void updateMembers_()
00197     {
00198       for ( UInt dim = 0; dim < 2; ++dim)
00199       {
00200         number_buckets_[dim] = param_.getValue(String("number_buckets:") + RawDataPoint2D::shortDimensionName(dim));
00201       }
00202     }
00203     
00205     PointMapType const * element_map_[2];
00206 
00208     ElementPairVectorType all_element_pairs_;
00209 
00211     Grid grid_;
00212 
00214     PositionBoundingBoxType bounding_box_scene_map_;
00215 
00217     PositionType box_size_;
00218 
00220     UInt number_buckets_[2];
00221   }
00222   ; // BasePairwiseMapMatcher
00223 
00224 
00225   //   template < typename MapT >
00226   //   int BasePairwiseMapMatcher<MapT>::dumpElementPairs(const String& filename)
00227   //   {
00228   //     // V_dumpElementPairs() is used for a few comments about the files being
00229   //     // written.
00230   // #define V_dumpElementPairs(bla) std::cerr << bla << std::endl;
00231   //     V_dumpElementPairs("### Writing "<<filename);
00232   //     std::ofstream dump_file(filename.c_str());
00233   //     dump_file << "# " << filename<< " generated " << Date::now() << std::endl;
00234   //     dump_file << "# 1:number 2:quality 3:firstRT 4:firstMZ 5:firstIT 6:firstQual 7:secondRT 8:secondMZ 9:secondIT 10:secondQual\n";
00235   //     for ( UInt fp = 0; fp < getElementPairs().size(); ++fp )
00236   //     {
00237   //       dump_file << fp << ' '
00238   //       << getElementPairs()[fp].getQuality() << ' '
00239   //       << getElementPairs()[fp].getFirst().getRT() << ' '
00240   //       << getElementPairs()[fp].getFirst().getMZ() << ' '
00241   //       << getElementPairs()[fp].getFirst().getIntensity() << ' '
00242   //       << getElementPairs()[fp].getFirst().getOverallQuality() << ' '
00243   //       << getElementPairs()[fp].getSecond().getRT() << ' '
00244   //       << getElementPairs()[fp].getSecond().getMZ() << ' '
00245   //       << getElementPairs()[fp].getSecond().getIntensity() << ' '
00246   //       << getElementPairs()[fp].getSecond().getOverallQuality() << ' '
00247   //       << std::endl;
00248   //     }
00249   //     dump_file << "# " << filename << " EOF " << Date::now() << std::endl;
00250   //     std::string dump_filename_gp = filename + ".gp";
00251   //     V_dumpElementPairs("### Writing "<<dump_filename_gp);
00252   //     std::ofstream dump_file_gp(dump_filename_gp.c_str());
00253   //     dump_file_gp << "# " << dump_filename_gp << " generated " << Date::now() << std::endl;
00254   //     dump_file_gp <<
00255   //     "# Gnuplot script to view element pairs\n"
00256   //     "plot   \"" << filename <<"\" using 3:4 title \"map 1\"\n"
00257   //     "replot \"" << filename <<"\" using 7:8 title \"map 2\"\n"
00258   //     "replot \"" << filename <<"\" using 3:4:($7-$3):($8-$4) w vectors nohead title \"pairs\"\n"
00259   //     ;
00260   //     dump_file_gp << "# " << dump_filename_gp << " EOF " << Date::now() << std::endl;
00261   //     V_dumpElementPairs("### You can view `"<<filename<<"' using the command line `gnuplot "<<dump_filename_gp<<" -'");
00262   // #undef V_dumpElementPairs
00263   //
00264   //     return 0;
00265   //   }
00266 
00267 } // namespace OpenMS
00268 
00269 #endif  // OPENMS_ANALYSIS_MAPMATCHING_BASEPAIRWISEMAPMATCHER_H

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