Skip to content

Commit

Permalink
Merge branch 'main' into B23O_repro
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet committed Jun 21, 2024
2 parents d42b42f + 13c7bc3 commit 02241e1
Show file tree
Hide file tree
Showing 10 changed files with 2,513 additions and 567 deletions.
6 changes: 3 additions & 3 deletions narps_open/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'43FJ': None,
'46CD': None,
'4SZ2': None,
'4TQ6': None,
'4TQ6': 'PipelineTeam4TQ6',
'50GV': None,
'51PW': 'PipelineTeam51PW',
'5G9K': None,
Expand Down Expand Up @@ -58,8 +58,8 @@
'L7J7': 'PipelineTeamL7J7',
'L9G5': None,
'O03M': None,
'O21U': None,
'O6R6': None,
'O21U': 'PipelineTeamO21U',
'O6R6': 'PipelineTeamO6R6',
'P5F3': None,
'Q58J': None,
'Q6O0': 'PipelineTeamQ6O0',
Expand Down
697 changes: 697 additions & 0 deletions narps_open/pipelines/team_4TQ6.py

Large diffs are not rendered by default.

563 changes: 0 additions & 563 deletions narps_open/pipelines/team_4TQ6_wip.py

This file was deleted.

742 changes: 742 additions & 0 deletions narps_open/pipelines/team_O21U.py

Large diffs are not rendered by default.

