else: raise OSError('%s exists, remove to re-run'%outdir) # Split files of each subject containing all ic's infiles = glob(subic_globstr) for subfile in infiles: subid = pydr.get_subid(subfile, pattern=subid_pattern) allic = pydr.split_components(subfile, subid, outdir) # Merge files of each ic across subjects for cn, item in enumerate(allic): #Search through ics using last subject's output datadir, ic = os.path.split(item) subid = pydr.get_subid(item, pattern=subid_pattern) globstr = ic.replace(subid, '*') mergefile, subject_order = pydr.merge_components(datadir, globstr = globstr, subid_pattern = subid_pattern) outfile = os.path.join(outdir, 'subject_order_ic%04d'%cn) with open(outfile, 'w+') as fid: fid.write('\n'.join(subject_order)) #Write out subject order for each ic # Rename files with ic count starting at 1 and unzip for cn, item in enumerate(glob(ic4d_globstr)): datadir, filename = os.path.split(item) new_cn = cn + 1 newfile = os.path.join(datadir, ''.join(['ic','%03d'%new_cn, '_4D.nii.gz'])) os.rename(item, newfile) cmd = CommandLine('gunzip %s'%(newfile)) cmd.run() order_file = os.path.join(datadir, 'subject_order_ic%04d'%cn) new_order_file = os.path.join(datadir, 'subject_order_ic%03d'%new_cn)
subid, 'func', 'confound_regressors_6mm.txt') #Name of confound file ## If you want residuals to be output, change out_res to True below stage2_ts, stage2_tsz = pydr.sub_spatial_map(tmpf, txtf, mask, outdir, desnorm=True, out_res=True,mvt=mvtfile) subd.update({subid:stage2_ts}) ###Split subject 4d file into separate 3d files for each component allic = pydr.split_components(stage2_ts, subid, outdir) ###Concat ics across subjects. ###Only merges ICs from gica, ###not those of confound regressors ############################################### for cn, item in enumerate(allic[:num_ics]): #Search through ics using last subject's output datadir, ic = os.path.split(item) subid = pydr.get_subid(item) globstr = ic.replace(subid, '*') mergefile, subject_order = pydr.merge_components(datadir, globstr = globstr) outfile = os.path.join(outdir, 'subject_order_ic%04d'%cn) with open(outfile, 'w+') as fid: fid.write('\n'.join(subject_order)) #Write out subject order for each ic os.chdir(startdir)