示例#1
0
        public BafFileReader(string bafFilePath)
        {
            if (string.IsNullOrWhiteSpace(bafFilePath))
            {
                throw new ArgumentNullException("bafFilePath");
            }
            if (!File.Exists(bafFilePath))
            {
                throw new FileNotFoundException("Baf file not exists.");
            }

            this.bafFilePath = bafFilePath;

            try
            {
                sqlFilePath = Baf2SqlWrapper.GetSQLiteCacheFilename(bafFilePath);

                // First argument = 1, ignore contents of Calibrator.ami (if it exists)
                baf2SqlHandle = Baf2SqlWrapper.baf2sql_array_open_storage(1, bafFilePath);

                if (baf2SqlHandle == 0)
                {
                    Baf2SqlWrapper.ThrowLastBaf2SqlError();
                }

                linq2BafSql = new Linq2BafSql(sqlFilePath);

                model = MzLiteJson.HandleExternalModelFile(this, GetModelFilePath());
                supportedVariables = SupportedVariablesCollection.ReadSupportedVariables(linq2BafSql);
            }
            catch (Exception ex)
            {
                throw new MzLiteIOException(ex.Message, ex);
            }
        }
示例#2
0
        public void Dispose()
        {
            if (disposed)
            {
                return;
            }

            if (baf2SqlHandle != 0)
            {
                Baf2SqlWrapper.baf2sql_array_close_storage(baf2SqlHandle);
            }

            if (linq2BafSql != null)
            {
                linq2BafSql.Dispose();
            }

            disposed = true;
        }
示例#3
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);
        }