forked from tools4plant-omics/PABLOG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpablog.py
127 lines (86 loc) · 4.12 KB
/
pablog.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import sys
from traceback import print_exc
import pysam
import HTSeq as ht
from utils import utilsAlignment
from utils import otherUtils
from utils import utilsPrimer3
def main(argv):
if(len(argv) < 4) or (len(argv) > 5):
print("\nRun pablog.py script using python:\n")
print(" python pablog.py FILE.bam Ref_Gene.fa output_result_file.txt [optional]\n")
print(" where:\n - FILE.bam is the result file from alignment,\n")
print(" - Ref_Gene.fa is the reference genome used in the alignment,\n")
print(" - output_result_file.txt filename where results are written in,\n")
print(" - [optional] args are: \n - size [INT] (=60 by default) which is a the minimun length we consider to filter out cigar operations in read analysis.\n")
return
elif(len(argv) == 4):
try:
#BAM file parsing
aln_file = ht.BAM_Reader(argv[1])
except Exception as err:
print(err)
return
print("Analyzing alignment reads... \n")
regions = utilsAlignment.analyzeAlignment(aln_file) #Alignment Analysis step
print("DONE!\n\n")
if len(regions) > 0 :
print("Analyzing regions' coverage ... \n")
sorted_regions = utilsAlignment.analyzeCoverage(argv[1],regions) #Coverage Analysys step
print("DONE!\n\n")
try:
print("Generating Consensus sequence from bam file ...\n")
consensus_sequence = utilsPrimer3.generateConsensus(argv[1],argv[2]) #Consensus Sequence step
print("DONE!\n\n")
print("Primers design ...\n")
utilsPrimer3.p3Design(consensus_sequence, regions, argv[3]) #Primers Design step
print("DONE!\n")
print("PABLOG analysis completed, results available in %s" %argv[3])
return
except Exception as err:
print(err)
return
else:
print("No good regions were found from the alignment.\n"
"No primer was designed.\n"
"Check if alignment is consistent or try using less restricting parameters.\n")
return
else:
#Same pipeline as above, but with optional parameter region min-length provided
try:
aln_file = ht.BAM_Reader(argv[1])
except Exception as err:
print(err)
return
print("Analyzing alignment reads... \n")
regions = utilsAlignment.analyzeAlignment(aln_file, _size=argv[4])
print("DONE!\n\n")
if len(regions) > 0:
print("Analyzing regions' coverage ... \n")
sorted_regions = utilsAlignment.analyzeCoverage(argv[1],regions)
print("DONE!\n\n")
try:
print("Generating Consensus sequence from bam file ...\n")
consensus_sequence = utilsPrimer3.generateConsensus(argv[1],argv[2]) #Consensus Sequence step
print("DONE!\n\n")
print("Primers design ...\n")
utilsPrimer3.p3Design(consensus_sequence, regions, argv[3]) #Primers Design step
print("DONE!\n\n")
print("PABLOG analysis completed, results available in %s" %argv[3])
return
except Exception as err:
print(err)
return
else:
print("No good regions were found from the alignment.\n"
"No primer was designed.\n"
"Check if alignment is consistent or try using less restricting parameters.\n")
return
if __name__ == "__main__":
#Main function
try:
arg = sys.argv
main(sys.argv)
except Exception as err:
print("Error: ", err)
sys.exit(-1)