コード例 #1
0
        public void Run(string path, Counter counter, ISpectrumReader spectrumReader, NormalizerEngine normalizer)
        {
            NGlycanTheoryPeaksBuilder builder = new NGlycanTheoryPeaksBuilder();

            builder.SetBuildType(true, false, false);
            List <IGlycanPeak> glycans = builder.Build();

            spectrumReader.Init(path);

            IResultSelect resultSelect = new ResultMaxSelect(SearchingParameters.Access.Threshold,
                                                             SearchingParameters.Access.PeakCutoff);
            List <IResult> final = new List <IResult>();

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

            Parallel.For(start, end, (i) =>
            {
                if (spectrumReader.GetMSnOrder(i) < 2)
                {
                    IResultFactory factory          = new NGlycanResultFactory();
                    EnvelopeProcess envelopeProcess = new EnvelopeProcess(
                        SearchingParameters.Access.Tolerance,
                        SearchingParameters.Access.ToleranceBy);
                    MonoisotopicSearcher monoisotopicSearcher = new MonoisotopicSearcher(factory);
                    IProcess spectrumProcess       = new LocalNeighborPicking();
                    ISpectrumSearch spectrumSearch = new NGlycanSpectrumSearch(glycans,
                                                                               spectrumProcess, envelopeProcess, monoisotopicSearcher,
                                                                               SearchingParameters.Access.MaxCharage, SearchingParameters.Access.Cutoff);

                    ISpectrum spectrum     = spectrumReader.GetSpectrum(i);
                    List <IResult> results = spectrumSearch.Search(spectrum);
                    lock (resultLock)
                    {
                        resultSelect.Add(results);
                        final.AddRange(results);
                    }
                }
                counter.Add(end - start);
            });

            //original
            string outputPath = Path.Combine(Path.GetDirectoryName(path),
                                             Path.GetFileNameWithoutExtension(path) + "_one_quant.csv");
            List <string> outputString = new List <string>();

            foreach (IResult present in final.OrderBy(r => r.GetRetention()))
            {
                int    scan  = present.GetScan();
                double rt    = present.GetRetention();
                double index = Math.Round(normalizer.Normalize(rt), 2);

                TIQ3XIC xicer = new TIQ3XIC(spectrumReader);
                double  area  = xicer.OneArea(present);

                List <string> output;
                if (!normalizer.Initialized())
                {
                    output = new List <string>()
                    {
                        scan.ToString(), rt.ToString(),
                                         present.Glycan().GetGlycan().Name(),
                                         present.GetMZ().ToString(),
                                         area.ToString(),
                    };
                }
                else
                {
                    output = new List <string>()
                    {
                        scan.ToString(), rt.ToString(),
                                         index > 0? index.ToString():"0",
                                         present.Glycan().GetGlycan().Name(),
                                         present.GetMZ().ToString(),
                                         area.ToString(),
                    };
                }
                outputString.Add(string.Join(",", output));
            }

            using (FileStream ostrm = new FileStream(outputPath, FileMode.OpenOrCreate, FileAccess.Write))
            {
                using (StreamWriter writer = new StreamWriter(ostrm))
                {
                    if (!normalizer.Initialized())
                    {
                        writer.WriteLine("scan,time,glycan,mz,area");
                    }
                    else
                    {
                        writer.WriteLine("scan,time,GUI,glycan,mz,area");
                    }
                    foreach (string output in outputString)
                    {
                        writer.WriteLine(output);
                    }
                    writer.Flush();
                }
            }



            // merged
            string outputPathMerge = Path.Combine(Path.GetDirectoryName(path),
                                                  Path.GetFileNameWithoutExtension(path) + "_quant.csv");
            List <string> outputStringMerge = new List <string>();
            Dictionary <string, List <SelectResult> > resultContainer = resultSelect.Produce();

            foreach (string name in resultContainer.Keys)
            {
                List <SelectResult> selectResults = resultContainer[name];
                foreach (SelectResult select in selectResults)
                {
                    IResult present = select.Present;
                    int     scan    = present.GetScan();
                    double  rt      = present.GetRetention();
                    double  index   = Math.Round(normalizer.Normalize(rt), 2);

                    IXIC   xicer = new TIQ3XIC(spectrumReader);
                    double area  = xicer.Area(select);

                    List <string> output;
                    if (!normalizer.Initialized())
                    {
                        output = new List <string>()
                        {
                            scan.ToString(), rt.ToString(),
                                             name,
                                             present.GetMZ().ToString(),
                                             area.ToString(),
                        };
                    }
                    else
                    {
                        output = new List <string>()
                        {
                            scan.ToString(), rt.ToString(),
                                             index.ToString(),
                                             name,
                                             present.GetMZ().ToString(),
                                             area.ToString(),
                        };
                    }
                    outputStringMerge.Add(string.Join(",", output));
                }
            }

            using (FileStream ostrm = new FileStream(outputPathMerge, FileMode.OpenOrCreate, FileAccess.Write))
            {
                using (StreamWriter writer = new StreamWriter(ostrm))
                {
                    if (!normalizer.Initialized())
                    {
                        writer.WriteLine("scan,time,glycan,mz,area");
                    }
                    else
                    {
                        writer.WriteLine("scan,time,GUI,glycan,mz,area");
                    }
                    foreach (string output in outputStringMerge)
                    {
                        writer.WriteLine(output);
                    }
                    writer.Flush();
                }
            }
        }
コード例 #2
0
        public void Run(string path, Counter counter, ISpectrumReader reader)
        {
            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);
            initialized = true;
        }