3
md                 @   sD   d dl Z d dlmZ d dlmZ d dlmZ d dlmZ dd ZdS )    N)glob)split_filename)dedent)RawDescriptionHelpFormatterc          
   C   s   t d}dtjj kr>ttjjtjd d}dd |D }ng }| jddd}||_t	|_
|jdd	d
d |jdddd |jddd|dd |jdddddd |jdddddddddgd d! |jd"d#d$td%d& |jd'd(d)d |jd*d+d,d- |S ).Na  
    Process subject-level data in fitz.

    This script controls the workflows that process data. Depending on the
    workflow, the data may start from raw DICOM or Nifti files and finish
    as processed models or group-level stats. See the documentation for the
    pipeline (collection of workflows) for information on exactly what the
    image inputs and outputs will be.

    All fitz workflows use Nipype, so there are several common options for
    efficiently running multiple subjects at once with differnt nipype plugins.
    The script can thus be run for several subjects at once, and (with a large
    enough cluster) all of the subjects can be processed in the time it takes
    to process a single run of data linearly.

    Nipype creates a cache directory to save processing time when steps are
    re-run. If you do not delete your cache directory after running (which is
    configured in the project file), repeated use of this script will only
    rerun the nodes that have changes to their inputs. Otherwise, you will
    have to rerun at the level of the workflows.


    Examples
    --------


    Note that the parameter switches match any unique short version
    of the full parameter name.

    fitz run -w xnatconvert preproc onset model

        Run every stage of the standar SPM fMRI pipeline for the default
        experiment for each subject defined in $FITZ_DIR/subjects.txt.
        The processing will be distributed locally with the MultiProc plugin
        using 4 processes.

    fitz run -s subj1 subj2 subj3 -w preproc

        Run preprocessing of the default experiment for subjects `subj1`,
        `subj2`, and `subj3`.

    fitz run -s pilot_subjects -w model -e nback -n 8

        Run the model workflow on the subjects enumerated in
        $FITZ_DIR/pilot_subjects.txt with the experiment details in
        $FITZ_DIR/nback.py. Distribute the execution locally with 8 parallel
        processes.

    Usage Details
    -------------

    ZFITZ_DIRz*/workflows/*.pyc             S   s   g | ]}t |d  qS )   )r   ).0Zwf r   6/tmp/pip-build-7vycvbft/fitz/fitz/tools/commandline.py
<listcomp>@   s    zrun_parser.<locals>.<listcomp>run)helpz--experimentz-ezexperimental paradigmz--modelz-mzmodel to fitz--workflowsz-w*zwhich workflows to run)nargschoicesr   z
--subjectsz-sZsubjectsz`list of subject ids, name of file in lyman directory, or full path to text file with subject ids)r   destr   z--pluginz-pZ	multiprocZlinearZipythonZtorqueZsgeZslurmzworklow execution plugin)defaultr   r   z--nprocsz-n   z$number of MultiProc processes to use)r   typer   z--queuez-qz#which queue for scheduler executionz	--dontrun
store_truez$don't actually execute the workflows)actionr   )r   osenvironkeysr   pathjoinZ
add_parserdescriptionr   Zformatter_classadd_argumentint)Z
subparsersr   Zwf_filesZ	workflowsparserr   r   r	   
run_parser   s4    3


r   )	r   r   Znipype.utils.filemanipr   textwrapr   argparser   r   r   r   r   r	   <module>   s
   