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

use strict;
use warnings;
no warnings('once');

use PipelineAWE;
use Getopt::Long;
umask 000;

# options
my %types = (
    md5      => "md5s",
    ontology => "ontologies",
    function => "functions",
    organism => "organisms",
    lca      => "lcas"
);
my $tbl_range = 5000;
my $input   = "";
my $job_id  = "";
my $type    = "";
my $ver_db  = 1;
my $help    = 0;
my $options = GetOptions (
		"input=s"    => \$input,
		"job=s"      => \$job_id,
		"type=s"     => \$type,
		"nr_ver=s"   => \$ver_db,
		"help!"      => \$help
);

if ($help){
    print get_usage();
    exit 0;
}elsif (length($input)==0){
    print STDERR "ERROR: An input file was not specified.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (! -e $input){
    print STDERR "ERROR: The input summary file [$input] does not exist.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (length($job_id)==0){
    print STDERR "ERROR: A job ID is required.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (length($type)==0){
    print STDERR "ERROR: A summary type is required.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (! exists($types{$type})){
    print STDERR "ERROR: type $type is invalid.\n";
    print STDERR get_usage();
    exit __LINE__;
}

# get db variables from enviroment
my $dbhost = $ENV{'ANALYSIS_DB_HOST'} || undef;
my $dbname = $ENV{'ANALYSIS_DB_NAME'} || undef;
my $dbuser = $ENV{'ANALYSIS_DB_USER'} || undef;
my $dbpass = $ENV{'ANALYSIS_DB_PASS'} || undef;

unless (defined($dbhost) && defined($dbname) && defined($dbuser) && defined($dbpass)) {
    print STDERR "ERROR: missing analysis database ENV variables.\n";
    print STDERR get_usage();
    exit __LINE__;
}

# build / run command
my $dbopts  = "--dbhost ".$dbhost." --dbname ".$dbname." --dbuser ".$dbuser." --dbpass ".$dbpass." --dbtable_range ".$tbl_range;
my $fileopt = "--".$types{$type}."_filename ".$input;
PipelineAWE::run_cmd("load_summary2db --verbose --reload --seq-db-version $ver_db --job $job_id $dbopts $fileopt");

exit(0);

sub get_usage {
    return "USAGE: awe_loaddb.pl -input=<input summary file> -job=<job identifier> -type=<summary types> -dbhost=<db host> -dbname=<db name> -dbuser=<db user> [-nr_ver=<nr db version>]\n";
}<commit_msg>added psql cert to loaddb script<commit_after>#!/usr/bin/env perl

use strict;
use warnings;
no warnings('once');

use PipelineAWE;
use Getopt::Long;
umask 000;

# options
my %types = (
    md5      => "md5s",
    ontology => "ontologies",
    function => "functions",
    organism => "organisms",
    lca      => "lcas"
);
my $tbl_range = 5000;
my $job_id  = "";
my $input   = "";
my $psql    = "";
my $type    = "";
my $ver_db  = 1;
my $help    = 0;
my $options = GetOptions (
		"job=s"      => \$job_id,
		"input=s"    => \$input,
		"psql=s"     => \$psql,
		"type=s"     => \$type,
		"nr_ver=s"   => \$ver_db,
		"help!"      => \$help
);

if ($help){
    print get_usage();
    exit 0;
}elsif (length($input)==0){
    print STDERR "ERROR: An input file was not specified.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (! -e $input){
    print STDERR "ERROR: The input summary file [$input] does not exist.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (! -e $psql){
    print STDERR "ERROR: The input postgresql file [$psql] does not exist.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (length($job_id)==0){
    print STDERR "ERROR: A job ID is required.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (length($type)==0){
    print STDERR "ERROR: A summary type is required.\n";
    print STDERR get_usage();
    exit __LINE__;
}elsif (! exists($types{$type})){
    print STDERR "ERROR: type $type is invalid.\n";
    print STDERR get_usage();
    exit __LINE__;
}

# get db variables from enviroment
my $dbhost = $ENV{'ANALYSIS_DB_HOST'} || undef;
my $dbname = $ENV{'ANALYSIS_DB_NAME'} || undef;
my $dbuser = $ENV{'ANALYSIS_DB_USER'} || undef;
my $dbpass = $ENV{'ANALYSIS_DB_PASS'} || undef;

unless (defined($dbhost) && defined($dbname) && defined($dbuser) && defined($dbpass)) {
    print STDERR "ERROR: missing analysis database ENV variables.\n";
    print STDERR get_usage();
    exit __LINE__;
}

# place postgresql cert in home dir
PipelineAWE::run_cmd('tar -xf '.$psql.' -C '.$ENV{'HOME'}, 1);

# build / run command
my $dbopts  = "--dbhost ".$dbhost." --dbname ".$dbname." --dbuser ".$dbuser." --dbpass ".$dbpass." --dbtable_range ".$tbl_range;
my $fileopt = "--".$types{$type}."_filename ".$input;
PipelineAWE::run_cmd("load_summary2db --verbose --reload --seq-db-version $ver_db --job $job_id $dbopts $fileopt");

exit(0);

sub get_usage {
    return "USAGE: awe_loaddb.pl -job=<job identifier> -input=<input summary file> -psql=<postgresql cert tarball> -type=<summary types> -dbhost=<db host> -dbname=<db name> -dbuser=<db user> [-nr_ver=<nr db version>]\n";
}
{'fraction_non_alphanumeric': 0.1813566206336312, 'fraction_numerical': 0.00710804224207961, 'mean_word_length': 3.5142071494042164, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 39, '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': '6677145', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1835, 'n_words': 501}