| 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 | =head1 AUTHOR | ||
| 30 | |||
| 31 | Juguang Xiao <juguang@tll.org.sg> | ||
| 32 | |||
| 33 | =cut | ||
| 34 | |||
| 35 | =head1 NAME | ||
| 36 | |||
| 37 | Bio::EnsEMBL::Utils::Converter::bio_ens_featurePair | ||
| 38 | |||
| 39 | =head1 SYNOPISIS | ||
| 40 | |||
| 41 | =head1 DESCRIPTION | ||
| 42 | |||
| 43 | =head1 METHODS | ||
| 44 | |||
| 45 | =cut | ||
| 46 | |||
| 47 | package Bio::EnsEMBL::Utils::Converter::bio_ens_featurePair; | ||
| 48 | $Bio::EnsEMBL::Utils::Converter::bio_ens_featurePair::VERSION = '114.0.0'; | ||
| 49 | use strict; | ||
| 50 | use vars qw(@ISA); | ||
| 51 | |||
| 52 | use Bio::EnsEMBL::FeaturePair; | ||
| 53 | use Bio::EnsEMBL::RepeatConsensus; | ||
| 54 | use Bio::EnsEMBL::ProteinFeature; | ||
| 55 | use Bio::EnsEMBL::Utils::Converter; | ||
| 56 | use Bio::EnsEMBL::Utils::Converter::bio_ens; | ||
| 57 | @ISA = qw(Bio::EnsEMBL::Utils::Converter::bio_ens); | ||
| 58 | |||
| 59 | sub _initialize { | ||
| 60 | my ($self, @args) = @_; | ||
| 61 | $self->SUPER::_initialize(@args); | ||
| 62 | my ($translation_id) = $self->_rearrange([qw(TRANSLATION_ID)], @args); | ||
| 63 | $self->translation_id($translation_id); | ||
| 64 | |||
| 65 | # internal converter for seqFeature | ||
| 66 | $self->{_bio_ens_seqFeature} = new Bio::EnsEMBL::Utils::Converter ( | ||
| 67 | -in => 'Bio::SeqFeature::Generic', | ||
| 68 | -out => 'Bio::EnsEMBL::SeqFeature', | ||
| 69 | ); | ||
| 70 | } | ||
| 71 | |||
| 72 | sub _convert_single { | ||
| 73 | my ($self, $pair) = @_; | ||
| 74 | unless($pair && $pair->isa('Bio::SeqFeature::FeaturePair')){ | ||
| 75 | $self->throw('a Bio::SeqFeature::FeaturePair object needed'); | ||
| 76 | } | ||
| 77 | |||
| 78 | if($self->out eq 'Bio::EnsEMBL::RepeatFeature'){ | ||
| 79 | return $self->_convert_single_to_repeatFeature($pair); | ||
| 80 | }elsif($self->out eq 'Bio::EnsEMBL::FeaturePair'){ | ||
| 81 | return $self->_convert_single_to_featurePair($pair); | ||
| 82 | }elsif($self->out eq 'Bio::EnsEMBL::ProteinFeature'){ | ||
| 83 | return $self->_convert_single_to_proteinFeature($pair); | ||
| 84 | }else{ | ||
| 85 | my $output_module = $self->out; | ||
| 86 | $self->throw("Cannot covert to [$output_module]"); | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | sub _convert_single_to_featurePair { | ||
| 91 | my ($self, $pair) = @_; | ||
| 92 | my $feature1 = $pair->feature1; | ||
| 93 | my $feature2 = $pair->feature2; | ||
| 94 | $self->{_bio_ens_seqFeature}->contig($self->contig); | ||
| 95 | $self->{_bio_ens_seqFeature}->analysis($self->analysis); | ||
| 96 | my $ens_f1 = $self->{_bio_ens_seqFeature}->_convert_single($feature1); | ||
| 97 | my $ens_f2 = $self->{_bio_ens_seqFeature}->_convert_single($feature2); | ||
| 98 | my $ens_fp = Bio::EnsEMBL::FeaturePair->new( | ||
| 99 | -feature1 => $ens_f1, | ||
| 100 | -feature2 => $ens_f2 | ||
| 101 | ); | ||
| 102 | return $ens_fp; | ||
| 103 | } | ||
| 104 | |||
| 105 | sub _convert_single_to_proteinFeature { | ||
| 106 | my ($self, $pair) = @_; | ||
| 107 | my $featurePair = $self->_convert_single_to_featurePair($pair); | ||
| 108 | my $proteinFeature = Bio::EnsEMBL::ProteinFeature->new( | ||
| 109 | -feature1 => $featurePair->feature1, | ||
| 110 | -feature2 => $featurePair->feature2 | ||
| 111 | ); | ||
| 112 | $proteinFeature->seqname($self->translation_id); | ||
| 113 | return $proteinFeature; | ||
| 114 | } | ||
| 115 | |||
| 116 | sub _convert_single_to_repeatFeature { | ||
| 117 | my ($self, $pair) = @_; | ||
| 118 | my $feature1 = $pair->feature1; | ||
| 119 | my $feature2 = $pair->feature2; | ||
| 120 | my $ens_repeatfeature = new Bio::EnsEMBL::RepeatFeature( | ||
| 121 | -seqname => $feature1->seq_id, | ||
| 122 | -start => $feature1->start, | ||
| 123 | -end => $feature1->end, | ||
| 124 | -strand => $feature1->strand, | ||
| 125 | -source_tag => $feature1->source_tag, | ||
| 126 | ); | ||
| 127 | |||
| 128 | my ($h_start, $h_end); | ||
| 129 | if($feature1->strand == 1){ | ||
| 130 | $h_start = $feature2->start; | ||
| 131 | $h_end = $feature2->end; | ||
| 132 | }elsif($feature1->strand == -1){ | ||
| 133 | $h_start = $feature2->end; | ||
| 134 | $h_end = $feature2->start; | ||
| 135 | }else{ | ||
| 136 | $self->throw("strand cannot be outside of (1, -1)"); | ||
| 137 | } | ||
| 138 | |||
| 139 | $ens_repeatfeature->hstart($h_start); | ||
| 140 | $ens_repeatfeature->hend($h_end); | ||
| 141 | my $repeat_name = $feature2->seq_id; | ||
| 142 | my $repeat_class = $feature1->primary_tag; | ||
| 143 | $repeat_class ||= $feature2->primary_tag; | ||
| 144 | $repeat_class ||= "not sure"; | ||
| 145 | my $ens_repeat_consensus = | ||
| 146 | $self->_create_consensus($repeat_name, $repeat_class); | ||
| 147 | $ens_repeatfeature->repeat_consensus($ens_repeat_consensus); | ||
| 148 | |||
| 149 | my($contig) = ref ($self->contig) eq 'ARRAY' ? @{$self->contig} : $self->contig; | ||
| 150 | |||
| 151 | $ens_repeatfeature->attach_seq($contig); | ||
| 152 | $ens_repeatfeature->analysis($self->analysis); | ||
| 153 | return $ens_repeatfeature; | ||
| 154 | } | ||
| 155 | |||
| 156 | sub _create_consensus{ | ||
| 157 | my ($self, $repeat_name, $repeat_class) = @_; | ||
| 158 | my $consensus = new Bio::EnsEMBL::RepeatConsensus; | ||
| 159 | $consensus->name($repeat_name); | ||
| 160 | $consensus->repeat_class($repeat_class); | ||
| 161 | return $consensus; | ||
| 162 | } | ||
| 163 | |||
| 164 | 1; |