3
Yd>                 @   s"  d dl Z d dljZddlmZ ddlmZmZm	Z	m
Z
mZ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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   )split_filename   )CommandLineInputSpecCommandLinetraitsTraitedSpecFile	isdefinedc               @   s   e Zd Zedddd)ddZddgZeddd	ed
Zejej	ddddddded	Z
ddgZeddded
Zejej	ddddddded	Zej	ddddZedd*ddgdddZejddd Zejd!d"d Zejd#dd$d%Zejd&dd'd%Zd(S )+FilterTracksInputSpecTz%sr   zinput tracks to be filtered)existsargstr	mandatorypositiondescinclude_fileinclude_specz-include %szinclusion file)r   r   r   xorz2inclusion specification in mm and radius (x y z r)   ,mm)r   r   r   minlenmaxlensepunitsr   exclude_fileexclude_specz-exclude %szexclusion filez2exclusion specification in mm and radius (x y z r)z-minlength %szGSets the minimum length of any track in millimeters (default is 10 mm).)r   r   r      zOutput filtered track filenamein_fileFz%s_filt)r   r   r   name_sourceZ
hash_filesname_templatez-nomaskinterpz1Turns off trilinear interpolation of mask images.)r   r   z-invertzsinvert the matching process, so that tracks that wouldotherwise have been included are now excluded and vice-versa.z-quietz7Do not display information messages or progress status.)r   r   r   z-debugzDisplay debugging messages.N)__name__
__module____qualname__r	   r   include_xorr   r   ListFloatr   exclude_xorr   r   minimum_tract_lengthout_fileBoolno_mask_interpolationinvertquietdebug r1   r1   S/var/www/html/virt/lib/python3.6/site-packages/nipype/interfaces/mrtrix/tracking.pyr      sj   
r   c               @   s   e Zd ZedddZdS )FilterTracksOutputSpecTzthe output filtered tracks)r   r   N)r#   r$   r%   r	   r+   r1   r1   r1   r2   r3   [   s   r3   c               @   s   e Zd ZdZdZeZeZdS )FilterTracksa<  
    Use regions-of-interest to select a subset of tracks
    from a given MRtrix track file.

    Example
    -------

    >>> import nipype.interfaces.mrtrix as mrt
    >>> filt = mrt.FilterTracks()
    >>> filt.inputs.in_file = 'tracks.tck'
    >>> filt.run()                                 # doctest: +SKIP
    Zfilter_tracksN)	r#   r$   r%   __doc___cmdr   
input_specr3   output_specr1   r1   r1   r2   r4   _   s   r4   c               @   s   e Zd Zedddd&ddZeddddd	Zejejd
ddddddZ	ej
ddddZej
ddddZejdddddddddddddZejddd d!d"Zeddd'd#d$Zd%S )(Tracks2ProbInputSpecTz%sr   z
tract file)r   r   r   r   r   z-template %sr   zvan image file to be used as a template for the output (the output image wil have the same transform and field of view))r   r   r   r   z-vox %sr   r   zBThree comma-separated numbers giving the size of each voxel in mm.)r   r   r   r   r   r   z-colourzHadd colour to the output image according to the direction of the tracks.)r   r   r   z	-fractionzproduce an image of the fraction of fibres through each voxel (as a proportion of the total number in the file), rather than the count.ZBitZInt8ZUInt8ZInt16ZUInt16ZInt32ZUInt32Zfloat32Zfloat64z-datatype %szI"i.e. Bfloat". Can be "char", "short", "int", "long", "float" or "double"z-resample %dr   zresample the tracks at regular intervals using Hermite interpolation. If omitted, the program will select an appropriate interpolation factor automatically.)r   r   r   r   zoutput data file)Zgenfiler   r   r   Nr!   r"   )r#   r$   r%   r	   r   Ztemplate_filer   r'   r(   Z
voxel_dimsr,   ZcolourfractionEnumZoutput_datatypeZresampleout_filenamer1   r1   r1   r2   r9   r   sT   r9   c               @   s   e Zd ZedddZdS )Tracks2ProbOutputSpecTz)Output tract count or track density image)r   r   N)r#   r$   r%   r	   tract_imager1   r1   r1   r2   r=      s   r=   c               @   s4   e Zd ZdZdZeZeZdd Z	dd Z
dd Zd	S )
Tracks2Proba  
    Convert a tract file into a map of the fraction of tracks to enter
    each voxel - also known as a tract density image (TDI) - in MRtrix's
    image format (.mif). This can be viewed using MRview or converted to
    Nifti using MRconvert.

    Example
    -------

    >>> import nipype.interfaces.mrtrix as mrt
    >>> tdi = mrt.Tracks2Prob()
    >>> tdi.inputs.in_file = 'dwi_CSD_tracked.tck'
    >>> tdi.inputs.colour = True
    >>> tdi.run()                                       # doctest: +SKIP
    Ztracks2probc             C   sP   | j  j }| jj|d< t|d s8tj| j |d< ntj	j|d |d< |S )Nr>   )
