const ElementDB* db = ElementDB::getInstance(); Element carbon = *db->getElement("Carbon"); // .getResidue("C") would also be ok cout << carbon.getName() << " " << carbon.getSymbol() << " " << carbon.getMonoWeight() << " " << carbon.getAverageWeight() << endl;
Elements can be accessed by the ElementDB class. As it is implemented as a singleton, only a pointer of the singleton can be used, via getInstance(). The example program writes the following output to the console.
Carbon C 12 12.0107
EmpiricalFormula methanol("CH3OH"), water("H2O"); EmpiricalFormula sum = methanol + water; cout << sum << " " << sum.getNumberOf("Carbon") << " " << sum.getAverageWeight() << endl;
Two instances of empirical formula are created. They are summed up, and some information about the new formula is printed to the terminal. The next lines show how to create and handle a isotopic distribution of a given formula.
IsotopeDistribution iso_dist = sum.getIsotopeDistribution(3); for (IsotopeDistribution::ConstIterator it = iso_dist.begin(); it != iso_dist.end(); ++it) { cout << it->first << " " << it->second << endl; }
The isotopic distribution can be simply accessed by the getIsotopeDistribution() function. The parameter of this function describes how many isotopes should be reported. In our case, 3 are enough, as the following numbers get very small. On larger molecules, or when one want to have the exact distribution, this number can be set much higher. The output of the code snipped might look like this.
O2CH6 1 50.0571 50 0.98387 51 0.0120698 52 0.00406
ResidueDB res_db; Residue lys = *res_db.getResidue("Lysine"); // .getResidue("K") would also be ok cout << lys.getName() << " " << lys.getThreeLetterCode() << " " << lys.getOneLetterCode() << " " << lys.getAverageWeight() << endl;
This small example show how to create a instance of ResidueDB were all Residues are stored in. The amino acids themselves can be accessed via the getResidue function. ResidueDB reads its amino acid and modification data from data/CHEMISTRY/.
The output of the example would look like this
Lysine LYS K 146.188
Weights, formulas and isotope distribution can be calculated depending on the charge state (additional proton count in case of positive ions) and ion type. Therefore, the class allows for a flexible handling of amino acid strings.
A very simple example of handling amino acid sequence with AASequence is given in the next few lines.
AASequence seq("DFPIANGER"); AASequence prefix(seq.getPrefix(4)); AASequence suffix(seq.getSuffix(5)); cout << seq << " " << prefix << " " << suffix << " " << seq.getAverageWeight() << endl;
Not only the prefix, suffix and subsequence accession is supported, but also most of the features of EmpiricalFormulas and Residues given above. Additionally, a number of predicates like hasSuffix are supported. The output of the code snippet looks like this.
DFPIANGER DFPI ANGER 1018.08
TheoreticalSpectrumGenerator tsg; PeakSpectrum spec1, spec2; AASequence peptide("DFPIANGER"); tsg.addPeaks(spec1, peptide, Residue::YIon, 1); tsg.getSpectrum(spec2, peptide, 2); cout << "Spectrum 1 has " << spec1.size() << " peaks. " << endl; cout << "Spectrum 2 has " << spec2.size() << " peaks. " << endl;
The example shows how to put peaks of a certain type, y-ions in this case, into a spectrum. Spectrum 2 is filled with a complete spectrum of all peaks (a-, b-, y-ions and losses). The TheoreticalSpectrumGenerator has many parameters which have a detailed description located in the class documentation. The output of the program looks like the following two lines.
Generated Tue Apr 1 15:36:40 2008 -- using doxygen 1.5.4 | OpenMS / TOPP 1.1 |