}//*/

        public IEnumerable <ProductMatch> GetProductMZs(DBOptions options, GraphML_List <MsMsPeak> peaks)//, List<double> theoretical_product_mzs = null)
        {
            // speed optimizations
            //double[] experimental_masses = Query.spectrum.Masses;
            //GraphML_List<MSPeak> peaks = Query.spectrum.Peaks;
            int num_experimental_peaks = peaks.Count;

            TotalTheoreticalProducts = 0;
            TotalWeightedProducts    = 0;
            //New version that should include charged ions

            //foreach (ProductMatch matchTheo in AllFragmentSearch.ComputeAllFragments(Peptide, Query.precursor.Charge, options))
            foreach (ProductMatch matchTheo in options.fragments.ComputeFragmentsFast(Peptide.GetMasses(), Query.precursor.Charge, options))
            //foreach (ProductMatch matchTheo in options.fragments.ComputeFragments(Peptide, Query.precursor.Charge, options))
            {
                TotalTheoreticalProducts++;
                TotalWeightedProducts += matchTheo.weight;//++;
                //TODO test what is most common between charged ions, and uncharged ions
                //for (int charge = 1; charge <= Query.precursor.Charge; charge++)
                //for (int charge = Query.precursor.Charge; charge >= 1; charge--)
                //{
                double massDiff = options.productMassTolerance.Value;
                double bestMz   = -1;
                double bestInt  = 0;

                foreach (int index in Query.spectrum.GetIndexOfMZInRange(matchTheo.theoMz, options.productMassTolerance))
                {
                    if (peaks[index].Charge <= 0 || peaks[index].Charge == matchTheo.charge)
                    {
                        double diff = Numerics.CalculateMassError(peaks[index].MZ, matchTheo.theoMz, options.productMassTolerance.Units);
                        //double diff = matchTheo.theoMz - peaks[index].MZ;// experimental_masses[index];//TODO DALTON ONLY : add product mass tolerance unit test
                        if (Math.Abs(diff) < options.productMassTolerance.Value)
                        {
                            if (Math.Abs(diff) < Math.Abs(massDiff))//TODO Priority to intensity, or precision?
                            {
                                massDiff = diff;
                                bestMz   = peaks[index].MZ;
                            }
                            //if (peaks[index].Intensity > bestInt)
                            bestInt += peaks[index].Intensity;
                        }
                    }
                }
                if (bestMz >= 0)
                {
                    ProductMatch pMatch = new ProductMatch();
                    pMatch.weight              = matchTheo.weight;
                    pMatch.theoMz              = matchTheo.theoMz; // Utilities.MZFromMzSingleCharge(theoMass, charge);
                    pMatch.obsMz               = bestMz;           // experimental_masses[bestIndex];
                    pMatch.mass_diff           = massDiff;
                    pMatch.obsIntensity        = bestInt;          // Intensities[bestIndex];
                    pMatch.charge              = matchTheo.charge; // peaks[bestIndex].Charge;
                    pMatch.Fragment            = matchTheo.Fragment;
                    pMatch.fragmentPos         = matchTheo.fragmentPos;
                    pMatch.normalizedIntensity = pMatch.obsIntensity / (Query.spectrum.InjectionTime * Query.spectrum.PrecursorIntensityPerMilliSecond);
                    yield return(pMatch);
                    //break;
                }
            }
        }
Пример #2
0
        public void OptimizePSMScoreRatios_PREVIOUSVersion(DBOptions options, double desired_fdr)
        {
            List <Precursor> sortedPrecursorPrecision = new List <Precursor>(this);

            sortedPrecursorPrecision.Sort(Precursor.ComparePrecursorScore);
            double ratioPrecursorPrecision = FDRizer <Precursor> .ComputeAtFDR(sortedPrecursorPrecision, desired_fdr).Count / (double)this.Count;

            List <Precursor> sortedFragments = new List <Precursor>(this);

            sortedFragments.Sort(Precursor.CompareMatchingProductsFraction);
            double ratioFragments = FDRizer <Precursor> .ComputeAtFDR(sortedFragments, desired_fdr).Count / (double)this.Count;

            List <Precursor> sortedIntensities = new List <Precursor>(this);

            sortedIntensities.Sort(Precursor.CompareMatchingIntensityFraction);
            double ratioIntensities = FDRizer <Precursor> .ComputeAtFDR(sortedIntensities, desired_fdr).Count / (double)this.Count;

            List <Precursor> sortedPeptides = new List <Precursor>(this);

            sortedPeptides.Sort(Precursor.ComparePeptideScore);
            double ratioPeptideScore = FDRizer <Precursor> .ComputeAtFDR(sortedPeptides, desired_fdr).Count / (double)this.Count;

            double totalRatios = ratioPrecursorPrecision + ratioFragments + ratioIntensities + ratioPeptideScore;

            options.dPrecursor = ratioPrecursorPrecision / totalRatios;
            options.dMatchingProductFraction = ratioFragments / totalRatios;
            options.dIntensityFraction       = ratioIntensities / totalRatios;
            options.dPeptideScore            = ratioPeptideScore / totalRatios;
            options.ConSole.WriteLine("New score ratios  [" + totalRatios + " total ratios] ------------------------------------- ");
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dPrecursor:                     " + options.dPrecursor);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dMatchingProductFraction:       " + options.dMatchingProductFraction);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dIntensityFraction:             " + options.dIntensityFraction);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dPeptideScore:                  " + options.dPeptideScore);
            options.ConSole.WriteLine("------------------------------------------------------------------------------------------ ");
        }
