Example #1
0
def graficar_union3(A, B, C, etiqueta1="A", etiqueta2="B", etiqueta3="C"):
    """
    Grafica la unión de tres conjunto

    Parámetros:

    A-tipo Set: Es el primer conjunto de la operación.
    B-tipo Set: Es el segundo conjunto de la operación.
    C-tipo Set: Es el tercer conjunto de la operación.
    etiqueta1-tipo String: La etiqueta para el primer conjunto. Por defecto tiene el valor "A".
    etiqueta2-tipo String: La etiqueta para el segundo conjunto. Por defecto tiene el valor "B".
    etiqueta3-tipo String: La etiqueta para el tercer conjunto. Por defecto tiene el valor "C".
    """
    D = union(A, B)
    H = union(D, C)
    operacion = etiqueta1 + "U" + etiqueta2 + "U" + etiqueta3
    plt.figure(figsize=(6, 8),
               linewidth=10,
               edgecolor="black",
               facecolor="white")  # Creo la figura
    v = None  # Creo los dos conjuntos
    c = None
    if cardinalidad(A) == 0 and cardinalidad(B) == 0 and cardinalidad(C) == 0:
        aux = {1}
        v = venn3(subsets=[aux, aux, aux],
                  set_labels=(operacion, '', ''))  # Creo los dos conjuntos
        c = venn3_circles(subsets=[aux, aux, aux], linestyle='dashed')
        v.get_label_by_id('111').set_text(chr(216))
    else:
        v = venn3(subsets=[H, H, H],
                  set_labels=(operacion, '', ''))  # Creo los dos conjuntos
        c = venn3_circles(subsets=[H, H, H], linestyle='dashed')
        v.get_label_by_id('111').set_text(H)
Example #2
0
def plot_venn_three(sizes: List[int],
                    labels: List[str],
                    figpath: str = '',
                    title: str = '',
                    **kwargs) -> None:
    """Plot a single Venn Diagram with two terms.

    Args:
        sizes (List[int]): List of ints of length 3. First two elements correspond to
            the labels, third one to the intersection.
        labels (List[str]): List of str of length 2, containing names of circles.
        figpath (str): Name under which figure is saved. Defaults to '', i.e. it is
            inferred from labels.
        title (str): Title of the plot. Defaults to '', i.e. it is inferred from
            labels.
        **kwargs: Additional keyword arguments for venn3.
    """
    assert len(sizes) == 7, 'Incorrect type/length of sizes'
    assert len(labels) == 3, 'Incorrect type/length of labels'

    title = get_name(labels) if title == '' else title
    figname = title.lower().replace(' vs. ', '_') if figpath == '' else figpath

    venn3(subsets=sizes, set_labels=labels, alpha=0.6, **kwargs)
    venn3_circles(subsets=sizes,
                  linestyle='solid',
                  linewidth=0.6,
                  color='grey',
                  **kwargs)

    if kwargs.get('ax', False):
        kwargs['ax'].set_title(title, fontdict={'fontweight': 'bold'}, size=15)
    else:
        plt.title(title, fontdict={'fontweight': 'bold'}, size=15)
        plt.savefig(f'{figname}.pdf')
def plot_overlap_nb():
	syngo=load_syngo_genes()
	synsysnet=find_synsysnet()
	synDB=find_synDB()
	go_synapse=find_GO_synapse()

	db=list(set(syngo+synsysnet+synDB+go_synapse))


	nb=load_nb_genes()
	#pred=load_pred_genes()

	print (len(nb))

	#overlap=list(set(nb)&set(pred))
	#print (len(overlap))

	adult=list(set(load_adult_str())&set(load_adult_str()))
	fetal=list(set(load_fetal_brain())&set(load_ngn2()))

	#adult=list(set(load_adult_str()+load_adult_str()))
	#fetal=list(set(load_fetal_brain()+load_ngn2()))

	val=adult+fetal

	v=venn3([set(nb),set(val), set(db)], set_labels=('Non-Brain Predicted',  'Proteomics Screen', 'Synapse Databases'), set_colors=('dodgerblue', 'red', 'lightgray'),alpha=0.7)
	venn3_circles([set(nb),set(val), set(db)], linestyle='solid', linewidth=0.5, color='k');
	for text in v.set_labels:
	    text.set_fontweight('bold')
	for text in v.set_labels:
	    text.set_fontsize(30)
	for text in v.subset_labels:
	    text.set_fontsize(30)
	plt.show()
	plt.close()
Example #4
0
 def plot(self,figure_location):
     matplotlib_venn.venn3_circles(
         [set(self.data["ignacio"]), set(self.data["maricella"]), set(self.data["nury"])],
         linewidth=1,
         alpha=0.2)
     matplotlib_venn.venn3(
         [set(self.data["ignacio"]), set(self.data["maricella"]), set(self.data["nury"])],
         set_labels = ('Human 1', 'Human 2', 'Human 3'),
         alpha=0.4)
     plt.title('Venn Diagram for Human Agreement')
     plt.savefig(figure_location)
     plt.close()
Example #5
0
def main():
    gn = Granatum()

    set1 = gn.get_import('set1')
    set2 = gn.get_import('set2')
    set3 = gn.get_import('set3')

    maxScore = gn.get_arg('maxScore')
    minScore = gn.get_arg('minScore')

    labelSet1 = gn.get_arg("labelSet1")
    labelSet2 = gn.get_arg("labelSet2")
    labelSet3 = gn.get_arg("labelSet3")

    wordcloud = gn.get_arg("wordcloud")

    filtered_set1 = dict(filter(lambda elem: (isinstance(elem[1], numbers.Number) & (not isnan(elem[1]))) & (elem[1] >= minScore) & (elem[1] <= maxScore), set1.items()))
    filtered_set2 = dict(filter(lambda elem: (isinstance(elem[1], numbers.Number) & (not isnan(elem[1]))) & (elem[1] >= minScore) & (elem[1] <= maxScore), set2.items()))
    filtered_set3 = dict(filter(lambda elem: (isinstance(elem[1], numbers.Number) & (not isnan(elem[1]))) & (elem[1] >= minScore) & (elem[1] <= maxScore), set3.items()))
    merged_frequencies = {**filtered_set1, **filtered_set2, **filtered_set3}

    packedsets = [set(filtered_set1.keys()), set(filtered_set2.keys()), set(filtered_set3.keys())]

    fig, ax = plt.subplots(1,1)
    fig.set_size_inches(5,4)

    caption = (
        'The area weighted Venn diagram is shown for the gene sets matching the criteria'
    )

    if wordcloud:
        out = venn3_wordcloud(packedsets, set_labels=(labelSet1, labelSet2, labelSet3), wordcloud_kwargs=dict(max_font_size=36), word_to_frequency=merged_frequencies, ax=ax)
        for text in out.set_labels:
            if text:
                text.set_fontsize(18)
        for text in out.subset_labels:
            if text:
                text.set_fontsize(16)
                text.set_path_effects([path_effects.SimpleLineShadow(), path_effects.Normal()])
    else:
        out = venn3(packedsets, set_labels=(labelSet1, labelSet2, labelSet3))
        venn3_circles(packedsets, linestyle='dashed', linewidth=1, color="black")
        for text in out.set_labels:
            if text:
                text.set_fontsize(18)
        for text in out.subset_labels:
            if text:
                text.set_fontsize(16)
                text.set_path_effects([path_effects.SimpleLineShadow(), path_effects.Normal()])

    gn.add_current_figure_to_results(caption)

    gn.commit()
Example #6
0
def venn_ploting(wd, tools, fpr, path):
    if os.path.isfile(wd + '/bed/peaks.bed'):
        peaks = read_bed(wd + '/bed/peaks.bed')
    else:
        peaks = read_bed(wd + '/bed/test_sample.bed')

    tools_peaks = dict()
    for t in tools:
        bed = read_bed(wd + '/scan/{0}_{1:.2e}.bed'.format(t.lower(), fpr))
        tools_peaks[t] = set(get_indexes(peaks, bed))

    if len(tools) == 3:
        id_to_name_3 = {
            '001': '{0}'.format(tools[2]),
            '010': '{0}'.format(tools[1]),
            '011': '{0}&{1}'.format(tools[1], tools[2]),
            '100': '{0}'.format(tools[0]),
            '101': '{0}&{1}'.format(tools[0], tools[2]),
            '110': '{0}&{1}'.format(tools[0], tools[1]),
            '111': '{0}&{1}&{2}'.format(tools[0], tools[1], tools[2])
        }

        petal_labels = creat_petal_3(tools_peaks[tools[0]],
                                     tools_peaks[tools[1]],
                                     tools_peaks[tools[2]])
        data = dict()
        for k in petal_labels.keys():
            data[id_to_name_3[k]] = petal_labels[k]
        venn3(subsets=petal_labels,
              set_labels=tools,
              alpha=0.5,
              set_colors=['#FF0018', '#FBD704', '#0000F9'])
        venn3_circles(petal_labels, linewidth=.6)
    elif len(tools) == 2:
        id_to_name_2 = {
            '01': '{0}'.format(tools[1]),
            '10': '{0}'.format(tools[0]),
            '11': '{0}&{1}'.format(tools[0], tools[1])
        }

        petal_labels = creat_petal_2(tools_peaks[tools[0]],
                                     tools_peaks[tools[1]])
        data = dict()
        for k in petal_labels.keys():
            data[id_to_name_2[k]] = petal_labels[k]
        venn2(subsets=petal_labels,
              set_labels=tools,
              alpha=0.5,
              set_colors=['#FF0018', '#FBD704', '#0000F9'])
        venn2_circles(petal_labels, linewidth=.6)
    plt.savefig(path, format="pdf", dpi=400, bbox_inches='tight', pad_inches=0)
    return (0)
