예제 #1
0
        public static void GetIndex(this IRawDataPlus rawFile)
        {
            int firstScanNumber = rawFile.RunHeaderEx.FirstSpectrum;
            int lastScanNumber  = rawFile.RunHeaderEx.LastSpectrum;

            int idxCharge         = rawFile.GetIndexOfPattern();
            int idxMasterScan     = rawFile.GetIndexOfPattern("Master Scan Number:");
            int idxDependencyType = rawFile.GetIndexOfPattern("Dependency Type:");

            double charge, precursorMass;
            int    masterScan, dependencyType;

            Console.WriteLine("scan;scanType;rtinseconds;precursorMass;MSOrder;charge;masterScan;dependencyType");

            for (int scanNumber = firstScanNumber; scanNumber < lastScanNumber; scanNumber++)
            {
                var scanTrailer    = rawFile.GetTrailerExtraInformation(scanNumber);
                var scanStatistics = rawFile.GetScanStatsForScanNumber(scanNumber);
                var scanEvent      = rawFile.GetScanEventForScanNumber(scanNumber);
                var scanFilter     = rawFile.GetFilterForScanNumber(scanNumber);

                try{
                    var reaction0 = scanEvent.GetReaction(0);
                    precursorMass = reaction0.PrecursorMass;
                } catch {
                    precursorMass = -1;
                }

                try{
                    charge = int.Parse(scanTrailer.Values.ToArray()[idxCharge]);
                } catch {
                    charge = -1;
                }

                try{
                    masterScan = int.Parse(scanTrailer.Values.ToArray()[idxMasterScan]);
                } catch {
                    masterScan = -1;
                }

                try{
                    dependencyType = int.Parse(scanTrailer.Values.ToArray()[idxDependencyType]);
                } catch {
                    dependencyType = -1;
                }



                Console.WriteLine("{0};{1};{2};{3};{4};{5};{6};{7}", scanNumber,
                                  scanStatistics.ScanType.ToString(),
                                  Math.Round(scanStatistics.StartTime * 60 * 1000) / 1000,
                                  precursorMass,
                                  scanFilter.MSOrder.ToString(),
                                  charge, masterScan, dependencyType);
            }
        }
예제 #2
0
        /// <summary>
        ///    implements
        ///    https://github.com/fgcz/rawrr/issues/43
        /// </summary>
        /// <param name="rawFile"></param>
        /// <param name="filename"></param>
        /// <param name="L"></param>
        public static void WriteCentroidSpectrumAsRcode(this IRawDataPlus rawFile, string filename, List <int> L)
        {
            int count         = 1;
            var trailerFields = rawFile.GetTrailerExtraHeaderInformation();
            int indexCharge   = rawFile.GetIndexOfPattern("Charge State");

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(filename))
            {
                foreach (int scanNumber in L)
                {
                    var scan           = Scan.FromFile(rawFile, scanNumber);
                    var scanStatistics = rawFile.GetScanStatsForScanNumber(scanNumber);
                    var centroidStream = rawFile.GetCentroidStream(scanNumber, false);
                    var scanEvent      = rawFile.GetScanEventForScanNumber(scanNumber);
                    var scanTrailer    = rawFile.GetTrailerExtraInformation(scanNumber);

                    file.WriteLine("e$Spectrum[[{0}]] <- list(", count++);
                    file.WriteLine("\tscan = {0},", scanNumber);
                    file.WriteLine("\trtinseconds = {0},", Math.Round(scanStatistics.StartTime * 60 * 1000) / 1000);
                    if (indexCharge > 0)
                    {
                        file.WriteLine("\tcharge = {0},", int.Parse(scanTrailer.Values.ToArray()[indexCharge]));
                    }
                    else
                    {
                        file.WriteLine("\tcharge = NA,");
                    }

                    try{
                        var reaction0 = scanEvent.GetReaction(0);
                        file.WriteLine("\tpepmass = {0},", reaction0.PrecursorMass);
                    }catch {
                        file.WriteLine("\tpepmass = NA,");
                    }

                    if (scanStatistics.IsCentroidScan && centroidStream.Length > 0)
                    {
                        file.WriteLine("\tmZ = c(" + string.Join(", ", centroidStream.Masses) + "),");
                        file.WriteLine("\tintensity = c(" + string.Join(", ", centroidStream.Intensities) + ")");
                    }
                    else
                    {
                        file.WriteLine("\tmZ = NULL,\n\tintensity = NULL");
                    }
                    file.WriteLine("\t)");
                }
            }
        }
