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

Method store

src/openms/source/FORMAT/MSPGenericFile.cpp:168–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

166 }
167
168 void MSPGenericFile::store(const String& filename, const MSExperiment& library) const
169 {
170 std::ofstream output_file(filename.c_str());
171
172 // checking if file is writable
173 if (!File::writable(filename))
174 {
175 throw Exception::FileNotWritable(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, filename);
176 }
177
178 for (const auto& spectrum : library.getSpectra())
179 {
180 if (spectrum.getName().empty())
181 {
182 throw Exception::MissingInformation(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
183 "The current spectrum misses the Name information.");
184 }
185 if (spectrum.size())// we will not store spectrum with no peaks
186 {
187 output_file << "Name: " << spectrum.getName() << '\n';
188 output_file << "Retention Time: " << spectrum.getRT() << '\n';
189 const auto& synonyms = spectrum.getMetaValue("Synon");
190 if (synonyms.valueType() == OpenMS::DataValue::DataType::STRING_VALUE)
191 {
192 StringList list;
193 synonyms.toString().split(synonyms_separator_, list);
194 for (const auto& syn : list)
195 {
196 output_file << "Synon: " << syn << '\n';
197 }
198 }
199 if (spectrum.metaValueExists("CAS#") && spectrum.metaValueExists("NIST#"))
200 {
201 output_file << "CAS#: " << spectrum.getMetaValue("CAS#") << "; NIST#: " << spectrum.getMetaValue("NIST#") << '\n';
202 }
203 // Other metadata
204 static const std::array<std::string, 4> ignore_metadata = {"Synon", "CAS#", "NIST#", "Num Peaks"};
205 std::vector<String> keys;
206 spectrum.getKeys(keys);
207 for (const auto& key : keys)
208 {
209 const auto& value = spectrum.getMetaValue(key);
210 if (std::find(ignore_metadata.begin(), ignore_metadata.end(), key) == ignore_metadata.end())
211 {
212 output_file << key << ": " << value << '\n';
213 }
214 }
215 // Peaks
216 output_file << "Num Peaks: " << spectrum.size() << '\n';
217 int peak_counter = 0;
218 for (const auto& peak : spectrum)
219 {
220 output_file << peak.getPos() << ":" << peak.getIntensity() << " ";
221 if ((++peak_counter % 5) == 0)
222 {
223 output_file << '\n';
224 }
225 }

Callers

nothing calls this directly

Calls 13

getMetaValueMethod · 0.80
metaValueExistsMethod · 0.80
emptyMethod · 0.45
getNameMethod · 0.45
sizeMethod · 0.45
getRTMethod · 0.45
splitMethod · 0.45
toStringMethod · 0.45
getKeysMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
getIntensityMethod · 0.45

Tested by

no test coverage detected