使用matplotlib,venn3和venn3_circles在python中工作。
我试图在3圈维恩图中得到每个交叉点的元素列表。
我将使用示例here
from matplotlib import pyplot as plt
import numpy as np
from matplotlib_venn import venn3, venn3_circles
A = set(['DPEP1', 'CDC42BPA', 'GNG4', 'RAPGEFL1', 'MYH7B', 'SLC13A3', 'PHACTR3', 'SMPX', 'NELL2', 'PNMAL1', 'KRT23', 'PCP4', 'LOX', 'CDC42BPA'])
B = set(['ABLIM1','CDC42BPA','VSNL1','LOX','PCP4','SLC13A3'])
C = set(['PLCB4', 'VSNL1', 'TOX3', 'VAV3'])
v = venn3([A,B,C], ('GCPromoters', 'OCPromoters', 'GCSuppressors'))
ppp=v.get_label_by_id('100').set_text('\n'.join(A-B-C))
v.get_label_by_id('110').set_text('\n'.join(A&B-C))
v.get_label_by_id('011').set_text('\n'.join(B&C-A))
v.get_label_by_id('001').set_text('\n'.join(C-A-B))
v.get_label_by_id('010').set_text('')
plt.annotate(',\n'.join(B-A-C), xy=v.get_label_by_id('010').get_position() +
np.array([0, 0.2]), xytext=(-20,40), ha='center',
textcoords='offset points',
bbox=dict(boxstyle='round,pad=0.5', fc='gray', alpha=0.1),
arrowprops=dict(arrowstyle='->',
connectionstyle='arc',color='gray'))
如何在变量/列表中存储每个交叉点的内容?
我想得到这样的东西:
A:[MYH7B, PHACTR3,...,DPEP1]
AB: [LOX,...,PCP4]
B: [ABLIM1]
ABC: empty
B: empty
BC: [VSNL1]
C: [TOX3,VAV3,PLCB4]
其中A,AB,ABC,C,...是python中的列表
答案 0 :(得分:1)
不确定一旦制作了维恩图,您可以按照建议撤回数据。这将是一个很好的功能,希望图书馆的一些开发人员能够回答。
说。你可以做的是利用你可以使用python sets的逻辑操作。
Operation Equivalent Result
len(s) number of elements in set s (cardinality)
x in s test x for membership in s
x not in s test x for non-membership in s
s.issubset(t) s <= t test whether every element in s is in t
s.issuperset(t) s >= t test whether every element in t is in s
s.union(t) s | t new set with elements from both s and t
s.intersection(t) s & t new set with elements common to s and t
s.difference(t) s - t new set with elements in s but not in t
s.symmetric_difference(t) s ^ t new set with elements in either s or t but not both
s.copy() new set with a shallow copy of s
例如,要获得AB,ABC等,您可以这样做:
AB = A.intersection(B).difference(C)
ABC = A.intersection(B).intersection(C)
希望这有帮助!
答案 1 :(得分:0)
为什么不将它作为数组存储使用字母数字'token'作为索引和3个整数标志的数组[A,B,C]
因此您可以将项目列为
- ['MYH7B', [ 1, 0, 0 ]], - ['LOX', [ 1, 1, 0 ]], - ['ABLIM1',[ 0, 1, 0 ]], - ['VSNL1', [ 0, 1, 1 ]], - ['TOX3', [ 0, 0, 1 ]]
作为示例然后切片数组以查找模式匹配。
清晰,简洁,最大限度地减少存储空间,同时最大限度地提高多功能性。
如果您确实想将'B'部分表示为2个子部分'B1'和'B2',那么您只需添加一个额外的列... [A,B1,B2,C]
- ['MYH7B', [ 1, 0, 0, 0 ]], - ['LOX', [ 1, 1, 0, 0 ]], - ['ABLIM1',[ 0, 1, 0, 0 ]], - ['VSNL1', [ 0, 1, 0, 1 ]], - ['TOX3', [ 0, 0, 0, 1 ]]