This code will load the model information, generate the model definition, and run the model estimation using FSL


In [1]:
import nipype.algorithms.modelgen as model   # model generation
from  nipype.interfaces import fsl, spm   
from nipype.interfaces.base import Bunch
import os,json,glob,sys
import numpy
import nibabel
import nilearn.plotting
%matplotlib inline
import matplotlib.pyplot as plt

datadir='/home/vagrant/data/ds000114_R2.0.1/'
    
results_dir = os.path.abspath("../../results")
if not os.path.exists(results_dir):
    os.mkdir(results_dir)

from nipype.caching import Memory
mem = Memory(base_dir='.')

print('Using data from',datadir)


Using data from /home/vagrant/data/ds000114_R2.0.1/
/home/vagrant/miniconda3/lib/python3.5/site-packages/sklearn/cross_validation.py:44: DeprecationWarning: This module was deprecated in version 0.18 in favor of the model_selection module into which all the refactored classes and functions are moved. Also note that the interface of the new CV iterators are different from that of this module. This module will be removed in 0.20.
  "This module will be removed in 0.20.", DeprecationWarning)

In [2]:
from bids.grabbids import BIDSLayout
layout = BIDSLayout(datadir)
layout.get(type="bold", task="fingerfootlips", session="test", extensions="nii.gz")[0].filename


Out[2]:
'/home/vagrant/data/ds000114_R2.0.1/sub-01/ses-test/func/sub-01_ses-test_task-fingerfootlips_bold.nii.gz'

In [3]:
import pandas as pd
events = pd.read_csv(os.path.join(datadir, "task-fingerfootlips_events.tsv"), sep="\t")
events


Out[3]:
onset duration weight trial_type
0 10 15.0 1 Finger
1 40 15.0 1 Foot
2 70 15.0 1 Lips
3 100 15.0 1 Finger
4 130 15.0 1 Foot
5 160 15.0 1 Lips
6 190 15.0 1 Finger
7 220 15.0 1 Foot
8 250 15.0 1 Lips
9 280 15.0 1 Finger
10 310 15.0 1 Foot
11 340 15.0 1 Lips
12 370 15.0 1 Finger
13 400 15.0 1 Foot
14 430 15.0 1 Lips

In [4]:
for trial_type in events.trial_type.unique():
    print(events[events.trial_type == trial_type])


    onset  duration  weight trial_type
0      10      15.0       1     Finger
3     100      15.0       1     Finger
6     190      15.0       1     Finger
9     280      15.0       1     Finger
12    370      15.0       1     Finger
    onset  duration  weight trial_type
1      40      15.0       1       Foot
4     130      15.0       1       Foot
7     220      15.0       1       Foot
10    310      15.0       1       Foot
13    400      15.0       1       Foot
    onset  duration  weight trial_type
2      70      15.0       1       Lips
5     160      15.0       1       Lips
8     250      15.0       1       Lips
11    340      15.0       1       Lips
14    430      15.0       1       Lips

In [5]:
events[events.trial_type == 'Finger'].duration


Out[5]:
0     15.0
3     15.0
6     15.0
9     15.0
12    15.0
Name: duration, dtype: float64

In [13]:
source_epi = layout.get(type="bold", task="fingerfootlips", session="test", extensions="nii.gz")[5]

confounds = pd.read_csv(os.path.join(datadir, "derivatives", "fmriprep", 
                                        "sub-%s"%source_epi.subject, "ses-%s"%source_epi.session, "func", 
                                        "sub-%s_ses-%s_task-fingerfootlips_bold_confounds.tsv"%(source_epi.subject,
                                                                                                                           source_epi.session)),
           sep="\t", na_values="n/a")

info = [Bunch(conditions=['Finger',
                          'Foot',
                          'Lips'],
              onsets=[list(events[events.trial_type == 'Finger'].onset-10),
                      list(events[events.trial_type == 'Foot'].onset-10),
                      list(events[events.trial_type == 'Lips'].onset-10)],
              durations=[list(events[events.trial_type == 'Finger'].duration),
                          list(events[events.trial_type == 'Foot'].duration),
                          list(events[events.trial_type == 'Lips'].duration)],
             regressors=[list(confounds.FramewiseDisplacement.fillna(0)[4:]),
                         list(confounds.aCompCor0[4:]),
                         list(confounds.aCompCor1[4:]),
                         list(confounds.aCompCor2[4:]),
                         list(confounds.aCompCor3[4:]),
                         list(confounds.aCompCor4[4:]),
                         list(confounds.aCompCor5[4:]),
                        ],
             regressor_names=['FramewiseDisplacement',
                              'aCompCor0',
                              'aCompCor1',
                              'aCompCor2',
                              'aCompCor3',
                              'aCompCor4',
                              'aCompCor5'],
              amplitudes=None,
              tmod=None,
              pmod=None)
       ]

skip = mem.cache(fsl.ExtractROI)
skip_results = skip(in_file=os.path.join(datadir, "derivatives", "fmriprep", 
                                        "sub-%s"%source_epi.subject, "ses-%s"%source_epi.session, "func", 
                                        "sub-%s_ses-%s_task-fingerfootlips_bold_space-MNI152NLin2009cAsym_preproc.nii.gz"%(source_epi.subject,
                                                                                                                           source_epi.session)),
                     t_min=4, t_size=-1, output_type="NIFTI")
