Learn R Programming

⚠️There's a newer version (3.4.0) of this package.Take me there.

spant (version 1.19.0)

MR Spectroscopy Analysis Tools

Description

Tools for reading, visualising and processing Magnetic Resonance Spectroscopy data. The package includes methods for spectral fitting: Wilson (2021) and spectral alignment: Wilson (2018) .

Copy Link

Version

Install

install.packages('spant')

Monthly Downloads

605

Version

1.19.0

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Martin Wilson

Last Published

February 14th, 2022

Functions in spant (1.19.0)

Arg.mrs_data

Apply Arg operator to an MRS dataset.
bbase

Generate a spline basis, slightly adapted from : "Splines, knots, and penalties", Eilers 2010.
align

Align spectra to a reference frequency using a convolution based method.
apodise_xy

Apodise MRSI data in the x-y direction with a k-space filter.
Conj.mrs_data

Apply Conj operator to an MRS dataset.
Ncoils

Return the total number of coil elements in an MRS dataset.
apply_mrs

Apply a function across given dimensions of a MRS data object.
apply_pvc

Convert default LCM/TARQUIN concentration scaling to molal units with partial volume correction.
Nx

Return the total number of x locations in an MRS dataset.
Ny

Return the total number of y locations in an MRS dataset.
bc_als

Baseline correction using the ALS method.
Nz

Return the total number of z locations in an MRS dataset.
Ndyns

Return the total number of dynamic scans in an MRS dataset.
Re.mrs_data

Apply Re operator to an MRS dataset.
calc_sd_poly

Perform a polynomial fit, subtract and return the standard deviation of the residuals.
calc_spec_diff

Calculate the sum of squares differences between two mrs_data objects.
Im.mrs_data

Apply Im operator to an MRS dataset.
Mod.mrs_data

Apply Mod operator to an MRS dataset.
array2mrs_data

Convert a 7 dimensional array in into a mrs_data object. The array dimensions should be ordered as : dummy, X, Y, Z, dynamic, coil, FID.
comb_coils

Combine coil data based on the first data point of a reference signal.
collapse_to_dyns

Collapse MRS data by concatenating spectra along the dynamic dimension.
check_tqn

Check the TARQUIN binary can be run
append_dyns

Append MRS data across the dynamic dimension, assumes they matched across the other dimensions.
acquire

Simulate pulse sequence acquisition.
add_noise

Add noise to an mrs_data object.
auto_phase

Perform zeroth-order phase correction based on the minimisation of the squared difference between the real and magnitude components of the spectrum.
circ_mask

Create a logical circular mask spanning the full extent of an n x n matrix.
calc_ed_from_lambda

Calculate the effective dimensions of a spline smoother from lambda.
decimate_mrs_td

Decimate an MRS signal by filtering in the time domain before downsampling.
elliptical_mask

Create an elliptical mask stored as a matrix of logical values.
est_noise_sd

Estimate the standard deviation of the noise from a segment of an mrs_data object.
def_N

Return the default number of data points in the spectral dimension.
append_basis

Combine a pair of basis set objects.
ft_shift

Perform a fft and ffshift on a vector.
ft_dyn

Apply the Fourier transform over the dynamic dimension.
apply_axes

Apply a function over specified array axes.
append_coils

Append MRS data across the coil dimension, assumes they matched across the other dimensions.
def_acq_paras

Return (and optionally modify using the input arguments) a list of the default acquisition parameters.
calc_coil_noise_sd

Calculate the noise standard deviation for each coil element.
calc_coil_noise_cor

Calculate the noise correlation between coil elements.
crop_spec

Crop mrs_data object based on a frequency range.
conv_mrs

Convolve two MRS data objects.
Npts

Return the number of data points in an MRS dataset.
get_2d_psf

Get the point spread function (PSF) for a 2D phase encoded MRSI scan.
def_fs

Return the default sampling frequency in Hz.
def_ref

Return the default reference value for ppm scale.
calc_spec_snr

Calculate the spectral SNR.
check_lcm

Check LCModel can be run
dicom_reader

A very simple DICOM reader.
calc_peak_info_vec

Calculate the FWHM of a peak from a vector of intensity values.
get_acq_paras

Return acquisition parameters from a MRS data object.
get_dyns

Extract a subset of dynamic scans.
get_even_dyns

Return even numbered dynamic scans starting from 1 (2,4,6...).
Nspec

