-
Notifications
You must be signed in to change notification settings - Fork 26
/
deconcatenate.py
executable file
·54 lines (45 loc) · 1.09 KB
/
deconcatenate.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
#
# STUB not usable
#
#!/usr/bin/env python
import sys
import tempfile
import os
docstring= """
DESCRIPTION
Split a file in multiple files on the bases of a column of
identifiers (reverse of concatenate_bed.py)
Input MUST be sorted by the identifying column. Use - to read from stdin
USAGE:
deconcatenate.py <infile> <col-idx>
"""
if len(sys.argv) != 3:
print(docstring)
sys.exit(1)
if sys.argv[1] in ('-h', '--help'):
print(docstring)
sys.exit(0)
tmp= '/lustre/sblab/berald01/Tritume'## tempfile.mkdtemp(prefix= 'deconcatenate_')
outfiles= {}
if sys.argv[1] == '-':
fin= sys.stdin
else:
fin= open(sys.argv[1])
cfile= ''
start= True
while True:
line= fin.readline()
line= line.strip().split('\t')
print(int(sys.argv[2]) - 1)
id= line[int(sys.argv[2]) - 1]
if id != cfile:
if start:
start= False
else:
fout.close()
fname= os.path.join(tmp, id + '.txt')
fout= open(fname, 'w')
fout.write('\t'.join(line) + '\n')
cfile= id
else:
fout.write('\t'.join(line) + '\n')