OpenMS  2.7.0
TransitionTSVFile.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: Hannes Roest $
32 // $Authors: Hannes Roest $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
39 
44 
45 #include <fstream>
46 
47 namespace OpenMS
48 {
49 
144  class OPENMS_DLLAPI TransitionTSVFile :
145  public ProgressLogger,
146  public DefaultParamHandler
147  {
148 
149 protected:
157  {
158  double precursor = -1;
159  double product = -1;
160  double rt_calibrated = -1;
161  String transition_name = "";
162  double CE = -1;
163  double library_intensity = -1;
164  String group_id = "";
165  bool decoy = false;
167  std::vector<String> ProteinName;
178  String fragment_charge = "NA";
179  int fragment_nr = -1;
180  double fragment_mzdelta = -1;
181  double drift_time = -1;
182  int fragment_modification = 0;
184  std::vector<String> uniprot_id;
185  bool detecting_transition = true;
186  bool identifying_transition = false;
187  bool quantifying_transition = true;
188  std::vector<String> peptidoforms;
189 
192  bool isPeptide() const
193  {
194  return CompoundName.empty() || CompoundName == "NA";
195  }
196  };
197 
205 
213  void TSVToTargetedExperiment_(std::vector<TSVTransition>& transition_list, OpenMS::TargetedExperiment& exp);
214 
222  void TSVToTargetedExperiment_(std::vector<TSVTransition>& transition_list, OpenSwath::LightTargetedExperiment& exp);
223 
227 
229  void updateMembers_() override;
230 
231 private:
232 
233  // Members
237 
238  // Typedefs
239  typedef std::vector<OpenMS::TargetedExperiment::Protein> ProteinVectorType;
240  typedef std::vector<OpenMS::TargetedExperiment::Peptide> PeptideVectorType;
241  typedef std::vector<OpenMS::ReactionMonitoringTransition> TransitionVectorType;
242 
243  static const char* strarray_[];
244 
245  static const std::vector<std::string> header_names_;
246 
251 
259  void getTSVHeader_(const std::string& line, char& delimiter, std::map<std::string, int>& header_dict) const;
260 
268  void readUnstructuredTSVInput_(const char* filename, FileTypes::Type filetype, std::vector<TSVTransition>& transition_list);
269 
271  void spectrastRTExtract(const String str_inp, double & value, bool & spectrast_legacy);
272 
274  bool spectrastAnnotationExtract(const String str_inp, TSVTransition & mytransition);
275 
278  void cleanupTransitions_(TSVTransition& mytransition);
280 
285 
298  void resolveMixedSequenceGroups_(std::vector<TSVTransition>& transition_list) const;
299 
301  void createTransition_(std::vector<TSVTransition>::iterator& tr_it,
303 
305  void createProtein_(String protein_name, String uniprot_id,
307 
309  void interpretRetentionTime_(std::vector<TargetedExperiment::RetentionTime>& retention_times,
310  const OpenMS::DataValue rt_value);
311 
313  void createPeptide_(std::vector<TSVTransition>::const_iterator tr_it,
315 
317  void createCompound_(std::vector<TSVTransition>::const_iterator tr_it,
319 
321  void addModification_(std::vector<TargetedExperiment::Peptide::Modification>& mods,
322  int location,
323  const ResidueModification& rmod);
325 
331  void writeTSVOutput_(const char* filename, OpenMS::TargetedExperiment& targeted_exp);
332 
333 public:
334 
338 
340  ~TransitionTSVFile() override;
342 
349  void convertTargetedExperimentToTSV(const char* filename, OpenMS::TargetedExperiment& targeted_exp);
350 
358  void convertTSVToTargetedExperiment(const char* filename, FileTypes::Type filetype, OpenMS::TargetedExperiment& targeted_exp);
359 
367  void convertTSVToTargetedExperiment(const char* filename, FileTypes::Type filetype, OpenSwath::LightTargetedExperiment& targeted_exp);
368 
371 
372  };
373 }
374 
Class to hold strings, numeric values, lists of strings and lists of numeric values.
Definition: DataValue.h:59
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
This class stores a SRM/MRM transition.
Definition: ReactionMonitoringTransition.h:58
Representation of a modification.
Definition: ResidueModification.h:77
A more convenient string class.
Definition: String.h:61
Represents a compound (small molecule)
Definition: TargetedExperimentHelper.h:323
Represents a peptide (amino acid sequence)
Definition: TargetedExperimentHelper.h:360
A description of a targeted experiment containing precursor and production ions.
Definition: TargetedExperiment.h:65
This class supports reading and writing of OpenSWATH transition lists.
Definition: TransitionTSVFile.h:147
void addModification_(std::vector< TargetedExperiment::Peptide::Modification > &mods, int location, const ResidueModification &rmod)
Add a modification at the specified location.
static const std::vector< std::string > header_names_
Definition: TransitionTSVFile.h:245
void createProtein_(String protein_name, String uniprot_id, OpenMS::TargetedExperiment::Protein &protein)
Populate a new TargetedExperiment::Protein object from a row in the csv.
~TransitionTSVFile() override
Destructor.
bool override_group_label_check_
Definition: TransitionTSVFile.h:235
void createCompound_(std::vector< TSVTransition >::const_iterator tr_it, OpenMS::TargetedExperiment::Compound &compound)
Populate a new TargetedExperiment::Compound object (a metabolite) from a row in the csv.
bool spectrastAnnotationExtract(const String str_inp, TSVTransition &mytransition)
Extract annotation from a SpectraST comment string.
void cleanupTransitions_(TSVTransition &mytransition)
Cleanup of the read fields (removing quotes etc.)
bool force_invalid_mods_
Definition: TransitionTSVFile.h:236
void convertTargetedExperimentToTSV(const char *filename, OpenMS::TargetedExperiment &targeted_exp)
Write out a targeted experiment (TraML structure) into a tsv file.
TransitionTSVFile::TSVTransition convertTransition_(const ReactionMonitoringTransition *it, OpenMS::TargetedExperiment &targeted_exp)
Convert an OpenMS transition to a TSVTransition for output writing.
std::vector< OpenMS::ReactionMonitoringTransition > TransitionVectorType
Definition: TransitionTSVFile.h:241
void readUnstructuredTSVInput_(const char *filename, FileTypes::Type filetype, std::vector< TSVTransition > &transition_list)
Read tab or comma separated input with columns defined by their column headers only.
void writeTSVOutput_(const char *filename, OpenMS::TargetedExperiment &targeted_exp)
Write a TargetedExperiment to a file.
std::vector< OpenMS::TargetedExperiment::Peptide > PeptideVectorType
Definition: TransitionTSVFile.h:240
void spectrastRTExtract(const String str_inp, double &value, bool &spectrast_legacy)
Extract retention time from a SpectraST comment string.
void TSVToTargetedExperiment_(std::vector< TSVTransition > &transition_list, OpenMS::TargetedExperiment &exp)
Convert a list of TSVTransition to a TargetedExperiment.
void createPeptide_(std::vector< TSVTransition >::const_iterator tr_it, OpenMS::TargetedExperiment::Peptide &peptide)
Populate a new TargetedExperiment::Peptide object from a row in the csv.
void getTSVHeader_(const std::string &line, char &delimiter, std::map< std::string, int > &header_dict) const
Determine separator in a CSV file and check for correct headers.
void convertTSVToTargetedExperiment(const char *filename, FileTypes::Type filetype, OpenSwath::LightTargetedExperiment &targeted_exp)
Read in a tsv file and construct a targeted experiment (Light transition structure)
std::vector< OpenMS::TargetedExperiment::Protein > ProteinVectorType
Definition: TransitionTSVFile.h:239
String retentionTimeInterpretation_
Definition: TransitionTSVFile.h:234
void updateMembers_() override
Synchronize members with param class.
void TSVToTargetedExperiment_(std::vector< TSVTransition > &transition_list, OpenSwath::LightTargetedExperiment &exp)
Convert a list of TSVTransition to a LightTargetedExperiment.
void resolveMixedSequenceGroups_(std::vector< TSVTransition > &transition_list) const
Resolve cases where the same peptide label group has different sequences.
void convertTSVToTargetedExperiment(const char *filename, FileTypes::Type filetype, OpenMS::TargetedExperiment &targeted_exp)
Read in a tsv/mrm file and construct a targeted experiment (TraML structure)
void interpretRetentionTime_(std::vector< TargetedExperiment::RetentionTime > &retention_times, const OpenMS::DataValue rt_value)
Helper function to assign retention times to compounds and peptides.
void validateTargetedExperiment(const OpenMS::TargetedExperiment &targeted_exp)
Validate a TargetedExperiment (check that all ids are unique)
void createTransition_(std::vector< TSVTransition >::iterator &tr_it, OpenMS::ReactionMonitoringTransition &rm_trans)
Populate a new ReactionMonitoringTransition object from a row in the csv.
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Type
Actual file types enum.
Definition: FileTypes.h:57
Definition: TargetedExperimentHelper.h:100
Internal structure to represent a transition.
Definition: TransitionTSVFile.h:157
String FullPeptideName
Full peptide sequence with UniMod modifications.
Definition: TransitionTSVFile.h:170
String label_type
Type of label that was used (e.g. "heavy" or "light")
Definition: TransitionTSVFile.h:177
String PeptideSequence
Peptide sequence (only AA sequence)
Definition: TransitionTSVFile.h:166
std::vector< String > peptidoforms
List of peptidoforms.
Definition: TransitionTSVFile.h:188
std::vector< String > uniprot_id
List of UniProt identifiers of associated proteins.
Definition: TransitionTSVFile.h:184
bool isPeptide() const
Definition: TransitionTSVFile.h:192
String precursor_charge
Precursor charge state.
Definition: TransitionTSVFile.h:175
String CompoundName
Compound name (for metabolomics)
Definition: TransitionTSVFile.h:171
String SMILES
SMILES identifier (for metabolomics)
Definition: TransitionTSVFile.h:172
String peptide_group_label
Peptide group identifier (grouping isotopically labelled peptides)
Definition: TransitionTSVFile.h:176
String SumFormula
Molecular formula (for metabolomics)
Definition: TransitionTSVFile.h:173
String Adducts
Adducts (for metabolomics)
Definition: TransitionTSVFile.h:174
String fragment_type
Fragment type (e.g. "y" for a y7 ion)
Definition: TransitionTSVFile.h:183
String GeneName
Gene identifier.
Definition: TransitionTSVFile.h:168
std::vector< String > ProteinName
List of protein identifiers.
Definition: TransitionTSVFile.h:167
String Annotation
Fragment ion annotation.
Definition: TransitionTSVFile.h:169
Definition: TransitionExperiment.h:207