1818import multiprocessing
1919from util import *
2020
21- SCRIPTDIR = os . path . dirname (__file__ )
22- ROOTDIR = os . path . abspath (os . path . join (SCRIPTDIR , '..' ))
23- mniTmp = os . path . join (ROOTDIR , 'IITAtlas' , 'IITmean_FA.nii.gz' )
21+ SCRIPTDIR = dirname (__file__ )
22+ ROOTDIR = abspath (pjoin (SCRIPTDIR , '..' ))
23+ mniTmp = pjoin (ROOTDIR , 'IITAtlas' , 'IITmean_FA.nii.gz' )
2424
2525config = ConfigParser ()
26- config .read (f'/tmp/harm_config_{ os . getpid ()} .ini' )
26+ config .read (f'/tmp/harm_config_{ getpid ()} .ini' )
2727N_proc = int (config ['DEFAULT' ]['N_proc' ])
2828diffusionMeasures = [x for x in config ['DEFAULT' ]['diffusionMeasures' ].split (',' )]
2929bshell_b = int (config ['DEFAULT' ]['bshell_b' ])
3030
3131def register_reference (imgPath , warp2mni , trans2mni , templatePath ):
3232
3333 print (f'Warping { imgPath } diffusion measures to standard space' )
34- directory = os . path . dirname (imgPath )
34+ directory = dirname (imgPath )
3535 inPrefix = imgPath .split ('.nii' )[0 ]
3636 prefix = basename (inPrefix )
3737
3838 for dm in diffusionMeasures :
3939
40- output = os . path . join (templatePath , prefix + f'_InMNI_{ dm } .nii.gz' )
40+ output = pjoin (templatePath , prefix + f'_InMNI_{ dm } .nii.gz' )
4141
4242 # reference site have been already warped to reference template space in buildTemplate.py: warp_bands()
43- # warped data are os.path.join (templatePath, prefix, prefix + f'_WarpedFA.nii.gz')
44- moving = os . path . join (templatePath , prefix + f'_Warped{ dm } .nii.gz' )
43+ # warped data are pjoin (templatePath, prefix, prefix + f'_WarpedFA.nii.gz')
44+ moving = pjoin (templatePath , prefix + f'_Warped{ dm } .nii.gz' )
4545
4646 # so warp diffusion measure to MNI space directly
4747 antsApplyTransforms [
@@ -56,22 +56,22 @@ def register_reference(imgPath, warp2mni, trans2mni, templatePath):
5656def register_target (imgPath , templatePath ):
5757
5858 print (f'Warping { imgPath } diffusion measures to standard space' )
59- directory = os . path . dirname (imgPath )
59+ directory = dirname (imgPath )
6060 inPrefix = imgPath .split ('.nii' )[0 ]
6161 prefix = basename (inPrefix )
6262
63- dmImg = os . path . join (directory , 'dti' , prefix + f'_FA.nii.gz' )
64- outPrefix = os . path . join (templatePath , prefix .replace (f'_b{ bshell_b } ' ,'' ) + '_FA_ToMNI' )
63+ dmImg = pjoin (directory , 'dti' , prefix + f'_FA.nii.gz' )
64+ outPrefix = pjoin (templatePath , prefix .replace (f'_b{ bshell_b } ' ,'' ) + '_FA_ToMNI' )
6565 warp2mni = outPrefix + '1Warp.nii.gz'
6666 trans2mni = outPrefix + '0GenericAffine.mat'
6767 # unprocessed target data is given, so in case multiple debug is needed, pass the registration
68- if not os . path . exists (warp2mni ):
68+ if not exists (warp2mni ):
6969 antsReg (mniTmp , None , dmImg , outPrefix )
7070
7171 for dm in diffusionMeasures :
72- output = os . path . join (templatePath , prefix + f'_InMNI_{ dm } .nii.gz' )
72+ output = pjoin (templatePath , prefix + f'_InMNI_{ dm } .nii.gz' )
7373
74- moving = os . path . join (directory , 'dti' , prefix + f'_{ dm } .nii.gz' )
74+ moving = pjoin (directory , 'dti' , prefix + f'_{ dm } .nii.gz' )
7575 # warp diffusion measure to template space first, then to MNI space
7676 antsApplyTransforms [
7777 '-d' , '3' ,
@@ -85,25 +85,25 @@ def register_target(imgPath, templatePath):
8585def register_harmonized (imgPath , warp2mni , trans2mni , templatePath , siteName ):
8686
8787 print (f'Warping { imgPath } diffusion measures to standard space' )
88- directory = os . path . dirname (imgPath )
88+ directory = dirname (imgPath )
8989 inPrefix = imgPath .split ('.nii' )[0 ]
9090 prefix = basename (inPrefix )
9191
92- dmImg = os . path . join (directory , 'dti' , prefix + f'_FA.nii.gz' )
93- dmTmp = os . path . join (templatePath , f'Mean_{ siteName } _FA_b{ bshell_b } .nii.gz' )
94- maskTmp = os . path . join (templatePath , f'{ siteName } _Mask.nii.gz' )
95- outPrefix = os . path . join (templatePath , prefix .replace (f'_b{ bshell_b } ' ,'' ) + '_FA' )
92+ dmImg = pjoin (directory , 'dti' , prefix + f'_FA.nii.gz' )
93+ dmTmp = pjoin (templatePath , f'Mean_{ siteName } _FA_b{ bshell_b } .nii.gz' )
94+ maskTmp = pjoin (templatePath , f'{ siteName } _Mask.nii.gz' )
95+ outPrefix = pjoin (templatePath , prefix .replace (f'_b{ bshell_b } ' ,'' ) + '_FA' )
9696 warp2tmp = outPrefix + '1Warp.nii.gz'
9797 trans2tmp = outPrefix + '0GenericAffine.mat'
9898
9999 # check existence of transforms created with _b{bmax}
100- if not os . path . exists (warp2tmp ):
100+ if not exists (warp2tmp ):
101101 antsReg (dmTmp , maskTmp , dmImg , outPrefix )
102102
103103 for dm in diffusionMeasures :
104- output = os . path . join (templatePath , prefix + f'_InMNI_{ dm } .nii.gz' )
104+ output = pjoin (templatePath , prefix + f'_InMNI_{ dm } .nii.gz' )
105105
106- moving = os . path . join (directory , 'dti' , prefix + f'_{ dm } .nii.gz' )
106+ moving = pjoin (directory , 'dti' , prefix + f'_{ dm } .nii.gz' )
107107 # warp diffusion measure to template space first, then to MNI space
108108 antsApplyTransforms [
109109 '-d' , '3' ,
@@ -117,14 +117,14 @@ def register_harmonized(imgPath, warp2mni, trans2mni, templatePath, siteName):
117117def sub2tmp2mni (templatePath , siteName , caselist , ref = False , tar_unproc = False , tar_harm = False ):
118118
119119 # obtain the transform
120- moving = os . path . join (templatePath , f'Mean_{ siteName } _FA_b{ bshell_b } .nii.gz' )
120+ moving = pjoin (templatePath , f'Mean_{ siteName } _FA_b{ bshell_b } .nii.gz' )
121121
122- outPrefix = os . path . join (templatePath , f'TemplateToMNI_{ siteName } ' )
122+ outPrefix = pjoin (templatePath , f'TemplateToMNI_{ siteName } ' )
123123 warp2mni = outPrefix + '1Warp.nii.gz'
124124 trans2mni = outPrefix + '0GenericAffine.mat'
125125
126126 # check existence of transforms created with _b{bmax}
127- if not os . path . exists (warp2mni ):
127+ if not exists (warp2mni ):
128128 antsReg (mniTmp , None , moving , outPrefix )
129129
130130 imgs , _ = read_caselist (caselist )
@@ -160,7 +160,7 @@ def analyzeStat(file, templatePath):
160160 :return: mean of the images
161161 '''
162162
163- skel = load (os . path . join (ROOTDIR , 'IITAtlas' , 'IITmean_FA_skeleton.nii.gz' ))
163+ skel = load (pjoin (ROOTDIR , 'IITAtlas' , 'IITmean_FA_skeleton.nii.gz' ))
164164 skel_mask = (skel .get_data ()> 0 )* 1.
165165
166166 imgs , _ = read_caselist (file )
@@ -170,7 +170,7 @@ def analyzeStat(file, templatePath):
170170 inPrefix = imgPath .split ('.nii' )[0 ]
171171 prefix = basename (inPrefix )
172172
173- faImg = os . path . join (templatePath , prefix + f'_InMNI_FA.nii.gz' )
173+ faImg = pjoin (templatePath , prefix + f'_InMNI_FA.nii.gz' )
174174 data = load (faImg ).get_data ()
175175 temp = data * skel_mask
176176 meanAttr .append (temp [temp > 0 ].mean ())
0 commit comments