<commit_before>#!usr/bin/perl -w
############################################################################
# Module:      Utility.pm   
# Description: DIGS tool utility functions
# History:     December  2017: Created by <NAME> 
############################################################################
package Utility;

############################################################################
# Import statements/packages (externally developed packages)
############################################################################
use strict;

############################################################################
# Import statements/packages (internally developed packages)
############################################################################

# Base classes
use Base::FileIO;
use Base::Console;
use Base::DevTools;

# Program components
use DIGS::ScreenBuilder; # Functions to set up screen

############################################################################
# Globals
############################################################################

# Base objects
my $fileio    = FileIO->new();
my $console   = Console->new();
my $devtools  = DevTools->new();
1;

############################################################################
# LIFECYCLE
############################################################################

#***************************************************************************
# Subroutine:  new
# Description: create new Utility 'object'
#***************************************************************************
sub new {

	my ($invocant, $digs_obj) = @_;
	my $class = ref($invocant) || $invocant;

	# Set member variables
	my $self = {

		# Global settings
		process_id             => $digs_obj->{process_id},
		program_version        => $digs_obj->{program_version},
		
		# DIGS tool object
		digs_obj => $digs_obj,

	};
	
	bless ($self, $class);
	return $self;
}

############################################################################
# UTILITY FUNCTIONS
############################################################################

#***************************************************************************
# Subroutine:  show_utility_help_page
# Description: show help page information for utility functions
#***************************************************************************
sub show_utility_help_page {

	my ($self) = @_;

	# Create utility help menu
	my $program_version = $self->{program_version};

    my $HELP   = "\n\t ### DIGS version $program_version";
       $HELP .= "\n\t ### usage: $0 m=[option] -i=[control file] -e=[utility help]\n";

       $HELP  .= "\n\t ### Utility functions\n"; 
	   $HELP  .= "\n\t -u=1   Add extra tables to screening DB"; 
	   $HELP  .= "\n\t -u=2   Flush screening DB"; 
	   $HELP  .= "\n\t -u=3   Drop screening DB"; 
	   $HELP  .= "\n\t -u=4   Show BLAST chains"; 
	   $HELP  .= "\n\t -u=5   Show locus chains"; 
	   $HELP  .= "\n\t -u=6   Show nomenclature chains"; 
	   $HELP  .= "\n\t -u=7   Summarise genomes (short, by species)";
	   $HELP  .= "\n\t -u=8   Summarise genomes (long, by target file)";
	   $HELP  .= "\n\t -u=9   Translate DB schema"; 
	   $HELP  .= "\n\t -u=10  Create standard locus IDs"; 
	   $HELP  .= "\n\t -u=11  Upload data to digs_results table"; 
	   $HELP  .= "\n\t -u=12  Extract sequences using track";
	   $HELP  .= "\n\n"; 

	print $HELP;
}