예제 #3
0
        public static void WriteSpectrumAsRcode0(this IRawDataPlus rawFile, string filename)
        {
            int    idxCharge       = rawFile.GetIndexOfPattern();
            int    firstScanNumber = rawFile.RunHeaderEx.FirstSpectrum;
            int    lastScanNumber  = rawFile.RunHeaderEx.LastSpectrum;
            int    charge          = -1;
            double pc = -1;

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(filename))
            {
                for (int scanNumber = firstScanNumber; scanNumber < lastScanNumber; scanNumber++)
                {
                    var scanTrailer    = rawFile.GetTrailerExtraInformation(scanNumber);
                    var scanStatistics = rawFile.GetScanStatsForScanNumber(scanNumber);
                    var scanEvent      = rawFile.GetScanEventForScanNumber(scanNumber);
                    var scanFilter     = rawFile.GetFilterForScanNumber(scanNumber);


                    try{
                        var reaction0 = scanEvent.GetReaction(0);
                        pc = reaction0.PrecursorMass;
                    }
                    catch {
                        pc = -1;
                    }

                    try{
                        charge = int.Parse(scanTrailer.Values.ToArray()[idxCharge]);
                    }
                    catch {
                        charge = -1;
                    }

                    file.WriteLine("e$Spectrum[[{0}]] <- list(", scanNumber);
                    file.WriteLine("\tscan = {0};", scanNumber);
                    file.WriteLine("\tscanType = \"{0}\";", scanStatistics.ScanType.ToString());
                    file.WriteLine("\trtinseconds = {0};", Math.Round(scanStatistics.StartTime * 60 * 1000) / 1000);
                    file.WriteLine("\tprecursorMass = {0};", pc);
                    file.WriteLine("\tMSOrder = '{0}';", scanFilter.MSOrder.ToString());
                    file.WriteLine("\tcharge = {0}", charge);
                    file.WriteLine(")");
                }
            }
        }
