-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAFNI_resting.py
executable file
·49 lines (38 loc) · 1.5 KB
/
AFNI_resting.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# PURPOSE: run AFNI noise regression
import os
import glob
from shutil import copyfile
import pandas as pd
import json
import numpy as np
from subprocess import call
fmriprep_out="/data/jag/cnds/amennen/rtAttenPenn/fmridata/Nifti/derivatives/fmriprep"
reg_save_dir='/data/jag/cnds/amennen/rtAttenPenn/fmridata/Nifti/derivatives/resting/confound_EVs'
trunc_save_dir = '/data/jag/cnds/amennen/rtAttenPenn/fmridata/Nifti/derivatives/resting/trunc'
noise_save_dir = '/data/jag/cnds/amennen/rtAttenPenn/fmridata/Nifti/derivatives/resting/clean'
# subjects 106,3,107,4,108 got resting state
subjectNum = 106
bids_id = 'sub-{0:03d}'.format(subjectNum)
print(bids_id)
sessions = [1,3]
for s in session:
subjectDay = s
ses_id = 'ses-{0:02d}'.format(subjectDay)
print(ses_id)
# get regression file
confounds_path = reg_save_dir + '/' + bids_id + '/' + ses_id
confound_fn = glob.glob(os.path.join(confounds_path, '*.1D'))
confound_fn = confound_fn[0]
# get nifti file
nifti_path = trunc_save_dir + '/' + bids_id + '/' + ses_id
nifti_fn = glob.glob(os.path.join(nifti_path, '*.nii.gz'))
nifti_fn = nifti_fn[0]
# specify where to save cleaned version
clean_path = noise_save_dir + '/' + bids_id + '/' + ses_id
if not os.path.exists(clean_path):
os.makedirs(clean_path)
command = ("3dTproject -polort 1 -blur 6 -passband 0.0083 0.1 "
"-input {0} ".format(nifti_fn) +
"-ort {0} ".format(confound_fn) +
"-prefix {0}/{1}_{2}_task_rest_glm.nii.gz".format(clean_path,bids_id,ses_id))
call(command,shell=True)