Skip to content

Commit

Permalink
[PEP8] some linting + including the narps_open/pipelines dir to pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet committed Feb 6, 2024
1 parent 801d996 commit 829f119
Show file tree
Hide file tree
Showing 23 changed files with 214 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: Analyse the code with pylint
run: |
pylint --fail-under 8 --ignore-paths narps_open/pipelines/ narps_open > pylint_report_narps_open.txt
pylint --fail-under 8 narps_open > pylint_report_narps_open.txt
pylint --fail-under 8 tests > pylint_report_tests.txt
- name: Archive pylint results
Expand Down
30 changes: 0 additions & 30 deletions narps_open/pipelines/__main__.py

This file was deleted.

1 change: 1 addition & 0 deletions narps_open/pipelines/team_0I4U_debug.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
from nipype.interfaces.spm import (Coregister, Smooth, OneSampleTTestDesign, EstimateModel, EstimateContrast,
Level1Design, TwoSampleTTestDesign, RealignUnwarp, FieldMap, NewSegment,
Normalize12, Reslice)
Expand Down
1 change: 1 addition & 0 deletions narps_open/pipelines/team_1KB2_debug.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
from nipype.interfaces.fsl import (BET, FAST, MCFLIRT, FLIRT, FNIRT, ApplyWarp, SUSAN,
Info, ImageMaths, IsotropicSmooth, Threshold, Level1Design, FEATModel,
L2Model, Merge, FLAMEO, ContrastMgr,Cluster, FILMGLS, Randomise, MultipleRegressDesign)
Expand Down
1 change: 1 addition & 0 deletions narps_open/pipelines/team_43FJ_debug.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
from nipype.interfaces.fsl import (BET, FAST, MCFLIRT, FLIRT, FNIRT, ApplyWarp, SUSAN, MotionOutliers,
Info, ImageMaths, IsotropicSmooth, Threshold, Level1Design, FEATModel,
L2Model, Merge, FLAMEO, ContrastMgr, FILMGLS, Randomise, MultipleRegressDesign)
Expand Down
1 change: 1 addition & 0 deletions narps_open/pipelines/team_4TQ6_wip.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
from nipype.interfaces.fsl import (BET, ICA_AROMA, FAST, MCFLIRT, FLIRT, FNIRT, ApplyWarp, SUSAN,
Info, ImageMaths, IsotropicSmooth, Threshold, Level1Design, FEATModel,
L2Model, Merge, FLAMEO, ContrastMgr,Cluster, FILMGLS, Randomise, MultipleRegressDesign)
Expand Down
1 change: 1 addition & 0 deletions narps_open/pipelines/team_98BT.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
from nipype.interfaces.spm import (Coregister, Smooth, OneSampleTTestDesign, EstimateModel, EstimateContrast,
Level1Design, TwoSampleTTestDesign, RealignUnwarp, NewSegment, SliceTiming,
DARTEL, DARTELNorm2MNI, FieldMap)
Expand Down
63 changes: 42 additions & 21 deletions narps_open/pipelines/team_Q6O0.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,11 +468,14 @@ def get_subject_level_outputs(self):
)

