Beispiel #1
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 int GetSpectrumNumber(double retentionTime)
        {
            IBDAChromData tic   = _msdr.GetTIC();
            int           index = -1;

            for (int i = 0; i < tic.TotalDataPoints; i++)
            {
                if (index < 0 || Math.Abs(tic.XArray[i] - retentionTime) < Math.Abs(tic.XArray[index] - retentionTime))
                {
                    index = i;
                }
            }
            return(index + 1);
        }
Beispiel #3
0
        // Extract non-MS data from the specified file path, with UV spectra limited to at
        // most the specified number.
        private void ExtractNonMSData(string dataFilePath, int maxSpectraToReport)
        {
            IMsdrDataReader dataReader = new MassSpecDataReader();

            dataReader.OpenDataFile(dataFilePath);

            INonmsDataReader nonMsReader = dataReader as INonmsDataReader;

            IDeviceInfo[] deviceInfo = nonMsReader.GetNonmsDevices();
            if ((deviceInfo == null) || (deviceInfo.Length == 0))
            {
                println("No Non MS device found");
            }
            else
            {
                foreach (IDeviceInfo device in deviceInfo)
                {
                    println("Device = " + device.DeviceName + " Ordinal number = " + device.OrdinalNumber.ToString() + " Device type = " + device.DeviceType.ToString());

                    #region DAD Signal & Spectrum
                    if (device.DeviceType == DeviceType.DiodeArrayDetector ||
                        device.DeviceType == DeviceType.HDR ||
                        device.DeviceType == DeviceType.CompactLC1220DAD)
                    {
                        //Extracting Signal Information
                        ISignalInfo[] sigInfo = nonMsReader.GetSignalInfo(device, StoredDataType.Chromatograms);
                        if (sigInfo.Length == 0)
                        {
                            println("No DAD signal found");
                        }
                        else
                        {
                            StringBuilder sb = new StringBuilder();
                            sb.AppendFormat("Found info on {0} signals: ", sigInfo.Length);
                            foreach (ISignalInfo info in sigInfo)
                            {
                                sb.AppendFormat("{0}, ", info.SignalName);
                            }
                            println(sb.ToString());

                            IBDAChromData chromData = nonMsReader.GetSignal(sigInfo[0]);
                            if ((chromData == null) || (chromData.TotalDataPoints == 0))
                            {
                                println("No data found for first DAD signal");
                            }
                            else
                            {
                                int      count  = chromData.TotalDataPoints;
                                double[] xArray = chromData.XArray;
                                float[]  yArray = chromData.YArray;

                                // This information can be exported to a file on disk
                                FileStream file = new FileStream(@"C:\temp\reportNew.csv", FileMode.Create, FileAccess.ReadWrite);
                                TextWriter sw   = new StreamWriter(file);
                                sw.WriteLine("#Point,X(Minutes),Y(Response Units)");
                                for (int i = 0; i < xArray.Length; i++)
                                {
                                    sw.WriteLine(i.ToString() + "," + xArray[i].ToString() + "," + yArray[i].ToString());
                                }
                                sw.Close();
                                file.Close();
                            }
                        }

                        //Extracting TWC
                        IBDAChromData chromDataTWC = nonMsReader.GetTWC(device);

                        //compare this data with our own file
                        if ((chromDataTWC == null) || (chromDataTWC.TotalDataPoints == 0))
                        {
                            println("No TWC found");
                        }
                        else
                        {
                            int      dataPoints = chromDataTWC.TotalDataPoints;
                            double[] xArrayTWC  = chromDataTWC.XArray;
                            float[]  yArrayTWC  = chromDataTWC.YArray;

                            // Expoting this information to a file on disk
                            FileStream fileTWC = new FileStream(@"C:\temp\reportTWC.csv", FileMode.Create, FileAccess.ReadWrite);
                            TextWriter swTWC   = new StreamWriter(fileTWC);
                            swTWC.WriteLine("#Point,X(Minutes),Y(Response Units)");
                            for (int i = 0; i < xArrayTWC.Length; i++)
                            {
                                swTWC.WriteLine(i.ToString() + "," + xArrayTWC[i].ToString() + "," + yArrayTWC[i].ToString());
                            }
                            swTWC.Close();
                            fileTWC.Close();
                        }

                        //Extracting EWC
                        IRange rangeSignal = new MinMaxRange(40, 250);
                        IRange rangeRef    = new MinMaxRange(40, 250);

                        IBDAChromData chromDataEWC = nonMsReader.GetEWC(device, rangeSignal, rangeRef);
                        if ((chromDataEWC == null) || (chromDataEWC.TotalDataPoints == 0))
                        {
                            println("No EWC found");
                        }
                        else
                        {
                            double[] xArrayEWC = chromDataEWC.XArray;
                            float[]  yArrayEWC = chromDataEWC.YArray;

                            // Expoting this information to a file on disk
                            FileStream fileEWC = new FileStream(@"C:\temp\reportEWC.csv", FileMode.Create, FileAccess.ReadWrite);
                            TextWriter swEWC   = new StreamWriter(fileEWC);
                            swEWC.WriteLine("#Point,X(Minutes),Y(Response Units)");
                            for (int i = 0; i < xArrayEWC.Length; i++)
                            {
                                swEWC.WriteLine(i.ToString() + "," + xArrayEWC[i].ToString() + "," + yArrayEWC[i].ToString());
                            }
                            swEWC.Close();
                            fileEWC.Close();
                        }

                        //UV Spectrum: get each UV spectrum in the file
                        string uvSpectraFilePath = @"C:\temp\reportUV.csv";
                        if (File.Exists(uvSpectraFilePath))
                        {
                            File.Delete(uvSpectraFilePath);
                        }
                        for (int k = 0; k < chromDataTWC.XArray.Length && k < maxSpectraToReport; k++)
                        {
                            IRange range = new MinMaxRange(chromDataTWC.XArray[k], chromDataTWC.XArray[k]);

                            IBDASpecData[] uvSpecData = nonMsReader.GetUVSpectrum(device, range);
                            if (uvSpecData == null)
                            {
                                println("No UV spectrum found");
                            }
                            else
                            {
                                foreach (IBDASpecData uvSpec in uvSpecData)
                                {
                                    if (uvSpec.TotalDataPoints != 0)
                                    {
                                        int      dataPopints = uvSpec.TotalDataPoints;
                                        double[] xArrayUV    = uvSpec.XArray;
                                        float[]  yArrayUV    = uvSpec.YArray;

                                        // Expoting this information to a file on disk
                                        FileStream fileUV = new FileStream(uvSpectraFilePath, FileMode.Append,
                                                                           FileAccess.Write);
                                        TextWriter swUV = new StreamWriter(fileUV);
                                        swUV.WriteLine("#Point,X(Nanometers),Y(mAU)");
                                        for (int i = 0; i < xArrayUV.Length; i++)
                                        {
                                            swUV.WriteLine(i.ToString() + "," + xArrayUV[i].ToString() + "," +
                                                           yArrayUV[i].ToString());
                                        }
                                        swUV.Close();
                                        fileUV.Close();
                                    }
                                    else
                                    {
                                        println("No UV spectrum found");
                                    }
                                }
                            }
                        }
                    }
                    #endregion

                    #region InstrumentCurves - TCC

                    if (device.DeviceType == DeviceType.ThermostattedColumnCompartment)
                    {
                        ISignalInfo[] sigInfo = nonMsReader.GetSignalInfo(device, StoredDataType.InstrumentCurves);
                        if (sigInfo.Length == 0)
                        {
                            println("No TCC Curves found");
                        }
                        else
                        {
                            IBDAChromData chromData = nonMsReader.GetSignal(sigInfo[0]);
                            if ((chromData == null) || (chromData.TotalDataPoints == 0))
                            {
                                println("No TCC Curves found");
                            }
                            else
                            {
                                int      count  = chromData.TotalDataPoints;
                                double[] xArray = chromData.XArray;
                                float[]  yArray = chromData.YArray;

                                // Expoting this information to a file on disk
                                FileStream file = new FileStream(@"C:\temp\reportInstrumentCurve.csv", FileMode.Create, FileAccess.ReadWrite);
                                TextWriter sw   = new StreamWriter(file);
                                sw.WriteLine("#Point,X(Minutes),Y(Response Units)");
                                for (int i = 0; i < xArray.Length; i++)
                                {
                                    sw.WriteLine(i.ToString() + "," + xArray[i].ToString() + "," + yArray[i].ToString());
                                }
                                sw.Close();
                                file.Close();
                            }
                        }
                    }
                    #endregion
                }
            }
        }
