Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Adding some tests for Bio::Coordinate::Pair, showing up a bug

Signed-off-by: Jonathan "Duke" Leto <jonathan@leto.net>
  • Loading branch information...
commit c9dccef249e13404841ce4fad8184081db4380f0 1 parent 02d67e9
Dan Bolser authored October 04, 2010 leto committed April 29, 2011

Showing 1 changed file with 528 additions and 0 deletions. Show diff stats Hide diff stats

  1. 528  t/Coordinate/CoordinateBoundaryTest.t
528  t/Coordinate/CoordinateBoundaryTest.t
... ...
@@ -0,0 +1,528 @@
  1
+
  2
+## Test for a suspected bug and tests for debugging.
  3
+
  4
+use strict;
  5
+use Data::Dumper;
  6
+
  7
+BEGIN {
  8
+  use lib '.';
  9
+  use Bio::Root::Test;
  10
+  
  11
+  test_begin( -tests => 174 );
  12
+  
  13
+  use_ok('Bio::Location::Simple');
  14
+  use_ok('Bio::Coordinate::Pair');
  15
+}
  16
+
  17
+
  18
+## Set up two coordinate systems for the same sequence
  19
+
  20
+## The contig
  21
+ok my $ctg = Bio::Location::Simple->
  22
+  new( -seq_id => 'ctg',
  23
+       -start  =>    1,
  24
+       -end    => 1001,
  25
+       -strand =>   +1,
  26
+     );
  27
+
  28
+isa_ok $ctg, 'Bio::Location::Simple';
  29
+
  30
+
  31
+## The contig in the chromosome
  32
+ok my $ctg_on_chr_f = Bio::Location::Simple->
  33
+  new( -seq_id => 'ctg on chr f',
  34
+       -start  =>           5001,
  35
+       -end    =>           6001,
  36
+       -strand =>             +1,
  37
+     );
  38
+
  39
+isa_ok $ctg_on_chr_f, 'Bio::Location::Simple';
  40
+
  41
+
  42
+## The contig in the chromosome (again)
  43
+ok my $ctg_on_chr_r = Bio::Location::Simple->
  44
+  new( -seq_id => 'ctg on chr r',
  45
+       -start  =>           5001,
  46
+       -end    =>           6001,
  47
+       -strand =>             -1,
  48
+     );
  49
+
  50
+isa_ok $ctg_on_chr_r, 'Bio::Location::Simple';
  51
+
  52
+
  53
+
  54
+
  55
+
  56
+## Set up the mapping between them
  57
+
  58
+ok my $agp_f = Bio::Coordinate::Pair->
  59
+  new( -in  => $ctg,
  60
+       -out => $ctg_on_chr_f
  61
+     );
  62
+
  63
+isa_ok $agp_f, 'Bio::Coordinate::Pair';
  64
+
  65
+
  66
+ok my $agp_r = Bio::Coordinate::Pair->
  67
+  new( -in  => $ctg,
  68
+       -out => $ctg_on_chr_r
  69
+     );
  70
+
  71
+isa_ok $agp_r, 'Bio::Coordinate::Pair';
  72
+
  73
+
  74
+
  75
+
  76
+
  77
+## Perform some very basic sanity testing on the resulting map objects
  78
+
  79
+## f
  80
+
  81
+ok $agp_f->test;
  82
+
  83
+is $agp_f->in->seq_id, 'ctg';
  84
+is $agp_f->in->start,      1;
  85
+is $agp_f->in->end,     1001;
  86
+is $agp_f->in->strand,    +1;
  87
+
  88
+is $agp_f->out->seq_id, 'ctg on chr f';
  89
+is $agp_f->out->start,            5001;
  90
+is $agp_f->out->end,              6001;
  91
+is $agp_f->out->strand,             +1;
  92
+
  93
+
  94
+## r
  95
+
  96
+ok $agp_r->test;
  97
+
  98
+is $agp_r->in->seq_id, 'ctg';
  99
+is $agp_r->in->start,      1;
  100
+is $agp_r->in->end,     1001;
  101
+is $agp_r->in->strand,    +1;
  102
+
  103
+is $agp_r->out->seq_id, 'ctg on chr r';
  104
+is $agp_r->out->start,            5001;
  105
+is $agp_r->out->end,              6001;
  106
+is $agp_r->out->strand,             -1;
  107
+
  108
+
  109
+
  110
+
  111
+
  112
+##
  113
