Example #1
0
def venn(inp, names, title="venn", folder=''):
    """
    Plots a venn diagram using the pyvenn package

    Args:
    -----
      inp: list[set()] of sets of values (e.g. [(1,2,3,4),(2,3),(1,3,4,5)])
      names: list[str] of the name of each leaf
      title: str the plot title
      folder: str of location where to save the plot, won't save if empty
    """
    labels = pyvenn.get_labels(inp, fill=['number', 'logic'])
    if len(inp) == 2:
        fig, ax = pyvenn.venn2(labels, names=names)
    elif len(inp) == 3:
        fig, ax = pyvenn.venn3(labels, names=names)
    elif len(inp) == 4:
        fig, ax = pyvenn.venn4(labels, names=names)
    elif len(inp) == 5:
        fig, ax = pyvenn.venn5(labels, names=names)
    elif len(inp) == 6:
        fig, ax = pyvenn.venn6(labels, names=names)
    else:
        raise ValueError('need to be between 2 to 6')
    ax.set_title(title)
    if folder:
        fig.savefig(folder + title + '_venn.pdf')
    fig.show()
    plt.pause(0.1)
Example #2
0
def generate_venn_diagram(nb_dim, files, names, sep, label):
    """Cette fonction fait l'appel du fichier venn.py (qui doit être présent dans le même dossier que generate_venn.py)
	pour générer les diagrammes de Venn.
	:param: nombre de dimensions présent dans le diagramme de Venn (1 < nb_dim <= 6)
	:param: files: liste des chemins d'accès aux fichiers contenant les résultats des modèles
	:param: names: liste des noms des modèles (doit être en adéquation avec la liste des modèles files)
	:param: sep: séparateur présent dans filename séparant les id-instance des label 
	:label: label que l'on souhaite extraire
	"""
    if nb_dim < 2 or nb_dim > 6:
        print(
            'Le diagramme de Venn ne peut être généré que pour un nombre de dimensions supérieur à un et inférieur ou égal à 6.'
        )
    else:
        i = 0
        models = []
        while i < nb_dim:
            models.append(
                get_id_instances_title(files[i], sep=sep, label=label))
            i += 1

        labels = venn.get_labels(models)
        if nb_dim == 2:
            fig, ax = venn.venn2(labels, names=names)
            plt.show()
        elif nb_dim == 3:
            fig, ax = venn.venn3(labels, names=names)
            plt.show()
        elif nb_dim == 4:
            fig, ax = venn.venn4(labels, names=names)
            plt.show()
        elif nb_dim == 5:
            fig, ax = venn.venn5(labels, names=names)
            plt.show()
        elif nb_dim == 6:
            fig, ax = venn.venn6(labels, names=names)
            plt.show()
        else:
            print(
                'Le diagramme de Venn ne peut être généré que pour un nombre de dimensions supérieur à un et inférieur ou égal à 6.'
            )
Example #3
0
    def uniq_share_cal(self, infile):
        for line in infile:
            s = line.rstrip()
            orths = list(s.split('\t'))
            ids = []
            for x in xrange(len(orths)):
                item = orths[x].split('|')[0]
                if item in self.ids:
                    ids.append(item)
            target = set(ids)
            for key in self.data:
                if set(key) == target:
                    self.data[key] += 1

        labels = {}
        for key in self.data:
            key2 = ''
            for x in xrange(len(self.ids)):
                if self.ids[x] in key:
                    key2 += '1'
                else:
                    key2 += '0'
            labels[key2] = self.data[key]

        if len(self.ids) == 3:
            fig, ax = venn.venn3(labels, names=self.ids)
            fig.savefig('gene_family_3taxa.pdf')

        elif len(self.ids) == 4:
            fig, ax = venn.venn4(labels, names=self.ids)
            fig.savefig('gene_family_4taxa.pdf')

        elif len(self.ids) == 5:
            fig, ax = venn.venn5(labels, names=self.ids)
            fig.savefig('gene_family_5taxa.pdf')

        elif len(self.ids) == 6:
            fig, ax = venn.venn6(labels, names=self.ids)
            fig.savefig('gene_family_6taxa.pdf')
