<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def simulate(args):
 """ %prog simulate test Simulate CLM and IDS files with given names. The simulator assumes several distributions: - Links are distributed uniformly across genome - Log10(link_size) are distributed normally - Genes are distributed uniformly """

    p = OptionParser(simulate.__doc__)
    p.add_option("--genomesize", default=10000000, type="int",
                 help="Genome size")
    p.add_option("--genes", default=1000, type="int",
                 help="Number of genes")
    p.add_option("--contigs", default=100, type="int",
                 help="Number of contigs")
    p.add_option("--coverage", default=10, type="int",
                 help="Link coverage")
    opts, args = p.parse_args(args)

    if len(args) != 1:
        sys.exit(not p.print_help())

    pf, = args
    GenomeSize = opts.genomesize
    Genes = opts.genes
    Contigs = opts.contigs
    Coverage = opts.coverage
    PE = 500
    Links = int(GenomeSize * Coverage / PE)

    # Simulate the contig sizes that sum to GenomeSize
    # See also:
    # <https://en.wikipedia.org/wiki/User:Skinnerd/Simplex_Point_Picking>
    ContigSizes, = np.random.dirichlet([1] * Contigs, 1) * GenomeSize
    ContigSizes = np.array(np.round_(ContigSizes, decimals=0), dtype=int)
    ContigStarts = np.zeros(Contigs, dtype=int)
    ContigStarts[1:] = np.cumsum(ContigSizes)[:-1]

    # Write IDS file
    idsfile = pf + ".ids"
    fw = open(idsfile, "w")
    print("#Contig\tRECounts\tLength", file=fw)
    for i, s in enumerate(ContigSizes):
        print("tig{:04d}\t{}\t{}".format(i, s / (4 ** 4), s), file=fw)
    fw.close()

    # Simulate the gene positions
    GenePositions = np.sort(np.random.random_integers(0,
                            GenomeSize - 1, size=Genes))
    write_last_and_beds(pf, GenePositions, ContigStarts)

    # Simulate links, uniform start, with link distances following 1/x, where x
    # is the distance between the links. As an approximation, we have links
    # between [1e3, 1e7], so we map from uniform [1e-7, 1e-3]
    LinkStarts = np.sort(np.random.random_integers(0, GenomeSize - 1,
                                                   size=Links))
    a, b = 1e-7, 1e-3
    LinkSizes = np.array(np.round_(1 / ((b - a) * np.random.rand(Links) + a),
                         decimals=0), dtype="int")
    LinkEnds = LinkStarts + LinkSizes

    # Find link to contig membership
    LinkStartContigs = np.searchsorted(ContigStarts, LinkStarts) - 1
    LinkEndContigs = np.searchsorted(ContigStarts, LinkEnds) - 1

    # Extract inter-contig links
    InterContigLinks = (LinkStartContigs != LinkEndContigs) & \
                       (LinkEndContigs != Contigs)
    ICLinkStartContigs = LinkStartContigs[InterContigLinks]
    ICLinkEndContigs = LinkEndContigs[InterContigLinks]
    ICLinkStarts = LinkStarts[InterContigLinks]
    ICLinkEnds = LinkEnds[InterContigLinks]

    # Write CLM file
    write_clm(pf, ICLinkStartContigs, ICLinkEndContigs,
              ICLinkStarts, ICLinkEnds,
              ContigStarts, ContigSizes)