-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathclean_psl.py
88 lines (68 loc) · 2.38 KB
/
clean_psl.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python3
# Christopher Vollmers
# Roger Volden
import sys
def parse_contigs(psl_file, clean_psl_file):
'''
Adjusts some of the psl values
'''
out = open(clean_psl_file, 'w')
for line in open(psl_file):
a = line.strip().split('\t')
start = int(a[15])
blocksizes = a[18].split(',')[:-1]
blockstarts = a[20].split(',')[:-1]
blockstarts_clean = []
readstarts_clean = []
blocksizes_clean = []
size_gap = []
for x in range(len(blocksizes)):
blockstart = int(blockstarts[x])
blocksize = int(blocksizes[x])
blockend = blockstart + blocksize
size_gap.append(blocksize)
try:
next_blockstart = int(blockstarts[x + 1])
gap = next_blockstart - blockend
size_gap.append(gap)
except IndexError:
pass
new_size_gap = []
block = 0
for index in range(len(size_gap)):
if index % 2 == 0:
block += size_gap[index]
if index % 2 == 1:
if size_gap[index] < 20:
block += size_gap[index]
else:
new_size_gap.append(block)
new_size_gap.append(size_gap[index])
block = 0
new_size_gap.append(block)
current_position = start
current_readposition = int(a[11])
for index in range(0, len(new_size_gap), 1):
inter = new_size_gap[index]
if index % 2 == 0:
blockstarts_clean.append(str(current_position))
blocksizes_clean.append(str(inter))
readstarts_clean.append(str(current_readposition))
current_position += inter
current_readposition += inter
if index % 2 == 1:
current_position += inter
a[17] = str(len(blockstarts_clean))
blockstarts_clean.append('')
blocksizes_clean.append('')
readstarts_clean.append('')
a[18] = (',').join(blocksizes_clean)
a[19] = (',').join(readstarts_clean)
a[20] = (',').join(blockstarts_clean)
new_line = ('\t').join(a)
out.write(new_line + '\n')
def main():
psl_file = sys.argv[1]
clean_psl_file = sys.argv[2]
parse_contigs(psl_file, clean_psl_file)
main()