3
d7/                 @   sb   d dl jZddlmZmZmZ ddlmZmZ G dd deZ	G dd	 d	eZ
G d
d deZdS )    N   )traitsTraitedSpecFile   )MRTrix3BaseInputSpecMRTrix3Basec               @   s  e Zd ZejejejejejddZeddddgddZeddddhdd
dZ	ej
ddddddddddd
ZejeddedddZejeddedddZejedde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ejd)d*dZejd+d,dZejd-d.dZejd/d0dZejd1d2dZejd3d4dZejd5d6dZejejejejd7d8dZejd9d:dZejd;d<dZejd=dd>d?dZ ejd@dAdZ!ejdBdCdZ"ejdDdEdZ#eddFdGdHZ$ejdIdJdZ%ejdKdLdZ&ejejejejejdMdNdZ'eddOdPdHZ(ejeddej dQdRdSgdTdUZ)ejeddej dVdRdWgdXdUZ*eddYdZdHZ+edd[d\gd]d^Z,edd_d`dHZ-ejdadbdZ.edcddddedZ/dfS )iTractographyInputSpecz%f,%f,%f,%f)argstrTz%sr   zinput file to be processed)existsr
   	mandatorypositiondescztracked.tckr   zoutput file containing tracks)r
   r   r   
usedefaultr   ZiFOD2ZFACTZiFOD1ZNulldistZ	SD_StreamZ
Tensor_DetZTensor_Probz-algorithm %szxTractography algorithm to be used -- References:[FACT]_, [iFOD1]_, [iFOD2]_, [Nulldist]_, [Tensor_Det]_, [Tensor_Prob]_.)r   r
   r   )r   z-include %szgspecify an inclusion region of interest, streamlines must traverse ALL inclusion regions to be accepted)r
   r   z-exclude %szdspecify an exclusion region of interest, streamlines that enter ANY exclude region will be discardedz-mask %sz_specify a masking region of interest. If defined,streamlines exiting the mask will be truncatedz-step %fzaset the step size of the algorithm in mm (default is 0.1 x voxelsize; for iFOD2: 0.5 x voxelsize)z	-angle %fzXset the maximum angle between successive steps (default is 90deg x stepsize / voxelsize)z
-number %dz0.4zset 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)r
   Zmax_verr   z
-select %d3)r
   Zmin_verr   z
-maxnum %dzset 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-maxlength %fzFset the maximum length of any track in mm (default is 100 x voxelsize)z-minlength %fzDset the minimum length of any track in mm (default is 5 x voxelsize)z
-cutoff %fzJset the FA or FOD amplitude cutoff for terminating tracks (default is 0.1)z-initcutoff %fzdset the minimum FA or FOD amplitude for initiating tracks (default is the same as the normal cutoff)z
-trials %dz^set the maximum number of sampling trials at each point (only used for probabilistic tracking)z-unidirectionalzXtrack from the seed point in one direction only (default is to track in both directions)z-initdirection %f,%f,%fznspecify an initial direction for the tracking (this should be supplied as a vector of 3 comma-separated valuesz-noprecomputedzxdo NOT pre-compute legendre polynomial values. Warning: this will slow down the algorithm by a factor of approximately 4z	-power %dz<raise the FOD to the power specified (default is 1/nsamples)   z-samples %dzOset the number of FOD samples to take per step for the 2nd order (iFOD2) methodz-rk4zuuse 4th-order Runge-Kutta integration (slower, but eliminates curvature overshoot in 1st-order deterministic methods)z-stopzGstop propagating a streamline once it has traversed all include regionsz-downsample %fz?downsample the generated streamlines to reduce output file sizez-act %szuse the Anatomically-Constrained Tractography framework during tracking; provided image must be in the 5TT (five - tissue - type) format)r   r
   r   z
-backtrackzallow tracks to be truncatedz-crop_at_gmwmizJcrop streamline endpoints more precisely as they cross the GM-WM interfacez-seed_sphere %f,%f,%f,%fzspherical seedz-seed_image %sz/seed streamlines entirely at random within maskz-seed_random_per_voxel %s %d
seed_imageseed_grid_voxelzeseed a fixed number of streamlines per voxel in a mask image; random placement of seeds in each voxel)r
   xorr   z-seed_grid_per_voxel %s %dseed_rnd_voxelzseed a fixed number of streamlines per voxel in a mask image; place seeds on a 3D mesh grid (grid_size argument is per axis; so a grid_size of 3 results in 27 seeds per voxel)z-seed_rejection %szWseed from an image using rejection sampling (higher values = more probable to seed fromz-seed_gmwmi %sact_filezVseed from the grey matter - white matter interface (only valid if using ACT framework))r   r
   requiresr   z-seed_dynamic %sa  determine seed points dynamically using the SIFT model (must not provide any other seeding mechanism). Note that while this seeding mechanism improves the distribution of reconstructed streamlines density, it should NOT be used as a substitute for the SIFT method itself.z-max_seed_attempts %dzset the maximum number of times that the tracking algorithm should attempt to find an appropriate tracking direction from a given seed pointzout_seeds.nii.gzz-output_seeds %sz@output the seed location of all successful streamlines to a fileN)0__name__
