def color_mapping(sample_map, header, group_column, color_column=None):
group_colors = OrderedDict()<EOL>group_gather = gather_categories(sample_map, header, [group_column])<EOL>if color_column is not None:<EOL><INDENT>color_gather = gather_categories(sample_map, header, [color_column])<EOL>for group in group_gather:<EOL><INDENT>for color in color_gather:<EOL><INDENT>if group_gather[group].sids.intersection(color_gather[color].sids):<EOL><INDENT>group_colors[group] = color<EOL><DEDENT><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>bcolors = itertools.cycle(Set3_12.hex_colors)<EOL>for group in group_gather:<EOL><INDENT>group_colors[group] = bcolors.next()<EOL><DEDENT><DEDENT>return group_colors<EOL>
Determine color-category mapping. If color_column was specified, then map the category
names to color values. Otherwise, use the palettable colors to automatically generate
a set of colors for the group values.

:type sample_map: dict
:param unifracFN: Map associating each line of the mapping file with the appropriate
                  sample ID (each value of the map also contains the sample ID)

:type header: tuple
:param A tuple of header line for mapping file

:type group_column: str
:param group_column: String denoting the column name for sample groups.

:type color_column: str
:param color_column: String denoting the column name for sample colors.

:type return: dict
:param return: {SampleID: Color}