35 #ifndef OPENMS_APPLICATIONS_MAPALIGNERBASE_H 36 #define OPENMS_APPLICATIONS_MAPALIGNERBASE_H 71 class TOPPMapAlignerBase :
76 TOPPMapAlignerBase(String name, String description,
bool official =
true) :
77 TOPPBase(name, description, official)
82 static Param getModelDefaults(
const String& default_model)
85 params.setValue(
"type", default_model,
"Type of model");
87 StringList model_types = ListUtils::create<String>(
"linear,b_spline,interpolated");
90 model_types.insert(model_types.begin(), default_model);
92 params.setValidStrings(
"type", model_types);
96 params.insert(
"linear:", model_params);
97 params.setSectionDescription(
"linear",
"Parameters for 'linear' model");
99 params.insert(
"b_spline:", model_params);
100 params.setSectionDescription(
"b_spline",
"Parameters for 'b_spline' model");
102 params.insert(
"interpolated:", model_params);
103 params.setSectionDescription(
"interpolated",
104 "Parameters for 'interpolated' model");
109 void registerOptionsAndFlags_(
const String& file_formats,
const bool add_reference =
false)
111 registerInputFileList_(
"in",
"<files>",
StringList(),
"Input files separated by blanks (all must have the same file type)",
true);
112 setValidFormats_(
"in", ListUtils::create<String>(file_formats));
113 registerOutputFileList_(
"out",
"<files>",
StringList(),
"Output files separated by blanks. Either 'out' or 'trafo_out' has to be provided. They can be used together.",
false);
114 setValidFormats_(
"out", ListUtils::create<String>(file_formats));
115 registerOutputFileList_(
"trafo_out",
"<files>",
StringList(),
"Transformation output files separated by blanks. Either 'out' or 'trafo_out' has to be provided. They can be used together.",
false);
116 setValidFormats_(
"trafo_out", ListUtils::create<String>(
"trafoXML"));
120 registerTOPPSubsection_(
"reference",
"Options to define a reference file (use either 'file' or 'index', not both; if neither is given 'index' is used).");
121 registerInputFile_(
"reference:file",
"<file>",
"",
"File to use as reference (same file format as input files required)",
false);
122 setValidFormats_(
"reference:file", ListUtils::create<String>(file_formats));
123 registerIntOption_(
"reference:index",
"<number>", 0,
"Use one of the input files as reference ('1' for the first file, etc.).\nIf '0', no explicit reference is set - the algorithm will select a reference.",
false);
124 setMinInt_(
"reference:index", 0);
129 void handleReference_(MapAlignmentAlgorithm* alignment)
136 Size reference_index = getIntOption_(
"reference:index");
137 String reference_file = getStringOption_(
"reference:file");
138 if (reference_index > getStringList_(
"in").size())
140 throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"'reference:index' must not be higher than the number of input files");
142 if (reference_index && !reference_file.empty())
144 throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"'reference:index' and 'reference:file' cannot be used together");
148 alignment->setReference(reference_index, reference_file);
151 ExitCodes initialize_(MapAlignmentAlgorithm* alignment,
bool check_ref =
false)
158 StringList trafos = getStringList_(
"trafo_out");
164 if (outs.empty() && trafos.empty())
166 writeLog_(
"Error: Either data output or transformation output files have to be provided!");
167 return ILLEGAL_PARAMETERS;
170 if (!outs.empty() && (ins.size() != outs.size()))
172 writeLog_(
"Error: The number of input and output files has to be equal!");
173 return ILLEGAL_PARAMETERS;
175 if (!trafos.empty() && (ins.size() != trafos.size()))
177 writeLog_(
"Error: The number of input and transformation output files has to be equal!");
178 return ILLEGAL_PARAMETERS;
182 for (
Size i = 1; i < ins.size(); ++i)
186 writeLog_(
"Error: All input files have to be in the same format!");
187 return ILLEGAL_PARAMETERS;
193 Size reference_index = getIntOption_(
"reference:index");
194 String reference_file = getStringOption_(
"reference:file");
195 if (reference_index > getStringList_(
"in").size())
197 throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"'reference:index' must not be higher than the number of input files");
199 if (reference_index && !reference_file.empty())
201 throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"'reference:index' and 'reference:file' cannot be used together");
205 if (!reference_file.empty())
209 writeLog_(
"Error: Reference file has not the same format as other input files!");
210 return ILLEGAL_PARAMETERS;
218 Param alignment_param = getParam_().copy(
"algorithm:",
true);
220 writeDebug_(
"Used alignment parameters", alignment_param, 3);
221 alignment->setParameters(alignment_param);
222 alignment->setLogType(log_type_);
228 ExitCodes commonMain_(MapAlignmentAlgorithm* alignment)
230 ExitCodes ret = initialize_(alignment);
231 if (ret != EXECUTION_OK)
return ret;
233 ProgressLogger progresslogger;
234 progresslogger.setLogType(log_type_);
239 StringList trafos = getStringList_(
"trafo_out");
240 Param model_params = getParam_().copy(
"model:",
true);
241 String model_type = model_params.getValue(
"type");
242 model_params = model_params.copy(model_type +
":",
true);
244 std::vector<TransformationDescription> transformations;
252 std::vector<MSExperiment<> > peak_maps(ins.size());
254 f.setLogType(log_type_);
255 for (
Size i = 0; i < ins.size(); ++i)
257 f.load(ins[i], peak_maps[i]);
263 alignment->alignPeakMaps(peak_maps, transformations);
265 catch (Exception::NotImplemented&)
267 writeLog_(
"Error: The algorithm '" + alignment->getName() +
"' cannot be used for peak data!");
268 return INTERNAL_ERROR;
270 if (model_type !=
"none")
272 alignment->fitModel(model_type, model_params, transformations);
277 progresslogger.startProgress(0, outs.size(),
"writing output files");
278 for (
Size i = 0; i < outs.size(); ++i)
280 progresslogger.setProgress(i);
285 f.store(outs[i], peak_maps[i]);
287 progresslogger.endProgress();
295 std::vector<std::vector<Peak2D> > feat_maps(ins.size());
298 progresslogger.startProgress(0, ins.size(),
"loading input files");
299 for (
Size i = 0; i < ins.size(); ++i)
301 progresslogger.setProgress(i);
302 FeatureMap feature_map;
303 f.load(ins[i], feature_map);
304 feat_maps[i].resize(feature_map.size());
306 FeatureMap::const_iterator it = feature_map.begin();
307 std::vector<Peak2D>::iterator c_it = feat_maps[i].begin();
308 for (; it != feature_map.end(); ++it, ++c_it)
310 *c_it =
reinterpret_cast<const Peak2D&
>(*it);
313 progresslogger.endProgress();
318 alignment->alignCompactFeatureMaps(feat_maps, transformations);
320 catch (Exception::NotImplemented&)
322 writeLog_(
"Error: The algorithm '" + alignment->getName() +
"' cannot be used for feature data!");
323 return INTERNAL_ERROR;
325 if (model_type !=
"none")
327 alignment->fitModel(model_type, model_params, transformations);
332 progresslogger.startProgress(0, outs.size(),
"writing output files");
333 for (
Size i = 0; i < outs.size(); ++i)
335 progresslogger.setProgress(i);
337 FeatureMap feature_map;
338 f.load(ins[i], feature_map);
345 f.store(outs[i], feature_map);
347 progresslogger.endProgress();
355 std::vector<ConsensusMap> cons_maps(ins.size());
358 progresslogger.startProgress(0, ins.size(),
"loading input files");
359 for (
Size i = 0; i < ins.size(); ++i)
361 progresslogger.setProgress(i);
362 f.load(ins[i], cons_maps[i]);
364 progresslogger.endProgress();
369 alignment->alignConsensusMaps(cons_maps, transformations);
371 catch (Exception::NotImplemented&)
373 writeLog_(
"Error: The algorithm '" + alignment->getName() +
"' cannot be used for consensus feature data!");
374 return INTERNAL_ERROR;
376 if (model_type !=
"none")
378 alignment->fitModel(model_type, model_params, transformations);
383 progresslogger.startProgress(0, outs.size(),
"writing output files");
384 for (
Size i = 0; i < outs.size(); ++i)
386 progresslogger.setProgress(i);
391 f.store(outs[i], cons_maps[i]);
393 progresslogger.endProgress();
401 std::vector<std::vector<ProteinIdentification> > protein_ids_vec(ins.size());
402 std::vector<std::vector<PeptideIdentification> > peptide_ids_vec(ins.size());
407 progresslogger.startProgress(0, ins.size(),
"loading input files");
408 for (
Size i = 0; i < ins.size(); ++i)
410 progresslogger.setProgress(i);
411 f.load(ins[i], protein_ids_vec[i], peptide_ids_vec[i]);
413 progresslogger.endProgress();
418 alignment->alignPeptideIdentifications(peptide_ids_vec, transformations);
420 catch (Exception::NotImplemented&)
422 writeLog_(
"Error: The algorithm '" + alignment->getName() +
"' cannot be used for peptide data!");
423 return INTERNAL_ERROR;
425 if (model_type !=
"none")
427 alignment->fitModel(model_type, model_params, transformations);
433 progresslogger.startProgress(0, outs.size(),
"writing output files");
434 for (
Size i = 0; i < outs.size(); ++i)
436 progresslogger.setProgress(i);
437 f.store(outs[i], protein_ids_vec[i], peptide_ids_vec[i]);
439 progresslogger.endProgress();
445 return ILLEGAL_PARAMETERS;
450 for (
Size i = 0; i < transformations.size(); ++i)
452 TransformationXMLFile().store(trafos[i], transformations[i]);
465 #endif // OPENMS_APPLICATIONS_MAPALIGNERBASE_H Type
Actual file types enum.
Definition: FileTypes.h:59
static FileTypes::Type getType(const String &filename)
Tries to determine the file type (by name or content)
OpenMS identification format (.idXML)
Definition: FileTypes.h:67
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
OpenMS consensus map format (.consensusXML)
Definition: FileTypes.h:68
Retention time alignment of different maps.
Definition: DataProcessing.h:68
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:74
OpenMS feature file (.featureXML)
Definition: FileTypes.h:66
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:121
static bool contains(const std::vector< T > &container, const E &elem)
Checks whether the element elem is contained in the given container.
Definition: ListUtils.h:150
MzML file (.mzML)
Definition: FileTypes.h:73