35 #ifndef OPENMS_APPLICATIONS_MAPALIGNERBASE_H
36 #define OPENMS_APPLICATIONS_MAPALIGNERBASE_H
51 using namespace OpenMS;
67 class TOPPMapAlignerBase :
72 TOPPMapAlignerBase(
String name,
String description,
bool official =
true) :
73 TOPPBase(name, description, official)
78 static Param getModelDefaults(
const String & default_model)
81 params.
setValue(
"type", default_model,
"Type of model");
84 if (!model_types.
contains(default_model))
86 model_types.insert(model_types.begin(), default_model);
92 params.
insert(
"linear:", model_params);
95 params.
insert(
"b_spline:", model_params);
100 model_params.
getEntry(
"interpolation_type");
103 interpolation_types.end(),
"polynomial");
104 interpolation_types.erase(pos);
105 model_params.
setValidStrings(
"interpolation_type", interpolation_types);
106 params.
insert(
"interpolated:", model_params);
108 "Parameters for 'interpolated' model");
113 void registerOptionsAndFlags_(
const String & file_formats,
const bool add_reference =
false)
115 registerInputFileList_(
"in",
"<files>",
StringList(),
"Input files separated by blanks (all must have the same file type)",
true);
117 registerOutputFileList_(
"out",
"<files>",
StringList(),
"Output files separated by blanks. Either 'out' or 'trafo_out' has to be provided. They can be used together.",
false);
119 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);
124 registerTOPPSubsection_(
"reference",
"Options to define a reference file (use either 'file' or 'index', not both; if neither is given 'index' is used).");
125 registerInputFile_(
"reference:file",
"<file>",
"",
"File to use as reference (same file format as input files required)",
false);
127 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);
128 setMinInt_(
"reference:index", 0);
140 Size reference_index = getIntOption_(
"reference:index");
141 String reference_file = getStringOption_(
"reference:file");
142 if (reference_index > getStringList_(
"in").size())
144 throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"'reference:index' must not be higher than the number of input files");
146 if (reference_index && !reference_file.empty())
148 throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"'reference:index' and 'reference:file' cannot be used together");
152 alignment->
setReference(reference_index, reference_file);
162 StringList trafos = getStringList_(
"trafo_out");
168 if (outs.empty() && trafos.empty())
170 writeLog_(
"Error: Either data output or transformation output files have to be provided!");
171 return ILLEGAL_PARAMETERS;
174 if (!outs.empty() && (ins.size() != outs.size()))
176 writeLog_(
"Error: The number of input and output files has to be equal!");
177 return ILLEGAL_PARAMETERS;
179 if (!trafos.empty() && (ins.size() != trafos.size()))
181 writeLog_(
"Error: The number of input and transformation output files has to be equal!");
182 return ILLEGAL_PARAMETERS;
186 for (
Size i = 1; i < ins.size(); ++i)
190 writeLog_(
"Error: All input files have to be in the same format!");
191 return ILLEGAL_PARAMETERS;
197 Size reference_index = getIntOption_(
"reference:index");
198 String reference_file = getStringOption_(
"reference:file");
199 if (reference_index > getStringList_(
"in").size())
201 throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"'reference:index' must not be higher than the number of input files");
203 if (reference_index && !reference_file.empty())
205 throw Exception::InvalidParameter(__FILE__, __LINE__, __PRETTY_FUNCTION__,
"'reference:index' and 'reference:file' cannot be used together");
209 if (!reference_file.empty())
213 writeLog_(
"Error: Reference file has not the same format as other input files!");
214 return ILLEGAL_PARAMETERS;
222 Param alignment_param = getParam_().
copy(
"algorithm:",
true);
224 writeDebug_(
"Used alignment parameters", alignment_param, 3);
234 ExitCodes ret = initialize_(alignment);
235 if (ret != EXECUTION_OK)
return ret;
243 StringList trafos = getStringList_(
"trafo_out");
244 Param model_params = getParam_().
copy(
"model:",
true);
246 model_params = model_params.
copy(model_type +
":",
true);
248 std::vector<TransformationDescription> transformations;
256 std::vector<MSExperiment<> > peak_maps(ins.size());
258 f.setLogType(log_type_);
259 for (
Size i = 0; i < ins.size(); ++i)
261 f.load(ins[i], peak_maps[i]);
271 writeLog_(
"Error: The algorithm '" + alignment->
getName() +
"' cannot be used for peak data!");
272 return INTERNAL_ERROR;
274 if (model_type !=
"none")
276 alignment->
fitModel(model_type, model_params, transformations);
281 progresslogger.
startProgress(0, outs.size(),
"writing output files");
282 for (
Size i = 0; i < outs.size(); ++i)
289 f.store(outs[i], peak_maps[i]);
299 std::vector<std::vector<Peak2D> > feat_maps(ins.size());
302 progresslogger.
startProgress(0, ins.size(),
"loading input files");
303 for (
Size i = 0; i < ins.size(); ++i)
307 f.load(ins[i], feature_map);
308 feat_maps[i].resize(feature_map.size());
311 std::vector<Peak2D>::iterator c_it = feat_maps[i].begin();
312 for (; it != feature_map.end(); ++it, ++c_it)
314 *c_it =
reinterpret_cast<const Peak2D &
>(*it);
326 writeLog_(
"Error: The algorithm '" + alignment->
getName() +
"' cannot be used for feature data!");
327 return INTERNAL_ERROR;
329 if (model_type !=
"none")
331 alignment->
fitModel(model_type, model_params, transformations);
336 progresslogger.
startProgress(0, outs.size(),
"writing output files");
337 for (
Size i = 0; i < outs.size(); ++i)
342 f.load(ins[i], feature_map);
349 f.store(outs[i], feature_map);
359 std::vector<ConsensusMap> cons_maps(ins.size());
362 progresslogger.
startProgress(0, ins.size(),
"loading input files");
363 for (
Size i = 0; i < ins.size(); ++i)
366 f.load(ins[i], cons_maps[i]);
377 writeLog_(
"Error: The algorithm '" + alignment->
getName() +
"' cannot be used for consensus feature data!");
378 return INTERNAL_ERROR;
380 if (model_type !=
"none")
382 alignment->
fitModel(model_type, model_params, transformations);
387 progresslogger.
startProgress(0, outs.size(),
"writing output files");
388 for (
Size i = 0; i < outs.size(); ++i)
395 f.store(outs[i], cons_maps[i]);
405 std::vector<std::vector<ProteinIdentification> > protein_ids_vec(ins.size());
406 std::vector<std::vector<PeptideIdentification> > peptide_ids_vec(ins.size());
411 progresslogger.
startProgress(0, ins.size(),
"loading input files");
412 for (
Size i = 0; i < ins.size(); ++i)
415 f.load(ins[i], protein_ids_vec[i], peptide_ids_vec[i]);
426 writeLog_(
"Error: The algorithm '" + alignment->
getName() +
"' cannot be used for peptide data!");
427 return INTERNAL_ERROR;
429 if (model_type !=
"none")
431 alignment->
fitModel(model_type, model_params, transformations);
437 progresslogger.
startProgress(0, outs.size(),
"writing output files");
438 for (
Size i = 0; i < outs.size(); ++i)
441 f.store(outs[i], protein_ids_vec[i], peptide_ids_vec[i]);
449 return ILLEGAL_PARAMETERS;
454 for (
Size i = 0; i < transformations.size(); ++i)
467 #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)
const ParamEntry & getEntry(const String &key) const
Returns the whole parameter entry.
void setValue(const String &key, const DataValue &value, const String &description="", const StringList &tags=StringList())
Sets a value.
A more convenient string class.
Definition: String.h:56
void insert(const String &prefix, const Param ¶m)
A 2-dimensional raw data point or peak.
Definition: Peak2D.h:55
bool contains(const String &s) const
Returns if a string is contained in the list.
OpenMS identification format (.idXML)
Definition: FileTypes.h:67
Base class for all map-alignment algorithms.
Definition: MapAlignmentAlgorithm.h:58
Parameter entry used to store the actual information inside of a Param entry.
Definition: Param.h:74
void setSectionDescription(const String &key, const String &description)
Sets a description for an existing section.
void setParameters(const Param ¶m)
Sets the parameters.
Base class for TOPP applications.
Definition: TOPPBase.h:130
OpenMS consensus map format (.consensusXML)
Definition: FileTypes.h:68
Param copy(const String &prefix, bool remove_prefix=false) const
Returns a new Param object containing all entries that start with prefix.
File adapter for MzML files.
Definition: MzMLFile.h:58
void endProgress() const
Ends the progress display.
virtual void alignConsensusMaps(std::vector< ConsensusMap > &, std::vector< TransformationDescription > &)
Aligns consensus maps.
virtual void alignPeakMaps(std::vector< MSExperiment<> > &, std::vector< TransformationDescription > &)
Aligns peak maps.
const DataValue & getValue(const String &key) const
Returns a value of a parameter.
const String & getName() const
Non-mutable access to the name.
This class provides Input functionality for ConsensusMaps and Output functionality for alignments and...
Definition: ConsensusXMLFile.h:59
iterator Iterator
Mutable iterator.
Definition: StringList.h:65
static StringList create(const String &list, const char splitter= ',')
Returns a list that is created by splitting the given (comma-separated) string (String are not trimme...
Exception indicating that an invalid parameter was handed over to an algorithm.
Definition: Exception.h:348
virtual void alignCompactFeatureMaps(std::vector< std::vector< Peak2D > > &, std::vector< TransformationDescription > &)
Aligns vectors of 2D peaks (memory efficient version of FeatureMap)
Retention time alignment of different maps.
Definition: DataProcessing.h:68
void setValidStrings(const String &key, const std::vector< String > &strings)
Sets the valid strings for the parameter key.
OpenMS feature file (.featureXML)
Definition: FileTypes.h:66
Management and storage of parameters / INI files.
Definition: Param.h:69
This class provides Input/Output functionality for feature maps.
Definition: FeatureXMLFile.h:59
String list.
Definition: StringList.h:56
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
Base class for all classes that want to report their progess.
Definition: ProgressLogger.h:56
void startProgress(SignedSize begin, SignedSize end, const String &label) const
Initializes the progress display.
std::vector< String > valid_strings
Default: empty.
Definition: Param.h:104
void setProgress(SignedSize value) const
Sets the current progress.
static void fitModel(const String &model_type, const Param ¶ms, std::vector< TransformationDescription > &trafos)
Fits a model with given parameters to the transformations.
virtual void setReference(Size reference_index=0, const String &reference_file="")
Defines a reference for the alignment.
virtual void alignPeptideIdentifications(std::vector< std::vector< PeptideIdentification > > &, std::vector< TransformationDescription > &)
Aligns peptide identifications.
Not implemented exception.
Definition: Exception.h:437
MzML file (.mzML)
Definition: FileTypes.h:73
void setLogType(LogType type) const
Sets the progress log that should be used. The default type is NONE!
Used to load and store idXML files.
Definition: IdXMLFile.h:63