def main(argv=None):
    """script main.

    parses command line options in sys.argv, unless *argv* is given.
    """

    if argv is None:
        argv = sys.argv

    # setup command line parser
    parser = E.OptionParser(version="%prog version: $Id$",
                            usage=globals()["__doc__"])

    parser.add_option("-s", "--suffix", dest="suffixes",
                      action="append",
                      type="string",
                      help="mapping of suffix [%default]")

    parser.add_option("-m", "--map", dest="filename_map",
                      type="string",
                      help="filename containing a mapping of filenames "
                      "to destinations [%default]")

    parser.add_option("-u", "--no-sort", dest="do_sort",
                      action="store_false",
                      help="do not sort filenames before grouping "
                      "[%default]")

    parser.add_option("-n", "--dry-run", dest="dry_run",
                      action="store_true",
                      help="dry run - do not merge "
                      "[%default]")

    parser.set_defaults(
        filename_map=None,
        do_sort=True,
        dry_run=False,
        suffixes=[])

    # add common options (-h/--help, ...) and parse command line
    (options, args) = E.Start(parser, argv=argv)

    if options.filename_map:
        map_regex2dest = IOTools.readMap(
            IOTools.openFile(options.filename_map))
        map_regex2dest = dict([(re.compile(x), y) for x, y in
                               map_regex2dest.items()])

    map_suffix2dest = {}
    for suffix in options.suffixes:
        src, dest = suffix.split("=")
        map_suffix2dest[src.strip()] = dest.strip()

    filenames = args

    if options.do_sort:
        filenames.sort()

    dest2src = collections.defaultdict(list)
    for filename in filenames:
        dests = []
        for regex, dest in map_regex2dest.items():
            if regex.search(filename):
                dests.append(dest)
        if len(dests) == 0:
            raise ValueError("no destination found for %s" % filename)
        elif len(dests) > 1:
            raise ValueError(
                "multiple destinations found for %s: %s " %
                (filename, dests))

        dest = dests[0]
        # implement suffix mapping, note that
        # suffixes can extend beyond an extension
        for suffix, new_suffix in map_suffix2dest.items():
            if filename.endswith(suffix):
                if map_suffix2dest in suffix:
                    dest = dest + map_suffix2dest[suffix]
                    break

        dest2src[dest].append(filename)

    for dest, srcs in sorted(dest2src.iteritems()):
        E.info("merging: %s <- %s" % (dest, srcs))
        if options.dry_run:
            continue
        E.run('cat %s > %s' % (" ".join(srcs),
                               dest))

    # write footer and output benchmark information.
    E.Stop()
dataset/ETHPy150Open CGATOxford/cgat/scripts/combine_files.py/main/swapped operands of `in`