<commit_before>import os
from json_generator import JsonGenerator

# example call:
# snpQuery = 'select chromStart as Start, chromEnd as End, name as Name, transcript, frame, alleleCount, funcCodes, alleles, codons, peptides'
# db_importer.dbImport(conn, "snp132CodingDbSnp", snpQuery, "chromEnd", "chrom", "../data/", "snp132CodingDbSnp")
def dbImport(conn, table, query, endCol, chromCol, dataDir,
             trackLabel, key = None, chunkBytes = 200000, compress = True):
    query += " from %s where %s=? order by Start asc, End desc" \
             % (table, chromCol)
    cur = conn.execute("""
    select %(chrom)s, max(%(end)s), count(*) from %(table)s group by %(chrom)s
    """ % {'chrom': chromCol, 'end': endCol, 'table': table})
    chromList = cur.fetchall()
    for (chrom, refEnd, count) in chromList:
        cur = conn.execute(query, (chrom,))
        classes = [{
            'attributes': [f[0] for f in cur.description],
            'proto': {'Chrom': chrom}
            }]
        jsongen = JsonGenerator(dataDir, trackLabel, chrom, chunkBytes,
                                compress, classes, refEnd = refEnd,
                                writeHists = True, featureCount = count)
        for row in cur:
            jsongen.addSorted([0] + list(row))

        jsongen.generateTrack()
    jsongen.writeTrackEntry('FeatureTrack', {
        'style': {
            'className': 'feature2'
            }
        })<commit_msg>add config parameter to dbImport<commit_after>import os
from json_generator import JsonGenerator

# example call:
# snpQuery = 'select chromStart as Start, chromEnd as End, name as Name, transcript, frame, alleleCount, funcCodes, alleles, codons, peptides'
# db_importer.dbImport(conn, "snp132CodingDbSnp", snpQuery, "chromEnd", "chrom", "../data/", "snp132CodingDbSnp")
def dbImport(conn, table, query, endCol, chromCol, dataDir,
             trackLabel, key = None, chunkBytes = 200000,
             compress = True,
             config = {'style': {'className': 'feature2'}}):
    query += " from %s where %s=? order by Start asc, End desc" \
             % (table, chromCol)
    cur = conn.execute("""
    select %(chrom)s, max(%(end)s), count(*) from %(table)s group by %(chrom)s
    """ % {'chrom': chromCol, 'end': endCol, 'table': table})
    chromList = cur.fetchall()
    for (chrom, refEnd, count) in chromList:
        cur = conn.execute(query, (chrom,))
        classes = [{
            'attributes': [f[0] for f in cur.description],
            'proto': {'Chrom': chrom}
            }]
        jsongen = JsonGenerator(dataDir, trackLabel, chrom, chunkBytes,
                                compress, classes, refEnd = refEnd,
                                writeHists = True, featureCount = count)
        for row in cur:
            jsongen.addSorted([0] + list(row))

        jsongen.generateTrack()
    jsongen.writeTrackEntry('FeatureTrack', config)
{'fraction_non_alphanumeric': 0.135709389993146, 'fraction_numerical': 0.01028101439342015, 'mean_word_length': 2.6037037037037036, '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': '1963234', 'n_tokens_mistral': 918, 'n_tokens_neox': 869, 'n_words': 250}