Esempio n. 1
0
        public double ProbabilityScore(Peptide peptide)
        {
            double score = 0;

            foreach (Precursor precursor in precursors)
            {
                score += /*(1 - score) * */ precursor.ProbabilityScore(peptide, true);
            }

            return(score);
        }
        public PeptideMatches Search(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)
                        {
                            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);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            PeptideMatches TotalList = new PeptideMatches(peptideMatches.Values);

            options.ConSole.WriteLine(TotalList.Count + " distinct peptides (based on sequence" + (DiffByMod ? " and modifications)" : ")") + "    [" + nbClusterNewSeq + " added from clusters]");
            return(TotalList);
        }
Esempio n. 3
0
        public double ProbabilityScore(Peptide peptide)
        {
            double score = 0;

            foreach (clReplicate replicate in replicates)
            {
                if (replicate != null)
                {
                    score += /*(1 - score) * */ replicate.ProbabilityScore(peptide);
                }
            }
            return(score);
        }
Esempio n. 4
0
        public double OptimizedBestPsmScore(Peptide peptide = null, bool checkMods = false)
        {
            PeptideSpectrumMatch psm = OptimizedBestPsm(peptide, checkMods);

            if (psm != null)
            {
                return(psm.ProbabilityScore());
            }
            else
            {
                return(0);
            }
        }
Esempio n. 5
0
        //public ConcurrentDictionary<string, List<Protein>> DicOfProteins = new ConcurrentDictionary<string, List<Protein>>();
        private void ComputePSMs(Query query, Peptide modified_peptide)
        {
            PeptideSpectrumMatch psm = new PeptideSpectrumMatch(query, modified_peptide, options);

            if (psm.MatchingProducts > options.fragments.Count)
            {
                //DicOfProteins.GetOrAdd(psm.Peptide.BaseSequence, new List<Protein>()).Add(psm.Peptide.Parent);
//                if (!DicOfProteins.ContainsKey(psm.Peptide.BaseSequence))
//                    DicOfProteins.AddOrUpdate(psm.Peptide.BaseSequence, new List<Protein>());
//                DicOfProteins[psm.Peptide.BaseSequence].Add(psm.Peptide.Parent);

                //List<PeptideSpectrumMatch> psmsOfQuery = query.psms;

                if (query.psms.Count < options.NbPSMToKeep)
                {
                    query.psms.Add(psm);
                }
                else if (query.psms[options.NbPSMToKeep - 1].ProbabilityScore() < psm.ProbabilityScore())
                {
                    for (int i = 0; i < query.psms.Count; i++)
                    {
                        if (query.psms[i].ProbabilityScore() <= psm.ProbabilityScore())
                        {
                            query.psms.Insert(i, psm);
                            break;
                        }
                    }
                    if (query.psms.Count > options.NbPSMToKeep)
                    {
                        query.psms.RemoveAt(options.NbPSMToKeep - 1);
                    }
                }//*/
                 //TODO check optimal number of PSM to store

                /*
                 * //TODO Reactivate this to save on memory space
                 * if (psmsOfPrecursor.Count == 0 || psmsOfPrecursor[0].MaxQuantScore() == psm.MaxQuantScore())
                 *  psmsOfPrecursor.Add(psm);
                 * else
                 *  if (psm.MaxQuantScore() > psmsOfPrecursor[0].MaxQuantScore())
                 *  {
                 *      psmsOfPrecursor.Clear();
                 *      psmsOfPrecursor.Add(psm);
                 *  }
                 * //*/
            }
        }
