void Residue::setModification(const String & modification) { //modification_ = modification; ModificationsDB * mod_db = ModificationsDB::getInstance(); ResidueModification mod = mod_db->getModification(one_letter_code_, modification, ResidueModification::ANYWHERE); modification_ = mod.getId(); // update all the members if (mod.getAverageMass() != 0) { average_weight_ = mod.getAverageMass(); } if (mod.getMonoMass() != 0) { mono_weight_ = mod.getMonoMass(); } bool updated_formula(false); if (!mod.getDiffFormula().isEmpty()) { updated_formula = true; setFormula(getFormula() + mod.getDiffFormula()); } if (mod.getFormula() != "" && !updated_formula) { updated_formula = true; String formula = mod.getFormula(); formula.removeWhitespaces(); formula_ = EmpiricalFormula(formula); } if (updated_formula) { average_weight_ = formula_.getAverageWeight(); mono_weight_ = formula_.getMonoWeight(); } else { if (mod.getAverageMass() != 0) { average_weight_ = mod.getAverageMass(); } if (mod.getMonoMass() != 0) { mono_weight_ = mod.getMonoMass(); } } // neutral losses loss_formulas_.clear(); loss_names_.clear(); if (mod.hasNeutralLoss()) { loss_formulas_.push_back(mod.getNeutralLossDiffFormula()); loss_names_.push_back(mod.getNeutralLossDiffFormula().toString()); } is_modified_ = true; }
int main() { // construct a AASequence object, query a residue // and output some of its properties AASequence aas = AASequence::fromString("DECIANGER"); cout << aas[2].getName() << " " << aas[2].getFormula().toString() << " " << aas[2].getModificationName() << " " << aas[2].getMonoWeight() << endl; // find a modification in ModificationsDB // and output some of its properties // getInstance() returns a pointer to a ModsDB instance ResidueModification mod = ModificationsDB::getInstance()->getModification("Carbamidomethyl (C)"); cout << mod.getOrigin() << " " << mod.getFullId() << " " << mod.getDiffMonoMass() << " " << mod.getMonoMass() << endl; // set the modification on a residue of a peptide // and output some of its properties (the formula and mass have changed) // in this case ModificationsDB is used in the background // to relate the name of the mod to its attributes aas.setModification(2, "Carbamidomethyl (C)"); cout << aas[2].getName() << " " << aas[2].getFormula().toString() << " " << aas[2].getModificationName() << " " << aas[2].getMonoWeight() << endl; return 0; } //end of main
void MassDecompositionAlgorithm::updateMembers_() { // todo add accessor to tolerance, it is called very often in CID mode Map<char, double> aa_to_weight; set<const Residue *> residues = ResidueDB::getInstance()->getResidues((String)param_.getValue("residue_set")); for (set<const Residue *>::const_iterator it = residues.begin(); it != residues.end(); ++it) { aa_to_weight[(*it)->getOneLetterCode()[0]] = (*it)->getMonoWeight(Residue::Internal); } // now handle the modifications ModificationDefinitionsSet mod_set(param_.getValue("fixed_modifications"), param_.getValue("variable_modifications")); set<ModificationDefinition> fixed_mods = mod_set.getFixedModifications(); for (set<ModificationDefinition>::const_iterator it = fixed_mods.begin(); it != fixed_mods.end(); ++it) { const ResidueModification& mod = it->getModification(); char aa = ' '; if (mod.getOrigin() == 'X') { cerr << "MassDecompositionAlgorithm: Warning: cannot handle modification " << mod.getName() << ", because aa is ambiguous (" << mod.getOrigin() << "), ignoring modification!" << endl; continue; } else { aa = mod.getOrigin(); } if (mod.getMonoMass() != 0) { aa_to_weight[aa] = mod.getMonoMass(); } else { if (mod.getDiffMonoMass() != 0) { aa_to_weight[aa] += mod.getDiffMonoMass(); } else { cerr << "MassDecompositionAlgorithm: Warning: cannot handle modification " << mod.getName() << ", because no monoisotopic mass value was found! Ignoring modification!" << endl; continue; } } } const StringList mod_names(ListUtils::create<String>("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z")); vector<String>::const_iterator actual_mod_name = mod_names.begin(); set<ModificationDefinition> var_mods = mod_set.getVariableModifications(); for (set<ModificationDefinition>::const_iterator it = var_mods.begin(); it != var_mods.end(); ++it) { ResidueModification mod = it->getModification(); //cerr << it->getModification() << " " << mod.getOrigin() << " " << mod.getId() << " " << mod.getFullId() << " " << mod.getUniModAccession() << " " << mod.getPSIMODAccession() << endl; char aa = (*actual_mod_name)[0]; char origin_aa = ' '; ++actual_mod_name; if (mod.getOrigin() == 'X') { cerr << "MassDecompositionAlgorithm: Warning: cannot handle modification " << mod.getName() << ", because aa is ambiguous (" << mod.getOrigin() << "), ignoring modification!" << endl; continue; } else { origin_aa = mod.getOrigin(); } if (mod.getMonoMass() != 0) { aa_to_weight[aa] = mod.getMonoMass(); } else { if (mod.getDiffMonoMass() != 0) { aa_to_weight[aa] = aa_to_weight[origin_aa] + mod.getDiffMonoMass(); } else { cerr << "Warning: cannot handle modification " << mod.getName() << ", because no monoisotopic mass value was found! Ignoring modification!" << endl; continue; } } } if (alphabet_ != nullptr) { delete alphabet_; } if (decomposer_ != nullptr) { delete decomposer_; } // init mass decomposer alphabet_ = new ims::IMSAlphabet(); for (Map<char, double>::ConstIterator it = aa_to_weight.begin(); it != aa_to_weight.end(); ++it) { alphabet_->push_back(String(it->first), it->second); } // initializes weights ims::Weights weights(alphabet_->getMasses(), (double) param_.getValue("decomp_weights_precision")); // optimize alphabet by dividing by gcd weights.divideByGCD(); // decomposes real values decomposer_ = new ims::RealMassDecomposer(weights); return; }
void CompNovoIdentificationBase::updateMembers_() { // init residue mass table String residue_set(param_.getValue("residue_set")); set<const Residue *> residues = ResidueDB::getInstance()->getResidues(residue_set); for (set<const Residue *>::const_iterator it = residues.begin(); it != residues.end(); ++it) { aa_to_weight_[(*it)->getOneLetterCode()[0]] = (*it)->getMonoWeight(Residue::Internal); } max_number_aa_per_decomp_ = param_.getValue("max_number_aa_per_decomp"); tryptic_only_ = param_.getValue("tryptic_only").toBool(); fragment_mass_tolerance_ = (DoubleReal)param_.getValue("fragment_mass_tolerance"); max_number_pivot_ = param_.getValue("max_number_pivot"); decomp_weights_precision_ = (DoubleReal)param_.getValue("decomp_weights_precision"); min_mz_ = (DoubleReal)param_.getValue("min_mz"); max_mz_ = (DoubleReal)param_.getValue("max_mz"); max_decomp_weight_ = (DoubleReal)param_.getValue("max_decomp_weight"); max_subscore_number_ = param_.getValue("max_subscore_number"); max_isotope_ = param_.getValue("max_isotope"); name_to_residue_.clear(); residue_to_name_.clear(); // now handle the modifications ModificationDefinitionsSet mod_set((StringList)param_.getValue("fixed_modifications"), (StringList)param_.getValue("variable_modifications")); set<ModificationDefinition> fixed_mods = mod_set.getFixedModifications(); for (set<ModificationDefinition>::const_iterator it = fixed_mods.begin(); it != fixed_mods.end(); ++it) { ResidueModification mod = ModificationsDB::getInstance()->getModification(it->getModification()); char aa = ' '; if (mod.getOrigin().size() != 1 || mod.getOrigin() == "X") { cerr << "Warning: cannot handle modification " << it->getModification() << ", because aa is ambiguous (" << mod.getOrigin() << "), ignoring modification!" << endl; continue; } else { aa = mod.getOrigin()[0]; } if (mod.getMonoMass() != 0) { aa_to_weight_[aa] = mod.getMonoMass(); } else { if (mod.getDiffMonoMass() != 0) { aa_to_weight_[aa] += mod.getDiffMonoMass(); } else { cerr << "Warning: cannot handle modification " << it->getModification() << ", because no monoisotopic mass value was found! Ignoring modification!" << endl; continue; } } //cerr << "Setting fixed modification " << it->getModification() << " of amino acid '" << aa << "'; weight = " << aa_to_weight_[aa] << endl; const Residue * res = ResidueDB::getInstance()->getModifiedResidue(it->getModification()); name_to_residue_[aa] = res; residue_to_name_[res] = aa; } const StringList mod_names(StringList::create("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z")); vector<String>::const_iterator actual_mod_name = mod_names.begin(); set<ModificationDefinition> var_mods = mod_set.getVariableModifications(); for (set<ModificationDefinition>::const_iterator it = var_mods.begin(); it != var_mods.end(); ++it) { ResidueModification mod = ModificationsDB::getInstance()->getModification(it->getModification()); char aa = (*actual_mod_name)[0]; char origin_aa = ' '; ++actual_mod_name; if (mod.getOrigin().size() != 1 || mod.getOrigin() == "X") { cerr << "CompNovoIdentificationBase: Warning: cannot handle modification " << it->getModification() << ", because aa is ambiguous (" << mod.getOrigin() << "), ignoring modification!" << endl; continue; } else { origin_aa = mod.getOrigin()[0]; } if (mod.getMonoMass() != 0) { aa_to_weight_[aa] = mod.getMonoMass(); } else { if (mod.getDiffMonoMass() != 0) { aa_to_weight_[aa] = aa_to_weight_[origin_aa] + mod.getDiffMonoMass(); } else { cerr << "CompNovoIdentificationBase: Warning: cannot handle modification " << it->getModification() << ", because no monoisotopic mass value was found! Ignoring modification!" << endl; continue; } } //cerr << "Mapping variable modification " << it->getModification() << " to letter '" << aa << "' (@" << origin_aa << "); weight = " << aa_to_weight_[aa] << endl; const Residue * res = ResidueDB::getInstance()->getModifiedResidue(it->getModification()); name_to_residue_[aa] = res; residue_to_name_[res] = aa; } /* cerr << "Following masses are used for identification: " << endl; for (Map<char, DoubleReal>::const_iterator it = aa_to_weight_.begin(); it != aa_to_weight_.end(); ++it) { cerr << it->first << " " << precisionWrapper(it->second) << endl; }*/ initIsotopeDistributions_(); Param decomp_param(mass_decomp_algorithm_.getParameters()); decomp_param.setValue("tolerance", fragment_mass_tolerance_); decomp_param.setValue("fixed_modifications", (StringList)param_.getValue("fixed_modifications")); decomp_param.setValue("variable_modifications", (StringList)param_.getValue("variable_modifications")); mass_decomp_algorithm_.setParameters(decomp_param); min_aa_weight_ = numeric_limits<DoubleReal>::max(); for (Map<char, DoubleReal>::const_iterator it = aa_to_weight_.begin(); it != aa_to_weight_.end(); ++it) { if (min_aa_weight_ > it->second) { min_aa_weight_ = it->second; } } return; }