MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / calibrate

Method calibrate

src/openms/source/FILTERING/CALIBRATION/InternalCalibration.cpp:278–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

276 }
277
278 bool InternalCalibration::calibrate(PeakMap& exp,
279 const IntList& target_mslvl,
280 MZTrafoModel::MODELTYPE model_type,
281 double rt_chunk,
282 bool use_RANSAC,
283 double post_ppm_median,
284 double post_ppm_MAD,
285 const String& file_models,
286 const String& file_models_plot,
287 const String& file_residuals,
288 const String& file_residuals_plot,
289 const String& rscript_executable_)
290 {
291 QString rscript_executable = rscript_executable_.toQString();
292
293 // ensure sorting; required for finding RT ranges and lock masses
294 if (!exp.isSorted(true))
295 {
296 exp.sortSpectra(true);
297 }
298
299 startProgress(0, exp.size(), "Applying calibration to data");
300
301 std::vector<MZTrafoModel> tms; // each spectrum gets its own model (params are cheap to store)
302 std::map<Size, Size> invalid_models; // indices from tms[] -> exp[]; where model creation failed (e..g, not enough calibration points)
303 bool hasValidModels(false); // was at least one model valid?
304 bool global_model = (rt_chunk < 0);
305 if (global_model)
306 { // build one global modal
307 OPENMS_LOG_INFO << "Building a global model..." << std::endl;
308 tms.emplace_back();
309 tms[0].train(cal_data_, model_type, use_RANSAC);
310 if (MZTrafoModel::isValidModel(tms[0]))
311 {
312 applyTransformation(exp, target_mslvl, tms[0]);
313 hasValidModels = true;
314 }
315 }
316 else
317 { // one model per spectrum (not all might be needed, if certain MS levels are excluded from calibration)
318 tms.reserve(exp.size());
319 // go through spectra and calibrate
320 Size i(0), i_mslvl(0);
321 for (PeakMap::Iterator it = exp.begin(); it != exp.end(); ++it, ++i)
322 {
323 setProgress(i);
324
325 // skip this MS level?
326 if (!(ListUtils::contains(target_mslvl, it->getMSLevel()) || // scan m/z needs correction
327 ListUtils::contains(target_mslvl, it->getMSLevel() - 1))) // precursor m/z needs correction
328 {
329 continue;
330 }
331
332 //
333 // build model
334 //
335 tms.emplace_back();

Callers

nothing calls this directly

Calls 15

getPPMFunction · 0.85
medianFunction · 0.85
MADFunction · 0.85
sortSpectraMethod · 0.80
emplace_backMethod · 0.80
getMSLevelMethod · 0.80
backMethod · 0.80
setCoefficientsMethod · 0.80
countMethod · 0.80
getRefMZMethod · 0.80
containsFunction · 0.50
StringClass · 0.50

Tested by

no test coverage detected