Showing posts with label MRS. Show all posts
Showing posts with label MRS. Show all posts

Wednesday, 15 August 2012

MRS Voxel Registration

This describes the process of localising the actual voxel location used during the acquisition onto the participants FSPGR scan.  The output is a binary voxel mask, in the space of the FSPGR.   This can then be combined with outputs from segmentation (Fast) to calculate the tissue composition of the voxel (wm, gm, csf)

1) Copy native FSPGR dicoms

A copy of the native dicom files (dcm) is required as these contain the position information of the slices in the FSPGR.  The step to create the nifti removes these, so first a copy of the FSPGR dicoms should be made, e.g from the directory of the scan data;
cp Series_0000n FSPGR_dcm_folder
where n is the series number of the FSPGR.

2) Create FSPGR nifti

Then you need to create the FSPGR: go into the Series_0000n folder that contains the FSPGR scan by typing;
geprepfunct 172 1 [name of FSPGR]. 
 e.g.type:  geprepfunct  172  1 Subject1_FSPGR.nii.gz


3) Run VoxelOnFSPGR

Then, in Matlab, run the following function:

VoxelOnFSPGR(pfile, ImagingDataDirectory, MRS_Rot_folder,... FSPGR_dcm_folder, FSPGR_nifti)

VoxelOnFSPGR is in the same location as Gannet, so ensure that you have Gannet in your matlab path for this to work (/cubric/software/Gannet/GannetExtras).
e.g.
 VoxelOnFSPGR( ...
'~/mrs/somato_motor/data/3143_6_P12800.7', ...
'/cubric/home/sapje1/mrs/somato_motor/3143_081007-1', ...
 'Series_00005', ...
 'Series_00004_bak', ...
'fspgr.nii.gz')
Pfile = full path to pfile (e.g. '~/mrs/somato_motor/data/3143_6_P12800.7')

ImagingDirectory = the directory containing imaging data, unpacked by sortdicomball.  The directory '/cubric/home/sapje1/mrs/somato_motor/3143_081007-1' in the above example should contain the Series_00001, ... directories and the nifti FSPGR.

MRS_Rot_folder = folder containing the rotator/oblique localiser scan for the voxel, path from ImagingDirectory (e.g. ‘Series_00005’)

