Ejemplo n.º 1
0
 public RemoteChromDataProvider(SrmDocument document, IRetentionTimePredictor retentionTimePredictor, ChromFileInfo chromFileInfo, ProgressStatus progressStatus, int startPercent,
     int endPercent, ILoadMonitor loader)
     : base(chromFileInfo, progressStatus, startPercent, endPercent, loader)
 {
     _document = document;
     ChorusUrl chorusUrl = (ChorusUrl)chromFileInfo.FilePath;
     _chorusAccount = chorusUrl.FindChorusAccount(Settings.Default.ChorusAccountList);
     var chromatogramRequestProviders = new List<ChromatogramRequestProvider>();
     foreach (bool firstPass in new[] {true, false})
     {
         if (null == retentionTimePredictor && !firstPass)
         {
             continue;
         }
         var chromatogramRequestProvider = new ChromatogramRequestProvider(document, chorusUrl,
             retentionTimePredictor, firstPass);
         if (0 == chromatogramRequestProvider.ChromKeys.Count)
         {
             continue;
         }
         chromatogramRequestProviders.Add(chromatogramRequestProvider);
     }
     _chromatogramRequestProviders = chromatogramRequestProviders.ToArray();
     _chromTaskLists = new ChromTaskList[_chromatogramRequestProviders.Length];
 }
Ejemplo n.º 2
0
 private Stream CreateStream(ILoadMonitor loader)
 {
     if (_readStream == null)
     {
         _readStream = loader.StreamManager.CreatePooledStream(FilePath, false);
     }
     return(ReadStream.Stream);
 }
Ejemplo n.º 3
0
        public ChromCacheJoiner(string cachePath, IPooledStream streamDest,
                                IList <string> cacheFilePaths, ILoadMonitor loader, ProgressStatus status,
                                Action <ChromatogramCache, IProgressStatus> completed)
            : base(cachePath, loader, status, completed)
        {
            _destinationStream = streamDest;

            CacheFilePaths = cacheFilePaths;
        }
Ejemplo n.º 4
0
        public ChromCacheJoiner(string cachePath, IPooledStream streamDest,
            IList<string> cacheFilePaths, ILoadMonitor loader, ProgressStatus status,
            Action<ChromatogramCache, Exception> completed)
            : base(cachePath, loader, status, completed)
        {
            _destinationStream = streamDest;

            CacheFilePaths = cacheFilePaths;
        }
Ejemplo n.º 5
0
        public Digestion Digest(Enzyme enzyme, DigestSettings digestSettings, ILoadMonitor loader)
        {
            IProgressStatus progressStatus = new ProgressStatus(string.Format(Resources.BackgroundProteomeSpec_Digest_Digesting__0__, enzyme.Name));

            loader.UpdateProgress(progressStatus);
            using (var proteomeDb = OpenProteomeDb())
            {
                return(proteomeDb.Digest(new ProteaseImpl(enzyme), digestSettings.MaxMissedCleavages, loader, ref progressStatus));
            }
        }
Ejemplo n.º 6
0
        public static XHunterLibrary Load(XHunterLibSpec spec, ILoadMonitor loader)
        {
            var library = new XHunterLibrary(spec);

            if (library.Load(loader))
            {
                return(library);
            }
            return(null);
        }
Ejemplo n.º 7
0
        public ChromCacheJoiner(string cachePath, IPooledStream streamDest,
                                IList <string> cacheFilePaths, ILoadMonitor loader, ProgressStatus status,
                                Action <ChromatogramCache, IProgressStatus> completed,
                                bool assumeNegativeChargeInPreV11Caches)
            : base(cachePath, loader, status, completed)
        {
            _destinationStream = streamDest;

            CacheFilePaths = cacheFilePaths;
            _assumeNegativeChargeInPreV11Caches = assumeNegativeChargeInPreV11Caches; // Deal with older cache formats where we did not record polarity
        }
Ejemplo n.º 8
0
 protected ChromCacheWriter(string cachePath, ILoadMonitor loader, ProgressStatus status,
     Action<ChromatogramCache, Exception> completed)
 {
     CachePath = cachePath;
     _fs = new FileSaver(CachePath);
     _fsScans = new FileSaver(CachePath + ChromatogramCache.SCANS_EXT, true);
     _fsPeaks = new FileSaver(CachePath + ChromatogramCache.PEAKS_EXT, true);
     _fsScores = new FileSaver(CachePath + ChromatogramCache.SCORES_EXT, true);
     _loader = loader;
     _status = status;
     _completed = completed;
 }
Ejemplo n.º 9
0
 protected ChromCacheWriter(string cachePath, ILoadMonitor loader, IProgressStatus status,
                            Action <ChromatogramCache, IProgressStatus> completed)
 {
     CachePath  = cachePath;
     _fs        = new FileSaver(CachePath);
     _fsScans   = new FileSaver(CachePath + ChromatogramCache.SCANS_EXT, true);
     _fsPeaks   = new FileSaver(CachePath + ChromatogramCache.PEAKS_EXT, true);
     _fsScores  = new FileSaver(CachePath + ChromatogramCache.SCORES_EXT, true);
     _loader    = loader;
     _status    = status;
     _completed = completed;
 }
Ejemplo n.º 10
0
 public static EncyclopeDiaLibrary Load(EncyclopeDiaSpec spec, ILoadMonitor loader)
 {
     if (File.Exists(spec.FilePath) && new FileInfo(spec.FilePath).Length > 0)
     {
         var library = new EncyclopeDiaLibrary(spec, loader.StreamManager);
         if (library.Load(loader))
         {
             return(library);
         }
     }
     return(null);
 }
