Ejemplo n.º 1
0
        static void Main_Peakpick_Test(string[] args)
        {
            Console.WriteLine("Peakpicking test!");

            string       spectrumfile  = "//rc-data1/blaise/ms_data_share/Max/QE_API/peakpick_testing/segment.txt";
            string       outputfile    = "//rc-data1/blaise/ms_data_share/Max/QE_API/peakpick_testing/seg_output.txt";
            List <Peak>  spectrum_agg  = new List <Peak>();
            int          scan_number   = -1;
            StreamReader spectrum_data = File.OpenText(spectrumfile);
            StreamWriter peak_output   = new StreamWriter(outputfile);
            string       line          = null;

            while ((line = spectrum_data.ReadLine()) != null)
            {
                if (line.Contains('#'))
                {
                    List <Peak> pickedpeaks = Spectral_Processing.deisotope_scan(spectrum_agg);
                    peak_output.WriteLine("SCAN {0}", scan_number.ToString());
                    foreach (Peak charge_peak in pickedpeaks)
                    {
                        peak_output.WriteLine("{0} {1} {2}",
                                              charge_peak.Item1,
                                              charge_peak.Item2,
                                              charge_peak.Item3);
                    }
                    peak_output.WriteLine("#");
                    Console.WriteLine(scan_number.ToString() + " " + pickedpeaks.Count().ToString());
                }
                else if (line.Contains("SCAN"))
                {
                    string scannumstr = line.Split(' ')[1];
                    Debug.Assert(Int32.TryParse(scannumstr, out scan_number));
                    spectrum_agg.Clear();
                }
                else
                {
                    string[] words = line.Split(' ');
                    Debug.Assert(words.Length == 2);
                    double mz        = -1;
                    double intensity = -1;
                    Debug.Assert(Double.TryParse(words[0], out mz));
                    Debug.Assert(Double.TryParse(words[1], out intensity));
                    spectrum_agg.Add(new Peak(mz, intensity, null));
                }
            }
            peak_output.Close();
        }
