|
| 1 | +package TestsFor::BioX::Workflow::Command::run::Test007; |
| 2 | + |
| 3 | +use Test::Class::Moose; |
| 4 | +use Cwd; |
| 5 | +use FindBin qw($Bin); |
| 6 | +use File::Path qw(make_path remove_tree); |
| 7 | +use Data::Dumper; |
| 8 | +use Capture::Tiny ':all'; |
| 9 | +use BioX::Workflow::Command; |
| 10 | +use YAML::XS; |
| 11 | +use Data::Walk; |
| 12 | +use File::Slurp; |
| 13 | +use File::Spec; |
| 14 | +use DateTime; |
| 15 | +use DateTime::Format::Strptime; |
| 16 | +use Storable qw(dclone); |
| 17 | + |
| 18 | +extends 'TestMethod::Base'; |
| 19 | + |
| 20 | +sub write_test_file { |
| 21 | + my $test_dir = shift; |
| 22 | + |
| 23 | + my $fh; |
| 24 | + my $href = { |
| 25 | + global => [ |
| 26 | + { sample_rule => "Sample_.*" }, |
| 27 | + { root_dir => 'data/raw' }, |
| 28 | + { indir => '{$self->root_dir}' }, |
| 29 | + { outdir => 'data/processed' }, |
| 30 | + { find_sample_bydir => 1 }, |
| 31 | + { by_sample_outdir => 1 }, |
| 32 | + { chroms_list => [1,2,3,4,5]}, |
| 33 | + { samples => ['Sample_01']}, |
| 34 | + ], |
| 35 | + rules => [ |
| 36 | + { |
| 37 | + t3_rule1 => { |
| 38 | + 'local' => [ |
| 39 | + { root_dir => 'data/raw' }, |
| 40 | + { |
| 41 | + INPUT => |
| 42 | +'{$self->root_dir}/{$sample}/some_input_rule1.{$self->chunk}' |
| 43 | + }, |
| 44 | + { OUTPUT => ['some_output_rule1'] }, |
| 45 | + { use_chunks => 1 }, |
| 46 | + ], |
| 47 | + process => |
| 48 | +'R1: INDIR: {$self->indir} INPUT: {$self->INPUT} outdir: {$self->outdir} OUTPUT: {$self->OUTPUT->[0]}', |
| 49 | + }, |
| 50 | + }, |
| 51 | + ] |
| 52 | + }; |
| 53 | + |
| 54 | + #Write out the config |
| 55 | + open( $fh, ">$test_dir/conf/test1.1.yml" ) |
| 56 | + or die print "Couldn't open file! $!"; |
| 57 | + my $yaml = Dump $href; |
| 58 | + print $fh $yaml; |
| 59 | + close($fh); |
| 60 | + |
| 61 | + make_path( $test_dir . "/data/raw/Sample_01" ); |
| 62 | + make_path( $test_dir . "/data/raw/Sample_02" ); |
| 63 | + write_file( $test_dir . "/data/raw/Sample_01/" . "some_input_rule1" ); |
| 64 | + write_file( $test_dir . "/data/raw/Sample_02/" . "some_input_rule1" ); |
| 65 | +} |
| 66 | + |
| 67 | +sub construct_tests { |
| 68 | + my $test_methods = TestMethod::Base->new(); |
| 69 | + my $test_dir = $test_methods->make_test_dir(); |
| 70 | + write_test_file($test_dir); |
| 71 | + |
| 72 | + my $t = "$test_dir/conf/test1.1.yml"; |
| 73 | + my $test = $test_methods->make_test_env($t); |
| 74 | + my $rules = $test->workflow_data->{rules}; |
| 75 | + |
| 76 | + return ( $test, $test_dir, $rules ); |
| 77 | +} |
| 78 | + |
| 79 | +sub test_001 { |
| 80 | + my ( $test, $test_dir, $rules ) = construct_tests; |
| 81 | + |
| 82 | + $test->check_sample_exist; |
| 83 | + is_deeply($test->samples, ['Sample_01']); |
| 84 | + is_deeply($test->global_attr->chroms_list, [1,2,3,4,5]); |
| 85 | + |
| 86 | + # $test->stdout(1); |
| 87 | + $test->set_rule_names; |
| 88 | + $test->filter_rule_keys; |
| 89 | + |
| 90 | + foreach my $rule ( @{$rules} ) { |
| 91 | + _init_rule( $test, $rule ); |
| 92 | + } |
| 93 | + |
| 94 | + $test->post_process_rules; |
| 95 | + is_deeply($test->samples, ['Sample_01']); |
| 96 | + |
| 97 | + diag Dumper ($test->global_attr->chroms_list); |
| 98 | + diag Dumper ($test->global_attr->samples); |
| 99 | + diag Dumper($test->global_attr->has_samples); |
| 100 | + |
| 101 | + |
| 102 | + ok(1); |
| 103 | +} |
| 104 | + |
| 105 | + |
| 106 | +sub _init_rule { |
| 107 | + my $test = shift; |
| 108 | + my $rule = shift; |
| 109 | + |
| 110 | + $test->local_rule($rule); |
| 111 | + $test->process_rule; |
| 112 | + $test->p_rule_name( $test->rule_name ); |
| 113 | + $test->p_local_attr( dclone( $test->local_attr ) ); |
| 114 | +} |
0 commit comments