Return the total number of spectra in an MRS dataset.
diff_mrs

Apply the diff operator to an MRS dataset in the FID/spectral dimension.
fit_mrs

Perform a fit based analysis of MRS data.
downsample_mrs_fd

Downsample an MRS signal by a factor of 2 using an FFT "brick-wall" filter.
fit_res2csv

Write fit results table to a csv file.
get_seg_ind

Get the indices of data points lying between two values (end > x > start).
get_sh_dyns

Return the second half of a dynamic series.
abfit_opts

Return a list of options for an ABfit analysis.
comb_fit_tables

Combine all fitting data points into a single data frame.
get_1h_brain_basis_paras_v2

Return a list of mol_parameter objects suitable for 1H brain MRS analyses.
get_1h_brain_basis_paras_v3

Return a list of mol_parameter objects suitable for 1H brain MRS analyses.
get_td_amp

Return an array of amplitudes derived from fitting the initial points in the time domain and extrapolating back to t=0.
abfit_opts_v1_9_0

Return a list of options for an ABfit analysis to maintain comparability with analyses performed with version 1.9.0 (and earlier) of spant.
back_extrap_ar

Back extrapolate time-domain data points using an autoregressive model.
get_tqn_cmd

Print the command to run the TARQUIN command-line program.
bc_constant

Remove a constant baseline offset based on a reference spectral region.
beta2lw

Covert a beta value in the time-domain to an equivalent linewidth in Hz: x * exp(-i * t * t * beta).
basis2mrs_data

Convert a basis object to an mrs_data object - where basis signals are spread across the dynamic dimension.
gridplot.mrs_data

Arrange spectral plots in a grid.
lw2beta

Covert a linewidth in Hz to an equivalent beta value in the time-domain ie: x * exp(-t * t * beta).
gridplot

Arrange spectral plots in a grid.
image.mrs_data

Image plot method for objects of class mrs_data.
img2kspace_xy

Transform 2D MRSI data to k-space in the x-y direction.
mask_dyns

Mask an MRS dataset in the dynamic dimension.
comb_fit_list_fit_tables

Combine all fitting data points from a list of fits into a single data frame.
get_fit_map

Get a data array from a fit result.
get_fh_dyns

Return the first half of a dynamic series.
mrs_data2mat

Convert mrs_data object to a matrix, with spectral points in the column dimension and dynamics in the row dimension.
get_voi_seg

Return the white matter, gray matter and CSF composition of a volume.
ift_shift

Perform an iffshift and ifft on a vector.
get_voi_seg_psf

Return the white matter, gray matter and CSF composition of a volume.
phase

Apply phasing parameters to MRS data.
mrs_data2vec

Convert mrs_data object to a vector.
comb_metab_ref

Combine a reference and metabolite mrs_data object.
comb_fit_list_result_tables

Combine the fit result tables from a list of fit results.
get_head_dyns

Return the first scans of a dynamic series.
get_lcm_cmd

Print the command to run the LCModel command-line program.
plot.fit_result

Plot the fitting results of an object of class fit_result.
get_odd_dyns

Return odd numbered dynamic scans starting from 1 (1,3,5...).
decimate_mrs_fd

Decimate an MRS signal to half the original sampling frequency by filtering in the frequency domain before down sampling.
crossprod_3d

Compute the vector cross product between vectors x and y. Adapted from http://stackoverflow.com/questions/15162741/what-is-rs-crossproduct-function
fp_phase

Return the phase of the first data point in the time-domain.
ft_shift_mat

Perform a fft and fftshift on a matrix with each column replaced by its shifted fft.
fp_phase_correct

Perform a zeroth order phase correction based on the phase of the first data point in the time-domain.
get_mol_paras

Get a mol_parameters object for a named molecule.
gausswin_2d

Create a two dimensional Gaussian window function stored as a matrix.
crop_xy

Crop an MRSI dataset in the x-y direction
crop_td_pts

Crop mrs_data object data points in the time-domain.
plot_slice_fit

Plot a 2D slice from an MRSI fit result object.
plot_slice_fit_inter

Plot a 2D slice from an MRSI fit result object.
int_spec

Integrate a spectral region.
ift_shift_mat

Perform an ifft and ifftshift on a matrix with each column replaced by its shifted ifft.
interleave_dyns

Interleave the first and second half of a dynamic series.
mean_dyns

