Skip to content

Commit

Permalink
[TEST] adding tests for 0ED6
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet committed Mar 7, 2024
1 parent bf61b10 commit 3972f77
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 21 deletions.
26 changes: 18 additions & 8 deletions narps_open/pipelines/team_0ED6.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,17 +277,27 @@ def get_preprocessing_outputs(self):
'_run_id_{run_id}', '_subject_id_{subject_id}')

# Smoothing outputs
template = join(output_dir, '_smoothing1',
'swrusub-{subject_id}_task-MGT_run-{run_id}_bold.nii')
templates = [
join(output_dir, 'swrusub-{subject_id}_task-MGT_run-{run_id}_bold.nii'),
join(output_dir, 'swrmeanusub-{subject_id}_task-MGT_run-{run_id}_bold.nii')
]

# DVARS output
templates += [
join(output_dir, 'swrusub-{subject_id}_task-MGT_run-{run_id}_bold_dvars_std.tsv')
]

# Realignement parameters TODO
templates += [join(output_dir, f'_realign_unwarp{index}',
'rp_sub-{subject_id}'+f'_task-MGT_run-{run_id}_bold.txt')\
for index, run_id in zip(range(len(self.run_list)), self.run_list)]
# Realignement parameters
templates += [
join(output_dir, '_realign_unwarp0',
'rp_sub-{subject_id}_task-MGT_run-{run_id}_sbref.txt'),
join(output_dir, '_realign_unwarp1',
'rp_sub-{subject_id}_task-MGT_run-{run_id}_bold.txt')
]

# Format with subject_ids and run_ids
return [template.format(subject_id = s, run_id = r)
for s in self.subject_list for r in self.run_list]
return [t.format(subject_id = s, run_id = r)
for t in templates for s in self.subject_list for r in self.run_list]

def get_run_level_analysis(self):
""" No run level analysis has been done by team 0ED6 """
Expand Down
25 changes: 12 additions & 13 deletions tests/pipelines/test_team_0ED6.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_create():
pipeline = PipelineTeam0ED6()

# 1 - check the parameters
assert pipeline.fwhm == 4.0
assert pipeline.fwhm == 5.0
assert pipeline.team_id == '0ED6'

# 2 - check workflows
Expand All @@ -52,11 +52,11 @@ def test_outputs():
pipeline = PipelineTeam0ED6()
# 1 - 1 subject outputs
pipeline.subject_list = ['001']
helpers.test_pipeline_outputs(pipeline, [21, 0, 5, 42, 18])
helpers.test_pipeline_outputs(pipeline, [20, 0, 9, 84, 18])

# 2 - 4 subjects outputs
pipeline.subject_list = ['001', '002', '003', '004']
helpers.test_pipeline_outputs(pipeline, [84, 0, 20, 42, 18])
helpers.test_pipeline_outputs(pipeline, [80, 0, 36, 84, 18])

@staticmethod
@mark.unit_test
Expand All @@ -65,24 +65,23 @@ def test_confounds_file(temporary_data_dir):

# Test files
test_dvars = abspath(join(Configuration()['directories']['test_data'],
'pipelines', 'team_0ED6', 'realignment_parameters.txt')) # TODO
'pipelines', 'team_0ED6', 'swrusub-001_task-MGT_run-01_bold_dvars_std.tsv'))
test_realignment_parameters = abspath(join(Configuration()['directories']['test_data'],
'pipelines', 'team_0ED6', 'realignment_parameters.txt'))
'pipelines', 'team_0ED6', 'rp_sub-001_task-MGT_run-01_bold.txt'))

# Reference file
ref_file = abspath(join(Configuration()['directories']['test_data'],
'pipelines', 'team_0ED6', 'confounds.tsv'))
'pipelines', 'team_0ED6', 'confounds_file_sub-sid_run-rid.tsv'))

# Create average values file
confounds_node = Node(Function(
input_names = [
'realignement_parameters', 'subject_id', 'run_id'
],
input_names = ['dvars_file', 'realignement_parameters', 'subject_id', 'run_id'],
output_names = ['out_file'],
function = PipelineTeam0ED6.get_confounds_file),
name = 'confounds_node')
confounds_node.base_dir = temporary_data_dir
confounds_node.inputs.realignement_parameters = test_realignment_parameters
confounds_node.inputs.dvars_file = test_dvars
confounds_node.inputs.subject_id = 'sid'
confounds_node.inputs.run_id = 'rid'
confounds_node.run()
Expand Down Expand Up @@ -119,12 +118,12 @@ def test_subject_information():

paramateric_modulation = information.pmod[0]
assert isinstance(paramateric_modulation, Bunch)
assert paramateric_modulation.name == ['gain', 'loss', 'response_time']
assert paramateric_modulation.name == ['gain', 'loss', 'reaction_time']
assert paramateric_modulation.poly == [1, 1, 1]
helpers.compare_float_2d_arrays([
[14.0, 34.0, 0.0, 2.388, 2.289],
[14.0, 34.0, 0.0, 2.388, 2.289],
[14.0, 34.0, 0.0, 2.388, 2.289]
[14.0, 34.0, 38.0, 10.0, 16.0],
[6.0, 14.0, 19.0, 15.0, 17.0],
[2.388, 2.289, 0.0, 2.08, 2.288]
],
paramateric_modulation.param)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.0 0.0 0.0 0.0 0.0 0.0 0.0
0.0014317552 -0.030498826 0.037218343 0.0013638583 3.9244771e-05 0.00033324319 1.119707
0.000483077 -0.048475965 0.11827112 0.0015250625 0.00011069903 0.00069169236 1.032501
0.0026036058 -0.0018894815 0.1610942 0.001236676 0.00024482376 0.00053899813 1.020995
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00 0.0000000e+00
1.4317552e-03 -3.0498826e-02 3.7218343e-02 1.3638583e-03 3.9244771e-05 3.3324319e-04
4.8307700e-04 -4.8475965e-02 1.1827112e-01 1.5250625e-03 1.1069903e-04 6.9169236e-04
2.6036058e-03 -1.8894815e-03 1.6109420e-01 1.2366760e-03 2.4482376e-04 5.3899813e-04
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1.119707
1.032501
1.020995

0 comments on commit 3972f77

Please sign in to comment.