Example #7
0
def venn_diagram3(set1, set2, set3, name1, name2, name3, title='', ax=None):
    # make sure to convert to set object
    set1 = set(set1)
    set2 = set(set2)
    set3 = set(set3)

    # do all possible intersections
    intersect_12 = set(set1) & set(set2)
    intersect_13 = set(set1) & set(set3)
    intersect_23 = set(set2) & set(set3)
    full_intersect = set(set1) & set(set2) & set(set3)

    # figure out number only specific to one set
    len_set1_specific = len(set1 - set2 - set3)
    len_set2_specific = len(set2 - set1 - set3)
    len_set3_specific = len(set3 - set1 - set2)

    # Figure out length of full intersect
    len_full_intersect = len(full_intersect)

    # figure out length of two-set specific overlaps
    len_set12 = len(intersect_12 - full_intersect)
    len_set13 = len(intersect_13 - full_intersect)
    len_set23 = len(intersect_23 - full_intersect)

    # create overlap object
    #overlap = (len_set1 - len_intersect, len_set2 - len_intersect, len_intersect)
    overlap = {
        '100': len_set1_specific,
        '010': len_set2_specific,
        '001': len_set3_specific,
        '110': len_set12,
        '101': len_set13,
        '011': len_set23,
        '111': len_full_intersect
    }

    # plot venn diagram
    with sns.plotting_context('notebook', font_scale=1.0):
        if ax:
            venn3(subsets=overlap, set_labels=(name1, name2, name3), ax=ax)
            venn3_circles(subsets=overlap,
                          linestyle='solid',
                          linewidth=.75,
                          ax=ax)
        else:
            venn3(subsets=overlap, set_labels=(name1, name2, name3))
            venn3_circles(subsets=overlap, linestyle='solid', linewidth=.75)
        plt.title(title, size=16)

    return overlap
Example #8
0
    def new_oo_vs_old_fbf(self, ax):

        if 'OO FBF (25°C)' in self.targs:
            a = self.targs['OO FBF-1 (20°C)']
            b = self.targs['OO FBF (25°C)']
            c = self.targs['OO FBF-2 (20°C)']
        else:
            a = self.targs['old_fbf1']
            b = self.targs['oo_both']
            c = self.targs['old_fbf2']

        _lab = ('$\mathrm{^{20^\circ C}Oo. FBF}$-$\mathrm{1}$',
                '$\mathrm{^{25^\circ C}Oo. FBF}$',
                '$\mathrm{^{20^\circ C}Oo. FBF}$-$\mathrm{2}$')
        v_plt = venn3(subsets=(a, b, c), ax=ax, set_labels=_lab)
        v_plt.get_patch_by_id('100').set_color("g")  #("#933b41")
        v_plt.get_patch_by_id('100')._linewidth = 0
        v_plt.get_patch_by_id('010').set_color("r")
        v_plt.get_patch_by_id('010')._linewidth = 0
        v_plt.get_patch_by_id('001').set_color('#933b41')
        v_plt.get_patch_by_id('001')._linewidth = 0
        cir = venn3_circles(subsets=(a, b, c), ax=ax, linestyle='solid')
        cir[0].set_lw(0)
        cir[1].set_lw(0)
        cir[2].set_lw(0)
        return v_plt
Example #9
0
def venn_diagram():
    from matplotlib import pyplot as plt
    import numpy as np
    from matplotlib_venn import venn3, venn3_circles
    plt.figure(figsize=(4, 4))
    v = venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels=('A', 'B', 'C'))
    v.get_patch_by_id('100').set_alpha(1.0)
    v.get_patch_by_id('100').set_color('white')
    v.get_label_by_id('100').set_text('Unknown')
    v.get_label_by_id('A').set_text('Set "A"')
    c = venn3_circles(subsets=(1, 1, 1, 1, 1, 1, 1), linestyle='dashed')
    c[0].set_lw(1.0)
    c[0].set_ls('dotted')
    plt.title("Sample Venn diagram")
    plt.annotate('Unknown set',
                 xy=v.get_label_by_id('100').get_position() -
                 np.array([0, 0.05]),
                 xytext=(-70, -70),
                 ha='center',
                 textcoords='offset points',
                 bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.1),
                 arrowprops=dict(arrowstyle='->',
                                 connectionstyle='arc3,rad=0.5',
                                 color='gray'))
    plt.show()
    pass
Example #10
0
def venn3(subsets, title, unit_title, filename, set_labels=None, normalize=1.0, annotation=None):
    plt.figure()
    v = venn.venn3_unweighted(subsets=subsets, set_labels=set_labels)
    c = venn.venn3_circles(subsets=(1,1,1,1,1,1,1), linestyle='solid', linewidth=1.5, normalize_to=normalize)
    for i in range(len(venn3_keys)):
        label_id = venn3_keys[i]
        text = v.get_label_by_id(label_id)
        text.set_position(text.get_position() + np.array([0, 0.02]))
        # TEMPORALLY COUPLED WITH CREATION OF DIAGRAM
        subtitle = unit_title
        if text.get_text() != '1':
            subtitle += 's'
        text.set_text(text.get_text() + '\n' + subtitle)
        text.set_size(text.get_size() - 2)
    if annotation is not None:
        for a in annotation:
            text = v.get_label_by_id(a)
            xy= text.get_position() - np.array([0, 0.085])
            plt.annotate(annotation[a], xy=xy, xytext=xy, ha='center', textcoords='offset points', color='r', weight='bold')
    for label in v.subset_labels:
        label.set_fontname('sans-serif')
    if title is not None:
        plt.title(title)
    plt.savefig(filename)
    plt.close()
Example #11
0
def draw_venn3(A, B, C, set_labels=['A', 'B', 'C'], filename=None):
    """
    Draw a Venn diagram for sets A, B, and C
    """
    sets = [A, B, C]

    diagram = matplotlib_venn.venn3(sets, set_labels=set_labels)
    _ = matplotlib_venn.venn3_circles(sets, linestyle='solid', linewidth=1)

    # Abc, aBc, ABc, abC, AbC, aBC, ABC
    members = [
        A.difference(B.union(C)),
        B.difference(A.union(C)),
        A.intersection(B).difference(C),
        C.difference(B.union(A)),
        A.intersection(C).difference(B),
        B.intersection(C).difference(A),
        A.intersection(B).intersection(C)
    ]

    for v, curr_members in zip(diagram.subset_labels, members):
        if v is not None:
            v.set_text(str('\n'.join(curr_members)))

    if filename is not None:
        plt.savefig(filename, format='png', bbox_inches='tight')
    else:
        plt.show()
Example #12
0
def plot_fetal_adult_db_within_synsig():
    fetal_all_pred, adult_all_pred, db_pred = find_overlap_with_synsig()
    #plot the overlap of all fetal, all_adult and all database synapse genes:

    f = plt.figure()

    v = venn3([set(fetal_all_pred),
               set(adult_all_pred),
               set(db_pred)],
              set_labels=('Fetal Synapse', 'Adult Synapse',
                          'Synapse Databases'),
              set_colors=('red', 'gray', 'lightblue'),
              alpha=0.7)
    c = venn3_circles([set(fetal_all_pred),
                       set(adult_all_pred),
                       set(db_pred)],
                      linestyle='solid',
                      linewidth=0.5,
                      color="black")
    for text in v.set_labels:
        text.set_fontweight('bold')
    for text in v.set_labels:
        text.set_fontsize(25)
    for text in v.subset_labels:
        text.set_fontsize(25)

    plt.show()
    plt.close()
    f.savefig("fetal_adult_db.pdf", bbox_inches='tight')
def draw_venn(title, names, numbers, out):
  
  if len(numbers) == 7:
    if numbers[0] + numbers[2] + numbers[4] + numbers[6] == 0:
      numbers = [ numbers[1], numbers[3], numbers[5] ];
      names   = [ names[1], names[2] ];
    elif numbers[1] + numbers[2] + numbers[5] + numbers[6] == 0:
      numbers = [ numbers[0], numbers[3], numbers[4] ];
      names   = [ names[0], names[2] ];
    elif numbers[3] + numbers[4] + numbers[5] + numbers[6] == 0:
      numbers = [ numbers[0], numbers[1], numbers[2] ];
      names   = [ names[0], names[1] ];
    #fi
  #fi
  
  plt.cla();
  plt.figure(figsize=(10,10))
  if len(numbers) == 7:
    plt.cla();
    plt.figure(figsize=(10,10))
    v = venn3(subsets=numbers, set_labels = names)
    c = venn3_circles(subsets=numbers, linestyle='dashed')
  else:
    v = venn2(subsets = numbers, set_labels = names);
    c = venn2_circles(subsets = numbers, linestyle='dashed');
  #fi
  
  plt.title(title)
  plt.savefig(out);
Example #14
0
    def makeVenn3(self,truthDict,snr,addon=''):
        type1 = '.svg'
        type2 = '.png'
        f = \
            os.path.join(self.destDir,self.fname+'.c'+str(self.ch)+'.snr_'+str(snr)+addon)


        reqdVennOrder = [('map','not','not'),
                         ('not','map','not'),
                         ('map','map','not'),
                         ('not','not','map'),
                         ('map','not','map'),
                         ('not','map','map'),
                         ('map','map','map')]
        valSet = list()
        for vSet in reqdVennOrder:
            val = truthDict[vSet]
            valSet.append(val)
        
        unmapped = truthDict[('not','not','not')]
        # Making venn diagram
        plt.figure(figsize=( 5,5))
        v = \
            venn3(subsets=valSet,set_labels=('Cycle1:Mock','Cycle2:Mock','Cycle3:Edman'))
        c = venn3_circles(subsets=valSet,ls='solid')
        txt = 'unmapped='+str(unmapped)+'\n SNR='+str(snr)
        plt.title('Peak Mapping :'+self.fname + '.'+self.frame+'\n channel:'+str(self.ch))
        plt.figtext( 0.7,0.1,txt)
        plt.savefig(f+type1,dpi=300)        
        plt.savefig(f+type2,dpi=300)
        plt.close()
