Skip to content

Commit

Permalink
Output naming bug solved in all pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet committed Feb 6, 2024
1 parent 829f119 commit d20e36d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 33 deletions.
93 changes: 72 additions & 21 deletions narps_open/pipelines/team_08MQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,23 +386,24 @@ def get_preprocessing_outputs(self):
parameters = {
'subject_id': self.subject_list,
'run_id': self.run_list,
'file': [
'components_file.txt',
'sub-{subject_id}_task-MGT_run-{run_id}_bold_brain_mcf.nii.gz.par',
'sub-{subject_id}_task-MGT_run-{run_id}_bold_brain_mcf_st_smooth_flirt_wtsimt.nii.gz',
'sub-{subject_id}_task-MGT_run-{run_id}_bold_brain_mask_flirt_wtsimt.nii.gz'
]
}
parameter_sets = product(*parameters.values())
template = join(
output_dir = join(
self.directories.output_dir,
'preprocessing',
'_run_id_{run_id}_subject_id_{subject_id}',
'{file}'
)
'_run_id_{run_id}_subject_id_{subject_id}'
)
templates = [
join(output_dir, 'components_file.txt'),
join(output_dir, 'sub-{subject_id}_task-MGT_run-{run_id}_bold_brain_mcf.nii.gz.par'),
join(output_dir,
'sub-{subject_id}_task-MGT_run-{run_id}_bold_brain_mcf_st_smooth_flirt_wtsimt.nii.gz'),
join(output_dir,
'sub-{subject_id}_task-MGT_run-{run_id}_bold_brain_mask_flirt_wtsimt.nii.gz')
]

return [template.format(**dict(zip(parameters.keys(), parameter_values)))\
for parameter_values in parameter_sets]
for parameter_values in parameter_sets for template in templates]

