0
|
1 =head1 LICENSE
|
|
2
|
|
3 Copyright (c) 1999-2012 The European Bioinformatics Institute and
|
|
4 Genome Research Limited. All rights reserved.
|
|
5
|
|
6 This software is distributed under a modified Apache license.
|
|
7 For license details, please see
|
|
8
|
|
9 http://www.ensembl.org/info/about/code_licence.html
|
|
10
|
|
11 =head1 CONTACT
|
|
12
|
|
13 Please email comments or questions to the public Ensembl
|
|
14 developers list at <dev@ensembl.org>.
|
|
15
|
|
16 Questions may also be sent to the Ensembl help desk at
|
|
17 <helpdesk@ensembl.org>.
|
|
18
|
|
19 =head1 NAME
|
|
20
|
|
21 Bio::EnsEMBL::Compara::GenomicAlignGroup - Defines groups of genomic aligned sequences
|
|
22
|
|
23 =head1 SYNOPSIS
|
|
24
|
|
25 use Bio::EnsEMBL::Compara::GenomicAlignGroup;
|
|
26
|
|
27 my $genomic_align_group = new Bio::EnsEMBL::Compara::GenomicAlignGroup (
|
|
28 -adaptor => $genomic_align_group_adaptor,
|
|
29 -genomic_align_array => [$genomic_align1, $genomic_align2...]
|
|
30 );
|
|
31
|
|
32 SET VALUES
|
|
33 $genomic_align_group->adaptor($gen_ali_group_adaptor);
|
|
34 $genomic_align_group->dbID(12);
|
|
35 $genomic_align_group->genomic_align_array([$genomic_align1, $genomic_align2]);
|
|
36
|
|
37 GET VALUES
|
|
38 my $genomic_align_group_adaptor = $genomic_align_group->adaptor();
|
|
39 my $dbID = $genomic_align_group->dbID();
|
|
40 my $genomic_aligns = $genomic_align_group->genomic_align_array();
|
|
41
|
|
42 =head1 DESCRIPTION
|
|
43
|
|
44 The GenomicAlignGroup object defines groups of alignments.
|
|
45
|
|
46 =head1 OBJECT ATTRIBUTES
|
|
47
|
|
48 =over
|
|
49
|
|
50 =item dbID
|
|
51
|
|
52 corresponds to genomic_align_group.node_id
|
|
53
|
|
54 =item adaptor
|
|
55
|
|
56 Bio::EnsEMBL::Compara::DBSQL::GenomicAlignGroupAdaptor object to access DB
|
|
57
|
|
58 =item genomic_align_array
|
|
59
|
|
60 listref of Bio::EnsEMBL::Compara::DBSQL::GenomicAlign objects corresponding to this
|
|
61 Bio::EnsEMBL::Compara::DBSQL::GenomicAlignGroup object
|
|
62
|
|
63 =back
|
|
64
|
|
65 =head1 APPENDIX
|
|
66
|
|
67 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
|
|
68
|
|
69 =cut
|
|
70
|
|
71
|
|
72 # Let the code begin...
|
|
73
|
|
74
|
|
75 package Bio::EnsEMBL::Compara::GenomicAlignGroup;
|
|
76 use strict;
|
|
77
|
|
78 # Object preamble
|
|
79 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
|
|
80 use Bio::EnsEMBL::Utils::Exception qw(throw warning);
|
|
81 use Scalar::Util qw(weaken);
|
|
82
|
|
83
|
|
84 =head2 new (CONSTRUCTOR)
|
|
85
|
|
86 Arg [-DBID] : (opt.) int $dbID (the database internal ID for this object)
|
|
87 Arg [-ADAPTOR]
|
|
88 : (opt.) Bio::EnsEMBL::Compara::DBSQL::GenomicAlignAdaptor $adaptor
|
|
89 (the adaptor for connecting to the database)
|
|
90 Arg [-GENOMIC_ALIGN_ARRAY]
|
|
91 : (opt.) array_ref $genomic_aligns (a reference to the array of
|
|
92 Bio::EnsEMBL::Compara::GenomicAlign objects corresponding to this
|
|
93 Bio::EnsEMBL::Compara::GenomicAlignGroup object)
|
|
94 Example : my $genomic_align_group =
|
|
95 new Bio::EnsEMBL::Compara::GenomicAlignGroup(
|
|
96 -adaptor => $genomic_align_group_adaptor,
|
|
97 -genomic_align_array => [$genomic_align1, $genomic_align2...]
|
|
98 );
|
|
99 Description: Creates a new GenomicAligngroup object
|
|
100 Returntype : Bio::EnsEMBL::Compara::DBSQL::GenomicAlignGroup
|
|
101 Exceptions : none
|
|
102 Caller : general
|
|
103 Status : Stable
|
|
104
|
|
105 =cut
|
|
106
|
|
107 sub new {
|
|
108 my($class, @args) = @_;
|
|
109
|
|
110 my $self = {};
|
|
111 bless $self,$class;
|
|
112
|
|
113 my ($adaptor, $dbID, $genomic_align_array) =
|
|
114 rearrange([qw(
|
|
115 ADAPTOR DBID GENOMIC_ALIGN_ARRAY)], @args);
|
|
116
|
|
117 $self->adaptor($adaptor) if (defined ($adaptor));
|
|
118 $self->dbID($dbID) if (defined ($dbID));
|
|
119 $self->genomic_align_array($genomic_align_array) if (defined($genomic_align_array));
|
|
120
|
|
121 return $self;
|
|
122 }
|
|
123
|
|
124 =head2 new_fast
|
|
125
|
|
126 Arg [1] : hash reference $hashref
|
|
127 Example : none
|
|
128 Description: This is an ultra fast constructor which requires knowledge of
|
|
129 the objects internals to be used.
|
|
130 Returntype :
|
|
131 Exceptions : none
|
|
132 Caller :
|
|
133 Status : Stable
|
|
134
|
|
135 =cut
|
|
136
|
|
137 sub new_fast {
|
|
138 my $class = shift;
|
|
139 my $hashref = shift;
|
|
140
|
|
141 return bless $hashref, $class;
|
|
142 }
|
|
143
|
|
144 =head2 copy
|
|
145
|
|
146 Arg : none
|
|
147 Example : my $new_gag = $gag->copy()
|
|
148 Description : Create a copy of this Bio::EnsEMBL::Compara::GenomicAlignGroup
|
|
149 object
|
|
150 Returntype : Bio::EnsEMBL::Compara::GenomicAlignGroup
|
|
151 Exceptions : none
|
|
152 Caller : general
|
|
153 Status : Stable
|
|
154
|
|
155 =cut
|
|
156
|
|
157 sub copy {
|
|
158 my $self = shift;
|
|
159 my $copy;
|
|
160 $copy->{original_dbID} = $self->{dbID};
|
|
161
|
|
162 #This is not a deep copy
|
|
163 #$copy->{genomic_align_array} = $self->{genomic_align_array};
|
|
164
|
|
165 my $new_genomic_align_array;
|
|
166 foreach my $genomic_align (@{$self->{genomic_align_array}}) {
|
|
167 my $new_ga = $genomic_align->copy;
|
|
168 push @$new_genomic_align_array, $new_ga;
|
|
169 }
|
|
170 $copy->{genomic_align_array} = $new_genomic_align_array;
|
|
171
|
|
172 return bless $copy, ref($self);
|
|
173 }
|
|
174
|
|
175
|
|
176 =head2 adaptor
|
|
177
|
|
178 Arg [1] : Bio::EnsEMBL::Compara::DBSQL::GenomicAlignGroupAdaptor $adaptor
|
|
179 Example : my $gen_ali_grp_adaptor = $genomic_align_block->adaptor();
|
|
180 Example : $genomic_align_block->adaptor($gen_ali_grp_adaptor);
|
|
181 Description: Getter/Setter for the adaptor this object uses for database
|
|
182 interaction.
|
|
183 Returntype : Bio::EnsEMBL::Compara::DBSQL::GenomicAlignGroupAdaptor object
|
|
184 Exceptions : thrown if $adaptor is not a
|
|
185 Bio::EnsEMBL::Compara::DBSQL::GenomicAlignGroupAdaptor object
|
|
186 Caller : general
|
|
187 Status : Stable
|
|
188
|
|
189 =cut
|
|
190
|
|
191 sub adaptor {
|
|
192 my ($self, $adaptor) = @_;
|
|
193
|
|
194 if (defined($adaptor)) {
|
|
195 throw("$adaptor is not a Bio::EnsEMBL::Compara::DBSQL::GenomicAlignGroupAdaptor object")
|
|
196 unless ($adaptor->isa("Bio::EnsEMBL::Compara::DBSQL::GenomicAlignGroupAdaptor"));
|
|
197 $self->{'adaptor'} = $adaptor;
|
|
198 }
|
|
199
|
|
200 return $self->{'adaptor'};
|
|
201 }
|
|
202
|
|
203
|
|
204 =head2 dbID
|
|
205
|
|
206 Arg [1] : integer $dbID
|
|
207 Example : my $dbID = $genomic_align_group->dbID();
|
|
208 Example : $genomic_align_group->dbID(12);
|
|
209 Description: Getter/Setter for the attribute dbID
|
|
210 Returntype : integer
|
|
211 Exceptions : none
|
|
212 Caller : general
|
|
213 Status : Stable
|
|
214
|
|
215 =cut
|
|
216
|
|
217 sub dbID {
|
|
218 my ($self, $dbID) = @_;
|
|
219
|
|
220 if (defined($dbID)) {
|
|
221 $self->{'dbID'} = $dbID;
|
|
222 }
|
|
223
|
|
224 return $self->{'dbID'};
|
|
225 }
|
|
226
|
|
227 =head2 genomic_align_array
|
|
228
|
|
229 Arg [1] : array reference containing Bio::EnsEMBL::Compara::GenomicAlign objects
|
|
230 Example : $genomic_aligns = $genomic_align_group->genomic_align_array();
|
|
231 $genomic_align_group->genomic_align_array([$genomic_align1, $genomic_align2]);
|
|
232 Description: get/set for attribute genomic_align_array
|
|
233 Returntype : array reference containing Bio::EnsEMBL::Compara::GenomicAlign objects
|
|
234 Exceptions : none
|
|
235 Caller : general
|
|
236 Status : Stable
|
|
237
|
|
238 =cut
|
|
239
|
|
240 sub genomic_align_array {
|
|
241 my ($self, $genomic_align_array) = @_;
|
|
242 my $genomic_align_adaptor;
|
|
243
|
|
244 if (defined $genomic_align_array) {
|
|
245 foreach my $genomic_align (@$genomic_align_array) {
|
|
246 throw("$genomic_align is not a Bio::EnsEMBL::Compara::GenomicAlign object") unless ($genomic_align->isa("Bio::EnsEMBL::Compara::GenomicAlign"));
|
|
247 }
|
|
248 $self->{'genomic_align_array'} = $genomic_align_array;
|
|
249 } elsif (!defined $self->{'genomic_align_array'}) {
|
|
250 # Try to get genomic_align_array from other sources
|
|
251 if (defined($self->{'adaptor'}) and defined($self->{'dbID'})) {
|
|
252 my $genomic_align_group_adaptor = $self->adaptor->db->get_GenomicAlignGroupAdaptor;
|
|
253 my $gag = $genomic_align_group_adaptor->fetch_by_dbID($self->{'dbID'});
|
|
254 $self->{'genomic_align_array'} = $gag->{'genomic_align_array'};
|
|
255 } else {
|
|
256 warning("Fail to get data from other sources in Bio::EnsEMBL::Compara::GenomicAlignGroup->genomic_align_array".
|
|
257 " You either have to specify more information (see perldoc for".
|
|
258 " Bio::EnsEMBL::Compara::GenomicAlign) or to set it up directly");
|
|
259 }
|
|
260 }
|
|
261
|
|
262 return $self->{'genomic_align_array'};
|
|
263 }
|
|
264
|
|
265 =head2 add_GenomicAlign
|
|
266
|
|
267 Arg [1] : Bio::EnsEMBL::Compara::GenomicAlign $genomic_align
|
|
268 Example : $genomic_align_block->add_GenomicAlign($genomic_align);
|
|
269 Description: adds another Bio::EnsEMBL::Compara::GenomicAlign object to the set of
|
|
270 Bio::EnsEMBL::Compara::GenomicAlign objects in the attribute
|
|
271 genomic_align_array.
|
|
272 Returntype : Bio::EnsEMBL::Compara::GenomicAlign object
|
|
273 Exceptions : thrown if wrong argument
|
|
274 Caller : general
|
|
275 Status : Stable
|
|
276
|
|
277 =cut
|
|
278
|
|
279 sub add_GenomicAlign {
|
|
280 my ($self, $genomic_align) = @_;
|
|
281
|
|
282 throw("[$genomic_align] is not a Bio::EnsEMBL::Compara::GenomicAlign object")
|
|
283 unless ($genomic_align and ref($genomic_align) and
|
|
284 $genomic_align->isa("Bio::EnsEMBL::Compara::GenomicAlign"));
|
|
285 push(@{$self->{'genomic_align_array'}}, $genomic_align);
|
|
286
|
|
287 return $genomic_align;
|
|
288 }
|
|
289
|
|
290
|
|
291 =head2 get_all_GenomicAligns
|
|
292
|
|
293 Arg [1] : none
|
|
294 Example : $genomic_aligns = $genomic_align_block->get_all_GenomicAligns();
|
|
295 Description: returns the set of Bio::EnsEMBL::Compara::GenomicAlign objects in
|
|
296 the attribute genomic_align_array.
|
|
297 Returntype : array reference containing Bio::EnsEMBL::Compara::GenomicAlign objects
|
|
298 Exceptions : none
|
|
299 Caller : general
|
|
300 Status : Stable
|
|
301
|
|
302 =cut
|
|
303
|
|
304 sub get_all_GenomicAligns {
|
|
305 my ($self) = @_;
|
|
306
|
|
307 return ($self->{'genomic_align_array'} or []);
|
|
308 }
|
|
309
|
|
310
|
|
311 =head2 genome_db
|
|
312
|
|
313 Arg [1] : -none-
|
|
314 Example : $genome_db = $object->genome_db();
|
|
315 Description : Get the genome_db object from the underlying GenomicAlign objects
|
|
316 Returntype : Bio::EnsEMBL::Compara::GenomeDB
|
|
317 Exceptions : none
|
|
318 Caller : general
|
|
319 Status : Stable
|
|
320
|
|
321 =cut
|
|
322
|
|
323 sub genome_db {
|
|
324 my $self = shift;
|
|
325
|
|
326 foreach my $genomic_align (@{$self->get_all_GenomicAligns}) {
|
|
327 return $genomic_align->genome_db if ($genomic_align->genome_db);
|
|
328 }
|
|
329 return undef;
|
|
330 }
|
|
331
|
|
332
|
|
333 =head2 dnafrag
|
|
334
|
|
335 Arg [1] : -none-
|
|
336 Example : $dnafrag = $object->dnafrag();
|
|
337 Description : Get the dnafrag object from the underlying GenomicAlign objects
|
|
338 Returntype : Bio::EnsEMBL::Compara::DnaFrag
|
|
339 Exceptions : none
|
|
340 Caller : general
|
|
341 Status : Stable
|
|
342
|
|
343 =cut
|
|
344
|
|
345 sub dnafrag {
|
|
346 my $self = shift;
|
|
347 my $dnafrag;
|
|
348 foreach my $genomic_align (@{$self->get_all_GenomicAligns}) {
|
|
349 if (!$dnafrag) {
|
|
350 $dnafrag = $genomic_align->dnafrag;
|
|
351 } elsif ($dnafrag != $genomic_align->dnafrag) {
|
|
352 return bless({name => "Composite"}, "Bio::EnsEMBL::Compara::DnaFrag");
|
|
353 }
|
|
354 }
|
|
355 return $dnafrag;
|
|
356 }
|
|
357
|
|
358
|
|
359 =head2 dnafrag_start
|
|
360
|
|
361 Arg [1] : -none-
|
|
362 Example : $dnafrag_start = $object->dnafrag_start();
|
|
363 Description : Get the dnafrag_start value from the underlying GenomicAlign objects
|
|
364 Returntype : int
|
|
365 Exceptions : none
|
|
366 Caller : general
|
|
367 Status : Stable
|
|
368
|
|
369 =cut
|
|
370
|
|
371 sub dnafrag_start {
|
|
372 my $self = shift;
|
|
373 my $dnafrag;
|
|
374 my $dnafrag_start;
|
|
375 foreach my $genomic_align (@{$self->get_all_GenomicAligns}) {
|
|
376 if (!$dnafrag) {
|
|
377 $dnafrag = $genomic_align->dnafrag;
|
|
378 $dnafrag_start = $genomic_align->dnafrag_start;
|
|
379 } elsif ($dnafrag != $genomic_align->dnafrag) {
|
|
380 return 1;
|
|
381 } elsif ($genomic_align->dnafrag_start < $dnafrag_start) {
|
|
382 $dnafrag_start = $genomic_align->dnafrag_start;
|
|
383 }
|
|
384 }
|
|
385 return $dnafrag_start;
|
|
386 }
|
|
387
|
|
388
|
|
389 =head2 dnafrag_end
|
|
390
|
|
391 Arg [1] : -none-
|
|
392 Example : $dnafrag_end = $object->dnafrag_end();
|
|
393 Description : Get the dnafrag_end value from the underlying GenomicAlign objects
|
|
394 Returntype : int
|
|
395 Exceptions : none
|
|
396 Caller : general
|
|
397 Status : Stable
|
|
398
|
|
399 =cut
|
|
400
|
|
401 sub dnafrag_end {
|
|
402 my $self = shift;
|
|
403 my $dnafrag;
|
|
404 my $dnafrag_end;
|
|
405 foreach my $genomic_align (@{$self->get_all_GenomicAligns}) {
|
|
406 if (!$dnafrag) {
|
|
407 $dnafrag = $genomic_align->dnafrag;
|
|
408 $dnafrag_end = $genomic_align->dnafrag_end;
|
|
409 } elsif ($dnafrag != $genomic_align->dnafrag) {
|
|
410 return $genomic_align->length;
|
|
411 } elsif ($genomic_align->dnafrag_end > $dnafrag_end) {
|
|
412 $dnafrag_end = $genomic_align->dnafrag_end;
|
|
413 }
|
|
414 }
|
|
415 return $dnafrag_end;
|
|
416 }
|
|
417
|
|
418
|
|
419 =head2 dnafrag_strand
|
|
420
|
|
421 Arg [1] : -none-
|
|
422 Example : $dnafrag_strand = $object->dnafrag_strand();
|
|
423 Description : Get the dnafrag_strand value from the underlying GenomicAlign objects
|
|
424 Returntype : int
|
|
425 Exceptions : none
|
|
426 Caller : general
|
|
427 Status : Stable
|
|
428
|
|
429 =cut
|
|
430
|
|
431 sub dnafrag_strand {
|
|
432 my $self = shift;
|
|
433 my $dnafrag_strand;
|
|
434 foreach my $genomic_align (@{$self->get_all_GenomicAligns}) {
|
|
435 if (!$dnafrag_strand) {
|
|
436 $dnafrag_strand = $genomic_align->dnafrag_strand;
|
|
437 } elsif ($dnafrag_strand != $genomic_align->dnafrag_strand) {
|
|
438 return 0;
|
|
439 }
|
|
440 }
|
|
441 return $dnafrag_strand;
|
|
442 }
|
|
443
|
|
444
|
|
445 =head2 aligned_sequence
|
|
446
|
|
447 Arg [1] : -none-
|
|
448 Example : $aligned_sequence = $object->aligned_sequence();
|
|
449 Description : Get the aligned sequence for this group. When the group
|
|
450 contains one single sequence, returns its aligned sequence.
|
|
451 For composite segments, returns the combined aligned seq.
|
|
452 Returntype : string
|
|
453 Exceptions : none
|
|
454 Caller : general
|
|
455 Status : At risk
|
|
456
|
|
457 =cut
|
|
458
|
|
459 sub aligned_sequence {
|
|
460 my $self = shift;
|
|
461
|
|
462 my $aligned_sequence;
|
|
463 foreach my $this_genomic_align (@{$self->get_all_GenomicAligns}) {
|
|
464 if (!$aligned_sequence) {
|
|
465 $aligned_sequence = $this_genomic_align->aligned_sequence;
|
|
466 } else {
|
|
467 my $pos = 0;
|
|
468 foreach my $substr (grep {$_} split(/(\.+)/, $this_genomic_align->aligned_sequence)) {
|
|
469 if ($substr =~ /^\.+$/) {
|
|
470 $pos += length($substr);
|
|
471 } else {
|
|
472 substr($aligned_sequence, $pos, length($substr), $substr);
|
|
473 }
|
|
474 }
|
|
475 }
|
|
476 }
|
|
477
|
|
478 return $aligned_sequence;
|
|
479 }
|
|
480
|
|
481
|
|
482
|
|
483 1;
|