Skip to content

Commit

Permalink
🤝 Merge develop into fix/libGL.so.1
Browse files Browse the repository at this point in the history
  • Loading branch information
shnizzedy committed Jul 14, 2020
2 parents 6b88a22 + 36168df commit 71a8edd
Show file tree
Hide file tree
Showing 24 changed files with 4,144 additions and 1,292 deletions.
33 changes: 28 additions & 5 deletions CPAC/anat_preproc/anat_preproc.py
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import os
from nipype.interfaces import afni
from nipype.interfaces import ants
from nipype.interfaces import fsl
Expand All @@ -9,6 +10,23 @@
from CPAC.utils.datasource import create_check_for_s3_node
from CPAC.unet.function import predict_volumes

def patch_cmass_output(lst, index=0):
"""
Parameters
----------
lst : list of tuples
output of afni.CenterMass()
index : int
index in the list of tuples
Returns
-------
tuple
one set of center of mass coordinates
"""
if len(lst) <= index:
raise IndexError("lst index out of range")
return lst[index]

def create_anat_preproc(method='afni', already_skullstripped=False, config=None, wf_name='anat_preproc'):
"""The main purpose of this workflow is to process T1 scans. Raw mprage file is deobliqued, reoriented
Expand Down Expand Up @@ -82,15 +100,18 @@ def create_anat_preproc(method='afni', already_skullstripped=False, config=None,

preproc = pe.Workflow(name=wf_name)

inputnode = pe.Node(util.IdentityInterface(
fields=['anat', 'brain_mask']), name='inputspec')
inputnode = pe.Node(util.IdentityInterface(fields=['anat',
'brain_mask',
'template_cmass']),
name='inputspec')

outputnode = pe.Node(util.IdentityInterface(fields=['refit',
'reorient',
'skullstrip',
'brain',
'brain_mask']),
name='outputspec')
'brain_mask',
'center_of_mass']),
name='outputspec')

anat_deoblique = pe.Node(interface=afni.Refit(),
name='anat_deoblique')
Expand Down Expand Up @@ -241,6 +262,7 @@ def create_anat_preproc(method='afni', already_skullstripped=False, config=None,

preproc.connect(anat_reorient, 'out_file',
anat_skullstrip, 'in_file')

preproc.connect(skullstrip_args, 'expr',
anat_skullstrip, 'args')

Expand Down Expand Up @@ -295,7 +317,7 @@ def create_anat_preproc(method='afni', already_skullstripped=False, config=None,
anat_skullstrip = pe.Node(
interface=fsl.BET(), name='anat_skullstrip')
anat_skullstrip.inputs.output_type = 'NIFTI_GZ'

preproc.connect(anat_reorient, 'out_file',
anat_skullstrip, 'in_file')

Expand Down Expand Up @@ -491,3 +513,4 @@ def create_anat_preproc(method='afni', already_skullstripped=False, config=None,
preproc.connect(refined_brain, 'out_file', outputnode, 'brain')

return preproc

18 changes: 14 additions & 4 deletions CPAC/distortion_correction/distortion_correction.py
Expand Up @@ -357,26 +357,31 @@ def blip_distcor_wf(wf_name='blip_distcor'):


def connect_distortion_correction(workflow, strat_list, c, diff, blip,
fmap_rp_list):
fmap_rp_list, unique_id=None):

# Distortion Correction
new_strat_list = []

# Distortion Correction - Field Map Phase-difference
if "PhaseDiff" in c.distortion_correction and diff:
for num_strat, strat in enumerate(strat_list):
if unique_id is None:
workflow_name=f'diff_distcor_{num_strat}'
else:
workflow_name=f'diff_distcor_{unique_id}_{num_strat}'

if 'BET' in c.fmap_distcorr_skullstrip:
epi_distcorr = create_EPI_DistCorr(
use_BET=True,
wf_name='diff_distcor_%d' % (num_strat)
wf_name=workflow_name
)
epi_distcorr.inputs.bet_frac_input.bet_frac = c.fmap_distcorr_frac
epi_distcorr.get_node('bet_frac_input').iterables = \
('bet_frac', c.fmap_distcorr_frac)
else:
epi_distcorr = create_EPI_DistCorr(
use_BET=False,
wf_name='diff_distcor_%d' % (num_strat)
wf_name=workflow_name
)
epi_distcorr.inputs.afni_threshold_input.afni_threshold = \
c.fmap_distcorr_threshold
Expand Down Expand Up @@ -461,8 +466,13 @@ def connect_distortion_correction(workflow, strat_list, c, diff, blip,
workflow.connect(node, node_out,
match_epi_fmaps_node, 'bold_pedir')

if unique_id is None:
workflow_name=f'blip_correct_{num_strat}'
else:
workflow_name=f'blip_correct_{unique_id}_{num_strat}'

blip_correct = blip_distcor_wf(
wf_name='blip_correct_{0}'.format(num_strat))
wf_name=workflow_name)

node, out_file = strat["mean_functional"]
workflow.connect(node, out_file,
Expand Down
41 changes: 26 additions & 15 deletions CPAC/func_preproc/func_ingress.py
Expand Up @@ -18,7 +18,7 @@
)

def connect_func_ingress(workflow, strat_list, c, sub_dict, subject_id,
input_creds_path):
input_creds_path, unique_id=None):

for num_strat, strat in enumerate(strat_list):

Expand All @@ -27,8 +27,14 @@ def connect_func_ingress(workflow, strat_list, c, sub_dict, subject_id,
else:
func_paths_dict = sub_dict['rest']

if unique_id is None:
workflow_name=f'func_gather_{num_strat}'
else:
workflow_name=f'func_gather_{unique_id}_{num_strat}'

func_wf = create_func_datasource(func_paths_dict,
'func_gather_%d' % num_strat)
workflow_name)

func_wf.inputs.inputnode.set(
subject=subject_id,
creds_path=input_creds_path,
Expand Down Expand Up @@ -134,25 +140,30 @@ def connect_func_ingress(workflow, strat_list, c, sub_dict, subject_id,

# Add in nodes to get parameters from configuration file
# a node which checks if scan_parameters are present for each scan
if unique_id is None:
workflow_name=f'scan_params_{num_strat}'
else:
workflow_name=f'scan_params_{unique_id}_{num_strat}'

scan_params = \
pe.Node(Function(
input_names=['data_config_scan_params',
'subject_id',
'scan',
'pipeconfig_tr',
'pipeconfig_tpattern',
'pipeconfig_start_indx',
'pipeconfig_stop_indx'],
'subject_id',
'scan',
'pipeconfig_tr',
'pipeconfig_tpattern',
'pipeconfig_start_indx',
'pipeconfig_stop_indx'],
output_names=['tr',
'tpattern',
'ref_slice',
'start_indx',
'stop_indx',
'pe_direction'],
'tpattern',
'ref_slice',
'start_indx',
'stop_indx',
'pe_direction'],
function=get_scan_params,
as_module=True
), name='scan_params_%d' % num_strat)

), name=workflow_name)
if "Selected Functional Volume" in c.func_reg_input:
get_func_volume = pe.Node(interface=afni.Calc(),
name='get_func_volume_{0}'.format(
Expand Down

0 comments on commit 71a8edd

Please sign in to comment.