def plot_overlaps(otus, group_otus, group_colors, <EOL>out_fp, fig_size=None, title="<STR_LIT>",<EOL>filter_common=False):
def sort_order_group(sp):<EOL><INDENT>"""<STR_LIT>"""<EOL>count = <NUM_LIT:0><EOL>rank = <NUM_LIT:0><EOL>in_prev = True<EOL>max_penalty = len(group_otus)<EOL>for i, grp in enumerate(group_otus):<EOL><INDENT>if sp in group_otus[grp]:<EOL><INDENT>count += <NUM_LIT:1><EOL>if in_prev:<EOL><INDENT>rank += <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>rank -= max_penalty - i<EOL>in_prev = False<EOL><DEDENT><DEDENT>return count, rank<EOL><DEDENT>if filter_common:<EOL><INDENT>otus = [otu for otu in otus if sort_order_group(otu)[<NUM_LIT:0>] < len(group_otus)]<EOL><DEDENT>otus = sorted(otus, key=sort_order_group, reverse=True)<EOL>shared_table = [merge_dicts({grp: None for grp in group_otus},{"<STR_LIT>": otu_id}) for otu_id in otus]<EOL>fig, ax = plt.subplots(figsize=fig_size)<EOL>ax.xaxis.set_major_locator(MaxNLocator(nbins=len(otus), integer=True))<EOL>base = [(<NUM_LIT:0>,<NUM_LIT:0>),(<NUM_LIT:0>,<NUM_LIT:0.5>),(<NUM_LIT:0>,<NUM_LIT:0.5>),(<NUM_LIT:0>,<NUM_LIT:0>)]<EOL>y_step = <NUM_LIT:1><EOL>x_step = <NUM_LIT:2><EOL>bars = []<EOL>bar_colors = []<EOL>for i, grp in enumerate(group_otus):<EOL><INDENT>for j, otu in enumerate(otus):<EOL><INDENT>if otu in group_otus[grp]:<EOL><INDENT>bars.append(translate(base, j*x_step+<NUM_LIT:0.5>, i*y_step))<EOL>bar_colors.append(group_colors[grp])<EOL><DEDENT><DEDENT><DEDENT>black = (<NUM_LIT:0>,<NUM_LIT:0>,<NUM_LIT:0>,<NUM_LIT:1>)<EOL>collection = PolyCollection(<EOL>verts=bars,<EOL>facecolors = bar_colors,<EOL>edgecolors = (black,),<EOL>linewidths = (<NUM_LIT:1>,),<EOL>transOffset = ax.transData,<EOL>zorder=<NUM_LIT:3><EOL>)<EOL>ax.add_collection(collection)<EOL>axttl = ax.title<EOL>axttl.set_position([<NUM_LIT>, <NUM_LIT>])<EOL>ax.set_title(title, {"<STR_LIT>": fontsize*<NUM_LIT>, "<STR_LIT>": "<STR_LIT>"})<EOL>plt.xticks(range(<NUM_LIT:1>, len(otus)*x_step, x_step), otus, rotation="<STR_LIT>")<EOL>plt.yticks([i-<NUM_LIT> for i in range(<NUM_LIT:1>, len(group_otus)*y_step+<NUM_LIT:1>, y_step)], <EOL>group_otus.keys(), rotation="<STR_LIT>")<EOL>ax.margins(<NUM_LIT>)<EOL>ax.yaxis.set_visible(True)<EOL>ax.set_xlim((<NUM_LIT:0>, len(otus)*x_step))<EOL>if out_fp:<EOL><INDENT>plt.savefig(out_fp, facecolors="<STR_LIT>", edgecolor="<STR_LIT:none>",<EOL>bbox_inches="<STR_LIT>", pad_inches=<NUM_LIT:0.1>)<EOL><DEDENT>else:<EOL><INDENT>plt.show()<EOL><DEDENT>
Given a list of OTUs and a number of groups containing subsets of
the OTU set, plot a presence/absence bar chart showing which species
belong to which groups.

:type otus: list
:param otus: A list of OTU identifiers (names or otherwise) ordered
             by greatest presence across the groups, i.e. those that
             come first appear in all the groups, next come the OTUs
             that appear in n-1 groups, etc...
:type group_otus: OrderedDict
:param group_otus: A dictionary of OTU identifiers (subset of otus)
                   keyed on group name (for display purposes) in
                   display order (bottom to top).
:type group_colors: dict
:param group_colors: Color assignment for each group.