def prune(args):
    from collections import defaultdict

    p = OptionParser(prune.__doc__)
    add_graph_options(p)
    opts, args = p.parse_args(args)

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

    bestedges, = args
    G = read_graph(bestedges, maxerr=opts.maxerr)
    reads_to_ctgs = parse_ctgs(bestedges, opts.frgctg)
    edges = defaultdict(int)
    r = defaultdict(int)
    for a, b, d in G.edges_iter(data=True):
        ua, ub = reads_to_ctgs.get(a), reads_to_ctgs.get(b)
        nn = (ua, ub).count(None)
        if nn == 0:
            if ua == ub:
                r["Same tigs"] += 1
            else:
                r["Diff tigs"] += 1
                if ua > ub:
                    ua, ub = ub, ua
                edges[(ua, ub)] += 1
        elif nn == 1:
            r["One null"] += 1
        else:
            assert nn == 2
            r["Two nulls"] += 1

    U = nx.Graph()
    difftigs = "diff_tigs.txt"
    neighbors = defaultdict(list)
    fw = open(difftigs, "w")
    for (ua, ub), count in edges.items():
        print >> fw, "\t".join((ua, ub, str(count)))
        U.add_edge(ua, ub, weight=count)
        neighbors[ua].append((ub, count))
        neighbors[ub].append((ua, count))
    fw.close()

    print >> sys.stderr, "[Unitig edge property]"
    for k, v in r.items():
        print >> sys.stderr, ": ".join((k, str(v)))
    print >> sys.stderr, "Total: {0}".format(sum(r.values()))

    print >> sys.stderr, "[Unitig degree distribution]"
    degrees = U.degree()
    degree_counter = Counter(degrees.values())
    for degree, count in sorted(degree_counter.items()):
        print >> sys.stderr, "{0}\t{1}".format(degree, count)

    # To find associative contigs, one look for a contig that is connected and
    # only connected to another single contig - and do that recursively until no
    # more contigs can be found
    associative = {}
    for ua, ubs in neighbors.items():
        if len(ubs) == 1:   # Only one neighbor
            ub, count = ubs[0]
            if count >= 2:  # Bubble
                associative[ua] = (ub, count)
    print >> sys.stderr, "A total of {0} associative contigs found"\
                        .format(len(associative))

    # Keep only one for mutual associative
    for ua, ub in associative.items():
        if ub in associative and ua < ub:
            print >> sys.stderr, ua, "mutually associative with", ub
            del associative[ub]
    print >> sys.stderr, "A total of {0} associative contigs retained"\
                        .format(len(associative))

    assids = "associative.ids"
    fw = open(assids, "w")
    for ua, (ub, count) in sorted(associative.items(), key=lambda x:(x[1], x[0])):
        print >> fw, "\t".join((ua, ub, str(count)))
    fw.close()
    logging.debug("Associative contigs written to `{0}`".format(assids))
Tests the _get_wechat_server_ips method.
dataset/ETHPy150Open tanghaibao/jcvi/assembly/ca.py/prune--crossover with--dataset/ETHPy150Open OctavianLee/Pywechat/tests/test_base.py/BasicTest.test_get_wechat_server_ips