Example program converting ms_ms2quantitation to ms_customquantitation.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using matrix_science.msparser;
namespace MsParserExamples
{
class resfile_ms2quant_to_custom
{
public static int 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_ms2quant_to_custom()).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 1;
}
string sQuantSchema1Filepath = argv[0], sQuantSchema2Filepath = argv[1], sUnimodSchemaFilepath = argv[2], sResultFile = argv[3];
ms_mascotresfilebase resfile = ms_mascotresfilebase.createResfile(sResultFile);
if (!resfile.isValid())
{
Console.Error.WriteLine(resfile.getLastErrorString());
return 1;
}
dumpWarnings(resfile.getErrorHandler());
resfile.clearAllErrors();
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 1;
}
ms_peptidesummary pepsum;
{
ms_datfile datfile = new ms_datfile();
uint flags, flags2, minpeplen;
int maxhits;
double minprob, iisb;
bool usePepsum;
resfile.get_ms_mascotresults_params(datfile.getMascotOptions(), 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 1;
}
pepsum = new ms_peptidesummary(resfile, flags, minprob, maxhits, "", iisb, (int)minpeplen, "", flags2);
if (!resfile.isValid())
{
Console.Error.WriteLine(resfile.getLastErrorString());
return 1;
}
dumpWarnings(resfile.getErrorHandler());
resfile.clearAllErrors();
}
ms_ms2quantitation ms2quant = new ms_ms2quantitation(pepsum, qmethod);
if (!ms2quant.isValid())
{
Console.Error.WriteLine(ms2quant.getLastErrorString());
return 1;
}
if (ms2quant.hasIntensityNormalisation())
{
ms2quant.normaliseIntensities();
}
else if (ms2quant.hasPeptideRatioNormalisation())
{
ms2quant.normalisePeptideRatios();
}
dumpWarnings(ms2quant.getErrorHandler());
ms2quant.clearAllErrors();
ms_customquantitation customquant = new ms_customquantitation(ms2quant);
if (!customquant.isValid())
{
Console.Error.WriteLine(customquant.getLastErrorString());
return 1;
}
dumpWarnings(customquant.getErrorHandler());
customquant.clearAllErrors();
qmethod = customquant.getQuantitationMethod();
{
List<string> comps = new List<string>();
for (int i = 0; i < qmethod.getNumberOfComponents(); i++)
{
comps.Add(qmethod.getComponentByNumber(i).getName());
}
Console.WriteLine("Components: {0}", string.Join(", ", comps));
}
List<string> ratioNames = new List<string>();
for(int i = 0; i < qmethod.getNumberOfReportRatios(); i++) {
ratioNames.Add(qmethod.getReportRatioByNumber(i).getName());
}
Console.WriteLine("Report ratios: [{0}]", string.Join(", ", ratioNames));
Console.WriteLine("Protein 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.Count];
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();
return 0;
}
private static void dumpWarnings(ms_errs ms_errs)
{
for (int i = 1; i <= ms_errs.getNumberOfErrors(); i++)
{
Console.Error.WriteLine("Warning: {0}", ms_errs.getErrorString(i));
}
}
}
}