ensembl-hive  2.7.0
IdentityXref.pm
Go to the documentation of this file.
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 
34 
35 =head1 SYNOPSIS
36 
37  my $xref = Bio::EnsEMBL::IdentityXref->new(
38  -XREF_IDENTITY => 80.4,
39  -ENSEMBL_IDENTITY => 90.1,
40  -SCORE => 90,
41  -EVALUE => 12,
42  -CIGAR_LINE => '23MD3M2I40M',
43  -XREF_START => 1,
44  -XREF_END => 68,
45  -ENSEMBL_START => 10,
46  -ENSEMBL_END => 77,
47  -ADAPTOR => $adaptor,
48  -PRIMARY_ID => $primary_id,
49  -DBNAME => 'SwissProt'
50  );
51 
52 =head1 METHODS
53 
54 =cut
55 
56 package Bio::EnsEMBL::IdentityXref;
57 use vars qw(@ISA $AUTOLOAD);
58 use strict;
59 use Bio::EnsEMBL::Utils::Argument qw( rearrange );
60 
61 @ISA = qw( Bio::EnsEMBL::DBEntry );
62 
63 
64 =head2 new
65 
66  Arg [...] : XREF_IDENTITY ENSEMBL_IDENTITY SCORE EVALUE CIGAR_LINE
67  : XREF_START XREF_END ENSEMBL_START ENSEMBL_END
68  : ANALYSIS pairs
69  Example : see synopsis
70  Description: Create a new Bio::EnsEMBL::IdentityXref object
71  Returntype : Bio::EnsEMBL::IdentityXref
72  Exceptions : none
73  Caller : general
74  Status : Stable
75 
76 =cut
77 
78 my $error_shown = 0;
79 
80 sub new {
81  my ($class, @args) = @_;
82  my $self = $class->SUPER::new(@args);
83  my ($query_identity, $target_identity, $score, $evalue,
84  $cigar_line, $query_start, $query_end, $translation_start,
85  $translation_end, $analysis, $xref_identity, $ensembl_identity,
86  $xref_start, $xref_end, $ensembl_start, $ensembl_end) = rearrange(
87  [qw(QUERY_IDENTITY TARGET_IDENTITY SCORE EVALUE CIGAR_LINE
88  QUERY_START QUERY_END TRANSLATION_START TRANSLATION_END
89  ANALYSIS XREF_IDENTITY ENSEMBL_IDENTITY XREF_START XREF_END ENSEMBL_START ENSEMBL_END)], @args);
90 
91  if((defined($query_identity) or defined($target_identity) or defined($query_start) or defined ($query_end) or
92  defined($translation_start) or defined($translation_end)) and !$error_shown){
93  print STDERR "Arguments have now been changed to stop confusion so please replace the following\n";
94  print STDERR "\tQUERY_IDENTITY\t->\tXREF_IDENTITY\n";
95  print STDERR "\tTARGET_IDENTITY\t->\tENSEMBL_IDENTITY\n";
96  print STDERR "\tQUERY_START\t->\tXREF_START\n";
97  print STDERR "\tQUERY_END\t->\tXREF_END\n";
98  print STDERR "\tTRANSLATION_START\t->\tENSEMBL_START\n";
99  print STDERR "\tTRANSLATION_END\t->\tENSEMBL_END\n";
100  print STDERR "The old arguments will be removed in a futute release so please change your code to the new names\n";
101  $error_shown = 1;
102  }
103  $self->{'xref_identity'} = $query_identity || $xref_identity;
104  $self->{'ensembl_identity'} = $target_identity || $ensembl_identity;
105  $self->{'score'} = $score;
106  $self->{'evalue'} = $evalue;
107  $self->{'cigar_line'} = $cigar_line;
108  $self->{'xref_start'} = $query_start || $xref_start;
109  $self->{'xref_end'} = $query_end || $xref_end;
110  $self->{'ensembl_start'} = $translation_start || $ensembl_start;
111  $self->{'ensembl_end'} = $translation_end || $ensembl_end;
112  $self->{'analysis'} = $analysis;
113 
114  return $self;
115 }
116 
117 =head2 xref_identity
118 
119  Arg [1] : (optional) string $value
120  Example : $xref_identity = $id_xref->xref_identity;
121  Description: Getter/Setter for xref identity
122  Returntype : string
123  Exceptions : none
124  Caller : general
125  Status : Stable
126 
127 =cut
128 
129 sub xref_identity{
130  my $obj = shift;
131  if( @_ ) {
132  my $value = shift;
133  $obj->{'xref_identity'} = $value;
134  }
135  return $obj->{'xref_identity'};
136 
137 }
138 
139 
140 =head2 ensembl_identity
141 
142  Arg [1] : (optional) string $value
143  Example : $ensembl_identity = $id_xref->ensembl_identity;
144  Description: Getter/Setter for ensembl identity
145  Returntype : string
146  Exceptions : none
147  Caller : general
148  Status : Stable
149 
150 =cut
151 
152 sub ensembl_identity{
153  my $obj = shift;
154  if( @_ ) {
155  my $value = shift;
156  $obj->{'ensembl_identity'} = $value;
157  }
158  return $obj->{'ensembl_identity'};
159 
160 }
161 
162 
163 
164 =head2 cigar_line
165 
166  Arg [1] : string $cigar_line
167  Example : none
168  Description: get/set for attribute cigar_line
169  Returntype : string
170  Exceptions : none
171  Caller : general
172  Status : Stable
173 
174 =cut
175 
176 sub cigar_line {
177  my $self = shift;
178  $self->{'cigar_line'} = shift if( @_ );
179  return $self->{'cigar_line'};
180 }
181 
182 
183 =head2 ensembl_start
184 
185  Arg [1] : string $ensembl_start
186  Example : none
187  Description: get/set for attribute ensembl_start
188  Returntype : string
189  Exceptions : none
190  Caller : general
191  Status : Stable
192 
193 =cut
194 
195 sub ensembl_start {
196  my $self = shift;
197  $self->{'ensembl_start'} = shift if( @_ );
198  return $self->{'ensembl_start'};
199 }
200 
201 
202 =head2 ensembl_end
203 
204  Arg [1] : string $ensembl_end
205  Example : none
206  Description: get/set for attribute ensembl_end
207  Returntype : string
208  Exceptions : none
209  Caller : general
210  Status : Stable
211 
212 =cut
213 
214 sub ensembl_end {
215  my $self = shift;
216  $self->{'ensembl_end'} = shift if( @_ );
217  return $self->{'ensembl_end'};
218 }
219 
220 
221 =head2 xref_start
222 
223  Arg [1] : string $xref_start
224  Example : none
225  Description: get/set for attribute xref_start
226  Returntype : string
227  Exceptions : none
228  Caller : general
229  Status : Stable
230 
231 =cut
232 
233 sub xref_start {
234  my $self = shift;
235  $self->{'xref_start'} = shift if( @_ );
236  return $self->{'xref_start'};
237 }
238 
239 
240 =head2 xref_end
241 
242  Arg [1] : string $xref_end
243  Example : none
244  Description: get/set for attribute xref_end
245  Returntype : string
246  Exceptions : none
247  Caller : general
248  Status : Stable
249 
250 =cut
251 
252 sub xref_end {
253  my $self = shift;
254  $self->{'xref_end'} = shift if( @_ );
255  return $self->{'xref_end'};
256 }
257 
258 
259 =head2 score
260 
261  Arg [1] : string $score
262  Example : none
263  Description: get/set for attribute score
264  Returntype : string
265  Exceptions : none
266  Caller : general
267  Status : Stable
268 
269 =cut
270 
271 sub score {
272  my $self = shift;
273  $self->{'score'} = shift if( @_ );
274  return $self->{'score'};
275 }
276 
277 
278 =head2 evalue
279 
280  Arg [1] : string $evalue
281  Example : none
282  Description: get/set for attribute evalue
283  Returntype : string
284  Exceptions : none
285  Caller : general
286  Status : Stable
287 
288 =cut
289 
290 sub evalue {
291  my $self = shift;
292  $self->{'evalue'} = shift if( @_ );
293  return $self->{'evalue'};
294 }
295 
296 
297 
298 
299 =head2 get_mapper
300 
301  Args : none
302  Example : none
303  Description: produces a mapper object that takes coordinates from one side
304  of the alignment to the other side. "ensembl" and "external"
305  are the two coordinate systems contained.
306  Returntype : Bio::EnsEMBL::Mapper
307  Exceptions : none
308  Caller : general, ProteinDAS subsystem
309  Status : Stable
310 
311 =cut
312 
313 
314 sub get_mapper {
315  my ( $self ) = @_;
316  # parse the cigar_line and create a mapper ...
317  if( exists $self->{'_cached_mapper'} ) {
318  return $self->{'_cached_mapper'};
319  }
320 
321  my ( @lens, @chars );
322 
323  # if there is no cigar line, nothing is going to be loaded
324  if( $self->cigar_line() ) {
325  my @pre_lens = split( '[DMI]', $self->cigar_line() );
326  @lens = map { if( ! $_ ) { 1 } else { $_ }} @pre_lens;
327  @chars = grep { /[DMI]/ } split( //, $self->cigar_line() );
328  }
329  my $translation_start = $self->ensembl_start();
330  my $translation_end = $self->ensembl_end();
331  my $query_start = $self->xref_start();
332  my $query_end = $self->xref_end();
333 
334  # my $hit_id = $self->display_id();
335  my $ensembl_id = "ensembl_id";
336  my $external_id = "external_id";
337  # now build the mapper
338  my $mapper = Bio::EnsEMBL::Mapper->new( "external", "ensembl" );
339 
340 
341  for( my $i=0; $i<=$#lens; $i++ ) {
342  my $length = $lens[$i];
343  my $char = $chars[$i];
344  if( $char eq "M" ) {
345  $mapper->add_map_coordinates( $external_id, $query_start,
346  $query_start + $length - 1, 1,
347  $ensembl_id, $translation_start,
348  $translation_start + $length - 1);
349  $query_start += $length;
350  $translation_start += $length;
351 
352  } elsif( $char eq "D" ) {
353  $translation_start += $length;
354  } elsif( $char eq "I" ) {
355  $query_start += $length;
356  }
357  }
358 
359  $self->{'_cached_mapper'} = $mapper;
360 
361  return $mapper;
362 }
363 
364 
365 
366 =head2 transform_feature
367 
368  Arg [1] : a feature type with start and end $feature
369  This doesnt need to be a Bio::EnsEMBL::Feature as it doesnt
370  need an attached slice. We may have to introduce an appropriate
371  object type.
372  Example : my $ens_prot_feature_list =
373  $ident_xref->transform_feature( $swiss_prot_feature );
374  Description: a list of potential partial features which represent all
375  mappable places
376  of the original feature in ensembl translation coordinates.
377  Returntype : listref of whatever was put in
378  Exceptions : none
379  Caller : general, ProteinDAS subsystem
380  Status : Stable
381 
382 =cut
383 
384 
385 sub transform_feature {
386  my $self= shift;
387  my $feature = shift;
388 
389  my $fstart = $feature->start();
390  my $fend = $feature->end();
391 
392  my $mapper = $self->get_mapper();
393  my @result;
394 
395  my @coords = $mapper->map_coordinates( "external_id", $fstart, $fend,
396  1, "external" );
397 
398  for my $coord ( @coords ) {
399  if( $coord->isa( "Bio::EnsEMBL::Mapper::Coordinate" )) {
400  my $new_feature;
401  %{$new_feature} = %$feature;
402  bless $new_feature, ref( $feature );
403  $new_feature->start( $coord->start() );
404  $new_feature->end( $coord->end() );
405 
406  push( @result, $new_feature );
407  }
408  }
409 
410  return \@result;
411 }
412 
413 
414 
415 =head2 map_feature
416 
417  Arg [1] : a start,end capable feature object
418  Example : none
419  Description:
420  Returntype : list of Coordinates/Gaps which represents the mapping
421  Exceptions : none
422  Caller : another way of doing ProteinDAS
423  Status : Stable
424 
425 =cut
426 
427 sub map_feature {
428  my $self = shift;
429  my $feature = shift;
430 
431 
432  my $fstart = $feature->start();
433  my $fend = $feature->end();
434 
435  my $mapper = $self->get_mapper();
436  my @coords = $mapper->map_coordinates( "external_id", $fstart, $fend, 1,
437  "external" );
438 
439  return @coords;
440 }
441 
442 
443 1;
map
public map()
Bio::EnsEMBL::Feature
Definition: Feature.pm:47
Bio::EnsEMBL::Feature::start
public Int start()
Bio::EnsEMBL::DBEntry
Definition: DBEntry.pm:12
Bio::EnsEMBL::Utils::Argument
Definition: Argument.pm:34
Bio::EnsEMBL::IdentityXref::new
public Bio::EnsEMBL::IdentityXref new()
Bio::EnsEMBL::IdentityXref
Definition: IdentityXref.pm:23
Bio::EnsEMBL::Mapper
Definition: Coordinate.pm:3