Пример #3
0
        private void RunGPUProteinDigest(DBOptions options, List <Protein> Proteins, Queries listOfQueries)
        {
            List <double> precursorMasses = new List <double>(listOfQueries.Count);

            //double[] precursors = new double[listOfQueries.Count];
            for (int i = 0; i < listOfQueries.Count; i++)
            {
                precursorMasses.Add(listOfQueries[i].precursor.Mass - Constants.WATER_MONOISOTOPIC_MASS);
            }
            //precursors[i] = listOfQueries[i].precursor.Mass - Constants.WATER_MONOISOTOPIC_MASS;
            precursorMasses.Sort();

            //for each protein, build matrix of mass
            int nbProteins = 0;

            Trinity_Gpu.ProteinDigest pg = new Trinity_Gpu.ProteinDigest(precursorMasses.ToArray(), options.MaximumPeptideLength, options.MinimumPeptideLength);
            foreach (Protein protein in Proteins)
            {
                double[] proteinMasses = GetMasses(protein.BaseSequence);

                foreach (Trinity_Gpu.ProteinPrecursorMatch match in pg.Execute(proteinMasses, options.precursorMassTolerance.Value, options.MaximumPeptideMass))//TODO compute correct tolerance window
                {
                    CumulMatch.Enqueue(new Tuple <Peptide, int>(new Peptide(protein, match.proteinStartPos, match.proteinEndPos, 0), match.firstQueryIndex));
                    //yield return new Tuple<Peptide, int> new Peptide(protein, match.proteinStartPos, match.proteinEndPos, 0);//TODO add modifications
                }

                nbProteins++;
            }
            pg.Dispose();
        }
Пример #4
0
 public Samples(string projectFileName, int maxFractionSpreading, DBOptions options)
 {
     loadProjectFile(projectFileName, maxFractionSpreading);
     Sort(Compare);
     FileName = projectFileName;
     dbOptions = options;
 }
Пример #5
0
        public static Result Start(DBOptions dbOptions, Samples project, bool loadMS1 = true, bool filterMS2 = true, bool optimize = true, bool runcluster = true)
        {
            Propheus propheus = new Propheus(dbOptions, project);

            propheus.Preload(loadMS1, filterMS2);
            propheus.PrepareQueries();

            return(propheus.SearchLatestVersion(propheus.AllQueries, optimize, runcluster));
        }
        public static IEnumerable <Peptide> ProteinDigest(DBOptions options, List <Protein> Proteins, bool allowSNP)
        {
            int  nbProteins = 0;
            bool tooLong    = false;

            foreach (Protein protein in Proteins)
            {
                nbProteins++;
                if (tooLong)
                {
                    break;
                }
                List <int> indices = options.DigestionEnzyme.GetDigestionSiteIndices(protein);
                indices.Insert(0, -1);
                indices.Add(protein.Length - 1);

                for (int missed_cleavages = 0; missed_cleavages <= options.ToleratedMissedCleavages; missed_cleavages++)
                {
                    for (int i = 0; i < indices.Count - missed_cleavages - 1; i++)
                    {
                        if (indices[i + missed_cleavages + 1] + 1 - (indices[i] + 1 + 1) + 1 >= options.MinimumPeptideLength)
                        {
                            if (options.initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave || indices[i] + 1 != 0 || protein[0] != 'M')
                            {
                                Peptide newPep = new Peptide(protein, indices[i] + 1, indices[i + missed_cleavages + 1], missed_cleavages);
                                yield return(newPep);

                                if (allowSNP)
                                {
                                    foreach (Peptide possibleSnp in newPep.GetSNPsdPeptides())
                                    {
                                        yield return(possibleSnp);
                                    }
                                }
                            }

                            if (options.initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain && indices[i] + 1 == 0 && protein[0] == 'M')
                            {
                                Peptide newPep = new Peptide(protein, indices[i] + 1 + 1, indices[i + missed_cleavages + 1], missed_cleavages);
                                yield return(newPep);

                                if (allowSNP)
                                {
                                    foreach (Peptide possibleSnp in newPep.GetSNPsdPeptides())
                                    {
                                        yield return(possibleSnp);
                                    }
                                }
                            }
                        }
                    }
                }
                Console.Write("\r{0}%   ", ((100 * nbProteins) / Proteins.Count));
            }
            Console.Write("\r{0}%   ", 100);
        }
        public PeptideSpectrumMatch(Query query, Peptide peptide, DBOptions options)
        {
            Query = query;
            highestFragmentIntensity = query.spectrum.MostIntensePeak;
            Peptide = peptide;

            UpdatePrecursor(options);

            Initialize(options, GetProductMZs(options, query.spectrum.Peaks));
        }
        public void UpdatePrecursor(DBOptions options)
        {
            //PrecursorMassErrorDa = (spectrum. - spectrum.IsotopicShift) - peptide.MonoisotopicMass;
            PrecursorMzError = Numerics.MzDifference(Numerics.MZFromMass(Peptide.MonoisotopicMass, Query.precursor.Charge), Query.precursor.Track.MZ, options.precursorMassTolerance.Units);
            if (PrecursorMzError > options.precursorMassTolerance.Value)
            {
                PrecursorMzError = options.precursorMassTolerance.Value;
            }

            PrecursorScore = (options.precursorMassTolerance.Value - Math.Abs(PrecursorMzError)) / options.precursorMassTolerance.Value;
        }
