def plot_insertions(fname, seqs, gene, domain, tax, id2name):
<EOL>import matplotlib<EOL>import matplotlib.pyplot as plt<EOL>import numpy as np<EOL>from matplotlib.backends.backend_pdf import PdfPages<EOL>import matplotlib.cm as cm<EOL>import matplotlib.colors as col<EOL>from matplotlib.font_manager import FontProperties<EOL>plt.rcParams['<STR_LIT>'] = <NUM_LIT> <EOL>max_insert = max_insertion(seqs, gene, domain)<EOL>height = max_insert + max_insert * <NUM_LIT><EOL>xmax = model_length(gene, domain)<EOL>f, axarr = plt.subplots(<NUM_LIT:4>, sharex = True, sharey = True)<EOL>plt.axis([<NUM_LIT:0>, xmax, <NUM_LIT:0>, height])<EOL>plt.xticks(np.arange(<NUM_LIT:0>, xmax, <NUM_LIT:100>), rotation = <NUM_LIT>)<EOL>plt.yticks(np.arange(<NUM_LIT:0>, height, <NUM_LIT:200>))<EOL>axarr[<NUM_LIT:0>].set_title('<STR_LIT>')<EOL>axarr[<NUM_LIT:1>].set_title('<STR_LIT>')<EOL>axarr[<NUM_LIT:2>].set_title('<STR_LIT>')<EOL>axarr[<NUM_LIT:3>].set_title('<STR_LIT>')<EOL>plt.suptitle('<STR_LIT>' % (domain, gene))<EOL>plt.ylabel('<STR_LIT>')<EOL>plt.xlabel('<STR_LIT>' % (domain, gene))<EOL>color2tax = {}<EOL>if tax is False:<EOL><INDENT>taxa = ['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>taxa = sorted(set([tax[id2name[i]] for i, j in list(seqs.items()) if j[<NUM_LIT:2>] != [] and id2name[i] in tax]))<EOL>if '<STR_LIT>' not in taxa:<EOL><INDENT>taxa.append('<STR_LIT>')<EOL><DEDENT><DEDENT>colors = cm.spectral(np.linspace(<NUM_LIT:0>, <NUM_LIT:1>, len(taxa)))<EOL>colors = cycle(colors)<EOL>for t in taxa:<EOL><INDENT>color2tax[t] = next(colors)<EOL><DEDENT>markers = setup_markers(seqs)<EOL>for name, seq in list(seqs.items()):<EOL><INDENT>g, d = seq[<NUM_LIT:0>], seq[<NUM_LIT:1>]<EOL>if g != gene or d != domain or seq[<NUM_LIT:2>] == []:<EOL><INDENT>continue<EOL><DEDENT>if tax is False or id2name[name] not in tax:<EOL><INDENT>t = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>t = tax[id2name[name]]<EOL><DEDENT>c = color2tax[t] <EOL>for ins in seq[<NUM_LIT:2>]:<EOL><INDENT>family = [i for i in list(ins[-<NUM_LIT:1>].values()) if i != '<STR_LIT>']<EOL>if len(family) != <NUM_LIT:1>:<EOL><INDENT>family = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>family = family[<NUM_LIT:0>]<EOL><DEDENT>x, y = int(ins[<NUM_LIT:1>]), int(ins[<NUM_LIT:2>])<EOL>orf, intron = ins[-<NUM_LIT:3>], ins[-<NUM_LIT:2>]<EOL>if orf is True: <EOL><INDENT>if intron is True: <EOL><INDENT>p = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>p = <NUM_LIT:1><EOL><DEDENT><DEDENT>else:<EOL><INDENT>if intron is True: <EOL><INDENT>p = <NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>p = <NUM_LIT:3><EOL><DEDENT><DEDENT>marker, size = '<STR_LIT:o>', <NUM_LIT:30><EOL>if orf is True:<EOL><INDENT>marker, size = markers[family]<EOL><DEDENT>axarr[p].scatter(x, y,edgecolors = c, marker = marker, s = size, label = family,facecolors = '<STR_LIT:none>', clip_on = False)<EOL><DEDENT><DEDENT>handles, labels = [], []<EOL>for ax in axarr[<NUM_LIT:0>:<NUM_LIT:2>]:<EOL><INDENT>hs, ls = ax.get_legend_handles_labels()<EOL>for h, l in zip(hs, ls):<EOL><INDENT>if l in labels:<EOL><INDENT>continue<EOL><DEDENT>handles.append(h)<EOL>labels.append(l)<EOL><DEDENT><DEDENT>l1 = plt.legend(handles, labels, scatterpoints = <NUM_LIT:1>,prop = {'<STR_LIT:size>':<NUM_LIT:10>}, loc = '<STR_LIT>', bbox_to_anchor = (<NUM_LIT:1>, <NUM_LIT:0.5>))<EOL>names = [t for t in taxa]<EOL>boxes = [matplotlib.patches.Rectangle((<NUM_LIT:0>, <NUM_LIT:0>), <NUM_LIT:1>, <NUM_LIT:1>, fc = color2tax[t]) for t in taxa]<EOL>plt.legend(boxes, names, scatterpoints = <NUM_LIT:1>,prop = {'<STR_LIT:size>':<NUM_LIT:10>}, loc = '<STR_LIT>', bbox_to_anchor = (<NUM_LIT:1>, <NUM_LIT:0.5>))<EOL>plt.gca().add_artist(l1) <EOL><INDENT>plt.tight_layout()<EOL><DEDENT>figure = plt.gcf()<EOL>figure.set_size_inches(<NUM_LIT:12>, <NUM_LIT:12>)<EOL>pdf = PdfPages('<STR_LIT>' % (fname.rsplit('<STR_LIT:.>', <NUM_LIT:1>)[<NUM_LIT:0>], domain, gene))<EOL>pdf.savefig()<EOL>plt.close()<EOL>pdf.close()<EOL>
plot insertions wrt model positions
2 panels:
    1. insertions with ORF
        - triangle if has intron
        - circle if no intron
    2. insertion does not have ORF
        - triangle if has intron
        - circle if no intron
    *3. conservation of sequence in model
    *4. e. coli positions
# seqs[id] = [gene, model, [[i-gene_pos, i-model_pos, i-length, orf, intron], ...]]