Skip to content

Commit

Permalink
Merge branch 'main' into B5I6_repro
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet committed Jun 28, 2024
2 parents c3769e4 + af1651b commit e108ab0
Show file tree
Hide file tree
Showing 8 changed files with 1,429 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
identity and expression, level of experience, education, socioeconomic status,
nationality, personal appearance, race, caste, color, religion, or sexual
identity and orientation.

Expand Down
4 changes: 3 additions & 1 deletion narps_open/pipelines/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
'3TR7': 'PipelineTeam3TR7',
'43FJ': None,
'46CD': None,
'4SZ2': None,
'4SZ2': 'PipelineTeam4SZ2',
'4TQ6': 'PipelineTeam4TQ6',
'50GV': None,
'51PW': 'PipelineTeam51PW',
Expand All @@ -42,6 +42,8 @@
'AO86': None,
'B23O': None,
'B5I6': 'PipelineTeamB5I6',
'B23O': 'PipelineTeamB23O',
'B5I6': 'PipelineTeamB5I6',
'C22U': None,
'C88N': 'PipelineTeamC88N',
'DC61': None,
Expand Down
466 changes: 466 additions & 0 deletions narps_open/pipelines/team_4SZ2.py

Large diffs are not rendered by default.

722 changes: 722 additions & 0 deletions narps_open/pipelines/team_B23O.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())
parser.add_argument('-n', '--nsubjects', type=int, 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
106 changes: 106 additions & 0 deletions tests/pipelines/test_team_4SZ2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#!/usr/bin/python
# coding: utf-8

""" Tests of the 'narps_open.pipelines.team_4SZ2' module.
Launch this test with PyTest
Usage:
======
pytest -q test_team_4SZ2.py
pytest -q test_team_4SZ2.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_4SZ2 import PipelineTeam4SZ2

class TestPipelinesTeam4SZ2:
""" A class that contains all the unit tests for the PipelineTeam4SZ2 class."""

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

pipeline = PipelineTeam4SZ2()

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

# 2 - check workflows
assert pipeline.get_preprocessing() is None
assert isinstance(pipeline.get_run_level_analysis(), Workflow)
assert pipeline.get_subject_level_analysis() is None
assert isinstance(pipeline.get_group_level_analysis(), Workflow)

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

pipeline = PipelineTeam4SZ2()

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

# 2 - 4 subjects outputs
pipeline.subject_list = ['001', '002', '003', '004']
helpers.test_pipeline_outputs(pipeline, [0, 2*4*4*4, 0, 2*9, 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 = PipelineTeam4SZ2.get_subject_information(test_file)

# Compare bunches to expected
bunch = info_missed[0]
assert isinstance(bunch, Bunch)
assert bunch.conditions == ['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]
])
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]
])
helpers.compare_float_2d_arrays(bunch.amplitudes, [
[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_get_group_level_regressors():
""" Test the get_group_level_regressors method """

regressors = PipelineTeam4SZ2.get_group_level_regressors(
['001', '002', '003', '004'],
['01', '02'])

for k1, k2 in zip(regressors.keys(), ['equalIndifference', 'equalRange', 'age', 'gender']):
assert k1 == k2
assert regressors['equalIndifference'] == [1, 1, 0, 0, 1, 1, 0, 0]
assert regressors['equalRange'] == [0, 0, 1, 1, 0, 0, 1, 1]
assert regressors['age'] == [24, 24, 25, 25, 27, 27, 25, 25]
assert regressors['gender'] == [0, 0, 0, 0, 1, 1, 0, 0]

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

""" Tests of the 'narps_open.pipelines.team_B23O' module.
Launch this test with PyTest
Usage:
======
pytest -q test_team_B23O.py
pytest -q test_team_B23O.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_B23O import PipelineTeamB23O

class TestPipelinesTeamB23O:
""" A class that contains all the unit tests for the PipelineTeamB23O class."""

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

pipeline = PipelineTeamB23O()

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

# 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 PipelineTeamB23O object """

pipeline = PipelineTeamB23O()

# 1 - 1 subject outputs
pipeline.subject_list = ['001']
helpers.test_pipeline_outputs(pipeline, [0, 4*2*4*1, 4*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*2*4*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 = PipelineTeamB23O.get_subject_information(test_file)

# Compare bunches to expected
bunch = info[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 = join(
Configuration()['directories']['test_data'], 'pipelines', 'confounds.tsv')
reference_file = join(
Configuration()['directories']['test_data'],
'pipelines', 'team_B23O', 'confounds.tsv')

# Create new confounds file
confounds_node = Node(Function(
input_names = ['filepath', 'subject_id', 'run_id'],
output_names = ['confounds_file'],
function = PipelineTeamB23O.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 PipelineTeamB23O and compare results """
helpers.test_pipeline_evaluation('B23O')
3 changes: 3 additions & 0 deletions tests/test_data/pipelines/team_B23O/confounds.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
6551.281999999999 6476.4653 9874.576 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 -0.0 0.0
6484.7285 6473.4890000000005 9830.212 0.0263099209 -0.0673065879 0.0934882554 -0.0079328884 0.0338007737 -0.0114910839999999 -0.0424113470999999 0.0277364229 0.0453303087 -0.0702260949 0.0963618709 -0.0200867957 0.0665186088 0.0665174038 0.0665153954 0.0665125838 0.0665089688 0.0665045505999999 0.0 -0.00996895 -0.0313444 -3.00931e-06 0.00132687 -0.000384193 -0.00016819
6441.5337 6485.7256 9821.212 -0.0404820317 0.034150583 0.1366118421 0.0745358691 -0.0054829985999999 -0.0217322686 0.0462141151999999 0.005774624 -0.0439093598 -0.075619539 0.1754689153999999 -0.0345256763 0.0665153954 0.0665045505999999 0.0664864771999999 0.0664611772 0.0664286533 0.0663889091 0.0 -2.56954e-05 -0.00923735 0.0549667 0.000997278 -0.00019745 -0.000398988

0 comments on commit e108ab0

Please sign in to comment.