+## Map a particular match through both map objects
  114
+##
  115
+
  116
+## Define the match 1
  117
+ok my $match_on_ctg_1 = Bio::Location::Simple->
  118
+  new( -seq_id => 'hit 1',
  119
+       -start  =>      25,
  120
+       -end    =>     225,
  121
+       -strand =>      +1,
  122
+     );
  123
+
  124
+isa_ok $match_on_ctg_1, 'Bio::LocationI';
  125
+
  126
+
  127
+# Convert the match from contig into chromosomal coordinates
  128
+
  129
+ok my $match_on_chr_1_f =
  130
+  $agp_f->map( $match_on_ctg_1 );
  131
+
  132
+isa_ok $match_on_chr_1_f, 'Bio::Coordinate::Result';
  133
+
  134
+
  135
+ok my $match_on_chr_1_r =
  136
+  $agp_r->map( $match_on_ctg_1 );
  137
+
  138
+isa_ok $match_on_chr_1_r, 'Bio::Coordinate::Result';
  139
+
  140
+
  141
+
  142
+## Perform some very basic sanity testing on the match objects
  143
+
  144
+is $match_on_ctg_1->seq_id, 'hit 1';
  145
+is $match_on_ctg_1->start,       25;
  146
+is $match_on_ctg_1->end,        225;
  147
+is $match_on_ctg_1->strand,      +1;
  148
+
  149
+is $match_on_chr_1_f->seq_id, 'ctg on chr f';
  150
+is $match_on_chr_1_f->start,            5025;
  151
+is $match_on_chr_1_f->end,              5225;
  152
+is $match_on_chr_1_f->strand,             +1;
  153
+
  154
+is $match_on_chr_1_r->seq_id, 'ctg on chr r';
  155
+is $match_on_chr_1_r->start,            5777;
  156
+is $match_on_chr_1_r->end,              5977;
  157
+is $match_on_chr_1_r->strand,             -1;
  158
+
  159
+
  160
+
  161
+## Define the match 2
  162
+ok my $match_on_ctg_2 = Bio::Location::Simple->
  163
+  new( -seq_id => 'hit 2',
  164
+       -start  =>      25,
  165
+       -end    =>     225,
  166
+       -strand =>      -1,
  167
+     );
  168
+
  169
+isa_ok $match_on_ctg_2, 'Bio::LocationI';
  170
+
  171
+
  172
+# Convert the match from contig into chromosomal coordinates
  173
+
  174
+ok my $match_on_chr_2_f =
  175
+  $agp_f->map( $match_on_ctg_2 );
  176
+
  177
+isa_ok $match_on_chr_2_f, 'Bio::Coordinate::Result';
  178
+
  179
+
  180
+ok my $match_on_chr_2_r =
  181
+  $agp_r->map( $match_on_ctg_2 );
  182
+
  183
+isa_ok $match_on_chr_2_r, 'Bio::Coordinate::Result';
  184
+
  185
+
  186
+
  187
+
  188
+## Perform some very basic sanity testing on the match objects
  189
+
  190
+is $match_on_ctg_2->seq_id, 'hit 2';
  191
+is $match_on_ctg_2->start,       25;
  192
+is $match_on_ctg_2->end,        225;
  193
+is $match_on_ctg_2->strand,      -1;
  194
+
  195
+is $match_on_chr_2_f->seq_id, 'ctg on chr f';
  196
+is $match_on_chr_2_f->start,            5025;
  197
+is $match_on_chr_2_f->end,              5225;
  198
+is $match_on_chr_2_f->strand,             -1;
  199
+
  200
+is $match_on_chr_2_r->seq_id, 'ctg on chr r';
  201
+is $match_on_chr_2_r->start,            5777;
  202
+is $match_on_chr_2_r->end,              5977;
  203
+is $match_on_chr_2_r->strand,             +1;
  204
+
  205
+
  206
+
  207
+
  208
+
  209
+
  210
+
  211
+## OK, now we can get down to some debugging...
  212
+
  213
+
  214
+
  215
+## TEST ONE
  216
+
  217
+## Create a match that goes off the end of the contig
  218
+
  219
+## Define the match 3
  220
+ok my $match_on_ctg_3 = Bio::Location::Simple->
  221
+  new( -seq_id => 'hit 3',
  222
+       -start  =>     925,
  223
+       -end    =>    1125,
  224
+       -strand =>      +1,
  225
+     );
  226