# Formatting templates and returning it as a list of files
output_files = [contrast_map_template.format(**dict(zip(parameters.keys(), parameter_values)))\
output_files = [
contrast_map_template.format(**dict(zip(parameters.keys(), parameter_values)))\
for parameter_values in parameter_sets]
output_files += [mat_file_template.format(**dict(zip(parameters.keys(), parameter_values)))\
output_files += [
mat_file_template.format(**dict(zip(parameters.keys(), parameter_values)))\
for parameter_values in parameter_sets]
output_files += [spmt_file_template.format(**dict(zip(parameters.keys(), parameter_values)))\
output_files += [
spmt_file_template.format(**dict(zip(parameters.keys(), parameter_values)))\
for parameter_values in parameter_sets]

return output_files
Expand Down Expand Up @@ -698,23 +701,41 @@ def get_hypotheses_outputs(self):
""" Return all hypotheses output file names. """
nb_sub = len(self.subject_list)
files = [
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}', '_model_type_gain', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}', '_model_type_gain', 'spmT_0001.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}', '_model_type_gain', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}', '_model_type_gain', 'spmT_0001.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}', '_model_type_gain', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}', '_model_type_gain', 'spmT_0001.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}', '_model_type_gain', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}', '_model_type_gain', 'spmT_0001.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}', '_model_type_loss', '_threshold1', 'spmT_0002_thr.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}', '_model_type_loss', 'spmT_0002.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}', '_model_type_loss', '_threshold1', 'spmT_0002_thr.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}', '_model_type_loss', 'spmT_0002.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}', '_model_type_loss', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}', '_model_type_loss', 'spmT_0001.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}', '_model_type_loss', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}', '_model_type_loss', 'spmT_0001.nii'),
join(f'l2_analysis_groupComp_nsub_{nb_sub}', '_model_type_loss', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_groupComp_nsub_{nb_sub}', '_model_type_loss', 'spmT_0001.nii')
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}',
'_model_type_gain', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}',
'_model_type_gain', 'spmT_0001.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}',
'_model_type_gain', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}',
'_model_type_gain', 'spmT_0001.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}',
'_model_type_gain', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}',
'_model_type_gain', 'spmT_0001.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}',
'_model_type_gain', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}',
'_model_type_gain', 'spmT_0001.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}',
'_model_type_loss', '_threshold1', 'spmT_0002_thr.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}',
'_model_type_loss', 'spmT_0002.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}',
'_model_type_loss', '_threshold1', 'spmT_0002_thr.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}',
'_model_type_loss', 'spmT_0002.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}',
'_model_type_loss', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalIndifference_nsub_{nb_sub}',
'_model_type_loss', 'spmT_0001.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}',
'_model_type_loss', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_equalRange_nsub_{nb_sub}',
'_model_type_loss', 'spmT_0001.nii'),
join(f'l2_analysis_groupComp_nsub_{nb_sub}',
'_model_type_loss', '_threshold0', 'spmT_0001_thr.nii'),
join(f'l2_analysis_groupComp_nsub_{nb_sub}',
'_model_type_loss', 'spmT_0001.nii')
]
return [join(self.directories.output_dir, f) for f in files]
1 change: 1 addition & 0 deletions narps_open/pipelines/team_R9K3_wip.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
# THIS IS A TEMPLATE THAT CAN BE USE TO REPRODUCE A NEW PIPELINE

import os
Expand Down
1 change: 1 addition & 0 deletions narps_open/pipelines/team_V55J.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
from nipype.interfaces.spm import (Coregister, Smooth, OneSampleTTestDesign, EstimateModel, EstimateContrast,
Level1Design, TwoSampleTTestDesign, RealignUnwarp,
Normalize12, NewSegment, FieldMap)
Expand Down
1 change: 1 addition & 0 deletions narps_open/pipelines/team_X19V.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: skip-file
from nipype.interfaces.fsl import (Info, ImageMaths, IsotropicSmooth, Threshold, Level1Design, FEATModel,
L2Model, Merge, FLAMEO, ContrastMgr, FILMGLS, MultipleRegressDesign, Cluster, BET, SmoothEstimate)
from nipype.algorithms.modelgen import SpecifyModel
Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from os.path import join, isfile
from shutil import rmtree

from numpy import isclose
from pytest import helpers
from pathvalidate import is_valid_filepath

Expand All @@ -23,6 +24,15 @@
# Init configuration, to ensure it is in testing mode
Configuration(config_type='testing')

@helpers.register
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()

@helpers.register
def test_pipeline_outputs(pipeline: Pipeline, number_of_outputs: list):
""" Test the outputs of a Pipeline.
Expand Down
7 changes: 3 additions & 4 deletions tests/core/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def test_remove_file(remove_test_dir):

# Check file is removed
assert not exists(test_file_path)

@staticmethod
@mark.unit_test
def test_remove_directory(remove_test_dir):
Expand Down Expand Up @@ -396,7 +396,7 @@ def test_node_list_to_file_1():

# Check file was created
assert exists(out_file)

# Check file was created
with open(out_file, 'r', encoding = 'utf-8') as file:
for list_element, file_element in zip(out_list, file.read().split('\n')):
Expand Down Expand Up @@ -429,9 +429,8 @@ def test_node_list_to_file_2():

# Check file was created
assert exists(out_file)

# Check file was created
with open(out_file, 'r', encoding = 'utf-8') as file:
for list_element, file_element in zip(out_list, file.read().split('\n')):
assert list_element == file_element

6 changes: 3 additions & 3 deletions tests/data/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"""

from os.path import isdir, join
from shutil import rmtree, move, copytree
from time import sleep
from shutil import rmtree, copytree

from checksumdir import dirhash
from pytest import mark
Expand Down Expand Up @@ -74,7 +73,8 @@ def fake_get_uid(_):

# Mock the results path
results_directory = Configuration()['directories']['narps_results']
Configuration()['directories']['narps_results'] = Configuration()['directories']['test_runs']
Configuration()[
'directories']['narps_results'] = Configuration()['directories']['test_runs']

