9 $home = '.'; # set to '.' for Build use,
10 # '..' for debugging from .t file
13 test_begin(-tests => 41,
14 -requires_modules => [qw(IPC::Run Bio::Tools::Run::Samtools)]);
18 use Bio::Tools::Run::WrapperBase;
20 ok my $samt = Bio::Tools::Run::Samtools->new(
24 ), "make a factory using command 'pileup'";
25 # ParameterBaseI compliance : really AssemblerBase tests...
26 ok $samt->parameters_changed, "parameters changed on construction";
27 ok $samt->refseq, "access parameter";
28 ok !$samt->parameters_changed, "parameters_changed cleared on read";
29 ok $samt->set_parameters( -n_haplos => 4 ), "set a param not set in constructor";
30 ok $samt->parameters_changed, "parameters_changed set";
31 is ($samt->n_haplos, 4, "parameter really set");
32 is ($samt->refseq, 'my.fas', "original parameter unchanged");
33 ok !$samt->parameters_changed, "parameters_changed cleared on read";
34 ok $samt->set_parameters( -refseq => 'their.fas' ), "change an original parameter";
35 is ($samt->refseq, 'their.fas', "parameter really changed");
36 ok $samt->reset_parameters( -refseq => 'our.fas' ), "reset parameters with arg";
37 ok !$samt->theta, "original parameters undefined";
38 is ($samt->refseq, 'our.fas', "parameter really reset via arg");
40 $samt->set_parameters(
45 ok $samt->parameters_changed, "parameters changed";
47 is( scalar $samt->available_parameters, 14, "all available options");
48 is( scalar $samt->available_parameters('params'), 9, "available parameters" );
49 is( scalar $samt->available_parameters('switches'), 5, "available switches" );
50 my %pms = $samt->get_parameters;
52 { command => 'pileup',
54 theta => 0.05 }, "get_parameters correct");
55 is( $samt->command, 'pileup', "command attribute set");
57 is_deeply( $samt->{_options}->{_commands},
58 [@Bio::Tools::Run::Samtools::program_commands],
59 "internal command array set" );
61 is_deeply( $samt->{_options}->{_prefixes},
62 {%Bio::Tools::Run::Samtools::command_prefixes},
63 "internal prefix hash set");
65 is_deeply( $samt->{_options}->{_params},
66 [qw( command refseq map_qcap ref_list site_list theta n_haplos exp_hap_diff indel_prob )],
67 "commands filtered by prefix");
70 my @a = @{$samt->_translate_params};
71 is shift @a, 'pileup', 'translate_params: command correct';
74 (/^-/) ? ( $h{$k = $_} = undef ) : ( $h{$k} = $_ );
76 is_deeply( \%h, { '-T' => 0.05, '-f' => 'my.fas' }, 'translate_params: options correct');
80 test_skip( -requires_executable => $samt,
83 my $new_bam = Bio::Tools::Run::Samtools->new(
86 -obm => 'output_file.bam',
87 -ibm => ['t/data/Ft.bam', 't/data/Ft.bam'],
90 ok($new_bam, 'merge bam factory instantiated');
91 ok(-f 'output_file.bam', 'merged bam file created');
92 unlink('output_file.bam');
95 for (qw(refseq bamfile samfile rtbamfile sorted_bamfile fai bai)) {
96 $tmpfiles{$_} = test_output_file();
98 copy(test_input_file('Ft.bam'), $tmpfiles{bamfile}) or die "copy failed (1)";
99 copy(test_input_file('Ft.frag.fas'), $tmpfiles{refseq}) or die "copy failed (2)";
100 ok $samt = Bio::Tools::Run::Samtools->new( -command => 'faidx' ), "fasta index factory";
101 ok $samt->run( -fas => $tmpfiles{refseq}, -out => $tmpfiles{fai}), "make fasta index";
102 ok -e $tmpfiles{fai}, "fai file present";
103 ok $samt = Bio::Tools::Run::Samtools->new( -command => 'view' ), "bam -> sam cvt factory";
105 ok $samt->run( -bam => $tmpfiles{bamfile}, -out => $tmpfiles{samfile} ), "convert bam -> sam";
106 ok -T $tmpfiles{samfile}, "sam file present and text";
107 ok $samt->set_parameters( -sam_input => 1, -bam_output => 1, -refseq => $tmpfiles{refseq} ), "sam -> bam cvt factory";
108 ok $samt->run( -bam => $tmpfiles{samfile}, -out => $tmpfiles{rtbamfile} ), "convert sam -> bam";
109 ok -B $tmpfiles{rtbamfile}, "bam file present and binary";
111 ok $samt = Bio::Tools::Run::Samtools->new( -command => 'sort' ), 'bam sort factory';
112 ok $samt->run( -bam => $tmpfiles{rtbamfile}, -pfx => 'sorted_bam'), 'sort bam file';
114 ok $samt = Bio::Tools::Run::Samtools->new( -command => 'index' ), 'bam index factory';
115 ok $samt->run( -bam => 'sorted_bam', -out => $tmpfiles{bai}), 'make bam index';
116 ok -B $tmpfiles{bai}, 'bai file present and binary';
118 unlink('sorted_bam');