def main():
    parser = buildArgsParser()
    args = parser.parse_args()

    in_filename = args.input
    out_filename = args.output
    anat_filename = args.anat
    isForcing = args.isForce
    isVerbose = args.isVerbose

    if isVerbose:
        logging.basicConfig(level=logging.DEBUG)

    if not os.path.isfile(in_filename):
        parser.error('"{0}" must be an existing file!'.format(in_filename))

    if not tractconverter.is_supported(in_filename):
        parser.error('Input file must be one of {0}!'.format(",".join(
            FORMATS.keys())))

    if not tractconverter.is_supported(out_filename):
        parser.error('Output file must be one of {0}!'.format(",".join(
            FORMATS.keys())))

    if os.path.isfile(out_filename):
        if isForcing:
            if out_filename == in_filename:
                parser.error(
                    'Cannot use the same name for input and output files. Conversion would fail.'
                )
            else:
                logging.info('Overwriting "{0}".'.format(out_filename))
        else:
            parser.error('"{0}" already exist! Use -f to overwrite it.'.format(
                out_filename))

    inFormat = tractconverter.detect_format(in_filename)
    outFormat = tractconverter.detect_format(out_filename)

    #if inFormat == outFormat:
    #    parser.error('Input and output must be from different types!'.format(",".join(FORMATS.keys())))

    if anat_filename is not None:
        if not any(map(anat_filename.endswith, EXT_ANAT.split('|'))):
            if isForcing:
                logging.info('Reading "{0}" as a {1} file.'.format(
                    anat_filename.split("/")[-1], EXT_ANAT))
            else:
                parser.error(
                    'Anatomy file must be one of {1}!'.format(EXT_ANAT))

        if not os.path.isfile(anat_filename):
            parser.error(
                '"{0}" must be an existing file!'.format(anat_filename))

    #Convert input to output
    input = inFormat(in_filename, anat_filename)
    output = outFormat.create(out_filename, input.hdr, anat_filename)
    tractconverter.convert(input, output)
def main():
    parser = buildArgsParser()
    args = parser.parse_args()

    in_filename = args.input
    out_filename = args.output
    anat_filename = args.anat
    isForcing = args.isForce
    isVerbose = args.isVerbose

    if isVerbose:
        logging.basicConfig(level=logging.DEBUG)

    if not os.path.isfile(in_filename):
        parser.error('"{0}" must be an existing file!'.format(in_filename))

    if not tractconverter.is_supported(in_filename):
        parser.error("Input file must be one of {0}!".format(",".join(FORMATS.keys())))

    if not tractconverter.is_supported(out_filename):
        parser.error("Output file must be one of {0}!".format(",".join(FORMATS.keys())))

    if os.path.isfile(out_filename):
        if isForcing:
            if out_filename == in_filename:
                parser.error("Cannot use the same name for input and output files. Conversion would fail.")
            else:
                logging.info('Overwriting "{0}".'.format(out_filename))
        else:
            parser.error('"{0}" already exist! Use -f to overwrite it.'.format(out_filename))

    inFormat = tractconverter.detect_format(in_filename)
    outFormat = tractconverter.detect_format(out_filename)

    # if inFormat == outFormat:
    #    parser.error('Input and output must be from different types!'.format(",".join(FORMATS.keys())))

    if anat_filename is not None:
        if not any(map(anat_filename.endswith, EXT_ANAT.split("|"))):
            if isForcing:
                logging.info('Reading "{0}" as a {1} file.'.format(anat_filename.split("/")[-1], EXT_ANAT))
            else:
                parser.error("Anatomy file must be one of {1}!".format(EXT_ANAT))

        if not os.path.isfile(anat_filename):
            parser.error('"{0}" must be an existing file!'.format(anat_filename))

    # Convert input to output
    input = inFormat(in_filename, anat_filename)
    output = outFormat.create(out_filename, input.hdr, anat_filename)
    tractconverter.convert(input, output)
def main():
    parser = buildArgsParser()
    args = parser.parse_args()

    input = args.input
    output = args.output
    anat = args.anat
    vtk2tck = args.vtk2tck
    vtk2trk = args.vtk2trk
    vtk2fib = args.vtk2fib
    fib2tck = args.fib2tck
    fib2trk = args.fib2trk
    fib2vtk = args.fib2vtk
    trk2tck = args.trk2tck
    trk2fib = args.trk2fib
    trk2vtk = args.trk2vtk
    tck2trk = args.tck2trk
    tck2fib = args.tck2fib
    tck2vtk = args.tck2vtk
    isRecursive = args.isRecursive
    isForcing = args.isForce
    isVerbose = args.isVerbose

    if isVerbose:
        logging.basicConfig(level=logging.DEBUG)

    if not os.path.isdir(input):
        parser.error('"{0}" must be a folder!'.format(input))

    if output is not None:
        if not os.path.isdir(output):
            if isForcing:
                logging.info('Creating "{0}".'.format(output))
                os.makedirs(output)
            else:
                parser.error("Can't find the output folder")

    #TODO: Warn if duplicate conversion (i.e. tck2X, tck2Y)
    #TODO: Find better way to add multiple conversions.
    conversions = {}
    if vtk2tck:
        conversions['vtk'] = 'tck'
    if vtk2trk:
        conversions['vtk'] = 'trk'
    if vtk2fib:
        conversions['vtk'] = 'fib'
    if fib2tck:
        conversions['fib'] = 'tck'
    if fib2trk:
        conversions['fib'] = 'trk'
    if fib2vtk:
        conversions['fib'] = 'vtk'
    if trk2tck:
        conversions['trk'] = 'tck'
    if trk2fib:
        conversions['trk'] = 'fib'
    if trk2vtk:
        conversions['trk'] = 'vtk'
    if tck2trk:
        conversions['tck'] = 'trk'
    if tck2fib:
        conversions['tck'] = 'fib'
    if tck2vtk:
        conversions['tck'] = 'vtk'

    if len(conversions) == 0:
        parser.error('Nothing to convert! Please specify at least one conversion.')

    if anat is not None:
        if not any(map(anat.endswith, EXT_ANAT.split('|'))):
            if isForcing:
                logging.info('Reading "{0}" as a {1} file.'.format(anat.split("/")[-1], EXT_ANAT))
            else:
                parser.error('Anatomy file must be one of {0}!'.format(EXT_ANAT))

        if not os.path.isfile(anat):
            parser.error('"{0}" must be an existing file!'.format(anat))

    walkAndConvert(input, conversions, output, anat, isRecursive, isForcing)