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_CONSENSUSMAP_H
00036 #define OPENMS_KERNEL_CONSENSUSMAP_H
00037
00038 #include <OpenMS/DATASTRUCTURES/Map.h>
00039 #include <OpenMS/KERNEL/MSExperiment.h>
00040 #include <OpenMS/KERNEL/ConsensusFeature.h>
00041 #include <OpenMS/KERNEL/RangeManager.h>
00042 #include <OpenMS/KERNEL/ComparatorUtils.h>
00043 #include <OpenMS/METADATA/ProteinIdentification.h>
00044 #include <OpenMS/KERNEL/FeatureMap.h>
00045 #include <OpenMS/CONCEPT/UniqueIdIndexer.h>
00046
00047 namespace OpenMS
00048 {
00060 class ConsensusMap :
00061 public std::vector<ConsensusFeature>,
00062 public MetaInfoInterface,
00063 public RangeManager<2>,
00064 public DocumentIdentifier,
00065 public UniqueIdInterface,
00066 public UniqueIdIndexer<ConsensusMap>
00067 {
00068
00069 public:
00070
00072 struct OPENMS_DLLAPI FileDescription :
00073 public MetaInfoInterface
00074 {
00076 FileDescription();
00077
00079 String filename;
00081 String label;
00084 Size size;
00086 UInt64 unique_id;
00087 };
00088
00090
00091 typedef std::vector<ConsensusFeature> Base;
00092 typedef RangeManager<2> RangeManagerType;
00093 typedef Map<UInt64, FileDescription> FileDescriptions;
00095 typedef std::vector<ConsensusFeature>::iterator Iterator;
00097 typedef std::vector<ConsensusFeature>::const_iterator ConstIterator;
00099 typedef std::vector<ConsensusFeature>::reverse_iterator ReverseIterator;
00101 typedef std::vector<ConsensusFeature>::const_reverse_iterator ConstReverseIterator;
00103
00105 OPENMS_DLLAPI ConsensusMap();
00106
00108 OPENMS_DLLAPI ConsensusMap(const ConsensusMap & source);
00109
00111 OPENMS_DLLAPI ~ConsensusMap();
00112
00114 OPENMS_DLLAPI explicit ConsensusMap(Base::size_type n);
00115
00117 OPENMS_DLLAPI ConsensusMap & operator=(const ConsensusMap & source);
00118
00128 OPENMS_DLLAPI ConsensusMap & operator+=(const ConsensusMap & rhs);
00129
00135 OPENMS_DLLAPI void clear(bool clear_meta_data = true);
00136
00138 OPENMS_DLLAPI const FileDescriptions & getFileDescriptions() const;
00139
00141 OPENMS_DLLAPI FileDescriptions & getFileDescriptions();
00142
00144 OPENMS_DLLAPI const String & getExperimentType() const;
00145
00147 OPENMS_DLLAPI void setExperimentType(const String & experiment_type);
00148
00156
00157 OPENMS_DLLAPI void sortByIntensity(bool reverse = false);
00158
00160 OPENMS_DLLAPI void sortByRT();
00161
00163 OPENMS_DLLAPI void sortByMZ();
00164
00166 OPENMS_DLLAPI void sortByPosition();
00167
00169 OPENMS_DLLAPI void sortByQuality(bool reverse = false);
00170
00172 OPENMS_DLLAPI void sortBySize();
00173
00175 OPENMS_DLLAPI void sortByMaps();
00176
00178
00198 template <typename FeatureT>
00199 static void convert(UInt64 const input_map_index,
00200 FeatureMap<FeatureT> const & input_map,
00201 ConsensusMap & output_map,
00202 Size n = -1)
00203 {
00204 if (n > input_map.size())
00205 {
00206 n = input_map.size();
00207 }
00208
00209 output_map.clear(true);
00210 output_map.reserve(n);
00211
00212
00213 output_map.setUniqueId(input_map.getUniqueId());
00214
00215 for (UInt64 element_index = 0; element_index < n; ++element_index)
00216 {
00217 output_map.push_back(ConsensusFeature(input_map_index, input_map[element_index]));
00218 }
00219 output_map.getFileDescriptions()[input_map_index].size = (Size) input_map.size();
00220 output_map.setProteinIdentifications(input_map.getProteinIdentifications());
00221 output_map.setUnassignedPeptideIdentifications(input_map.getUnassignedPeptideIdentifications());
00222 output_map.updateRanges();
00223 }
00224
00238 OPENMS_DLLAPI static void convert(UInt64 const input_map_index,
00239 MSExperiment<> & input_map,
00240 ConsensusMap & output_map,
00241 Size n = -1)
00242 {
00243 output_map.clear(true);
00244
00245
00246 output_map.setUniqueId();
00247
00248 input_map.updateRanges(1);
00249 if (n > input_map.getSize())
00250 {
00251 n = input_map.getSize();
00252 }
00253 output_map.reserve(n);
00254 std::vector<Peak2D> tmp;
00255 tmp.reserve(input_map.getSize());
00256
00257
00258 input_map.get2DData(tmp);
00259
00260 std::partial_sort(tmp.begin(),
00261 tmp.begin() + n,
00262 tmp.end(),
00263 reverseComparator(Peak2D::IntensityLess()));
00264
00265 for (Size element_index = 0; element_index < n; ++element_index)
00266 {
00267 output_map.push_back(ConsensusFeature(input_map_index,
00268 tmp[element_index],
00269 element_index));
00270 }
00271
00272 output_map.getFileDescriptions()[input_map_index].size = n;
00273 output_map.updateRanges();
00274 }
00275
00288 OPENMS_DLLAPI static void convert(UInt64 const input_map_index,
00289 std::vector<Peak2D> & input_map,
00290 ConsensusMap & output_map,
00291 Size n = -1)
00292 {
00293
00294 output_map.setUniqueId();
00295 output_map.clear(true);
00296
00297
00298 if (n > input_map.size())
00299 {
00300 n = input_map.size();
00301 }
00302 output_map.reserve(n);
00303
00304 std::partial_sort(input_map.begin(),
00305 input_map.begin() + n,
00306 input_map.end(),
00307 reverseComparator(Peak2D::IntensityLess()));
00308
00309 for (Size element_index = 0; element_index < n; ++element_index)
00310 {
00311 output_map.push_back(ConsensusFeature(input_map_index, input_map[element_index], element_index));
00312 }
00313
00314 output_map.getFileDescriptions()[input_map_index].size = n;
00315 output_map.updateRanges();
00316 }
00317
00328 template <typename FeatureT>
00329 static void convert(ConsensusMap const & input_map,
00330 const bool keep_uids,
00331 FeatureMap<FeatureT> & output_map)
00332 {
00333 output_map.clear(true);
00334 output_map.resize(input_map.size());
00335 output_map.DocumentIdentifier::operator=(input_map);
00336
00337 if (keep_uids) output_map.UniqueIdInterface::operator=(input_map);
00338 else output_map.setUniqueId();
00339
00340 output_map.setProteinIdentifications(input_map.getProteinIdentifications());
00341 output_map.setUnassignedPeptideIdentifications(input_map.getUnassignedPeptideIdentifications());
00342
00343 for (Size i = 0; i < input_map.size(); ++i)
00344 {
00345 Feature & f = output_map[i];
00346 const ConsensusFeature & c = input_map[i];
00347 f.BaseFeature::operator=(c);
00348 if (!keep_uids) f.setUniqueId();
00349 }
00350 }
00351
00352
00353 OPENMS_DLLAPI void updateRanges();
00354
00356 OPENMS_DLLAPI void swap(ConsensusMap & from);
00357
00359 OPENMS_DLLAPI const std::vector<ProteinIdentification> & getProteinIdentifications() const;
00360
00362 OPENMS_DLLAPI std::vector<ProteinIdentification> & getProteinIdentifications();
00363
00365 OPENMS_DLLAPI void setProteinIdentifications(const std::vector<ProteinIdentification> & protein_identifications);
00366
00368 OPENMS_DLLAPI const std::vector<PeptideIdentification> & getUnassignedPeptideIdentifications() const;
00369
00371 OPENMS_DLLAPI std::vector<PeptideIdentification> & getUnassignedPeptideIdentifications();
00372
00374 OPENMS_DLLAPI void setUnassignedPeptideIdentifications(const std::vector<PeptideIdentification> & unassigned_peptide_identifications);
00375
00377 OPENMS_DLLAPI const std::vector<DataProcessing> & getDataProcessing() const;
00378
00380 OPENMS_DLLAPI std::vector<DataProcessing> & getDataProcessing();
00381
00383 OPENMS_DLLAPI void setDataProcessing(const std::vector<DataProcessing> & processing_method);
00384
00386 OPENMS_DLLAPI bool operator==(const ConsensusMap & rhs) const;
00387
00389 OPENMS_DLLAPI bool operator!=(const ConsensusMap & rhs) const;
00390
00404 template <typename Type>
00405 Size applyMemberFunction(Size (Type::* member_function)())
00406 {
00407 Size assignments = 0;
00408 assignments += ((*this).*member_function)();
00409 for (Iterator iter = this->begin(); iter != this->end(); ++iter)
00410 {
00411 assignments += ((*iter).*member_function)();
00412 }
00413 return assignments;
00414 }
00415
00417 template <typename Type>
00418 Size applyMemberFunction(Size (Type::* member_function)() const) const
00419 {
00420 Size assignments = 0;
00421 assignments += ((*this).*member_function)();
00422 for (ConstIterator iter = this->begin(); iter != this->end(); ++iter)
00423 {
00424 assignments += ((*iter).*member_function)();
00425 }
00426 return assignments;
00427 }
00428
00429 protected:
00430
00432 FileDescriptions file_description_;
00433
00435 String experiment_type_;
00436
00438 std::vector<ProteinIdentification> protein_identifications_;
00439
00441 std::vector<PeptideIdentification> unassigned_peptide_identifications_;
00442
00444 std::vector<DataProcessing> data_processing_;
00445 };
00446
00448 OPENMS_DLLAPI std::ostream & operator<<(std::ostream & os, const ConsensusMap & cons_map);
00449
00450 }
00451
00452 #endif // OPENMS_KERNEL_CONSENSUSMAP_H