# Copyright (C) 2018-2022 C-PAC Developers# This file is part of C-PAC.# C-PAC is free software: you can redistribute it and/or modify it under# the terms of the GNU Lesser General Public License as published by the# Free Software Foundation, either version 3 of the License, or (at your# option) any later version.# C-PAC is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public# License for more details.# You should have received a copy of the GNU Lesser General Public# License along with C-PAC. If not, see <https://www.gnu.org/licenses/>.importloggingimportsixfromCPAC.pipeline.engineimportResourcePoollogger=logging.getLogger('nipype.workflow')
[docs]defget_node_from_resource_pool(self,resource_key):try:returnself.resource_pool[resource_key]except:logger.error('No node for output: %s',resource_key)raise
[docs]defupdate_resource_pool(self,resources,override=False):forkey,valueinresources.items():ifkeyinself.resource_poolandnotoverride:raiseException('Key %s already exists in resource pool, ''replacing with %s '%(key,value))self.resource_pool[key]=value
def__getitem__(self,resource_key):assertisinstance(resource_key,six.string_types)try:returnself.resource_pool[resource_key]except:logger.error('No node for output: %s',resource_key)raisedef__contains__(self,resource_key):assertisinstance(resource_key,six.string_types)returnresource_keyinself.resource_pool
[docs]@staticmethoddefget_forking_labels(strategies):fork_names=[]# fork_points is a list of lists, each list containing node names of# nodes run in that strat/fork that are unique to that strat/forkfork_points=Strategy.get_forking_points(strategies)forfork_pointinfork_points:fork_point.sort()fork_name=[]forforkinfork_point:fork_label=''# TODO: reorganize labels# registration if'anat_mni_ants_register'infork:fork_label='anat-ants'if'anat_mni_fnirt_register'infork:fork_label='anat-fnirt'if'anat_mni_flirt_register'infork:fork_label='anat-flirt'if'func_to_epi_ants'infork:fork_label='func-ants'if'func_to_epi_fsl'infork:fork_label='func-fsl'# skullstripping if'func_preproc_afni'infork:fork_label='func-3dautomask'if'func_preproc_fsl'infork:fork_label='func-bet'if'func_preproc_fsl_afni'infork:fork_label='func-bet-3dautomask'# motion correction referenceif'mean'infork:fork_label='mean'if'median'infork:fork_label='median'if'selected_volume'infork:fork_label='selected_volume'# motion correctionif'mcflirt'infork:fork_label+='_func-mcflirt'if'3dvolreg'infork:fork_label+='_func-3dvolreg'if'anat_refined'infork:fork_label='func-anat-refined'if'motion_filter'infork:fork_label='motion-filter'# distortion correctionif'epi_distcorr'infork:fork_label='dist-corr'if'bbreg'infork:fork_label='bbreg'if'aroma'infork:fork_label='aroma'if'nuisance'infork:fork_label='nuisance'if'frequency_filter'infork:fork_label='freq-filter'if'gen_motion_stats_before_stc'infork:fork_label='motion_stats_before_stc'if'despike'infork:fork_label='despike'if'slice'infork:fork_label='slice'if'anat_preproc_afni'infork:fork_label='anat-afni'if'anat_preproc_bet'infork:fork_label='anat-bet'if'anat_preproc_ants'infork:fork_label='anat-ants'if'anat_preproc_unet'infork:fork_label='anat-unet'fork_name+=[fork_label]fork_names.append('_'.join(sorted(set(fork_name))))returndict(zip(strategies,fork_names))