Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef OPENMS_KERNEL_FEATUREMAP_H
00036 #define OPENMS_KERNEL_FEATUREMAP_H
00037
00038 #include <OpenMS/KERNEL/Feature.h>
00039 #include <OpenMS/METADATA/DocumentIdentifier.h>
00040 #include <OpenMS/METADATA/ProteinIdentification.h>
00041 #include <OpenMS/METADATA/DataProcessing.h>
00042 #include <OpenMS/KERNEL/RangeManager.h>
00043 #include <OpenMS/KERNEL/ComparatorUtils.h>
00044 #include <OpenMS/CONCEPT/UniqueIdIndexer.h>
00045
00046 #include <algorithm>
00047 #include <vector>
00048 #include <exception>
00049
00050 namespace OpenMS
00051 {
00052
00067 template <typename FeatureT = Feature>
00068 class FeatureMap :
00069 public std::vector<FeatureT>,
00070 public RangeManager<2>,
00071 public DocumentIdentifier,
00072 public UniqueIdInterface,
00073 public UniqueIdIndexer<FeatureMap<FeatureT> >
00074 {
00075 public:
00080 typedef FeatureT FeatureType;
00081 typedef RangeManager<2> RangeManagerType;
00082 typedef std::vector<FeatureType> Base;
00083 typedef typename Base::iterator Iterator;
00084 typedef typename Base::const_iterator ConstIterator;
00085 typedef typename Base::reverse_iterator ReverseIterator;
00086 typedef typename Base::const_reverse_iterator ConstReverseIterator;
00087 typedef FeatureType & Reference;
00088 typedef const FeatureType & ConstReference;
00090
00095
00097 FeatureMap() :
00098 Base(),
00099 RangeManagerType(),
00100 DocumentIdentifier(),
00101 UniqueIdInterface(),
00102 UniqueIdIndexer<FeatureMap<FeatureT> >(),
00103 protein_identifications_(),
00104 unassigned_peptide_identifications_(),
00105 data_processing_()
00106 {}
00107
00109 FeatureMap(const FeatureMap & source) :
00110 Base(source),
00111 RangeManagerType(source),
00112 DocumentIdentifier(source),
00113 UniqueIdInterface(source),
00114 UniqueIdIndexer<FeatureMap<FeatureT> >(source),
00115 protein_identifications_(source.protein_identifications_),
00116 unassigned_peptide_identifications_(source.unassigned_peptide_identifications_),
00117 data_processing_(source.data_processing_)
00118 {}
00119
00121 virtual ~FeatureMap()
00122 {}
00124
00126 FeatureMap & operator=(const FeatureMap & rhs)
00127 {
00128 if (&rhs == this) return *this;
00129
00130 Base::operator=(rhs);
00131 RangeManagerType::operator=(rhs);
00132 DocumentIdentifier::operator=(rhs);
00133 UniqueIdInterface::operator=(rhs);
00134 protein_identifications_ = rhs.protein_identifications_;
00135 unassigned_peptide_identifications_ = rhs.unassigned_peptide_identifications_;
00136 data_processing_ = rhs.data_processing_;
00137
00138 return *this;
00139 }
00140
00142 bool operator==(const FeatureMap & rhs) const
00143 {
00144 return std::operator==(*this, rhs) &&
00145 RangeManagerType::operator==(rhs) &&
00146 DocumentIdentifier::operator==(rhs) &&
00147 UniqueIdInterface::operator==(rhs) &&
00148 protein_identifications_ == rhs.protein_identifications_ &&
00149 unassigned_peptide_identifications_ == rhs.unassigned_peptide_identifications_ &&
00150 data_processing_ == rhs.data_processing_;
00151 }
00152
00154 bool operator!=(const FeatureMap & rhs) const
00155 {
00156 return !(operator==(rhs));
00157 }
00158
00164 FeatureMap operator+(const FeatureMap & rhs) const
00165 {
00166 FeatureMap tmp(*this);
00167 tmp += rhs;
00168 return tmp;
00169 }
00170
00183 FeatureMap & operator+=(const FeatureMap & rhs)
00184 {
00185 FeatureMap empty_map;
00186
00187 RangeManagerType::operator=(empty_map);
00188
00189 if (!this->getIdentifier().empty() || !rhs.getIdentifier().empty()) LOG_INFO << "DocumentIdentifiers are lost during merge of FeatureMaps\n";
00190 DocumentIdentifier::operator=(empty_map);
00191
00192 UniqueIdInterface::operator=(empty_map);
00193
00194
00195 protein_identifications_.insert(protein_identifications_.end(), rhs.protein_identifications_.begin(), rhs.protein_identifications_.end());
00196 unassigned_peptide_identifications_.insert(unassigned_peptide_identifications_.end(), rhs.unassigned_peptide_identifications_.begin(), rhs.unassigned_peptide_identifications_.end());
00197 data_processing_.insert(data_processing_.end(), rhs.data_processing_.begin(), rhs.data_processing_.end());
00198
00199
00200 this->insert(this->end(), rhs.begin(), rhs.end());
00201
00202
00203
00204
00205
00206 try
00207 {
00208 UniqueIdIndexer<FeatureMap<FeatureT> >::updateUniqueIdToIndex();
00209 }
00210 catch (Exception::Postcondition )
00211 {
00212 Size replaced_uids = UniqueIdIndexer<FeatureMap<FeatureT> >::resolveUniqueIdConflicts();
00213 LOG_INFO << "Replaced " << replaced_uids << " invalid uniqueID's\n";
00214 }
00215
00216 return *this;
00217 }
00218
00225
00226 void sortByIntensity(bool reverse = false)
00227 {
00228 if (reverse)
00229 {
00230 std::sort(this->begin(), this->end(), reverseComparator(typename FeatureType::IntensityLess()));
00231 }
00232 else
00233 {
00234 std::sort(this->begin(), this->end(), typename FeatureType::IntensityLess());
00235 }
00236 }
00237
00239 void sortByPosition()
00240 {
00241 std::sort(this->begin(), this->end(), typename FeatureType::PositionLess());
00242 }
00243
00245 void sortByRT()
00246 {
00247 std::sort(this->begin(), this->end(), typename FeatureType::RTLess());
00248 }
00249
00251 void sortByMZ()
00252 {
00253 std::sort(this->begin(), this->end(), typename FeatureType::MZLess());
00254 }
00255
00257 void sortByOverallQuality(bool reverse = false)
00258 {
00259 if (reverse)
00260 {
00261 std::sort(this->begin(), this->end(), reverseComparator(typename FeatureType::OverallQualityLess()));
00262 }
00263 else
00264 {
00265 std::sort(this->begin(), this->end(), typename FeatureType::OverallQualityLess());
00266 }
00267 }
00268
00270
00271
00272 void updateRanges()
00273 {
00274 this->clearRanges();
00275 updateRanges_(this->begin(), this->end());
00276
00277
00278 for (Size i = 0; i < this->size(); ++i)
00279 {
00280 DBoundingBox<2> box = this->operator[](i).getConvexHull().getBoundingBox();
00281 if (!box.isEmpty())
00282 {
00283
00284 if (box.minPosition()[Peak2D::RT] < this->pos_range_.minPosition()[Peak2D::RT])
00285 {
00286 this->pos_range_.setMinX(box.minPosition()[Peak2D::RT]);
00287 }
00288 if (box.maxPosition()[Peak2D::RT] > this->pos_range_.maxPosition()[Peak2D::RT])
00289 {
00290 this->pos_range_.setMaxX(box.maxPosition()[Peak2D::RT]);
00291 }
00292
00293 if (box.minPosition()[Peak2D::MZ] < this->pos_range_.minPosition()[Peak2D::MZ])
00294 {
00295 this->pos_range_.setMinY(box.minPosition()[Peak2D::MZ]);
00296 }
00297 if (box.maxPosition()[Peak2D::MZ] > this->pos_range_.maxPosition()[Peak2D::MZ])
00298 {
00299 this->pos_range_.setMaxY(box.maxPosition()[Peak2D::MZ]);
00300 }
00301 }
00302 }
00303 }
00304
00306 void swap(FeatureMap & from)
00307 {
00308 FeatureMap tmp;
00309
00310
00311 Base::swap(from);
00312
00313
00314 tmp.RangeManagerType::operator=(* this);
00315 this->RangeManagerType::operator=(from);
00316 from.RangeManagerType::operator=(tmp);
00317
00318
00319 DocumentIdentifier::swap(from);
00320
00321
00322 UniqueIdInterface::swap(from);
00323
00324
00325 UniqueIdIndexer<FeatureMap<FeatureT> >::swap(from);
00326
00327
00328 protein_identifications_.swap(from.protein_identifications_);
00329 unassigned_peptide_identifications_.swap(from.unassigned_peptide_identifications_);
00330 data_processing_.swap(from.data_processing_);
00331 }
00332
00334 const std::vector<ProteinIdentification> & getProteinIdentifications() const
00335 {
00336 return protein_identifications_;
00337 }
00338
00340 std::vector<ProteinIdentification> & getProteinIdentifications()
00341 {
00342 return protein_identifications_;
00343 }
00344
00346 void setProteinIdentifications(const std::vector<ProteinIdentification> & protein_identifications)
00347 {
00348 protein_identifications_ = protein_identifications;
00349 }
00350
00352 const std::vector<PeptideIdentification> & getUnassignedPeptideIdentifications() const
00353 {
00354 return unassigned_peptide_identifications_;
00355 }
00356
00358 std::vector<PeptideIdentification> & getUnassignedPeptideIdentifications()
00359 {
00360 return unassigned_peptide_identifications_;
00361 }
00362
00364 void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification> & unassigned_peptide_identifications)
00365 {
00366 unassigned_peptide_identifications_ = unassigned_peptide_identifications;
00367 }
00368
00370 const std::vector<DataProcessing> & getDataProcessing() const
00371 {
00372 return data_processing_;
00373 }
00374
00376 std::vector<DataProcessing> & getDataProcessing()
00377 {
00378 return data_processing_;
00379 }
00380
00382 void setDataProcessing(const std::vector<DataProcessing> & processing_method)
00383 {
00384 data_processing_ = processing_method;
00385 }
00386
00392 void clear(bool clear_meta_data = true)
00393 {
00394 Base::clear();
00395
00396 if (clear_meta_data)
00397 {
00398 clearRanges();
00399 this->DocumentIdentifier::operator=(DocumentIdentifier());
00400 clearUniqueId();
00401 protein_identifications_.clear();
00402 unassigned_peptide_identifications_.clear();
00403 data_processing_.clear();
00404 }
00405 }
00406
00419 template <typename Type>
00420 Size applyMemberFunction(Size (Type::* member_function)())
00421 {
00422 Size assignments = 0;
00423 assignments += ((*this).*member_function)();
00424 for (Iterator iter = this->begin(); iter != this->end(); ++iter)
00425 {
00426 assignments += iter->applyMemberFunction(member_function);
00427 }
00428 return assignments;
00429 }
00430
00432 template <typename Type>
00433 Size applyMemberFunction(Size (Type::* member_function)() const) const
00434 {
00435 Size assignments = 0;
00436 assignments += ((*this).*member_function)();
00437 for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
00438 {
00439 assignments += iter->applyMemberFunction(member_function);
00440 }
00441 return assignments;
00442 }
00443
00444 protected:
00445
00447 std::vector<ProteinIdentification> protein_identifications_;
00448
00450 std::vector<PeptideIdentification> unassigned_peptide_identifications_;
00451
00453 std::vector<DataProcessing> data_processing_;
00454 };
00455
00457 template <typename FeatureType>
00458 std::ostream & operator<<(std::ostream & os, const FeatureMap<FeatureType> & map)
00459 {
00460 os << "# -- DFEATUREMAP BEGIN --" << "\n";
00461 os << "# POS \tINTENS\tOVALLQ\tCHARGE\tUniqueID" << "\n";
00462 for (typename FeatureMap<FeatureType>::const_iterator iter = map.begin(); iter != map.end(); iter++)
00463 {
00464 os << iter->getPosition() << '\t'
00465 << iter->getIntensity() << '\t'
00466 << iter->getOverallQuality() << '\t'
00467 << iter->getCharge() << '\t'
00468 << iter->getUniqueId() << "\n";
00469 }
00470 os << "# -- DFEATUREMAP END --" << std::endl;
00471 return os;
00472 }
00473
00474 }
00475
00476 #endif // OPENMS_KERNEL_DFEATUREMAP_H