s = model.SpecifySPMModel()
s.inputs.input_units = 'secs'
s.inputs.functional_runs = skip_results.outputs.roi_file
s.inputs.time_repetition = layout.get_metadata(source_epi.filename)["RepetitionTime"]
s.inputs.high_pass_filter_cutoff = 128.
s.inputs.concatenate_runs=False
s.inputs.output_units='secs'
s.inputs.subject_info = info
specify_model_results = s.run()
specify_model_results.outputs


170216-18:24:41,205 workflow INFO:
	 Executing node 90e73a4efdfb9677c5c883f59a536b34 in dir: /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-fsl-utils-ExtractROI/90e73a4efdfb9677c5c883f59a536b34
170216-18:24:41,215 workflow INFO:
	 Collecting precomputed outputs
Out[13]:
session_info = [{'cond': [{'name': 'Finger', 'duration': [15.0, 15.0, 15.0, 15.0, 15.0], 'onset': [0.0, 90.0, 180.0, 270.0, 360.0]}, {'name': 'Foot', 'duration': [15.0, 15.0, 15.0, 15.0, 15.0], 'onset': [30.0, 120.0, 210.0, 300.0, 390.0]}, {'name': 'Lips', 'duration': [15.0, 15.0, 15.0, 15.0, 15.0], 'onset': [60.0, 150.0, 240.0, 330.0, 420.0]}], 'hpf': 128.0, 'regress': [{'name': 'FramewiseDisplacement', 'val': [0.16517459999999987, 0.16393550000000012, 0.060880000000000101, 0.099227999999999969, 0.092637999999999998, 0.058773500000000013, 0.08213899999999992, 0.07065919999999988, 0.059915799999999887, 0.040129600000000071, 0.087915000000000007, 0.53722140000000007, 0.37261459999999996, 0.15609944999999992, 0.20615815000000001, 0.11306650000000006, 0.78650280000000006, 0.33794455000000001, 0.19718554999999999, 0.081222700000000064, 0.047395350000000003, 0.070689999999999906, 0.054125800000000064, 0.15142230000000007, 0.044283699999999912, 0.10846885000000006, 0.13043414999999989, 0.11277090000000012, 0.078479199999999971, 0.068545650000000014, 0.090304000000000023, 0.050125399999999966, 0.10289699999999996, 0.097612349999999959, 0.15440522999999992, 0.16629848000000008, 0.047173899999999921, 0.075661450000000019, 0.060555500000000026, 0.11385728499999992, 0.035190245000000016, 0.034913249999999889, 0.16059369999999998, 0.053874784999999939, 0.13936081500000005, 0.069495279999999979, 0.11866974000000002, 0.22484146499999999, 0.16623668500000002, 0.097093499999999958, 0.071083899999999992, 0.022817399999999998, 0.11770249999999995, 0.10296874999999993, 0.081075800000000031, 0.069871350000000026, 0.097311499999999981, 0.068844000000000002, 0.046394900000000051, 0.10897365000000001, 0.14090870000000005, 0.11000940000000001, 0.1242501, 0.081413930000000051, 0.11753373000000004, 0.33189583, 0.29748943, 0.099371550000000003, 0.15874460000000001, 0.031603550000000015, 0.072232499999999977, 0.098253499999999994, 0.044037400000000011, 0.077632900000000019, 0.08363969999999997, 0.062188, 0.042488799999999986, 0.070169919999999997, 0.066629280000000013, 0.049232600000000022, 0.11020055400000001, 0.084599653999999969, 0.1351793, 0.097900799999999968, 0.76502095999999986, 0.055104880000000016, 0.10674817000000003, 0.07610355000000002, 0.054521396999999992, 0.15498364700000006, 0.12887514000000005, 0.088985495000000012, 0.077271466000000011, 0.039910559000000026, 0.13350717999999998, 0.071568700000000041, 0.15256744, 0.077055039999999977, 0.064590849999999991, 0.079980369999999981, 0.13742771000000004, 0.45459030000000011, 0.34766205000000011, 0.089609850000000019, 0.068456299999999942, 0.12760249000000001, 0.21788115999999999, 0.066572549999999994, 0.076563999999999979, 0.085570700000000069, 0.049431350000000013, 0.062972300000000009, 0.12426387, 0.25134267999999993, 0.23470850000000004, 0.29123424999999997, 0.13132495, 0.14487375000000008, 0.090303149999999957, 0.040195349999999984, 0.13619029999999999, 0.10077524999999997, 0.030785014999999964, 0.043871825600000053, 0.092358780600000023, 0.095606379999999963, 0.50843034999999992, 0.38368105000000002, 0.26847809999999994, 0.16101379999999998, 0.055101251500000031, 0.38141630150000011, 0.07587644999999997, 0.07810818999999998, 0.085004510000000061, 0.071288850000000001, 0.16647020000000001, 0.48020154999999998, 0.52059655000000005, 0.11314972000000002, 0.10985348, 0.0822349, 0.027236200000000002, 0.075436249999999969, 0.049020550000000031, 0.064593599999999987, 0.055595855, 0.10057375500000004, 0.16430800000000007, 0.12434174999999995, 0.11541970000000006, 0.089557699999999976, 0.10095553, 0.15160693, 0.065574600000000011, 0.14775870000000002, 0.37812014999999999, 0.17141424999999999, 0.51002879999999995, 0.38465404229999994, 0.2141633077, 0.20916519, 0.040236029999999964, 0.13361334000000002, 0.11888422, 0.079965549999999969, 0.037992100000000001, 0.093608399999999994, 0.097055589999999969, 0.069386785000000006, 0.078603724999999999, 0.22082002000000001, 0.16740896999999999, 0.092821599999999976, 0.036417100000000015, 0.064079649999999974, 0.12254188000000002, 0.13889573, 0.087809074999999973, 0.0]}, {'name': 'aCompCor0', 'val': [-0.029787337399999999, -0.027126343000000001, -0.051203401099999997, -0.029387428700000006, -0.0125039872, -0.032945181099999998, -0.046301911000000001, -0.019149111699999999, -0.00022791200000000001, -0.016521002, -0.021603886100000001, -0.021797721999999999, -0.019423610099999999, -0.035296345899999998, -0.0520776238, -0.0479258901, -0.041302992699999999, -0.023178171599999998, -0.0059673935999999999, -0.0090065806999999991, -0.0158546169, -0.011554428500000002, -0.0170745268, -0.0014300235000000001, -0.016433731699999999, -0.036652581099999998, -0.025225791099999999, -0.0086260180000000009, 0.00089371890000000003, -0.0140987341, -0.0111827943, -0.0051167748000000004, -0.0013633545000000002, 0.0052061965999999999, 0.0112013254, 0.0159769869, -0.0099001982999999995, -0.0118203708, -0.016784696599999999, -0.0190336862, 0.0074874809999999998, 0.00072439240000000005, -0.01266427, -0.043328152699999997, -0.0134611448, -0.0046127210000000002, 0.0087336259999999995, 0.0055675204000000004, -0.0033516797, -0.039493255099999999, -0.023383822799999999, -0.020578691199999999, -0.017104728700000002, -0.017042326100000001, -0.0171798339, -0.011711685600000001, -0.0151463233, -0.0066473607000000004, 0.028155579100000001, 0.014461842000000001, -0.0057811999999999994, -0.030671530200000002, 0.0233856541, 0.027137187600000001, 0.0027355431, -0.029965167400000006, -0.041082093100000001, 0.032954683800000002, 0.036213154300000001, 0.0068314183999999998, -0.0145182781, -0.0234055284, -0.0056675579, -0.0091387602000000002, -0.021040238500000003, -0.0190979854, -0.030881145700000001, -0.040717703100000002, -0.0070509555000000017, 0.0096555003999999993, 0.0022529939999999999, -0.0083846658999999994, 0.0006370414, -0.0018562305999999999, -0.0083701631999999991, -0.0095969987999999992, -0.024719947499999999, -0.018858894399999999, -0.020594366100000001, -0.036767015700000003, -0.0042097018, -0.012692601699999998, 0.013887185999999999, 0.028031830899999999, 0.025839508399999999, -0.0228585826, -0.031313985799999999, -0.0194732273, 0.0143758514, 0.0048750848999999999, 0.0033111809999999998, -0.0081179001000000004, -0.013139334900000001, 0.0187201179, 0.036244090899999998, 0.0087434086000000005, -0.027991180599999999, -0.032419889799999997, -0.0148870284, -0.0046234036999999997, -0.035570123199999998, 0.0030580484000000004, -0.0098039713000000004, -0.031142192499999999, -0.034851765899999998, -0.019690035200000001, -0.0010344396, 0.017458019799999999, 0.030648072799999999, -0.0001594919, -0.011257111699999999, 0.0028793618999999999, -0.0104290393, -0.021593099800000001, -0.0028101565, 0.00029135240000000001, 0.013979288100000001, -0.010283092400000001, 0.021765751699999999, 0.032106944700000001, 0.0278205742, -0.0068209759999999994, -0.0041961221000000005, 0.0131831525, 0.039940756800000005, 0.048781098799999999, 0.033303576299999998, 0.013995385500000001, 1.00128e-05, 0.011426144900000001, 0.025093135200000002, 0.0154904073, 0.0160871413, 0.0065396095999999994, 0.0073776600000000003, 0.0040491609000000003, 0.0085823131000000007, 0.0130497748, 0.0031480835, 0.0102042212, 0.022641664300000003, 0.0020726693000000002, -0.0074258218000000003, 0.0198901901, 0.0137436678, 0.019989295800000001, -0.0123828047, -0.0055813805000000001, 0.0031051718000000002, -0.0073085403000000002, 0.019825193200000001, 0.007844199100000001, -0.0016119959000000001, 0.0045174580999999998, -0.0052795825999999999, 0.0035846697000000002, 0.0026223156999999999, -0.0072809410999999996, -0.0188892908, -0.021967029300000003, -0.0074360664, 0.016340041200000002, 0.0092994983999999999, 0.0050949348999999996, 0.0101891308, 0.018061509999999999, -0.0030783376999999998, 0.0040098661000000004, 0.0040712748, 0.0051473747000000004]}, {'name': 'aCompCor1', 'val': [-0.11578609550000001, -0.11033201049999999, -0.13184946450000001, -0.1083028318, -0.14154735710000002, -0.097049770199999996, -0.078814153400000003, -0.033135085500000001, -0.065707416699999993, -0.056181931800000001, 0.0037981006999999998, -0.045334739200000002, -0.037686229299999999, -0.066403508, -0.014811630500000001, -0.055983364400000006, -0.030131254400000002, -0.092650565500000004, -0.057167333000000001, -0.062745490400000006, -0.095996972900000005, -0.081538373999999997, -0.0595359684, -0.090958995000000001, -0.074927759699999999, -0.075817856900000008, -0.065191184900000004, -0.080211726600000005, -0.058069516699999997, -0.044871359800000003, -0.025595149300000002, -0.031200974400000001, -0.025603879500000003, -0.044005765099999997, 0.010709205899999999, -0.08651006289999999, -0.0313382829, -0.053144728000000002, -0.040695838400000003, -0.056464030900000003, -0.018979006199999999, -0.010694827299999999, -0.041911852400000005, -0.0256989904, -0.016764023200000002, -0.012492543700000001, 0.017311740400000001, 0.012392200500000001, 0.011430644199999999, 0.0056269149999999997, 0.0037507486000000001, 0.021414425899999999, 0.0033740032000000001, 0.022157377200000002, 0.072229329299999992, 0.076203672400000005, 0.083738073199999999, 0.066722911600000004, 0.098248535600000006, 0.089100361300000014, 0.0647743286, 0.055879892200000003, 0.081797537000000003, 0.097366012299999999, 0.070988143599999998, 0.1095221712, 0.038573830199999999, 0.075535826100000009, 0.1043039211, 0.088186438200000009, 0.094055337200000005, 0.10001068809999999, 0.1001776481, 0.087814330800000007, 0.069547605099999993, 0.080782699499999999, 0.0497086126, 0.069903318499999992, 0.094297064900000005, 0.10313191770000001, 0.1069187456, 0.098721393399999996, 0.092960586499999998, 0.1047134316, 0.089920491800000002, 0.083591216799999993, 0.093164941700000004, 0.097155287100000029, 0.1090778017, 0.083052290799999998, 0.099911218699999998, 0.1090115426, 0.1002036025, 0.1051859901, 0.085804895399999997, 0.070457387400000002, 0.094383590000000003, 0.091018304800000005, 0.079144049399999999, 0.093223580900000005, 0.074378128700000004, 0.062544964999999994, 0.076695570300000002, 0.068709455000000003, 0.070666179800000006, 0.083111602399999998, 0.0831870901, 0.065317177199999993, 0.098568640799999996, 0.1138259428, 0.092283988600000005, 0.13315728960000001, 0.084943374299999999, 0.1046313691, 0.054119090799999998, 0.045099328700000003, 0.030244684399999999, 0.012823961199999999, 0.001153875, 0.0200313014, 0.069875332999999998, 0.046684835600000002, 0.051367755799999998, 0.089491664200000001, 0.071209344199999997, 0.032757561300000002, 0.026681101499999998, 0.0057181161999999997, -0.0449169918, -0.033839602400000002, -0.0072282469999999984, -0.034467928600000003, 0.023200504100000002, 0.026235793600000001, -0.0044818636999999998, 0.021459207099999999, -0.0064161162000000004, 0.036030704199999999, -0.011061182899999999, -0.067271571900000007, -0.038878969100000001, -0.071556390300000008, -0.053168290999999999, -0.0748732909, -0.040954178799999998, -0.048706621500000005, -0.024741187400000003, -0.0083679918999999998, -0.038465797400000001, -0.056105933900000002, -0.076491032900000006, -0.0486496134, -0.056590667699999986, -0.031246646699999998, -0.0477910603, -0.0271649443, -0.034462728300000002, -0.093014857899999998, -0.048675283200000002, -0.034235977200000003, -0.029940166000000001, -0.027637978399999999, -0.049107534699999997, -0.077140022699999991, -0.057391339100000001, -0.1069909416, -0.1128300461, -0.10240887379999999, -0.093708472099999995, -0.086002103800000007, -0.11304430209999999, -0.1070386651, -0.1025451473, -0.098752571799999994, -0.089242138000000013, -0.1116983156, -0.1286271957, -0.1102951774, -0.090843521999999996, -0.118746754]}, {'name': 'aCompCor2', 'val': [-0.043665168600000005, -0.023456332399999998, -0.111557805, -0.089852424800000011, 0.020268793300000001, -0.070056082500000005, -0.13751253520000001, -0.0688094385, 0.049053064, -0.0089621049000000001, -0.058545419600000002, -0.0051941388999999999, 0.013400086, -0.058772034700000003, -0.099423656999999999, 0.018319964099999999, -0.032620704900000005, 0.071989016399999994, 0.079231102900000003, 0.035226325500000003, 0.025298902000000002, 0.029206158900000001, 0.0023409002, 0.019851566300000002, -0.014889274100000001, -0.054149570700000003, -0.038566477299999999, 0.029424544800000001, 0.074693129400000002, 0.062337480200000003, 0.037235119400000002, 0.068623961900000002, 0.082706671400000001, 0.1035792001, 0.1087149622, 0.0963407233, 0.0293220498, 0.0337554495, 0.012204878799999999, -0.026385650399999998, 0.098574713999999994, 0.099156304599999995, 0.043832177799999997, -0.045191459100000005, -0.0037288979, 0.081102371699999995, 0.099170194599999997, 0.060068886699999997, 0.069264459, -0.091921315300000001, -0.096615101699999997, -0.071791723899999993, -0.056051367999999997, -0.0212800517, -0.032656801700000002, 0.0017030395999999999, -0.0225531034, 0.036743984, 0.0785967271, 0.085955064999999997, 0.020236456900000001, -0.0552988814, 0.1237584675, 0.15628387869999999, 0.081089345300000004, -0.068737483899999993, -0.1035512296, 0.1291314247, 0.1639554902, 0.087722150200000001, 0.015497091100000001, -0.0313658333, -0.0047461561000000001, -0.025719046299999999, -0.037287955300000002, -0.041648262599999999, -0.032525126699999997, -0.093925459700000005, -0.0212541428, 0.037226790799999999, 0.033569019800000002, 0.0058225723000000004, -0.0090722948999999997, -0.0288112653, -0.0055826785000000004, -0.094358979999999995, -0.1072290248, -0.10299388600000001, -0.095187802000000002, -0.123070209, -0.082477436399999993, -0.070556431099999997, 0.057542889799999997, 0.087661770500000014, 0.1317806889, -0.092239402999999998, -0.12903026770000001, -0.077387913700000005, 0.033607365299999997, 0.0071549218999999997, -0.0057052679000000007, -0.010611686499999998, -0.058048979400000013, 0.044008441299999999, 0.14705772449999999, 0.082967952900000003, -0.035898470000000002, -0.1030555447, -0.0091946987999999997, 0.0061509567000000006, -0.093117539599999993, -0.0470495701, -0.061059726699999997, -0.17514563759999999, -0.13765940300000001, -0.1090784243, -0.0018178946, 0.082412683600000008, 0.069640501300000004, 0.060713937099999997, 0.013354006000000002, -0.0351947632, -0.065259077200000001, -0.063526000999999999, -0.017872758400000001, 0.0048745390999999994, 0.076179711900000002, -0.079807353600000006, 0.1013434805, 0.15062043429999999, 0.14653245509999999, 0.0027660550999999999, 0.0050799779999999998, 0.034754966300000002, 0.16529902960000001, 0.189010758, 0.13000816339999999, 0.062552986399999996, 0.014708109699999999, 0.0043166204000000003, 0.056987154200000001, 0.1095495032, 0.0237509144, 0.0073927202999999999, 0.033764830499999995, 0.036187904100000001, 0.067494682400000006, 0.033898066900000003, 0.0446869243, 0.032630381200000003, 0.050287891900000006, 0.0033095849999999999, -0.090864377999999996, 0.0324372718, 0.023764179999999999, 0.0203472338, -0.090009762100000029, -0.13665239099999998, -0.012958247500000001, -0.066000156099999999, 0.065349927000000002, 0.026656258299999999, -0.00084562299999999999, 0.039218171099999997, -0.0523503409, -0.061417817899999998, -0.041345517999999998, -0.054234041699999999, -0.106185896, -0.14667681869999999, -0.1004454821, 0.036625834900000001, -0.07266498099999999, 0.0053669273000000002, -0.0153679018, 0.045926711699999997, -0.060106823500000003, -0.051659126100000001, -0.028506134900000001, 0.047404745800000002]}, {'name': 'aCompCor3', 'val': [0.075484539400000009, 0.051970740000000001, 0.1081095066, 0.058485828600000012, 0.07509964429999999, 0.078467751500000002, 0.08569157849999999, 0.031383950000000001, 0.107092983, 0.081163667800000006, 0.016514192, 0.018845444900000001, 0.0058696238999999999, 0.034631121399999999, -0.029372344900000007, 0.0026657746000000003, -0.029178926300000001, 0.049222093500000001, -0.012602898100000001, 0.0049887038, 0.068243836200000005, 0.042205456799999999, 0.0395021157, -0.032707368600000002, 0.016506371699999998, 0.00051754209999999999, -0.0097818343000000002, 0.0067880667000000004, -0.038791527499999999, -0.0062421559999999996, -0.054415894800000003, -0.033569113800000001, -0.077847032499999996, -0.042737903000000001, -0.045491804499999997, 0.0036748899000000001, -0.037361994500000002, -0.033058712900000002, -0.0127874219, -0.053061296900000006, -0.087986511400000009, -0.087899171999999998, -0.011856074499999999, -0.013668868799999999, -0.068436166800000003, -0.091519600899999998, -0.052638073100000002, -0.047321748400000002, -0.064420665799999999, -0.095045061099999995, -0.089299780399999987, -0.037877491200000002, -0.1045627708, -0.056433084299999998, -0.11523098900000001, -0.1102722642, -0.0071816982999999999, -0.065964233600000005, -0.1070282558, -0.049884525399999997, -0.080273038099999999, -0.049368531799999997, -0.0192125769, -0.0612922459, -0.078051598200000002, -0.010404421699999999, -0.022326148099999998, -0.064131227599999993, -0.093163928199999996, -0.0017902447999999999, -0.038206398599999997, -0.021230858700000001, 0.0066938414, -0.063842255199999989, -0.1138231214, -0.091482947699999997, -0.045925984900000001, -0.060422803999999997, -0.11528220760000001, -0.066928209699999991, -0.049043913600000003, -0.039479979999999998, -0.02364571, -0.055364891999999999, -0.1172049307, -0.099368592899999997, -0.1057920889, -0.033143603399999999, -0.015954881899999999, -0.059465847500000002, -0.042409538500000003, -0.013116216399999998, 0.0240477344, 0.043119971799999997, 0.025333285800000001, 0.104277439, 0.029985935500000001, 0.030066171100000001, 0.072326588299999994, 0.053612286600000003, 0.10322658480000001, 0.075521283099999989, -0.016219361000000002, 0.064107777800000001, -0.0063349786, 0.052388420599999999, 0.084808665000000005, 0.080719463700000008, 0.039399481299999997, 0.070897079000000002, 0.072733165500000002, 0.063010492000000001, 0.054295482700000001, 0.16498216979999999, 0.15436226419999999, 0.21103221389999999, 0.14999855619999999, 0.1249106054, 0.1390854869, 0.15684560450000001, 0.038908014800000001, 0.15751792980000001, 0.093810383400000003, 0.091865609700000003, 0.044202943299999999, -0.00093279609999999998, 0.033075921100000003, 0.08251327230000001, 0.1533646108, 0.13407653289999999, 0.044328932600000003, 0.1034653161, 0.0072221158999999984, 0.0176752981, 0.0062559915000000004, -0.0026099008999999999, -0.0023552435000000001, 0.081497684900000006, 0.078826838600000004, 0.081149658499999999, 0.018007131900000001, 0.087663654000000008, 0.048206815799999997, 0.094970662799999994, 0.10141340610000001, 0.1082709187, 0.085277269700000005, 0.1009383027, 0.048121372099999997, 0.033451968200000001, 0.073331336299999994, -0.021453555700000002, 0.041625241200000003, -0.050918579200000001, -0.1076689996, -0.036916995000000001, -0.087907701899999996, -0.035880144500000002, -0.067531560599999998, 0.045443701400000001, -0.020995433399999999, 0.033131181799999999, -0.024299832200000003, -0.0470639453, -0.060885063699999999, -0.058055088600000013, -0.081519278099999995, -0.080857174800000001, -0.1376300788, -0.12919356339999999, -0.064867225899999992, -0.0952414969, -0.14166033710000001, -0.054057478499999999, -0.062154847700000002, -0.1211820995, -0.1097194334, -0.1003409601, -0.026750889500000003, -0.13318793369999998]}, {'name': 'aCompCor4', 'val': [0.0320880578, 0.13012074470000001, 0.1412351547, 0.0239499803, 0.078678664400000001, 0.011371399500000001, -0.092331951999999995, -0.034474906999999999, 0.097486598199999996, 0.1187928093, 0.0341760994, 0.019139288300000001, 0.031615493600000003, 0.0066912280000000005, -0.051102704000000006, -0.066266686200000008, -0.097852739300000005, -0.031278092200000003, -0.052582394400000003, -0.0138558104, -0.0039462630999999998, -0.092938341199999996, -0.083598689300000001, 0.023278812699999998, 0.0379015454, -0.040050381099999997, -0.097029811600000002, 0.0040087643000000003, -0.019532535, -0.026924560300000001, -0.074573407800000005, -0.021861287000000004, -0.055592252500000001, 0.016685884299999999, -0.13051911869999999, 0.094632721500000003, 0.0304729005, 0.078458453099999992, 0.013711492800000001, -0.024768567799999999, -0.062481929700000001, -0.054606966799999997, -0.098210559099999997, -0.18844416520000001, -0.069056672099999994, -0.0090246618000000001, -0.082085385900000002, -0.041483315700000002, 0.017857519700000001, 0.092331110300000005, 0.048361529600000001, 0.040752987499999997, 0.0169790093, -0.079752977599999997, -0.046840294099999999, -0.099722404599999995, -0.093294821799999997, -0.18702306639999999, -0.054664912900000001, 0.032164453199999998, 0.11523668500000001, 0.107765267, 0.013433538300000001, -0.037306069900000002, -0.0098343430000000006, -0.044155606200000003, -0.063983731099999996, 0.19781306630000001, 0.19863423120000001, 0.1124642644, 0.088739776899999998, 0.0031341709999999998, 0.0029051559999999999, 0.027395974500000003, 0.06419303400000001, 0.076901128499999999, -0.060590257000000002, -0.19378773969999999, -0.1090319617, -0.053056195700000003, -0.038201207799999998, -0.072944066500000002, -0.075156831600000001, 0.075213080500000001, 0.16961678450000001, 0.13958724089999999, 0.15102600669999999, 0.038705678200000003, -0.1216104053, -0.094228598299999994, -0.12757740480000002, 0.0969349979, -0.031276926000000004, 0.047563873600000001, 0.12814658470000001, 0.17781609550000002, 0.0391234783, 0.048983965499999997, 0.1145872622, 0.12669015559999999, 0.054037607100000003, 0.050529721900000005, 0.072776643000000002, -0.043275403600000005, 0.061133852300000013, 0.040976703599999997, -0.12028452319999999, -0.043665770399999998, -0.1101067377, 0.0128234714, -0.0071412626, 0.035723438199999999, 0.0042124175000000002, 0.086227784700000004, -0.013226508499999999, -0.027042454099999998, -0.0057705958999999998, 0.059085077999999999, -0.013786369099999999, -0.0173913108, -0.0583686229, -0.035490916300000001, 0.067940013499999993, -0.025477052100000001, -0.030548758400000001, -0.1188587201, -0.0103653685, -0.091473465300000001, -0.050732780599999999, -0.041052992400000002, 0.021231042400000004, -0.025864803400000001, -0.032849903100000001, -0.064777377999999997, -0.0296557452, -0.0127340426, 0.056237987599999997, -0.0105221133, 0.097717955600000003, -0.0766329397, -0.057162497600000001, -0.036552425299999997, -0.095863034999999999, -0.069495190900000003, -0.10769519280000001, 0.063843127200000002, 0.030614075599999999, -0.0035967124999999999, -0.013765680400000001, -0.080996548700000004, -0.0343835698, 0.0042741398999999996, -0.048751716200000003, 0.027604365200000001, 0.0017479109, 0.0056497392, -0.011714764000000001, 0.072414487200000002, -0.020521832, 0.027518121800000003, 0.024047936400000001, 0.0063981838000000003, -0.045163770800000003, 0.018078692100000002, -0.0014874802999999999, 0.018070074799999999, 0.0100305651, -0.021246006599999999, -0.0017599950000000001, -0.019624814000000001, 0.038985660999999998, -0.040806490000000001, 0.0103941382, 0.1042369207, 0.1164231901, 0.091340607599999998, 0.076977090099999992, 0.060686367599999999, -0.10734302129999999, -0.0093989581999999999]}, {'name': 'aCompCor5', 'val': [-0.07404618360000001, -0.094020251999999999, -0.072963172199999995, -0.1677090276, -0.063856662999999994, -0.011268755199999999, -0.14657032720000002, -0.1185421913, -0.12507691769999998, -0.029922386200000001, -0.081943743999999999, 0.015444018300000001, -0.10776901699999999, 0.010149702700000001, 0.1105569762, 0.042210747700000002, 0.050000900199999997, 0.056963683000000001, 0.0065846161999999998, 0.065633760999999999, 0.021559569399999999, 0.089590400799999997, 0.092592122700000001, 0.020555357699999999, 0.030659049300000001, 0.062923456799999999, 0.088374990399999992, 0.063374199199999995, 0.10286621460000001, 0.026006781199999999, 0.1016652755, 0.12925180089999999, 0.074957513700000006, -0.042131750900000001, 0.1005681291, 0.030131305300000001, 0.012114333499999999, -0.029943607800000001, 0.043046874399999997, 0.11258079259999999, -0.027162038600000001, -0.039960323700000001, 0.1021708249, -0.013829223200000001, 0.0146285303, 0.032930977200000003, 0.059472780500000003, 0.060133871100000014, 0.0617058022, -0.035562991600000003, 0.035433294500000004, 0.083502180499999995, -0.021148279700000001, 0.091840210000000005, 0.056030184099999998, 0.1645317811, 0.027596403299999999, 0.019580386200000001, -0.1122809864, 0.0066369418000000006, -0.0286048146, -0.0082888687999999999, 0.0194031806, 0.033324777200000003, 0.0090175507999999995, 0.041418941200000003, -0.076096885500000003, -0.014511191, -0.0097917713, 0.043200582199999997, 0.024766574500000003, 0.0507621984, -0.0097589984999999994, 0.072139721599999998, 0.051247928700000001, 0.043820242300000006, -0.1127422933, -0.074076430799999995, -0.12549854939999999, -0.067960280200000001, -0.1124603158, -0.18141500520000001, -0.1181338712, -0.098977975699999998, -0.14436967539999998, 0.0440193116, 0.042738392700000002, 0.032041782799999995, -0.0111130502, -0.1196959125, -0.074692156299999993, 0.095312377399999995, -0.13304515410000001, -0.046426457599999998, -0.053157587100000001, 0.1182480025, 0.032903952400000006, 0.049336148200000006, -0.029137789899999999, 0.072144904400000001, 0.017088169600000001, -0.0415889485, 0.098540582000000002, -0.092894974800000002, -0.1096597321, -0.10471217569999999, -0.032296780800000001, -0.1157751665, -0.050322041100000006, 0.0029802428000000004, 0.043758333500000003, 0.0128351695, 0.022637819399999998, -0.0020479324999999999, 0.026853813800000001, -0.0034875167000000002, 0.0002288619, 0.036449246099999999, 0.118630833, 0.080104838600000006, 0.099757531400000002, 0.10233473849999999, 0.15028291400000002, 0.094273053400000001, 0.050110442900000003, -0.1073879309, -0.089689196799999996, -0.048190511900000003, 0.046369176200000001, 0.045138616300000003, 0.076167955699999998, 0.07360490900000001, 0.028702656300000001, -0.018917997200000002, -0.080417005599999994, -0.015529982499999999, -0.15812108120000001, 0.0229495041, 0.1123836227, -0.076133992900000003, -0.13957697569999999, -0.13450262630000001, -0.080284240000000007, -0.048899282199999998, -0.0331885081, -0.039820128500000003, -0.018381057100000001, 0.066083501900000008, 0.0153182944, -0.0189205741, 0.0395984962, 0.029206376700000002, 0.078240349900000006, -0.075634219799999999, -0.034911722100000001, 0.0228787217, 0.069368218799999992, -0.0156508016, -0.0075922398, -0.0202444073, -0.023300752200000004, 0.0168287531, 0.077331469400000005, 0.056664653200000012, 0.063451734999999995, -0.024576799699999999, -0.016257608999999999, -0.043999974900000002, -0.099474367600000002, -0.032843924699999999, -0.1119562673, -0.1088102588, -0.036089787999999998, -0.061994486799999998, 0.042538110400000002, 0.054300848200000001, 0.071870227300000006, 0.13802269810000001, 0.091616283500000006, 0.058382107900000001]}], 'scans': '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-fsl-utils-ExtractROI/90e73a4efdfb9677c5c883f59a536b34/sub-06_ses-test_task-fingerfootlips_bold_space-MNI152NLin2009cAsym_preproc_roi.nii'}]

