Beispiel #1
0
        public SpectrumSource(string filepath)
        {
            MSDataList msdList      = new MSDataList();
            var        readerConfig = new ReaderConfig
            {
                simAsSpectra = Program.SimAsSpectra,
                srmAsSpectra = Program.SrmAsSpectra
            };

            ReaderList.FullReaderList.read(filepath, msdList, readerConfig);
            msDataFile = msdList[0];
            //msDataFile = new MSDataFile(filepath);
            sourceFilepath = filepath;

            // create dummy spectrum/chromatogram list to simplify logic
            msDataFile.run.spectrumList     = msDataFile.run.spectrumList ?? new SpectrumListSimple();
            msDataFile.run.chromatogramList = msDataFile.run.chromatogramList ?? new ChromatogramListSimple();

            setInputFileWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);

            /*setInputFileDelegate = new ParameterizedThreadStart( startSetInputFile );
             * Thread setInputFileThread = new Thread( setInputFileDelegate );
             *
             * setInputFileThread.Start( (object) filepath );*/
        }
Beispiel #2
0
        public SpectrumSource(string filepath)
        {
            MSDataList msdList = new MSDataList();

            if (!File.Exists(filepath) && !Directory.Exists(filepath)) // Some mass spec "files" are really directory structures
            {
                throw new FileNotFoundException("Filepath not found: " + filepath, filepath);
            }

            ReaderList.FullReaderList.read(filepath, msdList, GetReaderConfig());
            msDataFile = msdList[0];
            //msDataFile = new MSDataFile(filepath);
            sourceFilepath = filepath;

            // create dummy spectrum/chromatogram list to simplify logic
            msDataFile.run.spectrumList     = msDataFile.run.spectrumList ?? new SpectrumListSimple();
            msDataFile.run.chromatogramList = msDataFile.run.chromatogramList ?? new ChromatogramListSimple();

            setInputFileWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);

            /*setInputFileDelegate = new ParameterizedThreadStart( startSetInputFile );
             * Thread setInputFileThread = new Thread( setInputFileDelegate );
             *
             * setInputFileThread.Start( (object) filepath );*/
        }
        private SourceInfo[] getSourceInfo(FileInfo fileInfo, bool getDetails)
        {
            var sourceInfoList = new List <SourceInfo>();

            sourceInfoList.Add(new SourceInfo());
            sourceInfoList[0].type         = getSourceType(fileInfo);
            sourceInfoList[0].name         = fileInfo.Name;
            sourceInfoList[0].hasDetails   = getDetails;
            sourceInfoList[0].size         = (UInt64)fileInfo.Length;
            sourceInfoList[0].dateModified = fileInfo.LastWriteTime;
            if (sourceInfoList[0].type != String.Empty)
            {
                if (!getDetails)
                {
                    return(sourceInfoList.ToArray());
                }

                try
                {
                    ReaderList readerList   = ReaderList.FullReaderList;
                    var        readerConfig = new ReaderConfig
                    {
                        simAsSpectra = Properties.Settings.Default.SimAsSpectra,
                        srmAsSpectra = Properties.Settings.Default.SrmAsSpectra,
                        combineIonMobilitySpectra = Properties.Settings.Default.CombineIonMobilitySpectra,
                        ignoreZeroIntensityPoints = Properties.Settings.Default.IgnoreZeroIntensityPoints,
                        acceptZeroLengthSpectra   = Properties.Settings.Default.AcceptZeroLengthSpectra,
                        allowMsMsWithoutPrecursor = false
                    };

                    MSDataList msInfo = new MSDataList();
                    readerList.read(fileInfo.FullName, msInfo, readerConfig);

                    foreach (MSData msData in msInfo)
                    {
                        SourceInfo sourceInfo = new SourceInfo();
                        sourceInfo.type = sourceInfoList[0].type;
                        sourceInfo.name = sourceInfoList[0].name;
                        if (msInfo.Count > 1)
                        {
                            sourceInfo.name += " (" + msData.run.id + ")";
                        }
                        sourceInfo.populateFromMSData(msData);
                        sourceInfoList.Add(sourceInfo);
                    }
                } catch
                {
                    sourceInfoList[0].spectra = 0;
                    sourceInfoList[0].type    = "Invalid " + sourceInfoList[0].type;
                }

                foreach (SourceInfo sourceInfo in sourceInfoList)
                {
                    sourceInfo.size         = (UInt64)fileInfo.Length;
                    sourceInfo.dateModified = fileInfo.LastWriteTime;
                }
                return(sourceInfoList.ToArray());
            }
            return(null);
        }
