<commit_before>"""
A revised version of rename trees that uses the ete3 library to parse the tree
"""

import os
import sys
import argparse
import re
from ete3 import Tree


if __name__ == '__main__':

    tags = ['id', 'address','altitude','country','date','latitude','longitude','name','note', 'site']

    parser = argparse.ArgumentParser(description='Parse a tree')
    parser.add_argument('-t', help='tree file', required=True)
    parser.add_argument('-i', help='id map file', required=True)
    parser.add_argument('-n', help='name of the tag to use in the label. You can provide multiple tags and they will be joined with _ Valid tags are {}'.format(tags), action='append')
    args = parser.parse_args()

    for n in args.n:
        if n.lower() not in tags:
            sys.exit('Sorry {} is not a valid tag. It must be one of {} '.format(args.n, tags))

    idmap = {}
    tagcount = {}
    with open(args.i, 'r') as f:
        for l in f:
            p=l.strip().split("\t")
            if tags == 'id':
                idmap[p[0]]=p[1].split()[0]
            else:
                m = re.findall('\[(\S+)\=(.*?)\]', p[1])
                tagdata = {t[0]:t[1] for t in m}
                tagarr = []
                for n in args.n:
                    if n.lower() in tagdata:
                        tagarr.append(tagdata[n.lower()])
                tagstring = "_".join(tagarr)

                if '' == tagstring:
                    sys.stderr.write("No {} data found in sample: {}\n".format(args.n, l.strip()))
                    idmap[p[0]] = p[1].split()[0]
                else:<commit_msg>adding more labels<commit_after>"""
A revised version of rename trees that uses the ete3 library to parse the tree
"""

import os
import sys
import argparse
import re
from ete3 import Tree


if __name__ == '__main__':

    tags = ['address', 'altitude', 'country', 'date', 'id', 'latitude', 'location', 'longitude', 'name', 'note', 'samplecount', 'site', 'volunteer']

    parser = argparse.ArgumentParser(description='Parse a tree')
    parser.add_argument('-t', help='tree file', required=True)
    parser.add_argument('-i', help='id map file', required=True)
    parser.add_argument('-n', help='name of the tag to use in the label. You can provide multiple tags and they will be joined with _ Valid tags are {}'.format(tags), action='append')
    args = parser.parse_args()

    for n in args.n:
        if n.lower() not in tags:
            sys.exit('Sorry {} is not a valid tag. It must be one of {} '.format(args.n, tags))

    idmap = {}
    tagcount = {}
    with open(args.i, 'r') as f:
        for l in f:
            p=l.strip().split("\t")
            if tags == 'id':
                idmap[p[0]]=p[1].split()[0]
            else:
                m = re.findall('\[(\S+)\=(.*?)\]', p[1])
                tagdata = {t[0]:t[1] for t in m}
                tagarr = []
                for n in args.n:
                    if n.lower() in tagdata:
                        tagarr.append(tagdata[n.lower()])
                tagstring = "_".join(tagarr)

                if '' == tagstring:
                    sys.stderr.write("No {} data found in sample: {}\n".format(args.n, l.strip()))
                    idmap[p[0]] = p[1].split()[0]
                else:
{'fraction_non_alphanumeric': 0.15954850518608907, 'fraction_numerical': 0.006711409395973154, 'mean_word_length': 2.0445682451253484, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5352550', 'n_tokens_mistral': 1036, 'n_tokens_neox': 993, 'n_words': 307}