Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
OpenSwathTSVWriter.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-2017.
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 #ifndef OPENMS_ANALYSIS_OPENSWATH_OPENSWATHTSVWRITER_H
36 #define OPENMS_ANALYSIS_OPENSWATH_OPENSWATHTSVWRITER_H
37 
38 // Interfaces
40 
42 
43 #include <fstream>
44 
45 namespace OpenMS
46 {
47 
57  class OPENMS_DLLAPI OpenSwathTSVWriter
58  {
59  std::ofstream ofs;
61  bool doWrite_;
63  bool sonar_;
65 
66  public:
67 
68  OpenSwathTSVWriter(String output_filename,
69  String input_filename = "inputfile",
70  bool ms1_scores = false,
71  bool sonar = false,
72  bool uis_scores = false) :
73  ofs(output_filename.c_str()),
74  input_filename_(input_filename),
75  doWrite_(!output_filename.empty()),
76  use_ms1_traces_(ms1_scores),
77  sonar_(sonar),
78  enable_uis_scoring_(uis_scores)
79  {}
80 
81  bool isActive()
82  {
83  return doWrite_;
84  }
85 
90  void writeHeader()
91  {
92  ofs << "transition_group_id\tpeptide_group_label\trun_id\tfilename\tRT\tid\tSequence\tFullPeptideName" <<
93  "\tCharge\tm/z\tIntensity\tProteinName\tdecoy\tassay_rt\tdelta_rt\tleftWidth" <<
94  "\tmain_var_xx_swath_prelim_score\tnorm_RT\tnr_peaks\tpeak_apices_sum\tpotentialOutlier\tinitialPeakQuality" <<
95  "\trightWidth\trt_score\tsn_ratio\ttotal_xic\tvar_bseries_score\tvar_dotprod_score" <<
96  "\tvar_intensity_score\tvar_isotope_correlation_score\tvar_isotope_overlap_score" <<
97  "\tvar_library_corr\tvar_library_dotprod\tvar_library_manhattan\tvar_library_rmsd" <<
98  "\tvar_library_rootmeansquare\tvar_library_sangle\tvar_log_sn_score\tvar_manhatt_score" <<
99  "\tvar_massdev_score\tvar_massdev_score_weighted\tvar_norm_rt_score\tvar_xcorr_coelution" <<
100  "\tvar_xcorr_coelution_weighted\tvar_xcorr_shape\tvar_xcorr_shape_weighted" <<
101  "\tvar_yseries_score\tvar_elution_model_fit_score";
102  if (use_ms1_traces_)
103  {
104  ofs << "\tvar_ms1_ppm_diff\tvar_ms1_isotope_corr\tvar_ms1_isotope_overlap\tvar_ms1_xcorr_coelution\tvar_ms1_xcorr_shape";
105  }
106  ofs << "\txx_lda_prelim_score\txx_swath_prelim_score";
107  if (sonar_)
108  {
109  ofs << "\tvar_sonar_lag\tvar_sonar_shape\tvar_sonar_log_sn\tvar_sonar_log_diff\tvar_sonar_log_trend\tvar_sonar_rsq";
110  }
111  if (use_ms1_traces_)
112  {
113  ofs << "\taggr_prec_Peak_Area\taggr_prec_Peak_Apex\taggr_prec_Fragment_Annotation";
114  }
115  ofs << "\taggr_Peak_Area\taggr_Peak_Apex\taggr_Fragment_Annotation";
116  if (enable_uis_scoring_)
117  {
118  ofs << "\tuis_target_transition_names"
119  << "\tuis_target_var_ind_log_intensity"
120  << "\tuis_target_num_transitions"
121  << "\tuis_target_var_ind_xcorr_coelution"
122  << "\tuis_target_main_var_ind_xcorr_shape"
123  << "\tuis_target_var_ind_log_sn_score"
124  << "\tuis_target_var_ind_massdev_score"
125  << "\tuis_target_var_ind_isotope_correlation"
126  << "\tuis_target_var_ind_isotope_overlap"
127  << "\tuis_decoy_transition_names"
128  << "\tuis_decoy_var_ind_log_intensity"
129  << "\tuis_decoy_num_transitions"
130  << "\tuis_decoy_var_ind_xcorr_coelution"
131  << "\tuis_decoy_main_var_ind_xcorr_shape"
132  << "\tuis_decoy_var_ind_log_sn_score"
133  << "\tuis_decoy_var_ind_massdev_score"
134  << "\tuis_decoy_var_ind_isotope_correlation"
135  << "\tuis_decoy_var_ind_isotope_overlap";
136  }
137  ofs << "\n";
138  }
139 
155  const OpenSwath::LightTransition * transition,
156  const FeatureMap& output, const String id)
157  {
158  String result = "";
159  String decoy = "0"; // 0 = false
160  if (transition->decoy)
161  {
162  decoy = "1";
163  }
164 
165  for (FeatureMap::const_iterator feature_it = output.begin(); feature_it != output.end(); ++feature_it)
166  {
167 
168  char intensity_char[40];
169  char intensity_apex_char[40];
170  String aggr_Peak_Area = "";
171  String aggr_Peak_Apex = "";
172  String aggr_Fragment_Annotation = "";
173  String aggr_prec_Peak_Area = "";
174  String aggr_prec_Peak_Apex = "";
175  String aggr_prec_Fragment_Annotation = "";
176  for (std::vector<Feature>::const_iterator sub_it = feature_it->getSubordinates().begin(); sub_it != feature_it->getSubordinates().end(); ++sub_it)
177  {
178  sprintf(intensity_char, "%f", sub_it->getIntensity());
179  sprintf(intensity_apex_char, "%f", (double)sub_it->getMetaValue("peak_apex_int"));
180  if (sub_it->metaValueExists("FeatureLevel") && sub_it->getMetaValue("FeatureLevel") == "MS2")
181  {
182  aggr_Peak_Area += (String)intensity_char + ";";
183  aggr_Peak_Apex += (String)intensity_apex_char + ";";
184  aggr_Fragment_Annotation += (String)sub_it->getMetaValue("native_id") + ";";
185  }
186  else if (sub_it->metaValueExists("FeatureLevel") && sub_it->getMetaValue("FeatureLevel") == "MS1")
187  {
188  aggr_prec_Peak_Area += (String)intensity_char + ";";
189  aggr_Peak_Apex += (String)intensity_apex_char + ";";
190  aggr_prec_Fragment_Annotation += (String)sub_it->getMetaValue("native_id") + ";";
191  }
192  }
193  if (!feature_it->getSubordinates().empty())
194  {
195  aggr_Peak_Area = aggr_Peak_Area.substr(0, aggr_Peak_Area.size() - 1);
196  aggr_Peak_Apex = aggr_Peak_Apex.substr(0, aggr_Peak_Apex.size() - 1);
197  aggr_Fragment_Annotation = aggr_Fragment_Annotation.substr(0, aggr_Fragment_Annotation.size() - 1);
198  aggr_prec_Peak_Area = aggr_prec_Peak_Area.substr(0, aggr_prec_Peak_Area.size() - 1);
199  aggr_prec_Peak_Apex = aggr_prec_Peak_Apex.substr(0, aggr_prec_Peak_Apex.size() - 1);
200  aggr_prec_Fragment_Annotation = aggr_prec_Fragment_Annotation.substr(0, aggr_prec_Fragment_Annotation.size() - 1);
201  }
202 
203  String full_peptide_name = "";
204  for (int loc = -1; loc <= (int)pep.sequence.size(); loc++)
205  {
206  if (loc > -1 && loc < (int)pep.sequence.size())
207  {
208  full_peptide_name += pep.sequence[loc];
209  }
210  // C-terminal and N-terminal modifications may be at positions -1 or pep.sequence
211  for (Size modloc = 0; modloc < pep.modifications.size(); modloc++)
212  {
213  if (pep.modifications[modloc].location == loc)
214  {
215  full_peptide_name += "(UniMod:" + String(pep.modifications[modloc].unimod_id) + ")";
216  }
217  }
218  }
219 
220  // Compute peptide group label (use the provided label or use the
221  // transition group).
222  String group_label = pep.peptide_group_label;
223  if (group_label.empty()) group_label = id;
224  if (group_label == "light") group_label = id; // legacy fix since there are many TraMLs floating around which have "light" in there
225  if (group_label == "NA") group_label = id; // legacy fix since there are many TraMLs floating around which have "NA" in there
226 
227  // If a protein is present, take the first one
228  String protein_name = "";
229  if (!pep.protein_refs.empty() )
230  {
231  protein_name = pep.protein_refs[0];
232  }
233 
234  String line = "";
235  line += id + "_run0"
236  + "\t" + group_label
237  + "\t" + "0"
238  + "\t" + input_filename_
239  + "\t" + (String)feature_it->getRT()
240  + "\t" + "f_" + feature_it->getUniqueId() // TODO might not be unique!!!
241  + "\t" + (String)pep.sequence
242  + "\t" + full_peptide_name
243  + "\t" + (String)pep.charge
244  + "\t" + (String)transition->precursor_mz
245  + "\t" + (String)feature_it->getIntensity()
246  + "\t" + protein_name
247  + "\t" + decoy
248  // Note: missing MetaValues will just produce a DataValue::EMPTY which lead to an empty column
249  + "\t" + (String)feature_it->getMetaValue("assay_rt")
250  + "\t" + (String)feature_it->getMetaValue("delta_rt")
251  + "\t" + (String)feature_it->getMetaValue("leftWidth")
252  + "\t" + (String)feature_it->getMetaValue("main_var_xx_swath_prelim_score")
253  + "\t" + (String)feature_it->getMetaValue("norm_RT")
254  + "\t" + (String)feature_it->getMetaValue("nr_peaks")
255  + "\t" + (String)feature_it->getMetaValue("peak_apices_sum")
256  + "\t" + (String)feature_it->getMetaValue("potentialOutlier")
257  + "\t" + (String)feature_it->getMetaValue("initialPeakQuality")
258  + "\t" + (String)feature_it->getMetaValue("rightWidth")
259  + "\t" + (String)feature_it->getMetaValue("rt_score")
260  + "\t" + (String)feature_it->getMetaValue("sn_ratio")
261  + "\t" + (String)feature_it->getMetaValue("total_xic")
262  + "\t" + (String)feature_it->getMetaValue("var_bseries_score")
263  + "\t" + (String)feature_it->getMetaValue("var_dotprod_score")
264  + "\t" + (String)feature_it->getMetaValue("var_intensity_score")
265  + "\t" + (String)feature_it->getMetaValue("var_isotope_correlation_score")
266  + "\t" + (String)feature_it->getMetaValue("var_isotope_overlap_score")
267  + "\t" + (String)feature_it->getMetaValue("var_library_corr")
268  + "\t" + (String)feature_it->getMetaValue("var_library_dotprod")
269  + "\t" + (String)feature_it->getMetaValue("var_library_manhattan")
270  + "\t" + (String)feature_it->getMetaValue("var_library_rmsd")
271  + "\t" + (String)feature_it->getMetaValue("var_library_rootmeansquare")
272  + "\t" + (String)feature_it->getMetaValue("var_library_sangle")
273  + "\t" + (String)feature_it->getMetaValue("var_log_sn_score")
274  + "\t" + (String)feature_it->getMetaValue("var_manhatt_score")
275  + "\t" + (String)feature_it->getMetaValue("var_massdev_score")
276  + "\t" + (String)feature_it->getMetaValue("var_massdev_score_weighted")
277  + "\t" + (String)feature_it->getMetaValue("var_norm_rt_score")
278  + "\t" + (String)feature_it->getMetaValue("var_xcorr_coelution")
279  + "\t" + (String)feature_it->getMetaValue("var_xcorr_coelution_weighted")
280  + "\t" + (String)feature_it->getMetaValue("var_xcorr_shape")
281  + "\t" + (String)feature_it->getMetaValue("var_xcorr_shape_weighted")
282  + "\t" + (String)feature_it->getMetaValue("var_yseries_score")
283  + "\t" + (String)feature_it->getMetaValue("var_elution_model_fit_score");
284 
285  if (use_ms1_traces_)
286  {
287  line += "\t" + (String)feature_it->getMetaValue("var_ms1_ppm_diff")
288  + "\t" + (String)feature_it->getMetaValue("var_ms1_isotope_correlation")
289  + "\t" + (String)feature_it->getMetaValue("var_ms1_isotope_overlap")
290  + "\t" + (String)feature_it->getMetaValue("var_ms1_xcorr_coelution")
291  + "\t" + (String)feature_it->getMetaValue("var_ms1_xcorr_shape");
292  }
293 
294  line += "\t" + (String)feature_it->getMetaValue("xx_lda_prelim_score")
295  + "\t" + (String)feature_it->getMetaValue("xx_swath_prelim_score");
296  if (sonar_)
297  {
298  line += "\t" + (String)feature_it->getMetaValue("var_sonar_lag")
299  + "\t" + (String)feature_it->getMetaValue("var_sonar_shape")
300  + "\t" + (String)feature_it->getMetaValue("var_sonar_log_sn")
301  + "\t" + (String)feature_it->getMetaValue("var_sonar_log_diff")
302  + "\t" + (String)feature_it->getMetaValue("var_sonar_log_trend")
303  + "\t" + (String)feature_it->getMetaValue("var_sonar_rsq");
304 
305  }
306  if (use_ms1_traces_)
307  {
308  line += "\t" + aggr_prec_Peak_Area + "\t" + aggr_prec_Peak_Apex + "\t" + aggr_prec_Fragment_Annotation;
309  }
310  line += "\t" + aggr_Peak_Area + "\t" + aggr_Peak_Apex + "\t" + aggr_Fragment_Annotation;
311  if (enable_uis_scoring_)
312  {
313  line += "\t" + (String)feature_it->getMetaValue("id_target_transition_names")
314  + "\t" + (String)feature_it->getMetaValue("id_target_ind_log_intensity")
315  + "\t" + (String)feature_it->getMetaValue("id_target_num_transitions")
316  + "\t" + (String)feature_it->getMetaValue("id_target_ind_xcorr_coelution")
317  + "\t" + (String)feature_it->getMetaValue("id_target_ind_xcorr_shape")
318  + "\t" + (String)feature_it->getMetaValue("id_target_ind_log_sn_score")
319  + "\t" + (String)feature_it->getMetaValue("id_target_ind_massdev_score")
320  + "\t" + (String)feature_it->getMetaValue("id_target_ind_isotope_correlation")
321  + "\t" + (String)feature_it->getMetaValue("id_target_ind_isotope_overlap")
322  + "\t" + (String)feature_it->getMetaValue("id_decoy_transition_names")
323  + "\t" + (String)feature_it->getMetaValue("id_decoy_ind_log_intensity")
324  + "\t" + (String)feature_it->getMetaValue("id_decoy_num_transitions")
325  + "\t" + (String)feature_it->getMetaValue("id_decoy_ind_xcorr_coelution")
326  + "\t" + (String)feature_it->getMetaValue("id_decoy_ind_xcorr_shape")
327  + "\t" + (String)feature_it->getMetaValue("id_decoy_ind_log_sn_score")
328  + "\t" + (String)feature_it->getMetaValue("id_decoy_ind_massdev_score")
329  + "\t" + (String)feature_it->getMetaValue("id_decoy_ind_isotope_correlation")
330  + "\t" + (String)feature_it->getMetaValue("id_decoy_ind_isotope_overlap");
331  }
332  line += "\n"; result += line;
333  } // end of iteration
334  return result;
335  }
336 
347  void writeLines(std::vector<String> to_output)
348  {
349  for (Size i = 0; i < to_output.size(); i++) { ofs << to_output[i]; }
350  }
351 
352  };
353 
354 }
355 
356 #endif // OPENMS_ANALYSIS_OPENSWATH_OPENSWATHTSVWRITER_H
357 
void writeLines(std::vector< String > to_output)
Write data to disk.
Definition: OpenSwathTSVWriter.h:347
A more convenient string class.
Definition: String.h:57
std::vector< LightModification > modifications
Definition: TransitionExperiment.h:186
bool use_ms1_traces_
Definition: OpenSwathTSVWriter.h:62
A container for features.
Definition: FeatureMap.h:94
bool sonar_
Definition: OpenSwathTSVWriter.h:63
Class to write out an OpenSwath TSV output (mProphet input)
Definition: OpenSwathTSVWriter.h:57
double precursor_mz
Definition: TransitionExperiment.h:60
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool decoy
Definition: TransitionExperiment.h:62
String prepareLine(const OpenSwath::LightCompound &pep, const OpenSwath::LightTransition *transition, const FeatureMap &output, const String id)
Prepare a single line (feature) for output.
Definition: OpenSwathTSVWriter.h:154
String substr(size_t pos=0, size_t n=npos) const
Wrapper for the STL substr() method. Returns a String object with its contents initialized to a subst...
bool isActive()
Definition: OpenSwathTSVWriter.h:81
std::string peptide_group_label
Definition: TransitionExperiment.h:163
bool enable_uis_scoring_
Definition: OpenSwathTSVWriter.h:64
std::ofstream ofs
Definition: OpenSwathTSVWriter.h:59
void writeHeader()
Initializes file by writing TSV header.
Definition: OpenSwathTSVWriter.h:90
Definition: TransitionExperiment.h:150
std::string sequence
Definition: TransitionExperiment.h:160
std::vector< std::string > protein_refs
Definition: TransitionExperiment.h:161
Definition: TransitionExperiment.h:47
String input_filename_
Definition: OpenSwathTSVWriter.h:60
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128
bool doWrite_
Definition: OpenSwathTSVWriter.h:61
OpenSwathTSVWriter(String output_filename, String input_filename="inputfile", bool ms1_scores=false, bool sonar=false, bool uis_scores=false)
Definition: OpenSwathTSVWriter.h:68
int charge
Definition: TransitionExperiment.h:159

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:02 using doxygen 1.8.13