35 #ifndef OPENMS_ANALYSIS_OPENSWATH_OPENSWATHOSWWRITER_H 36 #define OPENMS_ANALYSIS_OPENSWATH_OPENSWATHOSWWRITER_H 69 output_filename_(output_filename),
70 input_filename_(input_filename),
71 doWrite_(!output_filename.empty()),
72 use_ms1_traces_(ms1_scores),
74 enable_uis_scoring_(uis_scores)
77 static int callback(
void * ,
int argc,
char **argv,
char **azColName){
81 printf(
"%s = %s\n", azColName[i], argv[i] ? argv[i] :
"NULL");
103 rc = sqlite3_open(output_filename_.c_str(), &db);
106 fprintf(stderr,
"Can't open database: %s\n", sqlite3_errmsg(db));
110 const char * create_sql =
111 "CREATE TABLE FEATURE(" \
112 "ID INT PRIMARY KEY NOT NULL," \
113 "PRECURSOR_ID INT NOT NULL," \
114 "RT REAL NOT NULL," \
115 "DELTA_RT REAL NOT NULL," \
116 "LEFT_WIDTH REAL NOT NULL," \
117 "RIGHT_WIDTH REAL NOT NULL); " \
119 "CREATE TABLE FEATURE_MS1(" \
120 "FEATURE_ID INT NOT NULL," \
121 "AREA_INTENSITY REAL NOT NULL," \
122 "APEX_INTENSITY REAL NOT NULL," \
123 "VAR_MASSDEV_SCORE REAL NOT NULL," \
124 "VAR_ISOTOPE_CORRELATION_SCORE REAL NOT NULL," \
125 "VAR_ISOTOPE_OVERLAP_SCORE REAL NOT NULL," \
126 "VAR_XCORR_COELUTION REAL NOT NULL," \
127 "VAR_XCORR_SHAPE REAL NOT NULL); " \
129 "CREATE TABLE FEATURE_MS2(" \
130 "FEATURE_ID INT NOT NULL," \
131 "AREA_INTENSITY REAL NOT NULL," \
132 "APEX_INTENSITY REAL NOT NULL," \
133 "VAR_BSERIES_SCORE REAL NOT NULL," \
134 "VAR_DOTPROD_SCORE REAL NOT NULL," \
135 "VAR_INTENSITY_SCORE REAL NOT NULL," \
136 "VAR_ISOTOPE_CORRELATION_SCORE REAL NOT NULL," \
137 "VAR_ISOTOPE_OVERLAP_SCORE REAL NOT NULL," \
138 "VAR_LIBRARY_CORR REAL NOT NULL," \
139 "VAR_LIBRARY_DOTPROD REAL NOT NULL," \
140 "VAR_LIBRARY_MANHATTAN REAL NOT NULL," \
141 "VAR_LIBRARY_RMSD REAL NOT NULL," \
142 "VAR_LIBRARY_ROOTMEANSQUARE REAL NOT NULL," \
143 "VAR_LIBRARY_SANGLE REAL NOT NULL," \
144 "VAR_LOG_SN_SCORE REAL NOT NULL," \
145 "VAR_MANHATTAN_SCORE REAL NOT NULL," \
146 "VAR_MASSDEV_SCORE REAL NOT NULL," \
147 "VAR_MASSDEV_SCORE_WEIGHTED REAL NOT NULL," \
148 "VAR_NORM_RT_SCORE REAL NOT NULL," \
149 "VAR_XCORR_COELUTION REAL NOT NULL," \
150 "VAR_XCORR_COELUTION_WEIGHTED REAL NOT NULL," \
151 "VAR_XCORR_SHAPE REAL NOT NULL," \
152 "VAR_XCORR_SHAPE_WEIGHTED REAL NOT NULL," \
153 "VAR_YSERIES_SCORE REAL NOT NULL," \
154 "VAR_ELUTION_MODEL_FIT_SCORE REAL NULL," \
155 "VAR_SONAR_LAG REAL NULL," \
156 "VAR_SONAR_SHAPE REAL NULL," \
157 "VAR_SONAR_LOG_SN REAL NULL," \
158 "VAR_SONAR_LOG_DIFF REAL NULL," \
159 "VAR_SONAR_LOG_TREND REAL NULL," \
160 "VAR_SONAR_RSQ REAL NULL); " \
162 "CREATE TABLE FEATURE_TRANSITION(" \
163 "FEATURE_ID INT NOT NULL," \
164 "TRANSITION_ID INT NOT NULL," \
165 "AREA_INTENSITY REAL NOT NULL," \
166 "APEX_INTENSITY REAL NOT NULL," \
167 "VAR_LOG_INTENSITY REAL NULL," \
168 "VAR_XCORR_COELUTION REAL NULL," \
169 "VAR_XCORR_SHAPE REAL NULL," \
170 "VAR_LOG_SN_SCORE REAL NULL," \
171 "VAR_MASSDEV_SCORE REAL NULL," \
172 "VAR_ISOTOPE_CORRELATION_SCORE REAL NULL," \
173 "VAR_ISOTOPE_OVERLAP_SCORE REAL NULL); " ;
177 rc = sqlite3_exec(db, create_sql, callback, 0, &zErrMsg);
178 if( rc != SQLITE_OK )
182 sqlite3_free(zErrMsg);
205 std::stringstream sql, sql_feature, sql_feature_ms1, sql_feature_ms2, sql_feature_ms2_transition, sql_feature_uis_transition;
207 for (FeatureMap::iterator feature_it = output.begin(); feature_it != output.end(); ++feature_it)
209 for (std::vector<Feature>::iterator sub_it = feature_it->getSubordinates().begin(); sub_it != feature_it->getSubordinates().end(); ++sub_it)
211 if (sub_it->metaValueExists(
"FeatureLevel") && sub_it->getMetaValue(
"FeatureLevel") ==
"MS2")
213 sql_feature_ms2_transition <<
"INSERT INTO FEATURE_TRANSITION (FEATURE_ID, TRANSITION_ID, AREA_INTENSITY, APEX_INTENSITY) VALUES (" 214 << feature_it->getUniqueId() <<
", " 215 << (
String)sub_it->getMetaValue(
"native_id") <<
", " 216 << sub_it->getIntensity() <<
", " 217 << sub_it->getMetaValue(
"peak_apex_int") <<
"); ";
219 else if (sub_it->metaValueExists(
"FeatureLevel") && sub_it->getMetaValue(
"FeatureLevel") ==
"MS1")
221 sql_feature_ms1 <<
"INSERT INTO FEATURE_MS1 (FEATURE_ID, AREA_INTENSITY, APEX_INTENSITY, VAR_MASSDEV_SCORE, VAR_ISOTOPE_CORRELATION_SCORE, VAR_ISOTOPE_OVERLAP_SCORE, VAR_XCORR_COELUTION, VAR_XCORR_SHAPE) VALUES (" 222 << feature_it->getUniqueId() <<
", " 223 << sub_it->getIntensity() <<
", " 224 << sub_it->getMetaValue(
"peak_apex_int") <<
", " 225 << feature_it->getMetaValue(
"var_ms1_ppm_diff") <<
", " 226 << feature_it->getMetaValue(
"var_ms1_isotope_correlation") <<
", " 227 << feature_it->getMetaValue(
"var_ms1_isotope_overlap") <<
", " 228 << feature_it->getMetaValue(
"var_ms1_xcorr_coelution") <<
", " 229 << feature_it->getMetaValue(
"var_ms1_xcorr_shape") <<
"); ";
233 sql_feature <<
"INSERT INTO FEATURE (ID, PRECURSOR_ID, RT, DELTA_RT, LEFT_WIDTH, RIGHT_WIDTH) VALUES (" 234 << feature_it->getUniqueId() <<
", " 236 << feature_it->getMetaValue(
"norm_RT") <<
", " 237 << feature_it->getMetaValue(
"delta_rt") <<
", " 238 << feature_it->getMetaValue(
"leftWidth") <<
", " 239 << feature_it->getMetaValue(
"rightWidth") <<
"); ";
241 std::string var_elution_model_fit_score =
"NULL", var_sonar_lag =
"NULL", var_sonar_shape =
"NULL", var_sonar_log_sn =
"NULL", var_sonar_log_diff =
"NULL", var_sonar_log_trend =
"NULL", var_sonar_rsq =
"NULL";
243 if (!feature_it->getMetaValue(
"var_elution_model_fit_score").isEmpty())
245 var_elution_model_fit_score = feature_it->getMetaValue(
"var_elution_model_fit_score").toString();
247 if (!feature_it->getMetaValue(
"var_sonar_lag").isEmpty())
249 var_sonar_lag = feature_it->getMetaValue(
"var_sonar_lag").toString();
251 if (!feature_it->getMetaValue(
"var_sonar_shape").isEmpty())
253 var_sonar_shape = feature_it->getMetaValue(
"var_sonar_shape").toString();
255 if (!feature_it->getMetaValue(
"var_sonar_log_sn").isEmpty())
257 var_sonar_log_sn = feature_it->getMetaValue(
"var_sonar_log_sn").toString();
259 if (!feature_it->getMetaValue(
"var_sonar_log_diff").isEmpty())
261 var_sonar_log_diff = feature_it->getMetaValue(
"var_sonar_log_diff").toString();
263 if (!feature_it->getMetaValue(
"var_sonar_log_trend").isEmpty())
265 var_sonar_log_trend = feature_it->getMetaValue(
"var_sonar_log_trend").toString();
267 if (!feature_it->getMetaValue(
"var_sonar_rsq").isEmpty())
269 var_sonar_rsq = feature_it->getMetaValue(
"var_sonar_rsq").toString();
272 sql_feature_ms2 <<
"INSERT INTO FEATURE_MS2 (FEATURE_ID, AREA_INTENSITY, APEX_INTENSITY, VAR_BSERIES_SCORE, VAR_DOTPROD_SCORE, VAR_INTENSITY_SCORE, VAR_ISOTOPE_CORRELATION_SCORE, VAR_ISOTOPE_OVERLAP_SCORE, VAR_LIBRARY_CORR, VAR_LIBRARY_DOTPROD, VAR_LIBRARY_MANHATTAN, VAR_LIBRARY_RMSD, VAR_LIBRARY_ROOTMEANSQUARE, VAR_LIBRARY_SANGLE, VAR_LOG_SN_SCORE, VAR_MANHATTAN_SCORE, VAR_MASSDEV_SCORE, VAR_MASSDEV_SCORE_WEIGHTED, VAR_NORM_RT_SCORE, VAR_XCORR_COELUTION,VAR_XCORR_COELUTION_WEIGHTED, VAR_XCORR_SHAPE, VAR_XCORR_SHAPE_WEIGHTED, VAR_YSERIES_SCORE, VAR_ELUTION_MODEL_FIT_SCORE, VAR_SONAR_LAG, VAR_SONAR_SHAPE, VAR_SONAR_LOG_SN, VAR_SONAR_LOG_DIFF, VAR_SONAR_LOG_TREND, VAR_SONAR_RSQ) VALUES (" 273 << feature_it->getUniqueId() <<
", " 274 << feature_it->getIntensity() <<
", " 275 << feature_it->getMetaValue(
"peak_apices_sum") <<
", " 276 << feature_it->getMetaValue(
"var_bseries_score") <<
", " 277 << feature_it->getMetaValue(
"var_dotprod_score") <<
", " 278 << feature_it->getMetaValue(
"var_intensity_score") <<
", " 279 << feature_it->getMetaValue(
"var_isotope_correlation_score") <<
", " 280 << feature_it->getMetaValue(
"var_isotope_overlap_score") <<
", " 281 << feature_it->getMetaValue(
"var_library_corr") <<
", " 282 << feature_it->getMetaValue(
"var_library_dotprod") <<
", " 283 << feature_it->getMetaValue(
"var_library_manhattan") <<
", " 284 << feature_it->getMetaValue(
"var_library_rmsd") <<
", " 285 << feature_it->getMetaValue(
"var_library_rootmeansquare") <<
", " 286 << feature_it->getMetaValue(
"var_library_sangle") <<
", " 287 << feature_it->getMetaValue(
"var_log_sn_score") <<
", " 288 << feature_it->getMetaValue(
"var_manhatt_score") <<
", " 289 << feature_it->getMetaValue(
"var_massdev_score") <<
", " 290 << feature_it->getMetaValue(
"var_massdev_score_weighted") <<
", " 291 << feature_it->getMetaValue(
"var_norm_rt_score") <<
", " 292 << feature_it->getMetaValue(
"var_xcorr_coelution") <<
", " 293 << feature_it->getMetaValue(
"var_xcorr_coelution_weighted") <<
", " 294 << feature_it->getMetaValue(
"var_xcorr_shape") <<
", " 295 << feature_it->getMetaValue(
"var_xcorr_shape_weighted") <<
", " 296 << feature_it->getMetaValue(
"var_yseries_score") <<
", " 297 << var_elution_model_fit_score <<
", " 298 << var_sonar_lag <<
", " 299 << var_sonar_shape <<
", " 300 << var_sonar_log_sn <<
", " 301 << var_sonar_log_diff <<
", " 302 << var_sonar_log_trend <<
", " 303 << var_sonar_rsq <<
"); ";
305 if (enable_uis_scoring_)
307 std::vector<String> id_target_transition_names = ListUtils::create<String>((
String)feature_it->getMetaValue(
"id_target_transition_names"),
';');
308 std::vector<double> id_target_area_intensity = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_area_intensity"),
';');
309 std::vector<double> id_target_apex_intensity = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_apex_intensity"),
';');
310 std::vector<double> id_target_log_intensity = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_ind_log_intensity"),
';');
311 std::vector<double> id_target_ind_xcorr_coelution = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_ind_xcorr_coelution"),
';');
312 std::vector<double> id_target_ind_xcorr_shape = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_ind_xcorr_shape"),
';');
313 std::vector<double> id_target_ind_log_sn_score = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_ind_log_sn_score"),
';');
314 std::vector<double> id_target_ind_massdev_score = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_ind_massdev_score"),
';');
315 std::vector<double> id_target_ind_isotope_correlation = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_ind_isotope_correlation"),
';');
316 std::vector<double> id_target_ind_isotope_overlap = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_target_ind_isotope_overlap"),
';');
318 if ((
String)feature_it->getMetaValue(
"id_target_num_transitions") !=
"")
320 for (
int i = 0; i < feature_it->getMetaValue(
"id_target_num_transitions").toString().toInt(); ++i)
322 sql_feature_uis_transition <<
"INSERT INTO FEATURE_TRANSITION (FEATURE_ID, TRANSITION_ID, AREA_INTENSITY, APEX_INTENSITY, VAR_LOG_INTENSITY, VAR_XCORR_COELUTION, VAR_XCORR_SHAPE, VAR_LOG_SN_SCORE, VAR_MASSDEV_SCORE, VAR_ISOTOPE_CORRELATION_SCORE, VAR_ISOTOPE_OVERLAP_SCORE) VALUES (" 323 << feature_it->getUniqueId() <<
", " 324 << id_target_transition_names[i] <<
", " 325 << id_target_area_intensity[i] <<
", " 326 << id_target_apex_intensity[i] <<
", " 327 << id_target_log_intensity[i] <<
", " 328 << id_target_ind_xcorr_coelution[i] <<
", " 329 << id_target_ind_xcorr_shape[i] <<
", " 330 << id_target_ind_log_sn_score[i] <<
", " 331 << id_target_ind_massdev_score[i] <<
", " 332 << id_target_ind_isotope_correlation[i] <<
", " 333 << id_target_ind_isotope_overlap[i] <<
"); ";
337 std::vector<String> id_decoy_transition_names = ListUtils::create<String>((
String)feature_it->getMetaValue(
"id_decoy_transition_names"),
';');
338 std::vector<double> id_decoy_area_intensity = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_area_intensity"),
';');
339 std::vector<double> id_decoy_apex_intensity = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_apex_intensity"),
';');
340 std::vector<double> id_decoy_log_intensity = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_ind_log_intensity"),
';');
341 std::vector<double> id_decoy_ind_xcorr_coelution = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_ind_xcorr_coelution"),
';');
342 std::vector<double> id_decoy_ind_xcorr_shape = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_ind_xcorr_shape"),
';');
343 std::vector<double> id_decoy_ind_log_sn_score = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_ind_log_sn_score"),
';');
344 std::vector<double> id_decoy_ind_massdev_score = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_ind_massdev_score"),
';');
345 std::vector<double> id_decoy_ind_isotope_correlation = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_ind_isotope_correlation"),
';');
346 std::vector<double> id_decoy_ind_isotope_overlap = ListUtils::create<double>((
String)feature_it->getMetaValue(
"id_decoy_ind_isotope_overlap"),
';');
348 if ((
String)feature_it->getMetaValue(
"id_decoy_num_transitions") !=
"")
350 for (
int i = 0; i < feature_it->getMetaValue(
"id_decoy_num_transitions").toString().toInt(); ++i)
352 sql_feature_uis_transition <<
"INSERT INTO FEATURE_TRANSITION (FEATURE_ID, TRANSITION_ID, AREA_INTENSITY, APEX_INTENSITY, VAR_LOG_INTENSITY, VAR_XCORR_COELUTION, VAR_XCORR_SHAPE, VAR_LOG_SN_SCORE, VAR_MASSDEV_SCORE, VAR_ISOTOPE_CORRELATION_SCORE, VAR_ISOTOPE_OVERLAP_SCORE) VALUES (" 353 << feature_it->getUniqueId() <<
", " 354 << id_decoy_transition_names[i] <<
", " 355 << id_decoy_area_intensity[i] <<
", " 356 << id_decoy_apex_intensity[i] <<
", " 357 << id_decoy_log_intensity[i] <<
", " 358 << id_decoy_ind_xcorr_coelution[i] <<
", " 359 << id_decoy_ind_xcorr_shape[i] <<
", " 360 << id_decoy_ind_log_sn_score[i] <<
", " 361 << id_decoy_ind_massdev_score[i] <<
", " 362 << id_decoy_ind_isotope_correlation[i] <<
", " 363 << id_decoy_ind_isotope_overlap[i] <<
"); ";
369 if (enable_uis_scoring_)
371 sql << sql_feature.str() << sql_feature_ms1.str() << sql_feature_ms2.str() << sql_feature_uis_transition.str();
375 sql << sql_feature.str() << sql_feature_ms1.str() << sql_feature_ms2.str() << sql_feature_ms2_transition.str();
402 rc = sqlite3_open(output_filename_.c_str(), &db);
405 fprintf(stderr,
"Can't open database: %s\n", sqlite3_errmsg(db));
408 sqlite3_exec(db,
"BEGIN TRANSACTION", NULL, NULL, &zErrMsg);
410 for (
Size i = 0; i < to_osw_output.size(); i++)
412 rc = sqlite3_exec(db, to_osw_output[i].c_str(), callback, 0, &zErrMsg);
413 if( rc != SQLITE_OK )
417 sqlite3_free(zErrMsg);
421 sqlite3_exec(db,
"END TRANSACTION", NULL, NULL, &zErrMsg);
430 #endif // OPENMS_ANALYSIS_OPENSWATH_OPENSWATHOSWWRITER_H String input_filename_
Definition: OpenSwathOSWWriter.h:60
String output_filename_
Definition: OpenSwathOSWWriter.h:59
A more convenient string class.
Definition: String.h:57
A container for features.
Definition: FeatureMap.h:94
bool sonar_
Definition: OpenSwathOSWWriter.h:63
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
bool use_ms1_traces_
Definition: OpenSwathOSWWriter.h:62
static int callback(void *, int argc, char **argv, char **azColName)
Definition: OpenSwathOSWWriter.h:77
Class to write out an OpenSwath OSW SQLite output (PyProphet input)
Definition: OpenSwathOSWWriter.h:57
void writeHeader()
Initializes file by generating SQLite tables.
Definition: OpenSwathOSWWriter.h:96
bool enable_uis_scoring_
Definition: OpenSwathOSWWriter.h:64
OpenSwathOSWWriter(String output_filename, String input_filename="inputfile", bool ms1_scores=false, bool sonar=false, bool uis_scores=false)
Definition: OpenSwathOSWWriter.h:68
A method or algorithm argument contains illegal values.
Definition: Exception.h:649
String prepareLine(const OpenSwath::LightCompound &, const OpenSwath::LightTransition *, FeatureMap &output, String id)
Prepare a single line (feature) for output.
Definition: OpenSwathOSWWriter.h:201
bool doWrite_
Definition: OpenSwathOSWWriter.h:61
Definition: TransitionExperiment.h:150
Definition: TransitionExperiment.h:47
bool isActive()
Definition: OpenSwathOSWWriter.h:87
void writeLines(std::vector< String > to_osw_output)
Write data to disk.
Definition: OpenSwathOSWWriter.h:394
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:128