#***************************************************************************
# Subroutine:  run_utility_process
# Description: handler for DIGS tool utility functions 
#***************************************************************************
sub run_utility_process {

	my ($self, $option, $infile) = @_;

 	# Show title
	my $digs_obj = $self->{digs_obj};
	$digs_obj->show_title();  

	# If we're doing anything else we need a control file as input
	unless ($infile) { die "\n\t Option '$option' requires an infile\n\n"; }

	# Try opening control file
	my @ctl_file;
	my $valid = $fileio->read_file($infile, \@ctl_file);
	unless ($valid) {  # Exit if we can't open the file
		die "\n\t ### Couldn't open control file '$infile'\n\n\n ";
	}
	
	# If control file looks OK, store the path and parse the file
	$self->{ctl_file} = $infile;
	my $loader_obj = ScreenBuilder->new($digs_obj);
	$loader_obj->parse_control_file($infile, $digs_obj, $option);

	# Store the ScreenBuilder object (used later)
	$self->{loader_obj} = $loader_obj;

	# Create the output directories
	$loader_obj->create_output_directories($self);

	# Load/create the screening database
	my $db_name = $loader_obj->{db_name};
	unless ($db_name) { die "\n\t Error: no DB name defined \n\n\n"; }
	$digs_obj->initialise_screening_db($db_name);

	# Hand off to functions 
	if ($option eq 1) { # Add a table of data to the screening database
		$self->extend_screening_db();
	}
	elsif ($option eq 2) { # Flush screening DB
		my $db = $digs_obj->{db};
		my $db_name = $db->{db_name};
		my $question = "\n\n\t  Are you sure you want to flush data in the $db_name database?";
		my $answer1 = $console->ask_yes_no_question($question); # Ask to make sure
		if ($answer1 eq 'y') { $db->flush_screening_db(); }
	}
	elsif ($option eq 3) { # Drop screening DB 
		my $db = $digs_obj->{db};
		$db->drop_screening_db();    
	}
	elsif ($option eq 4) { # Show the BLAST chains for each extracted locus
		$self->show_blast_chains();
	}
	elsif ($option eq 5) { # Consolidate DIGS results into higher level loci 
		$self->show_locus_chains();
	}
	elsif ($option eq 6) { # Consolidate DIGS results into higher level loci 
		$self->show_nomenclature_chains();
	}
	elsif ($option eq 7)    { # Summarise target genome directory (short)
		my $target_db_obj = TargetDB->new($digs_obj);
		$target_db_obj->summarise_targets_short();
	}
	elsif ($option eq 8) { # Summarise target genome directory (long)
		my $target_db_obj = TargetDB->new($digs_obj);
		$target_db_obj->summarise_targets_long();
	}
	elsif ($option eq 9) { # DB schema translation
		die;
		my $db_obj = $self->{db};
		$db_obj->translate_schema();
	}
	elsif ($option eq 10) { # Standardised locus naming
		die;
		$self->upload_data_to_digs_results_table();
	}
	elsif ($option eq 10) { # Standardised locus naming
		die;
		$self->create_standard_locus_ids();
	}
	elsif ($option eq 12) {
		unless ($infile) {  die "\n\t Option '$option' requires an infile\n\n"; }
		$self->extract_track_sequences($infile);
	}<commit_msg>Fixed translate schema function in Utility.pm<commit_after>#!usr/bin/perl -w
############################################################################
# Module:      Utility.pm   
# Description: DIGS tool utility functions
# History:     December  2017: Created by <NAME> 
############################################################################
package Utility;

############################################################################
# Import statements/packages (externally developed packages)
############################################################################
use strict;

############################################################################
# Import statements/packages (internally developed packages)
############################################################################

# Base classes
use Base::FileIO;
use Base::Console;
use Base::DevTools;

# Program components
use DIGS::ScreenBuilder; # Functions to set up screen

############################################################################
# Globals
############################################################################

# Base objects
my $fileio    = FileIO->new();
my $console   = Console->new();
my $devtools  = DevTools->new();
1;

############################################################################
# LIFECYCLE
############################################################################

#***************************************************************************
# Subroutine:  new
# Description: create new Utility 'object'
#***************************************************************************
sub new {

	my ($invocant, $digs_obj) = @_;
	my $class = ref($invocant) || $invocant;

	# Set member variables
	my $self = {

		# Global settings
		process_id             => $digs_obj->{process_id},
		program_version        => $digs_obj->{program_version},
		
		# DIGS tool object
		digs_obj => $digs_obj,

	};
	
	bless ($self, $class);
	return $self;
}

############################################################################
# UTILITY FUNCTIONS
############################################################################

#***************************************************************************
# Subroutine:  show_utility_help_page
# Description: show help page information for utility functions
#***************************************************************************
sub show_utility_help_page {

	my ($self) = @_;

	# Create utility help menu
	my $program_version = $self->{program_version};

    my $HELP   = "\n\t ### DIGS version $program_version";
       $HELP .= "\n\t ### usage: $0 m=[option] -i=[control file] -e=[utility help]\n";

       $HELP  .= "\n\t ### Utility functions\n"; 
	   $HELP  .= "\n\t -u=1   Add extra tables to screening DB"; 
	   $HELP  .= "\n\t -u=2   Flush screening DB"; 
	   $HELP  .= "\n\t -u=3   Drop screening DB"; 
	   $HELP  .= "\n\t -u=4   Show BLAST chains"; 
	   $HELP  .= "\n\t -u=5   Show locus chains"; 
	   $HELP  .= "\n\t -u=6   Show nomenclature chains"; 
	   $HELP  .= "\n\t -u=7   Summarise genomes (short, by species)";
	   $HELP  .= "\n\t -u=8   Summarise genomes (long, by target file)";
	   $HELP  .= "\n\t -u=9   Translate DB schema"; 
	   $HELP  .= "\n\t -u=10  Create standard locus IDs"; 
	   $HELP  .= "\n\t -u=11  Upload data to digs_results table"; 
	   $HELP  .= "\n\t -u=12  Extract sequences using track";
	   $HELP  .= "\n\n"; 

	print $HELP;
}

#***************************************************************************
# Subroutine:  run_utility_process
# Description: handler for DIGS tool utility functions 
#***************************************************************************
sub run_utility_process {

	my ($self, $option, $infile) = @_;

 	# Show title
	my $digs_obj = $self->{digs_obj};
	$digs_obj->show_title();  

	# If we're doing anything else we need a control file as input
	unless ($infile) { die "\n\t Option '$option' requires an infile\n\n"; }

	# Try opening control file
	my @ctl_file;
	my $valid = $fileio->read_file($infile, \@ctl_file);
	unless ($valid) {  # Exit if we can't open the file
		die "\n\t ### Couldn't open control file '$infile'\n\n\n ";
	}
	
	# If control file looks OK, store the path and parse the file
	$self->{ctl_file} = $infile;
	my $loader_obj = ScreenBuilder->new($digs_obj);
	$loader_obj->parse_control_file($infile, $digs_obj, $option);

	# Store the ScreenBuilder object (used later)
	$self->{loader_obj} = $loader_obj;

	# Create the output directories
	$loader_obj->create_output_directories($self);

	# Load/create the screening database
	my $db_name = $loader_obj->{db_name};
	unless ($db_name) { die "\n\t Error: no DB name defined \n\n\n"; }
	$digs_obj->initialise_screening_db($db_name);

	# Hand off to functions 
	if ($option eq 1) { # Add a table of data to the screening database
		$self->extend_screening_db();
	}
	elsif ($option eq 2) { # Flush screening DB
		my $db = $digs_obj->{db};
		my $db_name = $db->{db_name};
		my $question = "\n\n\t  Are you sure you want to flush data in the $db_name database?";
		my $answer1 = $console->ask_yes_no_question($question); # Ask to make sure
		if ($answer1 eq 'y') { $db->flush_screening_db(); }
	}
	elsif ($option eq 3) { # Drop screening DB 
		my $db = $digs_obj->{db};
		$db->drop_screening_db();    
	}
	elsif ($option eq 4) { # Show the BLAST chains for each extracted locus
		$self->show_blast_chains();
	}
	elsif ($option eq 5) { # Consolidate DIGS results into higher level loci 
		$self->show_locus_chains();
	}
	elsif ($option eq 6) { # Consolidate DIGS results into higher level loci 
		$self->show_nomenclature_chains();
	}
	elsif ($option eq 7)    { # Summarise target genome directory (short)
		my $target_db_obj = TargetDB->new($digs_obj);
		$target_db_obj->summarise_targets_short();
	}
	elsif ($option eq 8) { # Summarise target genome directory (long)
		my $target_db_obj = TargetDB->new($digs_obj);
		$target_db_obj->summarise_targets_long();
	}
	elsif ($option eq 9) { # DB schema translation
		my $db_obj = $digs_obj->{db};
		$db_obj->translate_schema();
	}
	elsif ($option eq 10) { # Standardised locus naming
		die;
		$self->upload_data_to_digs_results_table();
	}
	elsif ($option eq 10) { # Standardised locus naming
		die;
		$self->create_standard_locus_ids();
	}
	elsif ($option eq 12) {
		unless ($infile) {  die "\n\t Option '$option' requires an infile\n\n"; }
		$self->extract_track_sequences($infile);
	}
{'fraction_non_alphanumeric': 0.32710062844285825, 'fraction_numerical': 0.005896500892233688, 'mean_word_length': 4.6784140969163, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 81, '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': '2230099', 'n_tokens_mistral': 4191, 'n_tokens_neox': 3803, 'n_words': 1048}