def main(argv=None):
    if argv is None:
        argv = sys.argv

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

    parser.add_option("-s", "--ignore-strand", dest="ignore_strand",
                      action="store_true",
                      help="ignore strand information [default=%default].")

    parser.add_option(
        "-u", "--update", dest="filename_update", type="string",
        help="if filename is given, previous results will be read"
        "from there and only changed sets will be computed "
        "[default=%default].")

    parser.add_option(
        "-p", "--pattern-identifier", dest="pattern_id", type="string",
        help="pattern to convert a filename to an id"
        "[default=%default].")

    parser.add_option(
        "-g", "--output-only-genes", dest="output_only_genes",
        action="store_true",
        help="only output gene stats (includes gene lists)"
        " [default=%default].")

    parser.set_defaults(
        ignore_strand=False,
        filename_update=None,
        pattern_id="(.*).gtf",
        output_only_genes=False,
    )

    (options, args) = E.Start(parser)

    if len(args) < 2:
        print USAGE
        raise ValueError("at least two arguments required")

    if options.filename_update:
        infile = open(options.filename_update, "r")
        previous_results = {}
        for line in infile:
            if line.startswith("#"):
                continue
            if line.startswith("set1"):
                continue
            data = line[:-1].split("\t")
            set1, set2 = data[0], data[1]

            if set1 not in previous_results:
                previous_results[set1] = {}
            if set2 not in previous_results:
                previous_results[set2] = {}

            previous_results[set1][set2] = "\t".join(data[2:])
            rev = [(data[x + 1], data[x]) for x in range(2, len(data), 2)]
            previous_results[set2][set1] = "\t".join(IOTools.flatten(rev))
    else:
        previous_results = {}

    if options.output_only_genes:
        counter = CounterGenes()
    else:
        counter = Counter()

    options.stdout.write("set1\tset2\t%s\n" % counter.getHeader())

    pattern_id = re.compile(options.pattern_id)

    def getTitle(x):
        try:
            return pattern_id.search(x).groups()[0]
        except AttributeError:
            return x

    ncomputed, nupdated = 0, 0
    for x in range(len(args)):
        title1 = getTitle(args[x])
        for y in range(0, x):
            title2 = getTitle(args[y])
            if previous_results:
                try:
                    prev = previous_results[title1][title2]
                except __HOLE__:
                    pass
                else:
                    options.stdout.write(
                        "%s\t%s\t%s\n" % ((title1, title2, prev)))
                    nupdated += 1
                    continue

            counter.count(args[x], args[y])
            options.stdout.write(
                "%s\t%s\t%s\n" % ((title1, title2, str(counter))))
            ncomputed += 1

    E.info("nupdated=%i, ncomputed=%i" % (nupdated, ncomputed))

    E.Stop()
dataset/ETHPy150Open CGATOxford/cgat/scripts/diff_gtf.py/main