-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
69 lines (61 loc) · 1.68 KB
/
main.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
from BlastHit import BlastHit
from DiffExp import DiffExp
from Blast import Blast
from Matrix import Matrix
def tuple_to_string(tup):
'''
A function that will accept a tuple and return it as a tab-separated string
Args:
tup: a tuple
Returns:
A tab-separated string
'''
return '\t'.join(tup)
FP1 = open(<'BLAST file'>, 'r')
FP2 = open(<'trinity assembly matrix'>, 'r')
blast = []
for line in FP1:
temp = line.strip().split()
trID = temp[0].split('|')[0]
SPID = temp[1].split('|')[3].split('.')[0]
Idy = float(temp[2])
msm = temp[4]
#print(SPID)
bh = BlastHit(trID, SPID, Idy, msm)
blast.append(bh)
FP1.close
expressions = []
FP2.readline()
for line in FP2:
temp = line.strip().split()
trID = temp[0]
dShift = temp[1]
hShock = temp[2]
loggrowth = temp[3]
pphase = temp[4]
dxp = DiffExp(trID, dShift, hShock, loggrowth, pphase)
expressions.append(dxp)
FP2.close
objblast = Blast(blast)
objmatrix = Matrix(expressions)
'''
Load the BlastHit objects that are good matches into a dictionary
'''
goodblasthits = {}
for item in objblast:
if item.good_match():
goodblasthits[item.TranscriptID] = item.SwissProtID
'''
create an output file
'''
FP3 = open("Output.txt", 'w')
FP3.write('{}\t{}\t{}\t{}\t{}\n'.format('','Sp_ds','Sp_hs', 'Sp_log', 'Sp_plat'))
'''
Perform a transcript-to-protein lookup for each DiffExp object
'''
for item in objmatrix:
if item.transcript in goodblasthits:
FP3.write(goodblasthits[item.transcript] + '\t' + tuple_to_string(item.return_attribs())+'\n')
else:
FP3.write(item.transcript + '\t' + tuple_to_string(item.return_attribs())+'\n')
FP3.close()