+
  227
+isa_ok $match_on_ctg_3, 'Bio::LocationI';
  228
+
  229
+
  230
+# Convert the match from contig into chromosomal coordinates
  231
+
  232
+ok my $match_on_chr_3_f =
  233
+  $agp_f->map( $match_on_ctg_3 );
  234
+
  235
+isa_ok $match_on_chr_3_f, 'Bio::Coordinate::Result';
  236
+
  237
+
  238
+ok my $match_on_chr_3_r =
  239
+  $agp_r->map( $match_on_ctg_3 );
  240
+
  241
+isa_ok $match_on_chr_3_r, 'Bio::Coordinate::Result';
  242
+
  243
+
  244
+
  245
+## Perform some very basic sanity testing on the match objects
  246
+
  247
+is $match_on_ctg_3->seq_id, 'hit 3';
  248
+is $match_on_ctg_3->start,      925;
  249
+is $match_on_ctg_3->end,       1125;
  250
+is $match_on_ctg_3->strand,      +1;
  251
+
  252
+is $match_on_chr_3_f->seq_id, 'ctg on chr f';
  253
+is $match_on_chr_3_f->start,            5925;
  254
+isnt $match_on_chr_3_f->end,            6125; # Gets truncated to maximum!
  255
+is $match_on_chr_3_f->end,              6001; # Gets truncated to maximum!
  256
+is $match_on_chr_3_f->strand,             +1;
  257
+
  258
+#print Dumper $match_on_ctg_3;
  259
+#print Dumper $match_on_chr_3_f;
  260
+
  261
+is $match_on_chr_3_r->seq_id, 'ctg on chr r';
  262
+isnt $match_on_chr_3_r->start,          4877; # Gets truncated to minimum!
  263
+is $match_on_chr_3_r->start,            5001; # Gets truncated to minimum!
  264
+is $match_on_chr_3_r->end,              5077;
  265
+#is $match_on_chr_3_r->strand,             -1; # FAIL
  266
+is $match_on_chr_3_r->strand,          undef; # See Bio::Location::Split
  267
+
  268
+#print Dumper $match_on_ctg_3;
  269
+#print Dumper $match_on_chr_3_r;
  270
+
  271
+
  272
+
  273
+## Define the match 4
  274
+ok my $match_on_ctg_4 = Bio::Location::Simple->
  275
+  new( -seq_id => 'hit 4',
  276
+       -start  =>     925,
  277
+       -end    =>    1125,
  278
+       -strand =>      -1,
  279
+     );
  280
+
  281
+isa_ok $match_on_ctg_4, 'Bio::LocationI';
  282
+
  283
+
  284
+# Convert the match from contig into chromosomal coordinates
  285
+
  286
+ok my $match_on_chr_4_f =
  287
+  $agp_f->map( $match_on_ctg_4 );
  288
+
  289
+isa_ok $match_on_chr_4_f, 'Bio::Coordinate::Result';
  290
+
  291
+
  292
+ok my $match_on_chr_4_r =
  293
+  $agp_r->map( $match_on_ctg_4 );
  294
+
  295
+isa_ok $match_on_chr_4_r, 'Bio::Coordinate::Result';
  296
+
  297
+
  298
+
  299
+## Perform some very basic sanity testing on the match objects
  300
+
  301
+is $match_on_ctg_4->seq_id, 'hit 4';
  302
+is $match_on_ctg_4->start,      925;
  303
+is $match_on_ctg_4->end,       1125;
  304
+is $match_on_ctg_4->strand,      -1;
  305
+
  306
+is $match_on_chr_4_f->seq_id, 'ctg on chr f';
  307
+is $match_on_chr_4_f->start,            5925;
  308
+isnt $match_on_chr_4_f->end,            6125; # Gets truncated to maximum!
  309
+is $match_on_chr_4_f->end,              6001; # Gets truncated to maximum!
  310
+is $match_on_chr_4_f->strand,             -1;
  311
+
  312
+#print Dumper $match_on_ctg_4;
  313
+#print Dumper $match_on_chr_4_f;
  314
+
  315
+is $match_on_chr_4_r->seq_id, 'ctg on chr r';
  316
+isnt $match_on_chr_4_r->start,          4877; # Gets truncated to minimum!
  317
+is $match_on_chr_4_r->start,            5001; # Gets truncated to minimum!
  318
+is $match_on_chr_4_r->end,              5077;
  319