def draw_venn(title, names, numbers, out):

    if len(numbers) == 7:
        if numbers[0] + numbers[2] + numbers[4] + numbers[6] == 0:
            numbers = [numbers[1], numbers[3], numbers[5]]
            names = [names[1], names[2]]
        elif numbers[1] + numbers[2] + numbers[5] + numbers[6] == 0:
            numbers = [numbers[0], numbers[3], numbers[4]]
            names = [names[0], names[2]]
        elif numbers[3] + numbers[4] + numbers[5] + numbers[6] == 0:
            numbers = [numbers[0], numbers[1], numbers[2]]
            names = [names[0], names[1]]
        #fi
    #fi

    plt.cla()
    plt.figure(figsize=(10, 10))
    if len(numbers) == 7:
        plt.cla()
        plt.figure(figsize=(10, 10))
        v = venn3(subsets=numbers, set_labels=names)
        c = venn3_circles(subsets=numbers, linestyle='dashed')
    else:
        v = venn2(subsets=numbers, set_labels=names)
        c = venn2_circles(subsets=numbers, linestyle='dashed')
    #fi

    plt.title(title)
    plt.savefig(out)
Example #16
0
def venn3_plot(set1 = set(),
               set2 = set(),
               set3 = set(),
               lab_set1 = 'Set1',
               lab_set2 = 'Set2',
               lab_set3 = 'Set3',
               linewidth = 1,
               color_line = 'black',
               alpha_sets = 0.3,
               font_sets = False, # False o 'bold'
               size_vals_sets = 12,
               alpha_inter = 0.3,
               font_inter = False, # False o 'bold'
               size_vals_inter = 12,
               size_label = 12,
               font_label = False): # False o 'bold'
    v = venn3_unweighted(subsets = (set1, set2, set3), set_labels = (lab_set1, lab_set2, lab_set3))
    c = venn3_circles(subsets = (1, 1, 1, 1, 1, 1, 1),
                      linestyle='--', linewidth = linewidth, color = color_line)
    partes = ['100', '010', '110', '001', '101', '011', '111']
    partes2 = ['100', '010', '110', '001', '101', '011']
    venn_info = [[i, j] for i, j in zip(v.subset_labels, partes)]
    for i in venn_info:
        if i[0] != None:
            if i[1] in partes2:
                v.get_patch_by_id(i[1]).set_alpha(alpha_sets) # i[1] = el conjunto creado,  0 = alpha del conjunto
                v.get_label_by_id(i[1]).set_fontweight(font_sets)
                v.get_label_by_id(i[1]).set_fontsize(size_vals_sets)
            if i[1] == '111': # configurar la intersección independientemente '111'
                v.get_patch_by_id('111').set_alpha(alpha_inter) # i[1] = el conjunto creado,  0 = alpha del conjunto
                v.get_label_by_id('111').set_fontweight(font_inter)
                v.get_label_by_id('111').set_fontsize(size_vals_inter)    
    for text in v.set_labels:
        text.set_fontsize(size_label)
        text.set_fontweight(font_label)
Example #17
0
def venn_3():
    for name, subset in subsets_dict_3.items():
        normalize = 0.0015

        v = venn3(subsets=subset,
                  normalize_to=normalize,
                  set_labels=("", "", ""))
        v.get_patch_by_id('100').set_color('orangered')
        v.get_patch_by_id("010").set_color('grey')
        v.get_patch_by_id("001").set_color('yellow')
        v.get_label_by_id('111').set_text("")
        v.get_label_by_id('110').set_text("")
        v.get_label_by_id('101').set_text("")
        v.get_label_by_id('011').set_text("")
        v.get_label_by_id('10').set_text("")
        v.get_label_by_id('010').set_text("")
        v.get_label_by_id('001').set_text("")
        c = venn3_circles(subsets=subset,
                          color="black",
                          normalize_to=normalize,
                          linewidth=1.5)

        file_name = name + "_notext.png"
        file_final_path = file_path + file_name
        plt.savefig(file_final_path,
                    transparent=True,
                    bbox_inches="tight",
                    pad_inches=-1.1)
        plt.close()
Example #18
0
def venn3_plot(sets, set_labels=('A', 'B', 'C'), 
    set_colors=None, alpha=1.0, circle_on=False):
    """
    venn3 plot based on venn3 and venn3_circles from matplotlib_venn.

    Example:
    --------
    set1 = set(['A', 'B', 'C', 'D'])
    set2 = set(['B', 'C', 'D', 'E'])
    set3 = set(['C', 'D',' E', 'F', 'G'])
    venn3_plot([set1, set2, set3], ('Set1', 'Set2', 'Set3'))
    """
    from matplotlib_venn import venn3, venn3_circles

    if circle_on:
        v = venn3_circles(subsets=(1,1,1,1,1,1,1), alpha=0.8, color="r")
    if set_colors is None: 
        set_colors = favorite_colors[:3]
    v = venn3(subsets=(1,1,1,1,1,1,1), set_labels=set_labels, 
        set_colors=set_colors, alpha=alpha)
    v.get_label_by_id('111').set_text(len(sets[0]&sets[1]&sets[2]))
    v.get_label_by_id('110').set_text(len(sets[0]&sets[1]-sets[2]))
    v.get_label_by_id('101').set_text(len(sets[0]-sets[1]&sets[2]))
    v.get_label_by_id('100').set_text(len(sets[0]-sets[1]-sets[2]))
    v.get_label_by_id('011').set_text(len(sets[2]&sets[1]-sets[0]))
    v.get_label_by_id('010').set_text(len(sets[1]-sets[2]-sets[0]))
    v.get_label_by_id('001').set_text(len(sets[2]-sets[1]-sets[0]))

    return v
def PlotGPVenns():
    file_bases = '/rscratch/asl47/Bulk_Run/Modular'
    avg_G_size = [[] for i in range(7)]

    for I in range(3):
        for run in range(50):
            avg_G_size[I].append(
                file_len(
                    '{}/A1_T20_C200_N10000_Mu0.003125_O1_K{}000_I{}_Run{}_Genotype.txt'
                    .format(file_bases, 15 if I == 0 else 20, I, run)))

    for I in range(3):
        for run in range(50):
            avg_G_size[3 + I].append(
                file_len(
                    '{}/A2_T20_C200_N10000_Mu0.003125_O1_K20000_I{}_Run{}_Genotype.txt'
                    .format(file_bases, I, run)))

    for run in range(25):
        avg_G_size[6].append(
            file_len(
                '{}/A3_T20_C200_N10000_Mu0.003125_O1_K20000_I0_Run{}_Genotype.txt'
                .format(file_bases, run)))

    # Abc # aBc # ABc # abC # AbC # aBC # ABC
    #return avg_G_size
    s = list(
        np.mean(G) / norming
        for G, norming in zip(avg_G_size, [50, 50, 50, 50, 50, 50, 25])
    )  #(square_only,cross_only,square_cross, tetris_only,square_tetris,cross_tetris,complete)
    print(s)
    v = venn3(subsets=s, set_labels=('A', 'B', 'C'))

    # Subset labels
    v.get_label_by_id('100').set_text('Abc')
    v.get_label_by_id('010').set_text('aBc')
    v.get_label_by_id('110').set_text('ABc')
    v.get_label_by_id('001').set_text('Abc')
    v.get_label_by_id('101').set_text('aBc')
    v.get_label_by_id('011').set_text('ABc')
    v.get_label_by_id('111').set_text('ABC')

    # Subset colors
    v.get_patch_by_id('100').set_color('c')
    v.get_patch_by_id('010').set_color('#993333')
    v.get_patch_by_id('110').set_color('blue')

    # Subset alphas
    v.get_patch_by_id('101').set_alpha(0.4)
    v.get_patch_by_id('011').set_alpha(1.0)
    v.get_patch_by_id('111').set_alpha(0.7)

    # Border styles
    c = venn3_circles(subsets=s, linestyle='solid')
    c[0].set_ls('dotted')  # Line style
    c[1].set_ls('dashed')
    c[2].set_lw(1.0)  # Line width

    plt.show(block=False)
Example #20
0
def plot_venn_diagram(data, ax=None, fontsize=25, alpha=0.6, x_loc=0.01, y_loc=-0.1):
    """Plot a Venn diagram of the three samples of galaxies."""
    # Making the plot
    if ax is None:
        fig = plt.figure(figsize=(9, 6))
        fig.subplots_adjust(
            left=0.01, right=0.99, bottom=0.01, top=0.99, wspace=0, hspace=0)
        ax = fig.add_subplot(111)
        use_ax = False
    else:
        use_ax = True

    set_1 = data['sample_1']['set']
    set_2 = data['sample_2']['set']
    if data['sample_3'] is None:
        set_list = [set_1, set_2]
        set_3 = None
        name_list = (
            data['sample_1']['name'], data['sample_2']['name'])
        color_list = (
            data['sample_1']['color'], data['sample_2']['color'])
    else:
        set_3 = data['sample_3']['set']
        set_list = [set_1, set_2, set_3]
        name_list = (
            data['sample_1']['name'], data['sample_2']['name'], data['sample_3']['name'])
        color_list = (
            data['sample_1']['color'], data['sample_2']['color'], data['sample_3']['color'])

    if set_3 is not None:
        vd = venn3(
            set_list, set_labels=name_list, set_colors=color_list, alpha=alpha, ax=ax)
        vdc = venn3_circles(set_list, linestyle='-', linewidth=3, color='grey', ax=ax)
    else:
        vd = venn2(
            set_list, set_labels=name_list, set_colors=color_list, alpha=alpha, ax=ax)
        vdc = venn2_circles(set_list, linestyle='-', linewidth=3, color='grey', ax=ax)

    vdc[1].set_ls("-.")
    if set_3 is not None:
        vdc[2].set_ls(":")

    for text in vd.set_labels:
        text.set_fontsize(fontsize)
    for text in vd.subset_labels:
        text.set_fontsize(fontsize)

    if set_3 is not None:
        _ = ax.text(
            x_loc, y_loc, r'${:3.1f} < z < {:3.1f}$'.format(data['z_low'], data['z_upp']),
            transform=ax.transAxes, fontsize=fontsize)
        _ = ax.text(
            x_loc, y_loc + 0.11,
            r'$\rm Top\ [{:d}:{:d}]$'.format(data['index_low'], data['index_upp']),
            transform=ax.transAxes, fontsize=fontsize)

    if use_ax:
        return ax
    return fig
