Bio::EnsEMBL::Compara::Production::DBSQL
DnaFragChunkAdaptor
Toolbar
Summary
Bio::EnsEMBL::Compara::Production::DBSQL::DnaFragChunkAdaptor
Package variables
No package variables defined.
Included modules
Inherit
Synopsis
Description
No description!
Methods
Methods description
Arg [1] : (optional) string $constraint An SQL query constraint (i.e. part of the WHERE clause) Arg [2] : (optional) string $logic_name the logic_name of the analysis of the features to obtain Example : $fts = $a->_generic_fetch('contig_id in (1234, 1235)', 'Swall'); Description: Performs a database fetch and returns feature objects in contig coordinates. Returntype : listref of Bio::EnsEMBL::Production::DnaFragChunk in contig coordinates Exceptions : none Caller : internal |
Arg : None Example : Description: Returntype : Exceptions : Caller : |
Arg [1] : int $genome_db_id Example : $chunks = $adaptor->fetch_all_for_genome_db_id(1); Description: Returns an array with all the DnaFragChunk objects for a given genome_db_id Returntype : listref of Bio::EnsEMBL::Compara::Production::DnaFragChunk objects Exceptions : thrown if $id is not defined Caller : general |
Arg [1] : int $id the unique database identifier for the feature to be obtained Example : $dfc = $adaptor->fetch_by_dbID(1234); Description: Returns the DnaFragChunk created from the database defined by the the id $id. Returntype : Bio::EnsEMBL::Compara::Production::DnaFragChunk Exceptions : thrown if $id is not defined Caller : general |
Arg [1...] : int $id (multiple) the unique database identifier for the feature to be obtained Example : $dfc = $adaptor->fetch_by_dbID(1234); Description: Returns an array of DnaFragChunk created from the database defined by the the id $id. Returntype : listref of Bio::EnsEMBL::Compara::Production::DnaFragChunk objects Exceptions : thrown if $id is not defined Caller : general |
Arg[1] : one or many DnaFragChunk objects Example : $adaptor->store($chunk); Description: stores DnaFragChunk objects into compara database Returntype : none Exceptions : none Caller : general |
Methods code
sub _columns
{ my $self = shift;
return qw (dfc.dnafrag_chunk_id
dfc.dnafrag_id
dfc.seq_start
dfc.seq_end
dfc.masking_analysis_data_id
dfc.sequence_id
); } |
sub _default_where_clause
{ my $self = shift;
return ''; } |
sub _fetch_DnaFrag_by_dbID
{
my $self = shift;
my $dnafrag_id = shift;
return $self->db->get_DnaFragAdaptor->fetch_by_dbID($dnafrag_id); } |
sub _fetch_MaskingOptions_by_dbID
{
my $self = shift;
my $data_id = shift;
$self->{'_masking_cache'} = {} unless(defined($self->{'_masking_cache'}));
if(!defined($self->{'_masking_cache'}->{$data_id})) {
my $dataDBA = new Bio::EnsEMBL::Hive::DBSQL::AnalysisDataAdaptor($self->dbc);
$self->{'_masking_cache'}->{$data_id} = $dataDBA->fetch_by_dbID($data_id);
}
return $self->{'_masking_cache'}->{$data_id};
}
1; } |
sub _final_clause
{ my $self = shift;
$self->{'_final_clause'} = shift if(@_);
return $self->{'_final_clause'}; } |
sub _generic_fetch
{ my ($self, $constraint, $join) = @_;
my @tables = $self->_tables;
my $columns = join(', ', $self->_columns());
if ($join) {
foreach my $single_join (@{$join}) {
my ($tablename, $condition, $extra_columns) = @{$single_join};
if ($tablename && $condition) {
push @tables, $tablename;
if($constraint) {
$constraint .= " AND $condition";
} else {
$constraint = " $condition";
}
}
if ($extra_columns) {
$columns .= ", " . join(', ', @{$extra_columns});
}
}
}
my $tablenames = join(', ', map({ join(' ', @$_) } @tables));
my $sql = "SELECT $columns FROM $tablenames";
my $default_where = $self->_default_where_clause;
my $final_clause = $self->_final_clause;
if($constraint) {
$sql .= " WHERE $constraint ";
if($default_where) {
$sql .= " AND $default_where ";
}
} elsif($default_where) {
$sql .= " WHERE $default_where ";
}
$sql .= " $final_clause" if($final_clause);
my $sth = $self->prepare($sql);
$sth->execute;
return $self->_objs_from_sth($sth); } |
sub _objs_from_sth
{ my ($self, $sth) = @_;
my %column;
$sth->bind_columns(\( @column{ @{$sth->{NAME_lc} } } ));
my @chunks = ();
while ($sth->fetch()) {
my $dfc;
$dfc = Bio::EnsEMBL::Compara::Production::DnaFragChunk->new();
$dfc->adaptor($self);
$dfc->dbID($column{'dnafrag_chunk_id'});
$dfc->seq_start($column{'seq_start'});
$dfc->seq_end($column{'seq_end'});
$dfc->sequence_id($column{'sequence_id'});
$dfc->dnafrag_id($column{'dnafrag_id'});
$dfc->masking_analysis_data_id($column{'masking_analysis_data_id'});
if($column{'masking_analysis_data_id'}) {
$dfc->masking_options($self->_fetch_MaskingOptions_by_dbID($column{'masking_analysis_data_id'}));
$dfc->masking_analysis_data_id($column{'masking_analysis_data_id'});
}
push @chunks, $dfc;
}
$sth->finish;
return\@ chunks } |
sub _tables
{ my $self = shift;
return (['dnafrag_chunk', 'dfc'] ); } |
sub fetch_all
{ my $self = shift;
return $self->_generic_fetch(); } |
sub fetch_all_for_genome_db_id
{ my $self = shift;
my $genome_db_id = shift;
$self->throw() unless (defined $genome_db_id);
my $constraint = "df.genome_db_id='$genome_db_id'";
my $join = [[['dnafrag', 'df'], 'dfc.dnafrag_id=df.dnafrag_id']];
return $self->_generic_fetch($constraint, $join);
}
} |
sub fetch_by_dbID
{ my ($self,$id) = @_;
unless(defined $id) {
$self->throw("fetch_by_dbID must have an id");
}
my @tabs = $self->_tables;
my ($name, $syn) = @{$tabs[0]};
my $constraint = "${syn}.${name}_id = $id";
my ($obj) = @{$self->_generic_fetch($constraint)};
return $obj; } |
sub fetch_by_dbIDs
{ my $self = shift;
my @ids = @_;
return undef unless(scalar(@ids));
my $id_string = join(",", @ids);
my $constraint = "dfc.dnafrag_chunk_id in ($id_string)";
return $self->_generic_fetch($constraint); } |
sub store
{ my ($self, $dfc) = @_;
return unless($dfc);
return unless($dfc->isa('Bio::EnsEMBL::Compara::Production::DnaFragChunk'));
my $query = "INSERT ignore INTO dnafrag_chunk".
"(dnafrag_id,sequence_id,seq_start,seq_end,masking_analysis_data_id) ".
"VALUES (?,?,?,?,?)";
$dfc->sequence_id($self->db->get_SequenceAdaptor->store($dfc->sequence));
if($dfc->masking_analysis_data_id==0 and defined($dfc->masking_options)) {
my $dataDBA = $self->db->get_AnalysisDataAdaptor;
$dfc->masking_analysis_data_id($dataDBA->store($dfc->masking_options));
}
my $sth = $self->prepare($query);
my $insertCount =
$sth->execute($dfc->dnafrag_id, $dfc->sequence_id,
$dfc->seq_start, $dfc->seq_end,
$dfc->masking_analysis_data_id);
if($insertCount>0) {
$dfc->dbID( $sth->{'mysql_insertid'} );
$sth->finish;
} else {
$sth->finish;
my $sth2 = $self->prepare("SELECT dnafrag_chunk_id FROM dnafrag_chunk ".
" WHERE dnafrag_id=? and seq_start=? and seq_end=? and masking_analysis_data_id=?");
$sth2->execute($dfc->dnafrag_id, $dfc->seq_start, $dfc->seq_end,
$dfc->masking_analysis_data_id);
my($id) = $sth2->fetchrow_array();
warn("DnaFragChunkAdaptor: insert failed, but dnafrag_chunk_id select failed too") unless($id);
$dfc->dbID($id);
$sth2->finish;
}
$dfc->adaptor($self);
return $dfc; } |
update_sequence | description | prev | next | Top |
sub update_sequence
{
my $self = shift;
my $dfc = shift;
return 0 unless($dfc);
return 0 unless($dfc->isa('Bio::EnsEMBL::Compara::Production::DnaFragChunk'));
return 0 unless($dfc->dbID);
return 0 unless(defined($dfc->sequence));
return 0 unless(length($dfc->sequence) <= 11500000);
my $seqDBA = $self->db->get_SequenceAdaptor;
my $newSeqID = $seqDBA->store($dfc->sequence);
return if($dfc->sequence_id == $newSeqID);
my $sth = $self->prepare("UPDATE dnafrag_chunk SET sequence_id=? where dnafrag_chunk_id=?");
$sth->execute($newSeqID, $dfc->dbID);
$sth->finish();
$dfc->sequence_id($newSeqID);
return $newSeqID;
}
} |
General documentation