<commit_before>
def parse_fai(fai):
    """ Parses a fasta index file (produced by samtools index)
    and returns chromosome names and lengths """
    with open(fai) as f:
        return dict([x.strip().split("\t")[0:2] for x in f.readlines()])<commit_msg>added option to weight values<commit_after>
def parse_fai(fai, weight = False):
    """ Parses a fasta index file (produced by samtools index)
    and returns chromosome names and lengths

    Optionally generate weights
    """
    with open(fai) as f:
        chrom_length = [x.strip().split("\t")[0:2] for x in f.readlines()]
        chrom_length = [[x[0],int(x[1])] for x in chrom_length]
        if weight == True:
            genome_length = sum([x[1] for x in chrom_length])
            return dict([x[0],1.0*x[1]/genome_length] for x in chrom_length)
        else:
            return dict(chrom_length)
{'fraction_non_alphanumeric': 0.12687427912341406, 'fraction_numerical': 0.012687427912341407, 'mean_word_length': 3.0185185185185186, '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': '2596081', 'n_tokens_mistral': 284, 'n_tokens_neox': 274, 'n_words': 88}