Пример #1
0
        private IEnumerable <IList <char> > FindPeptides(double mass, char[] ignoreAA)
        {
            int index = (int)(mass / Precision);

            string[] combinations = emptyArray;
            if (Dictionary.ContainsKey(index))
            {
                combinations = Dictionary[index].Split(',');
            }
            foreach (string comb in combinations)
            {
                bool keepIt = true;
                foreach (char c in comb)
                {
                    if (ignoreAA.Contains(c))
                    {
                        keepIt = false;
                    }
                }
                if (keepIt)
                {
                    double SeqMass = AminoAcidMasses.GetMass(comb);
                    if (Math.Abs(SeqMass - mass) < Precision)
                    {
                        foreach (IList <char> str in new Permutations <char>(new List <char>(comb), GenerateOption.WithoutRepetition))
                        {
                            yield return(str);
                        }
                    }
                }
            }
        }
Пример #2
0
        public void TestAminoAcidMassesDefaultLysine()
        {
            var MassesList1 = new AminoAcidMasses(true, true);

            Assert.AreEqual(136.109162, MassesList1.AA_Masses['K']);
            var MassesList2 = new AminoAcidMasses(true, false);

            Assert.Less(MassesList2.AA_Masses['K'], 136.109162);
        }
Пример #3
0
 public double GetMonoisotopicMassShift(char aa)
 {
     if (aa == AminoAcid)
     {
         return(MonoisotopicMassShift + AminoAcidMasses.GetMonoisotopicMass(aa));
     }
     else
     {
         return(0);
     }
 }
Пример #4
0
        public void TestAminoAcidMassesConstructor()
        {
            var MassesList1 = new AminoAcidMasses(true, false);

            Assert.AreEqual(131.040485, MassesList1.AA_Masses['M']);
            Assert.AreEqual(160.030649, MassesList1.AA_Masses['C']);

            var MassesList2 = new AminoAcidMasses(false, false);

            Assert.AreEqual(131.040485, MassesList2.AA_Masses['M']);
            Assert.AreEqual(103.009185, MassesList2.AA_Masses['C']);
        }
Пример #5
0
        public List <string> GetPermutations(double mass)
        {
            List <string> results = new List <string>();
            int           index   = (int)(mass / Precision);

            string[] combinations = emptyArray;
            if (Dictionary.ContainsKey(index))
            {
                combinations = Dictionary[index].Split(',');
            }
            foreach (string comb in combinations)
            {
                double SeqMass = AminoAcidMasses.GetMass(comb);
                if (Math.Abs(SeqMass - mass) < Precision)
                {
                    foreach (IList <char> str in new Permutations <char>(new List <char>(comb), GenerateOption.WithoutRepetition))
                    {
                        results.Add(string.Concat(str));
                    }
                }
            }
            return(results);
        }
Пример #6
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);
        }