<commit_before>#!/usr/bin/env python

__author__ = "<NAME>"
__copyright__ = "Copyright 2012, The QIIME Project"
__credits__ = ["<NAME>", "<NAME>", "<NAME>"]
__license__ = "GPL"
__version__ = "1.5.0-dev"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL>"
__status__ = "Development"

from itertools import izip
from qiime.util import parse_command_line_parameters, get_options_lookup, make_option, create_dir
from cogent.util.misc import create_dir
from taxcompare.generate_taxa_compare_table import generate_taxa_compare_table

options_lookup = get_options_lookup()

script_info={}
script_info['brief_description']="""Walks a file tree from a given root and compares the taxa summaries found."""
script_info['script_description'] = ""

script_info['script_usage']=[]

script_info['script_usage'].append(("", "", "%prog -h"))

script_info['output_description']="""A tab-delimited table showing Pearson's and Spearman's correalation between the expected (in the key files) and the actual (found within the root). There is a file for every level compared."""
script_info['required_options']=[\
 make_option('-r', '--root_dir',type="existing_dirpath",
        help='Path to the root of the output from multiple_assign_taxonomy.py'),\

 make_option('-k', '--key_dir',type="existing_dirpath",
        help='Path to file containing the expected results of the files in the output directory.')]

script_info['optional_options']=[\
 make_option('--output_dir', type="new_dirpath",
        help='Prefix for output files. If None is given, will print output.',
        default = None),\

 make_option('--levels', type="string",
        help='Comma-separated list of multiple_assign_taxonomy output levels to analyze. Numbers between 2 and 6 inclusive.'+\
        '[default: %default]',
        default = '2,3,4,5,6'),\

 make_option('--force', action='store_true',
	help='If true forces output directory creation even if the directory already exists.'+\
	'[default: %default]',
	default = False)]
script_info['version'] = __version__

def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if(opts.output_dir):
        create_dir(opts.output_dir, fail_on_exist=opts.force)

    levels = map(int, opts.levels.split(','))

    results = generate_taxa_compare_table(opts.root_dir, opts.key_dir, levels)

    for level, out_file in izip(levels, results):
        if(opts.output_dir):
            with open(opts.output_dir + '_L' + str(level) + '.txt', 'w') as f:
                datasets = sorted(out_file.keys())
                methods = set()
                for m in out_file.itervalues():
                    methods|= set(m.keys())
                methods = sorted(list(methods))
                f.write('P_S\t')
                f.write('\t'.join(methods)+'\n')
                for dataset in datasets:
                    f.write(dataset+'\t')
                    for method in methods:
                        try:
                            f.write(out_file[dataset][method][0] + "_" + out_file[dataset][method][1]+'\t')
                        except KeyError:
                            f.write('N/A'+'\t')#Don't have data for that set/method
                    f.write('\n')
        else:
            #Terminal output code here if wanted<commit_msg>Realized a mistake in directory creation. Should be fixed now.<commit_after>#!/usr/bin/env python

__author__ = "<NAME>"
__copyright__ = "Copyright 2012, The QIIME Project"
__credits__ = ["<NAME>", "<NAME>", "<NAME>"]
__license__ = "GPL"
__version__ = "1.5.0-dev"
__maintainer__ = "<NAME>node"
__email__ = "<EMAIL>"
__status__ = "Development"

from itertools import izip
from qiime.util import parse_command_line_parameters, get_options_lookup, make_option, create_dir
from cogent.util.misc import create_dir
from taxcompare.generate_taxa_compare_table import generate_taxa_compare_table

options_lookup = get_options_lookup()

script_info={}
script_info['brief_description']="""Walks a file tree from a given root and compares the taxa summaries found."""
script_info['script_description'] = ""

script_info['script_usage']=[]

script_info['script_usage'].append(("", "", "%prog -h"))

script_info['output_description']="""A tab-delimited table showing Pearson's and Spearman's correalation between the expected (in the key files) and the actual (found within the root). There is a file for every level compared."""
script_info['required_options']=[\
 make_option('-r', '--root_dir',type="existing_dirpath",
        help='Path to the root of the output from multiple_assign_taxonomy.py'),\

 make_option('-k', '--key_dir',type="existing_dirpath",
        help='Path to file containing the expected results of the files in the output directory.')]

script_info['optional_options']=[\
 make_option('--output_dir', type="new_dirpath",
        help='Prefix for output files. If None is given, will print output.',
        default = None),\

 make_option('--levels', type="string",
        help='Comma-separated list of multiple_assign_taxonomy output levels to analyze. Numbers between 2 and 6 inclusive.'+\
        '[default: %default]',
        default = '2,3,4,5,6'),\

 make_option('--force', action='store_true',
	help='If true forces output directory creation even if the directory already exists.'+\
	'[default: %default]',
	default = False)]
script_info['version'] = __version__

def main():
    option_parser, opts, args = parse_command_line_parameters(**script_info)

    if(opts.output_dir):
        create_dir('/'.join(opts.output_dir.split('/')[:-1]), fail_on_exist=opts.force)

    levels = map(int, opts.levels.split(','))

    results = generate_taxa_compare_table(opts.root_dir, opts.key_dir, levels)

    for level, out_file in izip(levels, results):
        if(opts.output_dir):
            with open(opts.output_dir + '_L' + str(level) + '.txt', 'w') as f:
                datasets = sorted(out_file.keys())
                methods = set()
                for m in out_file.itervalues():
                    methods|= set(m.keys())
                methods = sorted(list(methods))
                f.write('P_S\t')
                f.write('\t'.join(methods)+'\n')
                for dataset in datasets:
                    f.write(dataset+'\t')
                    for method in methods:
                        try:
                            f.write(out_file[dataset][method][0] + "_" + out_file[dataset][method][1]+'\t')
                        except KeyError:
                            f.write('N/A'+'\t')#Don't have data for that set/method
                    f.write('\n')
        else:
            #Terminal output code here if wanted
{'fraction_non_alphanumeric': 0.1347976530765759, 'fraction_numerical': 0.004964645704829246, 'mean_word_length': 3.136901057871811, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5314523', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1923, 'n_words': 512}