Archive Ensembl HomeArchive Ensembl Home
bio_ens_exon.pm
Go to the documentation of this file.
00001 =head1 LICENSE
00002 
00003   Copyright (c) 1999-2012 The European Bioinformatics Institute and
00004   Genome Research Limited.  All rights reserved.
00005 
00006   This software is distributed under a modified Apache license.
00007   For license details, please see
00008 
00009     http://www.ensembl.org/info/about/code_licence.html
00010 
00011 =head1 CONTACT
00012 
00013   Please email comments or questions to the public Ensembl
00014   developers list at <dev@ensembl.org>.
00015 
00016   Questions may also be sent to the Ensembl help desk at
00017   <helpdesk@ensembl.org>.
00018 
00019 =head1 AUTHOR
00020 
00021 Juguang Xiao <juguang@tll.org.sg>
00022 
00023 =cut
00024 
00025 =head1 NAME
00026 
00027 Bio::EnsEMBL::Utils::Converter::bio_ens_exon
00028 
00029 =head1 SYNOPISIS
00030 
00031 =head1 DESCRIPTION
00032 
00033 =head1 METHODS
00034 
00035 =cut
00036 
00037 package Bio::EnsEMBL::Utils::Converter::bio_ens_exon;
00038 
00039 use strict;
00040 use vars qw(@ISA %GTF_ENS_PHASE);
00041 use Bio::EnsEMBL::Utils::Converter;
00042 use Bio::EnsEMBL::Exon;
00043 use Bio::EnsEMBL::DnaPepAlignFeature;
00044 use Bio::EnsEMBL::Utils::Converter::bio_ens;
00045 @ISA = qw(Bio::EnsEMBL::Utils::Converter::bio_ens);
00046 
00047 BEGIN {
00048     %GTF_ENS_PHASE = (
00049         0  =>  0,
00050         1  =>  2,
00051         2  =>  1,
00052        '.' => -1
00053     );
00054 }
00055 
00056 sub _initialize {
00057     my ($self, @args) = @_;
00058     $self->SUPER::_initialize(@args);
00059 
00060     $self->{_bio_ens_seqFeature} = new Bio::EnsEMBL::Utils::Converter (
00061         -in => 'Bio::SeqFeature::Generic',
00062         -out => 'Bio::EnsEMBL::SeqFeature',
00063     );
00064 
00065     $self->{_bio_ens_featurePair} = new Bio::EnsEMBL::Utils::Converter (
00066         -in => 'Bio::SeqFeature::FeaturePair',
00067         -out => 'Bio::EnsEMBL::FeaturePair'
00068     );
00069 }
00070 
00071 sub _attach_supporting_feature {
00072     my ($self, $exon, $ens_exon) = @_;
00073     unless($exon->has_tag('supporting_feature')){
00074         return;
00075     }
00076     my ($sf) = $exon->each_tag_value('supporting_feature');
00077     unless(defined $sf){
00078         $self->warn("no supporting feature is attached in exon");
00079         return;
00080     }
00081 #    $self->{_bio_ens_seqFeature}->contig($self->contig);
00082     $self->{_bio_ens_seqFeature}->analysis($self->analysis);
00083     my $ens_f1 = $self->{_bio_ens_seqFeature}->_convert_single($sf->feature1);
00084     my $ens_f2 = $self->{_bio_ens_seqFeature}->_convert_single($sf->feature2);
00085     $self->{_bio_ens_featurePair}->contig($self->contig);
00086     $self->{_bio_ens_featurePair}->analysis($self->analysis);
00087     my $ens_sf = $self->{_bio_ens_featurePair}->_convert_single($sf);
00088     my @align_feautre_args = (
00089         -feature1 => $ens_f1,
00090         -feature2 => $ens_f2,
00091         -features => [$ens_sf]
00092     );
00093     
00094     my $ens_supporting_feature = 
00095         Bio::EnsEMBL::DnaPepAlignFeature->new(@align_feautre_args);
00096     
00097     $ens_exon->add_supporting_features($ens_supporting_feature);
00098 }
00099 
00100 sub _convert_single {
00101     my ($self, $arg) = @_;
00102     unless($arg && $arg->isa('Bio::SeqFeature::Gene::Exon')){
00103         $self->throw("a Bio::SeqFeature::Gene::Exon object needed");
00104     }
00105     my $exon = $arg;
00106     my $ens_exon = Bio::EnsEMBL::Exon->new_fast(
00107         $self->contig, $exon->start, $exon->end, $exon->strand);
00108 
00109     my ($phase) = $exon->each_tag_value('phase');
00110     $ens_exon->phase($GTF_ENS_PHASE{$phase});
00111     my $ens_end_phase = 3 - ($exon->length - $phase) % 3;
00112     $ens_end_phase = 0 if $ens_end_phase == 3;
00113     $ens_exon->end_phase($ens_end_phase);
00114     if($self->contig->isa('Bio::EnsEMBL::RawContig')){
00115         $ens_exon->sticky_rank(1);
00116     }
00117     $self->_attach_supporting_feature($exon, $ens_exon);
00118     return $ens_exon;
00119 }
00120 
00121 
00122 1;