def main(): args = parse_args() global CONFIG prophyle_conf_string = pro.load_prophyle_conf(CONFIG, args.config) try: assign_all_reads( tree_fn=args.tree_fn, inp_fo=args.input_file, form=args.format, k=args.k, measure=args.measure, annotate=args.annotate, tie_lca=args.tie_lca, kmer_lca=args.kmer_lca, ) # Karel: I don't remember why I was considering also IOError here # except (BrokenPipeError, IOError): except BrokenPipeError: # pipe error (e.g., when head is used) sys.stderr.close() sys.stdout.close() exit(0) except KeyboardInterrupt: pro.message("Error: Keyboard interrupt") pro.close_log() exit(1) finally: try: sys.stdout.flush() except BrokenPipeError: pass finally: try: sys.stderr.flush() except: pass
def main(): try: par = parser() args = par.parse_args() subcommand = args.subcommand global CONFIG prophyle_conf_string = pro.load_prophyle_conf(CONFIG, args.config) if subcommand == "download": pro.open_log(args.log_fn) for single_lib in args.library: pro.message('Downloading "{}" started'.format(single_lib)) prophyle_download( library=single_lib, library_dir=args.home_dir, force=args.force, ) pro.message('Downloading "{}" finished'.format(single_lib)) pro.close_log() elif subcommand == "index": if args.library_dir is None: library_dir = os.path.dirname(args.tree[0]) else: library_dir = args.library_dir if args.log_fn is None: args.log_fn = os.path.join(args.index_dir, "log.txt") pro.open_log(args.log_fn) pro.message('Index construction started') prophyle_index( index_dir=args.index_dir, threads=args.threads, k=args.k, trees_fn=args.tree, library_dir=library_dir, force=args.force, construct_klcp=args.klcp, no_prefixes=args.no_prefixes, mask_repeats=args.mask_repeats, keep_tmp_files=args.keep_tmp_files, sampling_rate=args.sampling_rate, autocomplete=args.autocomplete, ) pro.message('Index construction finished') pro.close_log() elif subcommand == "classify": # if args.log_fn is None: # args.log_fn = os.path.join(args.index_dir, "log.txt") pro.open_log(args.log_fn) pro.message('Classification started') prophyle_classify( index_dir=args.index_dir, fq_fn=args.reads, fq_pe_fn=args.reads_pe, k=args.k, out_format=args.oform, mimic_kraken=args.mimic, measure=args.measure, tie_lca=args.tie_lca, kmer_lca=args.kmer_lca, annotate=args.annotate, print_seq=args.print_seq, cimpl=args.cimpl, force_restarted_search=args.force_restarted_search, prophyle_conf_string=prophyle_conf_string, # already preprocessed ) pro.message('Classification finished') pro.close_log() elif subcommand == "analyze": prophyle_analyze( index_dir=args.index_dir, out_prefix=args.out_prefix, input_fns=args.input_fns, stats=args.stats, in_format=args.in_format, ) elif subcommand == "compress": if args.archive is None: archive = args.index_dir.rstrip("/") + ".tar.gz" else: archive = args.archive prophyle_compress( index_dir=args.index_dir, archive=archive, ) elif subcommand == "decompress": prophyle_decompress( archive=args.archive, output_dir=args.output_dir, klcp=args.klcp, ) elif subcommand == "compile": prophyle_compile( clean=args.clean, parallel=args.parallel, force=args.force, ) else: msg_lns = par.format_help().split("\n")[2:] msg_lns = [x for x in msg_lns if x.find("optional arguments") == -1 and x.find("--") == -1] msg = "\n".join(msg_lns) msg = msg.replace("\n\n", '\n').replace("subcommands:\n", "Command:\n").replace("Usage", "\nUsage") msg = msg.replace("\n compress", "\n\n compress") print(file=sys.stderr) print(msg, file=sys.stderr) sys.exit(2) except BrokenPipeError: # pipe error (e.g., when head is used) sys.stderr.close() sys.stdout.close() exit(0) except KeyboardInterrupt: pro.message("Error: Keyboard interrupt") pro.close_log() exit(1) finally: sys.stdout.flush() sys.stderr.flush()
histogram, unique_histogram = compute_histogram(tree, asgs, args.stats) otu_table = compute_otu_table(histogram, tree) with open(args.out_prefix + '.rawhits.tsv', 'w') as f: if args.stats.startswith('w'): print_histogram(histogram, f, tree) elif unique_histogram is not None: print_histogram(unique_histogram, f, tree) with open(args.out_prefix + '.otu.tsv', 'w') as f: print_histogram(otu_table, f, tree) with open(args.out_prefix + '.kraken.tsv', 'w') as f: tot_count = print_kraken_report(otu_table, histogram, unclassified, tree, f) with open(args.out_prefix + '.metaphlan.tsv', 'w') as f: print_metaphlan_report(otu_table, tot_count, tree, f) with open(args.out_prefix + '.centrifuge.tsv', 'w') as f: print_centrifuge_report(otu_table, histogram, unique_histogram, tree, f) if __name__ == "__main__": try: main() except BrokenPipeError: # pipe error (e.g., when head is used) sys.stderr.close() exit(0) except KeyboardInterrupt: pro.message("Error: Keyboard interrupt") pro.close_log() exit(1)