logfile.write("gaplen: " + str(gaplen) + "\n")
logfile.write("Ne at 1: " + str(ancnefn(t=1)) + "\n")
logfile.write("migprob at 1: " + str(migprobs(t=1)) + "\n")
logfile.write("chromosome ending positions: " +
              str(list(coal.chrpos) + [coal.chrlen]) + "\n")
logfile.write("\n")
logfile.write("Beginning ------------\n")

# here is where the action happens
for t in xrange(ngens):
    logfile.write("  t=" + str(t) + "\n")
    if t % 10 == 0:
        logfile.write("    census (num segments, num indivs): " +
                      str(coal.census(pop, sampsizes=sampsizes)) + "\n")
    logfile.flush()
    coal.parents(pop, ancne=ancnefn(t), migprobs=migprobs(t), t=t)
    if _exitnow:
        # there's been a ctrl-c; stop now.
        break

logfile.write("    census (num indivs, num segments): " +
              str(coal.census(pop, sampsizes=sampsizes)) + "\n")
logfile.write("Done with simulation at " +
              time.strftime("%d %h %Y %H:%M:%S", time.localtime()) +
              "; now writing out IBD info.\n")

coal.writeibd(pop, minlen=minlen, gaplen=gaplen, outfile=ibdfile)
# writecoal(ibdict,outfile=coalfile)
# pdb.set_trace()

logfile.write("\n")
logfile.write("sampsizes: " + str(sampsizes)+"\n")
logfile.write("minlen: " + str(minlen)+"\n")
logfile.write("gaplen: " + str(gaplen)+"\n")
logfile.write("Ne at 1: " + str(ancnefn(t=1))+"\n")
logfile.write("migprob at 1: " + str(migprobs(t=1))+"\n")
logfile.write("chromosome ending positions: " + str(list(coal.chrpos)+[coal.chrlen]) + "\n")
logfile.write("\n")
logfile.write("Beginning ------------\n")

# here is where the action happens
for t in xrange(ngens):
    logfile.write("  t="+str(t)+"\n")
    if t%10==0:
        logfile.write("    census (num segments, num indivs): " + str(coal.census(pop,sampsizes=sampsizes))+ "\n")
    logfile.flush()
    coal.parents(pop,ancne=ancnefn(t),migprobs=migprobs(t),t=t)
    if _exitnow:
        # there's been a ctrl-c; stop now.
        break

logfile.write("    census (num indivs, num segments): " + str(coal.census(pop,sampsizes=sampsizes))+ "\n")
logfile.write("Done with simulation at " + time.strftime("%d %h %Y %H:%M:%S", time.localtime()) + "; now writing out IBD info.\n" )

coal.writeibd(pop,minlen=minlen,gaplen=gaplen,outfile=ibdfile)
# writecoal(ibdict,outfile=coalfile)
# pdb.set_trace()

logfile.write("\n")
logfile.write("Closing ibd file...\n")

ibdfile.close()
# ancne = dict(a=10,b=10)
def ancnefn(t):
    return dict(a=max(10,100-5*t),b=10)

coal.chrlens = ( 2.0, 1.0 )
coal.chrpos = tuple( [ sum( coal.chrlens[0:k] ) for k in range(1,len(coal.chrlens)) ] )   # cumulative sum: position if lined up end-to-end
coal.chrlen = sum(coal.chrlens)  # the last one (total length)

start = time.time()

pop = coal.initpop(sampsizes)
ibdict = {}
poplist = []
for t in xrange(20):
    print " ----", t
    coal.parents(pop,t=t,ibdict=ibdict,migprobs=migprobs,ancne=ancnefn(t))
    coal.sanity(pop,sampsizes=sampsizes,ancne=ancnefn(t),print_details=True)
    coal.writeibd(pop,minlen=0.0,gaplen=0.0,filename="test-fibd-"+("%(t)02d" % {'t':t})+".gz")
    poplist.append( copy.deepcopy(pop) )

print time.time()-start

# run this to look at the above.
rscript <- '''
source("~/projects/genome/ibd-blocks-fns.R")
fnames <- list.files(".","test-fibd-[0-9]*.gz")
.chrlens <- c(2,1)
.chrstarts <- c(0,2,3)

ibd <- lapply( fnames, read.table, header=TRUE )
for (k in seq_along(ibd)) {
Beispiel #4
0

coal.chrlens = (2.0, 1.0)
coal.chrpos = tuple([
    sum(coal.chrlens[0:k]) for k in range(1, len(coal.chrlens))
])  # cumulative sum: position if lined up end-to-end
coal.chrlen = sum(coal.chrlens)  # the last one (total length)

start = time.time()

pop = coal.initpop(sampsizes)
ibdict = {}
poplist = []
for t in xrange(20):
    print " ----", t
    coal.parents(pop, t=t, ibdict=ibdict, migprobs=migprobs, ancne=ancnefn(t))
    coal.sanity(pop, sampsizes=sampsizes, ancne=ancnefn(t), print_details=True)
    coal.writeibd(pop,
                  minlen=0.0,
                  gaplen=0.0,
                  filename="test-fibd-" + ("%(t)02d" % {
                      't': t
                  }) + ".gz")
    poplist.append(copy.deepcopy(pop))

print time.time() - start

# run this to look at the above.
rscript < - '''
source("~/projects/genome/ibd-blocks-fns.R")
fnames <- list.files(".","test-fibd-[0-9]*.gz")