46 static Param getModelDefaults(
const String& default_model)
49 params.setValue(
"type", default_model,
"Type of model");
51 std::vector<std::string> model_types = {
"linear",
"b_spline",
"lowess",
"interpolated"};
52 if (!ListUtils::contains(model_types, default_model))
54 model_types.insert(model_types.begin(), default_model);
56 params.setValidStrings(
"type", model_types);
59 TransformationModelLinear::getDefaultParameters(model_params);
60 params.insert(
"linear:", model_params);
61 params.setSectionDescription(
"linear",
"Parameters for 'linear' model");
63 TransformationModelBSpline::getDefaultParameters(model_params);
64 params.insert(
"b_spline:", model_params);
65 params.setSectionDescription(
"b_spline",
"Parameters for 'b_spline' model");
67 TransformationModelLowess::getDefaultParameters(model_params);
68 params.insert(
"lowess:", model_params);
69 params.setSectionDescription(
"lowess",
"Parameters for 'lowess' model");
71 TransformationModelInterpolated::getDefaultParameters(model_params);
72 params.insert(
"interpolated:", model_params);
73 params.setSectionDescription(
"interpolated",
74 "Parameters for 'interpolated' model");
80class TOPPMapAlignerBase :
81 public TOPPBase,
public MapAlignerBase
85 TOPPMapAlignerBase(String name, String description,
bool official =
true) :
86 TOPPBase(name, description, official), ref_params_(REF_NONE)
96 enum ReferenceParameterKind { REF_NONE, REF_RESTRICTED, REF_FLEXIBLE }
99 void registerOptionsAndFlagsMapAligners_(
const String& file_formats,
100 enum ReferenceParameterKind ref_params)
102 registerInputFileList_(
"in",
"<files>",
StringList(),
"Input files to align (all must have the same file type)",
true);
103 setValidFormats_(
"in", ListUtils::create<String>(file_formats));
104 registerOutputFileList_(
"out",
"<files>",
StringList(),
"Output files (same file type as 'in'). This option or 'trafo_out' has to be provided; they can be used together.",
false);
105 setValidFormats_(
"out", ListUtils::create<String>(file_formats));
106 registerOutputFileList_(
"trafo_out",
"<files>",
StringList(),
"Transformation output files. This option or 'out' has to be provided; they can be used together.",
false);
107 setValidFormats_(
"trafo_out", ListUtils::create<String>(
"trafoXML"));
110 registerInputFileList_(
"in_spectra_files",
"<files>",
StringList(),
"Optional input spectra files (mzML) that will be transformed along with the alignment. Size must match the number of input files.",
false);
111 setValidFormats_(
"in_spectra_files", ListUtils::create<String>(
"mzML"));
112 registerOutputFileList_(
"out_spectra_files",
"<files>",
StringList(),
"Optional output spectra files (mzML) corresponding to transformed in_spectra_files. Size must match in_spectra_files.",
false);
113 setValidFormats_(
"out_spectra_files", ListUtils::create<String>(
"mzML"));
115 if (ref_params != REF_NONE)
117 registerTOPPSubsection_(
"reference",
"Options to define a reference file (use either 'file' or 'index', not both)");
118 String description =
"File to use as reference";
119 if (ref_params == REF_RESTRICTED)
121 description +=
" (same file format as input files required)";
123 registerInputFile_(
"reference:file",
"<file>",
"", description,
false);
124 setValidFormats_(
"reference:file", ListUtils::create<String>(file_formats));
125 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);
126 setMinInt_(
"reference:index", 0);
128 ref_params_ = ref_params;
131 ExitCodes checkParameters_()
138 StringList trafos = getStringList_(
"trafo_out");
139 StringList in_spectra = getStringList_(
"in_spectra_files");
140 StringList out_spectra = getStringList_(
"out_spectra_files");
146 if (outs.empty() && trafos.empty())
148 writeLogError_(
"Error: Data output or transformation output files have to be provided (parameters 'out'/'trafo_out')");
149 return ILLEGAL_PARAMETERS;
152 if (!outs.empty() && (ins.size() != outs.size()))
154 writeLogError_(
"Error: The number of data input and output files has to be equal (parameters 'in'/'out')");
155 return ILLEGAL_PARAMETERS;
157 if (!trafos.empty() && (ins.size() != trafos.size()))
159 writeLogError_(
"Error: The number of data input and transformation output files has to be equal (parameters 'in'/'trafo_out')");
160 return ILLEGAL_PARAMETERS;
163 FileTypes::Type in_type = FileHandler::getType(ins[0]);
164 for (Size i = 1; i < ins.size(); ++i)
166 if (FileHandler::getType(ins[i]) != in_type)
168 writeLogError_(
"Error: All input files (parameter 'in') must have the same format!");
169 return ILLEGAL_PARAMETERS;
174 if (!in_spectra.empty() || !out_spectra.empty())
176 if (in_spectra.size() != ins.size())
178 writeLogError_(
"Error: The number of spectra input files has to be equal to the number of main input files (parameters 'in_spectra_files'/'in')");
179 return ILLEGAL_PARAMETERS;
181 if (out_spectra.size() != in_spectra.size())
183 writeLogError_(
"Error: The number of spectra input and output files has to be equal (parameters 'in_spectra_files'/'out_spectra_files')");
184 return ILLEGAL_PARAMETERS;
188 if (ref_params_ != REF_NONE)
190 Size reference_index = getIntOption_(
"reference:index");
191 String reference_file = getStringOption_(
"reference:file");
192 if (reference_index > ins.size())
194 writeLogError_(
"Error: Value of parameter 'reference:index' must not be higher than the number of input files");
195 return ILLEGAL_PARAMETERS;
197 if (reference_index && !reference_file.empty())
199 writeLogError_(
"Error: Parameters 'reference:index' and 'reference:file' cannot be used together");
200 return ILLEGAL_PARAMETERS;
203 if ((ref_params_ == REF_RESTRICTED) && !reference_file.empty() &&
204 (FileHandler::getType(reference_file) != in_type))
206 writeLogError_(
"Error: Reference file must have the same format as other input files (parameters 'reference:file'/'in')");
207 return ILLEGAL_PARAMETERS;
214 void transformSpectraFiles_(
const StringList& in_spectra_files,
215 const StringList& out_spectra_files,
216 const std::vector<TransformationDescription>& transformations,
217 bool store_original_rt)
219 if (in_spectra_files.empty() || out_spectra_files.empty())
225 "Number of spectra files must match number of transformations");
227 "Number of input and output spectra files must match");
229 ProgressLogger progresslogger;
230 progresslogger.setLogType(log_type_);
231 progresslogger.startProgress(0, in_spectra_files.size(),
"transforming spectra files");
233 for (Size i = 0; i < in_spectra_files.size(); ++i)
235 progresslogger.setProgress(i);
238 FileHandler().loadExperiment(in_spectra_files[i], exp, {FileTypes::MZML}, log_type_);
240 MapAlignmentTransformer::transformRetentionTimes(exp, transformations[i], store_original_rt);
242 addDataProcessing_(exp, getProcessingInfo_(DataProcessing::ALIGNMENT));
243 FileHandler().storeExperiment(out_spectra_files[i], exp, {FileTypes::MZML}, log_type_);
246 progresslogger.endProgress();
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition Types.h:97
#define OPENMS_PRECONDITION(condition, message)
Precondition macro.
Definition openms/include/OpenMS/CONCEPT/Macros.h:94
std::vector< String > StringList
Vector of String.
Definition ListUtils.h:44
MSExperiment PeakMap
Two-dimensional map of raw data points or peaks.
Definition StandardTypes.h:35
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19