diff --git a/modules/t/coordSystem.t b/modules/t/coordSystem.t index a5c3eece97f1a186d6fb5c40aacce4e890955f69..9176b17d07a127dde5843ef0b6855e6fe1cee694 100644 --- a/modules/t/coordSystem.t +++ b/modules/t/coordSystem.t @@ -10,16 +10,17 @@ our $verbose = 0; BEGIN { $| = 1; use Test; - plan tests => 8; + plan tests => 12; } my $name = 'chromosome'; my $version = 'NCBI33'; my $dbID = 1; -my $top_level = 1; +my $top_level = 0; my $sequence_level = 0; my $default = 1; +my $rank = 1; # # Test constructor @@ -29,6 +30,7 @@ my $coord_system = Bio::EnsEMBL::CoordSystem->new -VERSION => $version, -DBID => $dbID, -TOP_LEVEL => $top_level, + -RANK => $rank, -SEQUENCE_LEVEL => $sequence_level, -DEFAULT => 1); @@ -49,7 +51,7 @@ ok($coord_system->version() eq $version); # # Test is_top_level() # -ok($coord_system->is_top_level()); +ok(!$coord_system->is_top_level()); # # Test is_sequence_level() @@ -61,6 +63,10 @@ ok(!$coord_system->is_sequence_level()); # ok($coord_system->is_default()); +# +# Test rank() +# +ok($coord_system->rank() == $rank); # # Test equals() @@ -70,6 +76,7 @@ my $coord_system2 = Bio::EnsEMBL::CoordSystem->new (-NAME => $name, -VERSION => $version, -DBID => 123, + -RANK => $rank, -TOP_LEVEL => $top_level); ok($coord_system->equals($coord_system2)); @@ -78,10 +85,24 @@ $coord_system2 = Bio::EnsEMBL::CoordSystem->new (-NAME => 'chromosome', -VERSION => 'NCBI34', -DBID => 123, + -RANK => $rank, -TOP_LEVEL => $top_level); ok(!$coord_system->equals($coord_system2)); +# +# test creation of toplevel system +# +$name = 'toplevel'; +$top_level = 1; +# +# Test constructor +# +$coord_system = Bio::EnsEMBL::CoordSystem->new + (-NAME => $name, + -TOP_LEVEL => $top_level); - +ok($coord_system->name() eq $name); +ok($coord_system->is_top_level()); +ok($coord_system->rank() == 0); diff --git a/modules/t/coordSystemAdaptor.t b/modules/t/coordSystemAdaptor.t index f4722f7713f23bc34a6370aea61637d79b9d1e7e..840ad0d62401c500a4d37705f488da44ded3121c 100644 --- a/modules/t/coordSystemAdaptor.t +++ b/modules/t/coordSystemAdaptor.t @@ -3,7 +3,7 @@ use strict; BEGIN { $| = 1; use Test ; - plan tests => 25; + plan tests => 32; } use MultiTestDB; @@ -33,7 +33,7 @@ my $cs = $csa->fetch_by_name('chromosome'); ok($cs->name eq 'chromosome'); ok($cs->dbID()); ok($cs->version eq 'NCBI33'); -ok($cs->is_top_level()); +ok(!$cs->is_top_level()); ok(!$cs->is_sequence_level()); ok($cs->is_default()); @@ -48,6 +48,7 @@ ok(@cs_list == 1); ok($cs_list[0]->equals($cs)); + # # Test fetch_by_dbID() # @@ -59,22 +60,26 @@ ok($cs->version() eq ''); # -# 11 Test fetch_top_level +# Test fetch_top_level # $cs = $csa->fetch_top_level(); -ok($cs->name eq 'chromosome'); +ok($cs->name eq 'toplevel'); +ok($cs->is_top_level()); +ok($cs->rank == 0); # -# 12 Test fetch_all_top_level +# Test fetch_by_rank # -($cs) = @{$csa->fetch_all_top_level()}; +$cs = $csa->fetch_by_rank(1); +ok($cs->name() eq 'chromosome' && $cs->rank() == 1); -ok($cs->name eq 'chromosome'); +$cs = $csa->fetch_by_rank(0); +ok($cs->name() eq 'toplevel' && $cs->rank() == 0); # -# 13-14 Test fetch_sequence_level +# Test fetch_sequence_level # $cs = $csa->fetch_sequence_level(); @@ -83,7 +88,22 @@ ok($cs->is_sequence_level()); # -# 15-16 Test get_mapping_path +# Test fetch_all +# +@cs_list = @{$csa->fetch_all()}; +my $prev_cs; + +#make sure that they are ordered by rank +foreach my $cs (@cs_list) { + if($prev_cs) { + ok($prev_cs->rank < $cs->rank); + } + $prev_cs = $cs; +} + + +# +# Test get_mapping_path # my $ctg_cs = $csa->fetch_by_name('contig'); @@ -116,11 +136,11 @@ ok(@$path == 3 && $multi->save('core', 'coord_system'); $cs = Bio::EnsEMBL::CoordSystem->new - (-NAME => 'chromosome', + (-NAME => 'newsystem', -VERSION => 'NCBI35', - -DEFAULT => 0, + -DEFAULT => 1, -SEQUENCE_LEVEL => 0, - -TOP_LEVEL => 1); + -RANK => 10); $csa->store($cs); @@ -128,19 +148,20 @@ ok($cs->adaptor == $csa); ok($cs->dbID()); #now make sure we can retrieve this -$cs = $csa->fetch_by_name('chromosome', 'NCBI35'); -ok($cs->name eq 'chromosome'); +$cs = $csa->fetch_by_name('newsystem', 'NCBI35'); +ok($cs->name eq 'newsystem'); ok($cs->version eq 'NCBI35'); -ok(!$cs->is_default); +ok($cs->is_default); ok(!$cs->is_sequence_level); -ok($cs->is_top_level); +ok(!$cs->is_top_level); +ok($cs->rank() == 10); my $sth = $db->prepare('SELECT attrib FROM coord_system ' . 'WHERE name = ? and version = ?'); -$sth->execute('chromosome', 'NCBI35'); +$sth->execute('newsystem', 'NCBI35'); my ($attrib) = $sth->fetchrow_array(); -ok($attrib eq 'top_level'); +ok($attrib eq 'default_version'); $sth->finish(); $multi->restore('core', 'coord_system'); diff --git a/modules/t/feature.t b/modules/t/feature.t index c40cccae7d8f7862aa0f0ddcbf0dd0c8f733aae7..4423bb1246e9b08cdc505d323265d99f62a41fc8 100644 --- a/modules/t/feature.t +++ b/modules/t/feature.t @@ -5,7 +5,7 @@ use lib 't'; BEGIN { $| = 1; use Test; - plan tests => 92; + plan tests => 97; } use TestUtils qw( debug test_getter_setter ); @@ -26,7 +26,7 @@ my $coord_system = Bio::EnsEMBL::CoordSystem->new (-NAME => 'chromosome', -VERSION => 'NCBI34', -DBID => 123, - -TOP_LEVEL => 1); + -RANK => 1); my $analysis = Bio::EnsEMBL::Analysis->new(-LOGIC_NAME => 'test'); @@ -158,6 +158,8 @@ ok($feature->slice->seq_region_name() eq 'AL359765.6.1.13780'); ok($feature->slice->coord_system->name() eq 'contig'); + + # # Test Transform contig -> clone # @@ -176,6 +178,30 @@ ok($feature->slice->seq_region_name() eq 'AL359765.6'); ok($feature->slice->coord_system->name() eq 'clone'); + +# +# Test transform clone -> toplevel +# + +$feature = $feature->transform('toplevel'); + +debug("\nclone -> toplevel"); +debug("start = " . $feature->start()); +debug("end = " . $feature->end()); +debug("strand = " . $feature->strand()); +debug("seq_region = " . $feature->slice->seq_region_name()); + + +ok($feature->start() == 300 + $slice->start() - 1); +ok($feature->end() == 500 + $slice->start() - 1); +ok($feature->strand() == 1); +ok($feature->slice->coord_system->name() eq 'chromosome'); +ok($feature->slice->seq_region_name() eq '20'); + +#put back to clone +$feature = $feature->transform('clone'); + + # # Test transform to into gap # diff --git a/modules/t/featurePair.t b/modules/t/featurePair.t index 1f6a041cf72dda3a95282dfa3cdf0a8045f93b7e..d367105e2c1a3169f2fd85a96c49d255f3823e9c 100644 --- a/modules/t/featurePair.t +++ b/modules/t/featurePair.t @@ -22,7 +22,7 @@ my $coord_system = Bio::EnsEMBL::CoordSystem->new (-NAME => 'chromosome', -VERSION => 'NCBI34', -DBID => 123, - -TOP_LEVEL => 1); + -RANK => 1); my $analysis = Bio::EnsEMBL::Analysis->new(-LOGIC_NAME => 'test'); diff --git a/modules/t/gene.t b/modules/t/gene.t index 65386b798f3bcf0a34d50781b6926a7b9f4f72df..979cc3acd27e9cc3a1d406acd39abd40a6cefffa 100644 --- a/modules/t/gene.t +++ b/modules/t/gene.t @@ -361,7 +361,7 @@ debug( "checking external references" ); $multi->restore(); $slice = $db->get_SliceAdaptor()->fetch_by_region - ( "toplevel", "20", 30_252_000, 31_252_001 ); + ( "chromosome", "20", 30_252_000, 31_252_001 ); my $known = 0; my $unknown = 0; diff --git a/modules/t/karyotypeBand.t b/modules/t/karyotypeBand.t index f13c4208691eb937946baa99109977578a7581e0..8bf8e3228c29dec0fb2013addd0216588517ebbd 100644 --- a/modules/t/karyotypeBand.t +++ b/modules/t/karyotypeBand.t @@ -22,7 +22,7 @@ my $coord_system = Bio::EnsEMBL::CoordSystem->new (-NAME => 'chromosome', -VERSION => 'NCBI34', -DBID => 123, - -TOP_LEVEL => 1); + -RANK => 1); my $slice = Bio::EnsEMBL::Slice->new(-COORD_SYSTEM => $coord_system, diff --git a/modules/t/repeatFeature.t b/modules/t/repeatFeature.t index fa5d6fbf8243456a31b6a25339d91f144903e9ed..6ee22d31c0ab4c62887b25a2cc605df879823c13 100644 --- a/modules/t/repeatFeature.t +++ b/modules/t/repeatFeature.t @@ -24,7 +24,7 @@ my $coord_system = Bio::EnsEMBL::CoordSystem->new (-NAME => 'chromosome', -VERSION => 'NCBI34', -DBID => 123, - -TOP_LEVEL => 1); + -RANK => 1); my $analysis = Bio::EnsEMBL::Analysis->new(-LOGIC_NAME => 'test'); diff --git a/modules/t/slice.t b/modules/t/slice.t index 9258ab03ac12ea598069c1648553fc9bf54a9ab1..3c262259a7e2468bd7490dfde77985630bcd0201 100644 --- a/modules/t/slice.t +++ b/modules/t/slice.t @@ -47,7 +47,7 @@ ok($slice->adaptor == $slice_adaptor); # #TEST - Slice::new # -my $coord_system = $csa->fetch_by_name('toplevel'); +my $coord_system = $csa->fetch_by_name('chromosome'); $slice = new Bio::EnsEMBL::Slice (-seq_region_name => $CHR, diff --git a/modules/t/sliceAdaptor.t b/modules/t/sliceAdaptor.t index cae9c666bbab6921e8a05fd2a9accd2f3a1be1be..0a2ab40a8a817fc6314d1804f1c11849c97f0b82 100644 --- a/modules/t/sliceAdaptor.t +++ b/modules/t/sliceAdaptor.t @@ -36,7 +36,7 @@ ok($slice_adaptor->db); # # fetch_by_region # -my $slice = $slice_adaptor->fetch_by_region('toplevel',$CHR, $START, $END); +my $slice = $slice_adaptor->fetch_by_region('chromosome',$CHR, $START, $END); ok($slice->seq_region_name eq $CHR); ok($slice->start == $START); ok($slice->end == $END); diff --git a/modules/t/topLevelAssemblyMapper.t b/modules/t/topLevelAssemblyMapper.t new file mode 100644 index 0000000000000000000000000000000000000000..95caec343ac082aa32cc09a192abfd512bdc342b --- /dev/null +++ b/modules/t/topLevelAssemblyMapper.t @@ -0,0 +1,112 @@ +use lib 't'; +use strict; + +BEGIN { $| = 1; + use Test ; + plan tests => 7; +} + +use MultiTestDB; +use TestUtils qw(debug test_getter_setter); + +our $verbose = 0; #set to 1 to turn on debug printouts + +my $multi = MultiTestDB->new(); +my $db = $multi->get_DBAdaptor( 'core' ); + + +my $asma = $db->get_AssemblyMapperAdaptor(); + +# +# Test fetch_by_CoordSystems +# + +my $csa = $db->get_CoordSystemAdaptor(); +my $toplevel_cs = $csa->fetch_by_name('toplevel'); +my $cln_cs = $csa->fetch_by_name('clone'); +my $superctg_cs = $csa->fetch_by_name('supercontig'); + +my $cln_toplevel_mapper = + $asma->fetch_by_CoordSystems($toplevel_cs, $cln_cs); +my $superctg_toplevel_mapper = + $asma->fetch_by_CoordSystems($toplevel_cs, $superctg_cs); + +ok($cln_toplevel_mapper && + $cln_toplevel_mapper->isa('Bio::EnsEMBL::TopLevelAssemblyMapper')); + + +# +# test db has chr 20 (50KB -> 62MB) +# + +# +# Test map +# + +debug("MAP 'AL359765.6'->toplevel"); +my @coords = $cln_toplevel_mapper->map('AL359765.6', 1, 13780, 1, $cln_cs); +print_coords(@coords); +ok(@coords); + + +debug("MAP NT_028392->toplevel"); +@coords = $superctg_toplevel_mapper->map('NT_028392', 600_000, 1e6, 1, + $superctg_cs); +print_coords(@coords); +ok(@coords); + + + +# +# Test list_seq_regions +# + +my @seq_regions = + $cln_toplevel_mapper->list_seq_regions('AL359765.6', 1, 13780, $cln_cs); +my $str = join("\n", "----------", @seq_regions); +debug("$str\n"); +ok(@seq_regions == 1 && $seq_regions[0] eq '20'); + + +@seq_regions = $superctg_toplevel_mapper->list_seq_regions('NT_028392', + 6e5, 1e6, + $superctg_cs); + +$str = join("\n", "----------", @seq_regions); +debug("$str\n"); +ok(@seq_regions == 1 && $seq_regions[0] eq '20'); + + +# +# Test list_seq_ids +# + +my @ids = + $cln_toplevel_mapper->list_ids('AL359765.6', 1, 13780, $cln_cs); +$str = join("\n", "----------", @ids); +debug("$str\n"); +ok(@ids == 1 && $ids[0] == 469283); + +@ids = $superctg_toplevel_mapper->list_ids('NT_028392', + 6e5, 1e6, + $superctg_cs); +$str = join("\n", "----------", @ids); +debug("$str\n"); +ok(@ids == 1 && $ids[0] == 469283); + +sub print_coords { + my @coord_list = @_; + + return if(!$verbose); + + foreach my $coord (@coord_list) { + if($coord->isa('Bio::EnsEMBL::Mapper::Gap')) { + debug("GAP"); + next; + } + my $cs = $coord->coord_system(); + my $cs_str = ($cs) ? $cs->name() . $cs->version() : ''; + debug($coord->id()."\t". $coord->start()."-".$coord->end(). + " (".$coord->strand.") [$cs_str]"); + } +}