1- # !/usr/bin/perl -w
1+ # !/usr/bin/env perl
22
33# Test script for Bio::ToolBox::Data and Bio::ToolBox::Data::Stream
44
5- use strict;
6- use Test::More;
7- use Test::Warn;
5+ use Test2::V0 -no_srand => 1;
6+ plan(255);
87use File::Spec;
98use FindBin ' $Bin' ;
109
1110BEGIN {
12- plan tests => 261;
1311 # # no critic
1412 $ENV {' BIOTOOLBOX' } = File::Spec-> catfile( $Bin , " Data" , " biotoolbox.cfg" );
1513 # # use critic
1614}
1715
18- require_ok ' Bio::ToolBox::Data'
19- or BAIL_OUT " Cannot load Bio::ToolBox::Data" ;
20- require_ok ' Bio::ToolBox::Data::Stream'
21- or BAIL_OUT " Cannot load Bio::ToolBox::Data::Stream" ;
16+ require Bio::ToolBox::Data;
17+ require Bio::ToolBox::Data::Stream;
2218
2319# ## Open a test file
2420my $infile = File::Spec-> catfile( $Bin , " Data" , " chrI.gff3" );
2521my $Data = Bio::ToolBox::Data-> new( file => $infile , );
26- isa_ok( $Data , ' Bio::ToolBox::Data' , ' GFF3 Data' );
22+ isa_ok( $Data , [ ' Bio::ToolBox::Data' ] , ' got a GFF3 Data object ' );
2723
2824# test general metadata
2925is( $Data -> gff, 3, ' gff version' );
@@ -96,10 +92,15 @@ is( $Data->name(7), 'Strand', 'name of column 7 again' );
9692# column metadata
9793is( $Data -> metadata( 1, ' name' ), ' Chromosome' , ' column name via metadata value' );
9894$Data -> metadata( 2, ' accuracy' , ' bogus' );
99- my $md = $Data -> metadata(2);
95+ my $md = $Data -> metadata(2);
96+ my $expected = {
97+ ' index' => 2,
98+ ' name' => ' Source' ,
99+ ' AUTO' => 3,
100+ ' accuracy' => ' bogus'
101+ };
100102ok( $md , ' metadata success' );
101- isa_ok( $md , ' HASH' , ' metadata is a hash' );
102- is( $md -> {' accuracy' }, ' bogus' , ' set metadata value is correct' );
103+ is( $md , $expected , ' metadata hash matches expected' );
103104
104105# column values
105106my $cv = $Data -> column_values(4);
@@ -109,7 +110,7 @@ is( $cv->[1], 1, 'check specific column value' );
109110
110111# test duplicate
111112my $Dupe = $Data -> duplicate;
112- isa_ok( $Dupe , ' Bio::ToolBox::Data' , ' Duplicated object' );
113+ isa_ok( $Dupe , [ ' Bio::ToolBox::Data' ], ' Duplicated object' );
113114is( $Dupe -> gff, 3, ' Dupe gff version' );
114115is( $Dupe -> program, undef , ' Dupe program name' );
115116is( $Dupe -> feature, ' region' , ' Dupe general feature' );
@@ -121,11 +122,11 @@ is( $Dupe->last_row, 0, 'Dupe last row index' );
121122
122123# test row_stream
123124my $stream = $Data -> row_stream;
124- isa_ok( $stream , ' Bio::ToolBox::Data::Iterator' , ' Iterator object' );
125+ isa_ok( $stream , [ ' Bio::ToolBox::Data::Iterator' ] , ' Got an Iterator object' );
125126
126127# first row feature
127128my $row = $stream -> next_row;
128- isa_ok( $row , ' Bio::ToolBox::Data::Feature' , ' Feature object' );
129+ isa_ok( $row , [ ' Bio::ToolBox::Data::Feature' ] , ' Got a Feature object' );
129130is( $row -> value(1), ' chrI' , ' row object value of index 1' );
130131is( $row -> seq_id, ' chrI' , ' row object chromosome value' );
131132is( $row -> start, 1, ' row object start value' );
@@ -146,8 +147,12 @@ is( $row->end, 62, 'row object end value' );
146147
147148# check gff attribute
148149my $gff_att = $row -> gff_attributes;
149- isa_ok( $gff_att , ' HASH' , ' row GFF attributes hash' );
150- is( $gff_att -> {Name }, ' TEL01L-TR' , ' row GFF attribute Name' );
150+ $expected = {
151+ ' Note' => ' Terminal stretch of telomeric repeats on the left arm of Chromosome I' ,
152+ ' Name' => ' TEL01L-TR' ,
153+ ' ID' => ' TEL01L-TR'
154+ };
155+ is( $gff_att , $expected , ' row GFF attributes hash' );
151156$gff_att -> {Note } = ' I hereby claim this telomeric repeat to be mine' ;
152157is( $row -> rewrite_gff_attributes, 1, ' rewrite row GFF attributes' );
153158is(
@@ -201,10 +206,13 @@ is( $Data->metadata( 10, 'name' ), 'Name', 'Name of new column' );
201206# change and copy metadata
202207$Data -> name( 10, ' DuplicateName' );
203208$Data -> copy_metadata( 2, 10 );
204- $md = $Data -> metadata(10);
205- is( $md -> {name }, ' DuplicateName' , ' metadata of changed column name' );
206- is( $md -> {accuracy }, ' bogus' , ' metadata of copied column' );
207- is( $md -> {' index' }, 10, ' metadata of copied column' );
209+ $md = $Data -> metadata(10);
210+ $expected = {
211+ ' name' => ' DuplicateName' ,
212+ ' index' => 10,
213+ ' accuracy' => ' bogus'
214+ };
215+ is( $md , $expected , ' copied metadata is expected' );
208216
209217# sort table
210218$Data -> sort_data( 9, ' d' );
@@ -264,7 +272,7 @@ undef $Data;
264272$Data = Bio::ToolBox::Data-> new( file => $file );
265273
266274# metadata tests
267- isa_ok( $Data , ' Bio::ToolBox::Data' , ' Bed Data' );
275+ isa_ok( $Data , [ ' Bio::ToolBox::Data' ] , ' Got a bed Data object ' );
268276is( $Data -> gff, 0, ' gff version' );
269277is( $Data -> bed, 4, ' bed version' );
270278is( $Data -> format, ' bed4' , ' bed format' );
@@ -289,7 +297,7 @@ is( $Data->headers, 0, 'includes headers' );
289297# stream tests and row feature
290298$stream = $Data -> row_stream;
291299$row = $stream -> next_row;
292- isa_ok( $row , ' Bio::ToolBox::Data::Feature' , ' Feature object' );
300+ isa_ok( $row , [ ' Bio::ToolBox::Data::Feature' ] , ' got a Feature object' );
293301is( $row -> value(1), ' chrI' , ' row object value of chromo index' );
294302is( $row -> start, 35155, ' row object start value' );
295303is( $row -> end, 36303, ' row object end value' );
@@ -299,7 +307,7 @@ is( $row->coordinate, 'chrI:35155-36303', 'row object coordinate string' );
299307
300308# grab row feature directly and change attributes using high API functions - v1.68
301309$row = $Data -> get_row(25);
302- isa_ok( $row , ' Bio::ToolBox::Data::Feature' , ' Direct Feature object' );
310+ isa_ok( $row , [ ' Bio::ToolBox::Data::Feature' ] , ' Got a direct Feature object' );
303311is( $row -> value(1), ' chrI' , ' Feature chromosome actual value' );
304312is( $row -> seq_id, ' chrI' , ' Feature chromosome' );
305313is( $row -> seq_id(' chrX' ), ' chrX' , ' Change chromosome via high level' );
@@ -326,18 +334,19 @@ is( $Data->value( 25, 4 ), 'bob', 'Feature name actual value' );
326334
327335is( $row -> value(5), ' .' , ' Feature actual strand value (nonexistent)' );
328336is( $row -> strand, 0, ' Feature strand (implied)' );
329- warning_is(
330- sub { $row -> strand(1) },
331- ' ERROR: No Strand column to update!' ,
337+
338+ like(
339+ warning { $row -> strand(1) },
340+ qr / ^ ERROR:\ No\ Strand\ column\ to\ update!/ x ,
332341 ' Attempt strand change via high level'
333342);
334343is( $row -> strand, 0, ' Check attempted strand change' );
335344is( $Data -> value( 25, 5 ), undef , ' Feature actual changed strand value' );
336-
337345is( $row -> type, ' region' , ' Feature type (implied)' );
338- warning_is(
339- sub { $row -> type(' gene' ) },
340- ' ERROR: No Type column to update!' ,
346+
347+ like(
348+ warning { $row -> type(' gene' ) },
349+ qr / ^ ERROR:\ No\ Type\ column\ to\ update!/ x ,
341350 ' Attempt type change via high level'
342351);
343352isnt( $row -> type, ' gene' , ' Check attempted type change' );
@@ -365,7 +374,7 @@ undef $Data;
365374
366375# open the bed file we just wrote
367376my $Stream = Bio::ToolBox::Data::Stream-> new( in => $file , );
368- isa_ok( $Stream , ' Bio::ToolBox::Data::Stream' , ' Stream Bed object' );
377+ isa_ok( $Stream , [ ' Bio::ToolBox::Data::Stream' ] , ' Got a Stream object' );
369378is( $Stream -> bed, 4, ' bed value' );
370379is( $Stream -> gff, 0, ' gff value' );
371380is( $Stream -> feature, ' region' , ' feature' );
@@ -386,7 +395,7 @@ is( $Stream->name(3), 'End', 'name of column again' );
386395
387396# iterate
388397my $f = $Stream -> next_row;
389- isa_ok( $f , ' Bio::ToolBox::Data::Feature' , ' next row Feature object' );
398+ isa_ok( $f , [ ' Bio::ToolBox::Data::Feature' ] , ' got the next row Feature object' );
390399
391400# check feature
392401is( $f -> seq_id, ' chrI' , ' feature seq_id' );
@@ -405,13 +414,14 @@ $Stream = Bio::ToolBox::Data->new(
405414 stream => 1,
406415 in => $file ,
407416);
408- isa_ok( $Stream , ' Bio::ToolBox::Data::Stream' , ' Stream object' );
417+ isa_ok( $Stream , [' Bio::ToolBox::Data::Stream' ],
418+ ' got another Stream object differently' );
409419
410420# create output file
411421my $file1 = $file ;
412422$file1 =~ s /\. bed$/ _2.bed/ ;
413423my $outStream = $Stream -> duplicate($file1 );
414- isa_ok( $outStream , ' Bio::ToolBox::Data::Stream' , ' duplicated Stream object' );
424+ isa_ok( $outStream , [ ' Bio::ToolBox::Data::Stream' ] , ' got a duplicated Stream object' );
415425is( $Stream -> basename, ' chrI' , ' in Stream basename' );
416426is( $outStream -> basename, ' chrI_2' , ' out Stream basename' );
417427
@@ -445,7 +455,7 @@ cmp_ok( -s $file2, '<', -s $file, "smaller file size due to lack of comments" );
445455# reload the duplicate files
446456# this should effectively delete the child files
447457$Data = Bio::ToolBox::Data-> new();
448- isa_ok( $Data , ' Bio::ToolBox::Data' , ' new empty Data object' );
458+ isa_ok( $Data , [ ' Bio::ToolBox::Data' ] , ' got a shiny new empty Data object' );
449459is( $Data -> number_columns, 0, ' number of columns' );
450460is( $Data -> last_row, 0, ' last row index' );
451461
@@ -460,7 +470,7 @@ undef $Data;
460470undef $row ;
461471$infile = File::Spec-> catfile( $Bin , " Data" , " H3K4me3.narrowPeak" );
462472$Data = Bio::ToolBox::Data-> new( file => $infile , );
463- isa_ok( $Data , ' Bio::ToolBox::Data' , ' narrowPeak Data' );
473+ isa_ok( $Data , [ ' Bio::ToolBox::Data' ] , ' got a narrowPeak Data object ' );
464474
465475# test general metadata
466476is( $Data -> gff, 0, ' gff version' );
@@ -476,15 +486,15 @@ is( $Data->find_column('pValue'), 8, 'find column pValue' );
476486is( $Data -> find_column(' peak' ), 10, ' find column peak' );
477487is( $Data -> headers, 0, ' include_headers' );
478488$row = $Data -> get_row(1);
479- isa_ok( $row , ' Bio::ToolBox::Data::Feature' , ' first peak interval Feature object' );
489+ isa_ok( $row , [ ' Bio::ToolBox::Data::Feature' ] , ' got first peak interval Feature object' );
480490is( $row -> peak, 11908866, ' peak interval peak coordinate' );
481491is( $row -> midpoint, 11909060, ' peak interval midpoint' );
482492
483493# ## Open a gappedPeak test file
484494undef $Data ;
485495$infile = File::Spec-> catfile( $Bin , " Data" , " H3K27ac.bed" );
486496$Data = Bio::ToolBox::Data-> new( file => $infile , );
487- isa_ok( $Data , ' Bio::ToolBox::Data' , ' gappedPeak bed Data' );
497+ isa_ok( $Data , [ ' Bio::ToolBox::Data' ] , ' got a gappedPeak bed Data object ' );
488498
489499# test general metadata
490500is( $Data -> gff, 0, ' gff version' );
@@ -506,7 +516,7 @@ undef $row;
506516$infile = File::Spec-> catfile( $Bin , " Data" , " H3K4me3.narrowPeak" );
507517$Stream = Bio::ToolBox::Data::Stream-> new( in => $infile );
508518$Data = $Stream -> duplicate;
509- isa_ok( $Data , ' Bio::ToolBox::Data' , ' duplicate Stream object to Data object' );
519+ isa_ok( $Data , [ ' Bio::ToolBox::Data' ] , ' got a duplicate Stream object to Data object' );
510520is( $Data -> number_columns, 10, ' number columns' );
511521is( $Data -> bed, 10, ' bed value' );
512522is( $Data -> feature, ' region' , ' feature' );
@@ -527,7 +537,7 @@ undef $Data;
527537
528538# reopen and check
529539my $fh = Bio::ToolBox::Data-> open_to_read_fh(' test.txt' );
530- isa_ok( $fh , ' IO::File' , ' opened filehandle' );
540+ isa_ok( $fh , [ ' IO::File' ] , ' got an opened filehandle object ' );
531541is( $fh -> getline, " # example Me3 narrowPeak\n " , ' first line' );
532542my @headers = split ( / \t / , $fh -> getline );
533543is( scalar (@headers ), 10, ' number of header items' );
@@ -541,9 +551,9 @@ unlink('test.txt');
541551undef $Data ;
542552$infile = File::Spec-> catfile( $Bin , ' Data' , ' sample.bed' );
543553$Data = Bio::ToolBox::Data-> new( in => $infile );
544- isa_ok( $Data , ' Bio::ToolBox::Data' , ' new sample bed file object' );
554+ isa_ok( $Data , [ ' Bio::ToolBox::Data' ] , ' got a new sample bed Data object' );
545555my $Data1 = Bio::ToolBox::Data-> new( columns => [qw( Coordinate Name) ] );
546- isa_ok( $Data1 , ' Bio::ToolBox::Data' , ' new empty Data object with columns' );
556+ isa_ok( $Data1 , [ ' Bio::ToolBox::Data' ] , ' got a new empty Data object with columns' );
547557$iterate_success = $Data -> iterate(
548558 sub {
549559 my $r = shift ;
@@ -555,7 +565,7 @@ is( $Data1->number_rows, $Data->number_rows, 'number of new rows' );
555565
556566# check extraction of coordinates from string, start is transformed
557567$row = $Data1 -> get_row(1);
558- isa_ok( $row , ' Bio::ToolBox::Data::Feature' , ' first feature ' );
568+ isa_ok( $row , [ ' Bio::ToolBox::Data::Feature' ] , ' got the first Feature object ' );
559569is( $row -> seq_id, ' chrI' , ' extracted seq_id from coordinate string' );
560570is( $row -> start, 54989, ' extracted start from coordinate string' );
561571is( $row -> end, 56857, ' extracted end from coordinate string' );
0 commit comments