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

Method getChargeRange

src/openms/source/METADATA/ProteinIdentification.cpp:188–247  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

186 }
187
188 std::pair<int,int> ProteinIdentification::SearchParameters::getChargeRange() const
189 {
190 std::pair<int,int> result{0,0};
191
192 try // is there only one number (min = max)?
193 {
194 result.first = charges.toInt();
195 result.second = result.first;
196 }
197 catch (Exception::ConversionError&) // nope, something else
198 {
199 if (charges.hasSubstring(',')) // it's probably a list
200 {
201 IntList chgs = ListUtils::create<Int>(charges);
202 auto minmax = minmax_element(chgs.begin(), chgs.end());
203 result.first = *minmax.first;
204 result.second = *minmax.second;
205 }
206 else if (charges.hasSubstring(':')) // it's probably a range
207 {
208 StringList chgs;
209 charges.split(':', chgs);
210 if (chgs.size() > 2)
211 {
212 throw OpenMS::Exception::MissingInformation(
213 __FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
214 "Charge string in SearchParameters not parseable.");
215 }
216 result.first = getChargeValue_(chgs[0]);
217 result.second = getChargeValue_(chgs[1]);
218 }
219 else
220 {
221 size_t pos = charges.find('-', 0);
222 std::vector<size_t> minus_positions;
223 while (pos != string::npos)
224 {
225 minus_positions.push_back(pos);
226 pos = charges.find('-', pos + 1);
227 }
228 if (!minus_positions.empty() && minus_positions.size() <= 3) // it's probably a range with '-'
229 {
230 Size split_pos(0);
231 if (minus_positions.size() <= 1) // split at first minus
232 {
233 split_pos = minus_positions[0];
234 }
235 else
236 {
237 split_pos = minus_positions[1];
238 }
239 String first = charges.substr(0, split_pos);
240 String second = charges.substr(split_pos + 1, string::npos);
241 result.first = getChargeValue_(first);
242 result.second = getChargeValue_(second);
243 }
244 }
245 }

Calls 10

toIntMethod · 0.80
hasSubstringMethod · 0.80
substrMethod · 0.80
beginMethod · 0.45
endMethod · 0.45
splitMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
push_backMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected