Beispiel #1
0
def main(argv):
    '''Basic reading in of commandline options.'''

    help_line = '''\
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

** JUST BETA VERSION AT THE MOMENT **

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'''
    comm_str = 'fat_mvm_review.py '
    file_in = ''
    pref_out = ''
    thr_out = 10**6
    TRUNC = 0

    try:
        opts, args = getopt.getopt(
            argv, "hTf:p:t:",
            ["help", "Trunc_labs", "file_in=", "prefix=", "thr_out="])

    except getopt.GetoptError:
        print "** Error reading options. Try looking at the helpfile:"
        print "\t $  fat_mvm_review.py -h\n"
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            print help_line
            sys.exit()
        elif opt in ("-f", "--file_in"):
            file_in = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-p", "--prefix"):
            pref_out = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-t", "--thr_out"):
            thr_out = float(arg)
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-T", "--Trunc_labs"):
            TRUNC = 1
            comm_str = GR.RecapAttach(comm_str, opt, arg)

    if not (file_in):
        print "** ERROR: missing an input (*MVM.txt) file."
        print "\t Need to use either '-f' or '--file_in'."
        sys.exit()

    # not requisite to have output prefix
    #if not(pref_out):
    #    print "** ERROR: missing an output prefix."
    #    print "\t Need to use either '-p' or '--pref_out'."
    #    sys.exit()

    return comm_str, file_in, pref_out, thr_out, TRUNC
