public SeemsPointList(ManagedScan scan) { fullPointList = new ZedGraph.PointPairList(); fullPointList.Capacity = scan.getTotalPeakCount(); Map <double, double> sortedFullPointList = new Map <double, double>(); for (int i = 0; i < scan.getTotalPeakCount(); ++i) { sortedFullPointList[scan.getPeakMz(i)] = scan.getPeakIntensity(i); } foreach (Map <double, double> .MapPair itr in sortedFullPointList) { fullPointList.Add(new ZedGraph.PointPair(itr.Key, itr.Value)); } scaledPointList = new ZedGraph.PointPairList(); scaledMaxIndexList = new List <int>(); }
public bool SetInputFile(string filepath) { ManagedInstrumentInterface tempInterface = new ManagedInstrumentInterface(); try { if (!tempInterface.initInterface()) { throw new Exception("failed to initialize temporary data interface."); } if (!File.Exists(filepath)) { throw new ArgumentException("file does not exist"); } sourceFilepath = filepath; OnStatusReport("Initializing interface for source file..."); if (!tempInterface.setInputFile(sourceFilepath)) { throw new Exception("LibMSR could not open the file"); } tempInterface.setCentroiding(false, false); } catch (Exception ex) { string message = "SeeMS encountered an error opening \"" + filepath + "\" (" + ex.Message + ")"; if (ex.InnerException != null) { message += "\n\nAdditional information: " + ex.InnerException.Message; } MessageBox.Show(message, "Error opening source file", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, false); return(false); } try { OnStatusReport("Loading metadata from source file..."); OnProgressReport(0); int totalScanCount = tempInterface.getTotalScanCount(); int curScanCount = 0; if (totalScanCount > 1) { ManagedScan chromatogram = tempInterface.getChromatogram(); if (chromatogram == null) { throw new Exception("failed to generate chromatogram"); } else { sourceScanHeaders.Add(new SeemsScan(chromatogram, "Chromatogram")); } } ParentToFragmentMap transitionMap = new ParentToFragmentMap(); // get all scans by sequential access ManagedScan curScan = tempInterface.getScanHeader(instrumentInterface.getFirstScanNumber()); while (curScan != null) { ++curScanCount; if ((curScanCount % 100) == 0 || curScanCount == totalScanCount) { OnStatusReport(String.Format("Loading metadata from source file ({0} of {1})...", curScanCount, totalScanCount)); OnProgressReport(curScanCount * 100 / totalScanCount); } if (curScan.ScanType == ScanTypeEnum.SRM || curScan.ScanType == ScanTypeEnum.MRM) { ManagedScan curScanWithPeakData = tempInterface.getScan(curScan.ScanNumber); if (curScanWithPeakData.getTotalPeakCount() > 0) { if (curScan.getPrecursorScanCount() > 0) { FragmentToChromatogramMap fragmentMap = transitionMap[curScan.getPrecursorScanInfo(0).Mz]; for (int i = 0; i < curScanWithPeakData.getTotalPeakCount(); ++i) { fragmentMap[curScanWithPeakData.getPeakMz(i)].Add(curScan.RetentionTime, curScanWithPeakData.getPeakIntensity(i)); } } } } else { sourceScanHeaders.Add(new SeemsScan(curScan)); } curScan = tempInterface.getScanHeader(); } OnProgressReport(100); if (transitionMap.Count > 0) { OnStatusReport("Generating chromatograms for SRM/MRM data..."); OnProgressReport(0); Map <double, RefPair <ManagedScan, Map <double, ManagedScan> > > transitionChromatograms = new Map <double, RefPair <ManagedScan, Map <double, ManagedScan> > >(); foreach (ParentToFragmentMap.MapPair pfPair in transitionMap) { Map <double, List <double> > parentPeaks = new Map <double, List <double> >(); foreach (FragmentToChromatogramMap.MapPair fcPair in pfPair.Value) { ManagedScan fragmentChromatogram = transitionChromatograms[pfPair.Key].second[fcPair.Key] = new ManagedScan(); foreach (Chromatogram.MapPair tiPair in fcPair.Value) { fragmentChromatogram.addPeak(tiPair.Key, tiPair.Value); parentPeaks[tiPair.Key].Add(tiPair.Value); } } ManagedScan parentChromatogram = transitionChromatograms[pfPair.Key].first = new ManagedScan(); ManagedScan productChromatogram = transitionChromatograms[pfPair.Key].second[pfPair.Key] = new ManagedScan(); foreach (Map <double, List <double> > .MapPair itr in parentPeaks) { double totalIntensity = 0, productIntensity = 1; foreach (double intensity in itr.Value) { totalIntensity += intensity; productIntensity *= intensity; } parentChromatogram.addPeak(itr.Key, totalIntensity); productChromatogram.addPeak(itr.Key, productIntensity); } OnProgressReport(transitionChromatograms.Count * 100 / transitionMap.Count); } foreach (Map <double, RefPair <ManagedScan, Map <double, ManagedScan> > > .MapPair kvp1 in transitionChromatograms) { sourceScanHeaders.Add(new SeemsScan(kvp1.Value.first, String.Format("{0} (Sum)", Math.Round(kvp1.Key, 2)))); sourceScanHeaders.Add(new SeemsScan(kvp1.Value.second[kvp1.Key], String.Format("{0} (Product)", Math.Round(kvp1.Key, 2)))); foreach (Map <double, ManagedScan> .MapPair kvp2 in kvp1.Value.second) { if (kvp1.Key != kvp2.Key) { sourceScanHeaders.Add(new SeemsScan(kvp2.Value, String.Format("{0} -> {1}", Math.Round(kvp1.Key, 2), Math.Round(kvp2.Key, 2)))); } } } OnStatusReport("Finished loading source metadata."); OnProgressReport(100); } } catch (Exception ex) { string message = "SeeMS encountered an error reading metadata from \"" + filepath + "\" (" + ex.Message + ")"; if (ex.InnerException != null) { message += "\n\nAdditional information: " + ex.InnerException.Message; } MessageBox.Show(message, "Error reading source metadata", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, false); OnStatusReport("Failed to read source metadata."); return(false); } return(true); }
public bool readScanMetadata(string sourceFilepath) { try { if (!File.Exists(sourceFilepath)) { return(false); } CurrentSourceFilepath = sourceFilepath; SeemsMdiParent.setFileControls(false); SeemsMdiParent.setScanControls(false); SeemsMdiParent.StatusLabel.Text = "Loading source metadata..."; SeemsMdiParent.StatusProgressBar.MarqueeAnimationSpeed = 100; Application.DoEvents(); if (!instrumentInterface.setInputFile(CurrentSourceFilepath)) { throw new Exception("failed to open file \"" + CurrentSourceFilepath + "\""); } instrumentInterface.setCentroiding(false, false); SeemsMdiParent.StatusProgressBar.MarqueeAnimationSpeed = 0; } catch (Exception ex) { string message = "SeeMS encountered an error opening the source file you specified (" + ex.Message + ")"; if (ex.InnerException != null) { message += "\n\nAdditional information: " + ex.InnerException.Message; } MessageBox.Show(message, "Error opening source file", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, false); SeemsMdiParent.setFileControls(true); return(false); } try { scanNumberComboBox.Items.Clear(); SeemsMdiParent.StatusProgressBar.Visible = true; SeemsMdiParent.StatusProgressBar.Value = 0; SeemsMdiParent.StatusProgressBar.Minimum = 0; SeemsMdiParent.StatusProgressBar.Maximum = instrumentInterface.getTotalScanCount(); SeemsMdiParent.StatusProgressBar.Step = 1; Application.DoEvents(); scanNumberComboBox.BeginUpdate(); ManagedScan chromatogram = instrumentInterface.getChromatogram(); if (chromatogram == null) { throw new Exception("failed to generate chromatogram"); } else { scanNumberComboBox.Items.Add(new SeemsScan(chromatogram, "Chromatogram")); } ParentToFragmentMap transitionMap = new ParentToFragmentMap(); //Dictionary<double, int> transitionMap = new Dictionary<double,int>(); //long beforeScanHeaders = Environment.WorkingSet; // get all scans by sequential access ManagedScan curScan = instrumentInterface.getScanHeader(instrumentInterface.getFirstScanNumber()); while (curScan != null) { SeemsMdiParent.StatusProgressBar.PerformStep(); Application.DoEvents(); if (curScan.ScanType == ScanTypeEnum.SRM || curScan.ScanType == ScanTypeEnum.MRM) { ManagedScan curScanWithPeakData = instrumentInterface.getScan(curScan.ScanNumber); if (curScanWithPeakData.getTotalPeakCount() > 0) { if (curScan.getPrecursorScanCount() > 0) { FragmentToChromatogramMap fragmentMap = transitionMap[curScan.getPrecursorScanInfo(0).Mz]; for (int i = 0; i < curScanWithPeakData.getTotalPeakCount(); ++i) { fragmentMap[curScanWithPeakData.getPeakMz(i)].Add(curScan.RetentionTime, curScanWithPeakData.getPeakIntensity(i)); } } } //if( curScan.getPrecursorScanCount() > 0 ) // transitionMap[curScan.getPrecursorScanInfo( 0 ).Mz] = 0; } else { scanNumberComboBox.Items.Add(new SeemsScan(curScan)); } curScan = instrumentInterface.getScanHeader(); } if (transitionMap.Count > 0) { SeemsMdiParent.StatusLabel.Text = "Generating chromatograms for SRM/MRM data..."; SeemsMdiParent.StatusProgressBar.Value = 0; SeemsMdiParent.StatusProgressBar.Minimum = 0; SeemsMdiParent.StatusProgressBar.Maximum = transitionMap.Count; SeemsMdiParent.StatusProgressBar.Step = 1; Application.DoEvents(); Map <double, RefPair <ManagedScan, Map <double, ManagedScan> > > transitionChromatograms = new Map <double, RefPair <ManagedScan, Map <double, ManagedScan> > >(); foreach (ParentToFragmentMap.MapPair pfPair in transitionMap) { Map <double, double> parentPeaks = new Map <double, double>(); foreach (FragmentToChromatogramMap.MapPair fcPair in pfPair.Value) { ManagedScan fragmentChromatogram = transitionChromatograms[pfPair.Key].second[fcPair.Key] = new ManagedScan(); foreach (Chromatogram.MapPair tiPair in fcPair.Value) { fragmentChromatogram.addPeak(tiPair.Key, tiPair.Value); parentPeaks[tiPair.Key] += tiPair.Value; } } ManagedScan parentChromatogram = transitionChromatograms[pfPair.Key].first = new ManagedScan(); foreach (Map <double, double> .MapPair peak in parentPeaks) { parentChromatogram.addPeak(peak.Key, peak.Value); } SeemsMdiParent.StatusProgressBar.PerformStep(); Application.DoEvents(); } foreach (Map <double, RefPair <ManagedScan, Map <double, ManagedScan> > > .MapPair kvp1 in transitionChromatograms) { scanNumberComboBox.Items.Add(new SeemsScan(kvp1.Value.first, kvp1.Key.ToString())); foreach (Map <double, ManagedScan> .MapPair kvp2 in kvp1.Value.second) { scanNumberComboBox.Items.Add(new SeemsScan(kvp2.Value, String.Format("{0} -> {1}", Math.Round(kvp1.Key, 2), Math.Round(kvp2.Key, 2)))); } } } scanNumberComboBox.EndUpdate(); SeemsMdiParent.StatusProgressBar.Visible = false; Application.DoEvents(); //long afterScanHeaders = Environment.WorkingSet; //MessageBox.Show( "Before adding headers: " + beforeScanHeaders + " After adding headers: " + afterScanHeaders ); SeemsMdiParent.setFileControls(true); if (scanNumberComboBox.Items.Count > 0) { SeemsMdiParent.setScanControls(true); scanNumberComboBox.SelectedIndex = 0; // triggers initial graph generation } else { SeemsMdiParent.setScanControls(false); return(false); } } catch (Exception ex) { string message = "SeeMS encountered an error reading metadata from the source file you specified (" + ex.Message + ")"; if (ex.InnerException != null) { message += "\n\nAdditional information: " + ex.InnerException.Message; } MessageBox.Show(message, "Error reading source metadata", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, 0, false); SeemsMdiParent.setFileControls(true); return(false); } return(true); }