def plot_insertions(fname, seqs, gene, domain, tax, id2name):
    """
    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], ...]]
    """
    # import
    import matplotlib
    import matplotlib.pyplot as plt
    import numpy as np
    from matplotlib.backends.backend_pdf import PdfPages
    import matplotlib.cm as cm
    import matplotlib.colors as col
    from matplotlib.font_manager import FontProperties
    plt.rcParams['pdf.fonttype'] = 42 # illustrator pdf
    # axis
    max_insert = max_insertion(seqs, gene, domain)
    height = max_insert + max_insert * 0.10
    xmax = model_length(gene, domain)
    f, axarr = plt.subplots(4, sharex = True, sharey = True)
    plt.axis([0, xmax, 0, height])
    plt.xticks(np.arange(0, xmax, 100), rotation = 45)
    plt.yticks(np.arange(0, height, 200))
    # labels
    axarr[0].set_title('encodes ORF and intron')
    axarr[1].set_title('encodes ORF, no intron')
    axarr[2].set_title('encodes intron, no ORF')
    axarr[3].set_title('no intron, no ORF')
    plt.suptitle('%s %s rRNA gene insertions' % (domain, gene))
    plt.ylabel('insertion length (bp)')
    plt.xlabel('position on %s %s rRNA gene model' % (domain, gene))
    # colors
    color2tax = {}
    if tax is False:
        taxa = ['n/a']
    else:
        taxa = sorted(set([tax[id2name[i]] for i, j in list(seqs.items()) if j[2] != [] and id2name[i] in tax]))
        if 'n/a' not in taxa:
            taxa.append('n/a')
    colors = cm.spectral(np.linspace(0, 1, len(taxa)))
    colors = cycle(colors)
    for t in taxa:
        color2tax[t] = next(colors)
    # markers
    markers = setup_markers(seqs)
    # plot
    for name, seq in list(seqs.items()):
        g, d = seq[0], seq[1]
        if g != gene or d != domain or seq[2] == []:
            continue
        if tax is False or id2name[name] not in tax:
            t = 'n/a'
        else:
            t = tax[id2name[name]]
        c = color2tax[t] 
        for ins in seq[2]:
            family = [i for i in list(ins[-1].values()) if i != 'n/a']
            if len(family) != 1:
                family = 'n/a'
            else:
                family = family[0]
            x, y = int(ins[1]), int(ins[2])
            orf, intron = ins[-3], ins[-2]
            if orf is True: # has orf
                if intron is True: # has intron
                    p = 0
                else:
                    p = 1
            else:
                if intron is True: # intron, no orf
                    p = 2
                else:
                    p = 3
            marker, size = 'o', 30
            if orf is True:
                marker, size = markers[family]
            axarr[p].scatter(x, y, \
                    edgecolors = c, marker = marker, s = size, label = family, \
                    facecolors = 'none', clip_on = False)
    # legend
    handles, labels = [], []
    for ax in axarr[0:2]:
        hs, ls = ax.get_legend_handles_labels()
        for h, l in zip(hs, ls):
            if l in labels:
                continue
            handles.append(h)
            labels.append(l)
    l1 = plt.legend(handles, labels, scatterpoints = 1, \
            prop = {'size':10}, loc = 'upper left', bbox_to_anchor = (1, 0.5))
    names = [t for t in taxa]
    boxes = [matplotlib.patches.Rectangle((0, 0), 1, 1, fc = color2tax[t]) for t in taxa]
    plt.legend(boxes, names, scatterpoints = 1, \
            prop = {'size':10}, loc = 'lower left', bbox_to_anchor = (1, 0.5))
    plt.gca().add_artist(l1) # add l1 as a separate legend
    # save
#    plt.tight_layout()
    figure = plt.gcf()
    figure.set_size_inches(12, 12)
    pdf = PdfPages('%s.%s-%srRNAgene-insertions.pdf' % (fname.rsplit('.', 1)[0], domain, gene))
    pdf.savefig()
    plt.close()
    pdf.close()
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], ...]]