Пример #1
0
        public Peak1DArray ReadSpectrumPeaks(UInt64 spectrumId, bool getCentroids)
        {
            BafSqlSpectrum bafSpec = linq2BafSql.GetBafSqlSpectrum(this.linq2BafSql.Core, spectrumId);

            if (bafSpec == null)
            {
                throw new MzLiteIOException("No spectrum found for id: " + spectrumId);
            }

            Peak1DArray pa = new Peak1DArray(
                BinaryDataCompressionType.NoCompression,
                BinaryDataType.Float32,
                BinaryDataType.Float32);

            double[] masses;
            UInt32[] intensities;

            // if profile data available we prefer to get profile data otherwise centroided data (line spectra)
            if (getCentroids && bafSpec.LineMzId.HasValue && bafSpec.LineIntensityId.HasValue)
            {
                masses      = Baf2SqlWrapper.GetBafDoubleArray(baf2SqlHandle, bafSpec.LineMzId.Value);
                intensities = Baf2SqlWrapper.GetBafUInt32Array(baf2SqlHandle, bafSpec.LineIntensityId.Value);
            }
            else if (getCentroids == false && bafSpec.ProfileMzId.HasValue && bafSpec.ProfileIntensityId.HasValue)
            {
                masses      = Baf2SqlWrapper.GetBafDoubleArray(baf2SqlHandle, bafSpec.ProfileMzId.Value);
                intensities = Baf2SqlWrapper.GetBafUInt32Array(baf2SqlHandle, bafSpec.ProfileIntensityId.Value);
            }
            else
            {
                masses      = new double[0];
                intensities = new UInt32[0];
            }

            pa.Peaks = new BafPeaksArray(masses, intensities);

            return(pa);
        }
Пример #2
0
        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);
        }