Makes sure arguments are valid, specified files exist, etc.

def validate_arguments(args):
    """Makes sure arguments are valid, specified files exist, etc."""

    #check arguments
    print
    print "Checking input...",

    semantic_tests = ["animals", "custom"]
    phonemic_tests = ["a", "p", "s", "f"]
    if args.similarity_file:
        print
        print "Custom similarity file was specified..."
        args.semantic = "custom"

    if args.threshold:
        try:
            args.threshold = float(args.threshold)
        except ValueError:
            raise VFClustException('Custom threshold (--threshold argument) must be a number.')


    if not (args.source_file_path.lower().endswith('csv') or args.source_file_path.lower().endswith('textgrid')):
        raise VFClustException('The input must be either a .TextGrid or .csv file!\nYou provided ' + args.source_file_path.lower())
    if not os.path.isfile(args.source_file_path):
        raise VFClustException('The input file path you provided does not exist on your system!')

    #if no output path provided, write to source file path
    if args.output_path == None:
        args.output_path = args.source_path
    #if output_path is False, don't output anything
    elif args.output_path == False:
        pass
    else:
        #verify/make folders for output
        if len(args.output_path) == 0:
            args.output_path = os.path.abspath(os.path.dirname(args.source_file_path))
        try:
            if not os.path.isdir(args.output_path):
                os.mkdir(args.output_path)
        except:
            print "Error creating folder for program output. " \
                  "Make sure you have write permissions to the folder you provided. " \
                  "You can change the folder with the -o option." \
                  "The output directory will be the same as the input directory."


    #make phonemic and semantic args lower case
    if (args.semantic): args.semantic = args.semantic.lower()
    if (args.phonemic): args.phonemic = args.phonemic.lower()

    #must choose either semantic or phonemic
    if not (args.semantic or args.phonemic):
        print "DEBUG", args.semantic, args.similarity_file
        raise VFClustException(
            '''You must specify at least one phonemic or semantic test to run using -p or -s, followed by the test type.
            Alternatively, provide a custom similarity file using the --similarity-file and --threshold options.''')

    #make sure semantic arguments are legit
    if args.semantic and args.semantic not in semantic_tests:
        raise VFClustException("Currently only " + ",".join(semantic_tests) + " are supported for semantic testing. " \
                                                       "You provided " + args.semantic)

    if args.phonemic and args.phonemic not in phonemic_tests:
        raise VFClustException("Currently only " + ",".join(phonemic_tests) + " are supported for phonemic testing.  " \
                                                       "You provided " + args.phonemic)


    if (args.phonemic and args.semantic):
        raise VFClustException("You must choose EITHER semantic OR phonemic clustering.")

    #make paths absolute
    args.source_file_path = os.path.abspath(args.source_file_path)
    if args.output_path:
        args.output_path = os.path.abspath(args.output_path)

    #using custom similarity file
    if args.similarity_file: #if it's not None
        if not os.path.isfile(args.similarity_file):
            raise VFClustException('The custom similarity file path you provided does not exist on your system!')
        if not args.threshold:
            raise VFClustException('You must specify a clustering threshold when using a custom similarity file. Use --threshold X, where X is the threshold number.')
        try:
            args.threshold = float(args.threshold)
        except:
            raise VFClustException('Error reading the custom threshold you provided. It must be a number, e.g. --threshold 6.7 or --threshold 10')
        args.similarity_file = os.path.abspath(args.similarity_file)

    print "OK!"
    print
    print "Parsed arguments:"
    print_table([(k, str(vars(args)[k])) for k in vars(args)])

    return args