Calculate the mean dynamic data.
mean_mrs_list

Return the mean of a list of mrs_data objects.
plot_slice_map

Plot a slice from a 7 dimensional array.
get_ref

Extract the reference component from an mrs_data object.
get_mrs_affine

Generate an affine for nifti generation.
def_ft

Return the default transmitter frequency in Hz.
def_nuc

Return the default nucleus.
hsvd_vec

HSVD of a complex vector.
ecc

Eddy current correction.
downsample_mrs_td

Downsample an MRS signal by a factor of 2 by removing every other data point in the time-domain. Note, signals outside the new sampling frequency will be aliased.
hz

Return the frequency scale of an MRS dataset in Hz.
fit_amps

Extract the fit amplitudes from an object of class fit_result.
hsvd

HSVD of an mrs_data object.
get_voi_cog

Calculate the centre of gravity for an image containing 0 and 1's.
get_uncoupled_mol

Generate a mol_parameters object for a simple spin system with one resonance.
plot_slice_map_inter

Plot an interactive slice map from a data array where voxels can be selected to display a corresponding spectrum.
read_mrs

Read MRS data from a file.
re_weighting

Apply a weighting to the FID to enhance spectral resolution.
hsvd_filt

HSVD based signal filter.
fit_diags

Calculate diagnostic information for object of class fit_result.
is.def

Check if an object is defined, which is the same as being not NULL.
get_1h_brain_basis_paras_v1

Return a list of mol_parameter objects suitable for 1H brain MRS analyses.
get_1h_brain_basis_paras

Return a list of mol_parameter objects suitable for 1H brain MRS analyses.
fd2td

Transform frequency-domain data to the time-domain.
is_fd

Check if the chemical shift dimension of an MRS data object is in the frequency domain.
mask_xy

Mask an MRSI dataset in the x-y direction
max_mrs_interp

Apply the max operator to an interpolated MRS dataset.
get_fp

Return the first time-domain data point.
get_mrsi2d_seg

Calculate the partial volume estimates for each voxel in a 2D MRSI dataset.
get_guassian_pulse

Generate a gaussian pulse shape.
mask_xy_mat

Mask a 2D MRSI dataset in the x-y dimension.
peak_info

Search for the highest peak in a spectral region and return the frequency, height and FWHM.
pg_extrap_xy

Papoulis-Gerchberg (PG) algorithm method for k-space extrapolation.
fp_scale

Scale the first time-domain data point in an mrs_data object.
fs

Return the sampling frequency in Hz of an MRS dataset.
fd_conv_filt

Frequency-domain convolution based filter.
mean.mrs_data

Calculate the mean spectrum from an mrs_data object.
get_mrsi_voi

Generate a MRSI VOI from an mrs_data object.
scale_mrs_amp

Scale an mrs_data object by a scalar or vector or amplitudes.
read_basis

Read a basis file in LCModel .basis format.
read_mrs_tqn

Read MRS data using the TARQUIN software package.
get_slice

Return a single slice from a larger MRSI dataset.
inv_even_dyns

Invert even numbered dynamic scans starting from 1 (2,4,6...).
get_subset

Extract a subset of MRS data.
seq_pulse_acquire

Simple pulse and acquire sequence with ideal pulses.
scale_spec

Scale mrs_data to a spectral region.
read_siemens_txt_hdr

Read the text format header found in Siemens IMA and TWIX data files.
seq_pulse_acquire_31p

Simple pulse and acquire sequence with ideal pulses.
ppm

Return the ppm scale of an MRS dataset or fit result.
precomp

Save function results to file and load on subsequent calls to avoid repeat computation.
median_dyns

Calculate the median dynamic data.
seq_spin_echo_ideal_31p

Spin echo sequence with ideal pulses.
seq_steam_ideal

STEAM sequence with ideal pulses.
scale_amp_molal_pvc

Apply partial volume correction to a fitting result object.
read_tqn_fit

Reader for csv fit results generated by TARQUIN.
mrs_data2basis

Convert an mrs_data object to basis object - where basis signals are spread across the dynamic dimension in the MRS data.
sd

Calculate the standard deviation spectrum from an mrs_data object.
sim_mol

Simulate a mol_parameter object.
scale_amp_molar

Apply water reference scaling to a fitting results object to yield metabolite quantities in millimolar (mM) units (mol/litre).
gen_F

