Skip to content

Commit

Permalink
Merge 151dc98 into b849964
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikstranneheim committed Nov 19, 2019
2 parents b849964 + 151dc98 commit 153a173
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 150 deletions.
74 changes: 34 additions & 40 deletions lib/MIP/Program/Qc/Multiqc.pm → lib/MIP/Program/Multiqc.pm
@@ -1,19 +1,22 @@
package MIP::Program::Qc::Multiqc;
package MIP::Program::Multiqc;

use 5.026;
use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use open qw{ :encoding(UTF-8) :std };
use Params::Check qw{ allow check last_error };
use strict;
use utf8;
use warnings;
use warnings qw{ FATAL utf8 };
use utf8;
use open qw{ :encoding(UTF-8) :std };
use charnames qw{ :full :short };
use Carp;
use English qw{ -no_match_vars };
use Params::Check qw{ check allow last_error };

## CPANM
use autodie qw{ :all };
use Readonly;

## MIPs lib/
use MIP::Constants qw{ $SPACE };
use MIP::Unix::Standard_streams qw{ unix_standard_streams };
use MIP::Unix::Write_to_file qw{ unix_write_to_file };

Expand All @@ -22,100 +25,91 @@ BEGIN {
use base qw{ Exporter };

# Set the version for version checking
our $VERSION = 1.00;
our $VERSION = 1.01;

# Functions and variables which can be optionally exported
our @EXPORT_OK = qw{ multiqc };
}

## Constants
Readonly my $SPACE => q{ };

sub multiqc {

## Function : Perl wrapper for writing multiqc recipe to already open $filehandle or return commands array. Based on multiqc 0.8.dev0.
## Returns : "@commands"
## Arguments : $indir_path => Indir path
## Returns : @commands
## Arguments : $filehandle => Filehandle to write to
## : $force => Force overwrite of output files
## : $indir_path => Indir path
## : $outdir_path => Outdir path
## : $stderrfile_path => Stderrfile path
## : $stdoutfile_path => Stdoutfile path
## : $filehandle => Filehandle to write to
## : $stderrfile_path_append => Append stderr info to file
## : $force => Force overwrite of output files
## : $stdoutfile_path => Stdoutfile path

my ($arg_href) = @_;

## Flatten argument(s)
my $filehandle;
my $indir_path;
my $outdir_path;
my $stdoutfile_path;
my $stderrfile_path;
my $stderrfile_path_append;
my $filehandle;
my $stdoutfile_path;

## Default(s)
my $force;

my $tmpl = {
filehandle => { store => \$filehandle, },
force => {
allow => [ 0, 1 ],
default => 0,
store => \$force,
strict_type => 1,
},
indir_path => {
required => 1,
defined => 1,
required => 1,
store => \$indir_path,
strict_type => 1,
store => \$indir_path
},
outdir_path => { strict_type => 1, store => \$outdir_path },
stderrfile_path => { strict_type => 1, store => \$stderrfile_path },
stdoutfile_path => { strict_type => 1, store => \$stdoutfile_path },
filehandle => { store => \$filehandle },
outdir_path => { store => \$outdir_path, strict_type => 1, },
stderrfile_path => { store => \$stderrfile_path, strict_type => 1, },
stderrfile_path_append =>
{ strict_type => 1, store => \$stderrfile_path_append },
force => {
default => 0,
allow => [ 0, 1 ],
strict_type => 1,
store => \$force
},
{ store => \$stderrfile_path_append, strict_type => 1, },
stdoutfile_path => { store => \$stdoutfile_path, strict_type => 1, },
};

check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

# Stores commands depending on input parameters
my @commands = q{multiqc};
my @commands = qw{ multiqc };

## Options
if ($force) {

push @commands, q{--force};
}

## Outdir
if ($outdir_path) {

push @commands, q{--outdir} . $SPACE . $outdir_path;
}

## Indir
push @commands, $indir_path;

push @commands,
unix_standard_streams(
{
stdoutfile_path => $stdoutfile_path,
stderrfile_path => $stderrfile_path,
stderrfile_path_append => $stderrfile_path_append,
stdoutfile_path => $stdoutfile_path,
}
);

unix_write_to_file(
{
commands_ref => \@commands,
separator => $SPACE,
filehandle => $filehandle,
separator => $SPACE,
}
);

return @commands;

}

