ExitCodes main_(int, const char**) { //------------------------------------------------------------- // parameter handling //------------------------------------------------------------- String in = getStringOption_("in"); String out = getStringOption_("out"); String trafo_in = getStringOption_("trafo_in"); String trafo_out = getStringOption_("trafo_out"); Param model_params = getParam_().copy("model:", true); String model_type = model_params.getValue("type"); model_params = model_params.copy(model_type + ":", true); ProgressLogger progresslogger; progresslogger.setLogType(log_type_); //------------------------------------------------------------- // check for valid input //------------------------------------------------------------- if (out.empty() && trafo_out.empty()) { writeLog_("Error: Either a data or a transformation output file has to be provided (parameters 'out'/'trafo_out')"); return ILLEGAL_PARAMETERS; } if (in.empty() != out.empty()) { writeLog_("Error: Data input and output parameters ('in'/'out') must be used together"); return ILLEGAL_PARAMETERS; } //------------------------------------------------------------- // apply transformation //------------------------------------------------------------- TransformationXMLFile trafoxml; TransformationDescription trafo; trafoxml.load(trafo_in, trafo); if (model_type != "none") { trafo.fitModel(model_type, model_params); } if (getFlag_("invert")) { trafo.invert(); } if (!trafo_out.empty()) { trafoxml.store(trafo_out, trafo); } if (!in.empty()) // load input { FileTypes::Type in_type = FileHandler::getType(in); if (in_type == FileTypes::MZML) { MzMLFile file; MSExperiment<> map; applyTransformation_(in, out, trafo, file, map); } else if (in_type == FileTypes::FEATUREXML) { FeatureXMLFile file; FeatureMap map; applyTransformation_(in, out, trafo, file, map); } else if (in_type == FileTypes::CONSENSUSXML) { ConsensusXMLFile file; ConsensusMap map; applyTransformation_(in, out, trafo, file, map); } else if (in_type == FileTypes::IDXML) { IdXMLFile file; vector<ProteinIdentification> proteins; vector<PeptideIdentification> peptides; file.load(in, proteins, peptides); bool store_original_rt = getFlag_("store_original_rt"); MapAlignmentTransformer::transformRetentionTimes(peptides, trafo, store_original_rt); // no "data processing" section in idXML file.store(out, proteins, peptides); } } return EXECUTION_OK; }
ExitCodes main_(int, const char **) { StringList file_list = getStringList_("in"); String tr_file_str = getStringOption_("tr"); String out = getStringOption_("out"); bool is_swath = getFlag_("is_swath"); bool ppm = getFlag_("ppm"); bool extract_MS1 = getFlag_("extract_MS1"); double min_upper_edge_dist = getDoubleOption_("min_upper_edge_dist"); double mz_extraction_window = getDoubleOption_("mz_window"); double rt_extraction_window = getDoubleOption_("rt_window"); String extraction_function = getStringOption_("extraction_function"); // If we have a transformation file, trafo will transform the RT in the // scoring according to the model. If we dont have one, it will apply the // null transformation. String trafo_in = getStringOption_("rt_norm"); TransformationDescription trafo; if (trafo_in.size() > 0) { TransformationXMLFile trafoxml; String model_type = getStringOption_("model:type"); Param model_params = getParam_().copy("model:", true); trafoxml.load(trafo_in, trafo); trafo.fitModel(model_type, model_params); } TransformationDescription trafo_inverse = trafo; trafo_inverse.invert(); const char * tr_file = tr_file_str.c_str(); MapType out_exp; std::vector< OpenMS::MSChromatogram > chromatograms; TraMLFile traml; OpenMS::TargetedExperiment targeted_exp; std::cout << "Loading TraML file" << std::endl; traml.load(tr_file, targeted_exp); std::cout << "Loaded TraML file" << std::endl; // Do parallelization over the different input files // Only in OpenMP 3.0 are unsigned loop variables allowed #ifdef _OPENMP #pragma omp parallel for #endif for (SignedSize i = 0; i < boost::numeric_cast<SignedSize>(file_list.size()); ++i) { boost::shared_ptr<PeakMap > exp(new PeakMap); MzMLFile f; // Logging and output to the console // IF_MASTERTHREAD f.setLogType(log_type_); // Find the transitions to extract and extract them MapType tmp_out; OpenMS::TargetedExperiment transition_exp_used; f.load(file_list[i], *exp); if (exp->empty() ) { continue; } // if empty, go on OpenSwath::SpectrumAccessPtr expptr = SimpleOpenMSSpectraFactory::getSpectrumAccessOpenMSPtr(exp); bool do_continue = true; if (is_swath) { do_continue = OpenSwathHelper::checkSwathMapAndSelectTransitions(*exp, targeted_exp, transition_exp_used, min_upper_edge_dist); } else { transition_exp_used = targeted_exp; } #ifdef _OPENMP #pragma omp critical (OpenSwathChromatogramExtractor_metadata) #endif // after loading the first file, copy the meta data from that experiment // this may happen *after* chromatograms were already added to the // output, thus we do NOT fill the experiment here but rather store all // the chromatograms in the "chromatograms" array and store them in // out_exp afterwards. if (i == 0) { out_exp = *exp; out_exp.clear(false); } std::cout << "Extracting " << transition_exp_used.getTransitions().size() << " transitions" << std::endl; std::vector< OpenSwath::ChromatogramPtr > chromatogram_ptrs; std::vector< ChromatogramExtractor::ExtractionCoordinates > coordinates; // continue if the map is not empty if (do_continue) { // Prepare the coordinates (with or without rt extraction) and then extract the chromatograms ChromatogramExtractor extractor; if (rt_extraction_window < 0) { extractor.prepare_coordinates(chromatogram_ptrs, coordinates, transition_exp_used, rt_extraction_window, extract_MS1); } else { // Use an rt extraction window of 0.0 which will just write the retention time in start / end positions extractor.prepare_coordinates(chromatogram_ptrs, coordinates, transition_exp_used, 0.0, extract_MS1); for (std::vector< ChromatogramExtractor::ExtractionCoordinates >::iterator it = coordinates.begin(); it != coordinates.end(); ++it) { it->rt_start = trafo_inverse.apply(it->rt_start) - rt_extraction_window / 2.0; it->rt_end = trafo_inverse.apply(it->rt_end) + rt_extraction_window / 2.0; } } extractor.extractChromatograms(expptr, chromatogram_ptrs, coordinates, mz_extraction_window, ppm, extraction_function); #ifdef _OPENMP #pragma omp critical (OpenSwathChromatogramExtractor_insertMS1) #endif { // Remove potential meta value indicating cached data SpectrumSettings exp_settings = (*exp)[0]; for (Size j = 0; j < exp_settings.getDataProcessing().size(); j++) { if (exp_settings.getDataProcessing()[j]->metaValueExists("cached_data")) { exp_settings.getDataProcessing()[j]->removeMetaValue("cached_data"); } } extractor.return_chromatogram(chromatogram_ptrs, coordinates, transition_exp_used, exp_settings, chromatograms, extract_MS1); } } // end of do_continue } // end of loop over all files / end of OpenMP // TODO check that no chromatogram IDs occur multiple times ! // store the output out_exp.setChromatograms(chromatograms); MzMLFile mzf; mzf.setLogType(log_type_); addDataProcessing_(out_exp, getProcessingInfo_(DataProcessing::SMOOTHING)); mzf.store(out, out_exp); return EXECUTION_OK; }