<commit_before>#!/usr/bin/env python
# encoding: utf-8

"""


Created by <NAME> on 04 October 2010 11:02 PDT (-0700).
Copyright (c) 2010 <NAME>. All rights reserved.
"""

import os
import sys
import pdb
import optparse
from operator import itemgetter

def interface():
    '''Command-line interface'''
    usage = "usage: %prog [options]"

    p = optparse.OptionParser(usage)

    p.add_option('--input', dest = 'input', action='store', 
type='string', default = None, help='The path to the input file.', 
metavar='FILE')
    p.add_option('--output', dest = 'output', action='store', 
type='string', default = None, help='The path to the output file.', 
metavar='FILE')
    p.add_option('--tabs', dest = 'tabs', action='store_true', default=False, 
help='Tab delimited input')

    (options,arg) = p.parse_args()
    options.input = os.path.abspath(os.path.expanduser(options.input))
    if options.output:
        options.output = os.path.abspath(os.path.expanduser(options.output))
    if not options.input:
        p.print_help()
        sys.exit(2)
    if not os.path.isfile(options.input):
        print "You must provide a valid path to the configuration file."
        p.print_help()
        sys.exit(2)
    return options, arg 


def main():
    options, args = interface()
    f = open(options.input, 'rU')
    header = f.next()
    data = []
    for line in f:
        if options.tabs:
            name, tag = line.strip().split('\t')
        else:
            name, tag = line.strip().split(',')
        flows = []
        for base in tag:
            for count, flow in enumerate(['T', 'A', 'C', 'G']):
                if base == flow:
                    flows.append(count+1)
                    break
        data.append([name, tag, sum(flows)])
    if options.output:
        o = open(options.output, 'w')
    # sort all the tags by the number of flows required
    for tag in sorted(data, key=itemgetter(2)):
        # there's an integer in the list, so we have to stringify it
        result = ','.join(['{0}'.format(i) for i in tag])
        if not options.output:
            print result
        else:
            o.write('{0}\n'.format(result))
    
if __name__ == '__main__':
    main()<commit_msg>updated check tag flows for new input format<commit_after>#!/usr/bin/env python
# encoding: utf-8

"""


Created by <NAME> on 04 October 2010 11:02 PDT (-0700).
Copyright (c) 2010 <NAME>. All rights reserved.
"""

import os
import sys
import pdb
import optparse
import ConfigParser
from operator import itemgetter
from lib.helpers import get_tag_flows
from lib.helpers import get_tag_dict

def interface():
    '''Command-line interface'''
    usage = "usage: %prog [options]"

    p = optparse.OptionParser(usage)

    p.add_option('--input', dest = 'input', action='store', 
type='string', default = None, help='The path to the input file.', 
metavar='FILE')
    p.add_option('--section', dest = 'section', action = 'store',\
type='string', default = None, help='[Optional] The section of'
+' the config file to evaluate')

    (options,arg) = p.parse_args()
    options.input = os.path.abspath(os.path.expanduser(options.input))
    #if options.output:
    #    options.output = os.path.abspath(os.path.expanduser(options.output))
    if not options.input:
        p.print_help()
        sys.exit(2)
    if not os.path.isfile(options.input):
        print "You must provide a valid path to the configuration file."
        p.print_help()
        sys.exit(2)
    return options, arg

def get_section_flows(section, flows, tags):
    for name in tags:
        flows.setdefault(section, []).append([name, tags[name], get_tag_flows(tags[name])])
    return flows

def show_results(flows):
    for sec in flows:
        print "{0}".format(sec)
        for item in sorted(flows[sec], key=itemgetter(2)):
            print "\t{0}\t{1}\t{2}".format(item[0], item[1], item[2])

def main():
    options, args = interface()
    conf = ConfigParser.ConfigParser()
    conf.read(options.input)
    flows = {}
    if not options.section:
        for section in conf.sections():
            tags = get_tag_dict(conf.items(section))
            flows = get_section_flows(section, flows, tags)
    elif options.section:
        tags = get_tag_array(conf.items(section))
        flows = get_section_flows(section, flows, tags)
    show_results(flows)
    
if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.1415909090909091, 'fraction_numerical': 0.012272727272727272, 'mean_word_length': 2.823631624674196, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4132357', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1386, 'n_words': 393}