3 See the NOTICE file distributed with
this work
for additional information
4 regarding copyright ownership.
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
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.
23 Please email comments or questions to the
public Ensembl
24 developers list at <http:
26 Questions may also be sent to the Ensembl help desk at
44 Module containing the subroutines fset2transcript*,
45 which create transcripts from features (formally housed in
46 Bio::EnsEMBL::DBSQL::Utils).
52 package Bio::EnsEMBL::TranscriptFactory;
61 my ($genscan,$contig)=@_;
64 unless ($genscan->isa (
"Bio::EnsEMBL::SeqFeatureI"))
65 {print
"$genscan must be Bio::EnsEMBL::SeqFeatureI\n";}
68 $transcript->temporary_id($contig->id .
"." . $genscan->seqname);
73 foreach my $f ($genscan->sub_SeqFeature) {
76 $transcript->add_Exon($exon);
77 $exon->contig ($contig);
78 $exon->
start ($f->start);
79 $exon->end ($f->end );
80 $exon->strand ($f->strand);
81 $exon->phase ($f->phase);
82 $exon->end_phase( ($exon->phase + $exon->length)%3 );
83 #$exon->score($f->score);
84 # $exon->p_value($f->p_value);
85 $exon->slice($contig->primary_seq);
93 $genscan->throw(
"Got a 0 exon genscan");
98 # This code got changed due to Translation convention changing. Should work...
101 if ($exons[0]->strand == 1) {
102 @exons = sort {$a->
start <=> $b->start} @exons;
104 @exons = sort {$b->start <=> $a->start} @exons;
107 $translation->start(1);
108 $translation->end($exons[scalar(@exons)-1]->length);
110 $translation->start_Exon($exons[0]);
111 $translation->end_Exon($exons[$#exons]);
113 my $endphase = $exons[0]->end_phase;
115 foreach my $exon (@exons) {
117 if ( $exon == $exons[0] ){
120 $exon->phase ($endphase);
121 $endphase = $exon->end_phase;
124 $transcript->translation($translation);
129 sub fset2transcript_guess_phases {
130 my ($fset,$contig) = @_;
134 $transcript->temporary_id($contig->id .
"." . $fset->id);
140 foreach my $f ($fset->sub_SeqFeature) {
143 $exon->contig ($contig);
144 $exon->
start ($f->start);
145 $exon->end ($f->end );
146 $exon->strand ($f->strand);
147 #$exon->score($f->score);
148 # $exon->p_value($f->p_value);
149 $exon->slice($contig);
150 $exon->phase($f->phase);
158 if ($exons[0]->strand == 1) {
159 @exons = sort {$a->
start <=> $b->start} @exons;
161 @exons = sort {$b->start <=> $a->start} @exons;
164 $translation->start (1);
165 $translation->end ($exons[$#exons]->end - $exons[$#exons]->start + 1);
166 $translation->start_Exon($exons[0]);
167 $translation->end_Exon($exons[$#exons]);
168 $transcript->translation($translation);
172 foreach my $exon (@exons) {
174 $exon ->phase ($endphase);
175 $transcript->add_Exon($exon);
177 $endphase = $exon->end_phase(($exon->phase + $exon->length)%3);
182 if ($transcript->translate->seq !~ /\*/) {
188 foreach my $exon (@exons) {
189 $exon->phase($endphase);
190 $endphase = $exon->end_phase(($exon->phase + $exon->length)%3);
193 if ($transcript->translate->seq !~ /\*/) {
199 foreach my $exon (@exons) {
200 $exon->phase($endphase);
201 $endphase = $exon->end_phase(($exon->phase + $exon->length)%3);
204 if ($transcript->translate->seq !~ /\*/) {
209 sub fset2transcript_3frame {
210 my ($fset,$contig) = @_;
212 my @f = $fset->sub_SeqFeature;
214 if ($f[0]->strand == 1) {
215 @f = sort {$a->start <=> $b->start} @f;
217 @f = sort {$b->start <=> $a->start} @f;
224 while ($startphase < 3) {
225 my $endphase = $startphase;
229 push(@transcripts,$transcript);
231 $transcript->temporary_id($contig->id .
"." . $endphase);
238 #print "exon seqname = ".$f->seqname."\n";
240 #print STDERR "exon ".$f->gffstring."\n";
242 $exon->seqname($f->seqname);
243 $exon->temporary_id ($contig->id .
".$count");
244 $exon->contig ($contig);
245 $exon->start ($f->start);
246 $exon->end ($f->end );
247 $exon->strand ($f->strand);
248 $exon->slice($contig);
249 $exon->phase ($endphase);
250 $exon->end_phase( ($exon->phase + $exon->length)%3 );
251 #$exon->score ($f->score);
252 # $exon->p_value ($f->p_value);
253 $endphase = $exon->end_phase;
255 $transcript->add_Exon($exon);
258 #print STDERR "Added exon start " . $exon->start . " end " . $exon->end . " strand " . $exon->strand . " score " . $exon->score . " pvalue " . $exon->p_value . "\n";
266 if (defined($contig->id)) {
267 $contig_id = $contig->id;
269 if (defined($fset->id)) {
270 $fset_id = $fset->id;
273 $translation->temporary_id($contig_id .
"." . $fset_id);
274 $translation->
start (1);
275 $translation->end ($exons[$#exons]->end - $exons[$#exons]->start + 1);
276 $translation->start_Exon($exons[0]);
277 $translation->end_Exon ($exons[$#exons]);
278 $transcript->translation($translation);
280 # print STDERR "Phase $startphase " . $transcript->translate->seq . "\n";
284 #print "finshed fset2transcript_3frame\n";
289 sub fset2transcript_with_seq {
290 my ($genscan,$seq)=@_;
293 unless ($genscan->isa (
"Bio::EnsEMBL::SeqFeatureI"))
294 {print
"$genscan must be Bio::EnsEMBL::SeqFeatureI\n";}
295 unless ($seq->isa (
"Bio::PrimarySeqI") || $seq->isa (
"Bio::SeqI"))
296 {print
"$seq must be Bio::SeqI or a Bio::PrimarySeqI\n";}
298 #print STDERR "running fset2transcript\n";
300 $transcript->temporary_id($seq->id .
"." . $genscan->seqname);
305 foreach my $f ($genscan->sub_SeqFeature) {
308 $exon->contig ($seq);
309 $exon->
start ($f->start);
310 $exon->end ($f->end );
311 $exon->strand ($f->strand);
312 $exon->phase ($f->phase);
313 $exon->end_phase( ($exon->phase + $exon->length)%3 );
314 #$exon->score ($f->score);
315 #print STDERR "contig is a = ".$seq."\n";
323 foreach my $exon (@exons) {
325 $transcript->add_Exon($exon);