-
Notifications
You must be signed in to change notification settings - Fork 4
/
change_psl_polyA3end_4digit.py
70 lines (58 loc) · 1.77 KB
/
change_psl_polyA3end_4digit.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
#!/usr/bin/python
import sys
import os
if len(sys.argv) >= 3 :
psl_filename = sys.argv[1]
threeend_filename =sys.argv[2]
else:
print("usage: psl_filename threeend_filename")
print("or ")
sys.exit(1)
################################################################################
threeend_dt = {}
threeend = open(threeend_filename,'r')
for line in threeend:
ls = line.strip().split('\t')
readname = ls[0]
strand = ls[1]
if threeend_dt.has_key(readname):
print "error: two 3end of\t" + readname
threeend_dt[readname] = strand
threeend.close()
################################################################################
psl = open(psl_filename,'r')
for line in psl:
ls = line.strip().split("\t")
identity = str(round(float(ls[0])/float(ls[10]),4))
name = identity + "_" + ls[10]
strand = ls[8]
readname = ls[9]
size_ls = ls[18].strip(',').split(',')
readstart_ls = ls[19].strip(',').split(',')
start_ls = ls[20].strip(',').split(',')
end_pt = int(readstart_ls[-1]) + int(size_ls[-1])
right_L = int(ls[10]) - int(ls[12])
left_L = int(ls[11])
last_ls = ls[9].split("+")
if len(last_ls) == 2:
if last_ls[0] == "ccs":
Iccs = 1
else:
Icss = 0
else:
if ls[9][-3:] == "ccs":
Iccs = 1
else:
Icss = 0
if ls[9][-3:] == "ccs":
name = name + "|ccs"
if threeend_dt.has_key(readname):
# print name, threeend_dt[readname], strand
if threeend_dt[readname] == strand:
name = name+"+"+str(right_L)
else:
name = name+"-"+str(left_L)
ls[9] = name
print "\t".join(ls)
psl.close()
################################################################################