Newer
Older
Ian Longden
committed
plan tests => 58;
use Bio::EnsEMBL::Test::MultiTestDB;
use Bio::EnsEMBL::Test::TestUtils;
use Bio::EnsEMBL::DBEntry;
# switch on the debug prints
debug( "Startup test" );
#
# 1 Test started
#
ok(1);
my $multi = Bio::EnsEMBL::Test::MultiTestDB->new();
#
# 2 Database instatiated
#
ok( $db );
# some retrievals
my $dbEntryAdaptor = $db->get_DBEntryAdaptor();
Ian Longden
committed
my $sth = $db->dbc->prepare( 'select count(*) from object_xref where ensembl_object_type = "Translation"' );
$sth->execute();
my ( $xref_count ) = $sth->fetchrow_array();
my $db_entry_count = 0;
my $goxref_count = 0;
my $ident_count = 0;
$sth->finish();
my $ga = $db->get_GeneAdaptor();
my $all_gene_ids = $ga->list_dbIDs();
for my $gene_id ( @$all_gene_ids ) {
my $gene = $ga->fetch_by_dbID( $gene_id );
for my $tr ( @{$gene->get_all_Transcripts()} ) {
my $tl = $tr->translation();
my $dbentries = $dbEntryAdaptor->fetch_all_by_Translation( $tl );
$db_entry_count += scalar( @{$dbentries});
$goxref_count += grep { $_->isa( "Bio::EnsEMBL::GoXref" )} @$dbentries;
$ident_count += grep {$_->isa( "Bio::EnsEMBL::IdentityXref" )} @$dbentries;
}
}
debug( "Found $xref_count xrefs and $db_entry_count dblinks." );
debug( " $goxref_count GoXrefs, $ident_count identityXrefs." );
#
# 3 as many dblinks as entries in object_xref
#
Ian Longden
committed
print $db_entry_count."\t".$xref_count."\n";
ok( $db_entry_count == $xref_count );
#
# 4,5 correct number of GoXrefs and IdentityXrefs
#
debug( "GoXrefs and IdentityXrefs: ".$goxref_count . " " . $ident_count);
ok( $goxref_count == 48 );
ok( $ident_count == 32 );
# try storing and retrieval
my $xref = Bio::EnsEMBL::DBEntry->new
(
-primary_id => "1",
-dbname => "Uniprot/SWISSPROT",
-display_id => "Ens related thing",
-primary_id_linkable => "0",
-display_id_linkable => "1",
-db_display_name => "Nice friendly name",
-info_type => "PROJECTION",
-info_text => "from human gene ENSG0000011111",
-type => "ARRAY"
);
my %goxref = %$xref;
my %identxref = %$xref;
my $goref = Bio::EnsEMBL::GoXref->new
(
-primary_id => "1",
-dbname => "GO",
-release => "1",
-display_id => "Ens related GO"
);
$goref->add_linkage_type( "IC" );
my $ident_xref = Bio::EnsEMBL::IdentityXref->new
(
-primary_id => "1",
-dbname => "Uniprot/SPTREMBL",
-display_id => "Ens related Ident"
);
$ident_xref->query_identity( 100 );
$ident_xref->target_identity( 95 );
$multi->hide( "core", "object_xref", "xref", "identity_xref", "go_xref" );
my $gene = $ga->fetch_by_dbID( $all_gene_ids->[0] );
my $tr = $gene->get_all_Transcripts()->[0];
my $tl = $tr->translation();
my $oxr_count = count_rows($db, 'object_xref');
$dbEntryAdaptor->store( $xref, $tr->dbID, "Transcript" );
$oxr_count = count_rows($db, 'object_xref');
$dbEntryAdaptor->store( $goref, $tl->dbID, "Translation" );
$oxr_count = count_rows($db, 'object_xref');
$dbEntryAdaptor->store( $ident_xref, $tl->dbID, "Translation" );
$oxr_count = count_rows($db, 'object_xref');
$dbEntryAdaptor->store( $ident_xref, $tr->dbID, "Transcript" );
$oxr_count = count_rows($db, 'object_xref');
#
# 6 right number of object xrefs in db
#
debug( "object_xref_count = $oxr_count" );
$xref_count = count_rows($db, 'xref');
$sth->finish();
#
# 7 number of xrefs right
#
debug( "Number of xrefs = $xref_count" );
ok( $xref_count == 3 );
#
# 8 number of go entries right
#
$go_count = count_rows($db, 'go_xref');
debug( "Number of go_xrefs = $go_count" );
ok( $go_count == 1 );
#
# 9 identity xrefs right
#
$ident_count = count_rows($db, 'identity_xref');
# the identity (query/target)values are not normalized ...
debug( "Number of identity_xrefs = $ident_count" );
ok( $ident_count == 2 );
# Check type storing and retrieval
ok($xref->type() eq 'ARRAY');
$multi->restore();
#
# 10-12 Test that external synonyms and go evidence tags are retrieved
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#
my $ta = $db->get_TranscriptAdaptor();
my $translation = $ta->fetch_by_dbID(21737)->translation;
#pull out an xref that should 2 external synonyms
my $xrefs = $dbEntryAdaptor->fetch_all_by_Translation($translation);
($xref) = grep {$_->dbID == 315} @$xrefs;
my @syns = grep {$_ eq 'syn1' || $_ eq 'syn2'} @{$xref->get_all_synonyms};
ok(@syns == 2);
#and also 2 evidence tags
if($xref && $xref->isa('Bio::EnsEMBL::GoXref')) {
my @evtags =
grep {$_ eq 'IEA' || $_ eq 'IC'} @{$xref->get_all_linkage_types()};
ok(@evtags == 2);
} else {
ok(0);
}
$translation = $ta->fetch_by_dbID(21723)->translation;
$xrefs = $dbEntryAdaptor->fetch_all_by_Translation($translation);
($xref) = grep {$_->dbID == 257} @$xrefs;
if($xref && $xref->isa('Bio::EnsEMBL::GoXref')) {
my ($evtag) = @{$xref->get_all_linkage_types()};
ok($evtag eq 'IC');
} else {
ok(0);
}
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#test the idxref mapping code a bit
my $id_xref = Bio::EnsEMBL::IdentityXref->new
(-QUERY_IDENTITY => 80.4,
-TARGET_IDENTITY => 90.1,
-SCORE => 100,
-EVALUE => 1,
-CIGAR_LINE => '10M5D10M5I10M',
-QUERY_START => 1,
-QUERY_END => 35,
-TRANSLATION_START => 10,
-TRANSLATION_END => 45,
-ADAPTOR => $dbEntryAdaptor);
my $mapper = $id_xref->get_mapper();
ok($mapper && ref($mapper) && $mapper->isa('Bio::EnsEMBL::Mapper'));
my @coords = $mapper->map_coordinates('external_id', 10, 100, 1, 'external');
ok(@coords == 5);
ok($coords[0]->isa('Bio::EnsEMBL::Mapper::Coordinate'));
ok($coords[0]->start() == 19);
ok($coords[0]->end() == 19);
ok($coords[1]->isa('Bio::EnsEMBL::Mapper::Coordinate'));
ok($coords[1]->start == 25);
ok($coords[1]->end == 34);
ok($coords[2]->isa('Bio::EnsEMBL::Mapper::Gap'));
ok($coords[2]->length == 5);
ok($coords[3]->isa('Bio::EnsEMBL::Mapper::Coordinate'));
ok($coords[3]->start == 35);
ok($coords[3]->end == 44);
ok($coords[4]->isa('Bio::EnsEMBL::Mapper::Gap'));
ok($coords[4]->length == 65);
my $feature = Bio::EnsEMBL::Feature->new
(-START => 10,
-END => 100,
-STRAND => 1,
-SEQNAME => 'SwisProtSeq');
@coords = $id_xref->map_feature($feature);
ok(@coords == 5);
ok($coords[0]->isa('Bio::EnsEMBL::Mapper::Coordinate') &&
$coords[0]->start() == 19 &&
$coords[0]->end() == 19);
my $features = $id_xref->transform_feature($feature);
ok($features->[0]->start == 19 &&
$features->[0]->end == 19 &&
$features->[1]->start == 25 &&
$features->[1]->end == 34 &&
$features->[2]->start == 35 &&
$features->[2]->end == 44);
Graham McVicker
committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#
# test DBEntryAdaptor::fetch_by_db_accession and
# DBEntryAdaptor::fetch_by_dbID
#
$xref = $dbEntryAdaptor->fetch_by_dbID(152202);
ok($xref->dbID == 152202);
ok($xref->display_id() eq 'C20orf125');
ok($xref->dbname() eq 'HUGO');
ok($xref->primary_id() eq '16118');
$xref = $dbEntryAdaptor->fetch_by_db_accession('Interpro', 'IPR000010');
ok($xref->dbID == 999999);
ok($xref->description eq 'Test interpro desc2');
$multi->hide('core', 'xref');
#make sure this still works when interpro entries missing in xref table
$xref = $dbEntryAdaptor->fetch_by_db_accession('Interpro', 'IPR000010');
ok($xref);
ok($xref->primary_id() eq 'IPR000010');
$multi->restore('core', 'xref');
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
$multi->save('core', 'object_xref', 'identity_xref', 'go_xref');
#
# test the removal of dbentry associations
#
$translation = $ta->fetch_by_dbID(21723)->translation;
my $dbes = $translation->get_all_DBEntries();
my $all_count = @$dbes;
$go_count = grep {$_->isa('Bio::EnsEMBL::GoXref')} @$dbes;
my $id_count = grep {$_->isa('Bio::EnsEMBL::IdentityXref')} @$dbes;
my $all_total = count_rows($db, 'object_xref');
my $go_total = count_rows($db, 'go_xref');
my $id_total = count_rows($db, 'identity_xref');
print_dbEntries($dbes);
foreach my $dbe (@$dbes) {
$dbEntryAdaptor->remove_from_object($dbe, $translation, 'Translation');
}
# make sure the appropriate rows were deleted
ok($all_total - $all_count == count_rows($db, 'object_xref'));
ok($go_total - $go_count == count_rows($db, 'go_xref'));
ok($id_total - $id_count == count_rows($db, 'identity_xref'));
$multi->restore('core', 'object_xref', 'identity_xref', 'go_xref');
Ian Longden
committed
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
# new info type checks
# fetch_all_by Gene Transcript Translation
# transclation info type
$translation = $ta->fetch_by_dbID(21737)->translation;
$dbes = $translation->get_all_DBEntries(undef,"DEPENDENT");
ok(@$dbes == 2); # test 44
$dbes = $translation->get_all_DBLinks(undef,"DEPENDENT");
ok(@$dbes == 2);
$dbes = $translation->get_all_DBLinks(undef,"SEQUENCE_MATCH");
ok(@$dbes == 1);
$dbes = $translation->get_all_DBLinks(undef,"INFERRED_PAIR");
ok(@$dbes == 1);
$dbes = $translation->get_all_DBLinks(undef,"RUBBISH");
ok(@$dbes == 0);
# transcript info type
my $transcript = $ta->fetch_by_dbID(21737);
$dbes = $transcript->get_all_DBEntries(undef,"DEPENDENT");
ok(@$dbes == 0); # test 49
$dbes = $transcript->get_all_DBLinks(undef,"DEPENDENT");
ok(@$dbes == 2);
$dbes = $transcript->get_all_DBLinks(undef,"SEQUENCE_MATCH");
ok(@$dbes == 1);
$dbes = $transcript->get_all_DBLinks(undef,"INFERRED_PAIR");
ok(@$dbes == 1);
$dbes = $transcript->get_all_DBLinks(undef,"RUBBISH");
ok(@$dbes == 0);
# gene info type
$gene = $ga->fetch_by_dbID(18272);
$dbes = $gene->get_all_DBEntries(undef,"DEPENDENT");
ok(@$dbes == 0); # test 54
$dbes = $gene->get_all_DBLinks(undef,"DEPENDENT");
ok(@$dbes == 2);
$dbes = $gene->get_all_DBLinks(undef,"SEQUENCE_MATCH");
ok(@$dbes == 1);
$dbes = $gene->get_all_DBLinks(undef,"INFERRED_PAIR");
ok(@$dbes == 1);
$dbes = $gene->get_all_DBLinks(undef,"RUBBISH");
ok(@$dbes == 0);
sub print_dbEntries {
my $dbes = shift;
foreach my $dbe (@$dbes) {
if($dbe->isa('Bio::EnsEMBL::IdentityXref')) {
debug("IDXref");
} elsif($dbe->isa('Bio::EnsEMBL::GoXref')) {
debug("GOXref");
} elsif($dbe->isa('Bio::EnsEMBL::DBEntry')) {
debug("DBEntry");
} else {
debug("UNKNOWN dbentry type");
}
debug(" ".$dbe->dbname()."-".$dbe->display_id()."\n");
}
debug(scalar(@$dbes). " total");
}