Beispiel #4
0
        public SpectrumSource(string filepath)
        {
            MSDataList msdList = new MSDataList();

            ReaderList.FullReaderList.read(filepath, msdList);
            msDataFile = msdList[0];
            //msDataFile = new MSDataFile(filepath);
            sourceFilepath = filepath;
        }
Beispiel #5
0
        private SourceInfo[] getSourceInfo(FileInfo fileInfo, bool getDetails)
        {
            var sourceInfoList = new List <SourceInfo>();

            sourceInfoList.Add(new SourceInfo());
            sourceInfoList[0].type         = getSourceType(fileInfo);
            sourceInfoList[0].name         = fileInfo.Name;
            sourceInfoList[0].hasDetails   = getDetails;
            sourceInfoList[0].size         = (UInt64)fileInfo.Length;
            sourceInfoList[0].dateModified = fileInfo.LastWriteTime;
            if (sourceInfoList[0].type != String.Empty)
            {
                if (!getDetails)
                {
                    return(sourceInfoList.ToArray());
                }

                try
                {
                    ReaderList readerList   = ReaderList.FullReaderList;
                    var        readerConfig = new ReaderConfig
                    {
                        simAsSpectra = Program.SimAsSpectra,
                        srmAsSpectra = Program.SrmAsSpectra
                    };

                    MSDataList msInfo = new MSDataList();
                    readerList.read(fileInfo.FullName, msInfo, readerConfig);

                    foreach (MSData msData in msInfo)
                    {
                        SourceInfo sourceInfo = new SourceInfo();
                        sourceInfo.type = sourceInfoList[0].type;
                        sourceInfo.name = sourceInfoList[0].name;
                        if (msInfo.Count > 1)
                        {
                            sourceInfo.name += " (" + msData.run.id + ")";
                        }
                        sourceInfo.populateFromMSData(msData);
                        sourceInfoList.Add(sourceInfo);
                    }
                } catch
                {
                    sourceInfoList[0].spectra = 0;
                    sourceInfoList[0].type    = "Invalid " + sourceInfoList[0].type;
                }

                foreach (SourceInfo sourceInfo in sourceInfoList)
                {
                    sourceInfo.size         = (UInt64)fileInfo.Length;
                    sourceInfo.dateModified = fileInfo.LastWriteTime;
                }
                return(sourceInfoList.ToArray());
            }
            return(null);
        }
Beispiel #6
0
        public SpectrumSource(string filepath)
        {
            MSDataList msdList = new MSDataList();

            ReaderList.FullReaderList.read(filepath, msdList);
            msDataFile = msdList[0];
            //msDataFile = new MSDataFile(filepath);
            sourceFilepath = filepath;

            setInputFileWaitHandle = new EventWaitHandle(false, EventResetMode.ManualReset);

            /*setInputFileDelegate = new ParameterizedThreadStart( startSetInputFile );
             * Thread setInputFileThread = new Thread( setInputFileDelegate );
             *
             * setInputFileThread.Start( (object) filepath );*/
        }
Beispiel #7
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.Continuous, _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.Continuous, _info);
                    }
                    MSDataFile.write(msd, outputFilename, config.WriteConfig, ilr);
                    ilr.removeListener(this);
                }
            }
        }