Ejemplo n.º 11
0
 private bool Load(ILoadMonitor loader)
 {
     if (LoadFromCache(loader))
     {
         return(true);
     }
     if (LoadLibraryFromDatabase(loader))
     {
         WriteCache(loader);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 12
0
        public static BiblioSpecLibrary Load(BiblioSpecLibSpec spec, ILoadMonitor loader)
        {
            var library = new BiblioSpecLibrary(spec)
            {
                FilePath = spec.FilePath
            };

            if (library.Load(loader))
            {
                return(library);
            }
            return(null);
        }
Ejemplo n.º 13
0
        public Digestion Digest(Enzyme enzyme, DigestSettings digestSettings, ILoadMonitor loader)
        {
            ProgressStatus progressStatus = new ProgressStatus(string.Format(Resources.BackgroundProteomeSpec_Digest_Digesting__0__, enzyme.Name));

            using (var proteomeDb = OpenProteomeDb())
            {
                return(proteomeDb.Digest(new ProteaseImpl(enzyme),
                                         (s, i) =>
                {
                    loader.UpdateProgress(progressStatus.ChangePercentComplete(i));
                    return !loader.IsCanceled;
                }));
            }
        }
Ejemplo n.º 14
0
        private static Library CreateLibraryFile(MemoryStreamManager streamManager, ILoadMonitor loader,
                                                 string nistText, Action <IStreamManager, Library> write)
        {
            streamManager.TextFiles[PATH_NIST_LIB] = nistText;

            var librarySpec = new NistLibSpec("Temporary (NIST)", PATH_NIST_LIB);

            Library libNist = librarySpec.LoadLibrary(loader);

            Assert.IsNotNull(libNist);
            write(streamManager, libNist);

            streamManager.TextFiles.Remove(PATH_NIST_LIB);
            streamManager.Delete(PATH_NIST_LIB_CACHE);

            return(libNist);
        }
 public ChorusResponseChromDataProvider(SrmDocument document, ChromFileInfo chromFileInfo, ProgressStatus progressStatus, int startPercent,
     int endPercent, ILoadMonitor loader)
     : base(chromFileInfo, progressStatus, startPercent, endPercent, loader)
 {
     ChromatogramCache.RawData rawData;
     MsDataFilePath msDataFilePath = (MsDataFilePath) chromFileInfo.FilePath;
     IPooledStream stream = loader.StreamManager.CreatePooledStream(msDataFilePath.FilePath, false);
     ChromatogramCache.LoadStructs(stream.Stream, out rawData);
     var chromCacheFile = rawData.ChromCacheFiles[0];
     rawData.ChromCacheFiles = new[]
     {
         new ChromCachedFile(chromFileInfo.FilePath, chromCacheFile.Flags, chromCacheFile.FileWriteTime,
             chromCacheFile.RunStartTime, chromCacheFile.MaxRetentionTime, chromCacheFile.MaxIntensity,
             chromCacheFile.InstrumentInfoList),
     };
     var cache = new ChromatogramCache("cachePath", rawData, stream); // Not L10N
     _cachedChromatogramDataProvider = new CachedChromatogramDataProvider(cache, document,
         chromFileInfo.FilePath, chromFileInfo, null, progressStatus, startPercent, endPercent, loader);
 }
Ejemplo n.º 16
0
 private bool LoadFromCache(ILoadMonitor loader)
 {
     if (!loader.StreamManager.IsCached(FilePath, CachePath))
     {
         return(false);
     }
     try
     {
         ValueCache valueCache = new ValueCache();
         using (var stream = loader.StreamManager.CreateStream(CachePath, FileMode.Open, true))
         {
             int version = PrimitiveArrays.ReadOneValue <int>(stream);
             if (version != FORMAT_VERSION_CACHE)
             {
                 return(false);
             }
             int           fileCount   = PrimitiveArrays.ReadOneValue <int>(stream);
             List <String> sourceFiles = new List <string>(fileCount);
             while (sourceFiles.Count < fileCount)
             {
                 int    byteCount = PrimitiveArrays.ReadOneValue <int>(stream);
                 byte[] bytes     = new byte[byteCount];
                 stream.Read(bytes, 0, bytes.Length);
                 sourceFiles.Add(Encoding.UTF8.GetString(bytes));
             }
             int spectrumInfoCount = PrimitiveArrays.ReadOneValue <int>(stream);
             _sourceFiles = ImmutableList.ValueOf(sourceFiles);
             List <ElibSpectrumInfo> spectrumInfos = new List <ElibSpectrumInfo>();
             while (spectrumInfos.Count < spectrumInfoCount)
             {
                 spectrumInfos.Add(ElibSpectrumInfo.Read(valueCache, stream));
             }
             SetLibraryEntries(spectrumInfos);
             return(true);
         }
     }
     catch (Exception exception)
     {
         Trace.TraceWarning(@"Exception loading cache: {0}", exception);
         return(false);
     }
 }
Ejemplo n.º 17
0
 private bool LoadFromCache(ILoadMonitor loadMonitor, ProgressStatus status)
 {
     if (!loadMonitor.StreamManager.IsCached(FilePath, CachePath))
     {
         return(false);
     }
     try
     {
         using (var stream = loadMonitor.StreamManager.CreateStream(CachePath, FileMode.Open, true))
         {
             var serializer = new Serializer(this, stream);
             serializer.Read();
             return(true);
         }
     }
     catch (Exception exception)
     {
         Trace.TraceWarning(Resources.ChromatogramLibrary_LoadFromCache_Exception_reading_cache__0_, exception);
         return(false);
     }
 }
Ejemplo n.º 18
0
        public bool CompleteDocument(SrmDocument document, ILoadMonitor loadMonitor)
        {
            // Refuse completion, if anything is still not final
            var status   = Status;
            var notFinal = status.ProgressList.Where(s => !s.IsFinal).ToArray();

            if (notFinal.Any())
            {
                // Write output in attempt to associate new hangs in nightly tests with the return false below
//                Console.WriteLine(TextUtil.LineSeparate(@"*** Attempt to complete document with non-final status ***",
//                    TextUtil.LineSeparate(notFinal.Select(s => string.Format(@"{0} {1}% - {2}", s.State, s.PercentComplete, s.FilePath)))));
                return(false);
            }

            if (status.ProgressList.Any())
            {
                loadMonitor.UpdateProgress(CompleteStatus());
            }
            ClearDocument(document);
            return(true);
        }
Ejemplo n.º 19
0
        public ChorusResponseChromDataProvider(SrmDocument document, ChromFileInfo chromFileInfo, IProgressStatus progressStatus, int startPercent,
                                               int endPercent, ILoadMonitor loader) : base(chromFileInfo, progressStatus, startPercent, endPercent, loader)
        {
            ChromatogramCache.RawData rawData;
            MsDataFilePath            msDataFilePath = (MsDataFilePath)chromFileInfo.FilePath;
            IPooledStream             stream         = loader.StreamManager.CreatePooledStream(msDataFilePath.FilePath, false);

            ChromatogramCache.LoadStructs(stream.Stream, out rawData);
            var chromCacheFile = rawData.ChromCacheFiles[0];

            rawData.ChromCacheFiles = new[]
            {
                new ChromCachedFile(chromFileInfo.FilePath, chromCacheFile.Flags, chromCacheFile.FileWriteTime,
                                    chromCacheFile.RunStartTime, chromCacheFile.MaxRetentionTime, chromCacheFile.MaxIntensity,
                                    chromCacheFile.InstrumentInfoList),
            };
            var cache = new ChromatogramCache("cachePath", rawData, stream); // Not L10N

            _cachedChromatogramDataProvider = new CachedChromatogramDataProvider(cache, document,
                                                                                 chromFileInfo.FilePath, chromFileInfo, null, progressStatus, startPercent, endPercent, loader);
        }
 public CachedChromatogramDataProvider(ChromatogramCache cache,
     SrmDocument document,
     MsDataFileUri dataFilePath,
     ChromFileInfo fileInfo,
     bool? singleMatchMz,
     ProgressStatus status,
     int startPercent,
     int endPercent,
     ILoadMonitor loader)
     : base(fileInfo, status, startPercent, endPercent, loader)
 {
     _cache = cache;
     _fileIndex = cache.CachedFiles.IndexOf(f => Equals(f.FilePath, dataFilePath));
     _chromKeyIndices = cache.GetChromKeys(dataFilePath).OrderBy(v => v.LocationPoints).ToArray();
     _cache.GetStatusDimensions(dataFilePath, out _maxRetentionTime, out _maxIntensity);
     _singleMatchMz = singleMatchMz.HasValue
                          ? singleMatchMz.Value
                          // Unfortunately, before the single matching status was
                          // written into the cache file, we can only guess about its
                          // status based on the overall document settings
                          : document.Settings.TransitionSettings.FullScan.IsEnabled;
 }
Ejemplo n.º 21
0
 public CachedChromatogramDataProvider(ChromatogramCache cache,
                                       SrmDocument document,
                                       MsDataFileUri dataFilePath,
                                       ChromFileInfo fileInfo,
                                       bool?singleMatchMz,
                                       ProgressStatus status,
                                       int startPercent,
                                       int endPercent,
                                       ILoadMonitor loader)
     : base(fileInfo, status, startPercent, endPercent, loader)
 {
     _cache           = cache;
     _fileIndex       = cache.CachedFiles.IndexOf(f => Equals(f.FilePath, dataFilePath));
     _chromKeyIndices = cache.GetChromKeys(dataFilePath).OrderBy(v => v.LocationPoints).ToArray();
     _cache.GetStatusDimensions(dataFilePath, out _maxRetentionTime, out _maxIntensity);
     _singleMatchMz = singleMatchMz.HasValue
                          ? singleMatchMz.Value
                      // Unfortunately, before the single matching status was
                      // written into the cache file, we can only guess about its
                      // status based on the overall document settings
                          : document.Settings.TransitionSettings.FullScan.IsEnabled;
 }
Ejemplo n.º 22
0
        public CachedChromatogramDataProvider(ChromatogramCache cache,
                                              SrmDocument document,
                                              MsDataFileUri dataFilePath,
                                              ChromFileInfo fileInfo,
                                              bool?singleMatchMz,
                                              IProgressStatus status,
                                              int startPercent,
                                              int endPercent,
                                              ILoadMonitor loader)
            : base(fileInfo, status, startPercent, endPercent, loader)
        {
            // Deal with older cache formats where we did not record chromatogram polarity
            var assumeNegativeChargesInPreV11Caches = document.MoleculeTransitionGroups.All(p => p.PrecursorMz.IsNegative);

            // Need a newly loaded copy to allow for concurrent loading for multiple cached files
            _cache = ChromatogramCache.Load(cache.CachePath, new ProgressStatus(), loader, assumeNegativeChargesInPreV11Caches);

            _fileIndex       = cache.CachedFiles.IndexOf(f => Equals(f.FilePath, dataFilePath));
            _chromKeyIndices = cache.GetChromKeys(dataFilePath).OrderBy(v => v.LocationPoints).ToArray();
            foreach (var c in _chromKeyIndices.Where(i => i.Key.Precursor != 0))
            {
                if (c.Key.Precursor.IsNegative)
                {
                    _sourceHasNegativePolarityData = true;
                }
                else
                {
                    _sourceHasPositivePolarityData = true;
                }
            }
            _cache.GetStatusDimensions(dataFilePath, out _maxRetentionTime, out _maxIntensity);
            _singleMatchMz = singleMatchMz.HasValue
                                 ? singleMatchMz.Value
                             // Unfortunately, before the single matching status was
                             // written into the cache file, we can only guess about its
                             // status based on the overall document settings
                                 : document.Settings.TransitionSettings.FullScan.IsEnabled;
        }
Ejemplo n.º 23
0
 public override Library LoadLibrary(ILoadMonitor loader)
 {
     return(SpectrastLibrary.Load(this, loader));
 }
Ejemplo n.º 24
0
 public override Library LoadLibrary(ILoadMonitor loader)
 {
     return(ChromatogramLibrary.LoadFromDatabase(this, loader));
 }
Ejemplo n.º 25
0
 private Stream CreateStream(ILoadMonitor loader)
 {
     if (_readStream == null)
         _readStream = loader.StreamManager.CreatePooledStream(FilePath, false);
     return ReadStream.Stream;
 }
Ejemplo n.º 26
0
 public static SpectrastLibrary Load(LibrarySpec spec, ILoadMonitor loader)
 {
     return((SpectrastLibrary)Load(spec, new SpectrastLibrary(spec), loader));
 }
Ejemplo n.º 27
0
 public override Library LoadLibrary(ILoadMonitor loader)
 {
     return(XHunterLibrary.Load(this, loader));
 }
Ejemplo n.º 28
0
        // ReSharper restore UnusedMember.Local
        private bool Load(ILoadMonitor loader)
        {
            ProgressStatus status =
                new ProgressStatus(string.Format(Resources.BiblioSpecLibrary_Load_Loading__0__library,
                                                 Path.GetFileName(FilePath)));
            loader.UpdateProgress(status);

            long lenRead = 0;
            // AdlerChecksum checksum = new AdlerChecksum();

            try
            {
                // Use a buffered stream for initial read
                BufferedStream stream = new BufferedStream(CreateStream(loader), 32 * 1024);

                int countHeader = (int) LibHeaders.count*4;
                byte[] libHeader = new byte[countHeader];
                if (stream.Read(libHeader, 0, countHeader) != countHeader)
                    throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Data_truncation_in_library_header_File_may_be_corrupted);
                lenRead += countHeader;
                // Check the first byte of the primary version number to determine
                // whether the format is little- or big-endian.  Little-endian will
                // have the version number in this byte, while big-endian will have zero.
                if (libHeader[(int) LibHeaders.version1 * 4] == 0)
                    _bigEndian = true;

                int numSpectra = GetInt32(libHeader, (int) LibHeaders.num_spectra);
                var dictLibrary = new Dictionary<LibKey, BiblioSpectrumInfo>(numSpectra);
                var setSequences = new HashSet<LibSeqKey>();

                string revStr = string.Format("{0}.{1}", // Not L10N
                                              GetInt32(libHeader, (int) LibHeaders.version1),
                                              GetInt32(libHeader, (int) LibHeaders.version2));
                Revision = float.Parse(revStr, CultureInfo.InvariantCulture);

                // checksum.MakeForBuff(libHeader, AdlerChecksum.ADLER_START);

                countHeader = (int) SpectrumHeaders.count*4;
                byte[] specHeader = new byte[1024];
                byte[] specSequence = new byte[1024];
                for (int i = 0; i < numSpectra; i++)
                {
                    int percent = i * 100 / numSpectra;
                    if (status.PercentComplete != percent)
                    {
                        // Check for cancellation after each integer change in percent loaded.
                        if (loader.IsCanceled)
                        {
                            loader.UpdateProgress(status.Cancel());
                            return false;
                        }

                        // If not cancelled, update progress.
                        loader.UpdateProgress(status = status.ChangePercentComplete(percent));
                    }

                    // Read spectrum header
                    int bytesRead = stream.Read(specHeader, 0, countHeader);
                    if (bytesRead != countHeader)
                        throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Data_truncation_in_spectrum_header_File_may_be_corrupted);

                    // If this is the first header, and the sequence length is zero,
                    // then this is a Linux format library.  Switch to linux format,
                    // and start over.
                    if (i == 0 && GetInt32(specHeader, (int)SpectrumHeaders.seq_len) == 0)
                    {
                        _linuxFormat = true;
                        stream.Seek(lenRead, SeekOrigin.Begin);

                        // Re-ead spectrum header
                        countHeader = (int)SpectrumHeadersLinux.count * 4;
                        bytesRead = stream.Read(specHeader, 0, countHeader);
                        if (bytesRead != countHeader)
                            throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Data_truncation_in_spectrum_header_File_may_be_corrupted);
                    }

                    lenRead += bytesRead;

                    // checksum.MakeForBuff(specHeader, checksum.ChecksumValue);

                    int charge = GetInt32(specHeader, (int)SpectrumHeaders.charge);
                    if (charge > TransitionGroup.MAX_PRECURSOR_CHARGE)
                        throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Invalid_precursor_charge_found_File_may_be_corrupted);

                    int numPeaks = GetInt32(specHeader, (int)SpectrumHeaders.num_peaks);
                    int seqLength = GetInt32(specHeader, (_linuxFormat ?
                        (int)SpectrumHeadersLinux.seq_len : (int)SpectrumHeaders.seq_len));
                    int copies = GetInt32(specHeader, (_linuxFormat ?
                        (int)SpectrumHeadersLinux.copies : (int)SpectrumHeaders.copies));

                    // Read sequence information
                    int countSeq = (seqLength + 1)*2;
                    if (stream.Read(specSequence, 0, countSeq) != countSeq)
                        throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Data_truncation_in_spectrum_sequence_File_may_be_corrupted);

                    lenRead += countSeq;

                    // checksum.MakeForBuff(specSequence, checksum.ChecksumValue);

                    // Store in dictionary
                    if (IsUnmodified(specSequence, seqLength + 1, seqLength))
                    {
                        // These libraries should not have duplicates, but just in case.
                        // CONSIDER: Emit error about redundancy?
                        // These legacy libraries assume [+57.0] modified Cysteine
                        LibKey key = new LibKey(GetCModified(specSequence, ref seqLength), 0, seqLength, charge);
                        if (!dictLibrary.ContainsKey(key))
                            dictLibrary.Add(key, new BiblioSpectrumInfo((short)copies, (short)numPeaks, lenRead));
                        setSequences.Add(new LibSeqKey(key));
                    }

                    // Read over peaks
                    int countPeaks = 2*sizeof(Single)*numPeaks;
                    stream.Seek(countPeaks, SeekOrigin.Current);    // Skip spectrum
                    lenRead += countPeaks;

                    // checksum.MakeForBuff(specPeaks, checksum.ChecksumValue);
                }

                // Checksum = checksum.ChecksumValue;
                _dictLibrary = dictLibrary;
                _setSequences = setSequences;
                loader.UpdateProgress(status.Complete());
                return true;
            }
            catch (InvalidDataException x)
            {
                loader.UpdateProgress(status.ChangeErrorException(x));
                return false;
            }
            catch (IOException x)
            {
                loader.UpdateProgress(status.ChangeErrorException(x));
                return false;
            }
            catch (Exception x)
            {
                x = new Exception(string.Format(Resources.BiblioSpecLibrary_Load_Failed_loading_library__0__, FilePath), x);
                loader.UpdateProgress(status.ChangeErrorException(x));
                return false;
            }
            finally
            {
                if (ReadStream != null)
                {
                    // Close the read stream to ensure we never leak it.
                    // This only costs on extra open, the first time the
                    // active document tries to read.
                    try { ReadStream.CloseStream(); }
                    catch(IOException) {}
                }
            }
        }
