Example program for extracting the peptide or protein summary.
import java.util.Date;
import matrix_science.msparser.*;
import java.util.regex.*;
import java.io.File;
public class resfile_summary {
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[])
{
int returnValue = -1;
if (argv.length < 1) {
System.out.println("Must specify results filename as parameter");
System.exit(returnValue);
}
ms_mascotresfilebase file = ms_mascotresfilebase.createResfile(argv[0]);
if (checkErrors(file)) {
ms_datfile datfile = new ms_datfile("../config/mascot.dat");
ms_mascotoptions mascotOptions = new ms_mascotoptions();
if (datfile.isValid())
{
mascotOptions = datfile.getMascotOptions();
}
boolean[] usePeptideSummary = {false};
long[] flags = {0};
double[] minProbability = {0};
int[] maxHitsToReport = {0};
double[] ignoreIonsScoreBelow = {0};
long[] minPepLenInPepSummary = {0};
long[] flags2 = {0};
String scriptName = file.get_ms_mascotresults_params(
mascotOptions,
flags,
minProbability,
maxHitsToReport,
ignoreIonsScoreBelow,
minPepLenInPepSummary,
usePeptideSummary,
flags2
);
boolean bResult;
if (usePeptideSummary[0]) {
System.out.println("-------------------------------------------------------------");
System.out.println("--- Peptide summary report ---");
System.out.println("-------------------------------------------------------------");
bResult = showResults(file,
usePeptideSummary[0],
(int)flags[0],
minProbability[0],
maxHitsToReport[0],
"",
ignoreIonsScoreBelow[0],
(int)minPepLenInPepSummary[0],
(int)flags2[0]
);
} else {
flags[0] &= ~ms_mascotresults.MSRES_GROUP_PROTEINS;
flags[0] &= ~ms_mascotresults.MSRES_SHOW_SUBSETS;
System.out.println("-------------------------------------------------------------");
System.out.println("--- Full Protein summary report ---");
System.out.println("-------------------------------------------------------------");
bResult = showResults(file,
usePeptideSummary[0],
(int)flags[0],
minProbability[0],
maxHitsToReport[0],
"",
ignoreIonsScoreBelow[0],
(int)minPepLenInPepSummary[0],
(int)flags2[0]
);
if(bResult && checkErrors(file)) {
System.out.println();
flags[0] |= ms_mascotresults.MSRES_GROUP_PROTEINS;
flags[0] |= ms_mascotresults.MSRES_SHOW_SUBSETS;
System.out.println("-------------------------------------------------------------");
System.out.println("--- Concise Protein summary report ---");
System.out.println("-------------------------------------------------------------");
bResult = showResults(file,
usePeptideSummary[0],
(int)flags[0],
minProbability[0],
maxHitsToReport[0],
"",
ignoreIonsScoreBelow[0],
(int)minPepLenInPepSummary[0],
(int)flags2[0]
);
}
}
if (bResult && checkErrors(file)) {
returnValue = 0;
}
}
System.exit(returnValue);
}
private static boolean showResults(ms_mascotresfilebase file,
boolean pepSum,
int flags,
double minProteinProb,
int maxHits,
String unigeneFile,
double minIonsScore,
int minPepLenInPepSummary,
int flags2){
ms_mascotresults results=null;
int family;
int hit;
ms_protein prot;
String accession;
String description;
double mass;
int dbIdx;
int num_peps;
int i;
int query;
int p;
int u;
ms_peptide pep;
if(pepSum) {
results = new ms_peptidesummary(file,
flags,
minProteinProb,
maxHits,
unigeneFile,
minIonsScore,
minPepLenInPepSummary,
null,
flags2);
} else {
results = new ms_proteinsummary(file,
flags,
minProteinProb,
maxHits,
null,
null);
}
if (!checkErrors(file))
{
return false;
}
if (results.isNA())
System.out.println("Nucleic acid database\n");
else
System.out.println("Amino acid database ");
family = 1;
hit = 1;
prot = results.getHit(hit);
while(hit <= results.getNumberOfHits()) {
accession = prot.getAccession();
description = results.getProteinDescription(accession);
mass = results.getProteinMass(accession);
dbIdx = prot.getDB();
String protein_hit = "Protein Hit " + hit;
if((flags & ms_mascotresults.MSRES_CLUSTER_PROTEINS) == ms_mascotresults.MSRES_CLUSTER_PROTEINS) {
protein_hit += "." + family;
}
System.out.println(protein_hit+"\n===================");
System.out.println("Accession : "+accession);
System.out.println("Description : "+description);
System.out.println("Score : "+roundWholeNumber(prot.getScore()));
System.out.println("Mass : "+mass);
System.out.println("Frame : "+prot.getFrame());
System.out.println("Coverage : "+prot.getCoverage());
System.out.println("RMS error : "+prot.getRMSDeltas(results));
System.out.println("Peptides : "+prot.getNumDisplayPeptides());
num_peps = prot.getNumPeptides();
for(i=1; i <= num_peps; i++) {
query = prot.getPeptideQuery(i);
p = prot.getPeptideP(i);
if((p != -1) && (query != -1) && (prot.getPeptideDuplicate(i) !=
ms_protein.DUPE_DuplicateSameQuery)) {
pep = results.getPeptide(query,p);
if(pep != null) {
displayPeptideInfo(false,pep,results,prot.getPeptideDuplicate(i)
== ms_protein.DUPE_Duplicate, prot.getPeptideIsBold(i),
prot.getPeptideShowCheckbox(i));
}
}
}
if((flags & ms_mascotresults.MSRES_GROUP_PROTEINS) == ms_mascotresults.MSRES_GROUP_PROTEINS
|| (flags & ms_mascotresults.MSRES_CLUSTER_PROTEINS) == ms_mascotresults.MSRES_CLUSTER_PROTEINS) {
System.out.println("Proteins matching the same set of peptides:");
i = 1;
while((prot = results.getNextSimilarProteinOf(accession, dbIdx, i)) != null) {
String similar_accession = prot.getAccession();
int similar_dbIdx = prot.getDB();
if((flags & ms_mascotresults.MSRES_CLUSTER_PROTEINS) == ms_mascotresults.MSRES_CLUSTER_PROTEINS
&& similar_dbIdx > 1) {
System.out.print(similar_dbIdx + "::");
}
System.out.print(similar_accession + " - Total score: " + roundWholeNumber(prot.getScore()));
System.out.println(" - Peptides matched: " + prot.getNumDisplayPeptides());
i++;
}
if((flags & ms_mascotresults.MSRES_SHOW_SUBSETS) == ms_mascotresults.MSRES_SHOW_SUBSETS) {
System.out.println("Proteins matching a subset of these peptides:");
i = 1;
while((prot = results.getNextSubsetProteinOf(accession, dbIdx, i)) != null) {
String subset_accession = prot.getAccession();
int subset_dbIdx = prot.getDB();
if((flags & ms_mascotresults.MSRES_CLUSTER_PROTEINS) == ms_mascotresults.MSRES_CLUSTER_PROTEINS
&& subset_dbIdx > 1) {
System.out.print(subset_dbIdx + "::");
}
System.out.print(subset_accession + " - Total score: " + roundWholeNumber(prot.getScore()));
System.out.println(" - Peptides matched: " + prot.getNumDisplayPeptides());
if((flags & ms_mascotresults.MSRES_CLUSTER_PROTEINS) == ms_mascotresults.MSRES_CLUSTER_PROTEINS) {
int j = 1;
if(results.getNextSimilarProteinOf(subset_accession, subset_dbIdx, j) != null) {
System.out.println(" Proteins matching the same set of peptides for this subset:");
}
ms_protein similar_subset_prot;
while((similar_subset_prot = results.getNextSimilarProteinOf(subset_accession, subset_dbIdx, j)) != null) {
String similar_subset_accession = similar_subset_prot.getAccession();
int similar_subset_dbIdx = similar_subset_prot.getDB();
System.out.print(" ");
if(similar_subset_dbIdx > 1) {
System.out.print(similar_subset_dbIdx + "::");
}
System.out.print(similar_subset_accession + " - Total score: " + roundWholeNumber(similar_subset_prot.getScore()));
System.out.println(" - Peptides matched: " + similar_subset_prot.getNumDisplayPeptides());
j++;
}
}
i++;
}
}
}
if((flags & ms_mascotresults.MSRES_CLUSTER_PROTEINS) == ms_mascotresults.MSRES_CLUSTER_PROTEINS) {
prot = results.getNextFamilyProtein(hit, family++);
if(prot == null) {
hit++;
prot = results.getHit(hit);
family = 1;
}
} else {
hit++;
prot = results.getHit(hit);
}
System.out.println("\n");
}
results.createUnassignedList(ms_mascotresults.SCORE);
if(results.getNumberOfUnassigned() > 0) {
System.out.println("Unassigned list");
System.out.println("---------------");
for(u=1; u <= results.getNumberOfUnassigned(); u++) {
pep = results.getUnassigned(u);
displayPeptideInfo(false, pep, results, false, true, true);
}
}
if(pepSum) displayYellowPopupInfo(results,97);
return true;
}
private static void displayYellowPopupInfo (ms_mascotresults results, int queryNo) {
int p;
ms_peptide pep;
String seq;
String tmp;
String hit;
String protein;
String morethan="";
System.out.println("Score Delta Hit Protein Peptide");
for(p=1; p <= 10; p++) {
pep = results.getPeptide(queryNo,p);
if(pep != null) {
seq = pep.getPeptideStr();
if(!(seq.equals(""))) {
tmp = results.getProteinsWithThisPepMatch(queryNo,p,true);
hit = " ";
protein = " ";
if(!(tmp.equals(""))) {
String regex = "(\\d):([^ ]*)[ ]*(.*)";
Pattern pat = Pattern.compile(regex);
Matcher m = pat.matcher(tmp);
if(m.matches()) {
int groupCount = m.groupCount();
if (groupCount >= 1) hit = m.group(1);
if (groupCount >= 2) protein = m.group(2);
if (groupCount >= 3) morethan = m.group(3);
}
if(!(morethan.equals(""))) {
hit = hit+"+";
}
}
System.out.print(pep.getIonsScore()+ " "+ pep.getDelta()+ " ");
System.out.println(hit+ " "+ protein+ " "+ pep.getPeptideStr());
}
}
}
p=1;
System.out.println("Accessions that matched query "+ queryNo+ " rank "
+ p+ ":- "+results.getProteinsWithThisPepMatch(queryNo,p, false));
}
private static void displayPeptideInfo(boolean showFullDetails, ms_peptide p,
ms_mascotresults r,
boolean isDuplicate,
boolean isBold,
boolean showCheckBox) {
int q;
q=p.getQuery();
if(showFullDetails) {
System.out.println("Peptide hit");
if(p.getAnyMatch()) {
System.out.println(" Query : "+q);
System.out.println(" Rank : "+p.getRank());
System.out.println(" Matched : "+p.getAnyMatch());
System.out.println(" missedCleave: "+p.getMissedCleavages());
System.out.println(" mrCalc : "+p.getMrCalc());
System.out.println(" delta : "+p.getDelta());
System.out.println(" observed : "+p.getObserved());
System.out.println(" charge : "+p.getCharge());
System.out.println(" mrExp : "+p.getMrExperimental());
System.out.println(" ionsMatched : "+p.getNumIonsMatched());
System.out.println(" peptideStr : "+p.getPeptideStr());
System.out.println(" peaksUsed1 : "+p.getPeaksUsedFromIons1());
System.out.println(" varModsStr : "+p.getVarModsStr());
System.out.println(" readable mod: "+r.getReadableVarMods(q, p.getRank(),2));
System.out.println(" ionsScore : "+p.getIonsScore());
System.out.println(" seriesUsedS : "+p.getSeriesUsedStr());
System.out.println(" peaksUsed2 : "+p.getPeaksUsedFromIons2());
System.out.println(" peaksUsed3 : "+p.getPeaksUsedFromIons3());
System.out.print(" idth, hth, p: " +r.getPeptideIdentityThreshold(q,20));
System.out.print(", " +r.getHomologyThreshold(q,20));
System.out.println(", " +r.getProbOfPepBeingRandomMatch(p.getIonsScore(),q));
System.out.println();
} else {
System.out.println(" No match");
}
} else {
if(showCheckBox) System.out.print("CB ");
else System.out.print("-- ");
if(isBold) System.out.print("BOLD ");
else System.out.print("dim ");
String query = ""+q;
String observed = ""+p.getObserved();
System.out.print(padout(query,4," "));
if(observed.indexOf(".")>-1) {
String one = observed.substring(0,observed.indexOf("."));
String two = observed.substring(observed.indexOf(".")+1,observed.length());
two = padend(two,6,"0");
observed = one+"."+two;
}
System.out.print(padout(observed,11," "));
System.out.print(padout(""+p.getRank(),4," "));
System.out.print("("+padout(""+p.getPrettyRank(),4," ")+")");
System.out.print(padout(p.getPeptideStr(),20," "));
double score = p.getIonsScore();
String scoreString = ""+score;
if(scoreString.indexOf(".")>-1) {
String one = scoreString.substring(0,scoreString.indexOf("."));
String two = scoreString.substring(scoreString.indexOf(".")+1,
scoreString.length());
if(isDuplicate) {
System.out.print("("+padout(one,3,"")+"."+padend(two,2,"0")+")");
} else {
System.out.print(" "+padout(one,3,"")+"."+padend(two,2,"0")+" ");
}
} else {
System.out.println(scoreString);
}
if(r.getReadableVarMods(q,p.getRank(),2).equals("")) System.out.println(" 0");
else {
String let = r.getReadableVarMods(q,p.getRank(),2).substring(0,1);
try {
int intLet = Integer.parseInt(let);
System.out.println(" "+let);
} catch (NumberFormatException notNumber) {
System.out.println(" 0");
}
}
}
}
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 padend(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;
}
private static String roundWholeNumber (double toRound) {
String myInt = ""+toRound;
myInt += "\n";
if(myInt.indexOf(".0\n")>-1) {
return myInt.substring(0,myInt.indexOf(".0\n"));
}
return ""+toRound;
}
private static boolean checkErrors(ms_mascotresfilebase file) {
if((file.getLastError())>0) {
for(int loopErrors=1; loopErrors <= file.getNumberOfErrors(); loopErrors++) {
System.out.print("Error number: "+file.getErrorNumber(loopErrors));
System.out.print(" : "+file.getErrorString(loopErrors));
System.out.println("");
}
}
boolean bIsValid = file.isValid();
file.clearAllErrors();
return bIsValid;
}
}