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

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

## CPANM
use autodie;
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 $SPACE        => q{ };
Readonly my $NEWLINE      => qq{\n};
Readonly my $COMMA        => q{,};
Readonly my $HG_VERSION   => 19;
Readonly my $GRCH_VERSION => 37;

### 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::Set::Parameter});

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

use MIP::Set::Parameter qw{ set_human_genome_reference_features };
use MIP::Log::MIP_log4perl qw{ initiate_logger };

diag(   q{Test set_human_genome_reference_features from Parameter.pm v}
      . $MIP::Set::Parameter::VERSION
      . $COMMA
      . $SPACE . q{Perl}
      . $SPACE
      . $PERL_VERSION
      . $SPACE
      . $EXECUTABLE_NAME );

## Create temp logger
my $test_dir = File::Temp->newdir();
my $test_log_path = catfile( $test_dir, q{test.log} );

## Creates log object
my $log = initiate_logger(
    {
        file_path => $test_log_path,
        log_name  => q{TEST},
    }
);

my %parameter;

## Test hash
my %file_info;

## Test Ensemble genome
my $human_genome_reference = q{GRCh37_homo_sapiens_-d5-.fasta};
set_human_genome_reference_features(
    {
        file_info_href         => \%file_info,
        human_genome_reference => $human_genome_reference,
        log                    => $log,
        parameter_href         => \%parameter,
    }
);
is( $file_info{human_genome_reference_version},
    $GRCH_VERSION, q{GRCh version test} );
is( $file_info{human_genome_reference_source}, q{GRCh}, q{GRCh source test} );
is( $file_info{human_genome_reference_name_prefix},
    q{GRCh37_homo_sapiens_-d5-}, q{GRCh prefix test} );
is( $file_info{human_genome_compressed}, 0, q{GRCh compressed test} );
is( $parameter{human_genome_reference_file_endings}{build_file},
    undef, q{Did not set build file for compression } );

## Test Refseq genome
$human_genome_reference = q{hg19_homo_sapiens.fasta.gz};
set_human_genome_reference_features(
    {
        file_info_href         => \%file_info,
        human_genome_reference => $human_genome_reference,
        log                    => $log,
        parameter_href         => \%parameter,
    }
);
is( $file_info{human_genome_reference_version},
    $HG_VERSION, q{hg version test} );
is( $file_info{human_genome_reference_source}, q{hg}, q{hg source test} );
is( $file_info{human_genome_reference_name_prefix},
    q{hg19_homo_sapiens}, q{hg prefix test} );
is( $file_info{human_genome_compressed}, 1, q{hg compressed test} );
is( $parameter{human_genome_reference_file_endings}{build_file},
    1, q{Set build file for compression } );

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>test(human_ref_version): Added test for croak when no human version<commit_after>#!/usr/bin/env perl

use 5.026;
use Carp;
use charnames qw{ :full :short };
use English qw{ -no_match_vars };
use File::Basename qw{ dirname };
use File::Spec::Functions qw{ catdir };
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{ 2014 };
use Readonly;
use Test::Trap;

## MIPs lib/
use lib catdir( dirname($Bin), q{lib} );
use MIP::Test::Fixtures qw{ test_log test_standard_cli };

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

$VERBOSE = test_standard_cli(
    {
        verbose => $VERBOSE,
        version => $VERSION,
    }
);

## Constants
Readonly my $COMMA        => q{,};
Readonly my $GRCH_VERSION => 37;
Readonly my $HG_VERSION   => 19;
Readonly my $SPACE        => q{ };

BEGIN {

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

### Check all internal dependency modules and imports
## Modules with import
    my %perl_module = (
        q{MIP::Set::Parameter} => [qw{ set_human_genome_reference_features }],
        q{MIP::Test::Fixtures} => [qw{ test_log test_standard_cli }],
    );

    test_import( { perl_module_href => \%perl_module, } );
}

use MIP::Set::Parameter qw{ set_human_genome_reference_features };
use MIP::Log::MIP_log4perl qw{ initiate_logger };

diag(   q{Test set_human_genome_reference_features from Parameter.pm v}
      . $MIP::Set::Parameter::VERSION
      . $COMMA
      . $SPACE . q{Perl}
      . $SPACE
      . $PERL_VERSION
      . $SPACE
      . $EXECUTABLE_NAME );

## Creates log object
my $log = test_log();

my %parameter;

## Test hash
my %file_info;

## Test Ensemble genome
my $human_genome_reference = q{GRCh37_homo_sapiens_-d5-.fasta};
set_human_genome_reference_features(
    {
        file_info_href         => \%file_info,
        human_genome_reference => $human_genome_reference,
        log                    => $log,
        parameter_href         => \%parameter,
    }
);

is( $file_info{human_genome_reference_version}, $GRCH_VERSION, q{GRCh version test} );
is( $file_info{human_genome_reference_source},  q{GRCh},       q{GRCh source test} );
is( $file_info{human_genome_reference_name_prefix},
    q{GRCh37_homo_sapiens_-d5-}, q{GRCh prefix test} );
is( $file_info{human_genome_compressed}, 0, q{GRCh compressed test} );
is( $parameter{human_genome_reference_file_endings}{build_file},
    undef, q{Did not set build file for compression } );

## Test Refseq genome
$human_genome_reference = q{hg19_homo_sapiens.fasta.gz};
set_human_genome_reference_features(
    {
        file_info_href         => \%file_info,
        human_genome_reference => $human_genome_reference,
        log                    => $log,
        parameter_href         => \%parameter,
    }
);
is( $file_info{human_genome_reference_version}, $HG_VERSION, q{hg version test} );
is( $file_info{human_genome_reference_source},  q{hg},       q{hg source test} );
is( $file_info{human_genome_reference_name_prefix},
    q{hg19_homo_sapiens}, q{hg prefix test} );
is( $file_info{human_genome_compressed}, 1, q{hg compressed test} );
is( $parameter{human_genome_reference_file_endings}{build_file},
    1, q{Set build file for compression } );

## Given a human reference, when no version
# Clear for new test
%file_info = ();
my $human_genome_reference_no_version = q{GRCh_homo_sapiens_-d5-.fasta};
trap {
    set_human_genome_reference_features(
        {
            file_info_href         => \%file_info,
            human_genome_reference => $human_genome_reference_no_version,
            log                    => $log,
            parameter_href         => \%parameter,
        }
      )
};

## Then exit and throw FATAL log message
ok( $trap->exit, q{Exit if the version cannot be found} );
like( $trap->stderr, qr/FATAL/xms,
    q{Throw fatal log message if the version cannot be found} );

done_testing();
{'fraction_non_alphanumeric': 0.13571024335031126, 'fraction_numerical': 0.00792303338992643, 'mean_word_length': 3.1797540208136237, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, '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': '7136472', 'n_tokens_mistral': 3180, 'n_tokens_neox': 3020, 'n_words': 708}