diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 547551b1..f03f7016 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,7 +7,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 21.12b0 + rev: 22.3.0 hooks: - id: black exclude: ^(fitlins/_version.py|versioneer.py) @@ -18,7 +18,7 @@ repos: name: Sort python imports (isort) args: ["--profile", "black", "--filter-files"] - repo: https://github.com/asottile/pyupgrade - rev: v2.31.0 + rev: v2.31.1 hooks: - id: pyupgrade exclude: ^(fitlins/_version.py|versioneer.py) diff --git a/fitlins/data/fitlins.json b/fitlins/data/fitlins.json index 529c8f84..f661f1c8 100644 --- a/fitlins/data/fitlins.json +++ b/fitlins/data/fitlins.json @@ -13,6 +13,10 @@ "name": "name", "pattern": "[_/\\\\]name-([a-zA-Z0-9]+)" + }, + { + "name": "node", + "pattern": "[_/\\\\]node-([a-zA-Z0-9]+)" } ] } diff --git a/fitlins/interfaces/bids.py b/fitlins/interfaces/bids.py index 3a840127..88841298 100644 --- a/fitlins/interfaces/bids.py +++ b/fitlins/interfaces/bids.py @@ -2,28 +2,26 @@ import os import re import shutil - -import numpy as np -import nibabel as nb - +from gzip import GzipFile from itertools import chain from pathlib import Path -from gzip import GzipFile +import nibabel as nb +import numpy as np from nipype import logging -from nipype.utils.filemanip import copyfile from nipype.interfaces.base import ( BaseInterfaceInputSpec, - TraitedSpec, - SimpleInterface, + Directory, + File, InputMultiPath, OutputMultiPath, - File, - Directory, - traits, + SimpleInterface, + TraitedSpec, isdefined, + traits, ) from nipype.interfaces.io import IOBase +from nipype.utils.filemanip import copyfile from ..utils import snake_to_camel, to_alphanum @@ -238,8 +236,8 @@ class LoadBIDSModel(SimpleInterface): output_spec = LoadBIDSModelOutputSpec def _run_interface(self, runtime): - from bids.modeling import BIDSStatsModelsGraph from bids.layout import BIDSLayout + from bids.modeling import BIDSStatsModelsGraph layout = BIDSLayout.load(database_path=self.inputs.database_path) selectors = self.inputs.selectors @@ -480,7 +478,7 @@ def _list_outputs(self): # format (eg: gain.Range, gain.EqualIndifference). # This prevents issues when creating/searching files for the report for k, v in ents.items(): - if k in ("name", "contrast", "stat"): + if k in ("node", "name", "contrast", "stat"): ents.update({k: to_alphanum(str(v))}) out_fname = os.path.join( diff --git a/fitlins/workflows/base.py b/fitlins/workflows/base.py index 82c9423a..0ab91fef 100644 --- a/fitlins/workflows/base.py +++ b/fitlins/workflows/base.py @@ -1,5 +1,4 @@ import warnings - from collections import OrderedDict from pathlib import Path @@ -21,17 +20,23 @@ def init_fitlins_wf( base_dir=None, name='fitlins_wf', ): - from nipype.pipeline import engine as pe from nipype.interfaces import utility as niu - from ..interfaces.bids import ModelSpecLoader, LoadBIDSModel, BIDSSelect, BIDSDataSink + from nipype.pipeline import engine as pe + + from ..interfaces.bids import ( + BIDSDataSink, + BIDSSelect, + LoadBIDSModel, + ModelSpecLoader, + ) from ..interfaces.nistats import DesignMatrix, SecondLevelModel + from ..interfaces.utils import CollateWithMetadata, MergeAll from ..interfaces.visualizations import ( - DesignPlot, - DesignCorrelationPlot, ContrastMatrixPlot, + DesignCorrelationPlot, + DesignPlot, GlassBrainPlot, ) - from ..interfaces.utils import MergeAll, CollateWithMetadata from ..utils import snake_to_camel if estimator == 'afni': @@ -121,6 +126,7 @@ def init_fitlins_wf( def _deindex(tsv): from pathlib import Path + import pandas as pd out_tsv = str(Path.cwd() / Path(tsv).name) @@ -133,33 +139,33 @@ def _deindex(tsv): # Set up common patterns image_pattern = ( - "reports/[sub-{subject}/][ses-{session}/]figures/[run-{run}/]" + "reports/[node-{node}/][sub-{subject}/][ses-{session}/]figures/[run-{run}/]" "[level-{level}_][name-{name}_][sub-{subject}_][ses-{session}_][task-{task}_]" "[acq-{acquisition}_][rec-{reconstruction}_][run-{run}_][echo-{echo}_]" "{suffix}{extension<.svg>|.svg}" ) contrast_plot_pattern = ( - "reports/[sub-{subject}/][ses-{session}/]figures/[run-{run}/]" + "reports/[node-{node}/][sub-{subject}/][ses-{session}/]figures/[run-{run}/]" "[level-{level}_][name-{name}_][sub-{subject}_][ses-{session}_][task-{task}_]" "[acq-{acquisition}_][rec-{reconstruction}_][run-{run}_][echo-{echo}_][space-{space}_]" "contrast-{contrast}_stat-{stat}_ortho{extension<.png>|.png}" ) design_matrix_pattern = ( - "[sub-{subject}/][ses-{session}/]" + "[node-{node}/][sub-{subject}/][ses-{session}/]" "[level-{level}_][name-{name}_][sub-{subject}_][ses-{session}_][task-{task}_]" "[acq-{acquisition}_][rec-{reconstruction}_][run-{run}_][echo-{echo}_]" "{suffix}{extension<.tsv>|.tsv}" ) contrast_pattern = ( - "[sub-{subject}/][ses-{session}/]" + "[node-{node}/][sub-{subject}/][ses-{session}/]" "[level-{level}_][name-{name}_][sub-{subject}_][ses-{session}_][task-{task}_]" "[acq-{acquisition}_][rec-{reconstruction}_][run-{run}_][echo-{echo}_][space-{space}_]" "contrast-{contrast}_stat-{stat}_" "statmap{extension<.nii.gz|.dscalar.nii>}" ) model_map_pattern = ( - "[sub-{subject}/][ses-{session}/]" + "[node-{node}/][sub-{subject}/][ses-{session}/]" "[level-{level}_][name-{name}_][sub-{subject}_][ses-{session}_][task-{task}_]" "[acq-{acquisition}_][rec-{reconstruction}_][run-{run}_][echo-{echo}_][space-{space}_]" "stat-{stat