| 1 |
#!/usr/bin/env perl |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Cwd; |
| 5 |
use File::Path 'rmtree'; |
| 6 |
use File::Temp; |
| 7 |
|
| 8 |
BEGIN { unshift( @INC, './lib' ) } |
| 9 |
BEGIN { unshift( @INC, '../lib' ) } |
| 10 |
|
| 11 |
BEGIN { |
| 12 |
use Test::Most; |
| 13 |
use Test::Exception; |
| 14 |
use_ok('Bio::Tradis::CommandLine::TradisAnalysis'); |
| 15 |
} |
| 16 |
|
| 17 |
# Tag which is found in both inputs |
| 18 |
my $output_directory_obj = File::Temp->newdir( 'tmp_TradisAnalysis_tests_XXXXX', |
| 19 |
CLEANUP => 0, |
| 20 |
DIR => cwd() ); |
| 21 |
my $output_directory = $output_directory_obj->dirname; |
| 22 |
|
| 23 |
ok( |
| 24 |
my $obj = Bio::Tradis::CommandLine::TradisAnalysis->new( |
| 25 |
args => ['-f', 't/data/CommandLine/fastq.list', '-t', |
| 26 |
"TAAGAGTCAG", '-r', "t/data/RunTradisSmalt/smallref.fa"], |
| 27 |
script_name => 'bacteria_tradis_test', |
| 28 |
_output_directory => $output_directory |
| 29 |
), |
| 30 |
'creating object' |
| 31 |
); |
| 32 |
|
| 33 |
ok( $obj->run, 'testing run' ); |
| 34 |
|
| 35 |
open(STATS, "$output_directory/fastq.stats") or die "Could not open stats file"; |
| 36 |
my $line_count = 0; |
| 37 |
while (<STATS>) { $line_count++; } |
| 38 |
is( $line_count, 3, "both files have reads with tag"); |
| 39 |
rmtree($output_directory); |
| 40 |
|
| 41 |
# Only one file has a read with the given tag |
| 42 |
$output_directory_obj = File::Temp->newdir( 'tmp_TradisAnalysis_tests_XXXXX', |
| 43 |
CLEANUP => 0, |
| 44 |
DIR => cwd() ); |
| 45 |
$output_directory = $output_directory_obj->dirname; |
| 46 |
|
| 47 |
$obj = Bio::Tradis::CommandLine::TradisAnalysis->new( |
| 48 |
args => ['-f', 't/data/CommandLine/fastq.list', '-t', |
| 49 |
"CGCACAGCCG", '-r', "t/data/RunTradisSmalt/smallref.fa"], |
| 50 |
script_name => 'bacteria_tradis_test', |
| 51 |
_output_directory => $output_directory |
| 52 |
); |
| 53 |
|
| 54 |
{ |
| 55 |
my $warning_counter = 0; |
| 56 |
local $SIG{'__WARN__'} = sub { $warning_counter++; }; |
| 57 |
ok( $obj->run, 'testing run with tag only found in one fastq' ); |
| 58 |
is( $warning_counter, 1, "one warning raised" ); |
| 59 |
} |
| 60 |
open(STATS, "$output_directory/fastq.stats") or die "Could not open stats file"; |
| 61 |
$line_count = 0; |
| 62 |
while (<STATS>) { $line_count++; } |
| 63 |
is( $line_count, 2, "only one input fastq has reads with tag"); |
| 64 |
rmtree($output_directory); |
| 65 |
|
| 66 |
# Neither fastq input has a read with the given tag |
| 67 |
$output_directory_obj = File::Temp->newdir( 'tmp_TradisAnalysis_tests_XXXXX', |
| 68 |
CLEANUP => 0, |
| 69 |
DIR => cwd() ); |
| 70 |
$output_directory = $output_directory_obj->dirname; |
| 71 |
|
| 72 |
$obj = Bio::Tradis::CommandLine::TradisAnalysis->new( |
| 73 |
args => ['-f', 't/data/CommandLine/fastq.list', '-t', |
| 74 |
"AAAAAAAAAA", '-r', "t/data/RunTradisSmalt/smallref.fa"], |
| 75 |
script_name => 'bacteria_tradis_test', |
| 76 |
_output_directory => $output_directory |
| 77 |
); |
| 78 |
|
| 79 |
{ |
| 80 |
my $warning_counter = 0; |
| 81 |
local $SIG{'__WARN__'} = sub { $warning_counter++; }; |
| 82 |
throws_ok {$obj->run} 'Bio::Tradis::Exception::TagFilterError', 'testing run without tag in either fastq'; |
| 83 |
is( $warning_counter, 2, "two warnings raised" ); |
| 84 |
} |
| 85 |
open(STATS, "$output_directory/fastq.stats") or die "Could not open stats file"; |
| 86 |
$line_count = 0; |
| 87 |
while (<STATS>) { $line_count++; } |
| 88 |
is( $line_count, 0, "neither input fastq has reads with tag"); |
| 89 |
rmtree($output_directory); |
| 90 |
|
| 91 |
done_testing(); |