22 "cells" : [
33 {
44 "cell_type" : " markdown" ,
5- "id" : " a4c07e0c-8673-4fa8-bc31-800409fb09c4" ,
6- "metadata" : {},
75 "source" : [
86 " # SPM_2_BIDS DEMO\n " ,
97 " \n " ,
10- " **Helping you convert your SPM output into a BIDS compliant datasets.**\n "
11- ]
8+ " **Helping you convert your SPM output into a BIDS compliant datasets.**\n " ,
9+ " \n " ,
10+ " ## BIDS filenames\n " ,
11+ " \n " ,
12+ " Ideally we would like to have the same pipeline for statistical analysis \n " ,
13+ " whether our data was preprocessed with SPM or with fmriprep (for example).\n " ,
14+ " \n " ,
15+ " This is possible under the condition that the input files for the statistical analysis are BIDS compliant: \n " ,
16+ " meaning that they follow the typical pattern of BIDS files:\n " ,
17+ " \n " ,
18+ " - pseudo \" regular expression\" : `entity-label(_entity-label)+_suffix.extension`\n " ,
19+ " \n " ,
20+ " \n " ,
21+ " - `entity`, `label`, `suffix`, `extension` are alphanumeric only (no special character): `([a-zA-Z0-9])+`\n " ,
22+ " - suffixes can be: `T1w` or `bold` but not `T1w_skullstripped` (no underscore allowed)\n " ,
23+ " \n " ,
24+ " \n " ,
25+ " - entity and label are separated by a dash: \n " ,
26+ " `entity-label --> ([a-zA-Z0-9])+-([a-zA-Z0-9])+`\n " ,
27+ " - you can have: `sub-01` but not `sub-01-blind`\n " ,
28+ " \n " ,
29+ " \n " ,
30+ " \n " ,
31+ " - entity-label pairs are separated by an underscore:\n " ,
32+ " `entity-label(_entity-label)+ --> ([a-zA-Z0-9])+-([a-zA-Z0-9])+(_([a-zA-Z0-9])+-([a-zA-Z0-9])+)+`\n " ,
33+ " \n " ,
34+ " \n " ,
35+ " - **prefixes are not a thing in official BIDS names**\n " ,
36+ " \n " ,
37+ " BIDS has a number of [officially recognised entities](https://bids-specification.readthedocs.io/en/stable/99-appendices/04-entity-table.html) (`sub`, `ses`, `task`...) \n " ,
38+ " that must come in a specific order for each data type.\n " ,
39+ " \n " ,
40+ " BIDS derivatives adds a few more entities (`desc`, `space`, `res`...) \n " ,
41+ " and suffixes (`pseg`, `dseg`, `mask`...) \n " ,
42+ " that can be used to name and describe preprocessed data.\n " ,
43+ " \n " ,
44+ " ## Typical SPM filenames\n " ,
45+ " \n " ,
46+ " SPM typically adds prefixes to filenames and concatenates them.\n " ,
47+ " \n " ,
48+ " - `r` for realigned or resliced\n " ,
49+ " - `w` for warped (often means normalized in MNI space)\n " ,
50+ " - `a` for slice time corrected images\n " ,
51+ " - `u` for unwarped\n " ,
52+ " - `s` for smoothed\n " ,
53+ " - `c1` for grey matter tissue probability maps\n " ,
54+ " - ...\n " ,
55+ " \n " ,
56+ " ## SPM to BIDS\n " ,
57+ " \n " ,
58+ " spm_2_bids offers a default mapping to rename the output of raw BIDS datasets preprocessed with SPM12\n " ,
59+ " into BIDS compliant derivatives datasets, by suggesting a name for each file by removing prefixes and \n " ,
60+ " adding the appropriate entities to be added.\n " ,
61+ " \n " ,
62+ " Files are not actually renamed by spm_2_bids (yet).\n "
63+ ],
64+ "metadata" : {}
1265 },
1366 {
1467 "cell_type" : " code" ,
1568 "execution_count" : 2 ,
16- "id" : " 68482373-0288-4920-99a6-68e7db8bac44" ,
17- "metadata" : {},
69+ "source" : [
70+ " run ../init_spm_2_bids.m"
71+ ],
1872 "outputs" : [
1973 {
20- "name" : " stdout" ,
2174 "output_type" : " stream" ,
75+ "name" : " stdout" ,
2276 "text" : [
2377 " Correct matlab/octave verions and added to the path!\n "
2478 ]
2579 }
2680 ],
27- "source" : [
28- " run ../init_spm_2_bids.m"
29- ]
81+ "metadata" : {}
3082 },
3183 {
3284 "cell_type" : " code" ,
3385 "execution_count" : 13 ,
34- "id" : " 0d1179df-bfa6-494c-a900-ab667d6bfa5d" ,
35- "metadata" : {},
36- "outputs" : [
37- {
38- "name" : " stdout" ,
39- "output_type" : " stream" ,
40- "text" : [
41- " sub-01_T1w_seg8.mat\t -->\t sub-01_label-T1w_segparam.mat\n " ,
42- " sub-01_task-auditory_bold_uw.mat\t -->\t sub-01_task-auditory_label-bold_unwarpparam.mat\n " ,
43- " y_sub-01_T1w.nii\t -->\t sub-01_from-T1w_to-IXI549Space_mode-image_xfm.nii\n " ,
44- " iy_sub-01_T1w.nii\t -->\t sub-01_from-IXI549Space_to-T1w_mode-image_xfm.nii\n " ,
45- " y_sub-01_T2w.nii\t -->\t sub-01_from-T2w_to-IXI549Space_mode-image_xfm.nii\n " ,
46- " susub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
47- " swuasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
48- " c1sub-01_T1w.nii\t -->\t sub-01_space-individual_label-GM_probseg.nii\n " ,
49- " c2sub-01_T1w.nii\t -->\t sub-01_space-individual_label-WM_probseg.nii\n " ,
50- " c3sub-01_T1w.nii\t -->\t sub-01_space-individual_label-CSF_probseg.nii\n " ,
51- " msub-01_T1w.nii\t -->\t sub-01_space-individual_desc-biascor_T1w.nii\n " ,
52- " wmsub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_desc-preproc_T1w.nii\n " ,
53- " wsub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_desc-preproc_T1w.nii\n " ,
54- " wc1sub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_label-GM_probseg.nii\n " ,
55- " wc2sub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_label-WM_probseg.nii\n " ,
56- " wc3sub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_label-CSF_probseg.nii\n " ,
57- " asub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-stc_bold.nii\n " ,
58- " usub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-realignUnwarp_bold.nii\n " ,
59- " rp_sub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_desc-confounds_regressors.tsv\n " ,
60- " rp_asub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_desc-confounds_regressors.tsv\n " ,
61- " meansub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-mean_bold.nii\n " ,
62- " meanusub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-mean_bold.nii\n " ,
63- " meanuasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-mean_bold.nii\n " ,
64- " wsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
65- " wuasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
66- " wusub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
67- " wrsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
68- " wrasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
69- " wmeanusub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-mean_bold.nii\n " ,
70- " swsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
71- " swuasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
72- " swusub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
73- " swrsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
74- " swrasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
75- " ssub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
76- " suasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
77- " susub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
78- " srsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
79- " srasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n "
80- ]
81- }
82- ],
8386 "source" : [
8487 " input_files = { 'sub-01_T1w_seg8.mat'; ...\n " ,
8588 " 'sub-01_task-auditory_bold_uw.mat'; ...\n " ,
130133 " fprintf(1, '%s\\ t-->\\ t%s\\ n', input_files{i, 1}, filename);\n " ,
131134 " \n " ,
132135 " end"
133- ]
136+ ],
137+ "outputs" : [
138+ {
139+ "output_type" : " stream" ,
140+ "name" : " stdout" ,
141+ "text" : [
142+ " sub-01_T1w_seg8.mat\t -->\t sub-01_label-T1w_segparam.mat\n " ,
143+ " sub-01_task-auditory_bold_uw.mat\t -->\t sub-01_task-auditory_label-bold_unwarpparam.mat\n " ,
144+ " y_sub-01_T1w.nii\t -->\t sub-01_from-T1w_to-IXI549Space_mode-image_xfm.nii\n " ,
145+ " iy_sub-01_T1w.nii\t -->\t sub-01_from-IXI549Space_to-T1w_mode-image_xfm.nii\n " ,
146+ " y_sub-01_T2w.nii\t -->\t sub-01_from-T2w_to-IXI549Space_mode-image_xfm.nii\n " ,
147+ " susub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
148+ " swuasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
149+ " c1sub-01_T1w.nii\t -->\t sub-01_space-individual_label-GM_probseg.nii\n " ,
150+ " c2sub-01_T1w.nii\t -->\t sub-01_space-individual_label-WM_probseg.nii\n " ,
151+ " c3sub-01_T1w.nii\t -->\t sub-01_space-individual_label-CSF_probseg.nii\n " ,
152+ " msub-01_T1w.nii\t -->\t sub-01_space-individual_desc-biascor_T1w.nii\n " ,
153+ " wmsub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_desc-preproc_T1w.nii\n " ,
154+ " wsub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_desc-preproc_T1w.nii\n " ,
155+ " wc1sub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_label-GM_probseg.nii\n " ,
156+ " wc2sub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_label-WM_probseg.nii\n " ,
157+ " wc3sub-01_T1w.nii\t -->\t sub-01_space-IXI549Space_label-CSF_probseg.nii\n " ,
158+ " asub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-stc_bold.nii\n " ,
159+ " usub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-realignUnwarp_bold.nii\n " ,
160+ " rp_sub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_desc-confounds_regressors.tsv\n " ,
161+ " rp_asub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_desc-confounds_regressors.tsv\n " ,
162+ " meansub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-mean_bold.nii\n " ,
163+ " meanusub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-mean_bold.nii\n " ,
164+ " meanuasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-mean_bold.nii\n " ,
165+ " wsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
166+ " wuasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
167+ " wusub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
168+ " wrsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
169+ " wrasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-preproc_bold.nii\n " ,
170+ " wmeanusub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-mean_bold.nii\n " ,
171+ " swsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
172+ " swuasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
173+ " swusub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
174+ " swrsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
175+ " swrasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-IXI549Space_desc-smth_bold.nii\n " ,
176+ " ssub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
177+ " suasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
178+ " susub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
179+ " srsub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n " ,
180+ " srasub-01_task-auditory_bold.nii\t -->\t sub-01_task-auditory_space-individual_desc-smth_bold.nii\n "
181+ ]
182+ }
183+ ],
184+ "metadata" : {}
134185 },
135186 {
136187 "cell_type" : " markdown" ,
137- "id" : " cdb56e9a-3757-45a6-ba5a-c1228f478a3e" ,
138- "metadata" : {},
139188 "source" : [
140189 " # Override the default name map"
141- ]
190+ ],
191+ "metadata" : {}
142192 },
143193 {
144194 "cell_type" : " code" ,
145195 "execution_count" : 20 ,
146- "id" : " 547873ea-d673-4338-998e-a10ea80b1682" ,
147- "metadata" : {},
148- "outputs" : [],
149196 "source" : [
150197 " map = Mapping();\n " ,
151198 " \n " ,
169216 " 'name_spec', name_spec);\n " ,
170217 " \n " ,
171218 " map = map.flatten_mapping();\n "
172- ]
219+ ],
220+ "outputs" : [],
221+ "metadata" : {}
173222 },
174223 {
175224 "cell_type" : " code" ,
176225 "execution_count" : 21 ,
177- "id" : " 6dde6430-e419-4771-8a61-1b5ba6d362d6" ,
178- "metadata" : {},
179- "outputs" : [
180- {
181- "name" : " stdout" ,
182- "output_type" : " stream" ,
183- "text" : [
184- " c1sub-01_T1w.surf.gii\t -->\t sub-01_desc-pialsurf_T1w.gii\n " ,
185- " wmsub-01_desc-skullstripped_T1w.nii\t -->\t sub-01_space-IXI549Space_res-1pt0_desc-preproc_T1w.nii\n " ,
186- " wmsub-01_desc-skullstripped_T2w.nii\t -->\t sub-01_space-IXI549Space_desc-preproc_T2w.nii\n " ,
187- " wmsub-01_desc-preproc_T1w.nii\t -->\t sub-01_space-IXI549Space_desc-preproc_T1w.nii\n "
188- ]
189- }
190- ],
191226 "source" : [
192227 " input_output = {'c1sub-01_T1w.surf.gii'; ... % new mapping for surface data\n " ,
193228 " 'wmsub-01_desc-skullstripped_T1w.nii'; ... % new mapping for skulltripped data\n " ,
202237 " fprintf(1, '%s\\ t-->\\ t%s\\ n', input_output{i, 1}, filename);\n " ,
203238 " \n " ,
204239 " end"
205- ]
240+ ],
241+ "outputs" : [
242+ {
243+ "output_type" : " stream" ,
244+ "name" : " stdout" ,
245+ "text" : [
246+ " c1sub-01_T1w.surf.gii\t -->\t sub-01_desc-pialsurf_T1w.gii\n " ,
247+ " wmsub-01_desc-skullstripped_T1w.nii\t -->\t sub-01_space-IXI549Space_res-1pt0_desc-preproc_T1w.nii\n " ,
248+ " wmsub-01_desc-skullstripped_T2w.nii\t -->\t sub-01_space-IXI549Space_desc-preproc_T2w.nii\n " ,
249+ " wmsub-01_desc-preproc_T1w.nii\t -->\t sub-01_space-IXI549Space_desc-preproc_T1w.nii\n "
250+ ]
251+ }
252+ ],
253+ "metadata" : {}
206254 }
207255 ],
208256 "metadata" : {
234282 },
235283 "nbformat" : 4 ,
236284 "nbformat_minor" : 5
237- }
285+ }
0 commit comments