コード例 #1
0
 private SpectrumPeaksInfo.MI[] ReadSpectrum(ElibSpectrumInfo info, int sourceFileId)
 {
     if (sourceFileId < 0)
     {
         return(null);
     }
     return(_pooledSqliteConnection.ExecuteWithConnection(connection =>
     {
         HashSet <double> mzs = new HashSet <double>();
         List <SpectrumPeaksInfo.MI> spectrum = new List <SpectrumPeaksInfo.MI>();
         // First read all of the quantifiable transitions from the PeptideQuants table.
         var peptideQuantSpectrum = ReadSpectrumFromPeptideQuants(connection, info);
         if (peptideQuantSpectrum != null)
         {
             foreach (var mi in peptideQuantSpectrum)
             {
                 if (mzs.Add(mi.Mz))
                 {
                     spectrum.Add(mi);
                 }
             }
         }
         // Then read the spectrum for the specific file
         var entriesSpectrum = ReadSpectrumFromEntriesTable(connection, info, sourceFileId);
         foreach (var mi in entriesSpectrum)
         {
             if (mzs.Add(mi.Mz))
             {
                 var miToAdd = mi;
                 if (peptideQuantSpectrum != null)
                 {
                     // If we successfully read from the PeptideQuants table, then the
                     // rest of the mzs we find in the entries table are non-quantitative.
                     miToAdd.Quantitative = false;
                 }
                 else
                 {
                     // If we were unable to read from the PeptideQuants table, then
                     // the non-quantitative transitions are the ones with really low intensity.
                     miToAdd.Quantitative = miToAdd.Intensity >= MIN_QUANTITATIVE_INTENSITY;
                 }
                 spectrum.Add(miToAdd);
             }
         }
         return spectrum.ToArray();
     }));
 }
コード例 #2
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);
     }
 }
コード例 #3
0
 protected override SpectrumHeaderInfo CreateSpectrumHeaderInfo(ElibSpectrumInfo info)
 {
     return(new ChromLibSpectrumHeaderInfo(Name, 0));
 }
コード例 #4
0
 private IEnumerable <SpectrumPeaksInfo.MI> ReadSpectrumFromEntriesTable(SQLiteConnection connection, ElibSpectrumInfo info,
                                                                         int sourceFileId)
 {
     using (var cmd = new SQLiteCommand(connection))
     {
         cmd.CommandText =
             @"SELECT MassEncodedLength, MassArray, IntensityEncodedLength, IntensityArray FROM entries WHERE PrecursorCharge = ? AND PeptideModSeq = ? AND SourceFile = ?";
         cmd.Parameters.Add(new SQLiteParameter(DbType.Int32)
         {
             Value = info.Key.Charge
         });
         cmd.Parameters.Add(new SQLiteParameter(DbType.String)
         {
             Value = info.PeptideModSeq
         });
         cmd.Parameters.Add(new SQLiteParameter(DbType.String)
         {
             Value = _sourceFiles[sourceFileId]
         });
         using (var reader = cmd.ExecuteReader())
         {
             if (reader.Read())
             {
                 double[] mzs = PrimitiveArrays.FromBytes <double>(
                     PrimitiveArrays.ReverseBytesInBlocks(
                         UncompressEncyclopeDiaData((byte[])reader.GetValue(1), reader.GetInt32(0)),
                         sizeof(double)));
                 float[] intensities =
                     PrimitiveArrays.FromBytes <float>(PrimitiveArrays.ReverseBytesInBlocks(
                                                           UncompressEncyclopeDiaData((byte[])reader.GetValue(3), reader.GetInt32(2)),
                                                           sizeof(float)));
                 return(mzs.Select((mz, index) => new SpectrumPeaksInfo.MI
                 {
                     Mz = mz,
                     Intensity = intensities[index],
                 })         // CONSIDER(bspratt): annotation?
                        .ToArray());
             }
             return(null);
         }
     }
 }
コード例 #5
0
 private IEnumerable <SpectrumPeaksInfo.MI> ReadSpectrumFromPeptideQuants(SQLiteConnection connection, ElibSpectrumInfo info)
 {
     using (var cmd = new SQLiteCommand(connection))
     {
         cmd.CommandText = @"SELECT QuantIonMassLength, QuantIonMassArray, QuantIonIntensityLength, QuantIonIntensityArray FROM peptidequants WHERE PrecursorCharge = ? AND PeptideModSeq = ?";
         cmd.Parameters.Add(new SQLiteParameter(DbType.Int32)
         {
             Value = info.Key.Charge
         });
         cmd.Parameters.Add(new SQLiteParameter(DbType.String)
         {
             Value = info.PeptideModSeq
         });
         SQLiteDataReader reader;
         try
         {
             reader = cmd.ExecuteReader();
         }
         catch (DbException)
         {
             // Older .elib files do not have these columns, so just return null
             return(null);
         }
         using (reader)
         {
             if (!reader.Read())
             {
                 // None of the transitions are considered Quantifiable.
                 return(new SpectrumPeaksInfo.MI[0]);
             }
             double[] mzs = PrimitiveArrays.FromBytes <double>(
                 PrimitiveArrays.ReverseBytesInBlocks(
                     UncompressEncyclopeDiaData((byte[])reader.GetValue(1), reader.GetInt32(0)),
                     sizeof(double)));
             float[] intensities =
                 PrimitiveArrays.FromBytes <float>(PrimitiveArrays.ReverseBytesInBlocks(
                                                       UncompressEncyclopeDiaData((byte[])reader.GetValue(3), reader.GetInt32(2)), sizeof(float)));
             return(mzs.Select(
                        (mz, index) => new SpectrumPeaksInfo.MI {
                 Mz = mz, Intensity = intensities[index]
             }));
         }
     }
 }
コード例 #6
0
 protected override SpectrumPeaksInfo.MI[] ReadSpectrum(ElibSpectrumInfo info)
 {
     return(ReadSpectrum(info, info.BestFileId));
 }