Example program extracting peptide ratios from a Reporter or Multiplex file.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using matrix_science.msparser;
namespace MsParserExamples
{
class resfile_ms2quantitation
{
public static void Main(string[] argv)
{
if (argv.Length < 4)
{
Console.Error.WriteLine("Usage: {0} <quantitation schema 1 filepath> <quantitation schema 2 filepath> <unimod schema filepath> <results file>", Path.GetFileName((new resfile_ms2quantitation()).GetType().Assembly.Location));
Console.Error.WriteLine(@"The location of schema files should be e.g.
../html/xmlns/schema/quantitation_1/quantitation_1.xsd
../html/xmlns/schema/quantitation_2/quantitation_2.xsd
../html/xmlns/schema/unimod_2/unimod_2.xsd
if running from the Mascot cgi directory.");
return;
}
string sQuantSchema1Filepath = argv[0], sQuantSchema2Filepath = argv[1], sUnimodSchemaFilepath = argv[2], sResultFile = argv[3];
ms_mascotresfilebase resfile = ms_mascotresfilebase.createResfile(sResultFile, 0);
if (!resfile.isValid())
{
Console.Error.WriteLine(resfile.getLastErrorString());
return;
}
resfile.setXMLschemaFilePath(ms_mascotresfilebase.XML_SCHEMA.XML_SCHEMA_QUANTITATION, "http://www.matrixscience.com/xmlns/schema/quantitation_2 " +
sQuantSchema2Filepath + " http://www.matrixscience.com/xmlns/schema/quantitation_1 " + sQuantSchema1Filepath);
resfile.setXMLschemaFilePath(ms_mascotresfilebase.XML_SCHEMA.XML_SCHEMA_UNIMOD, "http://www.unimod.org/xmlns/schema/unimod_2 " + sUnimodSchemaFilepath);
ms_quant_method qMethod = new ms_quant_method();
if (!resfile.getQuantitationMethod(qMethod))
{
Console.Error.WriteLine(resfile.getLastErrorString());
return;
}
ms_peptidesummary pepsum;
if (!loadPeptideSummary(resfile, out pepsum))
{
return;
}
ms_ms2quantitation ms2quant = new ms_ms2quantitation(pepsum, qMethod);
if (!ms2quant.isValid())
{
Console.Error.WriteLine(ms2quant.getLastErrorString());
return;
}
if (ms2quant.hasIntensityNormalisation())
{
ms2quant.normaliseIntensities();
}
else if (ms2quant.hasPeptideRatioNormalisation())
{
ms2quant.normalisePeptideRatios();
}
qMethod = ms2quant.getQuantitationMethod();
dumpWarnings(ms2quant.getErrorHandler());
ms2quant.clearAllErrors();
{
string[] comps = new string[qMethod.getNumberOfComponents()];
for (int i = 0; i < comps.Length; i++)
{
comps[i] = qMethod.getComponentByNumber(i).getName();
}
Console.WriteLine("Components: [{0}]", string.Join(", ", comps));
}
string[] ratioNames = new string[qMethod.getNumberOfReportRatios()];
for (int i = 0; i < ratioNames.Length; i++)
{
ratioNames[i] = qMethod.getReportRatioByNumber(i).getName();
}
Console.WriteLine("Report ratios [{0}]", string.Join(", ", ratioNames));
Console.WriteLine("Report ratio type = {0}", qMethod.getProteinRatioType());
Console.WriteLine("Min. number of peptides = {0}", qMethod.getMinNumPeptides());
if (qMethod.haveQuality())
{
ms_quant_quality q = qMethod.getQuality();
Console.WriteLine("Quality: min. precursor charge = {0}", q.getMinPrecursorCharge());
Console.WriteLine("Quality: pep. threshold type = {0}", q.getPepThresholdType());
Console.WriteLine("Quality: pep. threshold value = {0}", q.getPepThresholdValue());
}
else
{
Console.WriteLine("Quality: no restrictions");
}
if (qMethod.haveNormalisation())
{
ms_quant_normalisation _n = qMethod.getNormalisation();
Console.WriteLine("Normalisation = {0}", _n.getMethod());
if (_n.haveProteins())
{
ms_quant_normalisation_proteins _p = _n.getProteins();
StringBuilder sbJoin = new StringBuilder();
for (int i = 0; i < _p.getNumberOfProteins(); i++)
{
if (i > 0) sbJoin.Append(", ");
sbJoin.Append(_p.getProtein(i).getAccession());
}
Console.WriteLine(" - Accessions = {0}", sbJoin);
}
if (_n.havePeptides())
{
ms_quant_normalisation_peptides _p = _n.getPeptides();
StringBuilder sbJoin = new StringBuilder();
for (int i = 0; i < _p.getNumberOfPeptides(); i++)
{
if (i > 0) sbJoin.Append(", ");
sbJoin.Append(_p.getPeptide(i).getSequence());
}
Console.WriteLine(" - Sequences = {0}", sbJoin);
}
double[] intensityComponentBases = new double[qMethod.getNumberOfComponents()];
for (int i = 0; i < qMethod.getNumberOfComponents(); i++)
{
intensityComponentBases[i] = ms2quant.getIntensityNormalisationBase(qMethod.getComponentByNumber(i).getName());
}
double[] ratioComponentBases = new double[ratioNames.Length];
for (int i = 0; i < ratioComponentBases.Length; i++)
{
ratioComponentBases[i] = ms2quant.getPeptideRatioNormalisationBase(ratioNames[i]);
}
Console.WriteLine("Intensity normalisation constants: [{0}]", string.Join(", ", intensityComponentBases));
Console.WriteLine("Ratio normalisation constants: [{0}]", string.Join(", ", ratioComponentBases));
}
else
{
Console.WriteLine("Normalisation: none");
}
if (qMethod.haveOutliers())
{
Console.WriteLine("Outliers = {0}", qMethod.getOutliers().getMethod());
}
else
{
Console.WriteLine("Outliers: none");
}
Console.WriteLine();
List<ms_protein> proteins = new List<ms_protein>();
for (int i = 1; i <= pepsum.getNumberOfHits(); i++)
{
proteins.Add(pepsum.getHit(i));
int j = 0;
ms_protein protein;
while ((protein = pepsum.getNextFamilyProtein(i, ++j)) != null)
{
proteins.Add(protein);
}
}
foreach (ms_protein protein in proteins)
{
Console.WriteLine("{0}::{1}", protein.getDB(), protein.getAccession());
foreach (string rationame in ratioNames)
{
ms_protein_quant_ratio ratio = ms2quant.getProteinRatio(protein.getAccession(), protein.getDB(), rationame);
if (ratio.isMissing())
{
Console.WriteLine("{0}: ---", rationame.PadLeft(10));
}
else
{
Console.WriteLine("{0} = {1}, stderr = {2}, n = {3} normal-p = {4}, hypo-p = {5}",
rationame, ratio.getValue(), ratio.getStandardError(),
ratio.getSampleSize(), ratio.getNormalityPvalue(),
ratio.getHypothesisPvalue()
);
}
ratio.Dispose();
ratio = null;
}
Console.WriteLine();
StringBuilder sbHeader = new StringBuilder();
sbHeader.Append("Peptide".PadRight(11));
foreach (string rationame in ratioNames)
{
sbHeader.Append(" ").Append(rationame.PadRight(9));
}
Console.WriteLine(sbHeader);
for (int i = 1; i <= protein.getNumPeptides(); i++)
{
if (protein.getPeptideDuplicate(i) == ms_protein.DUPLICATE.DUPE_DuplicateSameQuery) continue;
int q = protein.getPeptideQuery(i), p = protein.getPeptideP(i);
ms_peptide peptide = pepsum.getPeptide(q, p);
if (peptide == null) continue;
List<string> aValues = new List<string>();
foreach (string rationame in ratioNames)
{
ms_peptide_quant_ratio ratio = ms2quant.getPeptideRatio(new ms_peptide_quant_key(q, p), rationame);
if (ratio.isMissing())
{
aValues.Add("---".PadRight(9));
continue;
}
if (ratio.isInfinite())
{
aValues.Add("###".PadRight(9));
}
else
{
string sValue = ratio.getValue().ToString("0.####").PadRight(9);
aValues.Add(sValue);
}
}
Console.WriteLine("{0} {1}", string.Format("q{0}_p{1}", q, p).PadRight(11), string.Join(" ", aValues));
}
Console.WriteLine();
}
pepsum.getNumberOfHits();
resfile._params();
}
private static void dumpWarnings(ms_errs ms_errs)
{
for (int i = 0; i < ms_errs.getNumberOfErrors(); i++)
{
Console.WriteLine("Warning: {0}", ms_errs.getErrorString(i));
}
}
private static bool loadPeptideSummary(ms_mascotresfilebase resfile, out ms_peptidesummary pepsum)
{
pepsum = null;
ms_mascotoptions opts = new ms_mascotoptions();
uint flags, flags2, minpeplen;
int maxhits;
double minprob, iisb;
bool usePepsum;
resfile.get_ms_mascotresults_params(opts, out flags, out minprob, out maxhits, out iisb, out minpeplen, out usePepsum, out flags2);
if (!usePepsum)
{
Console.Error.WriteLine("Results file cannot be opened as a peptide summary");
return false;
}
pepsum = new ms_peptidesummary(resfile, flags, minprob, maxhits, "", iisb, (int)minpeplen, "", flags2);
if (!resfile.isValid())
{
Console.Error.WriteLine(resfile.getLastErrorString());
return false;
}
return true;
}
}
}