In [14]:
finger_cond = ['Finger','T', ['Finger'],[1]]
foot_cond = ['Foot','T', ['Foot'],[1]]
lips_cond = ['Lips','T', ['Lips'],[1]]
lips_vs_others = ["Lips vs. others",'T', ['Finger', 'Foot', 'Lips'],[-0.5, -0.5, 1]]
all_motor = ["All motor", 'F', [finger_cond, foot_cond, lips_cond]]

contrasts=[finger_cond, foot_cond, lips_cond, lips_vs_others, all_motor]
    
matlab_cmd = '/home/vagrant/spm12/run_spm12.sh /home/vagrant/mcr/v85/ script'
spm.SPMCommand.set_mlab_paths(matlab_cmd=matlab_cmd, use_mcr=True)

level1design = mem.cache(spm.model.Level1Design)
level1design_results = level1design(interscan_interval = layout.get_metadata(source_epi.filename)["RepetitionTime"],
                                    bases = {'hrf':{'derivs': [0,0]}},
                                    session_info = specify_model_results.outputs.session_info,
                                    model_serial_correlations='AR(1)',
                                    timing_units='secs')

level1design_results.outputs


170216-18:24:42,653 workflow INFO:
	 Executing node d0fc8acdda948ce663ee87e3deb334c7 in dir: /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-Level1Design/d0fc8acdda948ce663ee87e3deb334c7
