Example #1
0
        public static void Uptimize()
        {
            string    fastaFile = @"C:\_IRIC\Data\NB\peptide.fasta";
            DBOptions dbOptions = PositionnalIsomerSolver.CreateOptions(fastaFile, @"C:\_IRIC\Data\NB\Units2\", 8, 0.05, new PeptidAce.Utilities.Interfaces.ConSolCommandLine());

            dbOptions.dProduct   = 0.0917981081138356;
            dbOptions.dPrecursor = 0.345789190542786;
            dbOptions.dMatchingProductFraction = 0.427418045898628;
            dbOptions.dMatchingProduct         = 0;
            dbOptions.dIntensityFraction       = 0.429418127252449;
            dbOptions.dIntensity     = 0;
            dbOptions.dProtein       = 0.692270441303156;
            dbOptions.dPeptideScore  = 0.636739763262095;
            dbOptions.dFragmentScore = 0.0229058195943506;

            dbOptions.fullFragment = new FullFragments(true);
            string  project = @"C:\_IRIC\Data\NB\ProjectTest_AllAce_Spiked_QEPlus_Apr21.csv";
            Samples samples = new Samples(project, 0, dbOptions);

            Uptimizer.Run(samples, dbOptions);

            dbOptions.Save(dbOptions.OutputFolder + "UptimizedOptions.csv");
        }
Example #2
0
        private double GetNbTimesFit(DBOptions dbOptions, int nbProductsToKeep, double precision, out double area)
        {
            long   nbRatios = 0;
            double nbTimes  = 0;

            area = 0.0;
            List <CharacterizedPrecursor> Isomers = new List <CharacterizedPrecursor>();

            Isomers.Add(this);

            ElutionCurve curve = new ElutionCurve();

            foreach (Query query in this.Queries)
            {
                //double overFlow = 0;
                double underFlow    = 0;
                double percentError = 0;
                Dictionary <CharacterizedPrecursor, PositionnalIsomerSolver.SolvedResult> finalRatios = PositionnalIsomerSolver.SolveFromSpectrum(Isomers, nbProductsToKeep, precision, query.spectrum.Peaks, dbOptions.productMassTolerance,
                                                                                                                                                  query.spectrum.PrecursorIntensityPerMilliSecond * query.spectrum.InjectionTime, out underFlow, out percentError, dbOptions.ConSole);

                if (percentError < 0.5)
                {
                    curve.AddPoint(query.spectrum.RetentionTimeInMin * 1000.0 * 60.0, finalRatios[this].Ratio * query.spectrum.PrecursorIntensityPerMilliSecond);
                    nbTimes += finalRatios[this].NbFitTimes;
                    nbRatios++;
                }
            }
            if (nbRatios > 2 && curve.GetNbPoints() > this.Queries.Count * 0.5)
            {
                curve.Compute();
                if (curve.Area > 0)
                {
                    area = curve.Area;
                }
            }
            return(nbTimes / (double)nbRatios);
        }
        public void OnNavigatedTo(NavigationEventArgs e)
        {
            //if (!isUpToDate)
            if (solverPTR != PepIso.solver)
            {
                solverPTR = PepIso.solver;
                // isUpToDate = true;
                ModernTabList.Links.Clear();
                ModernTabList.SelectedSource = null;
                Dictionary <string, string> parameters = GetParams(e.Source.OriginalString);
                if (parameters.ContainsKey("Sample"))
                {
                    string sampleName = parameters["Sample"];
                    foreach (double mzKey in solverPTR.characterizedPeptides.Keys)
                    {
                        if (solverPTR.characterizedPeptides[mzKey].Count > 0)
                        {
                            //Mixed Deconvoluted curves
                            foreach (Sample sample in solverPTR.characterizedPeptides[mzKey].Keys)
                            //foreach (Sample sample in PepIso.solver.characterizedPeptides.Keys)
                            {
                                string name = sample.Name;
                                if (name.CompareTo(sampleName) == 0)
                                {
                                    //bool found = false;
                                    //foreach (MixedPrecursor mp in PepIso.solver.mixedPrecursors[sample])
                                    //    if (mp.MZ == mzKey && mp.PeptideRatios.Count > 0)
                                    //        found = true;
                                    //if (found)
                                    {
                                        Uri source = new Uri("/Content/ResultsPeptides.xaml?mzKey=" + mzKey.ToString() + "&Sample=" + name, UriKind.Relative);
                                        ModernTabList.Links.Add(new Link
                                        {
                                            DisplayName = ((float)mzKey).ToString(),
                                            Source      = source
                                        });
                                        if (ModernTabList.SelectedSource == null)
                                        {
                                            ModernTabList.SelectedSource = source;
                                        }
                                    }
                                    break;
                                }
                            }

                            //Mixed Results

                            /*foreach (Sample sample in PepIso.solver.mixedPrecursors.Keys)
                             * {
                             *  string name = sample.Name;
                             *  ModernTabList.Links.Add(new Link
                             *  {
                             *      DisplayName = name + " Curves",
                             *      Source = new Uri("/Content/ResultsMixed.xaml?mzKey=" + mzKey + "&Sample=" + name, UriKind.Relative)
                             *  });
                             * }//*/
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Computes a curve [precursor observed intensity ; correction so that precursor computed intensity from fragments matches observed intensity]
        /// </summary>
        /// <param name="dbOptions"></param>
        /// <param name="nbProductsToKeep"></param>
        /// <returns></returns>
        private ElutionCurve GetNormalizingCurve(DBOptions dbOptions, int nbProductsToKeep)
        {
            List <CharacterizedPrecursor> Isomers = new List <CharacterizedPrecursor>();

            Isomers.Add(this);

            ElutionCurve curve = new ElutionCurve();

            foreach (Query query in this.Queries)
            {
                double timeInMilliSeconds = query.spectrum.RetentionTimeInMin * 60.0 * 1000.0;

                double underFlow    = 0;
                double percentError = 0;
                double intInTrap    = query.spectrum.PrecursorIntensityPerMilliSecond * query.spectrum.InjectionTime;
                Dictionary <CharacterizedPrecursor, PositionnalIsomerSolver.SolvedResult> finalRatios = PositionnalIsomerSolver.SolveFromSpectrum(Isomers, nbProductsToKeep, query.spectrum.Peaks, dbOptions.productMassTolerance,
                                                                                                                                                  intInTrap, query.spectrum.PrecursorIntensity,
                                                                                                                                                  out underFlow, out percentError, dbOptions.ConSole);

                if (percentError < 0.5 && finalRatios[this].NbFitTimes > 0)
                {
                    double ratio = intInTrap / finalRatios[this].NbFitTimes;
                    if (ratio > 0.5 && ratio < 2)
                    {
                        curve.AddPoint(intInTrap, intInTrap / finalRatios[this].NbFitTimes);
                    }
                }
            }
            curve.Compute(CurveType.LINEAR, true);
            return(curve);
        }
Example #5
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            if (conSol == null)
            {
                conSol = new ConSolBasic(AddTextOutput);
            }


            //PeptidAce.Iso.UnitTests.StatsMaker.ProjectMerge(conSol);
            //PeptidAce.Iso.UnitTests.PisTest.Uptimize();

            if (ButtonRun.IsEnabled && CheckParams())
            {
                ButtonRun.IsEnabled = false;
                TextConsol.Text     = "Launching Peptide Isomer solver ... ";

                runningTask = new Task(() =>
                {
                    PositionnalIsomerSolver newSolver = new PositionnalIsomerSolver();
                    try
                    {
                        newSolver.precTolPpm     = precursorMassTolPPm;
                        newSolver.prodTolDa      = productMassTolPPm;
                        newSolver.nbMinFragments = nbMinFragments;
                        newSolver.nbMaxFragments = nbMaxFragments;
                        newSolver.Solve(peptideFiles, mixedFiles, fastaFile, Utilities.vsCSV.GetFolder(mixedFiles[0]), conSol);

                        solver = newSolver;
                    }
                    catch (Exception ex)
                    {
                        AddTextOutput(ex.Message);
                        AddTextOutput(ex.StackTrace);
                    }

                    try
                    {
                        ButtonRun.Dispatcher.Invoke(
                            System.Windows.Threading.DispatcherPriority.Normal,
                            new Action(
                                delegate()
                        {
                            ButtonRun.IsEnabled = true;
                            AddTextOutput("\nDone! Your results are available in 'csv' files in these folders :\n" +
                                          "\n" + Utilities.vsCSV.GetFolder(mixedFiles[0]) + "Identifications" +
                                          "\n" + Utilities.vsCSV.GetFolder(mixedFiles[0]) + "Combined" +
                                          "\n" + Utilities.vsCSV.GetFolder(mixedFiles[0]) + "Individual");

                            ModernUI.Pages.Home.UpdateLinks(newSolver.SpikedSamples, newSolver.mixedPrecursors);
                        }
                                ));
                    }
                    catch (Exception ex)
                    {
                        AddTextOutput(ex.Message);
                        AddTextOutput(ex.StackTrace);
                    }
                });
                runningTask.Start();
            }
        }
Example #6
0
        public static void ProjectMerge(PeptidAce.Utilities.Interfaces.IConSol console)
        {
            string    strProjectAll = @"C:\_IRIC\Data\NB\ProjectFile_EverythingReplicates_Oct.csv";
            string    project       = @"C:\_IRIC\Data\NB\ProjectTest_AllAce_Spiked_19Oct.csv";
            string    fastaFile     = @"C:\_IRIC\Data\NB\peptide.fasta";
            DBOptions options       = PositionnalIsomerSolver.CreateOptions(fastaFile, @"C:\_IRIC\Data\NB\Units\", 8, 0.05, console);
            Samples   samplesMixed  = new Samples(strProjectAll, 0, options);
            Samples   samplesSynth  = new Samples(project, 0, options);

            PositionnalIsomerSolver newSolver = new PositionnalIsomerSolver();

            newSolver.precTolPpm     = 15;
            newSolver.prodTolDa      = 0.05;
            newSolver.nbMinFragments = 5;
            newSolver.nbMaxFragments = 5;

            string[] synths = new string[samplesSynth.Count];
            for (int i = 0; i < synths.Length; i++)
            {
                synths[i] = samplesSynth[i].sSDF;
            }

            string[] mixed = new string[samplesMixed.Count];
            for (int i = 0; i < mixed.Length; i++)
            {
                mixed[i] = samplesMixed[i].sSDF;
            }

            newSolver.Solve(synths, mixed, fastaFile, Utilities.vsCSV.GetFolder(mixed[0]), options.ConSole);

            //Precompute Spiked peptide identifications
            Result SpikedResult = Ace.Start(options, samplesSynth, false, false);

            Result mixedResult = Ace.Start(options, samplesMixed, false, false);

            //Compute all usable spiked peptides
            Dictionary <double, Dictionary <Sample, CharacterizedPrecursor> > characterizedPeptides = CharacterizedPrecursor.GetSpikedPrecursors(samplesSynth, SpikedResult, options, newSolver.nbMinFragments, newSolver.nbMaxFragments);

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

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

            Dictionary <Sample, List <Dictionary <CharacterizedPrecursor, MaxFlowElutionCurve> > > results = new Dictionary <Sample, List <Dictionary <CharacterizedPrecursor, MaxFlowElutionCurve> > >();

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

                            if (!results.ContainsKey(mixedSample))
                            {
                                results.Add(mixedSample, new List <Dictionary <CharacterizedPrecursor, MaxFlowElutionCurve> >());
                            }
                            results[mixedSample].Add(ratios);
                        }
                    }
                }
            }

            List <CharacterizedPrecursor> precursors = new List <CharacterizedPrecursor>();

            foreach (Dictionary <Sample, CharacterizedPrecursor> dic in characterizedPeptides.Values)
            {
                foreach (CharacterizedPrecursor cP in dic.Values)
                {
                    precursors.Add(cP);
                }
            }

            //Create average of each characterized peptide plus standard deviance
            vsCSVWriter writerArea = new vsCSVWriter(@"C:\_IRIC\Data\NB\Merge\stats_Area.csv");

            string lineC = "Count,";

            foreach (CharacterizedPrecursor cP in precursors)
            {
                lineC += cP.Peptide.Sequence + ",";
            }
            lineC += "Intensity per ms,";
            foreach (CharacterizedPrecursor cP in precursors)
            {
                lineC += cP.Peptide.Sequence + ",";
            }
            lineC += "Standard Deviation Count,";
            foreach (CharacterizedPrecursor cP in precursors)
            {
                lineC += cP.Peptide.Sequence + ",";
            }
            lineC += "Standard Deviation per ms,";
            foreach (CharacterizedPrecursor cP in precursors)
            {
                lineC += cP.Peptide.Sequence + ",";
            }
            writerArea.AddLine(lineC);

            foreach (int cond in samplesMixed.GetConditions())
            {
                Dictionary <CharacterizedPrecursor, Dictionary <int, MaxFlowElutionCurve> > deconvoluted = new Dictionary <CharacterizedPrecursor, Dictionary <int, MaxFlowElutionCurve> >();
                string sampleName = "";
                foreach (Sample mixedSample in results.Keys)
                {
                    if (mixedSample.PROJECT.CONDITION == cond)
                    {
                        sampleName = vsCSV.GetFileName_NoExtension(mixedSample.sSDF);
                        foreach (Dictionary <CharacterizedPrecursor, MaxFlowElutionCurve> ratio in results[mixedSample])
                        {
                            foreach (CharacterizedPrecursor cP in ratio.Keys)
                            {
                                if (ratio[cP].eCurveCount.Area > 0)
                                {
                                    if (!deconvoluted.ContainsKey(cP))
                                    {
                                        deconvoluted.Add(cP, new Dictionary <int, MaxFlowElutionCurve>());
                                    }

                                    if (deconvoluted[cP].ContainsKey(mixedSample.PROJECT.REPLICATE))
                                    {
                                        if (deconvoluted[cP][mixedSample.PROJECT.REPLICATE].eCurveCount.Area < ratio[cP].eCurveCount.Area)
                                        {
                                            deconvoluted[cP][mixedSample.PROJECT.REPLICATE] = ratio[cP];
                                        }
                                    }
                                    else
                                    {
                                        deconvoluted[cP].Add(mixedSample.PROJECT.REPLICATE, ratio[cP]);
                                    }
                                    //deconvoluted[cP].Add(ratio[cP]);
                                }
                            }
                        }
                    }
                }


                Dictionary <int, double> totalIntensityCount = new Dictionary <int, double>();
                Dictionary <int, double> totalIntensityPerMs = new Dictionary <int, double>();

                foreach (CharacterizedPrecursor cP in precursors)
                {
                    if (deconvoluted.ContainsKey(cP))
                    {
                        foreach (int keyRep in deconvoluted[cP].Keys)
                        //foreach (MaxFlowElutionCurve curve in deconvoluted[cP])
                        {
                            if (!totalIntensityCount.ContainsKey(keyRep))
                            {
                                totalIntensityCount.Add(keyRep, 0.0);
                                totalIntensityPerMs.Add(keyRep, 0.0);
                            }
                            MaxFlowElutionCurve curve = deconvoluted[cP][keyRep];
                            totalIntensityCount[keyRep] += curve.eCurveCount.Area;
                            totalIntensityPerMs[keyRep] += curve.eCurvePerMs.Area;
                        }
                    }
                }
                string lineArea    = sampleName + ",";
                string lineMS      = ",";
                string stdDevCount = "";
                string stdDevMS    = "";
                //1) Compute an average out of the replicates
                foreach (CharacterizedPrecursor cP in precursors)
                {
                    if (deconvoluted.ContainsKey(cP))
                    {
                        double averageAreaMS    = 0;
                        double averageAreaCount = 0;
                        foreach (MaxFlowElutionCurve curve in deconvoluted[cP].Values)
                        {
                            averageAreaCount += curve.eCurveCount.Area;
                            averageAreaMS    += curve.eCurvePerMs.Area;
                        }
                        if (averageAreaCount > 0)
                        {
                            averageAreaCount = (averageAreaCount / ((double)deconvoluted[cP].Count));
                            averageAreaMS    = (averageAreaMS / ((double)deconvoluted[cP].Count));

                            double        deNormAverageCount = 0.0;
                            double        deNormAveragePerMs = 0.0;
                            List <double> repAreaCount       = new List <double>();
                            List <double> repAreaMS          = new List <double>();
                            foreach (int keyRep in deconvoluted[cP].Keys)
                            {
                                MaxFlowElutionCurve curve = deconvoluted[cP][keyRep];
                                double tmpCount           = (curve.eCurveCount.Area / totalIntensityCount[keyRep]) * averageAreaCount;
                                deNormAverageCount += tmpCount;
                                repAreaCount.Add(tmpCount);
                                double tmpPerMs = (curve.eCurvePerMs.Area / totalIntensityPerMs[keyRep]) * averageAreaMS;
                                deNormAveragePerMs += tmpPerMs;
                                repAreaMS.Add(tmpPerMs);
                            }

                            lineArea += (deNormAverageCount / ((double)repAreaCount.Count)) + ",";
                            lineMS   += (deNormAveragePerMs / ((double)repAreaMS.Count)) + ",";
                            if (repAreaCount.Count > 1)
                            {
                                stdDevCount += MathNet.Numerics.Statistics.ArrayStatistics.StandardDeviation(repAreaCount.ToArray()) + ",";
                                stdDevMS    += MathNet.Numerics.Statistics.ArrayStatistics.StandardDeviation(repAreaMS.ToArray()) + ",";
                            }
                            else
                            {
                                stdDevCount += ",";
                                stdDevMS    += ",";
                            }
                        }
                        else
                        {
                            lineArea    += ",";
                            lineMS      += ",";
                            stdDevCount += ",";
                            stdDevMS    += ",";
                        }
                    }
                    else
                    {
                        lineArea    += ",";
                        lineMS      += ",";
                        stdDevCount += ",";
                        stdDevMS    += ",";
                    }
                }
                writerArea.AddLine(lineArea + lineMS + "," + stdDevCount + "," + stdDevMS);

                //2) Add replicates results (to use for standard deviation)
            }
            writerArea.WriteToFile();
        }