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

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

    if argv is None:
        argv = sys.argv

    parser = E.OptionParser(
        version="%prog version: $Id")

    parser.add_option("-e", "--header-names", dest="headers", action="store_true",
                      help="first row is a header [ignored].")
    parser.add_option("-t", "--title", dest="title", type="string",
                      help="page title.")
    parser.add_option("-f", "--footer", dest="footer", type="string",
                      help="page footer.")
    parser.add_option("--maxP", dest="max_pvalue", type="float",
                      help="maximum P-value displayed [default=%default].")
    parser.add_option("--maxQ", dest="max_qvalue", type="float",
                      help="maximum Q-value for controlling for FDR [default=%default].")
    parser.add_option("-c", "--column-titles", dest="col_names", type="string",
                      help="comma separated list of column titles [default: use filenames].")
    parser.add_option("-p", "--pattern-filename", dest="pattern_filename", type="string",
                      help="pattern to map columns to filename.")
    parser.add_option("-A", "--Annotator", dest="annotator", action="store_true",
                      help="use Annotator-style input files.")
    parser.add_option("--annotator-fdr", dest="annotator_fdr", action="store_true",
                      help="use fdr computed from annotator [default=%default].")
    parser.add_option("-T", "--thresholds", dest="thresholds", type="string",
                      help="7 comma-separated fold-change threshold values")
    parser.add_option("-P", "--pvalues", dest="pvalues", type="string",
                      help="6 comma-separated p value threshold values"),
    parser.add_option("-C", "--altcolours", dest="altcolours", action="store_true",
                      help="Use alternative colour palette")
    parser.add_option("-X", "--delimiters", dest="delims", type="string",
                      help="Delimiter characters for annotation label")
    parser.add_option("-Z", "--ignore", dest="ignore", type="string",
                      help="Ignored characters in annotation label")
    parser.add_option("--fdr", dest="fdr", type="float",
                      help="filter output by FDR (requires annotator output). [default=%default]")
    parser.add_option("-a", "--template", dest="template", type="choice",
                      choices=("screen", "publication"),
                      help="layout template to choose - affects colours.")
    parser.add_option("--sort-columns", dest="sort_columns", type="choice",
                      choices=("unsorted", "similarity", "alphabetical", ),
                      help="sort columns. The default, unsorted, list columns in the order that they are supplied on the command line [default=%default]")

    parser.set_defaults(
        sortAlphabetically=True,
        headers=False,
        col_names="",
        pattern_filename=None,
        title="",
        footer="",
        max_pvalue=None,
        max_qvalue=None,
        annotator=False,
        thresholds="0.25,0.33,0.5,1.0,2.0,3.0,4.0",
        pvalues="0.00001,0.0001,0.001,0.01,0.1",
        altcolours=False,
        delims="",
        ignore="",
        template="screen",
        annotator_fdr=False,
        fdr=None,
        sort_columns="unsorted",
    )

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

    if len(args) == 0:
        raise IOError("Please supply at least one input file.")

    if options.pattern_filename:
        input = []
        col_names = args
        for x in col_names:
            input.append(options.pattern_filename % x)
    else:
        input = args

        if options.col_names:
            col_names = options.col_names.split(",")
            if len(col_names) != len(input):
                raise ValueError(
                    "Number of col_names and files different: %i != %i" %
                    (len(col_names), len(input)))
        else:
            col_names = input

    E.info("reading data for %i columns" % len(input))

    columns = []
    errors = []

    for col_name, filename in zip(col_names, input):

        E.debug("reading data for column %s from %s " % (col_name, filename))
        # collect all columns
        try:
            values, nremoved, no_fdr = Collect(
                open(filename, "r"),
                with_headers=options.headers,
                annotator_format=options.annotator,
                delims=options.delims,
                ignore=options.ignore,
                use_annotator_fdr=options.annotator_fdr,
                max_pvalue=options.max_pvalue,
                max_qvalue=options.max_qvalue)
        except __HOLE__:
            E.warn("no data from %s" % filename)
            values = []
            no_fdr = False
            nremoved = 0

        E.info("read %i values from %s: %i significant, %i removed" %
               (len(values) + nremoved, filename,
                len(values),
                nremoved))
        columns.append((col_name, values))
        errors.append(no_fdr)

    if sum([len(x) for x in columns]) == 0:
        raise IOError("no data read - please check supplied files.")

    # collect all annotations
    # Also filter for max pvalue
    annotations = set()
    for col_name, column in columns:
        for d in column:
            annotations.add(d.mAnnotation)

    E.info("There are %i rows" % len(annotations))

    # sort and filter annotations
    # (Code removed which did some filtering; the annotations data is not used)
    # By removing labels from annlist you can select the annotations you want
    # to display
    row_names = list(annotations)
    if options.sortAlphabetically:
        row_names.sort()

    if options.sort_columns == "unsorted":
        pass
    elif options.sort_columns == "alphabetical":
        col_names.sort()
    elif options.sort_columns == "similarity":
        if len(row_names) * len(col_names) > 10000:
            E.info("no sorting as matrix too large")
        else:
            matrix = numpy.ones((len(row_names), len(col_names)), numpy.float)
            map_rows = dict(zip(row_names, range(len(row_names))))
            x = 0
            for col_name, column in columns:
                for d in column:
                    matrix[map_rows[d.mAnnotation], x] = d.mFoldChange
                x += 1
            row_indices, col_indices = CorrespondenceAnalysis.GetIndices(
                matrix)
            map_row_new2old = numpy.argsort(row_indices)
            map_col_new2old = numpy.argsort(col_indices)
            row_names = [row_names[map_row_new2old[x]]
                         for x in range(len(row_names))]
            col_names = [col_names[map_col_new2old[x]]
                         for x in range(len(col_names))]

    E.info("columns have been sorted")

    plot = GoPlot(row_names,
                  col_names,
                  thresholds_size=tuple(
                      map(float, options.pvalues.split(','))),
                  thresholds_colour=tuple(
                      map(float, options.thresholds.split(','))),
                  template=options.template,
                  alt_colours=options.altcolours,
                  max_pvalue=options.max_pvalue,
                  max_qvalue=options.max_qvalue,
                  mark_columns=errors)

    if options.title:
        plot.setTitle(options.title)
    if options.footer:
        plot.setFooter(options.footer)

    plot.initializePlot()

    for col_name, column in columns:
        for d in column:
            plot.addValue(d.mAnnotation,
                          col_name,
                          d.mPValue,
                          d.mFoldChange)

    plot.writeToFile(options.stdout)

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