EnsEMBL/Utils/VegaCuration/Translation.pm untested

filter: Statementstmt 0.0% 0 / 245 Branchbran 0.0% 0 / 110 Conditioncond 0.0% 0 / 69 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 439 CC 56 SCAR 60.7
CC
56
Cov
0%
check_for_stops
702.0
check_CDS_start_end_remarks_loutre
420.0
check_CDS_start_end_remarks
132.0
CRAP 432.7
1 =head1 LICENSE
2  
3 See the NOTICE file distributed with this work for additional information
4 regarding copyright ownership.
5  
6 Licensed under the Apache License, Version 2.0 (the "License");
7 you may not use this file except in compliance with the License.
8 You may obtain a copy of the License at
9  
10 http://www.apache.org/licenses/LICENSE-2.0
11  
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 See the License for the specific language governing permissions and
16 limitations under the License.
17  
18 =cut
19  
20 =head1 CONTACT
21 Please email comments or questions to the public Ensembl
22 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
23 Questions may also be sent to the Ensembl help desk at
24 <http://www.ensembl.org/Help/Contact>.
25  
26 =cut
27 =head1 NAME
28 =head1 SYNOPSIS
29 =head1 DESCRIPTION
30 =head1 METHODS
31 =cut
32  
33 package Bio::EnsEMBL::Utils::VegaCuration::Translation;
34 $Bio::EnsEMBL::Utils::VegaCuration::Translation::VERSION = '114.0.0_50'; # TRIAL
35 $Bio::EnsEMBL::Utils::VegaCuration::Translation::VERSION = '114.0.050';
36 use strict;
37 use warnings;
38 use vars qw(@ISA);
39 use Data::Dumper;
40 use Bio::EnsEMBL::Utils::VegaCuration::Transcript;
41 @ISA = qw(Bio::EnsEMBL::Utils::VegaCuration::Transcript);
42  
43 =head2 check_CDS_start_end_remarks
44  
45 Args : B::E::Transcript
46 Example : my $results = $support->check_CDS_end_remarks($transcript)
47 Description: identifies incorrect 'CDS end...' transcript remarks in a
48 otter-derived Vega database
49 Returntype : hashref
50  
51 =cut
52  
53 sub check_CDS_start_end_remarks {
54 my $self = shift;
55 my $trans = shift;
56 # info for checking
57 my @remarks = @{$trans->get_all_Attributes('remark')};
58 my $coding_end = $trans->cdna_coding_end;
59 my $coding_start = $trans->cdna_coding_start;
60 my $trans_end = $trans->length;
61 my $trans_seq = $trans->seq->seq;
62 my $stop_codon = substr($trans_seq, $coding_end-3, 3);
63 my $start_codon = substr($trans_seq, $coding_start-1, 3);
64 #hashref to return results
65 my $results;
66
67 #extra CDS end not found remarks
68 if (grep {$_->value eq 'CDS end not found'} @remarks) {
69 if ( ($coding_end != $trans_end)
70 && ( grep {$_ eq $stop_codon} qw(TGA TAA TAG) ) ) {
71 $results->{'END_EXTRA'} = 1;
72 }
73 }
74 #missing CDS end not found remark
75 if ( $coding_end == $trans_end ) {
76 if (! grep {$_->value eq 'CDS end not found'} @remarks) {
77 if (grep {$_ eq $stop_codon} qw(TGA TAA TAG)) {
78 $results->{'END_MISSING_2'} = 1;
79 }
80 else {
81 $results->{'END_MISSING_1'} = $stop_codon;
82 }
83 }
84 }
85 #extra CDS start not found remark
86 if (grep {$_->value eq 'CDS start not found'} @remarks) {
87 if ( ($coding_start != 1)
88 && ($start_codon eq 'ATG') ) {
89 $results->{'START_EXTRA'} = 1;
90 }
91 }
92 #missing CDS start not found remark
93 if ( $coding_start == 1) {
94 if ( ! grep {$_->value eq 'CDS start not found'} @remarks) {
95 if ($start_codon eq 'ATG') {
96 $results->{'START_MISSING_2'} = 1;
97 } else {
98 $results->{'START_MISSING_1'} = $start_codon;
99 }
100 }
101 }
102 return $results;
103 }
104  
105 =head2 check_CDS_start_end_remarks_loutre
106  
107 Args : B::E::Transcript
108 Example : my $results = $support->check_CDS_end_remarks($transcript)
109 Description: identifies incorrect 'CDS end...' transcript attribs in a loutre
110 of a loutre-derived Vega database.
111 Returntype : hashref
112  
113 =cut
114  
115 sub check_CDS_start_end_remarks_loutre {
116 my $self = shift;
117 my $trans = shift;
118  
119 # info for checking
120 my @stops = qw(TGA TAA TAG);
121 my %attributes;
122 foreach my $attribute (@{$trans->get_all_Attributes()}) {
123 push @{$attributes{$attribute->code}}, $attribute;
124 }
125 # warn $trans->stable_id;
126 # warn Data::Dumper::Dumper(\%attributes);
127 my $coding_end = $trans->cdna_coding_end;
128 my $coding_start = $trans->cdna_coding_start;
129 my $trans_end = $trans->length;
130 my $trans_seq = $trans->seq->seq;
131 my $stop_codon_offset = 3 + $trans->translation->end_Exon->end_phase;
132 my $initial_exon_phase = $trans->translation->start_Exon->phase;
133 my $stop_codon = substr($trans_seq, $coding_end-3, 3);
134 my $start_codon = substr($trans_seq, $coding_start-1, 3);
135  
136 my $start_codon_incorrect = 1;
137 if ($start_codon eq 'ATG' ) {
138 $start_codon_incorrect = 0;
139 }
140 elsif ($start_codon eq 'CTG') {
141 foreach my $attrib (@{$attributes{'remark'}}) {
142 if ($attrib->value =~ /non[- ]ATG start/) {
143 $start_codon_incorrect = 0;
144 }
145 }
146 }
147  
148 # warn "$start_codon -- $initial_exon_phase -- $coding_start -- $start_codon_incorrect";
149  
150 #hashref to return results
151 my $results;
152  
153 #extra CDS end not found remarks
154 if ($attributes{'cds_end_NF'}) {
155 if ( ($attributes{'cds_end_NF'}->[0]->value == 1)
156 && ($coding_end != $trans_end)
157 && ( grep {$_ eq $stop_codon} @stops) ) {
158 # warn $trans->stable_id.": $coding_end--$trans_end--$stop_codon";
159 # warn $trans->translation->end_Exon->end_phase;
160 $results->{'END_EXTRA'} = $stop_codon;
161 }
162 }
163 #missing CDS end not found remark
164 if ( $coding_end == $trans_end ) {
165 if ($attributes{'cds_end_NF'}) {
166 if ($attributes{'cds_end_NF'}->[0]->value == 0 ) {
167 if (! grep {$_ eq $stop_codon} @stops) {
168 # warn $trans->translation->end_Exon->end_phase;
169 $results->{'END_MISSING'}{'WRONG'} = $stop_codon;
170 }
171 }
172 }
173 elsif (! grep {$_ eq $stop_codon} @stops) {
174 $results->{'END_MISSING'}{'ABSENT'} = $stop_codon;
175 }
176 }
177 #extra CDS start not found remark
178 if ( $attributes{'cds_start_NF'}) {
179 if ( ($attributes{'cds_start_NF'}->[0]->value == 1 )
180 && (! $start_codon_incorrect)) {
181 unless ( ($coding_start == 1) && ( $initial_exon_phase > 0)) {
182 $results->{'START_EXTRA'} = $start_codon;
183 }
184 }
185 }
186 #missing CDS start not found remark
187 if ( $coding_start == 1) {
188 if ( $attributes{'cds_start_NF'} ) {
189 if ( $attributes{'cds_start_NF'}->[0]->value == 0 ) {
190 if ($start_codon_incorrect) {
191 $results->{'START_MISSING'}{'ABSENT'} = $start_codon;
192 }
193 elsif ($initial_exon_phase > 0) {
194 $results->{'START_MISSING'}{'INITIAL_PHASE'} = $initial_exon_phase;
195 }
196 }
197 }
198 elsif ($start_codon ne 'ATG') {
199 $results->{'START_MISSING'}{'ABSENT'} = $start_codon;
200 }
201  
202 }
203 return $results;
204 }
205  
206 =head2 get_havana_seleno_comments
207  
208 Args : none
209 Example : my $results = $support->get_havana_seleno_comments
210 Description: parses the HEREDOC containing Havana comments in this module
211 Returntype : hashref
212  
213 =cut
214  
215 sub get_havana_seleno_comments {
216 my $seen_translations;
217 while (<DATA>) {
218 next if /^\s+$/ or /#+/;
219 my ($obj,$comment) = split /=/;
220 $obj =~ s/^\s+|\s+$//g;
221 $comment =~ s/^\s+|\s+$//g;
222 # We add the origin as now "seen" can come from a number of places, and have
223 # a number of consequences in different cases, not just discounted Secs from this method. -- ds23
224 $seen_translations->{$obj} = [ $comment,"notsec-havana" ];
225 }
226 return $seen_translations;
227 }
228  
229 sub check_for_stops {
230 my $support = shift;
231 my ($gene,$seen_transcripts,$log_object) = @_;
232 my $transcripts;
233 my $has_log_object=defined($log_object);
234 if($has_log_object){
235 my @help = $log_object->species_params->get_trans($gene->stable_id);
236 $transcripts=\@help;
237 }else{
238 $log_object=$support;
239 $transcripts=$gene->get_all_Transcripts;
240 }
241  
242 my $gname = $gene->get_all_Attributes('name')->[0]->value;
243 my $gsi = $gene->stable_id;
244 my $scodon = 'TGA';
245 my $mod_date = $support->date_format( $gene->modified_date,'%d/%m/%y' );
246 my $hidden_remak_ttributes;
247 TRANS:
248 foreach my $trans (@$transcripts) {
249 my $tsi = $trans->stable_id;
250 my $tID = $trans->dbID;
251 my $tname = $trans->get_all_Attributes('name')->[0]->value;
252 if($has_log_object){
253 $hidden_remak_ttributes=$log_object->species_params->get_attributes->{$tsi}->{'hidden_remark'};
254 }else{
255 $hidden_remak_ttributes=$trans->get_all_Attributes('hidden_remark');
256 }
257 foreach my $rem (@$hidden_remak_ttributes) {
258 if ($rem->value =~ /not_for_Vega/) {
259 #$support->log_verbose("Skipping transcript $tname ($tsi) since 'not_for_Vega'\n",1);
260 $log_object->_save_log('log_verbose', '', $gsi, '', $tsi, '', "Skipping transcript $tname ($tsi) since 'not_for_Vega'");
261 next TRANS;
262 }
263 }
264  
265 # go no further if there is a ribosomal framshift attribute
266 foreach my $attrib (@{$trans->get_all_Attributes('_rib_frameshift')}) {
267 if ($attrib->value) {
268 $log_object->_save_log('log', '', $gsi, '', $tsi, '', "Skipping $tsi ($tname) since it has a ribosomal frameshift attribute");
269 next TRANS;
270 }
271 }
272 foreach my $attrib (@{$trans->get_all_Attributes('hidden_remark')}) {
273 if ($attrib->value eq 'ribosomal_frameshift') {
274 $log_object->_save_log('log', '', $gsi, '', $tsi, '', "Skipping $tsi ($tname) since it has a ribosomal frameshift hidden_remark");
275 next TRANS;
276 }
277 }
278  
279 #$support->log_verbose("Studying transcript $tsi ($tname, $tID)\n",1);
280 $log_object->_save_log('log_verbose', '', $gsi, '', $tsi, '', "Studying transcript $tsi ($tname, $tID)");
281 my $peptide;
282
283 # go no further if the transcript doesn't translate or if there are no stops
284 next TRANS unless ($peptide = $trans->translate);
285 my $pseq = $peptide->seq;
286 my $orig_seq = $pseq;
287 # (translate method trims stops from sequence end)
288  
289 next TRANS unless ($pseq =~ /\*/);
290 next TRANS if ($trans->biotype eq 'polymorphic_pseudogene' or
291 $trans->biotype =~ /processed_pseudogene$/);
292  
293 # warn sprintf("Stop codon is '%s'\n",substr($trans->translateable_seq,-3));
294 #$support->log_verbose("Stops found in $tsi ($tname)\n",1);
295 $log_object->_save_log('log_verbose', '', $gsi, '', $tsi, '', "Stops found in $tsi ($tname)");
296  
297 # find out where and how many stops there are
298 my @found_stops;
299 my $mrna = $trans->translateable_seq;
300 my $offset = 0;
301 my $tstop;
302 while ($pseq =~ /^([^\*]*)\*(.*)/) {
303 my $pseq1_f = $1;
304 $pseq = $2;
305 my $seq_flag = 0;
306 $offset += length($pseq1_f) * 3;
307 my $stop = substr($mrna, $offset, 3);
308 my $aaoffset = int($offset / 3)+1;
309 push(@found_stops, [ $stop, $aaoffset ]);
310 $tstop .= "$aaoffset ";
311 $offset += 3;
312 }
313
314 # are all stops TGA...?
315 my $num_stops = scalar(@found_stops);
316 my $num_tga = 0;
317 my $positions;
318 foreach my $stop (@found_stops) {
319 $positions .= $stop->[0]."(".$stop->[1].") ";
320 if ($stop->[0] eq $scodon) {
321 $num_tga++;
322 }
323 }
324 my $source = $gene->source;
325 #...no - an internal stop codon error in the database...
326 if ($num_tga < $num_stops) {
327 if ($source eq 'havana') {
328 #$support->log_warning("INTERNAL STOPS HAVANA: Transcript $tsi ($tname) from gene $gname has non \'$scodon\' stop codons [$mod_date]:\nSequence = $orig_seq\nStops at $positions)\n\n");
329 $log_object->_save_log('log_warning', '', $gsi, 'TRANSCRIPT', $tsi, 'VQCT_internal_stop', "INTERNAL STOPS HAVANA: Transcript $tsi ($tname) from gene $gname has non \'$scodon\' stop codons [$mod_date]: Sequence = $orig_seq Stops at $positions)");
330 }
331 else {
332 #$support->log_warning("INTERNAL STOPS EXTERNAL: Transcript $tsi ($tname) from gene $gname has non \'$scodon\' stop codons[$mod_date]:\nSequence = $orig_seq\nStops at $positions)\n\n");
333 $log_object->_save_log('log_warning', '', $gsi, 'TRANSCRIPT', $tsi, 'VQCT_internal_stop', "INTERNAL STOPS EXTERNAL: Transcript $tsi ($tname) from gene $gname has non \'$scodon\' stop codons[$mod_date]: Sequence = $orig_seq Stops at $positions)");
334 }
335 }
336 #...yes - check remarks
337 else {
338 my $flag_remark = 0; # 1 if word seleno has been used
339 my $flag_remark2 = 0; # 1 if existing remark has correct numbering
340 my $alabel = 'Annotation_remark- selenocysteine ';
341 my $alabel2 = 'selenocysteine ';
342 my $annot_stops;
343 my $remarks;
344 my $att;
345 #get both hidden_remarks and remarks
346 foreach my $remark_type ('remark','hidden_remark') {
347 if($has_log_object){
348 $att=$log_object->species_params->get_attributes->{$trans->stable_id}->{$remark_type};
349 }else{
350 $att=$trans->get_all_Attributes($remark_type)
351 }
352 foreach my $attrib ( @$att) {
353 push @{$remarks->{$remark_type}}, $attrib->value;
354 }
355 }
356 #parse remarks to check syntax for location of edits
357 while (my ($attrib,$remarks)= each %$remarks) {
358 foreach my $text (@{$remarks}) {
359 if ( ($attrib eq 'remark') && ($text=~/^$alabel(.*)/) ){
360 #$support->log_warning("seleno remark for $tsi stored as Annotation_remark not hidden remark) [$mod_date]\n");
361 $log_object->_save_log('log_warning', '', $gsi, '', $tsi, 'VQCT_wrong_selC_coord', "seleno remark for $tsi stored as Annotation_remark not hidden remark) [$mod_date]");
362 $annot_stops=$1;
363 }
364 elsif ($text =~ /^$alabel2(.*)/) {
365 my $maybe = $1;
366 if($maybe =~ /^\s*\d+(\s+\d+)*\s*$/) {
367 $annot_stops=$maybe;
368 } else {
369 $log_object->_save_log('log', '', $gene->stable_id, '', $tsi, '', "Maybe annotated stop in incorrect format, maybe just a remark that happens to begin '$alabel2'".
370 " -- might need to investigate: '$alabel2$maybe' [$mod_date]");
371 }
372 }
373 }
374 }
375  
376 #check the location of the annotated edits matches actual stops in the sequence
377 my @annotated_stops;
378 if ($annot_stops){
379 my $i = 0;
380 foreach my $offset (split(/\s+/, $annot_stops)) {
381 #OK if it matches a known stop
382 if (
383 defined($found_stops[$i]) && defined($found_stops[$i]->[1]) && ($found_stops[$i]->[1] == $offset)) {
384 push @annotated_stops, $offset;
385 }
386 # catch old annotations where number was in DNA not peptide coordinates
387 elsif (defined($found_stops[$i]) && defined($found_stops[$i]->[1]) && (($found_stops[$i]->[1] * 3) == $offset)) {
388 $log_object->_save_log('log_warning', '', $gene->stable_id, 'DNA', $tsi, 'VQCT_wrong_selC_coord', "DNA: Annotated stop for transcript tsi ($tname) is in DNA not peptide coordinates) [$mod_date]");
389 }
390 # catch old annotations where number off by one
391 elsif (defined($found_stops[$i]) && defined($found_stops[$i]->[1]) && (($found_stops[$i]->[1]) == $offset+1)) {
392 $log_object->_save_log('log_warning', '', $gene->stable_id, 'PEPTIDE', $tsi, 'VQCT_wrong_selC_coord', "PEPTIDE: Annotated stop for transcript $tsi ($tname) is out by one) [$mod_date]");
393 }
394 elsif (defined($offset) && ($offset=~/^\d+$/)){
395 if ($offset == length($orig_seq)+1) {
396 if($seen_transcripts->{$tsi} && $seen_transcripts->{$tsi}->[1] eq 'known-tga-stop') {
397 $log_object->_save_log('log', '', $gene->stable_id, 'TRANSCRIPT', $tsi, '', "Annotated stop for transcript $tsi ($tname) known to be a stop codon. Ok. [$mod_date]");
398 } elsif($seen_transcripts->{$tsi} && $seen_transcripts->{$tsi}->[1] eq 'known-terminal-sec') {
399 $log_object->_save_log('log', '', $gene->stable_id, 'TRANSCRIPT', $tsi, '', "Annotated stop for transcript $tsi ($tname) known to be a terminal Sec. Ok. [$mod_date]");
400 } else {
401 $log_object->_save_log('log_warning', '', $gene->stable_id, 'TRANSCRIPT', $tsi, '', "Annotated stop for transcript $tsi ($tname) \"$offset\" matches actual stop codon yet has no entry in script config to disambiguate it. Please investigate and add appropriate entry to config arrays in add_selcys.pl. [$mod_date]");
402 }
403 }
404 else {
405 $log_object->_save_log('log_warning', '', $gene->stable_id, 'TRANSCRIPT', $tsi, 'VQCT_wrong_selC_coord', "Annotated stop for transcript $tsi ($tname) \"$offset\" does not match a TGA codon) [$mod_date]");
406 push @annotated_stops, $offset;
407 }
408 }
409 $i++;
410 }
411 }
412  
413 #check location of found stops matches annotated ones - any new ones are reported
414 foreach my $stop ( @found_stops ) {
415 my $pos = $stop->[1];
416 my $seq = $stop->[0];
417 unless ( grep { $pos == $_} @annotated_stops) {
418 if ($seen_transcripts->{$tsi} && $seen_transcripts->{$tsi}->[1] eq 'notsec-havana') {
419 #$support->log_verbose("Transcript $tsi ($tname) has potential selenocysteines but has been discounted by annotators:\n\t".$seen_transcripts->{$tsi}.") [$mod_date]\n");
420 $log_object->_save_log('log_verbose', '', $gene->stable_id, '', $tsi, 'VQCT_pot_selC', "Transcript $tsi ($tname) has potential selenocysteines but has been discounted by annotators: ".$seen_transcripts->{$tsi}->[0].") [$mod_date]");
421 }
422 else {
423 #$support->log("POTENTIAL SELENO ($seq) in $tsi ($tname, gene $gname) found at $pos [$mod_date]\n");
424 $log_object->_save_log('log', '', $gene->stable_id, '', $tsi, 'VQCT_pot_selC', "POTENTIAL SELENO ($seq) in $tsi ($tname, gene $gname) found at $pos [$mod_date]");
425 }
426 }
427 }
428 }
429 }
430 }
431 sub _save_log{
432 my $self=shift;
433 my $log_type = shift;
434 my $chrom_name=shift || '';
435 my $gsi=shift || '';
436 my $type=shift || '';
437 my $tsi=shift || '';
438 my $tag=shift || '';
439 my $txt=shift || '';
440 $self->$log_type($txt."\n");
441 }
442  
443 #details of annotators comments
444 __DATA__