Skip to content
Snippets Groups Projects
Commit c902469a authored by Andy Yates's avatar Andy Yates
Browse files

[ENSCORESW-438]. Fixed API when someone can specify a _rna_edit where the...

[ENSCORESW-438]. Fixed API when someone can specify a _rna_edit where the substring length was not equal to the substituting string length
parent be42f00c
No related branches found
No related tags found
No related merge requests found
......@@ -88,8 +88,7 @@ sub new {
# See if this has any seq_region_attrib of type "_rna_edit_cache" if so store these
# in a hash.
#
my $sth = $self->dbc->prepare('select sra.seq_region_id, sra.value from seq_region_attrib sra, attrib_type at where sra.attrib_type_id = at.attrib_type_id and code like "_rna_edit"');
my $sth = $self->dbc->prepare('select sra.seq_region_id, sra.value from seq_region_attrib sra, attrib_type at where sra.attrib_type_id = at.attrib_type_id and code = "_rna_edit"');
$sth->execute();
my ($seq_region_id, $value);
......@@ -98,6 +97,12 @@ sub new {
my $count = 0;
while($sth->fetch()){
$count++;
my ($start, $end, $substring) = split (/\s+/, $value);
my $edit_length = ($end - $start) + 1;
my $substring_length = length($substring);
if($edit_length != $substring_length) {
throw "seq_region_id $seq_region_id has an attrib of type '_rna_edit' (value '$value'). Edit length ${edit_length} is not the same as the replacement's length ${substring_length}. Please fix. We only support substitutions via this mechanism";
}
push @{$edits{$seq_region_id}}, $value;
}
$sth->finish;
......
......@@ -2,11 +2,13 @@ use strict;
use warnings;
use Test::More;
use Test::Exception;
use Bio::EnsEMBL::Test::TestUtils;
use Bio::EnsEMBL::Test::MultiTestDB;
use Bio::EnsEMBL::Slice;
use Bio::EnsEMBL::Attribute;
our $verbose= 0;
......@@ -26,22 +28,37 @@ my $STRAND = 1;
my $slice_adaptor = $db->get_SliceAdaptor;
my $seq_adaptor = $db->get_SequenceAdaptor();
{
my $slice = $slice_adaptor->fetch_by_region('chromosome', $CHR, $START, $END);
compare_compliments($slice, $seq_adaptor);
my $slice = $slice_adaptor->fetch_by_region('chromosome', $CHR, $START, $END);
compare_compliments($slice, $seq_adaptor);
#Bigger than 1Mb
$slice = $slice_adaptor->fetch_by_region('chromosome', $CHR, $START, $START+2_000_000);
compare_compliments($slice, $seq_adaptor);
#Bigger than 1Mb
$slice = $slice_adaptor->fetch_by_region('chromosome', $CHR, $START, $START+2_000_000);
compare_compliments($slice, $seq_adaptor);
$slice = $slice_adaptor->fetch_by_region('clone','AL031658.11');
compare_compliments($slice, $seq_adaptor);
$slice = $slice_adaptor->fetch_by_region('clone','AL031658.11');
compare_compliments($slice, $seq_adaptor);
$slice = $slice_adaptor->fetch_by_region('supercontig','NT_028392');
compare_compliments($slice, $seq_adaptor);
$slice = $slice_adaptor->fetch_by_region('supercontig','NT_028392');
compare_compliments($slice, $seq_adaptor);
$slice = $slice_adaptor->fetch_by_region('contig', 'AL031658.11.1.162976');
compare_compliments($slice, $seq_adaptor);
}
$slice = $slice_adaptor->fetch_by_region('contig', 'AL031658.11.1.162976');
compare_compliments($slice, $seq_adaptor);
$multi_db->save('core','seq_region_attrib');
{
#Adding an insertion _rna_edit into the seq_region_attrib table. This should
#not occur and we should fail to build the adaptor whilst it is still there.
#We will attach it to the clone
my $attribute_adaptor = $db->get_AttributeAdaptor();
my $bad_attribute = Bio::EnsEMBL::Attribute->new(-CODE => '_rna_edit', -VALUE => '10 10 AT'); # 1bp edit but string is 2bp
my $slice = $slice_adaptor->fetch_by_region('clone','AL031658.11');
$attribute_adaptor->store_on_Slice($slice, [$bad_attribute]);
throws_ok { $seq_adaptor->new($db); } qr/Edit length .+ substitutions/, 'Exception will be thrown when attempting to build a SequenceAdaptor with a mis-match edit length _rna_edit (only support subs)';
}
$multi_db->restore('core','seq_region_attrib');
sub compare_compliments {
......@@ -50,13 +67,13 @@ sub compare_compliments {
my $seq = ${$seq_adaptor->fetch_by_Slice_start_end_strand($slice,1,undef,1)};
debug('FORWARD STRAND SLICE SEQ for ' . $slice->name());
debug($slice->length);
note('FORWARD STRAND SLICE SEQ for ' . $slice->name());
note($slice->length);
my $invert_seq =
${$seq_adaptor->fetch_by_Slice_start_end_strand($slice->invert,1,undef,1)};
debug('REVERSE STRAND SLICE SEQ for ' . $slice->name());
note('REVERSE STRAND SLICE SEQ for ' . $slice->name());
is(length($seq), $slice->length, 'sequence is correct length');
......@@ -64,7 +81,12 @@ sub compare_compliments {
$seq = reverse $seq; #reverse complement seq
$seq =~ tr/ACTG/TGAC/;
ok($seq eq $invert_seq, 'revcom same as seq on inverted slice');
#Only use ok here; is would just be crazy
my $ok = ok($seq eq $invert_seq, 'revcom same as seq on inverted slice');
if(! $ok ) {
diag 'SEQ: '.$seq;
diag 'INVERT: '.$invert_seq;
}
}
done_testing();
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