Skip to content

Commit

Permalink
Add the reference volume XNAT file name to the [Registration] topic.
Browse files Browse the repository at this point in the history
  • Loading branch information
FredLoney committed Jun 22, 2017
1 parent cac62f7 commit c7b8bdd
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions qipipe/pipeline/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,12 +316,14 @@ def _create_execution_workflow(self, reference, dest, recursive=False):
collect_realigned, 'realigned_files')

# Make the profile.
cr_prf_fields = ['technique', 'configuration', 'sections', 'dest']
cr_prf_fields = ['technique', 'configuration', 'sections',
'reference', 'dest']
cr_prf_xfc = Function(input_names=cr_prf_fields,
output_names=['out_file'],
function=_create_profile)
cr_prf = pe.Node(cr_prf_xfc, name='create_profile')
cr_prf.inputs.technique = self.technique
exec_wf.connect(input_spec, 'reference', cr_prf, 'reference')
cr_prf.inputs.configuration = self.configuration
cr_prf.inputs.sections = self.profile_sections
cr_prf.inputs.dest = "%s.cfg" % self.resource
Expand Down Expand Up @@ -567,26 +569,39 @@ def _create_realignment_workflow(self, **opts):

### Utility functions called by the workflow nodes. ###

def _create_profile(technique, configuration, sections, dest):
def _create_profile(technique, configuration, sections, reference, dest):
"""
:meth:`qipipe.helpers.metadata.create_profile` wrapper.
:param technique: the modeling technique
:param configuration: the modeling workflow interface settings
:param sections: the profile sections
:param reference: the fixed reference image file path
:param dest: the output profile file path
:return: the output profile file path
"""

import os
from qipipe.helpers import metadata

# The reference is the XNAT file name without a directory.
_, prf_reference = os.path.split(reference)
# The correct technique names.
TECHNIQUE_NAMES = dict(ants='ANTs', fnirt='FNIRT', mock='Mock')

technique = TECHNIQUE_NAMES.get(technique.lower(), technique)

return metadata.create_profile(configuration, sections, dest=dest,
general=dict(technique=technique))
prf_technique = TECHNIQUE_NAMES.get(technique.lower(), technique)
# Replace the technique in configuration keys for consistency.
tech_pat = "$%s\." % technique
tech_sub = "%s " % prf_technique
fix_key = lambda s: re.sub(tech_pat, tech_sub, s)
prf_cfg = {fix_key(k): v for k, v in configuration.iteritems()}
# The general [Registration] topic additional properties.
reg_cfg = dict(technique=prf_technique, reference=prf_reference)
# Update or create the [Registration] section.
if 'registration' in prf_cfg:
prf_cfg['registration'].update(reg_cfg)
else:
prf_cfg['registration'] = reg_cfg

return metadata.create_profile(prf_cfg, sections, dest=dest)


def _symlink_in_place(in_file, link_name):
Expand Down

0 comments on commit c7b8bdd

Please sign in to comment.