def main(): logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") parser = argparse.ArgumentParser() parser.add_argument("-p", dest="num_processes", type=int, default=1) parser.add_argument("--pattern", dest="pattern", default=r'{{CHROM}}.phastCons46way.bw') parser.add_argument('--window-sizes', dest='window_sizes', default='30,60,90,150,300,600,900,1500,3000') parser.add_argument('--bed', dest='bed_file', default=None) parser.add_argument("bigwig_file_dir") args = parser.parse_args() if which(BIGWIG_TO_BEDGRAPH_BIN) is None: parser.error('bigWigToBedGraph binary not found in PATH') if args.bed_file is not None: if not os.path.exists(args.bed_file): parser.error('bed file %s not found' % (args.bed_file)) else: parser.error('specify a bed file using --bed') window_sizes = map(int, args.window_sizes.split(',')) num_processes = max(1, args.num_processes) # find bigwig files chrom_bigwig_dict = find_bigwig_files(args.bigwig_file_dir, args.pattern) if num_processes > 1: conservation_parallel(args.bed_file, window_sizes, chrom_bigwig_dict, num_processes) else: conservation_serial(args.bed_file, window_sizes, chrom_bigwig_dict) return 0
def main(): # parse command line parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False) parser.add_argument('-p', '--num-processes', type=int, dest='num_processes', default=1) parser.add_argument("--pattern", dest="pattern", default=r'{{CHROM}}.phyloP46way.bw') parser.add_argument("bigwig_file_dir") parser.add_argument("bed_file") args = parser.parse_args() # set logging level if args.verbose: level = logging.DEBUG else: level = logging.INFO logging.basicConfig( level=level, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") # check command line parameters if which(BIGWIG_TO_BEDGRAPH_BIN) is None: parser.error('bigWigToBedGraph binary not found in PATH') if not os.path.exists(args.bed_file): parser.error("BED file %s not found" % (args.bed_file)) prefix = os.path.splitext(args.bed_file)[0] results_file = prefix + '.results.txt' hists_file = prefix + '.hists.npz' # find bigwig files logging.info("Indexing bigWig files") chrom_bigwig_dict = find_bigwig_files(args.bigwig_file_dir, args.pattern) # process bed file logging.info("Measuring conservation") if args.num_processes > 1: conservation_parallel(args.bed_file, chrom_bigwig_dict, args.num_processes, results_file, hists_file) else: hists = collections.defaultdict( lambda: np.zeros(NUM_BINS - 1, dtype=np.float)) with open(results_file, 'w') as outfile: for f in BEDFeature.parse(open(args.bed_file)): fields = bed_feature_conservation(f, chrom_bigwig_dict, hists) print >> outfile, '\t'.join(fields) np.savez(hists_file, **hists) return 0
def main(): # parse command line parser = argparse.ArgumentParser() parser.add_argument("-v", "--verbose", action="store_true", dest="verbose", default=False) parser.add_argument('-p', '--num-processes', type=int, dest='num_processes', default=1) parser.add_argument("--pattern", dest="pattern", default=r'{{CHROM}}.phyloP46way.bw') parser.add_argument("bigwig_file_dir") parser.add_argument("bed_file") args = parser.parse_args() # set logging level if args.verbose: level = logging.DEBUG else: level = logging.INFO logging.basicConfig(level=level, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s") # check command line parameters if which(BIGWIG_TO_BEDGRAPH_BIN) is None: parser.error('bigWigToBedGraph binary not found in PATH') if not os.path.exists(args.bed_file): parser.error("BED file %s not found" % (args.bed_file)) prefix = os.path.splitext(args.bed_file)[0] results_file = prefix + '.results.txt' hists_file = prefix + '.hists.npz' # find bigwig files logging.info("Indexing bigWig files") chrom_bigwig_dict = find_bigwig_files(args.bigwig_file_dir, args.pattern) # process bed file logging.info("Measuring conservation") if args.num_processes > 1: conservation_parallel(args.bed_file, chrom_bigwig_dict, args.num_processes, results_file, hists_file) else: hists = collections.defaultdict(lambda: np.zeros(NUM_BINS-1, dtype=np.float)) with open(results_file, 'w') as outfile: for f in BEDFeature.parse(open(args.bed_file)): fields = bed_feature_conservation(f, chrom_bigwig_dict, hists) print >>outfile, '\t'.join(fields) np.savez(hists_file, **hists) return 0