Ejemplo n.º 29
0
 public static SpectrastLibrary Load(LibrarySpec spec, ILoadMonitor loader)
 {
     return (SpectrastLibrary)Load(spec, new SpectrastLibrary(spec), loader);
 }
Ejemplo n.º 30
0
        // ReSharper restore UnusedMember.Local

        private bool CreateCache(ILoadMonitor loader, IProgressStatus status, int percent)
        {
            var sm = loader.StreamManager;

            BufferedStream stream = new BufferedStream(CreateStream(loader), 32 * 1024);

            int    version = 1;
            string id = string.Empty, revision = string.Empty;
            int    size = ReadSize(stream);
            int    i;

            if (size == 0)
            {
                version = 2;
                size    = ReadSize(stream);

                const int countLibHeader = 256 - 8;
                byte[]    libHeader      = new byte[countLibHeader];
                if (stream.Read(libHeader, 0, libHeader.Length) != libHeader.Length)
                {
                    throw new InvalidDataException(Resources.XHunterLibrary_CreateCache_Data_truncation_in_library_header_File_may_be_corrupted);
                }

                for (i = 0; i < libHeader.Length; i++)
                {
                    if (libHeader[i] == 0)
                    {
                        break;
                    }
                }

                string header = Encoding.UTF8.GetString(libHeader, 0, i);
                Match  match  = REGEX_HEADER.Match(header);
                if (match.Success)
                {
                    version  = int.Parse(match.Groups[1].Value);
                    id       = match.Groups[2].Value;
                    revision = match.Groups[3].Value;
                }
            }
            var setLibKeys     = new HashSet <LibKey>(size);
            var libraryEntries = new List <XHunterSpectrumInfo>(size);

            const int countHeader = ((int)SpectrumHeaders2.count) * sizeof(int);

            byte[] specHeader   = new byte[1024];
            byte[] specSequence = new byte[1024];
            i = 0;

            while (stream.Read(specHeader, 0, countHeader) == countHeader)
            {
                int percentComplete = (i++ *percent / size);
                if (status.PercentComplete != percentComplete)
                {
                    // Check for cancellation after each integer change in percent loaded.
                    if (loader.IsCanceled)
                    {
                        loader.UpdateProgress(status.Cancel());
                        return(false);
                    }

                    // If not cancelled, update progress.
                    loader.UpdateProgress(status = status.ChangePercentComplete(percentComplete));
                }

                int charge = (version == 1
                                  ? GetInt32(specHeader, ((int)SpectrumHeaders1.charge))
                                  : GetInt32(specHeader, ((int)SpectrumHeaders2.charge)));

                float i2 = (version == 1
                                ? GetSingle(specHeader, ((int)SpectrumHeaders1.i2))
                                : GetSingle(specHeader, ((int)SpectrumHeaders2.i2)));
                int seqLength = (version == 1
                                     ? GetInt32(specHeader, ((int)SpectrumHeaders1.seq_len))
                                     : GetInt32(specHeader, ((int)SpectrumHeaders2.seq_len)));

                float expect = (version == 1 ? 0.001f : GetSingle(specHeader, (int)SpectrumHeaders2.expect));


                // Read sequence information
                ReadComplete(stream, specSequence, seqLength);
                specSequence[seqLength] = 0;

                short numPeaks = (short)ReadSize(stream);

                // Save spectrum location
                long location = stream.Position;

                // Read over spectrum
                int countPeaks = (sizeof(byte) + sizeof(float)) * numPeaks;
                stream.Seek(countPeaks, SeekOrigin.Current); // Skip spectrum

                // Read modifications
                int    numMods          = ReadSize(stream);
                string modifiedSequence = Encoding.UTF8.GetString(specSequence, 0, seqLength);
                if (numMods > 0)
                {
                    StringBuilder sb = new StringBuilder();

                    ReadComplete(stream, specHeader, (4 + sizeof(double)) * numMods);
                    int    iLast    = 0;
                    double modTotal = 0;
                    for (int j = 0; j < numMods; j++)
                    {
                        int    iPos = GetInt32(specHeader, j * 3);
                        double mod  = BitConverter.ToDouble(specHeader, (j * 3 + 1) * 4);

                        // X! Hunter allows multiple modifications on the same
                        // residue.  So, they need to be totaled, and assigned to a
                        // single residue to allow them to match Skyline modification
                        // settings.
                        if (iPos > iLast)
                        {
                            if (modTotal != 0)
                            {
                                sb.Append(SequenceMassCalc.GetModDiffDescription(modTotal));
                            }
                            sb.Append(Encoding.UTF8.GetString(specSequence, iLast, iPos - iLast));

                            modTotal = 0;
                        }
                        modTotal += mod;
                        iLast     = iPos;
                    }
                    if (modTotal != 0)
                    {
                        sb.Append(SequenceMassCalc.GetModDiffDescription(modTotal));
                    }
                    sb.Append(Encoding.UTF8.GetString(specSequence, iLast, seqLength - iLast));
                    modifiedSequence = sb.ToString();
                }

                // Skip over homologs (list of protein IDs and start positions from a FASTA
                // file used to generate the library)
                int numHomologs = ReadSize(stream);
                for (int j = 0; j < numHomologs; j++)
                {
                    stream.Seek(ReadSize(stream) + 4, SeekOrigin.Current);
                }

                // These libraries should not have duplicates, but just in case.
                // Apparently, GPM libraries do contain redundancies, as we found
                // when a revision lost this test.
                var key = new LibKey(modifiedSequence, charge);
                if (setLibKeys.Add(key))
                {
                    libraryEntries.Add(new XHunterSpectrumInfo(key, i2, expect, numPeaks, location));
                }
            }

            libraryEntries = FilterInvalidLibraryEntries(ref status, libraryEntries);

            using (FileSaver fs = new FileSaver(CachePath, sm))
                using (Stream outStream = sm.CreateStream(fs.SafeName, FileMode.Create, true))
                {
                    foreach (var info in libraryEntries)
                    {
                        info.Key.Write(outStream);
                        PrimitiveArrays.WriteOneValue(outStream, info.Location);
                        PrimitiveArrays.WriteOneValue(outStream, info.ProcessedIntensity);
                        PrimitiveArrays.WriteOneValue(outStream, info.NumPeaks);
                        PrimitiveArrays.WriteOneValue(outStream, info.Expect);
                    }

                    byte[] revisionBytes = Encoding.UTF8.GetBytes(revision);
                    outStream.Write(revisionBytes, 0, revisionBytes.Length);
                    byte[] idBytes = Encoding.UTF8.GetBytes(id);
                    outStream.Write(idBytes, 0, idBytes.Length);
                    outStream.Write(BitConverter.GetBytes(revisionBytes.Length), 0, sizeof(int));
                    outStream.Write(BitConverter.GetBytes(idBytes.Length), 0, sizeof(int));
                    outStream.Write(BitConverter.GetBytes(FORMAT_VERSION_CACHE), 0, sizeof(int));
                    outStream.Write(BitConverter.GetBytes(libraryEntries.Count), 0, sizeof(int));
                    outStream.Write(BitConverter.GetBytes((long)0), 0, sizeof(long));

                    sm.Finish(outStream);
                    fs.Commit();
                    sm.SetCache(FilePath, CachePath);
                }

            loader.UpdateProgress(status.Complete());

            return(true);
        }
