This module is responsible of retrieving QTLs from the database.
sub _columns
{ return ( 'q.qtl_id','qs.source_database','qs.source_primary_id',
'q.trait','q.lod_score','q.flank_marker_id_1',
'q.flank_marker_id_2','q.peak_marker_id' ); } |
sub _generic_fetch
{ my $self = shift;
my $conditions = shift;
my $where = '';
if( @$conditions ) {
$where = "WHERE ".join( " and ", @$conditions );
}
my $query = "SELECT ".
join( ", ", $self->_columns() ).
" FROM qtl q LEFT JOIN qtl_synonym qs ON q.qtl_id = qs.qtl_id ".
$where;
my $sth = $self->prepare( $query );
$sth->execute();
return $self->_obj_from_sth( $sth ); } |
sub _obj_from_sth
{ my $self = shift;
my $sth = shift;
my ( $qtl_id, $source_database,
$source_primary_id, $trait, $lod_score, $flank_marker_id_1,
$flank_marker_id_2, $peak_marker_id );
$sth->bind_columns(\$ qtl_id,\$
source_database,\$ source_primary_id,\$ trait,\$
lod_score,\$ flank_marker_id_1,\$
flank_marker_id_2,\$ peak_marker_id );
my @out = ();
my %already_seen;
while( $sth->fetch()) {
if(my $qtl = $already_seen{$qtl_id}) {
$qtl->add_synonym($source_database, $source_primary_id);
next;
}
my $mad = $self->db()->get_MarkerAdaptor();
my $flank_marker_1 = $flank_marker_id_1 ? $mad->fetch_by_dbID( $flank_marker_id_1 ) : undef ;
my $flank_marker_2 = $flank_marker_id_2 ? $mad->fetch_by_dbID( $flank_marker_id_2 ) : undef;
my $peak_marker = $peak_marker_id ? $mad->fetch_by_dbID( $peak_marker_id ) : undef;
my $qtl = Bio::EnsEMBL::Map::Qtl->new
(
$qtl_id,
$self->db->get_QtlAdaptor(),
$flank_marker_1,
$peak_marker,
$flank_marker_2,
$trait,
$lod_score,
{$source_database => $source_primary_id}
);
push @out, $qtl;
$already_seen{$qtl_id} = $qtl;
}
return\@ out; } |
sub fetch_all_by_source_database
{
my $self = shift;
my $database_name = shift;
my $database_primary_id = shift;
return [] unless $database_name;
my @conditions;
if( $database_name ) {
push( @conditions, "q.source_database=\"$database_name\"" );
}
if( $database_primary_id ) {
push( @conditions, "q.source_primary_id=\"$database_primary_id\"" );
}
return $self->_generic_fetch(\@ conditions ); } |
sub fetch_all_by_trait
{ my $self = shift;
my $trait = shift;
return [] unless $trait;
return $self->_generic_fetch( [ "q.trait = '$trait'" ] ); } |
sub fetch_by_dbID
{ my $self = shift;
my $dbID = shift;
return unless $dbID;
my $res = $self->_generic_fetch( [ "q.qtl_id = $dbID" ] );
return $res->[0]; } |
sub list_traits
{ my $self = shift;
my $sth = $self->prepare( "
SELECT DISTINCT trait
FROM qtl q
" );
my $res = [];
$sth->execute();
push ( @$res ,
map { $_->[0] } @{$sth->fetchall_arrayref()}
);
return $res;
}
1; } |