from optparse import OptionParser parser = OptionParser(description=description) parser.add_option("-b","--ibdfile",dest="ibdfile",help="name of file to read ibd from (or '-' for stdin)",default="-") parser.add_option("-o","--outfile",dest="outfile",help="name of file to output merged ibd from (or '-' for stdout)",default="-") parser.add_option("-g","--gaplen",dest="gaplen",help="merge blocks separated by a block no longer than this long (in MORGANS)", default=0.0) parser.add_option("-c","--chromfile",dest="chromfile",help="file to parse chromosome lengths from (e.g. logfile for that run)", default=None) (options,args) = parser.parse_args() # size of maximum gap to merge gapthresh = float(options.gaplen) # find chromosome lengths try: if options.chromfile is None: chromfile = coal.fileopt( re.sub("\.fibd\.gz$",".log",options.ibdfile), "r") else: chromfile = coal.fileopt(options.chromfile,"r") except: raise ValueError("Invalid chromfile specification.") for line in chromfile: if line.startswith("chromosome ending positions:"): chrends = eval( line[28:].strip() ) break try: chrstartends = zip( [0.0]+chrends[:-1], chrends ) except NameError: raise ValueError("Can't find 'chromosome ending positions:' in chromfile.")
dest="minlen", help= "minimum length of IBD block to record IN MORGANS (default value 0.005M = 0.5cM)", default=None) parser.add_option( "-g", "--gaplen", dest="gaplen", help= "gap length, IN MORGANS: blocks closer together than this will be recorded even if shorter than minlen (default value 0.5M = 50cM)", default=None) (options, args) = parser.parse_args() # read in parameters etc if options.infile is not None: infile = coal.fileopt(options.infile, "r") inparams = infile.read() exec(inparams) # command line options supercede statements in infile ibdfile = coal.fileopt(options.ibdfile, "w") # coalfile = coal.fileopt(options.coalfile, "w") logfile = coal.fileopt(options.logfile, "w") ngens = int(options.ngens) if options.nesize is not None: ancnefn = lambda t: {}.fromkeys(pop.keys(), int(options.nesize)) else: try: if type(ancnefn) == type({}): ancnefn = lambda t: ancnefn
import coalpedigree as cp parser = OptionParser(description=description) parser.add_option("-b","--ibdfile",dest="ibdfile",help="name of file to read ibd from (or '-' for stdout)",default="-") parser.add_option("-o","--outfile",dest="outfile",help="name of output ibd file (or '-' for stdin)") parser.add_option("-l","--logfile",dest="logfile",help="name of log file (or '-' for stdout)",default="-") parser.add_option("-n","--minminlen",dest="minminlen",help="totally ignore any blocks shorter than this length", default=0.0) parser.add_option("-g","--gaplen",dest="gaplen",help="merge blocks separated by a block no longer than this long", default=0.0) parser.add_option("-m","--minlen",dest="minlen",help="only keep any blocks (including merged ones) at least this long", default=0.0) (options,args) = parser.parse_args() minminlen = float(options.minminlen) gaplen = float(options.gaplen) minlen = float(options.minlen) ibdfile = cp.fileopt(options.ibdfile, "r") outfile = cp.fileopt(options.outfile, "w") logfile = cp.fileopt(options.logfile, "w") results = {} # results is a dict indexed by pairs of ids # with entries a list of [start,end,nsegs] logfile.write("winnow.py: "+options.ibdfile+"\n") logfile.write("writing to " + options.outfile + "\n") logfile.write("totally ignoring blocks below: " + str(minminlen) + "\n") logfile.write("merging closer than gaplen: " + str(gaplen) + "\n") logfile.write("outputting merged blocks longer than: " + str(minlen) + "\n") nin = 0 nskip = 0
# parser.add_option("-c","--coalfile",dest="coalfile",help="name of file to write final coalescent info to (or '-' for stdout)",default="-") parser.add_option("-b","--ibdfile",dest="ibdfile",help="name of file to write final ibd blocks to (or '-' for stdout)",default="-") parser.add_option("-l","--logfile",dest="logfile",help="name of log file (or '-' for stdout)",default="-") parser.add_option("-i","--infile",dest="infile",help="name of input file to get parameters from (or '-' for stdin)") parser.add_option("-t","--ngens",dest="ngens",help="total number of generations to simulate",default="10") parser.add_option("-n","--nesize",dest="nesize",help="effective population size") parser.add_option("-m","--migprob",dest="migprob",help="migration probability") parser.add_option("-s","--samplesizes",dest="sampsizes",help="sample sizes") parser.add_option("-e","--minlen",dest="minlen",help="minimum length of IBD block to record IN MORGANS (default value 0.005M = 0.5cM)",default=None) parser.add_option("-g","--gaplen",dest="gaplen",help="gap length, IN MORGANS: blocks closer together than this will be recorded even if shorter than minlen (default value 0.5M = 50cM)",default=None) (options,args) = parser.parse_args() # read in parameters etc if options.infile is not None: infile = coal.fileopt(options.infile,"r") inparams = infile.read() exec(inparams) # command line options supercede statements in infile ibdfile = coal.fileopt(options.ibdfile, "w") # coalfile = coal.fileopt(options.coalfile, "w") logfile = coal.fileopt(options.logfile, "w") ngens = int(options.ngens) if options.nesize is not None: ancnefn = lambda t: {}.fromkeys(pop.keys(),int(options.nesize)) else: try: if type(ancnefn) == type({}): ancnefn = lambda t: ancnefn
dest="gaplen", help="merge blocks separated by a block no longer than this long", default=0.0) parser.add_option( "-m", "--minlen", dest="minlen", help="only keep any blocks (including merged ones) at least this long", default=0.0) (options, args) = parser.parse_args() minminlen = float(options.minminlen) gaplen = float(options.gaplen) minlen = float(options.minlen) ibdfile = cp.fileopt(options.ibdfile, "r") outfile = cp.fileopt(options.outfile, "w") logfile = cp.fileopt(options.logfile, "w") results = {} # results is a dict indexed by pairs of ids # with entries a list of [start,end,nsegs] logfile.write("winnow.py: " + options.ibdfile + "\n") logfile.write("writing to " + options.outfile + "\n") logfile.write("totally ignoring blocks below: " + str(minminlen) + "\n") logfile.write("merging closer than gaplen: " + str(gaplen) + "\n") logfile.write("outputting merged blocks longer than: " + str(minlen) + "\n") nin = 0 nskip = 0
default=0.0) parser.add_option( "-c", "--chromfile", dest="chromfile", help="file to parse chromosome lengths from (e.g. logfile for that run)", default=None) (options, args) = parser.parse_args() # size of maximum gap to merge gapthresh = float(options.gaplen) # find chromosome lengths try: if options.chromfile is None: chromfile = coal.fileopt( re.sub("\.fibd\.gz$", ".log", options.ibdfile), "r") else: chromfile = coal.fileopt(options.chromfile, "r") except: raise ValueError("Invalid chromfile specification.") for line in chromfile: if line.startswith("chromosome ending positions:"): chrends = eval(line[28:].strip()) break try: chrstartends = zip([0.0] + chrends[:-1], chrends) except NameError: raise ValueError("Can't find 'chromosome ending positions:' in chromfile.") results = {}