<commit_before>#!/usr/bin/env perl

use 5.018;
use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use File::Basename qw{ basename dirname  };
use File::Spec::Functions qw{ catdir };
use FindBin qw{ $Bin };
use Getopt::Long;
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{ 2014 };
use Readonly;

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

our $USAGE = build_usage( {} );

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

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

### User Options
GetOptions(

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

    # 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,
        }
    )
  );

BEGIN {

### Check all internal dependency modules and imports
## Modules with import
    my %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::Variantcalling::Vardict});

  MODULE:
    for my $module (@modules) {
        require_ok($module) or BAIL_OUT q{Cannot load} . $SPACE . $module;
    }
}

use MIP::Program::Variantcalling::Vardict qw{ SUB_ROUTINE };
use MIP::Test::Commands qw{ test_function };

diag(   q{Test vardict from Vardict.pm v}
      . $MIP::Program::Variantcalling::Vardict::VERSION
      . $COMMA
      . $SPACE . q{Perl}
      . $SPACE
      . $PERL_VERSION
      . $SPACE
      . $EXECUTABLE_NAME );

## Base arguments
my $function_base_command = q{vardict};

my %base_argument = (
    FILEHANDLE => {
        input           => undef,
        expected_output => $function_base_command,
    },
    stderrfile_path => {
        input           => q{stderrfile.test},
        expected_output => q{2> stderrfile.test},
    },
    stderrfile_path_append => {
        input           => q{stderrfile.test},
        expected_output => q{2>> stderrfile.test},
    },
    stdoutfile_path => {
        input           => q{stdoutfile.test},
        expected_output => q{1> stdoutfile.test},
    },
);

## Can be duplicated with %base_argument and/or %specific_argument
## to enable testing of each individual argument
my %required_argument = (
    referencefile_path => {
        input           => catfile(qw{ a test reference file }),
        expected_output => q{-G}
          . $SPACE
          . catfile(qw{ a test reference file }),
    },
    af_threshold => {
        input           => q{0.01},
        expetced_output => q{-f} . $SPACE . q{0.01},
    },
    sample_name => {
        input           => q{sample_name},
        expected_output => q{-N} . $SPACE . q{sample_name},
    },
    infile_path_tumor => {
        input           => q{an_input_tumor_bam},
        expected_output => q{an_input_tumor_bam},
    },
    out_chrom_start => {
        input           => q{out_chrom_start},
        expected_output => q{-c} . $SPACE . q{1},
    },
    out_region_start => {
        input           => q{out_region_start},
        expected_output => q{-S} . $SPACE . q{2},
    },
    out_region_end => {
        input           => q{out_region_end},
        expected_output => q{-E} . $SPACE . q{3},
    },
    out_segment_annotn => {
        input           => q{out_segment_annot},
        expected_output => q{-g} . $SPACE . q{4},
    },
    infile_bed_region_info => {
        input           => catfile(qw{ an input bed }),
        expected_output => catfile(qw{ an input bed }),
    }
);

my %specific_argument = (
    infile_path_normal => {
        input           => q{an_input_normal_bam},
        expected_output => q{an_input_normal_bam},
    }
);

my @infile_paths_ref = (
    $required_argument{infile_path_tumor}{input},
    $specific_argument{infile_path_tumor}{input}
);

$required_argument{infile_path_tumor}{input} =
  $DQUOTE . join( $PIPE, @infile_paths_ref ) . $DQUOTE;
$required_argument{infile_path_tumor}{expected_output} =
  q{-b} . $SPACE . $DQUOTE . join( $PIPE, @infile_paths_ref ) . $DQUOTE;

## Coderef - enables generalized use of generate call
my $module_function_cref = \&vardict;

## Test both base and function specific arguments
my @arguments = ( \%base_argument, \%specific_argument );

ARGUMENT_HASH_REF:
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_command  => $function_base_command,
            do_test_base_command   => 1,
        }
    );
}

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
}
<commit_msg>fixed region/chrom start/ends with a proper value<commit_after>#!/usr/bin/env perl

