/// <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); }
/// <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))); }
/// <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))); }
/// <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))); }
public void GetRawSpacialCoordinates() { double[] mz = { 1.0, 2.0, 3.0 }; double[,] data = { { 1, 1.1, 1.2 }, { 1, 1.1, 1.2 } }; int[,] coords = { { 1, 2, 3 }, { 4, 5, 6 } }; _dataset.CreateFromRawData(mz, data, coords); var retCoords3D = _dataset.GetRawSpacialCoordinates(is2D: false); Assert.AreEqual(retCoords3D, coords, message: "Dataset returned incorrect 3D spatial coordinates array."); var retCoords2D = _dataset.GetRawSpacialCoordinates(is2D: true); Assert.AreEqual(retCoords2D, actual: new[, ] { { 1, 2 }, { 4, 5 } }, message: "Dataset returned incorrect 2D spatial coordinates array."); }
/// <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))); }