Commit ce87f468 authored by Nathan Johnson's avatar Nathan Johnson
Browse files

Removed Oligo Classes and Adaptors

parent 9072f20c
=head1 LICENSE
Copyright (c) 1999-2009 The European Bioinformatics Institute and
Genome Research Limited. All rights reserved.
This software is distributed under a modified Apache license.
For license details, please see
http://www.ensembl.org/info/about/code_licence.html
=head1 CONTACT
Please email comments or questions to the public Ensembl
developers list at <ensembl-dev@ebi.ac.uk>.
Questions may also be sent to the Ensembl help desk at
<helpdesk@ensembl.org>.
=cut
=head1 NAME
Bio::EnsEMBL::DBSQL::OligoArrayAdaptor - A database adaptor for fetching and
storing OligoArray objects.
=head1 SYNOPSIS
my $oaa = $db->get_OligoArrayAdaptor();
my $array = $oaa->fetch_by_name('Array-1');
my @arrays = @{ $oaa->fetch_all() };
=head1 DESCRIPTION
The OligoArrayAdaptor is a database adaptor for storing and retrieving
OligoArray objects.
=head1 METHODS
=cut
package Bio::EnsEMBL::DBSQL::OligoArrayAdaptor;
use strict;
use warnings;
use Bio::EnsEMBL::Utils::Exception qw( warning );
use Bio::EnsEMBL::OligoArray;
use Bio::EnsEMBL::DBSQL::BaseAdaptor;
use vars qw(@ISA);
@ISA = qw(Bio::EnsEMBL::DBSQL::BaseAdaptor);
=head2 fetch_by_name
Arg [1] : string - name of an array
Example : my $array = $oaa->fetch_by_name('Array-1');
Description: Retrieves a named OligoArray object from the database.
Returntype : Bio::EnsEMBL::OligoArray
Exceptions : None
Caller : General
Status : Medium Risk
=cut
sub fetch_by_name {
my $self = shift;
my $name = shift;
$self->bind_param_generic_fetch($name,SQL_VARCHAR);
my $result = $self->generic_fetch("oa.name = ?");
if (scalar @$result > 1) {
warning("Array $name is not unique in the database, but only one result has been returned");
}
return $result->[0];
}
=head2 fetch_all_by_type
Arg [1] : List of strings - type(s) (e.g. AFFY or OLIGO)
Example : my @arrays = @{$oaa->fetch_all_by_type('OLIGO')};
Description: Fetch all arrays of a particular type.
Returntype : Listref of Bio::EnsEMBL::OligoArray objects
Exceptions : Throws if no type is provided
Caller : General
Status : Medium Risk
=cut
sub fetch_all_by_type {
my ($self, @types) = @_;
throw('Need type as parameter') if !@types;
my $constraint;
if (scalar @types == 1) {
$constraint = qq( oa.type = ? );
$self->bind_param_generic_fetch($types[0],SQL_VARCHAR);
} else {
$constraint = join q(','), @types;
$constraint = qq( oa.type IN ('$constraint') );
}
return $self->generic_fetch($constraint);
}
=head2 fetch_attributes
Arg [1] : Bio::EnsEMBL::OligoArray - array to fetch attributes for
Example : None
Description: This function is solely intended to lazy load attributes into
empty OligoArray objects. You should not need to call this.
Returntype : None
Exceptions : None
Caller : Bio::EnsEMBL::OligoArray getters
Status : Medium Risk
=cut
sub fetch_attributes {
my $self = shift;
my $array = shift;
my $tmp_array = $self->fetch_by_dbID( $array->dbID() );
%$array = %$tmp_array;
}
=head2 _tables
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 : Medium Risk
=cut
sub _tables {
my $self = shift;
return ['oligo_array', 'oa'];
}
=head2 _columns
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 : Medium Risk
=cut
sub _columns {
my $self = shift;
return qw( oa.oligo_array_id oa.parent_array_id oa.probe_setsize oa.name oa.type );
}
=head2 _objs_from_sth
Arg [1] : DBI statement handle object
Example : None
Description: PROTECTED implementation of superclass abstract method.
Creates OligoArray objects from an executed DBI statement
handle.
Returntype : Listref of Bio::EnsEMBL::OligoArray objects
Exceptions : None
Caller : Internal
Status : Medium Risk
=cut
sub _objs_from_sth {
my ($self, $sth) = @_;
my (@result, $array_id, $parent_id, $setsize, $name, $type);
$sth->bind_columns( \$array_id, \$parent_id, \$setsize, \$name, \$type );
while ( $sth->fetch() ) {
my $array = Bio::EnsEMBL::OligoArray->new(
-dbID => $array_id,
-adaptor => $self,
-name => $name,
-setsize => $setsize,
-type => $type,
);
push @result, $array;
if ($parent_id) {
my $parent_array = Bio::EnsEMBL::OligoArray->new(
-dbID => $parent_id,
-adaptor => $self,
);
$array->superset($parent_array);
}
}
return \@result;
}
=head2 store
Args : List of Bio::EnsEMBL::OligoArray objects
Example : $oaa->store($array1, $array2, $array3);
Description: Stores given OligoArray objects in the database. Should only be
called once per array because no checks are made for duplicates.
Sets dbID and adaptor on the objects that it stores.
Returntype : None
Exceptions : None
Caller : General
Status : Medium Risk
=cut
sub store {
my $self = shift;
my @args = @_;
foreach my $array (@args) {
if ( !$array->isa('Bio::EnsEMBL::OligoArray') ) {
warning('Can only store OligoArray objects');
next;
}
# Has array already been stored?
next if ( $array->dbID() && $array->adaptor() == $self );
my $superset = $array->superset();
if ( defined $superset && !$superset->dbID() ) {
$self->store($superset);
}
my $sth = $self->prepare("
INSERT INTO oligo_array
(name, probe_setsize, type, parent_array_id)
VALUES (?, ?, ?, ?)
");
$sth->bind_param(1, $array->name(), SQL_VARCHAR);
$sth->bind_param(2, $array->setsize(), SQL_INTEGER);
$sth->bind_param(3, $array->type(), SQL_VARCHAR);
if (defined $superset) {
$sth->bind_param(4, $superset->dbID(), SQL_INTEGER);
} else {
$sth->bind_param(4, undef);
}
$sth->execute();
my $dbID = $sth->{'mysql_insertid'};
$array->dbID($dbID);
$array->adaptor($self);
}
}
=head2 list_dbIDs
Args : None
Example : my @array_ids = @{$oaa->list_dbIDs()};
Description: Gets an array of internal IDs for all OligoArray objects in the
current database.
Returntype : List of ints
Exceptions : None
Caller : ?
Status : Medium Risk
=cut
sub list_dbIDs {
my ($self) = @_;
return $self->_list_dbIDs('oligo_array');
}
1;
=head1 LICENSE
Copyright (c) 1999-2009 The European Bioinformatics Institute and
Genome Research Limited. All rights reserved.
This software is distributed under a modified Apache license.
For license details, please see
http://www.ensembl.org/info/about/code_licence.html
=head1 CONTACT
Please email comments or questions to the public Ensembl
developers list at <ensembl-dev@ebi.ac.uk>.
Questions may also be sent to the Ensembl help desk at
<helpdesk@ensembl.org>.
=cut
=head1 NAME
Bio::EnsEMBL::DBSQL::OligoFeatureAdaptor - A database adaptor for fetching and
storing OligoFeature objects.
=head1 SYNOPSIS
my $ofa = $db->get_OligoFeatureAdaptor();
my $features = $ofa->fetch_all_by_Probe($probe);
$features =
$ofa->fetch_all_by_Slice_arrayname( $slice, 'Array-1', 'Array-2' );
=head1 DESCRIPTION
The OligoFeatureAdaptor is a database adaptor for storing and retrieving
OligoFeature objects.
=head1 METHODS
=cut
package Bio::EnsEMBL::DBSQL::OligoFeatureAdaptor;
use strict;
use warnings;
use Bio::EnsEMBL::Utils::Exception qw( throw warning );
use Bio::EnsEMBL::OligoFeature;
use Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor;
use vars qw(@ISA);
@ISA = qw(Bio::EnsEMBL::DBSQL::BaseFeatureAdaptor);
=head2 fetch_all_by_Probe
Arg [1] : Bio::EnsEMBL::OligoProbe
Example : my $features = $ofa->fetch_all_by_Probe($probe);
Description: Fetchs all features that a given probe creates.
Returntype : Listref of Bio::EnsEMBL::OligoFeature objects
Exceptions : Throws if argument is not a stored OligoProbe object
Caller : OligoProbe->get_all_OligoFeatures()
Status : Medium Risk
=cut
sub fetch_all_by_Probe {
my $self = shift;
my $probe = shift;
if ( !ref($probe) && !$probe->isa('Bio::EnsEMBL::OligoProbe') ) {
throw('fetch_all_by_Probe requires a Bio::EnsEMBL::OligoProbe object');
}
if ( !defined $probe->dbID() ) {
throw('fetch_all_by_Probe requires a stored Bio::EnsEMBL::OligoProbe object');
}
$self->bind_param_generic_fetch($probe->dbID(),SQL_INTEGER);
return $self->generic_fetch( 'of.oligo_probe_id = ?' );
}
=head2 fetch_all_by_probeset
Arg [1] : string - probeset
Example : my $features = $ofa->fetch_all_by_probeset('Set-1');
Description: Fetchs all features that a given probeset creates.
Returntype : Listref of Bio::EnsEMBL::OligoFeature objects
Exceptions : Throws if no probeset argument
Caller : General
Status : Medium Risk
=cut
sub fetch_all_by_probeset {
my $self = shift;
my $probeset = shift;
if (!$probeset) {
throw('fetch_all_by_probeset requires a probeset argument');
}
$self->bind_param_generic_fetch($probeset,SQL_VARCHAR);
return $self->generic_fetch( "op.probeset = ?" );
}
=head2 fetch_all_by_Slice_arrayname
Arg [1] : Bio::EnsEMBL::Slice
Arg [2...] : List of strings - array name(s)
Example : my $slice = $sa->fetch_by_region('chromosome', '1');
my $features = $ofa->fetch_by_Slice_arrayname($slice, '');
Description: Retrieves a list of features on a given slice that are created
by probes from the specified arrays.
Returntype : Listref of Bio::EnsEMBL::OligoFeature objects
Exceptions : Throws if no array name is provided
Caller : Slice->get_all_OligoFeatures()
Status : Medium Risk
=cut
sub fetch_all_by_Slice_arrayname {
my ($self, $slice, @arraynames) = @_;
throw('Need array name as parameter') if !@arraynames;
my $constraint;
if (scalar @arraynames == 1) {
$constraint = qq( oa.name = '$arraynames[0]' );
} else {
$constraint = join q(','), @arraynames;
$constraint = qq( oa.name IN ('$constraint') );
}
return $self->SUPER::fetch_all_by_Slice_constraint($slice, $constraint);
}
=head2 fetch_all_by_Slice_type
Arg [1] : Bio::EnsEMBL::Slice
Arg [2] : string - type of array (e.g. AFFY or OLIGO)
Arg [3] : (optional) string - logic name
Example : my $slice = $sa->fetch_by_region('chromosome', '1');
my $features = $ofa->fetch_by_Slice_type($slice, 'OLIGO');
Description: Retrieves a list of features on a given slice that are created
by probes from the specified type of array.
Returntype : Listref of Bio::EnsEMBL::OligoFeature objects
Exceptions : Throws if no array type is provided
Caller : General
Status : Medium Risk
=cut
sub fetch_all_by_Slice_type {
my ($self, $slice, $type, $logic_name) = @_;
throw('Need type as parameter') if !$type;
my $constraint = qq( oa.type = '$type' );
return $self->SUPER::fetch_all_by_Slice_constraint($slice, $constraint, $logic_name);
}
=head2 _tables
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 : Medium Risk
=cut
sub _tables {
my $self = shift;
return (
[ 'oligo_feature', 'of' ],
[ 'oligo_probe', 'op' ],
[ 'oligo_array', 'oa' ]
);
}
=head2 _columns
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 : Medium Risk
=cut
sub _columns {
my $self = shift;
return qw(
of.oligo_feature_id of.seq_region_id
of.seq_region_start of.seq_region_end
of.seq_region_strand of.mismatches
of.oligo_probe_id of.analysis_id
oa.name op.probeset
op.name
);
}
=head2 _default_where_clause
Args : None
Example : None
Description: PROTECTED implementation of superclass abstract method.
Returns an additional table joining constraint to use for
queries.
Returntype : List of strings
Exceptions : None
Caller : Internal
Status : Medium Risk
=cut
sub _default_where_clause {
my $self = shift;
return 'of.oligo_probe_id = op.oligo_probe_id AND op.oligo_array_id = oa.oligo_array_id';
}
=head2 _final_clause
Args : None
Example : None
Description: PROTECTED implementation of superclass abstract method.
Returns an ORDER BY clause. Sorting by oligo_feature_id would be
enough to eliminate duplicates, but sorting by location might
make fetching features on a slice faster.
Returntype : String
Exceptions : None
Caller : generic_fetch
Status : Medium Risk
=cut
sub _final_clause {
return ' ORDER BY of.seq_region_id, of.seq_region_start, of.oligo_feature_id';
}
=head2 _objs_from_sth
Arg [1] : DBI statement handle object
Example : None
Description: PROTECTED implementation of superclass abstract method.
Creates OligoFeature objects from an executed DBI statement
handle.
Returntype : Listref of Bio::EnsEMBL::OligoFeature objects
Exceptions : None
Caller : Internal
Status : Medium Risk
=cut
sub _objs_from_sth {
my ($self, $sth, $mapper, $dest_slice) = @_;
# This code is ugly because caching is used to improve speed
my $sa = $self->db->get_SliceAdaptor();
my $aa = $self->db->get_AnalysisAdaptor();
my @features;
my (%analysis_hash, %slice_hash, %sr_name_hash, %sr_cs_hash);
my (
$oligo_feature_id, $seq_region_id,
$seq_region_start, $seq_region_end,
$seq_region_strand, $mismatches,
$oligo_probe_id, $analysis_id,
$array_name, $probeset,
$oligo_probe_name,
);
$sth->bind_columns(
\$oligo_feature_id, \$seq_region_id,
\$seq_region_start, \$seq_region_end,
\$seq_region_strand, \$mismatches,
\$oligo_probe_id, \$analysis_id,
\$array_name, \$probeset,
\$oligo_probe_name,
);
my $asm_cs;
my $cmp_cs;
my $asm_cs_name;
my $asm_cs_vers;
my $cmp_cs_name;
my $cmp_cs_vers;
if ($mapper) {
$asm_cs = $mapper->assembled_CoordSystem();
$cmp_cs = $mapper->component_CoordSystem();
$asm_cs_name = $asm_cs->name();
$asm_cs_vers = $asm_cs->version();
$cmp_cs_name = $cmp_cs->name();
$cmp_cs_vers = $cmp_cs->version();
}
my $dest_slice_start;
my $dest_slice_end;
my $dest_slice_strand;
my $dest_slice_length;
my $dest_slice_sr_name;
my $dest_slice_sr_id;
if ($dest_slice) {
$dest_slice_start = $dest_slice->start();
$dest_slice_end = $dest_slice->end();
$dest_slice_strand = $dest_slice->strand();
$dest_slice_length = $dest_slice->length();
$dest_slice_sr_name = $dest_slice->seq_region_name();
$dest_slice_sr_id = $dest_slice->get_seq_region_id();
}
my $last_feature_id = -1;
FEATURE: while ( $sth->fetch() ) {
# This assumes that features come out sorted by ID
next if ($last_feature_id == $oligo_feature_id);
$last_feature_id = $oligo_feature_id;
# Get the analysis object