Generate the F product operator.
gen_F_xy

Generate the Fxy product operator with a specified phase.
inv_odd_dyns

Invert odd numbered dynamic scans starting from 1 (1,3,5...).
get_mol_names

Return a character array of names that may be used with the get_mol_paras function.
get_mrsi_voxel

Generate a MRSI voxel from an mrs_data object.
get_metab

Extract the metabolite component from an mrs_data object.
read_basis_ac

Read a basis file in LCModel .basis format (for testing only).
sim_noise

Simulate an mrs_data object containing simulated Gaussian noise.
n2coord

Print fit coordinates from a single index.
nifti_flip_lr

Flip the x data dimension order of a nifti image. This corresponds to flipping MRI data in the left-right direction, assuming the data in save in neurological format (can check with fslorient program).
print.fit_result

Print a summary of an object of class fit_result.
sd.mrs_data

Calculate the standard deviation spectrum from an mrs_data object.
mat2mrs_data

Convert a matrix (with spectral points in the column dimension and dynamics in the row dimensions) into a mrs_data object.
print.mrs_data

Print a summary of mrs_data parameters.
set_lw

Apply line-broadening to an mrs_data object to achieve a specified linewidth.
set_mask_xy_mat

Set the masked voxels in a 2D MRSI dataset to given spectrum.
read_ima_coil_dir

Read a directory containing Siemens MRS IMA files and combine along the coil dimension. Note that the coil ID is inferred from the sorted file name and should be checked when consistency is required between two directories.
max_mrs

Apply the max operator to an MRS dataset.
sim_basis_tqn

Simulate a basis file using TARQUIN.
mean_dyn_blocks

Calculate the mean of adjacent dynamic scans.
qn_states

Get the quantum coherence matrix for a spin system.
get_mrsi_voxel_xy_psf

Generate a MRSI voxel PSF from an mrs_data object.
spant_abfit_benchmark

Simulate and fit some spectra with ABfit for benchmarking purposes. Basic timing and performance metrics will be printed.
rectangular_mask

Create a rectangular mask stored as a matrix of logical values.
rats

Robust Alignment to a Target Spectrum (RATS).
reexports

Objects exported from other packages
reslice_to_mrs

Reslice a nifti object to match the orientation of mrs data.
resample_voi

Resample a VOI to match a target image space using nearest-neighbour interpolation.
spant_mpress_drift

Example MEGA-PRESS data with significant B0 drift.
varpro_opts

Return a list of options for VARPRO based fitting.
rep_array_dim

Repeat an array over a given dimension.
vec2mrs_data

Convert a vector into a mrs_data object.
seconds

Return a time scale vector to match the FID of an MRS data object.
scale_amp_water_ratio

Scale metabolite amplitudes as a ratio to the unsuppressed water amplitude.
scale_amp_ratio

Scale fitted amplitudes to a ratio of signal amplitude.
seq_cpmg_ideal

CPMG style sequence with ideal pulses.
rep_dyn

Replicate a scan in the dynamic dimension.
mean_dyn_pairs

Calculate the pairwise means across a dynamic data set.
sim_brain_1h

Simulate MRS data with a similar appearance to normal brain (by default).
get_svs_voi

Generate a SVS acquisition volume from an mrs_data object.
sim_zero

Simulate an mrs_data object containing complex zero valued samples.
sim_resonances

Simulate a MRS data object containing a set of simulated resonances.
sum_coils

Calculate the sum across receiver coil elements.
svs_1h_brain_batch_analysis

Batch interface to the standard SVS 1H brain analysis pipeline.
sub_mean_dyns

Subtract the mean dynamic spectrum from a dynamic series.
plot.mrs_data

Plotting method for objects of class mrs_data.
plot_bc

Convenience function to plot a baseline estimate with the original data.
seq_press_ideal

PRESS sequence with ideal pulses.
seq_mega_press_ideal

MEGA-PRESS sequence with ideal localisation pulses and Gaussian shaped editing pulse.
set_def_acq_paras

Set the default acquisition parameters.
set_ref

Set the ppm reference value (eg ppm value at 0Hz).
plot_voi_overlay

Plot a volume as an image overlay.
td2fd

Transform time-domain data to the frequency-domain.
set_td_pts

Set the number of time-domain data points, truncating or zero-filling as appropriate.
get_tail_dyns

Return the last scans of a dynamic series.
read_lcm_coord

