-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment3.py
83 lines (66 loc) · 3.45 KB
/
experiment3.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
def BET (file_in, file_out, parameters):
command = 'bet ' + file_in + ' ' + file_out + ' ' + parameters
#print(command)
os.system(command)
def GLM (pathFileIn, pathDesignMatrix, pathOut, pathRes, pathMask):
command = 'fsl_glm' + ' -i ' + pathFileIn + ' -d ' + pathDesignMatrix + ' -o ' + pathOut + ' --out_res=' + pathRes + ' -m ' + pathMask
#print(command)
os.system(command)
def FAST (file_in, parameters):
command = 'fast ' + parameters + ' ' + file_in
os.system(command)
import nibabel as nib
import numpy as np
from dipy.align.reslice import reslice
import utils as t
import os.path
generalPath = '/home/jrudascas/Desktop/IBIA/'
pathMask = '/usr/share/fsl/data/standard/MNI152_T1_2mm_brain_mask.nii.gz'
dwiPath = 'data/functional/fmri.nii.gz'
t1Path = 'data/structural/fwmfT1.nii.gz'
maskPath = 'data/structural/fwc1fT1.nii.gz'
preResliced = 'data/_T1resliced.nii.gz'
preBET = 'data/_bet.nii.gz'
preBET_mask = 'data/_bet_mask.nii.gz'
preDesignMatrix = 'data/'
timeDelayMapList = []
amplitudeWeightedTimeDelayMapList = []
for group in sorted(os.listdir(generalPath)):
pathInto = os.path.join(generalPath, group)
if os.path.isdir(pathInto):
for dir in sorted(os.listdir(pathInto)):
if os.path.isdir(os.path.join(pathInto, dir)):
pathfMRI = os.path.join(os.path.join(pathInto, dir), dwiPath)
t1 = os.path.join(os.path.join(pathInto, dir), t1Path)
greyMatter = os.path.join(os.path.join(pathInto, dir), maskPath)
pathT1Resliced = os.path.join(os.path.join(pathInto, dir), preResliced)
pathBET = os.path.join(os.path.join(pathInto, dir), preBET)
pathBET_maks = os.path.join(os.path.join(pathInto, dir), preBET_mask)
pathDesignMatrix = os.path.join(os.path.join(pathInto, dir), preDesignMatrix)
T1img = nib.load(t1)
T1Data = T1img.get_data()
T1Affine = T1img.affine
print('-----------------------------------------')
print(dir)
print('-----------------------------------------')
print("Reslicing")
if not os.path.exists(pathT1Resliced):
T1Resliced, affine2 = reslice(T1Data, T1Affine, T1img.header.get_zooms()[:3], (2., 2., 2.))
mask_img = nib.Nifti1Image(T1Resliced.astype(np.float32), affine2)
nib.save(mask_img, pathT1Resliced)
print("BET")
if not os.path.exists(pathBET):
BET(pathT1Resliced, pathBET, '-m -f .4')
print("FAST")
if not os.path.exists(pathDesignMatrix + '_bet_pve_0.nii.gz'):
FAST(pathBET, parameters='-n 3 -t 1')
print('Building Matrix Design')
if not os.path.exists(pathDesignMatrix + 'designMatrix.out'):
maskEV = [pathDesignMatrix + '_bet_pve_0.nii.gz',
pathDesignMatrix + '_bet_pve_2.nii.gz',
pathBET_maks]
dm = t.toBuildMatrixDesign(pathfMRI, pathOut=pathDesignMatrix, maskEVs=maskEV, maskThreadhold=0.8)
print('GLM')
if not os.path.exists(pathDesignMatrix + 'functional/' + 'fmriGLM.nii.gz'):
GLM(pathfMRI, dm, pathOut=pathDesignMatrix + 'ppp.txt', pathRes=pathDesignMatrix + 'functional/' + 'fmriGLM.nii.gz', pathMask=pathMask)