/// <summary> /// Illustrate how to use /// GetSpectrum(double retentionTime, MSScanType scanType, IonPolarity ionPolarity, IonizationMode ionMode, IMsdrPeakFilter peakFilter, bool peakFilterOnCentroid); /// Get a TIC, and then use the retention time array to access each scan. /// </summary> /// <param name="dataAccess"></param> private void DoSpectrumExtractionTest(IMsdrDataReader dataAccess) { IMsdrPeakFilter filter1 = new MsdrPeakFilter(); filter1.AbsoluteThreshold = 10; filter1.RelativeThreshold = 0.1; filter1.MaxNumPeaks = 0; IBDAChromFilter chromFilter = new BDAChromFilter(); chromFilter.ChromatogramType = ChromType.TotalIon; chromFilter.DesiredMSStorageType = DesiredMSStorageType.PeakElseProfile; IBDAChromData[] chroms = dataAccess.GetChromatogram(chromFilter); IBDAChromData chrom = chroms[0]; double[] retTime = chrom.XArray; for (int i = 0; i < retTime.Length; i++) { println("Extract spectrum at RT=" + retTime[i]); //Get a spectrum without doing peak filtering if the spectrum is centroid //The peak filter passed in will be applied to profile spectrum, but not //centroid spectrum, because the flag peakFilterOnCentroid=false IBDASpecData spec = dataAccess.GetSpectrum(retTime[i], MSScanType.All, IonPolarity.Mixed, IonizationMode.Unspecified, filter1, false);//peakFilterOnCentroid=false /*//uncomment this section if you want to print out spectrum points * double[] mzVals = spec.XArray; * float[] aboundanceVals = spec.YArray; * for (int j = 0; j < mzVals.Length; j++) * { * println(mzVals[j] + ", " + aboundanceVals[j]); * } */ //Get a spectrum and apply peak filtering to it regardless profile or centroid IBDASpecData spec2 = dataAccess.GetSpectrum(retTime[i], MSScanType.All, IonPolarity.Mixed, IonizationMode.Unspecified, filter1, true);//peakFilterOnCentroid=true /* * mzVals = spec.XArray; * aboundanceVals = spec.YArray; * for (int j = 0; j < mzVals.Length; j++) * { * if (aboundanceVals[j] > 5000) * { * println(mzVals[j] + ", " + aboundanceVals[j]); * } * } */ if (spec2.TotalDataPoints > spec.TotalDataPoints) {//since spec2 is always thresholded, it must have less than or equal # of points as spec println(" Error: filtered spectrum contains more points than unfiltered spectrum!"); } } }
public override MZSpectrum GetSpectrum(int spectrumNumber) { IBDASpecData spectrum = _msdr.GetSpectrum(spectrumNumber - 1); double[] doubleArray = new double[spectrum.YArray.Length]; for (int i = 0; i < doubleArray.Length; i++) { doubleArray[i] = spectrum.YArray[i]; } return(new MZSpectrum(spectrum.XArray, doubleArray)); }
/// <summary> /// Illustrate how to make calls to deisotope a spectrum. /// </summary> /// <param name="dataAccess"></param> private void DeisotopeTest(IMsdrDataReader dataAccess) { IMsdrPeakFilter filter1 = new MsdrPeakFilter(); filter1.AbsoluteThreshold = 10; filter1.RelativeThreshold = 0.1; filter1.MaxNumPeaks = 0;//no limit on max number of peaks IMsdrChargeStateAssignmentFilter csaFilter = new MsdrChargeStateAssignmentFilter(); IBDASpecFilter f = new BDASpecFilter(); f.SpectrumType = SpecType.MassSpectrum; IBDAMSScanFileInformation msscanFileInfo = dataAccess.MSScanFileInformation; int numSpectra = (int)msscanFileInfo.TotalScansPresent; int nNonEmptyCount = 0; // just deisotope the first 10 non-empty spectra for (int i = 0; i < numSpectra; i++) { IBDASpecData spec = dataAccess.GetSpectrum(i, filter1, filter1);//same peak filter used for both MS and MS2 spectra (you can pass in 2 different filters) println("Original spectrum has " + spec.TotalDataPoints + " points"); if (spec.XArray.Length > 0) { ++nNonEmptyCount; } if (nNonEmptyCount > 10) { break; } dataAccess.Deisotope(spec, csaFilter); println(" Deisotoped spectrum has " + spec.TotalDataPoints + " points"); } }
public override int GetMSLevelFromRawData(int scanNum) { m_spec = m_reader.GetSpectrum(scanNum); var level = m_spec.MSLevelInfo; if (level == MSLevel.MS) { return(1); } if (level == MSLevel.MSMS) { return(2); } return(1); }
/// <summary> /// Get all scans in the data file using row index. The storage mode defaults to peakElseProfile. /// Passing null for peak filter means do not filter any peaks. /// </summary> /// <param name="dataAccess"></param> private void GetAllScansUsingRowIndex(IMsdrDataReader dataAccess) { long totalNumScans = dataAccess.MSScanFileInformation.TotalScansPresent; for (int i = 0; i < totalNumScans; i++) { IBDASpecData spec = dataAccess.GetSpectrum(i, null, null);//no peak filtering } }
private void GetMSLevels(IMsdrDataReader dataAccess) { long totalNumScans = dataAccess.MSScanFileInformation.TotalScansPresent; for (int i = 0; i < totalNumScans; i++) { IBDASpecData spec = dataAccess.GetSpectrum(i, null, null);//no peak filtering IRange[] timeRange = spec.AcquiredTimeRange; Console.WriteLine(timeRange[0].Start); Console.WriteLine(i.ToString() + "\t" + spec.MSLevelInfo + "\t" + timeRange[0].Start); } }
private void DoSpectrumExtractionTestWithStorage(IMsdrDataReader dataAccess) { IMsdrPeakFilter filter1 = new MsdrPeakFilter(); filter1.AbsoluteThreshold = 10; filter1.RelativeThreshold = 0.1; filter1.MaxNumPeaks = 0; IBDAMSScanFileInformation msscanFileInfo = dataAccess.MSScanFileInformation; int numSpectra = (int)msscanFileInfo.TotalScansPresent; for (int i = 0; i < numSpectra; i++) { IBDASpecData spec = dataAccess.GetSpectrum(i, filter1, filter1, DesiredMSStorageType.PeakElseProfile); println("Spectrum " + i.ToString() + "has " + spec.TotalDataPoints + " points"); } }
public static PeakList <Peak> GetPeakList(this IMsdrDataReader reader, double retentionTime, IMsdrPeakFilter peakFilter) { PeakList <Peak> result = new PeakList <Peak>(); IBDASpecData s = reader.GetSpectrum(retentionTime, MSScanType.All, IonPolarity.Mixed, IonizationMode.Unspecified, peakFilter, true); for (int i = 0; i < s.XArray.Length; i++) { result.Add(new Peak(s.XArray[i], s.YArray[i])); } if (s.MZOfInterest.Length > 0) { result.PrecursorMZ = s.MZOfInterest[0].Start; } result.ScanTimes.Add(new ScanTime(0, retentionTime)); return(result); }
public override void ReadMS(int Scan) { IBDASpecData SpecData; try { //Agilent spectra are enumerated from 0, Thermo spectra + from 1, so here is a shift SpecData = MSReader.GetSpectrum(Scan - 1, PeakFilter, PeakFilter, DesiredMSStorageType.Peak); RawSpectra[Scan].Data = new MZData[SpecData.TotalDataPoints]; for (int k = 0; k < SpecData.TotalDataPoints; k++) { RawSpectra[Scan].Data[k] = new MZData(); RawSpectra[Scan].Data[k].Mass = SpecData.XArray[k]; RawSpectra[Scan].Data[k].Intensity = SpecData.YArray[k]; } } catch { Exception e = new Exception(string.Format("Scan #{0} cannot be loaded, probably RAW file is corrupted!", Scan - 1)); throw e; } SpecData = null; GC.Collect(2); }
private static bool GetAccurateMZAndIntensity(IDictionary <int, IBDASpecData> ms1s, IMsdrDataReader agilentD, int parentScanId, ref double mz, out double intensity) { IBDASpecData ms1; lock (ms1s) { if (!ms1s.TryGetValue(parentScanId, out ms1)) { IBDASpecFilter spec_filter = new BDASpecFilter(); spec_filter.SpectrumType = SpecType.MassSpectrum; spec_filter.ScanIds = new int[] { parentScanId }; lock (agilentD) { ms1 = agilentD.GetSpectrum(spec_filter)[0]; } ms1s.Add(parentScanId, ms1); } } int index = -1; for (int i = 0; i < ms1.TotalDataPoints; i++) { if (index < 0 || Math.Abs(ms1.XArray[i] - mz) < Math.Abs(ms1.XArray[index] - mz)) { index = i; } } if (index >= 0) { mz = ms1.XArray[index]; intensity = ms1.YArray[index]; return(true); } intensity = double.NaN; return(false); }
/// <summary> /// Get all Product Ion MS/MS scans and print out the precursor and collision energy. /// </summary> private void GetPrecursorInfo(IMsdrDataReader dataAccess) { //Create a chromatogram filter to let the scans that match //the filter criteria to pass through IBDAChromFilter chromFilter = new BDAChromFilter(); chromFilter.ChromatogramType = ChromType.TotalIon; chromFilter.DesiredMSStorageType = DesiredMSStorageType.PeakElseProfile;//This means to use peak scans if available, otherwise use profile scans chromFilter.MSLevelFilter = MSLevel.MSMS; chromFilter.MSScanTypeFilter = MSScanType.ProductIon; IBDAChromData[] chroms = dataAccess.GetChromatogram(chromFilter);//expect 1 chromatogram because we're not asking it to separate by scan segments, etc. IBDAChromData chrom = chroms[0]; double[] retTime = chrom.XArray; println("Get MS/MS spectra using retention time"); for (int i = 0; i < retTime.Length; i++) { //for each retention time, get the corresponding scan //passing in null for peak filter means no peak threshold applied IBDASpecData spec = dataAccess.GetSpectrum(retTime[i], MSScanType.ProductIon, IonPolarity.Mixed, IonizationMode.Unspecified, null); print("RT=" + retTime[i] + ", "); int precursorCount = 0; double[] precursorIons = spec.GetPrecursorIon(out precursorCount); if (precursorCount == 1) { print("Precursor Ions:"); for (int j = 0; j < precursorIons.Length; j++) { print(precursorIons[j] + " "); } println(""); int charge; double intensity; if (spec.GetPrecursorCharge(out charge)) { println(" charge: " + charge); } else { println(" no charge avaialble"); } if (spec.GetPrecursorIntensity(out intensity)) { println(" intensity: " + intensity); } else { println(" no intensity available"); } } else { println("No precursor ions"); } /* * //Uncomment this if you want to print out x and y values of the spectrum. * double[] mzVals = spec.XArray; * float[] aboundanceVals = spec.YArray; * println("RT=" + retTime[i]); * for (int j = 0; j < mzVals.Length; j++) * { * println(mzVals[j] + ", " + aboundanceVals[j]); * } */ } }
private static bool GetAccurateMZAndIntensity(IDictionary<int, IBDASpecData> ms1s, IMsdrDataReader agilentD, int parentScanId, ref double mz, out double intensity) { IBDASpecData ms1; lock(ms1s) { if(!ms1s.TryGetValue(parentScanId, out ms1)) { IBDASpecFilter spec_filter = new BDASpecFilter(); spec_filter.SpectrumType = SpecType.MassSpectrum; spec_filter.ScanIds = new int[] { parentScanId }; lock(agilentD) { ms1 = agilentD.GetSpectrum(spec_filter)[0]; } ms1s.Add(parentScanId, ms1); } } int index = -1; for(int i = 0; i < ms1.TotalDataPoints; i++) { if(index < 0 || Math.Abs(ms1.XArray[i] - mz) < Math.Abs(ms1.XArray[index] - mz)) { index = i; } } if(index >= 0) { mz = ms1.XArray[index]; intensity = ms1.YArray[index]; return true; } intensity = double.NaN; return false; }