__module____qualname__r   TupleZFloatZ	sph_traitr   in_fileout_fileEnum	algorithmZEitherZroi_inclZroi_exclZroi_maskZ	step_sizeZangleZIntZn_tracksselectZ
max_tracks
max_lengthZ
min_lengthcutoffZcutoff_initZn_trialsZBoolZunidirectionalZinit_dirZ
noprecomptpowerZ	n_samplesZuse_rk4stopZ
downsampler   Z	backtrackZcrop_at_gmwmiZseed_spherer   r   r   Zseed_rejectionZ
seed_gmwmiZseed_dynamicZmax_seed_attempts	out_seeds r(   r(   D/tmp/pip-build-7vycvbft/nipype/nipype/interfaces/mrtrix3/tracking.pyr	      s4  r	   c               @   s"   e Zd ZedddZeddZdS )TractographyOutputSpecTzthe output filtered tracks)r   r   z@output the seed location of all successful streamlines to a file)r   N)r   r   r   r   r   r'   r(   r(   r(   r)   r*   2  s   r*   c                   s4   e Zd ZdZdZeZeZ fddZ	dd Z
  ZS )Tractographya  
    Performs streamlines tractography after selecting the appropriate algorithm.

    References
    ----------

    .. [FACT] Mori, S.; Crain, B. J.; Chacko, V. P. & van Zijl,
      P. C. M. Three-dimensional tracking of axonal projections in the
      brain by magnetic resonance imaging. Annals of Neurology, 1999,
      45, 265-269

    .. [iFOD1] Tournier, J.-D.; Calamante, F. & Connelly, A. MRtrix:
      Diffusion tractography in crossing fiber regions. Int. J. Imaging
      Syst. Technol., 2012, 22, 53-66

    .. [iFOD2] Tournier, J.-D.; Calamante, F. & Connelly, A. Improved
      probabilistic streamlines tractography by 2nd order integration
      over fibre orientation distributions. Proceedings of the
      International Society for Magnetic Resonance in Medicine, 2010, 1670

    .. [Nulldist] Morris, D. M.; Embleton, K. V. & Parker, G. J.
      Probabilistic fibre tracking: Differentiation of connections from
      chance events. NeuroImage, 2008, 42, 1329-1339

    .. [Tensor_Det] Basser, P. J.; Pajevic, S.; Pierpaoli, C.; Duda, J.
      and Aldroubi, A. In vivo fiber tractography using DT-MRI data.
      Magnetic Resonance in Medicine, 2000, 44, 625-632

    .. [Tensor_Prob] Jones, D. Tractography Gone Wild: Probabilistic Fibre
      Tracking Using the Wild Bootstrap With Diffusion Tensor MRI. IEEE
      Transactions on Medical Imaging, 2008, 27, 1268-1274

    Example
    -------

    >>> import nipype.interfaces.mrtrix3 as mrt
    >>> tk = mrt.Tractography()
    >>> tk.inputs.in_file = 'fods.mif'
    >>> tk.inputs.roi_mask = 'mask.nii.gz'
    >>> tk.inputs.seed_sphere = (80, 100, 70, 10)
    >>> tk.cmdline                               # doctest: +ELLIPSIS
    'tckgen -algorithm iFOD2 -samples 4 -output_seeds out_seeds.nii.gz -mask mask.nii.gz -seed_sphere 80.000000,100.000000,70.000000,10.000000 fods.mif tracked.tck'
    >>> tk.run()                                 # doctest: +SKIP
    Ztckgenc                sD   d|kr0t |tr0dd |D }|jdj| S tt| j|||S )NZroi_c             S   s   g | ]}d | qS )z%fr(   ).0vr(   r(   r)   
<listcomp>o  s    z,Tractography._format_arg.<locals>.<listcomp>,)
isinstancetupler
   joinsuperr+   _format_arg)selfnameZ
trait_specvalue)	__class__r(   r)   r4   m  s    zTractography._format_argc             C   s"   | j  j }tj| jj|d< |S )Nr   )output_specgetopabspathinputsr   )r5   outputsr(   r(   r)   _list_outputst  s    zTractography._list_outputs)r   r   r   __doc__Z_cmdr	   Z
input_specr*   r9   r4   r?   __classcell__r(   r(   )r8   r)   r+   9  s   .r+   )os.pathpathr;   baser   r   r   r   r   r	   r*   r+   r(   r(   r(   r)   <module>   s   
  )