For calculating peptide and fragment masses.
#include "msparser.hpp"
#include <iostream>
#include <iomanip>
using namespace matrix_science;
static void printFragmentsTable(ms_fragmentvector & fragments);
static void displayMascotTestSearch(const ms_modvector vecFixed,
const ms_modvector vecVariable,
const ms_enzyme * enzyme,
const double mr,
const ms_fragmentvector fragments);
int main(int argc, char * argv[])
{
if ( argc < 3 )
{
std::cout << "Location of enzymes file and mod_file has to be specified as parameters" << std::endl;
return 0;
}
ms_enzymefile enzymefile(argv[1]);
if ( !enzymefile.isValid() )
{
std::cout << "There are errors. Cannot continue. The last error description:" << std::endl;
std::cout << enzymefile.getLastErrorString() << std::endl;
return 1;
}
const ms_enzyme *enzyme = enzymefile.getEnzymeByName("Trypsin");
if ( enzyme == NULL )
{
std::cout << "Cannot find Trypsin enzyme in the file. Cannot continue." << std::endl;
return 1;
}
ms_masses masses;
ms_modfile modfile(argv[2], &masses);
if ( !modfile.isValid() )
{
std::cout << "There are errors. Cannot continue. The last error description:" << std::endl;
std::cout << modfile.getLastErrorString() << std::endl;
return 1;
}
const ms_modification *oxidation = modfile.getModificationByName("Oxidation (M)");
const ms_modification *acetylNterm = modfile.getModificationByName("Acetyl (N-term)");
const ms_modification *phospho = modfile.getModificationByName("Phospho (STY)");
if ( oxidation == NULL || acetylNterm == NULL || phospho == NULL)
{
std::cout << "Cannot find necessary modifications in the mod_file. Cannot continue." << std::endl;
return 1;
}
ms_aahelper aahelper;
aahelper.setMasses(&masses);
aahelper.setEnzyme(enzyme);
char proteinStr[] = "MAIFRIDEIRNMSSEELEEELRKLEVELIRERGAVRAGGAPEKPGRIREIRRTIARMKTVQRERVRK";
aahelper.startIteratePeptides(proteinStr, static_cast<int>(strlen(proteinStr)), 0);
std::cout << "List of peptides" << std::endl;
while(aahelper.getNextPeptide())
{
int start = aahelper.getPepStart()-1;
int len = aahelper.getPepEnd() - aahelper.getPepStart()+1;
std::string peptideStr;
peptideStr.assign(proteinStr+start, len);
std::cout << peptideStr << std::endl;
}
std::cout << "End of list" << std::endl;
ms_modvector vecFixed;
vecFixed.appendModification(phospho);
ms_modvector vecVariable;
vecVariable.appendModification(oxidation);
vecVariable.appendModification(acetylNterm);
aahelper.setAvailableModifications(&vecFixed, &vecVariable);
if ( !aahelper.isValid() )
{
std::cout << "There are errors. Cannot continue. The last error description:" << std::endl;
std::cout << aahelper.getLastErrorString() << std::endl;
return 1;
}
ms_errs err;
std::vector< int > numThatMustBeModded;
numThatMustBeModded.push_back(1);
numThatMustBeModded.push_back(1);
double mr = aahelper.calcPeptideMZ(proteinStr,
static_cast<int>(strlen(proteinStr)),
1, 10,
numThatMustBeModded,
0,
matrix_science::MASS_TYPE_MONO,
&err);
if ( !err.isValid() )
{
std::cout << "There have been errors while calculating peptide mass: " << std::endl;
std::cout << err.getLastErrorString() << std::endl;
err.clearAllErrors();
}
else
{
std::cout << "Peptide mass calculated using 'calcPeptideMZ' is "
<< std::setprecision(3)
<< std::fixed
<< std::setw(8)
<< mr
<< std::endl << std::endl << std::endl;
}
std::vector< int > numModded;
numModded.push_back(2);
numModded.push_back(1);
numModded.push_back(0);
numModded.push_back(0);
numModded.push_back(0);
numModded.push_back(0);
numModded.push_back(0);
numModded.push_back(0);
numModded.push_back(0);
numModded.push_back(0);
numModded.push_back(0);
numModded.push_back(0);
std::vector< int > whichNl;
whichNl.push_back(0);
whichNl.push_back(1);
whichNl.push_back(0);
whichNl.push_back(0);
whichNl.push_back(0);
whichNl.push_back(0);
whichNl.push_back(0);
whichNl.push_back(0);
whichNl.push_back(0);
whichNl.push_back(0);
whichNl.push_back(0);
whichNl.push_back(0);
ms_peptide peptide = aahelper.createPeptide(proteinStr,
static_cast<int>(strlen(proteinStr)),
1,10,
numModded,
whichNl,
0,
matrix_science::MASS_TYPE_MONO,
&err);
if ( !err.isValid() )
{
std::cout << "There have been errors while creating a peptide: " << std::endl;
std::cout << err.getLastErrorString() << std::endl;
err.clearAllErrors();
}
else
{
std::cout
<< "Peptide has been created successfully: "
<< peptide.getPeptideStr()
<< std::endl;
}
std::vector< double > ions;
ms_fragmentvector fragments;
ms_fragmentvector all_fragments;
ions = aahelper.calcFragments(&peptide,
ms_fragmentationrules::FRAG_B_SERIES,
false,
100.0,
mr,
matrix_science::MASS_TYPE_MONO,
&fragments,
&err);
std::cout << "b-ion series fragments: " << std::endl;
printFragmentsTable(fragments);
all_fragments.copyFrom(&fragments);
ms_fragmentvector b_ions;
b_ions.copyFrom(&fragments);
ions = aahelper.calcFragments(&peptide,
ms_fragmentationrules::FRAG_Y_SERIES,
false,
100.0,
mr,
matrix_science::MASS_TYPE_MONO,
&fragments,
&err);
std::cout << "y-ion series fragments: " << std::endl;
printFragmentsTable(fragments);
int i;
for (i=0; i < fragments.getNumberOfFragments(); i++)
all_fragments.appendFragment(fragments.getFragmentByNumber(i));
aahelper.calcFragmentsEx(&peptide,
ms_fragmentationrules::FRAG_Y_SERIES,
2,
100.0,
mr,
matrix_science::MASS_TYPE_MONO,
&fragments,
&err);
std::cout << "y++-ion series fragments: " << std::endl;
printFragmentsTable(fragments);
for (i=0; i < fragments.getNumberOfFragments(); i++)
all_fragments.appendFragment(fragments.getFragmentByNumber(i));
ions = aahelper.calcFragments(&peptide,
ms_fragmentationrules::FRAG_INTERNAL_YB,
false,
100.0,
700,
matrix_science::MASS_TYPE_MONO,
&fragments,
&err);
std::cout << "internal yb-ion series fragments: " << std::endl;
printFragmentsTable(fragments);
for (i=0; i < fragments.getNumberOfFragments(); i++)
all_fragments.appendFragment(fragments.getFragmentByNumber(i));
std::cout << "Run a search under Mascot to verify the output above" << std::endl;
std::cout << "Paste the following into a Mascot search query window:" << std::endl;
displayMascotTestSearch(vecFixed, vecVariable,
enzyme,
mr,
b_ions);
return 0;
}
static void printFragmentsTable(ms_fragmentvector & fragments)
{
std::cout << "Number of fragments: " << fragments.getNumberOfFragments() << std::endl;
std::cout << "Col\tStart\tEnd\tLabel\t\t Mass\t NL\tName\tImmon\tIntern\tReg" << std::endl;
for (int i=0; i < fragments.getNumberOfFragments(); i++)
{
const ms_fragment * frag = fragments.getFragmentByNumber(i);
std::cout << frag->getColumn() << "\t";
std::cout << frag->getStart() << "\t";
std::cout << frag->getEnd() << "\t";
std::cout << std::setw(10) << frag->getLabel() << "\t";
std::cout << std::fixed << std::setprecision(2) << std::setw(7) << frag->getMass() << "\t";
std::cout << frag->getNeutralLoss()<< "\t";
std::cout << frag->getSeriesName() << "\t";
std::cout << frag->isImmonium() << "\t";
std::cout << frag->isInternal() << "\t";
std::cout << frag->isRegular() << std::endl;
}
std::cout << std::endl;
}
static void displayMascotTestSearch(const ms_modvector vecFixed,
const ms_modvector vecVariable,
const ms_enzyme * enzyme,
const double mr,
const ms_fragmentvector fragments)
{
int i;
for (i=0; i < vecFixed.getNumberOfModifications(); i++)
{
std::cout << "MODS="
<< vecFixed.getModificationByNumber(i)->getTitle()
<< std::endl;
}
for (i=0; i < vecVariable.getNumberOfModifications(); i++)
{
std::cout << "IT_MODS="
<< vecVariable.getModificationByNumber(i)->getTitle()
<< std::endl;
}
std::cout << "CHARGE=Mr" << std::endl;
std::cout << "CLE=" << enzyme->getTitle() << std::endl;
std::cout << "INSTRUMENT=MALDI-TOF-TOF" << std::endl;
std::cout << std::setprecision(3) << mr << " ions(";
for(i=0; i < fragments.getNumberOfFragments(); i++)
{
if (i > 0)
std::cout << ", ";
std::cout << fragments.getFragmentByNumber(i)->getMass();
}
std::cout << ")" << std::endl;
}