+#is $match_on_chr_4_r->strand,             +1; # FAIL
  320
+is $match_on_chr_4_r->strand,          undef; # See Bio::Location::Split
  321
+
  322
+#print Dumper $match_on_ctg_4;
  323
+#print Dumper $match_on_chr_4_r;
  324
+
  325
+
  326
+
  327
+
  328
+
  329
+
  330
+
  331
+###
  332
+### NOW! NONE OF THE ABOVE SHOULD BE AFFECTED BY LEAVING OFF seq_id
  333
+### NOW SHOULD IT?!
  334
+###
  335
+
  336
+## Try commenting out the three -seq_id lines below to observe strange
  337
+## interactions!
  338
+
  339
+## The contig
  340
+ok my $ctg_x = Bio::Location::Simple->
  341
+  new( -seq_id => 'ctg',
  342
+       -start  =>    1,
  343
+       -end    => 1001,
  344
+       -strand =>   +1,
  345
+     );
  346
+
  347
+isa_ok $ctg_x, 'Bio::Location::Simple';
  348
+
  349
+## The contig in the chromosome
  350
+ok my $ctg_on_chr_f_x = Bio::Location::Simple->
  351
+  new( -seq_id => 'ctg on chr f',
  352
+       -start  =>           5001,
  353
+       -end    =>           6001,
  354
+       -strand =>             +1,
  355
+     );
  356
+
  357
+isa_ok $ctg_on_chr_f_x, 'Bio::Location::Simple';
  358
+
  359
+## The contig in the chromosome (again)
  360
+ok my $ctg_on_chr_r_x = Bio::Location::Simple->
  361
+  new( -seq_id => 'ctg on chr r',
  362
+       -start  =>           5001,
  363
+       -end    =>           6001,
  364
+       -strand =>             -1,
  365
+     );
  366
+
  367
+isa_ok $ctg_on_chr_r_x, 'Bio::Location::Simple';
  368
+
  369
+
  370
+
  371
+## Set up the mapping between them
  372
+
  373
+ok my $agp_xf = Bio::Coordinate::Pair->
  374
+  new( -in  => $ctg_x,
  375
+       -out => $ctg_on_chr_f_x
  376
+     );
  377
+
  378
+isa_ok $agp_xf, 'Bio::Coordinate::Pair';
  379
+
  380
+
  381
+ok my $agp_xr = Bio::Coordinate::Pair->
  382
+  new( -in  => $ctg_x,
  383
+       -out => $ctg_on_chr_r_x
  384
+     );
  385
+
  386
+isa_ok $agp_xr, 'Bio::Coordinate::Pair';
  387
+
  388
+
  389
+
  390
+
  391
+
  392
+## Perform some very basic sanity testing on the resulting map objects
  393
+
  394
+## f
  395
+
  396
+ok $agp_xf->test;
  397
+
  398
+is $agp_xf->in->start,      1;
  399
+is $agp_xf->in->end,     1001;
  400
+is $agp_xf->in->strand,    +1;
  401
+
  402
+is $agp_xf->out->start,            5001;
  403
+is $agp_xf->out->end,              6001;
  404
+is $agp_xf->out->strand,             +1;
  405
+
  406
+
  407
+## r
  408
+
  409
+ok $agp_r->test;
  410
+
  411
+is $agp_xr->in->start,      1;
  412
+is $agp_xr->in->end,     1001;
  413
+is $agp_xr->in->strand,    +1;
  414
+
  415
+is $agp_xr->out->start,            5001;
  416
+is $agp_xr->out->end,              6001;
  417
+is $agp_xr->out->strand,             -1;
  418
+
  419
+
  420
+
  421
+
  422
+
  423
+##
  424
+## Map a particular match through both map objects
  425
+##
  426
+
  427
+# Convert the match from contig into chromosomal coordinates
  428
+
  429
+ok my $match_on_chr_1_xf =
  430
+  $agp_xf->map( $match_on_ctg_1 );
  431
+
  432
+isa_ok $match_on_chr_1_xf, 'Bio::Coordinate::Result';
  433
+
  434
+
  435
+ok my $match_on_chr_1_xr =
  436
+  $agp_xr->map( $match_on_ctg_1 );
  437
+
  438
+isa_ok $match_on_chr_1_xr, 'Bio::Coordinate::Result';
  439
+
  440
+## Perform some very basic sanity testing on the match objects
  441
+
  442
