コード例 #1
0
        public static void PrintSpectrumMS2(StreamWriter sr, MSUltraLight theSpectrum, string identification = null, string fileName = null)
        {
            sr.WriteLine("S\t" + theSpectrum.ScanNumber + "\t" + theSpectrum.ScanNumber + "\t" + theSpectrum.Precursors[0].Item1);
            sr.WriteLine("I\tRetTime\t" + theSpectrum.CromatographyRetentionTime);


            if (identification != null)
            {
                sr.WriteLine("I\tPeptide\t" + identification);
            }

            if (fileName != null)
            {
                sr.WriteLine("I\tFileName\t" + fileName);
            }

            foreach (var precursor in theSpectrum.Precursors)
            {
                sr.WriteLine("Z\t" + precursor.Item2 + "\t" + PatternTools.pTools.DechargeMSPeakToPlus1(precursor.Item1, precursor.Item2));
            }

            for (int i = 0; i < theSpectrum.Ions.Count; i++)
            {
                sr.WriteLine(Math.Round(theSpectrum.Ions[i].Item1, 5) + " " + Math.Round(theSpectrum.Ions[i].Item2, 5));
            }
        }
コード例 #2
0
        public static string PrintSpectrum(MSUltraLight theSpectrum)
        {
            StringBuilder sb = new StringBuilder();

            if (theSpectrum.MSLevel > 1)
            {
                sb.AppendLine("S\t" + theSpectrum.ScanNumber + "\t" + theSpectrum.ScanNumber + "\t" + theSpectrum.Precursors[0].Item1);
            }
            else
            {
                sb.AppendLine("S\t" + theSpectrum.ScanNumber + "\t" + theSpectrum.ScanNumber);
            }

            sb.AppendLine("I\tRetTime\t" + theSpectrum.CromatographyRetentionTime);
            sb.AppendLine("I\tInstrumentType\t" + theSpectrum.InstrumentType);

            if (theSpectrum.MSLevel > 1)
            {
                foreach (Tuple <float, short> precursor in theSpectrum.Precursors)
                {
                    sb.AppendLine("Z\t" + precursor.Item2 + "\t" + PatternTools.pTools.DechargeMSPeakToPlus1(precursor.Item1, precursor.Item2));
                }
            }

            for (int i = 0; i < theSpectrum.Ions.Count; i++)
            {
                sb.AppendLine(Math.Round(theSpectrum.Ions[i].Item1, 5) + " " + Math.Round(theSpectrum.Ions[i].Item2, 5));
            }

            return(sb.ToString());
        }
コード例 #3
0
        /// <summary>
        /// Method responsible for parsing RAW File.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public List <MSUltraLight> ParseFile(String rawFile, short fileIndex = -1, int MsnLevel = 2, List <int> ScanNumbers = null, bool toPrint_console = true)
        {
            if (!File.Exists(rawFile))
            {
                throw new Exception("ParserUltraLightRAW error:: Unable to find the file " + rawFile);
            }

            MSFileReaderLib.IXRawfile2 raw = (MSFileReaderLib.IXRawfile2) new MSFileReader_XRawfile();
            raw.Open(rawFile);
            raw.SetCurrentController(0, 1);

            Dictionary <int, double[, ]> ms1s = null;

            if (GET_PRECURSOR_MZ_AND_INTENSITY_FROM_MS1)
            {
                ms1s = new Dictionary <int, double[, ]>();
            }

            int first_scan_number = -1;

            raw.GetFirstSpectrumNumber(ref first_scan_number);
            int last_scan_number = -1;

            raw.GetLastSpectrumNumber(ref last_scan_number);

            object progress_lock     = new object();
            int    spectra_processed = 0;
            int    old_progress      = 0;

            MSUltraLight[] myTMSArray = new MSUltraLight[last_scan_number + 2];

            //We will only retrieve certain scan numbers
            if (ScanNumbers == null)
            {
                ScanNumbers = new List <int>();
                for (int scan_number = first_scan_number; scan_number <= last_scan_number + 1; scan_number++)
                {
                    ScanNumbers.Add(scan_number);
                }
            }

            ScanNumbers.Sort();


            foreach (int scan_number in ScanNumbers)
            {
                spectra_processed++;
                string scan_filter = null;
                raw.GetFilterForScanNum(scan_number, ref scan_filter);

                if (String.IsNullOrEmpty(scan_filter))
                {
                    Console.WriteLine("Scan " + scan_number + " is null");
                    continue;
                }

                if (MsnLevel == 1)
                {
                    if (!isMS1.IsMatch(scan_filter))
                    {
                        if (!isMS1_1.IsMatch(scan_filter))
                        {
                            continue;
                        }
                    }
                }
                else if (MsnLevel == 2)
                {
                    if (!isMS2.IsMatch(scan_filter))
                    {
                        continue;
                    }
                }
                else if (MsnLevel == 3)
                {
                    if (!isMS3.IsMatch(scan_filter))
                    {
                        continue;
                    }
                }


                string spectrum_id = "controllerType=0 controllerNumber=1 scan=" + scan_number.ToString();

                double retention_time = double.NaN;
                raw.RTFromScanNum(scan_number, ref retention_time);

                double precursor_mz;
                double precursor_intensity;
                int    precursor_scanNumber;


                double ionInjectionTime;
                int    charge;

                if (MsnLevel > 1)
                {
                    GetPrecursor(ms1s, raw, scan_number, scan_filter, first_scan_number, out precursor_mz, out precursor_intensity, out precursor_scanNumber);
                    DeterminePrecursorParams(raw, scan_number, out charge, out ionInjectionTime);
                }
                else
                {
                    charge              = -1;
                    precursor_mz        = -1;
                    precursor_intensity = -1;
                }

                double[,] label_data = GetFragmentationData(raw, scan_number, scan_filter);

                List <Tuple <float, float> > peaks = new List <Tuple <float, float> >(label_data.GetLength(1));
                for (int peak_index = label_data.GetLowerBound(1); peak_index <= label_data.GetUpperBound(1); peak_index++)
                {
                    // Calculate index in list of ions object
                    int index = peak_index - label_data.GetLowerBound(1);

                    // Get fragment ion m/z and intensity from RAW file
                    float mz        = (float)label_data[(int)RawLabelDataColumn.MZ, peak_index];
                    float intensity = (float)label_data[(int)RawLabelDataColumn.Intensity, peak_index];

                    // Create new ion object
                    peaks.Add(new Tuple <float, float>(mz, intensity));
                }

                if (peaks.Count > 0)
                {
                    MSUltraLight ms = new MSUltraLight((float)retention_time,
                                                       scan_number,
                                                       peaks,
                                                       new List <Tuple <float, short> >()
                    {
                        new Tuple <float, short>((float)precursor_mz, (short)charge)
                    },
                                                       (float)precursor_intensity,
                                                       1,          //Instrument type
                                                       (short)MsnLevel,
                                                       fileIndex);

                    myTMSArray[scan_number] = ms;
                }

                lock (progress_lock)
                {
                    int new_progress = (int)((double)spectra_processed / (last_scan_number - first_scan_number + 1) * 100);
                    if (new_progress > old_progress)
                    {
                        old_progress = new_progress;
                        if (toPrint_console)
                        {
                            int currentLineCursor = Console.CursorTop;
                            Console.SetCursorPosition(0, Console.CursorTop);
                            Console.Write(" Reading RAW File: " + old_progress + "%");
                            Console.SetCursorPosition(0, currentLineCursor);
                        }
                        else
                        {
                            Console.Write(" Reading RAW File: " + old_progress + "%");
                        }
                    }
                }
            }

            Console.Write(" Reading RAW File: 100%");
            return(myTMSArray.Where(a => a != null).ToList());
        }
