def __call__(self, seq_path=None, result_path=None, log_path=None): """Returns a dict mapping {seq_id:(taxonomy, confidence)} for each seq Keep in mind, "confidence" is only done for consistency and in fact all assignments will have a score of 0 because a method for determining confidence is not currently implemented. Parameters: seq_path: path to file of sequences. The sequences themselves are never actually used, but they are needed for their ids. result_path: path to file of results. If specified, dumps the result to the desired path instead of returning it. log_path: path to log, which should include dump of params. """ # initialize the logger logger = self._get_logger(log_path) logger.info(str(self)) with open(seq_path, 'U') as f: seqs = dict(MinimalFastaParser(f)) consensus_map = tax2tree.prep_consensus( open(self.Params['id_to_taxonomy_fp']), seqs.keys()) seed_con = consensus_map[0].strip().split('\t')[1] determine_rank_order(seed_con) tipnames_map = load_consensus_map(consensus_map, False) tree = load_tree(open(self.Params['tree_fp']), tipnames_map) results = tax2tree.generate_constrings(tree, tipnames_map) results = tax2tree.clean_output(results, seqs.keys()) if result_path: # if the user provided a result_path, write the # results to file with open(result_path, 'w') as f: for seq_id, (lineage, confidence) in results.iteritems(): f.write('%s\t%s\t%s\n' % (seq_id, lineage, confidence)) logger.info('Result path: %s' % result_path) return results
def __call__(self, seq_path=None, result_path=None, log_path=None): """Returns a dict mapping {seq_id:(taxonomy, confidence)} for each seq Keep in mind, "confidence" is only done for consistency and in fact all assignments will have a score of 0 because a method for determining confidence is not currently implemented. Parameters: seq_path: path to file of sequences. The sequences themselves are never actually used, but they are needed for their ids. result_path: path to file of results. If specified, dumps the result to the desired path instead of returning it. log_path: path to log, which should include dump of params. """ # initialize the logger logger = self._get_logger(log_path) logger.info(str(self)) with open(seq_path, 'U') as f: seqs = dict(parse_fasta(f)) consensus_map = tax2tree.prep_consensus( open(self.Params['id_to_taxonomy_fp']), seqs.keys()) seed_con = consensus_map[0].strip().split('\t')[1] determine_rank_order(seed_con) tipnames_map = load_consensus_map(consensus_map, False) tree = load_tree(open(self.Params['tree_fp']), tipnames_map) results = tax2tree.generate_constrings(tree, tipnames_map) results = tax2tree.clean_output(results, seqs.keys()) if result_path: # if the user provided a result_path, write the # results to file with open(result_path, 'w') as f: for seq_id, (lineage, confidence) in results.iteritems(): f.write('%s\t%s\t%s\n' % (seq_id, lineage, confidence)) logger.info('Result path: %s' % result_path) return results