本文整理汇总了Python中matplotlib_venn.venn3函数的典型用法代码示例。如果您正苦于以下问题:Python venn3函数的具体用法?Python venn3怎么用?Python venn3使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了venn3函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: plotVennDiagram
def plotVennDiagram(fdr_threshold):
groundtruth = pd.read_csv(groundtruth_fn, names=['formula', 'adduct'])
sim_layer_formulas = groundtruth.groupby('adduct')
def top_results(df, threshold, adduct):
"""
results with estimated FDR < threshold and positive MSM
"""
fdr = df['fdr'] if 'fdr' in df else df['est_fdr']
return df[(fdr < threshold) & (df['adduct'] == adduct) &
(df['img'] * df['iso'] * df['moc'] > 0)]
for i, adduct in enumerate(orig['fdr'].keys()):
plt.subplot(len(orig['fdr']), 1, i + 1)
plt.title("Annotation overlap for {} (FDR threshold = {})"
.format(adduct, fdr_threshold))
orig_res = pd.read_csv(orig['fdr'][adduct])
sim_res = pd.read_csv(sim['fdr'][adduct])
db = set(orig_res['formula'])
orig_top = set(top_results(orig_res, fdr_threshold, adduct)['formula'])
sim_top = set(top_results(sim_res, fdr_threshold, adduct)['formula'])
venn3([orig_top, sim_top,
set(sim_layer_formulas.get_group(adduct)['formula']) & db],
("Orig. annotations", "Sim. annotations", "Sim. groundtruth & DB"))
示例2: plot_venn
def plot_venn(t1=None, t2=None, t3=None, ax=None, set_colors=('r', 'b', 'k')):
"""input: 2 or 3 tuples: (list/set, name_to_display) """
assert len(t1) == len(t2) == 2
if t3:
venn3( [set(t[0]) for t in [t1,t2,t3]], tuple( ['%s\n(%s)'%(t[1], len(set(t[0])) ) for t in [t1,t2,t3]]) , set_colors=set_colors, alpha=0.5,ax=ax)
else:
venn2( [set(t[0]) for t in [t1,t2]], tuple( ['%s\n(%s)'%(t[1], len(set(t[0])) ) for t in [t1,t2]]), set_colors=set_colors[0:2],alpha=0.5, ax=ax)
示例3: mi_venn_snps
def mi_venn_snps(df_snp_1, df_snp_2, df_snp_3, file='venn_snp.png'):
import matplotlib_venn
from matplotlib import pyplot as plt
n_A = len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist() ) )
n_B = len( set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist() ) )
n_C = len( set(df_snp_3[df_snp_3['SNP'].isin([1,2])].FID.tolist() ) )
n_AB = len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist() ) )
n_AC = len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_snp_3[df_snp_3['SNP'].isin([1,2])].FID.tolist() ) )
n_BC = len( set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_snp_3[df_snp_3['SNP'].isin([1,2])].FID.tolist() ) )
n_ABC = len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_snp_3[df_snp_3['SNP'].isin([1,2])].FID.tolist() ) )
n_Abc = n_A - n_AC - n_AB + n_ABC
n_aBc = n_B - n_BC - n_AB + n_ABC
n_ABc = n_AB - n_ABC
n_abC = n_C - n_BC - n_AC + n_ABC
n_AbC = n_AC - n_ABC
n_aBC = n_BC - n_ABC
n_ABC = n_ABC
print n_Abc, n_aBc, n_ABc, n_abC, n_AbC, n_aBC, n_ABC
# (Abc, aBc, ABc, abC, AbC, aBC, ABC)
matplotlib_venn.venn3(subsets = (n_Abc, n_aBc, n_ABc, n_abC, n_AbC, n_aBC, n_ABC), set_labels = ('SNP_1', 'SNP_2', 'SNP_3'))
plt.savefig(file)
plt.close()
示例4: plot_venn3
def plot_venn3(cp,nc,bx,cp_nc,cp_bx,nc_bx,cnb,plotName=None) :
fig = plt.figure()
venn3(subsets={'100':cp,'010':nc,'001':bx,'110':cp_nc,'101':cp_bx,'011':nc_bx,'111':cnb},set_labels = ('Salmonella enterica', 'Escherichia coli', 'Staphylococcus aureus'))
plt.title("Venn diagram")
if plotName :
plt.savefig(plotName)
else :
plt.show()
示例5: main
def main():
""" main function """
args = parse_args()
f_chimp = pysam.Samfile(args.f_chimp, "rb")
f_bono = pysam.Samfile(args.f_bono, "rb")
f_human = pysam.Samfile(args.f_human, "rb")
# stores the ID of each mapped reads in each samfile in a list
reads_chimp = list()
reads_bono = list()
reads_human = list()
for read in f_chimp:
reads_chimp.append(read.qname)
for read in f_bono:
reads_bono.append(read.qname)
for read in f_human:
reads_human.append(read.qname)
# find out if there is duplicate in the read IDs
# find the intersections between the three
overlap_bono_chimp = set(reads_bono).intersection(set(reads_chimp))
overlap_bono_human = set(reads_bono).intersection(set(reads_human))
overlap_chimp_human = set(reads_chimp).intersection(set(reads_human))
overlap_bono_chimp_human = (set(reads_bono).
intersection(set(reads_chimp)).
intersection(set(reads_human)))
#venn3() takes a list of 7 numbers:
#venn[6] -> number of reads mapped to human, chimp and bonobo
#venn[5] -> number of reads mapped to chimp and human but not bonobo
#venn[4] -> number of reads mapped to bonobo and human but not chimp
#venn[3] -> number of reads mapped to chimp and bonobo but not human
#venn[2] -> number of reads mapped only to human
#venn[1] -> number of reads mapped only to chimp
#venn[0] -> number of reads mapped only to bonobo
venn = [0]*7
venn[6] = overlap_bono_chimp_human
venn[5] = overlap_chimp_human - overlap_bono_chimp_human
venn[4] = overlap_bono_human - overlap_bono_chimp_human
venn[3] = overlap_bono_chimp - overlap_bono_chimp_human
venn[2] = f_human.mapped - venn[4] - venn[5] - overlap_bono_chimp_human
venn[1] = f_chimp.mapped - venn[3] - venn[5] - overlap_bono_chimp_human
venn[0] = f_bono.mapped - venn[3] - venn[4] - overlap_bono_chimp_human
#plot and save venn diagrams
venn3(subsets=venn, set_labels = ("Bonobo", "Chimpanzee", "Human"))
plt.title(args.plot_title)
plt.show()
示例6: mi_venn
def mi_venn(df_snp_1, df_snp_2, df_pheno, file='venn.png'):
import matplotlib_venn
from matplotlib import pyplot as plt
pheno = df_pheno.pheno_name
pheno_total = float(len(set(df_pheno[df_pheno['pheno_'+pheno]==2].FID.tolist()) ) )
snp_codes = [1,2]
print "Venn Diagram"
p_1 = float( len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist()) \
& set(df_pheno[df_pheno['pheno_'+pheno]==2].FID.tolist()) ) )
p_2 = float( len( set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist()) \
& set(df_pheno[df_pheno['pheno_'+pheno]==2].FID.tolist()) ) )
n_ABC = float( len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_pheno[df_pheno['pheno_'+pheno]==2].FID.tolist())
) )
n_AB = len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist() ) )
n_AC = len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_pheno[df_pheno['pheno_'+pheno]==2].FID.tolist())
)
n_BC = len( set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist() ) \
& set(df_pheno[df_pheno['pheno_'+pheno]==2].FID.tolist())
)
n_A = len( set(df_snp_1[df_snp_1['SNP'].isin([1,2])].FID.tolist() ) )
n_B = len( set(df_snp_2[df_snp_2['SNP'].isin([1,2])].FID.tolist() ) )
n_Abc = n_A - n_AC - n_AB + n_ABC
n_aBc = n_B - n_BC - n_AB + n_ABC
n_ABc = n_AB - n_ABC
n_abC = pheno_total - n_BC - n_AC + n_ABC
n_AbC = n_AC - n_ABC
n_aBC = n_BC - n_ABC
n_ABC = n_ABC
print "n_pheno: {}\t n_SNP_common: {}\t n_SNP_rare: {}\n".format(pheno_total, n_A, n_B)
print n_Abc, n_aBc, n_ABc, n_abC, n_AbC, n_aBC, n_ABC
# (Abc, aBc, ABc, abC, AbC, aBC, ABC)
matplotlib_venn.venn3(subsets = (n_Abc, n_aBc, n_ABc, n_abC, n_AbC, n_aBC, n_ABC), set_labels = ('SNP_common', 'SNP_rare', 'Pheno'))
plt.savefig(file)
plt.close()
示例7: venn3_sets
def venn3_sets(set_a, set_b, set_c, set_labels, ax):
# order of values for Venn diagram: (Abc, aBc, ABc, abC, AbC, aBC, ABC)
Abc = len(set_a.difference(set_b.union(set_c)))
aBc = len(set_b.difference(set_a.union(set_c)))
abC = len(set_c.difference(set_a.union(set_b)))
ABc = len(set_a.intersection(set_b).difference(set_c))
AbC = len(set_a.intersection(set_c).difference(set_b))
aBC = len(set_b.intersection(set_c).difference(set_a))
ABC = len(set_a.intersection(set_b).intersection(set_c))
venn3(subsets = (Abc, aBc, ABc, abC, AbC, aBC, ABC),
set_labels=set_labels, ax=ax)
示例8: plot_venn
def plot_venn(List_of_sets,
Set_labels,
Main = "I forgot to give this plot a name.",
Out_File = "",
Custom_overlap_numbers = []):
"""
Given a list of sets, generate a venn diagram in Out_Dir.
Arguments:
List_of_sets (two or three only!)
Set_labels: Label for each circle
Main: Title of plot
Out_File: Where should plot be saved? And what should the file be named?
Parent directory expected to already exist...
This will overwrite plots if they already exist
Custom_overlap_numbers: optional. If you want to supply your own 3 overlap sets:
[# in first, # in second, # in both]
"""
if not os.path.isdir(os.path.dirname(Out_File)):
raise ValueError(os.path.dirname(Out_File)+" <--- PATH DOESN'T EXIST")
if len(Custom_overlap_numbers) != 0 and len(Custom_overlap_numbers) != 3:
raise ValueError("Custom overlap only works for 2 circle venn diagrams at the moment...")
if len(Custom_overlap_numbers) == 3:
plt.figure()
venn2(subsets={'10': Custom_overlap_numbers[0], '01': Custom_overlap_numbers[1], '11': Custom_overlap_numbers[2]}, set_labels = Set_labels)
plt.title(Main)
plt.savefig(Out_File)
return
if len(List_of_sets) == 2:
if len(Set_labels) != 2:
raise ValueError("Set_labels needs to be the same length as the number of sets...")
# Default figure dimensions...
plt.figure()
venn2(List_of_sets,Set_labels)
plt.title(Main)
plt.savefig(Out_File)
elif len(List_of_sets) == 3:
if len(Set_labels) != 3:
raise ValueError("Set_labels needs to be the same length as the number of sets...")
# Default figure dimensions...
plt.figure()
venn3(List_of_sets,Set_labels)
plt.title(Main)
plt.savefig(Out_File)
else:
raise ValueError("List_of_sets needs to be of length 2 or 3.")
示例9: main
def main(list_sequence_names, output_prefix):
sequence_list = []
labels = []
for [filename, label] in list_sequence_names:
sequence_list.append(set(seq_IO.read_sequences(filename)))
labels.append(label)
fig, ax = pconv.create_ax(1, 1)
venn3(sequence_list, set_labels = labels, ax=ax[0,0])
pconv.save_fig(fig, output_prefix, '_'.join(labels)+"_venn", 10, 10, size=12)
示例10: test_pr_28
def test_pr_28():
import matplotlib_venn as mv
v = mv.venn3((1, 2, 3, 4, 5, 6, 7), subset_label_formatter = None)
assert v.get_label_by_id('010').get_text() == '2'
v = mv.venn3((1, 2, 3, 4, 5, 6, 7), subset_label_formatter = lambda x: 'Value: %+0.3f' % (x / 100.0))
assert v.get_label_by_id('010').get_text() == 'Value: +0.020'
v = mv.venn2((1, 2, 3), subset_label_formatter = None)
assert v.get_label_by_id('01').get_text() == '2'
v = mv.venn2((1, 2, 3), subset_label_formatter = lambda x: 'Value: %+0.3f' % (x / 100.0))
assert v.get_label_by_id('01').get_text() == 'Value: +0.020'
v = mv.venn3_unweighted((1, 2, 3, 4, 5, 6, 7), subset_label_formatter = lambda x: 'Value: %+0.3f' % (x / 100.0))
assert v.get_label_by_id('010').get_text() == 'Value: +0.020'
v = mv.venn2_unweighted((1, 2, 3), subset_label_formatter = lambda x: 'Value: %+0.3f' % (x / 100.0))
assert v.get_label_by_id('01').get_text() == 'Value: +0.020'
示例11: draw_venn3
def draw_venn3(A, B, C, sets):
venn = [0]*7
venn[2] = len(sets["AB"]) - len(sets["ABC"])
venn[4] = len(sets["AC"]) - len(sets["ABC"])
venn[5] = len(sets["BC"]) - len(sets["ABC"])
venn[6] = len(sets["ABC"])
venn[0] = len(sets["A"]) - venn[2] - venn[4] - venn[6]
venn[1] = len(sets["B"]) - venn[2] - venn[5] - venn[6]
venn[3] = len(sets["C"]) - venn[4] - venn[5] - venn[6]
labelA = A + " (" + str(len(sets["A"])) + ")"
labelB = B + " (" + str(len(sets["B"])) + ")"
labelC = C + " (" + str(len(sets["C"])) + ")"
venn3(subsets=venn, set_labels = (labelA, labelB, labelC))
plt.show()
示例12: venn3_plot
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
示例13: draw
def draw(set1, set2, set3, label1, label2, label3):
set1 = set(set1)
set2 = set(set2)
if label3:
set3 = set(set3)
v = venn3([set1,set2, set3], (label1, label2, label3))
plt.title('Venn diagram for hubs: ' + label1 + "," + label2 +"," + label3, fontsize=20)
else:
v = venn2([set1, set2], (label1, label2))
plt.title('Venn diagram for hubs:' + label1 + "," + label2, fontsize=20)
# if v.get_label_by_id('110'):
# plt.annotate(percent_of(set1,set2)+"% of " +label1 , xy=v.get_label_by_id('110').get_position() - np.array([0.15, 0.10]))
# plt.annotate(percent_of(set2,set1)+"% of " +label2 , xy=v.get_label_by_id('110').get_position() - np.array([0.15, 0.15]))
if v.get_patch_by_id('100'):
v.get_patch_by_id('100').set_color("blue")
if v.get_patch_by_id('010'):
v.get_patch_by_id('010').set_color("red")
if v.get_patch_by_id('110'):
v.get_patch_by_id('110').set_color("purple")
if label3 and v.get_patch_by_id('001'):
v.get_patch_by_id('001').set_color("green")
if v.get_patch_by_id('111'):
v.get_patch_by_id('111').set_color("black")
gca().set_axis_bgcolor('white')
gca().set_axis_on()
plt.show()
示例14: makeVenn3
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()
示例15: venn
def venn(df1, df2, df3=None, labels=None, ix1=None, ix2=None, ix3=None, return_intersection=False):
try:
import matplotlib_venn as mplv
except:
ImportError("To plot venn diagrams, install matplotlib-venn package: pip install matplotlib-venn")
if labels is None:
labels = ["A", "B", "C"]
s1 = _process_ix(df1.index, ix1)
s2 = _process_ix(df2.index, ix2)
if df3 is not None:
s3 = _process_ix(df3.index, ix3)
if df3 is not None:
vn = mplv.venn3([s1,s2,s3], set_labels=labels)
intersection = s1 & s2 & s3
else:
vn = mplv.venn2([s1,s2], set_labels=labels)
intersection = s1 & s2
ax = plt.gca()
if return_intersection:
return ax, intersection
else:
return ax