forked from Dfam-consortium/RepeatMasker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·493 lines (437 loc) · 13.4 KB
/
configure
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
#!/usr/bin/env perl
##---------------------------------------------------------------------------##
## File:
## @(#) configure
## Author:
## Robert Hubley <[email protected]>
## Description:
## A configuration utility for the RepeatMasker distribution.
##
#******************************************************************************
#* Copyright (C) Institute for Systems Biology 2003-2019 Developed by
#* Robert Hubley.
#*
#* This work is licensed under the Open Source License v2.1. To view a copy
#* of this license, visit http://www.opensource.org/licenses/osl-2.1.php or
#* see the license.txt file contained in this distribution.
#*
###############################################################################
=head1 NAME
configure - Configure the RepeatMasker distribution
=head1 SYNOPSIS
perl ./configure
=head1 DESCRIPTION
An installation script for the RepeatMasker distribution
=head1 CONFIGURATION OVERRIDES
=head1 SEE ALSO
=over 4
RepeatMasker
=back
=head1 COPYRIGHT
Copyright 2003-2019 Robert Hubley, Institute for Systems Biology
=head1 AUTHOR
Robert Hubley <[email protected]>
=cut
#
# Module Dependence
#
use strict;
use Cwd;
use FindBin;
use Getopt::Long;
use Pod::Text;
use lib $FindBin::Bin;
use RepeatMaskerConfig;
use POSIX qw(:sys_wait_h);
# No output buffering
$|=1;
#
# Release Version
#
my $version = $RepeatMaskerConfig::VERSION;
#
# First...make sure we are running in the same directory
# as the script is located. This avoids problems where
# this script ends up in someones path and they run it
# unqualified from another installation directory.
#
if ( cwd() ne $FindBin::RealBin ) {
print "\n The RepeatMasker configure script must be run from\n"
. " inside the RepeatMasker installation directory:\n\n"
. " $FindBin::RealBin\n\n"
. " Perhaps this is not the \"configure\" you are looking for?\n\n";
exit;
}
#
# Option processing
# e.g.
# -t: Single letter binary option
# -t=s: String parameters
# -t=i: Number parameters
#
my @getopt_args = ( '-version', '-perlbin' );
# Add configuration parameters as additional command-line options
push @getopt_args, RepeatMaskerConfig::getCommandLineOptions();
#
# Get the supplied command line options, and set flags
#
my %options = ();
Getopt::Long::config( "noignorecase", "bundling_override" );
unless ( GetOptions( \%options, @getopt_args ) ) {
usage();
}
#
# Provide the POD text from this file and
# from the config file by merging them
# together. The heading "CONFIGURATION
# OVERRIDES" provides the insertion point
# for the configuration POD.
#
sub usage {
my $p = Pod::Text->new();
$p->output_fh(*STDOUT);
my $pod_str;
open IN,"<$0" or die "Could not open self ($0) for generating documentation!";
while (<IN>){
if ( /^=head1\s+CONFIGURATION OVERRIDES\s*$/ )
{
my $c_pod = RepeatMaskerConfig::getPOD();
if ( $c_pod ) {
$pod_str .= $_ . $c_pod;
}
}else {
$pod_str .= $_;
}
}
close IN;
print "$0 - $version\n";
$p->parse_string_document($pod_str);
exit(1);
}
#
# Resolve configuration settings using the following precedence:
# command line first, then environment, followed by config
# file.
#
RepeatMaskerConfig::resolveConfiguration(\%options);
my $config = $RepeatMaskerConfig::configuration;
##
## Perl interpreter location
##
my $perlLocation = $^X;
if ( $options{'perlbin'} ) {
my $tbin = "";
if ( -d $options{'perlbin'} ) {
if ( -x ( $options{'perlbin'} . "/perl" ) ) {
$tbin = $options{'perlbin'} . "/perl";
}
elsif ( -x ( $options{'perlbin'} . "/bin/perl" ) ) {
$tbin = $options{'perlbin'} . "/bin/perl";
}
else {
die "Could not find perl using supplied -perlbin parameter $options{'perlbin'}\n"
. "as $options{'perlbin'}/perl or $options{'perlbin'}/bin/perl. Please fix\n"
. "and rerun configure.\n";
}
}
elsif ( -x $options{'perlbin'} ) {
$tbin = $options{'perlbin'};
}
if ( $tbin ne $perlLocation ) {
my $optStr;
foreach my $key ( keys %options ) {
if ( $key ne "perlbin" ) {
$optStr .= " -$key " . $options{$key};
}
}
# Rerun with intended version of perl
exec( "$tbin $FindBin::RealBin/configure $optStr" );
}
}
##
## Check for perl version
##
if ( $] && $] < 5.008 ) {
print "RepeatMasker should be used with perl 5.008 or higher.\n"
. "Perl $] is being used to run configure.";
exit;
}
##
## Check for RepeatMasker dependencies
##
BEGIN {
my @modDependencies = (
"Tie::File", "Getopt::Long",
"POSIX", "File::Copy",
"File::Path", "Data::Dumper",
"Cwd", "Storable"
);
my @missingModules = ();
foreach my $module ( @modDependencies ) {
unless ( eval "require " . $module . ";" ) {
push @missingModules, $module;
}
}
if ( @missingModules ) {
print "\nThe following perl modules required by RepeatMasker "
. "are missing from\nyour system. Please install these or "
. "or upgrade your perl version\nto 5.8.x first:\n "
. join( "\n ", @missingModules ) . "\n";
exit;
}
}
#
# Check for XS version of Scalar::Util
#
eval "use Scalar::Util qw(weaken);";
if ( $@ ) {
print "\nThe CPAN module Scalar::Util included in this version of perl\n"
. "is not compiled with the XS option. RepeatMasker requires the\n"
. "XS version of the module. Please reinstall XS Scalar::Util from\n"
. "CPAN and restart the configure process.\n\n";
exit;
}
#
# Check Storable Version
#
my $storableVersion =
`$perlLocation -mStorable -e 'print \$Storable::VERSION' 2>/dev/null`;
if ( $storableVersion < 2.06 ) {
print "\nYour perl installation contains an old Storable CPAN module\n"
. "( version = $storableVersion ). Please upgrade your Storable module "
. "to\nversion 2.06 or higher and then re-run the configure program.\n\n";
exit;
}
##
## Alter perl invocation headers
##
print " -- Setting perl interpreter...\n";
my @progFiles = (
"RepeatMasker",
"DateRepeats",
"ProcessRepeats",
"RepeatProteinMask",
"DupMasker",
"addRepBase.pl",
"util/calcDivergenceFromAlign.pl",
"util/createRepeatLandscape.pl",
"util/maskFile.pl",
"util/rmOutToGFF3.pl",
"util/buildRMLibFromEMBL.pl",
"util/rmToUCSCTables.pl"
);
my $perlLocEsc = $perlLocation;
$perlLocEsc =~ s/\//\\\//g;
foreach my $file ( @progFiles ) {
system(
"$perlLocation -i -0pe \'s/^#\\!.*perl.*/#\\!$perlLocEsc/g\;' $file" );
}
##
## Introduce ourselves
##
system( "clear" );
print "RepeatMasker Configuration Program\n";
my $answer;
my $goodParam;
# So that we can get the engine versions
require NCBIBlastSearchEngine;
require WUBlastSearchEngine;
require CrossmatchSearchEngine;
require HMMERSearchEngine;
##
## RepeatMasker location
##
my $rmLocation = "$FindBin::Bin";
if ( -d "$rmLocation/Libraries" &&
$config->{'LIBDIR'}->{'value'} eq "" ){
$config->{'LIBDIR'}->{'value'} = $rmLocation . "/Libraries";
}
if ( ! RepeatMaskerConfig::validateParam('LIBDIR') ) {
RepeatMaskerConfig::promptForParam('LIBDIR');
}
my $LIBDIR = $config->{'LIBDIR'}->{'value'};
print "\n\nChecking for libraries...\n\n";
# Installation scenarios
# 1: Both Dfam *and* RepBase RepeatMasker Edition
if ( -s "$LIBDIR/Dfam.h5" && -s "$LIBDIR/RMRBSeqs.embl" ) {
unlink("$LIBDIR/RepeatMaskerLib.h5") if ( -e "$LIBDIR/RepeatMaskerLib.h5" );
defined(my $pid = fork) or die "Couldn't fork: $!";
if (!$pid) { # Child
system("$FindBin::RealBin/addRepBase.pl -libdir $LIBDIR");
exit;
} else { # Parent
while (! waitpid($pid, WNOHANG)) {
sleep 2;
print ".";
}
}
print "\n";
# 2: Just a form of Dfam ( curated or curated+uncurated )
}elsif ( -s "$LIBDIR/Dfam.h5" ) {
print " - Found Dfam\n";
unlink("$LIBDIR/RepeatMaskerLib.h5") if ( -e "$LIBDIR/RepeatMaskerLib.h5" );
system("ln -s $LIBDIR/Dfam.h5 $LIBDIR/RepeatMaskerLib.h5");
# 3: What...nothing?
}else {
die "\nCould not find $LIBDIR/Dfam.h5!\n" .
"Please download a copy of the Dfam library ( famdb HDF5 format )\n" .
"from:\n\n" .
" https://www.dfam.org/releases/Dfam_#.#/families/Dfam.h5.gz\n" .
"or\n" .
" https://www.dfam.org/releases/Dfam_#.#/families/Dfam_curatedonly.h5.gz\n\n" .
"uncompress it ( gunzip ), store in $LIBDIR,\n" .
"and rerun the configure program.\n\n\n";
}
#print "<PRESS ENTER TO CONTINUE>\n";
#$answer = <STDIN>;
my $dbInfo = `$rmLocation/famdb.py -i $LIBDIR/RepeatMaskerLib.h5 info`;
if ( ! $options{'trf_prgm'} ) {
RepeatMaskerConfig::promptForParam('TRF_PRGM');
}
##
## Search Engine Configuration
##
if ( ! ( $options{'abblast_dir'} || $options{'rmblast_dir'} || $options{'hmmer_dir'} ||
$options{'crossmatch_dir'} ) ) {
searchEngineMenu();
}else {
# Assumption: if at least one engine is specified on the command line then the intention
# is to not prompt for any engines.
}
print "Building FASTA version of RepeatMasker.lib ...";
defined(my $pid = fork) or die "Couldn't fork: $!";
if (!$pid) { # Child
system("$rmLocation/famdb.py -i $rmLocation/Libraries/RepeatMaskerLib.h5 families --descendants 1 --curated --format fasta_name > $rmLocation/Libraries/RepeatMasker.lib");
exit;
} else { # Parent
while (! waitpid($pid, WNOHANG)) {
sleep 2;
print ".";
}
}
print "\n";
#
# Freeze RM and RMPep libraries for RepeatModeler use among others
#
if ( RepeatMaskerConfig::validateParam('RMBLAST_DIR') )
{
my $binDir = $config->{'RMBLAST_DIR'}->{'value'};
print "Building RMBlast frozen libraries..\n";
system( "$binDir/makeblastdb -dbtype nucl -in "
. "$LIBDIR/RepeatMasker.lib > /dev/null 2>&1" );
system( "$binDir/makeblastdb -dbtype prot -in "
. "$LIBDIR/RepeatPeps.lib > /dev/null 2>&1" );
}
if ( RepeatMaskerConfig::validateParam('ABBLAST_DIR') )
{
my $binDir = $config->{'ABBLAST_DIR'}->{'value'};
print "Building WUBlast/ABBlast frozen libraries..\n";
system( "$binDir/xdformat -n -I "
. "$LIBDIR/RepeatMasker.lib > /dev/null 2>&1" );
system( "$binDir/xdformat -p -I "
. "$LIBDIR/RepeatPeps.lib > /dev/null 2>&1" );
}
# Save settings
RepeatMaskerConfig::updateConfigFile();
print "The program is installed with a the following repeat libraries:\n";
print "$dbInfo\n";
print "Further documentation on the program may be found here:\n";
print " $rmLocation/repeatmasker.help\n\n";
####################### S U B R O U T I N E S ##############################
sub searchEngineMenu {
my $configFile = shift;
my @searchEngines = (
{
name => "CROSSMATCH_DIR",
desc => "Crossmatch",
defname => "crossmatch",
status => 0,
},
{
name => "RMBLAST_DIR",
desc => "RMBlast",
defname => "rmblast",
status => 0,
},
{
name => "HMMER_DIR",
desc => "HMMER3.1 & DFAM",
defname => "hmmer",
status => 0,
},
{
name => "ABBLAST_DIR",
desc => "ABBlast",
defname => "abblast",
status => 0,
}
);
my $done = 0;
my $defaultEngine = "";
do {
system( "clear" );
print "\n\n\n";
print "Add a Search Engine:\n";
my $i;
for ( $i = 0 ; $i <= $#searchEngines ; $i++ )
{
print " " . ( $i + 1 ) . ". $searchEngines[$i]->{'desc'}: [ ";
if ( $searchEngines[ $i ]->{'status'} == 0 )
{
print "Un-configured ]\n";
} elsif ( $searchEngines[ $i ]->{'status'} == 1 )
{
print "Configured ]\n";
} else
{
print "Configured, Default ]\n";
}
}
print "\n";
print " " . ( $i + 1 ) . ". Done\n";
print "\n\nEnter Selection: ";
$answer = <STDIN>;
$answer =~ s/[\n\r]+//g;
if ( $answer =~ /\d+/ && $answer > 0 && $answer <= ( $#searchEngines + 2 ) )
{
if ( $answer == ( $#searchEngines + 2 ) ) {
if ( $defaultEngine eq "" ) {
print "You must configure at least one search engine!\n";
print "<PRESS ENTER TO CONTINUE - CTRL-C to QUIT>\n";
$answer = <STDIN>;
}
else {
$done = 1;
}
}
else {
RepeatMaskerConfig::promptForParam($searchEngines[$answer-1]->{'name'});
system("clear");
print "\n\n\n";
print "Do you want " . $searchEngines[$answer-1]->{'desc'} . " to be your default\nsearch engine for Repeatmasker? (Y/N) ";
print " [ Y ]: ";
my $isDefault = <STDIN>;
$isDefault =~ s/[\n\r]+//g;
if ( $isDefault =~ /^\s*$/ || $isDefault =~ /\s*[yY]\s*/ )
{
for ( $i = 0 ; $i <= $#searchEngines ; $i++ )
{
$searchEngines[$i]->{'status'} = 1
if ( $searchEngines[$i]->{'status'} == 2 );
}
$searchEngines[ $answer - 1 ]->{'status'} = 2;
$RepeatMaskerConfig::configuration->{'DEFAULT_SEARCH_ENGINE'}->{'value'} = $searchEngines[$answer-1]->{'defname'};
$defaultEngine = $answer;
}else {
$searchEngines[ $answer - 1 ]->{'status'} = 1;
}
}
}
else {
print "Invalid selection!\n";
print "<PRESS ENTER TO CONTINUE>\n";
$answer = <STDIN>;
}
} while ( $done == 0 );
}
1;