FSPGR_dcm_folder = folder containing the FSPGR native dicom files (e.g. Series_00004_bak')

FSPGR_nifti = the name of the FSPGR you created (e.g. ‘fspgr.nii.gz’)

This will create a voxel mask, in the FSPGR space, for the MRS voxel  and place it in a created directory named MRSVoxelReg. The filename is examnumber_series_Mask.nii.gz so e.g. 3999_08_Mask.nii.gz.

Below is a the output from VoxelOnFSPGR (e.g. 3999_08_Mask.nii.gz, but from an occipital voxel in this case) overlaid on the participant's FSPGR.





Wednesday, 16 May 2012

Gannet Analysis Pipeline Summary for CUBRIC


CJE 16 May 2012, but based very heavily on;

NP; March 2011; revised for new pipeline August 2011

Getting your data from the scanner

With MRS data; there are two different “types” of data you need: The p-files, which contain the spectra, and the dicom  data which contain the imaging data. These are saved separately.
P-files can be found in gpfs/mri/direct_transfer/spectro/ and then cd into the folder with your exam number in it (so for exam number 4236 go into the folder 4000). P-files are named examno_seriesno_pfileno.7 and to copy all the p-files from a session (in case of multiple scans) just type
cp –r examno* $path
Imaging data  (for segmentation) can be found in the normal MRI folder;
 /cubric/mri/direct_transfer/YEAR.
They can be unpacked using the sortdicomball command. Make sure you give it the full path.

Organising pfiles

This is very simple and there are very clear functions to use. The easiest thing is to have a document listing your p-files and commenting on their origin. How you do this is up to you but for an example for an .m file with your pfiles in it:
pfile_occ = {

‘2999_08_P00002.7’ %Subject 1, occipital
‘3000_07_P00003.7’ %Subject 2, occipital
‘3001_08_P00006.7’ %Subject 3, occipital
};

pfile_sensorimotor = {

‘2999_07_P00001.7’ %Subject 1, sensorimotor
‘3000_08_P00004.7’ %Subject 2, sensorimotor
‘3001_07_P00005.7’ %Subject 3, sensorimotor
};

Running the analysis

Add the following directories to your matlab path (with subdirectories);
    /cubric/software/matlab.versions/2012b/toolbox/stats
    /cubric/software/matlab.versions/2012b/toolbox/matlab/optimfun
Set the p-files (just run the file you made above) and then load the p-files using the command GannetLoad (just type help GannetLoad if needed). e.g.

[MRS_STRUCT] = GannetLoad(pfile_occ)

GannetLoad will load the pfiles and will give a whole range of output variables. Images will pop up for each pfile. These .pdf files are automatically saved in the folder MRSload_output.

-        The top left plot shows the GABA spectrum before (green line) and after (blue line) frequency realignment. Generally these are very similar.
-        The top right plot shows the drift in water frequency which can be an pseudo-indicator of motion. Any scan that are more than 2 standard deviations from the mean will be discarded (red circle)
-        The lower left plot shows the centre frequency of the Creatine peak before (top) and after realignment. Blue bard indicate scans that were rejected (same as the red circle).

Next you will want to fit the data by using GannetFit. This fits the GABA peak (with a Gaussian) and the Water peak (with a Voight lineshape) using Matlab's nonlinfit.

[MRS_STRUCT] = GannetFit(MRS_STRUCT)

Where the MRS_STRUCT behind brackets is the output from GannetLoad.  For each p-file separately it will plot: the full edited spectrum, GABA-peak and Water peak + their fit. This will spit out an .pdf file for each pfile as well (saved in MRSfit_date_timestamp in the folder you ran it from).
-        The top left plot shows the GABA peak (blue) and the fit (red) and the residuals.
-        The lower left plot shows the Water peak (blue) and fit (red) and its residuals.

When you look at MRS_STRUCT, you can see a whole range of different parameters.
-        MRS_STRUCT.gabaiu are your GABA concentration values in institutional units in the order you ran the pfiles in.
-        MRS_STRUCT.GABAIU_Error or .GABAFitError are the error of the GABA fit. .WaterFitError does the same for water.

Always inspect the outputs of GannetLoad and GannetFit for artefacts and spectral quality.

Note that for analysing  phantom data, use the equivalent commands GannetLoadPhantom and GannetFitPhantom.


Sunday, 29 April 2012

Gannet Version - CUBRIC


I've updated the MRS analysis code on the CUBRIC fileserver to the latest version of Gannet.  For those of you who will be using Gannet for the first time, the syntax is almost identical to the old MRSLoadPfiles and MRSGABAfit, albeit with a change in the function names (i.e. they now start with Gannet...).  There are instructions on the Gannet website;http://gabamrs.blogspot.co.uk/

The files are located in /cubric/software/Gannet, so put this at the top of your matlab path (add with subdirectories).  There are several old versions on the server (e.g. in /cubric/scratch), I have left these in place for the moment, but will eventually place these in a Gannet_history folder.

The version we have is a 'CUBRIC special'.  Not particularly special, really, but it has a scaling factor to get our 'institutional units' to be consistent with previously acquired data.  So, if you download the version from the Gannetwebsite, all values will be different by a constant scaling factor.

For those of you who have been using Gannet already, there is a slight change in the fitting range and changes to the way the code handles Siemens data, so no need to reanalyse.  For those who have used the December 2011 version of MRSload & MRSfit (with alignment on), again the changes are minor.  Attached are the correlations of the current Gannetversion with the first Gannet release (Feb) and the Dec 2011 version of MRSanalysis, based on 106 datasets over 3 voxels (occ, SM, DLPFC).  Overall the correlations are high R2>0.9, with differences being attributable to changes in the fitting limits and initial conditions of the fit (i.e. we are in the noise of the data, so different versions will result in slightly different results).