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

Method parseOneTableFile_

src/openms/source/FORMAT/ExperimentalDesignFile.cpp:139–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137 }
138
139 ExperimentalDesign ExperimentalDesignFile::parseOneTableFile_(const TextFile& text_file, const String& tsv_file, bool require_spectra_file)
140 {
141 ExperimentalDesign::MSFileSection msfile_section;
142 bool has_sample(false);
143 bool has_label(false);
144
145 /// Content of the sample section (vector of rows with column contents as strings)
146 std::vector< std::vector < String > > sample_content_;
147 /// Sample name to sample (row) index
148 std::map< unsigned, Size > sample_sample_to_rowindex_;
149 /// Inside each row, the value for a column can be accessed by name with this map
150 std::map< String, Size > sample_columnname_to_columnindex_;
151
152 /// Maps the column header string to the column index for
153 /// the file section
154 std::map <String, Size> fs_column_header_to_index;
155
156 /// Maps the sample name to all values of sample-related columns
157 std::map <String, std::vector<String>> sample_content_map;
158
159 /// Maps the sample name to its index (i.e., the order how it gets added to the sample section)
160 std::map<String, Size> samplename_to_index;
161 enum ParseState { RUN_HEADER, RUN_CONTENT };
162
163 ParseState state(RUN_HEADER);
164 Size n_col = 0;
165
166 for (String s : text_file)
167 {
168 const String line(s.trim());
169
170 if (line.hasPrefix("#") || line.empty()) { continue; }
171
172 // Now split the line into individual cells
173 StringList cells;
174 line.split("\t", cells);
175
176 // Trim whitespace from all cells (so , foo , and ,foo, is the same)
177 std::transform(cells.begin(), cells.end(), cells.begin(),
178 [](String cell) -> String { return cell.trim(); });
179
180 if (state == RUN_HEADER)
181 {
182 state = RUN_CONTENT;
183 parseHeader_(
184 cells,
185 tsv_file,
186 fs_column_header_to_index,
187 {"Fraction_Group", "Fraction", "Spectra_Filepath"},
188 {"Label", "Sample"}, true
189 );
190 has_label = fs_column_header_to_index.find("Label") != fs_column_header_to_index.end();
191 has_sample = fs_column_header_to_index.find("Sample") != fs_column_header_to_index.end();
192
193 if (!has_label) // add label column to end of header
194 {
195 size_t hs = fs_column_header_to_index.size();
196 fs_column_header_to_index["Label"] = hs;

Callers

nothing calls this directly

Calls 11

transformFunction · 0.85
findSpectraFileFunction · 0.85
toIntMethod · 0.80
hasPrefixMethod · 0.45
emptyMethod · 0.45
splitMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected