-
Notifications
You must be signed in to change notification settings - Fork 0
/
venn_transpose.py
executable file
·65 lines (50 loc) · 1.31 KB
/
venn_transpose.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python
import sys
'''
combine files for venn plot.
[Usage] venn_transpose.py file1 file2 file3 > outfile
eg.
file1:
aaa
bbb
ccc
ddd
file2:
mmm
nnnn
bbbbb
file3:
ppp
o
iii
uuu
outfile:
aaa bbb ccc ddd
mmm nnnn bbbbb
ppp o iii uuu
'''
def trs(names,outfile,with_header,sep):
#names: infile names
files=map(open,names)
for i in range(len(files)):
if not with_header:
#if infile without header,
#add infile name as header.
outfile.write(names[i]+sep)
outfile.write(sep.join(files[i].read().split("\n")))
outfile.write("\n")
def main(argv):
import argparse
parser = argparse.ArgumentParser(description="Combine and transpose files for venn plotting.")
parser.add_argument('files',nargs='+',help="infiles")
parser.add_argument('-o','--outfile',nargs='?',help="output file",default=sys.stdout,type=argparse.FileType('w'))
parser.add_argument('-s','--sep',nargs='?',default="\t")
parser.add_argument('-n','--has_header',action='store_true',default=False,help="If files has header,set this option.")
args = parser.parse_args(argv[1:])
#with_header = False
#sep="\t"
# outfile=sys.stdout
trs(args.files,args.outfile,args.has_header,args.sep)
if __name__ == '__main__':
import sys
main(sys.argv)