Exemplo n.º 1
0
        public DataReaderCSharpClient()
        {
            string msg        = null;
            string stackTrace = null;

            try
            {
                // Transition information for MRM data files
                TestIsPrimaryChrom(_tMRM_DataFile);

                // UV spectra and signals for non-MS detectors
                ExtractNonMSData(_nonMs_DataFile1, 10);

                //Create an instance of MassSpecDataReader to open up the data file
                IMsdrDataReader dataAccess = new MassSpecDataReader();
                println("MHDA API Version: " + dataAccess.Version);
                dataAccess.OpenDataFile(_tgtMsMs_DataFile);

                GetAxisInformation(dataAccess);
                PrintFileInfo(dataAccess);
                PrintDeviceInfo(dataAccess);
                PrintMSScanInfo(dataAccess);
                GetAllScansUsingRowIndex(dataAccess);//Get all scans using row Index
                GetPrecursorInfo(dataAccess);
                DeisotopeTest(dataAccess);
                DoSpectrumExtractionTest(dataAccess);
                DoSpectrumExtractionTestWithStorage(dataAccess);
                GetAllScanRecords(dataAccess);
                GetSampleInfoData(dataAccess);
                ExtractEIC(dataAccess);

                dataAccess.CloseDataFile();
                println("\nDone.");
            }
            catch (Exception ex)
            {
                msg        = ex.Message;
                stackTrace = ex.StackTrace;

                println("Exception: " + msg);
            }
            println("Press Enter to close");
            Console.ReadLine();
        }
Exemplo n.º 2
0
        // Examine triggered MRM data file transition chromatograms to see which are
        // for primary transitions.
        private void TestIsPrimaryChrom(string tMrmFilePath)
        {
            IMsdrDataReader dataReader = new MassSpecDataReader();

            dataReader.OpenDataFile(tMrmFilePath);
            IBDAChromFilter filter = new BDAChromFilter();

            filter.ChromatogramType = ChromType.MultipleReactionMode;
            filter.MSScanTypeFilter = MSScanType.MultipleReaction;
            filter.ExtractOneChromatogramPerScanSegment = true;
            filter.DoCycleSum = false;

            IBDAChromData[] chroms = dataReader.GetChromatogram(filter);
            foreach (IBDAChromData chrom in chroms)
            {
                bool   val = chrom.IsPrimaryMrm;
                string s   = string.Format("{0}->{1}, {2}", chrom.MZOfInterest[0].Start, chrom.MeasuredMassRange[0].Start,
                                           val);
                println(s);
            }

            dataReader.CloseDataFile();
        }
Exemplo n.º 3
0
        public DataReaderCSharpClient()
        {
            //Create an instance of MassSpecDataReader to open up the data file

            //ExtractNonMSData();

            IMsdrDataReader dataAccess = new MassSpecDataReader();

            println("MHDA API Version: " + dataAccess.Version);
            dataAccess.OpenDataFile(_dataFilename1);
            GetMSLevels(dataAccess);

            //PrintFileInfo(dataAccess);
            //PrintDeviceInfo(dataAccess);
            //PrintMSScanInfo(dataAccess);
            //GetAllScansUsingRowIndex(dataAccess);//Get all scans using row Index
            //GetPrecursorInfo(dataAccess);
            //DeisotopeTest(dataAccess);
            //DoSpectrumExtractionTest(dataAccess);
            //DoSpectrumExtractionTestWithStorage(dataAccess);
            //dataAccess.CloseDataFile();
            //DadSignalExtract();
        }
Exemplo n.º 4
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
                }
            }
        }
Exemplo n.º 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
                }
            }
        }
Exemplo n.º 6
0
        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();
        }
Exemplo n.º 7
0
        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();
        }