File Coverage

blib/lib/BioX/Workflow/StructureOutput.pm
Criterion Covered Total %
statement 20 32 62.5
branch 3 6 50.0
condition n/a
subroutine 2 3 66.6
pod 1 2 50.0
total 26 43 60.4


line stmt bran cond sub pod time code
1             package BioX::Workflow::StructureOutput;
2              
3 2     2   1045 use Moose::Role;
  2         3  
  2         15  
4              
5             =head1 BioX::Workflow::StructureOutput
6              
7             BioX::Workflow does the best it can to create an easy to parse directory structure.
8              
9             Options are either files or directories, and for the most part can output looks like:
10              
11             #Global indir - our raw data
12             data/raw
13             #Global outdir - our processed/analyzed data
14             data/processed
15             rule1
16             rule2
17              
18             Or if by_sample_outdir
19             data/processed
20             Sample1/rule1
21             Sample1/rule2
22              
23             =head2 Variables
24              
25             =head3 coerce_paths
26              
27             Coerce relative path directories in variables: indir, outdir, and other variables ending in _dir to full path names
28              
29             =cut
30              
31             has 'coerce_paths' => (
32             is => 'rw',
33             isa => 'Bool',
34             default => 1,
35             predicate => 'has_coerce_paths',
36             );
37              
38             =head3 min
39              
40             Print the workflow as 2 files.
41              
42             #run-workflow.sh
43             export SAMPLE=sampleN && ./run_things
44              
45             Instead of each sample having its own command, have sample exported as an environmental variable.
46              
47             This option is probably less ideal when working on an HPC cluster.
48              
49             =cut
50              
51             has 'min' => (
52             is => 'rw',
53             isa => 'Bool',
54             default => 0,
55             );
56              
57             =head2 Subroutines
58              
59             =cut
60              
61             sub write_min_files {
62 0     0 0 0 my ($self) = shift;
63              
64 0 0       0 open( my $fh, '>', 'run-workflow.sh' )
65             or die print "Could not open file $!\n";
66              
67 0         0 print $fh "#!/bin/bash\n\n";
68              
69 0         0 my $cwd = getcwd();
70 0         0 foreach my $sample ( @{ $self->samples } ) {
  0         0  
71 0         0 print $fh <<EOF;
72             export SAMPLE=$sample && ./workflow.sh
73             EOF
74             }
75              
76 0         0 close $fh;
77              
78 0         0 chmod 0777, 'run-workflow.sh';
79              
80 0         0 $self->samples( ["\${SAMPLE}"] );
81             }
82              
83             =head3 process_by_sample_outdir
84              
85             Make sure indir/outdirs are named appropriated for samples when using by
86              
87             =cut
88              
89             sub process_by_sample_outdir {
90 30     30 1 39 my $self = shift;
91 30         38 my $sample = shift;
92              
93 30         32 my ( $tt, $key );
94 30         670 $tt = $self->outdir;
95 30         603 $key = $self->key;
96 30         170 $tt =~ s/$key/$sample\/$key/;
97 30         923 $self->outdir($tt);
98 30         94 $self->make_outdir;
99 30         5713 $self->attr->set( 'outdir' => $self->outdir );
100              
101 30         2340 $tt = $self->indir;
102 30 50       93 if ( $tt =~ m/\{\$self/ ) {
    100          
103 0         0 $tt = "$tt/{\$sample}";
104 0         0 $self->indir($tt);
105             }
106             elsif ( $self->has_pkey ) {
107 20         410 $key = $self->pkey;
108 20         95 $tt =~ s/$key/$sample\/$key/;
109 20         595 $self->indir($tt);
110             }
111             else {
112 10         23 $tt = "$tt/$sample";
113 10         236 $self->indir($tt);
114             }
115 30         646 $self->attr->set( 'indir' => $self->indir );
116             }
117              
118             1;