Bio-EnsEMBL
view release on metacpan or search on metacpan
lib/Bio/EnsEMBL/Utils/ConversionSupport.pm view on Meta::CPAN
);
if (! $attrib_id) {
$self->log_warning("There is no attrib_type_id for code $attrib_code, please patch the attrib_table\n");
exit;
}
else {
return $attrib_id;
}
}
=head2 store_new_attribute
Arg[1] : seq_region.seq_region_id
Arg[2] : attrib_type.code
Arg[3] : attrib_type.value
ARG[4] : table to update (seq_region_attribute by default)
Example : $support->store_new_attribute(23,name,5);
Description : uses MySQL to store an entry (code and value) in an attribute table
(seq_region_attrib by default)
Return type : array_ref
Caller : general
Status : stable
=cut
sub store_new_attribute {
my $self = shift;
my $sr_id = shift;
my $attrib_code = shift;
my $attrib_value = shift || '';
my $table = shift || 'seq_region_attrib';
#get database handle
my $dbh = $self->get_dbconnection('loutre');
#get attrib_type_id for this particular attribute
my $attrib_id = $self->_get_attrib_id($attrib_code,$dbh);
#store
my $r = $dbh->do(
qq(insert into $table
values (?,?,?)),
{},
($sr_id,$attrib_id,$attrib_value)
);
return ['Stored',$r];
}
=head2 update_attribute
Arg[1] : seq_region.seq_region_id
Arg[2] : attrib_type.code
Arg[3] : attrib_type.value
ARG[4] : table to update (seq_region_attribute by default)
Example : $support->update_attribute(23,name,5);
Description : uses MySQL to update an attribute table (seq_region_attrib by default)
Return type : array_ref
Caller : general
Status : stable
=cut
sub update_attribute {
my $self = shift;
my $sr_id = shift;
my $attrib_code = shift;
my $attrib_value = shift;
my $table = shift || 'seq_region_attrib';
my $dbh = $self->get_dbconnection('loutre');
my $attrib_id = $self->_get_attrib_id($attrib_code,$dbh);
#update
my $r = $dbh->do(
qq(update $table
set value = ?
where seq_region_id = $sr_id
and attrib_type_id = $attrib_id),
{},
($attrib_value)
);
return ['Updated',$r];
}
=head2 remove_duplicate_attribs
Arg[1] : db handle
Arg[2] : table
Example : $support->remove_duplicate_attribs($dbh,'gene');
Description : uses MySQL to remove duplicate entries from an attribute table
Return type : none
Caller : general
Status : stable
=cut
sub remove_duplicate_attribs {
my $self = shift;
my $dbh = shift;
my $table = shift;
$dbh->do(qq(create table nondup_${table}_attrib like ${table}_attrib));
$dbh->do(qq(insert into nondup_${table}_attrib (select ${table}_id, attrib_type_id, value from ${table}_attrib group by ${table}_id, attrib_type_id, value)));
$dbh->do(qq(delete from ${table}_attrib));
$dbh->do(qq(insert into ${table}_attrib (select ${table}_id, attrib_type_id, value from nondup_${table}_attrib)));
$dbh->do(qq(drop table nondup_${table}_attrib));
}
=head2 sav_seq
Arg[1] : string (sequence to save)
Example : $support->save_seq('ACGT')
Description : creates a temporary file containing the sequence you give it
Return type : string (filename)
Caller : general
Status : stable
=cut
sub save_seq {
my $self = shift;
my $content = shift ;
my $seq_file = $self->param('logpath') . '/SEQ_' . time() . int(rand()*100000000) . $$;
open (my $fh,">$seq_file", $seq_file) or die("Cannot create working file.$!");
print $fh $content;
( run in 0.536 second using v1.01-cache-2.11-cpan-f56aa216473 )