blib/script/gtf2gff3.pl untested

filter: Statementstmt 0.0% 0 / 553 Branchbran 0.0% 0 / 308 Conditioncond 0.0% 0 / 214 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 28 Podpod 0.0% 0 / 24 totaltotal 0.0% 0 / 1127 CC 147 SCAR 54.7
CC
147
Cov
0%
process_start
462.0
process_stop
462.0
validate_and_finish_trnsc
420.0
CRAP 237.7
1 #!/usr/local/bin/perl
2 use strict;
3 use warnings;
4 use Getopt::Long;
5  
6 #-----------------------------------------------------------------------------
7 #----------------------------------- MAIN ------------------------------------
8 #-----------------------------------------------------------------------------
9 my $usage = "
10  
11 Synopsis:
12  
13 gtf2gff3 --cfg gtf2gff3_MY_CONFIG.cfg gtf_file > gff3_file
14  
15 gtf2gff3 --help # for a more detailed help message.
16  
17 Description:
18  
19 This script will convert GTF formatted files to valid GFF3 formatted
20 files. It will map the column 3 (\"type\" column) to valid SO, but
21 because any non standard term may appear in that column in GTF files,
22 you may edit the config file to provide your own GTF feature to SO
23 mapping. The script will also build gene models from exons, CDSs and
24 other features given in the GTF file. It is currently tested on Ensemble
25 and Twinscan GTF, and it should work on any other files that follow the
26 same specification. It does not work on GTF from the UCSC table browser
27 because those files use the same ID for gene and transcript, so it is
28 impossible to group multiple transcripts to a gene. See the README that
29 came with the script for more info.
30  
31 Options:
32  
33 --cfg Provide the filename for a config file. See the configuration
34 file provided with this script for format details. Use this
35 configuration file to modify the behavior of the script. If no config
36 file is given it looks for ./gtf2gff3.cfg, ~/gtf2gff3.cfg or
37 /etc/gtf2gff3.cfg in that order.
38  
39 --help Provide a more detailed help message.
40  
41 ";
42  
43 my ($help, $cfg_file);
44 my $opt_success = GetOptions('help' => \$help,
45 'cfg=s' => \$cfg_file);
46  
47 die $usage if ! $opt_success;
48  
49 if ($help) {
50 print `perldoc $0`;
51 exit;
52 }
53  
54 my $file = shift;
55 die $usage unless $file;
56  
57 my $home = $ENV{HOME} || '.'; #Apache has no home, so avoid the error.
58  
59 my @cfg_files = ($cfg_file,
60 './gtf2gff3.cfg',
61 "$home/gtf2gff3.cfg",
62 '/etc/gtf2gff3.cfg',
63 );
64 @cfg_files = grep {-e $_ if $_} @cfg_files;
65 $cfg_file = shift @cfg_files;
66 $cfg_file ||= '';
67  
68 ################################################################################
69 # LOAD CONFIGURATION OR USE DEFAULTS
70 ################################################################################
71  
72 my %config;
73 eval {
74 require Config::Std;
75 read_config $cfg_file => my %config if -e $cfg_file;
76 };
77 if ($@ =~ /Can't locate/) {
78 print STDERR "Config::Std not installed. Will use built-in defaults.\n";
79 }
80  
81 our $INPUT_FEATURE_MAP = $config{INPUT_FEATURE_MAP};
82 $INPUT_FEATURE_MAP ||= {gene => 'gene',
83 mRNA => 'mRNA',
84 exon => 'exon',
85 five_prime_UTR => 'five_prime_utr',
86 start_codon => 'start_codon',
87 CDS => 'CDS',
88 stop_codon => 'stop_codon',
89 three_prime_UTR => 'three_prime_utr'};
90  
91 our $GTF_ATTRB_MAP = $config{GTF_ATTRB_MAP};
92 $GTF_ATTRB_MAP ||= {gene_id => 'gene_id',
93 gene_name => 'gene_name',
94 trnsc_id => 'transcript_id',
95 trnsc_name => 'transcript_name'};
96  
97 our $GFF3_ATTRB_MAP = $config{GFF3_ATTRB_MAP};
98 $GFF3_ATTRB_MAP ||= {gene_id => 'gene_id',
99 gene_name => 'gene_name',
100 trnsc_id => 'transcript_id',
101 trnsc_name => 'transcript_name',
102 id => 'ID',
103 parent => 'Parent',
104 name => 'Name'};
105  
106 our $LIMIT_ATTRB = $config{MISC}{LIMIT_ATTRB} || 1;
107 our $ATTRB_DELIMITER = $config{MISC}{ATTRB_DELIMITER} ? qr{$config{MISC}{ATTRB_DELIMITER}}
108 : qr{\s*;\s*};
109 our $ATTRB_REGEX = $config{MISC}{ATTRB_REGEX} ? qr{$config{MISC}{ATTRB_REGEX}}
110 : qr{^\s*(\S+)\s+(\"[^\"]*\")\s*$};
111  
112 our $START_IN_CDS = $config{MISC}{START_IN_CDS} || 1;
113 our $STOP_IN_CDS = $config{MISC}{STOP_IN_CDS} || 0;
114 our $DEFAULT_STRAND = $config{MISC}{DEFAULT_STRAND};
115 ################################################################################
116  
117 my ($genes, $features) = parse_gtf($file);
118  
119 $genes = build_genes($genes);
120  
121 print_gff3($genes, $features);
122  
123 #-----------------------------------------------------------------------------
124 #-------------------------------- SUBROUTINES --------------------------------
125 #-----------------------------------------------------------------------------
126 sub parse_gtf {
127  
128 my $file = shift;
129 open (my $IN, '<', $file) or die "FATAL: Can't open GTF file: $file for reading.\n$!\n";
130  
131 # %genes will have the following structure:
132 # $genes->gene_id->trnsc_id->feature_type->feature
133 # |
134 # ->other->feature_type->feature
135 #
136 my (%genes, %features);
137  
138 while (<$IN>) {
139  
140 chomp;
141 s/^\s+//;
142 s/\s+$//;
143  
144 #Handle full line comments, meta-comments and blank lines;
145  
146 #Grab any comments
147 my ($comment) = $_ =~ s/(\#.*$)//;
148 ;
149  
150 my ($seqname, $source, $feature_type, $start, $end, $score,
151 $strand, $frame, $attrb_text) = split "\t", $_;
152  
153 my $attributes = parse_attributes($attrb_text);
154  
155 $feature_type = $INPUT_FEATURE_MAP->{$feature_type};
156  
157 #Note here that we're mapping between GTF/GFF and GFF3
158 #nomeclature for the hash keys
159 my $feature = {seq_id => $seqname,
160 source => $source,
161 type => $feature_type,
162 start => $start,
163 end => $end,
164 score => $score,
165 strand => $strand,
166 phase => $frame,
167 attributes => $attributes,
168 comment => $comment};
169  
170 #Feature has a gene_id
171 if (exists $attributes->{$GTF_ATTRB_MAP->{gene_id}}) {
172  
173 my $gene_id = $attributes->{$GTF_ATTRB_MAP->{gene_id}}[0];
174  
175 #Feature has a gene ID and transcript ID
176 if (exists $attributes->{$GTF_ATTRB_MAP->{trnsc_id}}) {
177 my $trnsc_id = $attributes->{$GTF_ATTRB_MAP->{trnsc_id}}[0];
178 # fix broken UCSC GTF!
179 if ($gene_id eq $trnsc_id) {
180 ($gene_id = $trnsc_id) =~ s/\.\d+$//;
181 $attributes->{gene_id}[0] = $gene_id;
182 }
183 push @{$genes{$seqname}{$gene_id}{$trnsc_id}{$feature_type}},
184 $feature;
185 }
186 else {
187 push @{$genes{$seqname}{$gene_id}{other}{$feature}},
188 $feature;
189 }
190  
191 }
192 else {
193 push @{$features{$feature_type}}, $feature;
194 }
195 }
196 return (\%genes, \%features);
197 }
198 #-----------------------------------------------------------------------------
199 sub parse_attributes {
200  
201 my $attrb_text = shift;
202  
203 #Skip it if it's undefined or empty
204 return if ! defined $attrb_text || $attrb_text =~ /^\s+$/;
205  
206 #Split the attributes
207 my @attrb_array = split $ATTRB_DELIMITER, $attrb_text;
208  
209 #Grab key, value pairs
210 my %attributes;
211 ATT:
212 for my $attrb (@attrb_array) {
213 my ($key, $value);
214  
215 if ($attrb =~ $ATTRB_REGEX) {
216 ($key, $value) = ($1, $2);
217 $value =~ s/\"//g if $value !~ /\s/;
218 }
219 else {
220 print STDERR "ERROR: Missing or non-standard attributes: parse_attributes\n";
221 next ATT;
222 }
223 push @{$attributes{$key}}, $value;
224 }
225 return \%attributes;
226 }
227 #-----------------------------------------------------------------------------
228 sub build_genes {
229  
230 my $genes = shift;
231  
232 my @genes;
233 for my $seq_id (keys %{$genes}) {
234 for my $gene_id (keys %{$genes->{$seq_id}}) {
235  
236 my $gene = build_gene($genes->{$seq_id}{$gene_id});
237 push @genes, $gene;
238 }
239 }
240 return \@genes;
241 }
242 #-----------------------------------------------------------------------------
243 sub build_gene {
244  
245 my $trnscs = shift;
246  
247 my @trnscs;
248 TRN:
249 for my $trnsc_id (keys %{$trnscs}) {
250  
251 if ($trnsc_id eq 'other') {
252 #Handle non-transcript gene features
253 print STDERR "ERROR: Non-transcript gene feature " .
254 "not supported. Please contact the author for " .
255 "support: build_gene\n";
256 next TRN;
257 }
258 my $features = $trnscs->{$trnsc_id};
259 my $trnsc = build_trnsc($features);
260 push @trnscs, $trnsc;
261 }
262  
263 my $gene = validate_and_build_gene(\@trnscs);
264 return $gene;
265 }
266 #-----------------------------------------------------------------------------
267 sub build_trnsc {
268  
269 my $features = shift;
270  
271 my $exons = $features->{exon} || [];
272 my $CDSs = $features->{CDS} || [];
273 my $start = $features->{start_codon} || [];
274 my $stop = $features->{stop_codon} || [];
275 my $five_UTRs = $features->{five_prime_utr} || [];
276 my $three_UTRs = $features->{three_prime_utr} || [];
277  
278 #We require at least CDSs or exons
279 unless (scalar @{$CDSs} || scalar @{$exons}) {
280 print STDERR "ERROR: Must have at least exons or CDSs to" .
281 "build a transcript: build_trnsc\n";
282 return;
283 }
284  
285 #Make start codons if they don't exist
286 $start = process_start($exons, $CDSs, $start, $five_UTRs)
287 if ! scalar @{$start};
288 #Make stop codons if they don't exist
289 $stop = process_stop($exons, $CDSs, $stop, $three_UTRs)
290 if ! scalar @{$stop};
291  
292 #Make UTRs, exons and/or CDSs if they don't exist
293 ($five_UTRs,
294 $exons,
295 $CDSs,
296 $three_UTRs) = process_exon_CDS_UTRs($exons, $CDSs,
297 $start, $stop,
298 $five_UTRs,
299 $three_UTRs);
300  
301  
302 $features = {exon => $exons,
303 five_prime_UTR => $five_UTRs,
304 start_codon => $start,
305 CDS => $CDSs,
306 stop_codon => $stop,
307 three_prime_UTR => $three_UTRs};
308  
309 #Build and validate the transcripts
310 my $trnsc = validate_and_finish_trnsc($features);
311  
312 return $trnsc;
313 }
314 #-----------------------------------------------------------------------------
315 sub process_start {
316 my ($exons, $CDSs, $start, $five_UTRs) = @_;
317  
318 my ($start_codon_start, $start_codon_end);
319  
320 my $strand;
321 #Get the strand for exons or CDSs
322 if (scalar @{$exons}) {
323 $strand = strand($exons->[0]->{strand});
324 }
325 elsif (scalar @{$CDSs}) {
326 $strand = strand($CDSs->[0]->{strand});
327 }
328 else {
329 die "FATAL: Need exons or CDSs to build transcripts: " .
330 "process_start.\n";
331 }
332  
333 #Already have start
334 if (scalar @{$start}) {
335 return $start;
336 }
337  
338 ################################################################################
339 # Don't infer start codons from CDS unless backed by UTR or exon infered UTR
340 ################################################################################
341  
342 #Build start from CDS
343 elsif (scalar @{$CDSs} && scalar @{$exons}) {
344  
345 $CDSs = sort_features($CDSs, $strand);
346 my $first_CDS = $CDSs->[0];
347  
348 $exons = sort_features($exons, $strand);
349 my $first_exon = $exons->[0];
350  
351 if ($strand == 1) {
352 if ($first_exon->{start} < $first_CDS->{start}) {
353 $start_codon_start = $first_CDS->{start};
354 #Move start codon out of CDS if config says to
355 if ($START_IN_CDS == 0) {
356 $start_codon_start -= 3;
357 }
358 }
359 }
360 elsif ($strand == -1) {
361 if ($first_exon->{end} > $first_CDS->{end}) {
362 $start_codon_start = $first_CDS->{end} - 2;
363 #Move start codon out of CDS if config says to
364 if ($START_IN_CDS == 0) {
365 $start_codon_start += 3;
366 }
367 }
368 }
369 $start_codon_end = $start_codon_start + 2
370 if defined $start_codon_start;
371 }
372 #Here we assume that if you have 5' UTR and CDS that the start codon
373 #must be at the begining of the first CDS. To be more rigorous we should
374 #check the coordinates and be sure that the 5' UTR and CDS are contiguous.
375 elsif (scalar @{$CDSs} && scalar @{$five_UTRs}) {
376  
377 $CDSs = sort_features($CDSs, $strand);
378 my $first_CDS = $CDSs->[0];
379  
380 if ($strand == 1) {
381 $start_codon_start = $first_CDS->{start};
382 #Move start codon out of CDS if config says to
383 if ($START_IN_CDS == 0) {
384 $start_codon_start -= 3;
385 }
386 }
387 elsif ($strand == -1) {
388 $start_codon_start = $first_CDS->{end} - 2;
389 #Move start codon out of CDS if config says to
390 if ($START_IN_CDS == 0) {
391 $start_codon_start += 3;
392 }
393 }
394 $start_codon_end = $start_codon_start + 2;
395 }
396 #Build start from UTRs - I haven't seen an example of this yet. Maybe I should
397 #only create a start codon if it falls within an exon or CDS.
398 elsif (scalar @{$five_UTRs}) {
399 die "FATAL: Untested code in process_start. Contact the aurthor for support\n";
400 $five_UTRs = sort_features($five_UTRs, $strand);
401 my $last_five_UTR = $five_UTRs->[-1];
402 $start_codon_start = $strand == 1 ? $last_five_UTR->{start} + 1 :
403 $last_five_UTR->{end} - 3;
404 $start_codon_end = $start_codon_start + 2;
405 }
406 #No CDSs or UTRs - let's pretend it's non-coding
407 elsif (scalar @{$exons}) {
408 return [];
409 }
410 else {
411 return []; # We don't really need to die here some annotations have stop_codon, but not start_codon
412 # die "FATAL: Invalid feature set: process_start\n";
413 }
414  
415 return [] if (! defined $start_codon_start ||
416 ! defined $start_codon_end);
417  
418 $start = [{start => $start_codon_start,
419 end => $start_codon_end,
420 type => 'start_codon',
421 score => '.',
422 phase => '0'}];
423  
424 return $start;
425 }
426 #-----------------------------------------------------------------------------
427 sub process_stop {
428 my ($exons, $CDSs, $stop, $three_UTRs) = @_;
429  
430 my ($stop_codon_start, $stop_codon_end);
431  
432 #Get the strand
433 my $strand;
434 if (scalar @{$exons}) {
435 $strand = strand($exons->[0]->{strand});
436 }
437 elsif (scalar @{$CDSs}) {
438 $strand = strand($CDSs->[0]->{strand});
439 }
440 else {
441 die "FATAL: Need exons or CDSs to build transcripts: " .
442 "process_stop\n";
443 }
444  
445 #If we already have a stop then return it.
446 if (scalar @{$stop}) {
447 return $stop;
448 }
449  
450 ################################################################################
451 # Don't infer stop codons from CDS unless backed by UTR or exon infered UTR
452 ################################################################################
453  
454 #Build stop from CDSs
455 elsif (scalar @{$CDSs}) {
456  
457 $CDSs = sort_features($CDSs, $strand);
458 my $last_CDS = $CDSs->[-1];
459  
460 $exons = sort_features($exons, $strand);
461 my $last_exon = $exons->[0];
462  
463 if ($strand == 1) {
464 if ($last_exon->{end} > $last_CDS->{end}) {
465 $stop_codon_start = $last_CDS->{end} - 2;
466 #Move stop codon out of CDS is config says to
467 if ($STOP_IN_CDS == 0) {
468 $stop_codon_start += 3;
469 }
470 }
471 }
472 elsif ($strand == -1) {
473 if ($last_exon->{start} < $last_CDS->{start}) {
474 $stop_codon_start = $last_CDS->{start};
475 #Move stop codon out of CDS is config says to
476 if ($STOP_IN_CDS == 0) {
477 $stop_codon_start -= 3;
478 }
479 }
480 }
481  
482 $stop_codon_end = $stop_codon_start + 2
483 if defined $stop_codon_end;
484 }
485 elsif (scalar @{$CDSs} && scalar @{$three_UTRs}) {
486  
487 $CDSs = sort_features($CDSs, $strand);
488 my $last_CDS = $CDSs->[-1];
489  
490 if ($strand == 1) {
491 $stop_codon_start = $last_CDS->{end} - 2;
492 #Move stop codon out of CDS is config says to
493 if ($STOP_IN_CDS == 0) {
494 $stop_codon_start += 3;
495 }
496 }
497 elsif ($strand == -1) {
498 $stop_codon_start = $last_CDS->{start};
499 #Move stop codon out of CDS is config says to
500 if ($STOP_IN_CDS == 0) {
501 $stop_codon_start -= 3;
502 }
503 }
504 $stop_codon_end = $stop_codon_start + 2;
505 }
506 #Build stop from UTRs
507 elsif (scalar @{$three_UTRs}) {
508 die("FATAL: Untested code: process_stop.\n");
509  
510 my $strand = strand($three_UTRs->[0]);
511 $three_UTRs = sort_features($three_UTRs, $strand);
512 my $first_three_UTR = $three_UTRs->[0];
513 $stop_codon_start = $strand == 1 ? $first_three_UTR->{start} - 3 :
514 $first_three_UTR->{end} + 1;
515  
516 $stop_codon_end = $stop_codon_start + 2;
517 }
518 elsif (scalar @{$exons}) {
519 #Treating this as a non-coding transcript
520 return [];
521 }
522 else {
523 # We don't really need to die here. Some features may have
524 # start_codon, but not stop_codon
525 return [];
526 #die "FATAL: Invalid feature set: process_stop\n";
527 }
528  
529 return [] if (! defined $stop_codon_start ||
530 ! defined $stop_codon_end);
531  
532 $stop = [{start => $stop_codon_start,
533 end => $stop_codon_end,
534 type => 'stop_codon',
535 score => '.',
536 phase => '0'}];
537  
538 return $stop;
539 }
540 #-----------------------------------------------------------------------------
541 sub process_exon_CDS_UTRs {
542 my ($exons, $CDSs, $start, $stop,
543 $five_UTRs, $three_UTRs) = @_;
544  
545 #Check what features we already have so we don't rebuild them
546 my $have_five_UTRs++ if scalar @{$five_UTRs};
547 my $have_exons++ if scalar @{$exons};
548 my $have_start++ if scalar @{$start};
549 my $have_CDSs++ if scalar @{$CDSs};
550 my $have_stop++ if scalar @{$stop};
551 my $have_three_UTRs++ if scalar @{$three_UTRs};
552  
553 #If CDSs already exist make sure that they include start and stop codons
554 if (scalar @{$CDSs}) {
555 include_terminal_codons($CDSs, $start, $stop);
556 }
557  
558 #If we already have everything, then return
559 if ($have_exons && $have_CDSs && ($have_five_UTRs || $have_three_UTRs)) {
560 return ($five_UTRs, $exons, $CDSs, $three_UTRs);
561 }
562 #Build CDSs && UTRs
563 elsif ($have_exons && ($have_start || $have_stop || $have_CDSs ||
564 $have_three_UTRs || $have_five_UTRs)) {
565 # Make sure that evaluate exons can handle only a start OR a stop!!!
566 for my $exon (@{$exons}) {
567 my ($five_UTR, $CDS, $three_UTR) =
568 evaluate_exon($exon, $start->[0], $stop->[0]);
569 push @{$five_UTRs}, $five_UTR
570 if scalar keys %{$five_UTR} && ! $have_five_UTRs;
571 push @{$CDSs}, $CDS if scalar keys %{$CDS} && ! $have_CDSs;
572 push @{$three_UTRs}, $three_UTR
573 if scalar keys %{$three_UTR} && ! $have_three_UTRs;
574 }
575 }
576 #Build exons
577 elsif (!$have_exons && $have_CDSs){
578 $exons = build_exons($five_UTRs, $start, $CDSs, $stop, $three_UTRs);
579 }
580 #Treat as non-coding even if we have a start or stop but not both
581 elsif ($have_exons && ! $have_CDSs && ! $have_five_UTRs &&
582 ! $have_three_UTRs && ! $have_start && ! $have_stop) {
583 #Treating this as a non_coding transcript
584 return ($five_UTRs, $exons, $CDSs, $three_UTRs);
585 }
586 else {
587 die "FATAL: Invalid feature set: process_exon_CDS_UTR\n";
588 }
589  
590 return ($five_UTRs, $exons, $CDSs, $three_UTRs);
591 }
592 #-----------------------------------------------------------------------------
593 sub include_terminal_codons {
594 my ($CDSs, $start, $stop) = @_;
595  
596 my $strand = strand($CDSs->[0]{strand});
597  
598 $CDSs = sort_features($CDSs, $strand);
599 my $first_CDS = $CDSs->[0];
600 my $last_CDS = $CDSs->[-1];
601  
602 if ($strand == 1) {
603 if (scalar @{$start}) {
604 $first_CDS->{start} = $start->[0]{start}
605 if $start->[0]{end} + 1 == $first_CDS->{start};
606 }
607 #START_IN_CDS was considered when start was built, so it could introduce errors
608 #to consider it again here
609 # elsif (defined $START_IN_CDS) {
610 # $first_CDS->{start} -= 3 if ! $START_IN_CDS;
611 # }
612  
613 if (scalar @{$stop}) {
614 $last_CDS->{end} = $stop->[0]{end}
615 if $stop->[0]{start} - 1 == $last_CDS->{end};
616 }
617  
618 #STOP_IN_CDS was considered when stop was built, so it could introduce errors
619 #to consider it again here
620 # elsif (defined $STOP_IN_CDS) {
621 # $last_CDS->{end} += 3 if ! $STOP_IN_CDS;
622 # }
623 }
624 elsif ($strand == -1) {
625 if (scalar @{$start}) {
626 $first_CDS->{end} = $start->[0]{end}
627 if $start->[0]{start} - 1 == $first_CDS->{end};
628 }
629 #START_IN_CDS was considered when start was built, so it could introduce errors
630 #to consider it again here
631 # elsif (defined $START_IN_CDS) {
632 # $first_CDS->{end} += 3 if ! $START_IN_CDS;
633 # }
634  
635 if (scalar @{$stop}) {
636 $last_CDS->{start} = $stop->[0]{start}
637 if $stop->[0]{end} + 1 == $last_CDS->{start};
638 }
639 #STOP_IN_CDS was considered when stop was built, so it could introduce errors
640 #to consider it again here
641 # elsif (defined $STOP_IN_CDS) {
642 # $last_CDS->{start} -= 3 if ! $STOP_IN_CDS;
643 # }
644 }
645 }
646 #-----------------------------------------------------------------------------
647 sub evaluate_exon {
648 my ($exon, $start, $stop) = @_;
649  
650 my $strand = strand($exon);
651  
652 my %five_UTR;
653 my %CDS;
654 my %three_UTR;
655  
656 #######################################
657 # Allow success if missing either start or stop
658 #######################################
659  
660 if ($strand == 1) {
661 #Exon is fully 5' UTR
662 if (defined $start->{start} &&
663 $exon->{end} <= $start->{start}) {
664 $five_UTR{start} = $exon->{start};
665 $five_UTR{end} = $exon->{end};
666 }
667 #Exon stradles start codon
668 elsif (defined $start->{start} &&
669 $exon->{start} < $start->{start} &&
670 $exon->{end} > $start->{start} ) {
671 $five_UTR{start} = $exon->{start};
672 $five_UTR{end} = $start->{start} - 1;
673 if (defined $stop->{start}) {
674 $CDS{start} = $start->{start};
675 $CDS{end} = $exon->{end};
676 $CDS{phase} = 0;
677 }
678 }
679 #Exon is fully CDS
680 elsif (defined $start->{start} &&
681 defined $stop->{end} &&
682 $exon->{start} >= $start->{start} &&
683 $exon->{end} <= $stop->{end} ) {
684 $CDS{start} = $exon->{start};
685 $CDS{end} = $exon->{end};
686 #Set phase if this is first CDS
687 if ($exon->{start} == $start->{end} + 1 ||
688 $exon->{start} == $start->{start} ) {
689 $CDS{phase} = 0;
690 }
691 }
692 #Exon stradles stop codon
693 elsif (defined $stop->{end} &&
694 $exon->{start} < $stop->{end} &&
695 $exon->{end} > $stop->{end} ) {
696 $three_UTR{start} = $stop->{end} + 1;
697 $three_UTR{end} = $exon->{end};
698 if (defined $start->{start}) {
699 $CDS{start} = $exon->{start};
700 $CDS{end} = $stop->{end};
701 }
702 }
703 #Exon is fully 3' UTR
704 elsif (defined $stop->{end} &&
705 $exon->{start} >= $stop->{end}) {
706 $three_UTR{start} = $exon->{start};
707 $three_UTR{end} = $exon->{end};
708 }
709 else {
710 # die "Fatal error in evaluate_exon\n";
711 }
712 }
713 else {
714 #Exon is fully 5' UTR
715 if (defined $start->{end} &&
716 $exon->{start} >= $start->{end}) {
717 $five_UTR{start} = $exon->{start};
718 $five_UTR{end} = $exon->{end};
719 }
720 #Exon stradles start codon
721 elsif (defined $start->{end} &&
722 $exon->{start} < $start->{end} &&
723 $exon->{end} > $start->{end} ) {
724 $five_UTR{start} = $start->{end} + 1;
725 $five_UTR{end} = $exon->{end};
726 if (defined $stop->{start}) {
727 $CDS{start} = $exon->{start};
728 $CDS{end} = $start->{end};
729 }
730 $CDS{phase} = 0;
731 }
732 #Exon is fully CDS
733 elsif (defined $start->{end} &&
734 defined $stop->{start} &&
735 $exon->{end} <= $start->{end} &&
736 $exon->{start} >= $stop->{start} ) {
737 $CDS{start} = $exon->{start};
738 $CDS{end} = $exon->{end};
739 #Set phase 0 if this is first CDS
740 if ($exon->{end} == $start->{start} - 1 ||
741 $exon->{end} == $start->{end} ) {
742 $CDS{phase} = 0;
743 }
744 }
745 #Exon stradles stop codon
746 elsif (defined $stop->{start} &&
747 $exon->{end} > $stop->{start} &&
748 $exon->{start} < $stop->{start} ) {
749 $three_UTR{start} = $exon->{start};
750 $three_UTR{end} = $stop->{start} - 1;
751 if (defined $start->{end}) {
752 $CDS{start} = $stop->{start};
753 $CDS{end} = $exon->{end};
754 }
755 }
756 #Exon is fully 3' UTR
757 elsif (defined $stop->{start} &&
758 $exon->{end} <= $stop->{start}) {
759 $three_UTR{start} = $exon->{start};
760 $three_UTR{end} = $exon->{end};
761 }
762 else {
763 # die "Fatal error in evaluate_exon\n";
764 }
765 }
766 return (\%five_UTR, \%CDS, \%three_UTR);
767 }
768 #-----------------------------------------------------------------------------
769 sub build_exons {
770 my ($five_UTRs, $start, $CDSs, $stop, $three_UTRs) = @_;
771  
772 my $strand = $CDSs->[0]{strand};
773  
774 my @exons;
775  
776 #Make an exon for every 5' UTR
777 for my $five_UTR (@{$five_UTRs}) {
778 push @exons, {start => $five_UTR->{start},
779 end => $five_UTR->{end},
780 type => 'exon',
781 score => '.',
782 strand => $strand,
783 phase => '.'};
784 }
785  
786 #Make and exon for every CDS
787 $CDSs = sort_features($CDSs);
788 for my $CDS (@{$CDSs}) {
789 my $exon = {start => $CDS->{start},
790 end => $CDS->{end},
791 type => 'exon',
792 score => '.',
793 strand => $strand,
794 phase => '.'};
795  
796 #START_IN_CDS and STOP_IN_CDS were already considered when start and stop were
797 #constructed and CDSs were adjusted in include_terminal_codons
798 =head1
799 if ($i == 0 &&
800 $START_IN_CDS == 0) {
801 if ($strand == 1) {
802 $exon->start = $start->[0]{start};
803 }
804 else {
805 $exon->end = $start->[0]{end};
806 }
807 }
808 if ($i == (scalar @{$CDSs} - 1) &&
809 $STOP_IN_CDS == 0) {
810 if ($strand == 1) {
811 $exon->{end} = $stop->[0]{end};
812 }
813 else {
814 $exon->{start} = $stop->[0]{start}
815 }
816 }
817 =cut
818  
819 push @exons, $exon;
820 }
821  
822 #Make an exon for every 3' UTR
823 for my $three_UTR (@{$three_UTRs}) {
824 push @exons, {start => $three_UTR->{start},
825 end => $three_UTR->{end},
826 type => 'exon',
827 score => '.',
828 strand => $strand,
829 phase => '.'};
830 }
831  
832 #Merge any contiguous exons (i.e. from UTR & CDS neighbors)
833 my $exons = sort_features(\@exons, 1);
834 my @merged_exons = shift @{$exons};
835 while (my $exon = shift @{$exons}) {
836 if ($exon->{start} <= $merged_exons[-1]{end} + 1) {
837 $merged_exons[-1]{end} = $exon->{end};
838 }
839 else {
840 push @merged_exons, $exon;
841 }
842 }
843 return \@merged_exons;
844 }
845 #-----------------------------------------------------------------------------
846 sub validate_and_finish_trnsc {
847 my $features = shift;
848  
849 my ($seq_id, $source, $strand, $gene_id, $gene_name,
850 $trnsc_id, $trnsc_name);
851  
852 #Find default parameters from either exons or CDSs
853 TYPE:
854 for my $type ( qw|exon CDS| ) {
855 for my $feature (@{$features->{$type}}) {
856 $seq_id ||= $feature->{seq_id};
857 $source ||= $feature->{source};
858 $strand ||= $feature->{strand};
859 $gene_id ||=
860 $feature->{attributes}{$GTF_ATTRB_MAP->{gene_id}};
861 $gene_name ||=
862 $feature->{attributes}{$GTF_ATTRB_MAP->{gene_name}};
863 $trnsc_id ||=
864 $feature->{attributes}{$GTF_ATTRB_MAP->{trnsc_id}};
865 $trnsc_name ||=
866 $feature->{attributes}{$GTF_ATTRB_MAP->{trnsc_name}};
867 last TYPE if ! grep {! defined $_} ($seq_id, $source,
868 $strand, $gene_name,
869 $trnsc_id, $trnsc_name);
870 }
871 }
872  
873  
874 #Flag if we have any coding features (CDS, start_codon, stop_codon)
875 my $coding_flag;
876 #Min and max for transcript boundaries
877 my ($min, $max);
878 for my $feature_type (keys %{$features}) {
879 my $count;
880  
881 #For keeping track of the phase for the next CDS.
882 my $next_phase = '.';
883  
884 #Sort the features
885 $features->{$feature_type} =
886 sort_features($features->{$feature_type},
887 strand($strand));
888 for my $feature (@{$features->{$feature_type}}) {
889  
890 #min and max to calculate transcript boundaries
891 $min = ! defined $min ?
892 $feature->{start} :
893 $min > $feature->{start} ?
894 $feature->{start} :
895 $min;
896  
897 $max = ! defined $max ?
898 $feature->{end} :
899 $max < $feature->{end} ?
900 $feature->{end} :
901 $max;
902  
903 #Set the flag if we see indications of coding features
904 if (grep {$feature_type eq $_} qw(CDS start_codon
905 stop_codon)) {
906 $coding_flag++ if $feature->{start};
907 }
908  
909 #Calculate CDS phases.
910 if ($feature_type eq 'CDS') {
911 ($feature, $next_phase) = CDS_phase($feature, $next_phase);
912 }
913  
914 #Set parameters to defaults for all features that
915 #don't already have them set
916 if (! defined $feature->{seq_id}) {
917 $feature->{seq_id} = $seq_id;
918 }
919 elsif ($feature->{seq_id} ne $seq_id) {
920 print STDERR "ERROR: seq_id conflict: " .
921 "validate_and_finish_trnsc\n";
922 }
923 if (! defined $feature->{source}) {
924 $feature->{source} = $source;
925 }
926 elsif ($feature->{source} ne $source) {
927 print STDERR "ERROR: source conflict: " .
928 "validate_and_finish_trnsc\n";
929 }
930 if (! defined $feature->{type}) {
931 $feature->{type} = $feature_type;
932 }
933 elsif ($feature->{type} ne $feature_type) {
934 print STDERR "ERROR: type conflict: " .
935 "validate_and_finish_trnsc\n";
936 }
937 if (! defined $feature->{strand}) {
938 $feature->{strand} = $strand;
939 }
940 elsif ($feature->{strand} ne $strand) {
941 print STDERR "ERROR: strand conflict: " .
942 "validate_and_finish_trnsc\n";
943 }
944 if (! defined $feature->{score}) {
945 $feature->{score} = '.';
946 }
947 if (! defined $feature->{phase}) {
948 $feature->{phase} = '.';
949 }
950 #Set attributes
951 $feature->{attributes} =
952 {parent => $trnsc_id,
953 id => ["$feature_type:" . $trnsc_id->[0] .
954 ":" . ++$count]};
955 }
956 }
957  
958 my $trnsc_type = $coding_flag ? 'mRNA' : 'transcript';
959  
960 my $attributes = {parent => $gene_id,
961 parent_name => $gene_name,
962 id => $trnsc_id,
963 name => $trnsc_name};
964  
965 my $trnsc = {seq_id => $seq_id,
966 source => $source,
967 type => $trnsc_type,
968 start => $min,
969 end => $max,
970 score => '.',
971 strand => $strand,
972 phase => '.',
973 attributes => $attributes,
974 features => $features};
975  
976 return $trnsc;
977 }
978 #-----------------------------------------------------------------------------
979 sub CDS_phase {
980 my ($feature, $next_phase) = @_;
981  
982 #If phase isn't already valid assign it
983 if (! defined $feature->{phase} ||
984 $feature->{phase} !~ /^0|1|2$/) {
985 $feature->{phase} = $next_phase;
986 }
987 #If phase is valid, calculate the next phase
988 if ($feature->{phase} =~ /^0|1|2$/) {
989 my $length = ($feature->{end} -
990 $feature->{start}) + 1;
991 # my $hang_3 = $length % 3; # 3' overhang
992 # my $hang_5 = 3 - $hang_3; # 5' overhang
993 #
994 # #The next phase is equal to this phase
995 # #plus the modulus 3 of the length wrapped
996 # #at 2.
997 # $next_phase = $feature->{phase} + $hang_5;
998 # $next_phase -= 3 if $next_phase > 2;
999  
1000 # This was update 5/24/10 in response to an
1001 # e-mail from Leighton Prichard regarding
1002 # errors in the GFF3 spec. The code above
1003 # calculates the phase correctly, but the
1004 # formula suggested by Leighton is cleaner.
1005  
1006 $next_phase = ($feature->{phase} - $length) % 3;
1007  
1008 }
1009  
1010 return ($feature, $next_phase);
1011 }
1012 #-----------------------------------------------------------------------------
1013 sub validate_and_build_gene {
1014 my $trnscs = shift;
1015  
1016 #Get parameter defaults
1017 my $seq_id = $trnscs->[0]{seq_id};
1018 my $source = $trnscs->[0]{source};
1019 my $strand = $trnscs->[0]{strand};
1020 my $gene_id = $trnscs->[0]{attributes}{parent};
1021 my $gene_name = $trnscs->[0]{attributes}{parent_name};
1022  
1023 #Get gene boundaries and check all transcripts for agreement with
1024 #parameter defaults
1025 my ($min, $max);
1026 for my $trnsc (@{$trnscs}) {
1027 $min = ! defined $min ?
1028 $trnsc->{start} :
1029 $min > $trnsc->{start} ?
1030 $trnsc->{start} :
1031 $min;
1032  
1033 $max = ! defined $max ?
1034 $trnsc->{end} :
1035 $max < $trnsc->{end} ?
1036 $trnsc->{end} :
1037 $max;
1038  
1039 print STDERR "ERROR: seq_id conflict: " .
1040 "validate_and_build_gene\n" if $seq_id ne $trnsc->{seq_id};
1041 print STDERR "ERROR: sourc`e conflict: " .
1042 "validate_and_build_gene\n" if $source ne $trnsc->{source};
1043 print STDERR "ERROR: strand conflict: " .
1044 "validate_and_build_gene\n" if $strand ne $trnsc->{strand};
1045 print STDERR "ERROR: gene_id conflict: " .
1046 "validate_and_build_gene\n" if $gene_id->[0] ne
1047 $trnsc->{attributes}{parent}[0];
1048  
1049 }
1050 my $attributes = {id => $gene_id,
1051 name => $gene_name};
1052  
1053 my $gene = {seq_id => $seq_id,
1054 source => $source,
1055 type => 'gene',
1056 start => $min,
1057 end => $max,
1058 score => '.',
1059 strand => $strand,
1060 phase => '.',
1061 attributes => $attributes,
1062 trnscs => $trnscs};
1063  
1064 return $gene;
1065 }
1066 #-----------------------------------------------------------------------------
1067 sub print_gff3 {
1068 my $genes = shift;
1069  
1070 #GFF3 Header here
1071 print "##gff-version 3\n";
1072  
1073 for my $gene (@{$genes}) {
1074 print_gene($gene);
1075 }
1076  
1077 print_features($features) if scalar keys %{$features};
1078 }
1079 #-----------------------------------------------------------------------------
1080 sub print_gene {
1081 my $gene = shift;
1082  
1083 my $attrb_text = make_attribute_text($gene->{attributes});
1084 $attrb_text .= ";Name=$gene->{attributes}{id}[0]";
1085 print join "\t", ($gene->{seq_id},
1086 $gene->{source},
1087 $gene->{type},
1088 $gene->{start},
1089 $gene->{end},
1090 $gene->{score},
1091 $gene->{strand},
1092 $gene->{phase},
1093 $attrb_text,
1094 );
1095 print " " . $gene->{comment} if $gene->{comment};
1096 print "\n";
1097  
1098 for my $trnsc (@{$gene->{trnscs}}) {
1099 print_trnsc($trnsc);
1100 }
1101 }
1102 #-----------------------------------------------------------------------------
1103 sub print_trnsc {
1104 my $trnsc = shift;
1105  
1106 my $attrb_text = make_attribute_text($trnsc->{attributes});
1107 print join "\t", ($trnsc->{seq_id},
1108 $trnsc->{source},
1109 $trnsc->{type},
1110 $trnsc->{start},
1111 $trnsc->{end},
1112 $trnsc->{score},
1113 $trnsc->{strand},
1114 $trnsc->{phase},
1115 $attrb_text,
1116 );
1117 print " " . $trnsc->{comment} if $trnsc->{comment};
1118 print "\n";
1119  
1120 print_features($trnsc->{features});
1121 }
1122 #-----------------------------------------------------------------------------
1123 sub print_features {
1124 my $features = shift;
1125  
1126 my @sorted_feature_types = sort_feature_types($features);
1127 for my $feature_type (@sorted_feature_types) {
1128 $features->{$feature_type} =
1129 sort_features($features->{$feature_type});
1130 for my $feature (@{$features->{$feature_type}}) {
1131 my $attrb_text =
1132 make_attribute_text($feature->{attributes});
1133 print join "\t", ($feature->{seq_id},
1134 $feature->{source},
1135 $feature->{type},
1136 $feature->{start},
1137 $feature->{end},
1138 $feature->{score},
1139 $feature->{strand},
1140 $feature->{phase},
1141 $attrb_text,
1142 );
1143 print " " . $feature->{comment} if
1144 $feature->{comment};
1145 print "\n";
1146 }
1147 }
1148 }
1149 #-----------------------------------------------------------------------------
1150 sub make_attribute_text {
1151 my $attributes = shift;
1152  
1153 #Only print the attributes listed in $LIMIT_ATTRB
1154 my @tags = $LIMIT_ATTRB ?
1155 grep {exists $GFF3_ATTRB_MAP->{$_}} keys %{$attributes} :
1156 keys %{$attributes};
1157  
1158 my %order = (id => 1,
1159 name => 2,
1160 parent => 3,
1161 );
1162  
1163 my @pairs;
1164 for my $tag (sort {$order{$a} || 999 <=> $order{$b} || 999} @tags) {
1165 next unless $attributes->{$tag};
1166 my $tag_text = $GFF3_ATTRB_MAP->{$tag} || $tag;
1167 my $value_text = join ',', @{$attributes->{$tag}};
1168 my $pair_text = join '=', ($tag_text, $value_text);
1169 push @pairs, $pair_text;
1170 }
1171 my $attrb_text = join ';', @pairs;
1172 return $attrb_text;
1173 }
1174 #-----------------------------------------------------------------------------
1175 sub sort_features {
1176 my ($features, $strand) = @_;
1177  
1178 $strand = strand($strand) || strand($features->[0]);
1179  
1180 #Make sure we get the array ref that we wanted
1181 if (ref $features eq 'ARRAY') {
1182 #If we get an array ref with more than one element - sort it
1183 if (scalar @{$features} > 1) {
1184 #Sort + strand features
1185 if ($strand == 1) {
1186 my @sorted_features = sort {$a->{start} <=> $b->{start}}
1187 @{$features};
1188 $features = \@sorted_features;
1189 return $features;
1190 }
1191 #Sort - strand features
1192 elsif ($strand == -1) {
1193 my @sorted_features = sort {$b->{end} <=> $a->{end}}
1194 @{$features};
1195 $features = \@sorted_features;
1196 return $features;
1197 }
1198 }
1199 #Empty or 1 length array just return it
1200 else {
1201 return $features;
1202 }
1203 }
1204 #Don't allow someone to misuse sort_features - require array ref
1205 else {
1206 die "FATAL: Array reference required: sort_features.\n";
1207 }
1208 }
1209 #-----------------------------------------------------------------------------
1210 sub sort_feature_types {
1211 my ($feature_types) = @_;
1212  
1213 #Make sure we get the hash ref that we wanted
1214 if (ref $feature_types eq 'HASH') {
1215 my @types = keys %{$feature_types};
1216 @types = grep{scalar @{$feature_types->{$_}} > 0} @types;
1217 my $strand;
1218 for my $type (@types) {
1219 if (defined $feature_types->{$type}[0]{strand}) {
1220 $strand = $feature_types->{$type}[0]{strand};
1221 last;
1222 }
1223 }
1224 $strand = strand($strand);
1225 die "FATAL: Can't determine strand in: sort_feature_types.\n"
1226 if ! defined $strand;
1227  
1228 #If we get an hash ref with more than one element - sort it
1229 if (scalar keys %{$feature_types} > 1) {
1230 #Sort + strand features
1231 if ($strand == 1) {
1232 my @sorted_types =
1233 sort {
1234 min_feature($feature_types->{$a}, 'start') <=>
1235 min_feature($feature_types->{$b}, 'start')
1236 ||
1237 min_feature($feature_types->{$a}, 'end') <=>
1238 min_feature($feature_types->{$b}, 'end')
1239 } @types;
1240 return @sorted_types;
1241 }
1242 #Sort - strand features
1243 elsif ($strand == -1) {
1244 my @sorted_types =
1245 sort {
1246 max_feature($feature_types->{$b}, 'start') <=>
1247 max_feature($feature_types->{$a}, 'start')
1248 ||
1249 max_feature($feature_types->{$b}, 'end') <=>
1250 max_feature($feature_types->{$a}, 'end')
1251 } @types;
1252 return @sorted_types;
1253 }
1254 }
1255 #Empty or 1 length hash just return it
1256 else {
1257 return keys %{$feature_types};
1258 }
1259 }
1260 #Don't allow someone to misuse sort_features - require array ref
1261 else {
1262 die "FATAL: Hash reference required: sort_feature_types.\n";
1263 }
1264 }
1265 #-----------------------------------------------------------------------------
1266 sub strand {
1267 my $feature = shift;
1268
1269 my $strand = ref $feature ? $feature->{strand} : $feature;
1270
1271 #If strand is undefined or invalid...
1272 if (! defined $strand || $strand !~ /\+|-|1|-1/) {
1273 # ...and if we have a default value then use it...
1274 if ($DEFAULT_STRAND) {
1275 $strand = $DEFAULT_STRAND;
1276 }
1277 else {
1278 # ...otherwise allow undefined to pass through..
1279 return $strand if ! defined $strand;
1280 }
1281 }
1282
1283 if ($strand eq '+') {
1284 return 1;
1285 }
1286 elsif ($strand eq '-') {
1287 return -1;
1288 }
1289 elsif ($strand == 1 || $strand == -1) {
1290 return $strand;
1291 }
1292 # ...finally if all else fails die
1293 die "FATAL: Invalid value passed to strand: $strand.";
1294 }
1295 #-----------------------------------------------------------------------------
1296 sub min_feature {
1297 my ($features, $terminus) = @_;
1298  
1299 my $min;
1300  
1301 for my $feature (@{$features}) {
1302 $min ||= $feature->{$terminus};
1303 $min = $feature->{$terminus} if $min > $feature->{$terminus};
1304 }
1305 return $min;
1306 }
1307 #-----------------------------------------------------------------------------
1308 sub max_feature {
1309 my ($features, $terminus) = @_;
1310  
1311 my $max;
1312  
1313 for my $feature (@{$features}) {
1314 $max ||= $feature->{$terminus};
1315 $max = $feature->{$terminus} if $max < $feature->{$terminus};
1316 }
1317 return $max;
1318 }
1319 #-----------------------------------------------------------------------------
1320  
1321 =head1 NAME
1322  
1323 gtf2gff3
1324  
1325 =head1 VERSION
1326  
1327 This document describes version 0.1
1328  
1329 =head1 SYNOPSIS
1330  
1331 gtf2gff3 --cfg gtf2gff3_MY_CONFIG.cfg gtf_file > gff3_file
1332  
1333 =head1 DESCRIPTION
1334  
1335 This script will convert GTF formatted files to valid GFF3 formatted
1336 files. It will map the value in column 3 (\"type\" column) to valid
1337 SO, but because many non standard term may appear in that column in GTF
1338 files, you may edit the config file to provide your own GTF feature to
1339 SO mapping. The script will also build gene models from exons, CDSs
1340 and other features given in the GTF file. It is currently tested on
1341 Ensemble and Twinscan GTF, and it should work on any other files that
1342 follow the same specification. It does not work on GTF from the UCSC
1343 table browser because those files use the same ID for gene and
1344 transcript, so it is impossible to group multiple transcripts to a
1345 gene. See the README that came with the script for more info.
1346  
1347 =head1 OPTIONS:
1348  
1349 =over
1350  
1351 =item --cfg
1352  
1353 Provide the filename for a config file. See the configuration file
1354 provided with this script for format details. Use this configuration
1355 file to modify the behavior of the script. If no config file is given
1356 it looks for ./gtf2gff3.cfg, ~/gtf2gff3.cfg or /etc/gtf2gff3.cfg in
1357 that order.
1358  
1359 =item --help
1360  
1361 Provide a detailed man page style help message and then exit.
1362  
1363 =back
1364  
1365 =head1 DIAGNOSTICS
1366  
1367 =over
1368  
1369 =item C<< ERROR: Missing or non-standard attributes: parse_attributes >>
1370  
1371 A line in the GTF file did not have any attributes, or it's attributes column
1372 was unparsable.
1373  
1374 =item C<< ERROR: Non-transcript gene feature not supported. Please contact the author for support: build_gene >>
1375  
1376 This warning indicates that a line was skipped because it contained a
1377 non-transcript gene feature, and the code is not currently equipped to
1378 handle this type of feature. This probably isn't too hard to add, so
1379 contact me if you get this error and would like to have these features
1380 supported.
1381  
1382 =item C<< ERROR: Must have at least exons or CDSs to build a transcript: build_trnsc >>
1383  
1384 Some feature had a transcript_id and yet there were no exons or CDSs
1385 associated with that transcript_id so the script failed to build a
1386 transcript.
1387  
1388 =item C<< ERROR: seq_id conflict: validate_and_finish_trnsc >>
1389  
1390 Found two features within the same transcript that didn't share the
1391 same seq_id.
1392  
1393 =item C<< ERROR: source conflict: validate_and_finish_trnsc >>
1394  
1395 Found two features within the same transcript that didn't share the
1396 same source.
1397  
1398 =item C<< ERROR: type conflict: validate_and_finish_trnsc >>
1399  
1400 Found two features within the same transcript that were expected to
1401 share the same type and yet they didn't.
1402  
1403 =item C<< ERROR: strand conflict: validate_and_finish_trnsc >>
1404  
1405 Found two features within the same transcript that didn't share the
1406 same strand.
1407  
1408 =item C<< ERROR: seq_id conflict: validate_and_build_gene >>
1409  
1410 Found two features within the same gene that didn't share the same
1411 seq_id.
1412  
1413 =item C<< ERROR: source conflict: validate_and_build_gene >>
1414  
1415 Found two features within the same gene that didn't share the same
1416 source.
1417  
1418 =item C<< ERROR: strand conflict: validate_and_build_gene >>
1419  
1420 Found two features within the same gene that didn't share the same
1421 strand.
1422  
1423 =item C<< ERROR: gene_id conflict: validate_and_build_gene >>
1424  
1425 Found two features within the same gene that didn't share the same
1426 gene_id.
1427  
1428 =item C<< FATAL: Can't open GTF file: file_name for reading. >>
1429  
1430 Unable to open the GTF file for reading.
1431  
1432 =item C<< FATAL: Need exons or CDSs to build transcripts: process_start >>
1433  
1434 A start_codon feature was annotated and yet there were no exons or
1435 CDSs associated with that transcript_id so the script failed.
1436  
1437 =item C<< FATAL: Untested code in process_start. Contact the aurthor for support. >>
1438  
1439 The script is written to infer a start codon based on the presence of
1440 a 5' UTR, but we had no example GTF of this type when we wrote the
1441 code, so we killed process rather than run untested code. Contact the
1442 author for support.
1443  
1444 =item C<< FATAL: Invalid feature set: process_start >>
1445  
1446 We tried to consider all possible ways of infering a start codon or
1447 infering a a non-coding gene, and yet we've failed. Your combination
1448 of gene features doesn't make sense to us. You should never get
1449 this error, and if you do, we'd really like to see the GTF file that
1450 generated it. Please contact the author for support.
1451  
1452 =item C<< FATAL: Need exons or CDSs to build transcripts: process_stop >>
1453  
1454 A stop_codon feature was annotated and yet there were no exons or
1455 CDSs associated with that transcript_id so the script failed.
1456  
1457 =item C<< FATAL: Untested code in process_stop. Contact the aurthor for support. >>
1458  
1459 The script is written to infer a stop codon based on the presence of
1460 a 3' UTR, but we had no example GTF of this type when we wrote the
1461 code, so we killed process rather than run untested code. Contact the
1462 author for support.
1463  
1464 =item C<< FATAL: Invalid feature set: process_stop >>
1465  
1466 We tried to consider all possible ways of infering a stop codon or
1467 infering a a non-coding gene, and yet we've failed. Your combination
1468 of gene features doesn't make sense to us. You should never get
1469 this error, and if you do, we'd really like to see the GTF file that
1470 generated it. Please contact the author for support.
1471  
1472 =item C<< FATAL: Invalid feature set: process_exon_CDS_UTR >>
1473  
1474 We tried to consider all possible ways of infering exons, CDSs and
1475 UTRs and yet we've failed. Your combination of gene features doesn't
1476 make sense to us. You really should ever get this error, and if you
1477 do, we'd really like to see the GTF file that generated it. Please
1478 contact the author for support.
1479  
1480 =item C<< FATAL: Array reference required: sort_features. >>
1481  
1482 A user shouldn't be able to trigger this error. It almost certainly
1483 indicates a software bug. Please contact the author.
1484  
1485 =item C<< FATAL: Can't determine strand in: sort_feature_types. >>
1486  
1487 This may indicate that your GTF file does not indicate the strand for
1488 features that require it. It may also indicate a software bug.
1489 Please contact the author.
1490  
1491 =item C<< FATAL: Hash reference required: sort_feature_types. >>
1492  
1493 A user shouldn't be able to trigger this error. It almost certainly
1494 indicates a software bug. Please contact the author.
1495  
1496 =item C<< FATAL: Invalid value passed to strand: strand. >>
1497  
1498 This may indicate that your GTF file does not indicate the strand for
1499 features that require it. Consider using the DEFAULT_STRAND paramater
1500 in the config file. It may also indicate a software bug. Please
1501 contact the author.
1502  
1503 =back
1504  
1505 =head1 CONFIGURATION AND ENVIRONMENT
1506  
1507 A configuration file is provided with this script. The script will
1508 look for that configuration file in ./gtf2gff3.cfg, ~/gtf2gff3.cfg
1509 or /etc/gtf2gff3.cfg in that order. If the configuration file is not
1510 found in one of those locations and one is not provided via the --cfg
1511 flag it will try to choose some sane defaults, but you really should
1512 provide the configuration file. See the supplied configuration file
1513 itself as well as the README that came with this package for format
1514 and details about the configuration file.
1515  
1516 =head1 DEPENDENCIES
1517  
1518 This script requires the following perl packages that are available
1519 from CPAN (www.cpan.org).
1520  
1521 Getopt::Long;
1522 use Config::Std;
1523  
1524 =head1 INCOMPATIBILITIES
1525  
1526 None reported.
1527  
1528 =head1 BUGS AND LIMITATIONS
1529  
1530 No bugs have been reported.
1531  
1532 Please report any bugs or feature requests to:
1533 <barry.moore@genetics.utah.edu>
1534  
1535 =head1 AUTHOR
1536  
1537 Barry Moore
1538 <barry.moore@genetics.utah.edu>
1539  
1540 =head1 LICENCE AND COPYRIGHT
1541  
1542 Copyright (c) 2007, University of Utah
1543  
1544 This module is free software; you can redistribute it and/or
1545 modify it under the same terms as Perl itself.
1546  
1547 =head1 DISCLAIMER OF WARRANTY
1548  
1549 BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
1550 FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
1551 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
1552 PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
1553 EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
1554 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
1555 ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
1556 YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
1557 NECESSARY SERVICING, REPAIR, OR CORRECTION.
1558  
1559 IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
1560 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
1561 REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
1562 LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
1563 OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
1564 THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
1565 RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
1566 FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
1567 SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
1568 SUCH DAMAGES.
1569  
1570 =cut