Пример #9
0
 public Queries(DBOptions dbOptions)
     : base()
 {
     MaxMZ = double.MinValue;
     MinMZ = double.MaxValue;
     MaxRt = double.MinValue;
     MinRt = double.MaxValue;
     //this.sample = sample;
     this.dbOptions = dbOptions;
     Precursors     = new Precursors();
 }
Пример #10
0
 /// <summary>
 /// Constructor used for Unit tests
 /// </summary>
 /// <param name="masses"></param>
 public Queries(DBOptions options, double[] masses)
 {
     Precursors = new Precursors();
     foreach (double mass in masses)
     {
         Precursor precursor = new Precursor();
         precursor.Mass = mass;
         Add(new Query(options, null, null, precursor));
         Precursors.Add(precursor);
     }
 }
Пример #11
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();
 }
Пример #12
0
 public Query(DBOptions dbOptions, Sample entry, ProductSpectrum spectrum, Precursor precursor, int spectraIndex = -1)
 {
     this.options       = dbOptions;
     this.sample        = entry;
     this.psms          = new PeptideSpectrumMatches();
     this.spectrum      = spectrum;
     this.precursor     = precursor;
     this.spectrumIndex = spectraIndex;
     if (spectrum != null && precursor != null)
     {
         this.TrapDistance = Math.Abs(spectrum.PrecursorMZ - precursor.Track.MZ);
     }
 }
Пример #13
0
        public static GraphML_List <Precursor> GetIsotopes(Track track, DBOptions dbOptions, Tracks listTracks, Sample entry)
        {
            double isotopicMzTolerance = dbOptions.precursorMassTolerance.Value * 0.5;

            if (dbOptions.precursorMassTolerance.Units == MassToleranceUnits.ppm)
            {
                isotopicMzTolerance = (isotopicMzTolerance / 1e6) * track.MZ;
            }

            GraphML_List <Precursor> bestIsotopes = new GraphML_List <Precursor>();

            for (int charge = dbOptions.MaximumPrecursorChargeState; charge >= dbOptions.MinimumPrecursorChargeState; charge--)
            {
                GraphML_List <Precursor> isotopes = new GraphML_List <Precursor>();
                for (int nbIsotope = 1; nbIsotope < 5; nbIsotope++)
                {
                    double bestDeltaMz = isotopicMzTolerance;
                    Track  bestTrack   = null;
                    double massShift   = Numerics.IsotopicMassShift(nbIsotope, charge);
                    double mzIsotope   = track.MZ + massShift;

                    foreach (Track trackToTest in listTracks.GetTracksInMzRange(mzIsotope, isotopicMzTolerance))
                    {
                        if (trackToTest.RT >= track.RT_Min &&
                            trackToTest.RT <= track.RT_Max)
                        {
                            double mzDiff = Math.Abs(mzIsotope - trackToTest.MZ);
                            if (mzDiff < bestDeltaMz)//TODO Is the best isotope the most precise one or the most intense?? Use a scoring function!
                            {
                                bestDeltaMz = mzDiff;
                                bestTrack   = trackToTest;
                            }
                        }
                    }
                    if (bestTrack != null)
                    {
                        isotopes.Add(new Precursor(bestTrack, charge, entry, Constants.C12_C13_MASS_DIFFERENCE * nbIsotope, null));
                    }
                    else
                    {
                        break;
                    }
                }
                if (isotopes.Count > bestIsotopes.Count)//TODO Best way to compare isotope potentials? Number of isotopes? Delta Mass? Intensity ratios?
                {
                    bestIsotopes = isotopes;
                }
            }
            return(bestIsotopes);
        }
        public void Merge(PeptideSpectrumMatch psm, DBOptions options)
        {
            //TODO Replace merging with Max flow approach
            //Augment list A
            List <ProductMatch> newList = new List <ProductMatch>();

            foreach (ProductMatch matchA in this.AllProductMatches)
            {
                bool isNew = true;
                foreach (ProductMatch matchB in psm.AllProductMatches)
                {
                    if (matchA.theoMz == matchB.theoMz && matchA.charge == matchB.charge)
                    {
                        if (matchA.mass_diff > matchB.mass_diff)
                        {
                            matchA.mass_diff = matchB.mass_diff;
                            matchA.obsMz     = matchB.obsMz;
                        }
                        matchA.obsIntensity += matchB.obsIntensity;
                        newList.Add(matchA);
                        isNew = false;
                    }
                }
                if (isNew)
                {
                    newList.Add(matchA);
                }
            }
            //Add items unique to list B
            foreach (ProductMatch matchB in psm.AllProductMatches)
            {
                bool isNew = true;
                foreach (ProductMatch matchNew in newList)
                {
                    if (matchNew.theoMz == matchB.theoMz && matchNew.charge == matchB.charge)
                    {
                        isNew = false;
                    }
                }
                if (isNew)
                {
                    newList.Add(matchB);
                }
            }

            highestFragmentIntensity += psm.highestFragmentIntensity;

            Initialize(options, newList);
        }//*/
