/// <summary>
        ///     Performs DiviK clustering on the specified data.
        /// </summary>
        /// <param name="dataset">Input dataset.</param>
        /// <param name="options">Configuration.</param>
        /// <returns>Segmentation result.</returns>
        /// <exception cref="System.ObjectDisposedException">thrown if this object has been disposed.</exception>
        public DivikResult Divik(IDataset dataset, DivikOptions options)
        {
            // This is needed to not to make MCR go wild
            const int numberOfOutputArgs = 2;
            var       coordinates        = dataset.GetRawSpacialCoordinates(is2D: true);
            var       coords             = new double[coordinates.GetLength(dimension: 0), coordinates.GetLength(dimension: 1)];

            for (var i = 0; i < coordinates.GetLength(dimension: 0); ++i)
            {
                for (var j = 0; j < coordinates.GetLength(dimension: 1); ++j)
                {
                    coords[i, j] = coordinates[i, j];
                }
            }

            var varargin          = options.ToVarargin();
            var matlabDivikResult = _segmentation.divik(
                numberOfOutputArgs,
                dataset.GetRawIntensities(),
                coordinates,
                varargin);

            // matlabResult[0] is equal to the "partition" field in matlabResult[1], that's why we only use matlabResult[1]
            // Besides it helps to create recursive single constructor for DivikResult
            var result = new DivikResult(matlabResult: matlabDivikResult[Segmentation.DivikStructureLocation]);

            return(result);
        }
Exemplo n.º 2
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);
        }
        /// <summary>
        /// Normalizes dataset by TIC-based method.
        /// </summary>
        /// <param name="dataset">Input dataset.</param>
        /// <returns>Normalized dataset.</returns>
        /// <exception cref="System.ObjectDisposedException">thrown if this object has been disposed.</exception>
        public IDataset NormalizeByTic(IDataset dataset)
        {
            ValidateDispose();
            var normalizationResult = _preprocessing.ticnorm(data: dataset.GetRawIntensities());

            return(new BasicTextDataset(
                       mz: dataset.GetRawMzArray(),
                       data: (double[, ])normalizationResult,
                       coordinates: dataset.GetRawSpacialCoordinates(is2D: true)));
        }
Exemplo n.º 4
0
        public void GetRawIntensitiesTest()
        {
            var result = _dataset.GetRawIntensities();

            Assert.AreEqual(result,
                            actual: new[, ] {
                { 1, 2.1, 3.2 }, { 4, 5.1, 6.2 }, { 7, 8.1, 9.2 }
            },
                            message: "Dataset returned wrong intensity row.");
        }
        /// <summary>
        /// Removes the baseline.
        /// </summary>
        /// <param name="dataset">Input dataset.</param>
        /// <returns>Dataset without baseline.</returns>
        /// <exception cref="System.ObjectDisposedException">thrown if this object has been disposed.</exception>
        public IDataset RemoveBaseline(IDataset dataset)
        {
            ValidateDispose();
            var baselineRemovalResult =
                _preprocessing.remove_baseline(mz: dataset.GetRawMzArray(), data: dataset.GetRawIntensities());

            return(new BasicTextDataset(
                       mz: dataset.GetRawMzArray(),
                       data: (double[, ])baselineRemovalResult,
                       coordinates: dataset.GetRawSpacialCoordinates(is2D: true)));
        }
Exemplo n.º 6
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)));
        }
        /// <summary>
        /// Perform FFT-based peak alignment.
        /// </summary>
        /// <param name="dataset">Input dataset.</param>
        /// <returns>Aligned dataset.</returns>
        /// <exception cref="System.ObjectDisposedException">thrown if this object has been disposed.</exception>
        public IDataset AlignPeaksFft(IDataset dataset)
        {
            ValidateDispose();
            var pafftResult = _preprocessing.pafft(mz: dataset.GetRawMzArray(), data: dataset.GetRawIntensities());

            return(new BasicTextDataset(
                       mz: dataset.GetRawMzArray(),
                       data: (double[, ])pafftResult,
                       coordinates: dataset.GetRawSpacialCoordinates(is2D: true)));
        }