Ejemplo n.º 31
0
 public static Library CreateBiblioFile(MemoryStreamManager streamManager, ILoadMonitor loader, string nistText)
 {
     return(CreateLibraryFile(streamManager, loader, nistText,
                              (sm, lib) => BiblioSpecLibrary.Write(sm, PATH_BIBLIOSPEC_LIB, lib)));
 }
Ejemplo n.º 32
0
 public override Library LoadLibrary(ILoadMonitor loader)
 {
     return SpectrastLibrary.Load(this, loader);
 }
Ejemplo n.º 33
0
 public static Library CreateHunterFile(MemoryStreamManager streamManager, ILoadMonitor loader,
                                        string nistText, bool lowIntensity)
 {
     return(CreateLibraryFile(streamManager, loader, nistText,
                              (sm, lib) => XHunterLibrary.Write(sm, PATH_HUNTER_LIB, lib, lowIntensity)));
 }
Ejemplo n.º 34
0
 public static Library CreateHunterFile(MemoryStreamManager streamManager, ILoadMonitor loader, string nistText)
 {
     return(CreateHunterFile(streamManager, loader, nistText, false));
 }
Ejemplo n.º 35
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());
                    }
        }
Ejemplo n.º 36
0
 public static Library CreateBiblioFile(MemoryStreamManager streamManager, ILoadMonitor loader, string nistText)
 {
     return CreateLibraryFile(streamManager, loader, nistText,
         (sm, lib) => BiblioSpecLibrary.Write(sm, PATH_BIBLIOSPEC_LIB, lib));
 }
