Archive Ensembl HomeArchive Ensembl Home
QtlFeatureAdaptor.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 =cut
00020 
00021 =head1 NAME
00022 
00023 Bio::EnsEMBL::Map::DBSQL::QtlFeatureAdaptor
00024 
00025 =head1 SYNOPSIS
00026 
00027 
00028 =head1 DESCRIPTION
00029 
00030 This module is responsible of retrieving QtlFeatures (and their
00031 associated Qtls) from the database.
00032 
00033 The bulk of this objects' methods are inherited from
00034 Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor
00035 
00036 =head1 METHODS
00037 
00038 =cut
00039 
00040 package Bio::EnsEMBL::Map::DBSQL::QtlFeatureAdaptor;
00041 
00042 use strict;
00043 
00044 use Bio::EnsEMBL::Map::Qtl;
00045 use Bio::EnsEMBL::Map::QtlFeature;
00046 use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
00047 
00048 use vars qw(@ISA);
00049 
00050 @ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
00051 
00052 
00053 
00054 =head2 fetch_all_by_Qtl
00055 
00056   Arg [1]    : Bio::EnsEMBL::Map::Qtl
00057   Example    : none
00058   Description: Retrieves a list of QtlFeatures for a given Qtl
00059   Returntype : listref of Bio::EnsEMBL::QtlFeatures
00060   Exceptions : none
00061   Caller     : general
00062   Status     : Stable
00063 
00064 =cut
00065 
00066 sub fetch_all_by_Qtl {
00067   my $self = shift;
00068   my $qtl = shift;
00069 
00070   my $constraint = 'q.qtl_id = ' . $qtl->dbID;
00071 
00072   return $self->generic_fetch($constraint, @_);
00073 }
00074 
00075 
00076 
00077 
00078 sub _columns {
00079   my $self = shift;
00080 
00081   return ( 'qf.seq_region_id', 'qf.seq_region_start', 'qf.seq_region_end',
00082            'q.qtl_id',
00083            'qf.analysis_id',
00084            'qs.source_database', 'qs.source_primary_id',
00085            'q.trait', 'q.lod_score', 'q.flank_marker_id_1',
00086            'q.flank_marker_id_2', 'q.peak_marker_id' );
00087 }
00088 
00089 sub _tables {
00090   my $self = shift;
00091 
00092   return (['qtl_feature', 'qf'], #primary table
00093             ['qtl', 'q'],
00094           ['qtl_synonym', 'qs']);
00095 }
00096 
00097 sub _left_join {
00098   return ( [ 'qtl_synonym', 'q.qtl_id = qs.qtl_id' ] );
00099 }
00100 
00101 sub _default_where_clause {
00102   my $self = shift;
00103 
00104   return ('qf.qtl_id = q.qtl_id');
00105 }
00106 
00107 
00108 sub _objs_from_sth {
00109   my $self = shift;
00110   my $sth  = shift;
00111 
00112   my ( $seq_region_id, $seq_region_start, $seq_region_end, $qtl_id,
00113        $analysis_id, $source_database,
00114        $source_primary_id, $trait, $lod_score, $flank_marker_id_1,
00115        $flank_marker_id_2, $peak_marker_id );
00116 
00117   #warning: ordering depends on _columns function implementation
00118   $sth->bind_columns( \$seq_region_id, \$seq_region_start, \$seq_region_end, 
00119                       \$qtl_id, \$analysis_id,
00120                       \$source_database, \$source_primary_id, \$trait,
00121                       \$lod_score, \$flank_marker_id_1,
00122                       \$flank_marker_id_2, \$peak_marker_id );
00123 
00124   my @out = ();
00125   my %already_seen;
00126 
00127   my $mad = $self->db()->get_MarkerAdaptor();
00128   my $aad = $self->db()->get_AnalysisAdaptor();
00129   my $sad = $self->db()->get_SliceAdaptor();
00130 
00131   while( $sth->fetch()) {
00132 
00133     my $flank_marker_1 = $flank_marker_id_1 ?
00134                          $mad->fetch_by_dbID( $flank_marker_id_1 ) :
00135                          undef;
00136     my $flank_marker_2 = $flank_marker_id_2 ?
00137                          $mad->fetch_by_dbID( $flank_marker_id_2 ) :
00138                          undef;
00139     my $peak_marker = $peak_marker_id ?
00140                       $mad->fetch_by_dbID( $peak_marker_id ) :
00141                       undef;
00142 
00143     my $analysis = $aad->fetch_by_dbID( $analysis_id );
00144 
00145     my $slice = $sad->fetch_by_seq_region_id($seq_region_id);
00146 
00147     #rows with the same qtl contain additional synonyms of the qtl
00148     if(my $qtl = $already_seen{$qtl_id}) {
00149       $qtl->add_synonym($source_database, $source_primary_id);
00150       next;
00151     }
00152 
00153     my $qtl = Bio::EnsEMBL::Map::Qtl->new
00154       (
00155        $qtl_id,
00156        $self->db->get_QtlAdaptor(),
00157        $flank_marker_1,
00158        $peak_marker,
00159        $flank_marker_2,
00160        $trait, 
00161        $lod_score,
00162        {$source_database => $source_primary_id}
00163       );
00164 
00165     $already_seen{$qtl_id} = $qtl;
00166 
00167     #now create a new marker_feature using the marker
00168     push @out, Bio::EnsEMBL::Map::QtlFeature->new
00169       ($self,
00170        $slice,
00171        $seq_region_start,
00172        $seq_region_end,
00173        $qtl,
00174        $analysis);
00175   }
00176 
00177   return \@out;
00178 }
00179 
00180 
00181 1;