annotate helper.py @ 5:6e589f267c14

Uploaded
author devteam
date Tue, 04 Nov 2014 12:15:19 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5
6e589f267c14 Uploaded
devteam
parents:
diff changeset
1 #!/usr/bin/env python
6e589f267c14 Uploaded
devteam
parents:
diff changeset
2 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
3 Common utility functions
6e589f267c14 Uploaded
devteam
parents:
diff changeset
4 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
5
6e589f267c14 Uploaded
devteam
parents:
diff changeset
6 import os
6e589f267c14 Uploaded
devteam
parents:
diff changeset
7 import re
6e589f267c14 Uploaded
devteam
parents:
diff changeset
8 import sys
6e589f267c14 Uploaded
devteam
parents:
diff changeset
9 import gzip
6e589f267c14 Uploaded
devteam
parents:
diff changeset
10 import bz2
6e589f267c14 Uploaded
devteam
parents:
diff changeset
11 import numpy
6e589f267c14 Uploaded
devteam
parents:
diff changeset
12
6e589f267c14 Uploaded
devteam
parents:
diff changeset
13 def init_gene():
6e589f267c14 Uploaded
devteam
parents:
diff changeset
14 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
15 Initializing the gene structure
6e589f267c14 Uploaded
devteam
parents:
diff changeset
16 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
17
6e589f267c14 Uploaded
devteam
parents:
diff changeset
18 gene_det = [('id', 'f8'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
19 ('anno_id', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
20 ('confgenes_id', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
21 ('name', 'S25'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
22 ('source', 'S25'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
23 ('gene_info', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
24 ('alias', 'S15'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
25 ('name2', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
26 ('strand', 'S2'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
27 ('score', 'S15'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
28 ('chr', 'S15'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
29 ('chr_num', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
30 ('paralogs', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
31 ('start', 'f8'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
32 ('stop', 'f8'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
33 ('transcripts', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
34 ('transcript_type', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
35 ('transcript_info', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
36 ('transcript_status', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
37 ('transcript_valid', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
38 ('exons', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
39 ('exons_confirmed', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
40 ('cds_exons', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
41 ('utr5_exons', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
42 ('utr3_exons', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
43 ('tis', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
44 ('tis_conf', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
45 ('tis_info', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
46 ('cdsStop', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
47 ('cdsStop_conf', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
48 ('cdsStop_info', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
49 ('tss', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
50 ('tss_info', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
51 ('tss_conf', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
52 ('cleave', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
53 ('cleave_info', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
54 ('cleave_conf', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
55 ('polya', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
56 ('polya_info', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
57 ('polya_conf', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
58 ('is_alt', 'f8'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
59 ('is_alt_spliced', 'f8'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
60 ('is_valid', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
61 ('transcript_complete', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
62 ('is_complete', numpy.dtype),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
63 ('is_correctly_gff3_referenced', 'S5'),
6e589f267c14 Uploaded
devteam
parents:
diff changeset
64 ('splicegraph', numpy.dtype) ]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
65
6e589f267c14 Uploaded
devteam
parents:
diff changeset
66 return gene_det
6e589f267c14 Uploaded
devteam
parents:
diff changeset
67
6e589f267c14 Uploaded
devteam
parents:
diff changeset
68 def open_file(fname):
6e589f267c14 Uploaded
devteam
parents:
diff changeset
69 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
70 Open the file (supports .gz .bz2) and returns the handler
6e589f267c14 Uploaded
devteam
parents:
diff changeset
71
6e589f267c14 Uploaded
devteam
parents:
diff changeset
72 @args fname: input file name for reading
6e589f267c14 Uploaded
devteam
parents:
diff changeset
73 @type fname: str
6e589f267c14 Uploaded
devteam
parents:
diff changeset
74 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
75
6e589f267c14 Uploaded
devteam
parents:
diff changeset
76 try:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
77 if os.path.splitext(fname)[1] == ".gz":
6e589f267c14 Uploaded
devteam
parents:
diff changeset
78 FH = gzip.open(fname, 'rb')
6e589f267c14 Uploaded
devteam
parents:
diff changeset
79 elif os.path.splitext(fname)[1] == ".bz2":
6e589f267c14 Uploaded
devteam
parents:
diff changeset
80 FH = bz2.BZ2File(fname, 'rb')
6e589f267c14 Uploaded
devteam
parents:
diff changeset
81 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
82 FH = open(fname, 'rU')
6e589f267c14 Uploaded
devteam
parents:
diff changeset
83 except Exception as error:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
84 sys.exit(error)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
85
6e589f267c14 Uploaded
devteam
parents:
diff changeset
86 return FH
6e589f267c14 Uploaded
devteam
parents:
diff changeset
87
6e589f267c14 Uploaded
devteam
parents:
diff changeset
88 def add_CDS_phase(strand, cds):
6e589f267c14 Uploaded
devteam
parents:
diff changeset
89 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
90 Calculate CDS phase and add to the CDS exons
6e589f267c14 Uploaded
devteam
parents:
diff changeset
91
6e589f267c14 Uploaded
devteam
parents:
diff changeset
92 @args strand: feature strand information
6e589f267c14 Uploaded
devteam
parents:
diff changeset
93 @type strand: +/-
6e589f267c14 Uploaded
devteam
parents:
diff changeset
94 @args cds: coding exon coordinates
6e589f267c14 Uploaded
devteam
parents:
diff changeset
95 @type cds: numpy array [[int, int, int]]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
96 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
97
6e589f267c14 Uploaded
devteam
parents:
diff changeset
98 cds_region, cds_flag = [], 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
99 if strand == '+':
6e589f267c14 Uploaded
devteam
parents:
diff changeset
100 for cdspos in cds:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
101 if cds_flag == 0:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
102 cdspos = (cdspos[0], cdspos[1], 0)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
103 diff = (cdspos[1]-(cdspos[0]-1))%3
6e589f267c14 Uploaded
devteam
parents:
diff changeset
104 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
105 xy = 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
106 if diff == 0:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
107 cdspos = (cdspos[0], cdspos[1], 0)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
108 elif diff == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
109 cdspos = (cdspos[0], cdspos[1], 2)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
110 xy = 2
6e589f267c14 Uploaded
devteam
parents:
diff changeset
111 elif diff == 2:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
112 cdspos = (cdspos[0], cdspos[1], 1)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
113 xy = 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
114 diff = ((cdspos[1]-(cdspos[0]-1))-xy)%3
6e589f267c14 Uploaded
devteam
parents:
diff changeset
115 cds_region.append(cdspos)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
116 cds_flag = 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
117 elif strand == '-':
6e589f267c14 Uploaded
devteam
parents:
diff changeset
118 cds.reverse()
6e589f267c14 Uploaded
devteam
parents:
diff changeset
119 for cdspos in cds:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
120 if cds_flag == 0:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
121 cdspos = (cdspos[0], cdspos[1], 0)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
122 diff = (cdspos[1]-(cdspos[0]-1))%3
6e589f267c14 Uploaded
devteam
parents:
diff changeset
123 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
124 xy = 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
125 if diff == 0:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
126 cdspos = (cdspos[0], cdspos[1], 0)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
127 elif diff == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
128 cdspos = (cdspos[0], cdspos[1], 2)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
129 xy = 2
6e589f267c14 Uploaded
devteam
parents:
diff changeset
130 elif diff == 2:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
131 cdspos = (cdspos[0], cdspos[1], 1)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
132 xy = 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
133 diff = ((cdspos[1]-(cdspos[0]-1))-xy)%3
6e589f267c14 Uploaded
devteam
parents:
diff changeset
134 cds_region.append(cdspos)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
135 cds_flag = 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
136 cds_region.reverse()
6e589f267c14 Uploaded
devteam
parents:
diff changeset
137 return cds_region
6e589f267c14 Uploaded
devteam
parents:
diff changeset
138
6e589f267c14 Uploaded
devteam
parents:
diff changeset
139 def buildUTR(cc, ec, strand):
6e589f267c14 Uploaded
devteam
parents:
diff changeset
140 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
141 Build UTR regions from a given set of CDS and exon coordiantes of a gene
6e589f267c14 Uploaded
devteam
parents:
diff changeset
142
6e589f267c14 Uploaded
devteam
parents:
diff changeset
143 @args cc: coding exon coordinates
6e589f267c14 Uploaded
devteam
parents:
diff changeset
144 @type cc: numpy array [[int, int, int]]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
145 @args ec: exon coordinates
6e589f267c14 Uploaded
devteam
parents:
diff changeset
146 @type ec: numpy array [[int, int]]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
147 @args strand: feature strand information
6e589f267c14 Uploaded
devteam
parents:
diff changeset
148 @type strand: +/-
6e589f267c14 Uploaded
devteam
parents:
diff changeset
149 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
150
6e589f267c14 Uploaded
devteam
parents:
diff changeset
151 utr5 = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
152 utr3 = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
153 if strand == '+':
6e589f267c14 Uploaded
devteam
parents:
diff changeset
154 cds_s = cc[0][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
155 for ex in ec:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
156 if ex[0] <= cds_s and cds_s <= ex[1]:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
157 if ex[0] != cds_s:utr5.append((ex[0], cds_s-1))
6e589f267c14 Uploaded
devteam
parents:
diff changeset
158 break
6e589f267c14 Uploaded
devteam
parents:
diff changeset
159 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
160 utr5.append(ex)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
161 cds_e = cc[-1][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
162 for i in range(len(ec)):
6e589f267c14 Uploaded
devteam
parents:
diff changeset
163 i += 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
164 if ec[-i][0] <= cds_e and cds_e <= ec[-i][1]:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
165 if ec[-i][1] != cds_e:utr3.append((cds_e +1, ec[-i][1]))
6e589f267c14 Uploaded
devteam
parents:
diff changeset
166 break
6e589f267c14 Uploaded
devteam
parents:
diff changeset
167 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
168 utr3.append(ec[-i])
6e589f267c14 Uploaded
devteam
parents:
diff changeset
169 utr3.reverse()
6e589f267c14 Uploaded
devteam
parents:
diff changeset
170 elif strand == '-':
6e589f267c14 Uploaded
devteam
parents:
diff changeset
171 cds_s = cc[-1][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
172 for i in range(len(ec)):
6e589f267c14 Uploaded
devteam
parents:
diff changeset
173 i += 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
174 if ec[-i][0] <= cds_s and cds_s <= ec[-i][1]:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
175 if ec[-i][1] != cds_s:utr5.append((cds_s+1, ec[-i][1]))
6e589f267c14 Uploaded
devteam
parents:
diff changeset
176 break
6e589f267c14 Uploaded
devteam
parents:
diff changeset
177 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
178 utr5.append(ec[-i])
6e589f267c14 Uploaded
devteam
parents:
diff changeset
179 utr5.reverse()
6e589f267c14 Uploaded
devteam
parents:
diff changeset
180 cds_e = cc[0][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
181 for ex in ec:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
182 if ex[0] <= cds_e and cds_e <= ex[1]:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
183 if ex[0] != cds_e:utr3.append((ex[0], cds_e-1))
6e589f267c14 Uploaded
devteam
parents:
diff changeset
184 break
6e589f267c14 Uploaded
devteam
parents:
diff changeset
185 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
186 utr3.append(ex)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
187 return utr5, utr3
6e589f267c14 Uploaded
devteam
parents:
diff changeset
188
6e589f267c14 Uploaded
devteam
parents:
diff changeset
189 def make_Exon_cod(strand_p, five_p_utr, cds_cod, three_p_utr):
6e589f267c14 Uploaded
devteam
parents:
diff changeset
190 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
191 Create exon cordinates from UTR's and CDS region
6e589f267c14 Uploaded
devteam
parents:
diff changeset
192
6e589f267c14 Uploaded
devteam
parents:
diff changeset
193 @args strand_p: feature strand information
6e589f267c14 Uploaded
devteam
parents:
diff changeset
194 @type strand_p: +/-
6e589f267c14 Uploaded
devteam
parents:
diff changeset
195 @args five_p_utr: five prime utr exon coordinates
6e589f267c14 Uploaded
devteam
parents:
diff changeset
196 @type five_p_utr: numpy array [[int, int]]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
197 @args cds_cod: coding exon coordinates
6e589f267c14 Uploaded
devteam
parents:
diff changeset
198 @type cds_cod: numpy array [[int, int, int]]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
199 @args three_p_utr: three prime utr exon coordinates
6e589f267c14 Uploaded
devteam
parents:
diff changeset
200 @type three_p_utr: numpy array [[int, int]]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
201 """
6e589f267c14 Uploaded
devteam
parents:
diff changeset
202
6e589f267c14 Uploaded
devteam
parents:
diff changeset
203 exon_pos = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
204 if strand_p == '+':
6e589f267c14 Uploaded
devteam
parents:
diff changeset
205 utr5_start, utr5_end = 0, 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
206 if five_p_utr != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
207 utr5_start, utr5_end = five_p_utr[-1][0], five_p_utr[-1][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
208 cds_5start, cds_5end = cds_cod[0][0], cds_cod[0][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
209 jun_exon = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
210 if cds_5start-utr5_end == 0 or cds_5start-utr5_end == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
211 jun_exon = [utr5_start, cds_5end]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
212 if len(cds_cod) == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
213 five_prime_flag = 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
214 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
215 five_p_utr = five_p_utr[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
216 five_prime_flag = 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
217 for utr5 in five_p_utr:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
218 exon_pos.append(utr5)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
219 jun_exon = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
220 utr3_start, utr3_end = 0, 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
221 if three_p_utr != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
222 utr3_start = three_p_utr[0][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
223 utr3_end = three_p_utr[0][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
224 if utr3_start-cds_5end == 0 or utr3_start-cds_5end == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
225 jun_exon = [cds_5start, utr3_end]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
226 three_prime_flag = 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
227 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
228 cds_cod = cds_cod[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
229 three_p_utr = three_p_utr[1:]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
230 three_prime_flag = 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
231 if five_prime_flag == 1 and three_prime_flag == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
232 exon_pos.append([utr5_start, utr3_end])
6e589f267c14 Uploaded
devteam
parents:
diff changeset
233 if five_prime_flag == 1 and three_prime_flag == 0:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
234 exon_pos.append([utr5_start, cds_5end])
6e589f267c14 Uploaded
devteam
parents:
diff changeset
235 cds_cod = cds_cod[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
236 if five_prime_flag == 0 and three_prime_flag == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
237 exon_pos.append([cds_5start, utr3_end])
6e589f267c14 Uploaded
devteam
parents:
diff changeset
238 for cds in cds_cod:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
239 exon_pos.append(cds)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
240 for utr3 in three_p_utr:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
241 exon_pos.append(utr3)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
242 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
243 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
244 five_p_utr = five_p_utr[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
245 cds_cod = cds_cod[1:]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
246 for utr5 in five_p_utr:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
247 exon_pos.append(utr5)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
248 exon_pos.append(jun_exon) if jun_exon != [] else ''
6e589f267c14 Uploaded
devteam
parents:
diff changeset
249 jun_exon = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
250 utr3_start, utr3_end = 0, 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
251 if three_p_utr != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
252 utr3_start = three_p_utr[0][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
253 utr3_end = three_p_utr[0][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
254 cds_3start = cds_cod[-1][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
255 cds_3end = cds_cod[-1][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
256 if utr3_start-cds_3end == 0 or utr3_start-cds_3end == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
257 jun_exon = [cds_3start, utr3_end]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
258 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
259 cds_cod = cds_cod[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
260 three_p_utr = three_p_utr[1:]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
261 for cds in cds_cod:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
262 exon_pos.append(cds)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
263 exon_pos.append(jun_exon) if jun_exon != [] else ''
6e589f267c14 Uploaded
devteam
parents:
diff changeset
264 for utr3 in three_p_utr:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
265 exon_pos.append(utr3)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
266 elif strand_p == '-':
6e589f267c14 Uploaded
devteam
parents:
diff changeset
267 utr3_start, utr3_end = 0, 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
268 if three_p_utr != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
269 utr3_start = three_p_utr[-1][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
270 utr3_end = three_p_utr[-1][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
271 cds_3start = cds_cod[0][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
272 cds_3end = cds_cod[0][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
273 jun_exon = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
274 if cds_3start-utr3_end == 0 or cds_3start-utr3_end == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
275 jun_exon = [utr3_start, cds_3end]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
276 if len(cds_cod) == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
277 three_prime_flag = 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
278 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
279 three_p_utr = three_p_utr[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
280 three_prime_flag = 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
281 for utr3 in three_p_utr:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
282 exon_pos.append(utr3)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
283 jun_exon = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
284 (utr5_start, utr5_end) = (0, 0)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
285 if five_p_utr != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
286 utr5_start = five_p_utr[0][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
287 utr5_end = five_p_utr[0][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
288 if utr5_start-cds_3end == 0 or utr5_start-cds_3end == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
289 jun_exon = [cds_3start, utr5_end]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
290 five_prime_flag = 0
6e589f267c14 Uploaded
devteam
parents:
diff changeset
291 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
292 cds_cod = cds_cod[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
293 five_p_utr = five_p_utr[1:]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
294 five_prime_flag = 1
6e589f267c14 Uploaded
devteam
parents:
diff changeset
295 if three_prime_flag == 1 and five_prime_flag == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
296 exon_pos.append([utr3_start, utr5_end])
6e589f267c14 Uploaded
devteam
parents:
diff changeset
297 if three_prime_flag == 1 and five_prime_flag == 0:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
298 exon_pos.append([utr3_start, cds_3end])
6e589f267c14 Uploaded
devteam
parents:
diff changeset
299 cds_cod = cds_cod[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
300 if three_prime_flag == 0 and five_prime_flag == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
301 exon_pos.append([cds_3start, utr5_end])
6e589f267c14 Uploaded
devteam
parents:
diff changeset
302 for cds in cds_cod:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
303 exon_pos.append(cds)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
304 for utr5 in five_p_utr:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
305 exon_pos.append(utr5)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
306 else:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
307 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
308 three_p_utr = three_p_utr[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
309 cds_cod = cds_cod[1:]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
310 for utr3 in three_p_utr:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
311 exon_pos.append(utr3)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
312 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
313 exon_pos.append(jun_exon)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
314 jun_exon = []
6e589f267c14 Uploaded
devteam
parents:
diff changeset
315 (utr5_start, utr5_end) = (0, 0)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
316 if five_p_utr != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
317 utr5_start = five_p_utr[0][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
318 utr5_end = five_p_utr[0][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
319 cds_5start = cds_cod[-1][0]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
320 cds_5end = cds_cod[-1][1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
321 if utr5_start-cds_5end == 0 or utr5_start-cds_5end == 1:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
322 jun_exon = [cds_5start, utr5_end]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
323 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
324 cds_cod = cds_cod[:-1]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
325 five_p_utr = five_p_utr[1:]
6e589f267c14 Uploaded
devteam
parents:
diff changeset
326 for cds in cds_cod:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
327 exon_pos.append(cds)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
328 if jun_exon != []:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
329 exon_pos.append(jun_exon)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
330 for utr5 in five_p_utr:
6e589f267c14 Uploaded
devteam
parents:
diff changeset
331 exon_pos.append(utr5)
6e589f267c14 Uploaded
devteam
parents:
diff changeset
332 return exon_pos