def main(maskname, output, k): """ This loops through input subjects, constructs individual cortical cluster maps, and then generates a single map at the group level. """ # keep track of the time T0 = time() # perform random clustering localcon = os.path.dirname(maskname) + "/rm_ones_connectivity.npy" if os.path.isfile(localcon) == False: # calculates local connectivity from binary mask make_local_connectivity_ones(maskname, localcon) if os.path.isfile(output + str(k[0]) + ".npy") == False: # segments into k clusters using local connectivity binfile_parcellate(localcon, output, k) if os.path.isfile(output + str(k[0]) + ".nii.gz") == False: # write out a nifti make_image_from_bin_renum(output + str(k[0]) + ".nii.gz", output + str(k[0]) + ".npy", maskname) T1 = time() print "**** Done in " + str(T1 - T0)
def main(maskname, output, k): """ This loops through input subjects, constructs individual cortical cluster maps, and then generates a single map at the group level. """ # keep track of the time T0 = time() # perform random clustering localcon = os.path.dirname(maskname) + '/rm_ones_connectivity.npy' if os.path.isfile(localcon) == False: # calculates local connectivity from binary mask make_local_connectivity_ones(maskname, localcon) if os.path.isfile(output + str(k[0]) + '.npy') == False: # segments into k clusters using local connectivity binfile_parcellate(localcon, output, k) if os.path.isfile(output + str(k[0]) + '.nii.gz') == False: # write out a nifti make_image_from_bin_renum(output + str(k[0]) + '.nii.gz', output + str(k[0]) + '.npy', maskname) T1 = time() print '**** Done in ' + str(T1 - T0)
# functions for connectivity metric from make_local_connectivity_ones import * # name of the maskfile that we will be using roidir = "/home2/data/Projects/CWAS/share/development+motion/rois" maskfile = path.join(roidir, "mask_gray_4mm.nii.gz") ### # 2. Generate Random Connectivity Matrix ### print "2. Random Connectivity Matrix" outfile = path.join(obase, "random_ones_conn.npy") make_local_connectivity_ones(maskfile, outfile) ### # 3. 'Clustering' ### print "3. Clustering" from binfile_parcellation import * ks = [25,50,100,200,400,800,1600,3200] # For random custering, this is all we need to do, there is no need for group # level clustering, remember that the output filename is a prefix, and infile = outfile
# functions for connectivity metric from make_local_connectivity_ones import * # name of the maskfile that we will be using roidir = "/home2/data/Projects/CWAS/share/age+gender/analysis/03_robustness/rois" maskfile = path.join(roidir, "mask_for_age+sex_gray_4mm.nii.gz") ### # 2. Generate Random Connectivity Matrix ### print "2. Random Connectivity Matrix" outfile = path.join(obase, "random_ones_conn.npy") make_local_connectivity_ones(maskfile, outfile) ### # 3. 'Clustering' ### print "3. Clustering" from binfile_parcellation import * ks = [25, 50, 100, 200, 400, 800, 1600, 3200] # For random custering, this is all we need to do, there is no need for group # level clustering, remember that the output filename is a prefix, and infile = outfile outbase = path.join(obase, "random_ones_cluster")
# the name of the maskfile that we will be using maskname = "gm_maskfile.nii.gz" # make a list of all of the input fMRI files that we will be using infiles = ['subject1.nii.gz', 'subject2.nii.gz', 'subject3.nii.gz'] ##### Step 1. Individual Conenctivity Matrices # first we need to make the individual connectivity matrices, I will # do this for all three different kinds (tcorr, scorr, ones) but you # will only need to do it for one # the easiest is random clustering which doesn't require any functional # data, just the mask print 'ones connectivity' make_local_connectivity_ones(maskname, 'rm_ones_connectivity.npy') # construct the connectivity matrices using tcorr and a r>0.5 threshold for idx, in_file in enumerate(infiles): # construct an output filename for this file outname = 'rm_tcorr_conn_' + str(idx) + '.npy' print 'tcorr connectivity', in_file # call the funtion to make connectivity make_local_connectivity_tcorr(in_file, maskname, outname, 0.5) # construct the connectivity matrices using scorr and a r>0.5 threshold # This can take a _really_ long time for idx, in_file in enumerate(infiles):
# the name of the maskfile that we will be using maskname="gm_maskfile.nii.gz" # make a list of all of the input fMRI files that we will be using infiles = [ 'subject1.nii.gz', 'subject2.nii.gz', 'subject3.nii.gz' ] ##### Step 1. Individual Conenctivity Matrices # first we need to make the individual connectivity matrices, I will # do this for all three different kinds (tcorr, scorr, ones) but you # will only need to do it for one # the easiest is random clustering which doesn't require any functional # data, just the mask print 'ones connectivity' if not os.path.isfile('rm_ones_connectivity.npy'): make_local_connectivity_ones( maskname, 'rm_ones_connectivity.npy') # construct the connectivity matrices using tcorr and a r>0.5 threshold for idx, in_file in enumerate(infiles): # construct an output filename for this file outname='rm_tcorr_conn_'+str(idx)+'.npy' print 'tcorr connectivity',in_file # call the funtion to make connectivity make_local_connectivity_tcorr( in_file, maskname, outname, 0.5 )
# the name of the maskfile that we will be using maskname="gm_maskfile.nii.gz" # make a list of all of the input fMRI files that we will be using infiles = [ 'subject1.nii.gz', 'subject2.nii.gz', 'subject3.nii.gz' ] ##### Step 1. Individual Conenctivity Matrices # first we need to make the individual connectivity matrices, I will # do this for all three different kinds (tcorr, scorr, ones) but you # will only need to do it for one # the easiest is random clustering which doesn't require any functional # data, just the mask print 'ones connectivity' make_local_connectivity_ones( maskname, 'rm_ones_connectivity.npy') # construct the connectivity matrices using tcorr and a r>0.5 threshold for idx, in_file in enumerate(infiles): # construct an output filename for this file outname='rm_tcorr_conn_'+str(idx)+'.npy' print 'tcorr connectivity',in_file # call the funtion to make connectivity make_local_connectivity_tcorr( in_file, maskname, outname, 0.5 ) # construct the connectivity matrices using scorr and a r>0.5 threshold