<commit_before># We try to keep all model creation in this file so it's easier to reference.
import pandas as pd
from middleware.models import SubtypingRow, SubtypingResult
from middleware.graphers.turtle_utils import actual_filename


def model_serotype(pi, pl, output_file):
    """
    Creates a SubtypingResult model from ECTYper's serotyping output.
    """
    # Read the vanilla output_file from ECTyper.
    df = pd.read_csv(output_file)

    # TODO: incorporate the pl.

    # Loop.
    subtyping_list = [
        {
            analysis='Serotype',
            contigid='n/a',
            filename=actual_filename(row['genome']),
            hitcutoff=str(pi),
            hitname="{0}:{1}".format(row['O_prediction'],row['H_prediction']),
            hitorientation='n/a',
            hitstart='n/a',
            hitstop='n/a'
        }
    for index, row in df.iterrows()]

    # Convert the list of rows into a SubtypingResult model.
    # subtyping_result = SubtypingResult(
    #     rows = subtyping_list
    # )
    return subtyping_list

def model_vf(lst):
    """
    Casts the output from display.beautify into a SubtypingResult object.
    """
    # Type check.
    assert isinstance(lst, list)
    print("model_vf() called with type {0} containing {1}".format(type(lst), str(lst)))
    subtyping_list = [
        {
            analysis=item('analysis'),
            contigid=item['contigid'],
            filename=item['filename'],
            hitcutoff=item['hitcutoff'],
            hitname=item['hitname'],
            hitorientation=item['hitorientation'],
            hitstart=item['hitstart'],
            hitstop=item['hitstop']
        }
    for item in lst]
    # Convert the list of rows into a SubtypingResult model.
    # subtyping_result = SubtypingResult(
    #     rows = subtyping_list
    # )
    return subtyping_list
<commit_msg>CHANGE: just define a list generating function<commit_after># We try to keep all model creation in this file so it's easier to reference.
import pandas as pd
from middleware.models import SubtypingRow, SubtypingResult
from middleware.graphers.turtle_utils import actual_filename


def model_serotype(pi, pl, output_file):
    """
    Creates a SubtypingResult model from ECTYper's serotyping output.
    """
    # Read the vanilla output_file from ECTyper.
    df = pd.read_csv(output_file)

    # TODO: incorporate the pl.

    # Loop.
    subtyping_list = [
        {
            'analysis':'Serotype',
            'contigid':'n/a',
            'filename':actual_filename(row['genome']),
            'hitcutoff':str(pi),
            'hitname':"{0}:{1}".format(row['O_prediction'],row['H_prediction']),
            'hitorientation':'n/a',
            'hitstart':'n/a',
            'hitstop':'n/a'
        }
    for index, row in df.iterrows()]

    # Convert the list of rows into a SubtypingResult model.
    # subtyping_result = SubtypingResult(
    #     rows = subtyping_list
    # )
    return subtyping_list

def model_vf(lst):
    """
    Casts the output from display.beautify into a SubtypingResult object.
    """
    # Type check.
    assert isinstance(lst, list)
    print("model_vf() called with type {0} containing {1}".format(type(lst), str(lst)))
    subtyping_list = [
        {
            'analysis':item('analysis'),
            'contigid':item['contigid'],
            'filename':item['filename'],
            'hitcutoff':item['hitcutoff'],
            'hitname':item['hitname'],
            'hitorientation':item['hitorientation'],
            'hitstart':item['hitstart'],
            'hitstop':item['hitstop']
        }
    for item in lst]
    # Convert the list of rows into a SubtypingResult model.
    # subtyping_result = SubtypingResult(
    #     rows = subtyping_list
    # )
    return subtyping_list

{'fraction_non_alphanumeric': 0.11543518275046016, 'fraction_numerical': 0.002103602419142782, 'mean_word_length': 2.5452003727865797, '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': '1850518', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1160, 'n_words': 276}