Esempio n. 6
0
        /*
         * public static int TargetDecoyComparison(Protein left, Protein right)
         * {
         *  if (left.Target)
         *      if (right.Target)
         *          return 0;
         *      else
         *          return -1;
         *  else
         *      if (right.Target)
         *          return 1;
         *      else
         *          return 0;
         * }//*/

        public IEnumerable <Peptide> Digest(Protease protease, int maximumMissedCleavages, InitiatorMethionineBehavior initiatorMethionineBehavior,
                                            int?minimumPeptideLength, int?maximumPeptideLength, bool onTheFlyDecoy)
        {
            List <int> indices = protease.GetDigestionSiteIndices(this);

            indices.Insert(0, -1);
            indices.Add(Length - 1);

            for (int missed_cleavages = 0; missed_cleavages <= maximumMissedCleavages; missed_cleavages++)
            {
                for (int i = 0; i < indices.Count - missed_cleavages - 1; i++)
                {
                    if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Cleave || indices[i] + 1 != 0 || this[0] != 'M')
                    {
                        Peptide peptide = new Peptide(this, indices[i] + 1, indices[i + missed_cleavages + 1], missed_cleavages);

                        if ((!minimumPeptideLength.HasValue || peptide.Length >= minimumPeptideLength.Value) &&
                            (!maximumPeptideLength.HasValue || peptide.Length <= maximumPeptideLength.Value))
                        {
                            yield return(peptide);

                            if (onTheFlyDecoy)
                            {
                                yield return(new Peptide(this, indices[i + missed_cleavages + 1], indices[i] + 1, missed_cleavages));
                            }
                        }
                    }

                    if (initiatorMethionineBehavior != InitiatorMethionineBehavior.Retain && indices[i] + 1 == 0 && this[0] == 'M')
                    {
                        Peptide peptide_without_initiator_methionine = new Peptide(this, indices[i] + 1 + 1, indices[i + missed_cleavages + 1], missed_cleavages);

                        if ((!minimumPeptideLength.HasValue || peptide_without_initiator_methionine.Length >= minimumPeptideLength.Value) &&
                            (!maximumPeptideLength.HasValue || peptide_without_initiator_methionine.Length <= maximumPeptideLength.Value))
                        {
                            yield return(peptide_without_initiator_methionine);

                            if (onTheFlyDecoy)
                            {
                                yield return(new Peptide(this, indices[i + missed_cleavages + 1], indices[i] + 1 + 1, missed_cleavages));
                            }
                        }
                    }
                }
            }
        }
Esempio n. 7
0
 public PeptideSpectrumMatch OptimizedBestPsm(Peptide peptide = null, bool checkMods = false)
 {
     if (psms.Count > 0)
     {
         if (peptide == null)
         {
             double bestScore        = psms[0].ProbabilityScore();
             int    bestProteinIndex = 0;
             double tmpScore;
             for (int i = 1; i < psms.Count; i++)
             {
                 tmpScore = psms[i].ProbabilityScore();
                 if (tmpScore > bestScore || (tmpScore == bestScore && psms[i].Target))//.ProteinScore >= proteinScore))
                 {
                     bestProteinIndex = i;
                     bestScore        = tmpScore;
                 }
             }
             return(psms[bestProteinIndex]);
         }
         else
         {
             double bestScore        = 0;
             int    bestProteinIndex = 0;
             double proteinScore     = 0;
             for (int i = 0; i < psms.Count; i++)
             {
                 if (peptide.IsSamePeptide(psms[i].Peptide, checkMods) && (psms[i].ProbabilityScore() > bestScore || (psms[i].ProbabilityScore() == bestScore && psms[i].Target)))//.ProteinScore > proteinScore)))
                 {
                     bestProteinIndex = i;
                     bestScore        = psms[i].ProbabilityScore();
                     proteinScore     = psms[i].ProteinScore;
                 }
             }
             if (bestScore > 0)
             {
                 return(psms[bestProteinIndex]);
             }
         }
     }
     return(null);
 }
Esempio n. 8
0
        public double ProbabilityScore(Peptide peptide = null, bool checkMods = false)
        {/*
          * double score = 0;
          * foreach(PeptideSpectrumMatch psm in psms)
          *     if(
          * foreach (PeptideSpectrumMatch psm in OptimizedBestPsms(peptide))
          *     score += (1 - score) * psm.OptimizedScore();
          * return score;
          * //*/
            if (peptide != null)
            {
                double score = 0;
                foreach (PeptideSpectrumMatch psm in psms)
                {
                    if (peptide.IsSamePeptide(psm.Peptide, checkMods))
                    {
                        score += psm.ProbabilityScore();
                    }
                }
                return(score);
            }
            else
            {
                return(OptimizedBestPsmScore(peptide, checkMods));//TODO Reactivate Optimized Precursor Score
            }
            //PeptideSpectrumMatch psmLeft = OptimizedBestPsm(peptide, checkMods);
            //if (psmLeft != null)
            //    return psmLeft.OptimizedScore();

            /*         (dIntensity * psmLeft.MatchingIntensityFraction +
             *                  dProduct * psmLeft.ProductScore +
             *                  dPrecursor * psmLeft.PrecursorScore +
             *                  dMatching * psmLeft.MatchingProductsFraction +
             *                  dProtein * psmLeft.ProteinScore +
             *                  dScore * psmLeft.MaxQuantScore() +
             *                  (Isotopes.Count > 0 ? dIsotope : 0) +
             *                  (Track.Invented ? dInvented : 0) +
             *                  dPeptideScore * psmLeft.PeptideScore);//*/
            //else
            //    return 0;//*/
        }