+is $match_on_chr_1_xf->start,            5025;
  443
+is $match_on_chr_1_xf->end,              5225;
  444
+is $match_on_chr_1_xf->strand,             +1;
  445
+
  446
+is $match_on_chr_1_xr->start,            5777;
  447
+is $match_on_chr_1_xr->end,              5977;
  448
+is $match_on_chr_1_xr->strand,             -1;
  449
+
  450
+
  451
+
  452
+# Convert the match from contig into chromosomal coordinates
  453
+
  454
+ok my $match_on_chr_2_xf =
  455
+  $agp_xf->map( $match_on_ctg_2 );
  456
+
  457
+isa_ok $match_on_chr_2_xf, 'Bio::Coordinate::Result';
  458
+
  459
+
  460
+ok my $match_on_chr_2_xr =
  461
+  $agp_xr->map( $match_on_ctg_2 );
  462
+
  463
+isa_ok $match_on_chr_2_xr, 'Bio::Coordinate::Result';
  464
+
  465
+## Perform some very basic sanity testing on the match objects
  466
+
  467
+is $match_on_chr_2_xf->start,            5025;
  468
+is $match_on_chr_2_xf->end,              5225;
  469
+is $match_on_chr_2_xf->strand,             -1;
  470
+
  471
+is $match_on_chr_2_xr->start,            5777;
  472
+is $match_on_chr_2_xr->end,              5977;
  473
+is $match_on_chr_2_xr->strand,             +1;
  474
+
  475
+
  476
+
  477
+# Convert the match from contig into chromosomal coordinates
  478
+
  479
+ok my $match_on_chr_3_xf =
  480
+  $agp_xf->map( $match_on_ctg_3 );
  481
+
  482
+isa_ok $match_on_chr_3_xf, 'Bio::Coordinate::Result';
  483
+
  484
+
  485
+ok my $match_on_chr_3_xr =
  486
+  $agp_xr->map( $match_on_ctg_3 );
  487
+
  488
+isa_ok $match_on_chr_3_xr, 'Bio::Coordinate::Result';
  489
+
  490
+## Perform some very basic sanity testing on the match objects
  491
+
  492
+is $match_on_chr_3_xf->start,            5925;
  493
+isnt $match_on_chr_3_xf->end,            6125; # Gets truncated to maximum!
  494
+is $match_on_chr_3_xf->end,              6001; # Gets truncated to maximum!
  495
+is $match_on_chr_3_xf->strand,             +1;
  496
+
  497
+isnt $match_on_chr_3_xr->start,          4877; # Gets truncated to minimum!
  498
+is $match_on_chr_3_xr->start,            5001; # Gets truncated to minimum!
  499
+is $match_on_chr_3_xr->end,              5077;
  500
+#is $match_on_chr_3_xr->strand,             -1; # FAIL
  501
+is $match_on_chr_3_xr->strand,          undef; # See Bio::Location::Split
  502
+
  503
+
  504
+# Convert the match from contig into chromosomal coordinates
  505
+
  506
+ok my $match_on_chr_4_xf =
  507
+  $agp_xf->map( $match_on_ctg_4 );
  508
+
  509
+isa_ok $match_on_chr_4_xf, 'Bio::Coordinate::Result';
  510
+
  511
+
  512
+ok my $match_on_chr_4_xr =
  513
+  $agp_xr->map( $match_on_ctg_4 );
  514
+
  515
+isa_ok $match_on_chr_4_xr, 'Bio::Coordinate::Result';
  516
+
  517
+## Perform some very basic sanity testing on the match objects
  518
+
  519
+is $match_on_chr_4_xf->start,            5925;
  520
+isnt $match_on_chr_4_xf->end,            6125; # Gets truncated to maximum!
  521
+is $match_on_chr_4_xf->end,              6001; # Gets truncated to maximum!
  522
+is $match_on_chr_4_xf->strand,             -1;
  523
+
  524
+isnt $match_on_chr_4_xr->start,          4877; # Gets truncated to minimum!
  525
+is $match_on_chr_4_xr->start,            5001; # Gets truncated to minimum!
  526
+is $match_on_chr_4_xr->end,              5077;
  527
+#is $match_on_chr_4_xr->strand,             +1; # FAIL
  528
+is $match_on_chr_4_xr->strand,          undef; # See Bio::Location::Split

0 notes on commit c9dccef

Please sign in to comment.
Something went wrong with that request. Please try again.