Ejemplo n.º 37
0
        private static Library CreateLibraryFile(MemoryStreamManager streamManager, ILoadMonitor loader,
            string nistText, Action<IStreamManager, Library> write)
        {
            streamManager.TextFiles[PATH_NIST_LIB] = nistText;

            var librarySpec = new NistLibSpec("Temporary (NIST)", PATH_NIST_LIB);

            Library libNist = librarySpec.LoadLibrary(loader);
            Assert.IsNotNull(libNist);
            write(streamManager, libNist);

            streamManager.TextFiles.Remove(PATH_NIST_LIB);
            streamManager.Delete(PATH_NIST_LIB_CACHE);

            return libNist;
        }
Ejemplo n.º 38
0
 public Digestion Digest(Enzyme enzyme, DigestSettings digestSettings, ILoadMonitor loader)
 {
     ProgressStatus progressStatus = new ProgressStatus(string.Format(Resources.BackgroundProteomeSpec_Digest_Digesting__0__, enzyme.Name));
     using (var proteomeDb = OpenProteomeDb())
     {
         return proteomeDb.Digest(new ProteaseImpl(enzyme),
                                     (s, i) =>
                                     {
                                         loader.UpdateProgress(progressStatus.ChangePercentComplete(i));
                                         return !loader.IsCanceled;
                                     });
     }
 }
