Debian Codegraph @

t/Bio/Tradis/Map.t

raw
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use File::Temp;
5 use Test::Files;
6
7 BEGIN {
8 unshift( @INC, '../lib' );
9 unshift( @INC, './lib' );
10 }
11
12 BEGIN {
13 use Test::Most;
14 use_ok('Bio::Tradis::Map');
15 }
16
17 my $destination_directory_obj = File::Temp->newdir( CLEANUP => 1 );
18 my $destination_directory = $destination_directory_obj->dirname();
19
20 my ( $fastqfile, $ref, $obj, $refname, $outfile );
21
22 $fastqfile = "t/data/Map/test.fastq";
23 $ref = "t/data/Map/smallref.fa";
24 $refname = "t/data/Map/test.ref";
25 $outfile = "t/data/Map/mapped.out";
26
27 ok(
28 $obj = Bio::Tradis::Map->new(
29 fastqfile => $fastqfile,
30 reference => $ref,
31 refname => $refname,
32 outfile => $outfile,
33 smalt => 1
34 ),
35 'creating object'
36 );
37 ok( $obj->index_ref, 'testing reference indexing' );
38 ok( -e 't/data/Map/test.ref.sma', 'checking index file existence' );
39 ok( -e 't/data/Map/test.ref.smi', 'checking index file existence' );
40
41 ok( $obj->do_mapping, 'testing smalt mapping' );
42 ok( -e 't/data/Map/mapped.out', 'checking index file existence' );
43 system("grep -v ^\@ t/data/Map/mapped.out > mapped.nohead.out");
44 system("grep -v ^\@ t/data/Map/expected.smalt.mapped > expected.smalt.nohead.mapped");
45 compare_ok(
46 'mapped.nohead.out',
47 'expected.smalt.nohead.mapped',
48 'checking file contents'
49 );
50
51 ok(
52 $obj = Bio::Tradis::Map->new(
53 fastqfile => $fastqfile,
54 reference => $ref,
55 refname => $refname,
56 outfile => $outfile,
57 smalt => 0
58 ),
59 'creating object'
60 );
61 ok( $obj->index_ref, 'testing reference indexing' );
62 ok( -e 't/data/Map/smallref.fa.amb', 'checking index file existence' );
63 ok( -e 't/data/Map/smallref.fa.ann', 'checking index file existence' );
64 ok( -e 't/data/Map/smallref.fa.bwt', 'checking index file existence' );
65 ok( -e 't/data/Map/smallref.fa.pac', 'checking index file existence' );
66 ok( -e 't/data/Map/smallref.fa.sa', 'checking index file existence' );
67
68
69 ok( $obj->do_mapping, 'testing bwa mapping' );
70 ok( -e 't/data/Map/mapped.out', 'checking index file existence' );
71 system("grep -v ^\@ t/data/Map/mapped.out > mapped.nohead.out");
72 system("grep -v ^\@ t/data/Map/expected.bwa.mapped > expected.bwa.nohead.mapped");
73 compare_ok(
74 'mapped.nohead.out',
75 'expected.bwa.nohead.mapped',
76 'checking file contents'
77 );
78
79 # test optional smalt parameters
80 ok(
81 $obj = Bio::Tradis::Map->new(
82 fastqfile => $fastqfile,
83 reference => $ref,
84 refname => $refname,
85 outfile => $outfile,
86 smalt => 1,
87 smalt_k => 10,
88 smalt_s => 10,
89 smalt_y => 0.9
90 ),
91 'creating object'
92 );
93
94 my $index_smalt_cmd = $obj->index_ref;
95 my $index_smalt_exp = "smalt index -k 10 -s 10 $refname $ref > /dev/null 2>&1";
96 is( $index_smalt_cmd, $index_smalt_exp, "indexing args correct" );
97
98 my $map_smalt_cmd = $obj->do_mapping;
99 my $map_smalt_exp = "smalt map -n 1 -x -r -1 -y 0.9 $refname $fastqfile 1> $outfile 2> align.stderr";
100 is( $map_smalt_cmd, $map_smalt_exp, "mapping args correct" );
101
102
103 unlink('t/data/Map/test.ref.sma');
104 unlink('t/data/Map/test.ref.smi');
105 unlink('t/data/Map/mapped.out');
106 unlink('t/data/Map/smallref.fa.amb');
107 unlink('t/data/Map/smallref.fa.ann');
108 unlink('t/data/Map/smallref.fa.bwt');
109 unlink('t/data/Map/smallref.fa.pac');
110 unlink('t/data/Map/smallref.fa.sa');
111 done_testing();