Example #4
0
     range(3, 8), range(8, 17)],
    fill=['number', 'logic'])
fig, ax = venn.venn4(labels, names=['list 1', 'list 2', 'list 3', 'list 4'])
fig.savefig('venn4.png', bbox_inches='tight')
plt.close()

labels = venn.get_labels(
    [range(10),
     range(5, 15),
     range(3, 8),
     range(8, 17),
     range(10, 20)],
    fill=['number', 'logic'])
fig, ax = venn.venn5(labels,
                     names=['list 1', 'list 2', 'list 3', 'list 4', 'list 5'])
fig.savefig('venn5.png', bbox_inches='tight')
plt.close()

labels = venn.get_labels([
    range(10),
    range(5, 15),
    range(3, 8),
    range(8, 17),
    range(10, 20),
    range(13, 25)
],
                         fill=['number', 'logic'])
fig, ax = venn.venn6(
    labels, names=['list 1', 'list 2', 'list 3', 'list 4', 'list 5', 'list 6'])
fig.savefig('venn6.png', bbox_inches='tight')
plt.close()
Example #5
0
matplotlib.use('Agg')

import matplotlib.pyplot as plt
import venn

labels = venn.get_labels([range(10), range(5, 15)], fill=['number', 'logic'])
fig, ax = venn.venn2(labels, names=['list 1', 'list 2'])
fig.savefig('venn2.png', bbox_inches='tight')
plt.close()

labels = venn.get_labels([range(10), range(5, 15), range(3, 8)], fill=['number', 'logic'])
fig, ax = venn.venn3(labels, names=['list 1', 'list 2', 'list 3'])
fig.savefig('venn3.png', bbox_inches='tight')
plt.close()

labels = venn.get_labels([range(10), range(5, 15), range(3, 8), range(8, 17)], fill=['number', 'logic'])
fig, ax = venn.venn4(labels, names=['list 1', 'list 2', 'list 3', 'list 4'])
fig.savefig('venn4.png', bbox_inches='tight')
plt.close()

labels = venn.get_labels([range(10), range(5, 15), range(3, 8), range(8, 17), range(10, 20)], fill=['number', 'logic'])
fig, ax = venn.venn5(labels, names=['list 1', 'list 2', 'list 3', 'list 4', 'list 5'])
fig.savefig('venn5.png', bbox_inches='tight')
plt.close()

labels = venn.get_labels([range(10), range(5, 15), range(3, 8), range(8, 17), range(10, 20), range(13, 25)], fill=['number', 'logic'])
fig, ax = venn.venn6(labels, names=['list 1', 'list 2', 'list 3', 'list 4', 'list 5', 'list 6'])
fig.savefig('venn6.png', bbox_inches='tight')
plt.close()

Example #6
0
        elif "full_model" in results_file:
            all_labels.append("Full model")

    for r_label in results:
        # print unique TP to this result
        tps = set(results[r_label]["all"]) & set(gold_pairs["all"])
        for r_label2 in results:
            if r_label2 == r_label:
                continue
            tps = tps - set(results[r_label2]["all"])
        print()
        print("unique to {}:".format(r_label))
        print(len(tps))
        print(tps)
        print()
    print(all_labels)
    # print(results)
    labels = venn.get_labels(all_pairs, fill=["number"])
    if len(all_pairs) == 2:
        fig, ax = venn.venn2(labels, names=all_labels)
    elif len(all_pairs) == 3:
        fig, ax = venn.venn3(labels, names=all_labels)
    elif len(all_pairs) == 4:
        fig, ax = venn.venn4(labels, names=all_labels)
    elif len(all_pairs) == 5:
        fig, ax = venn.venn5(labels, names=all_labels)
    elif len(all_pairs) == 6:
        fig, ax = venn.venn6(labels, names=all_labels)
    fig.savefig("{}.png".format("_".join(all_labels)), bbox_inches="tight")
    plt.close()