Skip to content

Commit

Permalink
80GC refac + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bclenet committed Mar 27, 2024
1 parent 7209739 commit 46bb1b3
Show file tree
Hide file tree
Showing 5 changed files with 2,789 additions and 0 deletions.
File renamed without changes.
169 changes: 169 additions & 0 deletions narps_open/core/interfaces/afni.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#!/usr/bin/python
# coding: utf-8

""" AFNI interfaces for Nipype """

from nipype.interfaces.base import traits, File, Str, InputMultiPath
from nipype.interfaces.afni.base import (
AFNICommand,
AFNICommandInputSpec,
AFNICommandOutputSpec
)

class TtestppInputSpec(AFNICommandInputSpec):
""" The input specification of the 3dttest++ interface """

set_a_label = Str(
desc='label for setA',
argstr='-labelA %s ',
mandatory=True
)
set_a = InputMultiPath(
traits.Tuple(
File(desc='3D dataset', exists=True),
traits.Int(desc='Index of the data in the dataset'),
),
desc='specifies a set of input datasets for setA + their label.',
argstr='-setA %s ', # Data tuples will be formatted in the _format_arg method
requires=['set_a_label'],
mandatory=True
)
set_b_label = Str(
desc='label for setB',
argstr='-labelB %s ',
)
set_b = InputMultiPath(
traits.Tuple(
File(desc='3D dataset', exists=True),
traits.Int(desc='Index of the data in the dataset'),
),
desc='specifies a set of input datasets for setB + their label.',
argstr='-setB %s ', # Data tuples will be formatted in the _format_arg method
requires=['set_b_label'],
)
set_a_weight = File(
desc='Name of a file with the weights for the -setA datasets.',
argstr='-setweightA %s ',
requires=['set_a'],
exists=True,
)
set_b_weight = File(
desc='Name of a file with the weights for the -setB datasets.',
argstr='-setweightB %s ',
requires=['set_b'],
exists=True,
)
covariates = File(
desc='name of a text file with a table for the covariate(s).'
' Each column in the file is treated as a separate covariate, and each'
' row contains the values of these covariates for one sample (dataset).',
argstr='-covariates %s ',
exists=True,
)
center = traits.Enum('NONE', 'DIFF', 'SAME',
desc='how the mean across subjects of a covariate will be processed.',
argstr='-center %s ',
requires=['covariates'],
)
paired = traits.Bool(
desc='specifies the use of a paired-sample t-test to compare setA and setB.',
argstr='-paired ',
requires=['set_a', 'set_b'],
)
unpooled = traits.Bool(
desc='specifies that the variance estimates for setA and setB be computed '
'separately (not pooled together).',
argstr='-paired ',
requires=['set_a', 'set_b'],
xor=['paired', 'covariates']
)
toz = traits.Bool(
desc='convert output t-statistics to z-scores.',
argstr='-toz ',
)
rankize = traits.Bool(
desc='convert the data (and covariates, if any) into ranks before '
'doing the 2-sample analyses.',
argstr='-rankize ',
)
no1sam = traits.Bool(
desc='do not calculate 1-sample test results when '
'doing 2-sample analyses.',
argstr='-no1sam ',
)
nomeans = traits.Bool(
desc='turn off output of the `mean` sub-bricks.',
argstr='-nomeans ',
)
notests = traits.Bool(
desc='turn off output of the `test` sub-bricks.',
argstr='-notests ',
)
mask = File(
desc='Only compute results for voxels in the specified mask.',
argstr='-mask %s ',
exists=True,
)
exblur = traits.Float(
desc='Before doing the t-test, apply some extra blurring to the input datasets; '
"parameter 'b' is the Gaussian FWHM of the smoothing kernel (in mm).",
argstr='-exblur %d ',
)
brickwise = traits.Bool(
desc='carry out t-tests sub-brick by sub-brick',
argstr='-brickwise ',
position=0
)
out_file = Str(
desc='the name of the output dataset file.',
argstr='-prefix %s ',
position=-1
)
out_residuals = Str(
desc='output the residuals into a dataset with given prefix.',
argstr='-resid %s ',
position=-2
)
clustsim = traits.Bool(
desc='run the cluster-size threshold simulation program 3dClustSim.',
argstr='-Clustsim ',
position=-4
)
seed = traits.Tuple(
traits.Int, traits.Int,
desc='This option is used to set the random number seed for'
'`-randomsign` to the first positive integer. If a second integer'
'follows, then that value is used for the random number seed for `-permute`.',
argstr='-seed %d %d ',
requires=['clustsim'],
position=-3
)

class TtestppOutputSpec(AFNICommandOutputSpec):
""" The output specification of the 3dttest++ interface """
out_file = File(desc='output dataset', exists=True)

class Ttestpp(AFNICommand):
""" Gosset (Student) t-test of sets of 3D datasets.
For complete details, see the `3dttest++ Documentation.
<https://afni.nimh.nih.gov/pub/dist/doc/program_help/3dttest++.html>`_
"""

_cmd = "3dttest++"
input_spec = TtestppInputSpec
output_spec = TtestppOutputSpec

def _format_arg(self, name, trait_spec, value):
""" Format arguments before actually building the command line """
out_value = value

# For arguments -setA and -setB, we want a list such as :
# dataset1'[index]' dataset2'[index]' dataset3'[index]' ...
if name in ['set_a', 'set_b']:
out_value = ''
for set_tuple in value:
out_value += f'{set_tuple[0]}\'[{set_tuple[1]}]\' '
out_value = [out_value] # Return a list as the input value

return super()._format_arg(name, trait_spec, out_value)
Loading

0 comments on commit 46bb1b3

Please sign in to comment.