# Init & download the collection
collection = ResultsCollection('2T6S')
Expand Down
4 changes: 2 additions & 2 deletions tests/data/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from pytest import mark, fixture

from narps_open.utils.configuration import Configuration
import narps_open.data.task as task
from narps_open.data import task

@fixture(scope='function', autouse=True)
def mock_task_data(mocker):
Expand Down Expand Up @@ -50,7 +50,7 @@ def test_singleton():
@mark.unit_test
def test_derived():
""" Test the derived values of a TaskInformation object """

task_info = task.TaskInformation()
assert task_info['NumberOfSlices'] == 6
assert task_info['AcquisitionTime'] == 1 / 6
Expand Down
20 changes: 6 additions & 14 deletions tests/pipelines/test_team_08MQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,11 @@ def test_outputs():
pipeline = PipelineTeam08MQ()
# 1 - 1 subject outputs
pipeline.subject_list = ['001']
assert len(pipeline.get_preprocessing_outputs()) == 4*4
assert len(pipeline.get_run_level_outputs()) == 8+4*3*4
assert len(pipeline.get_subject_level_outputs()) == 4*3
assert len(pipeline.get_group_level_outputs()) == 0
assert len(pipeline.get_hypotheses_outputs()) == 18
helpers.test_pipeline_ouputs(pipeline, [4*4, 8+4*3*4, 4*3, 0, 18])

# 2 - 4 subjects outputs
pipeline.subject_list = ['001', '002', '003', '004']
assert len(pipeline.get_preprocessing_outputs()) == 4*4*4
assert len(pipeline.get_run_level_outputs()) == (8+4*3*4)*4
assert len(pipeline.get_subject_level_outputs()) == 4*3*4
assert len(pipeline.get_group_level_outputs()) == 0
assert len(pipeline.get_hypotheses_outputs()) == 18
helpers.test_pipeline_ouputs(pipeline, [4*4*4, (8+4*3*4)*4, 4*3*4, 0, 18])

@staticmethod
@mark.unit_test
Expand Down Expand Up @@ -130,10 +122,10 @@ def test_two_sample_t_test_regressors():
['002', '004'], # equalIndifference group
['001', '002', '003', '004'] # all subjects
)
assert regressors == dict(
equalRange = [1, 0, 1, 0],
equalIndifference = [0, 1, 0, 1]
)
assert regressors == {
'equalRange' : [1, 0, 1, 0],
'equalIndifference' : [0, 1, 0, 1]
}
assert groups == [1, 2, 1, 2]

@staticmethod
Expand Down
12 changes: 2 additions & 10 deletions tests/pipelines/test_team_2T6S.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,11 @@ def test_outputs():
pipeline = PipelineTeam2T6S()
# 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
helpers.test_pipeline_outputs(pipeline, [0, 0, 7, 63, 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
helpers.test_pipeline_outputs(pipeline, [0, 0, 28, 63, 18])

@staticmethod
@mark.pipeline_test
Expand Down
18 changes: 6 additions & 12 deletions tests/pipelines/test_team_C88N.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,20 @@ def test_outputs():
pipeline = PipelineTeamC88N()
# 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()) == 8
assert len(pipeline.get_group_level_outputs()) == 53
assert len(pipeline.get_hypotheses_outputs()) == 18
helpers.test_pipeline_outputs(pipeline, [0, 0, 8, 53, 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()) == 32
assert len(pipeline.get_group_level_outputs()) == 53
assert len(pipeline.get_hypotheses_outputs()) == 18
helpers.test_pipeline_outputs(pipeline, [0, 0, 32, 53, 18])

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

# Test with 'gain'
test_event_file = join(Configuration()['directories']['test_data'], 'pipelines', 'events.tsv')
test_event_file = join(
Configuration()['directories']['test_data'], 'pipelines', 'events.tsv')
information = PipelineTeamC88N.get_subject_information(
[test_event_file, test_event_file],
'gain'
Expand Down Expand Up @@ -103,7 +96,8 @@ def test_subject_information():
assert isclose(reference_array, test_array).all()

# Test with 'loss'
test_event_file = join(Configuration()['directories']['test_data'], 'pipelines', 'events.tsv')
test_event_file = join(
Configuration()['directories']['test_data'], 'pipelines', 'events.tsv')
information = PipelineTeamC88N.get_subject_information(
[test_event_file, test_event_file],
'loss'
Expand Down
Loading

0 comments on commit 829f119

Please sign in to comment.