Generate a parsable reaction representation to the YAML parser.

    Check the number of compounds in the reaction, if it is larger than 10,
    then transform the reaction data into a list of directories with all
    attributes in the reaction; otherwise, just return the text_type format
    of the reaction data.

def _reaction_representer(dumper, data):
    """Generate a parsable reaction representation to the YAML parser.

    Check the number of compounds in the reaction, if it is larger than 10,
    then transform the reaction data into a list of directories with all
    attributes in the reaction; otherwise, just return the text_type format
    of the reaction data.
    """
    if len(data.compounds) > _MAX_REACTION_LENGTH:
        def dict_make(compounds):
            for compound, value in compounds:
                yield OrderedDict([
                    ('id', text_type(compound.name)),
                    ('compartment', compound.compartment),
                    ('value', value)])

        left = list(dict_make(data.left))
        right = list(dict_make(data.right))

        direction = data.direction == Direction.Both

        reaction = OrderedDict()
        reaction['reversible'] = direction
        if data.direction == Direction.Reverse:
            reaction['left'] = right
            reaction['right'] = left
        else:
            reaction['left'] = left
            reaction['right'] = right

        return dumper.represent_data(reaction)
    else:
        return _represent_text_type(dumper, text_type(data))