diff --git a/Analysis.ipynb b/Analysis.ipynb index cf36ad1..d82786e 100644 --- a/Analysis.ipynb +++ b/Analysis.ipynb @@ -11,23 +11,43 @@ "\n", "The data can be download at: XXX (TODO: upload on openneuro)\n", "\n", - "The structure of the input dataset is as follows:\n", + "The structure of the input dataset is as follows (JSON sidecars are not listed for clarity):\n", "~~~\n", - "RF_shimming_project_cleanupload/\n", - "├── SubA\n", - "│   ├── GRE_B1\n", - "│   │   ├── CVred\n", - "│   │   ├── Noshim\n", - "│   │   ├── PatSpec\n", - "│   │   ├── PhaseOnly\n", - "│   │   ├── SAReff\n", - "│   │   ├── Target\n", - "│   │   └── VolSpec\n", - "│   └── MPRAGE\n", - "├── SubB\n", - "├── SubC\n", - "├── SubD\n", - "└── SubE\n", + "├── CHANGES\n", + "├── README\n", + "├── dataset_description.json\n", + "├── participants.json\n", + "├── participants.tsv\n", + "├── sub-01\n", + "│   ├── anat\n", + "│   │   ├── sub-01_acq-CP_T1w.nii.gz\n", + "│   │   ├── sub-01_acq-CP_T2starw.nii.gz\n", + "│   │   ├── sub-01_acq-CoV_T1w.nii.gz\n", + "│   │   ├── sub-01_acq-CoV_T2starw.nii.gz\n", + "│   │   ├── sub-01_acq-SAReff_T2starw.nii.gz\n", + "│   │   ├── sub-01_acq-patient_T2starw.nii.gz\n", + "│   │   ├── sub-01_acq-phase_T2starw.nii.gz\n", + "│   │   ├── sub-01_acq-target_T2starw.nii.gz\n", + "│   │   ├── sub-01_acq-volume_T2starw.nii.gz\n", + "│   └── fmap\n", + "│   ├── sub-01_acq-anatCP_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-anatCoV_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-anatSAReff_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-anatpatient_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-anatphase_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-anattarget_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-anatvolume_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-fampCP_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-fampCoV_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-fampSAReff_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-famppatient_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-fampphase_TB1TFL.nii.gz\n", + "│   ├── sub-01_acq-famptarget_TB1TFL.nii.gz\n", + "│   └── sub-01_acq-fampvolume_TB1TFL.nii.gz\n", + "├── sub-02\n", + "├── sub-03\n", + "├── sub-04\n", + "└── sub-05\n", "~~~\n", "\n", "\n", @@ -78,9 +98,22 @@ "!datalad install https://github.com/OpenNeuroDatasets/ds004906.git\n", "os.chdir(\"ds004906\")\n", "# !datalad get . # uncomment for production\n", - "!datalad get sub-01/ # comment for debugging\n", + "!datalad get sub-01/ # comment for debugging" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6fe120e8", + "metadata": {}, + "outputs": [], + "source": [ + "# Define useful variables\n", + "\n", "path_data = os.getcwd()\n", - "path_qc = os.path.join(path_data, \"qc\")" + "path_qc = os.path.join(path_data, \"qc\")\n", + "shim_modes = [\"CP\", \"CoV\", \"patient\", \"phase\", \"SAReff\", \"target\", \"volume\"]\n", + "subjects = glob.glob(\"sub-*\")" ] }, { @@ -92,7 +125,6 @@ "source": [ "# Run segmentation on GRE scan\n", "\n", - "subjects = glob.glob(\"sub-*\")\n", "for subject in subjects:\n", " os.chdir(os.path.join(path_data, subject, \"anat\"))\n", " !sct_deepseg_sc -i {subject}_acq-CoV_T2starw.nii.gz -c t2 -qc {path_qc}" @@ -100,7 +132,7 @@ }, { "cell_type": "markdown", - "id": "49c57187", + "id": "aac9d889", "metadata": {}, "source": [ "## Verify quality control (QC) report\n", @@ -111,7 +143,22 @@ { "cell_type": "code", "execution_count": null, - "id": "1809bb43", + "id": "90deb5e5", + "metadata": {}, + "outputs": [], + "source": [ + "# Crop GRE scan for faster processing and better registration results\n", + "\n", + "for subject in subjects:\n", + " os.chdir(os.path.join(path_data, subject, \"anat\"))\n", + " !sct_crop_image -i {subject}_acq-CoV_T2starw.nii.gz -m {subject}_acq-CoV_T2starw_seg.nii.gz -dilate 20x20x0 -o {subject}_acq-CoV_T2starw_crop.nii.gz\n", + " !sct_crop_image -i {subject}_acq-CoV_T2starw_seg.nii.gz -m {subject}_acq-CoV_T2starw_seg.nii.gz -dilate 20x20x0 -o {subject}_acq-CoV_T2starw_crop_seg.nii.gz" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e0cde907", "metadata": {}, "outputs": [], "source": [ @@ -119,7 +166,8 @@ "\n", "for subject in subjects:\n", " os.chdir(os.path.join(path_data, subject, \"fmap\"))\n", - " !sct_register_multimodal -i {subject}_acq-anatCoV_TB1TFL.nii.gz -d ../anat/{subject}_acq-CoV_T2starw.nii.gz -param step=1,type=im,algo=slicereg,metric=CC -qc {path_qc}" + " for shim_mode in shim_modes:\n", + " !sct_register_multimodal -i {subject}_acq-anat{shim_mode}_TB1TFL.nii.gz -d ../anat/{subject}_acq-CoV_T2starw_crop.nii.gz -dseg ../anat/{subject}_acq-CoV_T2starw_crop_seg.nii.gz -param step=1,type=im,algo=slicereg,metric=CC -qc {path_qc}" ] } ],