Exemple #1
0
        public static AnnotatedSpectrum TestNeo4j(IConSol console)
        {
            DBOptions dbOptions     = GetDBOptions(false, false, console);
            Samples   ProjectRatios = new Samples(@"C:\_IRIC\DATA\NB\ProjectTest_MonoAce_Spiked_19Oct.csv", 0, dbOptions);//Group 2 (all)

            Result rez = Propheus.Start(dbOptions, ProjectRatios, false, false, false);

            Database.Neo4j.ResultsToNeo4j.Export(rez);
            PeptideSpectrumMatch bestPsm = null;

            foreach (Query query in rez.queries)
            {
                foreach (PeptideSpectrumMatch psm in query.psms)
                {
                    if (psm.Peptide.Sequence.CompareTo("GK(acetylation of K)GGK(propionylation of K)GLGK(propionylation of K)GGAK(propionylation of K)R") == 0 &&
                        (bestPsm == null || bestPsm.ProbabilityScore() < query.psms[0].ProbabilityScore()))
                    {
                        bestPsm = psm;
                    }
                }
            }
            AnnotatedSpectrum aSpec = new AnnotatedSpectrum(ProjectRatios[0], bestPsm.Query.spectrum, bestPsm.Peptide);

            return(aSpec);
        }
Exemple #2
0
        public void Solve(string[] spikedRaws, string[] mixedRaws, string fastaFile, string folderToOutputTo, IConSol conSol)
        {
            dbOptions     = CreateOptions(fastaFile, folderToOutputTo, conSol);
            SpikedSamples = new Samples(dbOptions);
            for (int i = 0; i < spikedRaws.Length; i++)
            {
                SpikedSamples.Add(new Sample(i + 1, 1, 1, spikedRaws[i], spikedRaws[i], 0, ""));
            }

            //Precompute Spiked peptide identifications
            SpikedResult = Propheus.Start(dbOptions, SpikedSamples, false, false, true, false);
            SpikedResult.ExportPSMs(1, dbOptions.OutputFolder + "Identifications" + System.IO.Path.DirectorySeparatorChar + "SpikedSamplesPSMs.csv");

            MixedSamples = new Samples(dbOptions);
            for (int i = 0; i < mixedRaws.Length; i++)
            {
                MixedSamples.Add(new Sample(i + 1, 1, 1, mixedRaws[i], mixedRaws[i], 0, ""));
            }

            //Precompute Mixed peptide identifications
            mixedResult = Propheus.Start(dbOptions, MixedSamples, false, false, true, false);
            mixedResult.ExportPSMs(1, dbOptions.OutputFolder + "Identifications" + System.IO.Path.DirectorySeparatorChar + "MixedSamplesPSMs.csv");

            conSol.WriteLine("Computing gradient descents...");

            //Compute all usable spiked peptides
            characterizedPeptides = CharacterizedPrecursor.GetSpikedPrecursors(SpikedSamples, SpikedResult, dbOptions, nbMinFragments, nbMaxFragments, precision);
            ExportSpikedSampleResult(characterizedPeptides, dbOptions);

            vsCSVWriter writerCumul        = new vsCSVWriter(OutputFolder + "Results.csv");
            string      titleCombined      = "Mixed Sample,Precursor";
            string      curveStr           = "Polynomial Curve,";
            string      spikedIntensityStr = "Area under the curve,";

            foreach (double precursor in characterizedPeptides.Keys)
            {
                foreach (CharacterizedPrecursor charPrec in characterizedPeptides[precursor].Values)
                {
                    titleCombined += "," + charPrec.Peptide.Sequence + " Charge " + charPrec.Charge;

                    if (charPrec.eCurve.Coefficients != null && charPrec.eCurve.Coefficients.Length == 3)
                    {
                        curveStr += "," + charPrec.eCurve.Coefficients[0] + "x^2 + " + charPrec.eCurve.Coefficients[1] + "x" + charPrec.eCurve.Coefficients[2];
                    }
                    else
                    {
                        curveStr += ",NA";
                    }

                    spikedIntensityStr += "," + charPrec.eCurve.Area;
                }
            }
            writerCumul.AddLine(titleCombined);
            writerCumul.AddLine(curveStr);
            writerCumul.AddLine(spikedIntensityStr);

            //mixedPrecursors = new Dictionary<Sample, Dictionary<double, MixedPrecursor>>();
            mixedPrecursors = new Dictionary <Sample, List <MixedPrecursor> >();

            foreach (Sample mixedSample in MixedSamples)
            {
                mixedPrecursors.Add(mixedSample, MixedPrecursor.GetMixedPrecursors(mixedSample, mixedResult, dbOptions, characterizedPeptides));
            }

            //Get the list of precursors to characterize
            foreach (Sample mixedSample in MixedSamples)
            {
                foreach (double keyMz in characterizedPeptides.Keys)
                {
                    List <Dictionary <CharacterizedPrecursor, ElutionCurve> > listOfRatios = new List <Dictionary <CharacterizedPrecursor, ElutionCurve> >();
                    foreach (MixedPrecursor mPrec in mixedPrecursors[mixedSample])
                    {
                        if (mPrec.MZ == keyMz)
                        {
                            // Compute Max Flow for this precursor
                            Dictionary <CharacterizedPrecursor, ElutionCurve> ratios = GetRatios(characterizedPeptides, mPrec);
                            listOfRatios.Add(ratios);

                            ExportMixedSampleResult(ratios, mixedSample, mPrec, keyMz, dbOptions);
                        }
                    }

                    bool   isEmpty   = true;
                    string resultStr = vsCSV.GetFileName(mixedSample.sSDF) + "," + keyMz;
                    foreach (double precursor in characterizedPeptides.Keys)
                    {
                        foreach (CharacterizedPrecursor charPrec in characterizedPeptides[precursor].Values)
                        {
                            double cumulArea = 0.0;
                            foreach (Dictionary <CharacterizedPrecursor, ElutionCurve> ratios in listOfRatios)
                            {
                                if (ratios.ContainsKey(charPrec))
                                {
                                    cumulArea += ratios[charPrec].Area;
                                }
                            }
                            resultStr += "," + cumulArea;
                            if (cumulArea > 0)
                            {
                                isEmpty = false;
                            }
                        }
                    }
                    if (!isEmpty)
                    {
                        writerCumul.AddLine(resultStr);
                    }
                }
            }
            writerCumul.WriteToFile();

            //List Modifications
            Dictionary <Modification, double> dicOfIntensityPerMod = new Dictionary <Modification, double>();

            foreach (Sample sample in mixedPrecursors.Keys)
            {
                foreach (MixedPrecursor mP in mixedPrecursors[sample])
                {
                    foreach (CharacterizedPrecursor cP in mP.PeptideRatios.Keys)
                    {
                        if (cP.Peptide.VariableModifications != null)
                        {
                            foreach (Modification mod in cP.Peptide.VariableModifications.Values)
                            {
                                if (!dicOfIntensityPerMod.ContainsKey(mod))
                                {
                                    dicOfIntensityPerMod.Add(mod, 0.0);
                                }
                            }
                        }
                    }
                }
            }

            //Compute site occupancy for identical sequences (real positionnal isomers)
            vsCSVWriter    writerSitesOccupancy = new vsCSVWriter(OutputFolder + "Results_SiteOccupancy.csv");
            List <Protein> AllProteins          = Propheus.ReadProteomeFromFasta(fastaFile, false, dbOptions);

            foreach (Protein protein in AllProteins)
            {
                string newTitleProtein = protein.Description.Replace(',', ' ') + "," + protein.Sequence;
                for (int i = 0; i < protein.Sequence.Length; i++)
                {
                    newTitleProtein += "," + protein[i].ToString();
                }
                writerSitesOccupancy.AddLine(newTitleProtein);

                foreach (Sample mixedSample in mixedPrecursors.Keys)
                {
                    string coverage = "Coverage," + mixedSample.Name;
                    for (int i = 0; i < protein.Sequence.Length; i++)
                    {
                        double cumulSite = 0.0;
                        newTitleProtein += "," + protein[i].ToString();
                        foreach (MixedPrecursor mP in mixedPrecursors[mixedSample])
                        {
                            foreach (CharacterizedPrecursor cP in mP.PeptideRatios.Keys)
                            {
                                if (i + 1 >= cP.Peptide.StartResidueNumber && i + 1 <= cP.Peptide.EndResidueNumber)
                                {
                                    cumulSite += mP.PeptideRatios[cP].Area;
                                }
                            }
                        }
                        coverage += "," + cumulSite;
                    }
                    writerSitesOccupancy.AddLine(coverage);
                }

                foreach (Modification mod in dicOfIntensityPerMod.Keys)
                {
                    Dictionary <Sample, string> dicOfLines = new Dictionary <Sample, string>();
                    for (int i = 0; i < protein.Sequence.Length; i++)
                    {
                        foreach (Sample mixedSample in mixedPrecursors.Keys)
                        {
                            double cumulModArea = 0.0;
                            foreach (MixedPrecursor mP in mixedPrecursors[mixedSample])
                            {
                                foreach (CharacterizedPrecursor cP in mP.PeptideRatios.Keys)
                                {
                                    if (i + 1 >= cP.Peptide.StartResidueNumber && i + 1 <= cP.Peptide.EndResidueNumber &&
                                        cP.Peptide.VariableModifications != null)
                                    {
                                        foreach (int pos in cP.Peptide.VariableModifications.Keys)
                                        {
                                            if (cP.Peptide.StartResidueNumber + pos - 2 == i + 1 && cP.Peptide.VariableModifications[pos] == mod)
                                            {
                                                cumulModArea += mP.PeptideRatios[cP].Area;
                                            }
                                        }
                                    }
                                }
                            }
                            if (!dicOfLines.ContainsKey(mixedSample))
                            {
                                dicOfLines.Add(mixedSample, mod.Description + "," + mixedSample.Name + "," + cumulModArea);
                            }
                            else
                            {
                                dicOfLines[mixedSample] += "," + cumulModArea;
                            }
                        }
                    }
                    foreach (string line in dicOfLines.Values)
                    {
                        writerSitesOccupancy.AddLine(line);
                    }
                }
            }
            writerSitesOccupancy.WriteToFile();
        }
        public void Solve(string[] mixedRaws, string fastaFile, string folderToOutputTo, IConSol conSol)
        {
            dbOptions = CreateOptions(fastaFile, folderToOutputTo, conSol);

            MixedSamples = new Samples(dbOptions);
            for (int i = 0; i < mixedRaws.Length; i++)
            {
                MixedSamples.Add(new Sample(i + 1, 1, 1, mixedRaws[i], mixedRaws[i], 0, ""));
            }

            //Precompute Mixed peptide identifications
            mixedResult = Propheus.Start(dbOptions, MixedSamples, false, false, true, false);

            conSol.WriteLine("Computing gradient descents...");

            //Compute all usable spiked peptides
            characterizedPeptides = CharacterizedPrecursor.GetSpikedPrecursors(MixedSamples, mixedResult, dbOptions, nbMinFragments, nbMaxFragments, precision);
            ExportSpikedSampleResult(characterizedPeptides, dbOptions);

            vsCSVWriter writerCumul        = new vsCSVWriter(OutputFolder + "Results.csv");
            string      titleCombined      = "Mixed Sample,Precursor";
            string      curveStr           = "Polynomial Curve,";
            string      spikedIntensityStr = "Area under the curve,";

            foreach (double precursor in characterizedPeptides.Keys)
            {
                foreach (CharacterizedPrecursor charPrec in characterizedPeptides[precursor].Values)
                {
                    titleCombined += "," + charPrec.Peptide.Sequence + " Charge " + charPrec.Charge;

                    if (charPrec.eCurve.Coefficients != null && charPrec.eCurve.Coefficients.Length == 3)
                    {
                        curveStr += "," + charPrec.eCurve.Coefficients[0] + "x^2 + " + charPrec.eCurve.Coefficients[1] + "x" + charPrec.eCurve.Coefficients[2];
                    }
                    else
                    {
                        curveStr += ",NA";
                    }

                    spikedIntensityStr += "," + charPrec.eCurve.Area;
                }
            }
            writerCumul.AddLine(titleCombined);
            writerCumul.AddLine(curveStr);
            writerCumul.AddLine(spikedIntensityStr);

            //mixedPrecursors = new Dictionary<Sample, Dictionary<double, MixedPrecursor>>();
            mixedPrecursors = new Dictionary <Sample, List <MixedPrecursor> >();

            foreach (Sample mixedSample in MixedSamples)
            {
                mixedPrecursors.Add(mixedSample, MixedPrecursor.GetMixedPrecursors(mixedSample, mixedResult, dbOptions, characterizedPeptides));
            }

            //Get the list of precursors to characterize
            foreach (Sample mixedSample in MixedSamples)
            {
                foreach (double keyMz in characterizedPeptides.Keys)
                {
                    List <Dictionary <Peptide, ElutionCurve> > listOfRatios = new List <Dictionary <Peptide, ElutionCurve> >();
                    foreach (MixedPrecursor mPrec in mixedPrecursors[mixedSample])
                    {
                        if (mPrec.MZ == keyMz)
                        {
                            // Compute Max Flow for this precursor
                            Dictionary <Peptide, ElutionCurve> ratios = GetRatiosNoSpikes(mPrec, precision);
                            listOfRatios.Add(ratios);

                            ExportMixedSampleResult(ratios, mixedSample, mPrec, keyMz, dbOptions);
                        }
                    }

                    /*
                     * string resultStr = vsCSV.GetFileName(mixedSample.sSDF) + "," + keyMz;
                     * foreach (double precursor in characterizedPeptides.Keys)
                     * {
                     *  foreach (Peptide charPrec in characterizedPeptides[precursor].Values)
                     *  {
                     *      double cumulArea = 0.0;
                     *      foreach (Dictionary<Peptide, ElutionCurve> ratios in listOfRatios)
                     *          if (ratios.ContainsKey(charPrec))
                     *              cumulArea += ratios[charPrec].Area;
                     *      resultStr += "," + cumulArea;
                     *  }
                     * }
                     * writerCumul.AddLine(resultStr);//*/
                }
            }
            writerCumul.WriteToFile();
        }