def get_item_from_model(item_type, item_id, model):
    """ Return the appropriate item from the model according to the specified
    item type and item id.

    Parameters
    ----------
    item_type : str
    item_id : str
    model : GEMEditor.model.classes.cobra.Model

    Returns
    -------
    item : GEMEditor.model.classes.cobra.Reaction, GEMEditor.model.classes.cobra.Metabolite, GEMEditor.model.classes.cobra.Gene, GEMEditor.model.classes.cobra.Model

    Raises
    ------
    ValueError
        If item_type is not "Reaction", "Model", "Gene", "GeneGroup" or "Metabolite"
    KeyError
        If item id is not present in the corresponding collection
    """
    if item_type == 'Reaction':
        return model.reactions.get_by_id(item_id)
    elif item_type == 'Metabolite':
        return model.metabolites.get_by_id(item_id)
    elif item_type == 'Gene':
        return model.genes.get_by_id(item_id)
    elif item_type == 'GeneGroup':
        raise NotImplementedError
    elif item_type == 'Model':
        return model
    elif item_type == 'Compartment':
        return model.gem_compartments[item_id]
    else:
        raise ValueError("Unexpected item type '{0}' with id {1}".format(
            item_type, item_id))
