-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput2dict.py
36 lines (32 loc) · 1.89 KB
/
output2dict.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
def convertToNumberIfPossible(num):
try:
return int(num)
except ValueError:
try:
return float(num)
except ValueError:
return num
def blastn(blastnOutput):
results = []
entryTypes = ["qseqid", "sseqid", "pident", "length", "mismatch", "gapopen", "qstart", "qend", "sstart", "send", "evalue", "bitscore"]
#outputVals = ["precursorName", "productName", "percentIdentity", "length", "mismatch", "gapopen", "precursorStart", "precursorEnd", "productStart", "productEnd", "expectedValue", "bitscore"]
tr = {"qseqid":"precursorId", "sseqid":"productId", "pident":"percentIdentity", "length":"length", "mismatch":"mismatch", "gapopen":"gapopen", "qstart":"precursorStart", "qend":"precursorEnd", "sstart":"productStart", "send":"productEnd", "evalue":"expectedValue", "bitscore":"bitscore"}
for line in blastnOutput.split('\n'):
if line != '':
record = {}
for entryType, entry in zip(entryTypes,line.split('\t')):
record[tr[entryType]] = convertToNumberIfPossible(entry)
results.append(record)
return results
def blat(blatOutput):
results = []
entryTypes = ["qseqid", "sseqid", "pident", "length", "mismatch", "gapopen", "qstart", "qend", "sstart", "send", "evalue", "bitscore"]
#outputVals = ["precursorName", "productName", "percentIdentity", "length", "mismatch", "gapopen", "precursorStart", "precursorEnd", "productStart", "productEnd", "expectedValue", "bitscore"]
tr = {"qseqid":"precursorId", "sseqid":"productId", "pident":"percentIdentity", "length":"length", "mismatch":"mismatch", "gapopen":"gapopen", "qstart":"precursorStart", "qend":"precursorEnd", "sstart":"productStart", "send":"productEnd", "evalue":"expectedValue", "bitscore":"bitscore"}
for line in blatOutput.split('\n'):
if line != '':
record = {}
for entryType, entry in zip(entryTypes, line.split('\t')):
record[tr[entryType]] = convertToNumberIfPossible(entry)
results.append(record)
return results