Commit d19760f9 authored by Christoph Arthofer's avatar Christoph Arthofer
Browse files

file permissions

parent 2921252d
......@@ -125,7 +125,45 @@ python run_template_construction.py
--gpuq gpu8.q
```
## Output
Output directories will be automatically created for different purposes. These include:
#### `log`
Contains log-files from the job submission system; this is very useful for debugging
### `scripts`
Contains generated Bash and Python scripts e.g. for job array submissions, wrappers for Python functions
#### `affine_it1`
Contains the output of the first set of rigd and affine registrations including
- rigid registrations between within-subject modalities (i.e. DTI to T2, T2 to T1)
- affine registrations between each subject and a reference subject
- unbiasing transformation removing the bias introduced by the reference subject
- unbiased average T1 template in the unbiased space of the subjects
- rigid transformation of unbiased template to MNI space
#### `affine_it1`
affine_it2 (affine_it2_dir)
{sub_id} (affine_it2_subject_dir)
T1_to_MNI152{ext_mat} (T1_to_MNI_mat)
T1_brain_to_MNI152{ext_nii} (T1_brain_to_MNI_img)
T1_head_to_MNI152{ext_nii} (T1_head_to_MNI_img)
T1_brain_mask_to_MNI152{ext_nii} (T1_brain_mask_to_MNI_img)
T2_FLAIR_to_MNI152{ext_mat} (T2_to_MNI_mat)
T2_FLAIR_brain_to_MNI152{ext_nii} (T2_brain_to_MNI_img)
T2_FLAIR_head_to_MNI152{ext_nii} (T2_head_to_MNI_img)
DTI_to_MNI152{ext_mat} (DTI_to_MNI_mat)
DTI_to_MNI152{ext_nii} (DTI_to_MNI_img)
DTI_tensor_to_MNI152{ext_nii} (DTI_tensor_to_MNI)
affine_template_T1_brain{ext_nii} (T1_brain_affine_template)
affine_template_T1_brain_mask{ext_nii} (T1_brain_mask_affine_template)
affine_template_T1_brain_mask_weighted{ext_nii} (T1_brain_mask_weighted_affine_template)
affine_template_T1_head{ext_nii} (T1_head_affine_template)
affine_template_T2_head{ext_nii} (T2_head_affine_template)
affine_template_DTI{ext_nii} (DTI_affine_template)
affine_template_DTI_tensor{ext_nii} (DTI_tensor_affine_template)
......@@ -278,7 +278,7 @@ def writeConfig(step,mod,fpath):
'fwhm_mov_tensor = 8.0 8.0 4.0 2.0 1.0 0.5 0.25 \n' \
'lambda_tensor = 1 1 1 1 1 1 1 \n'
f = open(fpath, 'w')
f = open(fpath, 'w+')
f.write(s)
f.close()
......@@ -501,7 +501,7 @@ def RMSdifference(img1_path, img2_path, mask1_path=None, mask2_path=None, rms_pa
print('RMS difference between {} and {}: {}'.format(img1_path, img2_path, rms))
if rms_path is not None:
with open(rms_path, 'w') as f:
with open(rms_path, 'w+') as f:
f.write('{}'.format(rms))
......@@ -544,7 +544,7 @@ def RMSstandardDeviation(img_paths, mean_img_path, mask_path, sd_img_out_path=No
print('RMS standard deviation: {}'.format(rms))
if rms_out_path is not None:
with open(rms_out_path, 'w') as f:
with open(rms_out_path, 'w+') as f:
f.write('{}'.format(rms))
......@@ -739,18 +739,18 @@ if __name__ == "__main__":
job_ids = ['' for _ in range(100)]
task_count = 0
os.mkdir(base_dir, mode=0o700) if not os.path.exists(base_dir) else print(base_dir + ' exists')
os.chmod(base_dir, 0o700)
os.mkdir(base_dir, mode=0o770) if not os.path.exists(base_dir) else print(base_dir + ' exists')
os.chmod(base_dir, 0o770)
tree = FileTree.read(tree_path, top_level='')
tree = tree.update(data_dir=data_dir, template_dir=base_dir)
script_dir = tree.get('script_dir')
os.mkdir(script_dir, mode=0o700) if not os.path.exists(script_dir) else print(script_dir + ' exists')
os.mkdir(script_dir, mode=0o770) if not os.path.exists(script_dir) else print(script_dir + ' exists')
log_dir = tree.get('log_dir')
os.mkdir(log_dir, mode=0o700) if not os.path.exists(log_dir) else print(log_dir + ' exists')
os.mkdir(log_dir, mode=0o770) if not os.path.exists(log_dir) else print(log_dir + ' exists')
misc_dir = tree.get('misc_dir')
os.mkdir(misc_dir, mode=0o700) if not os.path.exists(misc_dir) else print(misc_dir + ' exists')
os.mkdir(misc_dir, mode=0o770) if not os.path.exists(misc_dir) else print(misc_dir + ' exists')
shutil.copyfile(identity_path,tree.get('identity_mat'))
ref_idx = 0
......@@ -783,7 +783,7 @@ if __name__ == "__main__":
# Soft clamping of high skull intensities
task_name = '{:03d}_prep_clamping'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id)
T1_head_path = tree.get(mod['T1_head_key'])
......@@ -803,7 +803,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_registrations_2_ref'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
......@@ -822,7 +822,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_registrations_T2_2_T1'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=id)
cmd = flirt(tree.get(mod['T2_brain_key']), tree.get(mod['T1_brain_key']), omat=tree.get('T2_to_T1_mat'),
......@@ -837,7 +837,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_registrations_DTI_2_T2'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=id)
cmd = flirt(tree.get(mod['DTI_scalar_key']), tree.get(mod['T2_brain_key']), omat=tree.get('DTI_to_T2_mat'),
......@@ -873,7 +873,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_unbiased_transform_of_T1'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = applyxfm(src=tree.get(mod['T1_brain_key']), ref=affine_ref_path, mat=tree.get('T1_to_unbiased_mat'),
......@@ -889,7 +889,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_concat_T2_and_unbiased'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = concatxfm(tree.get('T2_to_T1_mat'), tree.get('T1_to_unbiased_mat'),
......@@ -905,7 +905,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_concat_DTI_and_unbiased'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = concatxfm(tree.get('DTI_to_T2_mat'), tree.get('T2_to_unbiased_mat'),
......@@ -943,7 +943,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_concat_T1_brain_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = concatxfm(tree.get('T1_to_unbiased_mat'), tree.get('T1_unbiased_affine_template_to_MNI_mat'),
......@@ -959,7 +959,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_concat_T2_brain_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = concatxfm(tree.get('T2_to_unbiased_mat'), tree.get('T1_unbiased_affine_template_to_MNI_mat'),
......@@ -975,7 +975,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_concat_DTI_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = concatxfm(tree.get('DTI_to_unbiased_mat'), tree.get('T1_unbiased_affine_template_to_MNI_mat'),
......@@ -991,7 +991,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_transform_T1_brain_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = applyxfm(src=tree.get(mod['T1_brain_key']), ref=mni_path, mat=tree.get('T1_to_MNI_mat'),
......@@ -1007,7 +1007,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_transform_T1_brain_masks_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = applyxfm(src=tree.get(mod['T1_brain_mask_key']), ref=mni_path,
......@@ -1024,7 +1024,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_transform_T1_head_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = applyxfm(src=tree.get('T1_head_clamped'), ref=mni_path, mat=tree.get('T1_to_MNI_mat'),
......@@ -1040,7 +1040,7 @@ if __name__ == "__main__":
task_name = '{:03d}_affT_transform_T2_head_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
if mod['T2_head_key'] is not None:
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = applyxfm(src=tree.get(mod['T2_head_key']), ref=mni_path, mat=tree.get('T2_to_MNI_mat'),
......@@ -1056,7 +1056,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_transform_DTI_scalar_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = applyxfm(src=tree.get(mod['DTI_scalar_key']), ref=mni_path, mat=tree.get('DTI_to_MNI_mat'),
......@@ -1072,7 +1072,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_affT_transform_DTI_tensor_to_MNI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, ref_id=aff_ref_id)
cmd = 'vecreg -i ' + tree.get(mod['DTI_tensor_key']) + \
......@@ -1233,7 +1233,7 @@ if __name__ == "__main__":
# Nonlinear registration to template from previous iteration
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
export_vars = {}
for i, id in enumerate(ls_ids):
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
......@@ -1344,7 +1344,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_resample_warps'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
warp_path = tree.get('mmorf_warp')
......@@ -1361,7 +1361,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_unbias_warps'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
f.write('fslmaths ' + tree.get('mmorf_warp_resampled') + ' -add ' + tree.get(
......@@ -1375,7 +1375,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_concat_unbiased_warps_T1_brain'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
full_resampled_path = tree.get('mmorf_warp_resampled_unbiased_full_T1brain')
......@@ -1394,7 +1394,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_concat_unbiased_warps_T1_head'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
full_resampled_path = tree.get('mmorf_warp_resampled_unbiased_full_T1head')
......@@ -1413,7 +1413,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_concat_unbiased_warps_T2_head'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
full_resampled_path = tree.get('mmorf_warp_resampled_unbiased_full_T2')
......@@ -1432,7 +1432,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_concat_unbiased_warps_DTI'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
full_resampled_path = tree.get('mmorf_warp_resampled_unbiased_full_DTI')
......@@ -1452,7 +1452,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_warp_T1_brain'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
img_path = tree.get(mod['T1_brain_key'])
......@@ -1470,7 +1470,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_warp_T1_brain_mask'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
img_path = tree.get(mod['T1_brain_mask_key'])
......@@ -1493,7 +1493,7 @@ if __name__ == "__main__":
T1_head_key_temp = mod['T1_head_key']
else:
T1_head_key_temp = 'T1_head_clamped'
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
img_path = tree.get(T1_head_key_temp)
......@@ -1512,7 +1512,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_warp_T2_head'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
img_path = tree.get(mod['T2_head_key'])
......@@ -1531,7 +1531,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_warp_DTI_scalar'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
img_path = tree.get(mod['DTI_scalar_key'])
......@@ -1550,7 +1550,7 @@ if __name__ == "__main__":
task_count += 1
task_name = '{:03d}_nlnT_warp_DTI_tensor'.format(task_count)
script_path = os.path.join(script_dir, task_name + '.sh')
with open(script_path, 'w') as f:
with open(script_path, 'w+') as f:
for id in ls_ids:
tree = tree.update(sub_id=id, step_id='{:02d}'.format(step), it_id='{:02d}'.format(it))
cmd = 'vecreg -i ' + tree.get('data/DTI_tensor') + \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment