Testing peptides for quantifiability.
using System;
using System.IO;
using System.Collections.Generic;
using matrix_science.msparser;
namespace MsParserExamples
{
class tools_quant_helper
{
private const string QUANT_SCHEMA = @"http://www.matrixscience.com/xmlns/schema/quantitation_2 ../html/xmlns/schema/quantitation_2/quantitation_2.xsd http://www.matrixscience.com/xmlns/schema/quantitation_1 ../html/xmlns/schema/quantitation_1/quantitation_1.xsd", UNIMOD_SCHEMA = @"http://www.unimod.org/xmlns/schema/unimod_2 ../html/xmlns/schema/unimod_2/unimod_2.xsd";
public static int Main(string[] argv)
{
if (argv.Length == 0)
{
Console.Error.WriteLine("Usage: {0} <quantitation results.dat>", Path.GetFileName((new tools_quant_helper()).GetType().Assembly.Location));
return 1;
}
ms_mascotresfilebase resfile = ms_mascotresfilebase.createResfile(argv[0]);
if (!resfile.isValid())
{
Console.Error.WriteLine(resfile.getLastErrorString());
return 1;
}
ms_quant_configfile quantConfigFile;
ms_quant_method qmethod;
ms_peptidesummary pepSum;
if (!loadMethod(resfile, out quantConfigFile, out qmethod)) return 1;
ms_umod_configfile umodfile = null;
if (!loadUmodConfigFile(resfile, out umodfile)) return 1;
if (!loadPeptideSummary(resfile, out pepSum)) return 1;
ms_quant_helper quantHelper = new ms_quant_helper(pepSum, qmethod, umodfile);
if (!quantHelper.isValid())
{
Console.WriteLine("ms_quant_helper is not value: {0}", quantHelper.getLastErrorString());
return 1;
}
List<ms_protein> proteins = pullProteinsFrom(pepSum);
Console.WriteLine("File {0} uses {1} and has {2} family proteins", argv[0], qmethod.getName(), proteins.Count);
dumpQuantMethod(qmethod);
Console.WriteLine();
Dictionary<int, string> peptideQuantStr = new Dictionary<int, string>()
{
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_HAS_EXCLUDED_FIXEDMOD, "PEPTIDE_HAS_EXCLUDED_FIXEDMOD"},
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_HAS_EXCLUDED_LOCAL_FIXEDMOD, "PEPTIDE_HAS_EXCLUDED_LOCAL_FIXEDMOD"},
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_HAS_EXCLUDED_LOCAL_VARMOD, "PEPTIDE_HAS_EXCLUDED_LOCAL_VARMOD"},
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_HAS_EXCLUDED_VARMOD, "PEPTIDE_HAS_EXCLUDED_VARMOD"},
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_HAS_NO_REQUIRED_FIXEDMOD, "PEPTIDE_HAS_NO_REQUIRED_FIXEDMOD"},
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_HAS_NO_REQUIRED_VARMOD, "PEPTIDE_HAS_NO_REQUIRED_VARMOD"},
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_HAS_UNMODIFIED_SITE, "PEPTIDE_HAS_UNMODIFIED_SITE"},
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_IS_QUANTIFIABLE, "PEPTIDE_IS_QUANTIFIABLE"},
{(int) ms_quant_helper.PEPTIDE_QUANTIFIABILITY.PEPTIDE_QUANTIFIABILITY_UNAVAILABLE, "PEPTIDE_QUANTIFIABILITY_UNAVAILABLE"}
};
Dictionary<int, string> peptideQualityStr = new Dictionary<int, string>()
{
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_EXPECT_ABOVE_THRESHOLD, "PEPTIDE_EXPECT_ABOVE_THRESHOLD"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_CHARGE_BELOW_PRECURSOR_MIN, "PEPTIDE_CHARGE_BELOW_PRECURSOR_MIN"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_HAS_NO_EXCLUSIVE_MODS, "PEPTIDE_HAS_NO_EXCLUSIVE_MODS"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_NOT_UNIQUE, "PEPTIDE_NOT_UNIQUE"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_QUALITY_IS_OK, "PEPTIDE_QUALITY_IS_OK"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_QUALITY_UNAVAILABLE, "PEPTIDE_QUALITY_UNAVAILABLE"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_SCORE_BELOW_HOMOLOGY_THR, "PEPTIDE_SCORE_BELOW_HOMOLOGY_THR"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_SCORE_BELOW_IDENTITY_THR, "PEPTIDE_SCORE_BELOW_IDENTITY_THR"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_SCORE_BELOW_IDENTITY_THR_NOHOM, "PEPTIDE_SCORE_BELOW_IDENTITY_THR_NOHOM"},
{(int) ms_quant_helper.PEPTIDE_QUALITY.PEPTIDE_SCORE_BELOW_SCORE_THR, "PEPTIDE_SCORE_BELOW_SCORE_THR"}
};
foreach (ms_protein protein in proteins)
{
Console.WriteLine("Protein {0}::{1}", protein.getDB(), protein.getAccession());
for (int i = 1; i <= protein.getNumPeptides(); i++)
{
int q = protein.getPeptideQuery(i), p = protein.getPeptideP(i);
ms_peptide peptide = pepSum.getPeptide(q, p);
if (peptide == null) continue;
{
string reason;
int ok = quantHelper.isPeptideQuantifiable(q, p, protein, i, out reason);
Console.WriteLine("\tq{0}_p{1} quantifiable? {2} ({3})", q, p, peptideQuantStr[ok], (string.IsNullOrEmpty(reason) ? "" : reason));
}
{
string reason;
int ok = quantHelper.isPeptideQualityOK(q, p, out reason);
Console.WriteLine("\tq{0}_p{1} quality? {2} ({3})", q, p, peptideQualityStr[ok], (string.IsNullOrEmpty(reason) ? "" : reason));
}
}
}
pepSum.getNumberOfHits();
resfile._params();
return 0;
}
private static void dumpQuantMethod(ms_quant_method qmethod)
{
{
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));
}
Console.WriteLine("Protein ratio type = {0}", qmethod.getProteinRatioType());
Console.WriteLine("Min. number of peptides = {0}", qmethod.getMinNumPeptides());
if (qmethod.haveQuality())
{
var 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())
{
var q = qmethod.getNormalisation();
Console.WriteLine("Normalisation = {0}", q.getMethod());
}
else
{
Console.WriteLine("Normalisation: none");
}
if (qmethod.haveOutliers())
{
var q = qmethod.getOutliers();
Console.WriteLine("Outliers = {0}", q.getMethod());
}
else
{
Console.WriteLine("Outliers: none");
}
}
private static List<ms_protein> pullProteinsFrom(ms_peptidesummary pepsum)
{
List<ms_protein> proteins = new List<ms_protein>();
for (int i = 1; i <= pepsum.getNumberOfHits(); i++)
{
ms_protein hit = pepsum.getHit(i);
proteins.Add(hit);
int j = 0;
ms_protein protein;
while((protein = pepsum.getNextFamilyProtein(i, ++j)) != null) {
proteins.Add(protein);
}
}
return proteins;
}
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;
}
private static bool loadUmodConfigFile(ms_mascotresfilebase resfile, out ms_umod_configfile umodfile)
{
umodfile = new ms_umod_configfile();
umodfile.setSchemaFileName(UNIMOD_SCHEMA);
if (!resfile.getUnimod(umodfile))
{
Console.Error.WriteLine("Result file does not have a Unimod section");
return false;
}
if (!umodfile.isValid())
{
Console.Error.WriteLine("Unimod file is not value: {0}", umodfile.getLastErrorString());
return false;
}
string str = umodfile.validateDocument();
if (str.Length > 0)
{
Console.Error.WriteLine("Unimod file does not validate: {0}", str);
return false;
}
return true;
}
private static bool loadMethod(ms_mascotresfilebase resfile, out ms_quant_configfile quantConfigFile, out ms_quant_method qmethod)
{
quantConfigFile = null;
qmethod = null;
string quantMethodName = resfile._params().getQUANTITATION();
if (quantMethodName == null || quantMethodName.Length == 0 || quantMethodName.Equals("none", StringComparison.OrdinalIgnoreCase))
{
Console.Error.WriteLine("File has no quantitation method");
return false;
}
quantConfigFile = new ms_quant_configfile();
quantConfigFile.setSchemaFileName(QUANT_SCHEMA);
if (!resfile.getQuantitation(quantConfigFile))
{
Console.Error.WriteLine("File has no quantitation method: {0}", resfile.getLastErrorString());
return false;
}
if (!quantConfigFile.isValid())
{
Console.Error.WriteLine("Quantitation file is not valid: {0}", quantConfigFile.getLastErrorString());
return false;
}
string str = quantConfigFile.validateDocument();
if (str.Length > 0)
{
Console.Error.WriteLine("Quantitation file does not validate: {0}", str);
return false;
}
qmethod = quantConfigFile.getMethodByName(quantMethodName);
if (qmethod == null)
{
Console.Error.WriteLine("Quantitation file has no method called: '{0}'", quantMethodName);
return false;
}
return true;
}
}
}