@@ -9,7 +9,7 @@ use File::Spec;
99use FindBin ' $Bin' ;
1010
1111BEGIN {
12- plan tests => 248 ;
12+ plan tests => 261 ;
1313 # # no critic
1414 $ENV {' BIOTOOLBOX' } = File::Spec-> catfile( $Bin , " Data" , " biotoolbox.cfg" );
1515 # # use critic
@@ -187,8 +187,10 @@ for my $i ( 1 .. $Data->last_row ) {
187187}
188188my $index = $Data -> add_column( \@new_column );
189189is( $index , 9, ' added column index' );
190- is( $Data -> value( 78, 9 ),
191- ' Feature78' , ' checked column value after adding new column values' );
190+ is(
191+ $Data -> value( 78, 9 ),
192+ ' Feature78' , ' checked column value after adding new column values'
193+ );
192194
193195# copy a column
194196$index = $Data -> copy_column(9);
@@ -350,8 +352,10 @@ my $args = {
350352 practical_start => 1001,
351353 practical_stop => 2000
352354};
353- is( $row -> calculate_reference($args ),
354- 1501, ' midpoint reference position of given positions' );
355+ is(
356+ $row -> calculate_reference($args ),
357+ 1501, ' midpoint reference position of given positions'
358+ );
355359
356360undef $row ;
357361undef $stream ;
@@ -533,3 +537,37 @@ is( $headers[6], 'signalValue', 'third column header name' );
533537$fh -> close ;
534538unlink (' test.txt' );
535539
540+ # test coordinate strings
541+ undef $Data ;
542+ $infile = File::Spec-> catfile( $Bin , ' Data' , ' sample.bed' );
543+ $Data = Bio::ToolBox::Data-> new( in => $infile );
544+ isa_ok( $Data , ' Bio::ToolBox::Data' , ' new sample bed file object' );
545+ my $Data1 = Bio::ToolBox::Data-> new( columns => [qw( Coordinate Name) ] );
546+ isa_ok( $Data1 , ' Bio::ToolBox::Data' , ' new empty Data object with columns' );
547+ $iterate_success = $Data -> iterate(
548+ sub {
549+ my $r = shift ;
550+ my $c = $r -> coordinate;
551+ $Data1 -> add_row( [ $c , $r -> display_name ] );
552+ }
553+ );
554+ is( $Data1 -> number_rows, $Data -> number_rows, ' number of new rows' );
555+
556+ # check extraction of coordinates from string, start is transformed
557+ $row = $Data1 -> get_row(1);
558+ isa_ok( $row , ' Bio::ToolBox::Data::Feature' , ' first feature' );
559+ is( $row -> seq_id, ' chrI' , ' extracted seq_id from coordinate string' );
560+ is( $row -> start, 54989, ' extracted start from coordinate string' );
561+ is( $row -> end, 56857, ' extracted end from coordinate string' );
562+
563+ # test resorting by genomic string
564+ # but need to remove the oddball chromosome "I"
565+ is( $Data1 -> delete_row(2), 1, ' delete abnormal chromosome' );
566+
567+ # sort data first by name, then by genomic coordinate from coordinate string
568+ is( $Data1 -> sort_data( 2, ' i' ), 1, ' resort data by name' );
569+ is( $Data1 -> value( 1, 2 ), ' YAL043C' , ' check resorted first row name' );
570+ is( $Data1 -> gsort_data, 1, ' resort data by coordinate' );
571+ is( $Data1 -> value( 1, 2 ), ' YAL047C' , ' check resorted first row name' );
572+ is( $Data1 -> value( 4, 2 ), ' YAL043C' , ' check resorted last row name' );
573+
0 commit comments