Commit d712a597 authored by William Clarke's avatar William Clarke
Browse files

Final checks and update notebooks.

parent fba26ca8
......@@ -43,20 +43,9 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Contents of file: meas_MID310_STEAM_metab_FID115673.dat\n",
"The file contains these evalinfo flags with dimensions and sizes as follows:\n",
"image :\tCol, Cha, Set \t[4096 32 64]\n",
"phasecor :\tCol, Cha \t[4096 32]\n"
]
}
],
"outputs": [],
"source": [
"%%bash\n",
"\n",
......@@ -78,7 +67,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -92,156 +81,11 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"steam_ecc_raw.json\n",
"steam_ecc_raw.nii.gz\n",
"steam_metab_raw_Set000.json\n",
"steam_metab_raw_Set000.nii.gz\n",
"steam_metab_raw_Set001.json\n",
"steam_metab_raw_Set001.nii.gz\n",
"steam_metab_raw_Set002.json\n",
"steam_metab_raw_Set002.nii.gz\n",
"steam_metab_raw_Set003.json\n",
"steam_metab_raw_Set003.nii.gz\n",
"steam_metab_raw_Set004.json\n",
"steam_metab_raw_Set004.nii.gz\n",
"steam_metab_raw_Set005.json\n",
"steam_metab_raw_Set005.nii.gz\n",
"steam_metab_raw_Set006.json\n",
"steam_metab_raw_Set006.nii.gz\n",
"steam_metab_raw_Set007.json\n",
"steam_metab_raw_Set007.nii.gz\n",
"steam_metab_raw_Set008.json\n",
"steam_metab_raw_Set008.nii.gz\n",
"steam_metab_raw_Set009.json\n",
"steam_metab_raw_Set009.nii.gz\n",
"steam_metab_raw_Set010.json\n",
"steam_metab_raw_Set010.nii.gz\n",
"steam_metab_raw_Set011.json\n",
"steam_metab_raw_Set011.nii.gz\n",
"steam_metab_raw_Set012.json\n",
"steam_metab_raw_Set012.nii.gz\n",
"steam_metab_raw_Set013.json\n",
"steam_metab_raw_Set013.nii.gz\n",
"steam_metab_raw_Set014.json\n",
"steam_metab_raw_Set014.nii.gz\n",
"steam_metab_raw_Set015.json\n",
"steam_metab_raw_Set015.nii.gz\n",
"steam_metab_raw_Set016.json\n",
"steam_metab_raw_Set016.nii.gz\n",
"steam_metab_raw_Set017.json\n",
"steam_metab_raw_Set017.nii.gz\n",
"steam_metab_raw_Set018.json\n",
"steam_metab_raw_Set018.nii.gz\n",
"steam_metab_raw_Set019.json\n",
"steam_metab_raw_Set019.nii.gz\n",
"steam_metab_raw_Set020.json\n",
"steam_metab_raw_Set020.nii.gz\n",
"steam_metab_raw_Set021.json\n",
"steam_metab_raw_Set021.nii.gz\n",
"steam_metab_raw_Set022.json\n",
"steam_metab_raw_Set022.nii.gz\n",
"steam_metab_raw_Set023.json\n",
"steam_metab_raw_Set023.nii.gz\n",
"steam_metab_raw_Set024.json\n",
"steam_metab_raw_Set024.nii.gz\n",
"steam_metab_raw_Set025.json\n",
"steam_metab_raw_Set025.nii.gz\n",
"steam_metab_raw_Set026.json\n",
"steam_metab_raw_Set026.nii.gz\n",
"steam_metab_raw_Set027.json\n",
"steam_metab_raw_Set027.nii.gz\n",
"steam_metab_raw_Set028.json\n",
"steam_metab_raw_Set028.nii.gz\n",
"steam_metab_raw_Set029.json\n",
"steam_metab_raw_Set029.nii.gz\n",
"steam_metab_raw_Set030.json\n",
"steam_metab_raw_Set030.nii.gz\n",
"steam_metab_raw_Set031.json\n",
"steam_metab_raw_Set031.nii.gz\n",
"steam_metab_raw_Set032.json\n",
"steam_metab_raw_Set032.nii.gz\n",
"steam_metab_raw_Set033.json\n",
"steam_metab_raw_Set033.nii.gz\n",
"steam_metab_raw_Set034.json\n",
"steam_metab_raw_Set034.nii.gz\n",
"steam_metab_raw_Set035.json\n",
"steam_metab_raw_Set035.nii.gz\n",
"steam_metab_raw_Set036.json\n",
"steam_metab_raw_Set036.nii.gz\n",
"steam_metab_raw_Set037.json\n",
"steam_metab_raw_Set037.nii.gz\n",
"steam_metab_raw_Set038.json\n",
"steam_metab_raw_Set038.nii.gz\n",
"steam_metab_raw_Set039.json\n",
"steam_metab_raw_Set039.nii.gz\n",
"steam_metab_raw_Set040.json\n",
"steam_metab_raw_Set040.nii.gz\n",
"steam_metab_raw_Set041.json\n",
"steam_metab_raw_Set041.nii.gz\n",
"steam_metab_raw_Set042.json\n",
"steam_metab_raw_Set042.nii.gz\n",
"steam_metab_raw_Set043.json\n",
"steam_metab_raw_Set043.nii.gz\n",
"steam_metab_raw_Set044.json\n",
"steam_metab_raw_Set044.nii.gz\n",
"steam_metab_raw_Set045.json\n",
"steam_metab_raw_Set045.nii.gz\n",
"steam_metab_raw_Set046.json\n",
"steam_metab_raw_Set046.nii.gz\n",
"steam_metab_raw_Set047.json\n",
"steam_metab_raw_Set047.nii.gz\n",
"steam_metab_raw_Set048.json\n",
"steam_metab_raw_Set048.nii.gz\n",
"steam_metab_raw_Set049.json\n",
"steam_metab_raw_Set049.nii.gz\n",
"steam_metab_raw_Set050.json\n",
"steam_metab_raw_Set050.nii.gz\n",
"steam_metab_raw_Set051.json\n",
"steam_metab_raw_Set051.nii.gz\n",
"steam_metab_raw_Set052.json\n",
"steam_metab_raw_Set052.nii.gz\n",
"steam_metab_raw_Set053.json\n",
"steam_metab_raw_Set053.nii.gz\n",
"steam_metab_raw_Set054.json\n",
"steam_metab_raw_Set054.nii.gz\n",
"steam_metab_raw_Set055.json\n",
"steam_metab_raw_Set055.nii.gz\n",
"steam_metab_raw_Set056.json\n",
"steam_metab_raw_Set056.nii.gz\n",
"steam_metab_raw_Set057.json\n",
"steam_metab_raw_Set057.nii.gz\n",
"steam_metab_raw_Set058.json\n",
"steam_metab_raw_Set058.nii.gz\n",
"steam_metab_raw_Set059.json\n",
"steam_metab_raw_Set059.nii.gz\n",
"steam_metab_raw_Set060.json\n",
"steam_metab_raw_Set060.nii.gz\n",
"steam_metab_raw_Set061.json\n",
"steam_metab_raw_Set061.nii.gz\n",
"steam_metab_raw_Set062.json\n",
"steam_metab_raw_Set062.nii.gz\n",
"steam_metab_raw_Set063.json\n",
"steam_metab_raw_Set063.nii.gz\n",
"steam_wref_comb_raw_Rep000.json\n",
"steam_wref_comb_raw_Rep000.nii.gz\n",
"steam_wref_comb_raw_Rep001.json\n",
"steam_wref_comb_raw_Rep001.nii.gz\n",
"steam_wref_quant_raw_Rep000.json\n",
"steam_wref_quant_raw_Rep000.nii.gz\n",
"steam_wref_quant_raw_Rep001.json\n",
"steam_wref_quant_raw_Rep001.nii.gz\n"
]
}
],
"outputs": [],
"source": [
"%%bash\n",
"# Check the content of the output folder\n",
......@@ -279,16 +123,15 @@
"7. Run HLSVD on the data to remove the residual water in the water suppressed data.\n",
"6. Phase the data by a single peak as a crude zero-order phase correction.\n",
"\n",
"Note that the \"%%capture\" and \"%sx\" commands are only required in this example notebook and are unecessary on the command line."
"Note that the \"%sx\" command is only required in this example notebook and are unecessary on the command line."
]
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"import os\n",
"if not os.path.isdir('fsl_mrs_proc'):\n",
" os.mkdir('fsl_mrs_proc')\n",
......@@ -302,7 +145,7 @@
"%sx fsl_mrs_proc coilcombine --file data/steam_ecc_raw.nii.gz --reference fsl_mrs_proc/steam_wref_comb.nii.gz --output fsl_mrs_proc \n",
"\n",
"#3. Align averages of water ref and metab data\n",
"%sx fsl_mrs_proc align --file fsl_mrs_proc/steam_metab_raw*.nii.gz --ppm 1.8 3.5 --output fsl_mrs_proc -r --filename steam_metab_align \n",
"%sx fsl_mrs_proc align --file fsl_mrs_proc/steam_metab_raw*.nii.gz --ppm 1.8 3.5 --output fsl_mrs_proc -r --filename steam_metab_align --apod 50 \n",
"%sx fsl_mrs_proc align --file fsl_mrs_proc/steam_wref_quant_raw*.nii.gz --ppm 4 6 --output fsl_mrs_proc --filename steam_water_align \n",
"\n",
"#3. Combine data across averages\n",
......@@ -334,11 +177,10 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"%sx merge_mrs_reports -d CMD_line_test -o fsl_mrs_proc --delete fsl_mrs_proc/*.html "
]
},
......@@ -352,13 +194,12 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"%%capture\n",
"%sx fsl_mrs_preproc --output fsl_mrs_preproc --data data/steam_metab_raw*.nii.gz --reference data/steam_wref_comb_raw*.nii.gz --quant data/steam_wref_quant_raw*.nii.gz --ecc data/steam_ecc_raw.nii.gz --hlsvd --leftshift 1 --t1 example_data/T1_biascorr.nii.gz --overwrite --report \n",
"\n",
"# You can also run this script without independent quant and ecc data (just 1 water reference)\n",
......@@ -377,20 +218,9 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['CSF: 0.12, GM: 0.39, WM: 0.49.']"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"%sx svs_segment -a example_data/T1.anat fsl_mrs_proc/metab.nii.gz"
]
......@@ -405,13 +235,12 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%capture\n",
"# Quick fit \n",
"%sx fsl_mrs --data fsl_mrs_preproc/metab.nii --basis example_data/steam_11ms --output fit_short --metab_groups Mac --overwrite --report --t1 example_data/T1.anat/T1_biascorr.nii.gz --h2o fsl_mrs_preproc/wref.nii --tissue_frac segmentation.json\n",
"%sx fsl_mrs --data fsl_mrs_preproc/metab.nii.gz --basis example_data/steam_11ms --output fit_short --metab_groups Mac --overwrite --report --t1 example_data/T1.anat/T1_biascorr.nii.gz --h2o fsl_mrs_preproc/wref.nii.gz --tissue_frac segmentation.json\n",
"\n"
]
},
......@@ -424,24 +253,12 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[]"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"%%capture\n",
"# Full fit \n",
"%sx fsl_mrs --data fsl_mrs_preproc/metab.nii --basis example_data/steam_11ms --output fit_long --algo MH --metab_groups Mac --overwrite --report --t1 example_data/T1.anat/T1_biascorr.nii.gz --h2o fsl_mrs_preproc/wref.nii --tissue_frac segmentation.json\n"
"%sx fsl_mrs --data fsl_mrs_preproc/metab.nii.gz --basis example_data/steam_11ms --output fit_long --algo MH --metab_groups Mac --overwrite --report --t1 example_data/T1.anat/T1_biascorr.nii.gz --h2o fsl_mrs_preproc/wref.nii.gz --tissue_frac segmentation.json\n"
]
},
{
......@@ -454,7 +271,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
......@@ -488,7 +305,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
"version": "3.7.7"
}
},
"nbformat": 4,
......
%% Cell type:markdown id: tags:
# Example of SVS processing on the command line
%% Cell type:markdown id: tags:
This notebook demos the process of fitting a single voxel scan using the command line scripts included in FSL MRS.
### Contents:
- [1. File conversion using spec2nii](#1.-File-conversion-using-spec2nii)
- [2. Preprocessing in two ways](#2.-Preprocessing-of-the-data)
- [2.1. Using individual fsl_mrs_proc commands](#2.1-Pre-processing-using-fsl_mrs_proc)
- [2.2. In one step using the script fsl_mrs_preproc](#2.2-Pre-processing-using-fsl_mrs_preproc)
- [3. Tissue segmentation](#3.-Run-tissue-segmentation)
- [4. Fitting of the resultant spectrum](#4.-Fit-the-data)
- [5. Display the fitting reports](#5.-Display-the-result)
Will Clarke
June 2020
University of Oxford
%% Cell type:markdown id: tags:
## 1. File conversion using spec2nii
Run spec2nii twix -v to establish the file contents, then using this information run spec2nii twix -e with the appropriate flags to extract the required scans.
The -j option causes a JSON side-car file to be generated. The -q flag suppresses text output.
This dataset uses a modified versions of the cmrr spectro package sequences on a siemens scanner. It has three sets of water reference scans. The first is taged as a phase correction, iscollected at the start of the main suppressed water scan and will be used for eddy current correction.
The second is collected in a separate scan with only the RF portion of the water suppression disabled. This is used for coil combination (and could be used for eddy current correction). The third is collected with the OVS and all aspects of the water suppression disabled. It therefore experiences eddy currents unlike all the other scans. It will be used for final concentration scaling.
%% Cell type:code id: tags:
``` python
%%bash
spec2nii twix -v -q example_data/meas_MID310_STEAM_metab_FID115673.dat
```
%%%% Output: stream
Contents of file: meas_MID310_STEAM_metab_FID115673.dat
The file contains these evalinfo flags with dimensions and sizes as follows:
image : Col, Cha, Set [4096 32 64]
phasecor : Col, Cha [4096 32]
%% Cell type:markdown id: tags:
From the final lines of the output of the first cell we can see that this "twix" file contains two groups of data.
The first is tagged as "image" and contains 64 repetitions (sets) of 4096 point FIDs collected on 32 channels.
The second has a single FID on each channel.
We now call spec2nii again specifying the group we want to extract each time. spec2nii will generate a NIfTI file for each repetition (set) with a size of 1x1x1x4096x32.
We repeat this for the water reference scans, extracting just the image data.
%% Cell type:code id: tags:
``` python
%%bash
spec2nii twix -e image -f steam_metab_raw -o data -j -q example_data/meas_MID310_STEAM_metab_FID115673.dat
spec2nii twix -e phasecor -f steam_ecc_raw -o data -j -q example_data/meas_MID310_STEAM_metab_FID115673.dat
spec2nii twix -e image -f steam_wref_comb_raw -o data -j -q example_data/meas_MID311_STEAM_wref1_FID115674.dat
spec2nii twix -e image -f steam_wref_quant_raw -o data -j -q example_data/meas_MID312_STEAM_wref3_FID115675.dat
```
%% Cell type:code id: tags:
``` python
%%bash
# Check the content of the output folder
ls data
```
%%%% Output: stream
steam_ecc_raw.json
steam_ecc_raw.nii.gz
steam_metab_raw_Set000.json
steam_metab_raw_Set000.nii.gz
steam_metab_raw_Set001.json
steam_metab_raw_Set001.nii.gz
steam_metab_raw_Set002.json
steam_metab_raw_Set002.nii.gz
steam_metab_raw_Set003.json
steam_metab_raw_Set003.nii.gz
steam_metab_raw_Set004.json
steam_metab_raw_Set004.nii.gz
steam_metab_raw_Set005.json
steam_metab_raw_Set005.nii.gz
steam_metab_raw_Set006.json
steam_metab_raw_Set006.nii.gz
steam_metab_raw_Set007.json
steam_metab_raw_Set007.nii.gz
steam_metab_raw_Set008.json
steam_metab_raw_Set008.nii.gz
steam_metab_raw_Set009.json
steam_metab_raw_Set009.nii.gz
steam_metab_raw_Set010.json
steam_metab_raw_Set010.nii.gz
steam_metab_raw_Set011.json
steam_metab_raw_Set011.nii.gz
steam_metab_raw_Set012.json
steam_metab_raw_Set012.nii.gz
steam_metab_raw_Set013.json
steam_metab_raw_Set013.nii.gz
steam_metab_raw_Set014.json
steam_metab_raw_Set014.nii.gz
steam_metab_raw_Set015.json
steam_metab_raw_Set015.nii.gz
steam_metab_raw_Set016.json
steam_metab_raw_Set016.nii.gz
steam_metab_raw_Set017.json
steam_metab_raw_Set017.nii.gz
steam_metab_raw_Set018.json
steam_metab_raw_Set018.nii.gz
steam_metab_raw_Set019.json
steam_metab_raw_Set019.nii.gz
steam_metab_raw_Set020.json
steam_metab_raw_Set020.nii.gz
steam_metab_raw_Set021.json
steam_metab_raw_Set021.nii.gz
steam_metab_raw_Set022.json
steam_metab_raw_Set022.nii.gz
steam_metab_raw_Set023.json
steam_metab_raw_Set023.nii.gz
steam_metab_raw_Set024.json
steam_metab_raw_Set024.nii.gz
steam_metab_raw_Set025.json
steam_metab_raw_Set025.nii.gz
steam_metab_raw_Set026.json
steam_metab_raw_Set026.nii.gz
steam_metab_raw_Set027.json
steam_metab_raw_Set027.nii.gz
steam_metab_raw_Set028.json
steam_metab_raw_Set028.nii.gz
steam_metab_raw_Set029.json
steam_metab_raw_Set029.nii.gz
steam_metab_raw_Set030.json
steam_metab_raw_Set030.nii.gz
steam_metab_raw_Set031.json
steam_metab_raw_Set031.nii.gz
steam_metab_raw_Set032.json
steam_metab_raw_Set032.nii.gz
steam_metab_raw_Set033.json
steam_metab_raw_Set033.nii.gz
steam_metab_raw_Set034.json
steam_metab_raw_Set034.nii.gz
steam_metab_raw_Set035.json
steam_metab_raw_Set035.nii.gz
steam_metab_raw_Set036.json
steam_metab_raw_Set036.nii.gz
steam_metab_raw_Set037.json
steam_metab_raw_Set037.nii.gz
steam_metab_raw_Set038.json
steam_metab_raw_Set038.nii.gz
steam_metab_raw_Set039.json
steam_metab_raw_Set039.nii.gz
steam_metab_raw_Set040.json
steam_metab_raw_Set040.nii.gz
steam_metab_raw_Set041.json
steam_metab_raw_Set041.nii.gz
steam_metab_raw_Set042.json
steam_metab_raw_Set042.nii.gz
steam_metab_raw_Set043.json
steam_metab_raw_Set043.nii.gz
steam_metab_raw_Set044.json
steam_metab_raw_Set044.nii.gz
steam_metab_raw_Set045.json
steam_metab_raw_Set045.nii.gz
steam_metab_raw_Set046.json
steam_metab_raw_Set046.nii.gz
steam_metab_raw_Set047.json
steam_metab_raw_Set047.nii.gz
steam_metab_raw_Set048.json
steam_metab_raw_Set048.nii.gz
steam_metab_raw_Set049.json
steam_metab_raw_Set049.nii.gz
steam_metab_raw_Set050.json
steam_metab_raw_Set050.nii.gz
steam_metab_raw_Set051.json
steam_metab_raw_Set051.nii.gz
steam_metab_raw_Set052.json
steam_metab_raw_Set052.nii.gz
steam_metab_raw_Set053.json
steam_metab_raw_Set053.nii.gz
steam_metab_raw_Set054.json
steam_metab_raw_Set054.nii.gz
steam_metab_raw_Set055.json
steam_metab_raw_Set055.nii.gz
steam_metab_raw_Set056.json
steam_metab_raw_Set056.nii.gz
steam_metab_raw_Set057.json
steam_metab_raw_Set057.nii.gz
steam_metab_raw_Set058.json
steam_metab_raw_Set058.nii.gz
steam_metab_raw_Set059.json
steam_metab_raw_Set059.nii.gz
steam_metab_raw_Set060.json
steam_metab_raw_Set060.nii.gz
steam_metab_raw_Set061.json
steam_metab_raw_Set061.nii.gz
steam_metab_raw_Set062.json
steam_metab_raw_Set062.nii.gz
steam_metab_raw_Set063.json
steam_metab_raw_Set063.nii.gz
steam_wref_comb_raw_Rep000.json
steam_wref_comb_raw_Rep000.nii.gz
steam_wref_comb_raw_Rep001.json
steam_wref_comb_raw_Rep001.nii.gz
steam_wref_quant_raw_Rep000.json
steam_wref_quant_raw_Rep000.nii.gz
steam_wref_quant_raw_Rep001.json
steam_wref_quant_raw_Rep001.nii.gz
%% Cell type:markdown id: tags:
After conversion we have 64 averages from the suppressed water scan. The "Set" descriptor at the end of the file name arises from the indexing loop used at acquisition time to store the data. This is likely to vary from sequence to sequence, and is the choice of the pulse sequence programmer. Multiple looping indicies might be used for more complex data acquisition strategies.
We also have one ecc scan, and two "Reps" (another looping index) of each of the water reference scans. In this case both Set and Rep are used to indicate transients that should be averaged toghether.
Notice that each NIfTI file is paired witht a JSON sidecar file which contains useful information for further processing.
%% Cell type:markdown id: tags:
## 2. Preprocessing of the data
### 2.1 Pre-processing using fsl_mrs_proc
In this section we will preprocess the data using individual subcommands of the fsl_mrs_proc script to preprocess step-by-step. This example could be used as a template to construct your own preprocessing script in either python or another batch processing script (e.g. bash).
#### Description of steps
1. Take averages of water references used for combination across files
2. Coil combine the metab data, the ecc data and the quantification data using the "comb" data as the reference.
3. Phase and frequency align the data where there are multiple transients.
4. Combine data across those transients (one in each file) by taking the mean.
5. Run eddy current correction using the appropriate reference.
6. In this data an additional FID point is collected before the echo centre. Remove this.
7. Run HLSVD on the data to remove the residual water in the water suppressed data.
6. Phase the data by a single peak as a crude zero-order phase correction.
Note that the "%%capture" and "%sx" commands are only required in this example notebook and are unecessary on the command line.
Note that the "%sx" command is only required in this example notebook and are unecessary on the command line.
%% Cell type:code id: tags:
``` python
%%capture
import os
if not os.path.isdir('fsl_mrs_proc'):
os.mkdir('fsl_mrs_proc')
#1. Combine comb water data across files
%sx fsl_mrs_proc average --file data/steam_wref_comb_raw*.nii.gz --avgfiles --output fsl_mrs_proc --filename steam_wref_comb
#2. Run coil combination on the three sets of data
%sx fsl_mrs_proc coilcombine --file data/steam_metab_raw*.nii.gz --reference fsl_mrs_proc/steam_wref_comb.nii.gz --output fsl_mrs_proc -r
%sx fsl_mrs_proc coilcombine --file data/steam_wref_quant_raw*.nii.gz --reference fsl_mrs_proc/steam_wref_comb.nii.gz --output fsl_mrs_proc
%sx fsl_mrs_proc coilcombine --file data/steam_ecc_raw.nii.gz --reference fsl_mrs_proc/steam_wref_comb.nii.gz --output fsl_mrs_proc
#3. Align averages of water ref and metab data
%sx fsl_mrs_proc align --file fsl_mrs_proc/steam_metab_raw*.nii.gz --ppm 1.8 3.5 --output fsl_mrs_proc -r --filename steam_metab_align
%sx fsl_mrs_proc align --file fsl_mrs_proc/steam_metab_raw*.nii.gz --ppm 1.8 3.5 --output fsl_mrs_proc -r --filename steam_metab_align --apod 50
%sx fsl_mrs_proc align --file fsl_mrs_proc/steam_wref_quant_raw*.nii.gz --ppm 4 6 --output fsl_mrs_proc --filename steam_water_align
#3. Combine data across averages
%sx fsl_mrs_proc average --file fsl_mrs_proc/steam_metab_align*.nii.gz --avgfiles --output fsl_mrs_proc -r --filename steam_metab_comb
%sx fsl_mrs_proc average --file fsl_mrs_proc/steam_water_align*.nii.gz --avgfiles --output fsl_mrs_proc --filename steam_wquant_comb
#5. Run the eddy current correction on the data
%sx fsl_mrs_proc ecc --file fsl_mrs_proc/steam_metab_comb.nii.gz --reference fsl_mrs_proc/steam_ecc_raw.nii.gz --output fsl_mrs_proc -r --filename steam_metab_comb_ecc
%sx fsl_mrs_proc ecc --file fsl_mrs_proc/steam_wquant_comb.nii.gz --reference fsl_mrs_proc/steam_wquant_comb.nii.gz --output fsl_mrs_proc --filename steam_wquant_comb_ecc
#6. Remove the first FID point
%sx fsl_mrs_proc truncate --file fsl_mrs_proc/steam_metab_comb_ecc.nii.gz --points -1 --pos first --output fsl_mrs_proc -r
%sx fsl_mrs_proc truncate --file fsl_mrs_proc/steam_wquant_comb_ecc.nii.gz --points -1 --pos first --output fsl_mrs_proc
#7. Run HLSVD on the data
%sx fsl_mrs_proc remove --file fsl_mrs_proc/steam_metab_comb_ecc.nii.gz --output fsl_mrs_proc -r --filename steam_metab_comb_ecc_hlsvd
#6. Phase the data
%sx fsl_mrs_proc phase --file fsl_mrs_proc/steam_metab_comb_ecc_hlsvd.nii.gz --output fsl_mrs_proc -r --filename metab
%sx fsl_mrs_proc phase --ppm 4.6 4.7 --file fsl_mrs_proc/steam_wquant_comb_ecc.nii.gz --output fsl_mrs_proc --filename water
```
%% Cell type:markdown id: tags:
Combine the reports generated by the individual preprocessing commands
%% Cell type:code id: tags:
``` python
%%capture
%sx merge_mrs_reports -d CMD_line_test -o fsl_mrs_proc --delete fsl_mrs_proc/*.html
```
%% Cell type:markdown id: tags:
### 2.2 Pre-processing using fsl_mrs_preproc
In this section we will preprocess the data using a single preprocessing script which encapsulates all of the commands run above. Some of the commands are optional.
%% Cell type:code id: tags:
``` python
%%capture
%sx fsl_mrs_preproc --output fsl_mrs_preproc --data data/steam_metab_raw*.nii.gz --reference data/steam_wref_comb_raw*.nii.gz --quant data/steam_wref_quant_raw*.nii.gz --ecc data/steam_ecc_raw.nii.gz --hlsvd --leftshift 1 --t1 example_data/T1_biascorr.nii.gz --overwrite --report
# You can also run this script without independent quant and ecc data (just 1 water reference)
%sx fsl_mrs_preproc --output fsl_mrs_preproc_simple --data data/steam_metab_raw*.nii.gz --reference data/steam_wref_comb_raw*.nii.gz --hlsvd --leftshift 1 --t1 example_data/T1_biascorr.nii.gz --overwrite --report
```
%% Cell type:markdown id: tags:
### 3. Run tissue segmentation
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.
This step requires an installation of FSL compatible with fslpy. If you don't want to run this step the fitting step will run using a pre-packaged tissue segmentation file.
%% Cell type:code id: tags:
``` python
%sx svs_segment -a example_data/T1.anat fsl_mrs_proc/metab.nii.gz
```
%%%% Output: execute_result
['CSF: 0.12, GM: 0.39, WM: 0.49.']
%% Cell type:markdown id: tags:
### 4. Fit the data
Run a quick fit using the Newton method (here using the processed data in `fsl_mrs_preproc`)
%% Cell type:code id: tags:
``` python
%%capture
# Quick fit
%sx fsl_mrs --data fsl_mrs_preproc/metab.nii --basis example_data/steam_11ms --output fit_short --metab_groups Mac --overwrite --report --t1 example_data/T1.anat/T1_biascorr.nii.gz --h2o fsl_mrs_preproc/wref.nii --tissue_frac segmentation.json
%sx fsl_mrs --data fsl_mrs_preproc/metab.nii.gz --basis example_data/steam_11ms --output fit_short --metab_groups Mac --overwrite --report --t1 example_data/T1.anat/T1_biascorr.nii.gz --h2o fsl_mrs_preproc/wref.nii.gz --tissue_frac segmentation.json
```
%% Cell type:markdown id: tags:
Or run a full fit with the MCMC method
%% Cell type:code id: tags:
``` python
%%capture
# Full fit
%sx fsl_mrs --data fsl_mrs_preproc/metab.nii --basis example_data/steam_11ms --output fit_long --algo MH --metab_groups Mac --overwrite --report --t1 example_data/T1.anat/T1_biascorr.nii.gz --h2o fsl_mrs_preproc/wref.nii --tissue_frac segmentation.json
%sx fsl_mrs --data fsl_mrs_preproc/metab.nii.gz --basis example_data/steam_11ms --output fit_long --algo MH --metab_groups Mac --overwrite --report --t1 example_data/T1.anat/T1_biascorr.nii.gz --h2o fsl_mrs_preproc/wref.nii.gz --tissue_frac segmentation.json
```
%%%% Output: execute_result
[]
%% Cell type:markdown id: tags:
### 5. Display the result
Display the html reports in new tabs
%% Cell type:code id: tags:
``` python
%%capture
import webbrowser
import os
current_path = os.getcwd()
# generate a URL
url = os.path.join('file:///'+current_path,'fsl_mrs_preproc/mergedReports.html')
webbrowser.open(url)
url = os.path.join('file:///'+current_path,'fit_short/report.html')
webbrowser.open(url)
url = os.path.join('file:///'+current_path,'fit_long/report.html')
webbrowser.open(url)
```
......
......@@ -406,22 +406,18 @@ def readData(files, conjugate):
FIDlist = []
shape = None
datatype = None
auto_conj = 0
for filename in files:
dtype = mrs_io.check_datatype(filename)
fid, header = mrs_io.read_FID(filename)
fid = np.squeeze(fid)
if conjugate:
fid = np.conj(fid)
if fid.ndim > 1:
mrs = MRS(FID=np.mean(fid, axis=1), header=header)
auto_conj += mrs.check_FID(repair=True)
else:
if fid.ndim > 1:
mrs = MRS(FID=np.mean(fid, axis=1), header=header)
conj = mrs.check_FID(repair=True)
if conj:
fid = np.conj(fid)
else:
mrs = MRS(FID=fid, header=header)
mrs.check_FID(repair=True)
fid = mrs.FID
mrs = MRS(FID=fid, header=header)
auto_conj += mrs.check_FID(repair=True)
if shape is not None:
if fid.shape != shape:
......@@ -435,6 +431,10 @@ def readData(files, conjugate):
FIDlist.append(fid)
auto_conj /= len(FIDlist)
if conjugate or auto_conj > 0.5:
FIDlist = [np.conj(f) for f in FIDlist]