Commit 905a4dd5 authored by Saad Jbabdi's avatar Saad Jbabdi
Browse files

tidying up - fsleyes was not loading so now just show the command

parent 89a3ed6d
......@@ -8,8 +8,8 @@
"\n",
"This notebook demos the process of fitting an MRSI scan using the command line scripts included in FSL-MRS.\n",
"### Contents: \n",
"- [1. Reconstruction, Processing and Data Conversion](#1.-Reconstruction,-Processing-and-Data-Conversion)\n",
"- [2. Fitting](#2.-Fitting)\n",
"- [1. Reconstruction, Processing and Data Conversion](#1.-Reconstruction,-processing-and-data-conversion)\n",
"- [2. Segmentation](#2.-Tissue-segmentation)\n",
"- [3. Fitting](#3.-Fitting)\n",
"- [4. Visualisation of fit](#4.-Visualisation-of-fit)\n",
"\n",
......@@ -39,27 +39,42 @@
"\n",
"Tissue segmentation is required to have meaningful scaling of water referenced metabolite concentrations. mrsi_segment will produce three files, corresponding to the GM, WM and CSF FAST tissue segmentations registered to the MRSI volume.\n",
"\n",
"Run tissue segmentation on the packaged T1 data and mask using the SVS voxel. Here we provide a (partial) .anat file produced by [fsl_anat](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat) to speed up execution.\n",
"Run tissue segmentation on the packaged T1 data and mask using the MRSI data file. Here we provide a (partial) .anat file produced by [fsl_anat](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat) to speed up execution.\n",
"\n",
"This step requires an installation of FSL compatible with fslpy."
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 6,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%capture\n",
"%sx mkdir MRSI\n",
"%sx mrsi_segment -o MRSI -a example_data/example_mrsi/T1.anat example_data/example_mrsi/FID_Metab.nii.gz"
"#%%capture\n",
"%sx mkdir -p MRSI\n",
"%sx mrsi_segment -o MRSI -a example_data/example_mrsi/T1.anat example_data/example_mrsi/mrsi.nii.gz"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Fitting"
"## 3. Fitting\n",
"\n",
"The below is a call to the main MRSI wrapper script. Not the use of the :code:`--add_MM` flag as this metabolite basis does not contain a macromolecule basis. Also note that the mrsi dataset provided is accompagnied by a JSON sidecar file which contains some useful information such as the echo time, the central frequency, and the dwell time.\n",
"\n",
"The script will by default run in parallel on the available CPU cores. Depending on hardware this should take a few minutes.\n"
]
},
{
......@@ -70,68 +85,7 @@
{
"data": {
"text/plain": [
"['',\n",
" '',\n",
" '',\n",
" '-----------------------------------------------------',\n",
" '',\n",
" '',\n",
" '',\n",
" '',\n",
" ' _____ ____ _ __ __ ____ ____ ___ ',\n",
" ' | ___/ ___|| | | \\\\/ | _ \\\\/ ___|_ _|',\n",
" ' | |_ \\\\___ \\\\| | _____| |\\\\/| | |_) \\\\___ \\\\| | ',\n",
" ' | _| ___) | |__|_____| | | | _ < ___) | | ',\n",
" ' |_| |____/|_____| |_| |_|_| \\\\_\\\\____/___|',\n",
" ' ',\n",
" ' ',\n",
" '',\n",
" '',\n",
" '',\n",
" '-----------------------------------------------------',\n",
" '',\n",
" '',\n",
" '',\n",
" '',\n",
" '--->> Start fitting',\n",
" '',\n",
" '',\n",
" ' Algorithm = [Newton]',\n",
" '',\n",
" ' Initialise with average fit',\n",
" ' Parallelising over 8 workers ',\n",
" ' 96 Voxels remaining ',\n",
" ' 96 Voxels remaining ',\n",
" ' 96 Voxels remaining ',\n",
" ' 96 Voxels remaining ',\n",
" ' 96 Voxels remaining ',\n",
" ' 96 Voxels remaining ',\n",
" ' 90 Voxels remaining ',\n",
" ' 72 Voxels remaining ',\n",
" ' 72 Voxels remaining ',\n",
" ' 72 Voxels remaining ',\n",
" ' 72 Voxels remaining ',\n",
" ' 72 Voxels remaining ',\n",
" ' 72 Voxels remaining ',\n",
" ' 48 Voxels remaining ',\n",
" ' 48 Voxels remaining ',\n",
" ' 48 Voxels remaining ',\n",
" ' 48 Voxels remaining ',\n",
" ' 48 Voxels remaining ',\n",
" ' 48 Voxels remaining ',\n",
" ' 48 Voxels remaining ',\n",
" ' 24 Voxels remaining ',\n",
" ' 24 Voxels remaining ',\n",
" ' 24 Voxels remaining ',\n",
" ' 24 Voxels remaining ',\n",
" ' 24 Voxels remaining ',\n",
" ' 24 Voxels remaining ',\n",
" '--->> Saving output files to MRSI/example_mrsi_fit',\n",
" '',\n",
" '',\n",
" '',\n",
" '',\n",
" 'Done.']"
"[]"
]
},
"execution_count": 13,
......@@ -147,8 +101,7 @@
" --h2o example_data/example_mrsi/wref.nii.gz \\\n",
" --tissue_frac MRSI/mrsi_seg_wm.nii.gz MRSI/mrsi_seg_gm.nii.gz MRSI/mrsi_seg_csf.nii.gz \\\n",
" --add_MM \\\n",
" --TE 30 \\\n",
" --baseline_order 4 \\\n",
" --baseline_order 2 \\\n",
" --combine PCho GPC --combine Cr PCr --combine NAA NAAG --combine Glu Gln --combine Glc Tau \\\n",
" --ignore Gly HG \\\n",
" --overwrite"
......@@ -159,38 +112,58 @@
"metadata": {},
"source": [
"## 4. Visualisation of fit\n",
"Now take a look at the outputs "
"\n",
"Now take a look at the outputs. A PNG of the fit to the average of all voxels is provided for a quick sanity check. The folders contain the following:\n",
"\n",
"- concs : concentration for each metabolite or combined metabolites (subfolders contain different types of referencing)\n",
"- fit : the model prediction FID, the residual FID, and the baseline (also in the time domain).\n",
"- qc : QC parameters split per metabolite\n",
"- uncertainties : the std of the fit per metabolite\n"
]
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['concs', 'fit', 'fit_avg.png', 'options.txt', 'qc', 'uncertainties']"
"['total 272',\n",
" 'drwxr-xr-x 6 saad staff 192 15 Jun 21:45 concs',\n",
" 'drwxr-xr-x 8 saad staff 256 15 Jun 21:45 fit',\n",
" '-rw-r--r-- 1 saad staff 134462 15 Jun 21:43 fit_avg.png',\n",
" '-rw-r--r-- 1 saad staff 1388 15 Jun 21:43 options.txt',\n",
" 'drwxr-xr-x 50 saad staff 1600 15 Jun 21:45 qc',\n",
" 'drwxr-xr-x 31 saad staff 992 15 Jun 21:45 uncertainties']"
]
},
"execution_count": 29,
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%sx ls MRSI/example_mrsi_fit"
"%sx ls -l MRSI/example_mrsi_fit"
]
},
{
"cell_type": "code",
"execution_count": 30,
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"%sx pythonw $(which fsleyes) example_data/example_mrsi/T1.anat/T1.nii.gz MRSI/example_mrsi_fit/fit/fit.nii.gz MRSI/example_mrsi_fit/concs/molarity/NAA+NAAG.nii.gz"
"Now run the command below in a terminal in order to load the data in FSLeyes. Follow the instructions [here](https://users.fmrib.ox.ac.uk/~saad/fsl_mrs/html/visualisation.html#fsleyes) to set it up in such a way that you can explore each voxel's individual fit.\n",
"\n",
"```\n",
"fsleyes example_data/example_mrsi/T1.anat/T1.nii.gz example_data/example_mrsi/mrsi.nii.gz MRSI/example_mrsi_fit/fit/fit.nii.gz MRSI/example_mrsi_fit/fit/baseline.nii.gz MRSI/example_mrsi_fit/concs/internal/NAA+NAAG.nii.gz\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
......@@ -209,7 +182,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
"version": "3.7.6"
}
},
"nbformat": 4,
......
%% Cell type:markdown id: tags:
# Example of MRSI fitting on the command line
This notebook demos the process of fitting an MRSI scan using the command line scripts included in FSL-MRS.
### Contents:
- [1. Reconstruction, Processing and Data Conversion](#1.-Reconstruction,-Processing-and-Data-Conversion)
- [2. Fitting](#2.-Fitting)
- [1. Reconstruction, Processing and Data Conversion](#1.-Reconstruction,-processing-and-data-conversion)
- [2. Segmentation](#2.-Tissue-segmentation)
- [3. Fitting](#3.-Fitting)
- [4. Visualisation of fit](#4.-Visualisation-of-fit)
Will Clarke
June 2020
University of Oxford
%% Cell type:markdown id: tags:
## 1. Reconstruction, processing and data conversion
MRSI reconstruction (from k-space data) can be highly specialised depending on the sequence. For example reconstruction of non-cartesian trajectories (e.g. spirals or concentric-rings) requires regridding or use of the NUFFT. Due to the specialised nature of MRSI reconstruction FSL-MRS does not contain tools for this step.
Simmilarly post-processing of MRSI data is commonly done as part of the reconstruction process. Though many of the processing tools in FSL-MRS can be run on MRSI data they have not been created with MRSI in mind.
This example therefore assumes that you are able to provide reconstructed and processed data ready for fitting. Data can be converted to NIfTI from the Siemens DICOM format using spec2nii. The authors of FSL-MRS and spec2nii are happy to add supported formats if example data and interpretation is provided.
%% Cell type:markdown id: tags:
## 2. Tissue segmentation
Tissue segmentation is required to have meaningful scaling of water referenced metabolite concentrations. mrsi_segment will produce three files, corresponding to the GM, WM and CSF FAST tissue segmentations registered to the MRSI volume.
Run tissue segmentation on the packaged T1 data and mask using the SVS voxel. Here we provide a (partial) .anat file produced by [fsl_anat](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat) to speed up execution.
Run tissue segmentation on the packaged T1 data and mask using the MRSI data file. Here we provide a (partial) .anat file produced by [fsl_anat](https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/fsl_anat) to speed up execution.
This step requires an installation of FSL compatible with fslpy.
%% Cell type:code id: tags:
``` python
%%capture
%sx mkdir MRSI
%sx mrsi_segment -o MRSI -a example_data/example_mrsi/T1.anat example_data/example_mrsi/FID_Metab.nii.gz
#%%capture
%sx mkdir -p MRSI
%sx mrsi_segment -o MRSI -a example_data/example_mrsi/T1.anat example_data/example_mrsi/mrsi.nii.gz
```
%%%% Output: execute_result
[]
%% Cell type:markdown id: tags:
## 3. Fitting
The below is a call to the main MRSI wrapper script. Not the use of the :code:`--add_MM` flag as this metabolite basis does not contain a macromolecule basis. Also note that the mrsi dataset provided is accompagnied by a JSON sidecar file which contains some useful information such as the echo time, the central frequency, and the dwell time.
The script will by default run in parallel on the available CPU cores. Depending on hardware this should take a few minutes.
%% Cell type:code id: tags:
``` python
%sx fsl_mrsi --data example_data/example_mrsi/mrsi.nii.gz \
--basis example_data/example_mrsi/3T_slaser_32vespa_1250.BASIS \
--output MRSI/example_mrsi_fit \
--mask example_data/example_mrsi/mask.nii.gz \
--h2o example_data/example_mrsi/wref.nii.gz \
--tissue_frac MRSI/mrsi_seg_wm.nii.gz MRSI/mrsi_seg_gm.nii.gz MRSI/mrsi_seg_csf.nii.gz \
--add_MM \
--TE 30 \
--baseline_order 4 \
--baseline_order 2 \
--combine PCho GPC --combine Cr PCr --combine NAA NAAG --combine Glu Gln --combine Glc Tau \
--ignore Gly HG \
--overwrite
```
%%%% Output: execute_result
['',
'',
'',
'-----------------------------------------------------',
'',
'',
'',
'',
' _____ ____ _ __ __ ____ ____ ___ ',
' | ___/ ___|| | | \\/ | _ \\/ ___|_ _|',
' | |_ \\___ \\| | _____| |\\/| | |_) \\___ \\| | ',
' | _| ___) | |__|_____| | | | _ < ___) | | ',
' |_| |____/|_____| |_| |_|_| \\_\\____/___|',
' ',
' ',
'',
'',
'',
'-----------------------------------------------------',
'',
'',
'',
'',
'--->> Start fitting',
'',
'',
' Algorithm = [Newton]',
'',
' Initialise with average fit',
' Parallelising over 8 workers ',
' 96 Voxels remaining ',
' 96 Voxels remaining ',
' 96 Voxels remaining ',
' 96 Voxels remaining ',
' 96 Voxels remaining ',
' 96 Voxels remaining ',
' 90 Voxels remaining ',
' 72 Voxels remaining ',
' 72 Voxels remaining ',
' 72 Voxels remaining ',
' 72 Voxels remaining ',
' 72 Voxels remaining ',
' 72 Voxels remaining ',
' 48 Voxels remaining ',
' 48 Voxels remaining ',
' 48 Voxels remaining ',
' 48 Voxels remaining ',
' 48 Voxels remaining ',
' 48 Voxels remaining ',
' 48 Voxels remaining ',
' 24 Voxels remaining ',
' 24 Voxels remaining ',
' 24 Voxels remaining ',
' 24 Voxels remaining ',
' 24 Voxels remaining ',
' 24 Voxels remaining ',
'--->> Saving output files to MRSI/example_mrsi_fit',
'',
'',
'',
'',
'Done.']
[]
%% Cell type:markdown id: tags:
## 4. Visualisation of fit
Now take a look at the outputs
Now take a look at the outputs. A PNG of the fit to the average of all voxels is provided for a quick sanity check. The folders contain the following:
- concs : concentration for each metabolite or combined metabolites (subfolders contain different types of referencing)
- fit : the model prediction FID, the residual FID, and the baseline (also in the time domain).
- qc : QC parameters split per metabolite
- uncertainties : the std of the fit per metabolite
%% Cell type:code id: tags:
``` python
%sx ls MRSI/example_mrsi_fit
%sx ls -l MRSI/example_mrsi_fit
```
%%%% Output: execute_result
['concs', 'fit', 'fit_avg.png', 'options.txt', 'qc', 'uncertainties']
['total 272',
'drwxr-xr-x 6 saad staff 192 15 Jun 21:45 concs',
'drwxr-xr-x 8 saad staff 256 15 Jun 21:45 fit',
'-rw-r--r-- 1 saad staff 134462 15 Jun 21:43 fit_avg.png',
'-rw-r--r-- 1 saad staff 1388 15 Jun 21:43 options.txt',
'drwxr-xr-x 50 saad staff 1600 15 Jun 21:45 qc',
'drwxr-xr-x 31 saad staff 992 15 Jun 21:45 uncertainties']
%% Cell type:markdown id: tags:
Now run the command below in a terminal in order to load the data in FSLeyes. Follow the instructions [here](https://users.fmrib.ox.ac.uk/~saad/fsl_mrs/html/visualisation.html#fsleyes) to set it up in such a way that you can explore each voxel's individual fit.
```
fsleyes example_data/example_mrsi/T1.anat/T1.nii.gz example_data/example_mrsi/mrsi.nii.gz MRSI/example_mrsi_fit/fit/fit.nii.gz MRSI/example_mrsi_fit/fit/baseline.nii.gz MRSI/example_mrsi_fit/concs/internal/NAA+NAAG.nii.gz
```
%% Cell type:code id: tags:
``` python
%%capture
%sx pythonw $(which fsleyes) example_data/example_mrsi/T1.anat/T1.nii.gz MRSI/example_mrsi_fit/fit/fit.nii.gz MRSI/example_mrsi_fit/concs/molarity/NAA+NAAG.nii.gz
```
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment