WGS2NCBI/GeneFeature.pm untested

filter: Statementstmt 0.0% 0 / 89 Branchbran 0.0% 0 / 32 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 147 CC 17 SCAR 26.5
CC
17
Cov
0%
annotate_partials
42.0
annotate_short_introns
20.0
new
6.0
CRAP 14.1
1 package Bio::WGS2NCBI::GeneFeature;
2 use Bio::WGS2NCBI::StrandedFeature;
3 use Bio::WGS2NCBI::Logger;
4 use Data::Dumper;
5 use base 'Bio::WGS2NCBI::StrandedFeature';
6  
7 sub new {
8 my $class = shift;
9 my %args = @_;
10 DEBUG "need locus_tag" if not $args{'locus_tag'};
11 $class->SUPER::new( 'five_prime_UTR' => [], 'three_prime_UTR' => [], %args );
12 }
13  
14 sub db_xref {
15 my $self = shift;
16 $self->{'db_xref'} = shift if @_;
17 return $self->{'db_xref'};
18 }
19  
20 sub gene {
21 my $self = shift;
22 $self->{'gene'} = shift if @_;
23 return $self->{'gene'};
24 }
25  
26 sub product {
27 my $self = shift;
28 $self->{'product'} = shift if @_;
29 return $self->{'product'};
30 }
31  
32 sub locus_tag {
33 my $self = shift;
34 $self->{'locus_tag'} = shift if @_;
35 return $self->{'locus_tag'};
36 }
37  
38 sub note {
39 my $self = shift;
40 $self->{'note'} = shift if @_;
41 return $self->{'note'};
42 }
43  
44 sub five_prime_UTR {
45 my $self = shift;
46 push @{ $self->{'five_prime_UTR'} }, shift if @_;
47 return @{ $self->{'five_prime_UTR'} };
48 }
49  
50 sub three_prime_UTR {
51 my $self = shift;
52 push @{ $self->{'three_prime_UTR'} }, shift if @_;
53 return @{ $self->{'three_prime_UTR'} };
54 }
55  
56 sub qualifiers { qw(locus_tag gene note) }
57  
58 sub annotate_short_introns {
59 my ( $gene, $cds, $mrna, $set, $config ) = @_;
60 DEBUG "Checking for short introns in ".$gene->product;
61 if ( $cds ) {
62 my @cds_ranges = $cds->range;
63 if ( @cds_ranges > 1 ) {
64 for my $i ( 1 .. $#cds_ranges ) {
65 my $intron_length = abs($cds_ranges[$i]->[0] - $cds_ranges[$i-1]->[1]);
66 if ( $intron_length <= $config->minintron ) {
67 $set->remove($cds,$mrna);
68 $gene->note('nonfunctional due to frameshift');
69 INFO "Found $intron_length nt intron in '".$gene->product."', marked pseudo-gene";
70 return 0;
71 }
72 }
73 }
74 else {
75 DEBUG "Gene had only one exon, no intron lengths to validate in ".$gene->product;
76 }
77 $gene->note('');
78 }
79 else {
80 WARN "No CDS for ".$gene->{'type'}." ".$gene->locus_tag;
81 }
82 return 1;
83 }
84  
85 sub annotate_partials {
86 my ( $gene, $cds, $mrna, $seq ) = @_;
87 if ( $cds ) {
88 DEBUG "Finalizing gene ".$gene->product;
89
90 # the 5' and 3' untranslated regions need to have been observed
91 # in order to be sure about the gene (and, transitively, CDS and mRNA) coordinates
92 my @five_prime_UTR = $gene->five_prime_UTR;
93 my @three_prime_UTR = $gene->three_prime_UTR;
94 my ($generange) = $gene->range;
95 my @mrna_ranges = $mrna->range;
96 my @cds_ranges = $cds->range;
97 my $strand = $gene->strand;
98
99 # if no 5' UTR was seen, all we know is that the gene, CDS and mRNA may start
100 # before the coordinate we have seen. Prefix the start coordinate of the first
101 # segment as 5' partial ('<'). If there is a UTR, the mRNA needs to be extended
102 # to cover it.
103 if ( not @five_prime_UTR ) {
104 $generange->[0] = '<' . $generange->[0];
105 $mrna_ranges[0]->[0] = '<' . $mrna_ranges[0]->[0];
106 $cds_ranges[0]->[0] = '<' . $cds_ranges[0]->[0];
107 DEBUG "No 5' UTR";
108 }
109 else {
110 $mrna_ranges[0]->[0] = $five_prime_UTR[0]->[0];
111 DEBUG "Found 5' UTR";
112 }
113
114 # if no 3' UTR was seen we don't know where the gene and mRNA ended, but we
115 # do know for the CDSs (because of the stop codons) - unless there isn't one
116 if ( not @three_prime_UTR ) {
117 $generange->[1] = '>' . $generange->[1];
118 $mrna_ranges[-1]->[1] = '>' . $mrna_ranges[-1]->[1];
119
120 # parse the stop codon from the strand
121 my $stop_codon;
122 my $cds_end = $cds_ranges[-1]->[1];
123 if ( $strand eq '+' ) {
124 $stop_codon = $seq->trunc( $cds_end - 2, $cds_end )->seq;
125 }
126 else {
127 $stop_codon = $seq->trunc( $cds_end, $cds_end + 2 )->revcom->seq;
128 }
129 if ( $stop_codon !~ /^(?:TAG|TAA|TGA)$/i ) {
130 DEBUG "No stop codon ($stop_codon) on $strand in ".$gene->product;
131 $cds_ranges[-1]->[1] = '>' . $cds_ranges[-1]->[1];
132 }
133 else {
134 DEBUG "Stop codon $stop_codon on $strand in ".$gene->product;
135 }
136 }
137 else {
138 $mrna_ranges[-1]->[1] = $three_prime_UTR[-1]->[1];
139 DEBUG "Found 3' UTR";
140 }
141 }
142 else {
143 WARN "No CDS for ".$gene->{'type'}." ".$gene->locus_tag;
144 }
145 }
146  
147 1;