| 171 | } |
| 172 | |
| 173 | void InspectInfile::handlePTMs(const String& modification_line, const String& modifications_filename, const bool monoisotopic) |
| 174 | { |
| 175 | PTMname_residues_mass_type_.clear(); |
| 176 | // to store the information about modifications from the ptm xml file |
| 177 | std::map<String, pair<String, String> > ptm_informations; |
| 178 | if (!modification_line.empty()) // if modifications are used look whether whether composition and residues (and type and name) is given, the name (type) is used (then the modifications file is needed) or only the mass and residues (and type and name) is given |
| 179 | { |
| 180 | vector<String> modifications, mod_parts; |
| 181 | modification_line.split(':', modifications); // get the single modifications |
| 182 | if (modifications.empty()) |
| 183 | { |
| 184 | modifications.push_back(modification_line); |
| 185 | } |
| 186 | // to get masses from a formula |
| 187 | EmpiricalFormula add_formula, substract_formula; |
| 188 | |
| 189 | String types = "OPT#FIX#"; |
| 190 | String name, residues, mass, type; |
| 191 | |
| 192 | // 0 - mass; 1 - composition; 2 - ptm name |
| 193 | Int mass_or_composition_or_name(-1); |
| 194 | |
| 195 | for (vector<String>::const_iterator mod_i = modifications.begin(); mod_i != modifications.end(); ++mod_i) |
| 196 | { |
| 197 | if (mod_i->empty()) |
| 198 | { |
| 199 | continue; |
| 200 | } |
| 201 | // clear the formulae |
| 202 | add_formula = substract_formula = EmpiricalFormula(); |
| 203 | name = residues = mass = type = ""; |
| 204 | |
| 205 | // get the single parts of the modification string |
| 206 | mod_i->split(',', mod_parts); |
| 207 | if (mod_parts.empty()) |
| 208 | mod_parts.push_back(*mod_i); |
| 209 | mass_or_composition_or_name = -1; |
| 210 | |
| 211 | // check whether the first part is a mass, composition or name |
| 212 | |
| 213 | // check whether it is a mass |
| 214 | try |
| 215 | { |
| 216 | mass = mod_parts.front(); |
| 217 | // to check whether the first part is a mass, it is converted into a float and then back into a string and compared to the given string |
| 218 | // remove + signs because they don't appear in a float |
| 219 | if (mass.hasPrefix("+")) |
| 220 | { |
| 221 | mass.erase(0, 1); |
| 222 | } |
| 223 | if (mass.hasSuffix("+")) |
| 224 | { |
| 225 | mass.erase(mass.length() - 1, 1); |
| 226 | } |
| 227 | if (mass.hasSuffix("-")) // a - sign at the end will not be converted |
| 228 | { |
| 229 | mass.erase(mass.length() - 1, 1); |
| 230 | mass.insert(0, "-"); |