forked from Inria-Empenn/narps_open_pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into documentation
- Loading branch information
Showing
7 changed files
with
854 additions
and
504 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
#!/usr/bin/python | ||
# coding: utf-8 | ||
|
||
""" Tests of the 'narps_open.pipelines.team_J7F9' module. | ||
Launch this test with PyTest | ||
Usage: | ||
====== | ||
pytest -q test_team_J7F9.py | ||
pytest -q test_team_J7F9.py -k <selected_test> | ||
""" | ||
from os import mkdir | ||
from os.path import join, exists | ||
from shutil import rmtree | ||
from filecmp import cmp | ||
|
||
from pytest import helpers, mark, fixture | ||
from numpy import isclose | ||
from nipype import Workflow | ||
from nipype.interfaces.base import Bunch | ||
|
||
from narps_open.utils.configuration import Configuration | ||
from narps_open.pipelines.team_J7F9 import PipelineTeamJ7F9 | ||
|
||
TEMPORARY_DIR = join(Configuration()['directories']['test_runs'], 'test_J7F9') | ||
|
||
@fixture | ||
def remove_test_dir(): | ||
""" A fixture to remove temporary directory created by tests """ | ||
|
||
rmtree(TEMPORARY_DIR, ignore_errors = True) | ||
mkdir(TEMPORARY_DIR) | ||
yield # test runs here | ||
rmtree(TEMPORARY_DIR, ignore_errors = True) | ||
|
||
def compare_float_2d_arrays(array_1, array_2): | ||
""" Assert array_1 and array_2 are close enough """ | ||
|
||
assert len(array_1) == len(array_2) | ||
for reference_array, test_array in zip(array_1, array_2): | ||
assert len(reference_array) == len(test_array) | ||
assert isclose(reference_array, test_array).all() | ||
|
||
class TestPipelinesTeamJ7F9: | ||
""" A class that contains all the unit tests for the PipelineTeamJ7F9 class.""" | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_create(): | ||
""" Test the creation of a PipelineTeamJ7F9 object """ | ||
|
||
pipeline = PipelineTeamJ7F9() | ||
|
||
# 1 - check the parameters | ||
assert pipeline.fwhm == 8.0 | ||
assert pipeline.team_id == 'J7F9' | ||
|
||
# 2 - check workflows | ||
assert pipeline.get_preprocessing() is None | ||
assert pipeline.get_run_level_analysis() is None | ||
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 PipelineTeamJ7F9 object """ | ||
pipeline = PipelineTeamJ7F9() | ||
# 1 - 1 subject outputs | ||
pipeline.subject_list = ['001'] | ||
assert len(pipeline.get_preprocessing_outputs()) == 0 | ||
assert len(pipeline.get_run_level_outputs()) == 0 | ||
assert len(pipeline.get_subject_level_outputs()) == 7 | ||
assert len(pipeline.get_group_level_outputs()) == 63 | ||
assert len(pipeline.get_hypotheses_outputs()) == 18 | ||
|
||
# 2 - 4 subjects outputs | ||
pipeline.subject_list = ['001', '002', '003', '004'] | ||
assert len(pipeline.get_preprocessing_outputs()) == 0 | ||
assert len(pipeline.get_run_level_outputs()) == 0 | ||
assert len(pipeline.get_subject_level_outputs()) == 28 | ||
assert len(pipeline.get_group_level_outputs()) == 63 | ||
assert len(pipeline.get_hypotheses_outputs()) == 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') | ||
test_file_2 = join(Configuration()['directories']['test_data'], | ||
'pipelines', 'team_J7F9', 'events_resp.tsv') | ||
|
||
# Prepare several scenarii | ||
info_missed = PipelineTeamJ7F9.get_subject_information([test_file, test_file]) | ||
info_ok = PipelineTeamJ7F9.get_subject_information([test_file_2, test_file_2]) | ||
info_half = PipelineTeamJ7F9.get_subject_information([test_file_2, test_file]) | ||
|
||
# Compare bunches to expected | ||
bunch = info_missed[0] | ||
assert isinstance(bunch, Bunch) | ||
assert bunch.conditions == ['trial', 'missed'] | ||
compare_float_2d_arrays(bunch.onsets, [[4.071, 11.834, 19.535, 27.535, 36.435], [19.535]]) | ||
compare_float_2d_arrays(bunch.durations, [[0.0, 0.0, 0.0, 0.0, 0.0], [0.0]]) | ||
assert bunch.amplitudes == None | ||
assert bunch.tmod == None | ||
assert bunch.pmod[0].name == ['gain', 'loss'] | ||
assert bunch.pmod[0].poly == [1, 1] | ||
compare_float_2d_arrays(bunch.pmod[0].param, [[-8.4, 11.6, 15.6, -12.4, -6.4], [-8.2, -0.2, 4.8, 0.8, 2.8]]) | ||
assert bunch.regressor_names == None | ||
assert bunch.regressors == None | ||
|
||
bunch = info_missed[1] | ||
assert isinstance(bunch, Bunch) | ||
assert bunch.conditions == ['trial', 'missed'] | ||
compare_float_2d_arrays(bunch.onsets, [[4.071, 11.834, 19.535, 27.535, 36.435], [19.535]]) | ||
compare_float_2d_arrays(bunch.durations, [[0.0, 0.0, 0.0, 0.0, 0.0], [0.0]]) | ||
assert bunch.amplitudes == None | ||
assert bunch.tmod == None | ||
assert bunch.pmod[0].name == ['gain', 'loss'] | ||
assert bunch.pmod[0].poly == [1, 1] | ||
compare_float_2d_arrays(bunch.pmod[0].param, [[-8.4, 11.6, 15.6, -12.4, -6.4], [-8.2, -0.2, 4.8, 0.8, 2.8]]) | ||
assert bunch.regressor_names == None | ||
assert bunch.regressors == None | ||
|
||
bunch = info_ok[0] | ||
assert isinstance(bunch, Bunch) | ||
assert bunch.conditions == ['trial'] | ||
compare_float_2d_arrays(bunch.onsets, [[4.071, 11.834, 27.535, 36.435]]) | ||
compare_float_2d_arrays(bunch.durations, [[0.0, 0.0, 0.0, 0.0]]) | ||
assert bunch.amplitudes == None | ||
assert bunch.tmod == None | ||
assert bunch.pmod[0].name == ['gain', 'loss'] | ||
assert bunch.pmod[0].poly == [1, 1] | ||
compare_float_2d_arrays(bunch.pmod[0].param, [[-4.5, 15.5, -8.5, -2.5], [-7.0, 1.0, 2.0, 4.0]]) | ||
assert bunch.regressor_names == None | ||
assert bunch.regressors == None | ||
|
||
bunch = info_ok[1] | ||
assert isinstance(bunch, Bunch) | ||
assert bunch.conditions == ['trial'] | ||
compare_float_2d_arrays(bunch.onsets, [[4.071, 11.834, 27.535, 36.435]]) | ||
compare_float_2d_arrays(bunch.durations, [[0.0, 0.0, 0.0, 0.0]]) | ||
assert bunch.amplitudes == None | ||
assert bunch.tmod == None | ||
assert bunch.pmod[0].name == ['gain', 'loss'] | ||
assert bunch.pmod[0].poly == [1, 1] | ||
compare_float_2d_arrays(bunch.pmod[0].param, [[-4.5, 15.5, -8.5, -2.5], [-7.0, 1.0, 2.0, 4.0]]) | ||
assert bunch.regressor_names == None | ||
assert bunch.regressors == None | ||
|
||
bunch = info_half[0] | ||
assert isinstance(bunch, Bunch) | ||
assert bunch.conditions == ['trial', 'missed'] | ||
compare_float_2d_arrays(bunch.onsets, [[4.071, 11.834, 27.535, 36.435], []]) | ||
compare_float_2d_arrays(bunch.durations, [[0.0, 0.0, 0.0, 0.0], []]) | ||
assert bunch.amplitudes == None | ||
assert bunch.tmod == None | ||
assert bunch.pmod[0].name == ['gain', 'loss'] | ||
assert bunch.pmod[0].poly == [1, 1] | ||
compare_float_2d_arrays(bunch.pmod[0].param, [[-6.666666666666668, 13.333333333333332, -10.666666666666668, -4.666666666666668], [-7.666666666666666, 0.3333333333333339, 1.333333333333334, 3.333333333333334]]) | ||
assert bunch.regressor_names == None | ||
assert bunch.regressors == None | ||
|
||
bunch = info_half[1] | ||
assert isinstance(bunch, Bunch) | ||
assert bunch.conditions == ['trial', 'missed'] | ||
compare_float_2d_arrays(bunch.onsets, [[4.071, 11.834, 19.535, 27.535, 36.435], [19.535]]) | ||
compare_float_2d_arrays(bunch.durations, [[0.0, 0.0, 0.0, 0.0, 0.0], [0.0]]) | ||
assert bunch.amplitudes == None | ||
assert bunch.tmod == None | ||
assert bunch.pmod[0].name == ['gain', 'loss'] | ||
assert bunch.pmod[0].poly == [1, 1] | ||
compare_float_2d_arrays(bunch.pmod[0].param, [[-6.666666666666668, 13.333333333333332, 17.333333333333332, -10.666666666666668, -4.666666666666668], [-7.666666666666666, 0.3333333333333339, 5.333333333333334, 1.333333333333334, 3.333333333333334]]) | ||
assert bunch.regressor_names == None | ||
assert bunch.regressors == None | ||
|
||
@staticmethod | ||
@mark.unit_test | ||
def test_confounds_file(remove_test_dir): | ||
""" Test the get_confounds_file method """ | ||
|
||
confounds_file = join( | ||
Configuration()['directories']['test_data'], 'pipelines', 'confounds.tsv') | ||
reference_file = join( | ||
Configuration()['directories']['test_data'], 'pipelines', 'team_J7F9', 'confounds.tsv') | ||
|
||
# Get new confounds file | ||
PipelineTeamJ7F9.get_confounds_file(confounds_file, 'sid', 'rid', TEMPORARY_DIR) | ||
|
||
# Check confounds file was created | ||
created_confounds_file = join( | ||
TEMPORARY_DIR, 'confounds_files', '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 PipelineTeamJ7F9 and compare results """ | ||
helpers.test_pipeline_evaluation('J7F9') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
CSF WhiteMatter GlobalSignal stdDVARS non-stdDVARS vx-wisestdDVARS FramewiseDisplacement tCompCor00 tCompCor01 tCompCor02 tCompCor03 tCompCor04 tCompCor05 aCompCor00 aCompCor01 aCompCor02 aCompCor03 aCompCor04 aCompCor05 Cosine00 Cosine01 Cosine02 Cosine03 Cosine04 Cosine05 NonSteadyStateOutlier00 X Y Z RotX RotY RotZ | ||
6551.281999999999 6476.4653 9874.576 n/a n/a n/a n/a 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 1.09046686 52.78273392 1.05943739 0.13527900930999998 0.0263099209 -0.0673065879 0.0934882554 -0.0079328884 0.0338007737 -0.011491083999999999 -0.042411347099999996 0.027736422900000002 0.0453303087 -0.07022609490000001 0.0963618709 -0.0200867957 0.0665186088 0.0665174038 0.0665153954 0.0665125838 0.0665089688 0.06650455059999999 0.0 -0.00996895 -0.0313444 -3.00931e-06 0.00132687 -0.000384193 -0.00016819 | ||
6441.5337 6485.7256 9821.212 1.07520139 52.04382706 1.03821933 0.12437666391 -0.0404820317 0.034150583 0.13661184210000002 0.0745358691 -0.0054829985999999995 -0.0217322686 0.046214115199999996 0.005774624 -0.043909359800000006 -0.075619539 0.17546891539999998 -0.0345256763 0.0665153954 0.06650455059999999 0.06648647719999999 0.0664611772 0.0664286533 0.0663889091 0.0 -2.56954e-05 -0.00923735 0.0549667 0.000997278 -0.00019745 -0.000398988 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 6551.281999999999 6476.4653 9874.576 | ||
-0.00996895 -0.0313444 -3.00931e-06 0.00132687 -0.000384193 -0.00016819 6484.7285 6473.4890000000005 9830.212 | ||
-2.56954e-05 -0.00923735 0.0549667 0.000997278 -0.00019745 -0.000398988 6441.5337 6485.7256 9821.212 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
onset duration gain loss RT participant_response | ||
4.071 4 14 6 2.388 weakly_accept | ||
11.834 4 34 14 2.289 strongly_accept | ||
27.535 4 10 15 2.08 strongly_reject | ||
36.435 4 16 17 2.288 weakly_reject |