Beispiel #1
0
        /// <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");
            }
        }
Beispiel #2
0
        public override PrecursorInfo GetPrecursorInfo(int scanNum)
        {
            m_spec = m_reader.GetSpectrum(scanNum);

            var precursor = new PrecursorInfo();

            var level = m_spec.MSLevelInfo;

            if (level == MSLevel.MS)
            {
                precursor.MSLevel = 1;
            }
            else if (level == MSLevel.MSMS)
            {
                precursor.MSLevel = 2;
            }
            else
            {
                precursor.MSLevel = 1;
            }

            //this returns a list of precursor masses (not sure how there can be more than one)
            var precursorMZlist = m_spec.GetPrecursorIon(out var precursorMassCount);

            //if a mass is returned
            if (precursorMassCount == 1)
            {
                //mass
                precursor.PrecursorMZ = precursorMZlist[0];

                //intensity
                m_spec.GetPrecursorIntensity(out var precursorIntensity);
                precursor.PrecursorIntensity = (float)precursorIntensity;

                //charge
                m_spec.GetPrecursorCharge(out var precursorCharge);
                precursor.PrecursorCharge = precursorCharge;

                //adjust scan number if needed
                precursor.PrecursorScan = scanNum;

                // TODO: Only CID possible in Agilent files?
                precursor.FragmentationType = FragmentionType.CID;
            }
            else if (precursorMassCount > 1)
            {
                throw new NotImplementedException("Strange case where more than one precursor is used to generate one spectrum");
            }
            else
            {
                precursor.PrecursorMZ        = 0;
                precursor.PrecursorIntensity = 0;
                precursor.PrecursorCharge    = -1;
                precursor.PrecursorScan      = scanNum;
            }

            precursor.IonizationMode = m_spec.IonPolarity == IonPolarity.Negative ? IonizationMode.Negative : IonizationMode.Positive;

            return(precursor);
        }
        public override int GetPrecusorCharge(int spectrumNumber, int msnOrder = 2)
        {
            IBDASpecData spectrum = _msdr.GetSpectrum(spectrumNumber - 1);
            int          precursor_charge;

            spectrum.GetPrecursorCharge(out precursor_charge);
            return((short)precursor_charge);
        }
Beispiel #4
0
        /// <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
            }
        }
Beispiel #5
0
        /// <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));
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        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");
            }
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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 MZAnalyzerType GetMzAnalyzer(int spectrumNumber)
        {
            IBDASpecData spectrum = _msdr.GetSpectrum(spectrumNumber - 1);

            switch (spectrum.DeviceType)
            {
            case DeviceType.IonTrap:
                return(MZAnalyzerType.IonTrap3D);

            case DeviceType.Quadrupole:
            case DeviceType.TandemQuadrupole:
                return(MZAnalyzerType.Quadrupole);

            case DeviceType.QuadrupoleTimeOfFlight:
            case DeviceType.TimeOfFlight:
                return(MZAnalyzerType.TOF);

            default:
                return(MZAnalyzerType.Unknown);
            }
        }
Beispiel #12
0
 private void getAgilentSpectrum(int scanNum)
 {
     m_spec = m_reader.GetSpectrum(scanNum, null, null, DesiredMSStorageType.ProfileElsePeak);
 }
        public override MzRange GetMzRange(int spectrumNumber)
        {
            IBDASpecData spectrum = _msdr.GetSpectrum(spectrumNumber - 1);

            return(new MzRange(spectrum.MeasuredMassRange.Start, spectrum.MeasuredMassRange.End));
        }
Beispiel #14
0
        /// <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]);
                 * }
                 */
            }
        }