Example #21
0
def SimpleMatplotVenn(names, data, outputDir=False, display=True):
    """ Uses http://pypi.python.org/pypi/matplotlib-venn (code combined into one module) to export
    simple or complex, overlapp weighted venn diagrams as an alternative to the default methods in
    this module """

    import numpy as np
    pylab.figure(figsize=(11, 7), facecolor='w')

    vd = get_labels(data, fill="number")
    set_labels = []
    for i in names:
        set_labels.append(string.replace(i, '.txt', ''))

    if len(set_labels) == 2:
        from matplotlib_venn import venn2, venn2_circles
        set_colors = ('r', 'g')
        subsets = (vd['10'], vd['01'], vd['11'])
        v = venn2(subsets=subsets,
                  set_labels=set_labels,
                  set_colors=set_colors)
        c = venn2_circles(subsets=subsets,
                          alpha=0.5,
                          linewidth=1.5,
                          linestyle='dashed')

    if len(set_labels) == 3:
        from matplotlib_venn import venn3, venn3_circles
        set_colors = ('r', 'g', 'b')
        subsets = (vd['100'], vd['010'], vd['110'], vd['001'], vd['101'],
                   vd['011'], vd['111'])
        v = venn3(subsets=subsets,
                  set_labels=set_labels,
                  set_colors=set_colors)
        c = venn3_circles(subsets=subsets,
                          alpha=0.5,
                          linewidth=1.5,
                          linestyle='dashed')

    pylab.title("Overlap Weighted Venn Diagram", fontsize=24)

    try:
        if outputDir != False:
            filename = outputDir + '/%s.pdf' % venn_export_weighted
            pylab.savefig(filename)
            filename = outputDir + '/%s.png' % venn_export_weighted
            pylab.savefig(filename, dpi=100)  #,dpi=200
    except Exception:
        print 'Image file not saved...'

    if display:
        pylab.show()

    try:
        import gc
        fig.clf()
        pylab.close()
        gc.collect()
    except Exception:
        pass
Example #22
0
def plot_venn3(subsets: Tuple[set, set, set], labels: Tuple[str, str, str]):
    # Custom text labels: change the label of group A
    v = venn3(subsets=subsets, set_labels=labels)
    c = venn3_circles(subsets=subsets,
                      linestyle='dashed',
                      linewidth=1,
                      color="grey")
    plt.show()
Example #23
0
def plot_venn3_set(dict_of_sets, overlap_name, folder):
    '''
    Makes 3 way venn from 3 sets.
    Saves to file.

    Inputs
    ------
    dict_of_sets: dictionary of sets to overlap
    overlap_name: string with name of overlap
    folder: output folder

    Returns
    -------
    None

    '''
    folder = make_folder(f"{val_folder(folder)}venn_plot")

    plt.clf()
    plt.figure(figsize=(7, 7))

    font = {
        'family': 'sans-serif',
        'weight': 'normal',
        'size': 16,
    }

    plt.rc('font', **font)

    set_list = []
    set_names = []
    for name, setlist in dict_of_sets.items():
        set_list.append(setlist)
        set_names.append(name.replace('_', ' '))

    # make venn
    venn_plot = venn3(subsets=set_list, set_labels=set_names)
    patch = ['100', '110', '101', '010', '011', '001', '111']
    for p in patch:
        if venn_plot.get_patch_by_id(p):
            venn_plot.get_patch_by_id(p).set_color('none')
            venn_plot.get_patch_by_id(p).set_alpha(.4)
            venn_plot.get_patch_by_id(p).set_edgecolor('none')

    # make
    c = venn3_circles(subsets=set_list)
    colors_list = ['green', 'blue', 'grey']
    for circle, color in zip(c, colors_list):
        circle.set_edgecolor(color)
        circle.set_alpha(0.8)
        circle.set_linewidth(4)

    plt.title(f"{overlap_name.replace('_', ' ')} Overlaps")
    plt.tight_layout()
    plt.savefig(f"{folder}{overlap_name.replace(' ', '_')}-overlap.svg")
    plt.savefig(f"{folder}{overlap_name.replace(' ', '_')}-overlap.png",
                dpi=300)
    plt.close()
def build_venn(df, sample_base, variant_type):
    """
    Create overlapping sets from cosmic or gene variants to build Venn Diagrams
    
    Arguments:
    df - a cosmic or gene dataframe storing specific variants across passages
    sample_base - the patient id the PDX models were derived from
    variant_type - which variant class to subset ('gene' or 'cosmic')
    
    Output:
    Matplotlib axes to build a venn diagram
    """

    if variant_type == 'gene':
        subset_variant = 'Gene.refGene'
    elif variant_type == 'cosmic':
        subset_variant = 'cosmic70'

    # Build Venn Diagram for cosmic variants
    f0 = '{}-F0'.format(sample_base)
    f5 = '{}-F5'.format(sample_base)
    prim = '{}-primary'.format(sample_base)

    # Get sets of variants matching specific passages
    set_f0 = set(df.query('sample_name == @f0')[subset_variant])
    set_f5 = set(df.query('sample_name == @f5')[subset_variant])
    set_prim = set(df.query('sample_name == @prim')[subset_variant])

    # Build venn diagram
    if len(set_prim) == 0:
        v = venn2(subsets=(set_f0, set_f5), set_labels=(f0, f5))
        v.get_patch_by_id('11').set_color('#fdff5b')
        v.get_patch_by_id('10').set_color('#b8ff87')
        v.get_patch_by_id('01').set_color('#82fffc')
        c = venn2_circles(subsets=(set_f0, set_f5), linestyle='dashed')
    else:
        v = venn3(subsets=(set_f0, set_f5, set_prim),
                  set_labels=(f0, f5, prim))
        v.get_patch_by_id('110').set_color('#fdff5b')
        v.get_patch_by_id('100').set_color('#b8ff87')
        v.get_patch_by_id('010').set_color('#82fffc')
        v.get_patch_by_id('001').set_color('#ff82cf')
        v.get_patch_by_id('101').set_color('#ffb05b')
        v.get_patch_by_id('011').set_color('#992dff')
        v.get_patch_by_id('111').set_color('#6872ff')
        c = venn3_circles(subsets=(set_f0, set_f5, set_prim),
                          linestyle='dashed')

    # Obtain axes and show plot
    plt.title('{} {}'.format(sample_base, variant_type))
    fig = plt.gcf()
    venn_fig = os.path.join('figures', 'venns',
                            'venn_{}_{}.pdf'.format(sample_base, variant_type))
    plt.tight_layout()
    plt.savefig(venn_fig)
    plt.show()
    return fig
Example #25
0
 def venn_digram(self, names, figname):
     import matplotlib_venn
     from matplotlib_venn import venn3, venn3_circles, venn2, venn2_circles
     plt.figure(figsize=(4, 4))
     if len(names) == 2:
         set1 = set(self['venn'][names[0]])
         set2 = set(self['venn'][names[1]])
         venn2([set1, set2], (names[0], names[1]))
         venn2_circles([set1, set2])
     if len(names) == 3:
         set1 = set(self['venn'][names[0]])
         set2 = set(self['venn'][names[1]])
         set3 = set(self['venn'][names[2]])
         venn3([set1, set2, set3], (names[0], names[1], names[2]))
         venn3_circles([set1, set2, set3])
     plt.savefig('f.png.' + figname + '.png')
     plt.savefig('f.eps.' + figname + '.eps')
     plt.clf()
Example #26
0
def plot_venn():
    files = [
        '/Users/kingxu/result/IJCAI19result/nmt_bleu.txt',
        '/Users/kingxu/result/IJCAI19result/nngen_bleu.txt',
        '/Users/kingxu/result/IJCAI19result/codisum_bleu.txt',
        '/Users/kingxu/result/IJCAI19result/nmt_meteor.txt',
        '/Users/kingxu/result/IJCAI19result/nngen_meteor.txt',
        '/Users/kingxu/result/IJCAI19result/codisum_meteor.txt'
    ]
    dicts = [txt2dict(f) for f in files]
    sets1 = [dict2set(d, "[0.0, 0.1)") for d in dicts]
    sets2 = [dict2set(d, "[0.9, 1.0]") for d in dicts]
    plt.figure()
    subsets = sets2[3:]
    venn3(subsets=subsets, set_labels=('NMT', 'NNGen', 'CoDiSum'))
    venn3_circles(subsets=subsets, linestyle='dotted', linewidth=1.0)
    plt.savefig("METEOR1venn2.eps", format="eps")
    plt.show()