Beispiel #4
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]);
                 * }
                 */
            }
        }
Beispiel #5
0
        /// <summary>
        /// To extract non MS data
        /// </summary>
        private void ExtractNonMSData()
        {
            IMsdrDataReader dataReader = new MassSpecDataReader();

            dataReader.OpenDataFile(_NonMSdataFilename);

            INonmsDataReader nonMsReader = dataReader as INonmsDataReader;

            IDeviceInfo[] deviceInfo = nonMsReader.GetNonmsDevices();
            if ((deviceInfo == null) || (deviceInfo.Length == 0))
            {
                println("No Non MS device found");
            }
            else
            {
                foreach (IDeviceInfo device in deviceInfo)
                {
                    println("Device = " + device.DeviceName + " Ordinal number = " + device.OrdinalNumber.ToString() + " Device type = " + device.DeviceType.ToString());

                    #region DAD Signal & Spectrum
                    if (device.DeviceType == DeviceType.DiodeArrayDetector)
                    {
                        //Extracting Signal Information
                        ISignalInfo[] sigInfo = nonMsReader.GetSignalInfo(device, StoredDataType.Chromatograms);
                        if (sigInfo.Length == 0)
                        {
                            println("No DAD signal found");
                        }
                        else
                        {
                            IBDAChromData chromData = nonMsReader.GetSignal(sigInfo[0]);
                            if ((chromData == null) || (chromData.TotalDataPoints == 0))
                            {
                                println("No DAD signal found");
                            }
                            else
                            {
                                int      count  = chromData.TotalDataPoints;
                                double[] xArray = chromData.XArray;
                                float[]  yArray = chromData.YArray;

                                // This information can be exported to a file on disk
                                FileStream file = new FileStream(@"C:\temp\reportNew.csv", FileMode.Create, FileAccess.ReadWrite);
                                TextWriter sw   = new StreamWriter(file);
                                sw.WriteLine("#Point,X(Minutes),Y(Response Units)");
                                for (int i = 0; i < xArray.Length; i++)
                                {
                                    sw.WriteLine(i.ToString() + "," + xArray[i].ToString() + "," + yArray[i].ToString());
                                }
                                sw.Close();
                                file.Close();
                            }
                        }

                        //Extracting TWC
                        IBDAChromData chromDataTWC = nonMsReader.GetTWC(device);

                        //compare this data with our own file
                        if ((chromDataTWC == null) || (chromDataTWC.TotalDataPoints == 0))
                        {
                            println("No TWC found");
                        }
                        else
                        {
                            int      dataPoints = chromDataTWC.TotalDataPoints;
                            double[] xArrayTWC  = chromDataTWC.XArray;
                            float[]  yArrayTWC  = chromDataTWC.YArray;

                            // Expoting this information to a file on disk
                            FileStream fileTWC = new FileStream(@"C:\temp\reportTWC.csv", FileMode.Create, FileAccess.ReadWrite);
                            TextWriter swTWC   = new StreamWriter(fileTWC);
                            swTWC.WriteLine("#Point,X(Minutes),Y(Response Units)");
                            for (int i = 0; i < xArrayTWC.Length; i++)
                            {
                                swTWC.WriteLine(i.ToString() + "," + xArrayTWC[i].ToString() + "," + yArrayTWC[i].ToString());
                            }
                            swTWC.Close();
                            fileTWC.Close();
                        }

                        //Extracting EWC
                        IRange rangeSignal = new MinMaxRange(40, 250);
                        IRange rangeRef    = new MinMaxRange(40, 250);

                        IBDAChromData chromDataEWC = nonMsReader.GetEWC(device, rangeSignal, rangeRef);
                        if ((chromDataEWC == null) || (chromDataEWC.TotalDataPoints == 0))
                        {
                            println("No EWC signal found");
                        }
                        else
                        {
                            int      dataPointsEWC = chromDataEWC.TotalDataPoints;
                            double[] xArrayEWC     = chromDataEWC.XArray;
                            float[]  yArrayEWC     = chromDataEWC.YArray;

                            // Expoting this information to a file on disk
                            FileStream fileEWC = new FileStream(@"C:\temp\reportEWC.csv", FileMode.Create, FileAccess.ReadWrite);
                            TextWriter swEWC   = new StreamWriter(fileEWC);
                            swEWC.WriteLine("#Point,X(Minutes),Y(Response Units)");
                            for (int i = 0; i < xArrayEWC.Length; i++)
                            {
                                swEWC.WriteLine(i.ToString() + "," + xArrayEWC[i].ToString() + "," + yArrayEWC[i].ToString());
                            }
                            swEWC.Close();
                            fileEWC.Close();
                        }

                        //UV Spectrum
                        IRange       range = new MinMaxRange(1.109, 1.409);
                        IMinMaxRange ran   = new MinMaxRange(1, 2);
                        ran.Max = 1;

                        IBDASpecData[] uvSpecData = nonMsReader.GetUVSpectrum(device, range);
                        if (uvSpecData == null)
                        {
                            println("No UV signal found");
                        }
                        else
                        {
                            foreach (IBDASpecData uvSpec in uvSpecData)
                            {
                                if (uvSpec.TotalDataPoints != 0)
                                {
                                    int      dataPopints = uvSpec.TotalDataPoints;
                                    double[] xArrayUV    = uvSpec.XArray;
                                    float[]  yArrayUV    = uvSpec.YArray;

                                    // Expoting this information to a file on disk
                                    FileStream fileUV = new FileStream(@"C:\temp\reportUV.csv", FileMode.Create, FileAccess.ReadWrite);
                                    TextWriter swUV   = new StreamWriter(fileUV);
                                    swUV.WriteLine("#Point,X(Nanometers),Y(mAU)");
                                    for (int i = 0; i < xArrayUV.Length; i++)
                                    {
                                        swUV.WriteLine(i.ToString() + "," + xArrayUV[i].ToString() + "," + yArrayUV[i].ToString());
                                    }
                                    swUV.Close();
                                    fileUV.Close();
                                }
                                else
                                {
                                    println("No UV signal found");
                                }
                            }
                        }
                    }
                    #endregion

                    #region InstrumentCurves - TCC

                    if (device.DeviceType == DeviceType.ThermostattedColumnCompartment)
                    {
                        ISignalInfo[] sigInfo = nonMsReader.GetSignalInfo(device, StoredDataType.InstrumentCurves);
                        if (sigInfo.Length == 0)
                        {
                            println("No TCC Curves found");
                        }
                        else
                        {
                            IBDAChromData chromData = nonMsReader.GetSignal(sigInfo[0]);
                            if ((chromData == null) || (chromData.TotalDataPoints == 0))
                            {
                                println("No TCC Curves found");
                            }
                            else
                            {
                                int      count  = chromData.TotalDataPoints;
                                double[] xArray = chromData.XArray;
                                float[]  yArray = chromData.YArray;

                                // Expoting this information to a file on disk
                                FileStream file = new FileStream(@"C:\temp\reportInstrumentCurve.csv", FileMode.Create, FileAccess.ReadWrite);
                                TextWriter sw   = new StreamWriter(file);
                                sw.WriteLine("#Point,X(Minutes),Y(Response Units)");
                                for (int i = 0; i < xArray.Length; i++)
                                {
                                    sw.WriteLine(i.ToString() + "," + xArray[i].ToString() + "," + yArray[i].ToString());
                                }
                                sw.Close();
                                file.Close();
                            }
                        }
                    }
                    #endregion
                }
            }
        }
        public double GetTotalIntensity()
        {
            IBDAChromData data = GetTIC();

            return((double)data.YArray.Sum());
        }