Пример #1
0
        public static void WriteToDisk(WorkFlows.WorkflowParameters opts)
        {
            List <string> files = new List <string>();

            Console.WriteLine();

            Console.WriteLine("Writing log files");

            foreach (var file in files)
            {
                Console.WriteLine(Path.GetFileName(file));
                Console.WriteLine("----------------------------------------");
                using (IRawDataPlus rawFile = RawFileReaderFactory.ReadFile(file))
                {
                    rawFile.SelectMsData();

                    var numberOfLogs = rawFile.GetStatusLogEntriesCount();
                    var logInfo      = rawFile.GetStatusLogHeaderInformation();

                    string logName = file + ".INST_LOG.txt";

                    Dictionary <int, ISingleValueStatusLog> log = new Dictionary <int, ISingleValueStatusLog>();

                    ProgressIndicator P = new ProgressIndicator(logInfo.Count(), "Preparing log data");
                    P.Start();
                    for (int i = 0; i < logInfo.Count(); i++)
                    {
                        log.Add(i, rawFile.GetStatusLogAtPosition(i));
                        P.Update();
                    }
                    P.Done();

                    using (StreamWriter f = new StreamWriter(logName))
                    {
                        P = new ProgressIndicator(numberOfLogs, $"Writing log");
                        P.Start();
                        f.Write("Time\t");
                        foreach (var x in logInfo)
                        {
                            f.Write(x.Label + "\t");
                        }
                        f.Write("\n");

                        for (int i = 0; i < numberOfLogs; i++)
                        {
                            f.Write($"{log[0].Times[i]}\t");

                            for (int j = 0; j < logInfo.Length; j++)
                            {
                                try
                                {
                                    f.Write("{0}\t", log[j].Values[i]);
                                }
                                catch (Exception)
                                {
                                    f.Write("\t");
                                }
                            }
                            f.Write("\n");
                            P.Update();
                        }
                        P.Done();
                    }
                }
                Console.WriteLine("\n");
            }
        }
Пример #2
0
        static int DoStuff(ArgumentParser.LogDumpOptions opts)
        {
            List <string> files = new List <string>();

            if (opts.InputFiles.Count() > 0) // did the user give us a list of files?
            {
                List <string> problems = new List <string>();
                files = opts.InputFiles.ToList();

                // check if the list provided contains only .raw files
                foreach (string file in files)
                {
                    if (!file.EndsWith(".raw", StringComparison.OrdinalIgnoreCase))
                    {
                        problems.Add(file);
                    }
                }

                if (problems.Count() == 1)
                {
                    Console.WriteLine("\nERROR: {0} does not appear to be a .raw file. Invoke '>RawTools --help' if you need help.", problems.ElementAt(0));
                    Log.Error("Invalid file provided: {0}", problems.ElementAt(0));

                    return(1);
                }

                if (problems.Count() > 1)
                {
                    Console.WriteLine("\nERROR: The following {0} files do not appear to be .raw files. Invoke '>RawTools --help' if you need help." +
                                      "\n\n{1}", problems.Count(), String.Join("\n", problems));
                    Log.Error("Invalid files provided: {0}", String.Join(" ", problems));
                    return(1);
                }

                Log.Information("Files to be processed, provided as list: {0}", String.Join(" ", files));
            }

            else // did the user give us a directory?
            {
                if (Directory.Exists(opts.InputDirectory))
                {
                    files = Directory.GetFiles(opts.InputDirectory, "*.*", SearchOption.TopDirectoryOnly)
                            .Where(s => s.EndsWith(".raw", StringComparison.OrdinalIgnoreCase)).ToList();
                }
                else
                {
                    Console.WriteLine("ERROR: The provided directory does not appear to be valid.");
                    Log.Error("Invalid directory provided: {0}", opts.InputDirectory);
                    return(1);
                }

                Log.Information("Files to be processed, provided as directory: {0}", String.Join(" ", files));
            }

            Console.WriteLine();

            foreach (var file in files)
            {
                Console.WriteLine(Path.GetFileName(file));
                Console.WriteLine("----------------------------------------");
                using (IRawDataPlus rawFile = RawFileReaderFactory.ReadFile(file))
                {
                    rawFile.SelectMsData();

                    var numberOfLogs = rawFile.GetStatusLogEntriesCount();
                    var logInfo      = rawFile.GetStatusLogHeaderInformation();

                    string logName = file + ".INST_LOG.txt";

                    Dictionary <int, ISingleValueStatusLog> log = new Dictionary <int, ISingleValueStatusLog>();

                    ProgressIndicator P = new ProgressIndicator(logInfo.Count(), "Preparing log data");
                    P.Start();
                    for (int i = 0; i < logInfo.Count(); i++)
                    {
                        log.Add(i, rawFile.GetStatusLogAtPosition(i));
                        P.Update();
                    }
                    P.Done();

                    using (StreamWriter f = new StreamWriter(logName))
                    {
                        P = new ProgressIndicator(numberOfLogs, $"Writing log");
                        P.Start();
                        f.Write("Time\t");
                        foreach (var x in logInfo)
                        {
                            f.Write(x.Label + "\t");
                        }
                        f.Write("\n");

                        for (int i = 0; i < numberOfLogs; i++)
                        {
                            f.Write($"{log[0].Times[i]}\t");

                            for (int j = 0; j < logInfo.Length; j++)
                            {
                                try
                                {
                                    f.Write("{0}\t", log[j].Values[i]);
                                }
                                catch (Exception)
                                {
                                    f.Write("\t");
                                }
                            }
                            f.Write("\n");
                            P.Update();
                        }
                        P.Done();
                    }
                }
                Console.WriteLine("\n");
            }
            return(0);
        }