def Venn_Inter(dist_dic, dunn_dic, dca_pares, mystic_pares, graficos_ruta,
               caso_venn, ALL_VENN, caso_graf):

    # Armo conjuntos entre metodos
    # siguiente orden: Abc, aBc, ABc, abC, AbC, aBC, ABC.
    # DCA , MY , DUNN
    conj_dca = 0  # Abc
    conj_my = 0  # aBc
    conj_du = 0  # abC
    conj_dca_my = 0  #ABc
    conj_dca_du = 0  # AbC
    conj_my_du = 0  # aBC
    conj_dca_my_du = 0  #ABC

    for llaves in ALL_VENN:
        if (llaves in dunn_dic):
            if (llaves in dca_pares) and (llaves in mystic_pares):
                conj_dca_my_du += 1  #ABC
            elif (llaves in dca_pares):
                conj_dca_du += 1  # AbC
            elif (llaves in mystic_pares):
                conj_my_du += 1  # aBC
            else:
                conj_du += 1  # abC
        else:
            if (llaves in dca_pares) and (llaves in mystic_pares):
                conj_dca_my += 1  #ABc
            elif (llaves in dca_pares):
                conj_dca += 1  # Abc
            elif (llaves in mystic_pares):
                conj_my += 1  # aBc

    subsets = (conj_dca, conj_my, conj_dca_my, conj_du, conj_dca_du,
               conj_my_du, conj_dca_my_du)

    venn3(subsets, set_labels=('DCA', 'Mystic', caso_graf))
    venn3_circles(subsets,
                  color="#008000",
                  alpha=1,
                  linestyle="-.",
                  linewidth=3)
    plt.savefig(graficos_ruta + "venn_metodos_" + caso_venn + ".png",
                dpi=720)  # ver bien dnd salvar el grafico
    plt.clf()
Example #28
0
def plot_venn3_counts(element_list, set_labels, overlap_name, folder):
    '''
    Plot three way venn based on counts of specific overlaping numbers.
    Saves to file.

    Inputs
    ------
    element_list: tuple with counts of the the overlaps from (Abc,aBc,ABc,abC,AbC,ABC)
    set_labels: list or tuple with names of the overlaps ('A','B','C')
    overlap_name: string with name of overlap
    folder: output folder

    Returns
    -------
    None

    '''
    folder = make_folder(f"{val_folder(folder)}venn_plot")

    plt.clf()
    plt.figure(figsize=(7, 7))

    font = {
        'family': 'sans-serif',
        'weight': 'normal',
        'size': 16,
    }

    plt.rc('font', **font)

    # make venn
    venn_plot = venn3(
        subsets=element_list,
        set_labels=[name.replace('_', ' ') for name in set_labels])
    patch = ['100', '110', '101', '010', '011', '001', '111']
    for p in patch:
        if venn_plot.get_patch_by_id(p):
            venn_plot.get_patch_by_id(p).set_color('none')
            venn_plot.get_patch_by_id(p).set_alpha(.4)
            venn_plot.get_patch_by_id(p).set_edgecolor('none')

    # make
    c = venn3_circles(subsets=element_list)
    colors_list = ['green', 'blue', 'grey']
    for circle, color in zip(c, colors_list):
        circle.set_edgecolor(color)
        circle.set_alpha(0.8)
        circle.set_linewidth(4)

    plt.title(f"{overlap_name.replace('_', ' ')} Overlaps")
    plt.tight_layout()
    plt.savefig(f"{folder}{overlap_name.replace(' ', '_')}-overlap.svg")
    plt.savefig(f"{folder}{overlap_name.replace(' ', '_')}-overlap.png",
                dpi=300)
 def __init__(self, set_labels=[]):
     self.figure = PP.figure()
     super().__init__(self.figure)
     if len(set_labels) == 2:
         self.ids = ["10", "01", "11"]
         self.venn = V.venn2(subsets=(1, 1, 1),
                             set_labels=set_labels,
                             subset_label_formatter=lambda x: "",
                             set_colors=['white', 'white', 'white'])
         V.venn2_circles(subsets=(1, 1, 1))
     elif len(set_labels) == 3:
         self.ids = ["100", "010", "001", "110", "101", "011", "111"]
         self.venn = V.venn3(subsets=(1, 1, 1, 1, 1, 1, 1),
                             set_labels=set_labels,
                             subset_label_formatter=lambda x: "",
                             set_colors=[
                                 'white', 'white', 'white', 'white',
                                 'white', 'white', 'white'
                             ])
         V.venn3_circles(subsets=(1, 1, 1, 1, 1, 1, 1))
     else:
         raise ValueError()
def Venn_Intra(dist_dic, venn_TP_Comb, venn_TP_Mult, venn_TP_Para,
               graficos_ruta):
    conj_ad = 0  # Abc
    conj_mu = 0  # aBc
    conj_pa = 0  # abC
    conj_ad_mu = 0  #ABc
    conj_ad_pa = 0  # AbC
    conj_mu_pa = 0  # aBC
    conj_ad_mu_pa = 0  #ABC

    for llaves in dist_dic:
        if (llaves in venn_TP_Comb):
            if (llaves in venn_TP_Mult) and (llaves in venn_TP_Para):
                conj_ad_mu_pa += 1  #ABC
            elif (llaves in venn_TP_Para):
                conj_ad_pa += 1  # AbC
            elif (llaves in venn_TP_Comb):
                conj_ad_mu += 1  # ABc
            else:
                conj_ad += 1  # Abc
        else:
            if (llaves in venn_TP_Mult) and (llaves in venn_TP_Para):
                conj_mu_pa += 1  #aBC
            elif (llaves in venn_TP_Mult):
                conj_mu += 1  # aBc
            elif (llaves in venn_TP_Para):
                conj_pa += 1  # abC

    subsets = (conj_ad, conj_mu, conj_ad_mu, conj_pa, conj_ad_pa, conj_mu_pa,
               conj_ad_mu_pa)
    venn3(subsets, set_labels=('Aditiva', 'Multipli.', 'Para'))
    venn3_circles(subsets,
                  color="#008000",
                  alpha=1,
                  linestyle="-.",
                  linewidth=3)
    plt.savefig(graficos_ruta + "venn_dunn.png", dpi=720)
    plt.clf()
Example #31
0
def draw_venn(infile, outfile, weighted=False) :

	with open(infile, "r") as f:
		sets = pickle.load(f)

	if weighted:
		venn3_circles(sets)
		venn = venn3(sets, set_labels=('Aesthetics', 'Semantics', 'Aes+Sem'))
		for l in venn.subset_labels : 
			l.set_fontsize(14)

	else :
		venn = venn3_unweighted(sets, set_labels=('Aesthetics', 'Semantics', 'Aes+Sem'))
		for l in venn.subset_labels : 
			l.set_fontsize(14)

		ax = pp.gca()
		for (c, r) in zip(venn.centers, venn.radii):
				circle = Circle(c, r, lw=2, alpha=1, facecolor='none')
				ax.add_patch(circle)

	pp.savefig(outfile)
	pp.show()
Example #32
0
def SimpleMatplotVenn(names,data,outputDir=False,display=True):
    """ Uses http://pypi.python.org/pypi/matplotlib-venn (code combined into one module) to export
    simple or complex, overlapp weighted venn diagrams as an alternative to the default methods in
    this module """

    import numpy as np
    pylab.figure(figsize=(11,7),facecolor='w')
    
    vd = get_labels(data, fill="number")
    set_labels=[]
    for i in names:
        set_labels.append(string.replace(i,'.txt',''))
        
    if len(set_labels)==2:
        from matplotlib_venn import venn2, venn2_circles
        set_colors = ('r', 'g')
        subsets = (vd['10'], vd['01'], vd['11'])
        v = venn2(subsets=subsets, set_labels = set_labels, set_colors=set_colors)
        c = venn2_circles(subsets=subsets, alpha=0.5, linewidth=1.5, linestyle='dashed')
        
    if len(set_labels)==3:
        from matplotlib_venn import venn3, venn3_circles
        set_colors = ('r', 'g', 'b')
        subsets = (vd['100'], vd['010'], vd['110'], vd['001'], vd['101'], vd['011'], vd['111'])
        v = venn3(subsets=subsets, set_labels = set_labels,set_colors=set_colors)
        c = venn3_circles(subsets=subsets, alpha=0.5, linewidth=1.5, linestyle='dashed')
        
    pylab.title("Overlap Weighted Venn Diagram",fontsize=24)

    try:
        if outputDir!=False:
            filename = outputDir+'/%s.pdf' % venn_export_weighted
            pylab.savefig(filename)
            filename = outputDir+'/%s.png' % venn_export_weighted
            pylab.savefig(filename, dpi=100) #,dpi=200
    except Exception:
        print 'Image file not saved...'
        
    if display:
        pylab.show()

    try:
        import gc
        fig.clf()
        pylab.close()
        gc.collect()
    except Exception:
        pass
Example #33
0
def commons2plot(samples, csizes, output, title, dpi, format, verbose):
    """
    #https://github.com/konstantint/matplotlib-venn
    """
    #get sizes
    plt.figure(figsize=(6,6))
    v = venn3(subsets=csizes, set_labels=samples)
    c = venn3_circles(subsets=csizes, linewidth=0.1) # ,linestyle='dashed'
    plt.title(title)
    #show Venn if not outfile provided
    if output.name=="<stdout>":
        plt.show()
    else:
        fpath = "%s.%s" % (output.name, format)
        plt.savefig(fpath, dpi=dpi, facecolor='w', edgecolor='w',
          orientation='landscape', format=format, transparent=False)
