Reading raw data and plotting

Load the spant package:

Get the path to a data file included with spant:

fname <- system.file("extdata", "philips_spar_sdat_WS.SDAT", package = "spant")

Read the file and save to the workspace as mrs_data:

mrs_data <- read_mrs(fname, format = "spar_sdat")

Output some basic information about the data:

print(mrs_data)
#> MRS Data Parameters
#> ----------------------------------
#> Trans. freq (MHz)       : 127.7861
#> FID data points         : 1024
#> X,Y,Z dimensions        : 1x1x1
#> Dynamics                : 1
#> Coils                   : 1
#> Voxel resolution (mm)   : 20x20x20
#> Sampling frequency (Hz) : 2000
#> Reference freq. (ppm)   : 4.65
#> Nucleus                 : 1H
#> Spectral domain         : FALSE

Plot the spectral region between 5 and 0.5 ppm:

plot(mrs_data, xlim = c(5, 0.5))

Basic preprocessing

Apply a HSVD filter to the residual water region and align the spectrum to the tNAA resonance at 2.01 ppm:

mrs_proc <- hsvd_filt(mrs_data)
mrs_proc <- align(mrs_proc, 2.01)
plot(mrs_proc, xlim = c(5, 0.5))

Basis simulation

Simulate a typical basis set for short TE brain analysis, print some basic information and plot:

basis <- sim_basis_1h_brain_press(mrs_proc)
print(basis)
#> Basis set parameters
#> -------------------------------
#> Trans. freq (MHz)       : 127.786142
#> Data points             : 1024
#> Sampling frequency (Hz) : 2000
#> Elements                : 27
#> 
#> Names
#> -------------------------------
#> -CrCH2,Ala,Asp,Cr,GABA,Glc,Gln,
#> GSH,Glu,GPC,Ins,Lac,Lip09,
#> Lip13a,Lip13b,Lip20,MM09,MM12,
#> MM14,MM17,MM20,NAA,NAAG,PCh,
#> PCr,sIns,Tau
stackplot(basis, xlim = c(4, 0.5), labels = basis$names, y_offset = 5)

Perform ABfit analysis of the processed data (mrs_proc):

fit_res <- fit_mrs(mrs_proc, basis)

Plot the fit result:

plot(fit_res)

Extract the estimated amplitudes from fit_res and print as a ratio to total-creatine in column format:

amps <- fit_amps(fit_res)
print(t(amps / amps$tCr))
#>               [,1]
#> X.CrCH2 0.00000000
#> Ala     0.15663658
#> Asp     0.54833803
#> Cr      0.66324807
#> GABA    0.28230956
#> Glc     0.06748410
#> Gln     0.07438533
#> GSH     0.35698567
#> Glu     1.10361880
#> GPC     0.26453269
#> Ins     0.99280837
#> Lac     0.09736929
#> Lip09   0.37790173
#> Lip13a  0.04521650
#> Lip13b  0.00000000
#> Lip20   0.00000000
#> MM09    0.17303299
#> MM12    0.11402107
#> MM14    0.44451591
#> MM17    0.42597926
#> MM20    1.53481636
#> NAA     0.97041384
#> NAAG    0.27639433
#> PCh     0.00000000
#> PCr     0.33675193
#> sIns    0.10886098
#> Tau     0.00000000
#> tNAA    1.24680816
#> tCr     1.00000000
#> tCho    0.26453269
#> Glx     1.17800413
#> tLM09   0.55093472
#> tLM13   0.60375348
#> tLM20   1.53481636