Esempio n. 9
0
        }//*/

        public double GetPrecursorMassError(Peptide peptide)
        {
            //Reproducibility is average number of replicates for conditions where seen
            double cumul  = 0;
            int    nbSeen = 0;

            foreach (clCondition condition in conditions)
            {
                if (condition != null)
                {
                    foreach (clReplicate replicate in condition.replicates)
                    {
                        foreach (Precursor precursor in replicate.precursors)
                        {
                            cumul += peptide.MonoisotopicMass - precursor.Mass;
                            nbSeen++;
                        }
                    }
                }
            }

            return(cumul / (double)nbSeen);
        }//*/
Esempio n. 10
0
        public IEnumerable <Peptide> GetSNPsdPeptides()
        {
            string strCumul = "";

            for (int i = 0; i < BaseSequence.Length; i++)
            {
                foreach (char letter in AminoAcidMasses.AMINO_ACIDS)
                {
                    if (BaseSequence[i] != letter)
                    {
                        Peptide newPeptide = new Peptide(this);
                        if (i + 1 < BaseSequence.Length)
                        {
                            newPeptide.BaseSequence = strCumul + letter + BaseSequence.Substring(i + 1);
                        }
                        else
                        {
                            newPeptide.BaseSequence = strCumul + letter;
                        }
                        yield return(newPeptide);
                    }
                }
            }
        }