1;
4 changes: 2 additions & 2 deletions lib/MIP/Recipes/Analysis/Multiqc.pm
Expand Up @@ -25,7 +25,7 @@ BEGIN {
use base qw{ Exporter };

# Set the version for version checking
our $VERSION = 1.11;
our $VERSION = 1.12;

# Functions and variables which can be optionally exported
our @EXPORT_OK = qw{ analysis_multiqc };
Expand Down Expand Up @@ -127,7 +127,7 @@ sub analysis_multiqc {
use MIP::Get::Parameter qw{ get_recipe_attributes get_recipe_resources };
use MIP::Parse::File qw{ parse_io_outfiles };
use MIP::Processmanagement::Processes qw{ submit_recipe };
use MIP::Program::Qc::Multiqc qw{ multiqc };
use MIP::Program::Multiqc qw{ multiqc };
use MIP::Script::Setup_script qw{ setup_script };
use MIP::Sample_info qw{ set_recipe_metafile_in_sample_info };

Expand Down
147 changes: 39 additions & 108 deletions t/multiqc.t
@@ -1,93 +1,57 @@
#!/usr/bin/env perl

use Modern::Perl qw{ 2018 };
use warnings qw{ FATAL utf8 };
use autodie;
use 5.026;
use utf8;
use open qw{ :encoding(UTF-8) :std };
use charnames qw{ :full :short };
use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use Params::Check qw{ check allow last_error };

use FindBin qw{ $Bin };
use File::Basename qw{ dirname basename };
use File::Basename qw{ dirname };
use File::Spec::Functions qw{ catdir catfile };
use Getopt::Long;
use FindBin qw{ $Bin };
use open qw{ :encoding(UTF-8) :std };
use Params::Check qw{ allow check last_error };
use Test::More;
use utf8;
use warnings qw{ FATAL utf8 };

## CPANM
use autodie qw{ :all };
use Modern::Perl qw{ 2018 };
use Readonly;

## MIPs lib/
use lib catdir( dirname($Bin), q{lib} );
use MIP::Script::Utils qw{ help };

our $USAGE = build_usage( {} );
use MIP::Constants qw{ $COMMA $SPACE };
use MIP::Test::Commands qw{ test_function };
use MIP::Test::Fixtures qw{ test_standard_cli };

my $VERBOSE = 1;
our $VERSION = 1.0.0;

## Constants
Readonly my $SPACE => q{ };
Readonly my $NEWLINE => qq{\n};
Readonly my $COMMA => q{,};

### User Options
GetOptions(

# Display help text
q{h|help} => sub {
done_testing();
say {*STDOUT} $USAGE;
exit;
},
our $VERSION = 1.01;

# Display version number
q{v|version} => sub {
done_testing();
say {*STDOUT} $NEWLINE . basename($PROGRAM_NAME) . $SPACE . $VERSION . $NEWLINE;
exit;
},
q{vb|verbose} => $VERBOSE,
)
or (
done_testing(),
help(
{
USAGE => $USAGE,
exit_code => 1,
}
)
);
$VERBOSE = test_standard_cli(
{
verbose => $VERBOSE,
version => $VERSION,
}
);

BEGIN {

use MIP::Test::Fixtures qw{ test_import };

### Check all internal dependency modules and imports
## Modules with import
my %perl_module;

$perl_module{q{MIP::Script::Utils}} = [qw{ help }];

PERL_MODULE:
while ( my ( $module, $module_import ) = each %perl_module ) {
use_ok( $module, @{$module_import} )
or BAIL_OUT q{Cannot load} . $SPACE . $module;
}

## Modules
my @modules = (q{MIP::Program::Qc::Multiqc});
my %perl_module = (
q{MIP::Program::Multiqc} => [qw{ multiqc }],
q{MIP::Test::Fixtures} => [qw{ test_standard_cli }],
);

MODULE:
for my $module (@modules) {
require_ok($module) or BAIL_OUT q{Cannot load} . $SPACE . $module;
}
test_import( { perl_module_href => \%perl_module, } );
}

use MIP::Program::Qc::Multiqc qw{ multiqc };
use MIP::Test::Commands qw{ test_function };
use MIP::Program::Multiqc qw{ multiqc };

diag( q{Test multiqc from Multiqc v}
. $MIP::Program::Qc::Multiqc::VERSION
. $MIP::Program::Multiqc::VERSION
. $COMMA
. $SPACE . q{Perl}
. $SPACE
Expand All @@ -99,9 +63,9 @@ diag( q{Test multiqc from Multiqc v}
my @function_base_commands = qw{ multiqc };

my %base_argument = (
stdoutfile_path => {
input => q{stdoutfile.test},
expected_output => q{1> stdoutfile.test},
filehandle => {
input => undef,
expected_output => \@function_base_commands,
},
stderrfile_path => {
input => q{stderrfile.test},
Expand All @@ -111,9 +75,9 @@ my %base_argument = (
input => q{stderrfile.test},
expected_output => q{2>> stderrfile.test},
},
filehandle => {
input => undef,
expected_output => \@function_base_commands,
stdoutfile_path => {
input => q{stdoutfile.test},
expected_output => q{1> stdoutfile.test},
},
);

Expand Down Expand Up @@ -144,45 +108,12 @@ foreach my $argument_href (@arguments) {
my @commands = test_function(
{
argument_href => $argument_href,
required_argument_href => \%required_argument,
module_function_cref => $module_function_cref,
function_base_commands_ref => \@function_base_commands,
do_test_base_command => 1,
function_base_commands_ref => \@function_base_commands,
module_function_cref => $module_function_cref,
required_argument_href => \%required_argument,
}
);
}

done_testing();

######################
####SubRoutines#######
######################

sub build_usage {

## Function : Build the USAGE instructions
## Returns :
## Arguments : $program_name => Name of the script

my ($arg_href) = @_;

## Default(s)
my $program_name;

my $tmpl = {
program_name => {
default => basename($PROGRAM_NAME),
strict_type => 1,
store => \$program_name,
},
};

check( $tmpl, $arg_href, 1 ) or croak q{Could not parse arguments!};

return <<"END_USAGE";
$program_name [options]
-vb/--verbose Verbose
-h/--help Display this help message
-v/--version Display version
END_USAGE
}

0 comments on commit 153a173

Please sign in to comment.