Пример #15
0
        public void OptimizePSMScoreRatios_PREVIOUSVersion(DBOptions options, double desired_fdr)
        {
            //TODO find a Max flow approach to modelize the score optimization routine to maximize Targets versus Decoys
            List <PeptideSpectrumMatch> sortedPrecursorPrecision = new List <PeptideSpectrumMatch>(this);

            sortedPrecursorPrecision.Sort(PeptideSpectrumMatches.ComparePrecursorScore);
            double ratioPrecursorPrecision = FDRizer <PeptideSpectrumMatch> .ComputeAtFDR(sortedPrecursorPrecision, desired_fdr).Count / (double)this.Count;

            List <PeptideSpectrumMatch> sortedFragments = new List <PeptideSpectrumMatch>(this);

            sortedFragments.Sort(PeptideSpectrumMatches.CompareMatchingProductsFraction);
            double ratioFragments = FDRizer <PeptideSpectrumMatch> .ComputeAtFDR(sortedFragments, desired_fdr).Count / (double)this.Count;

            List <PeptideSpectrumMatch> sortedIntensities = new List <PeptideSpectrumMatch>(this);

            sortedIntensities.Sort(PeptideSpectrumMatches.CompareMatchingIntensityFraction);
            double ratioIntensities = FDRizer <PeptideSpectrumMatch> .ComputeAtFDR(sortedIntensities, desired_fdr).Count / (double)this.Count;

            List <PeptideSpectrumMatch> sortedPeptides = new List <PeptideSpectrumMatch>(this);

            sortedPeptides.Sort(PeptideSpectrumMatches.ComparePeptideScore);
            double ratioPeptideScore = FDRizer <PeptideSpectrumMatch> .ComputeAtFDR(sortedPeptides, desired_fdr).Count / (double)this.Count;

            double totalRatios = ratioPrecursorPrecision + ratioFragments + ratioIntensities + ratioPeptideScore;

            options.dPrecursor += ratioPrecursorPrecision / totalRatios;
            options.dMatchingProductFraction += ratioFragments / totalRatios;
            options.dIntensityFraction       += ratioIntensities / totalRatios;
            options.dPeptideScore            += ratioPeptideScore / totalRatios;

            double somme = options.dPrecursor + options.dMatchingProductFraction + options.dIntensityFraction + options.dPeptideScore;

            options.dPrecursor /= somme;
            options.dMatchingProductFraction /= somme;
            options.dIntensityFraction       /= somme;
            options.dPeptideScore            /= somme;

            //options.dPrecursor                 = ratioPrecursorPrecision   / totalRatios;
            //options.dMatchingProductFraction   = ratioFragments            / totalRatios;
            //options.dIntensityFraction         = ratioIntensities          / totalRatios;
            //options.dPeptideScore              = ratioPeptideScore         / totalRatios;
            options.ConSole.WriteLine("New score ratios  [" + totalRatios + " total ratios] ------------------------------------- ");
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dPrecursor:                     " + options.dPrecursor);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dMatchingProductFraction:       " + options.dMatchingProductFraction);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dIntensityFraction:             " + options.dIntensityFraction);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dPeptideScore:                  " + options.dPeptideScore);
            options.ConSole.WriteLine("------------------------------------------------------------------------------------------ ");
        }
Пример #16
0
        public MSSearcher(DBOptions options, Samples project)
        {
            this.options = options;

            foreach (Sample sample in project)
            {
                if (!samples.ContainsKey(sample.PROJECT.CONDITION))
                {
                    samples.Add(sample.PROJECT.CONDITION, new List <int>());
                }
                if (!samples[sample.PROJECT.CONDITION].Contains(sample.PROJECT.REPLICATE))
                {
                    samples[sample.PROJECT.CONDITION].Add(sample.PROJECT.REPLICATE);
                }
            }
        }
        //TODO Check if those var are common with Precursor and remove zeroed out var
        public double ProbabilityScore()
        {
            DBOptions options = Query.options;
            //double score = FragmentScore() * PrecursorScore;// +ProductScore;
            //return MaxQuantScore();//TODO Reactivate Optimized PeptideSpectrumMatch Score
            double score = options.dIntensity * MatchingIntensity +
                           options.dIntensityFraction * MatchingIntensityFraction +
                           options.dProduct * ProductScore +
                           options.dPrecursor * PrecursorScore +
                           options.dMatchingProductFraction * MatchingProductsFraction +
                           options.dMatchingProduct * MatchingWeightedProducts +
                           options.dProtein * ProteinScore +
                           options.dPeptideScore * PeptideScore +
                           options.dFragmentScore * FragmentScore;     //*/

            return(score);
        }
Пример #18
0
        public static Spectra Import(string filenameMSMS, string filenameTracks, DBOptions dbOptions)
        {
            Spectra spectra = new Spectra();
            vsCSV   csv     = new vsCSV(filenameMSMS);

            if (csv.LINES_LIST.Count == 0 || csv.LINES_LIST[0].CompareTo(ProductSpectrum.TITLE) != 0)
            {
                return(null);
            }
            for (int i = 1; i < csv.LINES_LIST.Count; i++)
            {
                string[] splits  = csv.LINES_LIST[i].Split(vsCSV._Generic_Separator);
                double   mz      = double.Parse(splits[3]);
                int      charge  = int.Parse(splits[5]);
                int      nbPeaks = int.Parse(splits[9]);
                GraphML_List <MsMsPeak> peaks = new GraphML_List <MsMsPeak>(nbPeaks);
                i++;
                for (int j = 0; j < nbPeaks; i++, j++)
                {
                    try
                    {
                        string[] splitPeaks = csv.LINES_LIST[i].Split('\t');
                        if (splitPeaks.Length > 2)
                        {
                            peaks.Add(new MsMsPeak(double.Parse(splitPeaks[0]), double.Parse(splitPeaks[1]), int.Parse(splitPeaks[2])));
                        }
                        else
                        {
                            peaks.Add(new MsMsPeak(double.Parse(splitPeaks[0]), double.Parse(splitPeaks[1]), 0));
                        }
                    }
                    catch (Exception)
                    {
                        dbOptions.ConSole.WriteLine("Error parsing line : " + csv.LINES_LIST[i]);
                    }
                }
                spectra.AddMSMS(new ProductSpectrum(int.Parse(splits[0]), double.Parse(splits[1]), splits[2], mz, double.Parse(splits[4]), charge, Proteomics.Utilities.Numerics.MassFromMZ(mz, charge), peaks, double.Parse(splits[8]), double.Parse(splits[10]), double.Parse(splits[11])));
            }
            if (!string.IsNullOrEmpty(filenameTracks))
            {
                spectra.tracks = Tracks.Import(filenameTracks, dbOptions);
            }
            return(spectra);
        }
