comparison variant_effect_predictor/Bio/EnsEMBL/Compara/DnaFrag.pm @ 0:21066c0abaf5 draft

Uploaded
author willmclaren
date Fri, 03 Aug 2012 10:04:48 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:21066c0abaf5
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::DnaFrag - Defines the DNA sequences used in the database.
22
23 =head1 SYNOPSIS
24
25 use Bio::EnsEMBL::Compara::DnaFrag;
26 my $dnafrag = new Bio::EnsEMBL::Compara::DnaFrag(
27 -dbID => 1,
28 -adaptor => $dnafrag_adaptor,
29 -length => 256,
30 -name => "19",
31 -genome_db => $genome_db,
32 -coord_system_name => "chromosome"
33 );
34
35
36 SET VALUES
37 $dnafrag->dbID(1);
38 $dnafrag->adaptor($dnafrag_adaptor);
39 $dnafrag->length(256);
40 $dnafrag->genome_db($genome_db);
41 $dnafrag->genome_db_id(123);
42 $dnafrag->coord_system_name("chromosome");
43 $dnafrag->name("19");
44
45 GET VALUES
46 $dbID = $dnafrag->dbID;
47 $dnafrag_adaptor = $dnafrag->adaptor;
48 $length = $dnafrag->length;
49 $genome_db = $dnafrag->genome_db;
50 $genome_db_id = $dnafrag->genome_db_id;
51 $coord_system_name = $dnafrag->coord_system_name;
52 $name = $dnafrag->name;
53
54 =head1 DESCRIPTION
55 The DnaFrag object stores information on the toplevel sequences such as the name, coordinate system, length and species.
56
57 =head1 OBJECT ATTRIBUTES
58
59 =over
60
61 =item dbID
62
63 corresponds to dnafrag.dnafrag_id
64
65 =item adaptor
66
67 Bio::EnsEMBL::Compara::DBSQL::DnaFragAdaptor object to access DB
68
69 =item length
70
71 corresponds to dnafrag.length
72
73 =item genome_db_id
74
75 corresponds to dnafrag.genome_db_id
76
77 =item genome_db
78
79 Bio::EnsEMBL::Compara::GenomeDB object corresponding to genome_db_id
80
81 =item coord_system_name
82
83 corresponds to dnafrag.coord_system_name
84
85 =item name
86
87 corresponds to dnafrag.name
88
89 =back
90
91 =head1 APPENDIX
92
93 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
94
95 =cut
96
97
98 # Let the code begin...
99
100
101 package Bio::EnsEMBL::Compara::DnaFrag;
102
103 use strict;
104 use Bio::EnsEMBL::Utils::Exception qw(deprecate throw);
105 use Bio::EnsEMBL::Utils::Argument;
106
107 =head2 new
108
109 Arg [-DBID] : (opt.) int $dbID (the database internal ID for this object)
110 Arg [-ADAPTOR]
111 : (opt.) Bio::EnsEMBL::Compara::DBSQL::DnaFragAdaptor $adaptor
112 (the adaptor for connecting to the database)
113 Arg [-LENGTH]:(opt.) int $length (the length of this dnafrag)
114 Arg [-NAME]: (opt.) string $name (the name of this dnafrag)
115 Arg [-GENOME_DB]
116 :(opt.) Bio::EnsEMBL::Compara::GenomeDB $genome_db (the
117 genome_db object representing the species of this dnafrag)
118 Arg [-GENOME_DB_ID]
119 :(opt.) int $genome_db_id (the database internal for the
120 genome_db)
121 Arg [-COORD_SYSTEM_NAME]
122 :(opt.) string $coord_system_name (the name of the toplevel
123 coordinate system of the dnafrag eg 'chromosome', 'scaffold')
124 Example : my $dnafrag = new Bio::EnsEMBL::Compara::DnaFrag(
125 -length 247249719,
126 -name "1",
127 -genome_db $genome_db,
128 -coord_system_name "chromosome");
129 Example : my $dnafrag = new Bio::EnsEMBL::Compara::DnaFrag(
130 -length 247249719,
131 -name "1",
132 -genome_db_id 22,
133 -coord_system_name "chromosome");
134 Description: Creates a new DnaFrag object
135 Returntype : Bio::EnsEMBL::Compara::DnaFrag
136 Exceptions : none
137 Caller : general
138 Status : Stable
139
140 =cut
141
142
143 sub new {
144 my($class,@args) = @_;
145
146 my $self = {};
147
148 bless $self,$class;
149
150 # my ($name,$contig,$genomedb,$type,$adaptor,$dbID) =
151 # rearrange([qw(NAME CONTIG GENOMEDB TYPE ADAPTOR DBID)],@args);
152 # if ( defined $contig) {
153 # $self->contig($contig);
154 # }
155
156 my ($dbID, $adaptor, $length, $name, $genome_db, $genome_db_id, $coord_system_name, $is_reference,
157 $start, $end, $genomedb, $type
158 ) =
159 rearrange([qw(DBID ADAPTOR LENGTH NAME GENOME_DB GENOME_DB_ID COORD_SYSTEM_NAME IS_REFERENCE
160 START END
161 )],@args);
162
163 $self->dbID($dbID) if (defined($dbID));
164 $self->adaptor($adaptor) if (defined($adaptor));
165 $self->length($length) if (defined($length));
166 $self->name($name) if (defined($name));
167 $self->genome_db($genome_db) if (defined($genome_db));
168 $self->genome_db_id($genome_db_id) if (defined($genome_db_id));
169 $self->coord_system_name($coord_system_name) if (defined($coord_system_name));
170 $self->is_reference($is_reference) if (defined($is_reference));
171
172 ###################################################################
173 ## Support for backwards compatibility
174 $self->start($start) if (defined($start));
175 $self->end($end) if (defined($end));
176 ##
177 ###################################################################
178
179 return $self;
180 }
181
182 =head2 new_fast
183
184 Arg [1] : hash reference $hashref
185 Example : none
186 Description: This is an ultra fast constructor which requires knowledge of
187 the objects internals to be used.
188 Returntype :
189 Exceptions : none
190 Caller :
191 Status : Stable
192
193 =cut
194
195 sub new_fast {
196 my $class = shift;
197 my $hashref = shift;
198
199 return bless $hashref, $class;
200 }
201
202 =head2 dbID
203
204 Arg [1] : int $dbID
205 Example : $dbID = $dnafrag->dbID()
206 Example : $dnafrag->dbID(1)
207 Function : get/set dbID attribute.
208 Returns : integer
209 Exeption : none
210 Caller : $object->dbID
211 Status : Stable
212
213 =cut
214
215 sub dbID {
216 my ($self, $dbID) = @_;
217
218 if (defined($dbID)) {
219 $self->{'dbID'} = $dbID;
220 }
221
222 return $self->{'dbID'};
223 }
224
225
226 =head2 adaptor
227
228 Arg [1] : Bio::EnsEMBL::Compara::DBSQL::DnaFragAdaptor $dnafrag_adaptor
229 Example : $dnafrag_adaptor = $dnafrag->adaptor()
230 Example : $dnafrag->adaptor($dnafrag_adaptor)
231 Function : get/set adaptor attribute.
232 Returns : Bio::EnsEMBL::Compara::DBSQL::DnaFragAdaptor object
233 Exeption : thrown if argument is not a Bio::EnsEMBL::Compara::DBSQL::DnaFragAdaptor
234 object
235 Caller : $object->adaptor
236 Status : Stable
237
238 =cut
239
240 sub adaptor {
241 my ($self, $adaptor) = @_;
242
243 if (defined($adaptor)) {
244 throw("[$adaptor] must be a Bio::EnsEMBL::Compara::DBSQL::DnaFragAdaptor object")
245 unless ($adaptor->isa("Bio::EnsEMBL::Compara::DBSQL::DnaFragAdaptor"));
246 $self->{'adaptor'} = $adaptor;
247 }
248
249 return $self->{'adaptor'};
250 }
251
252
253 =head2 length
254
255 Arg [1] : int $length
256 Example : $length = $dnafrag->length()
257 Example : $dnafrag->length(256)
258 Function : get/set length attribute. Use 0 as argument to reset this attribute.
259 Returns : integer
260 Exeption : none
261 Caller : $object->length
262 Status : Stable
263
264 =cut
265
266 sub length {
267 my ($self, $length) = @_;
268
269 if (defined($length)) {
270 $self->{'length'} = ($length or undef);
271 }
272
273 return $self->{'length'};
274 }
275
276
277 =head2 name
278
279 Arg [1] : string $name
280 Example : $name = $dnafrag->name()
281 Example : $dnafrag->name("19")
282 Function : get/set name attribute. Use "" as argument to reset this attribute.
283 Returns : string
284 Exeption : none
285 Caller : $object->name
286 Status : Stable
287
288 =cut
289
290 sub name {
291 my ($self, $name) = @_;
292
293 if (defined($name)) {
294 $self->{'name'} = ($name or undef);
295 }
296
297 return $self->{'name'};
298 }
299
300
301 =head2 genome_db
302
303 Arg [1] : Bio::EnsEMBL::Compara::GenomeDB $genome_db
304 Example : $genome_db = $dnafrag->genome_db()
305 Example : $dnafrag->genome_db($genome_db)
306 Function : get/set genome_db attribute. If no argument is given and the genome_db
307 is not defined, it tries to get the data from other sources like the
308 database using the genome_db_id.
309 Returns : Bio::EnsEMBL::Compara::GenomeDB object
310 Exeption : thrown if argument is not a Bio::EnsEMBL::Compara::GenomeDB
311 object
312 Caller : $object->genome_db
313 Status : Stable
314
315 =cut
316
317 sub genome_db {
318 my ($self, $genome_db) = @_;
319
320 if (defined($genome_db)) {
321 throw("[$genome_db] must be a Bio::EnsEMBL::Compara::GenomeDB object")
322 unless ($genome_db and $genome_db->isa("Bio::EnsEMBL::Compara::GenomeDB"));
323 if ($genome_db->dbID and defined($self->genome_db_id)) {
324 throw("dbID of genome_db object does not match previously defined".
325 " genome_db_id. If you want to override this".
326 " Bio::EnsEMBL::Compara::GenomeDB object, you can reset the ".
327 "genome_db_id using \$dnafrag->genome_db_id(0)")
328 unless ($genome_db->dbID == $self->genome_db_id);
329 }
330 $self->{'genome_db'} = $genome_db;
331
332 } elsif (!defined($self->{'genome_db'})) {
333 # Try to get data from other sources
334 if (defined($self->{'genome_db_id'}) and defined($self->{'adaptor'})) {
335 $self->{'genome_db'} =
336 $self->{'adaptor'}->db->get_GenomeDBAdaptor->fetch_by_dbID($self->{'genome_db_id'});
337 }
338 }
339
340 return $self->{'genome_db'};
341 }
342
343
344 =head2 genome_db_id
345
346 Arg [1] : int $genome_db_id
347 Example : $genome_db_id = $dnafrag->genome_db_id()
348 Example : $dnafrag->genome_db_id(123)
349 Function : get/set genome_db_id attribute. If no argument is given and the genome_db_id
350 is not defined, it tries to get the data from other sources like the
351 corresponding Bio::EnsEMBL::Compara::GenomeDB object. Use 0 as argument to
352 clear this attribute.
353 Returns : integer
354 Exeption : none
355 Caller : $object->genome_db_id
356 Status : Stable
357
358 =cut
359
360 sub genome_db_id {
361 my ($self, $genome_db_id) = @_;
362
363 if (defined($genome_db_id)) {
364 if (defined($self->genome_db) and $genome_db_id) {
365 if (defined($self->genome_db->dbID)) {
366 throw("genome_db_id does not match previously defined".
367 " dbID of genome_db object.")
368 unless ($genome_db_id == $self->genome_db->dbID);
369 } else {
370 $self->genome_db->dbID($genome_db_id);
371 }
372 }
373 $self->{'genome_db_id'} = ($genome_db_id or undef);
374
375 } elsif (!defined($self->{'genome_db_id'})) {
376 # Try to get data from other sources
377 if (defined($self->{'genome_db'})) {
378 # From the dbID of the corresponding Bio::EnsEMBL::Compara::GenomeDB object
379 $self->{'genome_db_id'} = $self->{'genome_db'}->dbID;
380 }
381 }
382
383 return $self->{'genome_db_id'};
384 }
385
386
387 =head2 coord_system_name
388
389 Arg [1] : string $coord_system_name
390 Example : $coord_system_name = $dnafrag->coord_system_name()
391 Example : $dnafrag->coord_system_name("chromosome")
392 Function : get/set coord_system_name attribute. Use "" or 0 as argument to
393 clear this attribute.
394 Returns : string
395 Exeption : none
396 Caller : $object->coord_system_name
397 Status : Stable
398
399 =cut
400
401 sub coord_system_name {
402 my ($self, $coord_system_name) = @_;
403
404 if (defined($coord_system_name)) {
405 $self->{'coord_system_name'} = ($coord_system_name or undef);
406 }
407
408 return $self->{'coord_system_name'};
409 }
410
411
412 =head2 is_reference
413
414 Arg [1] : bool $is_reference
415 Example : $is_reference = $dnafrag->is_reference()
416 Example : $dnafrag->is_reference(1)
417 Function : get/set is_reference attribute. The default value
418 is 1 (TRUE).
419 Returns : bool
420 Exeption : none
421 Caller : $object->is_reference
422 Status : Stable
423
424 =cut
425
426 sub is_reference {
427 my ($self, $is_reference) = @_;
428
429 if (defined($is_reference)) {
430 $self->{'is_reference'} = $is_reference;
431 }
432 if (!defined($self->{'is_reference'})) {
433 $self->{'is_reference'} = 1;
434 }
435
436 return $self->{'is_reference'};
437 }
438
439
440 =head2 slice
441
442 Arg 1 : -none-
443 Example : $slice = $dnafrag->slice;
444 Description: Returns the Bio::EnsEMBL::Slice object corresponding to this
445 Bio::EnsEMBL::Compara::DnaFrag object.
446 Returntype : Bio::EnsEMBL::Slice object
447 Exceptions : warns when the corresponding Bio::EnsEMBL::Compara::GenomeDB,
448 coord_system_name, name or Bio::EnsEMBL::DBSQL::DBAdaptor
449 cannot be retrieved and returns undef.
450 Caller : $object->methodname
451 Status : Stable
452
453 =cut
454
455 sub slice {
456 my ($self) = @_;
457
458 unless (defined $self->{'_slice'}) {
459 if (!defined($self->genome_db)) {
460 warn "Cannot get the Bio::EnsEMBL::Compara::GenomeDB object corresponding to [".$self."]";
461 return undef;
462 }
463 if (!defined($self->coord_system_name)) {
464 warn "Cannot get the coord_system_name corresponding to [".$self."]";
465 return undef;
466 }
467 if (!defined($self->name)) {
468 warn "Cannot get the name corresponding to [".$self."]";
469 return undef;
470 }
471 my $dba = $self->genome_db->db_adaptor;
472 if (!defined($dba)) {
473 warn "Cannot get the Bio::EnsEMBL::DBSQL::DBAdaptor corresponding to [".$self->genome_db->name."]";
474 return undef;
475 }
476 $dba->dbc->reconnect_when_lost(1);
477
478 $self->{'_slice'} = $dba->get_SliceAdaptor->fetch_by_region($self->coord_system_name, $self->name);
479 }
480
481 return $self->{'_slice'};
482 }
483
484
485 =head2 display_id
486
487 Args : none
488 Example : my $id = $dnafrag->display_id;
489 Description: returns string describing this chunk which can be used
490 as display_id of a Bio::Seq object or in a fasta file.
491 Uses dnafrag information in addition to start and end.
492 Returntype : string
493 Exceptions : none
494 Caller : general
495 Status : Stable
496
497 =cut
498
499 sub display_id {
500 my $self = shift;
501
502 return "" unless($self->genome_db);
503 my $id = $self->genome_db->taxon_id. ".".
504 $self->genome_db->dbID. ":".
505 $self->coord_system_name.":".
506 $self->name;
507 return $id;
508 }
509
510
511 #####################################################################
512 #####################################################################
513
514 =head1 DEPRECATED METHODS
515
516 Bio::EnsEMBL::Compara::DnaFrag::start and Bio::EnsEMBL::Compara::DnaFrag::end
517 methods are no longer used. All Bio::EnsEMBL::Compara::DnaFrag objects start
518 in 1. Start and end coordinates have been replaced by length attribute. Please,
519 use Bio::EnsEMBL::Compara::DnaFrag::length method to access it.
520
521 Bio::EnsEMBL::Compara::DnaFrag::genomedb has been renamed
522 Bio::EnsEMBL::Compara::DnaFrag::genome_db.
523
524 Bio::EnsEMBL::Compara::DnaFrag::type has been renamed
525 Bio::EnsEMBL::Compara::DnaFrag::coord_system_name.
526
527 =cut
528
529 #####################################################################
530 #####################################################################
531
532
533
534
535 =head2 start [DEPRECATED]
536
537 DEPRECATED! All Bio::EnsEMBL::Compara::DnaFrag objects start in 1
538
539 Arg [1] : int
540 Example : $dnafrag->start(1);
541 Description: Getter/Setter for the start attribute
542 Returntype : int
543 Exceptions : thrown when trying to set a starting position different from 1
544 Caller : general
545
546 =cut
547
548 sub start {
549 my ($self,$value) = @_;
550
551 deprecate("All Bio::EnsEMBL::Compara::DnaFrag objects start in 1");
552 if (defined($value) and ($value != 1)) {
553 throw("Trying to set a start value different from 1!\n".
554 "All Bio::EnsEMBL::Compara::DnaFrag objects start in 1");
555 }
556
557 return 1;
558 }
559
560
561
562 =head2 end [DEPRECATED]
563
564 DEPRECATED! Use Bio::EnsEMBL::Compara::DnaFrag->length() method instead
565
566 Arg [1] : int $end
567 Example : $dnafrag->end(42);
568 Description: Getter/Setter for the start attribute
569 Returntype : int
570 Exceptions : none
571 Caller : general
572
573 =cut
574
575 sub end {
576 my ($self, $end) = @_;
577 deprecate("Use Bio::EnsEMBL::Compara::DnaFrag->length() method instead");
578
579 return $self->length($end);
580 }
581
582
583 1;
584
585