Esempio n. 11
0
 public bool IsSamePeptide(Peptide peptide, bool checkMods)
 {
     if (BaseSequence.Equals(peptide.BaseSequence))
     {
         if (checkMods)
         {
             if (VariableModifications != null && peptide.VariableModifications != null)
             {
                 foreach (int key in VariableModifications.Keys)
                 {
                     if (!peptide.VariableModifications.ContainsKey(key) || VariableModifications[key] != peptide.VariableModifications[key])
                     {
                         return(false);
                     }
                 }
             }
         }
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 12
0
        public Peptide ComputeBestPeptide()
        {
            Dictionary <Peptide, double> peptides = new Dictionary <Peptide, double>();

            foreach (clCondition condition in conditions)
            {
                if (condition != null)
                {
                    foreach (clReplicate replicate in condition.replicates)
                    {
                        foreach (Precursor precursor in replicate.precursors)
                        {
                            foreach (PeptideSpectrumMatch psm in precursor.OptimizedBestPsms())
                            {
                                if (!peptides.ContainsKey(psm.Peptide))
                                {
                                    peptides.Add(psm.Peptide, ProbabilityScore(psm.Peptide));
                                }
                            }
                        }
                    }
                }
            }
            double  best        = -1;
            Peptide bestPeptide = null;

            foreach (Peptide key in peptides.Keys)
            {
                if (peptides[key] > best || (peptides[key] == best && bestPeptide.Decoy))
                {
                    best        = peptides[key];
                    bestPeptide = key;
                }
            }
            return(bestPeptide);
        }
Esempio n. 13
0
 private Peptide(Peptide peptide) : this(peptide.Parent, peptide.StartResidueNumber - 1, peptide.EndResidueNumber - 1, peptide.MissedCleavages)
 {
 }
Esempio n. 14
0
        public void ExportFragmentIntensitiesForAllPSM(List <PeptideSpectrumMatch> psms, Peptide peptide, int psmCharge, string fileName)
        {
            vsCSVWriter writer = new vsCSVWriter(fileName);
            string      title  = "Retention Time";

            for (int i = 1; i <= peptide.Length; i++)
            {
                for (int charge = 1; charge <= psmCharge; charge++)
                {
                    foreach (FragmentClass fragment in dbOptions.fragments)
                    {
                        title += "," + i + fragment.Name + " ^" + charge;
                    }
                }
            }
            writer.AddLine(title);

            foreach (PeptideSpectrumMatch psm in psms)
            {
                string line = psm.Query.spectrum.RetentionTimeInMin.ToString();
                for (int i = 1; i <= peptide.Length; i++)
                {
                    for (int charge = 1; charge <= psmCharge; charge++)
                    {
                        foreach (FragmentClass fragment in dbOptions.fragments)
                        {
                            double cumul = 0.0;
                            foreach (ProductMatch match in psm.AllProductMatches)
                            {
                                if (fragment == match.Fragment && match.fragmentPos == i && match.charge == charge)
                                {
                                    cumul += match.obsIntensity;
                                }
                            }
                            line += "," + cumul;
                        }
                    }
                }
                writer.AddLine(line);
            }
            writer.WriteToFile();
        }
Esempio n. 15
0
        public void ExportFragmentIntensities(List <PeptideSpectrumMatch> psms, Peptide peptide, int psmCharge, string fileName)
        {
            vsCSVWriter          writer    = new vsCSVWriter(fileName);
            List <FragmentClass> fragments = new List <FragmentClass>();

            foreach (FragmentClass fragment in dbOptions.fragments)
            //foreach (string fragment in FragmentDictionary.Fragments.Keys)
            {
                bool found = false;
                foreach (ProductMatch match in dbOptions.fragments.ComputeFragments(peptide, psmCharge, dbOptions))
                {
                    if (fragment == match.Fragment)
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    fragments.Add(fragment);
                }
            }

            string title = "Cumulated Product Intensities";

            for (int charge = 1; charge <= psmCharge; charge++)
            {
                foreach (FragmentClass fragment in dbOptions.fragments)
                {
                    title += "," + fragment.Name + " ^" + charge;
                }
            }
            for (int charge = 1; charge <= psmCharge; charge++)
            {
                foreach (FragmentClass fragment in fragments)
                {
                    title += "," + fragment.Name + " ^" + charge;
                }
            }
            writer.AddLine(title);

            for (int i = 1; i <= peptide.Length; i++)
            {
                string line = i.ToString();
                for (int charge = 1; charge <= psmCharge; charge++)
                {
                    foreach (FragmentClass fragment in dbOptions.fragments)
                    {
                        double cumul = 0.0;
                        foreach (PeptideSpectrumMatch psm in psms)
                        {
                            foreach (ProductMatch match in psm.AllProductMatches)
                            {
                                if (fragment == match.Fragment && match.fragmentPos == i && match.charge == charge)
                                {
                                    cumul += match.obsIntensity;
                                }
                            }
                        }
                        line += "," + cumul;
                    }
                }
                for (int charge = 1; charge <= psmCharge; charge++)
                {
                    foreach (FragmentClass fragment in fragments)
                    {
                        double cumul = 0.0;
                        foreach (PeptideSpectrumMatch psm in psms)
                        {
                            foreach (ProductMatch match in psm.AllProductMatches)
                            {
                                if (fragment == match.Fragment && match.fragmentPos == i && match.charge == charge)
                                {
                                    cumul += match.obsIntensity;
                                }
                            }
                        }
                        line += "," + cumul;
                    }
                }
                writer.AddLine(line);
            }
            writer.WriteToFile();
        }
Esempio n. 16
0
        public IEnumerable <ProductMatch> ComputeFragments(Peptide peptide, int precursorKnownCharge, DBOptions dbOptions)
        {
            int maxCharge;

            if (precursorKnownCharge > 1)
            {
                maxCharge = precursorKnownCharge - 1;
            }
            else
            {
                maxCharge = precursorKnownCharge;
            }

            string       sequence = peptide.BaseSequence;
            ProductMatch match    = new ProductMatch();

            double cumulativeNTerminalMass = 0; // 1.007276 + 15.9949;//TODO Add NTerminal modifications here
            double cumulativeCTerminalMass = 0; // 1.007276;//TODO Add CTerminal modifications here
            string cumulSeq    = "";
            string cumulRevSeq = "";

            for (int r = 1; r <= sequence.Length; r++)
            {
                match.fragmentPos = r;
                //Peptide mods, computed during digestion
                //TODO Only search for modifications that were seen in the spectrum
                double tmp = 0;
                cumulSeq += sequence[r - 1];
                if (peptide.FixedModifications != null && peptide.FixedModifications.ContainsKey(r + 1))
                {
                    foreach (Modification mod in peptide.FixedModifications[r + 1])
                    {
                        tmp += mod.MonoisotopicMassShift;
                    }
                }
                if (peptide.VariableModifications != null && peptide.VariableModifications.ContainsKey(r + 1))
                {
                    tmp += peptide.VariableModifications[r + 1].MonoisotopicMassShift;
                }
                cumulativeNTerminalMass += AminoAcidMasses.GetMonoisotopicMass(sequence[r - 1]) + tmp;

                tmp          = 0;
                cumulRevSeq += sequence[sequence.Length - r];
                if (peptide.FixedModifications != null && peptide.FixedModifications.ContainsKey(sequence.Length + 2 - r))
                {
                    foreach (Modification mod in peptide.FixedModifications[sequence.Length + 2 - r])
                    {
                        tmp += mod.MonoisotopicMassShift;
                    }
                }
                if (peptide.VariableModifications != null && peptide.VariableModifications.ContainsKey(sequence.Length + 2 - r))
                {
                    tmp += peptide.VariableModifications[sequence.Length + 2 - r].MonoisotopicMassShift;
                }
                cumulativeCTerminalMass += AminoAcidMasses.GetMonoisotopicMass(sequence[sequence.Length - r]) + tmp;

                for (int c = maxCharge; c > 0; c--)
                {
                    match.charge = c;
                    foreach (FragmentClass fragment in this)
                    {
                        if (fragment.IsReverse)
                        {
                            match.fragmentPos = 1 + sequence.Length - r;
                        }
                        else
                        {
                            match.fragmentPos = r;
                        }
                        match.Fragment = fragment;

                        foreach (double product_mass in fragment.ComputeFragment(cumulativeCTerminalMass, cumulativeNTerminalMass))
                        {
                            match.weight = fragment.Distribution;//TODO Adjust this value by computing overall impact (times 10?)
                            //ModLess
                            match.theoMz = Numerics.MZFromMass(product_mass, c);
                            yield return(match);

                            //Added mods
                            if (dbOptions.addFragmentMods)
                            {
                                foreach (Modification mod in FragmentDictionary.Fragments.Values)
                                {
                                    if ((fragment.IsReverse ? cumulRevSeq : cumulSeq).Contains(mod.AminoAcid))
                                    {
                                        //!!!!match.Fragment = mod;
                                        match.weight = fragment.Distribution * mod.Probability;
                                        match.theoMz = Numerics.MZFromMass(product_mass + mod.MonoisotopicMassShift, c);
                                        yield return(match);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (dbOptions.addFragmentLoss)
            {
                match.charge   = 1;
                match.Fragment = FragLossObject;
                foreach (Modification mod in FragmentDictionary.AAFragments.Values)
                {
                    if (peptide.BaseSequence.Contains(mod.AminoAcid))
                    {
                        match.fragmentPos = peptide.BaseSequence.IndexOf(mod.AminoAcid);
                        match.theoMz      = mod.MonoisotopicMassShift;// Numerics.MZFromMass(mod.MonoisotopicMassShift, 1);
                        match.weight      = mod.Probability;
                        yield return(match);
                    }
                }
            }
        }
Esempio n. 17
0
        }//*/

        /*
         * private static IEnumerable<double> fragmentsTypesCTerm(double cTermCumul)
         * {
         *  yield return cTermCumul + Constants.OXYGEN_MASS * 2 + Constants.HYDROGEN_MASS + Constants.CARBON_MASS;//X
         *  yield return cTermCumul + Constants.OXYGEN_MASS + Constants.HYDROGEN_MASS * 3;//Y
         *  yield return cTermCumul + Constants.OXYGEN_MASS + Constants.HYDROGEN_MASS - Constants.NITROGEN_MASS - Constants.HYDROGEN_MASS;//Z
         * }    //*/
        public static IEnumerable <ProductMatch> ComputeAllFragments(Peptide peptide, int precursorKnownCharge, DBOptions dbOptions)
        {
            int maxCharge;

            if (precursorKnownCharge > 1)
            {
                maxCharge = precursorKnownCharge - 1;
            }
            else
            {
                maxCharge = 1;
            }
            FragmentA fragNTerm = new FragmentA();
            FragmentX fragCTerm = new FragmentX();

            double[]     masses = peptide.GetMasses();
            ProductMatch match  = new ProductMatch();

            match.weight = 1;
            double cumulN = 0.0; // Constants.WATER_MONOISOTOPIC_MASS;
            double cumulC = 0.0; // Constants.WATER_MONOISOTOPIC_MASS;

            for (int r = 0; r < masses.Length; r++)
            {
                cumulN += masses[r];
                cumulC += masses[masses.Length - r - 1];

                foreach (double product_mass in fragmentsTypesCTerm(cumulC))
                {
                    match.fragmentPos = masses.Length - r;
                    match.Fragment    = fragCTerm;
                    for (int c = maxCharge; c > 0; c--)
                    {
                        match.theoMz = Numerics.MZFromMass(product_mass, c);
                        match.charge = c;
                        yield return(match);
                        //match.theoMz = Numerics.MZFromMass(product_mass - Constants.WATER_MONOISOTOPIC_MASS, c);
                        //yield return match;
                    }
                }

                foreach (double product_mass in fragmentsTypesNTerm(cumulN))
                {
                    match.fragmentPos = r + 1;
                    match.Fragment    = fragNTerm;
                    for (int c = maxCharge; c > 0; c--)
                    {
                        match.theoMz = Numerics.MZFromMass(product_mass, c);
                        match.charge = c;
                        yield return(match);

                        match.theoMz = Numerics.MZFromMass(product_mass - Constants.WATER_MONOISOTOPIC_MASS, c);
                        yield return(match);

                        match.theoMz = Numerics.MZFromMass(product_mass - Constants.AMONIA_MASS, c);
                        yield return(match);
                    }
                }
            }
            //Single charge immonium ions
            //Water Loss
            //Amonia Loss
            //Internal fragments
            //Fragment types
        }
Esempio n. 18
0
        public IEnumerable <Peptide> GetVariablyModifiedPeptides(IEnumerable <Modification> variableModifications, int maximumVariableModificationIsoforms)
        {
            Dictionary <int, List <Modification> > possible_modifications = new Dictionary <int, List <Modification> >(Length + 4);

            foreach (Modification variable_modification in variableModifications)
            {
                if (variable_modification.Type == ModificationType.ProteinNTerminus && (StartResidueNumber == 1 || (StartResidueNumber == 2 && Parent[0] == 'M')))
                {
                    List <Modification> prot_n_term_variable_mods;
                    if (!possible_modifications.TryGetValue(0, out prot_n_term_variable_mods))
                    {
                        prot_n_term_variable_mods = new List <Modification>();
                        prot_n_term_variable_mods.Add(variable_modification);
                        possible_modifications.Add(0, prot_n_term_variable_mods);
                    }
                    else
                    {
                        prot_n_term_variable_mods.Add(variable_modification);
                    }
                }

                if (variable_modification.Type == ModificationType.PeptideNTerminus)
                {
                    List <Modification> pep_n_term_variable_mods;
                    if (!possible_modifications.TryGetValue(1, out pep_n_term_variable_mods))
                    {
                        pep_n_term_variable_mods = new List <Modification>();
                        pep_n_term_variable_mods.Add(variable_modification);
                        possible_modifications.Add(1, pep_n_term_variable_mods);
                    }
                    else
                    {
                        pep_n_term_variable_mods.Add(variable_modification);
                    }
                }

                for (int r = 0; r < Length; r++)
                {
                    if (variable_modification.Type == ModificationType.AminoAcidResidue && this[r] == variable_modification.AminoAcid)
                    {
                        List <Modification> residue_variable_mods;
                        if (!possible_modifications.TryGetValue(r + 2, out residue_variable_mods))
                        {
                            residue_variable_mods = new List <Modification>();
                            residue_variable_mods.Add(variable_modification);
                            possible_modifications.Add(r + 2, residue_variable_mods);
                        }
                        else
                        {
                            residue_variable_mods.Add(variable_modification);
                        }
                    }
                }

                if (variable_modification.Type == ModificationType.PeptideCTerminus)
                {
                    List <Modification> pep_c_term_variable_mods;
                    if (!possible_modifications.TryGetValue(Length + 2, out pep_c_term_variable_mods))
                    {
                        pep_c_term_variable_mods = new List <Modification>();
                        pep_c_term_variable_mods.Add(variable_modification);
                        possible_modifications.Add(Length + 2, pep_c_term_variable_mods);
                    }
                    else
                    {
                        pep_c_term_variable_mods.Add(variable_modification);
                    }
                }

                if (variable_modification.Type == ModificationType.ProteinCTerminus && (EndResidueNumber == Parent.Length - 1))
                {
                    List <Modification> prot_c_term_variable_mods;
                    if (!possible_modifications.TryGetValue(Length + 3, out prot_c_term_variable_mods))
                    {
                        prot_c_term_variable_mods = new List <Modification>();
                        prot_c_term_variable_mods.Add(variable_modification);
                        possible_modifications.Add(Length + 3, prot_c_term_variable_mods);
                    }
                    else
                    {
                        prot_c_term_variable_mods.Add(variable_modification);
                    }
                }
            }

            int variable_modification_isoforms = 0;

            foreach (Dictionary <int, Modification> kvp in GetVariableModificationPatterns(possible_modifications))
            {
                Peptide peptide = new Peptide(this);
                peptide.SetFixedModifications(FixedModifications);
                peptide.SetVariableModifications(kvp);
                yield return(peptide);

                variable_modification_isoforms++;
                if (variable_modification_isoforms >= maximumVariableModificationIsoforms)
                {
                    yield break;
                }
            }
        }
 public PeptideMatch(Peptide peptide)
 {
     this.peptide = peptide;
     clusters     = new GraphML_List <Cluster>();
 }
Esempio n. 20
0
 public double ScoreFct(Peptide peptide = null)
 {
     return(precursor.ProbabilityScore(peptide));
 }
        }//*/

        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;
                }
            }
        }
        public AnnotatedSpectrum(Sample sample, ProductSpectrum spectrum, Peptide peptide)
        {
            sequence = peptide.BaseSequence;
            peaks    = new double[spectrum.Peaks.Count][];
            for (int i = 0; i < peaks.Length; i++)
            {
                peaks[i]    = new double[2];
                peaks[i][0] = spectrum.Peaks[i].MZ;
                peaks[i][1] = spectrum.Peaks[i].Intensity;
            }
            scanNum     = spectrum.ScanNumber;
            charge      = spectrum.PrecursorCharge;
            precursorMz = spectrum.PrecursorMZ;
            fileName    = sample.sSDF;

            //Fixed modifications
            List <AnnotatedSpectrumModification> fixedMods = new List <AnnotatedSpectrumModification>();

            if (peptide.FixedModifications != null)
            {
                foreach (int position in peptide.FixedModifications.Keys)
                {
                    if (position == 1)
                    {
                        foreach (Modification mod in peptide.FixedModifications[position])
                        {
                            ntermMod += mod.MonoisotopicMassShift;
                        }
                    }
                    else
                    if (position == sequence.Length + 2)
                    {
                        foreach (Modification mod in peptide.FixedModifications[position])
                        {
                            ctermMod += mod.MonoisotopicMassShift;
                        }
                    }
                    else
                    {
                        foreach (Modification mod in peptide.FixedModifications[position])
                        {
                            fixedMods.Add(new AnnotatedSpectrumModification(mod.AminoAcid, mod.MonoisotopicMassShift, position - 1));
                        }
                    }
                }
            }
            staticMods = fixedMods.ToArray();

            //Variable modifications
            List <AnnotatedSpectrumModification> varMods = new List <AnnotatedSpectrumModification>();

            if (peptide.VariableModifications != null)
            {
                foreach (int position in peptide.VariableModifications.Keys)
                {
                    if (position == 1)
                    {
                        ntermMod += peptide.VariableModifications[position].MonoisotopicMassShift;
                    }
                    else
                    if (position == sequence.Length + 2)
                    {
                        ctermMod += peptide.VariableModifications[position].MonoisotopicMassShift;
                    }
                    else
                    {
                        varMods.Add(new AnnotatedSpectrumModification(peptide.VariableModifications[position].AminoAcid, peptide.VariableModifications[position].MonoisotopicMassShift, position - 1));
                    }
                }
            }
            variableMods = varMods.ToArray();

            /*
             * var sequence = "FDSFGDLSSASAIMGNPK";
             * var varMods = [];
             * // modification index = 14; modification mass = 16.0; modified residue = 'M'
             * varMods[0] = { index: 14, modMass: 16.0, aminoAcid: 'M' };
             * // mass to be added to the N-terminus
             * var ntermMod = 164.07;//*/
        }