Example #1
0
def sanity_check():
    G = 10000
    config = [G/2]
    mfl = 250
    lamb = 1.0/mfl
    num_frags = 10000
    frags = concat([chip(G,config,mfl) for i in xrange(num_frags)])
    min_seq_length = 75
    sequenced_frags = filter(lambda (start,stop):stop - start > min_seq_length,frags)
    fd_frags,bk_frags = separate(lambda x:random.random() < 0.5,sequenced_frags)
    fd_reads = [('+',start,start+min_seq_length) for (start,stop) in fd_frags]
    bk_reads = [('-',stop-min_seq_length,stop) for (start,stop) in bk_frags]
    reads = fd_reads + bk_reads
    inferred_frags = exp_reconstruction(reads,lamb,G)
    plot_reads(reads,G=G)
    plt.plot(frag_density(frags,G=G),label="all frags")
    plt.plot(frag_density(sequenced_frags,G=G),label="seq frags")
    plt.plot((inferred_frags),label="inferred frags")
    plt.legend()
Example #2
0
def recovery():
    G = 10000
    config = [G/2]
    mfl = 250
    lamb = 1/float(mfl)
    num_frags = 1000
    frags = concat([chip(G,config,mfl) for i in xrange(num_frags)])
    min_seq_length = 75
    sequenced_frags = filter(lambda (start,stop):stop - start > min_seq_length,frags)
    fd_frags,bk_frags = separate(lambda x:random.random() < 0.5,sequenced_frags)
    fd_reads = [('+',start,start+75) for (start,stop) in fd_frags]
    bk_reads = [('-',stop-75,stop) for (start,stop) in bk_frags]
    reads = fd_reads + bk_reads
    hyp0 = [int(random.random() < 0.5) for i in range(G)]
    def f(hyp):
        return log_likelihood(reads,hyp,lamb,G)
    def prop(hyp):
        i = random.randrange(G)
        hyp_copy = hyp[:]
        hyp_copy[i] = 1 - hyp_copy[i]
        return hyp_copy
    chain = mh(f,prop,hyp0,use_log=True,verbose=True)