示例#1
0
        public void DynamicProgrammingTest()
        {
            List <List <GUI> > guis = new List <List <GUI> >()
            {
                new List <GUI>()
                {
                    // unit, scan, peak
                    new GUI(2, 1, new GeneralPeak(1, 2)),
                    new GUI(3, 1, new GeneralPeak(1, 10)),
                    new GUI(4, 1, new GeneralPeak(1, 4)),
                },

                new List <GUI>()
                {
                    // unit, scan, peak
                    new GUI(2, 2, new GeneralPeak(1, 4)),
                    new GUI(3, 2, new GeneralPeak(1, 10)),
                    new GUI(3, 2, new GeneralPeak(1, 2)),
                },

                new List <GUI>()
                {
                    // unit, scan, peak
                    new GUI(3, 3, new GeneralPeak(1, 11)),
                    new GUI(4, 3, new GeneralPeak(1, 10)),
                    new GUI(5, 3, new GeneralPeak(1, 12)),
                },

                new List <GUI>()
                {
                    // unit, scan, peak
                    new GUI(4, 4, new GeneralPeak(1, 10)),
                    new GUI(5, 4, new GeneralPeak(1, 14)),
                    new GUI(7, 4, new GeneralPeak(1, 10)),
                },

                new List <GUI>()
                {
                    // unit, scan, peak
                    new GUI(3, 5, new GeneralPeak(1, 15)),
                    new GUI(5, 5, new GeneralPeak(1, 3)),
                    new GUI(6, 5, new GeneralPeak(1, 4)),
                },
            };

            IGUISequencer sequencer = new DynamicProgrammingSequencer();
            List <GUI>    GuiPoints = sequencer.Choose(guis);

            foreach (GUI g in GuiPoints)
            {
                Console.WriteLine(g.Unit);
            }

            Assert.Pass();
        }
示例#2
0
        static List <GUI> Init(ref ICurveFitting Fitter, ISpectrumReader reader)
        {
            double        ppm        = 5;
            object        resultLock = new object();
            List <double> Retention  = new List <double>();
            List <double> Guis       = new List <double>();

            IGUIFinder finder  = new BinarySearchFinder(ppm);
            IProcess   picking = new LocalNeighborPicking();
            Dictionary <int, List <GUI> > pointMaps = new Dictionary <int, List <GUI> >();

            int start = reader.GetFirstScan();
            int end   = reader.GetLastScan();

            Parallel.For(start, end, (i) =>
            {
                if (reader.GetMSnOrder(i) < 2)
                {
                    ISpectrum spectrum = picking.Process(reader.GetSpectrum(i));
                    lock (resultLock)
                    {
                        pointMaps[i] = finder.FindGlucoseUnits(spectrum);
                    }
                }
            });


            List <List <GUI> > points =
                pointMaps.OrderBy(p => p.Key).Select(p => p.Value).ToList();

            IGUISequencer sequencer = new DynamicProgrammingSequencer();
            List <GUI>    GuiPoints = sequencer.Choose(points);

            Fitter = new PolynomialFitting();

            Dictionary <int, GUI> guiSelected = new Dictionary <int, GUI>();

            foreach (GUI gui in GuiPoints)
            {
                if (guiSelected.ContainsKey(gui.Unit))
                {
                    if (guiSelected[gui.Unit].Peak.GetIntensity() < gui.Peak.GetIntensity())
                    {
                        guiSelected[gui.Unit] = gui;
                    }
                }
                else
                {
                    guiSelected[gui.Unit] = gui;
                }
            }

            Retention.Clear();
            Guis.Clear();

            List <GUI> guiChoice = guiSelected.Values.OrderBy(g => g.Scan).ToList();

            foreach (GUI gui in guiChoice)
            {
                int    scan = gui.Scan;
                double time = reader.GetRetentionTime(scan);
                Retention.Add(time);
                Guis.Add(gui.Unit);
            }

            Fitter.Fit(Retention, Guis);

            return(GuiPoints);
        }
示例#3
0
        public void Run(string path, Counter counter)
        {
            ISpectrumReader reader = new ThermoRawSpectrumReader();

            reader.Init(path);

            IGUIFinder finder  = new BinarySearchFinder(PPM);
            IProcess   picking = new LocalNeighborPicking();
            Dictionary <int, List <GUI> > pointMaps = new Dictionary <int, List <GUI> >();

            int start = reader.GetFirstScan();
            int end   = reader.GetLastScan();

            Parallel.For(start, end, (i) =>
            {
                if (reader.GetMSnOrder(i) < 2)
                {
                    ISpectrum spectrum = picking.Process(reader.GetSpectrum(i));
                    lock (resultLock)
                    {
                        pointMaps[i] = finder.FindGlucoseUnits(spectrum);
                    }
                }
                counter.Add(end - start);
            });
            List <List <GUI> > points =
                pointMaps.OrderBy(p => p.Key).Select(p => p.Value).ToList();

            IGUISequencer sequencer = new DynamicProgrammingSequencer();
            List <GUI>    guiPoints = sequencer.Choose(points);

            Dictionary <int, GUI> guiSelected = new Dictionary <int, GUI>();

            foreach (GUI gui in guiPoints)
            {
                if (guiSelected.ContainsKey(gui.Unit))
                {
                    if (guiSelected[gui.Unit].Peak.GetIntensity() < gui.Peak.GetIntensity())
                    {
                        guiSelected[gui.Unit] = gui;
                    }
                }
                else
                {
                    guiSelected[gui.Unit] = gui;
                }
            }

            Retention.Clear();
            Guis.Clear();

            List <GUI> looped = guiSelected.Values.OrderBy(g => g.Scan).ToList();
            string     output = Path.Combine(Path.GetDirectoryName(path),
                                             Path.GetFileNameWithoutExtension(path) + ".csv");

            using (FileStream ostrm = new FileStream(output, FileMode.OpenOrCreate, FileAccess.Write))
            {
                using (StreamWriter writer = new StreamWriter(ostrm))
                {
                    writer.WriteLine("scan,time,gui,peak,intensity");
                    foreach (GUI gui in looped)
                    {
                        int    scan = gui.Scan;
                        double time = reader.GetRetentionTime(scan);
                        Retention.Add(time);
                        Guis.Add(gui.Unit);
                        writer.WriteLine(scan.ToString() + "," +
                                         time.ToString() + "," +
                                         gui.Unit.ToString() + "," +
                                         gui.Peak.GetMZ().ToString() + "," +
                                         gui.Peak.GetIntensity().ToString());
                    }
                    writer.Flush();
                }
            }
            Fitter.Fit(Retention, Guis);
        }