Skip to content
Snippets Groups Projects
Commit 19445692 authored by Magali Ruffier's avatar Magali Ruffier
Browse files

ENSCORESW-926: add update method for sliceAdaptor

parent dc9ce250
No related branches found
No related tags found
3 merge requests!25GFF3 export: unstranded features and using analysis.gff_source,!25GFF3 export: unstranded features and using analysis.gff_source,!25GFF3 export: unstranded features and using analysis.gff_source
......@@ -2054,6 +2054,70 @@ sub store {
return $seq_region_id;
}
sub update {
my $self = shift;
my $slice = shift;
#
# Get all of the sanity checks out of the way before storing anything
#
if(!ref($slice) || !($slice->isa('Bio::EnsEMBL::Slice') or $slice->isa('Bio::EnsEMBL::LRGSlice'))) {
throw('Slice argument is required');
}
my $cs = $slice->coord_system();
throw("Slice must have attached CoordSystem.") if(!$cs);
my $db = $self->db();
if($slice->start != 1 || $slice->strand != 1) {
throw("Slice must have start==1 and strand==1.");
}
if($slice->end() != $slice->seq_region_length()) {
throw("Slice must have end==seq_region_length");
}
my $sr_len = $slice->length();
my $sr_name = $slice->seq_region_name();
if(!$sr_name) {
throw("Slice must have valid seq region name.");
}
#update the seq_region
my $seq_region_id = $slice->get_seq_region_id();
my $update_sql = qq(
UPDATE seq_region
SET name = ?,
length = ?,
coord_system_id = ?
WHERE seq_region_id = ?
);
my $sth = $db->dbc->prepare($update_sql);
$sth->bind_param(1,$sr_name,SQL_VARCHAR);
$sth->bind_param(2,$sr_len,SQL_INTEGER);
$sth->bind_param(3,$cs->dbID,SQL_INTEGER);
$sth->bind_param(4, $seq_region_id, SQL_INTEGER);
$sth->execute();
#synonyms
if(defined($slice->{'synonym'})){
foreach my $syn (@{$slice->{'synonym'}} ){
$syn->seq_region_id($seq_region_id); # set the seq_region_id
my $syn_adaptor = $db->get_SeqRegionSynonymAdaptor();
$syn_adaptor->store($syn);
}
}
}
=head2 remove
Arg [1] : Bio::EnsEMBL::Slice $slice
......
......@@ -297,6 +297,19 @@ ok($chr_slice->length() == $chr_len);
ok($chr_slice->seq_region_length() == $chr_len);
ok($chr_slice->seq_region_name eq $name);
#
# Update a slice
#
$chr_slice->add_synonym('testregion3');
$slice_adaptor->update($chr_slice);
my $updated_slice = $slice_adaptor->fetch_by_region('chromosome', 'testregion3');
ok($updated_slice->length() == $chr_len);
ok($updated_slice->seq_region_length() == $chr_len);
ok($updated_slice->seq_region_name eq $name);
#
# Store an assembly between the slices
#
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment