Debian Codegraph @

t/Bio/Tradis/AddTagsToSeq.t

raw
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use File::Temp;
5 use Test::Files qw(compare_ok);
6
7 BEGIN { unshift( @INC, './lib' ) }
8 BEGIN { unshift( @INC, '../lib' ) }
9 BEGIN {
10 use Test::Most;
11 use_ok('Bio::Tradis::AddTagsToSeq');
12 }
13 my $samtools_exec = 'samtools';
14
15 my $destination_directory_obj = File::Temp->newdir( CLEANUP => 1 );
16 my $destination_directory = $destination_directory_obj->dirname();
17
18 my ( $bamfile, $obj );
19
20 $bamfile = "t/data/AddTags/sample_sm_tr.bam";
21
22 ok(
23 $obj = Bio::Tradis::AddTagsToSeq->new(
24 bamfile => $bamfile,
25 script_name => 'name_of_script',
26 outfile => 't/data/output.bam'
27 ),
28 'creating object'
29 );
30
31 is($obj->_output_switch, '-b', 'correctly select the bam output switch');
32
33 ok( $obj->add_tags_to_seq, 'testing output' );
34 ok( -e 't/data/output.bam', 'checking file existence' );
35 `$samtools_exec view -h -o t/data/output.sam t/data/output.bam`;
36 `$samtools_exec view -h -o t/data/AddTags/expected_tradis.sam t/data/AddTags/expected_tradis.bam`;
37 compare_ok(
38 't/data/output.sam',
39 't/data/AddTags/expected_tradis.sam',
40 'checking file contents'
41 );
42
43
44 $bamfile = "t/data/AddTags/sample_sm_no_tr.bam";
45 ok(
46 $obj = Bio::Tradis::AddTagsToSeq->new(
47 bamfile => $bamfile,
48 script_name => 'name_of_script',
49 outfile => 't/data/output.bam'
50 ),
51 'creating object'
52 );
53 ok( -e 't/data/output.bam', 'checking file existence' );
54 `$samtools_exec view -h -o t/data/output.sam t/data/output.bam`;
55 `$samtools_exec view -h -o t/data/AddTags/sample_sm_no_tr.sam t/data/AddTags/sample_sm_no_tr.bam`;
56
57 compare_ok (
58 't/data/AddTags/sample_sm_no_tr.sam',
59 't/data/output.sam',
60 'checking file contents'
61 );
62
63 is(
64 6,
65 $obj->_number_of_lines_in_bam_file('t/data/AddTags/sample_sm_no_tr.bam'),
66 'number of reads as expected'
67 );
68
69 my $cramfile = "t/data/AddTags/sample_sm_tr.cram";
70
71 ok(
72 $obj = Bio::Tradis::AddTagsToSeq->new(
73 bamfile => $cramfile,
74 script_name => 'name_of_script',
75 outfile => 't/data/output.cram'
76 ),
77 'creating object with cram file'
78 );
79
80 is($obj->_output_switch, '-C', 'correctly select the cram output switch');
81
82 ok( $obj->add_tags_to_seq, 'testing output' );
83 ok( -e 't/data/output.cram', 'checking file existence' );
84 `$samtools_exec view -h -o t/data/output.sam t/data/output.cram`;
85 `$samtools_exec view -h -o t/data/AddTags/expected_tradis.sam t/data/AddTags/expected_tradis.cram`;
86 compare_ok(
87 't/data/output.sam',
88 't/data/AddTags/expected_tradis.sam',
89 'checking file contents'
90 );
91
92
93 unlink('t/data/output.cram');
94 unlink('t/data/output.bam');
95 unlink('t/data/output.sam');
96 unlink('t/data/AddTags/expected_tradis.sam');
97 unlink('t/data/AddTags/sample_sm_no_tr.sam');
98 done_testing();