private static MzLite.Model.MassSpectrum GetSpectrum( Batch batch, MassSpectrometerSample sample, MSExperiment msExp, int sampleIndex, int experimentIndex, int scanIndex) { MassSpectrumInfo wiffSpectrum = msExp.GetMassSpectrumInfo(scanIndex); MzLite.Model.MassSpectrum mzLiteSpectrum = new Model.MassSpectrum(ToSpectrumID(sampleIndex, experimentIndex, scanIndex)); // spectrum mzLiteSpectrum.SetMsLevel(wiffSpectrum.MSLevel); if (wiffSpectrum.CentroidMode) { mzLiteSpectrum.SetCentroidSpectrum(); } else { mzLiteSpectrum.SetProfileSpectrum(); } // scan Scan scan = new Scan(); scan.SetScanStartTime(wiffSpectrum.StartRT) .UO_Minute(); mzLiteSpectrum.Scans.Add(scan); // precursor if (wiffSpectrum.IsProductSpectrum) { Precursor precursor = new Precursor(); double isoWidth; double targetMz; if (GetIsolationWindow(wiffSpectrum.Experiment, out isoWidth, out targetMz)) { precursor.IsolationWindow .SetIsolationWindowTargetMz(targetMz) .SetIsolationWindowUpperOffset(isoWidth) .SetIsolationWindowLowerOffset(isoWidth); } SelectedIon selectedIon = new SelectedIon(); selectedIon.SetSelectedIonMz(wiffSpectrum.ParentMZ) .SetChargeState(wiffSpectrum.ParentChargeState); precursor.SelectedIons.Add(selectedIon); precursor.Activation .SetCollisionEnergy(wiffSpectrum.CollisionEnergy); mzLiteSpectrum.Precursors.Add(precursor); } return(mzLiteSpectrum); }
private MzLite.Model.MassSpectrum ReadMassSpectrum(int scanNo) { RaiseDisposed(); try { string spectrumID = GetSpectrumID(scanNo); MassSpectrum spectrum = new MassSpectrum(spectrumID); // spectrum int msLevel = GetMSLevel(rawFile, scanNo); spectrum.SetMsLevel(msLevel); if (IsCentroidSpectrum(rawFile, scanNo)) { spectrum.SetCentroidSpectrum(); } else { spectrum.SetProfileSpectrum(); } // scan Scan scan = new Scan(); scan.SetFilterString(GetFilterString(rawFile, scanNo)) .SetScanStartTime(GetRetentionTime(rawFile, scanNo)); //.UO_Minute(); spectrum.Scans.Add(scan); // precursor if (msLevel > 1) { Precursor precursor = new Precursor(); double isoWidth = GetIsolationWindowWidth(rawFile, scanNo, msLevel) * 0.5d; double targetMz = GetIsolationWindowTargetMz(rawFile, scanNo, msLevel); double precursorMz = GetPrecursorMz(rawFile, scanNo, msLevel); int chargeState = GetChargeState(rawFile, scanNo); precursor.IsolationWindow .SetIsolationWindowTargetMz(targetMz) .SetIsolationWindowUpperOffset(isoWidth) .SetIsolationWindowLowerOffset(isoWidth); SelectedIon selectedIon = new SelectedIon(); selectedIon .SetSelectedIonMz(precursorMz) .SetChargeState(chargeState); precursor.SelectedIons.Add(selectedIon); spectrum.Precursors.Add(precursor); } return(spectrum); } catch (Exception ex) { throw new MzLiteIOException(ex.Message, ex); } }
private MassSpectrum ReadMassSpectrum(UInt64 spectrumId) { BafSqlSpectrum bafSpec = linq2BafSql.GetBafSqlSpectrum(this.linq2BafSql.Core, spectrumId); if (bafSpec == null) { throw new MzLiteIOException("No spectrum found for id: " + spectrumId); } MassSpectrum ms = new MassSpectrum(spectrumId.ToString()); // determine ms level BafSqlAcquisitionKey aqKey = linq2BafSql.GetBafSqlAcquisitionKey(this.linq2BafSql.Core, bafSpec.AcquisitionKey); Nullable <int> msLevel = null; if (aqKey != null && aqKey.MsLevel.HasValue) { // bruker starts ms level by 0, must be added by 1 msLevel = aqKey.MsLevel.Value + 1; ms.SetMsLevel(msLevel.Value); } // determine type of spectrum and read peak data // if profile data available we prefer to get profile data otherwise centroided data (line spectra) if (bafSpec.ProfileMzId.HasValue && bafSpec.ProfileIntensityId.HasValue) { ms.SetProfileSpectrum(); } else if (bafSpec.LineMzId.HasValue && bafSpec.LineIntensityId.HasValue) { ms.SetCentroidSpectrum(); } if (msLevel == 1) { ms.SetMS1Spectrum(); } else if (msLevel > 1) { ms.SetMSnSpectrum(); } // scan if (bafSpec.Rt.HasValue) { Scan scan = new Scan(); scan.SetScanStartTime(bafSpec.Rt.Value).UO_Second(); ms.Scans.Add(scan); } // precursor if (msLevel > 1) { SpectrumVariableCollection spectrumVariables = SpectrumVariableCollection.ReadSpectrumVariables(linq2BafSql, bafSpec.Id); Precursor precursor = new Precursor(); decimal value; if (spectrumVariables.TryGetValue("Collision_Energy_Act", supportedVariables, out value)) { precursor.Activation.SetCollisionEnergy(Decimal.ToDouble(value)); } if (spectrumVariables.TryGetValue("MSMS_IsolationMass_Act", supportedVariables, out value)) { precursor.IsolationWindow.SetIsolationWindowTargetMz(Decimal.ToDouble(value)); } if (spectrumVariables.TryGetValue("Quadrupole_IsolationResolution_Act", supportedVariables, out value)) { double width = Decimal.ToDouble(value) * 0.5d; precursor.IsolationWindow.SetIsolationWindowUpperOffset(width); precursor.IsolationWindow.SetIsolationWindowLowerOffset(width); } Nullable <int> charge = null; if (spectrumVariables.TryGetValue("MSMS_PreCursorChargeState", supportedVariables, out value)) { charge = Decimal.ToInt32(value); } IEnumerable <BafSqlStep> ions = linq2BafSql.GetBafSqlSteps(this.linq2BafSql.Core, bafSpec.Id); foreach (BafSqlStep ion in ions) { if (ion.Mass.HasValue) { SelectedIon selectedIon = new SelectedIon(); precursor.SelectedIons.Add(selectedIon); selectedIon.SetSelectedIonMz(ion.Mass.Value); selectedIon.SetUserParam("Number", ion.Number.Value); selectedIon.SetUserParam("IsolationType", ion.IsolationType.Value); selectedIon.SetUserParam("ReactionType", ion.ReactionType.Value); selectedIon.SetUserParam("MsLevel", ion.MsLevel.Value); if (charge.HasValue) { selectedIon.SetChargeState(charge.Value); } } } // set parent spectrum as reference if (bafSpec.Parent.HasValue) { precursor.SpectrumReference = new SpectrumReference(bafSpec.Parent.ToString()); } ms.Precursors.Add(precursor); } return(ms); }