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

Method parseTwoTableFile_

src/openms/source/FORMAT/ExperimentalDesignFile.cpp:303–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

301 }
302
303 ExperimentalDesign ExperimentalDesignFile::parseTwoTableFile_(const TextFile& text_file, const String& tsv_file, bool require_spectra_file)
304 {
305 ExperimentalDesign::MSFileSection msfile_section;
306 bool has_sample(false);
307 bool has_label(false);
308
309 // Attributes of the sample section
310 std::vector< std::vector < String > > sample_content_;
311 std::map< String, Size > sample_sample_to_rowindex_;
312 std::map< String, Size > sample_columnname_to_columnindex_;
313
314 // Maps the column header string to the column index for
315 // the file section
316 std::map <String, Size> fs_column_header_to_index;
317
318 unsigned line_number(0);
319
320 enum ParseState { RUN_HEADER, RUN_CONTENT, SAMPLE_HEADER, SAMPLE_CONTENT };
321
322 ParseState state(RUN_HEADER);
323 Size n_col = 0;
324
325 for (String s : text_file)
326 {
327 // skip empty lines (except in state RUN_CONTENT, where the sample table is read)
328 const String line(s.trim());
329 // also skip comment lines
330 if (line.hasPrefix("#") || (line.empty() && state != RUN_CONTENT))
331 {
332 continue;
333 }
334
335 // Now split the line into individual cells
336 StringList cells;
337 line.split("\t", cells);
338
339 // Trim whitespace from all cells (so , foo , and ,foo, is the same)
340 std::transform(cells.begin(), cells.end(), cells.begin(),
341 [](String cell) -> String { return cell.trim(); });
342
343 if (state == RUN_HEADER)
344 {
345 state = RUN_CONTENT;
346 parseHeader_(
347 cells,
348 tsv_file,
349 fs_column_header_to_index,
350 {"Fraction_Group", "Fraction", "Spectra_Filepath"},
351 {"Label", "Sample"}, false
352 );
353 has_label = fs_column_header_to_index.find("Label") != fs_column_header_to_index.end();
354 has_sample = fs_column_header_to_index.find("Sample") != fs_column_header_to_index.end();
355
356 n_col = fs_column_header_to_index.size();
357 }
358 // End of file section lines, empty line separates file and sample section
359 else if (state == RUN_CONTENT && line.empty())
360 {

Callers

nothing calls this directly

Calls 13

transformFunction · 0.85
findSpectraFileFunction · 0.85
toIntMethod · 0.80
atMethod · 0.80
StringClass · 0.50
hasPrefixMethod · 0.45
emptyMethod · 0.45
splitMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected