OpenMS  2.8.0
LayerDataBase.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: Marc Sturm $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
37 // OpenMS_GUI config
38 #include <OpenMS/VISUAL/OpenMS_GUIConfig.h>
39 
41 
44 
52 //#include <OpenMS/VISUAL/Painter1DBase.h>
55 
56 #include <boost/shared_ptr.hpp>
57 
58 #include <bitset>
59 #include <vector>
60 
61 class QWidget;
62 
63 namespace OpenMS
64 {
65  class LayerStatistics;
66  class OnDiscMSExperiment;
67  class OSWData;
68  class Painter1DBase;
69 
98  class OPENMS_GUI_DLLAPI LayerDataBase
99  {
100  public:
105  enum DataType
106  {
112  DT_UNKNOWN
113  };
114 
116  enum Flags
117  {
126  SIZE_OF_FLAGS
127  };
128 
130  std::bitset<SIZE_OF_FLAGS> flags;
131 
134  {
140  SIZE_OF_LABEL_TYPE
141  };
142 
144  static const std::string NamesOfLabelType[SIZE_OF_LABEL_TYPE];
145 
148 
150  typedef boost::shared_ptr<FeatureMap> FeatureMapSharedPtrType;
151 
154 
156  typedef boost::shared_ptr<ConsensusMap> ConsensusMapSharedPtrType;
157 
160 
162  typedef boost::shared_ptr<ExperimentType> ExperimentSharedPtrType;
163 
164  typedef boost::shared_ptr<const ExperimentType> ConstExperimentSharedPtrType;
165 
167  typedef boost::shared_ptr<OnDiscMSExperiment> ODExperimentSharedPtrType;
168 
170  typedef boost::shared_ptr<OSWData> OSWDataSharedPtrType;
171 
173 
175  LayerDataBase() = delete;
177  LayerDataBase(const DataType type) : type(type) {};
179  LayerDataBase(const LayerDataBase& ld) = delete;
181  LayerDataBase& operator=(const LayerDataBase& ld) = delete;
183  LayerDataBase(LayerDataBase&& ld) = default;
187  virtual ~LayerDataBase() = default;
188 
189  virtual std::unique_ptr<Painter1DBase> getPainter1D() const = 0;
190 
191 
194  {
195  return features_;
196  }
197 
200  {
201  return features_;
202  }
203 
206  {
207  return consensus_map_;
208  }
209 
212  {
213  return consensus_map_;
214  }
215 
226 
237  {
238  return peak_map_;
239  }
240 
245  {
246  peak_map_ = p;
247  updateCache_();
248  }
249 
252  {
253  on_disc_peaks = p;
254  }
255 
258  {
259  return on_disc_peaks;
260  }
261 
264  {
265  return chromatogram_map_;
266  }
267 
270  {
271  return chromatogram_map_;
272  }
273 
277 
281 
284 
288  bool annotate(const std::vector<PeptideIdentification>& identifications,
289  const std::vector<ProteinIdentification>& protein_identifications);
290 
291 
294  {
295  return annotations_1d[current_spectrum_idx_];
296  }
297 
300  {
301  return annotations_1d[current_spectrum_idx_];
302  }
303 
305  const Annotations1DContainer& getAnnotations(Size spectrum_index) const
306  {
307  return annotations_1d[spectrum_index];
308  }
309 
312  {
313  return annotations_1d[spectrum_index];
314  }
315 
322 
324  {
325  cached_spectrum_.sortByPosition();
326  }
327 
329  const ExperimentType::SpectrumType getSpectrum(Size spectrum_idx) const;
330 
333  {
334  return current_spectrum_idx_;
335  }
336 
339  {
340  current_spectrum_idx_ = index;
341  updateCache_();
342  }
343 
344 
349  {
350  ExperimentSharedPtrType exp_sptr(getChromatogramData().get() == nullptr ||
351  getChromatogramData().get()->getNrChromatograms() == 0 ?
352  getPeakDataMuteable() :
353  getChromatogramData());
354  return exp_sptr;
355  }
356 
358  bool isIonMobilityData() const
359  {
360  return this->getPeakData()->size() > 0 &&
361  this->getPeakData()->metaValueExists("is_ion_mobility") &&
362  this->getPeakData()->getMetaValue("is_ion_mobility").toBool();
363  }
364 
366  {
367  peak_map_->setMetaValue("is_ion_mobility", "true");
368  }
369 
371  bool isDIAData() const
372  {
373  return this->getPeakData()->size() > 0 &&
374  this->getPeakData()->metaValueExists("is_dia_data") &&
375  this->getPeakData()->getMetaValue("is_dia_data").toBool();
376  }
377 
380  {
381  peak_map_->setMetaValue("is_dia_data", "true");
382  }
383 
393  {
394  return this->getPeakData()->size() > 0 &&
395  this->getPeakData()->metaValueExists("is_chromatogram") &&
396  this->getPeakData()->getMetaValue("is_chromatogram").toBool();
397  }
398 
401  {
402  peak_map_->setMetaValue("is_chromatogram", "true");
403  }
404 
407  {
408  if (this->chromatogram_flag_set())
409  {
410  peak_map_->removeMetaValue("is_chromatogram");
411  }
412  }
413 
417  virtual void updateRanges() = 0;
418 
420  float getMinIntensity() const;
421 
423  float getMaxIntensity() const;
424 
426 
429  virtual RangeAllType getRange() const = 0;
430 
432  virtual std::unique_ptr<LayerStatistics> getStats() const = 0;
433 
437 
439  void removePeakAnnotationsFromPeptideHit(const std::vector<Annotation1DItem*>& selected_annotations);
440 
442  bool visible = true;
443 
445  bool flipped = false;
446 
448  DataType type = DT_UNKNOWN;
449 
450  private:
453 
454  public:
455  const String& getName() const
456  {
457  return name_;
458  }
459  void setName(const String& new_name)
460  {
461  name_ = new_name;
462  }
463 
466 
469 
472 
475 
477  std::vector<Annotations1DContainer> annotations_1d = std::vector<Annotations1DContainer>(1);
478 
480  std::vector<QColor> peak_colors_1d;
481 
483  bool modifiable = false;
484 
486  bool modified = false;
487 
489  LabelType label = L_NONE;
490 
492  int peptide_id_index = -1;
493  int peptide_hit_index = -1;
494 
497 
498  protected:
500  void updateCache_();
501 
504 
507 
510 
513 
516 
519 
522 
524  Size current_spectrum_idx_ = 0;
525 
528  };
529 
533  {
534  public:
542  LayerAnnotatorBase(const FileTypes::FileTypeList& supported_types, const String& file_dialog_text, QWidget* gui_lock);
543 
548  bool annotateWithFileDialog(LayerDataBase& layer, LogWindow& log, const String& current_path) const;
549 
553  bool annotateWithFilename(LayerDataBase& layer, LogWindow& log, const String& filename) const;
554 
558  static std::unique_ptr<LayerAnnotatorBase> getAnnotatorWhichSupports(const FileTypes::Type& type);
559 
561  static std::unique_ptr<LayerAnnotatorBase> getAnnotatorWhichSupports(const String& filename);
562 
563  protected:
566  virtual bool annotateWorker_(LayerDataBase& layer, const String& filename, LogWindow& log) const = 0;
567 
570  QWidget* gui_lock_ = nullptr;
571  };
572 
576  {
577  public:
580  "Select peptide identification data", gui_lock)
581  {
582  }
583 
584  protected:
587  virtual bool annotateWorker_(LayerDataBase& layer, const String& filename, LogWindow& log) const;
588  };
589 
593  {
594  public:
597  "Select AccurateMassSearch's featureXML file", gui_lock)
598  {
599  }
600 
601  protected:
604  virtual bool annotateWorker_(LayerDataBase& layer, const String& filename, LogWindow& log) const;
605  };
606 
610  {
611  public:
613  LayerAnnotatorBase(std::vector<FileTypes::Type>{FileTypes::OSW},
614  "Select OpenSwath/pyProphet output file", gui_lock)
615  {
616  }
617 
618  protected:
621  virtual bool annotateWorker_(LayerDataBase& layer, const String& filename, LogWindow& log) const;
622  };
623 
625  OPENMS_GUI_DLLAPI std::ostream& operator<<(std::ostream& os, const LayerDataBase& rhs);
626 
627 }// namespace OpenMS
628 
Container for annotations to content of Plot1DCanvas.
Definition: Annotations1DContainer.h:55
A container for consensus elements.
Definition: ConsensusMap.h:90
DataFilter array providing some convenience functions.
Definition: DataFilters.h:51
A container for features.
Definition: FeatureMap.h:106
holds a vector of known file types, e.g. as a way to specify supported input formats
Definition: FileTypes.h:135
Definition: LayerDataBase.h:593
virtual bool annotateWorker_(LayerDataBase &layer, const String &filename, LogWindow &log) const
LayerAnnotatorAMS(QWidget *gui_lock)
Definition: LayerDataBase.h:595
Definition: LayerDataBase.h:533
QWidget * gui_lock_
optional widget which will be locked when calling annotateWorker_() in child-classes
Definition: LayerDataBase.h:570
const FileTypes::FileTypeList supported_types_
Definition: LayerDataBase.h:568
static std::unique_ptr< LayerAnnotatorBase > getAnnotatorWhichSupports(const FileTypes::Type &type)
bool annotateWithFilename(LayerDataBase &layer, LogWindow &log, const String &filename) const
bool annotateWithFileDialog(LayerDataBase &layer, LogWindow &log, const String &current_path) const
LayerAnnotatorBase(const FileTypes::FileTypeList &supported_types, const String &file_dialog_text, QWidget *gui_lock)
C'tor with params.
static std::unique_ptr< LayerAnnotatorBase > getAnnotatorWhichSupports(const String &filename)
see getAnnotatorWhichSupports(const FileTypes::Type& type). Filetype is queried from filename
const String file_dialog_text_
Definition: LayerDataBase.h:569
virtual bool annotateWorker_(LayerDataBase &layer, const String &filename, LogWindow &log) const =0
Definition: LayerDataBase.h:610
LayerAnnotatorOSW(QWidget *gui_lock)
Definition: LayerDataBase.h:612
virtual bool annotateWorker_(LayerDataBase &layer, const String &filename, LogWindow &log) const
Definition: LayerDataBase.h:576
virtual bool annotateWorker_(LayerDataBase &layer, const String &filename, LogWindow &log) const
LayerAnnotatorPeptideID(QWidget *gui_lock)
Definition: LayerDataBase.h:578
Class that stores the data for one layer.
Definition: LayerDataBase.h:99
void remove_chromatogram_flag()
remove the chromatogram flag
Definition: LayerDataBase.h:406
boost::shared_ptr< ExperimentType > ExperimentSharedPtrType
SharedPtr on MSExperiment.
Definition: LayerDataBase.h:162
const OSWDataSharedPtrType & getChromatogramAnnotation() const
const Annotations1DContainer & getAnnotations(Size spectrum_index) const
Returns a const reference to the annotations of the current spectrum (1D view)
Definition: LayerDataBase.h:305
const ExperimentSharedPtrType & getChromatogramData() const
Returns a mutable reference to the current chromatogram data.
Definition: LayerDataBase.h:263
PeakMap ExperimentType
Main data type (experiment)
Definition: LayerDataBase.h:159
boost::shared_ptr< OnDiscMSExperiment > ODExperimentSharedPtrType
SharedPtr on On-Disc MSExperiment.
Definition: LayerDataBase.h:167
const ExperimentType::SpectrumType getSpectrum(Size spectrum_idx) const
Returns a const-copy of the required spectrum which is guaranteed to be populated with raw data.
Size getCurrentSpectrumIndex() const
Get the index of the current spectrum (1D view)
Definition: LayerDataBase.h:332
bool annotate(const std::vector< PeptideIdentification > &identifications, const std::vector< ProteinIdentification > &protein_identifications)
virtual std::unique_ptr< LayerStatistics > getStats() const =0
compute layer statistics (via visitor)
LabelType
Label used in visualization.
Definition: LayerDataBase.h:134
@ L_ID_ALL
All peptide hits of the first identification run are used.
Definition: LayerDataBase.h:139
@ L_ID
The best peptide hit of the first identification run is used.
Definition: LayerDataBase.h:138
@ L_NONE
No label is displayed.
Definition: LayerDataBase.h:135
@ L_META_LABEL
The 'label' meta information is used.
Definition: LayerDataBase.h:137
@ L_INDEX
The element number is used.
Definition: LayerDataBase.h:136
LayerDataBase & operator=(const LayerDataBase &ld)=delete
no assignment operator (should not be needed)
float getMaxIntensity() const
Returns the maximum intensity of the internal data, depending on type.
float getMinIntensity() const
Returns the minimum intensity of the internal data, depending on type.
LayerDataBase(const LayerDataBase &ld)=delete
no Copy-ctor (should not be needed)
void setCurrentSpectrumIndex(Size index)
Set the index of the current spectrum (1D view)
Definition: LayerDataBase.h:338
virtual std::unique_ptr< Painter1DBase > getPainter1D() const =0
virtual ~LayerDataBase()=default
D'tor.
boost::shared_ptr< FeatureMap > FeatureMapSharedPtrType
SharedPtr on feature map.
Definition: LayerDataBase.h:150
bool isDIAData() const
Check whether the current layer contains DIA (SWATH-MS) data.
Definition: LayerDataBase.h:371
void set_chromatogram_flag()
set the chromatogram flag
Definition: LayerDataBase.h:400
String name_
layer name
Definition: LayerDataBase.h:452
void setOnDiscPeakData(ODExperimentSharedPtrType p)
Set the current on-disc data.
Definition: LayerDataBase.h:251
void removePeakAnnotationsFromPeptideHit(const std::vector< Annotation1DItem * > &selected_annotations)
remove peak annotations in the given list from the currently active PeptideHit
const ConstExperimentSharedPtrType getPeakData() const
Returns a const reference to the current in-memory peak data.
bool isIonMobilityData() const
Check whether the current layer should be represented as ion mobility.
Definition: LayerDataBase.h:358
void setChromatogramAnnotation(OSWData &&data)
add annotation from an OSW sqlite file.
ConsensusMap ConsensusMapType
consensus features
Definition: LayerDataBase.h:153
virtual void updateRanges()=0
Update ranges of the underlying data.
const FeatureMapSharedPtrType & getFeatureMap() const
Returns a const reference to the current feature data.
Definition: LayerDataBase.h:193
OSWDataSharedPtrType & getChromatogramAnnotation()
DataFilters filters
Filters to apply before painting.
Definition: LayerDataBase.h:474
const ExperimentSharedPtrType & getPeakDataMuteable()
Returns a mutable reference to the current in-memory peak data.
Definition: LayerDataBase.h:236
bool chromatogram_flag_set() const
Check whether the current layer is a chromatogram.
Definition: LayerDataBase.h:392
void setPeakData(ExperimentSharedPtrType p)
Set the current in-memory peak data.
Definition: LayerDataBase.h:244
const ODExperimentSharedPtrType & getOnDiscPeakData() const
Returns a mutable reference to the on-disc data.
Definition: LayerDataBase.h:257
void labelAsIonMobilityData() const
Definition: LayerDataBase.h:365
const ConsensusMapSharedPtrType & getConsensusMap() const
Returns a const reference to the consensus feature data.
Definition: LayerDataBase.h:205
void sortCurrentSpectrumByPosition()
Definition: LayerDataBase.h:323
FeatureMapSharedPtrType & getFeatureMap()
Returns a const reference to the current feature data.
Definition: LayerDataBase.h:199
void synchronizePeakAnnotations()
std::bitset< SIZE_OF_FLAGS > flags
Actual state of each flag.
Definition: LayerDataBase.h:130
LayerDataBase()=delete
Default constructor.
boost::shared_ptr< const ExperimentType > ConstExperimentSharedPtrType
Definition: LayerDataBase.h:164
boost::shared_ptr< ConsensusMap > ConsensusMapSharedPtrType
SharedPtr on consensus features.
Definition: LayerDataBase.h:156
ExperimentSharedPtrType & getChromatogramData()
Returns a mutable reference to the current chromatogram data.
Definition: LayerDataBase.h:269
void updatePeptideHitAnnotations_(PeptideHit &hit)
updates the PeakAnnotations in the current PeptideHit with manually changed annotations
LayerDataBase(LayerDataBase &&ld)=default
move C'tor
Flags
Flags that determine which information is shown.
Definition: LayerDataBase.h:117
@ I_PEPTIDEMZ
Identifications: m/z source.
Definition: LayerDataBase.h:124
@ F_HULL
Features: Overall convex hull.
Definition: LayerDataBase.h:118
@ F_UNASSIGNED
Features: Unassigned peptide hits.
Definition: LayerDataBase.h:120
@ P_PRECURSORS
Peaks: Mark precursor peaks of MS/MS scans.
Definition: LayerDataBase.h:121
@ I_LABELS
Identifications: Show labels (not sequences)
Definition: LayerDataBase.h:125
@ P_PROJECTIONS
Peaks: Show projections.
Definition: LayerDataBase.h:122
@ C_ELEMENTS
Consensus features: Show elements.
Definition: LayerDataBase.h:123
@ F_HULLS
Features: Convex hulls of single mass traces.
Definition: LayerDataBase.h:119
LayerDataBase(const DataType type)
C'tor for child classes.
Definition: LayerDataBase.h:177
const String & getName() const
Definition: LayerDataBase.h:455
void updateCache_()
Update current cached spectrum for easy retrieval.
LayerDataBase & operator=(LayerDataBase &&ld)=default
move assignment
Annotations1DContainer & getCurrentAnnotations()
Returns a mutable reference to the annotations of the current spectrum (1D view)
Definition: LayerDataBase.h:299
ConsensusMapSharedPtrType & getConsensusMap()
Returns current consensus map (mutable)
Definition: LayerDataBase.h:211
virtual RangeAllType getRange() const =0
OSWDataSharedPtrType chrom_annotation_
Chromatogram annotation data.
Definition: LayerDataBase.h:521
const Annotations1DContainer & getCurrentAnnotations() const
Returns a const reference to the annotations of the current spectrum (1D view)
Definition: LayerDataBase.h:293
MultiGradient gradient
Gradient for 2D and 3D views.
Definition: LayerDataBase.h:471
Param param
Layer parameters.
Definition: LayerDataBase.h:468
DataType
Definition: LayerDataBase.h:106
@ DT_FEATURE
Feature data.
Definition: LayerDataBase.h:109
@ DT_PEAK
Spectrum profile or centroided data.
Definition: LayerDataBase.h:107
@ DT_CONSENSUS
Consensus feature data.
Definition: LayerDataBase.h:110
@ DT_CHROMATOGRAM
Chromatogram data.
Definition: LayerDataBase.h:108
@ DT_IDENT
Peptide identification data.
Definition: LayerDataBase.h:111
ExperimentSharedPtrType getFullChromData()
Definition: LayerDataBase.h:348
FeatureMap FeatureMapType
Features.
Definition: LayerDataBase.h:147
String filename
file name of the file the data comes from (if available)
Definition: LayerDataBase.h:465
boost::shared_ptr< OSWData > OSWDataSharedPtrType
SharedPtr on OSWData.
Definition: LayerDataBase.h:170
ExperimentType::SpectrumType cached_spectrum_
Current cached spectrum.
Definition: LayerDataBase.h:527
const ExperimentType::SpectrumType & getCurrentSpectrum() const
Returns a const reference to the current spectrum (1D view)
void setName(const String &new_name)
Definition: LayerDataBase.h:459
String getDecoratedName() const
get name augmented with attributes, e.g. [flipped], or '*' if modified
void labelAsDIAData()
Label the current layer as DIA (SWATH-MS) data.
Definition: LayerDataBase.h:379
Annotations1DContainer & getAnnotations(Size spectrum_index)
Returns a mutable reference to the annotations of the current spectrum (1D view)
Definition: LayerDataBase.h:311
std::vector< QColor > peak_colors_1d
Peak colors of the currently shown spectrum.
Definition: LayerDataBase.h:480
A log window (QTextEdit) with convenience functions.
Definition: LogWindow.h:55
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:73
The representation of a 1D spectrum.
Definition: MSSpectrum.h:70
A gradient of multiple colors and arbitrary distances between colors.
Definition: MultiGradient.h:68
Holds all or partial information from an OSW file.
Definition: OSWData.h:305
Representation of a mass spectrometry experiment on disk.
Definition: OnDiscMSExperiment.h:67
Management and storage of parameters / INI files.
Definition: Param.h:70
Representation of a peptide hit.
Definition: PeptideHit.h:57
Handles the management of a multidimensional range, e.g. RangeMZ and RangeIntensity for spectra.
Definition: RangeManager.h:455
A more convenient string class.
Definition: String.h:60
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
const FileTypes::FileTypeList supported_types({ FileTypes::MZML, FileTypes::MZXML, FileTypes::MZDATA, FileTypes::SQMASS, FileTypes::FEATUREXML, FileTypes::CONSENSUSXML, FileTypes::IDXML, FileTypes::DTA, FileTypes::DTA2D, FileTypes::MGF, FileTypes::MS2, FileTypes::MSP, FileTypes::BZ2, FileTypes::GZ })
supported types which can be opened with File–>Open
std::ostream & operator<<(std::ostream &os, const AccurateMassSearchResult &amsr)
Centralizes the file types recognized by FileHandler.
Definition: FileTypes.h:53
Type
Actual file types enum.
Definition: FileTypes.h:57
@ MZIDENTML
mzIdentML (HUPO PSI AnalysisXML followup format) (.mzid)
Definition: FileTypes.h:75
@ FEATUREXML
OpenMS feature file (.featureXML)
Definition: FileTypes.h:63
@ IDXML
OpenMS identification format (.idXML)
Definition: FileTypes.h:64
@ OSW
OpenSWATH OpenSWATH report (OSW) SQLite DB.
Definition: FileTypes.h:104