Пример #3
0
     //Console.ReadKey();
 }

        public static void getentityData(string resFilePath, string rawFile, string headerInfo, string paraIndex)
        {
            IRawDataPlus plus = RawFileReaderAdapter.FileFactory(rawFile);
            plus.SelectInstrument(Device.MS, 1);

            ArrayList indexOfpara = new ArrayList();
            string[] selectIndex = paraIndex.Split(',');

            foreach (string ele in selectIndex)
            {
                int index = Int32.Parse(ele);
                indexOfpara.Add(index);
            }

            //string fileName = DateTime.Now.ToLocalTime().ToString().Replace("/", "").Replace(":", "").Replace(" ", "_") + ".csv";
            FileStream stream = new FileStream(resFilePath, FileMode.Create, FileAccess.Write);
            StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);

            headerInfo = "RT," + headerInfo;
            headerInfo = "#," + headerInfo;
            writer.WriteLine(headerInfo);

            int offset = 0;
            int maxoffset = plus.GetStatusLogEntriesCount();
            while (offset < maxoffset)
            {
                string temp = "";
                IStatusLogEntry statusLogEntry = plus.GetStatusLogEntry(offset);
                temp += offset.ToString() + ",";
                temp += statusLogEntry.Time.ToString() + ",";

                foreach (int ele in indexOfpara)
                {
                    temp += Convert.ToString(statusLogEntry.Values[ele]) + ",";
                }

                writer.WriteLine(temp.Substring(0, temp.Length - 1));
                offset += 1;
            }

            writer.Close();
        }

        public static void showheaderInfo(string filePath)
        {
            IRawDataPlus plus = RawFileReaderAdapter.FileFactory(filePath);
            plus.SelectInstrument(Device.MS, 1);
            HeaderItem[] statuslogheaderinformation = plus.GetStatusLogHeaderInformation();
            int index = 0;

            Console.OutputEncoding = Encoding.UTF8;

            while (index < statuslogheaderinformation.Length)
            {
                Console.WriteLine(statuslogheaderinformation[index].Label);
                //headerInfo[index] = statuslogheaderinformation[index].Label;
                //writer.WriteLine(statuslogheaderinformation[index].Label);
                index += 1;
            }
            //writer.Close();

            //while (true)
            //{
            //if (index >= statuslogheaderinformation.Length)
            //{
            //    Console.WriteLine(plus.RunHeaderEx.FirstSpectrum.ToString());
            //    Console.WriteLine(plus.RunHeaderEx.LastSpectrum.ToString());
            //    Console.WriteLine(plus.RunHeaderEx.StartTime.ToString("F2"));
            //    Console.WriteLine(plus.RunHeaderEx.EndTime.ToString("F2"));
            //    Console.WriteLine(plus.RunHeaderEx.LowMass.ToString());
            //    Console.WriteLine(plus.RunHeaderEx.HighMass.ToString());
            //    break;
            //}
            //    Console.WriteLine(statuslogheaderinformation[index].Label);
            //    writer.WriteLine(statuslogheaderinformation[index].Label);
            //    index++;
            //}

            //writer.Close();

        }
        public static void getTuneInfo(string filePath)
        {
            IRawDataPlus plus = RawFileReaderAdapter.FileFactory(filePath);
            plus.SelectInstrument(Device.MS, 1);
            string fileName = DateTime.Now.ToLocalTime().ToString().Replace("/", "").Replace(":", "").Replace(" ", "_") + ".txt";
            FileStream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
            StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);
            writer.WriteLine("*********************InstrumentMethod(0)***************************");
            writer.WriteLine(plus.GetInstrumentMethod(0));

            writer.WriteLine("*********************InstrumentMethod(1)****************************");
            writer.WriteLine(plus.GetInstrumentMethod(1));

            HeaderItem[] tuneDataHeaderInfo = plus.GetTuneDataHeaderInformation();

            writer.WriteLine("*********************Tune DATA ****************************");
            int tuneCnt = plus.GetTuneDataCount();

            for (int i = 0; i < tuneDataHeaderInfo.Length; ++i)
            {
                writer.WriteLine(tuneDataHeaderInfo[i].Label);
            }
            writer.Close();
        }

        public static void getMSdataFromScanNum(int startNum, int endNum, string filePath, double lowMS = 0.00, double highMS = 0.00)
        {
            IRawDataPlus plus = RawFileReaderAdapter.FileFactory(filePath);