3
d@'                 @   s   d dl Z d dljZddlmZmZmZmZm	Z	 ddlm
Z
 G dd deZG dd	 d	eZG d
d de
ZG dd deZG dd deZG dd de
ZG dd deZG dd deZG dd de
ZdS )    N   )CommandLineInputSpectraitsTraitedSpecFile	isdefined   )MRTrix3Basec            
   @   s   e Zd Zedddd+ddZeddd,ddZed	ddd-dddZejddddZ	ej
dddZejdddZejdddZejdddZejdddddddd dZedd!d"d#Zedd$d%d#Zej
d&d'dZej
d(d)dZd*S ).BuildConnectomeInputSpecTz%s   zinput tractography)existsargstr	mandatorypositiondescr   zparcellation file)r   r   r   r   zconnectome.csvr   zoutput file after processing)r   r   r   
usedefaultr   z-nthreads %dzEnumber of threads. if zero, the number of available cpus will be used)r   r   nohashz-assignment_voxel_lookupz;use a simple voxel lookup value at each streamline endpoint)r   r   z-assignment_radial_search %fzperform a radial search from each streamline endpoint to locate the nearest node. Argument is the maximum radius in mm; if no node is found within this radius, the streamline endpoint is not assigned to any node.z-assignment_reverse_search %fztraverse from each streamline endpoint inwards along the streamline, in search of the last node traversed by the streamline. Argument is the maximum traversal length in mm (set to 0 to allow search to continue to the streamline midpoint).z-assignment_forward_search %fzproject the streamline forwards from the endpoint in search of aparcellation node voxel. Argument is the maximum traversal length in mm.countZ
meanlengthZ	invlengthZinvnodevolumeZmean_scalarZinvlength_invnodevolumez
-metric %szspecify the edge weight metricz	-image %sz7provide the associated image for the mean_scalar metric)r   r   r   z-tck_weights_in %sz<specify a text scalar file containing the streamline weightsz-keep_unassignedzBy default, the program discards the information regarding those streamlines that are not successfully assigned to a node pair. Set this option to keep these values (will be the first row/column in the output matrix)z-zero_diagonalzwset all diagonal entries in the matrix to zero (these represent streamlines that connect to the same node at both ends)N)__name__
__module____qualname__r   in_fileZin_parcout_filer   IntnthreadsZBoolZ
vox_lookupZFloatZsearch_radiusZsearch_reverseZsearch_forwardEnumZmetricZ	in_scalarZ
in_weightsZkeep_unassignedZzero_diagonal r   r   H/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/mrtrix3/connectivity.pyr
      sb   r
   c               @   s   e Zd ZedddZdS )BuildConnectomeOutputSpecTzthe output response file)r   r   N)r   r   r   r   r   r   r   r   r    r!   _   s   r!   c               @   s$   e Zd ZdZdZeZeZdd Z	dS )BuildConnectomea  
    Generate a connectome matrix from a streamlines file and a node
    parcellation image

    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> mat = mrt.BuildConnectome()
    >>> mat.inputs.in_file = 'tracks.tck'
    >>> mat.inputs.in_parc = 'aparc+aseg.nii'
    >>> mat.cmdline                               # doctest: +ELLIPSIS
    'tck2connectome tracks.tck aparc+aseg.nii connectome.csv'
    >>> mat.run()                                 # doctest: +SKIP
    Ztck2connectomec             C   s"   | j  j }tj| jj|d< |S )Nr   )output_specgetopabspathinputsr   )selfoutputsr   r   r    _list_outputsx   s    zBuildConnectome._list_outputsN)
r   r   r   __doc___cmdr
   
input_specr!   r#   r*   r   r   r   r    r"   c   s
   r"   c               @   s   e Zd ZeddddddZedddddZed	ddddddZedddZedddZedddZ	edddZ
