def batchseeds(args): """ %prog batchseeds folder Extract seed metrics for each image in a directory. """ from jcvi.formats.pdf import cat xargs = args[1:] p = OptionParser(batchseeds.__doc__) opts, args, iopts = add_seeds_options(p, args) if len(args) != 1: sys.exit(not p.print_help()) folder, = args folder = folder.rstrip('/') outdir = folder + "-debug" outfile = folder + "-output.tsv" assert op.isdir(folder) images = [] jsonfile = opts.calibrate or op.join(folder, "calibrate.json") if not op.exists(jsonfile): jsonfile = None for im in iglob(folder, "*.jpg", "*.JPG", "*.png"): if im.endswith(".resize.jpg") or \ im.endswith(".main.jpg") or \ im.endswith(".label.jpg"): continue if op.basename(im).startswith("calibrate"): continue images.append(im) fw = must_open(outfile, 'w') print >> fw, Seed.header(calibrate=jsonfile) nseeds = 0 for im in images: imargs = [im, "--noheader", "--outdir={0}".format(outdir)] + xargs if jsonfile: imargs += ["--calibrate={0}".format(jsonfile)] objects = seeds(imargs) for o in objects: print >> fw, o nseeds += len(objects) fw.close() logging.debug("Processed {0} images.".format(len(images))) logging.debug("A total of {0} objects written to `{1}`.".\ format(nseeds, outfile)) pdfs = iglob(outdir, "*.pdf") outpdf = folder + "-output.pdf" cat(pdfs + ["--outfile={0}".format(outpdf)]) logging.debug("Debugging information written to `{0}`.".format(outpdf)) return outfile
def batchseeds(args): """ %prog batchseeds folder Extract seed metrics for each image in a directory. """ from jcvi.formats.pdf import cat xargs = args[1:] p = OptionParser(batchseeds.__doc__) opts, args, iopts = add_seeds_options(p, args) if len(args) != 1: sys.exit(not p.print_help()) folder, = args folder = folder.rstrip('/') outdir = folder + "-debug" outfile = folder + "-output.tsv" assert op.isdir(folder) images = [] jsonfile = opts.calibrate or op.join(folder, "calibrate.json") if not op.exists(jsonfile): jsonfile = None for im in iglob(folder, "*.jpg,*.JPG,*.png"): if im.endswith(".resize.jpg") or \ im.endswith(".main.jpg") or \ im.endswith(".label.jpg"): continue if op.basename(im).startswith("calibrate"): continue images.append(im) fw = must_open(outfile, 'w') print >> fw, Seed.header(calibrate=jsonfile) nseeds = 0 for im in images: imargs = [im, "--noheader", "--outdir={0}".format(outdir)] + xargs if jsonfile: imargs += ["--calibrate={0}".format(jsonfile)] objects = seeds(imargs) for o in objects: print >> fw, o nseeds += len(objects) fw.close() logging.debug("Processed {0} images.".format(len(images))) logging.debug("A total of {0} objects written to `{1}`.".\ format(nseeds, outfile)) pdfs = iglob(outdir, "*.pdf") outpdf = folder + "-output.pdf" cat(pdfs + ["--outfile={0}".format(outpdf)]) logging.debug("Debugging information written to `{0}`.".format(outpdf)) return outfile