Example #34
0
def scaledVenn(input_filename, sets_list, sets_names, title_for_venn,
               venn_output_file):
    sets_list_length = len(sets_list)
    venn_diag = ""
    plt.figure(figsize=(8, 8))
    if sets_list_length == 2:
        venn_diag = venn2(subsets=sets_list,
                          set_labels=(sets_names),
                          set_colors=('lightgray', 'dimgray'))
        c = venn2_circles(sets_list, linewidth=3, color="black")
        lblA = venn_diag.get_label_by_id("A")
        xA, yA = lblA.get_position()
        lblA.set_position((xA - 0.25, yA + 0.1))
        lblB = venn_diag.get_label_by_id("B")
        xB, yB = lblB.get_position()
        lblB.set_position((xB + 0.25, yB + 0.1))
    elif sets_list_length == 3:
        venn_diag = venn3(subsets=sets_list,
                          set_labels=(sets_names),
                          set_colors=('blueviolet', 'darkturquoise', 'tomato'))
        c = venn3_circles(sets_list, linewidth=3, color="black")
        lblA = venn_diag.get_label_by_id('A')
        xA, yA = lblA.get_position()
        lblA.set_position((xA - 0.1, yA - 0.1))
        lblB = venn_diag.get_label_by_id("B")
        xB, yB = lblB.get_position()
        lblB.set_position((xB - 0.25, yB + 0.05))
        lblC = venn_diag.get_label_by_id("C")
        xC, yC = lblC.get_position()
        lblC.set_position((xC - 0.25, yC))
    for text in venn_diag.set_labels:
        text.set_fontsize(18)
        text.set_family('arial')
        text.set_weight('bold')
    for text in venn_diag.subset_labels:
        if text is not None:
            text.set_fontsize(18)
            text.set_family('arial')
            text.set_weight('bold')

    plt.setp(plt.gca().spines.values(), linewidth=3)
    plt.gca().set_axis_on()
    plt.title(title_for_venn, fontsize=30, fontname='arial', weight='bold')

    plt.savefig(venn_output_file)
    plt.close()
    return ("done")
Example #35
0
def plot_venn_3(a, b, c, a_and_b, a_and_c, b_and_c, a_and_b_and_c, a_label="Group A", b_label="Group B", c_label="Group C"):
    '''use matplotlib venn library to plot three groups interactions'''
    position0 = int((a - a_and_b - a_and_c + a_and_b_and_c)/1000)
    position1 = int((b - b_and_c - a_and_b + a_and_b_and_c)/1000)
    position2 = int((a_and_b - a_and_b_and_c)/1000)
    position3 = int((c - a_and_c - b_and_c + a_and_b_and_c)/1000)
    position4 = int((a_and_c - a_and_b_and_c)/1000)
    position5 = int((b_and_c - a_and_b_and_c)/1000)
    position6 = int(a_and_b_and_c/1000)
 

    # Line style: can be 'dashed' or 'dotted' for example
    v = venn3(subsets=(position0, position1, position2, position3, position4,
                       position5, position6), set_labels=(a_label, b_label, c_label))
    c = venn3_circles(subsets=(position0, position1, position2, position3, position4,
                               position5, position6), linestyle='dashed', linewidth=1, color="grey")
    plt.savefig('outliers.png')
    plt.show()
Example #36
0
def venn_diagram(sets, names):
    """
    Plot a Venndiagram

    Parameters:
    -----------------------------
    sets: list of sets,
          elements that should be compared between samples

    names: tuple of str for the sets,
           elements that should be compared between samples
    """
    if len(sets) == 2:
        from matplotlib_venn import venn2, venn2_circles
        f = venn2(sets, names)
        f = venn2_circles(sets)
    elif len(sets) == 3:
        from matplotlib_venn import venn3, venn3_circles
        f = venn3(sets, names)
        f = venn3_circles(sets)
    return (f)
Example #37
0
def main():
    """main fcuntion
    """
    
    parser = cmdline_parser()
    args = parser.parse_args()
           
    if args.verbose:
        LOG.setLevel(logging.INFO)
    if args.debug:
        LOG.setLevel(logging.DEBUG)        
    
    if os.path.exists(args.plot):
        LOG.fatal("Cowardly refusing to overwrite already existing file %s" % args.plot)
        sys.exit(1)
        
    variants = []
    
    for arg in args.vcf:
        s = arg.rstrip().split(':')
        assert len(s)==3, ("Excpected argument format vcf:name:[txt] not found")
        (vcffile, name, text) = s
        print "DEBUG vcffile=%s name=%s text=%s" % (vcffile, name, text)
        
        LOG.info("Reading %s" % vcffile)
        # PyVCF can read gzip
        vcfreader = vcf.VCFReader(filename=vcffile)
        vars = [v for v in vcfreader if v.FILTER in [".", "PASS"] or len(v.FILTER)==0]
        LOG.info("Got %d vars" % len(vars))
        var_set = set(dict([(var_key(v), v) for v in vars]))
        variants.append(VcfContainer(name, vcffile, text, vars, var_set))
    
    subsets = [v.var_set for v in variants]
    labels = [v.name + "\n" + v.text for v in variants]
    v = venn3(subsets=subsets, set_labels=labels)
    c = venn3_circles(subsets=subsets, linestyle='solid')
    #plt.show()
    
    plt.savefig(args.plot)
Example #38
0
v.get_label_by_id('101').set_text('1141')
v.get_label_by_id('011').set_text('1290')
v.get_label_by_id('111').set_text('5904')

# # # Subset colors
v.get_patch_by_id('100').set_color('purple') 	
v.get_patch_by_id('010').set_color('green')
v.get_patch_by_id('110').set_color('orange')

# # # Subset alphas
v.get_patch_by_id('101').set_alpha(0.4)
v.get_patch_by_id('011').set_alpha(1.0)
v.get_patch_by_id('111').set_alpha(0.7)

# # # Border styles
c = venn3_circles(subsets=s, linestyle='solid')
c[0].set_ls('dotted')  # Line style
c[1].set_ls('dashed')
c[2].set_lw(1.0)       # Line width


plt.savefig('venn_diagram_abc.pdf')
plt.clf()


# # ###### Venn Diagram for Genospecies D and E
s = (
   3*83,  # Ab
   3*463,  # aB
   5904,  # AB
	)
Example #39
0
def making_venn(filename = 'C:/Users/MariaIzabel/Desktop/MASTER/PHD/Syn-Non/gene_groups/gene_groups.npy'):
	gene_groups = np.load(filename).item()
	pop = parse_pop_map()
	genospecies = ['gsA', 'gsB', 'gsC', 'gsD', 'gsE']

	venn_dictionary = define_combinations(genospecies)
	total_geno = {'gsA': 0, 'gsB':0, 'gsC': 0,'gsD': 0, 'gsE': 0}
	hist_per_geno = {'gsA': {}, 'gsB':{}, 'gsC': {},'gsD': {}, 'gsE': {}}

	for gene in gene_groups:
  		strains = gene_groups[gene]
  		gs_list = sp.array([pop[str(strain)]['genospecies'] for strain in strains])
  		counts_dict = Counter(gs_list)

  	# How many genes in total are present in each genospecies?
  	gs_list = sp.unique(gs_list)
  	print gs_list
  	for i in gs_list:
  		total_geno[i] += 1

  	# How many genes contain a given amount of strains from a certain genospecies?:
  	for geno, counts in counts_dict.items():
  		tup = (geno, counts)
  		if tup[1] not in hist_per_geno[tup[0]]:
  			hist_per_geno[tup[0]][tup[1]] = 1
    	else:
    		hist_per_geno[tup[0]][tup[1]] += 1

  	# How many genes are shared by each possible combination of genospecies?:    
  	gs_list_joined = "".join(sorted(sp.unique(gs_list)))
  	venn_dictionary[gs_list_joined] += 1


	print '\nAll the possible combinations is:', venn_dictionary
	print '\nTotal amount of genes present in each genospecies', total_geno
	print '\nDistribution of genes per genospecies', hist_per_geno
	json.dump(venn_dictionary, open("text.txt",'w'))


	'''Figures'''

	### Creating histograms
	'''Total number of strains present in each genopecies'''
	strains_geno = collections.OrderedDict() 
	strains_geno = {'gsC': 116, 'gsB': 34, 'gsA': 33, 'gsE': 11, 'gsD': 5}

	'''Total number of genes present in each genospecies'''

	make_histograms(total_geno, xlab = 'Genospecies', ylab = 'Genes', save_name = 'genes_genospecies.pdf')

	make_histograms(strains_geno, xlab = 'Genospecies', ylab = 'Strains', save_name = 'strains_genospecies.pdf')

	for i in strains_geno.keys():
  		make_histograms(hist_per_geno[i], xlab= 'Strains', ylab = 'Genes', save_name = i)

	#### Creating the venn diagram

	# # # Subset sizes
	s = (
     1082,   # Abc 
     898,    # aBc 
     332,    # ABc  
     3567,   # abC
     1141,   # AbC
     1290,   # DK/FR
     5904,   # ABC 
  	)

	v = venn3(subsets=s, set_labels=('Genospecies A', 'Genospecies B', 'Genospecies C'))

	# # # Subset labels
	v.get_label_by_id('100').set_text('1082')
	v.get_label_by_id('010').set_text('898')
	v.get_label_by_id('110').set_text('332')
	v.get_label_by_id('001').set_text('3567')
	v.get_label_by_id('101').set_text('1141')
	v.get_label_by_id('011').set_text('1290')
	v.get_label_by_id('111').set_text('5904')

	# # # Subset colors
	v.get_patch_by_id('100').set_color('purple') 	
	v.get_patch_by_id('010').set_color('green')
	v.get_patch_by_id('110').set_color('orange')

	# # # Subset alphas
	v.get_patch_by_id('101').set_alpha(0.4)
	v.get_patch_by_id('011').set_alpha(1.0)
	v.get_patch_by_id('111').set_alpha(0.7)

	# # # Border styles
	c = venn3_circles(subsets=s, linestyle='solid')
	c[0].set_ls('dotted')  # Line style
	c[1].set_ls('dashed')
	c[2].set_lw(1.0)       # Line width


	plt.savefig('venn_diagram_abc.pdf')
	plt.clf()


	# # ###### Venn Diagram for Genospecies D and E
	s = (
   	3*83,  # Ab
   	3*463,  # aB
   	5904,  # AB
	)

	v = venn2(subsets=s, set_labels=('Genospecies D', 'Genospecies E'))

	# # # Subset labels
	v.get_label_by_id('10').set_text('83')
	v.get_label_by_id('01').set_text('463')
	v.get_label_by_id('11').set_text('5904')

	# # # Subset colors
	v.get_patch_by_id('10').set_color('c')
	v.get_patch_by_id('01').set_color('#993333')
	v.get_patch_by_id('11').set_color('blue')

	# # # Subset alphas
	v.get_patch_by_id('10').set_alpha(0.4)
	v.get_patch_by_id('01').set_alpha(1.0)
	v.get_patch_by_id('11').set_alpha(0.7)

	# # # Border styles
	c = venn2_circles(subsets=s, linestyle='solid')
	c[0].set_ls('dashed')  # Line style
	c[0].set_lw(2.0)       # Line width


	plt.savefig('venn_diagram_de.pdf')
	plt.clf()
