public double GetMonoisotopicMassShift(char aa)
 {
     if (aa == AminoAcid)
     {
         return(MonoisotopicMassShift + AminoAcidMasses.GetMonoisotopicMass(aa));
     }
     else
     {
         return(0);
     }
 }
Esempio n. 2
0
        public List <PeptideView> GetPeptides(Spectrum spectrum, DBOptions options)
        {
            char[] ignoreAA = GetFixedModAA(options.fixedModifications);

            List <PeptideView> results = new List <PeptideView>();

            //Modless and Single variable mod peptides
            List <Modification> allMods = new List <Modification>(options.variableModifications);

            foreach (Modification mod in options.fixedModifications)
            {
                allMods.Add(mod);
            }
            allMods.Add(null);

            foreach (Modification mod in allMods)
            {
                IEnumerable <IList <char> > enumeration;
                if (mod == null)
                {
                    enumeration = FindPeptides(spectrum.PrecursorMass, ignoreAA);
                }
                else
                {
                    enumeration = FindPeptidesWithMods(spectrum.PrecursorMass, mod);
                }
                foreach (IList <char> str in enumeration)
                {
                    string   sequence = string.Concat(str);
                    double[] masses   = new double[sequence.Length];
                    for (int i = 0; i < sequence.Length; i++)
                    {
                        masses[i] = AminoAcidMasses.GetMonoisotopicMass(sequence[i]);
                    }
                    if (mod != null)
                    {
                        for (int i = 0; i < sequence.Length; i++)
                        {
                            if (sequence[i] == mod.AminoAcid)
                            {
                                double[] modMasses = new List <double>(masses).ToArray();
                                modMasses[i] += mod.MonoisotopicMassShift;
                                double score = DotNetMHC.Analysis.PeptideCoverage.PSMScoreMatch(modMasses, sequence.Length, spectrum.PrecursorCharge, spectrum, options);
                                if (score > 0)
                                {
                                    results.Add(new PeptideView(sequence, modMasses, spectrum.PrecursorMass, score, mod, i));
                                }
                            }
                        }
                    }
                    else
                    {
                        double score = DotNetMHC.Analysis.PeptideCoverage.PSMScoreMatch(masses, sequence.Length, spectrum.PrecursorCharge, spectrum, options);
                        if (score > 0)
                        {
                            results.Add(new PeptideView(sequence, masses, spectrum.PrecursorMass, score));
                        }
                    }
                }
            }
            return(results);
        }
        public static bool Run()
        {
            //TODO test GPU instead
            DBOptions dbOptions = MhcSample.CreateOptions("");
            Dictionary <string, int> sequences = new Dictionary <string, int>();
            List <Protein>           proteins  = Propheus.ReadProteomeFromFasta(Path.Combine(Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]), "UnitTest", "proteins.fasta"), false, dbOptions);//ETLPAMCNVYYVNCMAPLTE
            string sequence = proteins[0].BaseSequence;

            double[] proteinMasses = new double[sequence.Length];

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

            for (int i = 0; i < sequence.Length; i++)
            {
                for (int j = i + dbOptions.MinimumPeptideLength - 1; j < sequence.Length; j++)
                {
                    int size = j - i + 1;
                    if (size <= dbOptions.MaximumPeptideLength)
                    {
                        string subStr = sequence.Substring(i, j - i + 1);
                        if (!sequences.ContainsKey(subStr))
                        {
                            sequences.Add(subStr, 1);
                        }
                        else
                        {
                            sequences[subStr]++;
                        }

                        double mass = Constants.WATER_MONOISOTOPIC_MASS;
                        for (int k = 0; k < subStr.Length; k++)
                        {
                            mass += AminoAcidMasses.GetMonoisotopicMass(subStr[k]);
                        }
                        precursors.Add(mass);
                    }
                }
                proteinMasses[i] = AminoAcidMasses.GetMonoisotopicMass(sequence[i]);
            }
            precursors.Sort();

            Queries        queries = new Queries(dbOptions, precursors.ToArray());
            Digestion      ps      = new Digestion(dbOptions);
            List <Protein> lProt   = new List <Protein>();

            lProt.Add(proteins[0]);
            //for each protein, build matrix of mass
            //Trinity_Gpu.ProteinDigest pg = new Trinity_Gpu.ProteinDigest(precursors.ToArray(), sequence.Length);
            //Test twice to test that precursor list stays in gpu memory
            for (int iter = 0; iter < 2; iter++)
            {
                Dictionary <string, int> sequencesTmp = new Dictionary <string, int>(sequences);

                foreach (Tuple <Peptide, int> item in ps.DigestProteomeOnTheFlyNoEnzyme(lProt, queries))
                {
                    sequencesTmp[item.Item1.BaseSequence] -= 1;//TODO add modifications
                }

                /*
                 * foreach (Trinity_Gpu.ProteinPrecursorMatch match in pg.Execute(proteinMasses, 0.00005, 10000000))//TODO compute correct tolerance window
                 * {
                 *  int size = match.proteinEndPos - match.proteinStartPos;
                 *  string str = sequence.Substring(match.proteinStartPos, size);
                 *  if (size >= dbOptions.MinimumPeptideLength)
                 *  {
                 *      sequencesTmp[str] -= 1;//TODO add modifications
                 *  }
                 * }//*/

                foreach (int val in sequencesTmp.Values)
                {
                    if (val != 0)
                    {
                        return(false);//*/
                    }
                }
            }
            //pg.Dispose();
            return(true);
        }