private MsDataSpectrum GetSpectrumFromJObject(JObject jObject, int msLevel) { // ReSharper disable NonLocalizedString string strMzs = jObject["mzs-base64"].ToString(); string strIntensities = jObject["intensities-base64"].ToString(); byte[] mzBytes = Convert.FromBase64String(strMzs); byte[] intensityBytes = Convert.FromBase64String(strIntensities); double[] mzs = PrimitiveArrays.FromBytes <double>( PrimitiveArrays.ReverseBytesInBlocks(mzBytes, sizeof(double))); float[] intensityFloats = PrimitiveArrays.FromBytes <float>( PrimitiveArrays.ReverseBytesInBlocks(intensityBytes, sizeof(float))); double[] intensities = intensityFloats.Select(f => (double)f).ToArray(); double? driftTime = null; JToken jDriftTime; if (jObject.TryGetValue("driftTime", out jDriftTime)) { driftTime = jDriftTime.ToObject <double>(); } MsDataSpectrum spectrum = new MsDataSpectrum { Index = jObject["index"].ToObject <int>(), RetentionTime = jObject["rt"].ToObject <double>(), Mzs = mzs, Intensities = intensities, DriftTimeMsec = driftTime, }; return(spectrum); // ReSharper restore NonLocalizedString }
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] })); } } }
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); } } }
private MsDataSpectrum GetSpectrumFromJObject(JObject jObject, int msLevel) { // ReSharper disable NonLocalizedString string strMzs = jObject["mzs-base64"].ToString(); string strIntensities = jObject["intensities-base64"].ToString(); byte[] mzBytes = Convert.FromBase64String(strMzs); byte[] intensityBytes = Convert.FromBase64String(strIntensities); double[] mzs = PrimitiveArrays.FromBytes <double>( PrimitiveArrays.ReverseBytesInBlocks(mzBytes, sizeof(double))); float[] intensityFloats = PrimitiveArrays.FromBytes <float>( PrimitiveArrays.ReverseBytesInBlocks(intensityBytes, sizeof(float))); double[] intensities = intensityFloats.Select(f => (double)f).ToArray(); IonMobilityValue ionMobility = IonMobilityValue.EMPTY; JToken jDriftTime; if (jObject.TryGetValue("driftTime", out jDriftTime)) { var driftTime = jDriftTime.ToObject <double>(); if (driftTime != 0) { ionMobility = IonMobilityValue.GetIonMobilityValue(driftTime, MsDataFileImpl.eIonMobilityUnits.drift_time_msec); } } MsDataSpectrum spectrum = new MsDataSpectrum { Index = jObject["index"].ToObject <int>(), RetentionTime = jObject["rt"].ToObject <double>(), Mzs = mzs, Intensities = intensities, IonMobility = ionMobility, }; return(spectrum); // ReSharper restore NonLocalizedString }