Read an LCModel formatted coord file containing fit information.
read_tqn_result

Reader for csv results generated by TARQUIN.
read_ima_dyn_dir

Read a directory containing Siemens MRS IMA files and combine along the dynamic dimension. Note that the coil ID is inferred from the sorted file name and should be checked when consistency is required.
plot_voi_overlay_seg

Plot a volume as an overlay on a segmented brain volume.
set_lcm_cmd

Set the command to run the LCModel command-line program.
sim_basis_1h_brain

Simulate a basis-set suitable for 1H brain MRS analysis acquired with a PRESS sequence. Note, ideal pulses are assumed.
sim_basis_1h_brain_press

Simulate a basis-set suitable for 1H brain MRS analysis acquired with a PRESS sequence. Note, ideal pulses are assumed.
spant_simulation_benchmark

Simulate a typical metabolite basis set for benchmarking. Timing metrics will be printed on completion.
spec_op

Perform a mathematical operation on a spectral region.
set_precomp_verbose

Set the verbosity of the precompute function.
recon_twix_2d_mrsi

Reconstruct 2D MRSI data from a twix file loaded with read_mrs.
set_precomp_mode

Set the precompute mode.
shift_basis

Apply frequency shifts to basis set signals.
sim_basis

Simulate a basis set object.
stackplot.fit_result

Plot the fitting results of an object of class fit_result with individual basis set components shown.
spant-package

spant: spectroscopy analysis tools.
svs_1h_brain_analysis

Standard SVS 1H brain analysis pipeline.
sort_basis

Sort the basis-set elements alphabetically.
sum_mrs_list

Return the sum of a list of mrs_data objects.
write_basis

Write a basis object to an LCModel .basis formatted file.
stackplot.mrs_data

Stackplot plotting method for objects of class mrs_data.
write_basis_tqn

Generate a basis file using TARQUIN.
zero_nzoc

Zero all non-zero-order coherences.
zero_fade_spec

Fade a spectrum to zero by frequency domain multiplication with a tanh function. Note this operation distorts data points at the end of the FID.
kspace2img_xy

Transform 2D MRSI data from k-space to image space in the x-y direction.
l2_reg

Perform l2 regularisation artefact suppression.
lb

Apply line-broadening (apodisation) to MRS data or basis object.
grid_shift_xy

Grid shift MRSI data in the x/y dimension.
get_voxel

Return a single voxel from a larger mrs dataset.
write_mrs

Write MRS data object to file.
write_mrs_nifti

Write MRS data object to file in NIFTI format.
set_tqn_cmd

Set the command to run the TARQUIN command-line program.
mvfftshift

Perform a fftshift on a matrix, with each column replaced by its shifted result.
mvifftshift

Perform an ifftshift on a matrix, with each column replaced by its shifted result.
lw2alpha

Covert a linewidth in Hz to an equivalent alpha value in the time-domain ie: x * exp(-t * alpha).
ortho3

Display an orthographic projection plot of a nifti object.
shift

Apply a frequency shift to MRS data.
sum_mrs

Sum two mrs_data objects.
sum_dyns

Calculate the sum of data dynamics.
varpro_3_para_opts

Return a list of options for VARPRO based fitting with 3 free parameters:
  • zero'th order phase correction

  • global damping

  • global frequency shift.

varpro_basic_opts

Return a list of options for a basic VARPRO analysis.
ortho3_inter

Display an interactive orthographic projection plot of a nifti object.
resample_img

Resample an image to match a target image space.
rep_mrs

Replicate a scan over a given dimension.
reson_table2mrs_data

Generate mrs_data from a table of single Lorentzian resonances.
spin_sys

Create a spin system object for pulse sequence simulation.
seq_spin_echo_ideal

Spin echo sequence with ideal pulses.
rm_dyns

Remove a subset of dynamic scans.
seq_slaser_ideal

sLASER sequence with ideal pulses.
spm_pve2categorical

Convert SPM style segmentation files to a single categorical image where the numerical values map as: 0) Other, 1) CSF, 2) GM and 3) WM.
ssp

Signal space projection method for lipid suppression.
stackplot

Produce a plot with multiple traces.
zf_xy

Zero-fill MRSI data in the k-space x-y direction.
td_conv_filt

Time-domain convolution based filter.
tdsr

Time-domain spectral registration.
zf

Zero-fill MRS data in the time domain.