r8   getinputsr<   r
   opabspath_gen_outfilenameospath)selfoutputsr1   r1   r2   _list_outputs   s    zTracks2Prob._list_outputsc             C   s   |dkr| j  S d S d S )Nr<   )rD   )rG   namer1   r1   r2   _gen_filename   s    zTracks2Prob._gen_filenamec             C   s   t | jj\}}}|d S )Nz_TDI.mif)r   rA   r   )rG   _rJ   r1   r1   r2   rD      s    zTracks2Prob._gen_outfilenameN)r#   r$   r%   r5   r6   r9   r7   r=   r8   rI   rK   rD   r1   r1   r1   r2   r?      s   	r?   c               @   s  e Zd ZeddddKddZddgZeddd	ed
Zejej	ddddddded	Z
ddgZeddded
Zejej	ddddddded	ZddgZeddded
Zejej	ddddddded	ZddgZeddded
Zejej	ddddddded	Zejdd d!dd"ddLd$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/d0Zej	d1dd2d0Zejd3d4d'Zejd5d6d'Zej	d7dd8d0Z ej	d9dd:d0Z!ej	d;d<d=d0Z"ej	d>d<d?d0Z#ejejd@dAdddBdCZ$eddMdEgdFdGdHdIZ%dJS )NStreamlineTrackInputSpecTz%sr   zthe image containing the source data.The type of data required depends on the type of tracking as set in the preceeding argument. For DT methods, the base DWI are needed. For SD methods, the SH harmonic coefficients of the FOD are needed.)r   r   r   r   r   	seed_file	seed_specz-seed %sz	seed file)r   r   r   r   z-seed specification in mm and radius (x y z r)r   r   r   )r   r   r   r   r   r   r   r   r   r   z-include %szinclusion filez2inclusion specification in mm and radius (x y z r)r   r   z-exclude %szexclusion filez2exclusion specification in mm and radius (x y z r)	mask_file	mask_specz-mask %sz#mask file. Only tracks within mask.zaMask specification in mm and radius (x y z r). Tracks will be terminated when they leave the ROI.	DT_STREAMSD_PROB	SD_STREAMzinput model typer   )r   r   Z
usedefaultr   z-stopz;stop track as soon as it enters any of the include regions.)r   r   z-noprecomputedzTurns off precomputation of the legendre polynomial values. Warning: this will slow down the algorithm by a factor of approximately 4.z-unidirectionalzYTrack from the seed point in one direction only (default is to track in both directions).z-nomaskinterpz1Turns off trilinear interpolation of mask images.z-step %sz:Set the step size of the algorithm in mm (default is 0.2).)r   r   r   z-curvature %szrSet the minimum radius of curvature (default is 2 mm for DT_STREAM, 0 for SD_STREAM, 1 mm for SD_PROB and DT_PROB)z
-number %dzSets the desired number of tracks.The program will continue to generate tracks until this number of tracks have been selected and written to the output file(default is 100 for ``*_STREAM`` methods, 1000 for ``*_PROB`` methods).z
-maxnum %dzSets the maximum number of tracks to generate.The program will not generate more tracks than this number, even if the desired number of tracks hasn't yet been reached(default is 100 x number).z-minlength %szGSets the minimum length of any track in millimeters (default is 10 mm).z
-length %szHSets the maximum length of any track in millimeters (default is 200 mm).z
-cutoff %sZNAzKSet the FA or FOD amplitude cutoff for terminating tracks (default is 0.1).z-initcutoff %sz`Sets the minimum FA or FOD amplitude for initiating tracks (default is twice the normal cutoff).z2Specify the initial tracking direction as a vectorz-initdirection %sZvoxels)r   r   r   r   r   r   r   z%s_tracked.tcktrackedzoutput data file)r   r   r   r    Zoutput_namer   Nr!   r"   )&r#   r$   r%   r	   r   Zseed_xorrN   r   r'   r(   rO   r&   r   r   r)   r   r   Zmask_xorrP   rQ   r;   
inputmodelr,   stopZdo_not_precomputeZunidirectionalr-   Z	step_sizeZminimum_radius_of_curvatureIntZdesired_number_of_tracksZmaximum_number_of_tracksr*   Zmaximum_tract_lengthZcutoff_valueZinitial_cutoff_valueZinitial_directionr+   r1   r1   r1   r2   rM      s   
rM   c               @   s   e Zd ZedddZdS )StreamlineTrackOutputSpecTz+output file containing reconstructed tracts)r   r   N)r#   r$   r%   r	   rU   r1   r1   r1   r2   rZ   x  s   rZ   c               @   s   e Zd ZdZdZeZeZdS )StreamlineTracka  
    Performs tractography using one of the following models:
    'dt_prob', 'dt_stream', 'sd_prob', 'sd_stream',
    Where 'dt' stands for diffusion tensor, 'sd' stands for spherical
    deconvolution, and 'prob' stands for probabilistic.

    Example
    -------

    >>> import nipype.interfaces.mrtrix as mrt
    >>> strack = mrt.StreamlineTrack()
    >>> strack.inputs.inputmodel = 'SD_PROB'
    >>> strack.inputs.in_file = 'data.Bfloat'
    >>> strack.inputs.seed_file = 'seed_mask.nii'
    >>> strack.inputs.mask_file = 'mask.nii'
    >>> strack.cmdline
    'streamtrack -mask mask.nii -seed seed_mask.nii SD_PROB data.Bfloat data_tracked.tck'
    >>> strack.run()                                    # doctest: +SKIP
    ZstreamtrackN)	r#   r$   r%   r5   r6   rM   r7   rZ   r8   r1   r1   r1   r2   r[   |  s   r[   c               @   s   e Zd ZeddddddZdS )'DiffusionTensorStreamlineTrackInputSpecTz-grad %sr   zGradient encoding, supplied as a 4xN text file with each line is in the format [ X Y Z b ], where [ X Y Z ] describe the direction of the applied gradient, and b gives the b-value in units (1000 s/mm^2). See FSL2MRTrix)r   r   r   r   r   Nr!   )r#   r$   r%   r	   Zgradient_encoding_filer1   r1   r1   r2   r\     s   r\   c                   s&   e Zd ZdZeZd fdd	Z  ZS )DiffusionTensorStreamlineTracka  
    Specialized interface to StreamlineTrack. This interface is used for
    streamline tracking from diffusion tensor data, and calls the MRtrix
    function 'streamtrack' with the option 'DT_STREAM'

    Example
    -------

    >>> import nipype.interfaces.mrtrix as mrt
    >>> dtstrack = mrt.DiffusionTensorStreamlineTrack()
    >>> dtstrack.inputs.in_file = 'data.Bfloat'
    >>> dtstrack.inputs.seed_file = 'seed_mask.nii'
    >>> dtstrack.run()                                  # doctest: +SKIP
    Nc                s   d|d< t t| j|f|S )NrR   rW   )superr]   __init__)rG   commandrA   )	__class__r1   r2   r_     s    z'DiffusionTensorStreamlineTrack.__init__)N)r#   r$   r%   r5   r\   r7   r_   __classcell__r1   r1   )ra   r2   r]     s   r]   c               @   s   e Zd ZejdddZdS )<ProbabilisticSphericallyDeconvolutedStreamlineTrackInputSpecz
-trials %sz_Set the maximum number of sampling trials at each point (only used for probabilistic tracking).)r   r   N)r#   r$   r%   r   rY   Zmaximum_number_of_trialsr1   r1   r1   r2   rc     s   rc   c                   s&   e Zd ZdZeZd fdd	Z  ZS )3ProbabilisticSphericallyDeconvolutedStreamlineTracka  
    Performs probabilistic tracking using spherically deconvolved data

    Specialized interface to StreamlineTrack. This interface is used for
    probabilistic tracking from spherically deconvolved data, and calls
    the MRtrix function 'streamtrack' with the option 'SD_PROB'

    Example
    -------

    >>> import nipype.interfaces.mrtrix as mrt
    >>> sdprobtrack = mrt.ProbabilisticSphericallyDeconvolutedStreamlineTrack()
    >>> sdprobtrack.inputs.in_file = 'data.Bfloat'
    >>> sdprobtrack.inputs.seed_file = 'seed_mask.nii'
    >>> sdprobtrack.run()                                                       # doctest: +SKIP
    Nc                s   d|d< t t| j|f|S )NrS   rW   )r^   rd   r_   )rG   r`   rA   )ra   r1   r2   r_     s    z<ProbabilisticSphericallyDeconvolutedStreamlineTrack.__init__)N)r#   r$   r%   r5   rc   r7   r_   rb   r1   r1   )ra   r2   rd     s   rd   c                   s&   e Zd ZdZeZd fdd	Z  ZS )&SphericallyDeconvolutedStreamlineTrackaT  
    Performs streamline tracking using spherically deconvolved data

    Specialized interface to StreamlineTrack. This interface is used for
    streamline tracking from spherically deconvolved data, and calls
    the MRtrix function 'streamtrack' with the option 'SD_STREAM'

    Example
    -------

    >>> import nipype.interfaces.mrtrix as mrt
    >>> sdtrack = mrt.SphericallyDeconvolutedStreamlineTrack()
    >>> sdtrack.inputs.in_file = 'data.Bfloat'
    >>> sdtrack.inputs.seed_file = 'seed_mask.nii'
    >>> sdtrack.run()                                          # doctest: +SKIP
    Nc                s   d|d< t t| j|f|S )NrT   rW   )r^   re   r_   )rG   r`   rA   )ra   r1   r2   r_     s    
z/SphericallyDeconvolutedStreamlineTrack.__init__)N)r#   r$   r%   r5   rM   r7   r_   rb   r1   r1   )ra   r2   re     s   re   )rE   os.pathrF   rB   Zutils.filemanipr   baser   r   r   r   r	   r
   r   r3   r4   r9   r=   r?   rM   rZ   r[   r\   r]   rc   rd   re   r1   r1   r1   r2   <module>   s&   
 
H4) &