Пример #19
0
        public static GraphML_List <Precursor> GetOtherCharges(Precursor precursor, DBOptions dbOptions, Tracks listTracks, Sample entry)
        {
            GraphML_List <Precursor> otherPrecursor = new GraphML_List <Precursor>();

            for (int charge = dbOptions.MaximumPrecursorChargeState; charge >= 1; charge--)
            {
                if (charge != precursor.Charge)
                {
                    double aimedMZ = Numerics.MZFromMass(precursor.Mass, charge);

                    double chargeMzTolerance = dbOptions.precursorMassTolerance.Value * 0.5;
                    if (dbOptions.precursorMassTolerance.Units == MassToleranceUnits.ppm)
                    {
                        chargeMzTolerance = (chargeMzTolerance / 1e6) * aimedMZ;
                    }

                    double bestDeltaMz = chargeMzTolerance;
                    Track  bestTrack   = null;
                    foreach (Track trackToTest in listTracks.GetTracksInMzRange(aimedMZ, chargeMzTolerance))
                    {
                        if (trackToTest.RT >= precursor.Track.RT_Min &&
                            trackToTest.RT <= precursor.Track.RT_Max)
                        {
                            double mzDiff = Math.Abs(aimedMZ - trackToTest.MZ);
                            if (mzDiff < bestDeltaMz)//TODO Is the best isotope the most precise one or the closest in intensity?? Use a scoring function to get both!
                            {
                                bestDeltaMz = mzDiff;
                                bestTrack   = trackToTest;
                            }
                        }
                    }
                    if (bestTrack != null)
                    {
                        otherPrecursor.Add(new Precursor(bestTrack, charge, precursor.sample, 0, GetIsotopes(bestTrack, dbOptions, listTracks, entry)));
                    }
                }
            }
            return(otherPrecursor);
        }
        public void Initialize(DBOptions options, IEnumerable <ProductMatch> productMZs)
        {
            //List<double> theoretical_product_mz = Peptide.CalculateAllProductMz(PRODUCT_TYPES[Query.spectrum.FragmentationMethod], Query.precursor);
            //TotalProducts = theoretical_product_mz.Count;
            MatchingProducts  = 0;
            MatchingIntensity = 0.0;
            double cumulDiff = 0;

            ProductScore = 0;
            GraphML_List <ProductMatch> cumulMatch = new GraphML_List <ProductMatch>();

            MatchingWeightedProducts = 0;
            foreach (ProductMatch match in productMZs)
            {
                MatchingProducts++;
                MatchingWeightedProducts += match.weight;
                MatchingIntensity        += match.obsIntensity;
                cumulDiff += Math.Abs(match.mass_diff) * match.weight;

                cumulMatch.Add(match);
                if (match.obsIntensity > highestFragmentIntensity)
                {
                    highestFragmentIntensity = match.obsIntensity;
                }
                //options.ConSole.WriteLine("fragment intensity higher than most intense fragment ... should not happen!");
            }
            AllProductMatches         = cumulMatch;
            MatchingProductsFraction  = (double)MatchingWeightedProducts / (double)TotalWeightedProducts;
            MatchingIntensityFraction = MatchingIntensity / (double)(highestFragmentIntensity * TotalTheoreticalProducts);
            if (MatchingIntensityFraction > 1)
            {
                MatchingIntensityFraction = 1.0;
            }
            ProductScore   = 1.0 - (cumulDiff / (double)(MatchingProducts * options.productMassTolerance.Value));
            IntensityScore = MatchingIntensityFraction / (double)Query.spectrum.Peaks.Count;
            MorpheusScore  = MatchingProducts + MatchingIntensityFraction;
            FragmentScore  = ComputeFragmentScore();
        }
Пример #21
0
        private static Tracks ComputeSpectraTracks(Spectra spectra, DBOptions options, string outputFilename, int missingScan, int centroid, int minPeaks, double valleyFactor, MaxQuant.CentroidPosition centroidMethod)
        {
            //Trail.RemoveFinished(ref trails, spectra, -1);
            double[] centerMassArray;
            float[]  centerMassErrorArray;
            float[]  intensityArray;
            float[]  minTimeArray;
            float[]  maxTimeArray;
            long[]   filePosArray;
            //TODO Cycle values to optimize missing scans and centroid values

            string file = null;

            if (options.WriteMaxQuantPeakFile)
            {
                file = options.OutputFolder + vsCSV.GetFileName_NoExtension(outputFilename) + "_Peaks.txt";
            }
            MaxQuant.PeakDetection.Detect(file,
                                          missingScan,                                    //*1-2-3-4-5
                                          centroid,                                       //*1-2-3-4-5-6-7-8-9-10
                                          centroidMethod,                                 //*
                                          false, 0, options.precursorMassTolerance.Value, //TODO ensure its always in ppm
                                          minPeaks,                                       //*1-2-3-4-5-6-7-8-9-10
                                          valleyFactor,                                   //*0.1-0.2-0.3-...-3.0
                                          true,
                                          0,
                                          new Trinity.MaxQuant.RawFileWrapper(spectra),
                                          true,
                                          null, out centerMassArray, out centerMassErrorArray, out intensityArray, out minTimeArray, out maxTimeArray, out filePosArray);

            Tracks tracks = new Tracks();

            for (int i = 0; i < centerMassArray.Length; i++)
            {
                tracks.AddTrack(centerMassArray[i], (minTimeArray[i] + maxTimeArray[i]) * 0.5, minTimeArray[i], maxTimeArray[i], intensityArray[i]);
            }
            return(tracks);
        }