use 5.018;
use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use File::Basename qw{ basename dirname  };
use File::Spec::Functions qw{ catdir };
use FindBin qw{ $Bin };
use Getopt::Long;
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{ 2014 };
use Readonly;

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

our $USAGE = build_usage( {} );

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

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

### User Options
GetOptions(

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

    # 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,
        }
    )
  );

BEGIN {

### Check all internal dependency modules and imports
## Modules with import
    my %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::Variantcalling::Vardict});

  MODULE:
    for my $module (@modules) {
        require_ok($module) or BAIL_OUT q{Cannot load} . $SPACE . $module;
    }
}

use MIP::Program::Variantcalling::Vardict qw{ SUB_ROUTINE };
use MIP::Test::Commands qw{ test_function };

diag(   q{Test vardict from Vardict.pm v}
      . $MIP::Program::Variantcalling::Vardict::VERSION
      . $COMMA
      . $SPACE . q{Perl}
      . $SPACE
      . $PERL_VERSION
      . $SPACE
      . $EXECUTABLE_NAME );

## Base arguments
my $function_base_command = q{vardict};

my %base_argument = (
    FILEHANDLE => {
        input           => undef,
        expected_output => $function_base_command,
    },
    stderrfile_path => {
        input           => q{stderrfile.test},
        expected_output => q{2> stderrfile.test},
    },
    stderrfile_path_append => {
        input           => q{stderrfile.test},
        expected_output => q{2>> stderrfile.test},
    },
    stdoutfile_path => {
        input           => q{stdoutfile.test},
        expected_output => q{1> stdoutfile.test},
    },
);

## Can be duplicated with %base_argument and/or %specific_argument
## to enable testing of each individual argument
my %required_argument = (
    referencefile_path => {
        input           => catfile(qw{ a test reference file }),
        expected_output => q{-G}
          . $SPACE
          . catfile(qw{ a test reference file }),
    },
    af_threshold => {
        input           => q{0.01},
        expetced_output => q{-f} . $SPACE . q{0.01},
    },
    sample_name => {
        input           => q{sample_name},
        expected_output => q{-N} . $SPACE . q{sample_name},
    },
    infile_path_tumor => {
        input           => q{an_input_tumor_bam},
        expected_output => q{an_input_tumor_bam},
    },
    out_chrom_start => {
        input           => q{1},
        expected_output => q{-c} . $SPACE . q{1},
    },
    out_region_start => {
        input           => q{2},
        expected_output => q{-S} . $SPACE . q{2},
    },
    out_region_end => {
        input           => q{3},
        expected_output => q{-E} . $SPACE . q{3},
    },
    out_segment_annotn => {
        input           => q{4},
        expected_output => q{-g} . $SPACE . q{4},
    },
    infile_bed_region_info => {
        input           => catfile(qw{ an input bed }),
        expected_output => catfile(qw{ an input bed }),
    }
);

my %specific_argument = (
    infile_path_normal => {
        input           => q{an_input_normal_bam},
        expected_output => q{an_input_normal_bam},
    }
);

my @infile_paths_ref = (
    $required_argument{infile_path_tumor}{input},
    $specific_argument{infile_path_tumor}{input}
);

$required_argument{infile_path_tumor}{input} =
  $DQUOTE . join( $PIPE, @infile_paths_ref ) . $DQUOTE;
$required_argument{infile_path_tumor}{expected_output} =
  q{-b} . $SPACE . $DQUOTE . join( $PIPE, @infile_paths_ref ) . $DQUOTE;

## Coderef - enables generalized use of generate call
my $module_function_cref = \&vardict;

## Test both base and function specific arguments
my @arguments = ( \%base_argument, \%specific_argument );

ARGUMENT_HASH_REF:
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_command  => $function_base_command,
            do_test_base_command   => 1,
        }
    );
}

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
}

{'fraction_non_alphanumeric': 0.14708312675590812, 'fraction_numerical': 0.00561890596595604, 'mean_word_length': 2.355420016634322, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 137, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '46025', 'n_tokens_mistral': 4157, 'n_tokens_neox': 4060, 'n_words': 898}