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

BasePairFinder.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_BASEPAIRFINDER_H
00029 #define OPENMS_ANALYSIS_MAPMATCHING_BASEPAIRFINDER_H
00030 
00031 #include <OpenMS/ANALYSIS/MAPMATCHING/ElementPair.h>
00032 #include <OpenMS/ANALYSIS/MAPMATCHING/Grid.h>
00033 #include <OpenMS/ANALYSIS/MAPMATCHING/LinearMapping.h>
00034 #include <OpenMS/KERNEL/FeatureMap.h>
00035 #include <OpenMS/CONCEPT/FactoryProduct.h>
00036 
00037 #include <utility>
00038 #include <fstream>
00039 
00040 namespace OpenMS
00041 {
00042 
00059   template < typename MapT = FeatureMap< > >
00060   class BasePairFinder 
00061     : public FactoryProduct
00062   {
00063   public:
00064 
00068     enum Maps
00069     {
00070       MODEL = 0,
00071       SCENE = 1
00072     };
00073 
00075     typedef MapT PointMapType;
00076 
00078     typedef typename PointMapType::value_type PointType;
00079 
00081     //typedef typename PointType::TraitsType TraitsType;
00082 
00084     typedef DPosition < 2 > PositionType;
00085 
00087 
00088     //typedef typename TraitsType::QualityType QualityType;
00089     typedef DoubleReal QualityType;
00090 
00092     //typedef typename TraitsType::IntensityType IntensityType;
00093     typedef DoubleReal IntensityType;
00094 
00096     typedef ElementPair < PointType > ElementPairType;
00097 
00099     typedef std::vector < ElementPairType > ElementPairVectorType;
00100 
00102     typedef LinearMapping TransformationType;
00103 
00105     BasePairFinder()
00106         : FactoryProduct("BasePairFinder"),
00107         element_pairs_(0)
00108     {
00109       element_map_[MODEL] = 0;
00110       element_map_[SCENE] = 0;
00111       transformation_[RawDataPoint2D::RT].setSlope(1);
00112       transformation_[RawDataPoint2D::RT].setIntercept(0);
00113       transformation_[RawDataPoint2D::MZ].setSlope(1);
00114       transformation_[RawDataPoint2D::MZ].setIntercept(0);
00115     }
00116 
00118     virtual ~BasePairFinder()
00119     {
00120     }
00121 
00122     void setElementMap(UInt const index, const PointMapType& element_map)
00123     {
00124       element_map_[index] = &element_map;
00125     }
00126 
00128     const PointMapType& getElementMap(UInt index) const
00129     {
00130       return *element_map_[index];
00131     }
00132 
00134     void setElementPairs(ElementPairVectorType& element_pairs)
00135     {
00136       element_pairs_ = &element_pairs;
00137     }
00138 
00140     const ElementPairVectorType& getElementPairs() const
00141     {
00142       return *element_pairs_;
00143     }
00144 
00146     void setTransformation(UInt dim, const TransformationType& trafo)
00147     {
00148       transformation_[dim] = trafo;
00149     }
00150 
00152     const TransformationType& getTransformation(UInt dim) const
00153     {
00154       return transformation_[dim];
00155     }
00156 
00158     static void registerChildren();
00159 
00170     virtual int dumpElementPairs(const String& filename); // code is below
00171 
00173     virtual void findElementPairs() = 0;
00174 
00175   protected:
00177     PointMapType const * element_map_[2];
00178 
00180     TransformationType transformation_[2];
00181 
00183     mutable ElementPairVectorType * element_pairs_;
00184 
00185 
00187     Int computeGridCellIndex_(const PositionType& pos, const Grid& grid) throw (Exception::InvalidValue)
00188     {
00189       UInt index = 0;
00190       Grid::ConstIterator it = grid.begin();
00191       while ( it != grid.end() )
00192       {
00193         if (it->encloses(pos))
00194         {
00195           return index;
00196         }
00197         ++it;
00198         ++index;
00199       }
00200       throw Exception::InvalidValue(__FILE__, __LINE__, __PRETTY_FUNCTION__,"The position is not contained in any of the grid cells.","") ;
00201     }
00202   }
00203   ; // BasePairFinder
00204 
00205 
00206   template <typename MapT >
00207   int BasePairFinder<MapT>::dumpElementPairs(const String& filename)
00208   {
00209     // V_dumpElementPairs() is used for a few comments about the files being
00210     // written.  We are silent unless output is actually being written, so
00211     // it is defined here inside the "else" branch.
00212 #define V_dumpElementPairs(bla) std::cerr << bla << std::endl;
00213     V_dumpElementPairs("### Writing "<<filename);
00214     std::ofstream dump_file(filename.c_str());
00215     dump_file << "# " << filename<< " generated " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString() << std::endl;
00216     dump_file << "# 1:number 2:quality 3:firstRT 4:firstMZ 5:firstIT 6:firstQual 7:secondRT 8:secondMZ 9:secondIT 10:secondQual\n";
00217     for ( UInt fp = 0; fp < getElementPairs().size(); ++fp )
00218     {
00219       dump_file << fp << ' '
00220       << getElementPairs()[fp].getFirst().getRT() << ' '
00221       << getElementPairs()[fp].getFirst().getMZ() << ' '
00222       << getElementPairs()[fp].getFirst().getIntensity() << ' '
00223       << getElementPairs()[fp].getSecond().getRT() << ' '
00224       << getElementPairs()[fp].getSecond().getMZ() << ' '
00225       << getElementPairs()[fp].getSecond().getIntensity() << ' '
00226       << std::endl;
00227     }
00228     dump_file << "# " << filename << " EOF " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString() << std::endl;
00229     std::string dump_filename_gp = filename + ".gp";
00230     V_dumpElementPairs("### Writing "<<dump_filename_gp);
00231     std::ofstream dump_file_gp(dump_filename_gp.c_str());
00232     dump_file_gp << "# " << dump_filename_gp << " generated " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString() << std::endl;
00233     dump_file_gp <<
00234     "# Gnuplot script to view element pairs\n"
00235     "plot   \"" << filename <<"\" using 2:3 title \"map 1\"\n"
00236     "replot \"" << filename <<"\" using 5:6 title \"map 2\"\n"
00237     "replot \"" << filename <<"\" using 2:3:($5-$2):($6-$3) w vectors nohead title \"pairs\"\n"
00238     ;
00239     dump_file_gp << "# " << dump_filename_gp << " EOF " << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss").toStdString() << std::endl;
00240     V_dumpElementPairs("### You can view `"<<filename<<"' using the command line `gnuplot "<<dump_filename_gp<<" -'");
00241 #undef V_dumpElementPairs
00242 
00243     return 0;
00244   }
00245 } // namespace OpenMS
00246 
00247 #endif  // OPENMS_ANALYSIS_MAPMATCHING_BASEPAIRFINDER_H

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