For calculating peptide and fragment masses.
import matrix_science.msparser.ms_enzymefile;
import matrix_science.msparser.ms_fragmentationrules;
import matrix_science.msparser.msparserConstants;
import matrix_science.msparser.*;
import java.text.*;
public class tools_aahelper {
static {
try {
System.loadLibrary("msparserj");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load. "
+ "Is msparserj.dll on the path?\n" + e);
System.exit(0);
}
}
public static void main(String argv[])
{
if(argv.length < 2) {
System.out.println("Location of enzymes file and mod_file has to be specified as parameters");
System.exit(0);
}
ms_enzymefile enzymefile = new ms_enzymefile(argv[0]);
if ( !enzymefile.isValid() )
{
System.out.println("There are errors. Cannot continue. The last error description:");
System.out.println(enzymefile.getLastErrorString());
System.exit(1);
}
ms_enzyme enzyme = enzymefile.getEnzymeByName("Trypsin");
if ( enzyme == null )
{
System.out.println("Cannot find Trypsin enzyme in the file. Cannot continue.");
System.exit(1);
}
ms_masses masses = new ms_masses();
ms_modfile modfile = new ms_modfile(argv[1], masses);
if ( !modfile.isValid() )
{
System.out.println("There are errors. Cannot continue. The last error description:");
System.out.println(modfile.getLastErrorString());
System.exit(1);
}
ms_modification oxidation = modfile.getModificationByName("Oxidation (M)");
ms_modification acetylNterm = modfile.getModificationByName("Acetyl (N-term)");
ms_modification phospho = modfile.getModificationByName("Phospho (STY)");
if ( oxidation == null || acetylNterm == null || phospho == null )
{
System.out.println("Cannot find necessary modifications in the mod_file. Cannot continue.");
System.exit(1);
}
ms_aahelper aahelper = new ms_aahelper();
aahelper.setMasses(masses);
aahelper.setEnzyme(enzyme);
String proteinStr = "MAIFRIDEIRNMSSEELEEELRKLEVELIRERGAVRAGGAPEKPGRIREIRRTIARMKTVQRERVRK";
aahelper.startIteratePeptides(proteinStr, proteinStr.length(), 0);
System.out.println("List of peptides");
while(aahelper.getNextPeptide())
{
int start = aahelper.getPepStart()-1;
int end = aahelper.getPepEnd();
String peptideStr = proteinStr.substring(start, end);
System.out.println(peptideStr);
}
System.out.println("End of list");
ms_modvector vecFixed = new ms_modvector();
vecFixed.appendModification(phospho);
ms_modvector vecVariable = new ms_modvector();
vecVariable.appendModification(oxidation);
vecVariable.appendModification(acetylNterm);
aahelper.setAvailableModifications(vecFixed, vecVariable);
if ( !aahelper.isValid() )
{
System.out.println("There are errors. Cannot continue. The last error description:");
System.out.println(aahelper.getLastErrorString());
System.exit(1);
}
ms_errs err = new ms_errs();
vectori numThatMustBeModded = new vectori();
numThatMustBeModded.add(1);
numThatMustBeModded.add(1);
double mr = aahelper.calcPeptideMZ(proteinStr, proteinStr.length(),
1, 10,
numThatMustBeModded,
0,
msparserConstants.MASS_TYPE_MONO,
err);
if ( !err.isValid() )
{
System.out.println("There have been errors while calculating peptide mass: ");
System.out.println(err.getLastErrorString());
err.clearAllErrors();
}
else
{
DecimalFormat massFmt = new DecimalFormat("0.000");
System.out.println("Peptide mass calculated using 'calcPeptideMZ' is " + massFmt.format(mr));
}
vectori numModded = new vectori();
numModded.add(2);
numModded.add(1);
numModded.add(0);
numModded.add(0);
numModded.add(0);
numModded.add(0);
numModded.add(0);
numModded.add(0);
numModded.add(0);
numModded.add(0);
numModded.add(0);
numModded.add(0);
vectori whichNl = new vectori();
whichNl.add(0);
whichNl.add(1);
whichNl.add(0);
whichNl.add(0);
whichNl.add(0);
whichNl.add(0);
whichNl.add(0);
whichNl.add(0);
whichNl.add(0);
whichNl.add(0);
whichNl.add(0);
whichNl.add(0);
ms_peptide peptide = aahelper.createPeptide(proteinStr, proteinStr.length(),
1,10,
numModded,
whichNl,
0,
msparserConstants.MASS_TYPE_MONO,
err);
if ( !err.isValid() )
{
System.out.println("There have been errors while creating a peptide: ");
System.out.println(err.getLastErrorString());
err.clearAllErrors();
}
else
{
System.out.println();
System.out.println();
System.out.print("Peptide has been created successfully: ");
System.out.println(peptide.getPeptideStr());
}
vectord ions;
ms_fragmentvector fragments = new ms_fragmentvector();
ms_fragmentvector all_fragments = new ms_fragmentvector();
ions = aahelper.calcFragments(peptide,
ms_fragmentationrules.FRAG_B_SERIES,
false,
100.0,
mr,
msparserConstants.MASS_TYPE_MONO,
fragments,
err);
System.out.println("b-ion series fragments: ");
printFragmentsTable(fragments);
all_fragments.copyFrom(fragments);
ms_fragmentvector b_ions = new ms_fragmentvector();
b_ions.copyFrom(fragments);
ions = aahelper.calcFragments(peptide,
ms_fragmentationrules.FRAG_Y_SERIES,
false,
100.0,
mr,
msparserConstants.MASS_TYPE_MONO,
fragments,
err);
System.out.println("y-ion series fragments: ");
printFragmentsTable(fragments);
for (int i=0; i < fragments.getNumberOfFragments(); i++)
all_fragments.appendFragment(fragments.getFragmentByNumber(i));
aahelper.calcFragmentsEx(peptide,
ms_fragmentationrules.FRAG_Y_SERIES,
2,
100.0,
mr,
msparserConstants.MASS_TYPE_MONO,
fragments,
err);
System.out.println("y++-ion series fragments: ");
printFragmentsTable(fragments);
for (int 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.0,
msparserConstants.MASS_TYPE_MONO,
fragments,
err);
System.out.println("internal yb-ion series fragments: ");
printFragmentsTable(fragments);
for (int i=0; i < fragments.getNumberOfFragments(); i++)
all_fragments.appendFragment(fragments.getFragmentByNumber(i));
System.out.println("Run a search under Mascot to verify the output above");
System.out.println("Paste the following into a Mascot search query window:");
displayMascotTestSearch(vecFixed, vecVariable,
enzyme,
mr,
b_ions);
System.exit(0);
}
public static void printFragmentsTable(ms_fragmentvector fragments)
{
System.out.print("Number of fragments: ");
System.out.println(fragments.getNumberOfFragments());
System.out.println("Col\tStart\tEnd\tLabel\t\t Mass\t NL\tName\tImmon\tIntern\tReg");
int i;
for (i=0; i < fragments.getNumberOfFragments(); i++)
{
ms_fragment frag = fragments.getFragmentByNumber(i);
DecimalFormat fragMassFmt = new DecimalFormat("0.00");
System.out.print(frag.getColumn());
System.out.print("\t");
System.out.print(frag.getStart());
System.out.print("\t");
System.out.print(frag.getEnd());
System.out.print("\t");
System.out.print(padding(frag.getLabel(), 10, " "));
System.out.print("\t");
System.out.print(padout(fragMassFmt.format(frag.getMass()),7," "));
System.out.print("\t");
System.out.print(fragMassFmt.format(frag.getNeutralLoss()));
System.out.print("\t");
System.out.print(frag.getSeriesName());
System.out.print("\t");
if (frag.isImmonium())
System.out.print("1\t");
else
System.out.print("0\t");
if (frag.isInternal())
System.out.print("1\t");
else
System.out.print("0\t");
if (frag.isRegular())
System.out.print("1\n");
else
System.out.print("0\n");
}
System.out.println();
}
public static void displayMascotTestSearch(ms_modvector vecFixed,
ms_modvector vecVariable,
ms_enzyme enzyme,
double mr,
ms_fragmentvector fragments)
{
int i;
for (i=0; i < vecFixed.getNumberOfModifications(); i++)
{
System.out.print("MODS=");
System.out.println(vecFixed.getModificationByNumber(i).getTitle());
}
for (i=0; i < vecVariable.getNumberOfModifications(); i++)
{
System.out.print("IT_MODS=");
System.out.println(vecVariable.getModificationByNumber(i).getTitle());
}
System.out.println("CHARGE=Mr");
System.out.print("CLE=");
System.out.println(enzyme.getTitle());
System.out.println("INSTRUMENT=MALDI-TOF-TOF");
DecimalFormat massFmt = new DecimalFormat("#0.000");
System.out.print(massFmt.format(mr) + " ions(" );
for(i=0; i < fragments.getNumberOfFragments(); i++)
{
if (i > 0)
System.out.print(", ");
double mz = fragments.getFragmentByNumber(i).getMass();
System.out.print(massFmt.format(mz));
}
System.out.println(")");
}
private static String padout(String toPrint, int length,String padding) {
String returnValue="";
if(toPrint.length() < length) {
for(int queryLoop = 1; queryLoop <= length - toPrint.length(); queryLoop++) {
returnValue += padding;
}
returnValue += toPrint;
}
else returnValue = toPrint;
return returnValue;
}
private static String padding(String toPrint, int length,String padding) {
String returnValue=toPrint;
if(toPrint.length() < length) {
for(int queryLoop = 1; queryLoop <= length - toPrint.length(); queryLoop++) {
returnValue += padding;
}
}
return returnValue;
}
}