Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
atlas = 'whole_brain_cluster_labels_PCA200'
roi = base_dir + '/pDMN_3_bin.nii.gz'
mask = None
ID = '002'
parc = True
perc_overlap = 0.10
start_time = time.time()
[WB_coords, _, _] = nodemaker.get_names_and_coords_of_parcels(parlistfile)
print("%s%s%s" % ('get_names_and_coords_of_parcels (Masking whole-brain version) --> finished: ',
str(np.round(time.time() - start_time, 1)), 's'))
WB_labels = np.arange(len(WB_coords) + 1)[np.arange(len(WB_coords) + 1) != 0].tolist()
start_time = time.time()
WB_parcel_list = nodemaker.gen_img_list(parlistfile)
[_, _, WB_parcel_list_masked] = nodemaker.parcel_masker(roi, WB_coords, WB_parcel_list, WB_labels, dir_path,
ID, perc_overlap)
print("%s%s%s" % ('parcel_masker (Masking whole-brain version) --> finished: ',
np.round(time.time() - start_time, 1), 's'))
start_time = time.time()
[WB_parcels_map_nifti, parcel_list_exp] = nodemaker.create_parcel_atlas(WB_parcel_list_masked)
print("%s%s%s" % ('create_parcel_atlas (Masking whole-brain version) --> finished: ',
np.round(time.time() - start_time, 1), 's'))
start_time = time.time()
[WB_net_parcels_map_nifti_unmasked, WB_coords_unmasked, _,
WB_atlas, WB_uatlas, dir_path] = nodemaker.node_gen(WB_coords, WB_parcel_list, WB_labels,
dir_path, ID, parc, atlas, parlistfile)
print("%s%s%s" % ('node_gen (Masking whole-brain version) --> finished: ',
np.round(time.time() - start_time, 1), 's'))
parlistfile = base_dir + '/whole_brain_cluster_labels_PCA200.nii.gz'
roi = base_dir + '/pDMN_3_bin.nii.gz'
network = 'Default'
ID = '002'
perc_overlap = 0.10
parc = True
start_time = time.time()
[coords, _, _] = nodemaker.get_names_and_coords_of_parcels(parlistfile)
print("%s%s%s" % ('get_names_and_coords_of_parcels --> finished: ',
str(np.round(time.time() - start_time, 1)), 's'))
labels = np.arange(len(coords) + 1)[np.arange(len(coords) + 1) != 0].tolist()
start_time = time.time()
parcel_list = nodemaker.gen_img_list(parlistfile)
[net_coords, net_parcel_list, net_labels, network] = nodemaker.get_node_membership(network, func_file, coords,
labels, parc,
parcel_list)
print("%s%s%s" % ('get_node_membership --> finished: ', str(np.round(time.time() - start_time, 1)), 's'))
start_time = time.time()
[net_coords_masked, net_labels_masked, net_parcel_list_masked] = nodemaker.parcel_masker(roi, net_coords,
net_parcel_list,
net_labels,
dir_path, ID,
perc_overlap)
print("%s%s%s" % ('parcel_masker --> finished: ', str(np.round(time.time() - start_time, 1)), 's'))
start_time = time.time()
[net_parcels_map_nifti, parcel_list_exp] = nodemaker.create_parcel_atlas(net_parcel_list_masked)
print("%s%s%s" % ('create_parcel_atlas --> finished: ', str(np.round(time.time() - start_time, 1)), 's'))
dir_path = base_dir + '/002/fmri'
func_file = dir_path + '/002.nii.gz'
parlistfile = base_dir + '/whole_brain_cluster_labels_PCA200.nii.gz'
network = 'Default'
parc = True
start_time = time.time()
[coords, _, _] = nodemaker.get_names_and_coords_of_parcels(parlistfile)
print("%s%s%s" % ('get_names_and_coords_of_parcels --> finished: ',
str(np.round(time.time() - start_time, 1)), 's'))
labels = np.arange(len(coords) + 1)[np.arange(len(coords) + 1) != 0].tolist()
start_time = time.time()
parcel_list = nodemaker.gen_img_list(parlistfile)
[net_coords, net_parcel_list, net_labels, network] = nodemaker.get_node_membership(network, func_file, coords,
labels, parc,
parcel_list)
print("%s%s%s" % ('get_node_membership --> finished: ', str(np.round(time.time() - start_time, 1)), 's'))
start_time = time.time()
[net_parcels_map_nifti, parcel_list_exp] = nodemaker.create_parcel_atlas(net_parcel_list)
print("%s%s%s" % ('create_parcel_atlas --> finished: ', str(np.round(time.time() - start_time, 1)), 's'))
start_time = time.time()
out_path = nodemaker.gen_network_parcels(parlistfile, network, net_labels, dir_path)
print("%s%s%s" % ('gen_network_parcels --> finished: ', str(np.round(time.time() - start_time, 1)), 's'))
assert coords is not None
assert net_coords is not None
Test nodemaker_tools_parlistfile_WB functionality
"""
# Set example inputs
base_dir = str(Path(__file__).parent/"examples")
parlistfile = base_dir + '/whole_brain_cluster_labels_PCA200.nii.gz'
start_time = time.time()
[WB_coords, _, _] = nodemaker.get_names_and_coords_of_parcels(parlistfile)
print("%s%s%s" % ('get_names_and_coords_of_parcels (User-atlas whole-brain version) --> finished: ',
str(np.round(time.time() - start_time, 1)), 's'))
WB_labels = np.arange(len(WB_coords) + 1)[np.arange(len(WB_coords) + 1) != 0].tolist()
start_time = time.time()
WB_parcel_list = nodemaker.gen_img_list(parlistfile)
[WB_parcels_map_nifti, parcel_list_exp] = nodemaker.create_parcel_atlas(WB_parcel_list)
print("%s%s%s" % ('create_parcel_atlas (User-atlas whole-brain version) --> finished: ',
str(np.round(time.time() - start_time, 1)), 's'))
assert WB_coords is not None
assert WB_labels is not None
assert WB_parcel_list is not None
assert WB_parcels_map_nifti is not None
assert parcel_list_exp is not None
raise ValueError("%s%s%s" % ('\nERROR: Atlas file for ', atlas, ' not found!'))
par_max = None
elif uatlas:
if clustering is True:
while True:
if op.isfile(uatlas):
break
else:
print('Waiting for atlas file...')
time.sleep(15)
atlas = uatlas.split('/')[-1].split('.')[0]
try:
# Fetch user-specified atlas coords
[coords, atlas, par_max] = nodemaker.get_names_and_coords_of_parcels(uatlas)
if parc is True:
parcel_list = nodemaker.gen_img_list(uatlas)
else:
parcel_list = None
# Describe user atlas coords
print("%s%s%s%s" % ('\n', atlas, ' comes with {0} '.format(par_max), 'parcels\n'))
except ValueError:
print('\n\nError: Either you have specified the name of a nilearn atlas that does not exist or '
'you have not supplied a 3d atlas parcellation image!\n\n')
parcel_list = None
par_max = None
coords = None
labels = None
networks_list = None
else:
networks_list = None
labels = None
parcel_list = None
Path to directory containing subject derivative data for given run.
Returns
-------
out_path : str
File path to a new, RSN-filtered atlas parcellation Nifti1Image.
"""
from nilearn.image import concat_imgs
from pynets.core import nodemaker
import os.path as op
if not op.isfile(uatlas):
raise ValueError('\nERROR: User-specified atlas input not found! Check that the file(s) specified with the -ua '
'flag exist(s)')
img_list = nodemaker.gen_img_list(uatlas)
print("%s%s%s" % ('\nExtracting parcels associated with ', network, ' network locations...\n'))
net_parcels = [i for j, i in enumerate(img_list) if j in labels]
bna_4D = concat_imgs(net_parcels).get_fdata()
index_vec = np.array(range(len(net_parcels))) + 1
net_parcels_sum = np.sum(index_vec * bna_4D, axis=3)
net_parcels_map_nifti = nib.Nifti1Image(net_parcels_sum, affine=np.eye(4))
out_path = "%s%s%s%s" % (dir_path, '/', network, '_parcels.nii.gz')
nib.save(net_parcels_map_nifti, out_path)
net_parcels_map_nifti.uncache()
return out_path