public PeptideMatches SearchClusters(List <Cluster> clusters, List <Precursor> precursors, bool DiffByMod = true)
        {
            options.ConSole.WriteLine("Creating the list of peptide found...");
            Dictionary <string, PeptideMatch> peptideMatches = new Dictionary <string, PeptideMatch>();

            foreach (Precursor prec in precursors)
            {
                foreach (PeptideSpectrumMatch psm in prec.OptimizedBestPsms())
                {
                    Peptide pep = psm.Peptide;
                    string  seq = (DiffByMod ? pep.Sequence : pep.BaseSequence);
                    if (!peptideMatches.ContainsKey(seq))
                    {
                        peptideMatches.Add(seq, new PeptideMatch(pep));
                    }
                    else if (pep.Target)
                    {
                        peptideMatches[seq].peptide = pep;
                    }
                }
            }

            int nbClusterNewSeq = 0;

            foreach (Cluster cl in clusters)
            {
                foreach (clCondition condition in cl.conditions)
                {
                    if (condition != null)
                    {
                        foreach (clReplicate replicate in condition.replicates)
                        {
                            if (replicate != null)
                            {
                                foreach (Precursor precursor in replicate.precursors)
                                {
                                    foreach (PeptideSpectrumMatch psm in precursor.OptimizedBestPsms())
                                    {
                                        string seq = (DiffByMod ? psm.Peptide.Sequence : psm.Peptide.BaseSequence);
                                        if (peptideMatches.ContainsKey(seq))
                                        {
                                            peptideMatches[seq].AddOnlyOnce(cl);
                                        }
                                        else
                                        {
                                            nbClusterNewSeq++;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            PeptideMatches TotalList = new PeptideMatches(peptideMatches.Values);

            options.ConSole.WriteLine(TotalList.Count + " distinct peptides (based on sequence" + (DiffByMod ? " and modifications)" : ")") + "    [" + nbClusterNewSeq + " not unmapped clusters]");
            return(TotalList);
        }
Exemple #2
0
 public Result()
 {
     queries           = new Queries();
     precursors        = new Precursors();
     matchedPrecursors = new Precursors();
     clusters          = new GraphML_List <Cluster>();
     peptides          = new PeptideMatches(new PeptideMatch[0]);
     peptideSequences  = new PeptideMatches(new PeptideMatch[0]);
     proteins          = new ProteinGroupMatches();
     dbOptions         = new DBOptions("");
     samples           = new Samples();
 }
Exemple #3
0
        public void Export(double fdr, string keyword = "", bool onlyPrecursors = false)
        {
            dbOptions.ConSole.WriteLine("Exporting at " + (fdr * 100) + "% FDR (Decoy/Target)...");

            List <Precursor> prec = null;

            if (precursors != null)
            {
                if (matchedPrecursors == null)
                {
                    this.matchedPrecursors = new Precursors();
                    foreach (Precursor precursor in precursors)
                    {
                        if (precursor.psms.Count > 0)
                        {
                            matchedPrecursors.Add(precursor);
                        }
                    }
                }/*
                  * List<Precursor> prec = FDR.PrecursorsV2(precursors, fdr, 1);
                  * Sol.CONSOLE.OutputLine(">   " + prec.Count + " Precursors");
                  * MSSearcher.Export(dbOptions.outputFolder + keyword + "precursors.csv", prec);//*/
                 /*
                  * prec = Optimizer.PrecursorOptimizer(matchedPrecursors, fdr);
                  * Sol.CONSOLE.OutputLine(">   " + prec.Count + " Optimized Precursors");
                  * MSSearcher.Export(dbOptions.outputFolder + keyword + "Optimized_precursors.csv", prec);//*/

                prec = matchedPrecursors.ComputeAtFDR(fdr);
                dbOptions.ConSole.WriteLine(">   " + prec.Count + " Uptimized V5 Precursors");
                MSSearcher.Export(dbOptions.OutputFolder + keyword + "UptimizedV5_precursors.csv", prec);
            }

            if (!onlyPrecursors)
            {
                if (queries != null)
                {
                    List <Query> qs = queries.ComputeAtFDR(fdr);
                    dbOptions.ConSole.WriteLine(">   " + qs.Count + " PSMs (Top 10)");
                    MSSearcher.Export(dbOptions.OutputFolder + keyword + "queries.csv", qs);
                }
                if (clusters != null)
                {
                    //List<PeptideSpectrumMatch> psms = FDR.PSMs(clusters, fdr, 1, 10);
                    //dbOptions.ConSole.WriteLine(">   " + psms.Count + " PSMs (Top 10)");
                    //MSSearcher.Export(dbOptions.outputFolder + keyword + "psms_Top10.csv", psms);

                    //psms = FDR.PSMs(clusters, fdr, 1, 1);
                    //dbOptions.ConSole.WriteLine(">   " + psms.Count + " PSMs");
                    //MSSearcher.Export(dbOptions.outputFolder + keyword + "psms_Best.csv", psms);
                }

                if (peptides != null)
                {
                    List <PeptideMatch> pep = peptideSequences.ComputeAtFDR(fdr);
                    dbOptions.ConSole.WriteLine(">   " + pep.Count + " Peptides Sequences (Version 5)");
                    PeptideSearcher.Export(dbOptions.OutputFolder + keyword + "peptideSequencesV5_.csv", pep);

                    PeptideSearcher sr   = new PeptideSearcher(dbOptions);
                    PeptideMatches  seqs = sr.Search(clusters, prec, false);
                    pep = seqs.ComputeAtFDR(fdr);
                    dbOptions.ConSole.WriteLine(">   " + pep.Count + " Peptides Sequences (Version 5b)");
                    PeptideSearcher.Export(dbOptions.OutputFolder + keyword + "peptideSequencesV5b_PrecursorFDRed.csv", pep);

                    pep = peptides.ComputeAtFDR(fdr);
                    dbOptions.ConSole.WriteLine(">   " + pep.Count + " Peptides (Version 5)");
                    PeptideSearcher.Export(dbOptions.OutputFolder + keyword + "peptidesV5_.csv", pep);
                }
                if (proteins != null)
                {
                    List <ProteinGroupMatch> prots = proteins.ComputeAtFDR(fdr);
                    dbOptions.ConSole.WriteLine(">   " + prots.Count + " Proteins");
                    ProteinSearcher.Export(dbOptions.OutputFolder + keyword + "proteins_.csv", prots);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Updates scores for the PeptideSpectrumMatches based on newly computed elements (such as protein sequences, peptides, newly computed tolerances)
        /// </summary>
        /// <param name="protein_groups"></param>
        public static PeptideMatches UpdatePsmScores(PeptideMatches peptides, Result result)
        {
            Dictionary <Precursor, PeptideMatch> dicOfUsedPrecursors = new Dictionary <Precursor, PeptideMatch>();

            peptides.Sort(PeptideMatches.CompareScore);

            foreach (Precursor precursor in result.precursors)
            {
                precursor.psms.Clear();
            }

            double maxPeptideProbScore = 0;

            foreach (PeptideMatch peptide in peptides)
            {
                foreach (Cluster cluster in peptide.clusters)
                {
                    foreach (clCondition condition in cluster.conditions)
                    {
                        if (condition != null)
                        {
                            foreach (clReplicate replicate in condition.replicates)
                            {
                                if (replicate != null)
                                {
                                    foreach (Precursor precursor in replicate.precursors)
                                    {
                                        if (!dicOfUsedPrecursors.ContainsKey(precursor))
                                        {
                                            bool found = false;
                                            foreach (PeptideSpectrumMatch psm in precursor.psms_AllPossibilities)
                                            {
                                                if (psm.Peptide.IsSamePeptide(peptide.peptide, true))
                                                {
                                                    precursor.psms.Add(psm);
                                                    found = true;
                                                }
                                            }
                                            if (found)
                                            {
                                                dicOfUsedPrecursors.Add(precursor, peptide);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                double peptideScore = peptide.ProbabilityScore();
                if (peptideScore > maxPeptideProbScore)
                {
                    maxPeptideProbScore = peptideScore;
                }
            }

            peptides.Sort(PeptideMatches.CompareScore);
            foreach (PeptideMatch peptide in peptides)
            {
                double peptideScore = peptide.ProbabilityScore() / maxPeptideProbScore;
                foreach (Cluster cluster in peptide.clusters)
                {
                    foreach (clCondition condition in cluster.conditions)
                    {
                        if (condition != null)
                        {
                            foreach (clReplicate replicate in condition.replicates)
                            {
                                if (replicate != null)
                                {
                                    foreach (Precursor precursor in replicate.precursors)
                                    {
                                        foreach (PeptideSpectrumMatch psm in precursor.psms)
                                        {
                                            if (peptide.peptide.IsSamePeptide(psm.Peptide, true))
                                            {
                                                if (psm.PeptideScore < peptideScore)
                                                {
                                                    psm.PeptideScore = peptideScore;
                                                }
                                            }
                                        }
                                        foreach (Precursor isotope in precursor.Isotopes)
                                        {
                                            foreach (PeptideSpectrumMatch psm in isotope.psms)
                                            {
                                                if (peptide.peptide.IsSamePeptide(psm.Peptide, true))
                                                {
                                                    if (psm.PeptideScore < peptideScore)
                                                    {
                                                        psm.PeptideScore = peptideScore;
                                                    }
                                                }
                                            }
                                        }

                                        precursor.psms.Sort(PeptideSpectrumMatch.DescendingOptimizedScoreComparison);
                                        if (precursor.psms.Count == 0)
                                        {
                                            result.dbOptions.ConSole.WriteLine("Precursor with no match");    // = precursor;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(peptides);
        }