<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def reactions_to_files(model, dest, writer, split_subsystem):
 """Turn the reaction subsystems into their own files. If a subsystem has a number of reactions over the threshold, it gets its own YAML file. All other reactions, those that don't have a subsystem or are in a subsystem that falls below the threshold, get added to a common reaction file. Args: model: :class:`psamm_import.model.MetabolicModel`. dest: output path for model files. writer: :class:`psamm.datasource.native.ModelWriter`. split_subsystem: Divide reactions into multiple files by subsystem. """

    def safe_file_name(origin_name):
        safe_name = re.sub(
            r'\W+', '_', origin_name, flags=re.UNICODE)
        safe_name = re.sub(
            r'_+', '_', safe_name.lower(), flags=re.UNICODE)
        safe_name = safe_name.strip('_')
        return safe_name

    common_reactions = []
    reaction_files = []
    if not split_subsystem:
        common_reactions = sorted(model.reactions, key=lambda r: r.id)
        if len(common_reactions) > 0:
            reaction_file = 'reactions.yaml'
            with open(os.path.join(dest, reaction_file), 'w') as f:
                writer.write_reactions(f, common_reactions)
            reaction_files.append(reaction_file)
    else:
        subsystems = {}
        for reaction in sorted(model.reactions, key=lambda r: r.id):
            if 'subsystem' in reaction.properties:
                subsystem_file = safe_file_name(
                    reaction.properties['subsystem'])
                subsystems.setdefault(subsystem_file, []).append(reaction)
            else:
                common_reactions.append(reaction)

        subsystem_folder = 'reactions'
        sub_existance = False
        for subsystem_file, reactions in iteritems(subsystems):
            if len(reactions) < _MAX_REACTION_COUNT:
                for reaction in reactions:
                    common_reactions.append(reaction)
            else:
                if len(reactions) > 0:
                    mkdir_p(os.path.join(dest, subsystem_folder))
                    subsystem_file = os.path.join(
                        subsystem_folder, '{}.yaml'.format(subsystem_file))

                    with open(os.path.join(dest, subsystem_file), 'w') as f:
                        writer.write_reactions(f, reactions)
                    reaction_files.append(subsystem_file)
                    sub_existance = True

        reaction_files.sort()
        if sub_existance:
            reaction_file = os.path.join(
                subsystem_folder, 'other_reactions.yaml')
        else:
            reaction_file = 'reactions.yaml'
        if len(common_reactions) > 0:
            with open(os.path.join(dest, reaction_file), 'w') as f:
                writer.write_reactions(f, common_reactions)
            reaction_files.append(reaction_file)

    return reaction_files