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() logfile.write("All done at " + time.strftime("%d %h %Y %H:%M:%S", time.localtime()) + "\n") # coalfile.close() logfile.close()
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() logfile.write("All done at " + time.strftime("%d %h %Y %H:%M:%S", time.localtime()) + "\n" ) # coalfile.close() logfile.close()
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)) { ibd[[k]]$chrom <- findInterval( ibd[[k]]$start, .chrstarts, rightmost.closed=TRUE ) tmp <- length(.chrstarts) - findInterval( -ibd[[k]]$end, rev(-.chrstarts), rightmost.closed=TRUE )
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)) {