Beispiel #1
0
 private DbSpectrum(DbResultsFile resultsFile, double precursorMz, double?matchedPrecursorMz, double retentionTime, byte[] mzBytes, byte[] intensityBytes)
 {
     PrecursorMz        = precursorMz;
     MatchedPrecursorMz = matchedPrecursorMz;
     ResultsFile        = resultsFile;
     RetentionTime      = retentionTime;
     MzBytes            = mzBytes;
     IntensityBytes     = intensityBytes;
 }
Beispiel #2
0
 private DbSpectrum(DbResultsFile resultsFile, double precursorMz, double?matchedPrecursorMz, string documentPeptide, int?documentPrecursorCharge, double retentionTime, byte[] mzBytes, byte[] intensityBytes)
 {
     PrecursorMz             = precursorMz;
     MatchedPrecursorMz      = matchedPrecursorMz;
     DocumentPeptide         = documentPeptide;
     DocumentPrecursorCharge = documentPrecursorCharge;
     ResultsFile             = resultsFile;
     RetentionTime           = retentionTime;
     MzBytes        = mzBytes;
     IntensityBytes = intensityBytes;
 }
Beispiel #3
0
 public DbResultsFile(DbResultsFile other)
     : this(other.FilePath)
 {
     Id = other.Id;
 }
Beispiel #4
0
        public static void AddSpectra(MidasLibSpec libSpec, MsDataFilePath[] resultsFiles, SrmDocument doc, ILoadMonitor monitor, out List <MsDataFilePath> failedFiles)
        {
            // Get spectra from results files
            var       newSpectra          = new List <DbSpectrum>();
            var       progress            = new ProgressStatus(string.Empty).ChangeMessage(Resources.MidasLibrary_AddSpectra_Reading_MIDAS_spectra);
            const int percentResultsFiles = 80;

            failedFiles = new List <MsDataFilePath>();
            for (var i = 0; i < resultsFiles.Length; i++)
            {
                var resultsFile = resultsFiles[i];
                try
                {
                    monitor.UpdateProgress(progress.ChangePercentComplete(i * percentResultsFiles / resultsFiles.Length));

                    var filePath = resultsFile.GetFilePath();
                    if (File.Exists(filePath))
                    {
                        var sampleIndex = resultsFile.GetSampleIndex();
                        using (var msd = new MsDataFileImpl(filePath, sampleIndex == -1 ? 0 : sampleIndex, resultsFile.GetLockMassParameters(), requireVendorCentroidedMS2: true))
                        {
                            if (ChromatogramDataProvider.HasChromatogramData(msd) && SpectraChromDataProvider.HasSpectrumData(msd))
                            {
                                var chromPrecursors = ReadChromPrecursorsFromMsd(msd, monitor).ToList();
                                newSpectra.AddRange(ReadDbSpectraFromMsd(msd, monitor));
                                MatchSpectraToChrom(newSpectra, chromPrecursors, monitor);
                            }
                        }

                        MatchSpectraToPeptides(newSpectra, doc, monitor);
                    }
                    else
                    {
                        failedFiles.Add(resultsFile);
                    }
                }
                catch (Exception x)
                {
                    monitor.UpdateProgress(progress.ChangeErrorException(x));
                    failedFiles.Add(resultsFile);
                }
                if (monitor.IsCanceled)
                {
                    monitor.UpdateProgress(progress.Cancel());
                    return;
                }
            }

            if (!newSpectra.Any())
            {
                monitor.UpdateProgress(progress.Complete());
                return;
            }

            progress = progress.ChangePercentComplete(percentResultsFiles);
            monitor.UpdateProgress(progress);

            // Add spectra to library
            var midasLib = !File.Exists(libSpec.FilePath) ? Create(libSpec) : Load(libSpec, monitor);

            if (midasLib == null)
            {
                monitor.UpdateProgress(progress.ChangeErrorException(new Exception(Resources.MidasLibrary_AddSpectra_Error_loading_MIDAS_library_for_adding_spectra_)));
                return;
            }

            progress = progress.ChangeMessage(Resources.MidasLibrary_AddSpectra_Adding_spectra_to_MIDAS_library);
            monitor.UpdateProgress(progress);

            var results = new Dictionary <string, DbResultsFile>();

            if (midasLib._spectra != null)
            {
                foreach (var kvp in midasLib._spectra)
                {
                    results[kvp.Key.FilePath] = kvp.Key;
                }
            }

            using (var sessionFactory = SessionFactoryFactory.CreateSessionFactory(libSpec.FilePath, typeof(MidasLibrary), false))
                using (var session = new SessionWithLock(sessionFactory.OpenSession(), new ReaderWriterLock(), true))
                    using (var transaction = session.BeginTransaction())
                    {
                        for (var i = 0; i < newSpectra.Count; i++)
                        {
                            if (monitor.IsCanceled)
                            {
                                transaction.Rollback();
                                monitor.UpdateProgress(progress.Cancel());
                                return;
                            }
                            var spectrum = newSpectra[i];

                            monitor.UpdateProgress(progress.ChangePercentComplete(percentResultsFiles + (int)(100.0 * i / newSpectra.Count)));

                            DbResultsFile resultsFile;
                            if (!results.TryGetValue(spectrum.ResultsFile.FilePath, out resultsFile))
                            {
                                resultsFile = new DbResultsFile(spectrum.ResultsFile)
                                {
                                    Id = null
                                };
                                results[spectrum.ResultsFile.FilePath] = resultsFile;
                                session.SaveOrUpdate(resultsFile);
                            }
                            else if (midasLib._spectra != null)
                            {
                                List <DbSpectrum> existingSpectra;
                                if (midasLib._spectra.TryGetValue(resultsFile, out existingSpectra) &&
                                    existingSpectra.Any(x => Equals(x.ResultsFile.FilePath, spectrum.ResultsFile.FilePath) &&
                                                        Equals(x.PrecursorMz, spectrum.PrecursorMz) &&
                                                        Equals(x.RetentionTime, spectrum.RetentionTime)))
                                {
                                    // This spectrum already exists in the library
                                    continue;
                                }
                            }
                            var spectrumNewDisconnected = new DbSpectrum(spectrum)
                            {
                                Id = null, ResultsFile = resultsFile
                            };
                            session.SaveOrUpdate(spectrumNewDisconnected);
                        }
                        transaction.Commit();
                        monitor.UpdateProgress(progress.Complete());
                    }
        }
Beispiel #5
0
 public DbSpectrum(DbResultsFile resultsFile, double precursorMz, double?matchedPrecursorMz, string documentPeptide, int?documentPrecursorCharge, double retentionTime, double[] mzs, double[] intensities)
     : this(resultsFile, precursorMz, matchedPrecursorMz, documentPeptide, documentPrecursorCharge, retentionTime, CompressBytes(mzs), CompressBytes(intensities))
 {
 }
Beispiel #6
0
 public DbSpectrum(DbResultsFile resultsFile, double precursorMz, double?matchedPrecursorMz, double retentionTime, double[] mzs, double[] intensities)
     : this(resultsFile, precursorMz, matchedPrecursorMz, retentionTime, CompressBytes(mzs), CompressBytes(intensities))
 {
 }