727 changes: 727 additions & 0 deletions narps_open/pipelines/team_O6R6.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion narps_open/utils/correlation/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def main():
parser = ArgumentParser(description = 'Compare reproduced files to original results.')
parser.add_argument('-t', '--team', type = str, required = True,
help = 'the team ID', choices = get_implemented_pipelines())
subjects.add_argument('-n', '--nsubjects', type=str, required = True,
parser.add_argument('-n', '--nsubjects', type=int, required = True,
help='the number of subjects to be selected')
arguments = parser.parse_args()

Expand Down
96 changes: 96 additions & 0 deletions tests/pipelines/test_team_4TQ6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/usr/bin/python
# coding: utf-8

""" Tests of the 'narps_open.pipelines.team_4TQ6' module.
Launch this test with PyTest
Usage:
======
pytest -q test_team_4TQ6.py
pytest -q test_team_4TQ6.py -k <selected_test>
"""
from os.path import join, exists, abspath
from filecmp import cmp

from pytest import helpers, mark
from nipype import Workflow, Node, Function
from nipype.interfaces.base import Bunch

from narps_open.utils.configuration import Configuration
from narps_open.pipelines.team_4TQ6 import PipelineTeam4TQ6

class TestPipelinesTeam4TQ6:
""" A class that contains all the unit tests for the PipelineTeam4TQ6 class."""

@staticmethod
@mark.unit_test
def test_create():
""" Test the creation of a PipelineTeam4TQ6 object """

pipeline = PipelineTeam4TQ6()

# 1 - check the parameters
assert pipeline.fwhm == 6.0
assert pipeline.team_id == '4TQ6'

# 2 - check workflows
assert pipeline.get_preprocessing() is None
assert isinstance(pipeline.get_run_level_analysis(), Workflow)
assert isinstance(pipeline.get_subject_level_analysis(), Workflow)
group_level = pipeline.get_group_level_analysis()
assert len(group_level) == 3
for sub_workflow in group_level:
assert isinstance(sub_workflow, Workflow)

@staticmethod
@mark.unit_test
def test_outputs():
""" Test the expected outputs of a PipelineTeam4TQ6 object """

pipeline = PipelineTeam4TQ6()

# 1 - 1 subject outputs
pipeline.subject_list = ['001']
helpers.test_pipeline_outputs(pipeline, [0, 4*1*2*4, 4*2*1 + 2*1, 6*2*2 + 3*2, 18])

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

@staticmethod
@mark.unit_test
def test_subject_information():
""" Test the get_subject_information method """

# Get test files
test_file = join(Configuration()['directories']['test_data'], 'pipelines', 'events.tsv')

# Prepare several scenarii
info_missed = PipelineTeam4TQ6.get_subject_information(test_file)

# Compare bunches to expected
bunch = info_missed[0]
assert isinstance(bunch, Bunch)
assert bunch.conditions == ['trial', 'gain', 'loss']
helpers.compare_float_2d_arrays(bunch.onsets, [
[4.071, 11.834, 19.535, 27.535, 36.435],
[4.071, 11.834, 19.535, 27.535, 36.435],
[4.071, 11.834, 19.535, 27.535, 36.435]
])
helpers.compare_float_2d_arrays(bunch.durations, [
[4.0, 4.0, 4.0, 4.0, 4.0],
[4.0, 4.0, 4.0, 4.0, 4.0],
[4.0, 4.0, 4.0, 4.0, 4.0]
])
helpers.compare_float_2d_arrays(bunch.amplitudes, [
[1.0, 1.0, 1.0, 1.0, 1.0],
[14.0, 34.0, 38.0, 10.0, 16.0],
[6.0, 14.0, 19.0, 15.0, 17.0]
])

@staticmethod
@mark.pipeline_test
def test_execution():
""" Test the execution of a PipelineTeam4TQ6 and compare results """
helpers.test_pipeline_evaluation('4TQ6')
128 changes: 128 additions & 0 deletions tests/pipelines/test_team_O21U.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
#!/usr/bin/python
# coding: utf-8

""" Tests of the 'narps_open.pipelines.team_O21U' module.
Launch this test with PyTest
Usage:
======
pytest -q test_team_O21U.py
pytest -q test_team_O21U.py -k <selected_test>
"""
from os.path import join, exists, abspath
from filecmp import cmp

from pytest import helpers, mark
from nipype import Workflow, Node, Function
from nipype.interfaces.base import Bunch

from narps_open.utils.configuration import Configuration
from narps_open.pipelines.team_O21U import PipelineTeamO21U

class TestPipelinesTeamO21U:
""" A class that contains all the unit tests for the PipelineTeamO21U class."""

@staticmethod
@mark.unit_test
def test_create():
""" Test the creation of a PipelineTeamO21U object """

pipeline = PipelineTeamO21U()

# 1 - check the parameters
assert pipeline.fwhm == 5.0
assert pipeline.team_id == 'O21U'

# 2 - check workflows
assert pipeline.get_preprocessing() is None
assert isinstance(pipeline.get_run_level_analysis(), Workflow)
assert isinstance(pipeline.get_subject_level_analysis(), Workflow)
group_level = pipeline.get_group_level_analysis()
assert len(group_level) == 3
for sub_workflow in group_level:
assert isinstance(sub_workflow, Workflow)

@staticmethod
@mark.unit_test
def test_outputs():
""" Test the expected outputs of a PipelineTeamO21U object """

pipeline = PipelineTeamO21U()

# 1 - 1 subject outputs
pipeline.subject_list = ['001']
helpers.test_pipeline_outputs(pipeline, [0, 4*1*2*4, 4*2*1 + 2*1, 6*2*2 + 3*2, 18])

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

@staticmethod
@mark.unit_test
def test_subject_information():
""" Test the get_subject_information method """

# Get test files
test_file = join(Configuration()['directories']['test_data'], 'pipelines', 'events.tsv')

# Prepare several scenarii
info_missed = PipelineTeamO21U.get_subject_information(test_file)

# Compare bunches to expected
bunch = info_missed[0]
assert isinstance(bunch, Bunch)
assert bunch.conditions == ['trial', 'gain', 'loss']
helpers.compare_float_2d_arrays(bunch.onsets, [
[4.071, 11.834, 19.535, 27.535, 36.435],
[4.071, 11.834, 19.535, 27.535, 36.435],
[4.071, 11.834, 19.535, 27.535, 36.435]
])
helpers.compare_float_2d_arrays(bunch.durations, [
[4.0, 4.0, 4.0, 4.0, 4.0],
[4.0, 4.0, 4.0, 4.0, 4.0],
[4.0, 4.0, 4.0, 4.0, 4.0]
])
helpers.compare_float_2d_arrays(bunch.amplitudes, [
[1.0, 1.0, 1.0, 1.0, 1.0],
[14.0, 34.0, 38.0, 10.0, 16.0],
[6.0, 14.0, 19.0, 15.0, 17.0]
])

@staticmethod
@mark.unit_test
def test_confounds_file(temporary_data_dir):
""" Test the get_confounds_file method """

# Get input and reference output file
confounds_file = abspath(join(
Configuration()['directories']['test_data'], 'pipelines', 'confounds.tsv'))
reference_file = abspath(join(
Configuration()['directories']['test_data'],
'pipelines', 'team_O21U', 'confounds.tsv'))

# Create new confounds file
confounds_node = Node(Function(
input_names = ['filepath', 'subject_id', 'run_id'],
output_names = ['confounds_file'],
function = PipelineTeamO21U.get_confounds_file),
name = 'confounds_node')
confounds_node.base_dir = temporary_data_dir
confounds_node.inputs.filepath = confounds_file
confounds_node.inputs.subject_id = 'sid'
confounds_node.inputs.run_id = 'rid'
confounds_node.run()

# Check confounds file was created
created_confounds_file = abspath(join(
temporary_data_dir, confounds_node.name, 'confounds_file_sub-sid_run-rid.tsv'))
assert exists(created_confounds_file)

# Check contents
assert cmp(reference_file, created_confounds_file)

@staticmethod
@mark.pipeline_test
def test_execution():
""" Test the execution of a PipelineTeamO21U and compare results """
helpers.test_pipeline_evaluation('O21U')
116 changes: 116 additions & 0 deletions tests/pipelines/test_team_O6R6.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/python
# coding: utf-8

""" Tests of the 'narps_open.pipelines.team_O6R6' module.
Launch this test with PyTest
Usage:
======
pytest -q test_team_O6R6.py
pytest -q test_team_O6R6.py -k <selected_test>
"""
from os.path import join, exists, abspath
from filecmp import cmp

from pytest import helpers, mark
from nipype import Workflow, Node, Function
from nipype.interfaces.base import Bunch

from narps_open.utils.configuration import Configuration
from narps_open.pipelines.team_O6R6 import PipelineTeamO6R6

class TestPipelinesTeamO6R6:
""" A class that contains all the unit tests for the PipelineTeamO6R6 class."""

@staticmethod
@mark.unit_test
def test_create():
""" Test the creation of a PipelineTeamO6R6 object """

pipeline = PipelineTeamO6R6()

# 1 - check the parameters
assert pipeline.team_id == 'O6R6'

# 2 - check workflows
assert pipeline.get_preprocessing() is None
assert isinstance(pipeline.get_run_level_analysis(), Workflow)
assert isinstance(pipeline.get_subject_level_analysis(), Workflow)
group_level = pipeline.get_group_level_analysis()
assert len(group_level) == 3
for sub_workflow in group_level:
assert isinstance(sub_workflow, Workflow)

@staticmethod
@mark.unit_test
def test_outputs():
""" Test the expected outputs of a PipelineTeamO6R6 object """

pipeline = PipelineTeamO6R6()

# 1 - 1 subject outputs
pipeline.subject_list = ['001']
helpers.test_pipeline_outputs(pipeline, [0, 2*1*4*4, 2*4*1 + 2*1, 6*2*2 + 3*2, 18])

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

@staticmethod
@mark.unit_test
def test_subject_information():
""" Test the get_subject_information method """

# Get test files
test_file = join(Configuration()['directories']['test_data'], 'pipelines', 'events.tsv')

# Prepare several scenarii
info_ei = PipelineTeamO6R6.get_subject_information(test_file, 'equalIndifference')
info_er = PipelineTeamO6R6.get_subject_information(test_file, 'equalRange')

# Compare bunches to expected
bunch = info_ei[0]
assert isinstance(bunch, Bunch)
assert bunch.conditions == ['trial', 'gain_trial', 'loss_trial']
helpers.compare_float_2d_arrays(bunch.onsets, [
[4.071, 11.834, 27.535, 36.435],
[4.071, 11.834],
[27.535, 36.435]
])
helpers.compare_float_2d_arrays(bunch.durations, [
[2.388, 2.289, 2.08, 2.288],
[2.388, 2.289],
[2.08, 2.288]
])
helpers.compare_float_2d_arrays(bunch.amplitudes, [
[1.0, 1.0, 1.0, 1.0],
[3.0, 13.0],
[3.5, 4.5]
])

# Compare bunches to expected
bunch = info_er[0]
assert isinstance(bunch, Bunch)
assert bunch.conditions == ['trial', 'gain_trial', 'loss_trial']
helpers.compare_float_2d_arrays(bunch.onsets, [
[4.071, 11.834, 27.535, 36.435],
[4.071, 11.834],
[27.535, 36.435]
])
helpers.compare_float_2d_arrays(bunch.durations, [
[2.388, 2.289, 2.08, 2.288],
[2.388, 2.289],
[2.08, 2.288]
])
helpers.compare_float_2d_arrays(bunch.amplitudes, [
[1.0, 1.0, 1.0, 1.0],
[10.0, 30.0],
[11.0, 13.0]
])

@staticmethod
@mark.pipeline_test
def test_execution():
""" Test the execution of a PipelineTeamO6R6 and compare results """
helpers.test_pipeline_evaluation('O6R6')
3 changes: 3 additions & 0 deletions tests/test_data/pipelines/team_O21U/confounds.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0.0 0.0 0.0 0.0 0.0 -0.0 0.0
0.1352790093099999 -0.00996895 -0.0313444 -3.00931e-06 0.00132687 -0.000384193 -0.00016819
0.12437666391 -2.56954e-05 -0.00923735 0.0549667 0.000997278 -0.00019745 -0.000398988

0 comments on commit 02241e1

Please sign in to comment.