Ejemplo n.º 39
0
 public static Library CreateHunterFile(MemoryStreamManager streamManager, ILoadMonitor loader,
     string nistText, bool lowIntensity)
 {
     return CreateLibraryFile(streamManager, loader, nistText,
         (sm, lib) => XHunterLibrary.Write(sm, PATH_HUNTER_LIB, lib, lowIntensity));
 }
Ejemplo n.º 40
0
        private bool Load(ILoadMonitor loader, IProgressStatus status, bool cached)
        {
            try
            {
                int loadPercent = 100;

                if (!cached)
                {
                    // Building the cache will take 95% of the load time.
                    loadPercent = 5;

                    status = status.ChangeMessage(string.Format(Resources.XHunterLibrary_Load_Building_binary_cache_for__0__library, Path.GetFileName(FilePath)));
                    status = status.ChangePercentComplete(0);

                    loader.UpdateProgress(status);

                    if (!CreateCache(loader, status, 100 - loadPercent))
                    {
                        return(false);
                    }
                }

                status = status.ChangeMessage(string.Format(Resources.XHunterLibrary_Load_Loading__0__library, Path.GetFileName(FilePath)));
                loader.UpdateProgress(status);

                var valueCache = new ValueCache();
                var sm         = loader.StreamManager;
                using (Stream stream = sm.CreateStream(CachePath, FileMode.Open, true))
                {
                    // Read library header from the end of the cache
                    int countHeader = (int)LibHeaders.count * sizeof(int);
                    stream.Seek(-countHeader, SeekOrigin.End);

                    byte[] libHeader = new byte[countHeader];
                    ReadComplete(stream, libHeader, countHeader);

                    int version = GetInt32(libHeader, (int)LibHeaders.format_version);
                    if (version != FORMAT_VERSION_CACHE)
                    {
                        return(false);
                    }

                    int countRevisionBytes = GetInt32(libHeader, (int)LibHeaders.revision_byte_count);
                    int countIdBytes       = GetInt32(libHeader, (int)LibHeaders.id_byte_count);
                    stream.Seek(-countHeader - countRevisionBytes - countIdBytes, SeekOrigin.End);
                    Revision = ReadString(stream, countRevisionBytes);
                    Id       = ReadString(stream, countIdBytes);

                    int numSpectra = GetInt32(libHeader, (int)LibHeaders.num_spectra);

                    var libraryEntries = new XHunterSpectrumInfo[numSpectra];

                    // Seek to beginning of spectrum headers
                    long locationHeaders = BitConverter.ToInt64(libHeader,
                                                                ((int)LibHeaders.location_headers_lo) * sizeof(int));
                    stream.Seek(locationHeaders, SeekOrigin.Begin);

                    for (int i = 0; i < numSpectra; i++)
                    {
                        int percent = (100 - loadPercent) + (i * loadPercent / numSpectra);
                        if (status.PercentComplete != percent)
                        {
                            // Check for cancellation after each integer change in percent loaded.
                            if (loader.IsCanceled)
                            {
                                loader.UpdateProgress(status.Cancel());
                                return(false);
                            }

                            // If not cancelled, update progress.
                            loader.UpdateProgress(status = status.ChangePercentComplete(percent));
                        }

                        // Read spectrum header
                        LibKey key                = LibKey.Read(valueCache, stream);
                        long   location           = PrimitiveArrays.ReadOneValue <long>(stream);
                        float  processedIntensity = PrimitiveArrays.ReadOneValue <float>(stream);
                        int    numPeaks           = PrimitiveArrays.ReadOneValue <int>(stream);
                        float  expect             = PrimitiveArrays.ReadOneValue <float>(stream);
                        libraryEntries[i] = new XHunterSpectrumInfo(key, processedIntensity, expect, (short)numPeaks, location);
                    }

                    // Checksum = checksum.ChecksumValue;
                    SetLibraryEntries(libraryEntries);

                    loader.UpdateProgress(status.Complete());

                    // Create the stream from which the spectra will be read
                    CreateStream(loader);
                }

                return(true);
            }
            catch (InvalidDataException x)
            {
                if (!cached)
                {
                    loader.UpdateProgress(status.ChangeErrorException(x));
                }
                return(false);
            }
            catch (IOException x)
            {
                if (!cached)
                {
                    loader.UpdateProgress(status.ChangeErrorException(x));
                }
                return(false);
            }
            catch (Exception x)
            {
                if (!cached)
                {
                    x = new Exception(string.Format(Resources.XHunterLibrary_Load_Failed_loading_library__0__, FilePath), x);
                    loader.UpdateProgress(status.ChangeErrorException(x));
                }
                return(false);
            }
            finally
            {
                if (ReadStream != null)
                {
                    // Close the read stream to ensure we never leak it.
                    // This only costs on extra open, the first time the
                    // active document tries to read.
                    try { ReadStream.CloseStream(); }
                    catch (IOException) { }
                }
            }
        }
