private void Visualize_Click(object sender, RoutedEventArgs e) { if (path.Length == 0) { MessageBox.Show("Please input the spectrum file (*.Raw) path!"); return; } int scan; int.TryParse(ScanNumber.Text, out scan); if (scan > 0 && scan < spectrumReader.GetLastScan() && spectrumReader.GetMSnOrder(scan) == 1) { ISpectrum spectrum = spectrumProcessor.Process(spectrumReader.GetSpectrum(scan)); double rt = spectrumReader.GetRetentionTime(scan); double index = Math.Round(engine.Normalize(rt), 2); string output = "Retention time: " + Math.Round(rt, 2).ToString() + " (min) "; if (index > 0) { output += "GUI index " + index.ToString(); } RTtime.Text = output; // search List <IResult> results = spectrumSearch.Search(spectrum); //// draw curve canvas.Children.Clear(); if (spectrum.GetPeaks().Count > 0) { canvas.Children.Add(new VisualHost { Visual = visualizer.CreateDrawingVisual(spectrum, results) }); } PeakArea.Visibility = Visibility.Visible; } else { MessageBox.Show("Please input a valid scan number!"); canvas.Children.Clear(); PeakArea.Visibility = Visibility.Collapsed; return; } }
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); }
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; }