Exemplo n.º 1
0
        public void QueueWork(Config config)
        {
            if (StatusUpdate != null) StatusUpdate("Waiting...", ProgressBarStyle.Continuous, _info);

            _canceled = false;

            lock (_workQueue)
                _workQueue.Enqueue(new KeyValuePair<MainLogic, Config>(this, config));
        }
Exemplo n.º 2
0
        void processFile(string filename, Config config, ReaderList readers)
        {
            // read in data file
            using (var msdList = new MSDataList())
            {
                string msg = String.Format("Opening file \"{0}\" for read...",filename);
                if (LogUpdate != null) LogUpdate(msg, _info);
                if (StatusUpdate != null) StatusUpdate(msg, ProgressBarStyle.Marquee, _info);
                readers.read(filename, msdList);

                foreach (var msd in msdList)
                {
                    var outputFilename = config.outputFilename(filename, msd);

                    if (filename == outputFilename)
                        throw new ArgumentException("Output filepath is the same as input filepath");

                    if (StatusUpdate != null) StatusUpdate("Waiting...", ProgressBarStyle.Marquee, _info);

                    // only one thread 
                    lock (calculateSHA1Mutex)
                    {
                        if (LogUpdate != null) LogUpdate("Calculating SHA1 checksum...", _info);
                        if (StatusUpdate != null) StatusUpdate("Calculating SHA1 checksum...", ProgressBarStyle.Marquee, _info);
                        MSDataFile.calculateSHA1Checksums(msd);
                    }

                    if (LogUpdate != null) LogUpdate("Processing...", _info);
                    if (StatusUpdate != null) StatusUpdate("Processing...", ProgressBarStyle.Marquee, _info);

                    SpectrumListFactory.wrap(msd, config.Filters);

                    if ((msd.run.spectrumList == null) || msd.run.spectrumList.empty())
                    {
                        if ((msd.run.chromatogramList != null) && !msd.run.chromatogramList.empty())
                        {
                            msg = "Note: input contains only chromatogram data.";
                            switch (config.WriteConfig.format)
                            {
                                case MSDataFile.Format.Format_MZ5:
                                case MSDataFile.Format.Format_mzML:
                                    break;
                                default:
                                    msg += "  The selected output format can only represent spectra.  Consider using mzML instead.";
                                    break;
                            }
                        }
                        else
                            msg = "Note: input contains no spectra or chromatogram data.";
                        if (LogUpdate != null) LogUpdate(msg, _info);
                        if (StatusUpdate != null) StatusUpdate(msg, ProgressBarStyle.Marquee, _info);
                    }

                    if (StatusUpdate != null && msd.run.spectrumList != null)
                        StatusUpdate(String.Format("Processing ({0} of {1})", 
                                                   DataGridViewProgressCell.MessageSpecialValue.CurrentValue,
                                                   DataGridViewProgressCell.MessageSpecialValue.Maximum),
                                     ProgressBarStyle.Continuous, _info);

                    // write out the new data file
                    var ilr = new IterationListenerRegistry();
                    ilr.addListener(this, 100);
                    msg = String.Format("Writing \"{0}\"...", outputFilename);
                    if (LogUpdate != null) LogUpdate(msg, _info);
                    if (StatusUpdate != null) StatusUpdate(msg, ProgressBarStyle.Marquee, _info);
                    MSDataFile.write(msd, outputFilename, config.WriteConfig, ilr);
                    ilr.removeListener(this);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Processes files, returns number of failed files
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        int Go(Config config)
        {
            var readers = ReaderList.FullReaderList;

            var failedFileCount = 0;
            foreach (var it in config.Filenames)
            {
                try
                {
                    processFile(it, config, readers);
                }
                catch (Exception e)
                {
                    _errorMessage = e.ToString();
                    failedFileCount++;
                    if (LogUpdate == null)
                        throw;
                }
            }

            return failedFileCount;
        }
Exemplo n.º 4
0
        public Config ParseCommandLine(string outputFolder, string argv)
        {

            var config = new Config(outputFolder);
            string filelistFilename = null;
            string configFilename = null;

            var formatText = false;
            var formatMzMl = false;
            var formatMzXml = false;
            var formatMz5 = false;
            var formatMgf = false;
            var formatMs1 = false;
            var formatCms1 = false;
            var formatMs2 = false;
            var formatCms2 = false;
            var precision32 = false;
            var precision64 = false;
            var noindex = false;
            var zlib = false;
            var gzip = false;

            var commandList = argv.Split('|');

            for (var x = 0; x < commandList.Length; x++)
            {
                switch (commandList[x])
                {
                    case "--filelist":
                    case "-f":
                        x++;
                        filelistFilename = commandList[x];
                        break;
                    case "--config":
                    case "-c":
                        x++;
                        configFilename = commandList[x];
                        break;
                    case "--ext":
                    case "-e":
                        x++;
                        config.Extension = commandList[x];
                        break;
                    case "--mzML":
                        formatMzMl = true;
                        break;
                    case "--mzXML":
                        formatMzXml = true;
                        break;
                    case "--mz5":
                        formatMz5 = true;
                        break;
                    case "--mgf":
                        formatMgf = true;
                        break;
                    case "--text":
                        formatText = true;
                        break;
                    case "--ms1":
                        formatMs1 = true;
                        break;
                    case "--cms1":
                        formatCms1 = true;
                        break;
                    case "--ms2":
                        formatMs2 = true;
                        break;
                    case "--cms2":
                        formatCms2 = true;
                        break;
                    case "--64":
                        precision64 = true;
                        break;
                    case "--32":
                        precision32 = true;
                        break;
                    case "--noindex":
                        noindex = true;
                        break;
                    case "--contactinfo":
                    case "-i":
                        x++;
                        config.ContactFilename = commandList[x];
                        break;
                    case "--zlib":
                    case "-z":
                        zlib = true;
                        break;
                    case "--gzip":
                    case "-g":
                        gzip = true;
                        break;
                    case "--filter":
                        x++;
                        config.Filters.Add(commandList[x]);
                        break;
                    case "--numpressPic":
                        config.WriteConfig.numpressPic = true;
                        break;
                    case "--numpressLinear":
                        config.WriteConfig.numpressLinear = true;
                        break;
                    case "--numpressSlof":
                        config.WriteConfig.numpressLinear = true;
                        break;
                    default:
                        config.Filenames.Add(commandList[x]);
                        break;
                }


            }

            #region Parse config file if required

            if (!string.IsNullOrEmpty(configFilename))
            {
                var fileIn = new StreamReader(configFilename);
                var entirefile = fileIn.ReadToEnd().Replace('=', ' ').Replace(Environment.NewLine, " ");
                fileIn.Close();

                commandList = entirefile.Split();

                for (var x = 0; x < commandList.Length; x++)
                {
                    switch (commandList[x])
                    {
                        case "--filelist":
                        case "-f":
                            x++;
                            filelistFilename = commandList[x];
                            break;
                        case "--outdir":
                        case "-o":
                            x++;
                            config.OutputPath = commandList[x];
                            break;
                        case "--ext":
                        case "-e":
                            x++;
                            config.Extension = commandList[x];
                            break;
                        case "--mzML":
                            formatMzMl = true;
                            break;
                        case "--mzXML":
                            formatMzXml = true;
                            break;
                        case "--mgf":
                            formatMgf = true;
                            break;
                        case "--text":
                            formatText = true;
                            break;
                        case "--ms1":
                            formatMs1 = true;
                            break;
                        case "--cms1":
                            formatCms1 = true;
                            break;
                        case "--ms2":
                            formatMs2 = true;
                            break;
                        case "--cms2":
                            formatCms2 = true;
                            break;
                        case "--64":
                            precision64 = true;
                            break;
                        case "--32":
                            precision32 = true;
                            break;
                        case "--noindex":
                            noindex = true;
                            break;
                        case "--contactinfo":
                        case "-i":
                            x++;
                            config.ContactFilename = commandList[x];
                            break;
                        case "--zlib":
                        case "-z":
                            zlib = true;
                            break;
                        case "--gzip":
                        case "-g":
                            gzip = true;
                            break;
                        case "--filter":
                            x++;
                            config.Filters.Add(commandList[x]);
                            break;
                    }


                }
            }
            #endregion


            // parse filelist if required

            if (!string.IsNullOrEmpty(filelistFilename))
            {
                var fileIn = new StreamReader(filelistFilename);
                while (!fileIn.EndOfStream)
                {
                    var filename = fileIn.ReadLine();
                    if (!string.IsNullOrEmpty(filename))
                        config.Filenames.Add(filename);
                }
                fileIn.Close();
            }

            // check stuff

            if (config.Filenames.Count == 0)
                throw new Exception("[msconvert] No files specified.");

            var count = (formatText ? 1 : 0) 
                + (formatMzMl ? 1 : 0)
                + (formatMzXml ? 1 : 0)
                + (formatMz5 ? 1 : 0)
                + (formatMgf ? 1 : 0)
                + (formatMs1 ? 1 : 0)
                + (formatCms1 ? 1 : 0)
                + (formatMs2 ? 1 : 0)
                + (formatCms2 ? 1 : 0);
            if (count > 1) throw new Exception("[msconvert] Multiple format flags specified.");
            if (formatText) config.WriteConfig.format = MSDataFile.Format.Format_Text;
            if (formatMzMl) config.WriteConfig.format = MSDataFile.Format.Format_mzML;
            if (formatMzXml) config.WriteConfig.format = MSDataFile.Format.Format_mzXML;
            if (formatMz5) config.WriteConfig.format = MSDataFile.Format.Format_MZ5;
            if (formatMgf) config.WriteConfig.format = MSDataFile.Format.Format_MGF;
            if (formatMs1) config.WriteConfig.format = MSDataFile.Format.Format_MS1;
            if (formatCms1) config.WriteConfig.format = MSDataFile.Format.Format_CMS1;
            if (formatMs2) config.WriteConfig.format = MSDataFile.Format.Format_MS2;
            if (formatCms2) config.WriteConfig.format = MSDataFile.Format.Format_CMS2;

            config.WriteConfig.gzipped = gzip; // if true, file is written as .gz

            if (String.IsNullOrEmpty(config.Extension))
            {
                switch (config.WriteConfig.format)
                {
                    case MSDataFile.Format.Format_Text:
                        config.Extension = ".txt";
                        break;
                    case MSDataFile.Format.Format_mzML:
                        config.Extension = ".mzML";
                        break;
                    case MSDataFile.Format.Format_mzXML:
                        config.Extension = ".mzXML";
                        break;
                    case MSDataFile.Format.Format_MZ5:
                        config.Extension = ".mz5";
                        break;
                    case MSDataFile.Format.Format_MGF:
                        config.Extension = ".mgf";
                        break;
                    case MSDataFile.Format.Format_MS1:
                        config.Extension = ".ms1";
                        break;
                    case MSDataFile.Format.Format_CMS1:
                        config.Extension = ".cms1";
                        break;
                    case MSDataFile.Format.Format_MS2:
                        config.Extension = ".ms2";
                        break;
                    case MSDataFile.Format.Format_CMS2:
                        config.Extension = ".cms2";
                        break;
                    default:
                        throw new Exception("[msconvert] Unsupported format.");
                }
                if (config.WriteConfig.gzipped)
                {
                    config.Extension += ".gz";
                }
            }

            // precision defaults

            config.WriteConfig.precision = MSDataFile.Precision.Precision_64;

            // handle precision flags

            if (precision32 && precision64)
                throw new Exception("[msconvert] Incompatible precision flags.");

            if (precision32)
            {
                config.WriteConfig.precision = MSDataFile.Precision.Precision_32;
            }
            else if (precision64)
            {
                config.WriteConfig.precision = MSDataFile.Precision.Precision_64;
            }

            // other flags

            if (noindex)
                config.WriteConfig.indexed = false;

            if (zlib)
                config.WriteConfig.compression = MSDataFile.Compression.Compression_Zlib;

            return config;
        }