| 1 |
#!/usr/bin/env perl |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Cwd; |
| 5 |
use File::Path 'rmtree'; |
| 6 |
use File::Temp; |
| 7 |
use Test::Files qw(compare_ok); |
| 8 |
|
| 9 |
BEGIN { unshift( @INC, './lib' ) } |
| 10 |
BEGIN { unshift( @INC, '../lib' ) } |
| 11 |
|
| 12 |
BEGIN { |
| 13 |
use Test::Most; |
| 14 |
use Test::Exception; |
| 15 |
use_ok('Bio::Tradis::RunTradis'); |
| 16 |
} |
| 17 |
|
| 18 |
my $output_directory_obj = File::Temp->newdir( 'tmp_run_tradis_tagless_tests_XXXXX', |
| 19 |
CLEANUP => 0, |
| 20 |
DIR => cwd() ); |
| 21 |
my $output_directory = $output_directory_obj->dirname; |
| 22 |
my $temp_directory_obj = File::Temp->newdir( CLEANUP => 0, |
| 23 |
DIR => $output_directory ); |
| 24 |
my $temp_directory = $temp_directory_obj->dirname(); |
| 25 |
|
| 26 |
my ( $obj, $fastqfile, $stats_handle, $ref, $outfile, $aligner); |
| 27 |
|
| 28 |
# First, test all parts and complete pipeline without mismatch |
| 29 |
|
| 30 |
$fastqfile = "t/data/RunTradisTaglessBWA/notags.fastq"; |
| 31 |
$ref = "t/data/RunTradisTaglessBWA/smallref.fa"; |
| 32 |
$outfile = "test.plot"; |
| 33 |
$aligner = 0; |
| 34 |
open( $stats_handle, '>', "$output_directory/test.stats" ); |
| 35 |
|
| 36 |
ok( |
| 37 |
$obj = Bio::Tradis::RunTradis->new( |
| 38 |
fastqfile => $fastqfile, |
| 39 |
reference => $ref, |
| 40 |
smalt => $aligner, |
| 41 |
outfile => $outfile, |
| 42 |
output_directory => $output_directory, |
| 43 |
_temp_directory => $temp_directory, |
| 44 |
_stats_handle => $stats_handle |
| 45 |
), |
| 46 |
'creating object - Normal files, no mismatch' |
| 47 |
); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
# Mapping |
| 52 |
ok( $obj->_map, 'testing mapping' ); |
| 53 |
ok( -e "$temp_directory/mapped.sam", 'checking SAM existence' ); |
| 54 |
`grep -v "\@PG" $temp_directory/mapped.sam > $output_directory/tmp1.sam`; |
| 55 |
`grep -v "\@PG" t/data/RunTradisTaglessBWA/mapped.sam > $output_directory/tmp2.sam`; |
| 56 |
compare_ok( |
| 57 |
"$output_directory/tmp1.sam", |
| 58 |
"$output_directory/tmp2.sam", |
| 59 |
'checking mapped file contents' |
| 60 |
); |
| 61 |
|
| 62 |
# Conversion |
| 63 |
ok( $obj->_sam2bam, 'testing SAM/BAM conversion' ); |
| 64 |
ok( -e "$temp_directory/mapped.bam", 'checking BAM existence' ); |
| 65 |
|
| 66 |
# Sorting |
| 67 |
ok( $obj->_sort_bam, 'testing BAM sorting' ); |
| 68 |
ok( -e "$temp_directory/mapped.sort.bam", |
| 69 |
'checking sorted BAM existence - Normal files, no mismatch' ); |
| 70 |
ok( -e "$temp_directory/mapped.sort.bam.bai", |
| 71 |
'checking indexed BAM existence - Normal files, no mismatch' ); |
| 72 |
|
| 73 |
#Bamcheck |
| 74 |
ok( $obj->_bamcheck, 'testing bamcheck' ); |
| 75 |
ok( -e "$temp_directory/mapped.bamcheck", |
| 76 |
'checking bamcheck file existence - Normal files, no mismatch' ); |
| 77 |
|
| 78 |
# Plot |
| 79 |
ok( $obj->_make_plot, 'testing plotting' ); |
| 80 |
ok( -e "$temp_directory/test.plot.AE004091.insert_site_plot.gz", |
| 81 |
'checking plot file existence - Normal files, no mismatch' ); |
| 82 |
system( |
| 83 |
"gunzip -c $temp_directory/test.plot.AE004091.insert_site_plot.gz > $output_directory/test.plot.unzipped" |
| 84 |
); |
| 85 |
system("gunzip -c t/data/RunTradisTaglessBWA/expected.plot.gz > $output_directory/expected.plot.unzipped"); |
| 86 |
compare_ok( |
| 87 |
"$output_directory/test.plot.unzipped", |
| 88 |
"$output_directory/expected.plot.unzipped", |
| 89 |
'checking plot file contents - Normal files, no mismatch' |
| 90 |
); |
| 91 |
|
| 92 |
|
| 93 |
# Complete pipeline |
| 94 |
ok( $obj->run_tradis, 'testing complete analysis - Normal files, no mismatch' ); |
| 95 |
ok( -e "$output_directory/test.plot.AE004091.insert_site_plot.gz", |
| 96 |
'checking plot file existence - Normal files, no mismatch' ); |
| 97 |
system("gunzip -c $output_directory/test.plot.AE004091.insert_site_plot.gz > $output_directory/test.plot.unzipped"); |
| 98 |
system("gunzip -c t/data/RunTradisTaglessBWA/expected.plot.gz > $output_directory/expected.plot.unzipped"); |
| 99 |
compare_ok( |
| 100 |
"$output_directory/test.plot.unzipped", |
| 101 |
"$output_directory/expected.plot.unzipped", |
| 102 |
'checking completed pipeline file contents - Normal files, no mismatch' |
| 103 |
); |
| 104 |
|
| 105 |
unlink("$temp_directory/filter.fastq"); |
| 106 |
unlink("$temp_directory/tags_removed.fastq"); |
| 107 |
|
| 108 |
unlink("$output_directory/test.plot.AE004091.insert_site_plot.gz"); |
| 109 |
unlink("$output_directory/expected.plot.unzipped"); |
| 110 |
unlink("$output_directory/test.plot.unzipped"); |
| 111 |
|
| 112 |
$temp_directory_obj = File::Temp->newdir( CLEANUP => 0, |
| 113 |
DIR => $output_directory ); |
| 114 |
$temp_directory = $temp_directory_obj->dirname(); |
| 115 |
ok( |
| 116 |
$obj = Bio::Tradis::RunTradis->new( |
| 117 |
fastqfile => $fastqfile, |
| 118 |
reference => $ref, |
| 119 |
smalt => $aligner, |
| 120 |
outfile => $outfile, |
| 121 |
output_directory => $output_directory, |
| 122 |
_temp_directory => $temp_directory, |
| 123 |
_stats_handle => $stats_handle, |
| 124 |
k => 10, |
| 125 |
|
| 126 |
), |
| 127 |
'creating object with custom smalt parameters' |
| 128 |
); |
| 129 |
|
| 130 |
ok( $obj->_map, 'mapping with custom parameters fine' ); |
| 131 |
|
| 132 |
# Check die if ref is not found |
| 133 |
$temp_directory_obj = File::Temp->newdir( CLEANUP => 0, |
| 134 |
DIR => $output_directory ); |
| 135 |
$temp_directory = $temp_directory_obj->dirname(); |
| 136 |
ok( |
| 137 |
$obj = Bio::Tradis::RunTradis->new( |
| 138 |
fastqfile => $fastqfile, |
| 139 |
reference => "not_really_a_ref.fa", |
| 140 |
outfile => $outfile, |
| 141 |
output_directory => $output_directory, |
| 142 |
_temp_directory => $temp_directory, |
| 143 |
_stats_handle => $stats_handle, |
| 144 |
|
| 145 |
), |
| 146 |
'creating object' |
| 147 |
); |
| 148 |
throws_ok {$obj->run_tradis} 'Bio::Tradis::Exception::RefNotFound', 'correct error thrown'; |
| 149 |
|
| 150 |
unlink('t/data/RunTradisTaglessBWA/smallref.fa.amb'); |
| 151 |
unlink('t/data/RunTradisTaglessBWA/smallref.fa.ann'); |
| 152 |
unlink('t/data/RunTradisTaglessBWA/smallref.fa.bwt'); |
| 153 |
unlink('t/data/RunTradisTaglessBWA/smallref.fa.pac'); |
| 154 |
unlink('t/data/RunTradisTaglessBWA/smallref.fa.sa'); |
| 155 |
rmtree($output_directory); |
| 156 |
done_testing(); |