<commit_before># -------------------------------------------------------
# Change the names in a file to any format
# -------------------------------------------------------
from os.path import splitext

def switch(file, homologs, current_name, new_name):
    """ Switch between names. New name can be a list
        of keys in the homolog object (might be necessary
        for unique name in newick).    
    """
    f = open(file, "r")
    text = f.read()
    f.close()

    # Construct mapping for name replace.
    mapping = homologs.get_map(current_name, new_name)
    
    # If new_name was a list.
    if isinstance(new_name,list):
        for m in mapping:
            mapping[m] = " - ".join(mapping[m])
    
    # Replace the old name with this new constructed name
    for key in mapping:
        text = text.replace(key, mapping[key])
    
    new_file = splitext(file)[0] + "_names.fasta"
    f = open(new_file, "w")
    f.write(text)
    f.close()
    
    
<commit_msg>add names to newick<commit_after># -------------------------------------------------------
# Change the names in a file to any format
# -------------------------------------------------------
from os.path import splitext

def switch(file, homologs, current_name, new_name):
    """ Switch between names. New name can be a list
        of keys in the homolog object (might be necessary
        for unique name in newick).    
    """
    f = open(file, "r")
    text = f.read()
    f.close()

    # Construct mapping for name replace.
    mapping = homologs.get_map(current_name, new_name)
    
    # If new_name was a list.
    if isinstance(new_name,list):
        for m in mapping:
            mapping[m] = " - ".join(mapping[m])
    
    for m in mapping:
        mapping[m] = mapping[m].replace(" ", "_")
    
    # Replace the old name with this new constructed name
    for key in mapping:
        text = text.replace(key, mapping[key])
    
    new_file = splitext(file)[0] + "_names" + splitext(file)[1]
    f = open(new_file, "w")
    f.write(text)
    f.close()
    
    
def newick_names(file, homologs, current_name, new_name):
    """ Switch between names. New name can be a list
        of keys in the homolog object (might be necessary
        for unique name in newick).    
    """
    f = open(file, "r")
    text = f.read()
    f.close()

    # Construct mapping for name replace.
    mapping = homologs.get_map(current_name, new_name)
    
    # If new_name was a list.
    if isinstance(new_name,list):
        for m in mapping:
            mapping[m] = " - ".join(mapping[m])
    
    # Quality control for newick
    for m in mapping:
        name = mapping[m]
        name = name.strip()
        name = name.replace("(", "[")
        name = name.replace(")", "]")
        name = name.replace(",", "-")
        mapping[m] = name

    # Replace the old name with this new constructed name
    for key in mapping:
        text = text.replace(key, mapping[key])
    
    new_file = splitext(file)[0] + "_names" + splitext(file)[1]
    f = open(new_file, "w")
    f.write(text)
    f.close()
{'fraction_non_alphanumeric': 0.17867528271405492, 'fraction_numerical': 0.0016155088852988692, 'mean_word_length': 1.822242479489517, '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': '1035327', 'n_tokens_mistral': 934, 'n_tokens_neox': 916, 'n_words': 296}