Example #40
0
def event_space():
    """
    pip install matplotlib-venn
    """
    from matplotlib import pyplot as plt
    # import numpy as np
    from matplotlib_venn import venn3, venn2, venn3_circles
    plt.figure(figsize=(4, 4))
    v = venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels=('A', 'B', 'C'))
    v.get_patch_by_id('100').set_alpha(1.0)
    v.get_patch_by_id('100').set_color('white')
    v.get_label_by_id('100').set_text('Unknown')
    v.get_label_by_id('A').set_text('Set "A"')
    c = venn3_circles(subsets=(1, 1, 1, 1, 1, 1, 1), linestyle='dashed')
    c[0].set_lw(1.0)
    c[0].set_ls('dotted')
    plt.show()

    same = set(['comparable', 'incomparable', 'same'])
    diff = set(['comparable', 'incomparable', 'diff'])
    # comparable = set(['comparable', 'same', 'diff'])
    # incomparable = set(['incomparable', 'same', 'diff'])
    subsets = [same, diff]  # , comparable, incomparable]
    set_labels = ('same', 'diff')  # , 'comparable', 'incomparable')
    venn3(subsets=subsets, set_labels=set_labels)
    plt.show()

    import plottool as pt
    pt.ensure_pylab_qt4()
    from matplotlib_subsets import treesets_rectangles
    tree = (
        (120, 'Same', None), [
            ((50, 'comparable', None), []),
            ((50, 'incomparable', None), [])
        ]
        (120, 'Diff', None), [
            ((50, 'comparable', None), []),
            ((50, 'incomparable', None), [])
        ]
    )

    treesets_rectangles(tree)
    plt.show()

    from matplotlib import pyplot as plt
    from matplotlib_venn import venn2, venn2_circles  # NOQA

    # Subset sizes
    s = (
        2,  # Ab
        3,  # aB
        1,  # AB
    )

    v = venn2(subsets=s, set_labels=('A', 'B'))

    # Subset labels
    v.get_label_by_id('10').set_text('A but not B')
    v.get_label_by_id('01').set_text('B but not A')
    v.get_label_by_id('11').set_text('A and B')

    # Subset colors
    v.get_patch_by_id('10').set_color('c')
    v.get_patch_by_id('01').set_color('#993333')
    v.get_patch_by_id('11').set_color('blue')

    # Subset alphas
    v.get_patch_by_id('10').set_alpha(0.4)
    v.get_patch_by_id('01').set_alpha(1.0)
    v.get_patch_by_id('11').set_alpha(0.7)

    # Border styles
    c = venn2_circles(subsets=s, linestyle='solid')
    c[0].set_ls('dashed')  # Line style
    c[0].set_lw(2.0)       # Line width

    plt.show()
Example #41
0
v.get_patch_by_id('100').set_alpha(0.49)
v.get_patch_by_id('101').set_alpha(0.49)
v.get_patch_by_id('110').set_alpha(0.49)
v.get_patch_by_id('111').set_alpha(0.49)

label = v.get_label_by_id('011')
label.set_x(label.get_position()[0] + 0.05)

label = v.get_label_by_id('101')
label.set_x(label.get_position()[0] - 0.03)

label = v.get_label_by_id('110')
label.set_x(label.get_position()[0] - 0.1)
label.set_y(label.get_position()[1] + 0.05)

c = venn3_circles(subsets={'001':93,'010':256,'011':93,'100':75,'101':89,'110':72,'111':754},
                  linestyle='dashed',ax=axes[1][0])
first = c[0]
first.set_edgecolor('red')

second = c[1]
second.set_edgecolor('green')

third = c[2]
third.set_edgecolor('blue')





#============================ draw GS 4B7-10,11,12
v = venn3(subsets={'001':86,'010':66,'011':29,'100':46,'101':26,'110':24,'111':199}, 
Example #42
0
def make_diagram(a_set, b_set, c_set):
    # Find the size of elements unique to a set
    a_only_set = a_set - b_set - c_set
    b_only_set = b_set - c_set - a_set
    c_only_set = c_set - a_set - b_set
    print("{} elements in only A: {}".format(len(a_only_set), a_only_set))
    print("{} elements in only B: {}".format(len(b_only_set), b_only_set))
    print("{} elements in only C: {}".format(len(c_only_set), c_only_set))

    # Find the intersections between each pair of systems.
    ab_set = a_set & b_set - c_set
    ac_set = a_set & c_set - b_set
    bc_set = b_set & c_set - a_set
    print("{} elements in both A & B: {}".format(len(ab_set), ab_set))
    print("{} elements in both A & C: {}".format(len(ac_set), ac_set))
    print("{} elements in both B & C: {}".format(len(bc_set), bc_set))

    # Find the intersections between all the systems.
    abc_set = a_set & b_set & c_set
    print("{} elemements in all sets: {}\n".format(len(abc_set), abc_set))

    # Find the union of all the systems.
    union_set = a_set | b_set | c_set
    print("There are {} unique elements in the sets.".format(len(union_set)))

    # Something about python framework blah blah blah.
    matplotlib.use('TkAgg')

    # Set the size of the regions.  Not sure about the logic behind the
    # ordering here.
    s = (
        len(a_only_set),
        len(b_only_set),
        len(ab_set),
        len(c_only_set),
        len(ac_set),
        len(bc_set),
        len(abc_set)
    )

    # This is the diagram object that we will twiddle.
    v = venn3(subsets=s, set_labels=('A', 'B', 'C'))

    # The labels will be the size of the regions.  With three groups,
    # there will be seven regions.
    v.get_label_by_id('100').set_text(len(a_only_set))
    v.get_label_by_id('010').set_text(len(b_only_set))
    v.get_label_by_id('110').set_text(len(ab_set))
    v.get_label_by_id('001').set_text(len(c_only_set))
    v.get_label_by_id('101').set_text(len(ac_set))
    v.get_label_by_id('011').set_text(len(bc_set))
    v.get_label_by_id('111').set_text(len(abc_set))

    # Make some cosmetic settings.
    venn3_circles(subsets=s, linestyle='dotted')

    # Create the window with the graph
    plt.show()

    # Write the results out to files.  Should I wrap all of this into an
    # object?
    write_to_file()
Example #43
0
          
          elif sl_arr_BEAF.any() and not (sl_arr_CTCF.any() or sl_arr_SuHW.any()):
                
                count_aBc += 1  
          
          elif sl_arr_SuHW.any() and not (sl_arr_CTCF.any() or sl_arr_BEAF.any()):                      
                
                count_abC += 1
      
          else:
                pass                            
                
plt.figure()
plt.title("Venn Diagram")                
v = venn3(subsets = (count_Abc, count_aBc, count_ABc, count_abC, count_AbC, count_aBC, count_ABC), set_labels = ("CTCF", "BEAF", "SuHW"))       
c = venn3_circles(subsets=(count_Abc, count_aBc, count_ABc, count_abC, count_AbC, count_aBC, count_ABC))         
plt.savefig("overlaps.png")
#print "Total arr:", total_arr, "total_arr_CTCF:", total_arr_CTCF, "Count CTCF:", count_Abc, "Total BEAF:", total_arr_BEAF, "Count BEAF:", count_aBc, "Total SuHW:", total_arr_SuHW, "Count SuHW:", count_abC 
 

 


      
      #20 % overlap
 #         twentyper_arr += (np.sum( sl_arr ) / len( sl_arr ) > 0.2 )
  #        twentyper_arr2 += (np.sum(sl_arr2) / len( sl_arr2) > 0.2 )
      
#print "%d vs %d - Total: %d 20 percent overlap: %d" % (x, i, total, twentyper_overlap) 

Example #44
0
pd.DataFrame(lists[5], columns=[compare[1] + ' & ' + compare[2]]) \
    .to_excel(ew, sheet_name=compare[1] + ' & ' + compare[2], index=False)

pd.DataFrame(lists[6], columns=[compare[2]]) \
    .to_excel(ew, sheet_name=compare[2], index=False)

ew.save()

# Count the elements in each group
subsets = [len(lists[0]), len(lists[4]), len(lists[1]), len(lists[6]),
           len(lists[2]), len(lists[5]), len(lists[3])]

# Basic venn diagram
fig = plt.figure(1)
ax = fig.add_subplot(1, 1, 1)
v = venn3(subsets, (compare[0], compare[1], compare[2]), ax=ax)
c = venn3_circles(subsets)

# Annotation
ax.annotate('Total genes:\n' + str(len(union)),
            xy=v.get_label_by_id('111').get_position() - np.array([-0.5,
                                                                   0.05]),
            xytext=(0,-70), ha='center', textcoords='offset points',
            bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.3))

# Title
plt.title(compare[0] + ' & ' + compare[1] + ' & ' + compare[2] +
          ' gene expression overlap')