Ejemplo n.º 41
0
 public static void SetLoadMonitor(ILoadMonitor loadMon)
 {
     _loadMonitor = loadMon;
 }
Ejemplo n.º 42
0
 public override Library LoadLibrary(ILoadMonitor loader)
 {
     return BiblioSpecLibrary.Load(this, loader);
 }
Ejemplo n.º 43
0
 public static Library CreateHunterFile(MemoryStreamManager streamManager, ILoadMonitor loader, string nistText)
 {
     return CreateHunterFile(streamManager, loader, nistText, false);
 }
Ejemplo n.º 44
0
        // ReSharper restore UnusedMember.Local

        private bool Load(ILoadMonitor loader)
        {
            ProgressStatus status =
                new ProgressStatus(string.Format(Resources.BiblioSpecLibrary_Load_Loading__0__library,
                                                 Path.GetFileName(FilePath)));

            loader.UpdateProgress(status);

            long lenRead = 0;

            // AdlerChecksum checksum = new AdlerChecksum();

            try
            {
                // Use a buffered stream for initial read
                BufferedStream stream = new BufferedStream(CreateStream(loader), 32 * 1024);

                int    countHeader = (int)LibHeaders.count * 4;
                byte[] libHeader   = new byte[countHeader];
                if (stream.Read(libHeader, 0, countHeader) != countHeader)
                {
                    throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Data_truncation_in_library_header_File_may_be_corrupted);
                }
                lenRead += countHeader;
                // Check the first byte of the primary version number to determine
                // whether the format is little- or big-endian.  Little-endian will
                // have the version number in this byte, while big-endian will have zero.
                if (libHeader[(int)LibHeaders.version1 * 4] == 0)
                {
                    _bigEndian = true;
                }

                int numSpectra   = GetInt32(libHeader, (int)LibHeaders.num_spectra);
                var dictLibrary  = new Dictionary <LibKey, BiblioSpectrumInfo>(numSpectra);
                var setSequences = new HashSet <LibSeqKey>();

                string revStr = string.Format("{0}.{1}", // Not L10N
                                              GetInt32(libHeader, (int)LibHeaders.version1),
                                              GetInt32(libHeader, (int)LibHeaders.version2));
                Revision = float.Parse(revStr, CultureInfo.InvariantCulture);

                // checksum.MakeForBuff(libHeader, AdlerChecksum.ADLER_START);

                countHeader = (int)SpectrumHeaders.count * 4;
                byte[] specHeader   = new byte[1024];
                byte[] specSequence = new byte[1024];
                for (int i = 0; i < numSpectra; i++)
                {
                    int percent = i * 100 / numSpectra;
                    if (status.PercentComplete != percent)
                    {
                        // Check for cancellation after each integer change in percent loaded.
                        if (loader.IsCanceled)
                        {
                            loader.UpdateProgress(status.Cancel());
                            return(false);
                        }

                        // If not cancelled, update progress.
                        loader.UpdateProgress(status = status.ChangePercentComplete(percent));
                    }

                    // Read spectrum header
                    int bytesRead = stream.Read(specHeader, 0, countHeader);
                    if (bytesRead != countHeader)
                    {
                        throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Data_truncation_in_spectrum_header_File_may_be_corrupted);
                    }

                    // If this is the first header, and the sequence length is zero,
                    // then this is a Linux format library.  Switch to linux format,
                    // and start over.
                    if (i == 0 && GetInt32(specHeader, (int)SpectrumHeaders.seq_len) == 0)
                    {
                        _linuxFormat = true;
                        stream.Seek(lenRead, SeekOrigin.Begin);

                        // Re-ead spectrum header
                        countHeader = (int)SpectrumHeadersLinux.count * 4;
                        bytesRead   = stream.Read(specHeader, 0, countHeader);
                        if (bytesRead != countHeader)
                        {
                            throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Data_truncation_in_spectrum_header_File_may_be_corrupted);
                        }
                    }

                    lenRead += bytesRead;

                    // checksum.MakeForBuff(specHeader, checksum.ChecksumValue);

                    int charge = GetInt32(specHeader, (int)SpectrumHeaders.charge);
                    if (charge > TransitionGroup.MAX_PRECURSOR_CHARGE)
                    {
                        throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Invalid_precursor_charge_found_File_may_be_corrupted);
                    }

                    int numPeaks  = GetInt32(specHeader, (int)SpectrumHeaders.num_peaks);
                    int seqLength = GetInt32(specHeader, (_linuxFormat ?
                                                          (int)SpectrumHeadersLinux.seq_len : (int)SpectrumHeaders.seq_len));
                    int copies = GetInt32(specHeader, (_linuxFormat ?
                                                       (int)SpectrumHeadersLinux.copies : (int)SpectrumHeaders.copies));

                    // Read sequence information
                    int countSeq = (seqLength + 1) * 2;
                    if (stream.Read(specSequence, 0, countSeq) != countSeq)
                    {
                        throw new InvalidDataException(Resources.BiblioSpecLibrary_Load_Data_truncation_in_spectrum_sequence_File_may_be_corrupted);
                    }

                    lenRead += countSeq;

                    // checksum.MakeForBuff(specSequence, checksum.ChecksumValue);

                    // Store in dictionary
                    if (IsUnmodified(specSequence, seqLength + 1, seqLength))
                    {
                        // These libraries should not have duplicates, but just in case.
                        // CONSIDER: Emit error about redundancy?
                        // These legacy libraries assume [+57.0] modified Cysteine
                        LibKey key = new LibKey(GetCModified(specSequence, ref seqLength), 0, seqLength, charge);
                        if (!dictLibrary.ContainsKey(key))
                        {
                            dictLibrary.Add(key, new BiblioSpectrumInfo((short)copies, (short)numPeaks, lenRead));
                        }
                        setSequences.Add(new LibSeqKey(key));
                    }

                    // Read over peaks
                    int countPeaks = 2 * sizeof(Single) * numPeaks;
                    stream.Seek(countPeaks, SeekOrigin.Current);    // Skip spectrum
                    lenRead += countPeaks;

                    // checksum.MakeForBuff(specPeaks, checksum.ChecksumValue);
                }

                // Checksum = checksum.ChecksumValue;
                _dictLibrary  = dictLibrary;
                _setSequences = setSequences;
                loader.UpdateProgress(status.Complete());
                return(true);
            }
            catch (InvalidDataException x)
            {
                loader.UpdateProgress(status.ChangeErrorException(x));
                return(false);
            }
            catch (IOException x)
            {
                loader.UpdateProgress(status.ChangeErrorException(x));
                return(false);
            }
            catch (Exception x)
            {
                x = new Exception(string.Format(Resources.BiblioSpecLibrary_Load_Failed_loading_library__0__, FilePath), x);
                loader.UpdateProgress(status.ChangeErrorException(x));
                return(false);
            }
            finally
            {
                if (ReadStream != null)
                {
                    // Close the read stream to ensure we never leak it.
                    // This only costs on extra open, the first time the
                    // active document tries to read.
                    try { ReadStream.CloseStream(); }
                    catch (IOException) {}
                }
            }
        }
Ejemplo n.º 45
0
 public override Library LoadLibrary(ILoadMonitor loader)
 {
     return(BiblioSpecLibrary.Load(this, loader));
 }
Ejemplo n.º 46
0
 public override Library LoadLibrary(ILoadMonitor loader)
 {
     return ChromatogramLibrary.LoadFromDatabase(this, loader);
 }
Ejemplo n.º 47
0
 public static BiblioSpecLibrary Load(BiblioSpecLibSpec spec, ILoadMonitor loader)
 {
     var library = new BiblioSpecLibrary(spec) { FilePath = spec.FilePath };
     if (library.Load(loader))
         return library;
     return null;
 }