using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using matrix_science.msparser;
using System.Numerics;
using static matrix_science.msparser.ms_imputation;
namespace MsParserExamples
{
class tools_imputation
{
public static void Main(string[] args)
{
List<string[]> propsCsv = new List<string[]>();
using (var reader = new StreamReader(@"C:/MSData/Quantitation/ReadingReplicate6/tPeptidesHit9Props.csv"))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
for (int i = 0; i < values.Length; i++)
{
if (values[i].Length == 1)
{
values[i] = values[i].Substring(1, values[i].Length - 1);
}
else
{
values[i] = values[i].Substring(1, values[i].Length - 2);
}
}
propsCsv.Add(values);
}
}
string[] datFilePaths = new string[] { propsCsv[7][1], propsCsv[7][2], propsCsv[7][3], propsCsv[7][4], propsCsv[7][5], propsCsv[7][6] };
string mascotDotDatPath = propsCsv[1][3];
string cdbPath = propsCsv[6][3];
string cachePath = propsCsv[6][4];
string xmlPath = propsCsv[6][propsCsv[6].Count() - 2];
string resCachePath = propsCsv[6].Last();
string quantSchema = "http://www.matrixscience.com/xmlns/schema/quantitation_2 " + @"file:///C:\\ProgramData\\Matrix%20Science\\Mascot%20Distiller\\schema\\quantitation_2.xsd" + " http://www.matrixscience.com/xmlns/schema/quantitation_1 " + @"file:///C:\ProgramData\Matrix%20Science\Mascot%20Distiller\schema\quantitation_1.xsd";
string unimodSchema = "http://www.unimod.org/xmlns/schema/unimod_2 " + @"file:///C:\ProgramData\Matrix%20Science\Mascot%20Distiller\schema\unimod_2.xsd";
ms_mascotresfilebase resFile = ms_mascotresfilebase.createResfile(datFilePaths[0], 0, "<!-- %d seconds-->\n", (uint)ms_mascotresfilebase.FLAGS.RESFILE_USE_CACHE, resCachePath);
resFile.setXMLschemaFilePath(ms_mascotresfilebase.XML_SCHEMA.XML_SCHEMA_QUANTITATION, quantSchema);
resFile.setXMLschemaFilePath(ms_mascotresfilebase.XML_SCHEMA.XML_SCHEMA_UNIMOD, unimodSchema);
for (int i = 1; i < datFilePaths.Length; i++)
{
resFile.appendResfile(datFilePaths[i]);
}
ms_datfile mascotDotDat = new ms_datfile(mascotDotDatPath);
resFile.setPercolatorFeatures(mascotDotDat.getMascotOptions(), "");
ms_mascotoptions opts = new ms_mascotoptions();
ms_mascotresults_params resParams = new ms_mascotresults_params();
string returnVals = resFile.get_ms_mascotresults_params(opts, resParams);
ms_peptidesummary pepSum = new ms_peptidesummary(resFile, resParams);
ms_quant_method qMethod = new ms_quant_method();
ms_quant_configfile qConfigFile = new ms_quant_configfile(xmlPath, quantSchema);
qMethod = qConfigFile.getMethodByNumber(0);
ms_quant_protocol quantProtocol = qMethod.getProtocol();
string typeStr = quantProtocol.getType();
ms_ms1quantitation ms1Quant = new ms_ms1quantitation(pepSum, qMethod);
bool loadQuant = ms1Quant.loadCdbFile(cdbPath, cachePath, false);
ms_imputation_knn knnImputation = new ms_imputation_knn();
knnImputation.setKnnNumNeighbours(5);
knnImputation.setKnnUseWeightedAverage(true);
ms_imputation ImputationKnn = new ms_imputation(ms1Quant, knnImputation, IMPUTATION_VARIABLE.IMPUTE_PEPTIDE_RATIO);
ImputationKnn.setImputeMs1PeptideExcludedByStdErrThr(true);
VecVecdouble imputationResKnn = ImputationKnn.impute();
VecVecMissingValue imputationRaw = knnImputation.getDataWithMissing();
Console.WriteLine("=/=/=/=/= READING6 HIT9 RAW PEPTIDE RATIOS =/=/=/=/=");
Console.WriteLine("=/=/=/=/= STD ERR THRESHOLD SET TO 0.1 =/=/=/=/=");
for (int i = 0; i < imputationRaw.Count; i++)
{
string tempStr = "";
for (int j = 0; j < imputationRaw[i].Count; j++)
{
if (imputationRaw[i][j].isMissing())
{
tempStr += "MissVal,";
}
else
{
tempStr += Math.Round(imputationRaw[i][j].getVal(), 5) + ",";
}
}
Console.WriteLine(tempStr);
}
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("=/=/=/=/= KNN IMPUTED PEPTIDE RATIOS =/=/=/=/=");
Console.WriteLine("=/=/= NB: KNN DOES NOT IMPUTE BLANK ROWS =/=/=");
for (int i = 0; i < imputationResKnn.Count; i++)
{
string tempStr = "";
for (int j = 0; j < imputationResKnn[i].Count; j++)
{
tempStr += Math.Round(imputationResKnn[i][j], 5).ToString() + ",";
}
Console.WriteLine(tempStr);
}
ms_imputation_missforest missForestImputation = new ms_imputation_missforest();
ms_imputation ImputationMissForest = new ms_imputation(ms1Quant, missForestImputation, IMPUTATION_VARIABLE.IMPUTE_PEPTIDE_RATIO);
ImputationMissForest.setImputeMs1PeptideExcludedByStdErrThr(true);
VecVecdouble imputationMissForestRes = ImputationMissForest.impute();
Console.WriteLine("");
Console.WriteLine("");
Console.WriteLine("=/=/=/=/= MISS FOREST IMPUTED PROTEIN RATIOS =/=/=/=/=");
Console.WriteLine("=/=/=/= NB: MISS FOREST HAS IMPUTED BLANK ROWS =/=/=/=");
for (int i = 0; i < imputationMissForestRes.Count; i++)
{
string tempStr = "";
for (int j = 0; j < imputationMissForestRes[i].Count; j++)
{
tempStr += Math.Round(imputationMissForestRes[i][j], 5).ToString() + ",";
}
Console.WriteLine(tempStr);
}
}
}
}