<commit_before>from __future__ import print_function
import sys
import PyFBA


def roles_to_model(rolesFile, id, name, orgtype="gramnegative", verbose=False):
    """
    Read in the 'assigned_functions' file from RAST and create a model.

    :param rolesFile: File path to assigned functions RAST file
    :type rolesFile: str
    :param id: Model ID
    :type id: str
    :param name: Model name
    :type name: str
    :param orgtype: Organism type
    :type orgtype: str
    :param verbose: Verbose output
    :type verbose: bool
    :return: The generated model object
    :rtype: Model
    """

    # Load ModelSEED database
    compounds, reactions, enzymes = \
            PyFBA.parse.model_seed.compounds_reactions_enzymes(orgtype)

    # Read in assigned functions file to build set of roles
    assigned_functions = PyFBA.parse.read_assigned_functions(rolesFile)
    roles = set()
    for rs in assigned_functions.values():
        roles.update(rs)

    # Obtain reactions for each role
    # Key is role, value is set of reaction ids
    model_reactions = PyFBA.filters.roles_to_reactions(roles)

    # Create model object
    model = PyFBA.model.Model(id, name)
    for role, rxnIDs in model_reactions.items():
        for rxnID in rxnIDs:
            if rxnID in reactions:
                model.add_reactions({reactions[rxnID]})
                model.add_roles({role: {rxnID}})
            elif verbose:
                print("Reaction ID '{}' for role '{}'".format(rxnID, role),
                      "is not in our reactions list. Skipped.",
                      file=sys.stderr)

    return model<commit_msg>Adding biomass reaction to build_model method.<commit_after>from __future__ import print_function
import sys
import PyFBA


def roles_to_model(rolesFile, id, name, orgtype="gramnegative", verbose=False):
    """
    Read in the 'assigned_functions' file from RAST and create a model.

    :param rolesFile: File path to assigned functions RAST file
    :type rolesFile: str
    :param id: Model ID
    :type id: str
    :param name: Model name
    :type name: str
    :param orgtype: Organism type
    :type orgtype: str
    :param verbose: Verbose output
    :type verbose: bool
    :return: The generated model object
    :rtype: Model
    """

    # Load ModelSEED database
    compounds, reactions, enzymes = \
            PyFBA.parse.model_seed.compounds_reactions_enzymes(orgtype)

    # Read in assigned functions file to build set of roles
    assigned_functions = PyFBA.parse.read_assigned_functions(rolesFile)
    roles = set()
    for rs in assigned_functions.values():
        roles.update(rs)

    # Obtain reactions for each role
    # Key is role, value is set of reaction ids
    model_reactions = PyFBA.filters.roles_to_reactions(roles)

    # Create model object
    model = PyFBA.model.Model(id, name)
    for role, rxnIDs in model_reactions.items():
        for rxnID in rxnIDs:
            if rxnID in reactions:
                model.add_reactions({reactions[rxnID]})
                model.add_roles({role: {rxnID}})
            elif verbose:
                print("Reaction ID '{}' for role '{}'".format(rxnID, role),
                      "is not in our reactions list. Skipped.",
                      file=sys.stderr)

    # Set biomass equation based on organism type
    biomass_eqn = PyFBA.metabolism.biomass_equation(orgtype)
    model.set_biomass_reaction(biomass_eqn)
    return model
{'fraction_non_alphanumeric': 0.08130081300813008, 'fraction_numerical': 0.0, 'mean_word_length': 2.6805555555555554, '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': '892390', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1013, 'n_words': 322}