def get_subject_information(event_file):
"""
Expand Down Expand Up @@ -586,21 +587,20 @@ def get_run_level_outputs(self):
'run_id' : self.run_list,
'subject_id' : self.subject_list,
'contrast_id' : self.contrast_list,
'file' : [
join('results', 'cope{contrast_id}.nii.gz'),
join('results', 'tstat{contrast_id}.nii.gz'),
join('results', 'varcope{contrast_id}.nii.gz'),
join('results', 'zstat{contrast_id}.nii.gz'),
]
}
parameter_sets = product(*parameters.values())
template = join(
output_dir = join(
self.directories.output_dir,
'run_level_analysis', '_run_id_{run_id}_subject_id_{subject_id}','{file}'
'run_level_analysis', '_run_id_{run_id}_subject_id_{subject_id}'
)

templates = [
join(output_dir, 'results', 'cope{contrast_id}.nii.gz'),
join(output_dir, 'results', 'tstat{contrast_id}.nii.gz'),
join(output_dir, 'results', 'varcope{contrast_id}.nii.gz'),
join(output_dir, 'results', 'zstat{contrast_id}.nii.gz'),
]
return_list += [template.format(**dict(zip(parameters.keys(), parameter_values)))\
for parameter_values in parameter_sets]
for parameter_values in parameter_sets for template in templates]

return return_list

Expand Down Expand Up @@ -1005,6 +1005,57 @@ def get_group_level_analysis_sub_workflow(self, method):

return group_level_analysis

def get_group_level_outputs(self):
""" Return all names for the files the group level analysis is supposed to generate. """

# Handle equalRange and equalIndifference
parameters = {
'contrast_id': self.contrast_list,
'method': ['equalRange', 'equalIndifference'],
'file': [
'randomise_tfce_corrp_tstat1.nii.gz',
'randomise_tfce_corrp_tstat2.nii.gz',
'randomise_tstat1.nii.gz',
'randomise_tstat2.nii.gz',
'tstat1.nii.gz',
'tstat2.nii.gz',
'zstat1.nii.gz',
'zstat2.nii.gz'
],
'nb_subjects' : [str(len(self.subject_list))]
}
parameter_sets = product(*parameters.values())
template = join(
self.directories.output_dir,
'group_level_analysis_{method}_nsub_{nb_subjects}',
'_contrast_id_{contrast_id}',
'{file}'
)

return_list = [template.format(**dict(zip(parameters.keys(), parameter_values)))\
for parameter_values in parameter_sets]

# Handle groupComp
parameters = {
'contrast_id': self.contrast_list,
'file': [
'randomise_tfce_corrp_tstat1.nii.gz',
'randomise_tstat1.nii.gz',
'zstat1.nii.gz',
'tstat1.nii.gz'
]
}
parameter_sets = product(*parameters.values())
template = join(
self.directories.output_dir,
f'group_level_analysis_groupComp_nsub_{len(self.subject_list)}',
'_contrast_id_{contrast_id}', '{file}')

return_list += [template.format(**dict(zip(parameters.keys(), parameter_values)))\
for parameter_values in parameter_sets]

return return_list

def get_hypotheses_outputs(self):
""" Return the names of the files used by the team to answer the hypotheses of NARPS. """

Expand Down
21 changes: 13 additions & 8 deletions narps_open/pipelines/team_T54A.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,17 +765,22 @@ def get_group_level_outputs(self):
for parameter_values in parameter_sets]

# Handle groupComp
files = [
'randomise_tfce_corrp_tstat1.nii.gz',
'randomise_tstat1.nii.gz',
'zstat1.nii.gz',
'tstat1.nii.gz'
parameters = {
'contrast_id': self.contrast_list,
'file': [
'randomise_tfce_corrp_tstat1.nii.gz',
'randomise_tstat1.nii.gz',
'zstat1.nii.gz',
'tstat1.nii.gz'
]

return_list += [join(
}
parameter_sets = product(*parameters.values())
template = join(
self.directories.output_dir,
f'group_level_analysis_groupComp_nsub_{len(self.subject_list)}',
'_contrast_id_2', f'{file}') for file in files]
'_contrast_id_{contrast_id}', '{file}')
return_list += [template.format(**dict(zip(parameters.keys(), parameter_values)))\
for parameter_values in parameter_sets]

return return_list

Expand Down
4 changes: 2 additions & 2 deletions tests/pipelines/test_team_08MQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ def test_outputs():
pipeline = PipelineTeam08MQ()
# 1 - 1 subject outputs
pipeline.subject_list = ['001']
helpers.test_pipeline_ouputs(pipeline, [4*4, 8+4*3*4, 4*3, 0, 18])
helpers.test_pipeline_outputs(pipeline, [4*4, 8+4*3*4, 4*3, 8*2*3 + 4*3, 18])

# 2 - 4 subjects outputs
pipeline.subject_list = ['001', '002', '003', '004']
helpers.test_pipeline_ouputs(pipeline, [4*4*4, (8+4*3*4)*4, 4*3*4, 0, 18])
helpers.test_pipeline_outputs(pipeline, [4*4*4, (8+4*3*4)*4, 4*3*4, 8*2*3 + 4*3, 18])

@staticmethod
@mark.unit_test
Expand Down
4 changes: 2 additions & 2 deletions tests/pipelines/test_team_T54A.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def test_outputs():
pipeline = PipelineTeamT54A()
# 1 - 1 subject outputs
pipeline.subject_list = ['001']
helpers.test_pipeline_outputs(pipeline, [0, 9*4*1, 5*2*1, 8*2*2 + 4, 18])
helpers.test_pipeline_outputs(pipeline, [0, 9*4*1, 5*2*1, 8*2*2 + 4*2, 18])

# 2 - 4 subjects outputs
pipeline.subject_list = ['001', '002', '003', '004']
helpers.test_pipeline_outputs(pipeline, [0, 9*4*4, 5*2*4, 8*2*2 + 4, 18])
helpers.test_pipeline_outputs(pipeline, [0, 9*4*4, 5*2*4, 8*2*2 + 4*2, 18])

@staticmethod
@mark.unit_test
Expand Down
3 changes: 3 additions & 0 deletions tests/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def get_hypotheses_outputs(self):
class MockupWrongPipeline(Pipeline):
""" A simple Pipeline class for test purposes """

def __init__(self):
super().__init__()

def get_preprocessing(self):
""" Return a preprocessing worflow with wrong type """

Check failure on line 145 in tests/test_runner.py

View workflow job for this annotation

GitHub Actions / Check for spelling errors

worflow ==> workflow
return 'Wrong_workflow_type'
Expand Down

0 comments on commit d20e36d

Please sign in to comment.