Beispiel #8
0
        void processFile(string filename, Config config, ReaderList readers, Map <string, int> usedOutputFilenames)
        {
            // read in data file
            using (var msdList = new MSDataList())
            {
                string msg = String.Format("Opening file \"{0}\" for read...", filename);
                var    stripCredentialsMatch = Regex.Match(filename, "https?://([^:]+:[^@]+@).*", RegexOptions.CultureInvariant | RegexOptions.IgnoreCase);
                if (stripCredentialsMatch.Success)
                {
                    msg = msg.Replace(stripCredentialsMatch.Groups[1].Value, "");
                }

                LogUpdate?.Invoke(msg, _info);
                StatusUpdate?.Invoke(msg, ProgressBarStyle.Marquee, _info);
                readers.read(filename, msdList, config.ReaderConfig);

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

                        StatusUpdate?.Invoke("Waiting...", ProgressBarStyle.Marquee, _info);

                        // only one thread
                        lock (_calculateSHA1Mutex)
                        {
                            // if output name is same as input name, add a suffix
                            if (filename == outputFilename)
                            {
                                ++usedOutputFilenames[outputFilename];
                            }

                            if (usedOutputFilenames.Contains(deduplicatedFilename))
                            {
                                deduplicatedFilename = deduplicatedFilename.Replace(Path.GetExtension(outputFilename), String.Format(" ({0}).{1}", usedOutputFilenames[outputFilename] + 1, Path.GetExtension(outputFilename)));
                            }
                            ++usedOutputFilenames[outputFilename];

                            LogUpdate?.Invoke("Calculating SHA1 checksum...", _info);
                            StatusUpdate?.Invoke("Calculating SHA1 checksum...", ProgressBarStyle.Marquee, _info);
                            MSDataFile.calculateSHA1Checksums(msd);
                        }

                        var ilr = new IterationListenerRegistry();
                        ilr.addListenerWithTimer(this, 1);

                        LogUpdate?.Invoke("Processing...", _info);
                        StatusUpdate?.Invoke("Processing...", ProgressBarStyle.Marquee, _info);

                        SpectrumListFactory.wrap(msd, config.Filters, ilr);

                        config.WriteConfig.useWorkerThreads = msd.run.spectrumList.benefitsFromWorkerThreads();

                        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.";
                            }
                            LogUpdate?.Invoke(msg, _info);
                            StatusUpdate?.Invoke(msg, ProgressBarStyle.Continuous, _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
                        msg = String.Format("Writing \"{0}\"...", deduplicatedFilename);
                        LogUpdate?.Invoke(msg, _info);
                        StatusUpdate?.Invoke(msg, ProgressBarStyle.Continuous, _info);
                        MSDataFile.write(msd, deduplicatedFilename, config.WriteConfig, ilr);
                        ilr.removeListener(this);
                    }
                    finally
                    {
                        msd.Dispose();
                    }
                }
            }
        }
        public void Open(string fileName, int sampleIndex)
        {
            if (_currentSampleIndex != sampleIndex || _currentFileName != fileName)
            {
                MSDataList msdList = new MSDataList();
                ReaderList.FullReaderList.read(fileName, msdList);
                _dataFile = msdList[0];
                _run = _dataFile.run;

                _currentFileName = fileName;
                _currentSampleIndex = sampleIndex;

                spectrumCache = new SpectrumCache();
                ticGenerator = new TicGenerator(_run, spectrumCache);
                xicGenerator = new XicGenerator(_run, spectrumCache);
                spectrumExtractor = new SpectrumExtractor(_run, spectrumCache);
                averagedSpectrumExtractor = new AveragedSpectrumExtractor(_run, spectrumCache);
            }
        }