edddZejddddZdS )LabelConfigInputSpecTz%sr   zinput anatomical image)r   r   r   r   r   r   zconnectome configuration file)r   r   r   r   zparcellation.mifr   zoutput file after processing)r   r   r   r   r   z-lut_basic %szJget information from a basic lookup table consisting of index / name pairs)r   r   z-lut_freesurfer %szRget information from a FreeSurfer lookup table(typically "FreeSurferColorLUT.txt")z-lut_aal %szFget information from the AAL lookup table (typically "ROI_MNI_V4.txt")z-lut_itksnap %sz^get information from an ITK - SNAP lookup table(this includes the IIT atlas file "LUT_GM.txt")z	-spine %szprovide a manually-defined segmentation of the base of the spine where the streamlines terminate, so that this can become a node in the connection matrix.z-nthreads %dzEnumber of threads. if zero, the number of available cpus will be used)r   r   r   Nr   r   r   )r   r   r   r   r   	in_configr   Z	lut_basicZlut_fsZlut_aalZlut_itksnapspiner   r   r   r   r   r   r    r.   ~   sD   r.   c               @   s   e Zd ZedddZdS )LabelConfigOutputSpecTzthe output response file)r   r   N)r   r   r   r   r   r   r   r   r    r1      s   r1   c                   s6   e Zd ZdZdZeZeZd fdd	Z	dd Z
  ZS )	LabelConfiga  
    Re-configure parcellation to be incrementally defined.

    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> labels = mrt.LabelConfig()
    >>> labels.inputs.in_file = 'aparc+aseg.nii'
    >>> labels.inputs.in_config = 'mrtrix3_labelconfig.txt'
    >>> labels.cmdline                               # doctest: +ELLIPSIS
    'labelconfig aparc+aseg.nii mrtrix3_labelconfig.txt parcellation.mif'
    >>> labels.run()                                 # doctest: +SKIP
    ZlabelconfigNc                sv   |d krg }t | jjsdddlm} || j}|d krDtjtd}nt	j
t	j
|}t	j|d| j_tt| j|dS )Nr   )find_executablez/opt/mrtrix3z@src/dwi/tractography/connectomics/example_configs/fs_default.txt)skip)r   r'   r/   distutils.spawnr3   r,   osgetenvMRTRIX3_HOMEr%   dirnamejoinsuperr2   _parse_inputs)r(   r4   r3   path)	__class__r   r    r<      s    

zLabelConfig._parse_inputsc             C   s"   | j  j }tj| jj|d< |S )Nr   )r#   r$   r%   r&   r'   r   )r(   r)   r   r   r    r*      s    zLabelConfig._list_outputs)N)r   r   r   r+   r,   r.   r-   r1   r#   r<   r*   __classcell__r   r   )r>   r    r2      s   r2   c               @   sp   e Zd ZeddddddZeddddddZedddd	d
ZedddddddZedddZe	j
ddddZdS )LabelConvertInputSpecTz%s   zinput anatomical image)r   r   r   r   r   r   zJget information from a basic lookup table consisting of index / name pairsr   zconnectome configuration file)r   r   r   r   zparcellation.mifr   zoutput file after processing)r   r   r   r   r   z	-spine %szprovide a manually-defined segmentation of the base of the spine where the streamlines terminate, so that this can become a node in the connection matrix.)r   r   z-nthreads %dzEnumber of threads. if zero, the number of available cpus will be used)r   r   r   Nr   r   r   )r   r   r   r   r   Zin_lutr/   r   r0   r   r   Znum_threadsr   r   r   r    r@      s8   r@   c               @   s   e Zd ZedddZdS )LabelConvertOutputSpecTzthe output response file)r   r   N)r   r   r   r   r   r   r   r   r    rC     s   rC   c                   s6   e Zd ZdZdZeZeZd fdd	Z	dd Z
  ZS )	LabelConverta  
    Re-configure parcellation to be incrementally defined.

    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> labels = mrt.LabelConvert()
    >>> labels.inputs.in_file = 'aparc+aseg.nii'
    >>> labels.inputs.in_config = 'mrtrix3_labelconfig.txt'
    >>> labels.inputs.in_lut = 'FreeSurferColorLUT.txt'
    >>> labels.cmdline
    'labelconvert aparc+aseg.nii FreeSurferColorLUT.txt mrtrix3_labelconfig.txt parcellation.mif'
    >>> labels.run()                                 # doctest: +SKIP
    ZlabelconvertNc                sv   |d krg }t | jjsdddlm} || j}|d krDtjtd}nt	j
t	j
|}t	j|d| j_tt| j|dS )Nr   )whichz/opt/mrtrix3z@src/dwi/tractography/connectomics/example_configs/fs_default.txt)r4   )r   r'   r/   Znipype.utils.filemaniprE   r,   r6   r7   r8   r%   r9   r:   r;   rD   r<   )r(   r4   rE   r=   )r>   r   r    r<   *  s    

zLabelConvert._parse_inputsc             C   s"   | j  j }tj| jj|d< |S )Nr   )r#   r$   r%   r&   r'   r   )r(   r)   r   r   r    r*   >  s    zLabelConvert._list_outputs)N)r   r   r   r+   r,   r@   r-   rC   r#   r<   r*   r?   r   r   )r>   r    rD     s   rD   )r6   os.pathr=   r%   baser   r   r   r   r   r	   r
   r!   r"   r.   r1   r2   r@   rC   rD   r   r   r   r    <module>   s   
S8.)