/// <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 static PeakList <Peak> GetPeakList(this IMsdrDataReader reader, double retentionTime, double minPeakIntensity, int maxNumPeaks) { IMsdrPeakFilter peakFilter = new MsdrPeakFilter(); peakFilter.AbsoluteThreshold = minPeakIntensity; peakFilter.RelativeThreshold = 0; peakFilter.MaxNumPeaks = maxNumPeaks; return(GetPeakList(reader, retentionTime, peakFilter)); }
/// <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!"); } } }
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 void Load(string agilentDFolderPath, int minimumAssumedPrecursorChargeState, int maximumAssumedPrecursorChargeState, double absoluteThreshold, double relativeThresholdPercent, int maximumNumberOfPeaks, bool assignChargeStates, bool deisotope, int maximumThreads) { OnReportTaskWithoutProgress(new EventArgs()); IMsdrDataReader agilent_d = new MassSpecDataReader(); agilent_d.OpenDataFile(agilentDFolderPath); Dictionary <int, IBDASpecData> ms1s; if (GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1) { ms1s = new Dictionary <int, IBDASpecData>(); } IMsdrPeakFilter ms1_peak_filter = new MsdrPeakFilter(); IMsdrPeakFilter ms2_peak_filter = new MsdrPeakFilter(); ms2_peak_filter.AbsoluteThreshold = absoluteThreshold; ms2_peak_filter.RelativeThreshold = relativeThresholdPercent; ms2_peak_filter.MaxNumPeaks = maximumNumberOfPeaks; ChargeStateAssignmentWrapper csaw = new ChargeStateAssignmentWrapper(); OnReportTaskWithProgress(new EventArgs()); object progress_lock = new object(); int spectra_processed = 0; int old_progress = 0; ParallelOptions parallel_options = new ParallelOptions(); parallel_options.MaxDegreeOfParallelism = maximumThreads; Parallel.For(0, (int)agilent_d.MSScanFileInformation.TotalScansPresent, parallel_options, row_number => { IMSScanRecord scan_record; lock (agilent_d) { scan_record = agilent_d.GetScanRecord(row_number); } if (scan_record.MSLevel == MSLevel.MSMS) { IBDASpecData agilent_spectrum; lock (agilent_d) { agilent_spectrum = agilent_d.GetSpectrum(row_number, ms1_peak_filter, ms2_peak_filter); } if (agilent_spectrum.TotalDataPoints > 0) { int polarity = 0; if (agilent_spectrum.IonPolarity == IonPolarity.Positive) { polarity = 1; } else if (agilent_spectrum.IonPolarity == IonPolarity.Negative) { polarity = -1; } int spectrum_number = row_number + 1; string scan_id = "scanId=" + agilent_spectrum.ScanId.ToString(); double precursor_mz = agilent_spectrum.MZOfInterest[0].Start; double precursor_intensity; if (GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1) { GetAccurateMZAndIntensity(ms1s, agilent_d, agilent_spectrum.ParentScanId, ref precursor_mz, out precursor_intensity); } else { agilent_spectrum.GetPrecursorIntensity(out precursor_intensity); } int charge; agilent_spectrum.GetPrecursorCharge(out charge); if (polarity < 0) { charge = -charge; } List <MSPeak> peaks = null; if (!assignChargeStates) { peaks = new List <MSPeak>(agilent_spectrum.TotalDataPoints); for (int i = 0; i < agilent_spectrum.TotalDataPoints; i++) { peaks.Add(new MSPeak(agilent_spectrum.XArray[i], agilent_spectrum.YArray[i], 0, polarity)); } } for (int c = (ALWAYS_USE_PRECURSOR_CHARGE_STATE_RANGE || charge == 0 ? minimumAssumedPrecursorChargeState : charge); c <= (ALWAYS_USE_PRECURSOR_CHARGE_STATE_RANGE || charge == 0 ? maximumAssumedPrecursorChargeState : charge); c++) { if (assignChargeStates) { int[] peak_ids = new int[agilent_spectrum.TotalDataPoints]; double[] peak_mzs = new double[agilent_spectrum.TotalDataPoints]; double[] peak_intensities = new double[agilent_spectrum.TotalDataPoints]; for (int i = 0; i < agilent_spectrum.TotalDataPoints; i++) { peak_ids[i] = i; peak_mzs[i] = agilent_spectrum.XArray[i]; peak_intensities[i] = agilent_spectrum.YArray[i]; } int[] peak_charge_states = new int[agilent_spectrum.TotalDataPoints]; int[] peak_clusters = new int[agilent_spectrum.TotalDataPoints]; int num_peaks; lock (csaw) { csaw.SetParameters(IsotopeModel.Peptidic, 1, (short)c, false, ACCURACY_C0, ACCURACY_C1); num_peaks = csaw.AssignChargeStates(peak_ids, peak_mzs, peak_intensities, peak_charge_states, peak_clusters); } peaks = new List <MSPeak>(num_peaks); HashSet <int> observed_peak_clusters = new HashSet <int>(); for (int i = 0; i < num_peaks; i++) { bool isotopic_peak = observed_peak_clusters.Contains(peak_clusters[i]); if (!deisotope || !isotopic_peak) { peaks.Add(new MSPeak(peak_mzs[i], peak_intensities[i], peak_charge_states[i], polarity)); if (peak_clusters[i] > 0 && !isotopic_peak) { observed_peak_clusters.Add(peak_clusters[i]); } } } } double precursor_mass = MSPeak.MassFromMZ(precursor_mz, c); TandemMassSpectrum spectrum = new TandemMassSpectrum(agilentDFolderPath, spectrum_number, scan_id, null, scan_record.RetentionTime, FRAGMENTATION_METHOD, precursor_mz, precursor_intensity, c, precursor_mass, peaks); lock (this) { Add(spectrum); } } } } lock (progress_lock) { spectra_processed++; int new_progress = (int)((double)spectra_processed / agilent_d.MSScanFileInformation.TotalScansPresent * 100); if (new_progress > old_progress) { OnUpdateProgress(new ProgressEventArgs(new_progress)); old_progress = new_progress; } } }); agilent_d.CloseDataFile(); }
public void Load(string agilentDFolderPath, int minimumAssumedPrecursorChargeState, int maximumAssumedPrecursorChargeState, double absoluteThreshold, double relativeThresholdPercent, int maximumNumberOfPeaks, bool assignChargeStates, bool deisotope, int maximumThreads) { OnReportTaskWithoutProgress(new EventArgs()); IMsdrDataReader agilent_d = new MassSpecDataReader(); agilent_d.OpenDataFile(agilentDFolderPath); Dictionary<int, IBDASpecData> ms1s; if(GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1) { ms1s = new Dictionary<int, IBDASpecData>(); } IMsdrPeakFilter ms1_peak_filter = new MsdrPeakFilter(); IMsdrPeakFilter ms2_peak_filter = new MsdrPeakFilter(); ms2_peak_filter.AbsoluteThreshold = absoluteThreshold; ms2_peak_filter.RelativeThreshold = relativeThresholdPercent; ms2_peak_filter.MaxNumPeaks = maximumNumberOfPeaks; ChargeStateAssignmentWrapper csaw = new ChargeStateAssignmentWrapper(); OnReportTaskWithProgress(new EventArgs()); object progress_lock = new object(); int spectra_processed = 0; int old_progress = 0; ParallelOptions parallel_options = new ParallelOptions(); parallel_options.MaxDegreeOfParallelism = maximumThreads; Parallel.For(0, (int)agilent_d.MSScanFileInformation.TotalScansPresent, parallel_options, row_number => { IMSScanRecord scan_record; lock(agilent_d) { scan_record = agilent_d.GetScanRecord(row_number); } if(scan_record.MSLevel == MSLevel.MSMS) { IBDASpecData agilent_spectrum; lock(agilent_d) { agilent_spectrum = agilent_d.GetSpectrum(row_number, ms1_peak_filter, ms2_peak_filter); } if(agilent_spectrum.TotalDataPoints > 0) { int polarity = 0; if(agilent_spectrum.IonPolarity == IonPolarity.Positive) { polarity = 1; } else if(agilent_spectrum.IonPolarity == IonPolarity.Negative) { polarity = -1; } int spectrum_number = row_number + 1; string scan_id = "scanId=" + agilent_spectrum.ScanId.ToString(); double precursor_mz = agilent_spectrum.MZOfInterest[0].Start; double precursor_intensity; if(GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1) { GetAccurateMZAndIntensity(ms1s, agilent_d, agilent_spectrum.ParentScanId, ref precursor_mz, out precursor_intensity); } else { agilent_spectrum.GetPrecursorIntensity(out precursor_intensity); } int charge; agilent_spectrum.GetPrecursorCharge(out charge); if(polarity < 0) { charge = -charge; } List<MSPeak> peaks = null; if(!assignChargeStates) { peaks = new List<MSPeak>(agilent_spectrum.TotalDataPoints); for(int i = 0; i < agilent_spectrum.TotalDataPoints; i++) { peaks.Add(new MSPeak(agilent_spectrum.XArray[i], agilent_spectrum.YArray[i], 0, polarity)); } } for(int c = (ALWAYS_USE_PRECURSOR_CHARGE_STATE_RANGE || charge == 0 ? minimumAssumedPrecursorChargeState : charge); c <= (ALWAYS_USE_PRECURSOR_CHARGE_STATE_RANGE || charge == 0 ? maximumAssumedPrecursorChargeState : charge); c++) { if(assignChargeStates) { int[] peak_ids = new int[agilent_spectrum.TotalDataPoints]; double[] peak_mzs = new double[agilent_spectrum.TotalDataPoints]; double[] peak_intensities = new double[agilent_spectrum.TotalDataPoints]; for(int i = 0; i < agilent_spectrum.TotalDataPoints; i++) { peak_ids[i] = i; peak_mzs[i] = agilent_spectrum.XArray[i]; peak_intensities[i] = agilent_spectrum.YArray[i]; } int[] peak_charge_states = new int[agilent_spectrum.TotalDataPoints]; int[] peak_clusters = new int[agilent_spectrum.TotalDataPoints]; int num_peaks; lock(csaw) { csaw.SetParameters(IsotopeModel.Peptidic, 1, (short)c, false, ACCURACY_C0, ACCURACY_C1); num_peaks = csaw.AssignChargeStates(peak_ids, peak_mzs, peak_intensities, peak_charge_states, peak_clusters); } peaks = new List<MSPeak>(num_peaks); HashSet<int> observed_peak_clusters = new HashSet<int>(); for(int i = 0; i < num_peaks; i++) { bool isotopic_peak = observed_peak_clusters.Contains(peak_clusters[i]); if(!deisotope || !isotopic_peak) { peaks.Add(new MSPeak(peak_mzs[i], peak_intensities[i], peak_charge_states[i], polarity)); if(peak_clusters[i] > 0 && !isotopic_peak) { observed_peak_clusters.Add(peak_clusters[i]); } } } } double precursor_mass = MSPeak.MassFromMZ(precursor_mz, c); TandemMassSpectrum spectrum = new TandemMassSpectrum(agilentDFolderPath, spectrum_number, scan_id, null, scan_record.RetentionTime, FRAGMENTATION_METHOD, precursor_mz, precursor_intensity, c, precursor_mass, peaks); lock(this) { Add(spectrum); } } } } lock(progress_lock) { spectra_processed++; int new_progress = (int)((double)spectra_processed / agilent_d.MSScanFileInformation.TotalScansPresent * 100); if(new_progress > old_progress) { OnUpdateProgress(new ProgressEventArgs(new_progress)); old_progress = new_progress; } } }); agilent_d.CloseDataFile(); }