Skip to content

Commit 695668a

Browse files
authored
Adding participants exclusions in narps_open_runner (#194)
* Adding a command line tool showing the correlation results of a pipeline execution * [DOC] install doc about correlation command line tool [skip ci] * Modifications on runner * Correlation main + exclusions in runner
1 parent 1ae9ce1 commit 695668a

File tree

6 files changed

+84
-10
lines changed

6 files changed

+84
-10
lines changed

INSTALL.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ Finally, you are able to use the scripts of the project :
9595

9696
* `narps_open_runner`: run pipelines
9797
* `narps_open_tester`: run a pipeline and test its results against original ones from the team
98+
* `narps_open_correlations`: compute and display correlation between results and original ones from the team
9899
* `narps_description`: get the textual description made by a team
99100
* `narps_results`: download the original results from teams
100101
* `narps_open_status`: get status information about the development process of the pipelines
@@ -107,6 +108,10 @@ narps_open_runner -t 2T6S -n 40
107108
# and produces a report with correlation values.
108109
narps_open_tester -t 08MQ
109110

111+
# Compute the correlation values between results of 2T6S reproduction on 60 subjects with original ones
112+
# WARNING : 2T6S must have been previously computed with a group of 60 subjects
113+
narps_open_correlations -t 2T6S -n 60
114+
110115
# Get the description of team C88N in markdown formatting
111116
narps_description -t C88N --md
112117

@@ -121,6 +126,7 @@ narps_open_status --json
121126
> For further information about these command line tools, read the corresponding documentation pages.
122127
> * `narps_open_runner` : [docs/running.md](docs/running.md)
123128
> * `narps_open_tester` : [docs/testing.md](docs/testing.md#command-line-tool)
129+
> * `narps_open_correlations` : [docs/correlation.md](docs/correlation.md#command-line-tool)
124130
> * `narps_description` : [docs/description.md](docs/description.md)
125131
> * `narps_results` : [docs/data.md](docs/data.md#results-from-narps-teams)
126132
> * `narps_open_status` : [docs/status.md](docs/status.md)

narps_open/runner.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,15 @@ def main():
178178
help='run the first levels only (preprocessing + subjects + runs)')
179179
parser.add_argument('-c', '--check', action='store_true', required=False,
180180
help='check pipeline outputs (runner is not launched)')
181+
parser.add_argument('-e', '--exclusions', action='store_true', required=False,
182+
help='run the analyses without the excluded subjects')
181183
arguments = parser.parse_args()
182184

185+
# Check arguments
186+
if arguments.exclusions and not arguments.nsubjects:
187+
print('Argument -e/--exclusions only works with -n/--nsubjects')
188+
return
189+
183190
# Initialize a PipelineRunner
184191
runner = PipelineRunner(team_id = arguments.team)
185192
runner.pipeline.directories.dataset_dir = Configuration()['directories']['dataset']
@@ -193,7 +200,14 @@ def main():
193200
elif arguments.rsubjects is not None:
194201
runner.random_nb_subjects = int(arguments.rsubjects)
195202
else:
196-
runner.nb_subjects = int(arguments.nsubjects)
203+
if arguments.exclusions:
204+
# Intersection between the requested subset and the list of not excluded subjects
205+
runner.subjects = list(
206+
set(get_participants_subset(int(arguments.nsubjects)))
207+
& set(get_participants(arguments.team))
208+
)
209+
else:
210+
runner.nb_subjects = int(arguments.nsubjects)
197211

198212
# Check data
199213
if arguments.check:
File renamed without changes.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/python
2+
# coding: utf-8
3+
4+
""" A command line tool for the narps_open.utils.correlation module """
5+
6+
from os.path import join
7+
from argparse import ArgumentParser
8+
9+
from narps_open.data.results import ResultsCollection
10+
from narps_open.utils.configuration import Configuration
11+
from narps_open.utils.correlation import get_correlation_coefficient
12+
from narps_open.pipelines import get_implemented_pipelines
13+
from narps_open.runner import PipelineRunner
14+
15+
def main():
16+
""" Entry-point for the command line tool narps_open_correlations """
17+
18+
# Parse arguments
19+
parser = ArgumentParser(description = 'Compare reproduced files to original results.')
20+
parser.add_argument('-t', '--team', type = str, required = True,
21+
help = 'the team ID', choices = get_implemented_pipelines())
22+
subjects.add_argument('-n', '--nsubjects', type=str, required = True,
23+
help='the number of subjects to be selected')
24+
arguments = parser.parse_args()
25+
26+
# Initialize pipeline
27+
runner = PipelineRunner(arguments.team)
28+
runner.pipeline.directories.dataset_dir = Configuration()['directories']['dataset']
29+
runner.pipeline.directories.results_dir = Configuration()['directories']['reproduced_results']
30+
runner.pipeline.directories.set_output_dir_with_team_id(arguments.team)
31+
runner.pipeline.directories.set_working_dir_with_team_id(arguments.team)
32+
runner.nb_subjects = arguments.nsubjects
33+
34+
# Indices and keys to the unthresholded maps
35+
indices = list(range(1, 18, 2))
36+
37+
# Retrieve the paths to the reproduced files
38+
reproduced_files = runner.pipeline.get_hypotheses_outputs()
39+
reproduced_files = [reproduced_files[i] for i in indices]
40+
41+
# Retrieve the paths to the results files
42+
collection = ResultsCollection(arguments.team)
43+
file_keys = [f'hypo{h}_unthresh.nii.gz' for h in range(1,10)]
44+
results_files = [join(collection.directory, k) for k in file_keys]
45+
46+
# Compute the correlation coefficients
47+
print([
48+
get_correlation_coefficient(reproduced_file, results_file)
49+
for reproduced_file, results_file in zip(reproduced_files, results_files)
50+
])
51+
52+
if __name__ == '__main__':
53+
main()

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
'narps_open_runner = narps_open.runner:main',
7272
'narps_open_tester = narps_open.tester:main',
7373
'narps_open_status = narps_open.utils.status:main',
74+
'narps_open_correlations = narps_open.utils.correlation.__main__:main',
7475
'narps_description = narps_open.data.description.__main__:main',
7576
'narps_results = narps_open.data.results.__main__:main'
7677
]

tests/conftest.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from narps_open.utils.correlation import get_correlation_coefficient
2323
from narps_open.utils.configuration import Configuration
2424
from narps_open.data.results import ResultsCollection
25+
from narps_open.data.participants import get_participants_subset
2526

2627
# Init configuration, to ensure it is in testing mode
2728
Configuration(config_type='testing')
@@ -88,13 +89,12 @@ def test_pipeline_execution(
8889
TODO : how to keep intermediate files of the low level for the next numbers of subjects ?
8990
- keep intermediate levels : boolean in PipelineRunner
9091
"""
91-
# A list of number of subject to iterate over
92-
nb_subjects_list = list(range(
93-
Configuration()['testing']['pipelines']['nb_subjects_per_group'],
94-
nb_subjects,
95-
Configuration()['testing']['pipelines']['nb_subjects_per_group'])
96-
)
97-
nb_subjects_list.append(nb_subjects)
92+
# Create subdivisions of the requested subject list
93+
nb_subjects_per_group = Configuration()['testing']['pipelines']['nb_subjects_per_group']
94+
all_subjects = get_participants_subset(nb_subjects)
95+
subjects_lists = []
96+
for index in range(0, len(all_subjects), nb_subjects_per_group):
97+
subjects_lists.append(all_subjects[index:index+nb_subjects_per_group])
9898

9999
# Initialize the pipeline
100100
runner = PipelineRunner(team_id)
@@ -104,8 +104,8 @@ def test_pipeline_execution(
104104
runner.pipeline.directories.set_working_dir_with_team_id(team_id)
105105

106106
# Run first level by (small) sub-groups of subjects
107-
for subjects in nb_subjects_list:
108-
runner.nb_subjects = subjects
107+
for subjects_list in subjects_lists:
108+
runner.subjects = subjects_list
109109

110110
# Run as long as there are missing files after first level (with a max number of trials)
111111
# TODO : this is a workaround

0 commit comments

Comments
 (0)