Bio::EnsEMBL::Funcgen::DBSQL
ExperimentAdaptor
Toolbar
Summary
Bio::EnsEMBL::Funcgen::DBSQL::ExperimentAdaptor - A database adaptor for fetching and
storing Funcgen Experiment objects.
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
my $exp_a = $db->get_ExperimentAdaptor();
my $exp = $exp_a->fetch_by_name($name);
Description
The ExperimentAdaptor is a database adaptor for storing and retrieving
Funcgen Experiment objects.
Methods
Methods description
Args : None Example : None Description: PROTECTED implementation of superclass abstract method. Returns a list of columns to use for queries. Returntype : List of strings Exceptions : None Caller : Internal Status : At Risk |
Arg [1] : DBI statement handle object Example : None Description: PROTECTED implementation of superclass abstract method. Creates Array objects from an executed DBI statement handle. Returntype : Listref of Bio::EnsEMBL::Funcgen::Experiment objects Exceptions : None Caller : Internal Status : At Risk |
Args : None Example : None Description: PROTECTED implementation of superclass abstract method. Returns the names and aliases of the tables to use for queries. Returntype : List of listrefs of strings Exceptions : None Caller : Internal Status : At risk |
Arg [1] : int - dbID of array_chip Example : my $array = $oaa->fetch_by_array_chip_dbID($ac_dbid); Description: Retrieves a named Array object from the database. Returntype : listref of Bio::EnsEMBL::Funcgen::Experiment objects Exceptions : None Caller : General Status : At risk |
Arg [1] : Bio::EnsEMBL::Funcgen::Experiment - array to fetch attributes for Example : None Description: This function is solely intended to lazy load attributes into empty Experiment objects. You should not need to call this. Returntype : None Exceptions : None Caller : Bio::EnsEMBL::Funcgen::Experiment getters Status : Medium Risk |
Arg [1] : string - name of an Experiment Example : my $exp = $exp_a->fetch_by_name('Exp-1'); Description: Retrieves a named Experiment object from the database. Returntype : Bio::EnsEMBL::Funcgen::Experiment Exceptions : Throws if no name defined or if more than one returned Caller : General Status : At Risk -replace with fetch_all_by_name and fetch_by_name_group |
Args : Bio::EnsEMBL::Funcgen::Experiment Example : my $xml = $exp_adaptor->fetch_mage_xml_by_Experiment($exp); Description: Gets the MAGE XML for this experiment Returntype : string Exceptions : throws if arg is not a valid stored Experiment Caller : general Status : at Risk |
Args : Example : my $xml = $exp_adaptor->fetch_mage_xml_by_Experiment($exp); Description: Gets the MAGE XML for this experiment Returntype : string Exceptions : throws if no arg passed Caller : general Status : at Risk |
Arg [1] : (optional) boolean - flag to denote whether experiment is flagged for web display Example : my @names = @{$exp_a->get_all_experiment_names()}; Description: Retrieves names of all experiments. Returntype : ARRAYREF Exceptions : none Caller : General Status : At Risk -rename fetch? |
Args : None Example : my @exp_ids = @{$exp_a->list_dbIDs()}; Description: Gets an array of internal IDs for all Experiment objects in the current database. Returntype : List of ints Exceptions : None Caller : ? Status : Medium Risk |
Args : List of Bio::EnsEMBL::Funcgen::Experiment objects Example : $oaa->store($exp1, $exp2, $exp3); Description: Stores given Experiment objects in the database. Returntype : ARRAYREF of Bio::EnsEMBL::Funcgen::Experiment objects Exceptions : Throws is group not present in DB Throws if object is not a Bio::EnsEMBL::Funcgen::Experiment Throws if object is already present in the DB but has no dbID Caller : General Status : At Risk |
Args : Bio::EnsEMBL::Funcgen::Experiment Example : my $xml = $exp_adaptor->fetch_mage_xml_by_Experiment($exp); Description: Gets the MAGE XML for this experiment Returntype : string Exceptions : throws if arg is not a valid stored Experiment Caller : general Status : at Risk |
Methods code
sub _columns
{ my $self = shift;
return qw( e.experiment_id e.name e.experimental_group_id e.date e.primary_design_type e.description e.mage_xml_id); } |
sub _objs_from_sth
{ my ($self, $sth) = @_;
my (@result, $exp_id, $name, $group_id, $p_design_type, $date, $description, $xml_id);
$sth->bind_columns(\$exp_id,\$ name,\$ group_id,\$ date,\$ p_design_type,\$ description,\$ xml_id);
while ( $sth->fetch() ) {
my $exp = Bio::EnsEMBL::Funcgen::Experiment->new(
-DBID => $exp_id,
-ADAPTOR => $self,
-NAME => $name,
-GROUP_ID => $group_id,
-DATE => $date,
-PRIMARY_DESIGN_TYPE => $p_design_type,
-DESCRIPTION => $description,
-MAGE_XML_ID => $xml_id,
);
push @result, $exp;
}
return\@ result; } |
sub _tables
{ my $self = shift;
return ['experiment', 'e']; } |
sub fetch_all_by_group
{ my $self = shift;
throw("Not yet implemented");
my $ac_dbid = shift;
my $sth = $self->prepare("
SELECT a.array_id
FROM array a, array_chip ac
WHERE a.array_id = ac.array_id
AND ac.array_chip_id = $ac_dbid
");
$sth->execute();
my ($array_id) = $sth->fetchrow();
return $self->fetch_by_dbID($array_id); } |
sub fetch_attributes
{ my $self = shift;
my $array = shift;
my $tmp_array = $self->fetch_by_dbID( $array->dbID() );
%$array = %$tmp_array; } |
sub fetch_by_name
{ my $self = shift;
my $name = shift;
throw("Need to specify and experiment name argument") if (! defined $name);
my $result = $self->generic_fetch("e.name = '$name'");
if (scalar @$result > 1) {
throw("Experiment $name is not unique in the database, but only one result has been returned");
}
return $result->[0]; } |
sub fetch_mage_xml_by_Experiment
{ my ($self, $exp) = @_;
if(!($exp and $exp->isa('Bio::EnsEMBL::Funcgen::Experiment') && $exp->dbID())){
throw('You must provide a valid stored Bio::EnsEMBL::Funcgen::Experiment');
}
return if ! $exp->mage_xml_id();
my $sql = 'SELECT xml FROM mage_xml WHERE mage_xml_id='.$exp->mage_xml_id;
return $self->db->dbc->db_handle->selectall_arrayref($sql)->[0]; } |
sub fetch_mage_xml_by_experiment_name
{ my ($self, $exp_name) = @_;
if(! defined $exp_name){
throw('You must provide an Experiment name argument');
}
my $sql = 'SELECT mx.xml FROM mage_xml mx, experiment e WHERE e.name="'.$exp_name.'" and e.mage_xml_id=mx.mage_xml_id';
return $self->db->dbc->db_handle->selectall_arrayref($sql)->[0]; } |
sub get_all_experiment_names
{ my ($self, $displayable) = @_;
my ($constraint);
my $sql = "SELECT e.name FROM experiment e";
my @names = map $_ = "@$_", @{$self->db->dbc->db_handle->selectall_arrayref($sql)};
$sql .= ", status s WHERE e.experiment_id =\"s.table_id\" AND s.table_name=\"experiment\" AND s.state=\"DISPLAYABLE\"" if($displayable);
return\@ names;
}
} |
sub list_dbIDs
{ my ($self) = @_;
return $self->_list_dbIDs('experiment');
}
1; } |
sub store
{ my $self = shift;
my @args = @_;
my ($s_exp);
my $sth = $self->prepare('INSERT INTO experiment (name, experimental_group_id, date, primary_design_type, description, mage_xml_id) VALUES (?, ?, ?, ?, ?, ?)');
foreach my $exp (@args) {
throw('Can only store Experiment objects') if ( ! $exp->isa('Bio::EnsEMBL::Funcgen::Experiment'));
if (!( $exp->dbID() && $exp->adaptor() == $self )){
my ($g_dbid) = $self->db->fetch_group_details($exp->group());
throw("Group specified does, not exist. Use Importer(group, location, contact)") if(! $g_dbid);
$s_exp = $self->fetch_by_name($exp->name()); throw("Experimental already exists in the database with dbID:".$s_exp->dbID().
"\nTo reuse/update this Experimental you must retrieve it using the ExperimentalAdaptor".
"\nMaybe you want to use the -recover option?") if $s_exp;
$exp = $self->update_mage_xml_by_Experiment($exp) if(defined $exp->mage_xml());
$sth->bind_param(1, $exp->name(), SQL_VARCHAR);
$sth->bind_param(2, $g_dbid, SQL_INTEGER);
$sth->bind_param(3, $exp->date(), SQL_VARCHAR); $sth->bind_param(4, $exp->primary_design_type(), SQL_VARCHAR);
$sth->bind_param(5, $exp->description(), SQL_VARCHAR);
$sth->bind_param(6, $exp->mage_xml_id(), SQL_INTEGER);
$sth->execute();
$exp->dbID($sth->{'mysql_insertid'});
$exp->adaptor($self);
}else{
warn('You may want to use $exp->adaptor->store_states($exp)');
$self->store_states($exp);
}
}
return\@ args; } |
sub update_mage_xml_by_Experiment
{ my ($self, $exp) = @_;
if(!($exp and $exp->isa('Bio::EnsEMBL::Funcgen::Experiment'))){
throw('You must provide a valid Bio::EnsEMBL::Funcgen::Experiment');
}
if($exp->mage_xml_id()){
warn('Overwriting mage_xml entry for Experiment: '.$exp->name);
my $sql = "UPDATE mage_xml set xml='".$exp->mage_xml()."'";
$self->db->dbc->do($sql);
}else{
my $sql = "INSERT INTO mage_xml (xml) VALUES('".$exp->mage_xml()."')";
my $sth = $self->prepare($sql);
$sth->execute();
$exp->mage_xml_id($sth->{'mysql_insertid'});
$sql = "UPDATE experiment set mage_xml_id=".$exp->mage_xml_id()." where experiment_id =".$exp->dbID();
$sth = $self->prepare($sql);
$sth->execute();
}
return $exp; } |
General documentation
This module was created by Nathan Johnson.
This module is part of the Ensembl project:
/