在工作中我们会经常遇到需要比较两列数据或者文件是否有交集的情况,
我先推荐两个在线的工具:第一个:只需要将数据粘贴到框框里既可,每行一个数据。http://bioinfogp.cnb.csic.es/tools/venny/index.html
第二个在线工具,支持文件上传:http://bioinformatics.psb.ugent.be/webtools/Venn/
将两个待比较的文件上传上去即可得到交集的venn图。每个文件中只能是你需要比较的数据,不能是多列数据。
再来说一下我自己写的一个工具compare.py:因为我经常在linux服务器中处理数据,每次导出数据用在线工具就显得很麻烦。有了这个工具,现在一行命令就可以比较两组数据,还能得到venn图。非常方便。
功能:
1,比较两个文件,求交集,并集,补集,画venn图。
2,支持多种文件类型,指定文件分隔类型和需要比较的列。假如你的文件有三列,其中第三列是要比较的数据。则只需要加参数分隔符和指定列数即可。
3,python 脚本,灵活方便。可选择屏幕输出交集结果,或者以文件形式保存结果。
4,可以设置画图或者不画图。使用-g参数既可画图,不画图就不要加-g参数。
待更新:
1,目前只能比较两个文件,后续更新多个文件。
Requires:
需要安装的python包:matplotlib,matplotlib_venn
python版本:python 2.7
参数详解:
python compare.py -h
usage: compare.py [-h] -a FILE1 [-al FILE1_COLUM] [-sa SEPARATORA] [-header]
-b FILE2 [-bl FILE2_COLUM] [-sb SEPARATORB] [-c]
[-cname COMMON_OP_FILE] [-u] [-uname UNION_OP_FILE] [-l]
[-lname LEFTSIDE_OP_FILE] [-r] [-rname RIGHTSIDE_OP_FILE]
[-g] [-v]
A Python-Venn
optional arguments:
-h, --help show this help message and exit
-a FILE1, --afile FILE1
first file
-al FILE1_COLUM Set a colum to use, default first line.
-sa SEPARATORA, --separatora SEPARATORA
separator of first file. choose: tab or space, default
[ tab ].
-header file with or without header, the first line is header
or not.
-b FILE2, --bfile FILE2
second file
-bl FILE2_COLUM Set a colum to use, default first line.
-sb SEPARATORB, --separatorb SEPARATORB
separator of second file. choose: tab or space,
default [ tab ].
-c, --common show common or not. Default [ False ]. show this
common result.
-cname COMMON_OP_FILE, --cfilename COMMON_OP_FILE
You must give a file name when you use this
parmarater. must use "-c" simultaneously. will write
common result to the file which you give.
-u, --union show union or not. Default [ False ]. will not print
this union result.
-uname UNION_OP_FILE, --ufilename UNION_OP_FILE
You must give a file name when you use this
parmarater. must use "-u" simultaneously. will write
union result to the file which you give.
-l, --leftside show rest of A file. Default: False. will not print
this leftside result.
-lname LEFTSIDE_OP_FILE, --lfilename LEFTSIDE_OP_FILE
You must give a file name when you use this
parmarater. must use "-l" simultaneously. will write
leftside result to the file which you give.
-r, --rightside Show rest of B file. Default [ False ]. Will not print
this rightside result.
-rname RIGHTSIDE_OP_FILE, --rfilename RIGHTSIDE_OP_FILE
You must give a file name when you use this
parmarater. must use "-r" simultaneously. will write
rightside result to the file which you give.
-g, --graph Draw a venn graph. Default [ False ]. will not print
venn graph.
-v, --version show program's version number and exit
用法案例1:
案例文件:如下图,两个文件都包含三列,我想比较第一列是不是在两个文件中是否有交集。如果是第二列或者其他列,需要 -al指定A文件第几列,用-sa指定A文件分隔类型,目前仅支持table和空格分割的文件类型,B文件同理,使用-bl,-sb参数。
只输出比较信息,默认不画图:
python compare.py -a G17E3L1.umi.count.2.xls -b G17E5L1.umi.count.2.xls
Number of elements number of unique elements
File A: 2155 2155
File B: 1898 1898
Overall number of unique elements: 2677
-----------------------------------------------------
left middle right
779 1376 522
用法案例2:
屏幕输出交集信息,补集信息。-c为交集,-l 为A文件的补集,-r为输出B文件的补集,如果需要到处到指定文件则需要加-cname,-lname,-rname为分别输出交集,补集的文件名。
# 这里只演示输出交集部分并保存到XXX.out.xls文件中。
python /cygene/script/compare.py -a G17E3L1.umi.count.2.xls -b G17E5L1.umi.count.2.xls -c -cname xxx.out.xls
用法案例3:
画图:画图只需要加-g参数既可得到venn.jpg。
有意见或者建议欢迎留言。
其他多个venn图请看这里https://www.jianshu.com/p/05f4bae28443