Ejemplo n.º 2
0
        public override void receiveScan(IMsScan scanData)
        {
            //IInfoContainer info = scanData.CommonInformation;
            //IInfoContainer more_info = scanData.SpecificInformation;
            //MsScanInformationSource infosource = MsScanInformationSource.Unknown;
            object   obj_holder = null;
            ScanType scan_id    = ScanType.Unknown;
            int      scannum    = -1;

            //if (info.TryGetRawValue("Scan", out obj_holder, ref infosource))
            //{
            //    scannum = (int)obj_holder;
            //    if (ScanID.ContainsKey(scannum)) // Auto-scans also have Scan numbers!
            //    {
            //        scan_id = ScanID[scannum];
            //        ScanID.Remove(scannum);
            //    }
            //}
            //object accessid = null;
            if (scanData.SpecificInformation.TryGetRawValue("Access Id:", out obj_holder))
            {
                scannum = (int)obj_holder;
                if (ScanID.ContainsKey(scannum))
                {
                    scan_id = ScanID[scannum];
                    ScanID.Remove(scannum);
                }
            }

            //Debug.Assert(false);
            if (scannum >= ScanCount)
            {
                Console.WriteLine("Adjusting ScanCount: " + scannum.ToString() + " " + ScanCount.ToString());
                log_write("Adjusting ScanCount: " + scannum.ToString() + " " + ScanCount.ToString());
                ScanCount = scannum + 1;
            }
            //else if (scannum + 100 < ScanCount)
            //{
            //    Console.WriteLine("Adjusting ScanCount DOWNWARD: " + scannum.ToString() + " " + ScanCount.ToString());
            //    log_write("Adjusting ScanCount DOWNWARD: " + scannum.ToString() + " " + ScanCount.ToString());
            //    ScanCount = scannum + 1;
            //}

            Console.WriteLine("Received a " + scan_id.ToString() + " " + scannum.ToString());
            log_write("Received a " + scan_id.ToString() + " " + scannum.ToString());

            switch (scan_id)
            {
            case ScanType.MS2:
            case ScanType.Auto:
            case ScanType.Unknown:
                return;

            case ScanType.MS1:
                MS1_outstanding = false;

                IEnumerable <Tuple <double, double> >               scan             = Spectral_Processing.ConvertCentroids(scanData.Centroids);
                List <Tuple <int, Tuple <double, double> > >        molecular_peaks  = Spectral_Processing.deisotope_scan(scan);
                IEnumerable <Tuple <int, Tuple <double, double> > > valid_precursors = molecular_peaks.Where(x => x.Item1 > 1);

                IEnumerable <Tuple <int, Tuple <double, double> > > precursors_by_int = valid_precursors.OrderByDescending(OrderPeak);

                GenerateMS2s(precursors_by_int);
                Console.WriteLine("MS1 stats: " + scan.Count() + " " + valid_precursors.Count());
                log_write("MS1 stats: " + scan.Count() + " " + valid_precursors.Count());
                return;

            default:
                Debug.Assert(false);
                return;
            }
        }
        public override void receiveScan(IMsScan scanData)
        {
            //IInfoContainer info = scanData.CommonInformation;
            //IInfoContainer more_info = scanData.SpecificInformation;
            //MsScanInformationSource infosource = MsScanInformationSource.Unknown;
            object   obj_holder = null;
            ScanType scan_id    = ScanType.Unknown;
            int      scannum    = -1;

            //if (info.TryGetRawValue("Scan", out obj_holder, ref infosource))
            //{
            //    scannum = (int)obj_holder;
            //    if (ScanID.ContainsKey(scannum)) // Auto-scans also have Scan numbers!
            //    {
            //        scan_id = ScanID[scannum];
            //        ScanID.Remove(scannum);
            //    }
            //}
            //object accessid = null;
            if (scanData.SpecificInformation.TryGetRawValue("Access Id:", out obj_holder))
            {
                scannum = (int)obj_holder;
                if (ScanID.ContainsKey(scannum))
                {
                    scan_id = ScanID[scannum];
                    ScanID.Remove(scannum);
                }
            }

            if (scannum > ScanCount)
            {
                Console.WriteLine("Adjusting ScanCount: " + scannum.ToString() + " " + ScanCount.ToString());
                log_write("Adjusting ScanCount: " + scannum.ToString() + " " + ScanCount.ToString());
                ScanCount = scannum + 1;
            }
            //else if (scannum + 100 < ScanCount)
            //{
            //    Console.WriteLine("Adjusting ScanCount DOWNWARD: " + scannum.ToString() + " " + ScanCount.ToString());
            //    log_write("Adjusting ScanCount DOWNWARD: " + scannum.ToString() + " " + ScanCount.ToString());
            //    ScanCount = scannum + 1;
            //}

            Console.WriteLine("Received a " + scan_id.ToString() + " " + scannum.ToString());
            log_write("Received a " + scan_id.ToString() + " " + scannum.ToString());

            switch (scan_id)
            {
            case ScanType.MS1:
            case ScanType.MS2:
            case ScanType.Auto:
            case ScanType.Unknown:
                // Only Box-MS1 scans are being used for precursor assignment.
                // Other scans are merely written to the file automatically.
                return;

            case ScanType.BoxMS1_1:
            case ScanType.BoxMS1_2:
            case ScanType.BoxMS1_3:
                //MS1_outstanding -= 1;
                Debug.Assert(!BoxAggregation.ContainsKey(scan_id));
                BoxAggregation.Add(scan_id, Spectral_Processing.ConvertCentroids(scanData.Centroids).ToList());
                Console.WriteLine("Received MS1 " + MS1_outstanding.ToString() + " " + BoxAggregation.Count().ToString());


                if (BoxAggregation.Count() >= 3)
                {
                    log_write("Processing boxes. " + BoxAggregation.Keys.ToString());

                    MS1_outstanding = false;

                    IEnumerable <Peak> scan = BoxesToMS1();

                    List <Peak>        molecular_peaks  = Spectral_Processing.deisotope_scan(scan);
                    IEnumerable <Peak> valid_precursors = molecular_peaks.Where(x => x.Item1 > 1);

                    IEnumerable <Peak> precursors_by_int = valid_precursors.OrderByDescending(OrderPeak);

                    GenerateMS2s(precursors_by_int);
                }
                return;

            default:
                Debug.Assert(false);
                return;
            }
        }