-
Notifications
You must be signed in to change notification settings - Fork 6
/
digs_tool.pl
executable file
·184 lines (153 loc) · 5.92 KB
/
digs_tool.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/perl -w
############################################################################
# Script: digs_tool.pl database-integrated genome screening (DIGS) tool
# Description: A tool for exploring genomes 'in silico' using BLAST and
# a relational database
# History: Updated: February 2017
############################################################################
# Capture variables set in the environment
unless ($ENV{'DIGS_GENOMES'}) {
print "\n\n\t Required environment variable '\$DIGS_GENOMES' is undefined\n";
exit;
}
unless ($ENV{'DIGS_HOME'}) {
print "\n\n\t Required environment variable '\$DIGS_HOME' is undefined\n";
exit;
}
unless ($ENV{'DIGS_MYSQL_USER'}) {
print "\n\n\t Required environment variable '\$DIGS_MYSQL_USER' is undefined\n";
exit;
}
unless ($ENV{'DIGS_MYSQL_PASSWORD'}) {
print "\n\n\t Required environment variable '\$DIGS_MYSQL_PASSWORD' is undefined\n";
exit;
}
# Include the PERL module library for DIGS
use lib ($ENV{DIGS_HOME}) . '/modules/';
############################################################################
# Import statements/packages (externally developed packages)
############################################################################
use strict;
use Getopt::Long;
use Getopt::Long;
#use Carp;
############################################################################
# Import statements/packages (internally developed packages)
############################################################################
# Base modules
use Base::Console;
use Base::FileIO;
# Third party program interface modules
use Interface::BLAST; # Interface to BLAST
use Interface::MySQLtable; # Interface to BLAST
# DIGS framework modules
use DIGS::DIGS;
use DIGS::ScreenBuilder;
use DIGS::TargetDB;
use DIGS::ScreeningDB;
use DIGS::Utility;
############################################################################
# Paths & Globals
############################################################################
# Paths and database connection details from environment variables
my $mysql_username = ($ENV{DIGS_MYSQL_USER});
my $mysql_password = ($ENV{DIGS_MYSQL_PASSWORD});
my $genome_use_path = $ENV{DIGS_GENOMES} . '/';
my $blast_bin_path = ''; # left empty if BLAST+ programs are in your path
my $tmp_path = './tmp';
# Version number
my $program_version = '1.13.2';
# Create a unique process ID for this DIGS screening process
my $pid = $$;
my $time = time;
my $process_id = $pid . '_' . $time;
############################################################################
# Instantiations
############################################################################
# Base utilites
my $fileio = FileIO->new();
my $console = Console->new();
my $devtools = DevTools->new();
# Instantiate main program classes using global settings
my %params;
$params{program_version} = $program_version;
$params{process_id} = $process_id;
$params{blast_bin_path} = $blast_bin_path;
$params{genome_use_path} = $genome_use_path;
$params{mysql_username} = $mysql_username ;
$params{mysql_password} = $mysql_password;
$params{tmp_path} = $tmp_path;
my $digs_tool_obj = DIGS->new(\%params);
#$devtools->print_hash(\%params); die;
############################################################################
# Set up USAGE statement
############################################################################
# Initialise usage statement to print if usage is incorrect
my $USAGE = "\n\t ### DIGS version $program_version";
$USAGE .= "\n\t ### usage: $0 m=[option] -i=[control file] -h=[help]\n\n";
############################################################################
# Main program
############################################################################
# Run script
main();
exit;
############################################################################
# Subroutines
############################################################################
#***************************************************************************
# Subroutine: main
# Description: top level handler fxn
#***************************************************************************
sub main {
# Options that require a file path
my $infile = undef;
# Options that require a numerical value
my $mode = undef;
my $database = undef;
my $utility = undef;
my $genomes = undef;
# Options that don't require a value
my $help = undef;
my $extra_help = undef;
my $verbose = undef;
my $force = undef;
my $test = undef;
my $create_ids = undef;
# Read in options using GetOpt::Long
GetOptions ('infile|i=s' => \$infile,
'mode|m=i' => \$mode,
'database|d=i' => \$database,
'utility=i' => \$utility,
'genomes=i' => \$genomes,
'create_ids' => \$create_ids,
'verbose' => \$verbose,
'force' => \$force,
'help' => \$help,
'test' => \$test,
) or die $USAGE;
# Set flags based on options received
if ($verbose) { $digs_tool_obj->{verbose} = 'true'; }
if ($force) { $digs_tool_obj->{force} = 'true'; }
# Hand off to functions based on options received
if ($help) { # Show help page
$digs_tool_obj->show_help_page();
exit;
}
elsif ($mode) { # Main DIGS tool functions
$digs_tool_obj->run_digs_process($infile, $mode);
}
elsif ($database or $utility or $genomes or $utility) { # Utility functions
my $utility_obj = Utility->new($digs_tool_obj);
$utility_obj->run_utility_process($infile, $database, $genomes, $utility);
}
elsif ($test) { # Run inbuilt tests
my $test_obj = Test->new($digs_tool_obj);
$test_obj->show_test_validation_options();
}
else { die $USAGE; }
# Exit script
print "\n\n\t # Exit\n\n";
}
############################################################################
# End of file
############################################################################