EnsEMBL/Utils/VegaCuration/Transcript.pm untested

filter: Statementstmt 0.0% 0 / 126 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 3 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 165 CC 12 SCAR 31.9
CC
12
Cov
0%
check_remarks_and_update_names
56.0
check_names_and_overlap
20.0
find_non_overlaps
6.0
CRAP 24.2
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  
21 =head1 CONTACT
22  
23 Please email comments or questions to the public Ensembl
24 developers list at <http://lists.ensembl.org/mailman/listinfo/dev>.
25  
26 Questions may also be sent to the Ensembl help desk at
27 <http://www.ensembl.org/Help/Contact>.
28  
29 =cut
30  
31 =head1 NAME
32  
33 =head1 SYNOPSIS
34  
35 =head1 DESCRIPTION
36  
37 =head1 METHODS
38  
39 =cut
40  
41 package Bio::EnsEMBL::Utils::VegaCuration::Transcript;
42 $Bio::EnsEMBL::Utils::VegaCuration::Transcript::VERSION = '114.0.0_50'; # TRIAL
43 $Bio::EnsEMBL::Utils::VegaCuration::Transcript::VERSION = '114.0.050';
44 use strict;
45 use warnings;
46 no warnings 'uninitialized';
47 use vars qw(@ISA);
48  
49 use Bio::EnsEMBL::Utils::VegaCuration::Gene;
50 use Data::Dumper;
51  
52 @ISA = qw(Bio::EnsEMBL::Utils::VegaCuration::Gene);
53  
54  
55 =head2 find_non_overlaps
56  
57 Args : arrayref of B::E::Transcripts
58 Example : find_non_overlaps($all_transcripts)
59 Description: identifies any non-overlapping transcripts
60 Returntype : array refs of stable IDs
61 Exceptions : none
62  
63 =cut
64  
65 sub find_non_overlaps {
66 my $self = shift;
67 my ($all_transcripts) = @_;
68 my $non_overlaps = [];
69 foreach my $transcript1 (@{$all_transcripts}) {
70 foreach my $transcript2 (@{$all_transcripts}) {
71 if ($transcript1->end < $transcript2->start) {
72 push @{$non_overlaps}, $transcript1->stable_id;
73 push @{$non_overlaps}, $transcript2->stable_id;
74 }
75 }
76 }
77 return $non_overlaps;
78 }
79  
80 =head2 check_remarks_and_update_names
81  
82 Arg[1] : B::E::Gene (with potentially duplicated transcript names)
83 Arg[2] : counter 1 (no. of patched genes)
84 Arg[3] : counter 2 (no. of patched transcripts)
85 Example : $support->update_names($gene,\$c1,\$c2)
86 Description: - checks remarks and patches transcripts with identical names according to
87 CDS and length
88 Returntype : true | false (depending on whether patched or not), counter1, counter2
89  
90 =cut
91  
92 sub check_remarks_and_update_names {
93 my $self = shift;
94 my ($gene,$gene_c,$trans_c) = @_;
95 my $action = ($self->param('dry_run')) ? 'Would add' : 'Added';
96 my $aa = $gene->adaptor->db->get_AttributeAdaptor;
97 my $dbh = $gene->adaptor->db->dbc->db_handle;
98  
99 #get list of IDs that have previously been sent to annotators
100 my $seen_genes = $self->get_havana_fragmented_loci_comments;
101  
102 my $gsi = $gene->stable_id;
103 my $gid = $gene->dbID;
104 my $g_name;
105 my $study_more = 1;
106 eval {
107 $g_name = $gene->display_xref->display_id;
108 };
109 if ($@) {
110 $g_name = $gene->get_all_Attributes('name')->[0]->value;
111 }
112  
113 #get existing gene remarks
114 my $remarks = [ map {$_->value} @{$gene->get_all_Attributes('remark')} ];
115  
116 #shout if there is no remark to identify this as being fragmented
117 if ( grep {$_ eq 'fragmented locus' } @$remarks) {
118 $study_more = 0;
119 }
120 else {
121 $self->log_warning("Gene $gsi should have a fragmented locus remark\n");
122 }
123  
124 ##patch transcript names according to length and CDS
125 $gene_c++;
126  
127 #separate coding and non_coding transcripts
128 my $coding_trans = [];
129 my $noncoding_trans = [];
130 foreach my $trans ( @{$gene->get_all_Transcripts()} ) {
131 if ($trans->translate) {
132 push @$coding_trans, $trans;
133 }
134 else {
135 push @$noncoding_trans, $trans;
136 }
137 }
138  
139 #sort transcripts coding > non-coding, then on length
140 my $c = 0;
141 $self->log("\nPatching names according to CDS and length:\n",1);
142 foreach my $array_ref ($coding_trans,$noncoding_trans) {
143 foreach my $trans ( sort { $b->length <=> $a->length } @$array_ref ) {
144 $trans_c++;
145 my $tsi = $trans->stable_id;
146 my $t_name;
147 eval {
148 $t_name = $trans->display_xref->display_id;
149 };
150 if ($@) {
151 $t_name = $trans->get_all_Attributes('name')->[0]->value;
152 }
153 $c++;
154 my $ext = sprintf("%03d", $c);
155 my $new_name = $g_name.'-'.$ext;
156 $self->log(sprintf("%-20s%-3s%-20s", "$t_name ", "-->", "$new_name")."\n",1);
157 if (! $self->param('dry_run')) {
158
159 # update transcript display xref
160 $dbh->do(qq(UPDATE xref x, external_db edb
161 SET x.display_label = "$new_name"
162 WHERE x.external_db_id = edb.external_db_id
163 AND x.dbprimary_acc = "$tsi"
164 AND edb.db_name = "Vega_transcript"));
165 }
166 }
167 }
168 return ($study_more,$gene_c,$trans_c);
169 }
170  
171 =head2 check_names_and_overlap
172  
173 Arg[1] : arayref of arrayrefs of duplicated names
174 Arg[2] : B::E::Gene (with potentially duplicated transcript names)
175 Arg[3] : FH (to log new duplicates)
176 Example : $support->check_names_and_overlap($transcripts,$gene,$fh)
177 Description: checks pairs of transcripts identified as having duplicate Vega names:
178 - to see if they have identical names in loutre (shouldn't have)
179 - distinguish between overlapping and non overlapping transcripts
180 Returntype : none
181  
182 =cut
183  
184 sub check_names_and_overlap {
185 my $self = shift;
186 my ($transcript_info,$gene,$n_flist_fh) = @_;
187 my $ta = $gene->adaptor->db->get_TranscriptAdaptor;
188 my $gsi = $gene->stable_id;
189 my $g_name = $gene->get_all_Attributes('name')->[0]->value;
190 foreach my $set (values %{$transcript_info} ) {
191 next if (scalar @{$set} == 1);
192 my $transcripts = [];
193 my $all_t_names;
194 my %ids_to_names;
195 foreach my $id1 (@{$set}) {
196 my ($name1,$tsi1) = split /\|/, $id1;
197 $ids_to_names{$tsi1} = $name1;
198 $all_t_names .= "$tsi1 [$name1] ";
199 my $t = $ta->fetch_by_stable_id($tsi1);
200 push @{$transcripts}, $t;
201 }
202  
203 my $non_overlaps;
204 eval {
205 $non_overlaps = $self->find_non_overlaps($transcripts);
206 };
207 if ($@) {
208 $self->log_warning("Problem looking for overlapping transcripts for gene $gsi (is_current = 0 ?). Skipping this bit\n");
209 }
210  
211 #if the transcripts don't overlap
212 elsif (@{$non_overlaps}) {
213 my $tsi_string;
214 foreach my $id (@{$non_overlaps}) {
215 my $string = " $id [ $ids_to_names{$id} ] ";
216 $tsi_string .= $string;
217 }
218  
219 $self->log_warning("NEW: Non-overlapping: $gsi ($g_name) has non-overlapping transcripts ($tsi_string) with duplicated Vega names, and it has no \'fragmented locus\' gene remark. Neither has it been OKeyed by Havana before. Transcript names are being patched but this needs checking by Havana.\n");
220 #log gsi (to be sent to Havana)
221 print $n_flist_fh "$gsi\n";
222 }
223 #...otherwise if the transcripts do overlap
224 else {
225 $self->log_warning("NEW: Overlapping: $gsi ($g_name) has overlapping transcripts ($all_t_names) with duplicated Vega names and it has no \'fragmented locus\' gene_remark. Neither has it been OKeyed by Havana before. Transcript names are being patched but this could be checked by Havana if they were feeling keen.\n");
226 print $n_flist_fh "$gsi\n";
227 }
228 }
229 }
230  
231 =head2 get_havana_fragmented_loci_comments
232  
233 Args : none
234 Example : my $results = $support->get_havana_fragmented_loci_comments
235 Description: parses the HEREDOC containing Havana comments in this module
236 Returntype : hashref
237  
238 =cut
239  
240 sub get_havana_fragmented_loci_comments {
241 my $seen_genes;
242 while (<DATA>) {
243 next if /^\s+$/ or /#+/;
244 my ($obj,$comment) = split /=/;
245 $obj =~ s/^\s+|\s+$//g;
246 $comment =~ s/^\s+|\s+$//g;
247 $seen_genes->{$obj} = $comment;
248 }
249 return $seen_genes;
250 }
251  
252  
253  
254 #details of genes with duplicated transcript names that have already been reported to Havana
255 #identified as either fragmented or as being OK to patch
256 __DATA__