|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stderr", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "Failed to import duecredit due to No module named 'duecredit'\n" |
| 13 | + ] |
| 14 | + } |
| 15 | + ], |
| 16 | + "source": [ |
| 17 | + "import bids" |
| 18 | + ] |
| 19 | + }, |
| 20 | + { |
| 21 | + "cell_type": "code", |
| 22 | + "execution_count": 2, |
| 23 | + "metadata": {}, |
| 24 | + "outputs": [ |
| 25 | + { |
| 26 | + "data": { |
| 27 | + "text/plain": [ |
| 28 | + "<module 'bids' from '/opt/miniconda-latest/lib/python3.6/site-packages/bids/__init__.py'>" |
| 29 | + ] |
| 30 | + }, |
| 31 | + "execution_count": 2, |
| 32 | + "metadata": {}, |
| 33 | + "output_type": "execute_result" |
| 34 | + } |
| 35 | + ], |
| 36 | + "source": [ |
| 37 | + "bids\n" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "code", |
| 42 | + "execution_count": 3, |
| 43 | + "metadata": {}, |
| 44 | + "outputs": [], |
| 45 | + "source": [ |
| 46 | + "layout = bids.BIDSLayout(\"ds000003\")" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "cell_type": "code", |
| 51 | + "execution_count": 4, |
| 52 | + "metadata": {}, |
| 53 | + "outputs": [ |
| 54 | + { |
| 55 | + "data": { |
| 56 | + "text/plain": [ |
| 57 | + "BIDS Layout: .../data/ds000003 | Subjects: 13 | Sessions: 0 | Runs: 0" |
| 58 | + ] |
| 59 | + }, |
| 60 | + "execution_count": 4, |
| 61 | + "metadata": {}, |
| 62 | + "output_type": "execute_result" |
| 63 | + } |
| 64 | + ], |
| 65 | + "source": [ |
| 66 | + "layout\n" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": 5, |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [ |
| 74 | + { |
| 75 | + "data": { |
| 76 | + "text/plain": [ |
| 77 | + "[<BIDSFile filename='.git/annex/objects/29/WX/MD5E-s25362403--d72afc284b7608e29ab1e92c75513f69.nii.gz/MD5E-s25362403--d72afc284b7608e29ab1e92c75513f69.nii.gz'>,\n", |
| 78 | + " <BIDSFile filename='.git/annex/objects/J3/q7/MD5E-s664614--0f8bc47f9c3047b340abfcd3ce1fb021.nii.gz/MD5E-s664614--0f8bc47f9c3047b340abfcd3ce1fb021.nii.gz'>,\n", |
| 79 | + " <BIDSFile filename='.git/annex/objects/jJ/2v/MD5E-s5712417--0d1e0a7ff7063250404f45a955a66203.nii.gz/MD5E-s5712417--0d1e0a7ff7063250404f45a955a66203.nii.gz'>,\n", |
| 80 | + " <BIDSFile filename='CHANGES'>,\n", |
| 81 | + " <BIDSFile filename='dataset_description.json'>,\n", |
| 82 | + " <BIDSFile filename='participants.tsv'>,\n", |
| 83 | + " <BIDSFile filename='README'>,\n", |
| 84 | + " <BIDSFile filename='sub-01/anat/sub-01_inplaneT2.nii.gz'>,\n", |
| 85 | + " <BIDSFile filename='sub-01/anat/sub-01_T1w.nii.gz'>,\n", |
| 86 | + " <BIDSFile filename='sub-01/func/sub-01_task-rhymejudgment_bold.nii.gz'>,\n", |
| 87 | + " <BIDSFile filename='sub-01/func/sub-01_task-rhymejudgment_events.tsv'>,\n", |
| 88 | + " <BIDSFile filename='sub-02/anat/sub-02_inplaneT2.nii.gz'>,\n", |
| 89 | + " <BIDSFile filename='sub-02/anat/sub-02_T1w.nii.gz'>,\n", |
| 90 | + " <BIDSFile filename='sub-02/func/sub-02_task-rhymejudgment_bold.nii.gz'>,\n", |
| 91 | + " <BIDSFile filename='sub-02/func/sub-02_task-rhymejudgment_events.tsv'>,\n", |
| 92 | + " <BIDSFile filename='sub-03/anat/sub-03_inplaneT2.nii.gz'>,\n", |
| 93 | + " <BIDSFile filename='sub-03/anat/sub-03_T1w.nii.gz'>,\n", |
| 94 | + " <BIDSFile filename='sub-03/func/sub-03_task-rhymejudgment_bold.nii.gz'>,\n", |
| 95 | + " <BIDSFile filename='sub-03/func/sub-03_task-rhymejudgment_events.tsv'>,\n", |
| 96 | + " <BIDSFile filename='sub-04/anat/sub-04_inplaneT2.nii.gz'>,\n", |
| 97 | + " <BIDSFile filename='sub-04/anat/sub-04_T1w.nii.gz'>,\n", |
| 98 | + " <BIDSFile filename='sub-04/func/sub-04_task-rhymejudgment_bold.nii.gz'>,\n", |
| 99 | + " <BIDSFile filename='sub-04/func/sub-04_task-rhymejudgment_events.tsv'>,\n", |
| 100 | + " <BIDSFile filename='sub-05/anat/sub-05_inplaneT2.nii.gz'>,\n", |
| 101 | + " <BIDSFile filename='sub-05/anat/sub-05_T1w.nii.gz'>,\n", |
| 102 | + " <BIDSFile filename='sub-05/func/sub-05_task-rhymejudgment_bold.nii.gz'>,\n", |
| 103 | + " <BIDSFile filename='sub-05/func/sub-05_task-rhymejudgment_events.tsv'>,\n", |
| 104 | + " <BIDSFile filename='sub-06/anat/sub-06_inplaneT2.nii.gz'>,\n", |
| 105 | + " <BIDSFile filename='sub-06/anat/sub-06_T1w.nii.gz'>,\n", |
| 106 | + " <BIDSFile filename='sub-06/func/sub-06_task-rhymejudgment_bold.nii.gz'>,\n", |
| 107 | + " <BIDSFile filename='sub-06/func/sub-06_task-rhymejudgment_events.tsv'>,\n", |
| 108 | + " <BIDSFile filename='sub-07/anat/sub-07_inplaneT2.nii.gz'>,\n", |
| 109 | + " <BIDSFile filename='sub-07/anat/sub-07_T1w.nii.gz'>,\n", |
| 110 | + " <BIDSFile filename='sub-07/func/sub-07_task-rhymejudgment_bold.nii.gz'>,\n", |
| 111 | + " <BIDSFile filename='sub-07/func/sub-07_task-rhymejudgment_events.tsv'>,\n", |
| 112 | + " <BIDSFile filename='sub-08/anat/sub-08_inplaneT2.nii.gz'>,\n", |
| 113 | + " <BIDSFile filename='sub-08/anat/sub-08_T1w.nii.gz'>,\n", |
| 114 | + " <BIDSFile filename='sub-08/func/sub-08_task-rhymejudgment_bold.nii.gz'>,\n", |
| 115 | + " <BIDSFile filename='sub-08/func/sub-08_task-rhymejudgment_events.tsv'>,\n", |
| 116 | + " <BIDSFile filename='sub-09/anat/sub-09_inplaneT2.nii.gz'>,\n", |
| 117 | + " <BIDSFile filename='sub-09/anat/sub-09_T1w.nii.gz'>,\n", |
| 118 | + " <BIDSFile filename='sub-09/func/sub-09_task-rhymejudgment_bold.nii.gz'>,\n", |
| 119 | + " <BIDSFile filename='sub-09/func/sub-09_task-rhymejudgment_events.tsv'>,\n", |
| 120 | + " <BIDSFile filename='sub-10/anat/sub-10_inplaneT2.nii.gz'>,\n", |
| 121 | + " <BIDSFile filename='sub-10/anat/sub-10_T1w.nii.gz'>,\n", |
| 122 | + " <BIDSFile filename='sub-10/func/sub-10_task-rhymejudgment_bold.nii.gz'>,\n", |
| 123 | + " <BIDSFile filename='sub-10/func/sub-10_task-rhymejudgment_events.tsv'>,\n", |
| 124 | + " <BIDSFile filename='sub-11/anat/sub-11_inplaneT2.nii.gz'>,\n", |
| 125 | + " <BIDSFile filename='sub-11/anat/sub-11_T1w.nii.gz'>,\n", |
| 126 | + " <BIDSFile filename='sub-11/func/sub-11_task-rhymejudgment_bold.nii.gz'>,\n", |
| 127 | + " <BIDSFile filename='sub-11/func/sub-11_task-rhymejudgment_events.tsv'>,\n", |
| 128 | + " <BIDSFile filename='sub-12/anat/sub-12_inplaneT2.nii.gz'>,\n", |
| 129 | + " <BIDSFile filename='sub-12/anat/sub-12_T1w.nii.gz'>,\n", |
| 130 | + " <BIDSFile filename='sub-12/func/sub-12_task-rhymejudgment_bold.nii.gz'>,\n", |
| 131 | + " <BIDSFile filename='sub-12/func/sub-12_task-rhymejudgment_events.tsv'>,\n", |
| 132 | + " <BIDSFile filename='sub-13/anat/sub-13_inplaneT2.nii.gz'>,\n", |
| 133 | + " <BIDSFile filename='sub-13/anat/sub-13_T1w.nii.gz'>,\n", |
| 134 | + " <BIDSFile filename='sub-13/func/sub-13_task-rhymejudgment_bold.nii.gz'>,\n", |
| 135 | + " <BIDSFile filename='sub-13/func/sub-13_task-rhymejudgment_events.tsv'>,\n", |
| 136 | + " <BIDSFile filename='task-rhymejudgment_bold.json'>]" |
| 137 | + ] |
| 138 | + }, |
| 139 | + "execution_count": 5, |
| 140 | + "metadata": {}, |
| 141 | + "output_type": "execute_result" |
| 142 | + } |
| 143 | + ], |
| 144 | + "source": [ |
| 145 | + "layout.get()" |
| 146 | + ] |
| 147 | + }, |
| 148 | + { |
| 149 | + "cell_type": "code", |
| 150 | + "execution_count": 6, |
| 151 | + "metadata": {}, |
| 152 | + "outputs": [ |
| 153 | + { |
| 154 | + "data": { |
| 155 | + "text/plain": [ |
| 156 | + "OrderedDict([('bids.subject', <grabbit.core.Entity at 0x7fb7ec35a588>),\n", |
| 157 | + " ('bids.session', <grabbit.core.Entity at 0x7fb7ec35aa20>),\n", |
| 158 | + " ('bids.task', <grabbit.core.Entity at 0x7fb7ec35aa58>),\n", |
| 159 | + " ('bids.acquisition', <grabbit.core.Entity at 0x7fb7ec35ad30>),\n", |
| 160 | + " ('bids.ce', <grabbit.core.Entity at 0x7fb7ec35a9e8>),\n", |
| 161 | + " ('bids.reconstruction', <grabbit.core.Entity at 0x7fb7ec35a518>),\n", |
| 162 | + " ('bids.dir', <grabbit.core.Entity at 0x7fb7ec35aa90>),\n", |
| 163 | + " ('bids.run', <grabbit.core.Entity at 0x7fb7ec35ab38>),\n", |
| 164 | + " ('bids.proc', <grabbit.core.Entity at 0x7fb7ec35ac50>),\n", |
| 165 | + " ('bids.modality', <grabbit.core.Entity at 0x7fb7ec35abe0>),\n", |
| 166 | + " ('bids.echo', <grabbit.core.Entity at 0x7fb7ec35acc0>),\n", |
| 167 | + " ('bids.recording', <grabbit.core.Entity at 0x7fb7ec35ae80>),\n", |
| 168 | + " ('bids.suffix', <grabbit.core.Entity at 0x7fb7ec35ac88>),\n", |
| 169 | + " ('bids.scans', <grabbit.core.Entity at 0x7fb7ec35ad68>),\n", |
| 170 | + " ('bids.fmap', <grabbit.core.Entity at 0x7fb7ec35add8>),\n", |
| 171 | + " ('bids.datatype', <grabbit.core.Entity at 0x7fb7ec35acf8>)])" |
| 172 | + ] |
| 173 | + }, |
| 174 | + "execution_count": 6, |
| 175 | + "metadata": {}, |
| 176 | + "output_type": "execute_result" |
| 177 | + } |
| 178 | + ], |
| 179 | + "source": [ |
| 180 | + "layout.entities" |
| 181 | + ] |
| 182 | + }, |
| 183 | + { |
| 184 | + "cell_type": "code", |
| 185 | + "execution_count": 7, |
| 186 | + "metadata": {}, |
| 187 | + "outputs": [ |
| 188 | + { |
| 189 | + "data": { |
| 190 | + "text/plain": [ |
| 191 | + "[<BIDSFile filename='sub-01/anat/sub-01_inplaneT2.nii.gz'>,\n", |
| 192 | + " <BIDSFile filename='sub-01/anat/sub-01_T1w.nii.gz'>,\n", |
| 193 | + " <BIDSFile filename='sub-01/func/sub-01_task-rhymejudgment_bold.nii.gz'>,\n", |
| 194 | + " <BIDSFile filename='sub-01/func/sub-01_task-rhymejudgment_events.tsv'>]" |
| 195 | + ] |
| 196 | + }, |
| 197 | + "execution_count": 7, |
| 198 | + "metadata": {}, |
| 199 | + "output_type": "execute_result" |
| 200 | + } |
| 201 | + ], |
| 202 | + "source": [ |
| 203 | + "layout.get(subject=\"01\")" |
| 204 | + ] |
| 205 | + }, |
| 206 | + { |
| 207 | + "cell_type": "code", |
| 208 | + "execution_count": 8, |
| 209 | + "metadata": {}, |
| 210 | + "outputs": [ |
| 211 | + { |
| 212 | + "data": { |
| 213 | + "text/plain": [ |
| 214 | + "['06', '05', '04', '07', '10', '12', '03', '13', '02', '09', '11', '08', '01']" |
| 215 | + ] |
| 216 | + }, |
| 217 | + "execution_count": 8, |
| 218 | + "metadata": {}, |
| 219 | + "output_type": "execute_result" |
| 220 | + } |
| 221 | + ], |
| 222 | + "source": [ |
| 223 | + "layout.get_subjects()" |
| 224 | + ] |
| 225 | + }, |
| 226 | + { |
| 227 | + "cell_type": "code", |
| 228 | + "execution_count": 9, |
| 229 | + "metadata": {}, |
| 230 | + "outputs": [], |
| 231 | + "source": [ |
| 232 | + "from nipype.interfaces.fsl import BET" |
| 233 | + ] |
| 234 | + }, |
| 235 | + { |
| 236 | + "cell_type": "code", |
| 237 | + "execution_count": 10, |
| 238 | + "metadata": {}, |
| 239 | + "outputs": [ |
| 240 | + { |
| 241 | + "data": { |
| 242 | + "text/plain": [ |
| 243 | + "'/data/ds000003/sub-01/anat/sub-01_T1w.nii.gz'" |
| 244 | + ] |
| 245 | + }, |
| 246 | + "execution_count": 10, |
| 247 | + "metadata": {}, |
| 248 | + "output_type": "execute_result" |
| 249 | + } |
| 250 | + ], |
| 251 | + "source": [ |
| 252 | + "layout.get(subject=\"01\", suffix=\"T1w\", return_type=\"file\")[0]" |
| 253 | + ] |
| 254 | + }, |
| 255 | + { |
| 256 | + "cell_type": "code", |
| 257 | + "execution_count": 13, |
| 258 | + "metadata": {}, |
| 259 | + "outputs": [], |
| 260 | + "source": [ |
| 261 | + "res=BET(in_file=layout.get(subject=\"01\", suffix=\"T1w\", return_type=\"file\")[0], out_file=\"brain.nii.gz\").run()" |
| 262 | + ] |
| 263 | + }, |
| 264 | + { |
| 265 | + "cell_type": "markdown", |
| 266 | + "metadata": {}, |
| 267 | + "source": [ |
| 268 | + "writting a simple workflow to the script" |
| 269 | + ] |
| 270 | + }, |
| 271 | + { |
| 272 | + "cell_type": "code", |
| 273 | + "execution_count": 16, |
| 274 | + "metadata": {}, |
| 275 | + "outputs": [ |
| 276 | + { |
| 277 | + "name": "stdout", |
| 278 | + "output_type": "stream", |
| 279 | + "text": [ |
| 280 | + "Overwriting myscripy.py\n" |
| 281 | + ] |
| 282 | + } |
| 283 | + ], |
| 284 | + "source": [ |
| 285 | + "%%writefile myscripy.py\n", |
| 286 | + "\n", |
| 287 | + "import bids\n", |
| 288 | + "from nipype.interfaces.fsl import BET\n", |
| 289 | + "\n", |
| 290 | + "layout = bids.BIDSLayout(\"/data/ds000003\")\n", |
| 291 | + "res=BET(in_file=layout.get(subject=\"01\", suffix=\"T1w\", return_type=\"file\")[0], out_file=\"brain.nii.gz\").run()" |
| 292 | + ] |
| 293 | + }, |
| 294 | + { |
| 295 | + "cell_type": "markdown", |
| 296 | + "metadata": {}, |
| 297 | + "source": [ |
| 298 | + "## in the jupyter terminal" |
| 299 | + ] |
| 300 | + }, |
| 301 | + { |
| 302 | + "cell_type": "markdown", |
| 303 | + "metadata": {}, |
| 304 | + "source": [ |
| 305 | + "```\n", |
| 306 | + "ls /data/ds000003\n", |
| 307 | + "mkdir scripts\n", |
| 308 | + "cp /data/myscripy.py /data/ds000003/scripts\n", |
| 309 | + "git add scripts/myscripy.py\n", |
| 310 | + "git commit -am \"adding the script\"\n", |
| 311 | + "datalad run python scripts/myscripy.py\n", |
| 312 | + "```" |
| 313 | + ] |
| 314 | + }, |
| 315 | + { |
| 316 | + "cell_type": "code", |
| 317 | + "execution_count": null, |
| 318 | + "metadata": {}, |
| 319 | + "outputs": [], |
| 320 | + "source": [] |
| 321 | + } |
| 322 | + ], |
| 323 | + "metadata": { |
| 324 | + "kernelspec": { |
| 325 | + "display_name": "Python 3", |
| 326 | + "language": "python", |
| 327 | + "name": "python3" |
| 328 | + }, |
| 329 | + "language_info": { |
| 330 | + "codemirror_mode": { |
| 331 | + "name": "ipython", |
| 332 | + "version": 3 |
| 333 | + }, |
| 334 | + "file_extension": ".py", |
| 335 | + "mimetype": "text/x-python", |
| 336 | + "name": "python", |
| 337 | + "nbconvert_exporter": "python", |
| 338 | + "pygments_lexer": "ipython3", |
| 339 | + "version": "3.6.7" |
| 340 | + } |
| 341 | + }, |
| 342 | + "nbformat": 4, |
| 343 | + "nbformat_minor": 2 |
| 344 | +} |
0 commit comments