Example program for extracting the peptide or protein summary.
using System;
using System.Text.RegularExpressions;
using matrix_science.msparser;
namespace MsParserExamples
{
public class resfile_summary
{
public static int Main(string[] argv)
{
if (argv.Length < 1)
{
Console.WriteLine("Must specify results filename as parameter");
return 1;
}
int returnValue = 1;
ms_mascotresfilebase file = ms_mascotresfilebase.createResfile(argv[0], 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();
}
uint flags, flags2, minPepLenInPepSummary;
int maxHitsToReport;
double minProbability, ignoreIonsScoreBelow;
bool usePeptideSummary;
string scriptName = file.get_ms_mascotresults_params(
mascotOptions,
out flags,
out minProbability,
out maxHitsToReport,
out ignoreIonsScoreBelow,
out minPepLenInPepSummary,
out usePeptideSummary,
out flags2);
bool bResult;
if (usePeptideSummary)
{
Console.WriteLine("-------------------------------------------------------------");
Console.WriteLine("--- Peptide summary report ---");
Console.WriteLine("-------------------------------------------------------------");
bResult = showResults(file,
usePeptideSummary,
flags,
minProbability,
maxHitsToReport,
ignoreIonsScoreBelow,
(int)minPepLenInPepSummary,
flags2);
}
else
{
flags &= ~(uint)ms_mascotresults.FLAGS.MSRES_GROUP_PROTEINS;
flags &= ~(uint)ms_mascotresults.FLAGS.MSRES_SHOW_SUBSETS;
Console.WriteLine("-------------------------------------------------------------");
Console.WriteLine("--- Full Protein summary report ---");
Console.WriteLine("-------------------------------------------------------------");
bResult = showResults(file,
usePeptideSummary,
flags,
minProbability,
maxHitsToReport,
ignoreIonsScoreBelow,
(int)minPepLenInPepSummary,
flags2);
if (bResult && checkErrors(file))
{
flags |= (uint)ms_mascotresults.FLAGS.MSRES_GROUP_PROTEINS;
flags |= (uint)ms_mascotresults.FLAGS.MSRES_SHOW_SUBSETS;
Console.WriteLine("-------------------------------------------------------------");
Console.WriteLine("--- Concise Protein summary report ---");
Console.WriteLine("-------------------------------------------------------------");
bResult = showResults(file,
usePeptideSummary,
flags,
minProbability,
maxHitsToReport,
ignoreIonsScoreBelow,
(int)minPepLenInPepSummary,
flags2);
}
}
if (bResult && checkErrors(file))
{
returnValue = 0;
}
}
GC.KeepAlive(file);
return returnValue;
}
private static bool showResults(ms_mascotresfilebase file,
bool pepSum,
uint flags,
double minProteinProb,
int maxHits,
double minIonsScore,
int minPepLenInPepSummary,
uint flags2)
{
int hit, num_peps, i, query, p, u, family, dbIdx;
string accession, description;
double mass;
ms_mascotresults results;
ms_protein prot;
ms_peptide pep;
if (pepSum)
{
results = new ms_peptidesummary(file,
flags,
minProteinProb,
maxHits,
"",
minIonsScore,
minPepLenInPepSummary,
null,
flags2);
}
else
{
results = new ms_proteinsummary(file,
flags,
minProteinProb,
maxHits,
null,
null);
}
if (!checkErrors(file))
{
return false;
}
Console.WriteLine("{0} acid database", ((results.isNA()) ? "Nucleic" : "Amino"));
family = 1;
hit = 1;
prot = results.getHit(hit);
while (hit <= results.getNumberOfHits())
{
accession = prot.getAccession();
dbIdx = prot.getDB();
description = results.getProteinDescription(accession);
mass = results.getProteinMass(accession);
if ((flags & (uint)ms_mascotresults.FLAGS.MSRES_CLUSTER_PROTEINS) > 0)
{
Console.WriteLine("Protein Hit {0}.{1}\n===================", hit, family);
}
else
{
Console.WriteLine("Protein Hit {0}\n===================", hit);
}
Console.WriteLine("Accession : {0}", accession);
Console.WriteLine("Description : {0}", description);
Console.WriteLine("Score : {0:#}", prot.getScore());
Console.WriteLine("Mass : {0}", mass);
Console.WriteLine("Frame : {0}", prot.getFrame());
Console.WriteLine("Coverage : {0}", prot.getCoverage());
Console.WriteLine("RMS error : {0}", prot.getRMSDeltas(results));
Console.WriteLine("Peptides : {0}", 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.DUPLICATE.DUPE_DuplicateSameQuery)
{
pep = results.getPeptide(query, p);
if (pep != null)
{
displayPeptideInfo(false, pep, results, prot.getPeptideDuplicate(i) == ms_protein.DUPLICATE.DUPE_Duplicate,
prot.getPeptideIsBold(i), prot.getPeptideShowCheckbox(i));
}
}
}
if ((flags & (uint) ms_mascotresults.FLAGS.MSRES_GROUP_PROTEINS) > 0 ||
(flags & (uint)ms_mascotresults.FLAGS.MSRES_CLUSTER_PROTEINS) > 0)
{
Console.WriteLine("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 & (uint)ms_mascotresults.FLAGS.MSRES_CLUSTER_PROTEINS) > 0 && similar_dbIdx > 1)
{
Console.Write("{0}::", similar_dbIdx);
}
Console.WriteLine("{0} Total score: {1:#} Peptides matched: {2}", similar_accession,
prot.getScore(), prot.getNumDisplayPeptides());
i++;
}
if ((flags & ((uint) ms_mascotresults.FLAGS.MSRES_SHOW_SUBSETS)) > 0)
{
Console.WriteLine("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 & (uint)ms_mascotresults.FLAGS.MSRES_CLUSTER_PROTEINS) > 0 && subset_dbIdx > 1)
{
Console.Write("{0}::", subset_dbIdx);
}
Console.WriteLine("{0} Total score: {1:#} Peptides matched: {2}", subset_accession,
prot.getScore(), prot.getNumDisplayPeptides());
if ((flags & (uint)ms_mascotresults.FLAGS.MSRES_CLUSTER_PROTEINS) > 0)
{
int j = 1;
if (results.getNextSimilarProteinOf(subset_accession, subset_dbIdx, j) != null)
{
Console.WriteLine(" 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();
Console.Write(" ");
if (similar_subset_dbIdx > 1)
{
Console.Write("{0}::", similar_subset_dbIdx);
}
Console.WriteLine("{0} Total score: {1:#} Peptides matched: {2}",
similar_subset_accession, similar_subset_prot.getScore(),
similar_subset_prot.getNumDisplayPeptides());
j++;
}
}
i++;
}
}
}
Console.WriteLine();
Console.WriteLine();
if ((flags & (uint)ms_mascotresults.FLAGS.MSRES_CLUSTER_PROTEINS) > 0)
{
prot = results.getNextFamilyProtein(hit, family++);
if(prot == null)
{
hit++;
prot = results.getHit(hit);
family = 1;
}
}
else
{
hit++;
prot = results.getHit(hit);
}
}
results.createUnassignedList(ms_mascotresults.sortBy.SCORE);
if (results.getNumberOfUnassigned() > 0)
{
Console.WriteLine("Unassigned list");
Console.WriteLine("---------------");
for (u = 1; u <= results.getNumberOfUnassigned(); u++)
{
pep = results.getUnassigned(u);
displayPeptideInfo(false, pep, results, false, true, true);
}
}
if (pepSum) displayYellowPopupInfo(results, 1);
return true;
}
private static void displayYellowPopupInfo(ms_mascotresults results, int queryNo)
{
int p;
ms_peptide pep;
String seq, tmp, hit, protein, morethan = "";
Regex regex = new Regex(@"(\d):([^ ]*)[ ]*(.*)");
Console.WriteLine("Score Delta Hit Protein Peptide");
for (p = 1; p <= 10; p++)
{
if ((pep = results.getPeptide(queryNo, p)) != null)
{
seq = pep.getPeptideStr();
if (seq.Length > 0)
{
tmp = results.getProteinsWithThisPepMatch(queryNo, p, true);
hit = " ";
protein = " ";
morethan = "";
if (tmp.Length > 0)
{
if (regex.IsMatch(tmp))
{
Match OneMatch = regex.Match(tmp);
if (OneMatch.Success)
{
int groupCount = OneMatch.Groups.Count;
if (groupCount >= 2) hit = OneMatch.Groups[1].Value;
if (groupCount >= 3) protein = OneMatch.Groups[2].Value;
if (groupCount >= 4) morethan = OneMatch.Groups[3].Value;
}
}
if (morethan.Length > 0)
{
hit = hit+"+";
}
}
Console.WriteLine("{0} {1} {2} {3} {4}", pep.getIonsScore(), pep.getDelta(), hit, protein, pep.getPeptideStr());
}
}
}
p = 1;
Console.WriteLine("Accessions that matched query {0} rank {1}:- {2}", queryNo, p, results.getProteinsWithThisPepMatch(queryNo, p, false));
}
private static void displayPeptideInfo(bool showFullDetails, ms_peptide p, ms_mascotresults r, bool isDuplicate, bool isBold, bool showCheckBox)
{
int q = p.getQuery();
if (showFullDetails)
{
Console.WriteLine("Peptide hit");
if (p.getAnyMatch())
{
Console.WriteLine(" Query : {0}", q);
Console.WriteLine(" Rank : {0}", p.getRank());
Console.WriteLine(" Matched : {0}", p.getAnyMatch());
Console.WriteLine(" missedCleave: {0}", p.getMissedCleavages());
Console.WriteLine(" mrCalc : {0}", p.getMrCalc());
Console.WriteLine(" delta : {0}", p.getDelta());
Console.WriteLine(" observed : {0}", p.getObserved());
Console.WriteLine(" charge : {0}", p.getCharge());
Console.WriteLine(" mrExp : {0}", p.getMrExperimental());
Console.WriteLine(" ionsMatched : {0}", p.getNumIonsMatched());
Console.WriteLine(" peptideStr : {0}", p.getPeptideStr());
Console.WriteLine(" peaksUsed1 : {0}", p.getPeaksUsedFromIons1());
Console.WriteLine(" varModsStr : {0}", p.getVarModsStr());
Console.WriteLine(" readable mod: {0}", r.getReadableVarMods(q, p.getRank(), 2));
Console.WriteLine(" ionsScore : {0}", p.getIonsScore());
Console.WriteLine(" seriesUsedS : {0}", p.getSeriesUsedStr());
Console.WriteLine(" peaksUsed2 : {0}", p.getPeaksUsedFromIons2());
Console.WriteLine(" peaksUsed3 : {0}", p.getPeaksUsedFromIons3());
Console.WriteLine(" idth, hth, p: {0}, {1}, {2}", r.getPeptideIdentityThreshold(q, 20),
r.getHomologyThreshold(q, 20), r.getProbOfPepBeingRandomMatch(p.getIonsScore(), q));
Console.WriteLine();
}
else
{
Console.WriteLine(" No match");
}
}
else
{
if (showCheckBox) Console.Write("CB ");
else Console.Write("-- ");
if (isBold) Console.Write("BOLD ");
else Console.Write("dim ");
Console.Write(q.ToString().PadLeft(4));
Console.Write(" ");
double observed = p.getObserved();
Console.Write(" ");
Console.Write(string.Format("{0}", observed.ToString("0.000000")).PadLeft(11));
Console.Write(" ");
Console.Write(p.getRank().ToString().PadLeft(4));
Console.Write("({0})", p.getPrettyRank().ToString().PadLeft(4));
Console.Write(" ");
Console.Write(p.getPeptideStr().ToString().PadLeft(20));
Console.Write(" ");
double score = p.getIonsScore();
Console.Write(string.Format("{0}{1}{2}", (isDuplicate) ? "(" : "", score.ToString("0.00"), (isDuplicate) ? ")" : "").PadLeft(8));
Console.Write(" ");
if (r.getReadableVarMods(q, p.getRank(), 2).Length == 0) Console.WriteLine(" 0");
else
{
string let = r.getReadableVarMods(q, p.getRank(), 2).Substring(0, 1);
int iLet;
if (int.TryParse(let, out iLet))
{
Console.WriteLine(" {0}", iLet);
}
else Console.WriteLine(" 0");
}
}
}
private static bool checkErrors(ms_mascotresfilebase file)
{
for (int loop = 1; loop <= file.getNumberOfErrors(); loop++)
{
Console.WriteLine("Error number: {0} : {1}", file.getErrorNumber(loop), file.getErrorString(loop));
}
bool isValid = file.isValid();
file.clearAllErrors();
return isValid;
}
}
}