Beispiel #2
0
def main(argv):
    '''Basic reading in of commandline options.'''

    help_line = '''\
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    ++ Oct, 2014.  Written by PA Taylor (UCT/AIMS).  
    ++ Perform factor analysis on quantitative CSV data to find 
       latent variables.
     
    This program is designed to help prep subject data (clinical,
    neurophysiological, test scores, etc.) for statistical analysis,
    for example using 3dMVM (written by G. Chen).

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    This program reads in a group-worth of information from a CSV file
    (which could be dumped from a study spreadsheet), and calculates
    latent variables using factor analysis. Default is to perform
    factor analysis for all quantitative variables in the CSV file, as
    well as for all subjects.  If you want a subset of variables to be
    used only, you can input these via commandline list or as a file.
    If you want a subset of subjects used, this can be selected by
    globbing a list of *netcc or *.grid files from 3dNetCorr or
    3dTrackID creation, respectively (or, you can always edit your CSV
    file to chop out subjects).  The output CSV file is a copy of the
    input, with the set of variables input into factor analysis
    *replaced* by the estimated latent factors.

    NB: *Currently*, columns of data with missing data (->'NA') will
    be ignored during factor analysis processing but passed along to
    the output.  This might change over time, moving to a point of
    analysis phase space where data with NA values can somehow be
    treated in the formation of latent variables.

    Here, Factor analysis is performed using the existing R function
    'factanal()', as well as the function 'paran()' if you choose to
    use parallel analysis to determine the number of factors from the
    data.  For more on those methods, please read their individual R
    documentations.  Each function has maaany available options; for
    the most part, we use default settings, but also allow some
    further manipulation.  If you really need some other parameter
    settings to be directly input from the Python commandline, let the
    author know.  Two important parameters currently used in the
    factanal() function are: scores='regression', and
    rotation="varimax".  If you have strong opinions about this, then
    great.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

    OUTPUT: 

    + new *.csv file, with a set of quantitative variables replaced by
    latent factors. 

    + (option) an image file of Horn's Test, if you use parallel
    analysis to determine the number of latent factors.

    + a file recording loading factors of input variables for each
    output latent variable, so you can try to interpret the 'meaning'
    of the latent variables. Buon fortuna...
     
     
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

     TO USE (from a terminal commandline):\n
      $ fat_lat_csv.py  -p PREFIX  -c CSV_FILE                    \\
                       { -m MATR_FILES | -l LIST }                \\
                       { -v, --vars='X Y Z ...' | -f VAR_FILE }   \\
                       -N                                         \\
                       -L FACLAB  -C NLOAD   -n NF                \\
                       -P PERC   -I N_ITER                        \\
                       -g   -i ITYPE 
        
     where:
        -p, --prefix=PREFIX      :prefix for output files.
        -c, --csv_in=CSV_FILE    :name of comma-separated variable (CSV)
                                  file for input. Format notes: each row
                                  contains a single subject\'s data, and
                                  the first row contains column/variable
                                  labels (with no spaces in them); first
                                  column is subject IDs (no spaces); and
                                  factor/categorical variables (gender,
                                  etc.) should be recorded with at least
                                  one character (i.e., M/F and not 0/1). 
                                  I will replace spaces in the first row 
                                  and column.

        -m, --matr_in=MATR_FILES :[optional here-- can be used to select
                                  a subset of subjects in the CSV file;
                                  otherwise all CSV subjects are used in 
                                  computations]
                                  one way of providing the set of matrix
                                  (*.grid or *.netcc) files- by searchable
                                  path.  This can be a globbable entry in
                                  quotes containing wildcard characters,
                                  such as 'DIR1/*/*000.grid'.
                                  If this option is used instead of '-l',
                                  below, then this program tries to match
                                  each CSV subj ID to a matrix file by 
                                  finding which matrix file path in the
                                  MATR_FILES contains a given ID string;
                                  this method may not always find unique
                                  matches, in which case, use '-l'
                                  approach.
        -l, --list_match=LIST    :[optional here (see previous option)]
                                  another way of inputting the matrix
                                  (*.grid or *.netcc) files-- by explicit
                                  path, matched per file with a CSV
                                  subject ID.
                                  The LIST text file contains two columns:
                                  col 1: path to subject matrix file.
                                  col 2: CSV IDs,
                                  (first line can be a '#'-commented one).

        -v, --vars='X Y Z ...'   :one method for supplying a list of
                                  quantitative variables from which one wants
                                  to calculate latent variables. Names must
                                  be separated with whitespace. If no list of
                                  variables is input, then *all* quantitative
                                  variables in the CSV_FILE are used.
        -f, --file_vars=VAR_FILE :the second method for supplying a list of
                                  quantitative variables.  VAR_FILE is a text
                                  file with a single column of variable
                                  names. If no list of variables is input,
                                  then *all* quantitative variables in the
                                  CSV_FILE are used.

        -N, --NA_warn_off        :switch to turn off the automatic
                                  warnings as the data table is created. 
                                  (Default is to warn.)

    -L, --Label_factors=FACLAB   :Prefix string for latent variable column 
                                  in the output CSV, so that the names are:
                                  'FACLAB_01', 'FACLAB_02', etc.
                                  (Default: 'FACTOR'.)
    -C, --Count_loads=NLOAD      :When reporting loading factors for each 
                                  latent factor (that is, essentially what is
                                  the correlation of the most-related input
                                  variables to this particular factor), report
                                  NLOAD many values. If NLOAD<0, then ALL get 
                                  reported. (Default: 5.)

        -n, --num_facs=NF        :specify the number of latent factors 'NF'
                                  in which to decompose your variable data
                                  using factor analysis (default is to not use
                                  this, but instead to perform parallel 
                                  analysis, which has options below.)

     If not using an explicit number of factors, parallel analysis is
        performed to estimate the number of latent factors from the data, with
        the following options for Horn's test in the R function 'paran()':

    -P, --Percentile=PERC        :percentile value used in estimating bias;
                                  'percentile' in paran().
                                  (Default: conservative value of 99.)
    -I, --Iter_Horn=N_ITER       :number of Monte Carlo iterations in Horn's 
                                  test; 'iterations' in paran().  
                                  (Default: 5000.)
    -g, --graph_on               :switch to turn on saving the paran()-produced
                                  graph of Horn's test results. File prefix
                                  will be PREFIX string input above; file
                                  type can be set with the next option.
    -i, --image-type=ITYPE       :if 'graph_on' is used, then you can choose
                                  the output image file type from: 
                                      'jpeg', 'pdf', 'png', 'tiff'.
                                  (Default: 'jpeg'.)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

     Example:
            fat_lat_csv.py -c Subject_data.csv     \\
                           -p Subject_data_LAT     \\
                           -N  -g   -C -1
         or, equivalently,
            fat_lat_csv.py --csv_in='Subject_data.csv'     \\
                           --prefix='Subject_data_LAT'     \\
                           --NA_warn_off --graph_on        \\
                           --Count_loads=-1

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

   This program is part of AFNI-FATCAT:
    Taylor PA, Saad ZS (2013). FATCAT: (An Efficient) Functional And
    Tractographic Connectivity Analysis Toolbox. Brain Connectivity.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'''

    comm_str = 'fat_lat_csv.py '

    file_csv = ''
    file_matr_glob = ''
    file_prefix = ''
    file_listmatch = ''
    SWITCH_NAwarn = 1
    SWITCH_ExternLabsOK = 1  # user doesn't choose this here
    SWITCH_DoGraph = 0
    IMG_type = FR.PARN_OUT_types[0]
    N_FACS = 0
    file_listmodel = ''
    list_model = ''
    N_LOADS = 0
    fact_lab_pref = ''
    Percentile = 99
    N_iter = 5000

    try:
        opts, args = getopt.getopt(argv,"hNgc:m:l:i:n:C:L:P:I:p:v:f:",
                                   ["help",
                                    "NA_warn_off",
                                    "graph_on",
                                    "csv_in=",
                                    "matr_in=",
                                    "list_match=",
                                    "image_type=",
                                    "num_facs=",
                                    "Count_loads=",
                                    "Label_factors=",
                                    "Percentile=",
                                    "Iter_Horn=",
                                    "prefix=",
                                    "vars=", 
                                    "file_vars="])

    except getopt.GetoptError:
        print "** Error reading options. Try looking at the helpfile:"
        print "\t $  fat_mvm_prep.py -h\n"
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            print help_line
            sys.exit()
        elif opt in ("-N", "--NA_warn_off"):
            SWITCH_NAwarn = 0
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-g", "--graph_on"):
            SWITCH_DoGraph = 1
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-c", "--csv_in"):
            file_csv = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-m", "--matr_in"):
            file_matr_glob = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-p", "--prefix"):
            file_prefix = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-l", "--list_match"):
            file_listmatch = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-v", "--vars"):
            list_model = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-f", "--file_vars"):
            file_listmodel = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-i", "--image_type"):
            IMG_type = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-n", "--num_facs"):
            N_FACS = int(arg)
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-C", "--Count_loads"):
            N_LOADS = int(arg)
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-L", "--Label_factors"):
            fact_lab_pref = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-P", "--Percentile"):
            Percentile = int(arg)
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-I", "--Iter_Horn"):
            N_iter = int(arg)
            comm_str = GR.RecapAttach(comm_str, opt, arg)

            
    if N_FACS <0 :
        print "** ERROR: bad number of factors asked for: ",N_FACS
        sys.exit()
    if (Percentile <=0) or (Percentile >=100):
        print "** ERROR: bad percentile asked for; should be (0, 100)."
        sys.exit()
    if not( FR.PARN_OUT_types.__contains__(IMG_type) ):
        print "** Error! ",
        print "Output file type '-i %s' is not valid. Select from:" % (IMG_type)
        print "\t",
        for x in FR.PARN_OUT_types:
            print " '"+x+"' ",
        print "\n"
        sys.exit(32)
    if ( file_csv == '' ) or ( file_prefix == '' ) :
        print "** ERROR: missing a necessary input."
        sys.exit()
    if ( file_matr_glob == '' ) and ( file_listmatch == '' ):
        print "*+ No matrices input -> going to use all subjects in calcs."
    if not( file_matr_glob == '' ) and not( file_listmatch == '' ):
        print "*+ Warning: both a path for globbing *and* a listfile have",
        print " been input for the matrix file."
        print "\tThe glob one after '-m' will be ignored."
    if not( list_model == '' ) and not( file_listmodel == '' ):
        print "*+ Warning: both a variable list *and* a variable file have",
        print " been input (file will be given precedence)."

    return comm_str, file_csv, file_matr_glob, file_prefix, file_listmatch, \
     SWITCH_NAwarn, SWITCH_ExternLabsOK, SWITCH_DoGraph, \
     IMG_type, N_FACS, N_LOADS, fact_lab_pref, Percentile, N_iter, \
     list_model, file_listmodel
