#!/usr/bin/env python2 import subprocess import re import os from slurm import send_sbatch defacer = '/nas/usr/local/bin/mri_deface_linux' def_dir = '/nas/usr/local/share/mri_deface/' tal_gca = def_dir+'talairach_mixed_with_skull.gca' face_gca = def_dir+'face.gca' finder = 'find /nas/data/facehbi/bids/sub-* -name "*.nii.gz"' outdir = '/nas/data/facehbi/defaced/' time = '2:0:0' cpus = 4 wdir = os.environ.get('PWD') if not os.path.isdir(outdir): os.mkdir(outdir) ifiles = subprocess.check_output('find /nas/data/facehbi/bids/sub-* -name "*.nii.gz"', shell=True).split('\n') for ifile in ifiles: if os.path.exists(ifile): cdata = {'time':time, 'cpus':4, 'job_name':'deface'} ofile = re.sub('bids','defaced/bids',ifile) dst_dir = os.path.dirname(ofile) if not os.path.isdir(dst_dir): os.makedirs(dst_dir) order1 = defacer+' '+ifile+' '+tal_gca+' '+face_gca+' '+ofile jfile = re.sub('\.nii\.gz','.json',ifile) ojfile = re.sub('\.nii\.gz','.json',ofile) order2 = 'cp '+jfile+' '+ojfile name = os.path.basename(ifile).split('.')[0] cdata['filename'] = wdir+'/deface_'+name+'.sh' cdata['output'] = wdir+'/deface_'+name+'.out' cdata['command'] = order1+'\n'+order2+'\n' send_sbatch(cdata) mdata = {'job_name':'deface', 'filename':wdir+'/deface_end.sh', 'output':wdir+'/deface_end.log', 'dependency':'singleton'} send_sbatch(mdata)