Beispiel #10
0
		public SpectrumSource( string filepath )
		{
            MSDataList msdList = new MSDataList();
            var readerConfig = new ReaderConfig
            {
                simAsSpectra = Program.SimAsSpectra,
                srmAsSpectra = Program.SrmAsSpectra
            };
            ReaderList.FullReaderList.read(filepath, msdList, readerConfig);
            msDataFile = msdList[0];
			//msDataFile = new MSDataFile(filepath);
			sourceFilepath = filepath;

            // create dummy spectrum/chromatogram list to simplify logic
            msDataFile.run.spectrumList = msDataFile.run.spectrumList ?? new SpectrumListSimple();
            msDataFile.run.chromatogramList = msDataFile.run.chromatogramList ?? new ChromatogramListSimple();

			setInputFileWaitHandle = new EventWaitHandle( false, EventResetMode.ManualReset );
			/*setInputFileDelegate = new ParameterizedThreadStart( startSetInputFile );
			Thread setInputFileThread = new Thread( setInputFileDelegate );

			setInputFileThread.Start( (object) filepath );*/
		}
        private SourceInfo[] getSourceInfo( FileInfo fileInfo, bool getDetails )
        {
            var sourceInfoList = new List<SourceInfo>();
            sourceInfoList.Add( new SourceInfo() );
            sourceInfoList[0].type = getSourceType( fileInfo );
            sourceInfoList[0].name = fileInfo.Name;
            sourceInfoList[0].hasDetails = getDetails;
            sourceInfoList[0].size = (UInt64) fileInfo.Length;
            sourceInfoList[0].dateModified = fileInfo.LastWriteTime;
            if( sourceInfoList[0].type != String.Empty )
            {
                if( !getDetails )
                    return sourceInfoList.ToArray();

                try
                {
                    ReaderList readerList = ReaderList.FullReaderList;
                    var readerConfig = new ReaderConfig
                        {
                            simAsSpectra = Program.SimAsSpectra,
                            srmAsSpectra = Program.SrmAsSpectra
                        };

                    MSDataList msInfo = new MSDataList();
                    readerList.read( fileInfo.FullName, msInfo, readerConfig );

                    foreach( MSData msData in msInfo )
                    {
                        SourceInfo sourceInfo = new SourceInfo();
                        sourceInfo.type = sourceInfoList[0].type;
                        sourceInfo.name = sourceInfoList[0].name;
                        if( msInfo.Count > 1 )
                            sourceInfo.name += " (" + msData.run.id + ")";
                        sourceInfo.populateFromMSData( msData );
                        sourceInfoList.Add( sourceInfo );
                    }
                } catch
                {
                    sourceInfoList[0].spectra = 0;
                    sourceInfoList[0].type = "Invalid " + sourceInfoList[0].type;
                }

                foreach( SourceInfo sourceInfo in sourceInfoList )
                {
                    sourceInfo.size = (UInt64) fileInfo.Length;
                    sourceInfo.dateModified = fileInfo.LastWriteTime;
                }
                return sourceInfoList.ToArray();
            }
            return null;
        }
Beispiel #12
0
        void processFile(string filename, Config config, ReaderList readers)
        {
            if (LogUpdate != null)
            {
                LogUpdate("Opening file...", _info);
            }
            if (StatusUpdate != null)
            {
                StatusUpdate("Opening file...", ProgressBarStyle.Marquee, _info);
            }

            // read in data file
            using (var msdList = new MSDataList())
            {
                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 (LogUpdate != null)
                    {
                        LogUpdate("Calculating SHA1 checksum...", _info);
                    }
                    if (StatusUpdate != null)
                    {
                        StatusUpdate("Calculating SHA1 checksum...", ProgressBarStyle.Marquee, _info);
                    }

                    // only one thread
                    lock (calculateSHA1Mutex)
                        MSDataFile.calculateSHA1Checksums(msd);

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

                    SpectrumListFactory.wrap(msd, config.Filters);
                    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
                    IterationListenerRegistry ilr = null;
                    ilr = new IterationListenerRegistry();
                    ilr.addListener(this, 100);
                    MSDataFile.write(msd, outputFilename, config.WriteConfig, ilr);
                }
            }
        }
Beispiel #13
0
        public SpectrumSource( string filepath )
        {
            MSDataList msdList = new MSDataList();
            ReaderList.FullReaderList.read( filepath, msdList );
            msDataFile = msdList[0];
            //msDataFile = new MSDataFile(filepath);
            sourceFilepath = filepath;

            setInputFileWaitHandle = new EventWaitHandle( false, EventResetMode.ManualReset );
            /*setInputFileDelegate = new ParameterizedThreadStart( startSetInputFile );
            Thread setInputFileThread = new Thread( setInputFileDelegate );

            setInputFileThread.Start( (object) filepath );*/
        }
Beispiel #14
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);
                }
            }
        }