Пример #22
0
        public static Tracks Import(string filename, DBOptions dbOptions)
        {
            vsCSV csv = new vsCSV(filename);

            if (csv.LINES_LIST.Count == 0 || csv.LINES_LIST[0].CompareTo(Track.TITLE) != 0)
            {
                return(null);
            }
            Tracks tracks = new Tracks();

            for (int i = 1; i < csv.LINES_LIST.Count; i++)
            {
                try
                {
                    string[] splits = csv.LINES_LIST[i].Split(vsCSV._Generic_Separator);
                    tracks.AddTrack(double.Parse(splits[0]), double.Parse(splits[1]), double.Parse(splits[3]), double.Parse(splits[4]), double.Parse(splits[2]));
                }
                catch (Exception)
                {
                    dbOptions.ConSole.WriteLine("Error parsing line : " + csv.LINES_LIST[i]);
                }
            }
            return(tracks);
        }
Пример #23
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 void UpdatePsmScores(List <ProteinGroupMatch> protein_groups, DBOptions dbOptions)
        {
            //Push ProteinScores AND Peptide Score down to PSMs
            protein_groups.Sort(ProteinGroupMatch.AscendingProbabilityScore);
            double maxProteinProbScore = 0;
            double maxPeptideProbScore = 0;

            foreach (ProteinGroupMatch group in protein_groups)
            {
                double proteinScore = group.ProbabilityScore();
                if (proteinScore > maxProteinProbScore)
                {
                    maxProteinProbScore = proteinScore;
                }
                foreach (PeptideMatch peptide in group.PeptideMatches)
                {
                    double peptideScore = peptide.ProbabilityScore();
                    if (peptideScore > maxPeptideProbScore)
                    {
                        maxPeptideProbScore = peptideScore;
                    }
                }
            }

            foreach (ProteinGroupMatch group in protein_groups)
            {
                double proteinScore = group.ProbabilityScore() / maxProteinProbScore;
                foreach (PeptideMatch peptide in group.PeptideMatches)
                {
                    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.ProteinScore < proteinScore)
                                                    {
                                                        psm.ProteinScore = proteinScore;
                                                    }

                                                    if (psm.PeptideScore < peptideScore)
                                                    {
                                                        psm.PeptideScore = peptideScore;
                                                    }
                                                }
                                            }
                                            foreach (Precursor isotope in precursor.Isotopes)
                                            {
                                                foreach (PeptideSpectrumMatch psm in isotope.psms)
                                                {
                                                    if (psm.ProteinScore < proteinScore)
                                                    {
                                                        psm.ProteinScore = proteinScore;
                                                    }

                                                    if (psm.PeptideScore < peptideScore)
                                                    {
                                                        psm.PeptideScore = peptideScore;
                                                    }
                                                }
                                            }

                                            precursor.psms.Sort(PeptideSpectrumMatch.DescendingOptimizedScoreComparison);
                                            if (precursor.psms.Count == 0)
                                            {
                                                dbOptions.ConSole.WriteLine("Precursor with no match");// = precursor;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Пример #24
0
 public Samples(DBOptions options)
 {
     dbOptions = options;
 }
Пример #25
0
        public List <ProductMatch> GetCombinedSpectrum(DBOptions dbOptions, Dictionary <double, int> DicOfCommonPM = null)
        {
            Dictionary <PeptideSpectrumMatch, double> DicOfPsmFactor = new Dictionary <PeptideSpectrumMatch, double>();// this.ComputeMsMsNormalizationFactors();
            //Dictionary<ProductMatch, double> DicOfProductMsMsFactor = new Dictionary<ProductMatch, double>();
            Dictionary <string, Dictionary <PeptideSpectrumMatch, ProductMatch> > DicOfProducts = new Dictionary <string, Dictionary <PeptideSpectrumMatch, ProductMatch> >();

            double avgProbability = 0;

            foreach (PeptideSpectrumMatch psm in this)
            {
                bool usedPsm = false;
                foreach (ProductMatch match in psm.AllProductMatches)
                {
                    if (DicOfCommonPM == null || DicOfCommonPM.ContainsKey(match.theoMz))
                    {
                        string key = match.Fragment.Name + "|" + match.fragmentPos + "|" + match.charge;
                        if (!DicOfProducts.ContainsKey(key))
                        {
                            DicOfProducts.Add(key, new Dictionary <PeptideSpectrumMatch, ProductMatch>());
                        }
                        DicOfProducts[key].Add(psm, match);
                        //DicOfProductMsMsFactor.Add(match, DicOfPsmFactor[psm]);
                        usedPsm = true;
                    }
                }
                if (usedPsm)
                {
                    DicOfPsmFactor.Add(psm, psm.ProbabilityScore());//.MatchingIntensity);
                    avgProbability += psm.ProbabilityScore();
                }
            }
            avgProbability /= (double)DicOfPsmFactor.Count;

            double avgNormedInt          = 0;
            List <ProductMatch> products = new List <ProductMatch>();

            //if (DicOfProductMsMsFactor.Count > 0)
            {
                foreach (Dictionary <PeptideSpectrumMatch, ProductMatch> matchList in DicOfProducts.Values)
                {
                    ProductMatch newPM = null;
                    if (matchList.Count > 0)
                    {
                        double sumPsmFactor = 0;
                        foreach (PeptideSpectrumMatch psm in matchList.Keys)
                        {
                            if (psm.ProbabilityScore() > avgProbability)//Keep only above average spectrum
                            {
                                ProductMatch pm = matchList[psm];
                                if (newPM == null)
                                {
                                    newPM = new ProductMatch(pm);
                                    newPM.obsIntensity        = 0;
                                    newPM.normalizedIntensity = 0;
                                }
                                newPM.obsIntensity += pm.obsIntensity * DicOfPsmFactor[psm];// +pm.obsIntensity * DicOfProductMsMsFactor[pm];
                                //newPM.obsIntensity += pm.obsIntensity + pm.obsIntensity * DicOfProductMsMsFactor[pm];
                                newPM.normalizedIntensity += pm.normalizedIntensity * DicOfPsmFactor[psm];
                                sumPsmFactor += DicOfPsmFactor[psm];
                            }
                        }
                        if (sumPsmFactor > 0 && newPM != null)
                        {
                            newPM.obsIntensity        /= sumPsmFactor;
                            newPM.normalizedIntensity /= sumPsmFactor;

                            newPM.weight  = matchList.Count * newPM.normalizedIntensity;
                            avgNormedInt += newPM.normalizedIntensity;
                            products.Add(newPM);
                        }
                    }
                }
                if (products.Count > 0)
                {
                    avgNormedInt /= (double)products.Count;
                }

                //Add missed important fragments
                if (DicOfCommonPM != null)
                {
                    foreach (double mz in DicOfCommonPM.Keys)
                    {
                        bool found = false;
                        foreach (ProductMatch match in products)
                        {
                            if (match.theoMz == mz)
                            {
                                found = true;
                            }
                        }
                        if (!found)
                        {
                            double       sumPsmFactor = 0;
                            ProductMatch newMatch     = new ProductMatch();
                            newMatch.theoMz              = mz;
                            newMatch.weight              = 0;
                            newMatch.obsIntensity        = 0;
                            newMatch.normalizedIntensity = 0;
                            foreach (PeptideSpectrumMatch psm in DicOfPsmFactor.Keys)
                            {
                                foreach (MsMsPeak peak in psm.Query.spectrum.Peaks)
                                {
                                    if (Math.Abs(Proteomics.Utilities.Numerics.CalculateMassError(peak.MZ, mz, dbOptions.productMassTolerance.Units)) <= dbOptions.productMassTolerance.Value)
                                    {
                                        newMatch.obsIntensity        += peak.Intensity * DicOfPsmFactor[psm];
                                        newMatch.normalizedIntensity += (peak.Intensity / (psm.Query.spectrum.PrecursorIntensityPerMilliSecond * psm.Query.spectrum.InjectionTime)) * DicOfPsmFactor[psm];
                                        sumPsmFactor    += DicOfPsmFactor[psm];
                                        newMatch.weight += 1;
//                                        newMatch.obsIntensity += peak.Intensity;// + peak.Intensity * DicOfPsmFactor[psm];
//                                        newMatch.normalizedIntensity += peak.Intensity / (psm.Query.spectrum.PrecursorIntensityPerMilliSecond * psm.Query.spectrum.InjectionTime);
                                    }
                                }
                            }
                            if (newMatch.weight > 0)
                            {
                                newMatch.obsIntensity        /= sumPsmFactor;
                                newMatch.normalizedIntensity /= sumPsmFactor;
                            }
                            newMatch.weight *= newMatch.normalizedIntensity;
                            products.Add(newMatch);
                        }
                    }
                }

                //Keep only most intense fragments (5% of average normalized intensity)
                foreach (ProductMatch pm in products)
                {
                    if (pm.normalizedIntensity < avgNormedInt * 0.1)//0.05
                    {
                        pm.normalizedIntensity = 0;
                        pm.obsIntensity        = 0;
                    }
                }
            }

            return(products);
        }
Пример #26
0
        public void OptimizePSMScoreRatios(DBOptions options, double desired_fdr, Result results)
        {
            long   bestNbTargets   = 0;
            double bestProtein     = 0.1;
            double bestPeptide     = 0.2;
            double bestFragments   = 0.4;
            double bestIntensities = 0.1;
            double bestPrecursor   = 0.2;

            double incr = 0.05;

            for (options.dProtein = 0.1; options.dProtein < 0.3; options.dProtein += incr)
            {
                for (options.dPeptideScore = 0.1; options.dPeptideScore < 0.4; options.dPeptideScore += incr)
                {
                    for (options.dPrecursor = 0.1; options.dPrecursor < 0.5; options.dPrecursor += incr)
                    {
                        for (options.dMatchingProductFraction = 0.1; options.dMatchingProductFraction < 1 - options.dPrecursor - options.dPeptideScore - options.dProtein; options.dMatchingProductFraction += incr)
                        {
                            double cumul = options.dPrecursor + options.dPeptideScore + options.dProtein + options.dMatchingProductFraction;
                            for (options.dIntensityFraction = 0.1; options.dIntensityFraction < 1 - cumul; options.dIntensityFraction += incr)
                            {
                                if (cumul + options.dIntensityFraction == 1)
                                {
                                    long nbTargets = 0;
                                    foreach (Precursor precursor in results.matchedPrecursors)
                                    {
                                        if (precursor.Target)
                                        {
                                            nbTargets++;
                                        }
                                    }
                                    if (nbTargets > bestNbTargets)
                                    {
                                        bestNbTargets   = nbTargets;
                                        bestProtein     = options.dProtein;
                                        bestPeptide     = options.dPeptideScore;
                                        bestPrecursor   = options.dPrecursor;
                                        bestIntensities = options.dIntensityFraction;
                                        bestFragments   = options.dMatchingProductFraction;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            options.dProtein                 = bestProtein;
            options.dPeptideScore            = bestPeptide;
            options.dPrecursor               = bestPrecursor;
            options.dIntensityFraction       = bestIntensities;
            options.dMatchingProductFraction = bestFragments;

            options.ConSole.WriteLine("New score ratios   ----------------------------------------------------------------------- ");
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dPrecursor:                     " + options.dPrecursor);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dMatchingProductFraction:       " + options.dMatchingProductFraction);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dIntensityFraction:             " + options.dIntensityFraction);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dPeptideScore:                  " + options.dPeptideScore);
            options.ConSole.WriteLine("    PeptideSpectrumMatch.dProtein:                       " + options.dProtein);
            options.ConSole.WriteLine("------------------------------------------------------------------------------------------ ");
        }
Пример #27
0
        /// <summary>
        /// Crop observed fragments outside of the variance or the standard deviation (must be below the biggest of either value)
        /// Will alter DBOptions.productMassTolerance value to reflect the change
        /// </summary>
        /// <param name="result"></param>
        /// <param name="allPSMs"></param>
        /// <returns>Returns the newly computed Fragment/Product tolerance</returns>public static double CropProducts(Result result, PeptideSpectrumMatches allPSMs)
        public static double CropProducts(Result result, PeptideSpectrumMatches allPSMs, DBOptions dbOptions)
        {
            List <double> errorProduct = new List <double>(result.precursors.Count);

            foreach (Precursor precursor in result.matchedPrecursors)
            {
                PeptideSpectrumMatch psm = precursor.OptimizedBestPsm();
                if (psm.Target)
                {
                    foreach (ProductMatch match in psm.AllProductMatches)
                    {
                        errorProduct.Add(match.mass_diff);
                    }
                }
            }
            double variance = Numerics.Variance(errorProduct);
            double stdev    = Numerics.StandardDeviation(errorProduct);

            result.dbOptions.ConSole.WriteLine("Computed Product Variance = " + variance + "          STDev = " + stdev);
            if (variance < stdev)
            {
                variance = stdev;
            }
            //variance = result.dbOptions.productMassTolerance.Value * ((2 * variance) / result.dbOptions.productMassTolerance.Value);

            int nbRemovedProduct = 0;

            foreach (PeptideSpectrumMatch psm in allPSMs)
            {
                for (int i = 0; i < psm.AllProductMatches.Count;)
                {
                    if (Math.Abs(psm.AllProductMatches[i].mass_diff) > variance)
                    {
                        psm.AllProductMatches.RemoveAt(i);
                        nbRemovedProduct++;
                    }
                    else
                    {
                        i++;
                    }
                }
                psm.MatchingProducts = psm.AllProductMatches.Count;
            }

            int nbRemovedPSM = 0;

            foreach (Precursor precursor in result.precursors)
            {
                for (int i = 0; i < precursor.psms.Count;)
                {
                    if (precursor.psms[i].MatchingProducts < 2)
                    {
                        precursor.psms.RemoveAt(i);
                    }
                    else
                    {
                        precursor.psms[i].Initialize(result.dbOptions, precursor.psms[i].AllProductMatches);
                        i++;
                    }
                }
            }
            result.dbOptions.ConSole.WriteLine("Removed " + nbRemovedProduct + " [" + nbRemovedPSM + " removed PSMs] Fragment matches outside the variance [" + variance + "]");
            return(variance);
        }
Пример #28
0
 public Propheus(DBOptions dbOptions, Samples Project)
 {
     this.dbOptions = dbOptions;
     this.Project   = Project;
 }
Пример #29
0
 public DBSearcher(DBOptions options)
 {
     this.options = options;
 }
Пример #30
0
        /// <summary>
        /// Reads the proteins from a fasta file format
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="onTheFlyDecoys"> Adds reverse sequnce proteins </param>
        /// <returns></returns>
        public static List <Protein> ReadProteomeFromFasta(string fileName, bool addReverseProteins, DBOptions dbOptions)
        {
            List <Protein> AllProteins = new List <Protein>();

            try
            {
                dbOptions.ConSole.WriteLine("Reading FASTA file " + fileName + " ... ");
                //Extract Proteins from Fasta file
                FileStream protein_fasta_database = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
                foreach (Protein protein in ProteinFastaReader.ReadProteins(protein_fasta_database, addReverseProteins))
                {
                    AllProteins.Add(protein);
                }
                //AllProteins.Sort(Protein.TargetDecoyComparison);
                protein_fasta_database.Close();
                dbOptions.ConSole.WriteLine("Proteins in fasta file : " + AllProteins.Count);
            }
            catch (Exception e)
            {
                dbOptions.ConSole.WriteLine("Error reading fasta file : " + fileName);
            }
            return(AllProteins);
        }