コード例 #4
0
 public static void PrintSpectrum(StreamWriter sw, MSUltraLight theSpectrum)
 {
     sw.WriteLine(PrintSpectrum(theSpectrum));
 }
コード例 #5
0
        /// <summary>
        /// The result is sorted by scan number
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public static List <MSUltraLight> ParseSpectra(string fileName)
        {
            FileInfo fi = new FileInfo(fileName);

            if (!fi.Exists)
            {
                throw new Exception("File " + fi.FullName + " not found.");
            }
            List <MSUltraLight> theSpectra = new List <MSUltraLight>(100);

            if (fi.Extension.Equals(".ms2") || fi.Extension.Equals(".ms3"))
            {
                //The PathCandidates
                Regex        tabSeparator        = new Regex(@"\t");
                Regex        mzSeparator         = new Regex(@"\s+", RegexOptions.Compiled);
                Regex        isNumber            = new Regex(@"^[0-9]", RegexOptions.Compiled);
                Regex        RegExRetTime        = new Regex(@"RetTime");
                Regex        RegexActivationType = new Regex(@"ActivationType");
                Regex        RegexInstrumentType = new Regex(@"InstrumentType");
                StreamReader sr = new StreamReader(fileName);


                List <Tuple <float, float> > ionsTemp = new List <Tuple <float, float> >();

                string line;

                MSUltraLight ms = new MSUltraLight();
                ms.Precursors = new List <Tuple <float, short> >();
                while ((line = sr.ReadLine()) != null)
                {
                    if (isNumber.IsMatch(line))
                    {
                        string[] cols = mzSeparator.Split(line);
                        ionsTemp.Add(new Tuple <float, float>(float.Parse(cols[0]), float.Parse(cols[1])));
                    }
                    else if (RegExRetTime.IsMatch(line))
                    {
                        string[] theStrings2 = tabSeparator.Split(line);
                        ms.CromatographyRetentionTime = float.Parse(theStrings2[2]);
                    }
                    else if (line.StartsWith("Z"))
                    {
                        string[] cols = Regex.Split(line, "\t");
                        ms.Precursors.Add(new Tuple <float, short>((float.Parse(cols[2])), short.Parse(cols[1])));
                    }
                    else if (line.StartsWith("S"))
                    {
                        //We have a new spectra // scan
                        ms.UpdateIons(ionsTemp);

                        if (fi.Extension.Equals(".ms2"))
                        {
                            ms.MSLevel = 2;
                        }
                        else
                        {
                            ms.MSLevel = 3;
                        }

                        theSpectra.Add(ms);
                        //Step 2:Get the new one ready
                        ms            = new MSUltraLight();
                        ms.Precursors = new List <Tuple <float, short> >();
                        ionsTemp      = new List <Tuple <float, float> >();
                        string[] cols = tabSeparator.Split(line);
                        ms.ScanNumber    = int.Parse(cols[1]);
                        ms.FileNameIndex = -1;
                    }
                }

                ms.UpdateIons(ionsTemp);

                if (fi.Extension.Equals(".ms2"))
                {
                    ms.MSLevel = 2;
                }
                else
                {
                    ms.MSLevel = 3;
                }

                theSpectra.Add(ms);

                sr.Close();

                //Just in case
                theSpectra.Sort((a, b) => a.ScanNumber.CompareTo(b.ScanNumber));
                theSpectra.RemoveAt(0);

                return(theSpectra);
            }

            else
            {
                throw new Exception(fi.Extension + " is not an acceptable extendion");
            }
        }