public static IIdentifiedResult DoBuildGroupByPeptide(List <IIdentifiedSpectrum> spectra, Func <IIdentifiedPeptide, string> func)
        {
            IdentifiedResult result = new IdentifiedResult();

            var singlePeptides = (from s in spectra
                                  where s.Peptides.Count == 1
                                  select s).GroupBy(m => func(m.Peptide));

            var multiplePeptides = (from s in spectra
                                    where s.Peptides.Count > 1
                                    select s).ToList();

            Dictionary <string, List <IIdentifiedPeptide> > dic = new Dictionary <string, List <IIdentifiedPeptide> >();

            foreach (var g in singlePeptides)
            {
                dic[g.Key] = new List <IIdentifiedPeptide>(from s in g
                                                           select s.Peptide);
            }

            foreach (var o in multiplePeptides)
            {
                var pc = (from p in o.Peptides
                          let c = dic.ContainsKey(func(p)) ? dic[func(p)].Count : 0
                                  orderby c descending
                                  select p).First();
                if (!dic.ContainsKey(func(pc)))
                {
                    dic[func(pc)] = new List <IIdentifiedPeptide>();
                }
                dic[func(pc)].Add(pc);
            }

            var keys = new List <string>(dic.Keys);

            keys.Sort();

            foreach (var key in keys)
            {
                IdentifiedProtein protein = new IdentifiedProtein(key);
                protein.Peptides.AddRange(dic[key]);
                protein.UniquePeptideCount = 1;
                protein.Description        = dic[key][0].Proteins.Merge('/');

                IdentifiedProteinGroup group = new IdentifiedProteinGroup();
                group.Add(protein);

                result.Add(group);
            }

            result.BuildGroupIndex();
            //result.Sort();

            return(result);
        }
Exemplo n.º 2
0
        public void TestFilter2()
        {
            var spectrum = new IdentifiedSpectrum();

            spectrum.Query.FileScan.LongFileName = "ABDCDD.12.123.2.dat";

            var pro1 = new IdentifiedProtein("P1");

            pro1.Peptides.Add(new IdentifiedPeptide(spectrum)
            {
                Sequence = "AAAAAAA"
            });

            var pro2 = new IdentifiedProtein("P2");

            pro2.Peptides.Add(new IdentifiedPeptide(spectrum)
            {
                Sequence = "BBBBBBB"
            });

            var g1 = new IdentifiedProteinGroup();

            g1.Add(pro1);
            g1.Add(pro2);

            IdentifiedResult ir = new IdentifiedResult();

            ir.Add(g1);

            Assert.AreEqual(1, ir.Count);
            Assert.AreEqual(2, ir[0].Count);
            Assert.AreEqual(1, ir.GetSpectra().Count);

            ir.Filter(m =>
            {
                return(m.Sequence.Contains('A'));
            });

            Assert.AreEqual(1, ir.Count);
            Assert.AreEqual(1, ir[0].Count);
            Assert.AreEqual(1, ir.GetSpectra().Count);
            Assert.AreSame(pro1, ir[0][0]);

            ir.Filter(m =>
            {
                return(m.Sequence.Contains('C'));
            });

            Assert.AreEqual(0, ir.Count);
        }
Exemplo n.º 3
0
        public void TestFilter()
        {
            var pro1 = new IdentifiedProtein("P1");

            pro1.Peptides.Add(new IdentifiedPeptide(new IdentifiedSpectrum()
            {
                Charge = 1
            }));
            pro1.Peptides.Add(new IdentifiedPeptide(new IdentifiedSpectrum()
            {
                Charge = 2
            }));

            var pro2 = new IdentifiedProtein("P2");

            pro2.Peptides.Add(new IdentifiedPeptide(new IdentifiedSpectrum()
            {
                Charge = 3
            }));

            var g1 = new IdentifiedProteinGroup();

            g1.Add(pro1);

            var g2 = new IdentifiedProteinGroup();

            g2.Add(pro2);

            IdentifiedResult ir = new IdentifiedResult();

            ir.Add(g1);
            ir.Add(g2);

            Assert.AreEqual(2, ir.Count);
            Assert.AreEqual(3, ir.GetSpectra().Count);

            ir.Filter(m => { return(m.Spectrum.Query.Charge > 1); });

            Assert.AreEqual(2, ir.Count);
            Assert.AreEqual(2, ir.GetSpectra().Count);
            ir.GetSpectra().All(m => { return(m.Charge > 1); });

            ir.Filter(m => { return(m.Spectrum.Query.Charge > 2); });
            Assert.AreEqual(1, ir.Count);
            Assert.AreEqual(1, ir.GetSpectra().Count);
            ir.GetSpectra().All(m => { return(m.Charge > 2); });

            Assert.AreEqual("P2", ir[0][0].Name);
        }
        public IIdentifiedResult Build(List <IIdentifiedProteinGroup> groups)
        {
            IdentifiedResult result = new IdentifiedResult();

            result.AddRange(groups);
            result.Sort();
            result.BuildGroupIndex();

            if (FillSequence(result))
            {
                AveragePeptideMassCalculator massCalc = new AveragePeptideMassCalculator(new Aminoacids(), Atom.H.AverageMass, Atom.H.AverageMass + Atom.O.AverageMass);

                Progress.SetMessage("Calculating coverage and mass weight ...");
                foreach (IIdentifiedProteinGroup group in result)
                {
                    foreach (IIdentifiedProtein protein in group)
                    {
                        if (!string.IsNullOrEmpty(protein.Sequence))
                        {
                            try
                            {
                                protein.CalculateCoverage();
                                protein.MolecularWeight = massCalc.GetMass(protein.Sequence);
                            }
                            catch (Exception ex)
                            {
                                var error = "Calculating coverage and mass weight error:" + ex.Message;
                                Progress.SetMessage(error);
                                Console.Error.WriteLine(error);
                            }
                        }
                    }
                }
            }

            return(result);
        }