private void MSMSFileName_Click(object sender, RoutedEventArgs e) { OpenFileDialog fileNameDialog = new OpenFileDialog(); fileNameDialog.Filter = "Raw File|*.raw"; fileNameDialog.Title = "Open a MS2 File"; if (fileNameDialog.ShowDialog() == true) { Binding fileNameBinding = new Binding(); fileNameBinding.Path = new PropertyPath("FileName"); fileNameBinding.Source = fileNameDialog; fileNameBinding.Mode = BindingMode.OneWay; displayFileName.SetBinding(TextBox.TextProperty, fileNameBinding); path = displayFileName.Text; spectrumReader.Init(path); int start = spectrumReader.GetFirstScan(); int end = spectrumReader.GetLastScan(); for (int i = start; i <= end; i++) { if (spectrumReader.GetMSnOrder(i) == 1) { validScan.Add(i); } } ScanScroll.Minimum = 0; ScanScroll.Maximum = validScan.Count - 1; } }
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 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(); } } }
public int GetMSnOrder(int scanNum) { return(reader.GetMSnOrder(scanNum)); }
public double Area(IResult glycan) { // search xic double mz = glycan.GetMZ(); int scan = glycan.GetScan(); int charge = glycan.GetCharge(); // get neighbors List <ISpectrum> neighbors = new List <ISpectrum>(); int nextScan = scan; while (nextScan > spectrumReader.GetFirstScan()) { if (spectrumReader.GetMSnOrder(nextScan) == 1) { ISpectrum spectrum = spectrumReader.GetSpectrum(nextScan); int index = BinarySearch.Search(spectrum.GetPeaks(), mz, tol, by); if (index < 0) { break; } neighbors.Add(spectrum); } nextScan--; } nextScan = scan + 1; while (nextScan <= spectrumReader.GetLastScan()) { if (spectrumReader.GetMSnOrder(nextScan) == 1) { ISpectrum spectrum = spectrumReader.GetSpectrum(nextScan); int index = BinarySearch.Search(spectrum.GetPeaks(), mz, tol, by); if (index < 0) { break; } neighbors.Add(spectrum); } nextScan++; } // each neighbor get top 3 peaks List <double> topArea = new List <double>(); List <int> delta = new List <int>() { -2, -1, 0, 1, 2 }; foreach (ISpectrum spetrum in neighbors) { List <IPeak> top = new List <IPeak>(); foreach (int j in delta) { int index = BinarySearch.BestSearch(spetrum.GetPeaks(), mz + 1.0 / charge * j, tol, by); if (index < 0) { continue; } top.Add(spetrum.GetPeaks()[index]); } topArea.Add(top.OrderByDescending(p => p.GetIntensity()). Take(3).Select(p => p.GetIntensity()).Sum()); } return(topArea.OrderByDescending(a => a).Take(3).Sum()); }
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; }
public int GetMSnOrder(int scanNum) { return(spectrumReader.GetMSnOrder(scanNum)); }