170216-18:24:42,668 workflow INFO:
	 Collecting precomputed outputs
Out[14]:
spm_mat_file = /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-Level1Design/d0fc8acdda948ce663ee87e3deb334c7/SPM.mat

In [15]:
estimatemodel = mem.cache(spm.model.EstimateModel)
estimatemodel = estimatemodel(estimation_method={'Classical': 1}, 
                              spm_mat_file=level1design_results.outputs.spm_mat_file)
estimatemodel.outputs


170216-18:24:44,594 workflow INFO:
	 Executing node eeceacdf058c01cd9b67720165f53474 in dir: /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474
170216-18:24:44,598 workflow INFO:
	 Collecting precomputed outputs
Out[15]:
RPVimage = /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/RPV.nii
beta_images = ['/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0001.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0002.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0003.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0004.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0005.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0006.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0007.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0008.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0009.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0010.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/beta_0011.nii']
mask_image = /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/mask.nii
residual_image = /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/ResMS.nii
spm_mat_file = /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateModel/eeceacdf058c01cd9b67720165f53474/SPM.mat

In [16]:
estimatecontrasts = mem.cache(spm.model.EstimateContrast)
estimatecontrasts = estimatecontrasts(contrasts=contrasts,
                                      spm_mat_file=estimatemodel.outputs.spm_mat_file,
                                      beta_images=estimatemodel.outputs.beta_images,
                                      residual_image=estimatemodel.outputs.residual_image)
