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.15388523
#> Asp     0.54901288
#> Cr      0.66227394
#> GABA    0.27768834
#> Glc     0.06608352
#> Gln     0.07780192
#> GSH     0.35696175
#> Glu     1.10909460
#> GPC     0.26539787
#> Ins     0.99223315
#> Lac     0.09773823
#> Lip09   0.38611315
#> Lip13a  0.04661320
#> Lip13b  0.00000000
#> Lip20   0.00000000
#> MM09    0.16559633
#> MM12    0.11274444
#> MM14    0.44654610
#> MM17    0.42514400
#> MM20    1.55949315
#> NAA     0.98019279
#> NAAG    0.26060760
#> PCh     0.00000000
#> PCr     0.33772606
#> sIns    0.10907888
#> Tau     0.00000000
#> tNAA    1.24080039
#> tCr     1.00000000
#> tCho    0.26539787
#> Glx     1.18689652
#> tLM09   0.55170948
#> tLM13   0.60590374
#> tLM20   1.55949315

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         GABA
#> 1 1 1 1       1    1       0 9.343277e-06 3.33338e-05 4.021054e-05 1.686009e-05
#>            Glc          Gln          GSH          Glu          GPC          Ins
#> 1 4.012319e-06 4.723812e-06 2.167325e-05 6.733965e-05 1.611386e-05 6.024431e-05
#>            Lac       Lip09       Lip13a Lip13b Lip20         MM09         MM12
#> 1 5.934262e-06 2.34432e-05 2.830161e-06      0     0 1.005433e-05 6.845378e-06
#>           MM14         MM17         MM20          NAA         NAAG PCh
#> 1 2.711244e-05 2.581299e-05 9.468599e-05 5.951327e-05 1.582302e-05   0
#>            PCr        sIns Tau         tNAA          tCr         tCho
#> 1 2.050533e-05 6.62282e-06   0 7.533628e-05 6.071588e-05 1.611386e-05
#>            Glx        tLM09        tLM13        tLM20   X.CrCH2.sd       Ala.sd
#> 1 7.206346e-05 3.349753e-05 3.678798e-05 9.468599e-05 2.365865e-06 4.358582e-06
#>         Asp.sd        Cr.sd    GABA.sd       Glc.sd      Gln.sd      GSH.sd
#> 1 8.965961e-06 3.745162e-06 4.4433e-06 4.324165e-06 4.89224e-06 2.01775e-06
#>         Glu.sd       GPC.sd       Ins.sd       Lac.sd     Lip09.sd    Lip13a.sd
#> 1 4.904507e-06 2.485737e-06 2.021383e-06 5.353012e-06 4.069681e-06 1.340823e-05
#>      Lip13b.sd     Lip20.sd      MM09.sd      MM12.sd      MM14.sd      MM17.sd
#> 1 6.514835e-06 7.381739e-06 3.769421e-06 4.490832e-06 7.118536e-06 3.582287e-06
#>        MM20.sd       NAA.sd     NAAG.sd       PCh.sd      PCr.sd      sIns.sd
#> 1 8.255785e-06 1.018031e-06 1.23915e-06 2.126371e-06 3.16455e-06 7.094296e-07
#>         Tau.sd      tNAA.sd       tCr.sd      tCho.sd       Glx.sd     tLM09.sd
#> 1 3.714839e-06 7.075158e-07 5.852305e-07 2.122004e-07 2.894734e-06 9.740529e-07
#>       tLM13.sd     tLM20.sd    phase       lw        shift      asym
#> 1 1.527124e-06 2.881585e-06 10.68783 5.024704 -0.003553102 0.1745249
#>   res.deviance res.niter res.info
#> 1 7.468635e-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.218363e-05     497       3.8 63.11156 51.11143 1.52469
#>      tNAA_lw     tCr_lw    tCho_lw auto_bl_crit_7 auto_bl_crit_5.901
#> 1 0.04573569 0.05174082 0.05459451      -8.897184          -8.940906
#>   auto_bl_crit_4.942 auto_bl_crit_4.12 auto_bl_crit_3.425 auto_bl_crit_2.844
#> 1            -8.9744         -8.997882          -9.012253          -9.020869
#>   auto_bl_crit_2.364 auto_bl_crit_1.969 auto_bl_crit_1.647 auto_bl_crit_1.384
#> 1           -9.02583          -9.026291          -9.013371          -8.962017
#>   auto_bl_crit_1.17 auto_bl_crit_0.997 auto_bl_crit_0.856 auto_bl_crit_0.743
#> 1         -8.846433          -8.691287          -8.562194          -8.484756
#>   auto_bl_crit_0.654 auto_bl_crit_0.593 auto_bl_crit_0.558 auto_bl_crit_0.54
#> 1          -8.446477          -8.429617          -8.422562         -8.419628
#>   auto_bl_crit_0.532 auto_bl_crit_0.529
#> 1          -8.418397          -8.417877

Spectral SNR:

fit_res$res_tab$SNR
#> [1] 63.11156

Linewidth of the tNAA resonance in PPM:

fit_res$res_tab$tNAA_lw
#> [1] 0.04573569