예제 #4
0
        /// <summary>
        /// </summary>
        /// <param name="rawFile"></param>
        /// <param name="filename"></param>
        /// <param name="L"></param>
        public static void WriteSpectrumAsRcode(this IRawDataPlus rawFile, string filename, List <int> L)
        {
            int count               = 1;
            var trailerFields       = rawFile.GetTrailerExtraHeaderInformation();
            int indexCharge         = rawFile.GetIndexOfPattern("Charge State");
            int indexMonoisotopicmZ = rawFile.GetIndexOfPattern("MonoisotopicmZ");

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(filename))
            {
                foreach (int scanNumber in L)
                {
                    var basepeakMass      = -1.0;
                    var basepeakIntensity = -1.0;

                    var scanStatistics = rawFile.GetScanStatsForScanNumber(scanNumber);
                    var centroidStream = rawFile.GetCentroidStream(scanNumber, false);
                    var scanTrailer    = rawFile.GetTrailerExtraInformation(scanNumber);
                    var scanEvent      = rawFile.GetScanEventForScanNumber(scanNumber);

                    var scan = Scan.FromFile(rawFile, scanNumber);

                    file.WriteLine("e$Spectrum[[{0}]] <- list(", count++);
                    file.WriteLine("\tscan = {0},", scanNumber);

                    try
                    {
                        basepeakMass      = (scanStatistics.BasePeakMass);
                        basepeakIntensity = Math.Round(scanStatistics.BasePeakIntensity);
                        file.WriteLine("\tbasePeak = c({0}, {1}),", basepeakMass, basepeakIntensity);
                    }
                    catch
                    {
                        file.WriteLine("\tbasePeak = c(NA, NA),");
                    }
                    file.WriteLine("\tTIC = {0},", scanStatistics.TIC.ToString());
                    file.WriteLine("\tmassRange = c({0}, {1}),", scanStatistics.LowMass.ToString(), scanStatistics.HighMass.ToString());
                    file.WriteLine("\tscanType = \"{0}\",", scanStatistics.ScanType.ToString());
                    file.WriteLine("\trtinseconds = {0},", Math.Round(scanStatistics.StartTime * 60 * 1000) / 1000);
                    try
                    {
                        var reaction0 = scanEvent.GetReaction(0);
                        file.WriteLine("\tpepmass = {0},", reaction0.PrecursorMass);
                    }
                    catch
                    {
                        file.WriteLine("\tpepmass = NA,");
                    }

                    if (scanStatistics.IsCentroidScan && centroidStream.Length > 0)
                    {
                        // Get the centroid (label) data from the RAW file for this scan
                        file.WriteLine("\tcentroidStream = TRUE,");

                        file.WriteLine("\tHasCentroidStream = '{0}, Length={1}',", scan.HasCentroidStream, scan.CentroidScan.Length);
                        if (scan.HasCentroidStream)
                        {
                            file.WriteLine("\tcentroid.mZ = c(" + string.Join(", ", scan.CentroidScan.Masses.ToArray()) + "),");
                            file.WriteLine("\tcentroid.intensity = c(" + string.Join(", ", scan.CentroidScan.Intensities.ToArray()) + "),");
                        }

                        file.WriteLine("\ttitle = \"File: {0}; SpectrumID: {1}; scans: {2}\",",
                                       Path.GetFileName(rawFile.FileName),
                                       null,
                                       scanNumber);

                        if (indexMonoisotopicmZ > 0)
                        {
                            file.WriteLine("\tmonoisotopicMz = {0},", Convert.ToDouble(scanTrailer.Values.ToArray()[indexMonoisotopicmZ]));
                        }
                        else
                        {
                            file.WriteLine("\tmonoisotopicMz = NA,");
                        }


                        if (indexCharge > 0)
                        {
                            file.WriteLine("\tcharge = {0},", int.Parse(scanTrailer.Values.ToArray()[indexCharge]));
                        }
                        else
                        {
                            file.WriteLine("\tcharge = NA,");
                        }

                        file.WriteLine("\tmZ = c(" + string.Join(", ", centroidStream.Masses) + "),");
                        file.WriteLine("\tintensity = c(" + string.Join(", ", centroidStream.Intensities) + "),");
                        file.WriteLine("\tnoises = c(" + string.Join(", ", centroidStream.Noises) + "),");
                        file.WriteLine("\tresolutions = c(" + string.Join(", ", centroidStream.Resolutions.ToArray()) + "),");
                        file.WriteLine("\tcharges = c(" + string.Join(", ", centroidStream.Charges) + "),");
                        file.WriteLine("\tbaselines = c(" + string.Join(", ", centroidStream.Baselines) + "),");
                    }
                    else
                    {
                        file.WriteLine("\tcentroidStream = FALSE,");

                        file.WriteLine("\tHasCentroidStream = '{0}, Length={1}',", scan.HasCentroidStream, scan.CentroidScan.Length);
                        if (scan.HasCentroidStream)
                        {
                            file.WriteLine("\tcentroid.mZ = c(" + string.Join(",", scan.CentroidScan.Masses.ToArray()) + "),");
                            file.WriteLine("\tcentroid.intensity = c(" + string.Join(",", scan.CentroidScan.Intensities.ToArray()) + "),");
                        }

                        file.WriteLine("\ttitle = \"File: {0}; SpectrumID: {1}; scans: {2}\",",
                                       Path.GetFileName(rawFile.FileName),
                                       null,
                                       scanNumber);

                        if (indexCharge > 0)
                        {
                            file.WriteLine("\tcharge = {0},", int.Parse(scanTrailer.Values.ToArray()[indexCharge]));
                        }
                        else
                        {
                            file.WriteLine("\tcharge = NA,");
                        }

                        if (indexMonoisotopicmZ > 0)
                        {
                            file.WriteLine("\tmonoisotopicMz = {0},", Convert.ToDouble(scanTrailer.Values.ToArray()[indexMonoisotopicmZ]));
                        }
                        else
                        {
                            file.WriteLine("\tmonoisotopicMz = NA,");
                        }

                        file.WriteLine("\tmZ = c(" + string.Join(",", scan.SegmentedScan.Positions) + "),");
                        file.WriteLine("\tintensity = c(" + string.Join(",", scan.SegmentedScan.Intensities) + "),");
                        // file.WriteLine("\tnoises = c(" + string.Join(",", scan.SegmentedScan.Noises) + "),");
                    }
                    // ============= Instrument Data =============
                    // write scan Trailer
                    var trailerValues = scanTrailer.Values;
                    var trailerLabels = scanTrailer.Labels;
                    var zipTrailer    = trailerLabels.ToArray().Zip(trailerValues, (a, b) => string.Format("\t\"{0}\" = \"{1}\"", a, b));
                    file.WriteLine(string.Join(", \n", zipTrailer));
                    file.WriteLine(")");
                }
            }

            return;
        }