Introduction to spant

Reading raw data and plotting

Load the spant package:

library(spant)

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.15614884
#> Asp     0.54809302
#> Cr      0.66327791
#> GABA    0.28180848
#> Glc     0.06746846
#> Gln     0.07453135
#> GSH     0.35689234
#> Glu     1.10359962
#> GPC     0.26459041
#> Ins     0.99277074
#> Lac     0.09734830
#> Lip09   0.37880005
#> Lip13a  0.04545743
#> Lip13b  0.00000000
#> Lip20   0.00000000
#> MM09    0.17194597
#> MM12    0.11370655
#> MM14    0.44453995
#> MM17    0.42554654
#> MM20    1.53642806
#> NAA     0.97179508
#> NAAG    0.27434701
#> PCh     0.00000000
#> PCr     0.33672209
#> sIns    0.10883989
#> Tau     0.00000000
#> tNAA    1.24614209
#> tCr     1.00000000
#> tCho    0.26459041
#> Glx     1.17813097
#> tLM09   0.55074602
#> tLM13   0.60370393
#> tLM20   1.53642806

Unscaled amplitudes, CRLB error estimates and other fitting diagnostics, such as SNR, are given in the results table:

fit_res$res_tab
#>   X Y Z Dynamic Coil X.CrCH2          Ala          Asp           Cr
#> 1 1 1 1       1    1       0 9.497446e-06 3.333668e-05 4.034257e-05
#>           GABA          Glc          Gln          GSH          Glu          GPC
#> 1 1.714045e-05 4.103636e-06 4.533223e-06 2.170727e-05 6.712427e-05 1.609319e-05
#>            Ins          Lac        Lip09       Lip13a Lip13b Lip20         MM09
#> 1 6.038333e-05 5.921019e-06 2.303977e-05 2.764859e-06      0     0 1.045828e-05
#>           MM12         MM14         MM17         MM20          NAA         NAAG
#> 1 6.915977e-06 2.703827e-05 2.588303e-05 9.345021e-05 5.910752e-05 1.668662e-05
#>   PCh          PCr         sIns Tau         tNAA          tCr         tCho
#> 1   0 2.048046e-05 6.619972e-06   0 7.579414e-05 6.082303e-05 1.609319e-05
#>           Glx        tLM09       tLM13        tLM20   X.CrCH2.sd       Ala.sd
#> 1 7.16575e-05 3.349804e-05 3.67191e-05 9.345021e-05 2.353862e-06 4.359105e-06
#>         Asp.sd        Cr.sd      GABA.sd      Glc.sd       Gln.sd       GSH.sd
#> 1 8.967177e-06 3.769575e-06 4.496012e-06 4.33038e-06 4.891685e-06 2.019976e-06
#>         Glu.sd       GPC.sd       Ins.sd       Lac.sd     Lip09.sd    Lip13a.sd
#> 1 4.911039e-06 2.340557e-06 2.023101e-06 5.343971e-06 4.067373e-06 1.338191e-05
#>      Lip13b.sd     Lip20.sd      MM09.sd      MM12.sd      MM14.sd      MM17.sd
#> 1 6.502037e-06 7.383161e-06 3.767184e-06 4.507066e-06 7.122518e-06 3.579251e-06
#>        MM20.sd       NAA.sd      NAAG.sd       PCh.sd       PCr.sd      sIns.sd
#> 1 8.280714e-06 1.021341e-06 1.289272e-06 1.998752e-06 3.162822e-06 7.079375e-07
#>         Tau.sd      tNAA.sd       tCr.sd     tCho.sd       Glx.sd     tLM09.sd
#> 1 3.741984e-06 7.137556e-07 5.844875e-07 2.12582e-07 2.883712e-06 9.731164e-07
#>       tLM13.sd     tLM20.sd    phase       lw        shift      asym
#> 1 1.520084e-06 2.886552e-06 10.83963 5.024142 -0.002971685 0.1771378
#>   res.deviance res.niter res.info
#> 1 7.455766e-05        27        2
#>                                                        res.message bl_ed_pppm
#> 1 Relative error between `par' and the solution is at most `ptol'.   1.969325
#>   max_bl_flex_used     full_res fit_pts ppm_range      SNR      SRR      FQN
#> 1            FALSE 8.202625e-05     497       3.8 63.23666 51.27882 1.520763
#>      tNAA_lw auto_bl_crit_7 auto_bl_crit_5.901 auto_bl_crit_4.942
#> 1 0.04585122      -8.872611          -8.918514          -8.954323
#>   auto_bl_crit_4.12 auto_bl_crit_3.425 auto_bl_crit_2.844 auto_bl_crit_2.364
#> 1         -8.980263           -8.99748          -9.009404          -9.017234
#>   auto_bl_crit_1.969 auto_bl_crit_1.647 auto_bl_crit_1.384 auto_bl_crit_1.17
#> 1          -9.020159          -9.008891          -8.957936         -8.841036
#>   auto_bl_crit_0.997 auto_bl_crit_0.856 auto_bl_crit_0.743 auto_bl_crit_0.654
#> 1          -8.684537          -8.555256          -8.478502          -8.441092
#>   auto_bl_crit_0.593 auto_bl_crit_0.558 auto_bl_crit_0.54 auto_bl_crit_0.532
#> 1          -8.424848          -8.418125         -8.415348          -8.414187
#>   auto_bl_crit_0.529
#> 1          -8.413697

Spectral SNR:

fit_res$res_tab$SNR
#> [1] 63.23666

Linewidth of the tNAA resonance in PPM:

fit_res$res_tab$tNAA_lw
#> [1] 0.04585122