estimatecontrasts.outputs


170216-18:24:45,525 workflow INFO:
	 Executing node 4b2ee7cf0f93c6e576f9d3fc13948665 in dir: /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665
Out[16]:
con_images = ['/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/con_0001.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/con_0002.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/con_0003.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/con_0004.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/ess_0005.nii']
ess_images = /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/ess_0005.nii
spmF_images = /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/spmF_0005.nii
spmT_images = ['/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/spmT_0001.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/spmT_0002.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/spmT_0003.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/spmT_0004.nii', '/home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/spmF_0005.nii']
spm_mat_file = /home/vagrant/fmri-analysis-vm/analysis/firstlevel/nipype_mem/nipype-interfaces-spm-model-EstimateContrast/4b2ee7cf0f93c6e576f9d3fc13948665/SPM.mat

In [17]:
for con_image in estimatecontrasts.outputs.spmT_images:
    nilearn.plotting.plot_glass_brain(nilearn.image.smooth_img(con_image, 8),
                                      display_mode='lyrz', colorbar=True, plot_abs=False, threshold=2.3)



In [18]:
for con_image in estimatecontrasts.outputs.con_images:
    nilearn.plotting.plot_glass_brain(nilearn.image.smooth_img(con_image, 8),
                                      display_mode='lyrz', colorbar=True, plot_abs=False)