Archive Ensembl HomeArchive Ensembl Home
MethodLinkSpeciesSet.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 NAME
00020 
00021 Bio::EnsEMBL::Compara::MethodLinkSpeciesSet -
00022 Relates every method_link with the species_set for which it has been used
00023 
00024 =head1 SYNOPSIS
00025 
00026   use Bio::EnsEMBL::Compara::MethodLinkSpeciesSet;
00027   my $method_link_species_set = new Bio::EnsEMBL::Compara::MethodLinkSpeciesSet(
00028                        -adaptor => $method_link_species_set_adaptor,
00029                        -method_link_type => "MULTIZ",
00030                        -species_set => [$gdb1, $gdb2, $gdb3],
00031                        -max_alignment_length => 10000,
00032                    );
00033 
00034 SET VALUES
00035   $method_link_species_set->dbID(12);
00036   $method_link_species_set->adaptor($meth_lnk_spcs_adaptor);
00037   $method_link_species_set->method_link_id(23);
00038   $method_link_species_set->method_link_type("MULTIZ");
00039   $method_link_species_set->species_set([$gdb1, $gdb2, $gdb3]);
00040   $method_link_species_set->max_alignment_length(10000);
00041 
00042 GET VALUES
00043   my $dbID = $method_link_species_set->dbID();
00044   my $meth_lnk_spcs_adaptor = $method_link_species_set->adaptor();
00045   my $meth_lnk_id = $method_link_species_set->method_link_id();
00046   my $meth_lnk_type = $method_link_species_set->method_link_type();
00047   my $meth_lnk_species_set = $method_link_species_set->species_set();
00048   my $max_alignment_length = $method_link_species_set->max_alignment_length();
00049 
00050 
00051 =head1 OBJECT ATTRIBUTES
00052 
00053 =over
00054 
00055 =item dbID
00056 
00057 corresponds to method_link_species_set.method_link_species_set_id
00058 
00059 =item adaptor
00060 
00061 Bio::EnsEMBL::Compara::DBSQL::MethodLinkSpeciesSetAdaptor object to access DB
00062 
00063 =item method_link_id
00064 
00065 corresponds to method_link_species_set.method_link_id (external ref. to
00066 method_link.method_link_id)
00067 
00068 =item method_link_type
00069 
00070 corresponds to method_link.type, accessed through method_link_id (external ref.)
00071 
00072 =item method_link_class
00073 
00074 corresponds to method_link.class, accessed through method_link_id (external ref.)
00075 
00076 =item species_set_id
00077 
00078 corresponds to method_link_species_set.species_set_id (external ref. to
00079 species_set.species_set_id)
00080 
00081 =item species_set
00082 
00083 listref of Bio::EnsEMBL::Compara::GenomeDB objects. Each of them corresponds to
00084 a species_set.genome_db_id
00085 
00086 =item max_alignment_length (experimental)
00087 
00088 Integer. This value is used to speed up the fetching of genomic_align_blocks.
00089 It corresponds to an entry in the meta table where the key is "max_align_$dbID"
00090 where $dbID id the method_link_species_set.method_link_species_set_id.
00091 
00092 =back
00093 
00094 =head1 APPENDIX
00095 
00096 The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _
00097 
00098 =cut
00099 
00100 
00101 
00102 package Bio::EnsEMBL::Compara::MethodLinkSpeciesSet;
00103 
00104 use strict;
00105 use base ('Bio::EnsEMBL::Compara::Taggable');
00106 
00107 # Object preamble
00108 
00109 use Bio::EnsEMBL::Utils::Exception qw(throw warning deprecate);
00110 use Bio::EnsEMBL::Utils::Argument qw(rearrange);
00111 
00112 
00113 # new() is written here 
00114 
00115 =head2 new (CONSTRUCTOR)
00116 
00117   Arg [-DBID] : (opt.) int $dbID (the database internal ID for this object)
00118   Arg [-ADAPTOR]
00119               : (opt.) Bio::EnsEMBL::Compara::DBSQL::MethodLinkSpeciesSetAdaptor $adaptor
00120                 (the adaptor for connecting to the database)
00121   Arg [-METHOD_LINK_ID]
00122               : (opt.) int $method_link_id (the database internal ID for the method_link)
00123   Arg [-METHOD_LINK_TYPE]
00124               : (opt.) string $method_link_type (the name of the method_link)
00125   Arg [-METHOD_LINK_CLASS]
00126               : (opt.) string $method_link_class (the class of the method_link)
00127   Arg [-SPECIES_SET_ID]
00128               : (opt.) int $species_set_id (the database internal ID for the species_set)
00129   Arg [-SPECIES_SET]
00130               : (opt.) arrayref $genome_dbs (a reference to an array of
00131                 Bio::EnsEMBL::Compara::GenomeDB objects)
00132   Arg [-NAME]
00133               : (opt.) string $name (the name for this method_link_species_set)
00134   Arg [-SOURCE]
00135               : (opt.) string $source (the source of these data)
00136   Arg [-URL]
00137               : (opt.) string $url (the original url of these data)
00138   Arg [-MAX_ALGINMENT_LENGTH]
00139               : (opt.) int $max_alignment_length (the length of the largest alignment
00140                 for this MethodLinkSpeciesSet (only used for genomic alignments)
00141   Example     : my $method_link_species_set =
00142                    new Bio::EnsEMBL::Compara::MethodLinkSpeciesSet(
00143                        -adaptor => $method_link_species_set_adaptor,
00144                        -method_link_type => "MULTIZ",
00145                        -species_set => [$gdb1, $gdb2, $gdb3],
00146                        -max_alignment_length => 10000,
00147                    );
00148   Description : Creates a new MethodLinkSpeciesSet object
00149   Returntype  : Bio::EnsEMBL::Compara::MethodLinkSpeciesSet object
00150   Exceptions  : none
00151   Caller      : general
00152 
00153 =cut
00154 
00155 sub new {
00156   my($class, @args) = @_;
00157   
00158   my $self = {};
00159   bless $self,$class;
00160     
00161   my ($dbID, $adaptor, $method_link_id, $method_link_type, $species_set_id, $species_set,
00162       $method_link_class, $name, $source, $url, $max_alignment_length) =
00163       rearrange([qw(
00164           DBID ADAPTOR METHOD_LINK_ID METHOD_LINK_TYPE SPECIES_SET_ID SPECIES_SET
00165           METHOD_LINK_CLASS NAME SOURCE URL MAX_ALIGNMENT_LENGTH)], @args);
00166 
00167   $self->dbID($dbID) if (defined ($dbID));
00168   $self->adaptor($adaptor) if (defined ($adaptor));
00169   $self->method_link_id($method_link_id) if (defined ($method_link_id));
00170   $self->method_link_type($method_link_type) if (defined ($method_link_type));
00171   $self->method_link_class($method_link_class) if (defined ($method_link_class));
00172   $self->species_set_id($species_set_id) if (defined ($species_set_id));
00173   $self->species_set($species_set) if (defined ($species_set));
00174   $self->name($name) if (defined ($name));
00175   $self->source($source) if (defined ($source));
00176   $self->url($url) if (defined ($url));
00177   $self->max_alignment_length($max_alignment_length) if (defined ($max_alignment_length));
00178 
00179   return $self;
00180 }
00181 
00182 
00183 sub new_fast {
00184   my $class = shift;
00185   my $hashref = shift;
00186 
00187   return bless $hashref, $class;
00188 }
00189 
00190 
00191 =head2 dbID
00192 
00193   Arg [1]    : (opt.) integer dbID
00194   Example    : my $dbID = $method_link_species_set->dbID();
00195   Example    : $method_link_species_set->dbID(12);
00196   Description: Getter/Setter for the dbID of this object in the database
00197   Returntype : integer dbID
00198   Exceptions : none
00199   Caller     : general
00200 
00201 =cut
00202 
00203 sub dbID {
00204   my $obj = shift;
00205   
00206   if (@_) {
00207     $obj->{'dbID'} = shift;
00208   }
00209   
00210   return $obj->{'dbID'};
00211 }
00212 
00213 
00214 =head2 adaptor
00215 
00216   Arg [1]    : (opt.) Bio::EnsEMBL::Compara::DBSQL::MethodLinkSpeciesSetAdaptor
00217   Example    : my $meth_lnk_spcs_adaptor = $method_link_species_set->adaptor();
00218   Example    : $method_link_species_set->adaptor($meth_lnk_spcs_adaptor);
00219   Description: Getter/Setter for the adaptor this object uses for database
00220                interaction.
00221   Returntype : Bio::EnsEMBL::Compara::DBSQL::MethodLinkSpeciesSetAdaptor
00222   Exceptions : none
00223   Caller     : general
00224 
00225 =cut
00226 
00227 sub adaptor {
00228   my $obj = shift;
00229   
00230   if (@_) {
00231     $obj->{'adaptor'} = shift;
00232   }
00233   
00234   return $obj->{'adaptor'};
00235 }
00236 
00237 
00238 =head2 method_link_id
00239  
00240   Arg [1]    : (opt.) integer method_link_id
00241   Example    : my $meth_lnk_id = $method_link_species_set->method_link_id();
00242   Example    : $method_link_species_set->method_link_id(23);
00243   Description: get/set for attribute method_link_id
00244   Returntype : integer
00245   Exceptions : none
00246   Caller     : general
00247  
00248 =cut
00249 
00250 sub method_link_id {
00251   my ($self, $arg) = @_;
00252 
00253   if (defined($arg)) {
00254     $self->{'method_link_id'} = $arg ;
00255   }
00256   
00257   if (!defined($self->{'method_link_id'})
00258       && defined($self->{'method_link_type'})
00259       && defined($self->{'adaptor'})) {
00260     $self->{'method_link_id'} = $self->adaptor->get_method_link_id_from_method_link_type($self->{'method_link_type'});
00261   }
00262 
00263   return $self->{'method_link_id'};
00264 }
00265 
00266 
00267 =head2 method_link_type
00268  
00269   Arg [1]    : (opt.) string method_link_type
00270   Example    : my $meth_lnk_type = $method_link_species_set->method_link_type();
00271   Example    : $method_link_species_set->method_link_type("BLASTZ_NET");
00272   Description: get/set for attribute method_link_type
00273   Returntype : string
00274   Exceptions : none
00275   Caller     : general
00276  
00277 =cut
00278 
00279 sub method_link_type {
00280   my ($self, $arg) = @_;
00281 
00282   if (defined($arg)) {
00283     $self->{'method_link_type'} = $arg;
00284   }
00285   
00286   if (!defined($self->{'method_link_type'})
00287       && defined($self->{'method_link_id'})
00288       && defined($self->{'adaptor'})) {
00289     $self->{'method_link_type'} = $self->adaptor->get_method_link_type_from_method_link_id($self->{'method_link_id'});
00290   }
00291 
00292   return $self->{'method_link_type'};
00293 }
00294 
00295 
00296 =head2 method_link_class
00297  
00298   Arg [1]    : (opt.) string method_link_class
00299   Example    : my $meth_lnk_class = $method_link_species_set->method_link_class();
00300   Example    : $method_link_species_set->method_link_class("GenomicAlignBlock.multiple_alignment");
00301   Description: get/set for attribute method_link_class
00302   Returntype : string
00303   Exceptions : none
00304   Caller     : general
00305  
00306 =cut
00307 
00308 sub method_link_class {
00309   my ($self, $arg) = @_;
00310 
00311   if (defined($arg)) {
00312     $self->{'method_link_class'} = $arg;
00313   }
00314   
00315   if (!defined($self->{'method_link_class'})
00316       && defined($self->{'method_link_id'})
00317       && defined($self->{'adaptor'})) {
00318     $self->{'method_link_class'} = $self->adaptor->_get_method_link_class_from_id($self->{'method_link_id'});
00319   }
00320 
00321   return $self->{'method_link_class'};
00322 }
00323 
00324 
00325 =head2 species_set_id
00326 
00327   Arg [1]    : (opt.) integer species_set_id
00328   Example    : my $species_set_id = $method_link_species_set->species_set_id();
00329   Example    : $method_link_species_set->species_set_id(23);
00330   Description: get/set for attribute species_set_id
00331   Returntype : integer
00332   Exceptions : none
00333   Caller     : general
00334 
00335 =cut
00336 
00337 sub species_set_id {
00338   my ($self, $arg) = @_;
00339 
00340   if (defined($arg)) {
00341     $self->{'species_set_id'} = $arg ;
00342   }
00343 
00344   if (!defined($self->{'species_set_id'})
00345       && defined($self->{'species_set'})
00346       && defined($self->{'adaptor'})) {
00347     $self->{'species_set_id'} = $self->adaptor->_get_species_set_id_from_species_set($self->{'species_set'});
00348   }
00349 
00350   return $self->{'species_set_id'};
00351 }
00352 
00353 
00354 =head2 species_set
00355  
00356   Arg [1]    : (opt.) listref of Bio::EnsEMBL::Compara::GenomeDB objects
00357   Example    : my $meth_lnk_species_set = $method_link_species_set->species_set();
00358   Example    : $method_link_species_set->species_set([$gdb1, $gdb2, $gdb3]);
00359   Description: get/set for attribute species_set
00360   Returntype : listref of Bio::EnsEMBL::Compara::GenomeDB objects
00361   Exceptions : Thrown if any argument is not a Bio::EnsEMBL::Compara::GenomeDB
00362                object or a GenomeDB entry appears several times
00363   Caller     : general
00364  
00365 =cut
00366 
00367 sub species_set {
00368   my ($self, $arg) = @_;
00369  
00370   if ($arg && @$arg) {
00371     ## Check content
00372     my $genome_dbs;
00373     foreach my $gdb (@$arg) {
00374       throw("undefined value used as a Bio::EnsEMBL::Compara::GenomeDB\n")
00375         if (!defined($gdb));
00376       throw("$gdb must be a Bio::EnsEMBL::Compara::GenomeDB\n")
00377         unless $gdb->isa("Bio::EnsEMBL::Compara::GenomeDB");
00378 
00379       unless (defined $genome_dbs->{$gdb->dbID}) {
00380         $genome_dbs->{$gdb->dbID} = $gdb;
00381       } else {
00382         warn("GenomeDB (".$gdb->name."; dbID=".$gdb->dbID .
00383              ") appears twice in this Bio::EnsEMBL::Compara::MethodLinkSpeciesSet\n");
00384       }
00385     }
00386     $self->{'species_set'} = [ values %{$genome_dbs} ] ;
00387   }
00388   return $self->{'species_set'};
00389 }
00390 
00391 
00392 =head2 name
00393 
00394   Arg [1]    : (opt.) string $name
00395   Example    : my $name = $method_link_species_set->name();
00396   Example    : $method_link_species_set->name("families");
00397   Description: get/set for attribute name
00398   Returntype : string
00399   Exceptions : none
00400   Caller     : general
00401 
00402 =cut
00403 
00404 sub name {
00405   my ($self, $arg) = @_;
00406 
00407   if (defined($arg)) {
00408     $self->{'name'} = $arg ;
00409   }
00410 
00411   return $self->{'name'};
00412 }
00413 
00414 
00415 =head2 source
00416 
00417   Arg [1]    : (opt.) string $name
00418   Example    : my $name = $method_link_species_set->source();
00419   Example    : $method_link_species_set->source("ensembl");
00420   Description: get/set for attribute source. The source refers to who
00421                generated the data in a first instance (ensembl, ucsc...)
00422   Returntype : string
00423   Exceptions : none
00424   Caller     : general
00425 
00426 =cut
00427 
00428 sub source {
00429   my ($self, $arg) = @_;
00430 
00431   if (defined($arg)) {
00432     $self->{'source'} = $arg ;
00433   }
00434 
00435   return $self->{'source'};
00436 }
00437 
00438 
00439 =head2 url
00440 
00441   Arg [1]    : (opt.) string $url
00442   Example    : my $name = $method_link_species_set->source();
00443   Example    : $method_link_species_set->url("http://hgdownload.cse.ucsc.edu/goldenPath/monDom1/vsHg17/");
00444   Description: get/set for attribute url. Defines where the data come from if they
00445                have been imported
00446   Returntype : string
00447   Exceptions : none
00448   Caller     : general
00449 
00450 =cut
00451 
00452 sub url {
00453   my ($self, $arg) = @_;
00454 
00455   if (defined($arg)) {
00456     $self->{'url'} = $arg ;
00457   }
00458 
00459   return $self->{'url'};
00460 }
00461 
00462 
00463 =head2 get_common_classification
00464 
00465   Arg [1]    : -none-
00466   Example    : my $common_classification = $method_link_species_set->
00467                    get_common_classification();
00468   Description: This method fetches the taxonimic classifications for all the
00469                species included in this
00470                Bio::EnsEMBL::Compara::MethodLinkSpeciesSet object and
00471                returns the common part of them.
00472   Returntype : array of strings
00473   Exceptions : 
00474   Caller     : general
00475 
00476 =cut
00477 
00478 sub get_common_classification {
00479   my ($self) = @_;
00480   my $common_classification;
00481 
00482   my $species_set = $self->species_set();
00483 
00484   foreach my $this_genome_db (@$species_set) {
00485     my @classification = split(" ", $this_genome_db->taxon->classification);
00486     if (!defined($common_classification)) {
00487       @$common_classification = @classification;
00488     } else {
00489       my $new_common_classification = [];
00490       for (my $i = 0; $i <@classification; $i++) {
00491         for (my $j = 0; $j<@$common_classification; $j++) {
00492           if ($classification[$i] eq $common_classification->[$j]) {
00493             push(@$new_common_classification, splice(@$common_classification, $j, 1));
00494             last;
00495           }
00496         }
00497       }
00498       $common_classification = $new_common_classification;
00499     }
00500   }
00501 
00502   return $common_classification;
00503 }
00504 
00505 
00506 =head2 max_alignment_length
00507  
00508   Arg [1]    : (opt.) int $max_alignment_length
00509   Example    : my $max_alignment_length = $method_link_species_set->
00510                    max_alignment_length();
00511   Example    : $method_link_species_set->max_alignment_length(1000);
00512   Description: get/set for attribute max_alignment_length
00513   Returntype : integer
00514   Exceptions : 
00515   Caller     : general
00516  
00517 =cut
00518 
00519 sub max_alignment_length {
00520   my ($self, $arg) = @_;
00521 
00522   if (defined($arg)) {
00523     $self->{'max_alignment_length'} = int($arg);
00524   } elsif (!defined($self->{'max_alignment_length'}) and defined($self->adaptor)) {
00525     $self->adaptor->get_max_alignment_length($self);
00526   }
00527 
00528   return $self->{'max_alignment_length'};
00529 }
00530 
00531 1;