def is_valid_fragment(original_residue_id, mapping, frag_sizes):
    '''A function which determines whether a residue ID (original_residue_id) should be included in the nmer files generated by the mapping.'''
    for r in mapping['segment_list']:
        r = sorted(r)
        if r[0] - frag_sizes + 1 <= original_residue_id <= r[1] + frag_sizes - 1:
            return True
    return False