Beispiel #3
0
def main(argv):
    '''Basic reading in of commandline options.'''

    help_line = '''\
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

     ++ Jan, 2015 (ver 1.2).  Written by PA Taylor.
     ++ Read in a data table file (likely formatted using the program
        fat_mvm_prep.py) and build an executable command for 3dMVM 
        (written by G Chen) with a user-specified variable model. This
        should allow for useful repeated measures multivariate modeling
        of networks of data (such as from 3dNetCorr or 3dTrackID), as
        well as follow-up analysis of subconnections within the network.
     

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

     + INPUTS: 
        1) Group data table text file (formatted as the *_MVMtbl.txt file
           output by fat_mvm_prep.py); contains subject network info (ROI
           parameter values) and individual variables.
        2) Log file (formatted as the *_MVMprep.log file output by 
           fat_mvm_prep.py) containing, among other things, a list of
           network ROIs and a list of parameters whose values are stored
           in the group data table.
        3) A list of variables, whose values are also stored in the group
           data table, which are to be statistically modeled.  The list
           may be provided either directly on the commandline or in a 
           separate text file. 
           Variable entries may now include interactions (using '*') 
           among either 
           a) two categorical variables, or
           b) one categorical and one quantitative variable.
           Running with the '*' symbol includes both the main effects and
           the interactions effects of the variables in the test.  That is,
           A*B = A + B + A:B.
           Post hoc tests will now be run for both the main effects and the
           interactions, as well.

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

     + OUTPUTS
       1a) A text file (named PREFIX_scri.tcsh) containing a script for
           running 3dMVM, using the prescribed variables along with each 
           individual parameter.  If N parameters are contained in the 
           group data table and M variables selected for the model, then
           N network-wise ANOVAs for set of M+1 (includes the intercept)
           effects will be run.
           Additionally, if there are P ROIs comprising the network,
           then the generated script file is automatically set to perform
           PxM "post hoc" tests for the interactions of each ROI and
           each variable (if the variable is categorical, then there are
           actually more tests-- using one for each subcategory).
           This basic script can be run simply from the commandline:
           $  tcsh PREFIX_scri.tcsh
           after which ...
       1b) ... a text file of the test results is saved in a file
           called  "PREFIX_MVM.txt".
           Results in the default *MVM.txt file are grouped by variable,
           first producing a block of ANOVA output with three columns
           per variable:
           Chi-square value, degrees of freedom, and p-value.
           This is followed by a block of post hoc testing output with
           four columns:
           test value, t-statistic, degrees of freedom and p-value.
           See 3dMVM for more information.
    
           NB: The '1a' script is a *very basic starter/suggestion*
           for performing statistical tests.  Feel free to modify it
           as you wish for your particular study.  See '3dMVM -help'
           for more information.

       The ANOVA tests are performed on a network-wide level, and the
       posthoc tests followup with the same variables on a per-ROI
       level.  The idea is: if there is a significant
       parameter-variable association on the network level (seen in
       the ANOVA results), it may be interesting to see if some
       particular ROIs are driving the effect (seen in the posthoc
       results).

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

     + USAGE:
       $  fat_mvm_scripter.py  --prefix=PREFIX                     \\
            --table=TABLE_FILE  --log=LOG_FILE                     \\
            { --vars='VAR1 VAR2 VAR3 ...' | --file_vars=VAR_FILE } \\
            { --Pars='PAR1 PAR2 PAR3 ...' | --File_Pars=PAR_FILE } \\
            { --rois='ROI1 ROI2 ROI3 ...' | --file_rois=ROI_FILE } \\
            { --no_posthoc }  { --NA_warn_off }
     
      -p, --prefix=PREFIX      :output prefix for script file, which will
                                then be called PREFIX_scri.tcsh, for
                                ultimately creating a PREFIX_MVM.txt file
                                of statistical results from 3dMVM.
      -t, --table=TABLE_FILE   :text file containing columns of subject
                                data, one subject per row, formatted as
                                a *_MVMtbl.txt output by fat_mvm_prep.py (see
                                that program's help for more description.
      -l, --log=LOG_FILE       :file formatted according to fat_mvm_prep.py
                                containing commented headings and also
                                lists of cross-group ROIs and parameters.
                                for which there were network matrices
                                (potentially among other useful bits of
                                information).  See output of fat_mvm_prep.py
                                for more info;  NB: commented headings
                                generally contain selection keywords, so
                                pay attention to those if generating your
                                own.

      -v, --vars='X Y Z ...'   :one method for supplying a list of
                                variables for the 3dMVM model. Names must
                                be separated with whitespace.  Categorical
                                variables will be detected automatically
            *or*                by the presence of nonnumeric characters
                                in their columns; quantitative variables
                                will be automatically put into a list for
                                post hoc tests.
      -f, --file_vars=VAR_FILE :the second method for supplying a list of
                                variables for 3dMVM.  VAR_FILE is a text
                                file with a single column of variable
                                names.
                                Using the VAR_FILE, you can specify subsets
                                of categorical variables for GLT testing.
                                The categories to be tested are entered on the
                                same line as the variable, separated only by
                                spaces.  If specifying a subset for an inter-
                                action, then put a space-separated comma 
                                between the lists of variables, if necessary 
                                (and if specifying categories only for the 
                                second of two categorical variables, then put 
                                a space-separated comma before the list).
                  ---->     ... using either variable entry format, an 
                                interaction can be specified using '*', where 
                                A*B = A + B + A:B.

      -P, --Pars='T S R ...'   :one method for supplying a list of parameters
                                (that is, the names of matrices) to run in 
                                distinct 3dMVM models. Names must be
            *or*                separated with whitespace. Might be useful
                                to get a smaller jungle of output results in 
                                cases where there are many matrices in a file,
                                but only a few that are really cared about.
      -F, --File_Pars=PAR_FILE :the second method for supplying a list of
                                parameters for 3dMVM runs.  PAR_FILE is a text
                                file with a single column of variable
                                names.

      -r, --rois='A B C ...'   :optional command to be able to select
                                a subset of available network ROIs,
                                if that's useful for some reason (NB:
                                fat_mvm_prep.py should have already found
            *or*                a set of ROIs with data across all the
                                the subjects in the group, listed in the
                                *MVMprep.log file; default would be using
                                the entire list of ROIs in this log file as 
                                the network of ROIs).
      -R, --file_rois=ROI_FILE :the second method for supplying a (sub)list of
                                ROIs for 3dMVM runs.  ROI_FILE is a text
                                file with a single column of variable
                                names (see '--rois' for the default network 
                                selection).
      -s, --subnet_pref=SUBPR  :if a subnetwork list of ROIs is used (see
                                preceding two options), then one can give a 
                                name SUBPR for the new table file that is 
                                created. Otherwise, a default name from the
                                required '--prefix=PREFIX' (or '-p PREFIX') 
                                option is used:
                                PREFIX_SUBNET_MVMtbl.txt.

      -n, --no_posthoc         :switch to turn off the automatic
                                generation of per-ROI post hoc tests
                                (default is to do them all).
      -N, --NA_warn_off        :switch to turn off the automatic
                                warnings as the data table is created. 3dMVM
                                will excise subjects with NA values, so there
                                shouldn't be NA values in columns you want to
                                model.  However, you might have NAs elsewhere
                                in the data table that might be annoying to 
                                have flagged, so perhaps turning off warnings
                                would then be useful. (Default is to warn.)
      -c, --cat_pair_off       :switch to turn off the following test:
                                by default, if a categorical variable 
                                undergoes posthoc testing, a GLT will be 
                                created for every pairwise combination of
                                its categories, testing whether the given
                                parameter is higher in one group than another
                                (each category is assigned a +1 or -1, which is 
                                recorded in parentheses in the output label
                                names).
                                

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

     Example:
       $ fat_mvm_scripter.py --file_vars=VARLIST.txt          \\
                             --log_file=study_MVMprep.log     \\
                             --table=study_MVMtbl.txt         \\
                             --prefix=study 
     or, equivalently:
       $ fat_mvm_scripter.py -f VARLIST.txt -l study_MVMprep.log -t study_MVMtbl.txt -p study
 
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

   This program is part of AFNI-FATCAT:
    Taylor PA, Saad ZS (2013). FATCAT: (An Efficient) Functional And
    Tractographic Connectivity Analysis Toolbox. Brain Connectivity.

   For citing the statistical approach, please use the following:
    Chen, G., Adleman, N.E., Saad, Z.S., Leibenluft, E., Cox, R.W. (2014).
    Applications of Multivariate Modeling to Neuroimaging Group Analysis:
    A Comprehensive Alternative to Univariate General Linear Model. 
    NeuroImage 99:571-588.
    https://afni.nimh.nih.gov/pub/dist/HBM2014/Chen_in_press.pdf

   The first application of this network-based statistical approach is
    given in the following:
    Taylor PA, Jacobson SW, van der Kouwe AJW, Molteno C, Chen G,
    Wintermark P, Alhamud A, Jacobson JL, Meintjes EM (2014). A
    DTI-based tractography study of effects on brain structure
    associated with prenatal alcohol exposure in newborns. (HBM, in press)

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'''
 
    file_prefix = ''
    list_model = ''
    userlist_roi = ''
    pref_subnet = ''     # Sep,2015: make MVM table for user's ROI susbset
    list_pars = ''  
    file_listpars = ''
    file_listrois = ''
    file_listmodel = ''
    file_table = ''
    file_log = ''
    SWITCH_posthoc = 1
    SWITCH_NAwarn = 1
    SWITCH_subnet = 0    # Sep,2015: for subnet minitable
    comm_str = ''        
    CAT_PAIR_COMP = 1    # for categ var, now do rel compar by default

    # allow status 0 on -help   24 Sep 2018 [rickr]
    if "-help" in argv:
        print help_line
        sys.exit()

    try:
        opts, args = getopt.getopt(argv,"hnNcv:f:p:t:l:r:R:F:P:s:",
                                   ["help",
                                    "no_posthoc",
                                    "NA_warn_off",
                                    "cat_pair_off",
                                    "vars=",
                                    "file_vars=",
                                    "prefix=",
                                    "table=",
                                    "log_file=",
                                    "rois=",
                                    "file_rois=",
                                    "File_Pars=",
                                    "Pars=",
                                    "subnet_pref="
                                ])
    except getopt.GetoptError:
        print "** Error reading options. Try looking at the helpfile:"
        print "\t $  fat_mvm_scripter.py -h\n"
        sys.exit(2)

    for opt, arg in opts:
        if opt in ("-h", "--help"):
            print help_line
            sys.exit()
        elif opt in ("-r", "--rois"):
            userlist_roi = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
            SWITCH_subnet = 1
        elif opt in ("-R", "--file_rois"):
            file_listrois = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
            SWITCH_subnet = 1
        elif opt in ("-s", "--subnet_pref"):
            pref_subnet = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-P", "--Pars"):
            list_pars = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-F", "--File_Pars"):
            file_listpars = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-v", "--vars"):
            list_model = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-f", "--file_vars"):
            file_listmodel = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-p", "--prefix"):
            file_prefix = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-t", "--table"):
            file_table = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-l", "--log_file"):
            file_log = arg
            comm_str = GR.RecapAttach(comm_str, opt, arg)
        elif opt in ("-n", "--no_posthoc"):
            SWITCH_posthoc = 0
            comm_str = GR.RecapAttach(comm_str, opt, '')
        elif opt in ("-N", "--NA_warn_off"):
            SWITCH_NAwarn = 0
            comm_str = GR.RecapAttach(comm_str, opt, '')
        elif opt in ("-c", "--cat_pair_off"):
            CAT_PAIR_COMP = 0
            comm_str = GR.RecapAttach(comm_str, opt, '')

    if not(file_prefix):
        print "** ERROR: missing an output prefix."
        print "\t Need to use either '-p' or '--prefix'."
        sys.exit()
    if not(file_table):
        print "** ERROR: missing an input table."
        print "\t Need to use either '-t' or '--table'."
        sys.exit()
    if not(file_log):
        print "** ERROR: missing an input log file."
        print "\t Need to use either '-l' or '--log'."
        sys.exit()
    if ( list_model == '' ) and ( file_listmodel == '' ):
        print "** ERROR: missing a necessary model description input."
        print "\t Need to use either '-m' or '-f'."
        sys.exit()
    if not( list_model == '' ) and not( file_listmodel == '' ):
        print "*+ Warning: both a model list *and* a model file have",
        print " been input."
        print "\tThe latter will be used."
    if not( list_pars == '' ) and not( file_listpars == '' ):
        print "*+ Warning: both a parameter list *and* a parameter file have",
        print " been input."
        print "\tThe latter will be used."
    if not( userlist_roi == '' ) and not( file_listrois == '' ):
        print "*+ Warning: both a ROI list *and* a ROI file have",
        print " been input."
        print "\tThe latter will be used."
    if SWITCH_subnet:   # in case no prefix is given
        if not(pref_subnet) :
            pref_subnet = file_table.strip(GR.MVM_file_postfix)
            pref_subnet+= '_SUBNET'+GR.MVM_file_postfix

            
    return \
    list_model, file_listmodel, file_prefix, file_table, \
    file_log, userlist_roi, file_listrois, pref_subnet, list_pars, \
    file_listpars, SWITCH_posthoc, comm_str, SWITCH_NAwarn, CAT_PAIR_COMP