Exemple #1
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);
        }
Exemple #2
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);
        }