-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTranscript.py
More file actions
455 lines (363 loc) · 24.8 KB
/
Transcript.py
File metadata and controls
455 lines (363 loc) · 24.8 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
# general class containing info about a transcribed region. Can come from UCSC Knowngenes (BED) or Ensembl GTF files currently
# Stephen N. Floor
# Fall 2014
class Transcript:
def __init__(self):
#properties defined in UCSC knowngenes
self.name = ''
self.chrom = ''
self.strand = ''
self.txStart = 0
self.txEnd = 0
self.cdsStart = 0
self.cdsEnd = 0
self.exonCt = 0
self.exonStarts = []
self.exonEnds = []
self.exonLengths = []
#meta properties to be computed during construction. these are lists of BED first four field tuples with the exception of Len terms which are the length of the total region for the gene
self.utr5 = []
self.utr5Len = 0
self.utr5start = []
self.utr5startLen = 0
self.cds = []
self.cdsLen = 0
self.utr3 = []
self.utr3Len = 0
self.exons = []
self.exonsLen = 0
self.introns = []
self.intronsLen = 0
self.coding = False
def __str__(self): #currently roughly knownGenes format with a second line containing metadata
return "%s\t%s\t%s\t%d\t%d\t%d\t%d\t%d\t%s\t%s\n%s\t%d\t%s\t%d\t%s\t%d\t%s\t%d\t%s\t%d\t%s" % (self.name, self.chrom, self.strand, self.txStart, self.txEnd, self.cdsStart, self.cdsEnd, self.exonCt, self.exonStarts, self.exonEnds, self.utr5, self.utr5Len, self.cds, self.cdsLen, self.utr3, self.utr3Len, self.exons, self.exonsLen, self.introns, self.intronsLen, self.coding)
#BED format output is goal. Fields are optional after featureEnd
# chrom featureStart featureEnd nameOfLine score(0-1000) strand thickStart thickEnd itemRGBtuple blockCount blockSizes blockStarts
#this function returns a list of BED-formatted strings for the feature passed as region with multiple entries per region possible, one for each primitive (exon/intron)
def bedFormat(self, region="exons"):
if (not self.coding and (region == "5utr" or region == "cds" or region == "3utr")):
print "Transcript.py bedFormat error: noncoding transcripts do not have 5utr/cds/3utr"
return []
returnVal = []
if (region == "5utr"):
for chunk in self.utr5:
returnVal.append("%s\t%d\t%d\t%s\t0\t%c\t%d\t%d\t0" % (chunk[0], chunk[1], chunk[2], chunk[3]+"_5utr",self.strand, chunk[1],chunk[2]))
elif (region == "5utr_start"):
for chunk in self.utr5_start:
returnVal.append("%s\t%d\t%d\t%s\t0\t%c\t%d\t%d\t0" % (chunk[0], chunk[1], chunk[2], chunk[3]+"_5utr_start",self.strand, chunk[1],chunk[2]))
elif (region == "cds"):
for chunk in self.cds:
returnVal.append("%s\t%d\t%d\t%s\t0\t%c\t%d\t%d\t0" % (chunk[0], chunk[1], chunk[2], chunk[3]+"_cds",self.strand, chunk[1],chunk[2]))
elif (region == "3utr"):
for chunk in self.utr3:
returnVal.append("%s\t%d\t%d\t%s\t0\t%c\t%d\t%d\t0" % (chunk[0], chunk[1], chunk[2], chunk[3]+"_3utr",self.strand, chunk[1],chunk[2]))
elif (region == "exons"):
for chunk in self.exons:
returnVal.append("%s\t%d\t%d\t%s\t0\t%c\t%d\t%d\t0" % (chunk[0], chunk[1], chunk[2], chunk[3]+"_exon",self.strand, chunk[1],chunk[2]))
elif (region == "introns"):
for chunk in self.introns:
returnVal.append("%s\t%d\t%d\t%s\t0\t%c\t%d\t%d\t0" % (chunk[0], chunk[1], chunk[2], chunk[3]+"_intron",self.strand, chunk[1],chunk[2]))
else:
print "Transcript.py bedFormat error: currently only regions 5utr/cds/3utr/exons/introns are supported"
return returnVal
#BED format output is goal. Fields are optional after featureEnd
# chrom featureStart featureEnd nameOfLine score(0-1000) strand thickStart thickEnd itemRGBtuple blockCount blockSizes blockStarts
#blockCount - The number of blocks (exons) in the BED line.
#blockSizes - A comma-separated list of the block sizes. The number of items in this list should correspond to blockCount.
#blockStarts - A comma-separated list of block starts. All of the blockStart positions should be calculated relative to chromStart. The number of items in this list should correspond to blockCount.
#this function returns a BED-formatted string for the feature passed as region with blocks defining the exons as per the BED file format
def blockBedFormat(self, region="exons"):
if (not self.coding and (region == "5utr" or region == "cds" or region == "3utr")):
print "Transcript.py blockBedFormat error: noncoding transcripts do not have 5utr/cds/3utr"
return ""
returnVal = ""
score = 0
rgb = 0
if (region == "5utr"):
chromStart = self.utr5[0][1] # start of feature is start of first block
chromEnd = self.utr5[-1][2] # end of feature is end of last block
regionName = self.name + "_5utr"
blockCount = len(self.utr5)
blockSizes = ''.join(["%d," % (chunk[2]-chunk[1]) for chunk in self.utr5])
blockStarts = ''.join(["%d," % (chunk[1]-chromStart) for chunk in self.utr5])
#print "blockCount %d blockSizes %s blockStarts %s" % (blockCount, blockSizes, blockStarts)
elif (region == "5utr_start"):
chromStart = self.utr5start[0][1] # start of feature is start of first block
chromEnd = self.utr5start[-1][2] # end of feature is end of last block
regionName = self.name + "_5utr_start"
blockCount = len(self.utr5start)
blockSizes = ''.join(["%d," % (chunk[2]-chunk[1]) for chunk in self.utr5start])
blockStarts = ''.join(["%d," % (chunk[1]-chromStart) for chunk in self.utr5start])
#print "blockCount %d blockSizes %s blockStarts %s" % (blockCount, blockSizes, blockStarts)
elif (region == "cds"):
chromStart = self.cds[0][1] # start of feature is start of first block
chromEnd = self.cds[-1][2] # end of feature is end of last block
regionName = self.name + "_cds"
blockCount = len(self.cds)
blockSizes = ''.join(["%d," % (chunk[2]-chunk[1]) for chunk in self.cds])
blockStarts = ''.join(["%d," % (chunk[1]-chromStart) for chunk in self.cds])
#print "blockCount %d blockSizes %s blockStarts %s" % (blockCount, blockSizes, blockStarts)
elif (region == "3utr"):
chromStart = self.utr3[0][1] # start of feature is start of first block
chromEnd = self.utr3[-1][2] # end of feature is end of last block
regionName = self.name + "_3utr"
blockCount = len(self.utr3)
blockSizes = ''.join(["%d," % (chunk[2]-chunk[1]) for chunk in self.utr3])
blockStarts = ''.join(["%d," % (chunk[1]-chromStart) for chunk in self.utr3])
#print "blockCount %d blockSizes %s blockStarts %s" % (blockCount, blockSizes, blockStarts)
elif (region == "exons"):
chromStart = self.exons[0][1] # start of feature is start of first block
chromEnd = self.exons[-1][2] # end of feature is end of last block
regionName = self.name + "_exon"
blockCount = len(self.exons)
blockSizes = ''.join(["%d," % (chunk[2]-chunk[1]) for chunk in self.exons])
blockStarts = ''.join(["%d," % (chunk[1]-chromStart) for chunk in self.exons])
#print "blockCount %d blockSizes %s blockStarts %s" % (blockCount, blockSizes, blockStarts)
elif (region == "introns"):
chromStart = self.introns[0][1] # start of feature is start of first block
chromEnd = self.introns[-1][2] # end of feature is end of last block
regionName = self.name + "_intron"
blockCount = len(self.introns)
blockSizes = ''.join(["%d," % (chunk[2]-chunk[1]) for chunk in self.introns])
blockStarts = ''.join(["%d," % (chunk[1]-chromStart) for chunk in self.introns])
#print "blockCount %d blockSizes %s blockStarts %s" % (blockCount, blockSizes, blockStarts)
else:
print "UCSCKnownGene blockBedFormat error: currently only regions 5utr/cds/3utr/exons/introns are supported"
returnVal = "%s\t%d\t%d\t%s\t%d\t%c\t%d\t%d\t%s\t%d\t%s\t%s" % (self.chrom, chromStart, chromEnd, regionName, score, self.strand, chromStart, chromEnd, rgb, blockCount, blockSizes, blockStarts)
return returnVal
def computeMetadata(self):
# -- begin computing metadata --
# -- note: chose clarity of code and conditionals here over most efficient computation (i.e. some clauses may be redundant)
if (self.strand == "+"):
#print ("DBUG - exonCt %d i %d exonEnds[i] %d cdsStart %d exonStarts[i] %d cdsEnd %d") % \
# (self.exonCt, i, self.exonEnds[i], self.cdsStart, self.exonStarts[i], self.cdsEnd)
for i in range (self.exonCt):
if (self.cdsStart != self.cdsEnd): # if this is a coding transcript
self.coding = True
# -- first compute 5'utr, CDS, 3'utr regions --
#case 1 - exon spans 5' UTR/CDS/3' UTR
if (self.exonStarts[i] < self.cdsStart and self.exonEnds[i] > self.cdsEnd):
self.utr5.append((self.chrom, self.exonStarts[i], self.cdsStart, self.name))
self.utr5Len += self.cdsStart - self.exonStarts[i]
self.utr5start.append((self.chrom, self.exonStarts[i], self.cdsStart, self.name)) # for now just append the 5' utr exons to the utr5start
self.utr5startLen += self.cdsStart - self.exonStarts[i]
self.cds.append((self.chrom, self.cdsStart, self.cdsEnd, self.name))
self.cdsLen += self.cdsEnd - self.cdsStart
self.utr3.append((self.chrom, self.cdsEnd, self.exonEnds[i], self.name))
self.utr3Len += self.exonEnds[i] - self.cdsEnd
#case 2 - exon spans 5' UTR/CDS junction
elif (self.exonStarts[i] < self.cdsStart and self.exonEnds[i] >= self.cdsStart):
self.utr5.append((self.chrom, self.exonStarts[i], self.cdsStart, self.name))
self.utr5Len += self.cdsStart - self.exonStarts[i]
self.utr5start.append((self.chrom, self.exonStarts[i], self.cdsStart, self.name))
self.utr5startLen += self.cdsStart - self.exonStarts[i]
self.cds.append((self.chrom, self.cdsStart, self.exonEnds[i], self.name))
self.cdsLen += self.exonEnds[i]- self.cdsStart
#case 3 - exon spans CDS/3'UTR junction
elif (self.exonStarts[i] >= self.cdsStart and self.exonStarts[i] <= self.cdsEnd and self.exonEnds[i] > self.cdsEnd):
self.cds.append((self.chrom, self.exonStarts[i], self.cdsEnd, self.name))
self.cdsLen += self.cdsEnd - self.exonStarts[i]
self.utr3.append((self.chrom, self.cdsEnd, self.exonEnds[i], self.name))
self.utr3Len += self.exonEnds[i] - self.cdsEnd
#case 4 - exon is 5' UTR only
elif (self.exonStarts[i] < self.cdsStart and self.exonEnds[i] < self.cdsStart):
self.utr5.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.utr5Len += self.exonEnds[i] - self.exonStarts[i]
self.utr5start.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.utr5startLen += self.exonEnds[i] - self.exonStarts[i]
#case 5 - exon is CDS only
elif (self.exonStarts[i] >= self.cdsStart and self.exonEnds[i] <= self.cdsEnd):
self.cds.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.cdsLen += self.exonEnds[i] - self.exonStarts[i]
#case 6 - exon is 3' UTR only
elif (self.exonStarts[i] > self.cdsEnd and self.exonEnds[i] > self.cdsEnd):
self.utr3.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.utr3Len += self.exonEnds[i] - self.exonStarts[i]
else:
print "Thar be dragons - Transcript computeMetadata + stranded gene region parsing"
# -- generate combined exonic and intronic regions --
#exons are easy
self.exons.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.exonsLen += self.exonEnds[i] - self.exonStarts[i]
#print "DBUG2: i %d self.exonCt-1 %d self.exonEnds %s self.exonStarts %s" % (i, self.exonCt-1, self.exonEnds, self.exonStarts)
if (i < self.exonCt - 1): # only compute introns for nonterminal exons
# an intron is the region between the end of the current exon and start of the next
self.introns.append((self.chrom, self.exonEnds[i], self.exonStarts[i+1], self.name))
self.intronsLen += self.exonStarts[i+1] - self.exonEnds[i]
# append 27 nt of the coding sequence onto the utr5start regions by creating another block, only if there is a 5' utr already
if (self.coding and self.utr5Len > 0):
added = 0
index = 0
while(added < 27 and index < len(self.cds)):
if (self.cds[index][2] - self.cds[index][1]) > 27 - added:
self.utr5start.append((self.chrom, self.cds[index][1], self.cds[index][1] + 27 - added, self.name))
self.utr5startLen += 27 - added
added += 27 - added
else:
self.utr5start.append((self.chrom, self.cds[index][1], self.cds[index][2], self.name))
self.utr5startLen += self.cds[index][2] - self.cds[index][1]
added += self.cds[index][2] - self.cds[index][1]
index += 1
if (added < 27):
#print "Transcript.py: aborting 5' UTR start for transcript %s because %d nts added (CDS length %d)" % (self.name, added, self.cdsLen)
self.utr5startLen = 0
self.utr5start = []
elif (self.strand == "-"):
#uc001ach.2 chr1 - 910578 917473 911551 916546 5 910578,911878,914260,916516,917444, 911649,912004,916037,916553,917473, Q5SV97 uc001ach.2
# name chrom strand txStart txEnd cdsStart self.cdsEnd exonCt exonStarts exonEnds proteinID alignID
# for the minus strand everything is the same except the order of encountering regions is reversed
# i.e. 3' UTR -> CDS -> 5' UTR
for i in range (self.exonCt):
#print ("DBUG - exonCt %d i %d self.exonEnds[i] %d self.cdsStart %d exonStarts[i] %d self.cdsEnd %d") % \
# (self.exonCt, i, self.exonEnds[i], self.cdsStart, self.exonStarts[i], self.cdsEnd)
if (self.cdsStart != self.cdsEnd):
self.coding = True
# -- first compute 5'utr, CDS, 3'utr regions --
# -- this is the same as for + sense except 5' UTR and 3' UTR are swapped throughout
#case 1 - exon spans 3' UTR/CDS/5' UTR
if (self.exonStarts[i] < self.cdsStart and self.exonEnds[i] > self.cdsEnd):
self.utr3.append((self.chrom, self.exonStarts[i], self.cdsStart, self.name))
self.utr3Len += self.cdsStart - self.exonStarts[i]
self.cds.append((self.chrom, self.cdsStart, self.cdsEnd, self.name))
self.cdsLen += self.cdsEnd - self.cdsStart
self.utr5.append((self.chrom, self.cdsEnd, self.exonEnds[i], self.name))
self.utr5Len += self.exonEnds[i] - self.cdsEnd
self.utr5start.append((self.chrom, self.cdsEnd, self.exonEnds[i], self.name))
self.utr5startLen += self.exonEnds[i] - (self.cdsEnd)
#case 2 - exon spans 3' UTR/CDS junction
elif (self.exonStarts[i] < self.cdsStart and self.exonEnds[i] >= self.cdsStart):
self.utr3.append((self.chrom, self.exonStarts[i], self.cdsStart, self.name))
self.utr3Len += self.cdsStart - self.exonStarts[i]
self.cds.append((self.chrom, self.cdsStart, self.exonEnds[i], self.name))
self.cdsLen += self.exonEnds[i]- self.cdsStart
#case 3 - exon spans CDS/5'UTR junction
elif (self.exonStarts[i] >= self.cdsStart and self.exonStarts[i] <= self.cdsEnd and self.exonEnds[i] > self.cdsEnd):
self.cds.append((self.chrom, self.exonStarts[i], self.cdsEnd, self.name))
self.cdsLen += self.cdsEnd - self.exonStarts[i]
self.utr5.append((self.chrom, self.cdsEnd, self.exonEnds[i], self.name))
self.utr5Len += self.exonEnds[i] - self.cdsEnd
self.utr5start.append((self.chrom, self.cdsEnd, self.exonEnds[i], self.name))
self.utr5startLen += self.exonEnds[i] - (self.cdsEnd)
#case 4 - exon is 3' UTR only
elif (self.exonStarts[i] < self.cdsStart and self.exonEnds[i] < self.cdsStart):
self.utr3.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.utr3Len += self.exonEnds[i] - self.exonStarts[i]
#case 5 - exon is CDS only
elif (self.exonStarts[i] >= self.cdsStart and self.exonEnds[i] <= self.cdsEnd):
self.cds.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.cdsLen += self.exonEnds[i] - self.exonStarts[i]
#case 6 - exon is 5' UTR only
elif (self.exonStarts[i] > self.cdsEnd and self.exonEnds[i] > self.cdsEnd):
self.utr5.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.utr5Len += self.exonEnds[i] - self.exonStarts[i]
self.utr5start.append((self.chrom, self.exonStarts[i] , self.exonEnds[i], self.name))
self.utr5startLen += self.exonEnds[i] - self.exonStarts[i]
else:
print "Thar be dragons - Transcript computeMetadata - stranded gene region parsing"
#else:
# print "- strand noncoding transcript"
# -- generate combined exonic and intronic regions --
#exons are easy
self.exons.append((self.chrom, self.exonStarts[i], self.exonEnds[i], self.name))
self.exonsLen += self.exonEnds[i] - self.exonStarts[i]
if (i < self.exonCt - 1): # only compute introns for nonterminal exons
# an intron is the region between the end of the current exon and start of the next
self.introns.append((self.chrom, self.exonEnds[i], self.exonStarts[i+1], self.name))
self.intronsLen += self.exonStarts[i+1] - self.exonEnds[i]
# append 27 nt of the coding sequence onto the utr5start regions by creating another block, only if there is a 5' utr already
if (self.coding and self.utr5Len > 0):
added = 0
index = -1
while(added < 27 and index >= len(self.cds)*-1): #cdsEnd is the start, and the last exon is the first exon of the cds
#print self.cds
#print self.cds[index]
# need to insert at the beginning here and not append
if (self.cds[index][2] - self.cds[index][1]) > 27 - added:
self.utr5start.insert(0,(self.chrom, self.cds[index][2] - (27 - added), self.cds[index][2], self.name))
self.utr5startLen += 27 - added
added += 27 - added
else:
self.utr5start.insert(0,(self.chrom, self.cds[index][1], self.cds[index][2], self.name))
self.utr5startLen += self.cds[index][2] - self.cds[index][1]
added += self.cds[index][2] - self.cds[index][1]
index -= 1
if (added < 27):
#print "Transcript.py: aborting 5' UTR start for transcript %s because %d nts added (CDS length %d)" % (self.name, added, self.cdsLen)
self.utr5startLen = 0
self.utr5start = []
else:
print "Thar be dragons - Transcript computeMetadata strand does not match + or -"
#example line format from knownGenes file (from UCSC)
# uc010nxq.1 chr1 + 11873 14409 12189 13639 3 11873,12594,13402, 12227,12721,14409, B7ZGX9 uc010nxq.1
# line format
# name chrom strand txStart txEnd cdsStart cdsEnd exonCt exonStarts exonEnds proteinID alignID
def createUCSCTranscript(knownGeneLine):
foo = Transcript()
line = knownGeneLine.split()
# -- read in knownGene fields --
foo.name = line[0]
foo.chrom = line[1]
foo.strand = line[2]
foo.txStart = int(line[3])
foo.txEnd = int(line[4])
foo.cdsStart = int(line[5])
foo.cdsEnd = int(line[6])
foo.exonCt = int(line[7])
starts = line[8].split(",")
ends = line[9].split(",")
for i in range(foo.exonCt):
foo.exonStarts.append(int(starts[i]))
foo.exonEnds.append(int(ends[i]))
foo.computeMetadata()
return foo
# input to createGTFTranscript below must be a list of dictionaries for each line of the input GTF file
# these are created inside knowngenes_to_transcript_regions.py
# example input:
#[{'gene_name': 'DDX11L1', 'seqname': '1', 'end': '12227', 'start': '11869', 'frame': None, 'transcript_source': 'havana', 'feature': 'exon', 'exon_number': '1', 'exon_id': 'ENSE00002234944', 'tss_id': 'TSS15145', 'source': 'processed_transcript', 'gene_source': 'ensembl_havana', 'score': None, 'gene_biotype': 'pseudogene', 'gene_id': 'ENSG00000223972', 'transcript_id': 'ENST00000456328', 'transcript_name': 'DDX11L1-002', 'strand': '+'}, {'seqname': '1', 'end': '14409', 'start': '11869', 'frame': None, 'transcript_source': 'havana', 'feature': 'transcript', 'gene_id': 'ENSG00000223972', 'tss_id': 'TSS15145', 'source': 'processed_transcript', 'gene_source': 'ensembl_havana', 'score': None, 'gene_biotype': 'pseudogene', 'gene_name': 'DDX11L1', 'transcript_id': 'ENST00000456328', 'transcript_name': 'DDX11L1-002', 'strand': '+'}]
# keys for each dict:
# gene_name
# seqname
# start
# end
# frame
# transcript_source
# feature
# exon_number
# exon_id
# tss_id
# source
# gene_source
# score
# gene_biotype
# gene_id
# transcript_id
# transcript_name
# strand
def createGTFTranscript(gtfLines):
foo = Transcript()
# these properties (better be) all identical for each entry in the list of dicts
first = gtfLines[0]
foo.name = first["transcript_id"]
foo.chrom = first["seqname"]
foo.strand = first["strand"]
# now process all lines for this transcript ID
for dict in gtfLines:
# ensembl GTFs have special lines where feature = "transcript" and feature = "CDS" that define the transcript and CDS start/ends, respectively
# GTF files are closed intervals while BED are right-open-left-closed, so ---
# need to subtract one from all start coordinates? seems counterintuitive maybe the input genome.fa is zero based?
if (dict["feature"] == "transcript"):
if (foo.txStart == 0 or int(dict["start"]) < foo.txStart):
foo.txStart = int(dict["start"]) - 1
if (foo.txEnd == 0 or int(dict["end"]) > foo.txEnd):
foo.txEnd = int(dict["end"])
if (dict["feature"] == "CDS"):
if (foo.cdsStart == 0 or int(dict["start"]) < foo.cdsStart):
foo.cdsStart = int(dict["start"]) - 1
if (foo.cdsEnd== 0 or int(dict["end"]) > foo.cdsEnd):
foo.cdsEnd = int(dict["end"])
if (dict["feature"] == "exon"):
foo.exonCt += 1
foo.exonStarts.append(int(dict["start"]) - 1)
foo.exonEnds.append(int(dict["end"]))
foo.computeMetadata()
return foo