EnsEMBL/TranscriptFactory.pm untested

filter: Statementstmt 0.0% 0 / 173 Branchbran 0.0% 0 / 26 Conditioncond 0.0% 0 / 3 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 214 CC 14 SCAR 30.1
CC
14
Cov
0%
fset2transcript
30.0
fset2transcript_guess_phases
30.0
fset2transcript_3frame
20.0
CRAP 20.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 Bio::EnsEMBL::TranscriptFactory - Module having the fset2transcript*
34 subroutines
35  
36 =head1 SYNOPSIS
37  
38 use Bio::EnsEMBL::TranscriptFactory;
39  
40 &Bio::EnsEMBL::TranscriptFactory::fset2transcript($fset_id);
41  
42 =head1 DESCRIPTION
43  
44 Module containing the subroutines fset2transcript*,
45 which create transcripts from features (formally housed in
46 Bio::EnsEMBL::DBSQL::Utils).
47  
48 =head1 METHODS
49  
50 =cut
51  
52 package Bio::EnsEMBL::TranscriptFactory;
53 $Bio::EnsEMBL::TranscriptFactory::VERSION = '114.0.0_50'; # TRIAL
54 $Bio::EnsEMBL::TranscriptFactory::VERSION = '114.0.050';
55 use strict;
56  
57 use Bio::EnsEMBL::Exon;
58 use Bio::EnsEMBL::Translation;
59 use Bio::EnsEMBL::Transcript;
60  
61 sub fset2transcript {
62 my ($genscan,$contig)=@_;
63  
64
65 unless ($genscan->isa ("Bio::EnsEMBL::SeqFeatureI"))
66 {print "$genscan must be Bio::EnsEMBL::SeqFeatureI\n";}
67
68 my $transcript = new Bio::EnsEMBL::Transcript;
69 $transcript->temporary_id($contig->id . "." . $genscan->seqname);
70
71 my @exons;
72 my $count= 1;
73
74 foreach my $f ($genscan->sub_SeqFeature) {
75
76 my $exon = new Bio::EnsEMBL::Exon;
77 $transcript->add_Exon($exon);
78 $exon->contig ($contig);
79 $exon->start ($f->start);
80 $exon->end ($f->end );
81 $exon->strand ($f->strand);
82 $exon->phase ($f->phase);
83 $exon->end_phase( ($exon->phase + $exon->length)%3 );
84 #$exon->score($f->score);
85 # $exon->p_value($f->p_value);
86 $exon->slice($contig->primary_seq);
87
88 push(@exons,$exon);
89 $count++;
90
91 }
92
93 if( $count == 1 ) {
94 $genscan->throw("Got a 0 exon genscan");
95 }
96  
97 my $translation = new Bio::EnsEMBL::Translation;
98 #
99 # This code got changed due to Translation convention changing. Should work...
100 #
101
102 if ($exons[0]->strand == 1) {
103 @exons = sort {$a->start <=> $b->start} @exons;
104 } else {
105 @exons = sort {$b->start <=> $a->start} @exons;
106 }
107
108 $translation->start(1);
109 $translation->end($exons[scalar(@exons)-1]->length);
110
111 $translation->start_Exon($exons[0]);
112 $translation->end_Exon($exons[$#exons]);
113  
114 my $endphase = $exons[0]->end_phase;
115
116 foreach my $exon (@exons) {
117
118 if ( $exon == $exons[0] ){
119 next;
120 }
121 $exon->phase ($endphase);
122 $endphase = $exon->end_phase;
123 }
124
125 $transcript->translation($translation);
126
127 return $transcript;
128 }
129  
130 sub fset2transcript_guess_phases {
131 my ($fset,$contig) = @_;
132  
133 my $transcript = new Bio::EnsEMBL::Transcript;
134  
135 $transcript->temporary_id($contig->id . "." . $fset->id);
136  
137  
138 my @exons;
139 my $count = 1;
140  
141 foreach my $f ($fset->sub_SeqFeature) {
142  
143 my $exon = new Bio::EnsEMBL::Exon;
144 $exon->contig ($contig);
145 $exon->start ($f->start);
146 $exon->end ($f->end );
147 $exon->strand ($f->strand);
148 #$exon->score($f->score);
149 # $exon->p_value($f->p_value);
150 $exon->slice($contig);
151 $exon->phase($f->phase);
152 push(@exons,$exon);
153 $count++;
154
155 }
156
157 my $translation = new Bio::EnsEMBL::Translation;
158
159 if ($exons[0]->strand == 1) {
160 @exons = sort {$a->start <=> $b->start} @exons;
161 } else {
162 @exons = sort {$b->start <=> $a->start} @exons;
163 }
164
165 $translation->start (1);
166 $translation->end ($exons[$#exons]->end - $exons[$#exons]->start + 1);
167 $translation->start_Exon($exons[0]);
168 $translation->end_Exon($exons[$#exons]);
169 $transcript->translation($translation);
170
171 my $endphase = 0;
172
173 foreach my $exon (@exons) {
174
175 $exon ->phase ($endphase);
176 $transcript->add_Exon($exon);
177  
178 $endphase = $exon->end_phase(($exon->phase + $exon->length)%3);
179
180 }
181  
182  
183 if ($transcript->translate->seq !~ /\*/) {
184 return $transcript;
185 }
186  
187 $endphase = 1;
188
189 foreach my $exon (@exons) {
190 $exon->phase($endphase);
191 $endphase = $exon->end_phase(($exon->phase + $exon->length)%3);
192 }
193  
194 if ($transcript->translate->seq !~ /\*/) {
195 return $transcript;
196 }
197  
198 $endphase = 2;
199
200 foreach my $exon (@exons) {
201 $exon->phase($endphase);
202 $endphase = $exon->end_phase(($exon->phase + $exon->length)%3);
203 }
204
205 if ($transcript->translate->seq !~ /\*/) {
206 return $transcript;
207 }
208 }
209  
210 sub fset2transcript_3frame {
211 my ($fset,$contig) = @_;
212  
213 my @f = $fset->sub_SeqFeature;
214
215 if ($f[0]->strand == 1) {
216 @f = sort {$a->start <=> $b->start} @f;
217 } else {
218 @f = sort {$b->start <=> $a->start} @f;
219 }
220  
221 my @transcripts;
222  
223 my $startphase = 0;
224  
225 while ($startphase < 3) {
226 my $endphase = $startphase;
227  
228 my $transcript = new Bio::EnsEMBL::Transcript;
229  
230 push(@transcripts,$transcript);
231  
232 $transcript->temporary_id($contig->id . "." . $endphase);
233  
234 my $count = 1;
235 my @exons;
236  
237
238 foreach my $f (@f) {
239 #print "exon seqname = ".$f->seqname."\n";
240 my $exon = new Bio::EnsEMBL::Exon;
241 #print STDERR "exon ".$f->gffstring."\n";
242 push(@exons,$exon);
243 $exon->seqname($f->seqname);
244 $exon->temporary_id ($contig->id . ".$count");
245 $exon->contig ($contig);
246 $exon->start ($f->start);
247 $exon->end ($f->end );
248 $exon->strand ($f->strand);
249 $exon->slice($contig);
250 $exon->phase ($endphase);
251 $exon->end_phase( ($exon->phase + $exon->length)%3 );
252 #$exon->score ($f->score);
253 # $exon->p_value ($f->p_value);
254 $endphase = $exon->end_phase;
255  
256 $transcript->add_Exon($exon);
257 $count++;
258  
259 #print STDERR "Added exon start " . $exon->start . " end " . $exon->end . " strand " . $exon->strand . " score " . $exon->score . " pvalue " . $exon->p_value . "\n";
260 }
261
262 my $translation = new Bio::EnsEMBL::Translation;
263  
264 my $contig_id = "";
265 my $fset_id = "";
266  
267 if (defined($contig->id)) {
268 $contig_id = $contig->id;
269 }
270 if (defined($fset->id)) {
271 $fset_id = $fset->id;
272 }
273  
274 $translation->temporary_id($contig_id . "." . $fset_id);
275 $translation->start (1);
276 $translation->end ($exons[$#exons]->end - $exons[$#exons]->start + 1);
277 $translation->start_Exon($exons[0]);
278 $translation->end_Exon ($exons[$#exons]);
279 $transcript->translation($translation);
280  
281 # print STDERR "Phase $startphase " . $transcript->translate->seq . "\n";
282  
283 $startphase++;
284 }
285 #print "finshed fset2transcript_3frame\n";
286 return @transcripts;
287 }
288  
289  
290 sub fset2transcript_with_seq {
291 my ($genscan,$seq)=@_;
292  
293
294 unless ($genscan->isa ("Bio::EnsEMBL::SeqFeatureI"))
295 {print "$genscan must be Bio::EnsEMBL::SeqFeatureI\n";}
296 unless ($seq->isa ("Bio::PrimarySeqI") || $seq->isa ("Bio::SeqI"))
297 {print "$seq must be Bio::SeqI or a Bio::PrimarySeqI\n";}
298  
299 #print STDERR "running fset2transcript\n";
300 my $transcript = new Bio::EnsEMBL::Transcript;
301 $transcript->temporary_id($seq->id . "." . $genscan->seqname);
302
303 my @exons;
304 my $count= 1;
305
306 foreach my $f ($genscan->sub_SeqFeature) {
307
308 my $exon = new Bio::EnsEMBL::Exon;
309 $exon->contig ($seq);
310 $exon->start ($f->start);
311 $exon->end ($f->end );
312 $exon->strand ($f->strand);
313 $exon->phase ($f->phase);
314 $exon->end_phase( ($exon->phase + $exon->length)%3 );
315 #$exon->score ($f->score);
316 #print STDERR "contig is a = ".$seq."\n";
317 $exon->slice($seq);
318
319 push(@exons,$exon);
320 $count++;
321
322 }
323  
324 foreach my $exon (@exons) {
325
326 $transcript->add_Exon($exon);
327
328
329 }
330 return $transcript;
331
332 }
333  
334  
335  
336 1;