plt.show()
def linear_regression_venn3(gene, grouping, subgroups, showplot=False):
	# move to correct directory
	os.chdir('%s\\Linear_Regression' % grouping)
	# pull in gene lists
	group1 = pd.read_csv('short_summary_%s.csv' % subgroups[0], index_col = 0)
	group2 = pd.read_csv('short_summary_%s.csv' % subgroups[1], index_col = 0)
	group3 = pd.read_csv('short_summary_%s.csv' % subgroups[2], index_col = 0)

	group1_genes = set(group1.index.tolist())
	group2_genes = set(group2.index.tolist())
	group3_genes = set(group3.index.tolist())
	allgenes = list(set(list(group1_genes) + list(group2_genes) + list(group3_genes)))
	allgenes.sort()

	# plot venn diagram of gene list intersections
	fig, ax = plt.subplots(figsize=(12,12))
	v = venn3([group1_genes, group2_genes, group3_genes], (subgroups), alpha=0.5)
	for x in v.set_labels:
		x.set_name('Arial')
		x.set_size(24)
	for x in v.subset_labels:
		x.set_name('Arial')
		x.set_size(19)
	c = venn3_circles([group1_genes, group2_genes, group3_genes], linestyle='solid')
	plt.title('Genes Correlated to %s by Subgroup' % gene, fontname='Arial', fontsize=30)
	textbox = dict(horizontalalignment = 'center', verticalalignment = 'center', fontname = 'Arial', fontsize = 22)
	plt.text(0.5, 0.97, '%d total genes' % (len(allgenes)), textbox, transform=ax.transAxes)
	plt.tight_layout()
	if showplot == True:
		plt.show()
	fig.savefig('Venn_Diagram.png', transparent = True)
	fig.savefig('Venn_Diagram.eps', transparent = True)

	# create and save total gene list with TRUE and FALSE variables for sorting
	groups = {subgroups[0]: set(group1_genes), subgroups[1]: set(group2_genes), subgroups[2]: set(group3_genes)}

	summary = {}
	for group in subgroups:
		summary[group] = {}
		for gene in allgenes:
			if gene in groups[group]:
				summary[group][gene] = True
			else:
				summary[group][gene] = False

	df = pd.DataFrame.from_dict(summary)
	df.to_csv("Venn_Diagram.csv")

	# create a short list with unique values for each group as well as overall intersections
	group1_alone = df[(df[subgroups[0]] == True ) & (df[subgroups[1]] == False) & (df[subgroups[2]] == False)].index.values.tolist()
	group2_alone = df[(df[subgroups[1]] == True ) & (df[subgroups[0]] == False) & (df[subgroups[2]] == False)].index.values.tolist()
	group3_alone = df[(df[subgroups[2]] == True ) & (df[subgroups[1]] == False) & (df[subgroups[0]] == False)].index.values.tolist()
	intersection = df[(df[subgroups[0]] == True ) & (df[subgroups[1]] == True) & (df[subgroups[2]] == True)].index.values.tolist()

	venn_summary = {subgroups[0]: group1_alone, subgroups[1]: group2_alone, subgroups[2]: group3_alone, 'intersection': intersection}

	with open('Venn_Summary.txt', 'w') as f:
		for key in subgroups:
			f.write('%s\t%d genes\t' % (key, len(venn_summary[key])))
			for gene in venn_summary[key]:
				f.write('%s\t' % gene)
			f.write('\n')
		f.write('Intersection\t%d genes\t' % (len(venn_summary['intersection'])))
		for gene in venn_summary['intersection']:
			f.write('%s\t' % gene)
		f.write('\n')

	elevate()
	elevate()
Example #46
0
    cluster_dic = cluster_dic(fi_clstr)
    l_lab = []
    for f in fi_gene_list:
        sys.stderr.write(f)
        f = f.rstrip()
        tran_name(f, cluster_dic)
        l_lab.append(f.split('/')[-1].split('.')[0])

    l_sets = [set(i) for i in stat_set(s_gene_list).values()]
    sys.stderr.write('End at ' + time.ctime(time.time()) + '\n')

    # draw ven
    if len(fi_gene_list) == 3:
        v = venn3(l_sets, tuple(l_lab))
        # v.get_patch_by_id('010').set_color('#00447E')
        # v.get_patch_by_id('001').set_color('#F34800')

        v.get_label_by_id('100').set_size('10')
        v.get_label_by_id('010').set_size('10')
        v.get_label_by_id('001').set_size('10')
        v.get_label_by_id('110').set_size('10')
        v.get_label_by_id('101').set_size('10')
        v.get_label_by_id('011').set_size('10')
        v.get_label_by_id('111').set_size('10')

        venn3_circles(l_sets, linestyle='dashed')
        # c[0].set_lw(1.0)
        # c[0].set_ls('dotted')
        plt.title("Venn diagram")
        plt.savefig('ven3.pdf')
from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3, venn3_circles
from matplotlib_venn import venn2, venn2_circles
figure, axes = plt.subplots(2, 2)
venn2(subsets={'10': 1, '01': 1, '11': 1}, set_labels = ('A', 'B'), ax=axes[0][0])
venn2_circles((1, 2, 3), ax=axes[0][1])
venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels = ('A', 'B', 'C'), ax=axes[1][0])
venn3_circles({'001': 10, '100': 20, '010': 21, '110': 13, '011': 14}, ax=axes[1][1])
plt.show()
Example #48
0
from matplotlib_venn import venn2
venn2(subsets = (3, 2, 1))

# For the three-circle case:

from matplotlib_venn import venn3
venn3(subsets = (1, 1, 1, 2, 1, 2, 2), set_labels = ('Set1', 'Set2', 'Set3'))


# more elaborate example

from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3, venn3_circles
plt.figure(figsize=(4,4))
v = venn3(subsets=(1, 1, 1, 1, 1, 1, 1), set_labels = ('A', 'B', 'C'))
v.get_patch_by_id('100').set_alpha(1.0)
v.get_patch_by_id('100').set_color('white')
v.get_label_by_id('100').set_text('Unknown')
v.get_label_by_id('A').set_text('Set "A"')
c = venn3_circles(subsets=(1, 1, 1, 1, 1, 1, 1), linestyle='dashed')
c[0].set_lw(1.0)
c[0].set_ls('dotted')
plt.title("Sample Venn diagram")
plt.annotate('Unknown set', xy=v.get_label_by_id('100').get_position() - np.array([0, 0.05]), xytext=(-70,-70),
             ha='center', textcoords='offset points', bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.1),
             arrowprops=dict(arrowstyle='->', connectionstyle='arc3,rad=0.5',color='gray'))
plt.show()
        if slA.any() & ~slB.any() & ~slC.any():
            countA += 1
        
        if ~slA.any() & slB.any() & ~slC.any():
            countB += 1
        
        if ~slA.any() & ~slB.any() & slC.any():
            countC += 1
        
        if slA.any() & slB.any() & ~slC.any():
            countAB += 1
        
        if ~slA.any() & slB.any() & slC.any():
            countBC += 1
        
        if slA.any() & ~slB.any() & slC.any():
            countAC += 1
            
        if slA.any() & slB.any() & slC.any():
            countABC += 1

# venn subset order: A, B, AB, C, AC, BC, ABC

plt.figure()
v = venn3(subsets= (countA, countB, countAB, countC, countAC, countBC, countABC), set_labels = ("CTCF", "BEAF", "Su(HW)"))
c = venn3_circles(subsets = (countA, countB, countAB, countC, countAC, countBC, countABC))
plt.savefig("d4lunchvenncorrected.png")
        
        
        
        sl7 = sl3 & sl4
        if len(sl7) > 0:
            total += 1 
            count7 += (np.sum(sl7)/len(sl7) > 0.5)
        
        sl8 = sl2 & sl3 & sl4
        if len(sl8) > 0:
            total += 1
            count8 += (np.sum(sl8)/len(sl8) > 0.5)

CTCF_1 = count2
BEAF_1 = count3
SU_1 = count4 
CTCFBEAF = int(count5 / 2)
CTCFSU = int(count6 / 2)
BEAFSU = int(count7 / 2)
CTCFBEAFSU = int(count8 / 3)

#A, B, AB, C, AC, BC, ABC

plt.figure()
v = venn3(subsets= (CTCF_1, BEAF_1, CTCFBEAF, SU_1, CTCFSU, BEAFSU, CTCFBEAFSU), set_labels = ("CTCF", "BEAF", "Su(HW)"))
c = venn3_circles(subsets = (CTCF_1, BEAF_1, CTCFBEAF, SU_1, CTCFSU, BEAFSU, CTCFBEAFSU))
plt.savefig("d4lunchvenn.png")

print "Total: %d, Count(C-len): %d, Count(B-len): %d, Count4(S-len): %d, Count(C-B): %d, Count(C-S): %d, Count(B-S): %d,  Count(C-S-B): %d" % (total, count2, count3, count4, count5, count6, count7, count8)
        
        
        
        
Example #51
0
# get sets of sig genes

def create_sig_set(fl):
    fl_open = open(fl)
    gene_set = set()
    for line in fl_open:
        line = line.strip()
        cols = line.split(" ")
        gene = cols[0]
        gene_set.add(gene)
    return gene_set

set_list = []
for fl in sys.argv[1:]:
    new_set = create_sig_set(fl)
    set_list.append(new_set)

# now create venn diagrams of these sets
text_names = [name.split(".")[0] for name in sys.argv[1:]]
if len(set_list) == 2:
    vn.venn2(set_list, text_names)
    c = vn.venn2_circles(set_list, linestyle='dashed')
if len(set_list) == 3:
    vn.venn3(set_list, text_names)
    c = vn.venn3_circles(set_list, linestyle='dashed')
for circ in c:
    circ.set_lw(1.0)
plt.show()