/// <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> /// 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 CreateFromFileTest() { Assert.DoesNotThrow(code: () => { _dataset = new BasicTextDataset(textFilePath: "small-test.txt"); }, message: "Dataset failed to initialize from file."); Assert.Throws <IOException>(code: () => { _dataset = new BasicTextDataset(textFilePath: "wrong-filepath.txt"); }, message: "Dataset has been initialized using wrong file path."); var coordinates = _dataset.SpatialCoordinates; var enumerator = coordinates.GetEnumerator(); enumerator.MoveNext(); var sc = enumerator.Current; Assert.AreEqual(expected: 1, actual: sc.X, message: "Spatial coordinates differ"); Assert.AreEqual(expected: 1, actual: sc.Y, message: "Spatial coordinates differ"); Assert.AreEqual(expected: 0, actual: sc.Z, message: "Spatial coordinates differ"); enumerator.MoveNext(); sc = enumerator.Current; Assert.AreEqual(expected: 2, actual: sc.X, message: "Spatial coordinates differ in second spectrum"); Assert.AreEqual(expected: 1, actual: sc.Y, message: "Spatial coordinates differ in second spectrum"); Assert.AreEqual(expected: 0, actual: sc.Z, message: "Spatial coordinates differ in second spectrum"); Assert.AreEqual(expected: _dataset.GetRawMzArray(), actual: new[] { 899.99, 902.58, 912.04 }, message: "The m/zs differ"); Assert.AreEqual(expected: _dataset.GetRawIntensityArray(spectrumIdx: 0), actual: new[] { 12.0, 20.0, 0.0 }, message: "The intensities of first spectrum differs"); }
/// <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))); }
/// <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))); }