Exemple #1
0
        /// <summary>
        /// Estimates the GMM model from the data set.
        /// </summary>
        /// <param name="dataset">Input dataset.</param>
        /// <returns>Estimated model</returns>
        /// <exception cref="System.ObjectDisposedException">thrown if this object has been disposed.</exception>
        public GmmModel EstimateGmm(IDataset dataset)
        {
            ValidateDispose();
            var originalMz  = dataset.GetRawMzArray();
            var matlabModel = _gmm.estimate_gmm(originalMz, data: dataset.GetRawIntensities());
            var model       = new GmmModel(matlabModel, originalMz);

            return(model);
        }
Exemple #2
0
        /// <summary>
        /// Reduces the model filtering by height of the component.
        /// </summary>
        /// <param name="model">The reduced model.</param>
        /// <returns>Reduced model</returns>
        /// <exception cref="System.ObjectDisposedException">thrown if this object has been disposed.</exception>
        /// <exception cref="NotImplementedException">in any other case, as status of filtering threshold specification is unknown</exception>
        public GmmModel ReduceModelByComponentHeight(GmmModel model)
        {
            ValidateDispose();
            throw new NotImplementedException(message: nameof(GmmModelling.ReduceModelByComponentHeight)
                                              + " is not implemented.");

            // var matlabModel = model.MatlabStruct;
            //// @gmrukwa: this has an issue with opts.thr -> it must be defined, but no one knows how
            // var reduced = _gmm.reduce_gmm_by_component_height(matlabModel, model.OriginalMz, model.OriginalMeanSpectrum);
            // return new GmmModel(reduced, model) { IsNoiseReduced = true };
        }
Exemple #3
0
        /// <summary>
        /// Applies the GMM model onto data.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="dataset">Input dataset.</param>
        /// <returns>Convolved data.</returns>
        /// <exception cref="System.ObjectDisposedException">thrown if this object has been disposed.</exception>
        /// <exception cref="InvalidOperationException">Applying model build on different m/z axis.</exception>
        public IDataset ApplyGmm(GmmModel model, IDataset dataset)
        {
            ValidateDispose();
            if (!dataset.GetRawMzArray()
                .SequenceEqual(model.OriginalMz))
            {
                throw new InvalidOperationException(message: "Applying model built on different m/z axis.");
            }
            var matlabModel = model.MatlabStruct;
            var applyResult = _gmm.apply_gmm(matlabModel, data: dataset.GetRawIntensities(), mz: dataset.GetRawMzArray());
            var data        = (double[, ])((MWStructArray)model.MatlabStruct).GetField(fieldName: "mu");
            var mz          = new double[data.GetLength(dimension: 0)];

            Buffer.BlockCopy(data, srcOffset: 0, dst: mz, dstOffset: 0, count: data.GetLength(dimension: 0));
            return(new BasicTextDataset(mz, data: (double[, ])applyResult, coordinates: dataset.GetRawSpacialCoordinates(is2D: true)));
        }
Exemple #4
0
        /// <summary>
        /// Merges the components supposed to correspond to the same compound.
        /// </summary>
        /// <param name="model">The merged model.</param>
        /// <param name="mzThreshold">The mz threshold used for components matching.</param>
        /// <returns>Merged model</returns>
        /// <exception cref="System.InvalidOperationException">Applying merging on merged model.</exception>
        /// <exception cref="System.ObjectDisposedException">thrown if this object has been disposed.</exception>
        public GmmModel MergeComponents(GmmModel model, double mzThreshold = 0.3)
        {
            ValidateDispose();
            if (model.IsMerged)
            {
                throw new InvalidOperationException(message: "Applying merging on merged model.");
            }
            var matlabModel = model.MatlabStruct;
            var merged      = _gmm.merge_gmm_model_components(
                matlabModel,
                model.OriginalMz,
                model.OriginalMeanSpectrum,
                mzThreshold);

            return(new GmmModel(merged, model)
            {
                IsMerged = true, MzMergingThreshold = mzThreshold
            });
        }